CINXE.COM

LKML: "tip-bot2 for Eric Dumazet": [tip: timers/core] posix-timers: Make signal_struct:: Next_posix_timer_id an atomic_t

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>LKML: "tip-bot2 for Eric Dumazet": [tip: timers/core] posix-timers: Make signal_struct:: Next_posix_timer_id an atomic_t</title><link href="/css/message.css" rel="stylesheet" type="text/css" /><link href="/css/wrap.css" rel="alternate stylesheet" type="text/css" title="wrap" /><link href="/css/nowrap.css" rel="stylesheet" type="text/css" title="nowrap" /><link href="/favicon.ico" rel="shortcut icon" /><script src="/js/simple-calendar.js" type="text/javascript"></script><script src="/js/styleswitcher.js" type="text/javascript"></script><link rel="alternate" type="application/rss+xml" title="lkml.org : last 100 messages" href="/rss.php" /><link rel="alternate" type="application/rss+xml" title="lkml.org : last messages by &quot;tip-bot2 for Eric Dumazet&quot;" href="/groupie.php?aid=" /><!--Matomo--><script> var _paq = window._paq = window._paq || []; /* tracker methods like "setCustomDimension" should be called before "trackPageView" */ _paq.push(["setDoNotTrack", true]); _paq.push(["disableCookies"]); _paq.push(['trackPageView']); _paq.push(['enableLinkTracking']); (function() { var u="//m.lkml.org/"; _paq.push(['setTrackerUrl', u+'matomo.php']); _paq.push(['setSiteId', '1']); var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s); })(); </script><!--End Matomo Code--></head><body onload="es.jasper.simpleCalendar.init();" itemscope="itemscope" itemtype="http://schema.org/BlogPosting"><table border="0" cellpadding="0" cellspacing="0"><tr><td width="180" align="center"><a href="/"><img style="border:0;width:135px;height:32px" src="/images/toprowlk.gif" alt="lkml.org" /></a></td><td width="32">聽</td><td class="nb"><div><a class="nb" href="/lkml"> [lkml]</a> 聽 <a class="nb" href="/lkml/2025"> [2025]</a> 聽 <a class="nb" href="/lkml/2025/3"> [Mar]</a> 聽 <a class="nb" href="/lkml/2025/3/13"> [13]</a> 聽 <a class="nb" href="/lkml/last100"> [last100]</a> 聽 <a href="/rss.php"><img src="/images/rss-or.gif" border="0" alt="RSS Feed" /></a></div><div>Views: <a href="#" class="nowrap" onclick="setActiveStyleSheet('wrap');return false;">[wrap]</a><a href="#" class="wrap" onclick="setActiveStyleSheet('nowrap');return false;">[no wrap]</a> 聽 <a class="nb" href="/lkml/mheaders/2025/3/13/623" onclick="this.href='/lkml/headers'+'/2025/3/13/623';">[headers]</a>聽 <a href="/lkml/bounce/2025/3/13/623">[forward]</a>聽 </div></td><td width="32">聽</td></tr><tr><td valign="top"><div class="es-jasper-simpleCalendar" baseurl="/lkml/"></div><div class="threadlist">Messages in this thread</div><ul class="threadlist"><li class="root"><a href="/lkml/2025/3/8/426">First message in thread</a></li><li><a href="/lkml/2025/3/8/426">Thomas Gleixner</a><ul><li><a href="/lkml/2025/3/8/427">Thomas Gleixner</a><ul><li><a href="/lkml/2025/3/8/616">Frederic Weisbecker</a></li><li><a href="/lkml/2025/3/13/634">"tip-bot2 for Thomas Gleixner"</a></li></ul></li><li><a href="/lkml/2025/3/8/428">Thomas Gleixner</a><ul><li><a href="/lkml/2025/3/11/914">Frederic Weisbecker</a><ul><li><a href="/lkml/2025/3/11/977">Thomas Gleixner</a></li></ul></li><li><a href="/lkml/2025/3/13/633">"tip-bot2 for Eric Dumazet"</a></li></ul></li><li><a href="/lkml/2025/3/8/430">Thomas Gleixner</a><ul><li><a href="/lkml/2025/3/13/631">"tip-bot2 for Eric Dumazet"</a></li></ul></li><li><a href="/lkml/2025/3/8/431">Thomas Gleixner</a><ul><li><a href="/lkml/2025/3/13/630">"tip-bot2 for Thomas Gleixner"</a></li></ul></li><li><a href="/lkml/2025/3/8/432">Thomas Gleixner</a><ul><li><a href="/lkml/2025/3/13/632">"tip-bot2 for Thomas Gleixner"</a></li></ul></li><li><a href="/lkml/2025/3/8/433">Thomas Gleixner</a><ul><li><a href="/lkml/2025/3/13/629">"tip-bot2 for Thomas Gleixner"</a></li></ul></li><li><a href="/lkml/2025/3/8/434">Thomas Gleixner</a><ul><li><a href="/lkml/2025/3/13/627">"tip-bot2 for Thomas Gleixner"</a></li></ul></li><li><a href="/lkml/2025/3/8/435">Thomas Gleixner</a><ul><li><a href="/lkml/2025/3/13/626">"tip-bot2 for Thomas Gleixner"</a></li></ul></li><li><a href="/lkml/2025/3/8/436">Thomas Gleixner</a><ul><li><a href="/lkml/2025/3/10/13">Frederic Weisbecker</a><ul><li><a href="/lkml/2025/3/10/148">Thomas Gleixner</a></li></ul></li><li><a href="/lkml/2025/3/10/256">Thomas Gleixner</a><ul><li><a href="/lkml/2025/3/13/628">"tip-bot2 for Thomas Gleixner"</a></li></ul></li></ul></li><li><a href="/lkml/2025/3/8/437">Thomas Gleixner</a><ul><li><a href="/lkml/2025/3/10/634">Frederic Weisbecker</a><ul><li><a href="/lkml/2025/3/10/1329">Thomas Gleixner</a><ul><li><a href="/lkml/2025/3/10/1664">Frederic Weisbecker</a></li></ul></li></ul></li><li><a href="/lkml/2025/3/13/625">"tip-bot2 for Peter Zijlstra"</a></li></ul></li><li><a href="/lkml/2025/3/8/438">Thomas Gleixner</a><ul><li><a href="/lkml/2025/3/10/1716">Frederic Weisbecker</a></li><li><a href="/lkml/2025/3/11/927">Frederic Weisbecker</a></li><li class="origin"><a href="">"tip-bot2 for Eric Dumazet"</a></li></ul></li><li><a href="/lkml/2025/3/8/439">Thomas Gleixner</a><ul><li><a href="/lkml/2025/3/11/932">Frederic Weisbecker</a></li><li><a href="/lkml/2025/3/13/624">"tip-bot2 for Thomas Gleixner"</a></li></ul></li><li><a href="/lkml/2025/3/8/440">Thomas Gleixner</a><ul><li><a href="/lkml/2025/3/13/622">"tip-bot2 for Thomas Gleixner"</a></li></ul></li><li><a href="/lkml/2025/3/8/441">Thomas Gleixner</a><ul><li><a href="/lkml/2025/3/11/940">Frederic Weisbecker</a></li><li><a href="/lkml/2025/3/13/621">"tip-bot2 for Thomas Gleixner"</a></li><li><a href="/lkml/2025/3/13/1624">David Laight</a></li><li><a href="/lkml/2025/3/17/208">"Nysal Jan K.A."</a></li></ul></li><li><a href="/lkml/2025/3/8/442">Thomas Gleixner</a><ul><li><a href="/lkml/2025/3/11/1110">Frederic Weisbecker</a></li><li><a href="/lkml/2025/3/13/620">"tip-bot2 for Thomas Gleixner"</a></li></ul></li><li><a href="/lkml/2025/3/8/443">Thomas Gleixner</a><ul><li><a href="/lkml/2025/3/9/14">Cyrill Gorcunov</a></li><li><a href="/lkml/2025/3/11/1103">Frederic Weisbecker</a></li><li><a href="/lkml/2025/3/13/619">"tip-bot2 for Thomas Gleixner"</a></li></ul></li><li><a href="/lkml/2025/3/8/444">Thomas Gleixner</a><ul><li><a href="/lkml/2025/3/9/13">Cyrill Gorcunov</a></li><li><a href="/lkml/2025/3/11/1588">Frederic Weisbecker</a><ul><li><a href="/lkml/2025/3/11/1615">Thomas Gleixner</a><ul><li><a href="/lkml/2025/3/11/1618">Thomas Gleixner</a></li></ul></li><li><a href="/lkml/2025/3/12/649">Cyrill Gorcunov</a></li></ul></li></ul></li><li><a href="/lkml/2025/3/8/445">Thomas Gleixner</a><ul><li><a href="/lkml/2025/3/10/254">Thomas Gleixner</a><ul><li><a href="/lkml/2025/3/11/1599">Frederic Weisbecker</a></li><li><a href="/lkml/2025/3/13/617">"tip-bot2 for Thomas Gleixner"</a></li></ul></li></ul></li></ul></li></ul><div class="threadlist">Patch in this message</div><ul class="threadlist"><li><a href="/lkml/diff/2025/3/13/623/1">Get diff 1</a></li></ul></td><td width="32" rowspan="2" class="c" valign="top"><img src="/images/icornerl.gif" width="32" height="32" alt="/" /></td><td class="c" rowspan="2" valign="top" style="padding-top: 1em"><table><tr><td><table><tr><td class="lp">Date</td><td class="rp" itemprop="datePublished">Thu, 13 Mar 2025 11:31:26 -0000</td></tr><tr><td class="lp">From</td><td class="rp" itemprop="author">"tip-bot2 for Eric Dumazet" &lt;&gt;</td></tr><tr><td class="lp">Subject</td><td class="rp" itemprop="name">[tip: timers/core] posix-timers: Make signal_struct:: Next_posix_timer_id an atomic_t</td></tr></table></td><td></td></tr></table><pre itemprop="articleBody">The following commit has been merged into the timers/core branch of tip:<br /><br />Commit-ID: feb864ee99a2d8a22800342388401f3a3b90d42b<br />Gitweb: <a href="https://git.kernel.org/tip/feb864ee99a2d8a22800342388401f3a3b90d42b">https://git.kernel.org/tip/feb864ee99a2d8a22800342388401f3a3b90d42b</a><br />Author: Eric Dumazet &lt;edumazet&#64;google.com&gt;<br />AuthorDate: Sat, 08 Mar 2025 17:48:36 +01:00<br />Committer: Thomas Gleixner &lt;tglx&#64;linutronix.de&gt;<br />CommitterDate: Thu, 13 Mar 2025 12:07:17 +01:00<br /><br />posix-timers: Make signal_struct:: Next_posix_timer_id an atomic_t<br /><br />The global hash_lock protecting the posix timer hash table can be heavily<br />contended especially when there is an extensive linear search for a timer<br />ID.<br /><br />Timer IDs are handed out by monotonically increasing next_posix_timer_id<br />and then validating that there is no timer with the same ID in the hash<br />table. Both operations happen with the global hash lock held.<br /><br />To reduce the hash lock contention the hash will be reworked to a scaled<br />hash with per bucket locks, which requires to handle the ID counter<br />lockless.<br /><br />Prepare for this by making next_posix_timer_id an atomic_t, which can be<br />used lockless with atomic_inc_return().<br /><br />[ tglx: Adopted from Eric's series, massaged change log and simplified it ]<br /><br />Signed-off-by: Eric Dumazet &lt;edumazet&#64;google.com&gt;<br />Signed-off-by: Thomas Gleixner &lt;tglx&#64;linutronix.de&gt;<br />Reviewed-by: Frederic Weisbecker &lt;frederic&#64;kernel.org&gt;<br />Acked-by: Frederic Weisbecker &lt;frederic&#64;kernel.org&gt;<br />Link: <a href="https://lore.kernel.org/all/20250219125522.2535263-2-edumazet&#64;google.com">https://lore.kernel.org/all/20250219125522.2535263-2-edumazet&#64;google.com</a><br />Link: <a href="https://lore.kernel.org/all/20250308155624.151545978&#64;linutronix.de">https://lore.kernel.org/all/20250308155624.151545978&#64;linutronix.de</a><br /><br /><br />---<br /> include/linux/sched/signal.h | 2 +-<br /> kernel/time/posix-timers.c | 14 +++++---------<br /> 2 files changed, 6 insertions(+), 10 deletions(-)<br /><br />diff --git a/include/linux/sched/signal.h b/include/linux/sched/signal.h<br />index d5d03d9..72649d7 100644<br />--- a/include/linux/sched/signal.h<br />+++ b/include/linux/sched/signal.h<br />&#64;&#64; -136,7 +136,7 &#64;&#64; struct signal_struct {<br /> #ifdef CONFIG_POSIX_TIMERS<br /> <br /> /* POSIX.1b Interval Timers */<br />- unsigned int next_posix_timer_id;<br />+ atomic_t next_posix_timer_id;<br /> struct hlist_head posix_timers;<br /> struct hlist_head ignored_posix_timers;<br /> <br />diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c<br />index 991d12a..f9a70c1 100644<br />--- a/kernel/time/posix-timers.c<br />+++ b/kernel/time/posix-timers.c<br />&#64;&#64; -119,21 +119,17 &#64;&#64; static bool posix_timer_hashed(struct hlist_head *head, struct signal_struct *si<br /> static int posix_timer_add(struct k_itimer *timer)<br /> {<br /> struct signal_struct *sig = current-&gt;signal;<br />- struct hlist_head *head;<br />- unsigned int cnt, id;<br /> <br /> /*<br /> * FIXME: Replace this by a per signal struct xarray once there is<br /> * a plan to handle the resulting CRIU regression gracefully.<br /> */<br />- for (cnt = 0; cnt &lt;= INT_MAX; cnt++) {<br />- spin_lock(&amp;hash_lock);<br />- id = sig-&gt;next_posix_timer_id;<br />-<br />- /* Write the next ID back. Clamp it to the positive space */<br />- sig-&gt;next_posix_timer_id = (id + 1) &amp; INT_MAX;<br />+ for (unsigned int cnt = 0; cnt &lt;= INT_MAX; cnt++) {<br />+ /* Get the next timer ID and clamp it to positive space */<br />+ unsigned int id = atomic_fetch_inc(&amp;sig-&gt;next_posix_timer_id) &amp; INT_MAX;<br />+ struct hlist_head *head = &amp;posix_timers_hashtable[hash(sig, id)];<br /> <br />- head = &amp;posix_timers_hashtable[hash(sig, id)];<br />+ spin_lock(&amp;hash_lock);<br /> if (!posix_timer_hashed(head, sig, id)) {<br /> /*<br /> * Set the timer ID and the signal pointer to make<br /></pre></td><td width="32" rowspan="2" class="c" valign="top"><img src="/images/icornerr.gif" width="32" height="32" alt="\" /></td></tr><tr><td align="right" valign="bottom"> 聽 </td></tr><tr><td align="right" valign="bottom">聽</td><td class="c" valign="bottom" style="padding-bottom: 0px"><img src="/images/bcornerl.gif" width="32" height="32" alt="\" /></td><td class="c">聽</td><td class="c" valign="bottom" style="padding-bottom: 0px"><img src="/images/bcornerr.gif" width="32" height="32" alt="/" /></td></tr><tr><td align="right" valign="top" colspan="2"> 聽 </td><td class="lm">Last update: 2025-03-13 12:33 聽聽 [W:0.383 / U:2.551 seconds]<br />漏2003-2020 <a href="http://blog.jasper.es/"><span itemprop="editor">Jasper Spaans</span></a>|hosted at <a href="https://www.digitalocean.com/?refcode=9a8e99d24cf9">Digital Ocean</a> and my Meterkast|<a href="http://blog.jasper.es/categories.html#lkml-ref">Read the blog</a></td><td>聽</td></tr></table><script language="javascript" src="/js/styleswitcher.js" type="text/javascript"></script></body></html>

Pages: 1 2 3 4 5 6 7 8 9 10