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

From: Changwoo Min
Date: Thu Dec 26 2024 - 19:39:13 EST


Hello,

On 24. 12. 25. 06:47, Tejun Heo wrote:
Hello,

On Fri, Dec 20, 2024 at 03:20:21PM +0900, Changwoo Min wrote:
...
+__bpf_kfunc u64 scx_bpf_now_ns(void)

Given that the default time unit is ns for the scheduler, the _ns suffix
can probably go.

Ok. I will change is as suggested.



+ 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);

Hmm... what does this update do?
It can be dropped as we do not track prev_clock.


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

Isn't rq->scx.clock used iff VALID is set? If so, why does !VALID read need
to update rq->scx.clock?

If we drop the previous scx_rq_clock_update(.., false), we can
drop the if condition checking the valid flag.

Regards,
Changwoo Min