From: Eric Dumazet <edumazet@google.com>
To: Anna-Maria Behnsen <anna-maria@linutronix.de>,
Frederic Weisbecker <frederic@kernel.org>,
Thomas Gleixner <tglx@linutronix.de>
Cc: linux-kernel <linux-kernel@vger.kernel.org>,
Benjamin Segall <bsegall@google.com>,
Eric Dumazet <eric.dumazet@gmail.com>,
Eric Dumazet <edumazet@google.com>
Subject: [PATCH 1/2] posix-timers: Make next_posix_timer_id an atomic_t
Date: Fri, 14 Feb 2025 13:59:10 +0000 [thread overview]
Message-ID: <20250214135911.2037402-2-edumazet@google.com> (raw)
In-Reply-To: <20250214135911.2037402-1-edumazet@google.com>
Instead of relying on a global and shared hash_lock
to protect sig->next_posix_timer_id, make it atomic.
This allows the following patch to use RCU.
Signed-off-by: Eric Dumazet <edumazet@google.com>
---
include/linux/sched/signal.h | 2 +-
kernel/time/posix-timers.c | 9 +++++----
2 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/include/linux/sched/signal.h b/include/linux/sched/signal.h
index d5d03d919df8..72649d7fce2a 100644
--- a/include/linux/sched/signal.h
+++ b/include/linux/sched/signal.h
@@ -136,7 +136,7 @@ struct signal_struct {
#ifdef CONFIG_POSIX_TIMERS
/* POSIX.1b Interval Timers */
- unsigned int next_posix_timer_id;
+ atomic_t next_posix_timer_id;
struct hlist_head posix_timers;
struct hlist_head ignored_posix_timers;
diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c
index 1b675aee99a9..204a351a2fd3 100644
--- a/kernel/time/posix-timers.c
+++ b/kernel/time/posix-timers.c
@@ -105,13 +105,14 @@ static int posix_timer_add(struct k_itimer *timer)
* a plan to handle the resulting CRIU regression gracefully.
*/
for (cnt = 0; cnt <= INT_MAX; cnt++) {
- spin_lock(&hash_lock);
- id = sig->next_posix_timer_id;
+ id = atomic_inc_return(&sig->next_posix_timer_id) - 1;
- /* Write the next ID back. Clamp it to the positive space */
- sig->next_posix_timer_id = (id + 1) & INT_MAX;
+ /* Clamp id to the positive space */
+ id &= INT_MAX;
head = &posix_timers_hashtable[hash(sig, id)];
+
+ spin_lock(&hash_lock);
if (!__posix_timers_find(head, sig, id)) {
hlist_add_head_rcu(&timer->t_hash, head);
spin_unlock(&hash_lock);
--
2.48.1.601.g30ceb7b040-goog
next prev parent reply other threads:[~2025-02-14 13:59 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-14 13:59 [PATCH 0/2] posix-timers: Reduce spinlock contention Eric Dumazet
2025-02-14 13:59 ` Eric Dumazet [this message]
2025-02-14 13:59 ` [PATCH 2/2] posix-timers: Use RCU in posix_timer_add() Eric Dumazet
2025-02-14 16:59 ` David Laight
2025-02-14 17:48 ` Eric Dumazet
2025-02-17 19:25 ` Thomas Gleixner
2025-02-17 19:24 ` Thomas Gleixner
2025-02-18 14:16 ` 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=20250214135911.2037402-2-edumazet@google.com \
--to=edumazet@google.com \
--cc=anna-maria@linutronix.de \
--cc=bsegall@google.com \
--cc=eric.dumazet@gmail.com \
--cc=frederic@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tglx@linutronix.de \
/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