From patchwork Fri Mar 1 18:47:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 209027 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:fa17:b0:10a:f01:a869 with SMTP id ju23csp85292dyc; Fri, 1 Mar 2024 10:53:25 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVIycS4uFRDarvLV5F85iWm6pMu4qleBYd+TqD7vqFlOOgGb+hWzR8wAJkw8ajoxsgWapA3a8T4vHI2BlPB/EI5hdaoyg== X-Google-Smtp-Source: AGHT+IHvCi8dPx6NMJKudAzqSzr8uowH0cHbVqdVwpC2UMGJArBwsSwhZ2nNbcRDeXAIoAAChoIm X-Received: by 2002:a05:6808:201f:b0:3c1:9456:e0c5 with SMTP id q31-20020a056808201f00b003c19456e0c5mr2839413oiw.58.1709319205624; Fri, 01 Mar 2024 10:53:25 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709319205; cv=pass; d=google.com; s=arc-20160816; b=ZKJQbCqFyHKCTH9Y8/WFe3jhjAlPbjVC/zXVFAx0ZolLKfFLIsuzONPVDCYVBYWL0M UulU0H/7qFjpfllHaP2C2pjkH1pHO+JKE6oKUf1XLAW0pWvsYwRs9crupGlU7lIDiZ3U lqtoaujn569OSNInhqqpDQ7/6maDbBeyB8W/KRi2lQw0rVxDdzeILcStKMz1FIpCV1DX TzVuVEpXfMhUevEwWzJoyLNZ2AgFStZdf/MJIBp/e821vsU6AyF+BtuQjmQ+6SpcfQ99 2pdgW++kTUnghK2BCsHCDmGy8C1CxO0/sjYsFW83qytMTXCkteWjPASLhI/y9HYXXPo5 Kxzw== 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=rDmb+1G4FeL2VOjrPNtrbYg/sNUzgE2lO0wYF9ntEME=; fh=q3Eu0u6jntl3WogKo1CH+a3D85EqIwRi4kSFGUOWvuI=; b=zg6qm0iVhvoh+ff7SSGqllPfnP/LE4Z8Ho8nWxcwIWmKWKMHitH8uMW1XUlG2dFk5g bsiMvNmqerziERqjDbT+7cdL4xD4xpdH/awboXRxsLRprHxFdA351exnspIWAbBZ5T52 T7PK41NEGUNRZVvU4ogTGWjX8bKMo6CQFE8QTd/U5lBTQ5deN54irrY8bImJkqCZdIJo aZtU9QXVr4WqbLYk42kue7MqKqayXsIM3MTZUECGDwZuhHmMUh5ZSw498Ct4BLtuPXPP 0Qzb2H0vZp2tcjxQO4u/VUuHxeiPAveqhE3HqGQjEkXePUEG+hbE0/p2Ai0aiJk/fTtq cGYw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=KlnRSczW; 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-88949-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88949-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. [139.178.88.99]) by mx.google.com with ESMTPS id d17-20020a631d11000000b005d8e3a18794si4012025pgd.474.2024.03.01.10.53.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 10:53:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-88949-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=KlnRSczW; 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-88949-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88949-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 65FD52824FF for ; Fri, 1 Mar 2024 18:51:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C2B9A3A294; Fri, 1 Mar 2024 18:48:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="KlnRSczW" 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 5F8AE3D56F for ; Fri, 1 Mar 2024 18:48:15 +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=1709318896; cv=none; b=U0xgfQzkqV5rn8jPoUSAgJgQXn3M/sdWpq7NCckgKAEXQcONzqpL12X4eS+o9viO0byJkdujVVaFyUuaNbOde3qsiSHdHkJqVifX2GBTReREscidZXLwm/UJ6ABbNebzgHKTQ6z6NFNqAB5afclU2snY3uUBMswtIMJFuPt+RKA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709318896; c=relaxed/simple; bh=UwkjYK+U+f8LwVeVeyTQSJU60/nxqzY/uXtXOkioAuY=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=oYclqJZucPE1xUSl/PcrLX7SAm5wm1XnvCCf4luEYdGqKZN0KOS5fFGJuLf3baLRcpJiDW746K415diQ7eG36J7xBWoNmnmm7xvBggE2uj8d8GN4Ch8BCw0yxwmsM/W5Dq+KyM8YGx943Gx5RmY/zxEz/FInDQD8YhtN3CXa69c= 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=KlnRSczW; 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-dc743cc50a6so3228725276.2 for ; Fri, 01 Mar 2024 10:48:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709318894; x=1709923694; 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=rDmb+1G4FeL2VOjrPNtrbYg/sNUzgE2lO0wYF9ntEME=; b=KlnRSczWV9Ue3URYn+VSNWt8DdbUZdt9dwyGMTyN1+kV1Yo1nVLPyv1m3UBNaGtWSL Jf0FqqHVnjGRso4FzECrta+bQ08ZuuNamme9jE7cD8SHzDaLMeLkBo6SXQzFCVJcHA1K qcRxeNRmwoyUQBSLV7bJ1/Ns0nGdUxO4IaqXKApplrZsKmUYKXrL0U/Ay+IndTIb/ETy KQAf2pph9Yw3M7L78bXx8cWWF7kmddl8iRjB1BRf6IrBoMMiA/p6RRP3Nc+CfgOQ750r LlTUieFjno8lpOkPmio9hqF/3+OgKQ/4nQ6GTlLNDITXs+cfj8yS8++560kr/+zKWiFn Wlag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709318894; x=1709923694; 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=rDmb+1G4FeL2VOjrPNtrbYg/sNUzgE2lO0wYF9ntEME=; b=tfTq/H8tZFVyhfKY5xViPzAF+KRYSlc4sEWE6cCTk5PXIugvAzppRWaLdnG8KvtDRM 6UYiiI8P6LRWpiK/doBabDNp+/m7ODi2rkSirN/k4Fo09obH1O/eIX3U+ZtHPcwHSbqf ms5CMdNBTxlsImvFIGJZsSc4pakeiEFp70Z4liGKP7+EWAmsqmfLuCEgVjRq7FMbSFTT Ka+cRYSRyFp4a+voGhs3+RfgN6PiMNQPblOcPxJ7jIOERGmIm5eCAZYV2j0h8G3fsmAc pUlgQOTdyXEczur0njvY/PpQp55mTbwsIBhnFZFBVuL1YC6qq3Adx6//ByLYazkEAc8b okkA== X-Forwarded-Encrypted: i=1; AJvYcCVyx06jvWU/9wShrHIt1qjcTFvgzrOcj8z6aoURLKI1CHKnTVaQ77BODQjWjvTjg288ky/40BXB8p6+k4UECHyJvO7Uppc5A+zvBVaz X-Gm-Message-State: AOJu0YzHhmegCxkRh9T3dD5gMU8xchG/rPkqag18Q8Dbhc5rL6ad3Ngv 9w1GISGm4NePJeLSUh5pyKWOrVmi92ELVE/6fD7GmXOI6SrqHicyRinX/MENgtb8PX/h2YROk/8 pjnLolg== X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:af4b:7fc1:b7be:fcb7]) (user=irogers job=sendgmr) by 2002:a05:6902:1024:b0:dc2:5273:53f9 with SMTP id x4-20020a056902102400b00dc2527353f9mr93587ybt.1.1709318894486; Fri, 01 Mar 2024 10:48:14 -0800 (PST) Date: Fri, 1 Mar 2024 10:47:37 -0800 In-Reply-To: <20240301184737.2660108-1-irogers@google.com> Message-Id: <20240301184737.2660108-13-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 12/12] perf jevents: Add context switch metrics for AMD 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: 1792351095242268465 X-GMAIL-MSGID: 1792351095242268465 Metrics break down context switches for different kinds of instruction. Signed-off-by: Ian Rogers --- tools/perf/pmu-events/amd_metrics.py | 32 ++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tools/perf/pmu-events/amd_metrics.py b/tools/perf/pmu-events/amd_metrics.py index 91f323c1a149..377ce413d051 100755 --- a/tools/perf/pmu-events/amd_metrics.py +++ b/tools/perf/pmu-events/amd_metrics.py @@ -125,6 +125,37 @@ def AmdBr(): description="breakdown of retired branch instructions") +def AmdCtxSw() -> MetricGroup: + cs = Event("context\-switches") + metrics = [ + Metric("cs_rate", "Context switches per second", d_ratio(cs, interval_sec), "ctxsw/s") + ] + + ev = Event("instructions") + metrics.append(Metric("cs_instr", "Instructions per context switch", + d_ratio(ev, cs), "instr/cs")) + + ev = Event("cycles") + metrics.append(Metric("cs_cycles", "Cycles per context switch", + d_ratio(ev, cs), "cycles/cs")) + + ev = Event("ls_dispatch.ld_dispatch") + metrics.append(Metric("cs_loads", "Loads per context switch", + d_ratio(ev, cs), "loads/cs")) + + ev = Event("ls_dispatch.store_dispatch") + metrics.append(Metric("cs_stores", "Stores per context switch", + d_ratio(ev, cs), "stores/cs")) + + ev = Event("ex_ret_brn_tkn") + metrics.append(Metric("cs_br_taken", "Branches taken per context switch", + d_ratio(ev, cs), "br_taken/cs")) + + return MetricGroup("cs", metrics, + description = ("Number of context switches per second, instructions " + "retired & core cycles between context switches")) + + def AmdIlp() -> MetricGroup: tsc = Event("msr/tsc/") c0 = Event("msr/mperf/") @@ -589,6 +620,7 @@ def UncoreL3(): all_metrics = MetricGroup("", [ AmdBr(), + AmdCtxSw(), AmdIlp(), AmdDtlb(), AmdItlb(),