From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 961C620C47F for ; Thu, 23 Jan 2025 07:47:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737618437; cv=none; b=TT8yn0tsIbcIOLR9WJ3CxNJfOGvz2zGJyVCtgoFgGHImoNNhIh+i5Yutr5K60UonNNCN3iYKbun8BtUv5MXuIHNdwgRTYW3WRjs0eqR5ZDcsI9EqHlBLBRbIET6XwJlq0hACO19PQncAcw3zzZJuI34UNF9KVtKxeBYNUrtBimg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737618437; c=relaxed/simple; bh=fLRFvGEGqKtFQGLXLVLSNIBik5FhXuDM0tMa3Nsu98Y=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=CsbmDN10MQXDug0ErqCODWybN2vpgmkb7g6BC4Jfy39LOzgnWTBPPFuqCyAnhzFBzR4hCNQEnt6uKeVcnfLbkgkN5MPGqaG5jyb763ilxUJ02oYxzgHOUEnJUR/WP1VAPmTWM8QMCavJ82mSOQduF2PdoRKJrVXZv2ZmNHmBkbk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=uYvn44cs; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="uYvn44cs" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e54cb50c3baso1845576276.0 for ; Wed, 22 Jan 2025 23:47:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1737618434; x=1738223234; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=76ttAHRF3rIX3juKfMVrnox6BeyYpMdEkjNVR8LNQkM=; b=uYvn44csAmSxUA6CYG4GQzo4WpeWdP1vO/5EEjqmMm4DVTx9wI2PJj8jadLfT577OC 0ORhX3RBacKmWL0q8MN4C1B2R1dndlEl3JtwdhfAGzoqRZsfeIBHFHdu1vPv0+xFXeya q2z+F7MDtiWWWIB3ZSjJRoFKWYpe3URG6Vmx48POJtmelU38uOuX/XI59iHXrt6JW8QU Txc/vNybSAbnPOblAYAiY8vUjIKyNSGe3JDi2q75YBCKtX7xxaP2R+CAiYoXOzYKN1Nz fpFbY9MmZ7JvgfKkqy8De11t+FiaWqBB/F8jlLHcLdwu8x5bT2iToeLCWbGWirPeSV2J ZxfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737618434; x=1738223234; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=76ttAHRF3rIX3juKfMVrnox6BeyYpMdEkjNVR8LNQkM=; b=XPlb9ZtglYa5MI5nWhs9B8Oa2Q/ZL4qdz6NZmsDrUN2LCNNv7s4k71pcJZNJHs1kz8 Jb22fITzZv+btgYckpO2xwU5d4pnp4ixCwnqsML4nQK2Pm6/TmFj2pDU1+QjX/EWHjvc k1QVT9Ktk1b7LrHhoIgOOPxVYuHn423L2aJ2NvlwoLx7HqsnfyBhSnPJvH+9Y9+k6DCk HzRCNwvDjj38LFWsoertRyVYVLg1t/+5uRiotGLfUpfz52hcGo43IM/tQR60Wkvo+5qc 66Ome4McAdcUfoja/jPDKis6U0AAtmdM0DmndLJ3ME3GwhZh4VeHWZYM+tc8aPOKBHHb zi0g== X-Forwarded-Encrypted: i=1; AJvYcCWT7pd6KknMlMbHxIZ/NnlYot2giPnVF1B5Wz/fXlTJzsk7VyiHNgm94UylyY8+FNJ27hFr1km/5XcEWD4=@vger.kernel.org X-Gm-Message-State: AOJu0YzJYgqswmKqCSLCg8E0KflU0FzdIyXVhHsFiDus+26DbhVR26RC W0b0gj/mVVJ8NXwmatK4FIcWyjCv+8W1rRimpnS0BFhlg0lL1FxsIgtkcxCg67oGAHEjbvrbnVh 4TPBtEA== X-Google-Smtp-Source: AGHT+IE9R9Fh4lUJwDFvHC3tyBYYt2+JIwpoi2K88c9BoJjp6yVFbFpdGz4GeMyh+mZoFlBYDHvT/MZkAxDd X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:2fda:d811:ae83:77e0]) (user=irogers job=sendgmr) by 2002:a25:d8d4:0:b0:e57:f46a:98ce with SMTP id 3f1490d57ef6-e58259f769dmr7324276.6.1737618433366; Wed, 22 Jan 2025 23:47:13 -0800 (PST) Date: Wed, 22 Jan 2025 23:46:59 -0800 In-Reply-To: <20250123074659.698123-1-irogers@google.com> Message-Id: <20250123074659.698123-6-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250123074659.698123-1-irogers@google.com> X-Mailer: git-send-email 2.48.1.262.g85cc9f2d1e-goog Subject: [PATCH v2 5/5] perf stat: Changes to event name uniquification From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , Ze Gao , Weilin Wang , Jean-Philippe Romain , Junhao He , Yicong Yang , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" The existing logic would disable uniquification on an evlist or enable it per evsel, this is unfortunate as uniquification is most needed when events have the same name and so the whole evlist must be considered. Change the initial disable uniquify on an evlist processing to also set a needs_uniquify flag, for cases like the matching event names. This must be done as an initial pass as uniquification of an event name will change the behavior of the check. Keep the per counter uniquification but now only uniquify event names when the needs_uniquify flag is set. Before this change a hwmon like temp1 wouldn't be uniquified and afterwards it will (ie the PMU is added to the temp1 event's name). Signed-off-by: Ian Rogers --- tools/perf/util/evsel.h | 1 + tools/perf/util/stat-display.c | 111 +++++++++++++++++++++++---------- 2 files changed, 79 insertions(+), 33 deletions(-) diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index 5e789fa80590..d91621b6c8c2 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -119,6 +119,7 @@ struct evsel { bool errored; bool needs_auxtrace_mmap; bool default_metricgroup; /* A member of the Default metricgroup */ + bool needs_uniquify; struct hashmap *per_pkg_mask; int err; int script_output_type; diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index ba79f73e1cf5..e65c7e9f15d1 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -929,12 +929,16 @@ static void printout(struct perf_stat_config *config, struct outstate *os, } } -static void uniquify_event_name(struct evsel *counter) +static void evsel__uniquify_counter(struct evsel *counter) { const char *name, *pmu_name; char *new_name, *config; int ret; + /* No uniquification necessary. */ + if (!counter->needs_uniquify) + return; + /* The evsel was already uniquified. */ if (counter->uniquified_name) return; @@ -942,19 +946,6 @@ static void uniquify_event_name(struct evsel *counter) /* Avoid checking to uniquify twice. */ counter->uniquified_name = true; - /* The evsel has a "name=" config term or is from libpfm. */ - if (counter->use_config_name || counter->is_libpfm_event) - return; - - /* Legacy no PMU event, don't uniquify. */ - if (!counter->pmu || - (counter->pmu->type < PERF_TYPE_MAX && counter->pmu->type != PERF_TYPE_RAW)) - return; - - /* A sysfs or json event replacing a legacy event, don't uniquify. */ - if (counter->pmu->is_core && counter->alternate_hw_config != PERF_COUNT_HW_MAX) - return; - name = evsel__name(counter); pmu_name = counter->pmu->name; /* Already prefixed by the PMU name. */ @@ -993,17 +984,6 @@ static void uniquify_event_name(struct evsel *counter) } } -static bool hybrid_uniquify(struct evsel *evsel, struct perf_stat_config *config) -{ - return evsel__is_hybrid(evsel) && !config->hybrid_merge; -} - -static void uniquify_counter(struct perf_stat_config *config, struct evsel *counter) -{ - if (config->aggr_mode == AGGR_NONE || hybrid_uniquify(counter, config)) - uniquify_event_name(counter); -} - /** * should_skip_zero_count() - Check if the event should print 0 values. * @config: The perf stat configuration (including aggregation mode). @@ -1089,7 +1069,7 @@ static void print_counter_aggrdata(struct perf_stat_config *config, if (counter->merged_stat) return; - uniquify_counter(config, counter); + evsel__uniquify_counter(counter); val = aggr->counts.val; ena = aggr->counts.ena; @@ -1670,7 +1650,8 @@ static void print_cgroup_counter(struct perf_stat_config *config, struct evlist print_metric_end(config, os); } -static void disable_uniquify(struct evlist *evlist) +/* Should uniquify be disabled for the evlist? */ +static bool evlist__disable_uniquify(const struct evlist *evlist) { struct evsel *counter; struct perf_pmu *last_pmu = NULL; @@ -1679,20 +1660,84 @@ static void disable_uniquify(struct evlist *evlist) evlist__for_each_entry(evlist, counter) { /* If PMUs vary then uniquify can be useful. */ if (!first && counter->pmu != last_pmu) - return; + return false; first = false; if (counter->pmu) { /* Allow uniquify for uncore PMUs. */ if (!counter->pmu->is_core) - return; + return false; /* Keep hybrid event names uniquified for clarity. */ if (perf_pmus__num_core_pmus() > 1) - return; + return false; + } + } + return true; +} + +static void evsel__set_needs_uniquify(struct evsel *counter, const struct perf_stat_config *config) +{ + struct evsel *evsel; + + if (counter->merged_stat) { + /* Counter won't be shown. */ + return; + } + + if (counter->use_config_name || counter->is_libpfm_event) { + /* Original name will be used. */ + return; + } + + if (counter->core.attr.type < PERF_TYPE_MAX && counter->core.attr.type != PERF_TYPE_RAW) { + /* Legacy event, don't uniquify. */ + return; + } + + if (counter->pmu && counter->pmu->is_core && + counter->alternate_hw_config != PERF_COUNT_HW_MAX) { + /* A sysfs or json event replacing a legacy event, don't uniquify. */ + return; + } + + if (config->aggr_mode == AGGR_NONE) { + /* Always unique with no aggregation. */ + counter->needs_uniquify = true; + return; + } + + if (!config->hybrid_merge && evsel__is_hybrid(counter)) { + /* Unique hybrid counters necessary. */ + counter->needs_uniquify = true; + return; + } + + /* + * Do other non-merged events in the evlist have the same name? If so + * uniquify is necessary. + */ + evlist__for_each_entry(counter->evlist, evsel) { + if (evsel == counter || evsel->merged_stat) + continue; + + if (evsel__name_is(counter, evsel__name(evsel))) { + counter->needs_uniquify = true; + return; } } - evlist__for_each_entry_continue(evlist, counter) { - counter->uniquified_name = true; +} + +static void evlist__set_needs_uniquify(struct evlist *evlist, const struct perf_stat_config *config) +{ + struct evsel *counter; + + if (evlist__disable_uniquify(evlist)) { + evlist__for_each_entry(evlist, counter) + counter->uniquified_name = true; + return; } + + evlist__for_each_entry(evlist, counter) + evsel__set_needs_uniquify(counter, config); } void evlist__print_counters(struct evlist *evlist, struct perf_stat_config *config, @@ -1706,7 +1751,7 @@ void evlist__print_counters(struct evlist *evlist, struct perf_stat_config *conf .first = true, }; - disable_uniquify(evlist); + evlist__set_needs_uniquify(evlist, config); if (config->iostat_run) evlist->selected = evlist__first(evlist); -- 2.48.1.262.g85cc9f2d1e-goog