From patchwork Fri May 30 17:10:57 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: 4272651 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.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id BCBDABEEA7 for ; Fri, 30 May 2014 17:11:11 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DD98F20270 for ; Fri, 30 May 2014 17:11:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0C58720171 for ; Fri, 30 May 2014 17:11:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933505AbaE3RLI (ORCPT ); Fri, 30 May 2014 13:11:08 -0400 Received: from mail-pa0-f42.google.com ([209.85.220.42]:35944 "EHLO mail-pa0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932378AbaE3RLI (ORCPT ); Fri, 30 May 2014 13:11:08 -0400 Received: by mail-pa0-f42.google.com with SMTP id rd3so1910787pab.15 for ; Fri, 30 May 2014 10:11:07 -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=7iYUz+jmznA9VDd+OXeZ79KmJ4DqGXKNOgteFByaP8Y=; b=CxVV1X8rbXXahcTnD/7hZS4COJ03BfRJ34HIatM6fUgEfYzIlVseMhylsuBpWPrw6u C8zZBp0qE+T6iS5jbhBIw2txYSWpLsDXC21PZQ8mA9IMAIZESoYwV7awPW2iQ9L0Au8r q4cAspncc7R2aDxKa+L4Ysu5hiqLTZa8WloVUDNINTUm6j4STKnEt3RtkGR5ImXTvd5S RAFLZptsSRKcTNum9uwctG0iVfC7WgeQflHf4Ro/7ybKQANGd0+d/JKO9imj7LzVosRO dot37e1ZVOntnXBgFkAY2nDmi+KSnAHmqI15WmK0Z8RDp+O1oAWQnIm4p8RHAdJQDkJU QwfA== X-Received: by 10.66.236.163 with SMTP id uv3mr20474089pac.18.1401469867509; Fri, 30 May 2014 10:11:07 -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 lr3sm21325794pab.4.2014.05.30.10.11.05 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 30 May 2014 10:11:06 -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] intel_pstate: Improve initial busy calculation Date: Fri, 30 May 2014 10:10:57 -0700 Message-Id: <1401469857-4908-1-git-send-email-dirk.j.brandewie@intel.com> X-Mailer: git-send-email 1.9.0 In-Reply-To: <1917099.8KOhsjZWCp@vostro.rjw.lan> References: <1917099.8KOhsjZWCp@vostro.rjw.lan> 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: Doug Smythies This change makes the busy calculation using 64 bit math which prevents overflow for large values of aperf/mperf. Cc: # 3.14.x Signed-off-by: Doug Smythies Signed-off-by: Dirk Brandewie --- drivers/cpufreq/intel_pstate.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c index 032efe4f7..c034cde 100644 --- a/drivers/cpufreq/intel_pstate.c +++ b/drivers/cpufreq/intel_pstate.c @@ -563,16 +563,19 @@ static void intel_pstate_get_cpu_pstates(struct cpudata *cpu) static inline void intel_pstate_calc_busy(struct cpudata *cpu, struct sample *sample) { - int32_t core_pct; + int64_t core_pct; + int32_t rem; - core_pct = div_fp(int_tofp((sample->aperf)), - int_tofp((sample->mperf))); - core_pct = mul_fp(core_pct, int_tofp(100)); + core_pct = int_tofp(sample->aperf) * int_tofp(100); + core_pct = div_u64_rem(core_pct, int_tofp(sample->mperf), &rem); + + if ((rem << 1) >= int_tofp((sample->mperf))) + core_pct += 1; sample->freq = fp_toint( mul_fp(int_tofp(cpu->pstate.max_pstate * 1000), core_pct)); - sample->core_pct_busy = core_pct; + sample->core_pct_busy = (int32_t)core_pct; } static inline void intel_pstate_sample(struct cpudata *cpu)