From nobody Fri Dec 19 11:08:37 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.14]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DD2AD12E1C7; Tue, 2 Jul 2024 06:39:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719902385; cv=none; b=P/EGnt3Dfhj6OJs0FFU/Du9IMda6EwX0xUnexXc/i58+1xroj28MJbeJMcnmQxzabSCyblgKV2Kz5oaQTeXFvSKEC2Ca1paSHMLjvAhVskJkTX4qDOOfPJhpA62nNB3f99wjgRSpbGSpBetv/zbiTWxaJuJUFCq0oH9CiPCFIKM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719902385; c=relaxed/simple; bh=ZClm0i5H0Il54cRWuWGyDTiX2aGbpAZRjtMpNeIqxLM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=pIS2S9TTKzUQnZAMTpDJUM1m39PbnarUg0HZ4kEz7fRY5mzMWMuiw04sPavT3TmpYRWcf+p3+Wi+EwR7QjvwR65DUbVA1e5wG9/kkUMRFtUdB/oeTuvU+xiqT1izs5QtEbH51R+BxnFPeRpMV4w4om1KSHLYKL1xWTvGjpWjyr4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=nfdxGojK; arc=none smtp.client-ip=198.175.65.14 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="nfdxGojK" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1719902384; x=1751438384; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ZClm0i5H0Il54cRWuWGyDTiX2aGbpAZRjtMpNeIqxLM=; b=nfdxGojKfXeIh1KziKu5TDLFQxrnS7V59xBMUTn6nXURIW4XgqHqGvjc k3Rp1bptiQK7GkD602FKF8ThoijoOdkgAl+jwZj3r2OwSvgf9qZyEGaQ6 IOxXlFdFV1Tv84NkwhorUcpR+pof6eP+Gif4v6nA27zA1gGPHf8Zsahf5 L+9fDaAc63BXRTgfGnKQ4ixBYjiivN6CmV1G6nRjRX8KIOcsedj1eP2fW ayt6q7Q4LFjChJrSeIaGNtcvR1rCvEMELtubPOD8JyKuJivfQSLkGMbn+ JPgghUzYEeGsGv65T2M8CoeCwwmxnRCxqlHg8vJJTRLHWddjS1yHGtBKJ A==; X-CSE-ConnectionGUID: ArXHdOayS4yz6PpPZpgyCw== X-CSE-MsgGUID: Nshp4690RniwlQqpi3Jnog== X-IronPort-AV: E=McAfee;i="6700,10204,11120"; a="20868287" X-IronPort-AV: E=Sophos;i="6.09,178,1716274800"; d="scan'208";a="20868287" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Jul 2024 23:39:44 -0700 X-CSE-ConnectionGUID: z09Xz4fLQrymbBuPBA8HpA== X-CSE-MsgGUID: ulAMclR3Saero1o9YjqWXw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,178,1716274800"; d="scan'208";a="45926345" Received: from unknown (HELO dell-3650.sh.intel.com) ([10.239.159.147]) by orviesa009.jf.intel.com with ESMTP; 01 Jul 2024 23:39:40 -0700 From: Dapeng Mi To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Ian Rogers , Adrian Hunter , Alexander Shishkin , Kan Liang Cc: linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Yanfei Xu , Dapeng Mi , Dapeng Mi Subject: [PATCH 1/4] perf topdown: Correct leader selection with sample_read enabled Date: Wed, 3 Jul 2024 06:40:34 +0800 Message-Id: <20240702224037.343958-2-dapeng1.mi@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240702224037.343958-1-dapeng1.mi@linux.intel.com> References: <20240702224037.343958-1-dapeng1.mi@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Addresses an issue where, in the absence of a topdown metrics event within a sampling group, the slots event was incorrectly bypassed as the sampling leader when sample_read was enabled. perf record -e '{slots,branches}:S' -c 10000 -vv sleep 1 In this case, the slots event should be sampled as leader but the branches event is sampled in fact like the verbose output shows. perf_event_attr: type 4 (cpu) size 168 config 0x400 (slots) sample_type IP|TID|TIME|READ|CPU|IDENTIFIER read_format ID|GROUP|LOST disabled 1 sample_id_all 1 exclude_guest 1 ------------------------------------------------------------ sys_perf_event_open: pid -1 cpu 0 group_fd -1 flags 0x8 =3D 5 ------------------------------------------------------------ perf_event_attr: type 0 (PERF_TYPE_HARDWARE) size 168 config 0x4 (PERF_COUNT_HW_BRANCH_INSTRUCTIONS) { sample_period, sample_freq } 10000 sample_type IP|TID|TIME|READ|CPU|IDENTIFIER read_format ID|GROUP|LOST sample_id_all 1 exclude_guest 1 The sample period of slots event instead of branches event is reset to 0. This fix ensures the slots event remains the leader under these conditions. Signed-off-by: Dapeng Mi --- tools/perf/arch/x86/util/topdown.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/tools/perf/arch/x86/util/topdown.c b/tools/perf/arch/x86/util/= topdown.c index 3f9a267d4501..5d7b78eb7516 100644 --- a/tools/perf/arch/x86/util/topdown.c +++ b/tools/perf/arch/x86/util/topdown.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 #include "api/fs/fs.h" #include "util/evsel.h" +#include "util/evlist.h" #include "util/pmu.h" #include "util/pmus.h" #include "util/topdown.h" @@ -41,11 +42,22 @@ bool topdown_sys_has_perf_metrics(void) */ bool arch_topdown_sample_read(struct evsel *leader) { + struct evsel *event; + if (!evsel__sys_has_perf_metrics(leader)) return false; =20 - if (leader->core.attr.config =3D=3D TOPDOWN_SLOTS) - return true; + if (leader->core.attr.config !=3D TOPDOWN_SLOTS) + return false; + + /* + * If slots event as leader event but no topdown metric events in group, + * slots event should still sample as leader. + */ + evlist__for_each_entry(leader->evlist, event) { + if (event !=3D leader && strcasestr(event->name, "topdown")) + return true; + } =20 return false; } --=20 2.40.1 From nobody Fri Dec 19 11:08:37 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.14]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5382E145B1E; Tue, 2 Jul 2024 06:39:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719902388; cv=none; b=L78ubgXByIVEAB0PJrJRfSFlTEMQV26l3WmwoZlQZ7kZ2DbIfLBoVV+/sqLI+KzEChZIc9ej8mmTfBEjFAVc4M2Zymh7LyQcKAzgd16CGfWTrARHMopWVmVMdb3viKKd5oSHZRPbN2BySSgd+DgRmfRTDEZvIz03JiGL+AeDAfI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719902388; c=relaxed/simple; bh=t0LwNIKeDKg9+7mSznLYzFb7X6hl3ZbDp13yFvLwpIQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Hr4pzPRDdlKpXMEuYv0rEkC/UKqB/QugmXXmm5pC4V5+2dXKeYNzy+BB8SCTXt2zERilHMHL6V+djxlPyPB9DbiPmTQyU5HdqRXY8YZB8m6jU+3TrHW3q1bRBlhsTo/k0mSRUCkdEh0o0K8IjryG/a5KCCFlUG8tFDnU/oGVYEM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=CHpAsaay; arc=none smtp.client-ip=198.175.65.14 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="CHpAsaay" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1719902388; x=1751438388; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=t0LwNIKeDKg9+7mSznLYzFb7X6hl3ZbDp13yFvLwpIQ=; b=CHpAsaayuzui8ZhRgTYCFMLokOCmltK05VCn4RHyezOZZWKr7bPRPH4I yg9uCY98FzctrNt3/26ouH1dPT7qS/vCHU3PZqjs21bo77SLQ0/+Zxcrr TwDLuDrISAJ0yL4FOR6hFjkrlKUHJOs/YzKWJdscNBV8mP6iSYjPAfXDI ICzSugaHoDpxI4Q2aiJ5CjQAsjfEIgaX3mG5MJs8DUfv/JfDff0OHEFql TpTqZuheiLtXE8U7kdeVWvoY5cQmZQ6T6vHshB9WAugS6Jw0WQ2DDCTiP GF9qGM2CDhiG/3WsMI4AnBvWKg/mIesHo9cxeT2FNFFGCmy+YDDwD6xTh g==; X-CSE-ConnectionGUID: oJhRqq+PQtaIV2lL5UCxtw== X-CSE-MsgGUID: jA81FSGqSU63jVjLrtUV2Q== X-IronPort-AV: E=McAfee;i="6700,10204,11120"; a="20868300" X-IronPort-AV: E=Sophos;i="6.09,178,1716274800"; d="scan'208";a="20868300" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Jul 2024 23:39:47 -0700 X-CSE-ConnectionGUID: TvRkG8V8TDi5P/rAQPoZkw== X-CSE-MsgGUID: ZKKufPS/TCq62QnL4eFXZw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,178,1716274800"; d="scan'208";a="45926358" Received: from unknown (HELO dell-3650.sh.intel.com) ([10.239.159.147]) by orviesa009.jf.intel.com with ESMTP; 01 Jul 2024 23:39:43 -0700 From: Dapeng Mi To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Ian Rogers , Adrian Hunter , Alexander Shishkin , Kan Liang Cc: linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Yanfei Xu , Dapeng Mi , Dapeng Mi Subject: [PATCH 2/4] perf parse-events: Don't move topdown metrics events when sorting events Date: Wed, 3 Jul 2024 06:40:35 +0800 Message-Id: <20240702224037.343958-3-dapeng1.mi@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240702224037.343958-1-dapeng1.mi@linux.intel.com> References: <20240702224037.343958-1-dapeng1.mi@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" when running below perf command, we say error is reported. perf record -e "{slots,instructions,topdown-retiring}:S" -vv -C0 sleep 1 ------------------------------------------------------------ perf_event_attr: type 4 (cpu) size 168 config 0x400 (slots) sample_type IP|TID|TIME|READ|CPU|PERIOD|IDENTIFIER read_format ID|GROUP|LOST disabled 1 sample_id_all 1 exclude_guest 1 ------------------------------------------------------------ sys_perf_event_open: pid -1 cpu 0 group_fd -1 flags 0x8 =3D 5 ------------------------------------------------------------ perf_event_attr: type 4 (cpu) size 168 config 0x8000 (topdown-retiring) { sample_period, sample_freq } 4000 sample_type IP|TID|TIME|READ|CPU|PERIOD|IDENTIFIER read_format ID|GROUP|LOST freq 1 sample_id_all 1 exclude_guest 1 ------------------------------------------------------------ sys_perf_event_open: pid -1 cpu 0 group_fd 5 flags 0x8 sys_perf_event_open failed, error -22 Error: The sys_perf_event_open() syscall returned with 22 (Invalid argument) for e= vent (topdown-retiring). The reason of error is that the events are regrouped and topdown-retiring event is moved to closely after the slots event and topdown-retiring event needs to do the sampling, but Intel PMU driver doesn't support to sample topdown metrics events. For topdown metrics events, it just requires to be in a group which has slots event as leader. It doesn't require topdown metrics event must be closely after slots event. Thus it's a overkill to move topdown metrics event closely after slots event in events regrouping and furtherly cause the above issue. Thus delete the code that moving topdown metrics events to fix the issue. Signed-off-by: Dapeng Mi --- tools/perf/arch/x86/util/evlist.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tools/perf/arch/x86/util/evlist.c b/tools/perf/arch/x86/util/e= vlist.c index b1ce0c52d88d..7215c7c7b435 100644 --- a/tools/perf/arch/x86/util/evlist.c +++ b/tools/perf/arch/x86/util/evlist.c @@ -82,11 +82,6 @@ int arch_evlist__cmp(const struct evsel *lhs, const stru= ct evsel *rhs) return -1; if (strcasestr(rhs->name, "slots") && !strcasestr(rhs->name, "uops_retir= ed.slots")) return 1; - /* Followed by topdown events. */ - if (strcasestr(lhs->name, "topdown") && !strcasestr(rhs->name, "topdown"= )) - return -1; - if (!strcasestr(lhs->name, "topdown") && strcasestr(rhs->name, "topdown"= )) - return 1; } =20 /* Default ordering by insertion index. */ --=20 2.40.1 From nobody Fri Dec 19 11:08:37 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.14]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7BC89148856; Tue, 2 Jul 2024 06:39:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719902392; cv=none; b=YHna2prgVsPElUED8gJBX0UYUKTZLFaQtr3VSdxZ5D8Mlv4Mp9/5SO0HFlGA6KIU0+8ClpP2S+BBzZGlRO8iVAt0z9ULZCYVhIwjEzNm5AI8WbdV32wJqea4GhcOiMP29HeZQJVDXufb3TOv4sOh0JMWsrC2eu+da2tfcwsnbJs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719902392; c=relaxed/simple; bh=zarh+EDgol1sdirsIMupecoTuGmDTB5Wrw+1cz3ZnpI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=EUqsTvkOhpSUaGN6dQUyShTWjsM9LPxyn2srDv3Ez+1I7u/QJ6tt6KKTdLZEUgTzQ+yT2yBxOyA4ghOLu5tuVktid5FC/VX3D9Dax9lcsjMDt+n2TulemE938DSdG+XICbHBH9bkpHz1EdF/J2JH7GJYZzShVbXbwuRClY1XJ+o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=j16DEaY2; arc=none smtp.client-ip=198.175.65.14 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="j16DEaY2" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1719902391; x=1751438391; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=zarh+EDgol1sdirsIMupecoTuGmDTB5Wrw+1cz3ZnpI=; b=j16DEaY2XIIwvPCYz0pe+ZbKhipQ1wcK7eUXWqphtq5Ary8l8+Qyz2X1 oDl6Zc3xUGBsEy1KsU9HlYdvCg3HKMeB/J86uxyd5Ez72bp9rbYirkG5C 6tlr07gMZ1TvWB7qph2IKs0B6e8tYA2ZSDRc67ixg4rufMJSl6OtnmA3C Sy+2w8hbZw+QMVQu5Y+qAsxj9uH3Qru6B8FykiI3k/jmG1kNaILtmZ5Ek 1C+MOnEgaQgmJ//bsyeDf18pousJxHMfyiaPI0Cb6lp8JhXzXh+eGcnd/ hiEMVQnD05YDWYzRt+nrDkDf1svtrUtcLZobFYuDOTrEPGvNVJgM16HwQ w==; X-CSE-ConnectionGUID: 8t7hLyghQoumICakdwpAHA== X-CSE-MsgGUID: +XhpdHyWS6K4Kx6X31xAfA== X-IronPort-AV: E=McAfee;i="6700,10204,11120"; a="20868308" X-IronPort-AV: E=Sophos;i="6.09,178,1716274800"; d="scan'208";a="20868308" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Jul 2024 23:39:51 -0700 X-CSE-ConnectionGUID: 3X6BaOToQ6SS94fnsXNGMg== X-CSE-MsgGUID: Su7PP3ceTs+JWRYJaIgFXA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,178,1716274800"; d="scan'208";a="45926368" Received: from unknown (HELO dell-3650.sh.intel.com) ([10.239.159.147]) by orviesa009.jf.intel.com with ESMTP; 01 Jul 2024 23:39:47 -0700 From: Dapeng Mi To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Ian Rogers , Adrian Hunter , Alexander Shishkin , Kan Liang Cc: linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Yanfei Xu , Dapeng Mi , Dapeng Mi Subject: [PATCH 3/4] perf parse-events: Don't move slots event when no topdwon metrics event Date: Wed, 3 Jul 2024 06:40:36 +0800 Message-Id: <20240702224037.343958-4-dapeng1.mi@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240702224037.343958-1-dapeng1.mi@linux.intel.com> References: <20240702224037.343958-1-dapeng1.mi@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Currently the helper arch_evlist__cmp() would unconditionally move slots event to be the leader event even though there is no topdown metrics event in the group. perf stat -e "{instructions,slots}" -C 0 sleep 1 WARNING: events were regrouped to match PMUs Performance counter stats for 'CPU(s) 0': 27,581,148 slots 8,390,827 instructions 1.045546595 seconds time elapsed This is an overkill. It's not necessary to move slots event as the leader event if there is no topdown metrics event. Thus only regroup events when there are both topdown slots and metrics events in a group. Signed-off-by: Dapeng Mi --- tools/perf/arch/x86/util/evlist.c | 6 ++++-- tools/perf/util/evlist.h | 7 ++++++- tools/perf/util/parse-events.c | 35 ++++++++++++++++++------------- 3 files changed, 31 insertions(+), 17 deletions(-) diff --git a/tools/perf/arch/x86/util/evlist.c b/tools/perf/arch/x86/util/e= vlist.c index 7215c7c7b435..a1e78be6ebd1 100644 --- a/tools/perf/arch/x86/util/evlist.c +++ b/tools/perf/arch/x86/util/evlist.c @@ -73,9 +73,11 @@ int arch_evlist__add_default_attrs(struct evlist *evlist, return ___evlist__add_default_attrs(evlist, attrs, nr_attrs); } =20 -int arch_evlist__cmp(const struct evsel *lhs, const struct evsel *rhs) +int arch_evlist__cmp(const struct evsel *lhs, const struct evsel *rhs, voi= d *priv) { - if (topdown_sys_has_perf_metrics() && + struct sort_priv *_priv =3D priv; + + if (topdown_sys_has_perf_metrics() && _priv->topdown_metrics_in_group && (arch_evsel__must_be_in_group(lhs) || arch_evsel__must_be_in_group(rh= s))) { /* Ensure the topdown slots comes first. */ if (strcasestr(lhs->name, "slots") && !strcasestr(lhs->name, "uops_retir= ed.slots")) diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h index cb91dc9117a2..14c858dcf5a2 100644 --- a/tools/perf/util/evlist.h +++ b/tools/perf/util/evlist.h @@ -89,6 +89,11 @@ struct evsel_str_handler { void *handler; }; =20 +struct sort_priv { + int force_grouped_idx; + bool topdown_metrics_in_group; +}; + struct evlist *evlist__new(void); struct evlist *evlist__new_default(void); struct evlist *evlist__new_dummy(void); @@ -112,7 +117,7 @@ int arch_evlist__add_default_attrs(struct evlist *evlis= t, #define evlist__add_default_attrs(evlist, array) \ arch_evlist__add_default_attrs(evlist, array, ARRAY_SIZE(array)) =20 -int arch_evlist__cmp(const struct evsel *lhs, const struct evsel *rhs); +int arch_evlist__cmp(const struct evsel *lhs, const struct evsel *rhs, voi= d *priv); =20 int evlist__add_dummy(struct evlist *evlist); struct evsel *evlist__add_aux_dummy(struct evlist *evlist, bool system_wid= e); diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 6ed0f9c5581d..a3f7173a7ae2 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -1962,19 +1962,21 @@ static int evsel__compute_group_pmu_name(struct evs= el *evsel, return evsel->group_pmu_name ? 0 : -ENOMEM; } =20 -__weak int arch_evlist__cmp(const struct evsel *lhs, const struct evsel *r= hs) +__weak int arch_evlist__cmp(const struct evsel *lhs, const struct evsel *r= hs, + void *priv __maybe_unused) { /* Order by insertion index. */ return lhs->core.idx - rhs->core.idx; } =20 -static int evlist__cmp(void *_fg_idx, const struct list_head *l, const str= uct list_head *r) +static int evlist__cmp(void *_sort_priv, const struct list_head *l, const = struct list_head *r) { const struct perf_evsel *lhs_core =3D container_of(l, struct perf_evsel, = node); const struct evsel *lhs =3D container_of(lhs_core, struct evsel, core); const struct perf_evsel *rhs_core =3D container_of(r, struct perf_evsel, = node); const struct evsel *rhs =3D container_of(rhs_core, struct evsel, core); - int *force_grouped_idx =3D _fg_idx; + struct sort_priv *sort_priv =3D _sort_priv; + int force_grouped_idx =3D sort_priv->force_grouped_idx; int lhs_sort_idx, rhs_sort_idx, ret; const char *lhs_pmu_name, *rhs_pmu_name; bool lhs_has_group, rhs_has_group; @@ -1992,8 +1994,8 @@ static int evlist__cmp(void *_fg_idx, const struct li= st_head *l, const struct li lhs_sort_idx =3D lhs_core->leader->idx; } else { lhs_has_group =3D false; - lhs_sort_idx =3D *force_grouped_idx !=3D -1 && arch_evsel__must_be_in_gr= oup(lhs) - ? *force_grouped_idx + lhs_sort_idx =3D force_grouped_idx !=3D -1 && arch_evsel__must_be_in_gro= up(lhs) + ? force_grouped_idx : lhs_core->idx; } if (rhs_core->leader !=3D rhs_core || rhs_core->nr_members > 1) { @@ -2001,8 +2003,8 @@ static int evlist__cmp(void *_fg_idx, const struct li= st_head *l, const struct li rhs_sort_idx =3D rhs_core->leader->idx; } else { rhs_has_group =3D false; - rhs_sort_idx =3D *force_grouped_idx !=3D -1 && arch_evsel__must_be_in_gr= oup(rhs) - ? *force_grouped_idx + rhs_sort_idx =3D force_grouped_idx !=3D -1 && arch_evsel__must_be_in_gro= up(rhs) + ? force_grouped_idx : rhs_core->idx; } =20 @@ -2019,16 +2021,17 @@ static int evlist__cmp(void *_fg_idx, const struct = list_head *l, const struct li } =20 /* Architecture specific sorting. */ - return arch_evlist__cmp(lhs, rhs); + return arch_evlist__cmp(lhs, rhs, _sort_priv); } =20 static int parse_events__sort_events_and_fix_groups(struct list_head *list) { - int idx =3D 0, force_grouped_idx =3D -1; struct evsel *pos, *cur_leader =3D NULL; struct perf_evsel *cur_leaders_grp =3D NULL; bool idx_changed =3D false, cur_leader_force_grouped =3D false; int orig_num_leaders =3D 0, num_leaders =3D 0; + struct sort_priv sort_priv =3D {-1, false}; + int idx =3D 0; int ret; =20 /* @@ -2053,13 +2056,17 @@ static int parse_events__sort_events_and_fix_groups= (struct list_head *list) pos->core.idx =3D idx++; =20 /* Remember an index to sort all forced grouped events together to. */ - if (force_grouped_idx =3D=3D -1 && pos =3D=3D pos_leader && pos->core.nr= _members < 2 && - arch_evsel__must_be_in_group(pos)) - force_grouped_idx =3D pos->core.idx; + if (sort_priv.force_grouped_idx =3D=3D -1 && pos =3D=3D pos_leader && + pos->core.nr_members < 2 && arch_evsel__must_be_in_group(pos)) + sort_priv.force_grouped_idx =3D pos->core.idx; + + if (!sort_priv.topdown_metrics_in_group && + strcasestr(pos->name, "topdown")) + sort_priv.topdown_metrics_in_group =3D true; } =20 /* Sort events. */ - list_sort(&force_grouped_idx, list, evlist__cmp); + list_sort(&sort_priv, list, evlist__cmp); =20 /* * Recompute groups, splitting for PMUs and adding groups for events @@ -2070,7 +2077,7 @@ static int parse_events__sort_events_and_fix_groups(s= truct list_head *list) const struct evsel *pos_leader =3D evsel__leader(pos); const char *pos_pmu_name =3D pos->group_pmu_name; const char *cur_leader_pmu_name; - bool pos_force_grouped =3D force_grouped_idx !=3D -1 && + bool pos_force_grouped =3D sort_priv.force_grouped_idx !=3D -1 && arch_evsel__must_be_in_group(pos); =20 /* Reset index and nr_members. */ --=20 2.40.1 From nobody Fri Dec 19 11:08:37 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.14]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9A9DE14B97D; Tue, 2 Jul 2024 06:39:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719902395; cv=none; b=AbiB0vLAl/ZIFdRAGVQFHnxDbZVbOxM+/hq6JkFyJOM28bhTL3MEO28kG/Y0umspL3DKCM/aoMTg8f6qw3QojKxWdTRkHgTYZYFUGGx1d6m6o+zVRkWunq1jLLAuzCqFU1tHCfBX28QoQhd7uU0iIR7BYI4a2H6vpQsJ0KmYdSs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719902395; c=relaxed/simple; bh=7NPeKnDoJ/P82slpVaSMciOgj75XI6ViCTDAXn0KGrA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=SO7HQjnIc9PNUiijRv0H6fzMR+CuEth197nLGWWzrbdsisGcB1nNEwUBO05zJyosdLvrWIpCwJNssQ6H7BEOO8HCIXj16ISLhpoBZl8XvGH2Bhzwsg9pY1/TEccvW0z9uZ6ZXFvxzUNDZteNMAONbkgchKc4WWIZbH2MNY0M0Lk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=Sf9RGDO+; arc=none smtp.client-ip=198.175.65.14 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Sf9RGDO+" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1719902394; x=1751438394; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=7NPeKnDoJ/P82slpVaSMciOgj75XI6ViCTDAXn0KGrA=; b=Sf9RGDO+91C4pCOs8XqDkuIFgAFaQJWBOD2Lvhw1RTw0G8SGCpPbvy3g 3PSq6BTOjRXL3fAi59/MSinDduHQ4TqaUr3I1Feq6S3WVmNh2B7M14wZZ bpoUKEGT7Y4ntVLVqB0tNpEp0xc3+m4sRdpETVNWC9Ml5aSdcgEJJiitb QvnScDkv5P57qIf5BKZXTCIDwRFlzD/BT2I9geNa4fYRP9IL2aUWgmSmB UHXIGglzwDLLzD/HtDgMbJ0u8SLRLAsF0ceTIhjL+Pf/Y5U8UVHTnn4aq JR8nCTJtsXiaBdnjXP77AxpVIIRFUCqR4pHiQ2Y48K2tsnmHvYaSVwuSU w==; X-CSE-ConnectionGUID: Ph/4wuruTPyaaBnzUmAWwg== X-CSE-MsgGUID: RN0yfUfLQDSyneK7lyfDBw== X-IronPort-AV: E=McAfee;i="6700,10204,11120"; a="20868314" X-IronPort-AV: E=Sophos;i="6.09,178,1716274800"; d="scan'208";a="20868314" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Jul 2024 23:39:54 -0700 X-CSE-ConnectionGUID: JVYy6AcfQ3my9bBm+Ctx/g== X-CSE-MsgGUID: K9AZoyEjTwmJ4iL38u3GMw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,178,1716274800"; d="scan'208";a="45926378" Received: from unknown (HELO dell-3650.sh.intel.com) ([10.239.159.147]) by orviesa009.jf.intel.com with ESMTP; 01 Jul 2024 23:39:50 -0700 From: Dapeng Mi To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Ian Rogers , Adrian Hunter , Alexander Shishkin , Kan Liang Cc: linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Yanfei Xu , Dapeng Mi , Dapeng Mi Subject: [PATCH 4/4] perf tests: Add leader sampling test in record tests Date: Wed, 3 Jul 2024 06:40:37 +0800 Message-Id: <20240702224037.343958-5-dapeng1.mi@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240702224037.343958-1-dapeng1.mi@linux.intel.com> References: <20240702224037.343958-1-dapeng1.mi@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add leader sampling test to validate event counts are captured into record and the count value is consistent. Suggested-by: Kan Liang Signed-off-by: Dapeng Mi --- tools/perf/tests/shell/record.sh | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tools/perf/tests/shell/record.sh b/tools/perf/tests/shell/reco= rd.sh index 3d1a7759a7b2..8e3e66780fed 100755 --- a/tools/perf/tests/shell/record.sh +++ b/tools/perf/tests/shell/record.sh @@ -17,6 +17,7 @@ skip_test_missing_symbol ${testsym} =20 err=3D0 perfdata=3D$(mktemp /tmp/__perf_test.perf.data.XXXXX) +script_output=3D$(mktemp /tmp/__perf_test.perf.data.XXXXX.script) testprog=3D"perf test -w thloop" cpu_pmu_dir=3D"/sys/bus/event_source/devices/cpu*" br_cntr_file=3D"/caps/branch_counter_nr" @@ -190,11 +191,38 @@ test_branch_counter() { echo "Basic branch counter test [Success]" } =20 +test_leader_sampling() { + echo "Basic leader sampling test" + if ! perf record -o "${perfdata}" -e "{branches,branches}:Su" perf test = -w brstack 2> /dev/null + then + echo "Leader sampling [Failed record]" + err=3D1 + return + fi + index=3D0 + perf script -i "${perfdata}" > $script_output + while IFS=3D read -r line + do + # Check if the two branches counts are equal in each record + branches=3D$(echo $line | awk '{for(i=3D1;i<=3DNF;i++) if($i=3D=3D"bra= nches:") print $(i-1)}') + if [ $(($index%2)) -ne 0 ] && [ ${branches}x !=3D ${prev_branches}x ] + then + echo "Leader sampling [Failed inconsistent branches count]" + err=3D1 + return + fi + index=3D$(($index+1)) + prev_branches=3D$branches + done < $script_output + echo "Basic leader sampling test [Success]" +} + test_per_thread test_register_capture test_system_wide test_workload test_branch_counter +test_leader_sampling =20 cleanup exit $err --=20 2.40.1