Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp3635714imm; Mon, 2 Jul 2018 02:47:48 -0700 (PDT) X-Google-Smtp-Source: ADUXVKI/qUCwEwAFKadKMjsCjiZ6bffFQNhVznin0YD44nuDKT8X35/meh6UOzdWiEdAHixv1XG/ X-Received: by 2002:a17:902:1101:: with SMTP id d1-v6mr24694047pla.147.1530524868902; Mon, 02 Jul 2018 02:47:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530524868; cv=none; d=google.com; s=arc-20160816; b=E3hYcoeadnzEq7NJa90KKv6rhv07leC06enrDU/Vy/yjP95zq1CgXcf1FWZxNspmFm AwujqzVN04+il2agDTRM4RYNC3ZstKLJYOtlZvVIpHdJhlzM9zytFy76ix1AWmXlJseb mIqdEpGx22DaW2cKTGSw0jzny47jy7J9yyCqSCpqWP/5fH3wadgJzT7yHoWvfOVWLeQp bUyK3Ue2r9Vh7vMq0QPzQllLGUqQ5ygVnqrfZPt2aXIiIkR8nFMlXMkGmd1P9nShCFLf CO2b6JUxmX52Tzadj3BLJPPjxMKcI4jxXrY4todrzzG08Z7nagUuO4L8pFFURrDEBw3J LgGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=x/1I4dqniDqwCvoVpiOCroB2/eRlbH0d8dRSlQ1QJ2M=; b=o96TDSgr5i6vRnQi0VOvA5ZKOxlPU+g6xFrhb0QFbCNgclerIlp9jnvWLJ8oLgr07/ 8M+uo9iQuWOnvA3BGOL2D4XQcj2siaZxaYKXPrzT3oNvymJw0N78Zrxr3lQw7G1tmi5i B/EzM1DQDTekyQl7fvMil5Gz1BOWwsKBcxQsRwCWRUhZzQMKGlO+z+XTheakARVnFvt2 cqsfTtWndrBuzSZ+ZFJ7qC7eNzhA9sPvTy8jksij/8FqOhKDWcE84vWCWi0JJLDC6BcO vG+QixQXrFNWNeCuRpvfQj/6kyQKox8p2wgP3VUA5TILQJZwKybdHIcFOuXMJAODJJYM BODA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 65-v6si15592950pfd.73.2018.07.02.02.47.34; Mon, 02 Jul 2018 02:47:48 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934181AbeGBJfe (ORCPT + 99 others); Mon, 2 Jul 2018 05:35:34 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:9191 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S933423AbeGBJf3 (ORCPT ); Mon, 2 Jul 2018 05:35:29 -0400 Received: from DGGEMS407-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id E4A3E4405BBA3; Mon, 2 Jul 2018 17:35:12 +0800 (CST) Received: from [127.0.0.1] (10.142.68.147) by DGGEMS407-HUB.china.huawei.com (10.3.19.207) with Microsoft SMTP Server id 14.3.382.0; Mon, 2 Jul 2018 17:35:08 +0800 Subject: hrtimer become inaccurate with RT patch To: Thomas Gleixner , , , , CC: Hangaohuai , "zhangjianwei (D)" , , "Zhangbin (EulerOS)" , References: <12e6da4e-7681-771f-38d3-3c1abf943c24@huawei.com> From: gengdongjiu Message-ID: <43d78927-3955-acde-a2d1-d2b82932a7a6@huawei.com> Date: Mon, 2 Jul 2018 17:34:34 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <12e6da4e-7681-771f-38d3-3c1abf943c24@huawei.com> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.142.68.147] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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? Check the patch-4.1.46-rt52.patch will found in function 'hrtimer_interrupt' the modify below: @@ -1296,7 +1539,10 @@ retry: if (basenow.tv64 < hrtimer_get_softexpires_tv64(timer)) break; - __run_hrtimer(timer, &basenow); + if (!hrtimer_rt_defer(timer)) + __run_hrtimer(timer, &basenow); + else + raise = 1; } } /* Reevaluate the clock bases for the next expiry */ @@ -1357,6 +1603,9 @@ retry: tick_program_event(expires_next, 1); printk_once(KERN_WARNING "hrtimer: interrupt took %llu ns\n", ktime_to_ns(delta)); +out: + if (raise) + raise_softirq_irqoff(HRTIMER_SOFTIRQ); } I think this is why hrtimer is run as a thread, I tried to set hrtimer.irqsafe to 1, but the timer still seemed not right. Could anyone give some advise? Thanks.