Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752710AbeAETiC (ORCPT + 1 other); Fri, 5 Jan 2018 14:38:02 -0500 Received: from mx0a-00010702.pphosted.com ([148.163.156.75]:38464 "EHLO mx0b-00010702.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752166AbeAETh7 (ORCPT ); Fri, 5 Jan 2018 14:37:59 -0500 Subject: Re: [PATCH v3 2/2] timers: Don't search for expired timers while TIMER_SOFTIRQ is scheduled To: linux-rt-users@vger.kernel.org, linux-kernel@vger.kernel.org, bigeasy@linutronix.de, tglx@linutronix.de Cc: harisokn@gmail.com, julia.cartwright@ni.com, gratian.crisan@ni.com, anna-maria@linutronix.de References: <20170803210657.19179-1-haris.okanovic@ni.com> <20170803210657.19179-2-haris.okanovic@ni.com> From: Haris Okanovic Message-ID: <28f05e39-6bc6-99c5-e1bc-91be3e79ea78@ni.com> Date: Fri, 5 Jan 2018 13:37:45 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 MIME-Version: 1.0 In-Reply-To: <20170803210657.19179-2-haris.okanovic@ni.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [130.164.62.150] X-ClientProxiedBy: CY4PR03CA0090.namprd03.prod.outlook.com (2603:10b6:910:4d::31) To SN4PR0401MB3631.namprd04.prod.outlook.com (2603:10b6:803:47::16) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ea6bdb01-6d43-479a-6fa7-08d55473cd73 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(5600026)(4604075)(2017052603307)(7153060);SRVR:SN4PR0401MB3631; X-Microsoft-Exchange-Diagnostics: 1;SN4PR0401MB3631;3:GbQ1WPopeDFbZxYO3L7rwMQCtPNl+9ozsw11yuUBhSjKhc4GxVs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vpNlcintW2jFLYICv3Q2QnOEBssszUK0kDTfcCJmfmgb+8LD++T76U7aksT+oGlNtDaGqdcZkcfGUne/u9R4fiqWPjcpnaz88FNWGDXtbpeBzUqrLOYz2kBahvV2C+D43Iw1CBjzjWeZBQO96GwSNRmmEr9XbJKWRcPAME2VJLt/mzZObPU/qSdgbyK8kXpBghwYojCyBr9AlIv8y6zeZf+meuPWFjDfn4M5Dx2DtgMQ5gnEMoWKACbGFgeG8uzBAwrWpoa4tqIYu/COmdR7powTjpC9zXkvgQCmPLZvw24KA0C0H1fpRkW9KMKv1PbRhEqu8o+vsGLxez+lCQnApf4VL7caELXxtuIhfrSdNDp4uMj0ZJeboQCbuB+by0eX5qf9M15uJCDRSbwp7WI26RkDMo8z6oiHg= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(166708455590820)(145744241990776); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040470)(2401047)(8121501046)(5005006)(3231023)(944501075)(3002001)(10201501046)(93006095)(93001095)(6041268)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123564045)(20161123558120)(6072148)(201708071742011);SRVR:SN4PR0401MB3631;BCL:0;PCL:0;RULEID:(100000803101)(100110400095);SRVR:SN4PR0401MB3631; X-Microsoft-Exchange-Diagnostics: 1;SN4PR0401MB3631;4:1HS3gUHdkG/IqqqJBiMMtpJvYFaZ8elDnaUuouZ3c7//ArMKfVG/M5nDeV5vjCIG2tKsGnCb0O41JEmQ1o3h0ZiU2f4G5mHRx+rV8ea3ysllrb0p5GVPDbtPkbudPB37T1S7Y7XRgZ+W49h+LvS8AtN08pJOOCLTzfftlN05PZ6VZRhVJVFvhMmHGgCZ3fu5A+fF0kF1voVoiX6ZrXOi0AIapPkcm3uJpRO4hBHPJ4Xht5wIsiJ/nvSHWuBMCbyhPBEuNR24wBDA0kQ/mU7x+3Tl6P2LPULYunBF0bjxh9bZWhxxr7KigfgzoSyoBz9qX5w10ZBQu0iiYiFrrMPXF+KY7hKhGZ6JUxihAcJrduk= X-Forefront-PRVS: 05437568AA X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(396003)(366004)(39380400002)(39860400002)(376002)(346002)(189003)(199004)(24454002)(6512007)(6246003)(39060400002)(105586002)(53936002)(65956001)(16526018)(3846002)(6116002)(31686004)(106356001)(66066001)(4326008)(6306002)(47776003)(316002)(58126008)(31696002)(25786009)(575784001)(5660300001)(305945005)(7736002)(86362001)(83506002)(2950100002)(97736004)(478600001)(53546011)(65826007)(966005)(36756003)(2486003)(6666003)(6486002)(52116002)(67846002)(50466002)(52146003)(229853002)(59450400001)(76176011)(8676002)(386003)(2906002)(64126003)(8936002)(6506007)(68736007)(23676004)(81156014)(230700001)(81166006)(65806001);DIR:OUT;SFP:1102;SCL:1;SRVR:SN4PR0401MB3631;H:harisdt.amer.corp.natinst.com;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtTTjRQUjA0MDFNQjM2MzE7MjM6WG1sTWJJN0NycGJyTDFZc1hTbmZ0c093?= =?utf-8?B?QnRsV1VWTllqNXBKOWFHNjZ2SkZ2SkhZVHpqMDlmY2c1RWh1RXZHOGFROG51?= =?utf-8?B?UnhqYnFyWFRKZ2tWVk4ybmpJYll1aGNLRU05VjhueWRZYm1NTm4wRnp6SVo4?= =?utf-8?B?U0dvUGMrbFZXdm15QnUyNmI2aTVVc0ZYeXZBUktVZTZuNEJDYnRuYlhzeWVN?= =?utf-8?B?WWRWdXVYalRWYk8xdVZoOTdQT3dJMzBnNnRjckNuSHhKc0UyZXdROGVEK1NW?= =?utf-8?B?NTVRRmt0dGk2bEhPR2xHT21helQ4TlpkaWU5VmNGY0hDUzU1Sll1TVNLMUtJ?= =?utf-8?B?R0xEUW9heGtMSnFMcXFxdnl2Y216ZGJlKzZROWl5blZPT2J1UzdTbWx0TXF4?= =?utf-8?B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Hkbpu47wC1g1s73gA/jx9O8Ckg0P2zQSItmJ/mEdHYqqmvDW/rUdNa4vDvWbxiTr5xtBP/aTawWfM9IoA8j6OlivOABFZdP/k=;5:sPwmbFCCfcsbEzA8rB+ONelc1OVX/qGllHr6z8BEqxfWw4Qm6IqfvroPPunBT52wlXIeNFB7CoO5hfs6Q3nS2qMhSdHKB2oazrucHeq/qrs29apWpxY4gpQMywfcIZVQJCk4tuPNmxinecKSIamObUjmquQyUuHbrNko1GxURr0=;24:ZZMdA+jLL5VkHmDjq4Xa2QTTRyrdq14DRyWb+PfdPCswfSr/5UZSA8LN++IWChITB9yXAftZSVtmifSBR5OiE3vQkcpAEQ2rIodHV+Xp68U=;7:EvfDEkc/HafLHBLQGpe436lo27k4/HYczNTMEZcemXiq9wHu50TfgojG8H907Mcu9FCFhMLXz487ektZc1hD5FtYRdipmez/VHbbS0p1qnDL8VcXSalmfGzuFEufOe8XyHymZlSbtDksdc/4O3vNeTJZKMNxX7KSiHnr7Wd0w0FnUVaSzZYo6Vkpy4LBjOZSteKWiD2x4j1jha/cvG6H4XMYofKso1XF8yC1dt44OFp38G41dUS/trraIIqV+2Ns SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: ni.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Jan 2018 19:37:48.2034 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ea6bdb01-6d43-479a-6fa7-08d55473cd73 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 87ba1f9a-44cd-43a6-b008-6fdb45a5204e X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN4PR0401MB3631 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2018-01-05_09:,, signatures=0 X-Proofpoint-Spam-Details: rule=inbound_policy_notspam policy=inbound_policy score=30 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=30 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1801050271 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: It looks like an old version of this patch is included in v4.9*-rt* kernels -- E.g. commit 032f93ca in v4.9.68-rt60. There's nothing functionally wrong with the included version to the best of my knowledge. However, I posted a newer V3 [1][2] based on Thomas' feedback that's substantially cleaner and likely more efficient (haven't measured yet). I think we should include the latter version instead, if only for the cosmetic benefits. Thoughts? [1] https://patchwork.kernel.org/patch/9879825/ [PATCH v3,1/2] [2] https://patchwork.kernel.org/patch/9879827/ [PATCH v3,2/2] -- Haris On 08/03/2017 04:06 PM, Haris Okanovic wrote: > This change avoid needlessly searching for more timers in > run_local_timers() (hard interrupt context) when they can't fire. > For example, when ktimersoftd/run_timer_softirq() is scheduled but > preempted due to cpu contention. When it runs, run_timer_softirq() will > discover newly expired timers up to current jiffies in addition to > firing previously expired timers. > > However, this change also adds an edge case where non-hrtimer firing > is sometimes delayed by an additional tick. This is acceptable since we > don't make latency guarantees for non-hrtimers and would prefer to > minimize hard interrupt time instead. > > Signed-off-by: Haris Okanovic > --- > [PATCH v3] > - Split block_softirq into separate commit > > https://github.com/harisokanovic/linux/tree/dev/hokanovi/timer-peek-v5 > --- > kernel/time/timer.c | 21 +++++++++++++++++++-- > 1 file changed, 19 insertions(+), 2 deletions(-) > > diff --git a/kernel/time/timer.c b/kernel/time/timer.c > index 078027d8a866..f0ef9675abdf 100644 > --- a/kernel/time/timer.c > +++ b/kernel/time/timer.c > @@ -208,6 +208,7 @@ struct timer_base { > bool migration_enabled; > bool nohz_active; > bool is_idle; > + bool block_softirq; > DECLARE_BITMAP(pending_map, WHEEL_SIZE); > struct hlist_head vectors[WHEEL_SIZE]; > struct hlist_head expired_lists[LVL_DEPTH]; > @@ -1376,9 +1377,11 @@ static int __collect_expired_timers(struct timer_base *base) > > /* > * expire_timers() must be called at least once before we can > - * collect more timers. > + * collect more timers. We should never hit this case unless > + * TIMER_SOFTIRQ got raised without expired timers. > */ > - if (base->expired_levels) > + if (WARN_ONCE(base->expired_levels, > + "Must expire collected timers before collecting more")) > return base->expired_levels; > > clk = base->clk; > @@ -1702,6 +1705,9 @@ static __latent_entropy void run_timer_softirq(struct softirq_action *h) > __run_timers(base); > if (IS_ENABLED(CONFIG_NO_HZ_COMMON) && base->nohz_active) > __run_timers(this_cpu_ptr(&timer_bases[BASE_DEF])); > + > + /* Allow new TIMER_SOFTIRQs to get scheduled by run_local_timers() */ > + base->block_softirq = false; > } > > /* > @@ -1712,6 +1718,14 @@ void run_local_timers(void) > struct timer_base *base = this_cpu_ptr(&timer_bases[BASE_STD]); > > hrtimer_run_queues(); > + > + /* > + * Skip if TIMER_SOFTIRQ is already running on this CPU, since it > + * will find and expire all timers up to current jiffies. > + */ > + if (base->block_softirq) > + return; > + > /* Raise the softirq only if required. */ > if (time_before(jiffies, base->clk) || !tick_find_expired(base)) { > if (!IS_ENABLED(CONFIG_NO_HZ_COMMON) || !base->nohz_active) > @@ -1720,7 +1734,10 @@ void run_local_timers(void) > base++; > if (time_before(jiffies, base->clk) || !tick_find_expired(base)) > return; > + base--; > } > + > + base->block_softirq = true; > raise_softirq(TIMER_SOFTIRQ); > } > >