Received: by 10.213.65.68 with SMTP id h4csp278211imn; Wed, 28 Mar 2018 03:29:36 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+pnO7QaExSdjw9L8f8AY32Fe6Q+zZGi2R8qxecKYqHi2yV5GLg9roRTzp99jl1qbfH+xtA X-Received: by 10.99.113.83 with SMTP id b19mr2154201pgn.167.1522232976017; Wed, 28 Mar 2018 03:29:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522232975; cv=none; d=google.com; s=arc-20160816; b=lZSo+lm6/pPVPeHAIigS2MTSeDZdyuk28qwfJGu1keJqosUmGoCKQlmry+zJl/U5Ms EWx6LHKpdszpAglr9RdEuQY1v73wrRt/D7opar03Qp0Nm0/6bHQnEQpALrukjmZsf3oL XYj47t+NUJIBR3t++7McAPfsbBkE2XbjzD56M6Cslrlgry0q1mdXf41uqQZj6DoSuY6D jEE1GOdn9Qqakyi6T7qn4q1VjwhMa351Mk5mz6/WUG6wDk5fmhOXywALmjANNfv8juYW /Ec2guND/0mdsSxR03pePsLwFKA/IX5zhMbQHcaEGyC6ygOPxTOg0p3Q9PqfZ23g6SrR rLgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date :arc-authentication-results; bh=u0COoUKkhZQHRVaPVctLLJOqYUep347M4YpOTJ1AFpg=; b=RlhARku3IKYbj2zROmQyRwpCZ51JZkd8zRuquoP6JrtH8H+FTye3GTWoyWOQOX0Ha1 U1rKFKgqdGLxmKY8U8/Dk1MMqAnvCX+TT0AjnpWDWSXjuM9xL+hT10eQ7v5HyTY33cFa lhRNggyrpbZbvJJj+eLJp2w0ZbXKiMHR9lq4yVS/H45GU3Fsxs1qI2DsCGiPmLTJ5uac 0cHJ26UZn7TtLVwWZr7IQ5CJ1Ngp8McXmSKowWxmG0e1fSQzYZIC/IZheRpnPId6RALb T0+vbnqPWKuUa5PYmH2IAHWFWdRbNCT0AiUxuhFGtp7LHmpPBrIKBdXGX7K7dyFurAcu 5iKg== 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 u70si2536429pfj.341.2018.03.28.03.29.19; Wed, 28 Mar 2018 03:29:35 -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 S1752698AbeC1K2R convert rfc822-to-8bit (ORCPT + 99 others); Wed, 28 Mar 2018 06:28:17 -0400 Received: from Galois.linutronix.de ([146.0.238.70]:50245 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752125AbeC1K2P (ORCPT ); Wed, 28 Mar 2018 06:28:15 -0400 Received: from bigeasy by Galois.linutronix.de with local (Exim 4.80) (envelope-from ) id 1f18JR-0001Qh-HT; Wed, 28 Mar 2018 12:28:13 +0200 Date: Wed, 28 Mar 2018 12:28:13 +0200 From: Sebastian Andrzej Siewior To: linux-rt-users@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Thomas Gleixner , Steven Rostedt , stable-rt@vger.kernel.org Subject: [PATCH RT 2/3 v2] posix-timers: user proper timer while waiting for alarmtimer Message-ID: <20180328102813.gaf25zu7lajidwyy@linutronix.de> References: <20180328100746.18668-1-bigeasy@linutronix.de> <20180328100746.18668-2-bigeasy@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8BIT In-Reply-To: <20180328100746.18668-2-bigeasy@linutronix.de> User-Agent: NeoMutt/20180223 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On RT the timer can be preempted while running and therefore we wait with timer_wait_for_callback() for the timer to complete (instead of busy looping). The POSIX timer has an hrtimer underneath and this hrtimer is used to wait for its completion. The alartimer has also an hrtimer but at a different location. Instead of checking for ->timer_set which is the same for the alarmtimer and the "posix-timers" I instead check for ->arm which is only used by the "posix-timers". To match the alarmtimer I check for the alarm_clock struct. Cc: stable-rt@vger.kernel.org Signed-off-by: Sebastian Andrzej Siewior --- v1…v2: move timer_wait_for_callback() so that it actually compiles. kernel/time/posix-timers.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c index 0b568087bd64..3abd449a926f 100644 --- a/kernel/time/posix-timers.c +++ b/kernel/time/posix-timers.c @@ -796,20 +796,6 @@ SYSCALL_DEFINE1(timer_getoverrun, timer_t, timer_id) return overrun; } -/* - * Protected by RCU! - */ -static void timer_wait_for_callback(const struct k_clock *kc, struct k_itimer *timr) -{ -#ifdef CONFIG_PREEMPT_RT_FULL - if (kc->timer_set == common_timer_set) - hrtimer_wait_for_timer(&timr->it.real.timer); - else - /* FIXME: Whacky hack for posix-cpu-timers */ - schedule_timeout(1); -#endif -} - static void common_hrtimer_arm(struct k_itimer *timr, ktime_t expires, bool absolute, bool sigev_none) { @@ -840,6 +826,22 @@ static void common_hrtimer_arm(struct k_itimer *timr, ktime_t expires, hrtimer_start_expires(timer, HRTIMER_MODE_ABS); } +/* + * Protected by RCU! + */ +static void timer_wait_for_callback(const struct k_clock *kc, struct k_itimer *timr) +{ +#ifdef CONFIG_PREEMPT_RT_FULL + if (kc->timer_arm == common_hrtimer_arm) + hrtimer_wait_for_timer(&timr->it.real.timer); + else if (kc == &alarm_clock) + hrtimer_wait_for_timer(&timr->it.alarm.alarmtimer.timer); + else + /* FIXME: Whacky hack for posix-cpu-timers */ + schedule_timeout(1); +#endif +} + static int common_hrtimer_try_to_cancel(struct k_itimer *timr) { return hrtimer_try_to_cancel(&timr->it.real.timer); -- 2.16.3