From: Tejun Heo <tj@kernel.org>
To: Changwoo Min <multics69@gmail.com>
Cc: void@manifault.com, arighi@nvidia.com, mingo@redhat.com,
peterz@infradead.org, changwoo@igalia.com, kernel-dev@igalia.com,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v6 2/6] sched_ext: Implement scx_bpf_now_ns()
Date: Tue, 24 Dec 2024 11:47:54 -1000 [thread overview]
Message-ID: <Z2ssCtnEciplLogy@slm.duckdns.org> (raw)
In-Reply-To: <20241220062025.27724-3-changwoo@igalia.com>
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.
> +{
> + struct rq *rq;
> + u64 clock;
> +
> + preempt_disable();
> +
> + /*
> + * If the rq clock is valid, use the cached rq clock.
> + * Otherwise, return a fresh rq glock.
> + *
> + * Note that scx_bpf_now_ns() 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.
> + */
> + rq = this_rq();
> + clock = READ_ONCE(rq->scx.clock);
> +
> + 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?
...
> +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?
Thanks.
--
tejun
next prev parent reply other threads:[~2024-12-24 21:47 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-20 6:20 [PATCH v6 0/6] sched_ext: Support high-performance monotonically non-decreasing clock Changwoo Min
2024-12-20 6:20 ` [PATCH v6 1/6] sched_ext: Relocate scx_enabled() related code Changwoo Min
2024-12-20 6:20 ` [PATCH v6 2/6] sched_ext: Implement scx_bpf_now_ns() Changwoo Min
2024-12-20 21:30 ` Andrea Righi
2024-12-22 4:32 ` Changwoo Min
2024-12-24 21:47 ` Tejun Heo [this message]
2024-12-27 0:38 ` Changwoo Min
2024-12-20 6:20 ` [PATCH v6 3/6] sched_ext: Add scx_bpf_now_ns() for BPF scheduler Changwoo Min
2024-12-20 6:20 ` [PATCH v6 4/6] sched_ext: Add time helpers for BPF schedulers Changwoo Min
2024-12-24 21:49 ` Tejun Heo
2024-12-27 0:32 ` Changwoo Min
2024-12-20 6:20 ` [PATCH v6 5/6] sched_ext: Replace bpf_ktime_get_ns() to scx_bpf_now_ns() Changwoo Min
2024-12-20 6:20 ` [PATCH v6 6/6] sched_ext: Use time helpers in BPF schedulers Changwoo Min
2024-12-20 22:29 ` [PATCH v6 0/6] sched_ext: Support high-performance monotonically non-decreasing clock Andrea Righi
2024-12-22 6:37 ` Changwoo Min
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Z2ssCtnEciplLogy@slm.duckdns.org \
--to=tj@kernel.org \
--cc=arighi@nvidia.com \
--cc=changwoo@igalia.com \
--cc=kernel-dev@igalia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=multics69@gmail.com \
--cc=peterz@infradead.org \
--cc=void@manifault.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.