Re: [PATCH v6 2/6] sched_ext: Implement scx_bpf_now_ns()

From: Changwoo Min
Date: Sat Dec 21 2024 - 23:33:39 EST


Hi Andrea,

On 24. 12. 21. 06:30, Andrea Righi wrote:
Hi Changwoo,

On Fri, Dec 20, 2024 at 03:20:21PM +0900, Changwoo Min wrote:
...
+ /*
+ * If the rq clock is valid, use the cached rq clock.
+ * Otherwise, return a fresh rq glock.

s/glock/clock/
Opps. My bad.

+ if (!(READ_ONCE(rq->scx.flags) & SCX_RQ_CLK_VALID)) {
+ clock = sched_clock_cpu(cpu_of(rq));
+
+ /*
+ * The rq clock is updated outside of the rq lock.
+ * In this case, keep the updated rq clock invalid so the next
+ * kfunc call outside the rq lock gets a fresh rq clock.
+ */
+ scx_rq_clock_update(rq, clock, false);
+ }

I was wondering if we could use a special value for clock (like ~0ULL or
similar) to mark the clock as invalid.

This way, we could get rid of the extra READ_ONCE(rq->scx.flags) logic for
checking the clock validity. And if the actual clock happens to match the
special value, we'd simply re-read the TSC, which shouldn't be a big issue
in theory.


Thank you for the suggestion. In theory, the clock can overflow,
so it would be hard to reserve a specific value. I think it would
be better to keep the code as it is.

Regards,
Changwoo Min