From patchwork Fri Feb 9 03:14:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Weilin" X-Patchwork-Id: 198734 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp606027dyd; Thu, 8 Feb 2024 19:28:02 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUDZY2X6oS//yVBJ/n7vV4vnB1JzQcpaC5OTWS6W9npWDWZ5SbIj+LMvKBj3nwwdbKa4ZoasmqnayZwtoxXlYI4NuA1aQ== X-Google-Smtp-Source: AGHT+IGSPp0+ZPnzDJ8V+dIBQd5hEEcC9NAF1RfModNYscEhsdgDJ/P8y3faij9/BPyQmf63sAyh X-Received: by 2002:a05:6a20:ac44:b0:19e:aa16:2189 with SMTP id dh4-20020a056a20ac4400b0019eaa162189mr532835pzb.42.1707449282214; Thu, 08 Feb 2024 19:28:02 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707449282; cv=pass; d=google.com; s=arc-20160816; b=Nm6FxVDByPKa8iTMlwd8dqDgsqsiVXsxZnsYxtTevGJW9Jo/A2On0v76apR3lmfpAX NcIXoDWMez1Z3aFrKWfhdvXX/uKlVv/pEXnyVFIyZ+XHCK/9tbjVLH+BYCXtJVBTpazR Fo8lbynCb8GFa6CFEmbhzwAH11M/HDJx/ihV5WqTn6XPqt8kfdelSgnEiXOXlHjVDP5Q Ym7AXgk/0XhMYqGf64k3NLFjyq7T4PhXd58sNfqcjXo8eFnW7Ics3/gVQaKXsivqwZRq 2YnOmN8rx94WJnR6AaN4N2vKGeezPmVwSBS+KSR/zh8yYQan280IanMVBQr6XvTkNXTR 5b4g== 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=NDdGFwG3a0+EalbZ+mjkQXiXXKx5FQBgoOyrIZQQg0w=; fh=23cqvxsusgJQEOQw4Ut9JnRsDo34IXRLwZBaMrUIsWY=; b=FcXN1abdvTZihF2+9UfHLMyace1uFLZhUP2bE6j+jP9ferVf3lSsmHb3aSAKe5VmsE 4dK2G4YjLjvZ08di3GDx/0vPJKXAWK3L14v5b0SV0EH5rOCQvVaqtkbzc92FAwUSsTNr xooDXAjPDg9hQGZ6M0FC1LvTW6RV7haLJMw/NBQgXEZVdDqbJKFZwGLW3ItNYdgp00l0 OAzEceF6wfED0kE4urFrGQFZcd01+CmC/WccoqwYFjVUz9RmWsGB0MdCGiz6czwjARgS UHwWuojxfmbfHoebn4kezGF2xtvHjkAjW0x+ldrcV2ShHraNxH0yq6ytlIUHKxsAKKmn aEpg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=C6rpb2Ks; 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-58967-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58967-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=2; AJvYcCXjNxb46UaDVcz2LiJd0ClRUXi+kHKU780QR54QHiA95rgmMzsbNNyUIol40ZzD5kvlWjftAkWD+Up24hytRaSnQ4VftQ== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id e4-20020a17090a804400b00296eea36704si834845pjw.35.2024.02.08.19.28.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 19:28:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58967-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=C6rpb2Ks; 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-58967-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58967-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 166B6B27F0C for ; Fri, 9 Feb 2024 03:15:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 323A8F510; Fri, 9 Feb 2024 03:14:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="C6rpb2Ks" 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 386144C6F; Fri, 9 Feb 2024 03:14:48 +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=1707448491; cv=none; b=uQGumUzI7KnbNoCFXd3L5Vb/h1QHatKHNz3qg53VxBY9revm6znP62UxNaDTqbph4kLDa993V7ITCIH6EbQt40cTyZuDDW1f0h0KDUT55RbR4K0N/42uyP7gCDmnkL3d2WB7i3G6buYBX4Nwx61qMzdHgodga1zsVuAUR4bAc0w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707448491; c=relaxed/simple; bh=eIAG1lzH2RfVMJ7M1xyrOqwbKw0bArWx7n920cAVzVs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=H0aB33fujvyJRFmq+VIJUZuQ+ZArEHcIgmOo+3eqO2WZdNJkEYilMNUWHkDEltR7Y61OLpMdTzWxGWoifhkerN3t8y3kBq44ojQimgeC69ZNxAeV/RMzfYJwxj4MwReoh9tP8lHj3y9gcmJZ2ug8Dt01zMije9YCbC8Dw648CPE= 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=C6rpb2Ks; 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=1707448489; x=1738984489; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=eIAG1lzH2RfVMJ7M1xyrOqwbKw0bArWx7n920cAVzVs=; b=C6rpb2KsTN8biYoEuNKkES23bVx/kEGinN2MRJX3c/YyXLLZqk0nr8Yb Q3woLNgHYQTSpRFUmacu3c5+IE29tTYAkW/AXGv6dnzfs+UAHWLWKz5Ud s0TkCBPEQj8wwIcSWgaeuWz84CePZZitN6r98Y/D4F6FijzzMPcedaNqC qsmiH9qDTwUxo9ABn6/OLSo7tOqddRooWO2RGrImRiZjgGAqnGo0e18XP jrxnvsV2DXCY2FU1M7ZJE0nr7g/bcq8q6LzAwIUulpU1uXrceBKRWWcQF Y3F6F8EVutSM3c0R4R+ju3Y5UyWs9lap99PABe/vDE7vPH00OigV4XzTp A==; X-IronPort-AV: E=McAfee;i="6600,9927,10978"; a="1257875" X-IronPort-AV: E=Sophos;i="6.05,255,1701158400"; d="scan'208";a="1257875" 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:47 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,255,1701158400"; d="scan'208";a="32631404" Received: from b49691a74b80.jf.intel.com ([10.165.54.183]) by orviesa002.jf.intel.com with ESMTP; 08 Feb 2024 19:14:47 -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 01/15] perf stat: Add new field in stat_config to enable hardware aware grouping. Date: Thu, 8 Feb 2024 19:14:27 -0800 Message-ID: <20240209031441.943012-2-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: 1790390338633787386 X-GMAIL-MSGID: 1790390338633787386 From: Weilin Wang Hardware counter and event information could be used to help creating event groups that better utilize hardware counters and improve multiplexing. Reviewed-by: Ian Rogers Signed-off-by: Weilin Wang --- tools/perf/builtin-stat.c | 5 +++++ tools/perf/util/metricgroup.c | 5 +++++ tools/perf/util/metricgroup.h | 1 + tools/perf/util/stat.h | 1 + 4 files changed, 12 insertions(+) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 5fe9abc6a524..d08a40c4bae1 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -2062,6 +2062,7 @@ static int add_default_attributes(void) stat_config.metric_no_threshold, stat_config.user_requested_cpu_list, stat_config.system_wide, + stat_config.hardware_aware_grouping, &stat_config.metric_events); } @@ -2095,6 +2096,7 @@ static int add_default_attributes(void) stat_config.metric_no_threshold, stat_config.user_requested_cpu_list, stat_config.system_wide, + stat_config.hardware_aware_grouping, &stat_config.metric_events); } @@ -2129,6 +2131,7 @@ static int add_default_attributes(void) /*metric_no_threshold=*/true, stat_config.user_requested_cpu_list, stat_config.system_wide, + stat_config.hardware_aware_grouping, &stat_config.metric_events) < 0) return -1; } @@ -2170,6 +2173,7 @@ static int add_default_attributes(void) /*metric_no_threshold=*/true, stat_config.user_requested_cpu_list, stat_config.system_wide, + stat_config.hardware_aware_grouping, &stat_config.metric_events) < 0) return -1; @@ -2702,6 +2706,7 @@ int cmd_stat(int argc, const char **argv) stat_config.metric_no_threshold, stat_config.user_requested_cpu_list, stat_config.system_wide, + stat_config.hardware_aware_grouping, &stat_config.metric_events); zfree(&metrics); diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index ca3e0404f187..18df1af4bdd3 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -1690,12 +1690,17 @@ int metricgroup__parse_groups(struct evlist *perf_evlist, bool metric_no_threshold, const char *user_requested_cpu_list, bool system_wide, + bool hardware_aware_grouping, struct rblist *metric_events) { const struct pmu_metrics_table *table = pmu_metrics_table__find(); if (!table) return -EINVAL; + if (hardware_aware_grouping) { + pr_debug("Use hardware aware grouping instead of traditional metric grouping method\n"); + } + return parse_groups(perf_evlist, pmu, str, metric_no_group, metric_no_merge, metric_no_threshold, user_requested_cpu_list, system_wide, diff --git a/tools/perf/util/metricgroup.h b/tools/perf/util/metricgroup.h index d5325c6ec8e1..779f6ede1b51 100644 --- a/tools/perf/util/metricgroup.h +++ b/tools/perf/util/metricgroup.h @@ -77,6 +77,7 @@ int metricgroup__parse_groups(struct evlist *perf_evlist, bool metric_no_threshold, const char *user_requested_cpu_list, bool system_wide, + bool hardware_aware_grouping, struct rblist *metric_events); int metricgroup__parse_groups_test(struct evlist *evlist, const struct pmu_metrics_table *table, diff --git a/tools/perf/util/stat.h b/tools/perf/util/stat.h index 4357ba114822..a7798506465b 100644 --- a/tools/perf/util/stat.h +++ b/tools/perf/util/stat.h @@ -86,6 +86,7 @@ struct perf_stat_config { bool metric_no_group; bool metric_no_merge; bool metric_no_threshold; + bool hardware_aware_grouping; bool stop_read_counter; bool iostat_run; char *user_requested_cpu_list; From patchwork Fri Feb 9 03:14:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Weilin" X-Patchwork-Id: 198724 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp602914dyd; Thu, 8 Feb 2024 19:17:21 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWoBhL1js+mOn3JoWHyE9+1LiAC2CjoIZxYVuz3ID6WVFR/u61Ztbv3sY7mm6KkV4+etWTh3OWQulLDJ0leX4tckwpgQQ== X-Google-Smtp-Source: AGHT+IEKbbhYoAwxaN/2MK6CTZhU9XsPNJR26stlmVebyHET/jjHVzhRwQJnl/tz8Gq4gIv3pP0E X-Received: by 2002:a05:622a:649:b0:42c:1f5c:127a with SMTP id a9-20020a05622a064900b0042c1f5c127amr486917qtb.68.1707448641192; Thu, 08 Feb 2024 19:17:21 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707448641; cv=pass; d=google.com; s=arc-20160816; b=tOhJQKDH17W2ZMbjOOl2h8LswBby+SPaOWGzo7MIHC9IDOC3YXiUy9KSwzAAiyrQtj 1LDOJPU9guFe00mdPOX1EFLPl6upQ3/ifwA9tj0svcYUwzsoW9lPx54xNHXY0nTtQG2g qkj08dQAC1aLotSrY87YTOol7hHuFgzisdvx3g0bToKBY6ikA0Cry1eTKX+a65Xab20A m4e+QVgTDZ0VdJpf76L/oxxkPfzy57oLizJ94YDGze0u5ZObAopZWOixGn6m5gWEwqYg XaO8g1IZ6QVaz2Rjvd4Mxm8rKAB3ZHHWydc1P2HaaHdhUmXpaJsZDTF4SujT0sY/EZiC Mlzg== 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=SGsGpaSubEJ83LAwygWfIy5onY+sGGc0HKsu+rcwHng=; fh=EBb6GaV5ymEwkwFy9yociQAIC/5Mm4omkO1GerW4568=; b=oC12LrZObK1fM6mOeQy4YnF35KiTDwW8VEkFFkUMks0AjTuE8pukU57LVYf3oSRWXP F0xOAj7qijuisQkDmxDSgPvlvud+rTHE8mJbVMLHivt1v3Yfy9it5p63+bRHkWy2ITg0 vGcK634UnmVBiP0EvpNV3sUeBiDgBQA9pIpznCIIb8nsFwwLnFGm7/hRqlO2yYeU/s3x wYi/GtgL8FIyKuHfpNnmDQeKGft7NnvKm1VKgH+UchGNOV+9PvK72Swvff3QjZ+z+VJ5 6Bt+wx+CAdx2sh6E9I8pXh9rSfyRzBzMaHKBQomgGYRf6iPPlvexO9iQzt2acYOOga22 lPiQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=b0P4bLkC; 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-58969-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58969-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=2; AJvYcCWKGT77RcAvOxElt9K/uQdqRcX9FP3Vq6SyXuAmGHKvphHyXHtd3l8hMOttKqe8ggGUFxtqh5w+jCnRsDzk2SGlG8pGdw== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id f6-20020ac859c6000000b0042bf69979f1si913918qtf.419.2024.02.08.19.17.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 19:17:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58969-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=b0P4bLkC; 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-58969-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58969-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 1CEFC1C26847 for ; Fri, 9 Feb 2024 03:16:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1EBFC1DDCE; Fri, 9 Feb 2024 03:14:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="b0P4bLkC" 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 495A64C92; Fri, 9 Feb 2024 03:14:50 +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=1707448492; cv=none; b=mwDqDLchTHinZDaWv7Pq04b5FGXuefc4dqUI4+ywNBaMJPlsp6me7iAyVCwji3SpWd+tpVMGM0su1c+7K+Fj48q+pHQxzOd6CyQcktqPDqylHcpibdasFyD8e5G6E7bLD6l7Umdkjr6xgHjCcs/pgIkPMTN4C/wHao2l3ytAUhU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707448492; c=relaxed/simple; bh=YkcdAzNWIFPX0/ELSP1ZgYTdwPdrUl8xdN68jdAHQys=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dSCbA+XPy4pR2xf9vISr1tElG5r9PfAqiGbJNZp7usoj+hKskXbqlfQdO2xjr2pDb4EYOXafcU+Lr/bKXlorURm3tWITyoI9Ak0xbwNJx+6vuKo62bUnP07ykTIOpPjkILVUvW9tzgKT1NTtuo0fRdAyTZ/yiW7ChrWUt10ydg0= 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=b0P4bLkC; 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=1707448491; x=1738984491; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=YkcdAzNWIFPX0/ELSP1ZgYTdwPdrUl8xdN68jdAHQys=; b=b0P4bLkCijz+Xq4gOXhXDcvDJI2hbTEoBUYwpxT0ErIGpErFUbMGv0ot 4DNAvZpGM7JZFja8qyYA9/5dG0IctDexUduDVQb7zVhIRNE9bSI4P7xxH cjfwfesrj1eb+KsSwC0bVgVaXHdRROE9zY97mrI9CgbX8u+cKmZGN8OIQ yu/uPI2t3eTxcgqV6bXyChBRM1RQ4u6QGSHgRQlzNnOmKhM+zwUvMfxAO cWtW8HhTBmX/KpMU7f9r2IU7TWi9Ho2i3XyhuSRHuXhJnYyZAaySLVCOY rGmF1SpgNM6X3TbSA5ySfEDyqSpNBlhAdYNI9652BkeRABkv68ITbEVqv w==; X-IronPort-AV: E=McAfee;i="6600,9927,10978"; a="1257881" X-IronPort-AV: E=Sophos;i="6.05,255,1701158400"; d="scan'208";a="1257881" 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="32631409" Received: from b49691a74b80.jf.intel.com ([10.165.54.183]) by orviesa002.jf.intel.com with ESMTP; 08 Feb 2024 19:14:47 -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 02/15] perf stat: Add basic functions for the hardware aware grouping Date: Thu, 8 Feb 2024 19:14:28 -0800 Message-ID: <20240209031441.943012-3-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: 1790389666611064475 X-GMAIL-MSGID: 1790389666611064475 From: Weilin Wang Add the first set of functions for the hardware aware grouping method. Function hw_aware_parse_groups() is the entry point of this metric grouping method. It does metric grouping on a combined list of events and will create a list of grouping strings as final results of the grouping method. These grouping strings will be used in the same manner as existing metric grouping process. This method will fall back to normal grouping when hardware aware grouping return with err so that perf stat still executes and returns with correct result. Signed-off-by: Weilin Wang --- tools/perf/util/metricgroup.c | 218 +++++++++++++++++++++++++++++++++- 1 file changed, 217 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index 18df1af4bdd3..ee638578afdd 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -157,6 +157,14 @@ struct metric { struct evlist *evlist; }; +/** + * Each group is one node in the group string list. + */ +struct metricgroup__group_strs { + struct list_head nd; + struct strbuf grouping_str; +}; + static void metric__watchdog_constraint_hint(const char *name, bool foot) { static bool violate_nmi_constraint; @@ -1432,6 +1440,101 @@ static int build_combined_expr_ctx(const struct list_head *metric_list, return ret; } +/** + * hw_aware_build_grouping - Build event groupings by reading counter + * requirement of the events and counter available on the system from + * pmu-events. + * @ctx: the event identifiers parsed from metrics. + * @groupings: header to the list of final event grouping. + * @modifier: any modifiers added to the events. + */ +static int hw_aware_build_grouping(struct expr_parse_ctx *ctx __maybe_unused, + struct list_head *groupings __maybe_unused, + const char *modifier __maybe_unused) +{ + int ret = 0; + + pr_debug("This is a placeholder\n"); + return ret; +} + +static void group_str_free(struct metricgroup__group_strs *g) +{ + if (!g) + return; + + strbuf_release(&g->grouping_str); + free(g); +} + +static void metricgroup__free_grouping_strs(struct list_head + *grouping_strs) +{ + struct metricgroup__group_strs *g, *tmp; + + list_for_each_entry_safe(g, tmp, grouping_strs, nd) { + list_del_init(&g->nd); + group_str_free(g); + } +} + +/** + * hw_aware_parse_ids - Build the event string for the ids and parse them + * creating an evlist. The encoded metric_ids are decoded. Events are placed + * into groups based on event counter requirements and counter availabilities of + * the system. + * @metric_no_merge: is metric sharing explicitly disabled. + * @fake_pmu: used when testing metrics not supported by the current CPU. + * @ids: the event identifiers parsed from a metric. + * @modifier: any modifiers added to the events. + * @out_evlist: the created list of events. + */ +static int hw_aware_parse_ids(struct perf_pmu *fake_pmu, + struct expr_parse_ctx *ids, const char *modifier, + struct evlist **out_evlist) +{ + struct parse_events_error parse_error; + struct evlist *parsed_evlist; + LIST_HEAD(groupings); + struct metricgroup__group_strs *group; + int ret; + + *out_evlist = NULL; + ret = hw_aware_build_grouping(ids, &groupings, modifier); + if (ret) { + metricgroup__free_grouping_strs(&groupings); + return ret; + } + + parsed_evlist = evlist__new(); + if (!parsed_evlist) { + ret = -ENOMEM; + goto err_out; + } + list_for_each_entry(group, &groupings, nd) { + struct strbuf *events = &group->grouping_str; + + pr_debug("Parsing metric events '%s'\n", events->buf); + parse_events_error__init(&parse_error); + ret = __parse_events(parsed_evlist, events->buf, /*pmu_filter=*/NULL, + &parse_error, fake_pmu, /*warn_if_reordered=*/false); + if (ret) { + parse_events_error__print(&parse_error, events->buf); + goto err_out; + } + ret = decode_all_metric_ids(parsed_evlist, modifier); + if (ret) + goto err_out; + } + *out_evlist = parsed_evlist; + parsed_evlist = NULL; +err_out: + parse_events_error__exit(&parse_error); + evlist__delete(parsed_evlist); + metricgroup__free_grouping_strs(&groupings); + return ret; +} + /** * parse_ids - Build the event string for the ids and parse them creating an * evlist. The encoded metric_ids are decoded. @@ -1520,6 +1623,114 @@ static int parse_ids(bool metric_no_merge, struct perf_pmu *fake_pmu, return ret; } +static int hw_aware_parse_groups(struct evlist *perf_evlist, + const char *pmu, const char *str, + bool metric_no_threshold, + const char *user_requested_cpu_list, + bool system_wide, + struct perf_pmu *fake_pmu, + struct rblist *metric_events_list, + const struct pmu_metrics_table *table) +{ + struct evlist *combined_evlist = NULL; + LIST_HEAD(metric_list); + struct metric *m; + int ret; + bool metric_no_group = false; + bool metric_no_merge = false; + + if (metric_events_list->nr_entries == 0) + metricgroup__rblist_init(metric_events_list); + ret = metricgroup__add_metric_list(pmu, str, metric_no_group, metric_no_threshold, + user_requested_cpu_list, + system_wide, &metric_list, table); + if (ret) + goto out; + + /* Sort metrics from largest to smallest. */ + list_sort(NULL, &metric_list, metric_list_cmp); + + if (!metric_no_merge) { + struct expr_parse_ctx *combined = NULL; + + ret = build_combined_expr_ctx(&metric_list, &combined); + + if (!ret && combined && hashmap__size(combined->ids)) { + ret = hw_aware_parse_ids(fake_pmu, combined, + /*modifier=*/NULL, + &combined_evlist); + } + + if (ret) + goto out; + + if (combined) + expr__ctx_free(combined); + } + + list_for_each_entry(m, &metric_list, nd) { + struct metric_expr *expr; + struct metric_event *me; + struct evsel **metric_events; + + ret = setup_metric_events(fake_pmu ? "all" : m->pmu, m->pctx->ids, + combined_evlist, &metric_events); + if (ret) { + pr_debug("Cannot resolve IDs for %s: %s\n", + m->metric_name, m->metric_expr); + goto out; + } + + me = metricgroup__lookup(metric_events_list, metric_events[0], true); + + expr = malloc(sizeof(struct metric_expr)); + if (!expr) { + ret = -ENOMEM; + free(metric_events); + goto out; + } + + expr->metric_refs = m->metric_refs; + m->metric_refs = NULL; + expr->metric_expr = m->metric_expr; + if (m->modifier) { + char *tmp; + + if (asprintf(&tmp, "%s:%s", m->metric_name, m->modifier) < 0) + expr->metric_name = NULL; + else + expr->metric_name = tmp; + } else { + expr->metric_name = strdup(m->metric_name); + } + + if (!expr->metric_name) { + ret = -ENOMEM; + free(metric_events); + goto out; + } + expr->metric_threshold = m->metric_threshold; + expr->metric_unit = m->metric_unit; + expr->metric_events = metric_events; + expr->runtime = m->pctx->sctx.runtime; + list_add(&expr->nd, &me->head); + } + + if (combined_evlist) { + evlist__splice_list_tail(perf_evlist, &combined_evlist->core.entries); + evlist__delete(combined_evlist); + } + + list_for_each_entry(m, &metric_list, nd) { + if (m->evlist) + evlist__splice_list_tail(perf_evlist, &m->evlist->core.entries); + } + +out: + metricgroup__free_metrics(&metric_list); + return ret; +} + static int parse_groups(struct evlist *perf_evlist, const char *pmu, const char *str, bool metric_no_group, @@ -1698,10 +1909,15 @@ int metricgroup__parse_groups(struct evlist *perf_evlist, if (!table) return -EINVAL; if (hardware_aware_grouping) { + int ret; pr_debug("Use hardware aware grouping instead of traditional metric grouping method\n"); + 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) + return 0; } - return parse_groups(perf_evlist, pmu, str, metric_no_group, metric_no_merge, metric_no_threshold, user_requested_cpu_list, system_wide, /*fake_pmu=*/NULL, metric_events, table); From patchwork Fri Feb 9 03:14:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Weilin" X-Patchwork-Id: 198726 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp603063dyd; Thu, 8 Feb 2024 19:17:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IE+jb2KmQMqnd9tpw7Ec5DMFOl8/hUdEihO4bx7xgtkmCcF3dylZ0HefL03LfRtXkwwzfrL X-Received: by 2002:a05:6a21:164a:b0:19c:a00c:f1f8 with SMTP id no10-20020a056a21164a00b0019ca00cf1f8mr679764pzb.23.1707448676678; Thu, 08 Feb 2024 19:17:56 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707448676; cv=pass; d=google.com; s=arc-20160816; b=V3oS8COcESPaPV9mHxIbmIQI3xJPdJucFFs4oHsChem6Q35xf8gfa650rtddJiN+bU ne9EcgkG6WNw8Rx9T9pu+67L2EjM8852Er3oNUQidr8R3EE1pcSyExacUWqP0o0pOVvQ cJHW+N4a1xzEyigQFOjZLo4Ct+57l83Um43AnI59CWD3qj5H6tp0+lCuhgqI5sIu+9UL dc0tGBtzjy4RZUXg7LYtKX1+/e5r3zO/zx6Wf/cJGoPYNcA8rBQ0RyT1SqS/VvGYiDqB 7/v6WzfQ+JfLkH1fN6QM/HsPJpoFg5raFSYkCvJRcFXREZup+vmkdmn2sdS079Ndw+U6 omIA== 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=iGqsgYsvTJYGCQH7ZqBFl8ZV/wahuHL5OEZtjGCR8+Q=; fh=xxs8akDBibhWNGyEFzers4AU58aLdyOzPqIzzynasTg=; b=0/6ys0A/k6qZESsl/9z57bGc6M2XPSUW8y3y696k1peU0HxHWNpZZa+EIRcA9BKhE8 806kdNsyaH7nlIk+kkzRWgPLLAS2VF0Ox8Ky4w5ScMwYZFSWEKC8O33rHzQ2CHZroOBx ZCDJ6zMhm6Pr2fOSsFEJAoCZJbT85DKAjfxHkC7o7jJm87AVte6zmfJqCGwHHOcf0sY3 cYeUdW4pA3OfoIpotuj7EZ9wIOj1YjXcGR5ZKf0BviG7xOSpCf6EaS5/BA+Jz53rKu1L rTbDkSXPjAdaOWZEyNggfI3CQVYuXPyEExBPRzoJDsDZX/NfcEp6ZoxPeY/T22orqYan TW5w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=NqzApKXV; 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-58968-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58968-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=2; AJvYcCXHgs8/57RgVcoNfUuDa/MvIrmrIvY89UoSoOXIcYbzyLmLKnIfnmkR+Dcxlxc5JeamVupNRGpXO7N76fk/SS5Rw9VyUw== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id b17-20020a637151000000b005cdf801a27dsi883102pgn.198.2024.02.08.19.17.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 19:17:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58968-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=@intel.com header.s=Intel header.b=NqzApKXV; 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-58968-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58968-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 6F16C284EBB for ; Fri, 9 Feb 2024 03:17:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3DBEF28370; Fri, 9 Feb 2024 03:14:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="NqzApKXV" 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 36FB04C89; Fri, 9 Feb 2024 03:14:50 +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=1707448492; cv=none; b=eXreRUxp1FSQaEnT+d7iUtmF4Lm3odsuSTuGO4x36ZX4MmCk1XAZG5QSkHZ6vG6CkPSULCYLncyjEBJhuJyM39Pwnp1IIPQY8LzYUxvAqC3sVYChWx/2nwyUOIx4GAiCi7H5xJNm408iSdHkOzWWMR/RDwQZWbkeJpNyxyYFSlw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707448492; c=relaxed/simple; bh=41xh2KqrEMxjoSEW6TMdownUge+f3VOfo3blzwhoK2c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gXbDF8lP+OlBTSwSUpmdbnBVByyS38VJVnG/iQ99PuebfOxjk+sVObmc/rc2aSIFQVLUNUCSrbjA1irhwOVySfdbT+AnCNE/Y09a3hKUpnWPXp4GnK3XUBEd55ifAaDPPwI2mexeleNg1FqK+eXth9Cl76bhlGQ9MKsoYISNmaQ= 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=NqzApKXV; 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=1707448490; x=1738984490; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=41xh2KqrEMxjoSEW6TMdownUge+f3VOfo3blzwhoK2c=; b=NqzApKXVG1IyxJIeeg+3HPlwpwnbWgzHyMmm/wZTlWtvSQLuPl1gqrz3 Gghw2Jq6CrE8p1xm8uVcZFPOnriLZgDVFsbEEHBpS+pPWiZASr+triTqA UJ93HL/DFXLDdsMHPy7K2zer4iCcVJNuIjxdF0Xw7+sqPdUW2BxB9y6GV jUrDRF2RwzIPcxWXvL5pWcyNQR0gWygN4Afn0yNxFUGKBWRFgDMhVbV1R 8Mpykbaf005L2KPuby/ikc+lXlX9qXtN7NCxf735Iflps97/+g9eeJh1B Oa3p4MSKctNqA+0u7AYEt2M79COryBBmyRQOT3K00yohJxza/wx9N3ZKp Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10978"; a="1257890" X-IronPort-AV: E=Sophos;i="6.05,255,1701158400"; d="scan'208";a="1257890" 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="32631415" Received: from b49691a74b80.jf.intel.com ([10.165.54.183]) by orviesa002.jf.intel.com with ESMTP; 08 Feb 2024 19:14:47 -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 03/15] perf pmu-events: Add functions in jevent.py to parse counter and event info for hardware aware grouping Date: Thu, 8 Feb 2024 19:14:29 -0800 Message-ID: <20240209031441.943012-4-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: 1790389703453064775 X-GMAIL-MSGID: 1790389703453064775 From: Weilin Wang These functions are added to parse event counter restrictions and counter availability info from json files so that the metric grouping method could do grouping based on the counter restriction of events and the counters that are available on the system. Signed-off-by: Weilin Wang --- tools/perf/pmu-events/jevents.py | 185 +++++++++++++++++++++++++++-- tools/perf/pmu-events/pmu-events.h | 34 +++++- 2 files changed, 207 insertions(+), 12 deletions(-) diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jevents.py index 2c7e5d61ce92..bc91b7efa49a 100755 --- a/tools/perf/pmu-events/jevents.py +++ b/tools/perf/pmu-events/jevents.py @@ -23,6 +23,8 @@ _metric_tables = [] _sys_metric_tables = [] # Mapping between sys event table names and sys metric table names. _sys_event_table_to_metric_table_mapping = {} +# List of regular PMU counter layout tables. +_pmu_layouts_tables = [] # Map from an event name to an architecture standard # JsonEvent. Architecture standard events are in json files in the top # f'{_args.starting_dir}/{_args.arch}' directory. @@ -31,6 +33,10 @@ _arch_std_events = {} _pending_events = [] # Name of events table to be written out _pending_events_tblname = None +# PMU counter layout to write out when the layout table is closed +_pending_pmu_counts = [] +# Name of PMU counter layout table to be written out +_pending_pmu_counts_tblname = None # Metrics to write out when the table is closed _pending_metrics = [] # Name of metrics table to be written out @@ -47,10 +53,17 @@ _json_event_attributes = [ 'event', # Short things in alphabetical order. 'compat', 'deprecated', 'perpkg', 'unit', + # The list of counter(s) this event could use + 'counters', # Longer things (the last won't be iterated over during decompress). 'long_desc' ] +# Attributes that are in pmu_unit_layout. +_json_layout_attributes = [ + 'pmu', 'desc', 'num_counters', 'num_fixed_counters' +] + # Attributes that are in pmu_metric rather than pmu_event. _json_metric_attributes = [ 'metric_name', 'metric_group', 'metric_expr', 'metric_threshold', @@ -58,7 +71,9 @@ _json_metric_attributes = [ 'default_metricgroup_name', 'aggr_mode', 'event_grouping' ] # Attributes that are bools or enum int values, encoded as '0', '1',... -_json_enum_attributes = ['aggr_mode', 'deprecated', 'event_grouping', 'perpkg'] +_json_enum_attributes = ['aggr_mode', 'deprecated', 'event_grouping', 'perpkg', + 'num_counters', 'num_fixed_counters' +] def removesuffix(s: str, suffix: str) -> str: """Remove the suffix from a string @@ -334,6 +349,12 @@ class JsonEvent: if 'Errata' in jd: extra_desc += ' Spec update: ' + jd['Errata'] self.pmu = unit_to_pmu(jd.get('Unit')) + # The list of counter(s) the event could be collected with + self.counters = jd.get('Counter') + # Number of generic counter + self.num_counters = jd.get('NumCounters') + # Number of fixed counter + self.num_fixed_counters = jd.get('NumFixedCounters') filter = jd.get('Filter') self.unit = jd.get('ScaleUnit') self.perpkg = jd.get('PerPkg') @@ -405,8 +426,16 @@ class JsonEvent: s += f'\t{attr} = {value},\n' return s + '}' - def build_c_string(self, metric: bool) -> str: + def build_c_string(self, metric: bool, layout: bool) -> str: s = '' + if layout: + for attr in _json_layout_attributes: + x = getattr(self, attr) + if attr in _json_enum_attributes: + s += x if x else '0' + else: + s += f'{x}\\000' if x else '\\000' + return s for attr in _json_metric_attributes if metric else _json_event_attributes: x = getattr(self, attr) if metric and x and attr == 'metric_expr': @@ -421,10 +450,10 @@ class JsonEvent: s += f'{x}\\000' if x else '\\000' return s - def to_c_string(self, metric: bool) -> str: + def to_c_string(self, metric: bool, layout: bool) -> str: """Representation of the event as a C struct initializer.""" - s = self.build_c_string(metric) + s = self.build_c_string(metric, layout) return f'{{ { _bcs.offsets[s] } }}, /* {s} */\n' @@ -461,6 +490,8 @@ def preprocess_arch_std_files(archpath: str) -> None: _arch_std_events[event.name.lower()] = event if event.metric_name: _arch_std_events[event.metric_name.lower()] = event + if event.num_counters: + _arch_std_events[event.pmu.lower()] = event def add_events_table_entries(item: os.DirEntry, topic: str) -> None: @@ -470,6 +501,8 @@ def add_events_table_entries(item: os.DirEntry, topic: str) -> None: _pending_events.append(e) if e.metric_name: _pending_metrics.append(e) + if e.num_counters: + _pending_pmu_counts.append(e) def print_pending_events() -> None: @@ -510,7 +543,7 @@ def print_pending_events() -> None: last_pmu = event.pmu pmus.add((event.pmu, pmu_name)) - _args.output_file.write(event.to_c_string(metric=False)) + _args.output_file.write(event.to_c_string(metric=False, layout=False)) _pending_events = [] _args.output_file.write(f""" @@ -565,7 +598,7 @@ def print_pending_metrics() -> None: last_pmu = metric.pmu pmus.add((metric.pmu, pmu_name)) - _args.output_file.write(metric.to_c_string(metric=True)) + _args.output_file.write(metric.to_c_string(metric=True, layout=False)) _pending_metrics = [] _args.output_file.write(f""" @@ -583,6 +616,35 @@ const struct pmu_table_entry {_pending_metrics_tblname}[] = {{ """) _args.output_file.write('};\n\n') +def print_pending_pmu_counter_layout_table() -> None: + '''Print counter layout data from counter.json file to counter layout table in + c-string''' + + def pmu_counts_cmp_key(j: JsonEvent) -> Tuple[bool, str, str]: + def fix_none(s: Optional[str]) -> str: + if s is None: + return '' + return s + + return (j.desc is not None, fix_none(j.pmu), fix_none(j.num_counters)) + + global _pending_pmu_counts + if not _pending_pmu_counts: + return + + global _pending_pmu_counts_tblname + global pmu_layouts_tables + _pmu_layouts_tables.append(_pending_pmu_counts_tblname) + + _args.output_file.write( + f'static const struct compact_pmu_event {_pending_pmu_counts_tblname}[] = {{\n') + + for pmu_layout in sorted(_pending_pmu_counts, key=pmu_counts_cmp_key): + _args.output_file.write(pmu_layout.to_c_string(metric=False, layout=True)) + _pending_pmu_counts = [] + + _args.output_file.write('};\n\n') + def get_topic(topic: str) -> str: if topic.endswith('metrics.json'): return 'metrics' @@ -619,10 +681,12 @@ def preprocess_one_file(parents: Sequence[str], item: os.DirEntry) -> None: pmu_name = f"{event.pmu}\\000" if event.name: _bcs.add(pmu_name, metric=False) - _bcs.add(event.build_c_string(metric=False), metric=False) + _bcs.add(event.build_c_string(metric=False, layout=False), metric=False) if event.metric_name: _bcs.add(pmu_name, metric=True) - _bcs.add(event.build_c_string(metric=True), metric=True) + _bcs.add(event.build_c_string(metric=True, layout=False), metric=True) + if event.num_counters: + _bcs.add(event.build_c_string(metric=False, layout=True), metric=False) def process_one_file(parents: Sequence[str], item: os.DirEntry) -> None: """Process a JSON file during the main walk.""" @@ -636,11 +700,14 @@ def process_one_file(parents: Sequence[str], item: os.DirEntry) -> None: if item.is_dir() and is_leaf_dir(item.path): print_pending_events() print_pending_metrics() + print_pending_pmu_counter_layout_table() global _pending_events_tblname _pending_events_tblname = file_name_to_table_name('pmu_events_', parents, item.name) global _pending_metrics_tblname _pending_metrics_tblname = file_name_to_table_name('pmu_metrics_', parents, item.name) + global _pending_pmu_counts_tblname + _pending_pmu_counts_tblname = file_name_to_table_name('pmu_layouts_', parents, item.name) if item.name == 'sys': _sys_event_table_to_metric_table_mapping[_pending_events_tblname] = _pending_metrics_tblname @@ -674,6 +741,12 @@ struct pmu_metrics_table { uint32_t num_pmus; }; +/* Struct used to make the PMU counter layout table implementation opaque to callers. */ +struct pmu_layouts_table { + const struct compact_pmu_event *entries; + size_t length; +}; + /* * Map a CPU to its table of PMU events. The CPU is identified by the * cpuid field, which is an arch-specific identifier for the CPU. @@ -687,6 +760,7 @@ struct pmu_events_map { const char *cpuid; struct pmu_events_table event_table; struct pmu_metrics_table metric_table; + struct pmu_layouts_table layout_table; }; /* @@ -731,6 +805,12 @@ const struct pmu_events_map pmu_events_map[] = { metric_size = '0' if event_size == '0' and metric_size == '0': continue + layout_tblname = file_name_to_table_name('pmu_layouts_', [], row[2].replace('/', '_')) + if layout_tblname in _pmu_layouts_tables: + layout_size = f'ARRAY_SIZE({layout_tblname})' + else: + layout_tblname = 'NULL' + layout_size = '0' cpuid = row[0].replace('\\', '\\\\') _args.output_file.write(f"""{{ \t.arch = "{arch}", @@ -742,6 +822,10 @@ const struct pmu_events_map pmu_events_map[] = { \t.metric_table = {{ \t\t.pmus = {metric_tblname}, \t\t.num_pmus = {metric_size} +\t}}, +\t.layout_table = {{ +\t\t.entries = {layout_tblname}, +\t\t.length = {layout_size} \t}} }}, """) @@ -752,6 +836,7 @@ const struct pmu_events_map pmu_events_map[] = { \t.cpuid = 0, \t.event_table = { 0, 0 }, \t.metric_table = { 0, 0 }, +\t.layout_table = { 0, 0 }, } }; """) @@ -840,6 +925,24 @@ static void decompress_metric(int offset, struct pmu_metric *pm) _args.output_file.write('\twhile (*p++);') _args.output_file.write("""} +static void decompress_layout(int offset, struct pmu_layout *pm) +{ +\tconst char *p = &big_c_string[offset]; +""") + for attr in _json_layout_attributes: + _args.output_file.write(f'\n\tpm->{attr} = ') + if attr in _json_enum_attributes: + _args.output_file.write("*p - '0';\n") + else: + _args.output_file.write("(*p == '\\0' ? NULL : p);\n") + if attr == _json_layout_attributes[-1]: + continue + if attr in _json_enum_attributes: + _args.output_file.write('\tp++;') + else: + _args.output_file.write('\twhile (*p++);') + _args.output_file.write("""} + static int pmu_events_table__for_each_event_pmu(const struct pmu_events_table *table, const struct pmu_table_entry *pmu, pmu_event_iter_fn fn, @@ -995,6 +1098,21 @@ int pmu_metrics_table__for_each_metric(const struct pmu_metrics_table *table, return 0; } +int pmu_layouts_table__for_each_layout(const struct pmu_layouts_table *table, + pmu_layout_iter_fn fn, + void *data) { + for (size_t i = 0; i < table->length; i++) { + struct pmu_layout pm; + int ret; + + decompress_layout(table->entries[i].offset, &pm); + ret = fn(&pm, data); + if (ret) + return ret; + } + return 0; +} + static const struct pmu_events_map *map_for_pmu(struct perf_pmu *pmu) { static struct { @@ -1090,6 +1208,33 @@ const struct pmu_metrics_table *perf_pmu__find_metrics_table(struct perf_pmu *pm return NULL; } +const struct pmu_layouts_table *perf_pmu__find_layouts_table(struct perf_pmu *pmu) +{ + const struct pmu_layouts_table *table = NULL; + char *cpuid = perf_pmu__getcpuid(pmu); + int i; + + /* on some platforms which uses cpus map, cpuid can be NULL for + * PMUs other than CORE PMUs. + */ + if (!cpuid) + return NULL; + + i = 0; + for (;;) { + const struct pmu_events_map *map = &pmu_events_map[i++]; + if (!map->arch) + break; + + if (!strcmp_cpuid_str(map->cpuid, cpuid)) { + table = &map->layout_table; + break; + } + } + free(cpuid); + return table; +} + const struct pmu_events_table *find_core_events_table(const char *arch, const char *cpuid) { for (const struct pmu_events_map *tables = &pmu_events_map[0]; @@ -1111,6 +1256,16 @@ const struct pmu_metrics_table *find_core_metrics_table(const char *arch, const } return NULL; } +const struct pmu_layouts_table *find_core_layouts_table(const char *arch, const char *cpuid) +{ + for (const struct pmu_events_map *tables = &pmu_events_map[0]; + tables->arch; + tables++) { + if (!strcmp(tables->arch, arch) && !strcmp_cpuid_str(tables->cpuid, cpuid)) + return &tables->layout_table; + } + return NULL; +} int pmu_for_each_core_event(pmu_event_iter_fn fn, void *data) { @@ -1139,6 +1294,19 @@ int pmu_for_each_core_metric(pmu_metric_iter_fn fn, void *data) return 0; } +int pmu_for_each_core_layout(pmu_layout_iter_fn fn, void *data) +{ + for (const struct pmu_events_map *tables = &pmu_events_map[0]; + tables->arch; + tables++) { + int ret = pmu_layouts_table__for_each_layout(&tables->layout_table, fn, data); + + if (ret) + return ret; + } + return 0; +} + const struct pmu_events_table *find_sys_events_table(const char *name) { for (const struct pmu_sys_events *tables = &pmu_sys_event_tables[0]; @@ -1295,6 +1463,7 @@ struct pmu_table_entry { ftw(arch_path, [], process_one_file) print_pending_events() print_pending_metrics() + print_pending_pmu_counter_layout_table() print_mapping_table(archs) print_system_mapping_table() diff --git a/tools/perf/pmu-events/pmu-events.h b/tools/perf/pmu-events/pmu-events.h index f5aa96f1685c..e245e4738970 100644 --- a/tools/perf/pmu-events/pmu-events.h +++ b/tools/perf/pmu-events/pmu-events.h @@ -45,6 +45,11 @@ struct pmu_event { const char *desc; const char *topic; const char *long_desc; + /** + * The list of counter(s) the event could be collected on. + * eg., "0,1,2,3,4,5,6,7". + */ + const char *counters; const char *pmu; const char *unit; bool perpkg; @@ -67,8 +72,20 @@ struct pmu_metric { enum metric_event_groups event_grouping; }; +struct pmu_layout { + const char *pmu; + const char *desc; + /** Total number of generic counters*/ + int num_counters; + /** + * Total number of fixed counters. + * Set to zero if no fixed counter on the unit.*/ + int num_fixed_counters; +}; + struct pmu_events_table; struct pmu_metrics_table; +struct pmu_layouts_table; typedef int (*pmu_event_iter_fn)(const struct pmu_event *pe, const struct pmu_events_table *table, @@ -78,15 +95,21 @@ typedef int (*pmu_metric_iter_fn)(const struct pmu_metric *pm, const struct pmu_metrics_table *table, void *data); +typedef int (*pmu_layout_iter_fn)(const struct pmu_layout *pm, + void *data); + int pmu_events_table__for_each_event(const struct pmu_events_table *table, struct perf_pmu *pmu, pmu_event_iter_fn fn, void *data); int pmu_events_table__find_event(const struct pmu_events_table *table, - struct perf_pmu *pmu, - const char *name, - pmu_event_iter_fn fn, - void *data); + struct perf_pmu *pmu, + const char *name, + pmu_event_iter_fn fn, + void *data); +int pmu_layouts_table__for_each_layout(const struct pmu_layouts_table *table, + pmu_layout_iter_fn fn, + void *data); size_t pmu_events_table__num_events(const struct pmu_events_table *table, struct perf_pmu *pmu); @@ -95,10 +118,13 @@ int pmu_metrics_table__for_each_metric(const struct pmu_metrics_table *table, pm const struct pmu_events_table *perf_pmu__find_events_table(struct perf_pmu *pmu); const struct pmu_metrics_table *perf_pmu__find_metrics_table(struct perf_pmu *pmu); +const struct pmu_layouts_table *perf_pmu__find_layouts_table(struct perf_pmu *pmu); const struct pmu_events_table *find_core_events_table(const char *arch, const char *cpuid); const struct pmu_metrics_table *find_core_metrics_table(const char *arch, const char *cpuid); +const struct pmu_layouts_table *find_core_layouts_table(const char *arch, const char *cpuid); int pmu_for_each_core_event(pmu_event_iter_fn fn, void *data); int pmu_for_each_core_metric(pmu_metric_iter_fn fn, void *data); +int pmu_for_each_core_layout(pmu_layout_iter_fn fn, void *data); const struct pmu_events_table *find_sys_events_table(const char *name); const struct pmu_metrics_table *find_sys_metrics_table(const char *name); From patchwork Fri Feb 9 03:14:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Weilin" X-Patchwork-Id: 198735 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp606293dyd; Thu, 8 Feb 2024 19:29:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IHucDXCbQOJwENld02EoKedBL8qIZo9SX4zSY9Ra5IbwP2hx1KdU91Cb1cIfcAJiZcdwrZi X-Received: by 2002:a17:90a:6408:b0:296:c788:b280 with SMTP id g8-20020a17090a640800b00296c788b280mr1009664pjj.18.1707449347437; Thu, 08 Feb 2024 19:29:07 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707449347; cv=pass; d=google.com; s=arc-20160816; b=B2DODyVdMpiXCyUN08ur+ZBsJcIl8Le6P1YH7yqdR1/po1VgcEQNEjTsTdG2Y+FCiX 4a3GfsNPKpWH02sSGFZmuLjLwunvt796eIJ30AlO+H9qj8ynTbs4JLsedoPvtZRF0zny ZTF6gYV3M0Y8lYOeFikXGZGLSCZUAb2z3zA/jAybBJyCOwhPr86eCuDPg8S3F1v3Ogut yHF63JCZUrc1OLaL9ZFtB0F4zGhsbYu9RSXoTmn5B9KvrZxrKS9GAogVpGEHsFyMn+Sa Lci+QB/4zj5CmZ1kqE+pGn7JXYZnQwZKh47L26UY3AJLuFXa5/gv+/Vk1BVzHpiRpHWC bsSQ== 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=kVMSCUffSjyTRFBfOy3mjVqsI+hh65hBDS2PEc6g13k=; fh=N3AtaYQDmjdlYY2XGWg+gwywM+t3+tQfyHH67n7Ym2I=; b=GMYw1TpmTf++0YfxIKbql+WMfYXdaiBJvs+YmTk32yhqvgd37G+JvHj5pzp4qYyV1x rurAuXNoIvfHD3f6hDGZWySY3FSHNi/Q+gJUe5UWt7Jn9++uOpIPlh1pPryKjk0I2F2U IQASUwRBsJOkimPmxV7wowEsBsUtyfoYr9qHUB8ld1qlRfBx5vQ3llF/xK60Zn2e8Xb2 IeaFyBg/frq36JRxCC5Ikl5AK/7BbFODmv/nz3CjrbOXHXfFOH5zJiMXutq21JSfcYeV jIHXIZgiRjClRdXt8ZkAjyvKmh5ZUM82zZl08Qr+xx40uULVT6ftZjj4x5XLGIAQxrT0 f2DQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=CdHjXUcO; 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-58970-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58970-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=2; AJvYcCU8XIMC+VuRw+coB0y6VAEp2dSMTsjzh/oFgewUiDWydSXDqIeQreTaq38SXtFnjQDIfbLKhWyV/sFfVZ2LmpboePgsew== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id d90-20020a17090a6f6300b00290349120dfsi804925pjk.129.2024.02.08.19.29.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 19:29:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58970-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=CdHjXUcO; 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-58970-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58970-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 BD8DCB28D3B for ; Fri, 9 Feb 2024 03:16:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8F50C182DC; Fri, 9 Feb 2024 03:14:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="CdHjXUcO" 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 216095227; Fri, 9 Feb 2024 03:14:51 +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=1707448492; cv=none; b=Q1ryN55mU/Cb/oGgn/9aykSJg07PzKc3Yg6HOzv9zYuhhbIzuav+bnyBGS6sMnd1XTG/8Eh8X2v3AG9h89eYBpAyv9LGmxL6wCO3K7E7Z6Koua4wQZaDhu+H2DVLeQl7LgEABXxU9aVLp24Mj/u5EL8ghiAzesESSQg/NMEK/dc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707448492; c=relaxed/simple; bh=UeJbm2alYHDiXSHmzWkkiSfZ2SjtcJME+Lz2npuv+/w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LPkWtLMis0pE+r58iIQDTTKRu/tbbY+F1HrlGH2VMgsDknBIRmkixbTDBBqvnDTrwA1xn5gP1YwzpKyViAf/iDi1lNf/aP18AtfWFKP6zvay8ynGCFZq+3cpGhBQnlNrwXYM1eAgQ8FBeD1IynEnLxnsu1YSr6q0R/ojKIkWALQ= 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=CdHjXUcO; 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=1707448491; x=1738984491; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=UeJbm2alYHDiXSHmzWkkiSfZ2SjtcJME+Lz2npuv+/w=; b=CdHjXUcO25JYgNNUIOPM5iBL4fsjcLEYheOBaKdvLbVaWOjz+7/K0prN FnJod2SEPbC6xIbl2C9ocY3cQC2CzJrAJCbc6tHNzrWq/IC8HlYrxaPge ZvBQ7B8X9zkQcjJoj9C9xo608haZMItgzAUEjl1Nh4LXrU23q3kWpmNqv itOy2BhgMgesWgsDiPNrnR3xto2DLINJgXtFlpZBmrQJY3IaofMna2CHN MDGreMjxyFNC56gO2JaTwRlTaeHUFf3ZfGOBsKP75aMcNZFyHakjZLAJg 20L4bu+fge7yJw+tJgTH8DSa9yBbFr8vqgxj3DDXQAAVzoaK9gG9bfMes A==; X-IronPort-AV: E=McAfee;i="6600,9927,10978"; a="1257900" X-IronPort-AV: E=Sophos;i="6.05,255,1701158400"; d="scan'208";a="1257900" 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="32631420" Received: from b49691a74b80.jf.intel.com ([10.165.54.183]) by orviesa002.jf.intel.com with ESMTP; 08 Feb 2024 19:14:47 -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 04/15] find_bit: add _find_last_and_bit() to support finding the most significant set bit Date: Thu, 8 Feb 2024 19:14:30 -0800 Message-ID: <20240209031441.943012-5-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: 1790390406823377083 X-GMAIL-MSGID: 1790390406823377083 From: Weilin Wang This function is required for more efficient PMU counter assignment. When we use bitmap to log available PMU counters and counters that support a given event, we want to find a most significant set bit so that we could starting assigning counters with larger index first. This is helpful because counters with smaller indexes usually are more generic and support more events. Signed-off-by: Weilin Wang --- tools/include/linux/find.h | 18 ++++++++++++++++++ tools/lib/find_bit.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/tools/include/linux/find.h b/tools/include/linux/find.h index 38c0a542b0e2..fce336ec2b96 100644 --- a/tools/include/linux/find.h +++ b/tools/include/linux/find.h @@ -18,6 +18,8 @@ extern unsigned long _find_first_bit(const unsigned long *addr, unsigned long si extern unsigned long _find_first_and_bit(const unsigned long *addr1, const unsigned long *addr2, unsigned long size); extern unsigned long _find_first_zero_bit(const unsigned long *addr, unsigned long size); +extern unsigned long _find_last_and_bit(const unsigned long *addr1, + const unsigned long *addr2, unsigned long size); #ifndef find_next_bit /** @@ -174,4 +176,20 @@ unsigned long find_first_zero_bit(const unsigned long *addr, unsigned long size) } #endif +#ifndef find_last_and_bit +static inline +unsigned long find_last_and_bit(const unsigned long *addr1, + const unsigned long *addr2, + unsigned long size) +{ + if (small_const_nbits(size)) { + unsigned long val = *addr1 & *addr2 & GENMASK(size - 1, 0); + + return val ? __fls(val) : size; + } + + return _find_last_and_bit(addr1, addr2, size); +} +#endif + #endif /*__LINUX_FIND_H_ */ diff --git a/tools/lib/find_bit.c b/tools/lib/find_bit.c index 6a3dc167d30e..e475a7368e36 100644 --- a/tools/lib/find_bit.c +++ b/tools/lib/find_bit.c @@ -67,6 +67,27 @@ out: \ sz; \ }) +/* + * Common helper for find_bit() function family + * @FETCH: The expression that fetches and pre-processes each word of bitmap(s) + * @MUNGE: The expression that post-processes a word containing found bit (may be empty) + * @size: The bitmap size in bits + */ +#define FIND_LAST_BIT(FETCH, MUNGE, size) \ +({ \ + unsigned long idx, val, sz = (size); \ + \ + for (idx = ((size - 1) / BITS_PER_LONG); idx >= 0; idx--) { \ + val = (FETCH); \ + if (val) { \ + sz = min(idx * BITS_PER_LONG + __fls(MUNGE(val)), sz); \ + break; \ + } \ + } \ + \ + sz; \ +}) + #ifndef find_first_bit /* * Find the first set bit in a memory region. @@ -121,3 +142,15 @@ unsigned long _find_next_zero_bit(const unsigned long *addr, unsigned long nbits return FIND_NEXT_BIT(~addr[idx], /* nop */, nbits, start); } #endif + +#ifndef find_last_and_bit +/* + * Find the last set bit in two memory regions. + */ +unsigned long _find_last_and_bit(const unsigned long *addr1, + const unsigned long *addr2, + unsigned long size) +{ + return FIND_LAST_BIT(addr1[idx] & addr2[idx], /* nop */, size); +} +#endif \ No newline at end of file From patchwork Fri Feb 9 03:14:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Weilin" X-Patchwork-Id: 198725 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp603050dyd; Thu, 8 Feb 2024 19:17:53 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXQU8lFffRqbUwP/I9Uq3FqPVeU3oMbJBOIBfvkAL7fU9dSnJ2TVgcVq8biWGeuqnM2s9bScqKdNJEacXKJ2KXPiPEAHA== X-Google-Smtp-Source: AGHT+IH/vfkP2UMF/wZtrrG+DCCEoscbzo8IFMgZCS/mkweSf3M0Fgdif3sR/Pv0KMZl+ekbZ3uS X-Received: by 2002:a17:906:46cc:b0:a38:4dc0:22f9 with SMTP id k12-20020a17090646cc00b00a384dc022f9mr478701ejs.4.1707448673481; Thu, 08 Feb 2024 19:17:53 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707448673; cv=pass; d=google.com; s=arc-20160816; b=VsysWd3dBtEQfSe4AK+vhaoC+7aSbh1aV6neWZAPkZgMdhXRm7iV4sxViM68ED/mGX nXnLrOYP+vUMaQKYYKnBDhhm0wknDHDkQ+JTRXoduIyEqiwkfXHgmJIB9Hyn7lHjZKIO vQtaiuDUmrZBbQeGO7aO5ELbEvRnM57TkMRA/fvKMad23GhIeCnMlOUEc9Eh/lm+codC 0tZXgYEzQ2heb9zGJOPaeXpsrt1lyjvHIYi1j96EJ9ltm8yMcRdeJngnJyrkng5IYsbu fzr3KF8DtSmnETs5pGavL06wGOJx+6Z1j6a68w7kY3T7uS4QL4HI0YUX3cPUxr8QaTWF LQFg== 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=brtCVvTsNak2qoxKEWerk8o3a4AvQcK6/2GvzJRRSCE=; fh=gcznsdSYscc2hwwt7RmAf2w2kjSI20y/3fZ3JFb0NKE=; b=tNs8AhJjGe9BEx0m2DaSAIRJHD3VcSZdShnMHc28X8gf1dSV3pRsZ2P12xk3cLPB2e wWRM9pv9QYOlhf1+2KBPDQ2BB0rv8CIwoVttcIFNI6RaGnYQunOYD23x9VtQZYC1EJcJ LEvx2n/cYbvl1KWz4ecXiJLHygd9esRSsR8fvl1qYQAPNB3lpWHgpsQ5PuTveY/+3egP e65EmK44jNuf4/JxaNRDhrTHPPnkmR7KJm5sGXBMVDViVzDjBCMalSJ0r4rMvMXc5Ruw niWKwhKR7la1Rd0SIVksIk8X/H8wMqzVov39djv5MmZ4ZND/4MILM/kuov4PJ4nvCB8v q41w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=cu2xU6wH; 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-58971-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58971-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=2; AJvYcCXR0Q3qJjIVqGen8I0Svdtpkzv7ZbrALjfbVYWGVAJiyBZeCUjPUe6cLRGpSMZdEZJCaFr9iABsp5YQMEYYac1SnDY5oA== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id o25-20020a17090637d900b00a38460e2c73si333462ejc.773.2024.02.08.19.17.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 19:17:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58971-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=cu2xU6wH; 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-58971-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58971-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 35BC61F22D1D for ; Fri, 9 Feb 2024 03:17:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 04E5122619; Fri, 9 Feb 2024 03:14:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="cu2xU6wH" 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 6813B6125; Fri, 9 Feb 2024 03:14:52 +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=1707448494; cv=none; b=nbA5aT7wNrbNfj7dr0Fi7wz2RiLuvz/EUdk1g2W7C2UI3Dz63MEuDRhQYktvvChMPyiKdep8vaSRghbNXbwUoysKF5dUwDABQNZxJ3BcIeZQjGAQ6+cNntXP8U6MtdC93zmsp11y798EvAS0qDNeSXbWXWk5zEqUZb5t4olr6MA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707448494; c=relaxed/simple; bh=DjJPq4T9ViJb+2InPFFCi7oWrQjyZ8Rl/e9jnSYLBoc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aE13RwUhHYDOuqBoW5L5AsZn1pOxFcObgKfDK7dra2dlT7I6IivmfmtiQhl2VL18VUe/aEMLP8RrqXYWTJpwPkRl0neLjltuzS072O00mD4C9SPQB5zoNHQrHC2PGfyEkpq5UdNhMkKleMDLxSzYbt+oXpRc63iRCvyxNe32hWk= 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=cu2xU6wH; 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=1707448493; x=1738984493; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=DjJPq4T9ViJb+2InPFFCi7oWrQjyZ8Rl/e9jnSYLBoc=; b=cu2xU6wHEY8Lnm0RVlHFmw+kBa44yoPNQ4yyeNvZMHgsyIUj9qS3N8jH CWi2H9xJsxQzb6YSMfsyEYUblPzS7uj/svLyX1AByh8td+1CFcmIMyidd EY8yq1g/Lzj+2JOZKJQ7he07kf+VB54HxzBt/a4FktQluoJX58oxvyhEV wdydDKm/cYydpkv4H3qfg/QrhCIm9XyI1UFfGX9URqzTMFQFCJz4mXDpY BlWIMPEK4lO1WbQdyGsfVHwcBYlILM2AM1YTyBZRSbikeXHYnXvu8zQzG xMJ3OHeNP9hSdXliv76fSCDHUjS9J3cTvr8ypNnK7NZTa+ybhj6GLRHUd A==; X-IronPort-AV: E=McAfee;i="6600,9927,10978"; a="1257908" X-IronPort-AV: E=Sophos;i="6.05,255,1701158400"; d="scan'208";a="1257908" 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="32631423" Received: from b49691a74b80.jf.intel.com ([10.165.54.183]) by orviesa002.jf.intel.com with ESMTP; 08 Feb 2024 19:14:47 -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 05/15] perf stat: Add functions to set counter bitmaps for hardware-grouping method Date: Thu, 8 Feb 2024 19:14:31 -0800 Message-ID: <20240209031441.943012-6-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: 1790389700338766324 X-GMAIL-MSGID: 1790389700338766324 From: Weilin Wang Add metricgroup__event_info data structure to represent an event in the metric grouping context; the list of counters and the PMU name an event should be collected with. Add functions to parse event counter info from pmu-events and generate a list of metricgroup__event_info data to prepare grouping. Signed-off-by: Weilin Wang --- tools/perf/util/metricgroup.c | 211 +++++++++++++++++++++++++++++++++- 1 file changed, 208 insertions(+), 3 deletions(-) diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index ee638578afdd..2a917220fb34 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -157,6 +158,27 @@ struct metric { struct evlist *evlist; }; +/* Maximum number of counters per PMU*/ +#define NR_COUNTERS 16 + +/** + * An event used in a metric. This info is for metric grouping. + */ +struct metricgroup__event_info { + struct list_head nd; + /** The name of the event. */ + const char *name; + /** The name of the pmu the event be collected on. */ + const char *pmu_name; + /** The event uses fixed counter*/ + bool fixed_counter; + /** The event uses special counters that we consider that as free counter + * during the event grouping*/ + bool free_counter; + /** The counters the event allowed to be collected on. */ + DECLARE_BITMAP(counters, NR_COUNTERS); +}; + /** * Each group is one node in the group string list. */ @@ -1440,6 +1462,175 @@ static int build_combined_expr_ctx(const struct list_head *metric_list, return ret; } +/** + * set_counter_bitmap - The counter bitmap: [0-15]. + */ +static int set_counter_bitmap(int pos, unsigned long *bitmap) +{ + if (pos >= NR_COUNTERS || pos < 0) + return -EINVAL; + __set_bit(pos, bitmap); + return 0; +} + +static int parse_fixed_counter(const char *counter, + unsigned long *bitmap, + bool *fixed) +{ + int ret = -ENOENT; + //TODO: this pattern is different on some other platforms + const char *pattern = "Fixed counter "; + int pos = 0; + + if (!strncmp(counter, pattern, strlen(pattern))) { + pos = atoi(counter + strlen(pattern)); + ret = set_counter_bitmap(pos, bitmap); + if (ret) + return ret; + *fixed = true; + return 0; + } + return ret; +} + +/** + * parse_counter - Parse event counter info from pmu-events and set up bitmap + * accordingly. + * + * @counter: counter info string to be parsed. + * @bitmap: bitmap to set based on counter info parsed. + * @fixed: is set to true if the event uses fixed counter. + */ +static int parse_counter(const char *counter, + unsigned long *bitmap, + bool *fixed) +{ + int ret = 0; + char *p; + char *tok; + int pos = 0; + + ret = parse_fixed_counter(counter, bitmap, fixed); + // ret==0 means matched with fixed counter + if (ret == 0) + return ret; + + p = strdup(counter); + tok = strtok(p, ","); + if (!tok) + return -ENOENT; + + while (tok) { + pos = atoi(tok); + ret = set_counter_bitmap(pos, bitmap); + if (ret) + return ret; + tok = strtok(NULL, ","); + } + return 0; +} + +static struct metricgroup__event_info *event_info__new(const char *name, + const char *pmu_name, + const char *counter, + bool free_counter) +{ + int ret = 0; + char *bit_buf = malloc(NR_COUNTERS); + bool fixed_counter = false; + struct metricgroup__event_info *e; + + e = zalloc(sizeof(*e)); + if (!e) + return NULL; + if (!pmu_name) + pmu_name = "core"; + + e->name = name; + e->free_counter = free_counter; + e->pmu_name = strdup(pmu_name); + if (free_counter) { + ret = set_counter_bitmap(0, e->counters); + if (ret) + return NULL; + } else { + ret = parse_counter(counter, e->counters, &fixed_counter); + if (ret) + return NULL; + e->fixed_counter = fixed_counter; + } + + bitmap_scnprintf(e->counters, NR_COUNTERS, bit_buf, NR_COUNTERS); + pr_debug("Event %s requires pmu %s counter: %s bitmap %s, [pmu=%s]\n", + e->name, e->pmu_name, counter, bit_buf, pmu_name); + + return e; +} + +struct metricgroup__add_metric_event_data { + struct list_head *list; + /* pure event name, exclude umask and other info*/ + const char *event_name; + /* event name and umask if applicable*/ + const char *event_id; +}; + +static int metricgroup__add_metric_event_callback(const struct pmu_event *pe, + const struct pmu_events_table *table __maybe_unused, + void *data) +{ + struct metricgroup__event_info *event; + struct metricgroup__add_metric_event_data *d = data; + + if (!strcasecmp(pe->name, d->event_name)) { + event = event_info__new(d->event_id, pe->pmu, pe->counter, /*free_counter=*/false); + if (!event) + return -ENOMEM; + list_add(&event->nd, d->list); + } + + return 0; +} + +/** + * get_metricgroup_events - Find counter requirement of events from the + * pmu_events table + * @full_id: the full event identifiers. + * @table: pmu_events table that is searched for event data. + * @event_info_list: the list that the new event counter info added to. + */ +static int get_metricgroup_events(const char *full_id, + const struct pmu_events_table *table, + struct list_head *event_info_list) +{ + LIST_HEAD(list); + int ret = 0; + const char *id; + const char *rsep, *sep = strchr(full_id, '@'); + + if (sep) { + rsep = strchr(full_id, ','); + id = strndup(sep + 1, rsep - sep - 1); + if (ret) + goto out; + } else { + id = full_id; + } + { + struct metricgroup__add_metric_event_data data = { + .list = &list, + .event_name = id, + .event_id = full_id, + }; + ret = pmu_events_table_for_each_event(table, + metricgroup__add_metric_event_callback, &data); + } + +out: + list_splice(&list, event_info_list); + return ret; +} + /** * hw_aware_build_grouping - Build event groupings by reading counter * requirement of the events and counter available on the system from @@ -1453,9 +1644,25 @@ static int hw_aware_build_grouping(struct expr_parse_ctx *ctx __maybe_unused, const char *modifier __maybe_unused) { int ret = 0; + struct hashmap_entry *cur; + LIST_HEAD(pmu_info_list); + LIST_HEAD(event_info_list); + size_t bkt; + const struct pmu_events_table *etable = perf_pmu__find_events_table(NULL); + +#define RETURN_IF_NON_ZERO(x) do { if (x) return x; } while (0) + hashmap__for_each_entry(ctx->ids, cur, bkt) { + const char *id = cur->pkey; + + pr_debug("found event %s\n", id); + + ret = get_metricgroup_events(id, etable, &event_info_list); + if (ret) + return ret; + } - pr_debug("This is a placeholder\n"); return ret; +#undef RETURN_IF_NON_ZERO } static void group_str_free(struct metricgroup__group_strs *g) @@ -1529,8 +1736,6 @@ static int hw_aware_parse_ids(struct perf_pmu *fake_pmu, *out_evlist = parsed_evlist; parsed_evlist = NULL; err_out: - parse_events_error__exit(&parse_error); - evlist__delete(parsed_evlist); metricgroup__free_grouping_strs(&groupings); return ret; } From patchwork Fri Feb 9 03:14:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Weilin" X-Patchwork-Id: 198736 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp606669dyd; Thu, 8 Feb 2024 19:30:24 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVXHC/eDGJXDkmgNy8ckBnab2Q/YUVMR9zj2KI+4thwuKMgpWMYZlQ/rV6h3oh3LIURP6ygtXvzytNsvaI89n+s+OmSJw== X-Google-Smtp-Source: AGHT+IEJGisCi2s0J+FFSKRZ2E/Z57mN32A3iU3a2Vy2YUrXxxEuwqOkca6hAmbesuZaRcJFrcZq X-Received: by 2002:aa7:8051:0:b0:6db:cfd7:102c with SMTP id y17-20020aa78051000000b006dbcfd7102cmr516654pfm.15.1707449423824; Thu, 08 Feb 2024 19:30:23 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707449423; cv=pass; d=google.com; s=arc-20160816; b=uq78YQwEGBQ9EXLnl8f3V7G4KXxkhmLXwUZ2dWgkF2cWUw+lClxEuCUkVX2P3kDdlY 83WcB1UAaF9h0sUah/dpRsIMT6lLvGgem56gXrGW1bKDgpo1krh2rSdTVvYDgZ8xFijJ IsJfdRPUPaco/rzgCYRhBrRZjGZU/3R6THAKzEOsovhVkbpeUflgWLqnA74A+/c6Eop5 uLuccIZghIt/BfgRI6AWgIH2rNi43mFldrFqFB9ZbVLQ7iB9sEroTqX3cGWGOrQMI9Tg n2rAJgNX985cAdWniMWML0ibHsbNScWQlOC3PG0dMHEX6FLGhrV9HM1NiSsJSS2ZLhX/ lOmw== 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=GCyjOvfA4YRBXobswdIgkZQFMEOT56eCvfyLjzSS9jc=; fh=WnT9IvLEUGTWYTzcgL9ySW4dQYm2unXT14nMVB7hPlg=; b=sKCeZkUHZaR8ecQWjrKYRPZ+BgBmdQKxL4rqBLVWAW4UBnqbfnmYiZJx/0EWE5i9v4 LaplJ6imsY9tb4Ep4K+RtJXH/Oy4M7XXPK9mTpD020weJNF8qDPu6Yho6iL3Frfkrgbz 5JENuVRskxLwsgD25tz0q5BCa1u/1DeslWl0L7r0Qo0bIz7agRsqRvwNG2H6pBiEzOe5 xPgOG6LVdvWojWudEW6GoKycMyJTxI1Cu4z+kPaVJgvu4MzM/UK9gAy/3lLOfIVAWqkI xkav7PbgkJmpFGhNI8DbN/lOI+Is2B7QdnvQFLorZ0FLOL0VjhqMCPc9JjbV+YAKvo5v 1UaA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="WrddKb/4"; 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-58972-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58972-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=2; AJvYcCWDCynC2LzpCGH700IaRqGXj8q7757tbi1D+5AckKN/zVyqcj4Hag2OG6xFI3d1hLEA2Ls/Awq68yY4PkxQO0J7N1p07w== 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.30.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 19:30:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58972-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="WrddKb/4"; 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-58972-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58972-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 71A42B22427 for ; Fri, 9 Feb 2024 03:17:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AFE6E2135A; Fri, 9 Feb 2024 03:14:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="WrddKb/4" 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 6810E611E; Fri, 9 Feb 2024 03:14:52 +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=1707448494; cv=none; b=UtAeKyECutJ/PpqFDGxWn7LRPhuVJ6fPJvN08UEEfqYYpFRPEwkXQNkRe+qbioYzmkqAdlt5wEtylPTgO6IszVU4gx64Q++v03VnEcmm/HX/33fckmDpfO8hEYQQy5bGctGPc9q1C8lKxHnOqGIMADavfd8xW/6ZO8MEF86sOCw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707448494; c=relaxed/simple; bh=Ptn1JpRP3StyuOfIWKSzj6sKJoeJjAtlLJUNbm0+pS8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sVe/Sbr5XQjX4IrJSmot5k/NJw1EH3JT3uPagMZGzNilidYRYIesyCSs4BsCLUQqy9Pm4iw3pCUrQaTFv/HGiRa8TnnAF1f3TejANvzD2N6n2XW/QSmiMKZe1QBoYk70nqDx2yShoaoz5G9hEV5W+9obCH5PB0L+0DDzlGoLE6g= 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=WrddKb/4; 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=1707448493; x=1738984493; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Ptn1JpRP3StyuOfIWKSzj6sKJoeJjAtlLJUNbm0+pS8=; b=WrddKb/4rSojKTkCLJ5XBYuTuEUd2qohsIjSPd31BdD5Poais91vEMKy eA6EsC52iI2mvlEJNcNyG/kJdAgrtk7af8DJTHz+qMabCZNTH5rp8YGxh 5GNuMsRMvjvOvuvcR0Do00HyMfO5e3yUoC7gi/3E9WJIVoEP8MoHCg3gm LQ9T6W89Vc5Nati46u4zKM/9XT0iqWqrNYPGJiCW5Q4Ey9i6BVg6F767R /eTJOkeUd8cT/iF32zNL2B34CdYzeSD3zBOjF/MhwcySMrKssBeeUCyZ0 MiQhBKWLwUoS0MO2VfWp5y2zkQ1T6ANoa8zm0oUP7Wj2NNNdxml9lsJdP Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10978"; a="1257909" X-IronPort-AV: E=Sophos;i="6.05,255,1701158400"; d="scan'208";a="1257909" 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="32631428" Received: from b49691a74b80.jf.intel.com ([10.165.54.183]) by orviesa002.jf.intel.com with ESMTP; 08 Feb 2024 19:14:47 -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 06/15] perf stat: Add functions to get counter info Date: Thu, 8 Feb 2024 19:14:32 -0800 Message-ID: <20240209031441.943012-7-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: 1790390486732809267 X-GMAIL-MSGID: 1790390486732809267 From: Weilin Wang Add data structure metricgroup__pmu_counters to represent hardware counters available in the system. Add functions to parse pmu-events and create the list of pmu_info_list to hold the counter information of the system. Add functions to free pmu_info_list and event_info_list before exit grouping for hardware-grouping method This method would fall back to normal grouping when event json files do not support hardware aware grouping. Signed-off-by: Weilin Wang --- tools/perf/util/metricgroup.c | 101 ++++++++++++++++++++++++++++++++-- 1 file changed, 97 insertions(+), 4 deletions(-) diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index 2a917220fb34..9061ed4ca015 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -179,6 +179,20 @@ struct metricgroup__event_info { DECLARE_BITMAP(counters, NR_COUNTERS); }; +/** + * A node is the counter availability of a pmu. + * This info is built up at the beginning from JSON file and + * used as a reference in metric grouping process. + */ +struct metricgroup__pmu_counters { + struct list_head nd; + /** The name of the pmu the event collected on. */ + const char *name; + /** The number of gp counters in the pmu. */ + size_t num_counters; + size_t num_fixed_counters; +}; + /** * Each group is one node in the group string list. */ @@ -1530,6 +1544,27 @@ static int parse_counter(const char *counter, return 0; } +static void metricgroup__free_event_info(struct list_head + *event_info_list) +{ + struct metricgroup__event_info *e, *tmp; + + list_for_each_entry_safe(e, tmp, event_info_list, nd) { + list_del_init(&e->nd); + free(e); + } +} + +static void metricgroup__free_pmu_info(struct list_head *pmu_info_list) +{ + struct metricgroup__pmu_counters *p, *tmp; + + list_for_each_entry_safe(p, tmp, pmu_info_list, nd) { + list_del_init(&p->nd); + free(p); + } +} + static struct metricgroup__event_info *event_info__new(const char *name, const char *pmu_name, const char *counter, @@ -1548,7 +1583,7 @@ static struct metricgroup__event_info *event_info__new(const char *name, e->name = name; e->free_counter = free_counter; - e->pmu_name = strdup(pmu_name); + e->pmu_name = pmu_name; if (free_counter) { ret = set_counter_bitmap(0, e->counters); if (ret) @@ -1583,7 +1618,9 @@ static int metricgroup__add_metric_event_callback(const struct pmu_event *pe, struct metricgroup__add_metric_event_data *d = data; if (!strcasecmp(pe->name, d->event_name)) { - event = event_info__new(d->event_id, pe->pmu, pe->counter, /*free_counter=*/false); + if (!pe->counters) + return -EINVAL; + event = event_info__new(d->event_id, pe->pmu, pe->counters, /*free_counter=*/false); if (!event) return -ENOMEM; list_add(&event->nd, d->list); @@ -1622,7 +1659,7 @@ static int get_metricgroup_events(const char *full_id, .event_name = id, .event_id = full_id, }; - ret = pmu_events_table_for_each_event(table, + ret = pmu_events_table__for_each_event(table, /*pmu=*/NULL, metricgroup__add_metric_event_callback, &data); } @@ -1631,6 +1668,57 @@ static int get_metricgroup_events(const char *full_id, return ret; } +static struct metricgroup__pmu_counters *pmu_layout__new(const struct pmu_layout *pl) +{ + struct metricgroup__pmu_counters *l; + + l = zalloc(sizeof(*l)); + + if (!l) + return NULL; + + l->name = pl->pmu; + l->num_counters = pl->num_counters; + l->num_fixed_counters = pl->num_fixed_counters; + pr_debug("create new pmu_layout: [pmu]=%s, [gp_size]=%ld, [fixed_size]=%ld\n", + l->name, l->num_counters, l->num_fixed_counters); + return l; +} + +static int metricgroup__add_pmu_layout_callback(const struct pmu_layout *pl, + void *data) +{ + struct metricgroup__pmu_counters *pmu; + struct list_head *d = data; + int ret = 0; + + pmu = pmu_layout__new(pl); + if (!pmu) + return -ENOMEM; + list_add(&pmu->nd, d); + return ret; +} + +/** + * get_pmu_counter_layouts - Find counter info of the architecture from + * the pmu_layouts table + * @pmu_info_list: the list that the new counter info of a pmu is added to. + * @table: pmu_layouts table that is searched for counter info. + */ +static int get_pmu_counter_layouts(struct list_head *pmu_info_list, + const struct pmu_layouts_table + *table) +{ + LIST_HEAD(list); + int ret; + + ret = pmu_layouts_table__for_each_layout(table, + metricgroup__add_pmu_layout_callback, &list); + + list_splice(&list, pmu_info_list); + return ret; +} + /** * hw_aware_build_grouping - Build event groupings by reading counter * requirement of the events and counter available on the system from @@ -1649,6 +1737,7 @@ static int hw_aware_build_grouping(struct expr_parse_ctx *ctx __maybe_unused, LIST_HEAD(event_info_list); size_t bkt; const struct pmu_events_table *etable = perf_pmu__find_events_table(NULL); + const struct pmu_layouts_table *ltable = perf_pmu__find_layouts_table(NULL); #define RETURN_IF_NON_ZERO(x) do { if (x) return x; } while (0) hashmap__for_each_entry(ctx->ids, cur, bkt) { @@ -1658,9 +1747,13 @@ static int hw_aware_build_grouping(struct expr_parse_ctx *ctx __maybe_unused, ret = get_metricgroup_events(id, etable, &event_info_list); if (ret) - return ret; + goto err_out; } + ret = get_pmu_counter_layouts(&pmu_info_list, ltable); +err_out: + metricgroup__free_event_info(&event_info_list); + metricgroup__free_pmu_info(&pmu_info_list); return ret; #undef RETURN_IF_NON_ZERO } From patchwork Fri Feb 9 03:14:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Weilin" X-Patchwork-Id: 198730 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp603404dyd; Thu, 8 Feb 2024 19:19:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IGT57/6weiFDuSSBpnvv+FHwVayUpwBU2PZlLl2lHIadTpErKvKWV01EiaVeBwfVVTvym2y X-Received: by 2002:a17:906:856:b0:a38:8d72:250f with SMTP id f22-20020a170906085600b00a388d72250fmr169317ejd.44.1707448745981; Thu, 08 Feb 2024 19:19:05 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707448745; cv=pass; d=google.com; s=arc-20160816; b=HlCJLkIaor/W8y6JT8FU7AGTCw36UUVx2tDeqUy+f9w2P7HSybL9QgIJ28whh5sLRa TmavjcGfytwkCgh54HbGQG5bALK+YJvFZyZNdk4Ne8IgP0Qy6uPkxOZEZKxUdnChqCtD 8nkAUIHbIpQGYGsfdiNGmVzSlPzpYiK9Rd0lorsKIadK9znMs7Uq0zr44z5Wi8B+JaZU tEdzUVcxUebRqsqvAL2iK1vVn7udxqGVFwalIaBfPQwLYCk0U0szSPMFxR0Q9M/PdI3z e3fePibBozufrot3SQsfhkf/HsvHpEBx8qE/f46UZIBUnQrNPRAat/Cogg1EGe+gWHet gH7w== 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=FinQGuT9orHUQEk/30shpQGLl4N5HqGIC/Q5zOUsiZk=; fh=dfYCFzqSUVhOLWMFN2JAnLq1nvDMjlvVJ/xhb0upcX4=; b=1AQMcE62h+PGFHBsUOfoR9O3hnWa3LXL02y27UJ4QH/VeLYDW5J43UW40QYciAF2vS +OhPIueFJa4ky00kMlZASgD/JnklCuU2tQhKCBPpjNQ5KmILpHuqcLoeCBRf27VioBK9 HlJA8VmS4tUt9KIf8KuTQz4jkjAwjuiRjaQwgzq5a93Mj4Z0KdToP8aGMeEgP3gbcuGg DqTHvThJUgyl6orYDl3GKiSDcUAIUM1JAa/u732SdqhjZSz3l4AVrvpKEWWu7NgdBTDW 2eEuYZutSEzv4QcJ3ru1KsM3k56a400R6bZI/EGtuX55bG8Gg7W/WBVyQm7SpK6llgDk nCLg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=eqZhLYem; 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-58975-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58975-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=2; AJvYcCVMNymLrX+DZjH629e/TN80NRg2B8yK6tnozEBTlPV1LvVakTQ+MzQu8f9jfrylXSVHUOrkZw8E9HyIWeYU85nFfI97vg== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id gs4-20020a170906f18400b00a37812ceee2si323667ejb.491.2024.02.08.19.19.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 19:19:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58975-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=eqZhLYem; 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-58975-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58975-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 606321F2181D for ; Fri, 9 Feb 2024 03:19:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 085C138DEC; Fri, 9 Feb 2024 03:15:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="eqZhLYem" 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 79F72FBF0; 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=qz3kM5DoMq8gQ6rf48/pO4LbEWxSYw+Aqdyj9+g9S8qiG28D2VAXp/qjngy0uVoeVGg04jhLAUlehqYAk3aKQo7GdrvQqtG0xBIwUS01/kIh8oNayLC1+EyQBlfTAjQBFR0q3tU0utQ4JpysO6syM62UlB8dTi+w8DYGOCD6vvQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707448496; c=relaxed/simple; bh=dstIOELs4oGs/0dQrJIS3jxgee0OEbKkbpMgzEO7qmE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=j/uHu6zWRBP+yZOzRkhTA54xHljloueEx31wCyJQPXaPIQ7GEYPXfIALXsj9NP4V0BH51NPJOK75HdzOQ3NWwCJQbFbULEN24sm1wahjb1R/CZdYxrgWbKBKKjZwqxGF6IotkCnsua9MQiifhuEMUJmJBqHj4Ax8MgRK4SR/fR4= 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=eqZhLYem; 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=dstIOELs4oGs/0dQrJIS3jxgee0OEbKkbpMgzEO7qmE=; b=eqZhLYem7ipIXGctCQMX5gIH43Psq/AkeoBwmsaEBaD+93ulCIWBESzV MWpvz7EtSLAuu60CvGWuPzNM5k0t0C6HcKsTebnZc8IeWnXtXkoq7lSU5 0GLSdHqcQZNLm+j92TVsd0oat/7bP68n5G99pPPGlNRS5Ii7q1z1G6KFi rPsdzOCE74S1sdujBsrD0Jx+2v6K0ORJjHxgakMZgM0jeh/gYzBMwGMN6 OkohqGHcDf0RzrcE2V09NPE+nKDzMY/bPH7oulRiyeIcEobXDx/5TFoJw 4w7/OnAd2Zyzkn6SDgYa3hy9JqbGDGu+ReTMV664qBv5Y+gRQ12lDKuRI Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10978"; a="1257920" X-IronPort-AV: E=Sophos;i="6.05,255,1701158400"; d="scan'208";a="1257920" 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="32631432" Received: from b49691a74b80.jf.intel.com ([10.165.54.183]) by orviesa002.jf.intel.com with ESMTP; 08 Feb 2024 19:14:47 -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 07/15] perf stat: Add functions to create new group and assign events into groups Date: Thu, 8 Feb 2024 19:14:33 -0800 Message-ID: <20240209031441.943012-8-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: 1790389775810230090 X-GMAIL-MSGID: 1790389775810230090 From: Weilin Wang Add struct metricgroup__pmu_group_list to hold the lists of groups from different PMUs. Each PMU has one separate list. Add struct metricgroup__group as one node (one group in the grouping result) of the metricgroup__pmu_group_list. It uses two bitmaps to log counter availabilities(gp counters and fixed counters). Add functions to create group and assign event into the groups based on the event restrictions (struct metricgroup__event_info) and counter availability (pmu_info_list and bitmaps). New group is inserted into the list of groups. Add functions to handle counter bitmaps. Add functions do find and insert operations to handle inserting event into groups. Add function to fill all bits of one counter bitmap. Add functions to create new groups when no counter is available in all the existing groups. Signed-off-by: Weilin Wang --- tools/perf/util/metricgroup.c | 296 ++++++++++++++++++++++++++++++++++ 1 file changed, 296 insertions(+) diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index 9061ed4ca015..f86e9a0b0d65 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -192,6 +192,41 @@ struct metricgroup__pmu_counters { size_t num_counters; size_t num_fixed_counters; }; +/** + * A list of event groups for this pmu. + * This is updated during the grouping. + */ +struct metricgroup__pmu_group_list { + struct list_head nd; + /** The name of the pmu(/core) the events collected on. */ + const char *pmu_name; + /** The number of gp counters in the pmu(/core). */ + size_t num_counters; + /** The number of fixed counters in the pmu(/core) if applicable. */ + size_t num_fixed_counters; + /** Head to the list of groups using this pmu(/core)*/ + struct list_head group_head; +}; +/** + * This is one node in the metricgroup__pmu_group_list. + * It represents on group. + */ +struct metricgroup__group { + struct list_head nd; + /** The bitmaps represent availability of the counters. + * They are updated once the corresponding counter is used by + * an event (event inserted into the group). + */ + DECLARE_BITMAP(gp_counters, NR_COUNTERS); + DECLARE_BITMAP(fixed_counters, NR_COUNTERS); + /** Head to the list of event names in this group*/ + struct list_head event_head; +}; + +struct metricgroup__group_events { + struct list_head nd; + const char *event_name; +}; /** * Each group is one node in the group string list. @@ -1487,6 +1522,34 @@ static int set_counter_bitmap(int pos, unsigned long *bitmap) return 0; } +/** + * Returns 0 on success. Finds the last counter that is not used in pmu_counters + * and supports the event, included in event_counters. + */ +static int find_counter_bitmap(const unsigned long *pmu_counters, + const unsigned long *event_counters, + unsigned long *bit) +{ + /*It is helpful to assign from the highest bit because some events can + *only be collected using GP0-3. + */ + unsigned long find_bit = find_last_and_bit(pmu_counters, event_counters, NR_COUNTERS); + + if (find_bit == NR_COUNTERS) + return -ERANGE; + *bit = find_bit; + return 0; +} + +static int use_counter_bitmap(unsigned long *bitmap, + unsigned long find_bit) +{ + if (find_bit >= NR_COUNTERS) + return -EINVAL; + __clear_bit(find_bit, bitmap); + return 0; +} + static int parse_fixed_counter(const char *counter, unsigned long *bitmap, bool *fixed) @@ -1544,6 +1607,38 @@ static int parse_counter(const char *counter, return 0; } +static void group_event_list_free(struct metricgroup__group *groups) +{ + struct metricgroup__group_events *e, *tmp; + + list_for_each_entry_safe(e, tmp, &groups->event_head, nd) { + list_del_init(&e->nd); + free(e); + } +} + +static void group_list_free(struct metricgroup__pmu_group_list *groups) +{ + struct metricgroup__group *g, *tmp; + + list_for_each_entry_safe(g, tmp, &groups->group_head, nd) { + list_del_init(&g->nd); + group_event_list_free(g); + free(g); + } +} + +static void metricgroup__free_group_list(struct list_head *groups) +{ + struct metricgroup__pmu_group_list *g, *tmp; + + list_for_each_entry_safe(g, tmp, groups, nd) { + list_del_init(&g->nd); + group_list_free(g); + free(g); + } +} + static void metricgroup__free_event_info(struct list_head *event_info_list) { @@ -1719,6 +1814,203 @@ static int get_pmu_counter_layouts(struct list_head *pmu_info_list, return ret; } +static int fill_counter_bitmap(unsigned long *bitmap, int start, int size) +{ + int ret; + + bitmap_zero(bitmap, NR_COUNTERS); + + for (int pos = start; pos < start + size; pos++) { + ret = set_counter_bitmap(pos, bitmap); + if (ret) + return ret; + } + return 0; +} + +/** + * Find if there is a counter available for event e in current_group. If a + * counter is available, use this counter by filling the bit in the correct + * counter bitmap. Otherwise, return error (-ERANGE). + */ +static int find_and_set_counters(struct metricgroup__event_info *e, + struct metricgroup__group *current_group) +{ + int ret; + unsigned long find_bit = 0; + + if (e->free_counter) + return 0; + if (e->fixed_counter) { + ret = find_counter_bitmap(current_group->fixed_counters, e->counters, + &find_bit); + if (ret) + return ret; + pr_debug("found counter for [event]=%s [e->fixed_counters]=%lu\n", + e->name, *current_group->fixed_counters); + ret = use_counter_bitmap(current_group->fixed_counters, find_bit); + } else { + ret = find_counter_bitmap(current_group->gp_counters, e->counters, + &find_bit); + if (ret) + return ret; + pr_debug("found counter for [event]=%s [e->gp_counters]=%lu\n", + e->name, *current_group->gp_counters); + ret = use_counter_bitmap(current_group->gp_counters, find_bit); + } + return ret; +} + +static int _insert_event(struct metricgroup__event_info *e, + struct metricgroup__group *group) +{ + struct metricgroup__group_events *event = malloc(sizeof(struct metricgroup__group_events)); + + if (!event) + return -ENOMEM; + event->event_name = e->name; + if (e->fixed_counter) + list_add(&event->nd, &group->event_head); + else + list_add_tail(&event->nd, &group->event_head); + return 0; +} + +/** + * Insert the new_group node at the end of the group list. + */ +static int insert_new_group(struct list_head *head, + struct metricgroup__group *new_group, + size_t num_counters, + size_t num_fixed_counters) +{ + INIT_LIST_HEAD(&new_group->event_head); + fill_counter_bitmap(new_group->gp_counters, 0, num_counters); + fill_counter_bitmap(new_group->fixed_counters, 0, num_fixed_counters); + list_add_tail(&new_group->nd, head); + return 0; +} + +/** + * Insert event e into a group capable to include it + * + */ +static int insert_event_to_group(struct metricgroup__event_info *e, + struct metricgroup__pmu_group_list *pmu_group_head) +{ + struct metricgroup__group *g; + int ret; + struct list_head *head; + + list_for_each_entry(g, &pmu_group_head->group_head, nd) { + ret = find_and_set_counters(e, g); + if (!ret) { /* return if successfully find and set counter*/ + ret = _insert_event(e, g); + return ret; + } + } + /* + * We were not able to find an existing group to insert this event. + * Continue to create a new group and insert the event in it. + */ + { + struct metricgroup__group *current_group = + malloc(sizeof(struct metricgroup__group)); + + if (!current_group) + return -ENOMEM; + pr_debug("create_new_group for [event] %s\n", e->name); + + head = &pmu_group_head->group_head; + ret = insert_new_group(head, current_group, pmu_group_head->num_counters, + pmu_group_head->num_fixed_counters); + if (ret) + return ret; + ret = find_and_set_counters(e, current_group); + if (ret) + return ret; + ret = _insert_event(e, current_group); + } + + return ret; +} + +/** + * assign_event_grouping - Assign an event into a group. If existing group + * cannot include it, create a new group and insert the event to it. + */ +static int assign_event_grouping(struct metricgroup__event_info *e, + struct list_head *pmu_info_list, + struct list_head *groups) +{ + int ret = 0; + + struct metricgroup__pmu_group_list *g = NULL; + struct metricgroup__pmu_group_list *pmu_group_head = NULL; + + list_for_each_entry(g, groups, nd) { + if (!strcasecmp(g->pmu_name, e->pmu_name)) { + pr_debug("found group for event %s in pmu %s\n", e->name, g->pmu_name); + pmu_group_head = g; + break; + } + } + if (!pmu_group_head) { + struct metricgroup__pmu_counters *p; + + pmu_group_head = malloc(sizeof(struct metricgroup__pmu_group_list)); + if (!pmu_group_head) + return -ENOMEM; + INIT_LIST_HEAD(&pmu_group_head->group_head); + pr_debug("create new group for event %s in pmu %s\n", e->name, e->pmu_name); + pmu_group_head->pmu_name = e->pmu_name; + list_for_each_entry(p, pmu_info_list, nd) { + if (!strcasecmp(p->name, e->pmu_name)) { + pmu_group_head->num_counters = p->num_counters; + pmu_group_head->num_fixed_counters = p->num_fixed_counters; + break; + } + } + list_add_tail(&pmu_group_head->nd, groups); + } + + ret = insert_event_to_group(e, pmu_group_head); + return ret; +} + +/** + * create_grouping - Create a list of groups and place all the events of + * event_info_list into these groups. + * @pmu_info_list: the list of PMU units info based on pmu-events data, used for + * creating new groups. + * @event_info_list: the list of events to be grouped. + * @groupings: the list of groups with events placed in. + * @modifier: any modifiers added to the events. + */ +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) +{ + int ret = 0; + struct metricgroup__event_info *e; + LIST_HEAD(groups); + char *bit_buf = malloc(NR_COUNTERS); + + //TODO: for each new core group, we should consider to add events that uses fixed counters + list_for_each_entry(e, event_info_list, nd) { + bitmap_scnprintf(e->counters, NR_COUNTERS, bit_buf, NR_COUNTERS); + pr_debug("Event name %s, [pmu]=%s, [counters]=%s\n", e->name, + e->pmu_name, bit_buf); + ret = assign_event_grouping(e, pmu_info_list, &groups); + if (ret) + goto out; + } +out: + metricgroup__free_group_list(&groups); + return ret; +}; + /** * hw_aware_build_grouping - Build event groupings by reading counter * requirement of the events and counter available on the system from @@ -1750,6 +2042,10 @@ static int hw_aware_build_grouping(struct expr_parse_ctx *ctx __maybe_unused, goto err_out; } ret = get_pmu_counter_layouts(&pmu_info_list, ltable); + if (ret) + goto err_out; + ret = create_grouping(&pmu_info_list, &event_info_list, groupings, + modifier); err_out: metricgroup__free_event_info(&event_info_list); From patchwork Fri Feb 9 03:14:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Weilin" X-Patchwork-Id: 198727 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp603091dyd; Thu, 8 Feb 2024 19:18:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IGuVShzs6Vu/HPajbKaQKOYu8tKhYdUQm1XqJ0JCHH/wHz1ecQMZ0qKu/5jpBd3e+CZQ9IU X-Received: by 2002:a05:6402:148a:b0:55f:e584:221e with SMTP id e10-20020a056402148a00b0055fe584221emr270411edv.29.1707448681893; Thu, 08 Feb 2024 19:18:01 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707448681; cv=pass; d=google.com; s=arc-20160816; b=IDlS1Eyhuu465e2yDUEY+3FAv7at6oegJxgQpX7luMfiwUEsZiMzVdRw2vAemhjxai gRqYCNQrJ6nNZ14/SuW/NcqTa23znrXH8lzOWO3NpQ8vjgovJMuyg7ZHbcZfJgWqXFob G47YCJAazvS12J8pZoL9Xj/B9yFAx1CI1ZoMo66VOmsUq1gVn+P7Mr0jp3LQ9XpG9KUW uA4zneaMsKAJl6kwN1qjJtjvtek2mZAIOUefmI0dGjbVDdsgNJwordXb7KOI+Cl2tmj4 Jsc4RiDBOaLU4XMpiiHaKSKPt0k7tiTSnIsT2vIY7iZ66aIKwW3Z7bYJaDeGguVJHjuR 4Rrg== 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=dEEYxQM+NSmUkZcFZV0H8H1jBOSGl1rEVsPMJ6+VB3c=; fh=v6M/VM/BJSN9lWxGxZlu+V+IL6NsBkZTpW5xwTnRAiA=; b=Bv27b1c2OnQOqFsYZEcuLzCQkh6ktjZp34YldtCp7/m3OO2wwzU5UJsmkMrGsGgeoU t6Efq3M0qgjMl8EDqsu1rQq5KuWK6sLoo8mitfSwcdrwSx8glcrYl6UsNaBFgUe0G11Q ODKdoVxqciCN2DtFdpOQ35dO7QVv7i7jfBH9DqYdqYhWb3m1k7mc+YAnWurOvfwdVSdF G0xwV5hfxKnvA6r3FhEy3A1E8vJqg2BOGyDMqQIfv3ZQaZVC3ncqAA2rZI2IHdfkzB6w t2Wmb03fK3s+JlqUOpV8U3YN9jNH6lWFfCzXw19N0wZgvVIUwYt+Y10vgoPGm6iwiL9B Rg0w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=GrXXwEFZ; 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-58973-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58973-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=2; AJvYcCUmHKmfTE5Uo7DZPQzphmL6qu7Lxhx6KcCxVMyEV6AY2JUodGcl0eT+M0/LJt44gJI+wx3cBjULeDOdcOdTdAmv8D6jtg== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id i14-20020a056402054e00b0056141017becsi101485edx.523.2024.02.08.19.18.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 19:18:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58973-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=GrXXwEFZ; 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-58973-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58973-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 779E91F2204B for ; Fri, 9 Feb 2024 03:18:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 719B31B268; Fri, 9 Feb 2024 03:14:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="GrXXwEFZ" 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 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790389709058052430 X-GMAIL-MSGID: 1790389709058052430 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; } +static int hw_aware_metricgroup__build_event_string(struct list_head *group_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 = true; + int ret = 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 = + malloc(sizeof(struct metricgroup__group_strs)); + + if (!new_group_str) + return -ENOMEM; + strbuf_init(&new_group_str->grouping_str, 0); + events = &new_group_str->grouping_str; + ret = strbuf_addch(events, '{'); + RETURN_IF_NON_ZERO(ret); + no_group = true; + list_for_each_entry(ge, &g->event_head, nd) { + const char *sep, *rsep, *id = ge->event_name; + + pr_debug("found event %s\n", id); + + /* Separate events with commas and open the group if necessary. */ + if (!no_group) { + ret = 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=msr!3tsc!3/ + */ + sep = strchr(id, '@'); + if (sep) { + ret = strbuf_add(events, id, sep - id); + RETURN_IF_NON_ZERO(ret); + ret = strbuf_addch(events, '/'); + RETURN_IF_NON_ZERO(ret); + rsep = strrchr(sep, '@'); + ret = strbuf_add(events, sep + 1, rsep - sep - 1); + RETURN_IF_NON_ZERO(ret); + ret = strbuf_addstr(events, ",metric-id="); + RETURN_IF_NON_ZERO(ret); + sep = rsep; + } else { + sep = strchr(id, ':'); + if (sep) { + ret = strbuf_add(events, id, sep - id); + RETURN_IF_NON_ZERO(ret); + } else { + ret = strbuf_addstr(events, id); + RETURN_IF_NON_ZERO(ret); + } + ret = strbuf_addstr(events, "/metric-id="); + RETURN_IF_NON_ZERO(ret); + } + ret = encode_metric_id(events, id); + RETURN_IF_NON_ZERO(ret); + ret = strbuf_addstr(events, "/"); + RETURN_IF_NON_ZERO(ret); + + if (sep) { + ret = strbuf_addstr(events, sep + 1); + RETURN_IF_NON_ZERO(ret); + } + if (modifier) { + ret = strbuf_addstr(events, modifier); + RETURN_IF_NON_ZERO(ret); + } + no_group = false; + } + ret = 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 = 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 = hw_aware_metricgroup__build_event_string(groupings, modifier, &groups); 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 = cur->pkey; - pr_debug("found event %s\n", id); - ret = get_metricgroup_events(id, etable, &event_info_list); if (ret) goto err_out; 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, From patchwork Fri Feb 9 03:14:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Weilin" X-Patchwork-Id: 198728 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp603263dyd; Thu, 8 Feb 2024 19:18:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IGM007mD0O6fg14dxKHPdYGB+bkMP+qaobzyTYSO/BzPzDAfNY6iLXVzgJssNzzWlCKQox2 X-Received: by 2002:a05:622a:1341:b0:42b:eeb6:d86d with SMTP id w1-20020a05622a134100b0042beeb6d86dmr462778qtk.52.1707448719110; Thu, 08 Feb 2024 19:18:39 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707448719; cv=pass; d=google.com; s=arc-20160816; b=ArxNUNb4KRm0LSVpB/JSgP3VAXUX5V9Bdmh52B3wXwtveVxAmFxegdenFJ5l2kn6+z FXpeA6Jxcj7ZggDsi/tkt81WdejIune7WgcHPCgv2Rv6MJYGE7MbhHSEjzfnDbYMWh6V ZqDbIwAOMIcDnAbfQeiJgQZbiLxaDCQRrMjGWBCpScyK/SMCiFf4HKypCDjGU1igae1l pEDYow3lOOWeOz7hFjn5MSn0xwqB/mkxBIBgS9JNRGow1CL4gyyH7Vldbl9CC3MNhHHk XpJwTd9fj5mU69LdMLbTiL9PYJtJKeJfBvfuoy5SfruW5hCwXtibUsIYNxpT2rrg6ZfI i8TA== 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=Nc3+SPSo4/ixtlM3ZHYwLHCusmbGaHjp/PDt0/j6WBg=; fh=q67hoTm05egYIkoXg8jfY0NPaThEGY0Dc3Fln4PYS5w=; b=gn7PbSA2HT6w2YyeMZwVHThucpxI8Aisgp3bBSsKXpmUziupY3K6kQYNc/YniZaBzj CBKDkEs/zxCwLnu6rSo4odzmUdQIGDZJL7yLFbOalbnUFTIkRn/dWhVzIQE/rLRujdoT aALYfGm6gR/qP8wy22p/7R9zp+uKMK50g8SndGybdYQfAmmyd+zyMtPEzpDBU0hrdVB8 +jhqO9rGm/5B6fs1cWCNrLCCp8Eo6KSY5PPMI6+M+avqAXXXtLAiS0HdHXV/veh8U1Eq P05ZcfG80NQHFEI67HG9fbje3hy9YDx5qd71STEFq77LjDrMCf9JwT7SO5lG/AXFlGXE RkuA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=dIHfv6p6; 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-58976-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58976-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=2; AJvYcCWE2bpjYLenNV1IRv16MizMw2lbax7TMNKnifLhtHzdyNYyq7nSygljEk3PvCcUJRRefHZCbOY0IXHB1jwKThc+B11uig== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id a19-20020a05622a065300b0042c5736e663si986335qtb.572.2024.02.08.19.18.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 19:18:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58976-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=dIHfv6p6; 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-58976-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58976-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id E23771C23EC8 for ; Fri, 9 Feb 2024 03:18:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1472B381B6; Fri, 9 Feb 2024 03:15:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="dIHfv6p6" 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 2C77A12E52; Fri, 9 Feb 2024 03:14:55 +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=Gnk0PSvnW25q6CvsIbjvuURYKkWW07UCVaN0LKoqjbQ270IS80SKfNk2dsUX3hlH3SskwyS+z7/Ld1wCvTaiShE7UWarZnT4n4HNtj1k3bY3n1qwP6eZK2xs8xd3rjg+8UtE9N37+Pvuh9Wv3UaTyGRHHzvTylE5qxaQH4JD+vM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707448496; c=relaxed/simple; bh=iGYgMhf+uN2QB4bkriW/0fEdhb3pg3tSD8oxatmuXLQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lSuCsbV2w9avXM7bo6Pn6JDOuw1M6eY1yNYicrm+O+itbLQQZVQ2M4A9SGe4kizHsU6kQveuQQOEhGo0II1fsIL83EbcIN5rlkc7BEUab4pNb0OJfXNcXvTeUXYrBOfMmxoJT8QxzpozTDxNF3xxoERPkfPR333mFrg1Tb7/grE= 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=dIHfv6p6; 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=iGYgMhf+uN2QB4bkriW/0fEdhb3pg3tSD8oxatmuXLQ=; b=dIHfv6p6e47SA/Yv1vmjZzsSp0HV3KJTK0NTy3LbvnFYIE91VbOKr7FK oK9iuEEAYC6CTC8GdBBwd9bdU0ISP9PITtn85m9PZfYYsE2CboYA39tir +urUoqx6zzQQbWUwD5QpkA4whS37zsrmziDXC+2CBEMoP8Usjign3j13X boR8OJf2ll2S0zQTIdrWErublOvHuJBRyXOhhETJHrG3ayRbLvcB5kHB3 Rf+cPBfj1vqbjpFhf6gacqFxOstuCZcPMMIG83hlLi1Wdej42a43MYg7B SPNmMsH+w4iX+878wxgyj/pO8+s7XilYiL8OHq2QxIQyYY/2yD2mDR4aM g==; X-IronPort-AV: E=McAfee;i="6600,9927,10978"; a="1257934" X-IronPort-AV: E=Sophos;i="6.05,255,1701158400"; d="scan'208";a="1257934" 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="32631443" 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 10/15] perf stat: Add function to combine metrics for hardware-grouping Date: Thu, 8 Feb 2024 19:14:36 -0800 Message-ID: <20240209031441.943012-11-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: 1790389747876206867 X-GMAIL-MSGID: 1790389747876206867 From: Weilin Wang This function is very similar to the existing build_combined_expr_ctx(). Should be able to reuse current function instead of adding a new one. Will fix this later. Signed-off-by: Weilin Wang --- tools/perf/util/metricgroup.c | 47 ++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index a0579b0f81e5..fe115f0880f9 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -1525,6 +1525,46 @@ static int build_combined_expr_ctx(const struct list_head *metric_list, return ret; } +/** + * hw_aware_build_combined_expr_ctx - Make an expr_parse_ctx with all !group_events + * metric IDs, as the IDs are held in a set, + * duplicates will be removed. + * @metric_list: List to take metrics from. + * @combined: Out argument for result. + */ +static int hw_aware_build_combined_expr_ctx(const struct list_head *metric_list, + struct expr_parse_ctx **combined) +{ + struct hashmap_entry *cur; + size_t bkt; + struct metric *m; + char *dup; + int ret; + + *combined = expr__ctx_new(); + if (!*combined) + return -ENOMEM; + + list_for_each_entry(m, metric_list, nd) { + hashmap__for_each_entry(m->pctx->ids, cur, bkt) { + pr_debug2("metric: %s\n", m->metric_name); + dup = strdup(cur->pkey); + if (!dup) { + ret = -ENOMEM; + goto err_out; + } + ret = expr__add_id(*combined, dup); + if (ret) + goto err_out; + } + } + return 0; +err_out: + expr__ctx_free(*combined); + *combined = NULL; + return ret; +} + /** * set_counter_bitmap - The counter bitmap: [0-15]. */ @@ -1815,8 +1855,7 @@ static int metricgroup__add_pmu_layout_callback(const struct pmu_layout *pl, * @table: pmu_layouts table that is searched for counter info. */ static int get_pmu_counter_layouts(struct list_head *pmu_info_list, - const struct pmu_layouts_table - *table) + const struct pmu_layouts_table *table) { LIST_HEAD(list); int ret; @@ -2248,6 +2287,8 @@ static int hw_aware_parse_ids(struct perf_pmu *fake_pmu, *out_evlist = parsed_evlist; parsed_evlist = NULL; err_out: + parse_events_error__exit(&parse_error); + evlist__delete(parsed_evlist); metricgroup__free_grouping_strs(&groupings); return ret; } @@ -2370,7 +2411,7 @@ static int hw_aware_parse_groups(struct evlist *perf_evlist, if (!metric_no_merge) { struct expr_parse_ctx *combined = NULL; - ret = build_combined_expr_ctx(&metric_list, &combined); + ret = hw_aware_build_combined_expr_ctx(&metric_list, &combined); if (!ret && combined && hashmap__size(combined->ids)) { ret = hw_aware_parse_ids(fake_pmu, combined, From patchwork Fri Feb 9 03:14:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Weilin" X-Patchwork-Id: 198733 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp604076dyd; Thu, 8 Feb 2024 19:21:20 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUkxFZoQKvFiOWBOOXGg7kLeFQbfihoOWXWM6XsUUX1Y5n0iDRspP/1oUho/j7L6fhpb530K7J7FrlGqieYXXD7tURAqA== X-Google-Smtp-Source: AGHT+IE1KaQd/uZCWXXpPzfP3IVyfJDDqG00xR8zJn0KLr2uSG6C7YujyWGvPESgtBd9J+zR+bg4 X-Received: by 2002:a17:903:41cc:b0:1d9:5ef2:abdd with SMTP id u12-20020a17090341cc00b001d95ef2abddmr507466ple.0.1707448879917; Thu, 08 Feb 2024 19:21:19 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707448879; cv=pass; d=google.com; s=arc-20160816; b=SM+Lvt/TIBRfc4oRmL5oep6ojwCFuopaEn56NybAd3F3CGtRlje5W0qhbeG1+wMojr afRU1bFJOEGTuN3DOIW4Sjr2vknS0k7CnmPowK2MHEPCIGR26ezl/ukFyqVii1S7uGyJ 4zJcskWAB4JmRLEL6sY9RJxWRqTJYbnsCuAGWeFWyKdCrznBCjYA5fNPx2zagzihskoG Dw7lpca2PHrAjJ3ryfoNe4DGsGekGr2b7nTu6uhB+BfeoA+tXJH1dJnnbYi/4BwZrUyk XSMgwrzBiOVGc7B/uukoYKpuOWiBtjlziRkeAyA+7B1ogJu01o1C3JKlOFitES3OZtPj ec5w== 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=pf4JOjYWAIoSVE6abYShzHFZmO/O1CMeAtoQYfh4IaM=; fh=9lw31hC6CbMiSZo+agMckVUArO1I7n11wVty+B3eP5I=; b=aqpCSEEkaZEO6GD4cea0lDGcRcZHAxwMvHMDSBPbRAupE4QKsaquXKisdGmpJOEERH b69nWPhcFPclapxlgBMb4y/dbH8f2wz/TAVnE7JhYhBorHCV3eYHsDOS9LDMfL3TPRmu pXqoTvhWyS18hzvtNrYBcfpRowOjCW2ec5+Z9shjLGCLsKTUlOFyreHzK7W/irctszjT ElhIzFRDoGgeipCa9B6dfP+1HP6oxVY6J5RoWcgiv7P5Yb5EO7+xR7BYLXcFNXjuVp3g vGTysTfKKyqbviH7ZsTa1zCdByoXwNaQ4TgH6/Jh/5ot8esMFqs58geBnzncyQF5lJkF AZgQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Lq5497B1; 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-58978-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58978-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=2; AJvYcCV5DFPEdbTKpczLJBwT+1ZeVb++rWIFKKcDGCxLhntpegE3YfbfLQjMDKsxs/adkKGOClwHtOAkXdvW4eYMjZDx2d9gDw== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id ju8-20020a170903428800b001d9773a198fsi822547plb.409.2024.02.08.19.21.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 19:21:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58978-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Lq5497B1; 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-58978-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58978-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id B7776284AAD for ; Fri, 9 Feb 2024 03:19:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A987E38FAD; Fri, 9 Feb 2024 03:15:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Lq5497B1" 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 988A01864C; Fri, 9 Feb 2024 03:14:56 +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=1707448498; cv=none; b=lt6LXKcazX53N4yR8nC/HW9liRo3wzLdeVi9dd0Y2tQbF1nS7pCmHtV/lU4xj7nPdQ/6XbWNCbJ/9ehnuAAGJaNjbpOtp4GCEEf4hiHQ8sVlNaI+L1nVDvdn0SnBkcamOITJQwHfqE8ST4Cf4YFAeYjKdpEIiwnMdAH/Jln0Cec= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707448498; c=relaxed/simple; bh=mL5H4TvbTCZl43JaCvHWfIfur/YIYIR57bOSDnbW6HY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=d1MmKi/Xpuvb51FWD4O0rtlUJkNegwpRy5BSN7Dm3xtVfbnEEt1mPEvjW39myg8rb0UnhVRTJOHdxtVhwxnwaSVWpcMp9I7hM55hVAdIiLKQASli49qY9RThBMVaLeIk3dWoBZ6TBTfoxk/iQKTsikdy9D6t+Oqpn5MsG7w1r9g= 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=Lq5497B1; 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=1707448497; x=1738984497; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=mL5H4TvbTCZl43JaCvHWfIfur/YIYIR57bOSDnbW6HY=; b=Lq5497B1TlTNJwvvzgE4f1s4aFE0i7U7kXKoMVhif80WuJvmsrV7mbnB BvntQpHhfZXiN3vJfrSe4lR1vstnIdoi56TMa5FAVHevwlDJ3w1YTSzqf HW7bDHcci8AVDmkU2MILm1ltP60GUIrO/B3zM+xP7QQ3o7WNaEoPW0YPg m+EXFsL4Qorhr4LZbKEWnfjOqsNX5Ve3lTw/w+HyD8lqB1T46yQOXz/ju lavxIztXgHI2KFwIrNEe0mR1VS9oDlpO9ja3I6BLEG2I8z6bYvcKaTMRy We6WfIrAIsdH4XVkSxc9HwJ0bywa04PnvvGgwe1gphT+aJG53FJl8fNaf g==; X-IronPort-AV: E=McAfee;i="6600,9927,10978"; a="1257942" X-IronPort-AV: E=Sophos;i="6.05,255,1701158400"; d="scan'208";a="1257942" 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="32631446" 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 11/15] perf stat: Handle taken alone in hardware-grouping Date: Thu, 8 Feb 2024 19:14:37 -0800 Message-ID: <20240209031441.943012-12-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: 1790389916667544212 X-GMAIL-MSGID: 1790389916667544212 From: Weilin Wang Add taken alone into consideration when grouping. Only one taken alone event is supported per group. Signed-off-by: Weilin Wang --- tools/perf/pmu-events/jevents.py | 7 ++++++- tools/perf/pmu-events/pmu-events.h | 1 + tools/perf/util/metricgroup.c | 20 +++++++++++++++----- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jevents.py index bc91b7efa49a..4fbb367a3228 100755 --- a/tools/perf/pmu-events/jevents.py +++ b/tools/perf/pmu-events/jevents.py @@ -56,7 +56,9 @@ _json_event_attributes = [ # The list of counter(s) this event could use 'counters', # Longer things (the last won't be iterated over during decompress). - 'long_desc' + 'long_desc', + # Taken alone event could not be collected in the same group with other taken alone event + 'taken_alone' ] # Attributes that are in pmu_unit_layout. @@ -355,6 +357,9 @@ class JsonEvent: self.num_counters = jd.get('NumCounters') # Number of fixed counter self.num_fixed_counters = jd.get('NumFixedCounters') + # If the event is taken alone event, which cannot be grouped with any other + # taken alone event. + self.taken_alone = jd.get('TakenAlone') filter = jd.get('Filter') self.unit = jd.get('ScaleUnit') self.perpkg = jd.get('PerPkg') diff --git a/tools/perf/pmu-events/pmu-events.h b/tools/perf/pmu-events/pmu-events.h index e245e4738970..837edfeb676a 100644 --- a/tools/perf/pmu-events/pmu-events.h +++ b/tools/perf/pmu-events/pmu-events.h @@ -54,6 +54,7 @@ struct pmu_event { const char *unit; bool perpkg; bool deprecated; + bool taken_alone; }; struct pmu_metric { diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index fe115f0880f9..95d3868819e3 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -189,6 +189,7 @@ struct metricgroup__event_info { /** The event uses special counters that we consider that as free counter * during the event grouping*/ bool free_counter; + bool taken_alone; /** The counters the event allowed to be collected on. */ DECLARE_BITMAP(counters, NR_COUNTERS); }; @@ -235,6 +236,7 @@ struct metricgroup__group { DECLARE_BITMAP(fixed_counters, NR_COUNTERS); /** Head to the list of event names in this group*/ struct list_head event_head; + bool taken_alone; }; struct metricgroup__group_events { @@ -1717,6 +1719,7 @@ static void metricgroup__free_pmu_info(struct list_head *pmu_info_list) static struct metricgroup__event_info *event_info__new(const char *name, const char *pmu_name, const char *counter, + bool taken_alone, bool free_counter) { int ret = 0; @@ -1731,6 +1734,7 @@ static struct metricgroup__event_info *event_info__new(const char *name, pmu_name = "core"; e->name = name; + e->taken_alone = taken_alone; e->free_counter = free_counter; e->pmu_name = pmu_name; if (free_counter) { @@ -1769,7 +1773,8 @@ static int metricgroup__add_metric_event_callback(const struct pmu_event *pe, if (!strcasecmp(pe->name, d->event_name)) { if (!pe->counters) return -EINVAL; - event = event_info__new(d->event_id, pe->pmu, pe->counters, /*free_counter=*/false); + event = event_info__new(d->event_id, pe->pmu, pe->counters, + pe->taken_alone, /*free_counter=*/false); if (!event) return -ENOMEM; list_add(&event->nd, d->list); @@ -1892,6 +1897,8 @@ static int find_and_set_counters(struct metricgroup__event_info *e, int ret; unsigned long find_bit = 0; + if (e->taken_alone && current_group->taken_alone) + return -ENOSPC; if (e->free_counter) return 0; if (e->fixed_counter) { @@ -1926,11 +1933,13 @@ static int _insert_event(struct metricgroup__event_info *e, list_add(&event->nd, &group->event_head); else list_add_tail(&event->nd, &group->event_head); + if (e->taken_alone) + group->taken_alone = true; return 0; } /** - * Insert the new_group node at the end of the group list. + * Initialize the new group and insert it to the end of the group list. */ static int insert_new_group(struct list_head *head, struct metricgroup__group *new_group, @@ -1940,6 +1949,7 @@ static int insert_new_group(struct list_head *head, INIT_LIST_HEAD(&new_group->event_head); fill_counter_bitmap(new_group->gp_counters, 0, num_counters); fill_counter_bitmap(new_group->fixed_counters, 0, num_fixed_counters); + new_group->taken_alone = false; list_add_tail(&new_group->nd, head); return 0; } @@ -2143,8 +2153,8 @@ static int create_grouping(struct list_head *pmu_info_list, //TODO: for each new core group, we should consider to add events that uses fixed counters list_for_each_entry(e, event_info_list, nd) { bitmap_scnprintf(e->counters, NR_COUNTERS, bit_buf, NR_COUNTERS); - pr_debug("Event name %s, [pmu]=%s, [counters]=%s\n", e->name, - e->pmu_name, bit_buf); + pr_debug("Event name %s, [pmu]=%s, [counters]=%s, [taken_alone]=%d\n", + e->name, e->pmu_name, bit_buf, e->taken_alone); ret = assign_event_grouping(e, pmu_info_list, &groups); if (ret) goto out; @@ -2191,7 +2201,7 @@ static int hw_aware_build_grouping(struct expr_parse_ctx *ctx __maybe_unused, if (is_special_event(id)) { struct metricgroup__event_info *event; - event = event_info__new(id, "default_core", "0", + event = event_info__new(id, "default_core", "0", false, /*free_counter=*/true); if (!event) goto err_out; From patchwork Fri Feb 9 03:14:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Weilin" X-Patchwork-Id: 198729 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp603366dyd; Thu, 8 Feb 2024 19:19:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IExZQZfHKQR4gB8f24S3q2DPpv2pGA7O4Ct391u1Df98h32WhpdPvzcrgZQniygPox5JUPM X-Received: by 2002:a05:620a:3dc:b0:785:5efd:fc22 with SMTP id r28-20020a05620a03dc00b007855efdfc22mr472481qkm.11.1707448740686; Thu, 08 Feb 2024 19:19:00 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707448740; cv=pass; d=google.com; s=arc-20160816; b=yEUckgE2xJAm9QzGThhXoPAjYUmU7EIf6MNFiY3lgdCPxvJRgXaIs5RmcV/M2rfqrG 7uZCZ0pH2lY6OOKV/v5zzUUGmgeGf4tJYeLxGv/8Owuw9D7CRC4vtTQJdQtXLYWiahuQ 7LSTBMdPQX3U4uLlv7eWLwQQZ1/+3Vh24uOuBO0QXW4+Zzk+fbszV0912ikHyt/WsT05 s6xVBn2GoV6vrxdHwd5KjbagSefVFnJOSht48x248b8x0sBDX2i99gGS+Bx/MbXh+rk/ vyph4vAupxbwOXN9UAhekJREJVVVhJsTph3lyjAgW2Cblc9/tp9fJQOw9C+ppuaoanTp ce3w== 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=sprFx4bZ30C0GLwPKmPka9LXaGYqs99o+NarEg714E0=; fh=Cg2Lf4VfOgzNOwgDQRFr8glYFjONudX9KrdqQrp8XDU=; b=e7YlkRofhKQVsHTzvDDIoTdlhSHh004lyA1lmFKPzWASp+alYb1NstEfIV9Evmqo1u P20xdIwMzSDYC2xQUyD7CRHiytItdtHf1LqCLsZGKFmu1XgCktZ1CSjzyyoRyvmb8vO6 FBKN0tX+bTdofkzy71HqC+O6SYVl3fprLzcc4p0Bxs2FzDR9t2QaMPY7JuItx+H+iY/K u5lAxgECMKvZgQYpHmPjzXml+C7X3hswYM2KBCT/hB7qQiBPujOFWA91qyd7kEEdgtda b8svdc7tMr/QK8+Fo9As03DojYCFL8YS0ALQ+ZrL9le7f4xpniYJXs3igEz21mdGlAzJ 28/g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=YvX5ZOHU; 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-58977-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58977-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=2; AJvYcCX2z2MrgTjRTcU2NhiXEVzB2MJgWjlrUj7uAMnXI8w/L1eMwUEzAEHlRQLD5cvtTDiCVGM+JXL9W7T8UDcXemeerqByWA== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id j15-20020a05622a038f00b0042c4c4622fcsi946431qtx.738.2024.02.08.19.19.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 19:19:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58977-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=YvX5ZOHU; 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-58977-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58977-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 7AB271C20F43 for ; Fri, 9 Feb 2024 03:19:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D915938DE2; Fri, 9 Feb 2024 03:15:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="YvX5ZOHU" 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 DAFDF1B942; Fri, 9 Feb 2024 03:14:56 +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=1707448498; cv=none; b=Ho3VBPkylD9d/eFT/hNUK/nIh/OL7wKB8Wk9MEYkHaybgvnlStYQ1uHDQzPMfzsHqz0f+nYB9TdpZKFMs+X4ynWzcrWJtqvk8M2Oc+MHOdgW2ZM/Z5mp2vL9JHpXTztq7kOhc0kYFiUHAtC/95qnCCtmJuOSB3m0e9eZCS6KEeM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707448498; c=relaxed/simple; bh=4TtYi0lpyHo54jJPp5QX24oZBCSlhJrdo5RjQxIdVIQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fvkQRl9fC3Xk/1oWK1mNUi7+Pu5uz7WCaOvEL1grMaa31F3aGWUcXsaS6afKBU08Mwc7hPDjdzDrhqoxaCD0xErQYKC9TRK15GIQrgLMg2VzyFJ8x2z/x58ml4+sxLVe0jBfv7vPnq2z3qOC7wJyv9wqz1C+alb1WOlHiXE4e/Y= 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=YvX5ZOHU; 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=1707448497; x=1738984497; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=4TtYi0lpyHo54jJPp5QX24oZBCSlhJrdo5RjQxIdVIQ=; b=YvX5ZOHUqwP3G1ate8wcnTfVlfuOyfr7O/qCqXAZ68Ge1r5b3JROXJLf 7cshPAcNRX5PM87/kclURq/Au/1RcycLx/Xvst0gwZMSDFdcYSrEcTiYr SKlNQU2emAolnmSDmFLQrPRiOX7/M8AfTrvDU8gdHsGQJzYZbR78/5Crd 0iMNelEADLrD6vwffGIj4V7t1WQ6dMrAktEic5y981ZJP2uP8IXgAd84X ZO47tYgfliOQ7n202VabwbSTqtzm57wNorgjJVWF3EHuHTNetSDEEIk0q HCnhqibMWTcXVnUOt/RhKid6vaUFMggutMT/nPyXBwVrjBoCpHplRPq0K w==; X-IronPort-AV: E=McAfee;i="6600,9927,10978"; a="1257945" X-IronPort-AV: E=Sophos;i="6.05,255,1701158400"; d="scan'208";a="1257945" 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="32631450" 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 12/15] perf stat: Handle NMI in hardware-grouping Date: Thu, 8 Feb 2024 19:14:38 -0800 Message-ID: <20240209031441.943012-13-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: 1790389770733860097 X-GMAIL-MSGID: 1790389770733860097 From: Weilin Wang Add an easy nmi watchdog support in grouping. When nmi watchdog is enabled, we reduce the total num of events could be assigned to one group by 1. A more efficient solution will be added in later. Signed-off-by: Weilin Wang --- tools/perf/util/metricgroup.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index 95d3868819e3..f1eb73957765 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -1947,6 +1947,10 @@ static int insert_new_group(struct list_head *head, size_t num_fixed_counters) { INIT_LIST_HEAD(&new_group->event_head); + if (sysctl__nmi_watchdog_enabled()) { + pr_debug("NMI watchdog is enabled. Reduce num of counters by 1\n"); + num_counters -= 1; + } fill_counter_bitmap(new_group->gp_counters, 0, num_counters); fill_counter_bitmap(new_group->fixed_counters, 0, num_fixed_counters); new_group->taken_alone = false; From patchwork Fri Feb 9 03:14:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Weilin" X-Patchwork-Id: 198732 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp603657dyd; Thu, 8 Feb 2024 19:19:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IHRXGaTsfRgXPz9Q90XPZZu/HDLIE+pNkhcQQTHCI0iRGg/SjTg2ly9YRmhr7dG03LwEUWB X-Received: by 2002:a17:906:e44:b0:a38:532a:f72b with SMTP id q4-20020a1709060e4400b00a38532af72bmr308585eji.17.1707448795180; Thu, 08 Feb 2024 19:19:55 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707448795; cv=pass; d=google.com; s=arc-20160816; b=qx0Q6y19J/Pm1IuA87JNIDQUrsO58vwhRw4q4E5up2+0dOL1t2/cXpdTcVsCFHf6hY zviF50eWgnbxngsl4r8CkD/w8iIZ6iPfsmw8b2ZSikc327X3B5iF2SisX1lla1IzB7M+ 8Y9fu0tdKPjSfi4DmRzETvjQgXtnWKxmJ/5tPtT7lzUwmdFM+jGN3WSSqxUpYkcRMNlq rSksWVWz7edh+GXPixS7WRiVGeVHa20Q3qBm4Z1OoPgXPfnMlQeymEUBD6eRGZeJ0Za3 KEpKKR7oH9DAxaLJrDjbK/rSHNXXTRP3H6yDU0aSqtJu3FgVWFAu61IPJJU0t2u3fzTJ nnag== 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=qFXW+lsJJQBeSr3AQvKsaPzSqHGqKPVmCHb7neQbOr4=; fh=llgCZWXMwzO7q6UhH/Kn+ASs1GqO7mXzXsbqeCXJiM0=; b=DgsbXj9dC8tq/hVgJNwkKLA2ZjC+b2lJzUZ3D+f2WmArC1Hb3XKInewsBDy09OGlmR GGOcQIGWBAPbSihSoYxEzKChfj7j/LOYUpsj78Pji+kOJRoJ1JhHFwZTE2WJjbUw50eF RFzqeU0teKo03G4dYbQH/YL5ax0lf1pfofup+Gf37HaCBPviCcIjnTYMIe0q9rlDiNGj wSSm4Xuu9ZhjIli6ZFvg80cwtoh7HbnodY8S454cO66tvs3lxSQnJE0tuZXcpY/VQ37h tCpcqotoZHQUthi2OdwZ8E3kJYQGTTf1qJ5mZD8Sd1+hOQDCqO6a2ln68yp0PQOsOJVk AcfQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=R9BoWN15; 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-58981-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58981-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=2; AJvYcCW/CCZWY63rjkUXbNb1h8o8aFStUih86z5GxlZn8KWpgsbTJtGz7aIRbNmGk3VGS5zEHfQ31knQ9Sxog1BVnKcELTD+Jg== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id h18-20020a17090634d200b00a389612f13bsi340870ejb.995.2024.02.08.19.19.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 19:19:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58981-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=R9BoWN15; 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-58981-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58981-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 9A6D41F22671 for ; Fri, 9 Feb 2024 03:19:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 38562523B; Fri, 9 Feb 2024 03:15:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="R9BoWN15" 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 1D9961DA32; Fri, 9 Feb 2024 03:14:57 +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=1707448502; cv=none; b=IWMzUzqgihIKCZ+kytDKyTg9UExLVdx7a+BqX8KqiYmAjVU+6YHga8TiDm+h0xoMxtLV8kP5fm8oREF6eAsyo+ww//a//v7sps0/XWA7X1JqX9dIRXlc88n+sdf5O/Pz2qBp7hQc9CEY5fcG4N0nUbWfPqN1mip+AVEH7eUpHTo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707448502; c=relaxed/simple; bh=nObyFR7ak2CI9RBnkdMxnonoYCxryMBB96Dff9fIYBo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dI65umDV6RloJtiyvk97h3nO8xhGXSd1vpz/sp7KlFJri9BnY8arp5cCwBkHEZiVy0YZSdm8XcQln6ZIejv3qPqYLBQuTQ2S96jF/TtY71wAvDCxbCqt6u1q932zEBNXrcitGMvktG6yKdxJgnPcb5TLh2kWoH+fnDA2+zDYnwA= 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=R9BoWN15; 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=1707448497; x=1738984497; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=nObyFR7ak2CI9RBnkdMxnonoYCxryMBB96Dff9fIYBo=; b=R9BoWN15C1kFRuH9fFbqY8GqeTunEeBspXuHep/iCV7ksZiGA5J9gem8 R3NMF7gRGmDlHThj1k49PQRoPA08YAEPwFV6t3ZFp1ZCVuplyJ6tKsyQG 4LIVdOs4kwJdrZcpX+WHOKviu0oFex1N2+pv4+HFrk+AVnryt9IjOSvFK PcYyMuuYhbZ8gvk7sDrtljhvszGu3Qso2O6EN9TR5mzmF7OvvO7wVkZpY qWpNydTUM1vCbydkdd7UtUt7/pPyx37jtPjUucRgtkilmk5j0EkJgGHnN NTrJ4MLbV3Nz5lSL5Y2/CHiTcW99V4qKKxk5Dm3eovLp4heSqrPb6KNMj g==; X-IronPort-AV: E=McAfee;i="6600,9927,10978"; a="1257948" X-IronPort-AV: E=Sophos;i="6.05,255,1701158400"; d="scan'208";a="1257948" 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="32631457" 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 13/15] perf stat: Code refactoring in hardware-grouping Date: Thu, 8 Feb 2024 19:14:39 -0800 Message-ID: <20240209031441.943012-14-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: 1790389827837426540 X-GMAIL-MSGID: 1790389827837426540 From: Weilin Wang Decouple the step to generate final grouping strings out from the build_grouping step so that we could do single metric grouping and then merge groups if needed later. Signed-off-by: Weilin Wang --- tools/perf/util/metricgroup.c | 50 +++++++++++++++++------------------ 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index f1eb73957765..cfdbb5f7fb77 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -1896,9 +1896,10 @@ static int find_and_set_counters(struct metricgroup__event_info *e, { int ret; unsigned long find_bit = 0; - - if (e->taken_alone && current_group->taken_alone) + if (e->taken_alone && current_group->taken_alone) { + pr_debug("current group with taken alone event already\n"); return -ENOSPC; + } if (e->free_counter) return 0; if (e->fixed_counter) { @@ -2017,7 +2018,8 @@ static int assign_event_grouping(struct metricgroup__event_info *e, list_for_each_entry(g, groups, nd) { if (!strcasecmp(g->pmu_name, e->pmu_name)) { - pr_debug("found group for event %s in pmu %s\n", e->name, g->pmu_name); + pr_debug("found group header for event %s in pmu %s\n", + e->name, g->pmu_name); pmu_group_head = g; break; } @@ -2146,26 +2148,22 @@ static int hw_aware_metricgroup__build_event_string(struct list_head *group_strs */ static int create_grouping(struct list_head *pmu_info_list, struct list_head *event_info_list, - struct list_head *groupings, - const char *modifier) + struct list_head *grouping) { int ret = 0; struct metricgroup__event_info *e; - LIST_HEAD(groups); char *bit_buf = malloc(NR_COUNTERS); - //TODO: for each new core group, we should consider to add events that uses fixed counters + //TODO: for each new core group, we could consider to add events that + //uses fixed counters list_for_each_entry(e, event_info_list, nd) { bitmap_scnprintf(e->counters, NR_COUNTERS, bit_buf, NR_COUNTERS); pr_debug("Event name %s, [pmu]=%s, [counters]=%s, [taken_alone]=%d\n", e->name, e->pmu_name, bit_buf, e->taken_alone); - ret = assign_event_grouping(e, pmu_info_list, &groups); + ret = assign_event_grouping(e, pmu_info_list, grouping); if (ret) - goto out; + return ret; } - ret = hw_aware_metricgroup__build_event_string(groupings, modifier, &groups); -out: - metricgroup__free_group_list(&groups); return ret; }; @@ -2186,9 +2184,8 @@ static bool is_special_event(const char *id) * @groupings: header to the list of final event grouping. * @modifier: any modifiers added to the events. */ -static int hw_aware_build_grouping(struct expr_parse_ctx *ctx __maybe_unused, - struct list_head *groupings __maybe_unused, - const char *modifier __maybe_unused) +static int hw_aware_build_grouping(struct expr_parse_ctx *ctx, + struct list_head *grouping) { int ret = 0; struct hashmap_entry *cur; @@ -2220,8 +2217,7 @@ static int hw_aware_build_grouping(struct expr_parse_ctx *ctx __maybe_unused, ret = get_pmu_counter_layouts(&pmu_info_list, ltable); if (ret) goto err_out; - ret = create_grouping(&pmu_info_list, &event_info_list, groupings, - modifier); + ret = create_grouping(&pmu_info_list, &event_info_list, grouping); err_out: metricgroup__free_event_info(&event_info_list); @@ -2267,23 +2263,25 @@ static int hw_aware_parse_ids(struct perf_pmu *fake_pmu, { struct parse_events_error parse_error; struct evlist *parsed_evlist; - LIST_HEAD(groupings); + LIST_HEAD(grouping_str); + LIST_HEAD(grouping); struct metricgroup__group_strs *group; int ret; *out_evlist = NULL; - ret = hw_aware_build_grouping(ids, &groupings, modifier); - if (ret) { - metricgroup__free_grouping_strs(&groupings); - return ret; - } + ret = hw_aware_build_grouping(ids, &grouping); + if (ret) + goto out; + ret = hw_aware_metricgroup__build_event_string(&grouping_str, modifier, &grouping); + if (ret) + goto out; parsed_evlist = evlist__new(); if (!parsed_evlist) { ret = -ENOMEM; goto err_out; } - list_for_each_entry(group, &groupings, nd) { + list_for_each_entry(group, &grouping_str, nd) { struct strbuf *events = &group->grouping_str; pr_debug("Parsing metric events '%s'\n", events->buf); @@ -2303,7 +2301,9 @@ static int hw_aware_parse_ids(struct perf_pmu *fake_pmu, err_out: parse_events_error__exit(&parse_error); evlist__delete(parsed_evlist); - metricgroup__free_grouping_strs(&groupings); +out: + metricgroup__free_group_list(&grouping); + metricgroup__free_grouping_strs(&grouping_str); return ret; } From patchwork Fri Feb 9 03:14:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Weilin" X-Patchwork-Id: 198731 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp603608dyd; Thu, 8 Feb 2024 19:19:45 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVygn+Oqk8lyBgVki6acAQEpPiAT1g9xrGmWnMR0lt/0gjX3qpKiGEr89FVVGP//40RnXvHbmSwCKCeFea3QypnChV+sQ== X-Google-Smtp-Source: AGHT+IEBlWJo8aY8GvlAhNySVpkWtFdmiw3/rX7cT6I6zjLOR2wW/1Cyz6T/pfhacoNkKvSGQsvL X-Received: by 2002:a05:622a:1aa7:b0:42c:3999:c9a5 with SMTP id s39-20020a05622a1aa700b0042c3999c9a5mr546139qtc.9.1707448785071; Thu, 08 Feb 2024 19:19:45 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707448785; cv=pass; d=google.com; s=arc-20160816; b=mxYYbl41PTZKtZxx1Yx9X8xYh4j70ZtnIHY2Q2DGQashp/Ktc+D4c5PbpPvzMDWnmc tLvEF7SXssY8zVaUh6mkCwVLz55hPkCg/tVV/UCVQP2OqdYH37lzRYCiiQxaWJ8oKeub YeBclcQVcr77k1zaORZeCZ1vdjhC8PFwktiZenrgAnTGjlsKKbyh7UkNTh/OIFbmAOZq E2+ZXi8zd0SiYGhUKhbptm+YAiTinV/p8aTjZMXyUapkCgwGNdUPjVUEOTStW3V/zRCm USASDUp1k0DwLeOffSy6NBrdmx+zr6PqbSPWChkVtdpMJCVpz85qfLapmEIchqeZks6S hjIQ== 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=956AJVg/RqIe3wjmDD09plijMcpI5t2rk5tk7UOPo1w=; fh=za9cv/CAcIU+jS1kDPankTIR3VQcWDD2WGKLR2/7tEo=; b=0KLR30Qu0ZVC8zPTlGLWEv4WH4F3Tm7Gv9XfSa2dHAWph22WKwCr+g/xxS+Hg40Ivq rTBt0tXeszQgxsBHeBjKsYxOro5hgvsmJ1ct6tbZ2zg1HFOz5uTVI45y1kNhJwcFMMXv cXZBaK+q6yE+zSt/9t86SjSr4/wnKI8ue+0+bGPx/3CLQFgGky9pus+OdFBPJN5VZfxc lLj3xdlbOHvIDJDg2/GD2g5Uhe3vqqkR3v2s8Noxn+Te/pGpAdCzVsWonl1DBXDLh3Dz efwQQeHZ4fc8/HObVar8zxqie5Po5YRE+c8ULv3AAZF1X/d/WrpM4oTqnP1JisAsa64+ CQ6w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=JohPDLCg; 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-58979-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58979-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=2; AJvYcCWN0MGnnCJSL2YGOI/aHNmP0AjgjVNAOcIhqw/WZov7/A5aWAkkfWiJhiBQGKOuay7JMCJ6EQ98RPeUzNMW7xy+yUwKlg== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id h2-20020ac85842000000b0042c4e080110si987395qth.363.2024.02.08.19.19.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 19:19:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58979-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=JohPDLCg; 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-58979-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58979-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id C76291C2439B for ; Fri, 9 Feb 2024 03:19:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0AF6E39ACC; Fri, 9 Feb 2024 03:15:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="JohPDLCg" 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 CD97117BC8; Fri, 9 Feb 2024 03:14:58 +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=1707448500; cv=none; b=YzdRlW44EiA7EqkxrSv9D1fqoa13lhsrECxNsgpvWMRCe7Vz14vZO+a3ZUe2GRmF59W2gxW9+ySeJ+I7dwcYMfwce3kLa1elNsOOY/OMqbWm6OaxN7ZjyeUk3HTgF2bzgAd4tWGn3uXrKZ9u9Zbo4jIY4w3lZAg41PAU+Qyg6oM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707448500; c=relaxed/simple; bh=vOPR8LxQn3WFF9Ql8k9wlrgDI26EFBXQsZ+EoLn19bY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LBKoshao74JjdfzhATgzKZFmFnbZTZ+crjNgxtc7BQnfysXtx+OufoXv1sjFiH7K4UvcG5dtttxTPfxry5Zgka+sZapfJrsVeDHhjVloi8mgQhVHsk4YKvsQZAjLhRDzA2GSm5Br6RgX/10lbLfhrKqmkXHHn2h6U+HDAI/yd34= 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=JohPDLCg; 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=1707448499; x=1738984499; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=vOPR8LxQn3WFF9Ql8k9wlrgDI26EFBXQsZ+EoLn19bY=; b=JohPDLCgpzm4TsCU0oLQP7vwSbhqTbKm3ZVSGIJI1LCnhba8Ef+PsI1c OgG/J9KXdTYKPtdV5prmSettj8rjbEabGiIN1+JQj26hShThU1FTPwW/C a3QnQVeoeJd3hgre6h8nDWcFk8YM/boNAEUF+0r+w8Xyz/ef49O67XViV q47XO5grPHSJINMrZUdOUVEIHaui0irK9jGJzjK9N2IYYl0sBD5K9FHJo N4rJ7GOwPGacSex6/SLMCtso/Kakoz4aeQiMVfhteqVH1YYlIloAB84n3 560VYjipKK1omzGRb5jqZgCNwCIQ5TsEDOyc3SGOtwSdeeuBex8rUG3vY w==; X-IronPort-AV: E=McAfee;i="6600,9927,10978"; a="1257952" X-IronPort-AV: E=Sophos;i="6.05,255,1701158400"; d="scan'208";a="1257952" 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="32631461" 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 14/15] perf stat: Add tool events support in hardware-grouping Date: Thu, 8 Feb 2024 19:14:40 -0800 Message-ID: <20240209031441.943012-15-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: 1790389817300280567 X-GMAIL-MSGID: 1790389817300280567 From: Weilin Wang Add tool events into default_core grouping strings if find tool events so that metrics use tool events could be correctly calculated. Need this step to support TopdownL4-L5. Signed-off-by: Weilin Wang --- tools/perf/util/metricgroup.c | 49 ++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index cfdbb5f7fb77..e5b8456d0405 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -1486,6 +1486,35 @@ static void find_tool_events(const struct list_head *metric_list, } } +/** + * get_tool_event_str - Generate and return a string with all the used tool + * event names. + */ +static int get_tool_event_str(struct strbuf *events, + const bool tool_events[PERF_TOOL_MAX], + bool *has_tool_event) +{ + int i = 0; + int ret; + + perf_tool_event__for_each_event(i) { + if (tool_events[i]) { + const char *tmp = strdup(perf_tool_event__to_str(i)); + + if (!tmp) + return -ENOMEM; + *has_tool_event = true; + ret = strbuf_addstr(events, ","); + if (ret) + return ret; + ret = strbuf_addstr(events, tmp); + if (ret) + return ret; + } + } + return 0; +} + /** * build_combined_expr_ctx - Make an expr_parse_ctx with all !group_events * metric IDs, as the IDs are held in a set, @@ -2049,6 +2078,7 @@ static int assign_event_grouping(struct metricgroup__event_info *e, static int hw_aware_metricgroup__build_event_string(struct list_head *group_strs, const char *modifier, + const bool tool_events[PERF_TOOL_MAX], struct list_head *groups) { struct metricgroup__pmu_group_list *p; @@ -2056,8 +2086,12 @@ static int hw_aware_metricgroup__build_event_string(struct list_head *group_strs struct metricgroup__group_events *ge; bool no_group = true; int ret = 0; + struct strbuf tool_event_str = STRBUF_INIT; + bool has_tool_event = false; #define RETURN_IF_NON_ZERO(x) do { if (x) return x; } while (0) + ret = get_tool_event_str(&tool_event_str, tool_events, &has_tool_event); + RETURN_IF_NON_ZERO(ret); list_for_each_entry(p, groups, nd) { list_for_each_entry(g, &p->group_head, nd) { @@ -2129,6 +2163,12 @@ static int hw_aware_metricgroup__build_event_string(struct list_head *group_strs } ret = strbuf_addf(events, "}:W"); RETURN_IF_NON_ZERO(ret); + + if (!strcmp(p->pmu_name, "default_core") && has_tool_event) { + ret = strbuf_addstr(events, tool_event_str.buf); + RETURN_IF_NON_ZERO(ret); + } + pr_debug("events-buf: %s\n", events->buf); list_add_tail(&new_group_str->nd, group_strs); } @@ -2214,6 +2254,7 @@ static int hw_aware_build_grouping(struct expr_parse_ctx *ctx, if (ret) goto err_out; } + ret = get_pmu_counter_layouts(&pmu_info_list, ltable); if (ret) goto err_out; @@ -2259,6 +2300,7 @@ static void metricgroup__free_grouping_strs(struct list_head */ static int hw_aware_parse_ids(struct perf_pmu *fake_pmu, struct expr_parse_ctx *ids, const char *modifier, + const bool tool_events[PERF_TOOL_MAX], struct evlist **out_evlist) { struct parse_events_error parse_error; @@ -2272,7 +2314,8 @@ static int hw_aware_parse_ids(struct perf_pmu *fake_pmu, ret = hw_aware_build_grouping(ids, &grouping); if (ret) goto out; - ret = hw_aware_metricgroup__build_event_string(&grouping_str, modifier, &grouping); + ret = hw_aware_metricgroup__build_event_string(&grouping_str, modifier, + tool_events, &grouping); if (ret) goto out; @@ -2407,6 +2450,7 @@ static int hw_aware_parse_groups(struct evlist *perf_evlist, struct evlist *combined_evlist = NULL; LIST_HEAD(metric_list); struct metric *m; + bool tool_events[PERF_TOOL_MAX] = {false}; int ret; bool metric_no_group = false; bool metric_no_merge = false; @@ -2425,11 +2469,14 @@ static int hw_aware_parse_groups(struct evlist *perf_evlist, if (!metric_no_merge) { struct expr_parse_ctx *combined = NULL; + find_tool_events(&metric_list, tool_events); + ret = hw_aware_build_combined_expr_ctx(&metric_list, &combined); if (!ret && combined && hashmap__size(combined->ids)) { ret = hw_aware_parse_ids(fake_pmu, combined, /*modifier=*/NULL, + tool_events, &combined_evlist); } From patchwork Fri Feb 9 03:14:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Weilin" X-Patchwork-Id: 198738 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp608494dyd; Thu, 8 Feb 2024 19:36:17 -0800 (PST) X-Google-Smtp-Source: AGHT+IGP3pR6H9Glh0KD+CGf/LoIw2C/p+FTvT0iuX6oZC9RjsKdPt16RMM+7RBM/Gq3F8sMf6ty X-Received: by 2002:a17:902:d4c8:b0:1d9:ad4e:5600 with SMTP id o8-20020a170902d4c800b001d9ad4e5600mr378857plg.29.1707449777292; Thu, 08 Feb 2024 19:36:17 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707449777; cv=pass; d=google.com; s=arc-20160816; b=yhMJSSBdP6uElPxOvG3W361uHtL/Gn+/EPpAOBDv781eeJbnXSoQGIHgp9xUweX7Ap EIdfuVd1w8nMjIX2GN6OEoTx9/YREMGUuBAdqKwCanXdGLeL0riE8X9iGu2bp2MKhDmq WNCNeCHzZHPnfvd21STpkOx33LhES7sdx4ulJgzEqD5qN0KqFcKxn0cIb1/uf+3GbxnD t0kAVt+rGDjiaJgLWIF5/RY9XtJdrgtwFSej+z7fmLnM8KMQ/fIPre6ygRtTFrjdaXYx /gsEaV06qARbhFh9xrWhmSpu2oDutggFsstqyPpVRWrwKn0VpFdclEKOUvzgofiLayc8 wkyw== 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=O8vfh9AdzWzoQSOI9FHtdsUgg5XT6y5eCsn97EyqRNI=; fh=GEthRwBjKniwGr/6goTyeBiERObPSA4+w9Zki/+yqZI=; b=OiaW4BlSsab3gmZfy5WrqlwVsn6f2E46cwP4hLfE1WpleqY9LPD2vr3X4xDvMAnp6C s6RbqNDClk+U1KPtdsNFfCYBm7LnaaGh7uOUg+A0tfuHduXbALc/cwL/fZEBEEBjIFIb Gaon9G5j/qPIG+GFwpKp0Uw1Nq3WBYatmQQcZ2vnD3sEBL3sHYpzL9I9n0rp4SWb2HKY s3KpMjG/+K05eM3yN0crkMnkk+epO7n8trJ0Y0Sn+xQKABvfnCUCzbVlyuar4MFYQHnF oOLwgSfXrey/W5d2TTbkZ0wKNhLGgVCvY2BOqMEvCT1crqtWnka7ZECQ6BJeCAJkCorA /emA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=MvnuPpkT; 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-58980-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58980-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=2; AJvYcCV10A3hObNpeF0lLYTifhggJycZBlvFQUm4w/6MjWneImlLgxlLbctVufrUIUv7cLAaoqW36Iv9+loIkTlNax+qlqiSTQ== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id ja15-20020a170902efcf00b001d95a6b0b54si843376plb.252.2024.02.08.19.36.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 19:36:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58980-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=MvnuPpkT; 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-58980-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58980-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 3A661B24DA6 for ; Fri, 9 Feb 2024 03:19:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id ACFFD39AC2; Fri, 9 Feb 2024 03:15:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="MvnuPpkT" 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 0C53D25610; Fri, 9 Feb 2024 03:14:59 +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=1707448501; cv=none; b=nQkAPqIHakcMJTnv2TOIk0oHQ5VQ2G96HowL3fIfgm6yfZiQ1EzWeWXf3TRrNoBe3PB0a17Y21LeSDCm2J2YxqApBBl68WU9AI0d2RUAIKjHCsUBv+RHlv5mNSnvXLNEsYQN6ZwU32Yp3/XR6c5oK+wb92x/eeFylf76O+CEkdg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707448501; c=relaxed/simple; bh=UHYv/wd8Tx2Q5u/rY/pti40zJf3hKXnFNuJLdQgtOuo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eG03dlf1P2vqToihW3g+2L0micwUf83CTGGbb6cDXVo8trX8+xa83Ub26FjFw5bjf5Zki6p9QP2iLXOUVYVMD4opfLTIzR5DqkAGcPu/BEux6KlBQjwSMEKVUg9pUdInnBfrBHeF4dxhwhXXVjEuHTU0zye0Myai/LvELv9kZqY= 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=MvnuPpkT; 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=1707448499; x=1738984499; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=UHYv/wd8Tx2Q5u/rY/pti40zJf3hKXnFNuJLdQgtOuo=; b=MvnuPpkT2/KZ6zS4y8pvDvbb3cDm/0MOALVBKWSpREpLkoKfwRKwsRZV p6GXRuv6sFMhPfGdxQzDaR1xcR+yc9Jlf9F4slSBDmbe9GYbw0SpM5kAS RTilMKcykHgID+m2T2lpLs8dMWj7qyjgnoN6TWCpsVHwGrBcYt1/7Fd1W ga/L1VQH5H2rMsiBaGnzBko2+QzJtNtrVsVP4UyvaVkrRGHSblnSeXZe1 wOvbcWu68Iu1oubh9YMxzlKJr3Cur+u678p3NeGbvWv3fZeEXSzhIlyGp F4++1DbtKg6GSdAldW3yUdqNpRnaVsf5xWezLvO/MF/v1U3X/66iTVEAd Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10978"; a="1257954" X-IronPort-AV: E=Sophos;i="6.05,255,1701158400"; d="scan'208";a="1257954" 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="32631469" 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 15/15] perf stat: Add hardware-grouping cmd option to perf stat Date: Thu, 8 Feb 2024 19:14:41 -0800 Message-ID: <20240209031441.943012-16-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: 1790390857996973366 X-GMAIL-MSGID: 1790390857996973366 From: Weilin Wang Add a cmd option to allow user to choose this new metric grouping method. $ perf stat -M TopdownL1 -a --hardware-grouping Signed-off-by: Weilin Wang --- tools/perf/builtin-stat.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index d08a40c4bae1..e30f7a856122 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -1257,6 +1257,8 @@ static struct option stat_options[] = { "don't try to share events between metrics in a group"), OPT_BOOLEAN(0, "metric-no-threshold", &stat_config.metric_no_threshold, "disable adding events for the metric threshold calculation"), + OPT_BOOLEAN(0, "hardware-grouping", &stat_config.hardware_aware_grouping, + "Use hardware aware metric grouping method"), OPT_BOOLEAN(0, "topdown", &topdown_run, "measure top-down statistics"), OPT_UINTEGER(0, "td-level", &stat_config.topdown_level,