Re: [PATCH v7 2/6] sched_ext: Implement scx_bpf_now()

From: Changwoo Min
Date: Wed Jan 08 2025 - 11:05:16 EST


Hello,

On 25. 1. 8. 17:50, Peter Zijlstra wrote:

That is, I rather think you need:

+static inline void scx_rq_clock_update(struct rq *rq, u64 clock)
+{
+ if (!scx_enabled())
+ return;
+ WRITE_ONCE(rq->scx.clock, clock);
+ smp_store_release(&rq->scx.flags, rq->scx.flags | SCX_RQ_CLK_VALID);
+}

and:

if (smp_load_acquire(&rq->scx.flags) & SCX_RQ_CLK_VALID) {
+ /*
+ * If the rq clock is valid, use the cached rq clock.
+ *
+ * Note that scx_bpf_now() is re-entrant between a process
+ * context and an interrupt context (e.g., timer interrupt).
+ * However, we don't need to consider the race between them
+ * because such race is not observable from a caller.
+ */
+ clock = READ_ONCE(rq->scx.clock);

Such that if you ovbserve VALID, you must then also observe the clock.

Thank you for catching this out! I will change it as suggested in
the next version.

Regards,
Changwoo Min