[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20250224215555.GF11590@noisy.programming.kicks-ass.net>
Date: Mon, 24 Feb 2025 22:55:55 +0100
From: Peter Zijlstra <peterz@...radead.org>
To: Thomas Gleixner <tglx@...utronix.de>
Cc: LKML <linux-kernel@...r.kernel.org>,
Anna-Maria Behnsen <anna-maria@...utronix.de>,
Frederic Weisbecker <frederic@...nel.org>,
Benjamin Segall <bsegall@...gle.com>,
Eric Dumazet <edumazet@...gle.com>,
Andrey Vagin <avagin@...nvz.org>,
Pavel Tikhomirov <ptikhomirov@...tuozzo.com>
Subject: Re: [patch 04/11] posix-timers: Remove pointless unlock_timer()
wrapper
On Mon, Feb 24, 2025 at 07:43:26PM +0100, Thomas Gleixner wrote:
> On Mon, Feb 24 2025 at 17:21, Peter Zijlstra wrote:
> > On Mon, Feb 24, 2025 at 11:15:28AM +0100, Thomas Gleixner wrote:
> >> It's just a wrapper around spin_unlock_irqrestore() with zero value.
> >
> > Well, I disagree... the value is that is matches lock_timer(). Both in
> > naming and in argument types.
>
> Sure, but it's not used consistently as we have places where
> lock_timer() is not involved.
>
> > @@ -327,14 +350,13 @@ bool posixtimer_deliver_signal(struct ke
> > * Release siglock to ensure proper locking order versus
> > * timr::it_lock. Keep interrupts disabled.
> > */
> > - spin_unlock(¤t->sighand->siglock);
> > + guard(spinlock)(¤t->sighand->siglock);
>
> How is that equivalent?
I R idiot :-)
> So the resulting code is:
>
> scoped_guard (lock_timer, timer_id) {
> struct k_itimer *timr = __guard_ptr(lock_timer)(&scope);
> const struct k_clock *kc;
>
> memset(setting, 0, sizeof(*setting));
> kc = timr->kclock;
> if (WARN_ON_ONCE(!kc || !kc->timer_get))
> return -EINVAL;
>
> return 0;
> }
> return -EINVAL;
>
> I had to go and stare at the guard/class muck 10 times to convince
> myself, that this actually works. This really wants to be express the
> condition of the scoped_guard() somehow, e.g. scoped_cond_guard() or
> such.
Right, so the alternative form is something like:
scoped_cond_guard (lock_timer, return -EINVAL, timer_id) {
struct k_itimer *timr = __guard_ptr(lock_timer)(&scope);
const struct k_clock *kc;
memset(setting, 0, sizeof(*setting));
kc = timr->kclock;
if (WARN_ON_ONCE(!kc || !kc->timer_get))
return -EINVAL;
}
return 0;
Is that really so much better?
> > /* Delete a POSIX.1b interval timer. */
> > SYSCALL_DEFINE1(timer_delete, timer_t, timer_id)
> > {
> > - return posix_timer_delete(NULL, timer_id);
> > + scoped_guard (lock_timer, timer_id) {
> > + posix_timer_invalidate(scope.lock, scope.flags);
> > + scoped_guard_end(lock_timer);
> > + posix_timer_unhash_and_free(scope.lock);
>
> Not sure whether it's a good idea to free the scope.lock and not
> scope.timer :)
There is no scope.timer, the way this work is that the main pointer is
.lock, per the __DEFINE_UNLOCK_GUARD() helper.
I said there were rough edges :-/
Anyway, should I continue poking at this to see if I can clean it up /
extract more useful helpers.
Or shall I just let it be.
Powered by blists - more mailing lists