From patchwork Fri Mar 1 18:55:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 209031 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:fa17:b0:10a:f01:a869 with SMTP id ju23csp87196dyc; Fri, 1 Mar 2024 10:57:07 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCURLju/h0CMaq5g1E0VV2RIMKAwoQ4sY70SxldKNRbR7crWb8Nuv2VHI1gt94MjDCrv9mZwGIEWXS325R94FYck/Rvc2A== X-Google-Smtp-Source: AGHT+IEu9cTX9b8Dsi68ojfiSwQMJPsKDFCdqzK19zUXB7O2+IT8xP9sEumm6C11VbNqKVm4d8Fj X-Received: by 2002:aa7:dd09:0:b0:566:d450:a362 with SMTP id i9-20020aa7dd09000000b00566d450a362mr1757058edv.24.1709319427791; Fri, 01 Mar 2024 10:57:07 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709319427; cv=pass; d=google.com; s=arc-20160816; b=JPEnhuXMdXsTjQvMhb+4mmNoExvuJFcVhOqlYkO4V/eG/63GGyS0nVnqTi9VWJIdaT yKstSyji2usJyfZdfUT62cK+Jbi9dQIn75hdxzK19sYFr3Fb+osZBoT7KXdXPNvxvPwR r8a8u1kAyLVdOOFMFzAMwhSOX9VCTrcPSifh8976D5oLBU+ivShgMITUcEdgOJbX6gwE HG9Wr3XnI37ZiG3DaVi4eXcyBXx0tiJnE9L9RoS0NxffC3Rq8VjlpMEDX+e+PfhFp5rA RWz2M9vRiJxj1h+PePGmfvGZxATrG2gyLunBp1RDxxiU9LMrZ7kVXsx/dK8FaO25eRJg IHuQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=to:from:subject:references:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:in-reply-to:date :dkim-signature; bh=GKFU1+MHZzi/z8CBZByS67OdqLWVZjwrZ1eTBs4nZzo=; fh=MPlJA1F4olXGbQrKYh4eCKo7mv0KbT183amjI+jYV78=; b=CkL1zcEW/rlRVib5BR8agTWLBB3DWO+oWT02RMtNOpbClih8FDSIyMsteU71/YMisw W3q1OePZLqhYEixX2tvvgf8jGAM5POVSVXl49itoXXJ58RJ8dcuxRN1Z1uyIOPNAgfP7 ysb/EDbZ5UekkBlyQu/nJTQAjC+3Bvs22ROLUWuqkk1CrLKBJT+lecM4meCZwE1T8XqY QFgVGkjJNRPZeAidaHCazTtkrnzN1wGIhSMSfg0lbtF023Wtm/FdBOYN5Ps69QZcN0y1 pzZl1RiVV1fNYdFNTin5E3RcKJbg0tBze8B6Css2Wf+AHPbFaeTI3S1hQrT9kgm4XC/u Mevg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=td1ebTcd; arc=pass (i=1 spf=pass spfdomain=flex--irogers.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-88960-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88960-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id q15-20020a056402518f00b00565e08477b6si1792684edd.139.2024.03.01.10.57.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 10:57:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-88960-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=td1ebTcd; arc=pass (i=1 spf=pass spfdomain=flex--irogers.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-88960-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88960-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 614101F21AB9 for ; Fri, 1 Mar 2024 18:57:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3E1473B199; Fri, 1 Mar 2024 18:56:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="td1ebTcd" Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DAE5C3A1D7 for ; Fri, 1 Mar 2024 18:56:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709319380; cv=none; b=bGSBZft0MoeYWWMWtFYiJJklmB4qnsEpoWGcMBjfYdcAQKy4XGPx14ftK7HnMFy11p9ZujiLwnpBOFRQsEE8X3tbypCiOWPZz/NtflXanvKXNucdmBrVsNw3DQupt6BS/t56x/jmcRyGCvq+e1pWVpX2lsfuxtRqAcivI2OvJ3s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709319380; c=relaxed/simple; bh=E0c1iJm+nhJFbSwna0W+hQvedFVJgQU0OfqpGYXtacY=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=QtB+kvDger/oaHMA1RniFf27aa9p0JyTsybzvwaSiPVN93Y/ddk1vkbT3kIPcCkF5yckwmuT8n0S/FcKYf0S0t6hprOvwvsy6j3QvDaQNpb6BrfnFeiQS0buU3HZgfPoVXFSyqkaIqJQ+s1tpp9NF2EMPzuXTxBXLFhJe1DIFl8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=td1ebTcd; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-608852fc324so36525067b3.2 for ; Fri, 01 Mar 2024 10:56:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709319378; x=1709924178; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=GKFU1+MHZzi/z8CBZByS67OdqLWVZjwrZ1eTBs4nZzo=; b=td1ebTcdZk28aPBKMd1V2gQC/JTGS0MXy7/ALgwf4r6Jt0yQPthZHqgitofER2UscW ng9fLcoJYkgeNahsctRIT2JrwiGzWgS9AIktuL49BMGjQrc4srGUEkD48qNsCDshyYHI Hm6cDJYVue5uRjdhoIVp7p6NEi0pjCdiTbzWv7gyR0XYKE+Sga7g42ALdRUwjX4r6sjU Barr+Fs6t6hR/O3N2Nc2UOenVlEAMXbfRKk0P/N8Ig9J6ZKOa9rYTIXAtU8FRvH+/kQ2 eCC//QJ57/k5qC8BhsIXpETi/xIRFibFd1PP9NahV5uFSGCE0V1uuYBh6I6aQh43jHKG iURg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709319378; x=1709924178; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=GKFU1+MHZzi/z8CBZByS67OdqLWVZjwrZ1eTBs4nZzo=; b=dGxtsn+G5aKZn/coaZQB19kWlWu9zf5b4N2LJfXEYyYXZVOu0kikL4eMTXRq6u0DRg CqE1T5pHdUw6Mg8+X5vyIEx+j3MLw18QBKGZKdTa8njoIHik1Ty2mslq6XYhzyYeT7L3 HN0YcCv4BWd5hPE+f5KCtqgA8nb072CkRd5Lrz7o1kz+pvwCqk9/Ai23eqOAkDGn74SL pLfxhrWMOzx8ivtNc70C6XLhxV+4kR4FtezI8zeV6x9tW3hzbORhP4ik+sKChtrdD5tv ldcjR3MOm06yCmU6v/Gcvo+5+aklIklZZylHsJEClvZbeyU6SjY/Mgnxk82Wh6uGqR5K M6/A== X-Forwarded-Encrypted: i=1; AJvYcCViwOadC7bryDkC48aR7OHGftPVPaBBQW7raMPRaCFEJGtehaiwhyt69VimyxR123NQl+BizAG7Y+24/XaUUxuwme7bxEF0Y3HsBT0M X-Gm-Message-State: AOJu0YyaS9IAOnKUsxvAKG7ZsaOPZQ7c9eAwLcHuhdlmMuhou1K1+Vyn 50YCCenw5j4D0EBtOq94rKgM1TctDufD+qnktCkGE4387t8/a9S4haFq6t3179elKmaSkTu2cMS ejlL+Zg== X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:af4b:7fc1:b7be:fcb7]) (user=irogers job=sendgmr) by 2002:a05:6902:1004:b0:dc2:3441:897f with SMTP id w4-20020a056902100400b00dc23441897fmr538112ybt.6.1709319377920; Fri, 01 Mar 2024 10:56:17 -0800 (PST) Date: Fri, 1 Mar 2024 10:55:41 -0800 In-Reply-To: <20240301185559.2661241-1-irogers@google.com> Message-Id: <20240301185559.2661241-3-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240301185559.2661241-1-irogers@google.com> X-Mailer: git-send-email 2.44.0.278.ge034bb2e1d-goog Subject: [PATCH v2 02/20] perf jevents: Add idle metric for Intel models From: Ian Rogers To: Perry Taylor , Samantha Alt , Caleb Biggers , Weilin Wang , Edward Baker , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark , John Garry , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Stephane Eranian X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792351328240327846 X-GMAIL-MSGID: 1792351328240327846 Compute using the msr PMU the percentage of wallclock cycles where the CPUs are in a low power state. Signed-off-by: Ian Rogers --- tools/perf/pmu-events/intel_metrics.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/tools/perf/pmu-events/intel_metrics.py b/tools/perf/pmu-events/intel_metrics.py index 7704c170a7db..2622d4e5ff54 100755 --- a/tools/perf/pmu-events/intel_metrics.py +++ b/tools/perf/pmu-events/intel_metrics.py @@ -1,7 +1,8 @@ #!/usr/bin/env python3 # SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) -from metric import (d_ratio, has_event, Event, JsonEncodeMetric, JsonEncodeMetricGroupDescriptions, - LoadEvents, Metric, MetricGroup, Select) +from metric import (d_ratio, has_event, max, Event, JsonEncodeMetric, + JsonEncodeMetricGroupDescriptions, LoadEvents, Metric, + MetricGroup, Select) import argparse import json import math @@ -17,6 +18,16 @@ LoadEvents(directory) interval_sec = Event("duration_time") +def Idle() -> Metric: + cyc = Event("msr/mperf/") + tsc = Event("msr/tsc/") + low = max(tsc - cyc, 0) + return Metric( + "idle", + "Percentage of total wallclock cycles where CPUs are in low power state (C1 or deeper sleep state)", + d_ratio(low, tsc), "100%") + + def Rapl() -> MetricGroup: """Processor power consumption estimate. @@ -52,6 +63,7 @@ def Rapl() -> MetricGroup: all_metrics = MetricGroup("", [ + Idle(), Rapl(), ])