From patchwork Fri Mar 1 18:47:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 209015 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:fa17:b0:10a:f01:a869 with SMTP id ju23csp82713dyc; Fri, 1 Mar 2024 10:48:18 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUM84SA3KpHWc3yGn8PWNHF823+JdGQ5BavYHsDLfV0LDwt9Srr3B3AHV7623/LHmctm3qXNkizRvj6yXTSZxmMHWyJZw== X-Google-Smtp-Source: AGHT+IHkbfJTAp3fZjvmd4wahKAFBP5bCIYNOmfnOtLieT8mLtPXaSNFBvXUdxl02R1+iLb2FMGx X-Received: by 2002:a05:6a00:63c7:b0:6e5:d2e4:bc72 with SMTP id gi7-20020a056a0063c700b006e5d2e4bc72mr1290145pfb.8.1709318897882; Fri, 01 Mar 2024 10:48:17 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709318897; cv=pass; d=google.com; s=arc-20160816; b=uxYsE7BIX7N7chS2gA5VmSwLdL10QtLsubkjpPhqqpJl85cuSOtw/Hp6wCrhSd1oCq iWPeioy9v4aoJA7cXa139dOPaXtKURMrWmgTOvVmh+kn44fUjyr8PQsQpq79m5ASna1C tCjJdyRhHCTV383frxbB85nBj+091pvRJYd0mgP8gJEtZMf5byQ2hSM5V9MGNqFyULkz VCxw7PJBb0I/zF8FY2AEcMHlbPWvp8P0cscY6Jy3cJzlMbGQftggxMe2/UQRMTM3ZTk9 hGmGeyo2DcyqRq73O8BF5QR/pWmb5Pnj2WgYibi2VILsiu1JEuJPeU8Aky4pYEUYUHUL PK5g== 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=Pr4WIv++H0HDAnrGFLxDjHsCZ1ntGDE7FfUCE5Wa1h4=; fh=iz25i9uW9HGamPpwPIb9YcCLb/qpX5yzXUOYOmCIaWU=; b=TThyo+48MvonEc5VKWmW8DhwwKWjjFWYm1RkyH4VpRBnk0tcbZ0/2P6eap+2WZlf7M laJ/oaXkySeMpKHVDxKqSVN3z0QYqFj2BHZopnOL1eSaCflWRTgIBmlY1mPvZkvq5wui T23ecgNrkNEULJdXfoBX8jOdGhckc0DqXb4EYdOSBA/ydUyeTJ0P9oK0aaQdcGV0wKw1 Zw83VY/g8G+B7zeodEZeXehxFKj5mFQ377nrh+JubBWdDsfxgGCFLNLNPU/Gl5NxHODU xpMKE6xyDUdVpTRugbrZ8/6B7Rz6QS4FmGzmS+dwgwT/K3xdzmGz25n1+B+z7ecEuvj4 Mo4Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=1Sixqs21; 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-88938-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88938-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id ay16-20020a056a00301000b006e5ae7ddf95si2758487pfb.282.2024.03.01.10.48.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 10:48:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-88938-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=1Sixqs21; 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-88938-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88938-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id A88C028248B for ; Fri, 1 Mar 2024 18:48:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 00AF13A294; Fri, 1 Mar 2024 18:47:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="1Sixqs21" Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (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 BABDF39AF6 for ; Fri, 1 Mar 2024 18:47:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709318871; cv=none; b=SXAPiOiMEScNysBvoPBM8Z5y4m4UGDyyvZxjWaGRcXi+THJI8YV9Gy9kzYeW8vQ130zc+1b97l0XPu7BGf+vyeiyuWhO9IuaVss+x4c1SRzBeO99c2J4FrlvGlcOhNB3sLdxo9QnznOOmMI/OqVyg1NJz73pwo3TDWWlaYi1x8c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709318871; c=relaxed/simple; bh=RzPNAkcYFaWtPD0d/orbD+ZkcQxuwvwqzQzOuKyN1IE=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=eSrb+hxAde04YLPmqAhP72AK5Z/jVz8zs+RSUe/dsBys92MpXr+Ww1113vxK+48tiM2sjFEXaHNaDoD1L+/ZmwlDep9WyRLpEjFHoEKGjOV/X0QzDikBXO1XG4qVaS6uTEsTuo2DG8yrk1pp3CcwiK5t02kB4Hs/63pReIZwUiY= 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=1Sixqs21; arc=none smtp.client-ip=209.85.219.201 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-yb1-f201.google.com with SMTP id 3f1490d57ef6-dc746178515so3500027276.2 for ; Fri, 01 Mar 2024 10:47:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709318869; x=1709923669; 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=Pr4WIv++H0HDAnrGFLxDjHsCZ1ntGDE7FfUCE5Wa1h4=; b=1Sixqs21LI2Q8+b0hz22jeQsPK1Pyp9lTx6foX7/mvlu6EFagVWgAQEuXAyZ0XCcqG ZcwV+01ok3ktnDlZDOyFjV6Xxsd4mZDTwY5OzLL2pdeqv6RgLO+arZ+OE+PxvULqgK8q t6KjhC9HldfqmksE9Ago7BrxJ3Xn9r9GTis+S6+8iTJyt7gieellQSWgzbzNHZ7gYZo2 FnKX++BZL/NCfWKKxjo1yBglhKwcbxeu0PQj+WR7alTlaXYi8x5ZpAf4/0L5yIsLdtL/ aFyAQ06PiVeKpwkjAnBnF3FNsWGpExPKauxuT/yjiJgkKRGT13PyLb2JWH41SAnZ1M3i ebJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709318869; x=1709923669; 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=Pr4WIv++H0HDAnrGFLxDjHsCZ1ntGDE7FfUCE5Wa1h4=; b=JFS8pDSW07JjnPSXfQWCnOXpTnWnSnNutIPE4eIzlBsQy/+9FMHCINMhrbXHaJ09j8 A7DxWJLBofn6H4Zh9U/Gjxro0ZsGmdsS4NtbdMPWpdr4q2DvmToojttN4EYSdgznCohQ haEIOiq6iDFO0HXPI3/ub8wKv/u1cWkmPpAujBnRmEfrCMq9RKBlh4fG5DdeB5N+l81U uu+bY2dZaKgaFX4m3EDWoYvSMKQP5me1FEZHpp8D81KH7aEkUQGkjSfkM1lqfshgQDBP ZE7BFphPDDhd6qv9n7zJDZ3+PnibBDBojDmwLLNTOIQP3O+vt8oFLrJPf790Ed07/W31 AAEg== X-Forwarded-Encrypted: i=1; AJvYcCU3fiU0poWkcvlC3kkDo3LfSVRAd7WVHC9v/7kcx8gkageeRdhazs4aXBILfNYDcxt8mdlfYdcw0ZIhmK+PYcRPJlL9Q8Wrl/vRgLfR X-Gm-Message-State: AOJu0Yw9EZ7aS946PJt3+XUOirFsSIH9+prDtA7naM4HImVlraPfiK8M WBkpWSQkKyakggYU2ZcztDuYfKBh18LD6EhcCfdDFRJy8AYA1S8KyP8TmC8CGwohR9JWjBByiRo LmRZc9g== X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:af4b:7fc1:b7be:fcb7]) (user=irogers job=sendgmr) by 2002:a25:2688:0:b0:dc6:eea0:1578 with SMTP id m130-20020a252688000000b00dc6eea01578mr531960ybm.13.1709318868700; Fri, 01 Mar 2024 10:47:48 -0800 (PST) Date: Fri, 1 Mar 2024 10:47:26 -0800 In-Reply-To: <20240301184737.2660108-1-irogers@google.com> Message-Id: <20240301184737.2660108-2-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240301184737.2660108-1-irogers@google.com> X-Mailer: git-send-email 2.44.0.278.ge034bb2e1d-goog Subject: [PATCH v2 01/12] perf jevents: Add RAPL event metric for AMD zen models From: Ian Rogers To: Sandipan Das , Ravi Bangoria , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , John Garry , Kan Liang , Jing Zhang , Thomas Richter , James Clark , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Stephane Eranian X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792350772490739638 X-GMAIL-MSGID: 1792350772490739638 Add power per second metrics based on RAPL. Signed-off-by: Ian Rogers --- tools/perf/pmu-events/amd_metrics.py | 30 ++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/tools/perf/pmu-events/amd_metrics.py b/tools/perf/pmu-events/amd_metrics.py index 227f9b98c016..4016ecee6464 100755 --- a/tools/perf/pmu-events/amd_metrics.py +++ b/tools/perf/pmu-events/amd_metrics.py @@ -1,9 +1,10 @@ #!/usr/bin/env python3 # SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) -from metric import (JsonEncodeMetric, JsonEncodeMetricGroupDescriptions, LoadEvents, - MetricGroup) +from metric import (d_ratio, has_event, Event, JsonEncodeMetric, JsonEncodeMetricGroupDescriptions, + LoadEvents, Metric, MetricGroup, Select) import argparse import json +import math import os parser = argparse.ArgumentParser(description="AMD perf json generator") @@ -16,6 +17,31 @@ LoadEvents(directory) all_metrics = MetricGroup("",[]) +interval_sec = Event("duration_time") + +def Rapl() -> MetricGroup: + """Processor socket power consumption estimate. + + Use events from the running average power limit (RAPL) driver. + """ + # Watts = joules/second + # Currently only energy-pkg is supported by AMD: + # https://lore.kernel.org/lkml/20220105185659.643355-1-eranian@google.com/ + pkg = Event("power/energy\-pkg/") + cond_pkg = Select(pkg, has_event(pkg), math.nan) + scale = 2.3283064365386962890625e-10 + metrics = [ + Metric("cpu_power_pkg", "", + d_ratio(cond_pkg * scale, interval_sec), "Watts"), + ] + + return MetricGroup("cpu_power", metrics, + description="Processor socket power consumption estimates") + +all_metrics = MetricGroup("", [ + Rapl(), +]) + if args.metricgroups: print(JsonEncodeMetricGroupDescriptions(all_metrics)) else: