Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp2345398lqz; Tue, 2 Apr 2024 14:45:39 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXjNW6dwapW837ieI1Ur7ojTM7bhbxa5jXuZZbJ9gMRU0c98F3dYm4p0j9G8LASX7B1nYqyd+0yOdh2S7o4He2bqn5hw3dqBeuSOYy4Vg== X-Google-Smtp-Source: AGHT+IHv9rU7I7s6XMyihgFNdUJRUEx9e+cqknmmmC+T6G42sT4mBp+FsM/1InNkCgVG7HtOnpqr X-Received: by 2002:a17:906:5958:b0:a47:48b0:922e with SMTP id g24-20020a170906595800b00a4748b0922emr8520355ejr.23.1712094339763; Tue, 02 Apr 2024 14:45:39 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712094339; cv=pass; d=google.com; s=arc-20160816; b=gUWb6lweX88zZfmksMJ0pfSVbWUbseXjvZjbOyBuf7qfSUDo0DROuMYlkV4OHBquv3 NGXuPpmPpfI08gorSFT+7TlVzTsmFxz9KAN37rUawANuLnM0pjJFlnfcZ4iKmjVI+hZv z/4/7GK0BmFKVkKwJ/9CyUXBpJvlPOsVcTGK+7K7NscVkBZffLSmtpcwBUKh03KH3SCA FXb28GTFINyVkY6GAYhvh9VHKxnLpK1HGECQJM91O6pOH4X+ztskB2FZMxTwaijcllrp wlzBbfF8QTYF3xEYIX2gl+JAwqTglFya1Wz+UMeIi8UyQHqzNxLmZ2aLHkFDsvgH1W56 Y0LA== 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=2FzENBa+AoVm0vOEMk1MBramLq4Pl3zysTNlRGIemoE=; fh=7D8bWqELNqJM6KF7zbibUOya8038rGAdDMFXsJMRu8c=; b=nxTuwQdK9Nb6o6w+bJRC0Y8IhullIAYgJSBt0jbuH04aatbaoVpvaEWakxK/Y4X+/K aY4/5OKoFOwylWxm2aAwBYG34Ku+q4SaVtZjFHWsleKziiUQc2UBWXqj9I09+e+9OD/w hENI3Cou/64EcLFbak7f2LgLZetADfiLQq97EYwLwfuNlLGAVyFHLvesTcK8HLrr+rcA WlYbeFeMX0HCSSaFHCl6TPZF3bEW1hgxA5RbX+gy0z5+Xz0idz/xnGO20mNDlwv7ZBC4 biZL1E8+oWF/kSZQ5c3ngcJ2dpI4SCfBMT+0KO01G5tgjyOovuotfZXpXGEHaz/6fVwy 773A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=jCSfqwJr; 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-128741-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-128741-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id kn8-20020a170906aa4800b00a4a347e0896si3129998ejb.1024.2024.04.02.14.45.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Apr 2024 14:45:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-128741-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=jCSfqwJr; 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-128741-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-128741-linux.lists.archive=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 258391F2389A for ; Tue, 2 Apr 2024 21:45:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3C0C115E7F2; Tue, 2 Apr 2024 21:45:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="jCSfqwJr" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) (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 87AF315AAA7; Tue, 2 Apr 2024 21:45:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.9 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712094331; cv=none; b=QO+0ISzpKf6Ev4G9ZMbDotZGjBKad8mGz5t0iQ7IeoacvD+ZXooe3IrpZolG8Pln8c+s75NEVbUwSRHZ/gNnP4gXcSq0wY3sdd8W2GCySMzXkhCQgGAs1CTibXtTwbLD0GG8oH5fre5kZlV5btWlg4PPhHQ/BKUvq6Gr7KVNGAI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712094331; c=relaxed/simple; bh=RrlAoHUPPXFkM0/EMu06O7izLrnBjjYpZG/IRp+10Wk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=r31/s3yI1EM/WR6YpmLLp8jcDSFA040Q71uouQKVZpi+93R/ugC4rVy11EbnZjUIHluEaZd+ztjenB15JXTQ0D9e079H3g3WFex3bW/lTQizX6/cj5cbe53eSow37piNA+yuRwfFUFJNvIoubswLLSKjLBPWV0fMXOQUS66jwnA= 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=jCSfqwJr; arc=none smtp.client-ip=192.198.163.9 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=1712094328; x=1743630328; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=RrlAoHUPPXFkM0/EMu06O7izLrnBjjYpZG/IRp+10Wk=; b=jCSfqwJrVORvHGvTaLLVPel1Zaqcq81Lmo4OhZVYrD/+C+ikC9Yi9BDD 1+aAdtpoYcHE9Hhgo7dXOl6sX8yuo+MxCR0pZ5zZVKumbEIEmuTZT/6Fy gZ6D3OpLZ0rn4zXHe+H9IIkGqOLkK2RuZsWLTUDj9PjFpnJz6f683PiDx mtdet5vxjkwrAGJkN/vducK2ec3JdlHKDYFi5OTIFFgnPSPQ2Po5dk6QG 1SD2qVvKjGddm0sD2eYgMob3vUVaszSKH4mLE0bLqa8aAi0RmHg4Ft3Ak ZNKLPL/2Nn/micjtC25HG8Ng0yNBj6FOTmW6AMc2jCW5wA9p6ZQGXVfPe Q==; X-CSE-ConnectionGUID: ZPJo83J+SOeTzEC6J1zYKQ== X-CSE-MsgGUID: xuIkvNmqRe+w/637oB5Qgw== X-IronPort-AV: E=McAfee;i="6600,9927,11032"; a="18020005" X-IronPort-AV: E=Sophos;i="6.07,176,1708416000"; d="scan'208";a="18020005" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Apr 2024 14:45:03 -0700 X-CSE-ConnectionGUID: L8rSP6S3QSOMPfkrnufpag== X-CSE-MsgGUID: 1s8PwmuuTMOUQ8TuqvD4+A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,176,1708416000"; d="scan'208";a="22849062" Received: from fl31ca102ks0602.deacluster.intel.com (HELO gnr-bkc.deacluster.intel.com) ([10.75.133.163]) by fmviesa004.fm.intel.com with ESMTP; 02 Apr 2024 14:45:02 -0700 From: weilin.wang@intel.com To: weilin.wang@intel.com, Namhyung Kim , Ian Rogers , Arnaldo Carvalho de Melo , Peter Zijlstra , Ingo Molnar , Alexander Shishkin , Jiri Olsa , Adrian Hunter , Kan Liang Cc: linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Perry Taylor , Samantha Alt , Caleb Biggers Subject: [RFC PATCH v7 1/6] perf stat: Parse and find tpebs events when parsing metrics to prepare for perf record sampling Date: Tue, 2 Apr 2024 17:44:31 -0400 Message-ID: <20240402214436.1409476-2-weilin.wang@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240402214436.1409476-1-weilin.wang@intel.com> References: <20240402214436.1409476-1-weilin.wang@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Weilin Wang Metrics that use tpebs values would use the R as retire_latency modifier in formulas. We put all these events into a list and pass the list to perf record to collect their retire latency value. Signed-off-by: Weilin Wang Reviewed-by: Ian Rogers --- tools/perf/builtin-stat.c | 40 ++++++++++++++-- tools/perf/util/metricgroup.c | 87 +++++++++++++++++++++++++++++------ tools/perf/util/metricgroup.h | 10 +++- tools/perf/util/stat.h | 2 + 4 files changed, 120 insertions(+), 19 deletions(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 6bba1a89d030..4558b9d95441 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -162,6 +162,7 @@ static struct perf_stat_config stat_config = { .ctl_fd = -1, .ctl_fd_ack = -1, .iostat_run = false, + .tpebs_events = LIST_HEAD_INIT(stat_config.tpebs_events), }; static bool cpus_map_matched(struct evsel *a, struct evsel *b) @@ -686,6 +687,12 @@ static enum counter_recovery stat_handle_error(struct evsel *counter) return COUNTER_FATAL; } +static int __run_perf_record(void) +{ + pr_debug("Prepare perf record for retire_latency\n"); + return 0; +} + static int __run_perf_stat(int argc, const char **argv, int run_idx) { int interval = stat_config.interval; @@ -703,6 +710,18 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx) int err; bool second_pass = false; + /* + * Prepare perf record for sampling event retire_latency before fork and + * prepare workload + */ + if (stat_config.tpebs_event_size > 0) { + int ret; + + ret = __run_perf_record(); + if (ret) + return ret; + } + if (forks) { if (evlist__prepare_workload(evsel_list, &target, argv, is_pipe, workload_exec_failed_signal) < 0) { perror("failed to prepare workload"); @@ -2106,7 +2125,9 @@ static int add_default_attributes(void) stat_config.metric_no_threshold, stat_config.user_requested_cpu_list, stat_config.system_wide, - &stat_config.metric_events); + &stat_config.metric_events, + &stat_config.tpebs_events, + &stat_config.tpebs_event_size); } if (smi_cost) { @@ -2139,7 +2160,9 @@ static int add_default_attributes(void) stat_config.metric_no_threshold, stat_config.user_requested_cpu_list, stat_config.system_wide, - &stat_config.metric_events); + &stat_config.metric_events, + &stat_config.tpebs_events, + &stat_config.tpebs_event_size); } if (topdown_run) { @@ -2173,7 +2196,9 @@ static int add_default_attributes(void) /*metric_no_threshold=*/true, stat_config.user_requested_cpu_list, stat_config.system_wide, - &stat_config.metric_events) < 0) + &stat_config.metric_events, + &stat_config.tpebs_events, + &stat_config.tpebs_event_size) < 0) return -1; } @@ -2214,7 +2239,9 @@ static int add_default_attributes(void) /*metric_no_threshold=*/true, stat_config.user_requested_cpu_list, stat_config.system_wide, - &stat_config.metric_events) < 0) + &stat_config.metric_events, + /*&stat_config.tpebs_events=*/NULL, + /*stat_config.tpebs_event_size=*/0) < 0) return -1; evlist__for_each_entry(metric_evlist, metric_evsel) { @@ -2736,6 +2763,7 @@ int cmd_stat(int argc, const char **argv) } } + /* * Metric parsing needs to be delayed as metrics may optimize events * knowing the target is system-wide. @@ -2748,7 +2776,9 @@ 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.metric_events); + &stat_config.metric_events, + &stat_config.tpebs_events, + &stat_config.tpebs_event_size); zfree(&metrics); if (ret) { diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index 79ef6095ab28..6a1d44d07a87 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -277,7 +277,8 @@ static bool contains_metric_id(struct evsel **metric_events, int num_events, */ static int setup_metric_events(const char *pmu, struct hashmap *ids, struct evlist *metric_evlist, - struct evsel ***out_metric_events) + struct evsel ***out_metric_events, + size_t tpebs_event_size) { struct evsel **metric_events; const char *metric_id; @@ -286,7 +287,7 @@ static int setup_metric_events(const char *pmu, struct hashmap *ids, bool all_pmus = !strcmp(pmu, "all") || perf_pmus__num_core_pmus() == 1 || !is_pmu_core(pmu); *out_metric_events = NULL; - ids_size = hashmap__size(ids); + ids_size = hashmap__size(ids) - tpebs_event_size; metric_events = calloc(ids_size + 1, sizeof(void *)); if (!metric_events) @@ -323,6 +324,7 @@ static int setup_metric_events(const char *pmu, struct hashmap *ids, } } if (matched_events < ids_size) { + pr_debug("Error: matched_events = %lu, ids_size = %lu\n", matched_events, ids_size); free(metric_events); return -EINVAL; } @@ -668,7 +670,9 @@ static int decode_all_metric_ids(struct evlist *perf_evlist, const char *modifie static int metricgroup__build_event_string(struct strbuf *events, const struct expr_parse_ctx *ctx, const char *modifier, - bool group_events) + bool group_events, + struct list_head *tpebs_events __maybe_unused, + size_t *tpebs_event_size) { struct hashmap_entry *cur; size_t bkt; @@ -681,8 +685,55 @@ static int metricgroup__build_event_string(struct strbuf *events, hashmap__for_each_entry(ctx->ids, cur, bkt) { const char *sep, *rsep, *id = cur->pkey; enum perf_tool_event ev; + /* + * Parse and search for event name with retire_latency modifier R. + * If found, put event name into the tpebs_events list. This list + * of events will be passed to perf record for sampling to get + * their reitre_latency value. + * In hybrid platform, some event names are in format with '@'. + * Search for ":R" in event name without '@'. Search for the + * last "@R" in event name with '@'. + */ + char *p = strstr(id, ":R"); + char *p1 = strrchr(id, '@'); + + if (p1 && *(p1+1) != '\0') { + if (*(p1+1) == 'R') + p = p1; + } + + if (p) { + char *name; + char *at; + struct tpebs_event *new_event = malloc(sizeof(struct tpebs_event)); + + if (!new_event) + return -ENOMEM; - pr_debug("found event %s\n", id); + new_event->tpebs_name = strdup(id); + if (!new_event->tpebs_name) + return -ENOMEM; + p = p + 1; + *p = '\0'; + name = malloc(strlen(id) + 2); + if (!name) + return -ENOMEM; + + at = strchr(id, '@'); + if (at != NULL) { + *at = '/'; + at = strchr(id, '@'); + *at = '/'; + } + strcpy(name, id); + strcat(name, "p"); + new_event->name = name; + *tpebs_event_size += 1; + pr_debug("retire_latency required, tpebs_event_size=%lu, new_event=%s\n", + *tpebs_event_size, new_event->name); + list_add_tail(&new_event->nd, tpebs_events); + continue; + } /* Always move tool events outside of the group. */ ev = perf_tool_event__from_str(id); @@ -1447,7 +1498,8 @@ static int build_combined_expr_ctx(const struct list_head *metric_list, static int parse_ids(bool metric_no_merge, struct perf_pmu *fake_pmu, struct expr_parse_ctx *ids, const char *modifier, bool group_events, const bool tool_events[PERF_TOOL_MAX], - struct evlist **out_evlist) + struct evlist **out_evlist, struct list_head *tpebs_events, + size_t *tpebs_event_size) { struct parse_events_error parse_error; struct evlist *parsed_evlist; @@ -1490,7 +1542,7 @@ static int parse_ids(bool metric_no_merge, struct perf_pmu *fake_pmu, } } ret = metricgroup__build_event_string(&events, ids, modifier, - group_events); + group_events, tpebs_events, tpebs_event_size); if (ret) return ret; @@ -1529,7 +1581,9 @@ static int parse_groups(struct evlist *perf_evlist, bool system_wide, struct perf_pmu *fake_pmu, struct rblist *metric_events_list, - const struct pmu_metrics_table *table) + const struct pmu_metrics_table *table, + struct list_head *tpebs_events, + size_t *tpebs_event_size) { struct evlist *combined_evlist = NULL; LIST_HEAD(metric_list); @@ -1561,7 +1615,8 @@ static int parse_groups(struct evlist *perf_evlist, /*modifier=*/NULL, /*group_events=*/false, tool_events, - &combined_evlist); + &combined_evlist, + tpebs_events, tpebs_event_size); } if (combined) expr__ctx_free(combined); @@ -1616,14 +1671,15 @@ static int parse_groups(struct evlist *perf_evlist, } if (!metric_evlist) { ret = parse_ids(metric_no_merge, fake_pmu, m->pctx, m->modifier, - m->group_events, tool_events, &m->evlist); + m->group_events, tool_events, &m->evlist, + tpebs_events, tpebs_event_size); if (ret) goto out; metric_evlist = m->evlist; } ret = setup_metric_events(fake_pmu ? "all" : m->pmu, m->pctx->ids, - metric_evlist, &metric_events); + metric_evlist, &metric_events, *tpebs_event_size); if (ret) { pr_err("Cannot resolve IDs for %s: %s\n", m->metric_name, m->metric_expr); @@ -1690,7 +1746,9 @@ int metricgroup__parse_groups(struct evlist *perf_evlist, bool metric_no_threshold, const char *user_requested_cpu_list, bool system_wide, - struct rblist *metric_events) + struct rblist *metric_events, + struct list_head *tpebs_events, + size_t *tpebs_event_size) { const struct pmu_metrics_table *table = pmu_metrics_table__find(); @@ -1699,7 +1757,8 @@ int metricgroup__parse_groups(struct evlist *perf_evlist, 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); + /*fake_pmu=*/NULL, metric_events, table, tpebs_events, + tpebs_event_size); } int metricgroup__parse_groups_test(struct evlist *evlist, @@ -1713,7 +1772,9 @@ int metricgroup__parse_groups_test(struct evlist *evlist, /*metric_no_threshold=*/false, /*user_requested_cpu_list=*/NULL, /*system_wide=*/false, - &perf_pmu__fake, metric_events, table); + &perf_pmu__fake, metric_events, table, + /*tpebs_events=*/NULL, + /*tpebs_event_size=*/0); } struct metricgroup__has_metric_data { diff --git a/tools/perf/util/metricgroup.h b/tools/perf/util/metricgroup.h index d5325c6ec8e1..7c24ed768ff3 100644 --- a/tools/perf/util/metricgroup.h +++ b/tools/perf/util/metricgroup.h @@ -66,6 +66,12 @@ struct metric_expr { int runtime; }; +struct tpebs_event { + struct list_head nd; + const char *name; + const char *tpebs_name; +}; + struct metric_event *metricgroup__lookup(struct rblist *metric_events, struct evsel *evsel, bool create); @@ -77,7 +83,9 @@ int metricgroup__parse_groups(struct evlist *perf_evlist, bool metric_no_threshold, const char *user_requested_cpu_list, bool system_wide, - struct rblist *metric_events); + struct rblist *metric_events, + struct list_head *tpebs_events, + size_t *tpebs_event_size); int metricgroup__parse_groups_test(struct evlist *evlist, const struct pmu_metrics_table *table, const char *str, diff --git a/tools/perf/util/stat.h b/tools/perf/util/stat.h index d6e5c8787ba2..b987960df3c5 100644 --- a/tools/perf/util/stat.h +++ b/tools/perf/util/stat.h @@ -109,6 +109,8 @@ struct perf_stat_config { struct cpu_aggr_map *cpus_aggr_map; u64 *walltime_run; struct rblist metric_events; + struct list_head tpebs_events; + size_t tpebs_event_size; int ctl_fd; int ctl_fd_ack; bool ctl_fd_close; -- 2.43.0