From patchwork Fri Feb 9 03:14:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Weilin" X-Patchwork-Id: 198737 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp607034dyd; Thu, 8 Feb 2024 19:31:25 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXBZNkJMhcpdn57unjUwCUk4LEB2yF17H+HO3USYGTGROV4nBAXamLPmZxPBIr6I2MkvnDQK/iyCEaBLZkaKDaQeyXzcQ== X-Google-Smtp-Source: AGHT+IHbHAeJ1NaWfDzJjH4LRMI/5GZ0xwCW+hzL/qRY/llGwAET4nY1XeI3tKpj/ulR1vRB+4wp X-Received: by 2002:a05:6a00:4c14:b0:6de:1d4a:c22c with SMTP id ea20-20020a056a004c1400b006de1d4ac22cmr634755pfb.0.1707449484944; Thu, 08 Feb 2024 19:31:24 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707449484; cv=pass; d=google.com; s=arc-20160816; b=fEpHf7q2KCQsRmxiIJ5KUwz5tIbULaqjfxLXZGs20D0zdHhWMvCtOlfXlAjSF/1Lux ALNmuUFvYEPXzlrL6JwnMhWoX1414bT36LJYZ0PRbYtpJ7PouzFESezhe1Cd7aQgOg2G 1eLQHMb5Tvu4fBMvFICAyGOIHBKqkYoi4iEyf50ZODpMJes/xiPA6hhFKITJ2VQW2Mw5 z5hmd+fbRBQrUOXG7sxMRkMQ0dwEvoAU4sjX5ZcK2CfUWHvfKxU8VvOE3dK+epeWVmr8 xQA/NFNoofu9JI/kc9ASujqchlPFwB5G4NKSaIeLzh23Ud7xeK5qVjvxocb2gTbWh0Am 0ANw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=EGBlgRrvlheCPt05AT04AWO6EpYk6EHtDd0PAkc3LUc=; fh=lQ72bGR/dWq5XAwlK4ZkRLvKgNzKeKRXQETwfie+yZg=; b=IGaTxbcHX62IpR31heFuzMB62+pNyKBdLpPvxsr5NJObppZ+bklnUUiiE4rtcQ+9LE ZFvOFYOMdy+Q+nTKU+Rk6VFF4n7mBpVdKYvODTYDf/4F+DOg/AnnDAPU9leJ8CY9xjxb zIDqecBOsP9+p8GghOS3Uzof1Pjod/+H0MGpzPrCJCJ1+HL+4ES4IpwTU+jqZg8zVTp7 mpqx6j9lrzyvnL2U0PSx/fw5oT7vOcRkQtrUyKWPjO26ZwI8jMqldgUGYG1/Cy0/8bxA pArKKlYKazsXQfZxQ2plVC+QN5pHmDIMivbQP1m3LHdQLved38JedQwiB8HMKy8UoDTp 17xA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ORB6GULE; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-58974-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58974-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=2; AJvYcCXVIWyG47VBtR+ZqiAfyVEJvbbbBkypay5EibkycnVVfxzUyRwltOqRFKaChtNQh+ZGmHWt0W55BV2z+8onef1K7HHF0g== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id h4-20020a056a00000400b006dff68781f7si826336pfk.0.2024.02.08.19.31.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 19:31:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58974-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ORB6GULE; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-58974-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58974-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 7426CB2977E for ; Fri, 9 Feb 2024 03:18:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6E5D836B08; Fri, 9 Feb 2024 03:15:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="ORB6GULE" 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 8909CFC19; Fri, 9 Feb 2024 03:14:54 +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=1707448496; cv=none; b=BC+XIa+PXdpdhIQxfqB9ZhBuXoyH+uek6ypPMfv7XVJScs+Esn7MpTb49hVwFk3MaFkKe3hb8ZW17SV6wLOCaxGje5PgsUFyvQsXW1MAN63a/Q59+HtaERyUaWL4aM+5tQQZwazberMPxbvNzOOhNyXz8h5yOS/L6zFTBmj1lrs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707448496; c=relaxed/simple; bh=QrlkCZNny4tWyjIwHE8jfNEOkLmWaf4ylMQufuD0nQI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=W6DFCgbz2wtfLgqkYYFFwko0o0uFNvByrgyWAEfEcO6xgmy4E+0kzMg35y8CyyJzfKRTriJd05e9rZ3IRUFURDfDPguVpS5zGoaHOgRjz/aVCOXgH91iNpGFrxZodvWIzVXq//lE24WQoioJHPueOz6vAOVuMhga9WxSk0RoPMI= 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=ORB6GULE; 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1707448495; x=1738984495; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=QrlkCZNny4tWyjIwHE8jfNEOkLmWaf4ylMQufuD0nQI=; b=ORB6GULEezVp5amF0oxTFcOWmeUhYJkNtx+7sJfkXJmyI+oX61p+tclg u7icw3W57EyXw4aEeXYpWtQb29RJ1vgCncpW/VJS/bUxc7byWYo9BnEDl X4Sww2MKA/v0TluC9oAWYVwgHeJr/ywo2DIFY6g0ZjAlwkaOy/Ii0vyRN hdSzaj5n6gu58yWu24us2V0jr4VTTHrpZf4rpsmp2sDbapld3tBwpSV/c nxpGN/l2mTujB/ss/Vn7W9QU1ytoxN4w3tjBnETtVLZZS7JlJKEUnf8eQ NfPAOIw07gbn0Mc0wZT/vcjZ3B7gr4/xNJoJfdphd/d+TvWuIjQqJX8yQ Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10978"; a="1257931" X-IronPort-AV: E=Sophos;i="6.05,255,1701158400"; d="scan'208";a="1257931" 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:49 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,255,1701158400"; d="scan'208";a="32631438" 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 09/15] perf stat: Add function to handle special events in hardware-grouping Date: Thu, 8 Feb 2024 19:14:35 -0800 Message-ID: <20240209031441.943012-10-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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790390551312807968 X-GMAIL-MSGID: 1790390551312807968 From: Weilin Wang There are some special events like topdown events and TSC that are not described in pmu-event JSON files. Add support to handle this type of events. This should be considered as a temporary solution because including these events in JSON files would be a better solution. Signed-off-by: Weilin Wang --- tools/perf/util/metricgroup.c | 38 ++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index 660c6b9b5fa7..a0579b0f81e5 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -160,6 +160,20 @@ struct metric { /* Maximum number of counters per PMU*/ #define NR_COUNTERS 16 +/* Special events that are not described in pmu-event JSON files. + * topdown-* and TSC use dedicated registers, set as free + * counter for grouping purpose + */ +enum special_events { + TOPDOWN = 0, + TSC = 1, + SPECIAL_EVENT_MAX, +}; + +static const char *const special_event_names[SPECIAL_EVENT_MAX] = { + "topdown-", + "TSC", +}; /** * An event used in a metric. This info is for metric grouping. @@ -2102,6 +2116,15 @@ static int create_grouping(struct list_head *pmu_info_list, return ret; }; +static bool is_special_event(const char *id) +{ + for (int i = 0; i < SPECIAL_EVENT_MAX; i++) { + if (!strncmp(id, special_event_names[i], strlen(special_event_names[i]))) + return true; + } + return false; +} + /** * hw_aware_build_grouping - Build event groupings by reading counter * requirement of the events and counter available on the system from @@ -2126,6 +2149,17 @@ static int hw_aware_build_grouping(struct expr_parse_ctx *ctx __maybe_unused, hashmap__for_each_entry(ctx->ids, cur, bkt) { const char *id = cur->pkey; + if (is_special_event(id)) { + struct metricgroup__event_info *event; + + event = event_info__new(id, "default_core", "0", + /*free_counter=*/true); + if (!event) + goto err_out; + + list_add(&event->nd, &event_info_list); + continue; + } ret = get_metricgroup_events(id, etable, &event_info_list); if (ret) goto err_out; @@ -2597,8 +2631,10 @@ int metricgroup__parse_groups(struct evlist *perf_evlist, ret = hw_aware_parse_groups(perf_evlist, pmu, str, metric_no_threshold, user_requested_cpu_list, system_wide, /*fake_pmu=*/NULL, metric_events, table); - if (!ret) + if (!ret) { + pr_info("Hardware aware grouping completed\n"); return 0; + } } return parse_groups(perf_evlist, pmu, str, metric_no_group, metric_no_merge,