From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S940713AbdEZT2m (ORCPT ); Fri, 26 May 2017 15:28:42 -0400 Received: from mx0b-00010702.pphosted.com ([148.163.158.57]:54642 "EHLO mx0b-00010702.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S944727AbdEZT1s (ORCPT ); Fri, 26 May 2017 15:27:48 -0400 Authentication-Results: ni.com; dkim=none (message not signed) header.d=none;ni.com; dmarc=none action=none header.from=ni.com; Subject: Re: [PATCH] Revert "timers: Don't wake ktimersoftd on every tick" To: Anna-Maria Gleixner References: <20170203165151.qbpjothhaqctuzx5@linutronix.de> <20170203182112.18053-1-haris.okanovic@ni.com> <20170210170207.3kzfqyfa4ueh7mih@linutronix.de> Cc: Sebastian Andrzej Siewior , linux-rt-users@vger.kernel.org, linux-kernel@vger.kernel.org, tglx@linutronix.de, julia.cartwright@ni.com, gratian.crisan@ni.com From: Haris Okanovic Message-ID: Date: Fri, 26 May 2017 14:27:35 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [130.164.62.171] X-ClientProxiedBy: CY4PR12CA0034.namprd12.prod.outlook.com (10.175.82.148) To BN6PR04MB0693.namprd04.prod.outlook.com (10.172.198.14) X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN6PR04MB0693: X-MS-Office365-Filtering-Correlation-Id: 3b2152ec-39fb-466c-7a92-08d4a46d4551 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001)(201703131423075)(201703031133081);SRVR:BN6PR04MB0693; X-Microsoft-Exchange-Diagnostics: 1;BN6PR04MB0693;3:z+r2Q+ZCoFth3FpsNdn/zmb+6g+eJAiJZRR4leIo+RJD2hziun5i7l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kzT6L50BvNuqAQ3331UNKMw7HdU7SwkSsFmDC0c0IES4qaIhsdqHJtLKIB9xJAhDuN5zW9nx+jkzW6VUESOMsw393IWNKCFKRG8a0FKZuc5ePGEijzFkpeSNirTJG2K64pfJ0/QmNc96v6kHlbaTdp/heJ8zO4FxuUk57c9CNxUghw4u7zw4SVQb2t3hrQE+UsHi2cxtPk8bomax+WrAgd0Mt3/luWSxl6DpsJA8TWno3ZLztnZd8vUI7sB2VrTlgB8BHsnKx8A7cLGPVtI52e6tlTElWu9KepA+PS5ykUB3JcTwTI9XSk3Ov3inWi0v+ov003UNKYmeLwjE3jog6Y8hvPiirdXLq7m22bn4gp/9PNJaNcP6nBtgMaUa9luoAEwYlyvRachGBuO7RRdl7feuOrfRSLUHfgAaQO71QmA8hsKE0hXDaj4mRoNcF5h9TpaBfXBaIgLntZEA55HSgGg15BZ5lWnCItCuvLB9ZHMLzgG78NVnK1gQllAi/b/dyYdhROMvzqlCDQ9LxDZETkFlkj0b37M6KUeX2TB7wzxtY3cd5hc31fE3HI+hVg8VkUFOyB6R9QKzlww5KKaJSnI4dGbrVSZ7nxh10= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040450)(601004)(2401047)(5005006)(8121501046)(10201501046)(3002001)(93006095)(93001095)(6041248)(20161123558100)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123560025)(20161123555025)(20161123562025)(20161123564025)(6072148);SRVR:BN6PR04MB0693;BCL:0;PCL:0;RULEID:;SRVR:BN6PR04MB0693; X-Microsoft-Exchange-Diagnostics: 1;BN6PR04MB0693;4:efvkjwdnkNSPe+Np4ywM/a9IVFWhZr6QGGnKQrD8u3ZY6xqg4C2UEKr3W7cVgrAQ2MO3Sb7Uk5woBlFFMBPBtOg80rgvhzf1n0xVGYG89RKgjHadCoyCMhiniAaBoG9R7/Y6/UqUFbGHJfHbszYqBWMNumRZ/daRxxCmZO4vlKFfqRcurMyi7qnkxkkY5CPOQZ7HifkV+Tx+c1Iz6n+rO1TZkohmmoeOyGGybDYJpr9TZBBq0Kv1dFe8Mx1GQ8YWxFd99pHO9FYQdRTIOn8yNiKQ7oOzsS7rvQnlL9ofloszOIcON+mMRbsHHMXDVU6TbUOS3gpMtuzbAbFpPQLlpqMss5rSrHmJ9WNoP/ay0YhIVdgaPDaQiMPXAPN+QG6dQsMzD2itruWVhyFCwqrgnkusfai7uQtbq0yzfQIsADjlLIVw50/au5ZEI/tbC+Wefn2S2+GxvsxkuEf/jpZLj6h2V0pytWuZaSclrZHf/QOvC7tuzjqqGXi9PBkbVJbcMVnE7o/Uu5WWYJr1maSJGF91TkGhMIzjpDIgvkzdwBUIAXDJjc/Kib9dckeqwAWlOkDr03nXocp76GTkOS1cF3ML7gCV4aTleVNyWOtnSHIQNr3o4oKar+wyBRcDm7H0rGP664U5WO4+Tny1Ow0ylwfjK7ybkXUA0cDk0pfSwjfgrmEbIlY6pxcGN9dVnwGM7PrlBE1yJIEtggu+cIGSX3HgzGVDYMrERjZpPLEuUPhmmBWaJ/3NrO+UCH+/QW9xe4yxJtVcXiAHw+D9jDc2SoiWJlHatHRJRYosGsp9nf0= X-Forefront-PRVS: 031996B7EF X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(4630300001)(6009001)(39850400002)(39400400002)(39410400002)(39840400002)(39450400003)(377454003)(24454002)(2906002)(93886004)(305945005)(6512007)(66066001)(53936002)(189998001)(36756003)(7736002)(47776003)(5660300001)(6486002)(6506006)(50986999)(64126003)(25786009)(76176999)(54356999)(53546009)(50466002)(42186005)(31686004)(23746002)(33646002)(6916009)(2950100002)(31696002)(229853002)(8676002)(230700001)(110136004)(3846002)(6116002)(81166006)(478600001)(4326008)(38730400002)(86362001)(6246003);DIR:OUT;SFP:1102;SCL:1;SRVR:BN6PR04MB0693;H:harisdt.amer.corp.natinst.com;FPR:;SPF:None;MLV:sfv;LANG:en; X-Microsoft-Exchange-Diagnostics: =?Windows-1252?Q?1;BN6PR04MB0693;23:ajiGRcnRdEsK1ygkSvzGYSlf1SlW+kaPDUwZs?= =?Windows-1252?Q?0dIcW0y8F7RV+GeDI8I/HpHPIfepqt3HAjb4QIXgk6x2DvdD4khZRRA4?= =?Windows-1252?Q?xF5r8SH4bynNEzF3c0FW28gMyVwXkg22FjXvx3VhHxvAkye11jfvH83Z?= =?Windows-1252?Q?7SKY2d1jfwBulJfNpvCPIt3B34kcMwrBvGz0NJxM6Gyul6fUd2eLd2Cw?= =?Windows-1252?Q?jBvjOHn7gwoCQVjFWcDT+HWbyI54OrQn3k49lz28gKg/BZqWp9hwD6El?= =?Windows-1252?Q?u+0OC1jQHQ36/tFSpkn+k7aW7d/bx5SHOPXXLvPjf8G4lXn/tyNVSrGw?= =?Windows-1252?Q?KWWNcMYe04vJrMtXHHn3PrbHbRikmSBMH7VFVCYMQCzUtU0c34Vm5R5z?= =?Windows-1252?Q?H4gklVzEGBcLJq3Z+7Okwx3yNgIHmqdOo148FuxTGpEV+dD2kkPhnJp6?= =?Windows-1252?Q?hYn022uM0dyLkTu63nvLgu8rYEcPhjLDeybFLG+S8jJnvKe4hBCUNCK8?= =?Windows-1252?Q?IF7/yvgyaMIhWRSj8pGCr1NKh8fL9+SaX9fwPabycvJAm/zkDQS7Kkrz?= =?Windows-1252?Q?nX1Kme4gCS9LfAKN1iPcPUYTGI/a/ig2ZHCB83kLDh4h47PADYhMFHe2?= =?Windows-1252?Q?CYCi/5N9oHsZ/dblZHu8o3M2M8D7/85Uxwpuj/hxHkG5u2RVZl1e7hbv?= =?Windows-1252?Q?KJoGn4uSV+rDevIFntZyJMQgUrIIeeAf/9kxOFZMxrfs40f13nZlXjE7?= =?Windows-1252?Q?wCu5QBnhhQEO862MdwWsp32AS07+WDwO2ONnhdF7xw5AT1ERn58qCqQf?= =?Windows-1252?Q?lxwFcHgKuICsyp/IaJFnM0MHZxTy7waS4eAgDgB95CLwB1VT/8TWp8HK?= =?Windows-1252?Q?GgT/uXAwfqenvc9NdCxUB92YHVGq0UkqXBmrJ+r40ZrlIO0NFmHdVQOc?= =?Windows-1252?Q?PMBMaQQOX2VElS771k5cbHhcBr2xPRsUb+vthn5ix4pPRwSf+xVG07L8?= =?Windows-1252?Q?IPvfzpN2e2yHGGCQsq2G1czVsCBmO1R72crcsjVuXzRE06QpvlTnthJQ?= =?Windows-1252?Q?tk8DCcu+vTpOqpkusSWVC9WPjnYtCCBtQzr8qtlWrL6xlJb3z0EzpHq1?= =?Windows-1252?Q?wnN/NAxync9cpnpRLVeVohnwNwLynOE5sgaBQgvx4n9RKipTApt6qGCE?= =?Windows-1252?Q?wLaZGUTmHNldxICzmzk1an/3ze40XWGILmJEHoZ8/tR8Ve1i9kE+0Kn1?= =?Windows-1252?Q?aYcJK5NPUOEgAZxw8Agoey1qt10eqbBxD+58/8=3D?= X-Microsoft-Exchange-Diagnostics: 1;BN6PR04MB0693;6:eag1EjX+xmZ50hO94Ej2k/QIbQpLt1NhS3oDub5YIJCKQVtmQo3iYUZCst37LVDFDwU6SM75RZEjyEePj9RBY9l9CEBY4m80LlVH82GT4x8ueaRXJ5Ua2YY9mdMBYZxWlvbnlcRYX6CPuZXr5ZBF1ghy0mawW7FhNK4pE2nRspRMQvibxiJL58a56k7+qo4Usqew+/ID0bW0jPorHK50z4848sQQ1eQaDBMWDRldX91yFGZ4LaA8aoiJAfl9iunEyZ5vCvPzRQXIE+Pce5yPP/fqeLlnPHTnP2Qw3crxAkDPGVOdV31b+d/8Va7CQzVQ4X+Fl2yJ0WOS9BjHsHw9yAoiSnY7ui9gZ9xqkhenKqSYlSgBRpr3IlhQdP+eQq+XRVjgejX3UWVSVBqfwxNFFggy0D3SiKNhYzdUYK7aIWH8WuLt1awvxDq++If3a+4oAV0P6GSiDy+DuS/V+uAommYv6UbXBH55dx5jpAIK4hw12PUHsdMherrFR3YOK9CwLGpRTRPiB2f/i8Kdru04bQ==;5:Hpki/yA0XXPnESPYDAbB6YFjhTWiN78BIAYnXAJlMzn1KvJ5MXHS7Flvo3Bl+Cxo1OndmM4QDCaE6dOwLqi8hdzkWUbF6pugiT1oMRCDyVzxAOoJVigKmkVHZSVDnLi1eVu0cCZaREGqx6dW174BIe3zn2YEfq22kWqoGPDngtA=;24:SDHCWgg/x9GJZaB3L5yklFuuSox2z92QNSY6krgzGekxfEZxGu8mak2NmhIPJ/eIJFA4pw1wz0mfLF1en4/eMUfnO19iA3nU5iTSfAUZKz8= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;BN6PR04MB0693;7:ovw9sKffbfYkAeUSun3NFkp2+uBF6sea+YETItQRehwGV/Rxiusc2QzysOc50RIev7sXkLF63CMgDon7J6w+y0zn140RgzyPkQHRVDW6961xlQoCjZ36sYY3fX7Xm6qeQ/ypi/IhPAmLmJP0zvt/JlRnlPFbYO0izYQOYGXMjOE19Xi775tdyd6ncp8igPGRAtKh+eapudicB3Zugc1Uxyny7Jbb0wT+957/J88+ryRfUBTxSGnFJXB/QT5u5gX0gX52Jyg9KWhxR5UUOz63EcyA7oXkdIM9rGbNAwo6ZHbso6nMXwfmnus+UWpOUreUOkRNuUNLI8Utp7EYdnflYw== X-OriginatorOrg: ni.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 May 2017 19:27:37.9785 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR04MB0693 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-05-26_13:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_policy_notspam policy=outbound_policy score=30 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=30 reason=mlx scancount=1 engine=8.0.1-1703280000 definitions=main-1705260347 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Anna-Maria, Look-ahead is implemented by tick_find_expired() and expiry by __run_timers(), both of which hold timer_base::lock (raw spin lock) while running. Those two routines shouldn't be able to run simultaneously on the same timer_base. Are you sure the race isn't in another code path? Do you have a test which demonstrates this? I'd like to investigate. Your .config file would also be useful. I'm looking at v4.9.27-rt17 source. Thanks, Haris On 05/26/2017 12:16 PM, Anna-Maria Gleixner wrote: > This reverts commit 032f93cae150a. > > The problem is that the look ahead optimization from the tick timer > interrupt context can race with the softirq thread expiring timer. As > a consequence the temporary hlist heads which hold the to expire > timers are overwritten and the timers which are already removed from > the wheel bucket for expiry are now dangling w/o a list head. > > That means those timers never get expired. If one of those timers is > canceled the removal operation will result in a hlist corruption. > > Signed-off-by: Anna-Maria Gleixner > --- > kernel/time/timer.c | 96 ++++++++++++++++------------------------------------- > 1 file changed, 29 insertions(+), 67 deletions(-) > > diff --git a/kernel/time/timer.c b/kernel/time/timer.c > index cdff4411f8f6..08a5ab762495 100644 > --- a/kernel/time/timer.c > +++ b/kernel/time/timer.c > @@ -206,8 +206,6 @@ struct timer_base { > bool is_idle; > DECLARE_BITMAP(pending_map, WHEEL_SIZE); > struct hlist_head vectors[WHEEL_SIZE]; > - struct hlist_head expired_lists[LVL_DEPTH]; > - int expired_count; > } ____cacheline_aligned; > > static DEFINE_PER_CPU(struct timer_base, timer_bases[NR_BASES]); > @@ -1355,8 +1353,7 @@ static void call_timer_fn(struct timer_list *timer, void (*fn)(unsigned long), > } > } > > -static inline void __expire_timers(struct timer_base *base, > - struct hlist_head *head) > +static void expire_timers(struct timer_base *base, struct hlist_head *head) > { > while (!hlist_empty(head)) { > struct timer_list *timer; > @@ -1387,38 +1384,21 @@ static inline void __expire_timers(struct timer_base *base, > } > } > > -static void expire_timers(struct timer_base *base) > -{ > - struct hlist_head *head; > - > - while (base->expired_count--) { > - head = base->expired_lists + base->expired_count; > - __expire_timers(base, head); > - } > - base->expired_count = 0; > -} > - > -static void __collect_expired_timers(struct timer_base *base) > +static int __collect_expired_timers(struct timer_base *base, > + struct hlist_head *heads) > { > unsigned long clk = base->clk; > struct hlist_head *vec; > - int i; > + int i, levels = 0; > unsigned int idx; > > - /* > - * expire_timers() must be called at least once before we can > - * collect more timers > - */ > - if (WARN_ON(base->expired_count)) > - return; > - > for (i = 0; i < LVL_DEPTH; i++) { > idx = (clk & LVL_MASK) + i * LVL_SIZE; > > if (__test_and_clear_bit(idx, base->pending_map)) { > vec = base->vectors + idx; > - hlist_move_list(vec, > - &base->expired_lists[base->expired_count++]); > + hlist_move_list(vec, heads++); > + levels++; > } > /* Is it time to look at the next level? */ > if (clk & LVL_CLK_MASK) > @@ -1426,6 +1406,7 @@ static void __collect_expired_timers(struct timer_base *base) > /* Shift clock for the next level granularity */ > clk >>= LVL_CLK_SHIFT; > } > + return levels; > } > > #ifdef CONFIG_NO_HZ_COMMON > @@ -1618,7 +1599,8 @@ void timer_clear_idle(void) > base->is_idle = false; > } > > -static void collect_expired_timers(struct timer_base *base) > +static int collect_expired_timers(struct timer_base *base, > + struct hlist_head *heads) > { > /* > * NOHZ optimization. After a long idle sleep we need to forward the > @@ -1635,49 +1617,20 @@ static void collect_expired_timers(struct timer_base *base) > if (time_after(next, jiffies)) { > /* The call site will increment clock! */ > base->clk = jiffies - 1; > - return; > + return 0; > } > base->clk = next; > } > - __collect_expired_timers(base); > + return __collect_expired_timers(base, heads); > } > #else > -static inline void collect_expired_timers(struct timer_base *base) > +static inline int collect_expired_timers(struct timer_base *base, > + struct hlist_head *heads) > { > - __collect_expired_timers(base); > + return __collect_expired_timers(base, heads); > } > #endif > > -static int find_expired_timers(struct timer_base *base) > -{ > - const unsigned long int end_clk = jiffies; > - > - while (!base->expired_count && time_after_eq(end_clk, base->clk)) { > - collect_expired_timers(base); > - base->clk++; > - } > - > - return base->expired_count; > -} > - > -/* Called from CPU tick routine to quickly collect expired timers */ > -static int tick_find_expired(struct timer_base *base) > -{ > - int count; > - > - raw_spin_lock(&base->lock); > - > - if (unlikely(time_after(jiffies, base->clk + HZ))) { > - /* defer to ktimersoftd; don't spend too long in irq context */ > - count = -1; > - } else > - count = find_expired_timers(base); > - > - raw_spin_unlock(&base->lock); > - > - return count; > -} > - > /* > * Called from the timer interrupt handler to charge one tick to the current > * process. user_tick is 1 if the tick is user time, 0 for system. > @@ -1704,11 +1657,22 @@ void update_process_times(int user_tick) > */ > static inline void __run_timers(struct timer_base *base) > { > + struct hlist_head heads[LVL_DEPTH]; > + int levels; > + > + if (!time_after_eq(jiffies, base->clk)) > + return; > + > raw_spin_lock_irq(&base->lock); > > - while (find_expired_timers(base)) > - expire_timers(base); > + while (time_after_eq(jiffies, base->clk)) { > + > + levels = collect_expired_timers(base, heads); > + base->clk++; > > + while (levels--) > + expire_timers(base, heads + levels); > + } > raw_spin_unlock_irq(&base->lock); > wakeup_timer_waiters(base); > } > @@ -1736,12 +1700,12 @@ void run_local_timers(void) > > hrtimer_run_queues(); > /* Raise the softirq only if required. */ > - if (time_before(jiffies, base->clk) || !tick_find_expired(base)) { > + if (time_before(jiffies, base->clk)) { > if (!IS_ENABLED(CONFIG_NO_HZ_COMMON) || !base->nohz_active) > return; > /* CPU is awake, so check the deferrable base. */ > base++; > - if (time_before(jiffies, base->clk) || !tick_find_expired(base)) > + if (time_before(jiffies, base->clk)) > return; > } > raise_softirq(TIMER_SOFTIRQ); > @@ -1911,7 +1875,6 @@ int timers_dead_cpu(unsigned int cpu) > raw_spin_lock_nested(&old_base->lock, SINGLE_DEPTH_NESTING); > > BUG_ON(old_base->running_timer); > - BUG_ON(old_base->expired_count); > > for (i = 0; i < WHEEL_SIZE; i++) > migrate_timer_list(new_base, old_base->vectors + i); > @@ -1938,7 +1901,6 @@ static void __init init_timer_cpu(int cpu) > #ifdef CONFIG_PREEMPT_RT_FULL > init_swait_queue_head(&base->wait_for_running_timer); > #endif > - base->expired_count = 0; > } > } > >