From nobody Sun Feb 8 17:36:28 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.19]) (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 10140CA7F; Fri, 9 Feb 2024 03:14:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707448495; cv=none; b=gj5YcnWX77fYQrVD0/xSphAD0LrIvxjmkCn2I2sd46RtwA6h/Yy7N+bOnSljJhoRlKbPUptsLaRU0m34GVGYPCQkHhhSLv9RY4ThEij6WAycd7zhXvy39wxX59vvuoMvb4+9dqTSKubeoB3EzQ4FM56qVPifq5l2dOJ7OR9rkGA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707448495; c=relaxed/simple; bh=nwvJ4bQEjdGfxAja5WB8p9z4vCfBey7kRZHlUv8cNoY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IACxRJjXL8UqG3XOYTQKlkp697zcmjP2zaAddsG7vS36mg/BYd3n7iiJy19pzHzdEKhkqXnaFI0dbvJ7+BAf6BCynQvUcSVx0AM3Qr1Ejv6Zn85aCNhKAc98VE8tJP/DCmD0zxsVPvsvkyNCrsMM4XFx6gtA9o/Vb5y7v5HW+Pw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=GrXXwEFZ; arc=none smtp.client-ip=192.198.163.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="GrXXwEFZ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1707448493; x=1738984493; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=nwvJ4bQEjdGfxAja5WB8p9z4vCfBey7kRZHlUv8cNoY=; b=GrXXwEFZTCDqS++vvYT9rQFT+PP9HfnlFc2/NUPyrZgqrmyTZWGKFgIR v7gPyojPnooKFDZO8BECWc5V5A/k3qjRBt2nOvows9FjOTZSFPMIoshhA lUieFzf/5jjEwT5SmZJLnSa89lbLfw7PUdRIxrSqjaqvcqV7CZI3B8CBG SwWbFd2xGp2hlwlhP0mZ7wuMQ+8g92SDNTMa9WUFjXiMFm/xEDPCJ0lhi c8rDARPyaPr759qF1mLq1j/HeYT7FO22kNUvlkcpqpBADb+AWzSQHBIos cdmPUT09DH6a9drc8LDb7RSgIAE09WQi4yfHjTwCf/kU3v+i0q31k6MDZ g==; X-IronPort-AV: E=McAfee;i="6600,9927,10978"; a="1257921" X-IronPort-AV: E=Sophos;i="6.05,255,1701158400"; d="scan'208";a="1257921" Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Feb 2024 19:14:48 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,255,1701158400"; d="scan'208";a="32631435" Received: from b49691a74b80.jf.intel.com ([10.165.54.183]) by orviesa002.jf.intel.com with ESMTP; 08 Feb 2024 19:14:48 -0800 From: weilin.wang@intel.com To: weilin.wang@intel.com, Ian Rogers , Kan Liang , Namhyung Kim , Arnaldo Carvalho de Melo , Peter Zijlstra , Ingo Molnar , Alexander Shishkin , Jiri Olsa , Adrian Hunter Cc: linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Perry Taylor , Samantha Alt , Caleb Biggers , Mark Rutland Subject: [RFC PATCH v4 08/15] perf stat: Add build string function and topdown events handling in hardware-grouping Date: Thu, 8 Feb 2024 19:14:34 -0800 Message-ID: <20240209031441.943012-9-weilin.wang@intel.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240209031441.943012-1-weilin.wang@intel.com> References: <20240209031441.943012-1-weilin.wang@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" From: Weilin Wang Add the function to generate final grouping strings. This function is very similar to the existing metricgroup__build_event_string() function. The difference is that the input data includes a list of grouping lists. Reviewed-by: Ian Rogers Signed-off-by: Weilin Wang --- tools/perf/util/metricgroup.c | 97 +++++++++++++++++++++++++++++++++-- 1 file changed, 93 insertions(+), 4 deletions(-) diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index f86e9a0b0d65..660c6b9b5fa7 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -1978,6 +1978,96 @@ static int assign_event_grouping(struct metricgroup_= _event_info *e, return ret; } =20 +static int hw_aware_metricgroup__build_event_string(struct list_head *grou= p_strs, + const char *modifier, + struct list_head *groups) +{ + struct metricgroup__pmu_group_list *p; + struct metricgroup__group *g; + struct metricgroup__group_events *ge; + bool no_group =3D true; + int ret =3D 0; + +#define RETURN_IF_NON_ZERO(x) do { if (x) return x; } while (0) + + list_for_each_entry(p, groups, nd) { + list_for_each_entry(g, &p->group_head, nd) { + struct strbuf *events; + struct metricgroup__group_strs *new_group_str =3D + malloc(sizeof(struct metricgroup__group_strs)); + + if (!new_group_str) + return -ENOMEM; + strbuf_init(&new_group_str->grouping_str, 0); + events =3D &new_group_str->grouping_str; + ret =3D strbuf_addch(events, '{'); + RETURN_IF_NON_ZERO(ret); + no_group =3D true; + list_for_each_entry(ge, &g->event_head, nd) { + const char *sep, *rsep, *id =3D ge->event_name; + + pr_debug("found event %s\n", id); + + /* Separate events with commas and open the group if necessary. */ + if (!no_group) { + ret =3D strbuf_addch(events, ','); + RETURN_IF_NON_ZERO(ret); + } + /* + * Encode the ID as an event string. Add a qualifier for + * metric_id that is the original name except with characters + * that parse-events can't parse replaced. For example, + * 'msr@tsc@' gets added as msr/tsc,metric-id=3Dmsr!3tsc!3/ + */ + sep =3D strchr(id, '@'); + if (sep) { + ret =3D strbuf_add(events, id, sep - id); + RETURN_IF_NON_ZERO(ret); + ret =3D strbuf_addch(events, '/'); + RETURN_IF_NON_ZERO(ret); + rsep =3D strrchr(sep, '@'); + ret =3D strbuf_add(events, sep + 1, rsep - sep - 1); + RETURN_IF_NON_ZERO(ret); + ret =3D strbuf_addstr(events, ",metric-id=3D"); + RETURN_IF_NON_ZERO(ret); + sep =3D rsep; + } else { + sep =3D strchr(id, ':'); + if (sep) { + ret =3D strbuf_add(events, id, sep - id); + RETURN_IF_NON_ZERO(ret); + } else { + ret =3D strbuf_addstr(events, id); + RETURN_IF_NON_ZERO(ret); + } + ret =3D strbuf_addstr(events, "/metric-id=3D"); + RETURN_IF_NON_ZERO(ret); + } + ret =3D encode_metric_id(events, id); + RETURN_IF_NON_ZERO(ret); + ret =3D strbuf_addstr(events, "/"); + RETURN_IF_NON_ZERO(ret); + + if (sep) { + ret =3D strbuf_addstr(events, sep + 1); + RETURN_IF_NON_ZERO(ret); + } + if (modifier) { + ret =3D strbuf_addstr(events, modifier); + RETURN_IF_NON_ZERO(ret); + } + no_group =3D false; + } + ret =3D strbuf_addf(events, "}:W"); + RETURN_IF_NON_ZERO(ret); + pr_debug("events-buf: %s\n", events->buf); + list_add_tail(&new_group_str->nd, group_strs); + } + } + return ret; +#undef RETURN_IF_NON_ZERO +} + /** * create_grouping - Create a list of groups and place all the events of * event_info_list into these groups. @@ -1989,8 +2079,8 @@ static int assign_event_grouping(struct metricgroup__= event_info *e, */ static int create_grouping(struct list_head *pmu_info_list, struct list_head *event_info_list, - struct list_head *groupings __maybe_unused, - const char *modifier __maybe_unused) + struct list_head *groupings, + const char *modifier) { int ret =3D 0; struct metricgroup__event_info *e; @@ -2006,6 +2096,7 @@ static int create_grouping(struct list_head *pmu_info= _list, if (ret) goto out; } + ret =3D hw_aware_metricgroup__build_event_string(groupings, modifier, &gr= oups); out: metricgroup__free_group_list(&groups); return ret; @@ -2035,8 +2126,6 @@ static int hw_aware_build_grouping(struct expr_parse_= ctx *ctx __maybe_unused, hashmap__for_each_entry(ctx->ids, cur, bkt) { const char *id =3D cur->pkey; =20 - pr_debug("found event %s\n", id); - ret =3D get_metricgroup_events(id, etable, &event_info_list); if (ret) goto err_out; --=20 2.42.0