From nobody Sat Nov 30 01:31:18 2024 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) (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 2155E1448DC; Fri, 13 Sep 2024 05:21:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.17 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726204875; cv=none; b=UaELfohJLJaTLjRwJcu5DFXlYqgMZWJsDesYjPVtMJxHorI2OTMCoxshJiu4lGxXjZX/CySNa8KYV64QK9aXwsgQoNPpvcfJFk1M6pRm0/BBn+ugJBS9/lKgwAnv7eL5YAM+kJGzF0V/z97GW5fqfuoBpibu8ZmmAXC+eC9c4MI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726204875; c=relaxed/simple; bh=OPRO3Ck5Mv9JVxsIkE9GdKaKnw+uc3sa72LXbE7ZSHc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=JoFhtYQcn6DrVsUA2pEwoMbBiWIHaFG5OAaDHX5O80NBt24uVf0LhTh8dvs4MpMxSp9ze9OJC+SR4tsh+zHUGAxQWVyKZObw71iMuag7WeH59P46Dg7DK5VxnjmV7jis+5Bf5K5F1YWB5M0CuYUT4iiG28dWGxYqowpi6tdwukw= 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=lGp6q++U; arc=none smtp.client-ip=192.198.163.17 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="lGp6q++U" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1726204874; x=1757740874; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=OPRO3Ck5Mv9JVxsIkE9GdKaKnw+uc3sa72LXbE7ZSHc=; b=lGp6q++UYWB4BHdSReBQ4MtAhXgJETNujjuXt42Z56Wd1GIgyvKQ7vmF rReV3nhflvga0mglBxHHVJgXUJV/1DiT3LShZGksloALEnae2WaffmRvz vHPUvnxpg3wCXBkhAnXBQKlMDymRD7XaX+Og3lTISpXoO5xfZ7WXZPseE nWVjDoYoLJzByj3G6Z/HXHOLaVOaYPQKo06DUGJ2wh9KPfy53FNWeed9+ 2iCgKGr/4L+o92u6J70gPL5XdLu0/JECqGK5Z0+IZLC6j3d7IM2bsV7po WIsRFA6f53ldHqzik5jQ8E3kPRgEQNJrGh6pWtphOI+ZfZWZBnyYHpR7U w==; X-CSE-ConnectionGUID: KIEEb37YT+a+itoRdfI8hw== X-CSE-MsgGUID: GyadPeUzQW60y/jqnu2KlA== X-IronPort-AV: E=McAfee;i="6700,10204,11193"; a="24967762" X-IronPort-AV: E=Sophos;i="6.10,225,1719903600"; d="scan'208";a="24967762" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Sep 2024 22:21:13 -0700 X-CSE-ConnectionGUID: WVUgNk4fQoinykkXgtan6Q== X-CSE-MsgGUID: ZNgjLrlNTCqqhhw3flA/0A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,225,1719903600"; d="scan'208";a="67900597" Received: from emr.sh.intel.com ([10.112.229.56]) by fmviesa009.fm.intel.com with ESMTP; 12 Sep 2024 22:21:10 -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, Yongwei Ma , Dapeng Mi , Dapeng Mi Subject: [Patch v5 1/6] perf x86/topdown: Complete topdown slots/metrics events check Date: Fri, 13 Sep 2024 08:47:07 +0000 Message-Id: <20240913084712.13861-2-dapeng1.mi@linux.intel.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240913084712.13861-1-dapeng1.mi@linux.intel.com> References: <20240913084712.13861-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" It's not complete to check whether an event is a topdown slots or topdown metrics event by only comparing the event name since user may assign the event by RAW format, e.g. perf stat -e '{instructions,cpu/r400/,cpu/r8300/}' sleep 1 Performance counter stats for 'sleep 1': instructions cpu/r400/ cpu/r8300/ 1.002917796 seconds time elapsed 0.002955000 seconds user 0.000000000 seconds sys The RAW format slots and topdown-be-bound events are not recognized and not regroup the events, and eventually cause error. Thus add two helpers arch_is_topdown_slots()/arch_is_topdown_metrics() to detect whether an event is topdown slots/metrics event by comparing the event config directly, and use these two helpers to replace the original event name comparisons. Reviewed-by: Kan Liang Signed-off-by: Dapeng Mi --- tools/perf/arch/x86/util/evlist.c | 8 ++--- tools/perf/arch/x86/util/evsel.c | 3 +- tools/perf/arch/x86/util/topdown.c | 48 +++++++++++++++++++++++++++++- tools/perf/arch/x86/util/topdown.h | 2 ++ 4 files changed, 55 insertions(+), 6 deletions(-) diff --git a/tools/perf/arch/x86/util/evlist.c b/tools/perf/arch/x86/util/e= vlist.c index cebdd483149e..79799865a62a 100644 --- a/tools/perf/arch/x86/util/evlist.c +++ b/tools/perf/arch/x86/util/evlist.c @@ -78,14 +78,14 @@ int arch_evlist__cmp(const struct evsel *lhs, const str= uct evsel *rhs) if (topdown_sys_has_perf_metrics() && (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")) + if (arch_is_topdown_slots(lhs)) return -1; - if (strcasestr(rhs->name, "slots") && !strcasestr(rhs->name, "uops_retir= ed.slots")) + if (arch_is_topdown_slots(rhs)) return 1; /* Followed by topdown events. */ - if (strcasestr(lhs->name, "topdown") && !strcasestr(rhs->name, "topdown"= )) + if (arch_is_topdown_metrics(lhs) && !arch_is_topdown_metrics(rhs)) return -1; - if (!strcasestr(lhs->name, "topdown") && strcasestr(rhs->name, "topdown"= )) + if (!arch_is_topdown_metrics(lhs) && arch_is_topdown_metrics(rhs)) return 1; } =20 diff --git a/tools/perf/arch/x86/util/evsel.c b/tools/perf/arch/x86/util/ev= sel.c index 090d0f371891..181f2ba0bb2a 100644 --- a/tools/perf/arch/x86/util/evsel.c +++ b/tools/perf/arch/x86/util/evsel.c @@ -6,6 +6,7 @@ #include "util/pmu.h" #include "util/pmus.h" #include "linux/string.h" +#include "topdown.h" #include "evsel.h" #include "util/debug.h" #include "env.h" @@ -44,7 +45,7 @@ bool arch_evsel__must_be_in_group(const struct evsel *evs= el) strcasestr(evsel->name, "uops_retired.slots")) return false; =20 - return strcasestr(evsel->name, "topdown") || strcasestr(evsel->name, "slo= ts"); + return arch_is_topdown_metrics(evsel) || arch_is_topdown_slots(evsel); } =20 int arch_evsel__hw_name(struct evsel *evsel, char *bf, size_t size) diff --git a/tools/perf/arch/x86/util/topdown.c b/tools/perf/arch/x86/util/= topdown.c index 3f9a267d4501..49f25d67ed77 100644 --- a/tools/perf/arch/x86/util/topdown.c +++ b/tools/perf/arch/x86/util/topdown.c @@ -32,6 +32,52 @@ bool topdown_sys_has_perf_metrics(void) } =20 #define TOPDOWN_SLOTS 0x0400 +bool arch_is_topdown_slots(const struct evsel *evsel) +{ + if (evsel->core.attr.config =3D=3D TOPDOWN_SLOTS) + return true; + + return false; +} + +static int compare_topdown_event(void *vstate, struct pmu_event_info *info) +{ + int *config =3D vstate; + int event =3D 0; + int umask =3D 0; + char *str; + + if (!strcasestr(info->name, "topdown")) + return 0; + + str =3D strcasestr(info->str, "event=3D"); + if (str) + sscanf(str, "event=3D%x", &event); + + str =3D strcasestr(info->str, "umask=3D"); + if (str) + sscanf(str, "umask=3D%x", &umask); + + if (event =3D=3D 0 && *config =3D=3D (event | umask << 8)) + return 1; + + return 0; +} + +bool arch_is_topdown_metrics(const struct evsel *evsel) +{ + struct perf_pmu *pmu =3D evsel__find_pmu(evsel); + int config =3D evsel->core.attr.config; + + if (!pmu || !pmu->is_core) + return false; + + if (perf_pmu__for_each_event(pmu, false, &config, + compare_topdown_event)) + return true; + + return false; +} =20 /* * Check whether a topdown group supports sample-read. @@ -44,7 +90,7 @@ bool arch_topdown_sample_read(struct evsel *leader) if (!evsel__sys_has_perf_metrics(leader)) return false; =20 - if (leader->core.attr.config =3D=3D TOPDOWN_SLOTS) + if (arch_is_topdown_slots(leader)) return true; =20 return false; diff --git a/tools/perf/arch/x86/util/topdown.h b/tools/perf/arch/x86/util/= topdown.h index 46bf9273e572..1bae9b1822d7 100644 --- a/tools/perf/arch/x86/util/topdown.h +++ b/tools/perf/arch/x86/util/topdown.h @@ -3,5 +3,7 @@ #define _TOPDOWN_H 1 =20 bool topdown_sys_has_perf_metrics(void); +bool arch_is_topdown_slots(const struct evsel *evsel); +bool arch_is_topdown_metrics(const struct evsel *evsel); =20 #endif --=20 2.40.1