From patchwork Tue Feb 26 14:54:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 159217 Delivered-To: patches@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp3303965jad; Tue, 26 Feb 2019 06:54:36 -0800 (PST) X-Received: by 2002:a2e:805a:: with SMTP id p26mr13447410ljg.179.1551192876415; Tue, 26 Feb 2019 06:54:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551192876; cv=none; d=google.com; s=arc-20160816; b=fAzaTFApv2LRik5MDJ2voE9+xRn09PbDFtku3qvALf/y9hMLq7CXOPbHfjmxCcPK6u 6k7x0R+n8MdR3lBWgZE+JKWVphAD1FngjLXPq7xnXhSXb1Hz4DbyI2ZOohhrwl2FZz9T P4qsFU4FG1nRb8F+1HBgwdQzB3zZVgfDqJHAJjuq1cRP5t8ybfbU77s3p1XhUMkujP0y 3JQ+65Ru5P9m141sR8oDd6eLktEiO+aEZqSfHhM/rITEmqQq+tvFQEm/ijzOJlPbatR5 3C+kyWU3locdWp9FmbNZqpOsIXJ4vqHku3tQrlW3wb64ZVbS4nl7Hy4Y8k//gi6+naGU t9+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=cHcnRnu2FIgTWtisqlvCscC0vHLrnc1MItOKTfTvXoU=; b=0VWfaOr7rPxZJoMDl5ITj1FCAJi1LaLGbyhkk8P3CUvPDyw1o5/TNL38iWW7ycONHv KNuFP2S6kR+SD0L8hTzRRWDJZmOgK9iHag3+OI7rQWhmFFHrqxBsEgJFSHOobGDu5oU7 3GrlhVPwKOrEMwvpMzmAQWpQ7Aj0bGypfcVkjRblqLx/BrQyMGqAO2Tn1ls6XPJevbHs vVSKb96D/O1s5AgruBKqGFTWK2Oi6c1WR1O52mFtBryGhYQ3nh40knxem+ECxUjN72R4 7M27VHdQY8DjUv5ZjVcPNZ+LCnMLOzHCmIQjNVrCKgcE8+VYPeHIt+sj4LlOL6C8CRTC 93yQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="XADwoXr/"; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id h18sor7402253lja.11.2019.02.26.06.54.36 for (Google Transport Security); Tue, 26 Feb 2019 06:54:36 -0800 (PST) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="XADwoXr/"; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=cHcnRnu2FIgTWtisqlvCscC0vHLrnc1MItOKTfTvXoU=; b=XADwoXr/kyyiMCzb9CS6DjwET0munxhbMQIwQFME2w8OCXzBvaWMH170NRncocFNPW X3IwkYXquWtD2FqzjNypn1QvdA7rhC0Sg2pfd2tAB07t2GK1sz4eeSlPq1ZSMerouLB/ yL8xYGa3C8T1+P97PJKc85J9n3JhT1JffBZg2gW80U8pJoFeRkcqssL4pm6zAMO2NeE+ yW0k2bLLZTbWiRsTJBgR0SZMbYTMLrLTASulOBpc7SS6P+0jyFj3qeCrkahnJLbwzeXv xrqwjvn5VSxFLH+8WtQk+CDKV2LnJKl/bQFJ2FpE6XkLYTYAMtvFOu6hw1idcP0G7FXW w8bQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=cHcnRnu2FIgTWtisqlvCscC0vHLrnc1MItOKTfTvXoU=; b=lULZH8N1RxnfT96Z8BOFAmNmh5GinjexgAWP8Tsxzmh9orhztGXRKHau/DdIhEMTc1 HYHQZsVJGb8TDtxljosgdfX1XcYHIMn4MxAQeG9Udtc/NYs/voP2YZ5kfsioejd5d1IW /XC5JM0UASZUbaCzFRFeEAoeA2Z6xVlHfKT6isckOka9mBAeO2FzjAQUozX1lLf+f3jh rVO6rxkY6c0QC/r8dg+NLqXsz4NB4e3HAyCOXbAWQHof9gSMxZUWgian87Vxu3wlEqBQ ZIyzM4sLA+c62ZvKZ2SCr/aAw2YXBpfWHFHgJyQ04bAEvr2i2EdlPhwaVd5fhkP7EYLE q2fA== X-Gm-Message-State: AHQUAuZdrRm4O08tJMp1hg6pCLmesHnjfSKtfr5yG6v0H+N9E88RbdgB qLugQfl58u6E9uwB8JmLsblXYBDo X-Google-Smtp-Source: AHgI3IauEHmxkM6+fHc/XlZ7fBCCsrlb0JVEuV8nYLBMNV+/1LXzmHXaNCoZrVoDUKDl+bDaD0aZRg== X-Received: by 2002:a2e:6c09:: with SMTP id h9mr13631068ljc.139.1551192875997; Tue, 26 Feb 2019 06:54:35 -0800 (PST) Return-Path: Received: from uffe-XPS-13-9360.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id t11sm2206554ljj.92.2019.02.26.06.54.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Feb 2019 06:54:35 -0800 (PST) From: Ulf Hansson To: "Rafael J . Wysocki" , linux-pm@vger.kernel.org Cc: Frederic Weisbecker , Thomas Gleixner , Sudeep Holla , Lorenzo Pieralisi , Mark Rutland , Daniel Lezcano , "Raju P . L . S . S . S . N" , Stephen Boyd , Tony Lindgren , Kevin Hilman , Lina Iyer , Ulf Hansson , Viresh Kumar , Vincent Guittot , Geert Uytterhoeven , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v11 3/8] time: tick-sched: Provide helpers to get the next timer expiration Date: Tue, 26 Feb 2019 15:54:10 +0100 Message-Id: <20190226145415.19411-4-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190226145415.19411-1-ulf.hansson@linaro.org> References: <20190226145415.19411-1-ulf.hansson@linaro.org> From: Daniel Lezcano In the power control path with the interrupts disabled, cpuidle governors calls tick_nohz_get_sleep_length() to get the duration until the next timer expires. This is not always convenient when going forward, as the duration is a relative time to "now". To make it more flexible, let's instead provide two new functions tick_nohz_get_next_timer|hrtimer(), which provides the actual time for when the next timer is about to expire. The computation of the duration can then be done by the caller. For now, leave tick_nohz_get_sleep_length() as is. When users of it has converted to the new APIs, then we can remove it. Signed-off-by: Daniel Lezcano [Ulf: Clarified information in changelog] Signed-off-by: Ulf Hansson --- Changes in v11: - New patch, replace "timer: Export next wakeup time of a CPU" from v10. --- include/linux/tick.h | 7 +++++ kernel/time/tick-sched.c | 68 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 74 insertions(+), 1 deletion(-) -- 2.17.1 diff --git a/include/linux/tick.h b/include/linux/tick.h index 55388ab45fd4..5b10a0e4acbb 100644 --- a/include/linux/tick.h +++ b/include/linux/tick.h @@ -111,6 +111,8 @@ enum tick_dep_bits { #define TICK_DEP_MASK_SCHED (1 << TICK_DEP_BIT_SCHED) #define TICK_DEP_MASK_CLOCK_UNSTABLE (1 << TICK_DEP_BIT_CLOCK_UNSTABLE) +extern ktime_t tick_nohz_get_next_hrtimer(void); + #ifdef CONFIG_NO_HZ_COMMON extern bool tick_nohz_enabled; extern bool tick_nohz_tick_stopped(void); @@ -123,6 +125,7 @@ extern void tick_nohz_idle_exit(void); extern void tick_nohz_irq_exit(void); extern bool tick_nohz_idle_got_tick(void); extern ktime_t tick_nohz_get_sleep_length(ktime_t *delta_next); +extern ktime_t tick_nohz_get_next_timer(void); extern unsigned long tick_nohz_get_idle_calls(void); extern unsigned long tick_nohz_get_idle_calls_cpu(int cpu); extern u64 get_cpu_idle_time_us(int cpu, u64 *last_update_time); @@ -145,6 +148,10 @@ static inline void tick_nohz_idle_restart_tick(void) { } static inline void tick_nohz_idle_enter(void) { } static inline void tick_nohz_idle_exit(void) { } static inline bool tick_nohz_idle_got_tick(void) { return false; } +static inline ktime_t tick_nohz_get_next_timer(void) +{ + return tick_nohz_get_next_hrtimer(); +} static inline ktime_t tick_nohz_get_sleep_length(ktime_t *delta_next) { diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c index 6fa52cd6df0b..9966be665074 100644 --- a/kernel/time/tick-sched.c +++ b/kernel/time/tick-sched.c @@ -443,6 +443,20 @@ void __init tick_nohz_init(void) } #endif +/** + * tick_nohz_get_next_hrtimer - return the expected deadline for the + * next hrtimer + * + * Called from power state control code with interrupts disabled + * + * Returns a ktime_t based value giving the next deadline for the tick + * or an earlier hrtimer + */ +ktime_t tick_nohz_get_next_hrtimer(void) +{ + return __this_cpu_read(tick_cpu_device.evtdev)->next_event; +} + /* * NOHZ - aka dynamic tick functionality */ @@ -918,7 +932,7 @@ static void __tick_nohz_idle_stop_tick(struct tick_sched *ts) int cpu = smp_processor_id(); /* - * If tick_nohz_get_sleep_length() ran tick_nohz_next_event(), the + * If tick_nohz_get_next_timer() ran tick_nohz_next_event(), the * tick timer expiration time is known already. */ if (ts->timer_expires_base) @@ -1022,6 +1036,58 @@ bool tick_nohz_idle_got_tick(void) return false; } +/** + * tick_nohz_get_next_timer - return the earliest timer deadline + * + * Called from power state control code with interrupts disabled + * + * Returns a ktime_t based value giving the earliest timer + */ +ktime_t tick_nohz_get_next_timer(void) +{ + + struct tick_sched *ts = this_cpu_ptr(&tick_cpu_sched); + ktime_t next_tick, next_timer, next_hrtimer; + int cpu = smp_processor_id(); + + /* + * Actually the function returns the next hrtimer which can + * be the next tick or another hrtimer expiring before the tick. + */ + next_tick = tick_nohz_get_next_hrtimer(); + + /* + * If we can not stop the tick, then in any case the next + * timer is the earliest one expiring with the hrtimer. + */ + if (!can_stop_idle_tick(cpu, ts)) + return next_tick; + + /* + * Get the next low resolution timer led by the hrtimer. If + * there is no timer in this case, then we can rely on the + * hrtimer next event only coming from the call above. + */ + next_timer = tick_nohz_next_event(ts, cpu); + if (!next_timer) + return next_tick; + + /* + * This function will return the next timer after the + * sched_timer aka the tick. We know there is another hrtimer + * because the tick_nohz_next_event() returned a non zero + * deadline and we need a tick to make the lowres to expire. + */ + next_hrtimer = hrtimer_next_event_without(&ts->sched_timer); + + /* + * At this point, we have the next lowres timer and the next + * hrtimer which is not the tick. We need to figure out which + * one expires first. + */ + return min_t(u64, next_hrtimer, next_timer); +} + /** * tick_nohz_get_sleep_length - return the expected length of the current sleep * @delta_next: duration until the next event if the tick cannot be stopped