Received: by 10.223.185.111 with SMTP id b44csp106314wrg; Fri, 9 Mar 2018 01:51:42 -0800 (PST) X-Google-Smtp-Source: AG47ELv2XHy7fPxv0rZ8XYqTuj2r2tSwe8Ahew6m6hwaiMpn7HGe8YH/uI3HqwICUWUS3XtF5krH X-Received: by 2002:a17:902:7008:: with SMTP id y8-v6mr7418862plk.395.1520589102737; Fri, 09 Mar 2018 01:51:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520589102; cv=none; d=google.com; s=arc-20160816; b=l2x1RpkyPOPnM+DX5XWXHmZqKp0GLjV9KCNljn84iOVtvkL01pzTC4PtjeFAggW81S OJ5iHYrs54UH6mdqSSri9x/+O1+BTStn2n7gLD+p9UbCX8M7aSwpRhSA4dpaU69qpnN5 vvl44cs1PPer6L4x+DPXpCf12pUVm8np3c7dCT7dU7suwNGYYb7Xw6w9qGu3WYxV2UMj 7zHZX5IPEYc4xf9nAGvAWdEhpaGTzZdYa4SU0zsGwhm/m8Njq/X4HASQvIPvTG6p4P3B d7z8xZHCCOlrJVXl3Yfbr6tJuyY31OkOahUQ9X4fwqmB1St+bTSiMhkOzeVxf73+LlcA G+Ug== 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=W6so2zAMAdNE//gY3av16WyNOq4nMiljZeX4+aSvUnI=; b=Ezvh846Xmf5KTo5A1D5fv1RCslf/N9F5XhThaeQbeEyen652xcyj6jOP4F2YvNgtqG pp6UfGlb/IicufD+4b0hDMyv4Ld/43q5HnbT8LVhfvheWHN74nG4BsMo+yioet3C79zD q3n4ubwyJ+XjN34UKcUnLs2syFXnvk8KWBTyLGQVkYkdAuA8bxClneZKSsax5UBxL7wp m+TEBSw0OXNYqjtWwvHxqfF2LWtPYYyvnPfk3aOaF8pgIidcrlL+IWk+70y9nlzVbOlB 8MAynKF6MP42wMyyJybJe/Q/7ZucBhhbcSZv1eTrZB8oKcvgVkFZyWBjzFnhXJXJGOZ4 FL+w== 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 b2si499831pgq.240.2018.03.09.01.51.28; Fri, 09 Mar 2018 01:51:42 -0800 (PST) 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 S1751266AbeCIJt5 (ORCPT + 99 others); Fri, 9 Mar 2018 04:49:57 -0500 Received: from cloudserver094114.home.pl ([79.96.170.134]:64912 "EHLO cloudserver094114.home.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750965AbeCIJsv (ORCPT ); Fri, 9 Mar 2018 04:48:51 -0500 Received: from 79.184.254.228.ipv4.supernova.orange.pl (79.184.254.228) (HELO aspire.rjw.lan) by serwer1319399.home.pl (79.96.170.134) with SMTP (IdeaSmtpServer 0.83) id a1b677941efeaedb; Fri, 9 Mar 2018 10:48:50 +0100 From: "Rafael J. Wysocki" To: Peter Zijlstra , Linux PM , Frederic Weisbecker Cc: Thomas Gleixner , Paul McKenney , Thomas Ilsche , Doug Smythies , Rik van Riel , Aubrey Li , Mike Galbraith , LKML Subject: [RFC/RFT][PATCH v3 2/6] sched: idle: Do not stop the tick upfront in the idle loop Date: Fri, 09 Mar 2018 10:38:27 +0100 Message-ID: <3430605.IRKCBv8i4O@aspire.rjw.lan> In-Reply-To: <2450532.XN8DODrtDf@aspire.rjw.lan> References: <2450532.XN8DODrtDf@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 Push the decision whether or not to stop the tick somewhat deeper into the idle loop. Stopping the tick upfront leads to unpleasant outcomes in case the idle governor doesn't agree with the timekeeping code on the duration of the upcoming idle period. Specifically, if the tick has been stopped and the idle governor predicts short idle, the situation is bad regardless of whether or not the prediction is accurate. If it is accurate, the tick has been stopped unnecessarily which means excessive overhead. If it is not accurate, the CPU is likely to spend too much time in the (shallow, because short idle has been predicted) idle state selected by the governor [1]. As the first step towards addressing this problem, change the code to make the tick stopping decision inside of the loop in do_idle(). In particular, do not stop the tick in the cpu_idle_poll() code path. Also don't do that in tick_nohz_irq_exit() which doesn't really have enough information on whether or not to stop the tick. Link: https://marc.info/?l=linux-pm&m=150116085925208&w=2 # [1] Link: https://tu-dresden.de/zih/forschung/ressourcen/dateien/projekte/haec/powernightmares.pdf Signed-off-by: Rafael J. Wysocki --- kernel/sched/idle.c | 8 +++++--- kernel/time/tick-sched.c | 6 ++---- 2 files changed, 7 insertions(+), 7 deletions(-) Index: linux-pm/kernel/sched/idle.c =================================================================== --- linux-pm.orig/kernel/sched/idle.c +++ linux-pm/kernel/sched/idle.c @@ -221,13 +221,13 @@ static void do_idle(void) __current_set_polling(); tick_nohz_idle_enter(); - tick_nohz_idle_stop_tick_protected(); while (!need_resched()) { check_pgt_cache(); rmb(); if (cpu_is_offline(cpu)) { + tick_nohz_idle_stop_tick_protected(); cpuhp_report_idle_dead(); arch_cpu_idle_dead(); } @@ -241,10 +241,12 @@ static void do_idle(void) * broadcast device expired for us, we don't want to go deep * idle as we know that the IPI is going to arrive right away. */ - if (cpu_idle_force_poll || tick_check_broadcast_expired()) + if (cpu_idle_force_poll || tick_check_broadcast_expired()) { cpu_idle_poll(); - else + } else { + tick_nohz_idle_stop_tick(); cpuidle_idle_call(); + } arch_cpu_idle_exit(); } Index: linux-pm/kernel/time/tick-sched.c =================================================================== --- linux-pm.orig/kernel/time/tick-sched.c +++ linux-pm/kernel/time/tick-sched.c @@ -984,12 +984,10 @@ void tick_nohz_irq_exit(void) { struct tick_sched *ts = this_cpu_ptr(&tick_cpu_sched); - if (ts->inidle) { + if (ts->inidle) tick_nohz_start_idle(ts); - __tick_nohz_idle_stop_tick(ts); - } else { + else tick_nohz_full_update_tick(ts); - } } /**