Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753375AbdGJBtP (ORCPT ); Sun, 9 Jul 2017 21:49:15 -0400 Received: from mga06.intel.com ([134.134.136.31]:24495 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753305AbdGJBtN (ORCPT ); Sun, 9 Jul 2017 21:49:13 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.40,337,1496127600"; d="scan'208";a="1193388660" From: Aubrey Li To: tglx@linutronix.de, peterz@infradead.org, len.brown@intel.com, rjw@rjwysocki.net, ak@linux.intel.com, tim.c.chen@linux.intel.com, arjan@linux.intel.com, paulmck@linux.vnet.ibm.com, yang.zhang.wz@gmail.com Cc: x86@kernel.org, linux-kernel@vger.kernel.org, Aubrey Li Subject: [RFC PATCH v1 10/11] cpuidle: update cpuidle governor when needed Date: Mon, 10 Jul 2017 09:38:40 +0800 Message-Id: <1499650721-5928-11-git-send-email-aubrey.li@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1499650721-5928-1-git-send-email-aubrey.li@intel.com> References: <1499650721-5928-1-git-send-email-aubrey.li@intel.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2267 Lines: 81 From: Aubrey Li Reflect the data to cpuidle governor when there is an update --- drivers/cpuidle/cpuidle.c | 6 ++++-- include/linux/cpuidle.h | 1 + kernel/sched/idle.c | 14 ++++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c index 97aacab..9c84c5c 100644 --- a/drivers/cpuidle/cpuidle.c +++ b/drivers/cpuidle/cpuidle.c @@ -387,9 +387,11 @@ unsigned int cpuidle_predict(void) /* * Give the governor an opportunity to update on the outcome */ - cpuidle_update(drv, dev); - gov_stat = (struct cpuidle_governor_stat *)&(dev->gov_stat); + if (gov_stat->needs_update) { + cpuidle_update(drv, dev); + gov_stat->needs_update = 0; + } gov_stat->next_timer_us = ktime_to_us(tick_nohz_get_sleep_length()); get_iowait_load(&nr_iowaiters, &cpu_load); diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h index b9964ec..c6a805f 100644 --- a/include/linux/cpuidle.h +++ b/include/linux/cpuidle.h @@ -79,6 +79,7 @@ struct cpuidle_state { struct cpuidle_governor_stat { int last_state_idx; + int needs_update; unsigned int next_timer_us; unsigned int predicted_us; diff --git a/kernel/sched/idle.c b/kernel/sched/idle.c index 16a766c..3358db2 100644 --- a/kernel/sched/idle.c +++ b/kernel/sched/idle.c @@ -187,6 +187,7 @@ static void cpuidle_idle_call(void) * Give the governor an opportunity to reflect on the outcome */ cpuidle_reflect(dev, entered_state); + dev->gov_stat.needs_update = 1; } exit_idle: @@ -206,6 +207,10 @@ static void cpuidle_idle_call(void) */ static void cpuidle_fast(void) { + struct cpuidle_device *dev = cpuidle_get_device(); + ktime_t time_start, time_end; + s64 diff; + while (!need_resched()) { check_pgt_cache(); rmb(); @@ -218,7 +223,16 @@ static void cpuidle_fast(void) local_irq_disable(); arch_cpu_idle_enter(); + time_start = ns_to_ktime(local_clock()); default_idle_call(); + time_end = ns_to_ktime(local_clock()); + + diff = ktime_us_delta(time_end, time_start); + if (diff > INT_MAX) + diff = INT_MAX; + + dev->last_residency = (int) diff; + dev->gov_stat.needs_update = 1; arch_cpu_idle_exit(); } -- 2.7.4