From patchwork Thu May 29 16:32:24 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: dirk.brandewie@gmail.com X-Patchwork-Id: 4266351 Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 0C7869F313 for ; Thu, 29 May 2014 16:32:45 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2E72520375 for ; Thu, 29 May 2014 16:32:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 50FDF20351 for ; Thu, 29 May 2014 16:32:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757015AbaE2Qcm (ORCPT ); Thu, 29 May 2014 12:32:42 -0400 Received: from mail-pa0-f49.google.com ([209.85.220.49]:40418 "EHLO mail-pa0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757052AbaE2Qcl (ORCPT ); Thu, 29 May 2014 12:32:41 -0400 Received: by mail-pa0-f49.google.com with SMTP id kp14so628590pab.22 for ; Thu, 29 May 2014 09:32:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=CamH9a2JWSPKpCD4gHNBMRwwMeuZGNe40a7+WSKw1BA=; b=MV9Ehbgz2DwnZSC6uFnjUz5P4sMeOcc3X6tqo1dXzv3NSIkiKIJD9hx4qOf/KG81ts CJ5qboDjfc5zrPSiSpaXJtuJnyb0kGaQ+mBLZtV5RS+1Z5GtZUz5LFyBrMIjlL/xScEd hH9eX+Dl/piTa2xeAa7yI9Y3n3l/b6Pa/04+ZBFAFSFbbqqXkfl4HCIjEzYFcwBl3oR+ gY1ah8E9v/12qBAtZVBaH4XW54NOc4tpM5o6fKVxRvmGqc29hb5jpgPZ/Gvm+8lu4lLA wRvn4QyXLJyQfHthrgoxmf4vUXe+K5cROVleabfG09UFanvIPHKX0TjA8ktaraeMBcPQ yMPA== X-Received: by 10.66.124.137 with SMTP id mi9mr10013767pab.111.1401381161033; Thu, 29 May 2014 09:32:41 -0700 (PDT) Received: from echolake.localdomain (static-50-43-42-35.bvtn.or.frontiernet.net. [50.43.42.35]) by mx.google.com with ESMTPSA id lr3sm5411991pab.4.2014.05.29.09.32.38 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 May 2014 09:32:39 -0700 (PDT) From: dirk.brandewie@gmail.com X-Google-Original-From: dirk.j.brandewie@intel.com To: linux-pm@vger.kernel.org Cc: dirk.brandewie@gmail.com, rjw@rjwysocki.net, dsmythies@telus.net, Dirk Brandewie , Subject: [PATCH 3/4] intel_pstate: add sample time scaling Date: Thu, 29 May 2014 09:32:24 -0700 Message-Id: <1401381145-17745-4-git-send-email-dirk.j.brandewie@intel.com> X-Mailer: git-send-email 1.9.0 In-Reply-To: <1401381145-17745-1-git-send-email-dirk.j.brandewie@intel.com> References: <1401381145-17745-1-git-send-email-dirk.j.brandewie@intel.com> 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.4 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham 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 From: Dirk Brandewie The PID assumes that samples are of equal time, which for a deferable timers this is not true when the system goes idle. This causes the PID to take a long time to converge to the min P state and depending on the pattern of the idle load can make the P state appear stuck. The hold-off value of three sample times before using the scaling is to give a grace period for applications that have high performance requirements and spend a lot of time idle, The poster child for this behavior is the ffmpeg benchmark in the Phoronix test suite. Cc: # 3.14.x Signed-off-by: Dirk Brandewie --- drivers/cpufreq/intel_pstate.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c index db8a992..c4dad16 100644 --- a/drivers/cpufreq/intel_pstate.c +++ b/drivers/cpufreq/intel_pstate.c @@ -58,6 +58,7 @@ struct sample { u64 aperf; u64 mperf; int freq; + ktime_t time; }; struct pstate_data { @@ -93,6 +94,7 @@ struct cpudata { struct vid_data vid; struct _pid pid; + ktime_t last_sample_time; u64 prev_aperf; u64 prev_mperf; struct sample sample; @@ -576,6 +578,8 @@ static inline void intel_pstate_sample(struct cpudata *cpu) aperf = aperf >> FRAC_BITS; mperf = mperf >> FRAC_BITS; + cpu->last_sample_time = cpu->sample.time; + cpu->sample.time = ktime_get(); cpu->sample.aperf = aperf; cpu->sample.mperf = mperf; cpu->sample.aperf -= cpu->prev_aperf; @@ -598,12 +602,24 @@ static inline void intel_pstate_set_sample_time(struct cpudata *cpu) static inline int32_t intel_pstate_get_scaled_busy(struct cpudata *cpu) { - int32_t core_busy, max_pstate, current_pstate; + int32_t core_busy, max_pstate, current_pstate, sample_ratio; + u32 duration_us; + u32 sample_time; core_busy = cpu->sample.core_pct_busy; max_pstate = int_tofp(cpu->pstate.max_pstate); current_pstate = int_tofp(cpu->pstate.current_pstate); core_busy = mul_fp(core_busy, div_fp(max_pstate, current_pstate)); + + sample_time = (pid_params.sample_rate_ms * USEC_PER_MSEC); + duration_us = (u32) ktime_us_delta(cpu->sample.time, + cpu->last_sample_time); + if (duration_us > sample_time * 3) { + sample_ratio = div_fp(int_tofp(sample_time), + int_tofp(duration_us)); + core_busy = mul_fp(core_busy, sample_ratio); + } + return core_busy; }