From patchwork Mon Apr 4 07:23:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: plongepe X-Patchwork-Id: 8737951 Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 78AF2C0553 for ; Mon, 4 Apr 2016 07:23:30 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 532E22024F for ; Mon, 4 Apr 2016 07:23:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 58A9C2022D for ; Mon, 4 Apr 2016 07:23:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751356AbcDDHXY (ORCPT ); Mon, 4 Apr 2016 03:23:24 -0400 Received: from mga09.intel.com ([134.134.136.24]:55996 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750979AbcDDHXY (ORCPT ); Mon, 4 Apr 2016 03:23:24 -0400 Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga102.jf.intel.com with ESMTP; 04 Apr 2016 00:23:22 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.24,439,1455004800"; d="scan'208";a="777542325" Received: from tllab185.tl.intel.com ([10.102.162.170]) by orsmga003.jf.intel.com with ESMTP; 04 Apr 2016 00:23:14 -0700 From: Philippe Longepe To: linux-pm@vger.kernel.org Cc: srinivas.pandruvada@linux.intel.com, rafael@kernel.org, len.brown@intel.com Subject: [PATCH V4] intel_pstate: Use avg_pstate instead of current_pstate Date: Mon, 4 Apr 2016 09:23:36 +0200 Message-Id: <1459754617-8872-1-git-send-email-philippe.longepe@linux.intel.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Spam-Status: No, score=-7.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The result returned by pid_calc() is subtracted from current_pstate (which is the pstate requested during the last period) in order to obtain the target pstate for the current iteration. However, current_pstate may not reflect the real current P-state of the CPU. In particular, that P-state may be higher because of the frequency sharing per module. The theory is: - The load is the percentage of time spent in C0 and is related to the average frequency during the same period (We'll not have the same load at 1GHz or at 2GHz for the same task running). - The current frequency can be completely different than the average frequency (because of frequency sharing or throttling). => The frequency shift computed by the pid_calc is based on the load, so it must be applied to the frequency with which the load was measured. Using the average pstate instead of current pstate solve some migration issues (e.g when a task migrates from one core to another in the same package/module and all of the cores in there except for that particular one are basically idle). Performance and power comparison with this patch on Android: IPLoad+Avg-Pstate vs IP Load: Benchmark ?Perf ?Power FishTank 10.45% 3.1% SmartBench-Gaming -0.1% -10.4% SmartBench-Productivity -0.8% -10.4% CandyCrush n/a -17.4% AngryBirds n/a -5.9% videoPlayback n/a -13.9% audioPlayback n/a -4.9% IcyRocks-20-50 0.0% -38.4% iozone RR -0.16% -1.3% iozone RW 0.74% -1.3% Comparison with the perf algorithm: (this patch in cpu_load vs Core algorithm) Benchmark ?Perf ?Power SmartBench-Gaming -0.58% -22.8% SmartBench-Productivity 0.82% CandyCrush n/a -20.8% AngryBirds n/a -37.0% videoPlayback n/a -53.4% audioPlayback n/a -2.1% iozone RR -0.55% -13.29% iozone RW 2.22% => No regression > 1% observed and a huge power improvement! Signed-off-by: Philippe Longepe --- drivers/cpufreq/intel_pstate.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c index 4b64452..b998e1d 100644 --- a/drivers/cpufreq/intel_pstate.c +++ b/drivers/cpufreq/intel_pstate.c @@ -919,6 +919,12 @@ static inline int32_t get_avg_frequency(struct cpudata *cpu) cpu->pstate.scaling, cpu->sample.mperf); } +static inline int32_t get_avg_pstate(struct cpudata *cpu) +{ + return div64_u64(cpu->pstate.max_pstate_physical * cpu->sample.aperf, + cpu->sample.mperf); +} + static inline int32_t get_target_pstate_use_cpu_load(struct cpudata *cpu) { struct sample *sample = &cpu->sample; @@ -951,7 +957,7 @@ static inline int32_t get_target_pstate_use_cpu_load(struct cpudata *cpu) cpu_load = div64_u64(int_tofp(100) * mperf, sample->tsc); cpu->sample.busy_scaled = cpu_load; - return cpu->pstate.current_pstate - pid_calc(&cpu->pid, cpu_load); + return get_avg_pstate(cpu) - pid_calc(&cpu->pid, cpu_load); } static inline int32_t get_target_pstate_use_performance(struct cpudata *cpu)