Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751199AbdFBOhS (ORCPT ); Fri, 2 Jun 2017 10:37:18 -0400 Received: from mx0a-00010702.pphosted.com ([148.163.156.75]:33736 "EHLO mx0b-00010702.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751128AbdFBOhP (ORCPT ); Fri, 2 Jun 2017 10:37:15 -0400 Authentication-Results: ni.com; dkim=none (message not signed) header.d=none;ni.com; dmarc=none action=none header.from=ni.com; From: Haris Okanovic Subject: Re: [PATCH] Revert "timers: Don't wake ktimersoftd on every tick" To: Thomas Gleixner References: <20170203165151.qbpjothhaqctuzx5@linutronix.de> <20170203182112.18053-1-haris.okanovic@ni.com> <20170210170207.3kzfqyfa4ueh7mih@linutronix.de> <4b4df775-53b8-cdeb-381b-af8cabb364a8@ni.com> Cc: Anna-Maria Gleixner , Sebastian Andrzej Siewior , linux-rt-users@vger.kernel.org, linux-kernel@vger.kernel.org, julia.cartwright@ni.com, gratian.crisan@ni.com Message-ID: Date: Fri, 2 Jun 2017 09:37:04 -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: DM5PR19CA0016.namprd19.prod.outlook.com (10.175.226.154) To CY4PR04MB0694.namprd04.prod.outlook.com (10.172.137.11) X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PR04MB0694: X-MS-Office365-Filtering-Correlation-Id: 6452d9f9-851e-4770-dabe-08d4a9c4d8e0 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001)(201703131423075)(201703031133081);SRVR:CY4PR04MB0694; X-Microsoft-Exchange-Diagnostics: 1;CY4PR04MB0694;3:PX/mRli7ruBi7QRTVhsXjD4ArQQQC/S7M8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;20:lLmS7SwpHYm7M2sCuARX/ABoyO3SKsyPq9yxHNH81t1sVQcdKajaiL/XM4KeKuoiuo4ZF9kIdpDf/SwH0SJ8l81kVLVMHnPmHELfEMxc2ARpTyMU6nFRcvfN+E+ap6HtcAnRjOOI2d7QIF5Fk9wc7LLPVKtoU+58JkAwrTUYGTq+62dI5sX9TaF61uR5oWByn/5XOp/f/sqocqqf+QwYrp3vr4xrAq/zwtIYqvQKRldi1WtzeY62JVTHbrEoegi1d+Y9LeVPaIDHMBSXessOyXpuNHtDE+XYpiNJNIIrJj+ycM3SOmpmEENsBV4N2+i2gobGXPZdLQ3B+Sfn9vJAS+cOX31A3mi3+GNQBzVU2D+ur/aIOwPwPaw1wq1IYTbv0lnl3u7eVfYMajrzD70JjEYcNaII4UW7i1LlMKocHf4vybDOG4NdKNi+vqwm7Z+ibI+8EHuvwCOwz75gowY6uXSZ2X+YwwhqiBcYKtJay43wsoXrggG0stfO1I3eb7Els5Gjk7fOLEz87jKoZZ/JuHB26aMfrdNtgfemWymqZfVjderausx/DElkV+kRYTWmj9z8ElbgoehXhKbiDAUi7uqfMcH8cgjaVszumzxEWRM= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(166708455590820); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(5005006)(8121501046)(100000703101)(100105400095)(10201501046)(3002001)(93006095)(93001095)(6041248)(20161123555025)(20161123562025)(20161123564025)(20161123560025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123558100)(6072148)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:CY4PR04MB0694;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:CY4PR04MB0694; X-Microsoft-Exchange-Diagnostics: =?Windows-1252?Q?1;CY4PR04MB0694;4:uZshqUzUtsGJ+m+X4FzQwRPGi+XrrIu44kGAaG?= =?Windows-1252?Q?N2BRs3eYmxsPngcz6NNZ3ghgUcvNKW5JsrcZVQXvhtdNO7DR/9+2KF1/?= =?Windows-1252?Q?PdpcXx6iWbP8pY06mCMqfZiK9m9pGRXt6j/ApnAZM8HqVOD//Q19yxpi?= =?Windows-1252?Q?Ka351+7mFKyc6GJDY6UjSTcs/Iw6BAAyQWnJ5Eeqq9IoZ0cD6HfuzaXu?= =?Windows-1252?Q?ckGjcWhvbX7+Vz37A9MqneR0tuRp0rikPVArRfUUhD9IiAS4psHXo5tw?= =?Windows-1252?Q?46100GG1Dvh4+SkfJJp6gARmmVEf2O7y9pDeEZ41ATQ2GDu44biktTpf?= =?Windows-1252?Q?Mlj0A1mO0LCKfx+SkxuApDe8dwa0OtiiDXSGEAKevCOII1KSK5U/zaDR?= =?Windows-1252?Q?45ODHoVvOZFjl49aF4MMEq5Bfn7JLX5AG/Fv4zziLHRR4FlVUwIv5lt+?= =?Windows-1252?Q?grUUwcxxOPE0WMQGgHqOaBqUWKJyZkctsAPPztl8koT5iPefl40Wgur0?= =?Windows-1252?Q?/wbqHP5NnJ5mSrSb4nRCmnlOtWaOd/5nCOE0R8MVL6AP0ue7sxXT2YXR?= =?Windows-1252?Q?UdqbzfcTAnTd4XLWka2n1pxiqCGRzqui20gfMHXblIexBdN0WRqqfOxf?= =?Windows-1252?Q?zMKT9+iKFZWNa+to36UnZwcWzZP6MJAMITP2bxwmUv8+yKlsGIxWYnXe?= =?Windows-1252?Q?/mYTWTed73aWM4EbQX2w86WNtv2V2vUM9jaUkNSADwdd+moVIaX2ps+b?= =?Windows-1252?Q?TtPQpCKKMm2DOjqCnDR4r6YX7QOy80zAqnWNMHogT4YNU9Qgj8qNP2tO?= =?Windows-1252?Q?L3X4+e889VEcuE//o5/RQUJqGn2UtW8px3qU2HEcPUAS3BDmcVOzQFEZ?= =?Windows-1252?Q?S4XKK0/vR31+vRdpuo7jGOkx7jH/q5jO27qoLzVNaqAfqWv+xnrJGWh6?= =?Windows-1252?Q?RMxLlUEfqABpEx/+A7qHGYy3OROARkVMr3CZjspt+uZ8sgf3em6T6Sp7?= =?Windows-1252?Q?fHNATahqfuQEahAkndUUi5f5XSNOE7wZxfDrf0DGpUJrKO4Tgvj/zreC?= =?Windows-1252?Q?MGZWDWniFs96HWtTUo3J8D30zagFOlBS2MJ4G919iCtl7WwYit7Z1yqe?= =?Windows-1252?Q?4rFkG7uC9fHDFUG2KQIAyojJ4IxQESJPEnPVqE0BXZDFAmm+0RcvDOeP?= =?Windows-1252?Q?hjdTl1jx3qbqahwqmw0uJGecGEPU3nnXZEEnG2JsUAJEB2fQqFshmmSv?= =?Windows-1252?Q?4WxlVHzH4qIggBQltYV35NkV4NN+jPmSGjN/U=3D?= X-Forefront-PRVS: 03264AEA72 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(4630300001)(6009001)(39400400002)(39840400002)(39410400002)(39450400003)(39850400002)(24454002)(377454003)(8676002)(81166006)(33646002)(50466002)(2906002)(7736002)(305945005)(54356999)(76176999)(50986999)(230700001)(5660300001)(36756003)(3846002)(23746002)(65826007)(6116002)(966005)(42186005)(83506001)(31686004)(478600001)(86362001)(189998001)(53936002)(53546009)(6512007)(54906002)(4001350100001)(4326008)(6506006)(25786009)(31696002)(6486002)(6306002)(47776003)(93886004)(6666003)(38730400002)(2950100002)(6916009)(110136004)(6246003)(66066001)(229853002);DIR:OUT;SFP:1102;SCL:1;SRVR:CY4PR04MB0694;H:harisdt.amer.corp.natinst.com;FPR:;SPF:None;MLV:sfv;LANG:en; X-Microsoft-Exchange-Diagnostics: =?Windows-1252?Q?1;CY4PR04MB0694;23:B2bNLSdkmdEs5M26YkPkt3FkI8A7rktmA3gVr?= =?Windows-1252?Q?YLrwGsEoM+qc9uL+aVfobvVbHMBtsH/bYZ22LtseNqFnQBml+ZsIG2uW?= =?Windows-1252?Q?OuypTcdUBCc05xrnwsyaaB9aGM0K8HamQ+bKfydBhjjWIgdj/uH+hEMd?= =?Windows-1252?Q?5XAN4jijVRdyi8bd/VYmNWQbwng7CriHLDdZ2f2QU9n75ezD3LEPcbmG?= =?Windows-1252?Q?SD7C1Dp5dEL41cmRFpJfcTD8U0u2OSJbGuLi2uLk4OgzcQgwAsFRsr6F?= =?Windows-1252?Q?kSiw+OCx0edmei2EOODwPX9LAExJ51CjltuZFGUK+VRq4Z8+YtnKaaDo?= =?Windows-1252?Q?8udGfYNH/j2WatE7SfQElNT3BfZhTe8XOYedCnrRAKHcYPDpMBD/cZez?= =?Windows-1252?Q?4eypkMG/siqAxu2qmGaloykpIY2IlvIO7pzswpi6HIyulRefouj70C2k?= =?Windows-1252?Q?pkNh+b8HnW/8JvOMbTSipWkPVc6PEX35jFHdiRyJMD0TN9UDuRWI3Hzw?= =?Windows-1252?Q?fiz6pOhAU4JkcAcV26yjYBn8UxmwcQFPI2kYm/XgCxqCeX/JEZgKdOHe?= =?Windows-1252?Q?IUrFSKc+/KgOqRLQYe6d8+EcpvQDhCp3JH7avGKs+j/8ATnxWKnpcxiu?= =?Windows-1252?Q?If0CJ5LY/dX9mQg5ly/LOaiQsnrwFkat629lbE2wipevb1IAecb8KnhW?= =?Windows-1252?Q?R8YsIO+zZXmdfAd8fhLeuIo2pB2kdz+pvVVq8nY/rLZ/lf1dIIVavZ2c?= =?Windows-1252?Q?acelwEsvbP14sOPTKoQoBW/RL/7shh3bTYSe8EhGFdBmi46VGuaTWvue?= =?Windows-1252?Q?cmhVBaVYUOhVjO2dSnF2ZuY8zYCXE8ryi3AcNb0pmin1joqigNLGwrNh?= =?Windows-1252?Q?WC9M9SpwQ0nesiqd0nB/BH0hHmhwjoXVOh/f3TCuEAPT1QsHmdn3aY0T?= =?Windows-1252?Q?PMUjFWRoTJ4naezMhWDr2qhIDv/ijAmzrQSakcM+fej4zSZxpeX8WtjP?= =?Windows-1252?Q?gHHS6X3QVFU/zez1ZoetmteLNPASDn7huVHOQzOWmAUgTqEaCoTYV/K2?= =?Windows-1252?Q?gsiLiaQTxsCx7bNsssYhTj55sd8+zLn0LtlMD46bE5l7lA+rX8g6iRRv?= =?Windows-1252?Q?QtKp03KbBjssjl1FimP2JRwZ4tGkyWeZ40zEZe6hVevnX8zegzogTEQ9?= =?Windows-1252?Q?AsgSTU71nyqNk1EmuwXgB0vwma4pgOGboASu24rfr5UTU6ogVsnHAKeP?= =?Windows-1252?Q?u/Xqqw1239yelH62uVGpInL2pBvulD3cDV4HTCWrNpczEvvBZzqMrgU9?= =?Windows-1252?Q?vXli1S5JyaPh8fUbwSh1CX1ZmB3sHe39/4XU6ioOPQUWN2fSLsSLHfmZ?= =?Windows-1252?Q?Fd+WXaOO9roNJbbl9/V6L22j73Fs7VBw8sqA2B4Izf7Lxc6mSQ3HnY?= =?Windows-1252?Q?=3D?= X-Microsoft-Exchange-Diagnostics: 1;CY4PR04MB0694;6:nGixOuWxChj8b2cFSQyOCUx0Z0vfjZJKW6iw/0dws+lg0L+GxuvvQoTiq2j6QkiPSRVM315dqY8BAOmaS+PSuc1Vb0VDyvuE2tBzBluyzS06nuvtYwADR6AgQcBIbKZuKHC6iZx1g5qFAIZ+Gutu/xQl+e3uok/1UG6IWJuDR5nS8/yaQ6zXAxS+HswyiQ5nCNMJ8uSKOTPkooSDIISKE+47NT8DIs1/e0s+heJVMd/dIF9AExlvZJBmLkAH8aCE5qxBjo0pgJgER86O5tzTt6TlSxsTAgOgFNLa190/NsDylVyU/xipuNTNfaYIiQe1It34/9QOQZfwJjrPjoCyMNDnH80xsTLWMPHokNFFHqErVXB73oyMIdDJRbLt1FftMELncoo8bN25R1mY89jsp3ZtYdAxXOKk596rqka36KwEnnPVnNItRA1hnwMuJIRM/p364UWk53NuYjYYob8N6g0sq82e1epmWsRxkEQz4Xd/QVCQkmeWLpSYxvK26aE/AEpP/C2yR26GGoOk/8molA== X-Microsoft-Exchange-Diagnostics: 1;CY4PR04MB0694;5:Hf0kHUevuEMrFBG4XSNZ9BaCJVnNEFoqu3tNJw8zZyYw/3fjwmdTGo7HiwtdmpaeZTlGsghBL0ESRot1lT8uzcWaSP4DukS5RE41IIIOGlPIRgpNc63r9QlZ7DXnoo/25SjNUe5djX7R36k/d2KGD2CxvIVHkSmDe5xfgjO/3CwUyF36HsznWAWUgLCLT5c/XEQbEZjkSHKHy4ATb/jXSqCDKRpSNwuSDyk2+neNtMuGnxDnhAlk1j6iWMu5WGvlDiY6AEnBvWRbjWRc/gOMMEvkmbsH1qIIjoTBhIs6AhG4t/1eA5RJsgGfN+vJzrzT9i+DxmYTEeukRG3DGJxs74FRgFkcg8/nAY5b8F9PwlaT1kkgEkvk5bbS3gRRFoEA97FqEd1gOkZhsO7budyDBlhDDVTm5jOnAFlZZzY0jQ1wEzeN/Vw2mdZjqKQl5iKVnTexpNV/Px9UASmFh/lHkZ0yQrTtyisuJslV/8c93SK51S3tkHAUVKHsWNEHob0y;24:oEGZ38SxGlsh+PVKvLiR+xwjDVwifMOyJmukQBuKL81TpMr+NMiRXTvVE82quovN9r6Lmz3MS4JdCjhwxdJunZF11MWYuzwFRDaAXWmalRM= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;CY4PR04MB0694;7:cG1bKvIppsyOHujqhUUcXFjdHDk+zdX5Lav5Nd7Fi5UTJZjy8RLDNgo73NPpDkqX79E3TrDr/V00RTfFpRFq+97WTFx5SWlKx8OYxqoiIlfsxLcB0sodxAsXFvk54QJFPgPUMhvbh7R7lqhT3UjzhvbWdecu1l9vz4lipCmT82PMYMqkveEdmfwXOWXa6xF8PTewm6K1UVdwCdqpgQoRS03TwodxpC9Nkk4ytFrMBSTcLSP/BCd05EXhYC5aM0JkjdK+wtHx1BGHzG1x3D491he4KDI+Z+vbApykE73BT/MoNht0u+hgIwpZ5VRsyGXVX1BA5mEPbsNLNyQtK1JgdA== X-OriginatorOrg: ni.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jun 2017 14:37:07.9475 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR04MB0694 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-06-02_08:,, 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-1706020264 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2696 Lines: 83 On 05/26/2017 03:50 PM, Thomas Gleixner wrote: > On Fri, 26 May 2017, Haris Okanovic wrote: > >> Oh crap. I think I see the problem. I decrement expired_count before >> processing the list. Dropping the lock permits another run of >> tick_find_expired()->find_expired_timers() in the middle of __expire_timers() >> since it uses expired_count==0 as a condition. >> >> This should fix it, but I'll wait for Anna-Maria's test next week before >> submitting a patch. >> >>> static void expire_timers(struct timer_base *base) >>> { >>> struct hlist_head *head; >>> + int expCount = base->expired_count; > > No camel case for heavens sake! > > And this requires: > > cnt = READ_ONCE(base->expired_count); > >>> - while (base->expired_count--) { >>> - head = base->expired_lists + base->expired_count; >>> + while (expCount--) { >>> + head = base->expired_lists + expCount; >>> __expire_timers(base, head); >>> } > > Plus a comment. Fixed, thanks. Are your recommending READ_ONCE() purely for documentation purposes? All reads and writes to base->expired_count happen while base->lock is held. It just can't reach zero until expired_lists is ready to be rewritten. > >>> base->expired_count = 0; > > Anna-Maria spotted the same issue, but I voted for the revert right now > because I was worried about the consistency of base->clk under all > circumstances. > > The other thing I noticed was this weird condition which does not do the > look ahead when base->clk is back for some time. The soft interrupt fires unconditionally if base->clk hasn't advanced in some time to limit how long cpu spends in hard interrupt context. > Why don't you use the > existing optimization which uses the bitmap for fast forward? > Are you referring to forward_timer_base()/base->next_expiry? I think it's only updated in the nohz case. Can you share function name/line number(s) if you're thinking of something else. > The other issue I have is that this can race at all. If you raised the > softirq in the look ahead then you should not go into that function until > the softirq has actually completed. There is no point in wasting time in > the hrtimer interrupt if the softirq is running anyway. > Makes sense. Skipping the large `if` block in run_local_timers() when `local_softirq_pending() & TIMER_SOFTIRQ`. > Thanks, > > tglx > > > > I also ran Anna-Maria's test for 12h without failure; I.e. no "Stalled" messages. It fails withing 10-15m on my qemu VM without the fix (4-core Nehalem, 1GB RAM). You can view a diff at https://github.com/harisokanovic/linux/tree/dev/hokanovi/timers-race -- Haris