Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp378184imm; Mon, 2 Jul 2018 13:15:06 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLa+dSAggYbJc3dyGq3Dq7IAS1kjCOw0dJDu+2C+fds553FEN74rpxIFvKgfgXsXc7wnjGU X-Received: by 2002:a17:902:bb8a:: with SMTP id m10-v6mr27112986pls.236.1530562505964; Mon, 02 Jul 2018 13:15:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530562505; cv=none; d=google.com; s=arc-20160816; b=XcL4TTdGgS++WWLyIs8o/Ne+/UaDEJMYiVdoAbeg1XDk/c2Ac8BsX31s8HDZTWrrdy DRJ3aDsMb115pmNaFG7LGjpvBSyKmNyKVco1T/5YmDR84MlkJ3ojhzTlwxUOI6+PndJm +C9bkSgRyDRWth9N+6JY8PWw+97WeX/D5jzZJiDSgET7IXS/l7vO+5t9nVSCmyCBPJJV wjX5+5/pp3scaRSYOsbA6iWB8cgQKFgNnuKyba+kK8PeAoqlwvC7/MYwsvBObmGkIy39 zCzavhMSlqsJrDZTnwTXH4uo26TxKWZ5MujIxoZF56kctKALac3dQ9XtwYULJAEkwYe7 IZAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date :arc-authentication-results; bh=MwWYuJ04PSG+BDceZAtQArtVeB8mWqfD/VCSpcbTi1A=; b=c7/1az9jZUoRS8HqnPUfteWEk7SdGaH6te5T/hy+Ab9ENgQjM5kZ9SSHL48l7LWsCo NWlWxhDEDTywNpa0I0n8ppW6MmXPeVHV0hDBUVnrNzK3Jx6xB5AjkUsf64beer4/F/Qa Y533BGqYAJPKA84IDR/da3rkORYv+fJZ09SWypfGbW7XLa8xYg+4+T2naPonClKtHOO8 0FSsjG1SOZ/PkIb0c3iek/mytLWSMfiCeOlwdYMYz43CHT80KYHWCkOgnqNpq7LaWe4H QHy4m1A9ooJm38UTkOVhIgUyYfqLUDDwoONptIRT1z+LKyGCf0U3T0AH1Ovg4BY+Yg1K xEjw== 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 34-v6si11904188pgs.243.2018.07.02.13.14.51; Mon, 02 Jul 2018 13:15:05 -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 S1753161AbeGBUNr (ORCPT + 99 others); Mon, 2 Jul 2018 16:13:47 -0400 Received: from Galois.linutronix.de ([146.0.238.70]:40678 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752700AbeGBUNq (ORCPT ); Mon, 2 Jul 2018 16:13:46 -0400 Received: from p4fea482e.dip0.t-ipconnect.de ([79.234.72.46] helo=nanos) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1fa5Cg-0002IF-VR; Mon, 02 Jul 2018 22:13:43 +0200 Date: Mon, 2 Jul 2018 22:13:42 +0200 (CEST) From: Thomas Gleixner To: John Stultz cc: gengdongjiu , linux-rt-users , lkml , anna-maria@linutronix.de, Hangaohuai , "zhangjianwei (D)" , yangchuanlong@huawei.com, "Zhangbin (EulerOS)" , liupeifeng3@huawei.com Subject: Re: hrtimer become inaccurate with RT patch In-Reply-To: Message-ID: References: <12e6da4e-7681-771f-38d3-3c1abf943c24@huawei.com> <43d78927-3955-acde-a2d1-d2b82932a7a6@huawei.com> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 2 Jul 2018, John Stultz wrote: > 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. Yeah, we had that long ago. It was complex and nasty. > 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. Well, the main issues are actually the signal based posix-timers. The problem is not to keep track of them, them problem is which of the threads to wake up for which timer. I've had experimental code which kinda worked, but ran into issues with the signal masking and the horrors of sighand lock. Definitely more research required for that. It might have become simpler, but still sighand lock cannot be taken from hard interrupt context on RT. Thanks, tglx