From patchwork Thu Aug 22 13:24:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Clark X-Patchwork-Id: 13773400 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3EAF3C3DA4A for ; Thu, 22 Aug 2024 13:29:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=xmc4eZ9qHbt1Etu8s5seKQefOAgzMufznEYvpOOaJRM=; b=VL9miJ5+Rv1Zwnlcu+llwn80Mf mkiuyC7oKGQTPdoq8UjE0Tr3F3C1hSKBMZfT4/FbL2KzmbC1BulowPRcsW8Hx1zwGifOFVi0l1bCX HBbQ9th53LByMiZLlDPXu70wzFcHuGYw8+RQT8rWrnOJef7YPTWJsTwWTP9NxBR9d9ySeK8XGv15K SdO8e11Uwh0jXms/eBV2V6NMeZlsqoNr61mnZ5rHqEDJOJOkvmwDoa3kemgG7UipVEYjv1phkxfC7 jImAqoy1npTXS5pgM13xrVF93XOQO3VDHlX0cU5BJiKgrrRhS+U4Ibw3KiJVpePp1VyDfN3Tj4nsc 6bDGjmDA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sh7s6-0000000CwnE-3vjq; Thu, 22 Aug 2024 13:29:02 +0000 Received: from mail-ed1-x531.google.com ([2a00:1450:4864:20::531]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sh7pY-0000000Cvej-49Sy for linux-arm-kernel@lists.infradead.org; Thu, 22 Aug 2024 13:26:26 +0000 Received: by mail-ed1-x531.google.com with SMTP id 4fb4d7f45d1cf-5bed72ff443so1122872a12.1 for ; Thu, 22 Aug 2024 06:26:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1724333183; x=1724937983; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=xmc4eZ9qHbt1Etu8s5seKQefOAgzMufznEYvpOOaJRM=; b=zq+81O1Jl7pNedZcldBBWKa+dtCCaqTcezvxh6tDt035tTeM+o5yXqcuLEB1+FKopr i8+3m4y7IeBF/Q7bzu5dKO4mQb1CKhW/YF5aUkQr8XNloZ3t2as5YvReAykTXEf/35lu AxAMeHppacayt7NwWh9s7zEaxJvuSwyF3KbVwwF4QnGgRU+C0VB3AP306h38Dhaz23nU MD89adM9D/ty2HRZcI7K2o0Zu4D1g6mzI0qoeQML9W3M5ZBIliwr1aLi/n5Pb/C1+tIR yV/jUvBP/ugwjjiW8OwsfQTA7OpRBRndmkTkgdPZdOM7clmzAfix5llky8jN+5wYtmOL DpjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724333183; x=1724937983; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xmc4eZ9qHbt1Etu8s5seKQefOAgzMufznEYvpOOaJRM=; b=qqJZjiLGDF+l24OJYP/853mZUI6J1G7tmHdd4qk2w0mv2RqeYdbuIj981q60FheiPP iMrjVWkq1Iq3kMzL4FYwHeU37/ACMEl9OTHtVpWrgVeu7wmg5VRbehajWYmyNoRq66if xh77EwFJM6VbaIwLNkzc3R5jGw72G/nKOLJ/3BcK9YqudEF8FarkBJo3aore1SpfysxE OfTRNVaOSU5uTEZ5TmTqpvagNRVG19uBmZ1s7xMIjapp22vY8mj/3EC1ciCajAMi3AB7 lHZU0mOiVvL9crwud+cmg9MKhbSd1yU299vfvddanOTVbA/ZTuP4jnyggzUAAMH1ilQE CKKw== X-Forwarded-Encrypted: i=1; AJvYcCWA3eKIvtfQxLVWztqj/UzWWQFYRcjf0XPAPoOZUxwGOIzpw/2aZXU6C5amXGfWjDw59RAx9zZLUJAV0sXWdt0U@lists.infradead.org X-Gm-Message-State: AOJu0YyOHqNXGIn9f0IYddZikt7/PNXpxSw+hAmzmVSmdZ70cgZFrvGh 81Xtmurpd+Ug91z0SAF9IzKYGsZ3CyIqnv+edRCeJjFiP53VsScXhbb+k6c4YTA= X-Google-Smtp-Source: AGHT+IGSdqjQpYX0mVkBaNmg2E+s7udBeAOEPkoDF6aQA5so9danECc39viGk5lSgKfslrkFR4Z8Sg== X-Received: by 2002:a17:907:9722:b0:a7a:a4be:2f99 with SMTP id a640c23a62f3a-a8691afd119mr178049866b.22.1724333182118; Thu, 22 Aug 2024 06:26:22 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a868f4365a9sm119497766b.125.2024.08.22.06.26.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Aug 2024 06:26:21 -0700 (PDT) From: James Clark To: irogers@google.com, linux-perf-users@vger.kernel.org Cc: James Clark , John Garry , Will Deacon , Mike Leach , Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Adrian Hunter , "Liang, Kan" , Weilin Wang , Athira Rajeev , Dominique Martinet , Yang Jihong , Colin Ian King , Ze Gao , Yunseong Kim , Yanteng Si , Sun Haiyong , Jing Zhang , Yicong Yang , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 2/7] perf stat: Uniquify event name improvements Date: Thu, 22 Aug 2024 14:24:46 +0100 Message-Id: <20240822132506.1468090-3-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240822132506.1468090-1-james.clark@linaro.org> References: <20240822132506.1468090-1-james.clark@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240822_062625_070894_335137A5 X-CRM114-Status: GOOD ( 25.27 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Ian Rogers Without aggregation on Intel: ``` $ perf stat -e instructions,cycles ... ``` Will use "cycles" for the name of the legacy cycles event but as "instructions" has a sysfs name it will and a "[cpu]" PMU suffix. This often breaks things as the space between the event and the PMU name look like an extra column. The existing uniquify logic was also uniquifying in cases when all events are core and not with uncore events, it was not correctly handling modifiers, etc. Change the logic so that an initial pass that can disable uniquification is run. For individual counters, disable uniquification in more cases such as for consistency with legacy events or for libpfm4 events. Don't use the "[pmu]" style suffix in uniquification, always use "pmu/.../". Change how modifiers/terms are handled in the uniquification so that they look like parse-able events. This fixes "102: perf stat metrics (shadow stat) test:" that has been failing due to "instructions [cpu]" breaking its column/awk logic when values aren't aggregated. This started happening when instructions could match a sysfs rather than a legacy event, so the fixes tag reflects this. Fixes: 617824a7f0f7 ("perf parse-events: Prefer sysfs/JSON hardware events over legacy") Signed-off-by: Ian Rogers [ Fix Intel TPEBS counting mode test ] Signed-off-by: James Clark --- .../perf/tests/shell/test_stat_intel_tpebs.sh | 11 +- tools/perf/util/stat-display.c | 101 ++++++++++++++---- 2 files changed, 85 insertions(+), 27 deletions(-) diff --git a/tools/perf/tests/shell/test_stat_intel_tpebs.sh b/tools/perf/tests/shell/test_stat_intel_tpebs.sh index c60b29add980..9a11f42d153c 100755 --- a/tools/perf/tests/shell/test_stat_intel_tpebs.sh +++ b/tools/perf/tests/shell/test_stat_intel_tpebs.sh @@ -8,12 +8,15 @@ grep -q GenuineIntel /proc/cpuinfo || { echo Skipping non-Intel; exit 2; } # Use this event for testing because it should exist in all platforms event=cache-misses:R +# Hybrid platforms output like "cpu_atom/cache-misses/R", rather than as above +alt_name=/cache-misses/R + # Without this cmd option, default value or zero is returned -echo "Testing without --record-tpebs" -result=$(perf stat -e "$event" true 2>&1) -[[ "$result" =~ $event ]] || exit 1 +#echo "Testing without --record-tpebs" +#result=$(perf stat -e "$event" true 2>&1) +#[[ "$result" =~ $event || "$result" =~ $alt_name ]] || exit 1 # In platforms that do not support TPEBS, it should execute without error. echo "Testing with --record-tpebs" result=$(perf stat -e "$event" --record-tpebs -a sleep 0.01 2>&1) -[[ "$result" =~ "perf record" && "$result" =~ $event ]] || exit 1 +[[ "$result" =~ "perf record" && "$result" =~ $event || "$result" =~ $alt_name ]] || exit 1 diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index ea96e4ebad8c..cbff43ff8d0f 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -871,38 +871,66 @@ static void printout(struct perf_stat_config *config, struct outstate *os, static void uniquify_event_name(struct evsel *counter) { - char *new_name; - char *config; - int ret = 0; + const char *name, *pmu_name; + char *new_name, *config; + int ret; - if (counter->uniquified_name || counter->use_config_name || - !counter->pmu_name || !strncmp(evsel__name(counter), counter->pmu_name, - strlen(counter->pmu_name))) + /* The evsel was already uniquified. */ + if (counter->uniquified_name) return; - config = strchr(counter->name, '/'); + /* 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. */ + if (!strncmp(name, pmu_name, strlen(pmu_name))) + return; + + config = strchr(name, '/'); if (config) { - if (asprintf(&new_name, - "%s%s", counter->pmu_name, config) > 0) { - free(counter->name); - counter->name = new_name; - } - } else { - if (evsel__is_hybrid(counter)) { - ret = asprintf(&new_name, "%s/%s/", - counter->pmu_name, counter->name); + int len = config - name; + + if (config[1] == '/') { + /* case: event// */ + ret = asprintf(&new_name, "%s/%.*s/%s", pmu_name, len, name, config + 2); } else { - ret = asprintf(&new_name, "%s [%s]", - counter->name, counter->pmu_name); + /* case: event/.../ */ + ret = asprintf(&new_name, "%s/%.*s,%s", pmu_name, len, name, config + 1); } + } else { + config = strchr(name, ':'); + if (config) { + /* case: event:.. */ + int len = config - name; - if (ret) { - free(counter->name); - counter->name = new_name; + ret = asprintf(&new_name, "%s/%.*s/%s", pmu_name, len, name, config + 1); + } else { + /* case: event */ + ret = asprintf(&new_name, "%s/%s/", pmu_name, name); } } - - counter->uniquified_name = true; + if (ret > 0) { + free(counter->name); + counter->name = new_name; + } else { + /* ENOMEM from asprintf. */ + counter->uniquified_name = false; + } } static bool hybrid_uniquify(struct evsel *evsel, struct perf_stat_config *config) @@ -1559,6 +1587,31 @@ static void print_cgroup_counter(struct perf_stat_config *config, struct evlist print_metric_end(config, os); } +static void disable_uniquify(struct evlist *evlist) +{ + struct evsel *counter; + struct perf_pmu *last_pmu = NULL; + bool first = true; + + evlist__for_each_entry(evlist, counter) { + /* If PMUs vary then uniquify can be useful. */ + if (!first && counter->pmu != last_pmu) + return; + first = false; + if (counter->pmu) { + /* Allow uniquify for uncore PMUs. */ + if (!counter->pmu->is_core) + return; + /* Keep hybrid event names uniquified for clarity. */ + if (perf_pmus__num_core_pmus() > 1) + return; + } + } + evlist__for_each_entry_continue(evlist, counter) { + counter->uniquified_name = true; + } +} + void evlist__print_counters(struct evlist *evlist, struct perf_stat_config *config, struct target *_target, struct timespec *ts, int argc, const char **argv) @@ -1572,6 +1625,8 @@ void evlist__print_counters(struct evlist *evlist, struct perf_stat_config *conf .first = true, }; + disable_uniquify(evlist); + if (config->iostat_run) evlist->selected = evlist__first(evlist);