Received: by 10.213.65.68 with SMTP id h4csp488293imn; Wed, 4 Apr 2018 01:55:06 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+wGxVK5ScFeUTAWrjwB+z+An1s1IBVFo/jlCKiW+B40Zt41T8TRTMUxEc+s51IVP/oLMjL X-Received: by 2002:a17:902:650e:: with SMTP id b14-v6mr17889414plk.147.1522832106216; Wed, 04 Apr 2018 01:55:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522832106; cv=none; d=google.com; s=arc-20160816; b=yAt9/QgfAwXPShNfW5x+yra4qCG/td04GrW6NGQv5UroZYzK3ThrJLomNQb6//h5YW 9xi6VJvsjmCfPp2SfF9VbDZGvW+CajitehVGX2jF9Hd8cRjADH2ho6S+J+yg37yMFpus AptEdEEi4cl6Od1gG8Bdgk+c65gmiF0ICYNR4bKhCy1jTRTbdGcUDF2WX6msPgrb0Ubv I8gG+RiD9CusLqmzgpv4S14crIc9jMqKMKvMeg3mLWxGCrFnvIv1+OLTnfapvA9Yp2pX vw+A/TkxsvuDCC04Omz8mNySYC5YgAlQM3KO94pT8w5ZqAIhiAznf/QMElcG3dEida2B nShQ== 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:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=wjqSwwkibDih31Ajno9cTpPdaO/7TwOjGXxRDC7zDnc=; b=gNoXeMbsIBp040jk87Svsgyj9NHcOHxuj5vLu64TpDDS0f7jN8GU/iXOZZ/zz56m03 F0Av6iEEWTNfB7dUZN8vzC55mRqBZbwSFOyvZUstMnwFWGX+Kdm7U9YUAGWCgSs2dpdq ORtvcu0l7UOTSoFJaiVPbKUsAFRpC0JQpNS3k4tAsI99zvUFlnWV7w0UUi56fTWCOtWb MHILGz0IF7XqCbsHwEA+KdEZXykR2XYcsRPWEiLrRy84t338VlL9Jf5AX/ChOhEK6V1I /kBB13cVX0sslV5D+ys8Vk3mEvVS75UjRRO6lLyEd8W0xM5PIMZSTALTpt07VLMyab8W qUKw== 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 ay2-v6si2413791plb.749.2018.04.04.01.54.51; Wed, 04 Apr 2018 01:55:06 -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 S1751265AbeDDIx0 (ORCPT + 99 others); Wed, 4 Apr 2018 04:53:26 -0400 Received: from cloudserver094114.home.pl ([79.96.170.134]:54252 "EHLO cloudserver094114.home.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751284AbeDDIxI (ORCPT ); Wed, 4 Apr 2018 04:53:08 -0400 Received: from 79.184.255.92.ipv4.supernova.orange.pl (79.184.255.92) (HELO aspire.rjw.lan) by serwer1319399.home.pl (79.96.170.134) with SMTP (IdeaSmtpServer 0.83) id cef18e8b37f11809; Wed, 4 Apr 2018 10:53:06 +0200 From: "Rafael J. Wysocki" To: Linux PM Cc: Peter Zijlstra , Frederic Weisbecker , Thomas Gleixner , Paul McKenney , Thomas Ilsche , Doug Smythies , Rik van Riel , Aubrey Li , Mike Galbraith , LKML , Len Brown Subject: [PATCH v9 01/10] time: tick-sched: Reorganize idle tick management code Date: Wed, 04 Apr 2018 10:33:31 +0200 Message-ID: <69225844.x0Lc6voIo9@aspire.rjw.lan> In-Reply-To: <1736751.LdhZHb50jq@aspire.rjw.lan> References: <1736751.LdhZHb50jq@aspire.rjw.lan> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Rafael J. Wysocki Prepare the scheduler tick code for reworking the idle loop to avoid stopping the tick in some cases. The idea is to split the nohz idle entry call to decouple the idle time stats accounting and preparatory work from the actual tick stop code, in order to later be able to delay the tick stop once we reach more power-knowledgeable callers. Move away the tick_nohz_start_idle() invocation from __tick_nohz_idle_enter(), rename the latter to __tick_nohz_idle_stop_tick() and define tick_nohz_idle_stop_tick() as a wrapper around it for calling it from the outside. Make tick_nohz_idle_enter() only call tick_nohz_start_idle() instead of calling the entire __tick_nohz_idle_enter(), add another wrapper disabling and enabling interrupts around tick_nohz_idle_stop_tick() and make the current callers of tick_nohz_idle_enter() call it too to retain their current functionality. Signed-off-by: Rafael J. Wysocki Reviewed-by: Frederic Weisbecker --- v8 -> v9: * No changes in the patch. * Tag from Frederic. --- arch/x86/xen/smp_pv.c | 1 + include/linux/tick.h | 12 ++++++++++++ kernel/sched/idle.c | 1 + kernel/time/tick-sched.c | 46 +++++++++++++++++++++++++--------------------- 4 files changed, 39 insertions(+), 21 deletions(-) Index: linux-pm/include/linux/tick.h =================================================================== --- linux-pm.orig/include/linux/tick.h +++ linux-pm/include/linux/tick.h @@ -114,6 +114,7 @@ enum tick_dep_bits { #ifdef CONFIG_NO_HZ_COMMON extern bool tick_nohz_enabled; extern int tick_nohz_tick_stopped(void); +extern void tick_nohz_idle_stop_tick(void); extern void tick_nohz_idle_enter(void); extern void tick_nohz_idle_exit(void); extern void tick_nohz_irq_exit(void); @@ -122,9 +123,18 @@ extern unsigned long tick_nohz_get_idle_ extern unsigned long tick_nohz_get_idle_calls_cpu(int cpu); extern u64 get_cpu_idle_time_us(int cpu, u64 *last_update_time); extern u64 get_cpu_iowait_time_us(int cpu, u64 *last_update_time); + +static inline void tick_nohz_idle_stop_tick_protected(void) +{ + local_irq_disable(); + tick_nohz_idle_stop_tick(); + local_irq_enable(); +} + #else /* !CONFIG_NO_HZ_COMMON */ #define tick_nohz_enabled (0) static inline int tick_nohz_tick_stopped(void) { return 0; } +static inline void tick_nohz_idle_stop_tick(void) { } static inline void tick_nohz_idle_enter(void) { } static inline void tick_nohz_idle_exit(void) { } @@ -134,6 +144,8 @@ static inline ktime_t tick_nohz_get_slee } static inline u64 get_cpu_idle_time_us(int cpu, u64 *unused) { return -1; } static inline u64 get_cpu_iowait_time_us(int cpu, u64 *unused) { return -1; } + +static inline void tick_nohz_idle_stop_tick_protected(void) { } #endif /* !CONFIG_NO_HZ_COMMON */ #ifdef CONFIG_NO_HZ_FULL Index: linux-pm/kernel/time/tick-sched.c =================================================================== --- linux-pm.orig/kernel/time/tick-sched.c +++ linux-pm/kernel/time/tick-sched.c @@ -539,14 +539,11 @@ static void tick_nohz_stop_idle(struct t sched_clock_idle_wakeup_event(); } -static ktime_t tick_nohz_start_idle(struct tick_sched *ts) +static void tick_nohz_start_idle(struct tick_sched *ts) { - ktime_t now = ktime_get(); - - ts->idle_entrytime = now; + ts->idle_entrytime = ktime_get(); ts->idle_active = 1; sched_clock_idle_sleep_event(); - return now; } /** @@ -911,19 +908,21 @@ static bool can_stop_idle_tick(int cpu, return true; } -static void __tick_nohz_idle_enter(struct tick_sched *ts) +static void __tick_nohz_idle_stop_tick(struct tick_sched *ts) { - ktime_t now, expires; + ktime_t expires; int cpu = smp_processor_id(); - now = tick_nohz_start_idle(ts); - if (can_stop_idle_tick(cpu, ts)) { int was_stopped = ts->tick_stopped; ts->idle_calls++; - expires = tick_nohz_stop_sched_tick(ts, now, cpu); + /* + * The idle entry time should be a sufficient approximation of + * the current time at this point. + */ + expires = tick_nohz_stop_sched_tick(ts, ts->idle_entrytime, cpu); if (expires > 0LL) { ts->idle_sleeps++; ts->idle_expires = expires; @@ -937,16 +936,19 @@ static void __tick_nohz_idle_enter(struc } /** - * tick_nohz_idle_enter - stop the idle tick from the idle task + * tick_nohz_idle_stop_tick - stop the idle tick from the idle task * * When the next event is more than a tick into the future, stop the idle tick - * Called when we start the idle loop. - * - * The arch is responsible of calling: + */ +void tick_nohz_idle_stop_tick(void) +{ + __tick_nohz_idle_stop_tick(this_cpu_ptr(&tick_cpu_sched)); +} + +/** + * tick_nohz_idle_enter - prepare for entering idle on the current CPU * - * - rcu_idle_enter() after its last use of RCU before the CPU is put - * to sleep. - * - rcu_idle_exit() before the first use of RCU after the CPU is woken up. + * Called when we start the idle loop. */ void tick_nohz_idle_enter(void) { @@ -965,7 +967,7 @@ void tick_nohz_idle_enter(void) ts = this_cpu_ptr(&tick_cpu_sched); ts->inidle = 1; - __tick_nohz_idle_enter(ts); + tick_nohz_start_idle(ts); local_irq_enable(); } @@ -982,10 +984,12 @@ void tick_nohz_irq_exit(void) { struct tick_sched *ts = this_cpu_ptr(&tick_cpu_sched); - if (ts->inidle) - __tick_nohz_idle_enter(ts); - else + if (ts->inidle) { + tick_nohz_start_idle(ts); + __tick_nohz_idle_stop_tick(ts); + } else { tick_nohz_full_update_tick(ts); + } } /** Index: linux-pm/arch/x86/xen/smp_pv.c =================================================================== --- linux-pm.orig/arch/x86/xen/smp_pv.c +++ linux-pm/arch/x86/xen/smp_pv.c @@ -425,6 +425,7 @@ static void xen_pv_play_dead(void) /* us * data back is to call: */ tick_nohz_idle_enter(); + tick_nohz_idle_stop_tick_protected(); cpuhp_online_idle(CPUHP_AP_ONLINE_IDLE); } Index: linux-pm/kernel/sched/idle.c =================================================================== --- linux-pm.orig/kernel/sched/idle.c +++ linux-pm/kernel/sched/idle.c @@ -221,6 +221,7 @@ static void do_idle(void) __current_set_polling(); tick_nohz_idle_enter(); + tick_nohz_idle_stop_tick_protected(); while (!need_resched()) { check_pgt_cache();