From: Thomas Gleixner <tglx@linutronix.de>
To: Peter Zijlstra <peterz@infradead.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
Anna-Maria Behnsen <anna-maria@linutronix.de>,
Frederic Weisbecker <frederic@kernel.org>,
Benjamin Segall <bsegall@google.com>,
Eric Dumazet <edumazet@google.com>,
Andrey Vagin <avagin@openvz.org>,
Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
Subject: Re: [patch 04/11] posix-timers: Remove pointless unlock_timer() wrapper
Date: Mon, 24 Feb 2025 19:43:26 +0100 [thread overview]
Message-ID: <87seo3fak1.ffs@tglx> (raw)
In-Reply-To: <20250224162103.GD11590@noisy.programming.kicks-ass.net>
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?
This is a unlock/lock pair because __posix_timer_deliver_signal() takes
timr->it_lock and now you introduced the ABBA which the sighand::siglock
unlock carefully avoids :)
>
> ret = __posixtimer_deliver_signal(info, timr);
>
> /* Drop the reference which was acquired when the signal was queued */
> posixtimer_putref(timr);
>
> - spin_lock(¤t->sighand->siglock);
> return ret;
> }
>
> @@ -717,24 +739,20 @@ void common_timer_get(struct k_itimer *t
>
> static int do_timer_gettime(timer_t timer_id, struct itimerspec64 *setting)
> {
> - const struct k_clock *kc;
> - struct k_itimer *timr;
> - unsigned long flags;
> - int ret = 0;
> -
> - timr = lock_timer(timer_id, &flags);
> - if (!timr)
> - return -EINVAL;
> + 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;
>
> - memset(setting, 0, sizeof(*setting));
> - kc = timr->kclock;
> - if (WARN_ON_ONCE(!kc || !kc->timer_get))
> - ret = -EINVAL;
> - else
> kc->timer_get(timr, setting);
> + return 0;
> + }
>
> - spin_unlock_irqrestore(&timr->it_lock, flags);
> - return ret;
> + return -EINVAL;
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.
> /* 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 :)
Thanks,
tglx
next prev parent reply other threads:[~2025-02-24 18:43 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-24 10:15 [patch 00/11] posix-timers: Rework the global hash table and provide a sane mechanism for CRIU Thomas Gleixner
2025-02-24 10:15 ` [patch 01/11] posix-timers: Initialise timer before adding it to the hash table Thomas Gleixner
2025-02-24 10:15 ` [patch 02/11] posix-timers: Add cond_resched() to posix_timer_add() search loop Thomas Gleixner
2025-02-24 10:15 ` [patch 03/11] posix-timers: Cleanup includes Thomas Gleixner
2025-02-24 10:15 ` [patch 04/11] posix-timers: Remove pointless unlock_timer() wrapper Thomas Gleixner
2025-02-24 16:21 ` Peter Zijlstra
2025-02-24 18:43 ` Thomas Gleixner [this message]
2025-02-24 21:55 ` Peter Zijlstra
2025-02-24 10:15 ` [patch 05/11] posix-timers: Rework timer removal Thomas Gleixner
2025-02-24 10:15 ` [patch 06/11] posix-timers: Make signal_struct::next_posix_timer_id an atomic_t Thomas Gleixner
2025-02-24 13:20 ` Peter Zijlstra
2025-02-24 13:34 ` Eric Dumazet
2025-02-24 19:38 ` Thomas Gleixner
2025-02-24 10:15 ` [patch 07/11] posix-timers: Improve hash table performance Thomas Gleixner
2025-02-24 19:45 ` Thomas Gleixner
2025-02-24 10:15 ` [patch 08/11] posix-timers: Make per process list RCU safe Thomas Gleixner
2025-02-24 10:15 ` [patch 09/11] posix-timers: Dont iterate /proc/$PID/timers with sighand::siglock held Thomas Gleixner
2025-02-24 10:15 ` [patch 10/11] posix-timers: Provide a mechanism to allocate a given timer ID Thomas Gleixner
2025-02-24 10:15 ` [patch 11/11] selftests/timers/posix-timers: Add a test for exact allocation mode Thomas Gleixner
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=87seo3fak1.ffs@tglx \
--to=tglx@linutronix.de \
--cc=anna-maria@linutronix.de \
--cc=avagin@openvz.org \
--cc=bsegall@google.com \
--cc=edumazet@google.com \
--cc=frederic@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=ptikhomirov@virtuozzo.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox