[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250210095607.GH10324@noisy.programming.kicks-ass.net>
Date: Mon, 10 Feb 2025 10:56:07 +0100
From: Peter Zijlstra <peterz@...radead.org>
To: Kumar Kartikeya Dwivedi <memxor@...il.com>
Cc: bpf@...r.kernel.org, linux-kernel@...r.kernel.org,
Barret Rhoden <brho@...gle.com>,
Linus Torvalds <torvalds@...ux-foundation.org>,
Will Deacon <will@...nel.org>, Waiman Long <llong@...hat.com>,
Alexei Starovoitov <ast@...nel.org>,
Andrii Nakryiko <andrii@...nel.org>,
Daniel Borkmann <daniel@...earbox.net>,
Martin KaFai Lau <martin.lau@...nel.org>,
Eduard Zingerman <eddyz87@...il.com>,
"Paul E. McKenney" <paulmck@...nel.org>, Tejun Heo <tj@...nel.org>,
Josh Don <joshdon@...gle.com>, Dohyun Kim <dohyunkim@...gle.com>,
linux-arm-kernel@...ts.infradead.org, kernel-team@...a.com
Subject: Re: [PATCH bpf-next v2 07/26] rqspinlock: Add support for timeouts
On Thu, Feb 06, 2025 at 02:54:15AM -0800, Kumar Kartikeya Dwivedi wrote:
> @@ -68,6 +71,44 @@
>
> #include "mcs_spinlock.h"
>
> +struct rqspinlock_timeout {
> + u64 timeout_end;
> + u64 duration;
> + u16 spin;
> +};
> +
> +static noinline int check_timeout(struct rqspinlock_timeout *ts)
> +{
> + u64 time = ktime_get_mono_fast_ns();
This is only sane if you have a TSC clocksource. If you ever manage to
hit the HPET fallback, you're *really* sad.
> +
> + if (!ts->timeout_end) {
> + ts->timeout_end = time + ts->duration;
> + return 0;
> + }
> +
> + if (time > ts->timeout_end)
> + return -ETIMEDOUT;
> +
> + return 0;
> +}
> +
> +#define RES_CHECK_TIMEOUT(ts, ret) \
> + ({ \
> + if (!(ts).spin++) \
> + (ret) = check_timeout(&(ts)); \
> + (ret); \
> + })
Powered by blists - more mailing lists