From patchwork Wed Jul 25 03:41:44 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Len Brown X-Patchwork-Id: 1234541 Return-Path: X-Original-To: patchwork-linux-acpi@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 57D15DFFC0 for ; Wed, 25 Jul 2012 03:44:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933091Ab2GYDnr (ORCPT ); Tue, 24 Jul 2012 23:43:47 -0400 Received: from mail-qa0-f53.google.com ([209.85.216.53]:52413 "EHLO mail-qa0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933053Ab2GYDne (ORCPT ); Tue, 24 Jul 2012 23:43:34 -0400 Received: by mail-qa0-f53.google.com with SMTP id s11so247432qaa.19 for ; Tue, 24 Jul 2012 20:43:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references:in-reply-to:references:reply-to:organization; bh=dYmARhERQX4xYhCD0J1u6kVTavL2awVSuppCzKKM/LM=; b=v7Sj9PMATUQLjmTcqvGxc1W4SIstJfuFqVKIokLmZ7PRoumvihUCytLqKWegQj+MwR CZcdF+vz01TlNyMUPb+39uWad5RzA4OsUjBWW8R89IpSxe9jlh/6/6/Xyqg17jiZr42+ +pR5LGQgDhfkjA8N1BP4Kyf2W3INEd3aDn88jhQXdUBwR1XuFf+zF8dJ1+Mkv+RKA2B2 7wDAKtMKIAuwchvGAUqzbUhgxFhUu3h1+0kpeyyjDVaiBxEKUcgVX6MiBjSDGJ1uumI/ ZOqLRMMiPuwN6ej+AZwX7k5vogOPHB1JBi+8fZVoJGIqr0nYitO0s3HCZRveZawElq+C dnQA== Received: by 10.224.71.11 with SMTP id f11mr16740231qaj.41.1343187814569; Tue, 24 Jul 2012 20:43:34 -0700 (PDT) Received: from x980.localdomain6 (h184-61-125-197.altnnh.dsl.dynamic.tds.net. [184.61.125.197]) by mx.google.com with ESMTPS id et6sm15489186qab.8.2012.07.24.20.43.33 (version=SSLv3 cipher=OTHER); Tue, 24 Jul 2012 20:43:33 -0700 (PDT) From: Len Brown To: linux-acpi@vger.kernel.org, linux-pm@lists.linux-foundation.org Cc: linux-kernel@vger.kernel.org, Len Brown Subject: [PATCH 48/52] tools/power: turbostat: fix large c1% issue Date: Tue, 24 Jul 2012 23:41:44 -0400 Message-Id: X-Mailer: git-send-email 1.7.12.rc0 In-Reply-To: <1343187708-19532-1-git-send-email-lenb@kernel.org> References: <1343187708-19532-1-git-send-email-lenb@kernel.org> In-Reply-To: <6af1c4fc5227af65092ebc848989693562bfa3e8.1343187617.git.len.brown@intel.com> References: <6af1c4fc5227af65092ebc848989693562bfa3e8.1343187617.git.len.brown@intel.com> Reply-To: Len Brown Organization: Intel Open Source Technology Center Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org From: Len Brown Under some conditions, c1% was displayed as very large number, much higher than 100%. c1% is not measured, it is derived as "that, which is left over" from other counters. However, the other counters are not collected atomically, and so it is possible for c1% to be calaculagted as a small negative number -- displayed as very large positive. There was a check for mperf vs tsc for this already, but it needed to also include the other counters that are used to calculate c1. Signed-off-by: Len Brown --- tools/power/x86/turbostat/turbostat.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c index b815a12..861d771 100644 --- a/tools/power/x86/turbostat/turbostat.c +++ b/tools/power/x86/turbostat/turbostat.c @@ -444,6 +444,9 @@ delta_core(struct core_data *new, struct core_data *old) old->c7 = new->c7 - old->c7; } +/* + * old = new - old + */ void delta_thread(struct thread_data *new, struct thread_data *old, struct core_data *core_delta) @@ -482,19 +485,20 @@ delta_thread(struct thread_data *new, struct thread_data *old, /* - * As mperf and tsc collection are not atomic, - * it is possible for mperf's non-halted cycles + * As counter collection is not atomic, + * it is possible for mperf's non-halted cycles + idle states * to exceed TSC's all cycles: show c1 = 0% in that case. */ - if (old->mperf > old->tsc) + if ((old->mperf + core_delta->c3 + core_delta->c6 + core_delta->c7) > old->tsc) old->c1 = 0; else { /* normal case, derive c1 */ old->c1 = old->tsc - old->mperf - core_delta->c3 - core_delta->c6 - core_delta->c7; } + if (old->mperf == 0) { - if (verbose) fprintf(stderr, "cpu%d MPERF 0!\n", old->cpu_id); + if (verbose > 1) fprintf(stderr, "cpu%d MPERF 0!\n", old->cpu_id); old->mperf = 1; /* divide by 0 protection */ }