From nobody Sat Nov 30 10:41:42 2024 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (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 050B319995B for ; Tue, 10 Sep 2024 15:17:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725981454; cv=none; b=WK2t++fNpESoLFutR1H7F4Rhz5N4cK9ytMdMtlB1FyNIEp/6K5NwRp1vwOvjyQ1rCtOfxxi4WSzVZWfkF5JBV6SY6JXnexNUckrwhcNeIpWoC29rOcEV4PdXvFhfOABrESqPqIT22aCyVG66Aw4pGDCHb9W8BxR0LO5Z0qqu42k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725981454; c=relaxed/simple; bh=ZO0cjcf70UOuKOoHRZFkYxmjxvF57AkLik+p1Nx6jLA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=NNO2wOvcsasOalYMU1QXxg4/gTCLvwW3lYT0PU6fVkv/hjz2cDkfZlO0fHO4kvo7hgGGP2hQrRHYRlhSwWjHu1O7KhDCk00tR+K3KY2LDOac5FreKNQominB8Dqn86hCy6N5JkK96dyKgG4xGMcUDOROP1qMK7RjwC9BOKYSN9s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=NMPHWh4k; arc=none smtp.client-ip=209.85.128.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="NMPHWh4k" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-42cb806623eso8512245e9.2 for ; Tue, 10 Sep 2024 08:17:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1725981451; x=1726586251; darn=vger.kernel.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=NFDCbwWLYHtewDSmMSa5dxxCwM5A38zDayLzJ0EVNJs=; b=NMPHWh4kiXh+gb9EsHf3I9mSIZVJUTVw4QR291TzaBPRhtgTqh8IHX48e3SiUozNgI FbfQQ7cCIlyMSXRR+bSY7kBMctQ7zgMdzVT3kwwT/SgJ+Ymm6Kj65HB8vf20FlEuXZ0C 58eZTY0PJD4kUHO4zhhRqhKJnXD6sXGdf23ySzWHWwRFqXOstve/zP3Ma+rfNjQ0jQHI s5o04BsoF8dd9VRR37/72jPkKKBgdRZi0cl1sO3sMZkcz0xUt/w25hZ4QiYTDQeUz5QV l+T0PqPpfwPsP7inekR+Oq9c30lGYP7sRk2N2RO9zjiqn5VPtxeAhuk5yO8gjdfd1h1d 6eaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725981451; x=1726586251; 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=NFDCbwWLYHtewDSmMSa5dxxCwM5A38zDayLzJ0EVNJs=; b=WUMaMY4c/N0K0wD7Cwb4pdpZCP5mRgbX9KoB2IyZacwBEWYuSi3B/8AisE9+E5uGzf MKb9Dz74oxR+l3+39Lka7OIhqm7Elb6YaZP/MUyZDJZI8JIEk9AdC4jYenwt1OuxzKk8 eewy7i+2qaGeRkUijFJifuqyYYfd9CJ4u8qibIdUzarQsoBc4WNCDiM9QAvp6NBHFoSz E6HEoiqlAy47JWLnisjsEk09VUds3DGYhAR2Jj4riPM0iZ/f2QEge2hgMKXd4l2WWAdy mRYOXW3GT0qKGF2hNVBN6BqiErQKQYbzGG3VnN+7Ruxsiz0I8BCmXNGrvJApP3nqa36c YWvA== X-Forwarded-Encrypted: i=1; AJvYcCWFHgVHd3qKVpvYeqAgMYQeMXKsjVdW1lOU/qUIsEMLHrvG5+tLjWliREw9H2O2SsAAJkCEwMJnGWMbQkw=@vger.kernel.org X-Gm-Message-State: AOJu0YyVhQ2irn/jUDGwIa2cQuWWkE5fFIi6XZs0dmZsUDPKVUlMQmKM PdqFZbzCC2Y2KPMUe0NS7qNlktKi9ZlWwSoyKNfYl/7vwTcMgWbt48O/RqmtJOQ= X-Google-Smtp-Source: AGHT+IHGOqmfICWBH72NIu+jj0wdIAL5x8avGpXcKrAFVtiPuEoZPA6ZZQtEfVUU25gZymM2vqN12A== X-Received: by 2002:a05:600c:35cc:b0:42c:bfd6:9d4d with SMTP id 5b1f17b1804b1-42ccd30c326mr270615e9.2.1725981450497; Tue, 10 Sep 2024 08:17:30 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37895665517sm9440844f8f.36.2024.09.10.08.17.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2024 08:17:29 -0700 (PDT) From: James Clark To: irogers@google.com, linux-perf-users@vger.kernel.org, kan.liang@linux.intel.com, ak@linux.intel.com, namhyung@kernel.org Cc: James Clark , John Garry , Will Deacon , Mike Leach , Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Adrian Hunter , Weilin Wang , Dominique Martinet , Yang Jihong , Athira Rajeev , Colin Ian King , Howard Chu , Ze Gao , Sun Haiyong , Jing Zhang , Yicong Yang , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v7 2/7] perf stat: Uniquify event name improvements Date: Tue, 10 Sep 2024 16:16:20 +0100 Message-Id: <20240910151640.907359-3-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240910151640.907359-1-james.clark@linaro.org> References: <20240910151640.907359-1-james.clark@linaro.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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") Acked-by: Namhyung Kim 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/t= ests/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=3Dcache-misses:R =20 +# Hybrid platforms output like "cpu_atom/cache-misses/R", rather than as a= bove +alt_name=3D/cache-misses/R + # Without this cmd option, default value or zero is returned -echo "Testing without --record-tpebs" -result=3D$(perf stat -e "$event" true 2>&1) -[[ "$result" =3D~ $event ]] || exit 1 +#echo "Testing without --record-tpebs" +#result=3D$(perf stat -e "$event" true 2>&1) +#[[ "$result" =3D~ $event || "$result" =3D~ $alt_name ]] || exit 1 =20 # In platforms that do not support TPEBS, it should execute without error. echo "Testing with --record-tpebs" result=3D$(perf stat -e "$event" --record-tpebs -a sleep 0.01 2>&1) -[[ "$result" =3D~ "perf record" && "$result" =3D~ $event ]] || exit 1 +[[ "$result" =3D~ "perf record" && "$result" =3D~ $event || "$result" =3D~= $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, =20 static void uniquify_event_name(struct evsel *counter) { - char *new_name; - char *config; - int ret =3D 0; + const char *name, *pmu_name; + char *new_name, *config; + int ret; =20 - if (counter->uniquified_name || counter->use_config_name || - !counter->pmu_name || !strncmp(evsel__name(counter), counter->pmu_nam= e, - strlen(counter->pmu_name))) + /* The evsel was already uniquified. */ + if (counter->uniquified_name) return; =20 - config =3D strchr(counter->name, '/'); + /* Avoid checking to uniquify twice. */ + counter->uniquified_name =3D true; + + /* The evsel has a "name=3D" 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 !=3D 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 !=3D PERF_COUNT= _HW_MAX) + return; + + name =3D evsel__name(counter); + pmu_name =3D counter->pmu->name; + /* Already prefixed by the PMU name. */ + if (!strncmp(name, pmu_name, strlen(pmu_name))) + return; + + config =3D strchr(name, '/'); if (config) { - if (asprintf(&new_name, - "%s%s", counter->pmu_name, config) > 0) { - free(counter->name); - counter->name =3D new_name; - } - } else { - if (evsel__is_hybrid(counter)) { - ret =3D asprintf(&new_name, "%s/%s/", - counter->pmu_name, counter->name); + int len =3D config - name; + + if (config[1] =3D=3D '/') { + /* case: event// */ + ret =3D asprintf(&new_name, "%s/%.*s/%s", pmu_name, len, name, config += 2); } else { - ret =3D asprintf(&new_name, "%s [%s]", - counter->name, counter->pmu_name); + /* case: event/.../ */ + ret =3D asprintf(&new_name, "%s/%.*s,%s", pmu_name, len, name, config += 1); } + } else { + config =3D strchr(name, ':'); + if (config) { + /* case: event:.. */ + int len =3D config - name; =20 - if (ret) { - free(counter->name); - counter->name =3D new_name; + ret =3D asprintf(&new_name, "%s/%.*s/%s", pmu_name, len, name, config += 1); + } else { + /* case: event */ + ret =3D asprintf(&new_name, "%s/%s/", pmu_name, name); } } - - counter->uniquified_name =3D true; + if (ret > 0) { + free(counter->name); + counter->name =3D new_name; + } else { + /* ENOMEM from asprintf. */ + counter->uniquified_name =3D false; + } } =20 static bool hybrid_uniquify(struct evsel *evsel, struct perf_stat_config *= config) @@ -1559,6 +1587,31 @@ static void print_cgroup_counter(struct perf_stat_co= nfig *config, struct evlist print_metric_end(config, os); } =20 +static void disable_uniquify(struct evlist *evlist) +{ + struct evsel *counter; + struct perf_pmu *last_pmu =3D NULL; + bool first =3D true; + + evlist__for_each_entry(evlist, counter) { + /* If PMUs vary then uniquify can be useful. */ + if (!first && counter->pmu !=3D last_pmu) + return; + first =3D 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 =3D 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, st= ruct perf_stat_config *conf .first =3D true, }; =20 + disable_uniquify(evlist); + if (config->iostat_run) evlist->selected =3D evlist__first(evlist); =20 --=20 2.34.1