From patchwork Thu May 29 16:32:25 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: 4266361 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 9C52E9F313 for ; Thu, 29 May 2014 16:32:47 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D6AEE20364 for ; Thu, 29 May 2014 16:32:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0E28D20351 for ; Thu, 29 May 2014 16:32:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757650AbaE2Qco (ORCPT ); Thu, 29 May 2014 12:32:44 -0400 Received: from mail-pa0-f53.google.com ([209.85.220.53]:37993 "EHLO mail-pa0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757568AbaE2Qcn (ORCPT ); Thu, 29 May 2014 12:32:43 -0400 Received: by mail-pa0-f53.google.com with SMTP id kp14so631191pab.12 for ; Thu, 29 May 2014 09:32:42 -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=mRBhKqOKK0lPCpv3Vdfa0QP5j408/g36sZCECdgsvQc=; b=LSPW+4epJStkLiyX3moyb98ObfWY07+vrVQKl0kh6x5qs8mp3al4FJZ8yZspkGNAmi PgH6cJvf/jRyZMqov7+pvlbrITPmkkxwhYhonlpaK7xjXButF7tTh4sJzDxgKbooloHU QnrGYQqNB8nReqQsGuNoCW9Q078ZMyzEvr9SlsvHE04sLc7EFbkGSNzIWuVvYjJojPMd uENe6F2IJu0dWQ0cgQKSmvyRvjX64H6SvJAn6hPgej+msc1KuIzvVjMH336Inoldp3nH mg67mvO8I8zF2iON/05wVzf1QLZ5s1lj67och9OHw8lq3aZ6e9dh0jBf5yQLXZ8tV1Bi PfUA== X-Received: by 10.66.148.70 with SMTP id tq6mr10328505pab.56.1401381162882; Thu, 29 May 2014 09:32:42 -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.41 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 May 2014 09:32:41 -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 4/4] intel_pstate: Improve initial busy calculation Date: Thu, 29 May 2014 09:32:25 -0700 Message-Id: <1401381145-17745-5-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: 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 c4dad16..774d277 100644 --- a/drivers/cpufreq/intel_pstate.c +++ b/drivers/cpufreq/intel_pstate.c @@ -556,16 +556,19 @@ static void intel_pstate_get_cpu_pstates(struct cpudata *cpu) static inline void intel_pstate_calc_busy(struct cpudata *cpu) { - struct sample *sample = &cpu->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)