Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp338304imm; Mon, 2 Jul 2018 12:26:58 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfpWNC/r9snr4Lq6/hG5C/DelOIzWjFZV4hQZLmbakeqMMmz2cUlbBBwu3JnpRrbwmeS0R1 X-Received: by 2002:a62:4015:: with SMTP id n21-v6mr26610755pfa.198.1530559618385; Mon, 02 Jul 2018 12:26:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530559618; cv=none; d=google.com; s=arc-20160816; b=RMPJGhH6gEcvVYwKcX7IrcGicbIqDUZA/BE3unX97bP/iDjLXTGdtFLhUt4p3aCgbV DL/X2WfVsdOnKdq7DQvb1FVwO9S0dffIPMsxYQVJCkq2B4EKOnjaZbqaESVJWXRzyrYm fFeEp5ZjPIRY8DWRB/wkDqz0VlMKSv28sVcCt6VFUjqKFEZAan1rShEO5vKarhq13z8y B7cWg0kYMT+oEfj2J0t/4cMn2JsQPj7vxqxMWbUghgytOQ3+R356xI+nTusq6l5Avrc4 Dja18cRzHh4zIAJ/HqiOf6yKaXBrxBZiH+bDNf1t30HoZ1qiuSN8I9iEZJGKBgJngFtv 2glA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=tUnif5yH6Usb3sc0P6gTSL8F/AZ4ZoABmyDKr/7WYc8=; b=r9S9yMUXzWZy/1t5o9N5jntZpdrjX0AOr4ZpFhv/XokWMl37V2cCOaAsPo1Mu/2m4w zA6vuZs2fiqu5ny+VVdVm3koHkBfgX/JzvBAoar8ltU+qRbnHWpBiZFQ55NP3napOedM vpBWMNLKlCUbBxDo2+k2/HKFagU+wU+8h3Cm99zbQ3qMT7yM2RVNAZp6RQo399YWUBTB rNtXHrqp1RwSSJIjjSWFM12ZSOFwmtdNVO25rFKPvS9R9lL6psMQVhHUU39UMIK+khSB o/SgP1H1JXPQzY4UDYy9dYsg6wXmHeQSThQvXWOfooeiHqq2+aVm9iRTQ2ZaWOCOAwQ+ 97OA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HjTNHbTs; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v4-v6si13660349pgc.450.2018.07.02.12.26.43; Mon, 02 Jul 2018 12:26:58 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HjTNHbTs; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752839AbeGBTZb (ORCPT + 99 others); Mon, 2 Jul 2018 15:25:31 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:39556 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752292AbeGBTZ3 (ORCPT ); Mon, 2 Jul 2018 15:25:29 -0400 Received: by mail-wm0-f66.google.com with SMTP id p11-v6so9760171wmc.4 for ; Mon, 02 Jul 2018 12:25:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=tUnif5yH6Usb3sc0P6gTSL8F/AZ4ZoABmyDKr/7WYc8=; b=HjTNHbTsm8MB6PPpujVezpqEGLnRv2xLonbZ9GJ+8uJPd5wXgp7jsCufUnoYTTcLgG fY5CfmMi7iAXha6zFpV+++ny7vNsabr6LMxgQU1/HEau8vdJxKgkxOHq7y/24tfmUgFu iV4UL19clBXdZzRZTjjdo2XutuLE9OIDAkFBk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=tUnif5yH6Usb3sc0P6gTSL8F/AZ4ZoABmyDKr/7WYc8=; b=JsNlnAncCX4b8AzVsSmZzGHcebcQE8mjTwMmHEK0q/j66Lt3MrLVD8k84nRgD37YIs VZ+d+TRl+PIgQCHmnRl/xiUypfK0s8IW4W9cOn1wZOxZ57Z7EFboW5b1QvAiMBZ/7+tw 8ZM5dQqNerM9a2uNi3IXiN/1gVYuvxEr9EAP9wOxhpYBc5Dv1SI3I63PJLEYh5aC+bMq 5IwlOGKW2JKLTENEVUxGe8KTyQkw5E1KMv898zSzliqdBKLZ8jjPJGe8oVCutP9ItJT1 nfpELq9TWoypFALrCb7INZyc84pjUettFcAbEzi3i/ipuxw8I8JEOmQkxB2kXObpbkFh TViQ== X-Gm-Message-State: APt69E1PB0vGpYs3nPXV6f5BC50rkiBPpciNjuu3jeb4JJ3rZ7WJI4BJ HatVlZ+Q/Ooy4r8hqpbHuFtgk7XP+T8Hu1sbNCs06g== X-Received: by 2002:a1c:1e4b:: with SMTP id e72-v6mr7968812wme.155.1530559527912; Mon, 02 Jul 2018 12:25:27 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a1c:c202:0:0:0:0:0 with HTTP; Mon, 2 Jul 2018 12:25:27 -0700 (PDT) In-Reply-To: <43d78927-3955-acde-a2d1-d2b82932a7a6@huawei.com> References: <12e6da4e-7681-771f-38d3-3c1abf943c24@huawei.com> <43d78927-3955-acde-a2d1-d2b82932a7a6@huawei.com> From: John Stultz Date: Mon, 2 Jul 2018 12:25:27 -0700 Message-ID: Subject: Re: hrtimer become inaccurate with RT patch To: gengdongjiu Cc: Thomas Gleixner , linux-rt-users , lkml , anna-maria@linutronix.de, Hangaohuai , "zhangjianwei (D)" , yangchuanlong@huawei.com, "Zhangbin (EulerOS)" , liupeifeng3@huawei.com Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jul 2, 2018 at 2:34 AM, gengdongjiu wrote: > Hi Thomas/Anna/John, > > Recently I found that the hrtimer become inaccurate when there is a RT > process runs on the same cpu core, and the kernel has applied preempt_rt > patch. > The Linux kernel version is v4.1.46, and the preempt_rt patch is > patch-4.1.46-rt52.patch. > I know that in the preempt_rt environment the interrupt handlers no > longer run in interrupt context but in process context, so that RT > process will not be interrupt. But if the hrtimer is also runs in > process context the timer is useless when it's inaccurate. so I want to > consult you whether this is expected behavior? whether is reasonable to move the timer IRQ > handling to a thread? I've not looked at the PREEMPT_RT code in a long time, but years ago there was a tension in that there is not an easy way track ownership of timers. Thus timers all fired at the same priority of the hrtimer irq thread. This thread could be moved up or down in priority, but the problem was all timers would fire with the same priority. So either the thread priority was so high that low-priority process could generate a bunch of timers which would interrupt higher priority tasks, or the thread priority was lower, so a high priority task could block all timers. There was some handwavy talk of trying to keep per-process timer lists, so the hrtimer irq could still be in irq context but the firing logic it didn't do anything but mark its task as runnable and do the the actual timer firing logic before we eventually run the task (in proper rt priority order), in a fashion similar to signals. But I'm not sure if any attempts were made in that direction. I also think it was an open question if there's any logic in kernel that depend on strict in-order kernel timer processing, so its possible there could be odd inversion issues where high priority timer logic is waiting on /expecting lower priority timers to fire, etc, so its probably an area of research. thanks -john