From nobody Sat Nov 30 02:52:27 2024 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (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 3EDC61BFE01 for ; Thu, 12 Sep 2024 19:03:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726167834; cv=none; b=aswdk4hk30D+0OrxUH4SIVmOAFErZKGW6jNgc6ErRk3jlA86Mr24LbnyKVlZVLryea61cDdLjJpmrl9zn8ZnmTQZfRS13+9ROBuQJJXIr99aIkE3Nk9VERQmDBGwBa0Ksg7xKZpCnoTXeaKkFKoU72zWA4SE2QehOPJPlYj8tzE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726167834; c=relaxed/simple; bh=T4reglaGk2agCmsig/vvfDo/NC8b4AeSgIq7WlrArvk=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=Ez7ThS+Rik5ZhDqMPIfWh04fZe5DnlhyYicb+8X0J4puozp8Q6UgmQyOjXqSSfezgmy+Q+WVztyMWuRprGzrxgAZQwXuKRqxfSUpgtcyIr9H0mc3k1cCzyCb6t1cDKdXCpMjSky/wclrq/6Eth9QhCUrX8K7Y6Eg2ZUeyf08MH4= 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=xLDjdP1w; arc=none smtp.client-ip=209.85.219.202 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="xLDjdP1w" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e1dab3a941fso363175276.3 for ; Thu, 12 Sep 2024 12:03:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1726167832; x=1726772632; 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=hQMBpXmFrHu0lZBKkOWtMtzvpev+htAWAEEd8xjV15g=; b=xLDjdP1we35/IW6y1CWo00x7bSphROdFTc3OoIzsa7c/jm9umH7qQM3HO4QJ+ATgGL grEQNnL3JoXO3k13bHZ88pL/Z7QLupghN8OIDlNNDxpD9AUXe5il+5r7bSe1i1ncEBJd /YUfE7XWm0dxEdrfL385keCNsws4o3OPK6lxC6hXoMMAwqf149iy6bA9AtoKTmoC+0wY 5U2nLccrrVjLHm1SszfeSlZBwiNDW8hY7j8LyP45/kVRnxBPtanTHTH3FG4NXyyY146/ sReOKnriK06kWf6B2zOwj16K6scmZjjgVyGPnoREZ9s4axIQCABuYG9iEeXtl46LVqkd Sz/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726167832; x=1726772632; 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=hQMBpXmFrHu0lZBKkOWtMtzvpev+htAWAEEd8xjV15g=; b=Q/KBma9TM+3zsYxIKoTgez07KYStVWc/jK3KThzM9bkFIL+ix0Sg0KdhOg1a0Fl262 E870BQ1d6Bs6sktL5TLIcc6nbOeFvwmw6At1YZ3avvckxt+SV6S4shyFGd6mcwHQxW9E gTMV8qN/rlMKu0F2OHfXaXcXxqAYK1jhhpeJ6+xFajPcU7ThJK/KQxOXv+en3L6wdhV2 PvJ5GTBNeea9tuQ6Bb5ZK9kWMFhMrEw0Zh1PBnXl66qu4FclzrAMKuS6YVrnJZuieKFM +3lFW6+wnEqj+rqscOihxNrtTnDn/YVpzv6AZxsFtCGH5gc7ZdNJu12ALDtUy6udEH5k BxDA== X-Forwarded-Encrypted: i=1; AJvYcCUu/IC+lzSSo0JASGuzE1/sdq+mwfDPpeCWZlKlNPWulsnf52G4+lYMv99tRtE6UfTgbs/oCfvzcKYPQFc=@vger.kernel.org X-Gm-Message-State: AOJu0YzB5UphORSE/ZRB00wPBS/RHHboqJiRnso1QTb9NLPEu8Wry7E4 FmJbWAuwJwhE6uwTNTv6DX25bI602S6hSG7kSl3hg5/9FK/VoGt3Yic5psxMIE6pbNTD+5rH9r2 gZS72DA== X-Google-Smtp-Source: AGHT+IGZL/HvVahdSTWcK3oVoLbA+pDzQ5l89m9u+mrgImC94FUUrwM2wgkmYZVeutyA7IjYNfBdE82i96qy X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:cf0e:7a99:e672:3862]) (user=irogers job=sendgmr) by 2002:a25:dc4e:0:b0:e0b:a2a7:df77 with SMTP id 3f1490d57ef6-e1daff5b91emr387276.2.1726167832049; Thu, 12 Sep 2024 12:03:52 -0700 (PDT) Date: Thu, 12 Sep 2024 12:03:28 -0700 In-Reply-To: <20240912190341.919229-1-irogers@google.com> Message-Id: <20240912190341.919229-2-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240912190341.919229-1-irogers@google.com> X-Mailer: git-send-email 2.46.0.662.g92d0881bb0-goog Subject: [PATCH v2 01/13] perf pmu: Simplify an asprintf error message 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 , John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Ravi Bangoria , Weilin Wang , Jing Zhang , Xu Yang , Sandipan Das , Benjamin Gray , Athira Jajeev , Howard Chu , Dominique Martinet , Yang Jihong , Colin Ian King , Veronika Molnarova , "Dr. David Alan Gilbert" , Oliver Upton , Changbin Du , Ze Gao , Andi Kleen , "=?UTF-8?q?Cl=C3=A9ment=20Le=20Goffic?=" , Sun Haiyong , Junhao He , Tiezhu Yang , Yicong Yang , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-arm-kernel@lists.infradead.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use ifs rather than ?: to avoid a large compound statement. Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- tools/perf/util/pmu.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 61bdda01a05a..779db2ac06f0 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -1466,13 +1466,12 @@ static int pmu_config_term(const struct perf_pmu *p= mu, if (err) { char *err_str; =20 - parse_events_error__handle(err, term->err_val, - asprintf(&err_str, - "value too big for format (%s), maximum is %llu", - format->name, (unsigned long long)max_val) < 0 - ? strdup("value too big for format") - : err_str, - NULL); + if (asprintf(&err_str, + "value too big for format (%s), maximum is %llu", + format->name, (unsigned long long)max_val) < 0) { + err_str =3D strdup("value too big for format"); + } + parse_events_error__handle(err, term->err_val, err_str, /*help=3D*/NULL= ); return -EINVAL; } /* --=20 2.46.0.662.g92d0881bb0-goog From nobody Sat Nov 30 02:52:27 2024 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (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 5D9AC1C0DF9 for ; Thu, 12 Sep 2024 19:03:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726167837; cv=none; b=FJOuRh+NajFExFc5EQg9oK+C00s6MdMB7l81DtCG8bmy3pxuo5VN/e3N9y/3bBSyASUAVCaM2L4v0DMdutr6xyzDa21RZfBT0s6VEW+nlIUhauVqqjCLSVGoACiW6nO0e7AQD9QBrAmn+G1EHJMmcEiIIp7kLw4cTIyiKgZFB4k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726167837; c=relaxed/simple; bh=jAbcNv9yqSgarE211GJB5sWazFM4Lu5dS8WW6PuxC5A=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=urXdaHDJ7nTi/DV20CWLSDT6h4GkSSWELhWNsqFzmIGNxRbcYlxNl9mR0S9urO+z07p+tXZut0rsTmFZp6GwX9pVIGp6FsC1S7iIExTMosk4PiZ/a6xRZV4u0k3n6OwwMSzT6e9JX12Got32PKmNusJinUa9L0HCszcepznMsTQ= 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=Qjwc1m7H; arc=none smtp.client-ip=209.85.128.202 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="Qjwc1m7H" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6d5fccc3548so18871787b3.1 for ; Thu, 12 Sep 2024 12:03:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1726167834; x=1726772634; 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=ErJVEWbGWFbXBxm9ftNG9Im8DYNIr0eJ7a1WeskavbY=; b=Qjwc1m7HI2+K3sdHGH+pqPI1gN0AIqqdkzMelth5XcKqJwlFVzww9Fff/n1yt10PiR C5xmEksRBTn9DtwDnvM5KxaJY7MjaxvDunJLXu8YArm+gkFN/HU1sp9RgSxLhkTHbVWn d9wTOHVSs/tpF8WkeQz6NOepd0J5sMX4xtaOYrt4KaOkSEb7yvZXwid+v0vZIOsOpc6l d+pLYppym8mClZtgOJE0MVjZRUywjzPa44GUrimMBvzjIpPvWSoqbk/V4YsoSdMvqSST BmFFaqsAduSEhCfPu+C1D9FC7RggfmkEI/jtZ+DrVPuIMXYX6jCLnwVzfhmpnbKxn4+0 IVRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726167834; x=1726772634; 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=ErJVEWbGWFbXBxm9ftNG9Im8DYNIr0eJ7a1WeskavbY=; b=ouKy4Shhs0wsAGsm/1erpg5C1NndTpjBmoSRBwdv1tqyCx4Mq8yWufUc9C3VrMXWGY Bw4u3q1XzrF0RTdquCY+4wJ8poZZvC785erQVPhSNrH7xEB1lW7jHm07KxC7pEgaJjwh aMGuEaC1beEmeKZitIi9cpH7KHLSjpBYkS2ygYSSFtbfPmff+OkWGyG2bkiheMFnM+Ek k6l/bIZvvdawJqAMb7x5E0oa8boAsTDAfSw1RP7vou4tK6y/tX+887JYZiYNgCyPUB+0 ZXehR7yhC21G4o7JbS102joYlDf3hCAQs8VMrCauTpslYnikXo8a+4SsOryiA5huLHIR mYAg== X-Forwarded-Encrypted: i=1; AJvYcCWI3Bs7oayvjo/53PPYNy2L77Bjnl5mnYZTO2fnYGwMVEs0XMHkyksYUSVkW0Sqne0QIKmu5eDDe64mBqE=@vger.kernel.org X-Gm-Message-State: AOJu0Yz/SqJ9DPCBv9Wjy17fLj+7foTYRSpUkS8G7P+FdxOepxbGoKbF RqxeT55xg4HWdxcaAT0g11MTI9pmTAlLIeNJsEEvNQe1jnHVKOfzG2QnvwTU0bZtgVtXcSbbh/S 8kW4SCg== X-Google-Smtp-Source: AGHT+IEoVzs1oyyOhvrA5B/BlAJH69uJxOhlzgaDYyg724PtCyJm2X/3yyqctLyUb+O6fIKERxSQj2M4j+R0 X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:cf0e:7a99:e672:3862]) (user=irogers job=sendgmr) by 2002:a81:9f02:0:b0:6be:523:af53 with SMTP id 00721157ae682-6db95425354mr2564147b3.3.1726167834242; Thu, 12 Sep 2024 12:03:54 -0700 (PDT) Date: Thu, 12 Sep 2024 12:03:29 -0700 In-Reply-To: <20240912190341.919229-1-irogers@google.com> Message-Id: <20240912190341.919229-3-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240912190341.919229-1-irogers@google.com> X-Mailer: git-send-email 2.46.0.662.g92d0881bb0-goog Subject: [PATCH v2 02/13] perf pmu: Allow hardcoded terms to be applied to attributes 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 , John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Ravi Bangoria , Weilin Wang , Jing Zhang , Xu Yang , Sandipan Das , Benjamin Gray , Athira Jajeev , Howard Chu , Dominique Martinet , Yang Jihong , Colin Ian King , Veronika Molnarova , "Dr. David Alan Gilbert" , Oliver Upton , Changbin Du , Ze Gao , Andi Kleen , "=?UTF-8?q?Cl=C3=A9ment=20Le=20Goffic?=" , Sun Haiyong , Junhao He , Tiezhu Yang , Yicong Yang , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-arm-kernel@lists.infradead.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Hard coded terms like "config=3D10" are skipped by perf_pmu__config assuming they were already applied to a perf_event_attr by parse event's config_attr function. When doing a reverse number to name lookup in perf_pmu__name_from_config, as the hardcoded terms aren't applied the config value is incorrect leading to misses or false matches. Fix this by adding a parameter to have perf_pmu__config apply hardcoded terms too (not just in parse event's config_term_common). Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- tools/perf/arch/x86/util/intel-pt.c | 3 +- tools/perf/tests/pmu.c | 3 +- tools/perf/util/parse-events.c | 4 ++- tools/perf/util/pmu.c | 56 ++++++++++++++++++++++++----- tools/perf/util/pmu.h | 4 ++- 5 files changed, 58 insertions(+), 12 deletions(-) diff --git a/tools/perf/arch/x86/util/intel-pt.c b/tools/perf/arch/x86/util= /intel-pt.c index ea510a7486b1..8f235d8b67b6 100644 --- a/tools/perf/arch/x86/util/intel-pt.c +++ b/tools/perf/arch/x86/util/intel-pt.c @@ -75,7 +75,8 @@ static int intel_pt_parse_terms_with_default(const struct= perf_pmu *pmu, goto out_free; =20 attr.config =3D *config; - err =3D perf_pmu__config_terms(pmu, &attr, &terms, /*zero=3D*/true, /*err= =3D*/NULL); + err =3D perf_pmu__config_terms(pmu, &attr, &terms, /*zero=3D*/true, /*app= ly_hardcoded=3D*/false, + /*err=3D*/NULL); if (err) goto out_free; =20 diff --git a/tools/perf/tests/pmu.c b/tools/perf/tests/pmu.c index be18506f6a24..6a681e3fb552 100644 --- a/tools/perf/tests/pmu.c +++ b/tools/perf/tests/pmu.c @@ -176,7 +176,8 @@ static int test__pmu_format(struct test_suite *test __m= aybe_unused, int subtest } =20 memset(&attr, 0, sizeof(attr)); - ret =3D perf_pmu__config_terms(pmu, &attr, &terms, /*zero=3D*/false, /*er= r=3D*/NULL); + ret =3D perf_pmu__config_terms(pmu, &attr, &terms, /*zero=3D*/false, + /*apply_hardcoded=3D*/false, /*err=3D*/NULL); if (ret) { pr_err("perf_pmu__config_terms failed"); goto err_out; diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 9a8be1e46d67..26bbc6f603ab 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -1537,7 +1537,9 @@ static int parse_events_add_pmu(struct parse_events_s= tate *parse_state, return -ENOMEM; } =20 - if (perf_pmu__config(pmu, &attr, &parsed_terms, parse_state->error)) { + /* Skip configuring hard coded terms that were applied by config_attr. */ + if (perf_pmu__config(pmu, &attr, &parsed_terms, /*apply_hardcoded=3D*/fal= se, + parse_state->error)) { free_config_terms(&config_terms); parse_events_terms__exit(&parsed_terms); return -EINVAL; diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 779db2ac06f0..c020fc34b635 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -1366,7 +1366,8 @@ static int pmu_config_term(const struct perf_pmu *pmu, struct perf_event_attr *attr, struct parse_events_term *term, struct parse_events_terms *head_terms, - bool zero, struct parse_events_error *err) + bool zero, bool apply_hardcoded, + struct parse_events_error *err) { struct perf_pmu_format *format; __u64 *vp; @@ -1380,11 +1381,46 @@ static int pmu_config_term(const struct perf_pmu *p= mu, return 0; =20 /* - * Hardcoded terms should be already in, so nothing - * to be done for them. + * Hardcoded terms are generally handled in event parsing, which + * traditionally have had to handle not having a PMU. An alias may + * have hard coded config values, optionally apply them below. */ - if (parse_events__is_hardcoded_term(term)) + if (parse_events__is_hardcoded_term(term)) { + /* Config terms set all bits in the config. */ + DECLARE_BITMAP(bits, PERF_PMU_FORMAT_BITS); + + if (!apply_hardcoded) + return 0; + + bitmap_fill(bits, PERF_PMU_FORMAT_BITS); + + switch (term->type_term) { + case PARSE_EVENTS__TERM_TYPE_CONFIG: + assert(term->type_val =3D=3D PARSE_EVENTS__TERM_TYPE_NUM); + pmu_format_value(bits, term->val.num, &attr->config, zero); + break; + case PARSE_EVENTS__TERM_TYPE_CONFIG1: + assert(term->type_val =3D=3D PARSE_EVENTS__TERM_TYPE_NUM); + pmu_format_value(bits, term->val.num, &attr->config1, zero); + break; + case PARSE_EVENTS__TERM_TYPE_CONFIG2: + assert(term->type_val =3D=3D PARSE_EVENTS__TERM_TYPE_NUM); + pmu_format_value(bits, term->val.num, &attr->config2, zero); + break; + case PARSE_EVENTS__TERM_TYPE_CONFIG3: + assert(term->type_val =3D=3D PARSE_EVENTS__TERM_TYPE_NUM); + pmu_format_value(bits, term->val.num, &attr->config3, zero); + break; + case PARSE_EVENTS__TERM_TYPE_USER: /* Not hardcoded. */ + return -EINVAL; + case PARSE_EVENTS__TERM_TYPE_NAME ... PARSE_EVENTS__TERM_TYPE_HARDWARE: + /* Skip non-config terms. */ + break; + default: + break; + } return 0; + } =20 format =3D pmu_find_format(&pmu->format, term->config); if (!format) { @@ -1487,12 +1523,13 @@ static int pmu_config_term(const struct perf_pmu *p= mu, int perf_pmu__config_terms(const struct perf_pmu *pmu, struct perf_event_attr *attr, struct parse_events_terms *terms, - bool zero, struct parse_events_error *err) + bool zero, bool apply_hardcoded, + struct parse_events_error *err) { struct parse_events_term *term; =20 list_for_each_entry(term, &terms->terms, list) { - if (pmu_config_term(pmu, attr, term, terms, zero, err)) + if (pmu_config_term(pmu, attr, term, terms, zero, apply_hardcoded, err)) return -EINVAL; } =20 @@ -1506,6 +1543,7 @@ int perf_pmu__config_terms(const struct perf_pmu *pmu, */ int perf_pmu__config(struct perf_pmu *pmu, struct perf_event_attr *attr, struct parse_events_terms *head_terms, + bool apply_hardcoded, struct parse_events_error *err) { bool zero =3D !!pmu->perf_event_attr_init_default; @@ -1514,7 +1552,7 @@ int perf_pmu__config(struct perf_pmu *pmu, struct per= f_event_attr *attr, if (perf_pmu__is_fake(pmu)) return 0; =20 - return perf_pmu__config_terms(pmu, attr, head_terms, zero, err); + return perf_pmu__config_terms(pmu, attr, head_terms, zero, apply_hardcode= d, err); } =20 static struct perf_pmu_alias *pmu_find_alias(struct perf_pmu *pmu, @@ -2279,7 +2317,9 @@ const char *perf_pmu__name_from_config(struct perf_pm= u *pmu, u64 config) pmu_add_cpu_aliases(pmu); list_for_each_entry(event, &pmu->aliases, list) { struct perf_event_attr attr =3D {.config =3D 0,}; - int ret =3D perf_pmu__config(pmu, &attr, &event->terms, NULL); + + int ret =3D perf_pmu__config(pmu, &attr, &event->terms, /*apply_hardcode= d=3D*/true, + /*err=3D*/NULL); =20 if (ret =3D=3D 0 && config =3D=3D attr.config) return event->name; diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h index 4397c48ad569..af7532ca7fb1 100644 --- a/tools/perf/util/pmu.h +++ b/tools/perf/util/pmu.h @@ -206,11 +206,13 @@ typedef int (*pmu_format_callback)(void *state, const= char *name, int config, void pmu_add_sys_aliases(struct perf_pmu *pmu); int perf_pmu__config(struct perf_pmu *pmu, struct perf_event_attr *attr, struct parse_events_terms *head_terms, + bool apply_hardcoded, struct parse_events_error *error); int perf_pmu__config_terms(const struct perf_pmu *pmu, struct perf_event_attr *attr, struct parse_events_terms *terms, - bool zero, struct parse_events_error *error); + bool zero, bool apply_hardcoded, + struct parse_events_error *error); __u64 perf_pmu__format_bits(struct perf_pmu *pmu, const char *name); int perf_pmu__format_type(struct perf_pmu *pmu, const char *name); int perf_pmu__check_alias(struct perf_pmu *pmu, struct parse_events_terms = *head_terms, --=20 2.46.0.662.g92d0881bb0-goog From nobody Sat Nov 30 02:52:27 2024 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.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 900791C1748 for ; Thu, 12 Sep 2024 19:03:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726167839; cv=none; b=SYi/ILRu9saHjmlgvZgQrW0Ok10vK9d8yaNdvXT5YvEslfSnpIlkhQ7fwiNxlqaordX4fzNGSfMbyiK3XNezBXlnlDtgYsajYdxTSQD3TIg4MM9X+g9nJCXGHZckY6H8FB27fQHLzpIEntjZoHqKCGx0S37J8qV57LWCsl3OFiQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726167839; c=relaxed/simple; bh=Vk535oLjOoVnV6GXf6fF06oFHm6U/y8aVOQzLJgw0ks=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=eEpXY2A6MONhdxGaEnoZiv0iaWzCU0PI3AmEQ6wZjAJUVTrF1d/HiJJdOshQCXccDJIKfJOrCB/MtP4fT/XByoAieGczCd5dNgJteqk+5nube1+x6+R4vchwYGlmk3DDivfh2TvdR5Ir63CVN4AgpBVkGvwRhrboSf+H5UHqrvY= 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=3ZRW/bG/; arc=none smtp.client-ip=209.85.128.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="3ZRW/bG/" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6d3aa5a6715so3278617b3.2 for ; Thu, 12 Sep 2024 12:03:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1726167836; x=1726772636; 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=Nv46Pxr4RqOiUfocd6lnckQ6oaO49PAAJVzHx2iL/LI=; b=3ZRW/bG/1Kw8xpkWQvAb16sItUCWyMDKtgP49iwFKFUsKbz+1B9+v7BMkv1IFenJpW g6Yn9kAV+NEMzhNDIS4xe4mtzcCNosjvwiOwRuLlulNiPv4MrM6kZI4Ar3RFexGC6T/J PoQDyFN36QKXsiHLtY0fNgnNJod6X21R6v4a89BgB73b4Njuxrh5ZYA+zknt8ULxAw1w fxJICM72+Xu7LC8S3gEypNkulfNf4C74WVZBIe2nSiQZ4rgeeiIb0sEYC6Hfx46/3Rll 9O72V5uX6BaDms5KFH44TZ9x43xBDEGyT/8WsFkyaRN/dSVnbOj3rB9Z9+7LVSATmzF8 QczA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726167836; x=1726772636; 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=Nv46Pxr4RqOiUfocd6lnckQ6oaO49PAAJVzHx2iL/LI=; b=aLIH1bJF8gDLl6Hrwhh1Hf3acFpV1bMWNt7KNKerHrR+ODRCXH3byPXQ2xYi9ZkQGo 4s+3NrKQYhP6IPLACY15dLg67swBlkMin9KkWH/efdRF1gRVPhGPUmmqhTAO8KJ/v4dt 8+x4ISzf3hAh0IDW/8MAdT2FGZ9XYfqmUg1ZMSgKJNmgzSwqQxnnP8SQlNBJPquAn5sL oEiQ5EHkCRDl9kAFL1htWj7hJzSPYKZsPZ9yv1QULXYBl3Tgk7ZK/LFrEB+y8hcyL3pU Nlchxvm+Euu0COR5crHO6Pufn6t8PDBP0UOA2o3c+TcLQEokhVdI5ArsYjxP7baVxkVH Qs9w== X-Forwarded-Encrypted: i=1; AJvYcCWIE1YpbWgjE9Fyi06oRlyooVLRoruM5clDJXOy4P2MVsuMGP+wiX0P8Vnp7CXcatBsT60ggKzqzFFVvnw=@vger.kernel.org X-Gm-Message-State: AOJu0YzCFc+8cyjV5hdZaAgIiyx9DNs3iJszPtcDK+95XHAy31ab9kVQ 6Zfi3xWTpsYsR6wPM+AsGOzkOE1h4z9CEJPGh9uEQ08cck7C9iNM0bzKNdupbEmEx9nj3OySMHW ZeEjQRQ== X-Google-Smtp-Source: AGHT+IFHO09bW2w4OpHfnI1mvLyMuz+jqvEx61veclezxCDRJ5X1P4hSJYcP6uZSfsVCOzJE/dx5n6NbJdWI X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:cf0e:7a99:e672:3862]) (user=irogers job=sendgmr) by 2002:a0d:c641:0:b0:6c1:298e:5a7 with SMTP id 00721157ae682-6dbcc584e0emr97147b3.5.1726167836594; Thu, 12 Sep 2024 12:03:56 -0700 (PDT) Date: Thu, 12 Sep 2024 12:03:30 -0700 In-Reply-To: <20240912190341.919229-1-irogers@google.com> Message-Id: <20240912190341.919229-4-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240912190341.919229-1-irogers@google.com> X-Mailer: git-send-email 2.46.0.662.g92d0881bb0-goog Subject: [PATCH v2 03/13] perf parse-events: Expose/rename config_term_name 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 , John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Ravi Bangoria , Weilin Wang , Jing Zhang , Xu Yang , Sandipan Das , Benjamin Gray , Athira Jajeev , Howard Chu , Dominique Martinet , Yang Jihong , Colin Ian King , Veronika Molnarova , "Dr. David Alan Gilbert" , Oliver Upton , Changbin Du , Ze Gao , Andi Kleen , "=?UTF-8?q?Cl=C3=A9ment=20Le=20Goffic?=" , Sun Haiyong , Junhao He , Tiezhu Yang , Yicong Yang , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-arm-kernel@lists.infradead.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Expose config_term_name as parse_events__term_type_str so that PMUs not in pmu.c may access it. Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- tools/perf/util/parse-events.c | 20 +++++++++++--------- tools/perf/util/parse-events.h | 2 ++ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 26bbc6f603ab..776812460dad 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -794,7 +794,7 @@ static int check_type_val(struct parse_events_term *ter= m, =20 static bool config_term_shrinked; =20 -static const char *config_term_name(enum parse_events__term_type term_type) +const char *parse_events__term_type_str(enum parse_events__term_type term_= type) { /* * Update according to parse-events.l @@ -880,7 +880,7 @@ config_term_avail(enum parse_events__term_type term_typ= e, struct parse_events_er =20 /* term_type is validated so indexing is safe */ if (asprintf(&err_str, "'%s' is not usable in 'perf stat'", - config_term_name(term_type)) >=3D 0) + parse_events__term_type_str(term_type)) >=3D 0) parse_events_error__handle(err, -1, err_str, NULL); return false; } @@ -1004,7 +1004,7 @@ do { \ case PARSE_EVENTS__TERM_TYPE_HARDWARE: default: parse_events_error__handle(err, term->err_term, - strdup(config_term_name(term->type_term)), + strdup(parse_events__term_type_str(term->type_term)), parse_events_formats_error_string(NULL)); return -EINVAL; } @@ -1127,8 +1127,9 @@ static int config_term_tracepoint(struct perf_event_a= ttr *attr, default: if (err) { parse_events_error__handle(err, term->err_term, - strdup(config_term_name(term->type_term)), - strdup("valid terms: call-graph,stack-size\n")); + strdup(parse_events__term_type_str(term->type_term)), + strdup("valid terms: call-graph,stack-size\n") + ); } return -EINVAL; } @@ -2568,7 +2569,7 @@ int parse_events_term__num(struct parse_events_term *= *term, struct parse_events_term temp =3D { .type_val =3D PARSE_EVENTS__TERM_TYPE_NUM, .type_term =3D type_term, - .config =3D config ? : strdup(config_term_name(type_term)), + .config =3D config ? : strdup(parse_events__term_type_str(type_term)), .no_value =3D no_value, .err_term =3D loc_term ? loc_term->first_column : 0, .err_val =3D loc_val ? loc_val->first_column : 0, @@ -2602,7 +2603,7 @@ int parse_events_term__term(struct parse_events_term = **term, void *loc_term, void *loc_val) { return parse_events_term__str(term, term_lhs, NULL, - strdup(config_term_name(term_rhs)), + strdup(parse_events__term_type_str(term_rhs)), loc_term, loc_val); } =20 @@ -2709,7 +2710,8 @@ int parse_events_terms__to_strbuf(const struct parse_= events_terms *terms, struct if (ret < 0) return ret; } else if ((unsigned int)term->type_term < __PARSE_EVENTS__TERM_TYPE_NR= ) { - ret =3D strbuf_addf(sb, "%s=3D", config_term_name(term->type_term)); + ret =3D strbuf_addf(sb, "%s=3D", + parse_events__term_type_str(term->type_term)); if (ret < 0) return ret; } @@ -2729,7 +2731,7 @@ static void config_terms_list(char *buf, size_t buf_s= z) =20 buf[0] =3D '\0'; for (i =3D 0; i < __PARSE_EVENTS__TERM_TYPE_NR; i++) { - const char *name =3D config_term_name(i); + const char *name =3D parse_events__term_type_str(i); =20 if (!config_term_avail(i, NULL)) continue; diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h index 10cc9c433116..bbe6c5700828 100644 --- a/tools/perf/util/parse-events.h +++ b/tools/perf/util/parse-events.h @@ -162,6 +162,8 @@ struct parse_events_state { bool wild_card_pmus; }; =20 +const char *parse_events__term_type_str(enum parse_events__term_type term_= type); + bool parse_events__filter_pmu(const struct parse_events_state *parse_state, const struct perf_pmu *pmu); void parse_events__shrink_config_terms(void); --=20 2.46.0.662.g92d0881bb0-goog From nobody Sat Nov 30 02:52:27 2024 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (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 E035E1BFDE8 for ; Thu, 12 Sep 2024 19:03:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726167842; cv=none; b=tONXJV88fdjnmmY/Lm+0HOkIG9cfPxMtpt0MaO/fltw2PjUjCEV77292U9lXRjAZubiLVUsMGhJMSExzYSnW10CT+LT705jf1YoagVlDhdn9E9yoPC03lctke+wLHVcc4iXMPRHgcdbOH9HAYJvE75MPgdOVZfEPIh+aV24SEaQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726167842; c=relaxed/simple; bh=4qfP9ZVxdXzcHzAuDI5UG8cMq/TP9DRuZgypizKWG3o=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=Nc5/GqAJcbL7D06Ps6j3R6pPFy7xKYjaO2MmIl/ef9vtIggx9E6Fr/9hZgrpe54EG0X9l8oe14mCyVojC5JXIJX6V8Qs5ekIDLphxMbvBYII/A0jVovCZn1wskEqwZGGjxonDHZp/kCmMFUaRQm0h94W75L9qhr6ZUkxRqTO/x4= 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=SdYvB+zJ; arc=none smtp.client-ip=209.85.219.202 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="SdYvB+zJ" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e1aa529e30eso311342276.1 for ; Thu, 12 Sep 2024 12:03:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1726167839; x=1726772639; 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=/3zIqJH1Nb1xJkdDPq1qmlE+q9YgxX0rolq2yYt0gt0=; b=SdYvB+zJN1XytSgVnFfc4ykxkmG4+NMxPB5M952kmF69CAu8Tr4shEmGzqM1dmumy5 opkt+zUNvGb5eddajD5wWYjIsfCzbXBU3CwmEMpbT/ud/0AbyfLl3o8OOqsL2pyk+b60 jzEIQVx9p9RTfCAW3ACKpIfNBRry0pQSo2PcD9KYvpNP+g+/JIXkJY/JaSdWNYVDH/NN X9GD57dRuJa5bj2Syyt09+17kB6XGmH2t1Z8dtS3pn4sGr5kwUfIi0UET3GgsQPckM1j IZ/TihvcvJ7APoM79bZG6QsckVk+0WyD7Uizx1g3Po9AyzDYv6Rr6KXqT5RNcSPLKK0y HF+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726167839; x=1726772639; 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=/3zIqJH1Nb1xJkdDPq1qmlE+q9YgxX0rolq2yYt0gt0=; b=ipzePGNFwVH1UsnQgDUHZqy6znhLWzFRlNwaxOaMxSUZMtSV5Cdil0LpkEyGRiWWju DPz+jD9EDbE5iUXbA7GLx488kptbZMpycNrTejZDZ7DWAgunjvNvSZHgFd1SzHV5/+OF e3z1xswHgN6sBuTVeDqErv/W7GT5SduFBaG2nYqHe6blwF98JhpLnAJsTBBS1mWDmn36 x7Ka/us1UEG4i9FsZ88qSAKP5Li1iiAjptBDC52E+0ItGudjEt+4mssGcZN9mSvA4xxm HsuNINjcJ45xt9DKEhOwnK+lqGYxfQZU0sSvu03LePKnpFEilg75mWDTXYHiBi5y7gvI vTNw== X-Forwarded-Encrypted: i=1; AJvYcCV3mMcEphhbrojCaYbgTjB8ulJsJDjT3fWPzwfQ1sG+7B6vad/tsoaIzJqQgWYWVIUsx/dEGaXdF60eLcw=@vger.kernel.org X-Gm-Message-State: AOJu0YzNEmHYvmAc++6XOGkAPHDQQoH44JKm7L1HISVl9NQhdjFHChU0 75WRKESHghT7zilUhTkl/XASzCCz8NNq7NZoTtmipgrIxbAL2DSEVCgK9eZ2XCR9pVkp9CWFlE2 33zlP3g== X-Google-Smtp-Source: AGHT+IG+OaDlHM52Tt0QR23AOssqxOgT8TZSC1n4SwmjTxRYV0WHiBO+/H4j5Y/+5MyAyzaCQljjFPwS0UHQ X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:cf0e:7a99:e672:3862]) (user=irogers job=sendgmr) by 2002:a25:3602:0:b0:e1d:2043:da46 with SMTP id 3f1490d57ef6-e1daff6d90bmr469276.3.1726167838849; Thu, 12 Sep 2024 12:03:58 -0700 (PDT) Date: Thu, 12 Sep 2024 12:03:31 -0700 In-Reply-To: <20240912190341.919229-1-irogers@google.com> Message-Id: <20240912190341.919229-5-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240912190341.919229-1-irogers@google.com> X-Mailer: git-send-email 2.46.0.662.g92d0881bb0-goog Subject: [PATCH v2 04/13] perf tool_pmu: Factor tool events into their own PMU 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 , John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Ravi Bangoria , Weilin Wang , Jing Zhang , Xu Yang , Sandipan Das , Benjamin Gray , Athira Jajeev , Howard Chu , Dominique Martinet , Yang Jihong , Colin Ian King , Veronika Molnarova , "Dr. David Alan Gilbert" , Oliver Upton , Changbin Du , Ze Gao , Andi Kleen , "=?UTF-8?q?Cl=C3=A9ment=20Le=20Goffic?=" , Sun Haiyong , Junhao He , Tiezhu Yang , Yicong Yang , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-arm-kernel@lists.infradead.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Rather than treat tool events as a special kind of event, create a tool only PMU where the events/aliases match the existing duration_time, user_time and system_time events. Remove special parsing and printing support for the tool events, but add function calls for when PMU functions are called on a tool_pmu. Move the tool PMU code in evsel into tool_pmu.c to better encapsulate the tool event behavior in that file. Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- tools/perf/builtin-list.c | 13 +- tools/perf/builtin-stat.c | 1 + tools/perf/util/Build | 1 + tools/perf/util/evsel.c | 272 ++-------------------- tools/perf/util/evsel.h | 28 +-- tools/perf/util/metricgroup.c | 1 + tools/perf/util/parse-events.c | 38 --- tools/perf/util/parse-events.h | 3 - tools/perf/util/parse-events.l | 11 - tools/perf/util/parse-events.y | 16 -- tools/perf/util/pmu.c | 20 +- tools/perf/util/pmu.h | 2 + tools/perf/util/pmus.c | 9 + tools/perf/util/print-events.c | 36 +-- tools/perf/util/print-events.h | 1 - tools/perf/util/stat-display.c | 6 +- tools/perf/util/stat-shadow.c | 1 + tools/perf/util/tool_pmu.c | 413 +++++++++++++++++++++++++++++++++ tools/perf/util/tool_pmu.h | 51 ++++ 19 files changed, 532 insertions(+), 391 deletions(-) create mode 100644 tools/perf/util/tool_pmu.c create mode 100644 tools/perf/util/tool_pmu.h diff --git a/tools/perf/builtin-list.c b/tools/perf/builtin-list.c index 65b8cba324be..b8378ba18c28 100644 --- a/tools/perf/builtin-list.c +++ b/tools/perf/builtin-list.c @@ -19,6 +19,7 @@ #include "util/string2.h" #include "util/strlist.h" #include "util/strbuf.h" +#include "util/tool_pmu.h" #include #include #include @@ -614,9 +615,18 @@ int cmd_list(int argc, const char **argv) event_symbols_hw, PERF_COUNT_HW_MAX); else if (strcmp(argv[i], "sw") =3D=3D 0 || strcmp(argv[i], "software") =3D=3D 0) { + char *old_pmu_glob =3D default_ps.pmu_glob; + print_symbol_events(&print_cb, ps, PERF_TYPE_SOFTWARE, event_symbols_sw, PERF_COUNT_SW_MAX); - print_tool_events(&print_cb, ps); + default_ps.pmu_glob =3D strdup("tool"); + if (!default_ps.pmu_glob) { + ret =3D -1; + goto out; + } + perf_pmus__print_pmu_events(&print_cb, ps); + zfree(&default_ps.pmu_glob); + default_ps.pmu_glob =3D old_pmu_glob; } else if (strcmp(argv[i], "cache") =3D=3D 0 || strcmp(argv[i], "hwcache") =3D=3D 0) print_hwcache_events(&print_cb, ps); @@ -664,7 +674,6 @@ int cmd_list(int argc, const char **argv) event_symbols_hw, PERF_COUNT_HW_MAX); print_symbol_events(&print_cb, ps, PERF_TYPE_SOFTWARE, event_symbols_sw, PERF_COUNT_SW_MAX); - print_tool_events(&print_cb, ps); print_hwcache_events(&print_cb, ps); perf_pmus__print_pmu_events(&print_cb, ps); print_tracepoint_events(&print_cb, ps); diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 689a3d43c258..ae525fdcfbde 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -46,6 +46,7 @@ #include "util/parse-events.h" #include "util/pmus.h" #include "util/pmu.h" +#include "util/tool_pmu.h" #include "util/event.h" #include "util/evlist.h" #include "util/evsel.h" diff --git a/tools/perf/util/Build b/tools/perf/util/Build index dc616292b2dd..fa508e113dd0 100644 --- a/tools/perf/util/Build +++ b/tools/perf/util/Build @@ -83,6 +83,7 @@ perf-util-y +=3D pmu.o perf-util-y +=3D pmus.o perf-util-y +=3D pmu-flex.o perf-util-y +=3D pmu-bison.o +perf-util-y +=3D tool_pmu.o perf-util-y +=3D svghelper.o perf-util-$(CONFIG_LIBTRACEEVENT) +=3D trace-event-info.o perf-util-y +=3D trace-event-scripting.o diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index dbf9c8cee3c5..b75c4a4c7aa7 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include @@ -51,6 +50,7 @@ #include "off_cpu.h" #include "pmu.h" #include "pmus.h" +#include "tool_pmu.h" #include "rlimit.h" #include "../perf-sys.h" #include "util/parse-branch-options.h" @@ -71,33 +71,6 @@ struct perf_missing_features perf_missing_features; =20 static clockid_t clockid; =20 -static const char *const perf_tool_event__tool_names[PERF_TOOL_MAX] =3D { - NULL, - "duration_time", - "user_time", - "system_time", -}; - -const char *perf_tool_event__to_str(enum perf_tool_event ev) -{ - if (ev > PERF_TOOL_NONE && ev < PERF_TOOL_MAX) - return perf_tool_event__tool_names[ev]; - - return NULL; -} - -enum perf_tool_event perf_tool_event__from_str(const char *str) -{ - int i; - - perf_tool_event__for_each_event(i) { - if (!strcmp(str, perf_tool_event__tool_names[i])) - return i; - } - return PERF_TOOL_NONE; -} - - static int evsel__no_extra_init(struct evsel *evsel __maybe_unused) { return 0; @@ -421,7 +394,6 @@ struct evsel *evsel__clone(struct evsel *orig) evsel->core.leader =3D orig->core.leader; =20 evsel->max_events =3D orig->max_events; - evsel->tool_event =3D orig->tool_event; free((char *)evsel->unit); evsel->unit =3D strdup(orig->unit); if (evsel->unit =3D=3D NULL) @@ -617,11 +589,6 @@ static int evsel__sw_name(struct evsel *evsel, char *b= f, size_t size) return r + evsel__add_modifiers(evsel, bf + r, size - r); } =20 -static int evsel__tool_name(enum perf_tool_event ev, char *bf, size_t size) -{ - return scnprintf(bf, size, "%s", perf_tool_event__to_str(ev)); -} - static int __evsel__bp_name(char *bf, size_t size, u64 addr, u64 type) { int r; @@ -772,10 +739,7 @@ const char *evsel__name(struct evsel *evsel) break; =20 case PERF_TYPE_SOFTWARE: - if (evsel__is_tool(evsel)) - evsel__tool_name(evsel__tool_event(evsel), bf, sizeof(bf)); - else - evsel__sw_name(evsel, bf, sizeof(bf)); + evsel__sw_name(evsel, bf, sizeof(bf)); break; =20 case PERF_TYPE_TRACEPOINT: @@ -786,6 +750,10 @@ const char *evsel__name(struct evsel *evsel) evsel__bp_name(evsel, bf, sizeof(bf)); break; =20 + case PERF_PMU_TYPE_TOOL: + scnprintf(bf, sizeof(bf), "%s", evsel__tool_pmu_event_name(evsel)); + break; + default: scnprintf(bf, sizeof(bf), "unknown attr type: %d", evsel->core.attr.type); @@ -811,7 +779,7 @@ const char *evsel__metric_id(const struct evsel *evsel) return evsel->metric_id; =20 if (evsel__is_tool(evsel)) - return perf_tool_event__to_str(evsel__tool_event(evsel)); + return evsel__tool_pmu_event_name(evsel); =20 return "unknown"; } @@ -1684,167 +1652,6 @@ static int evsel__read_group(struct evsel *leader, = int cpu_map_idx, int thread) return evsel__process_group_data(leader, cpu_map_idx, thread, data); } =20 -static bool read_until_char(struct io *io, char e) -{ - int c; - - do { - c =3D io__get_char(io); - if (c =3D=3D -1) - return false; - } while (c !=3D e); - return true; -} - -static int read_stat_field(int fd, struct perf_cpu cpu, int field, __u64 *= val) -{ - char buf[256]; - struct io io; - int i; - - io__init(&io, fd, buf, sizeof(buf)); - - /* Skip lines to relevant CPU. */ - for (i =3D -1; i < cpu.cpu; i++) { - if (!read_until_char(&io, '\n')) - return -EINVAL; - } - /* Skip to "cpu". */ - if (io__get_char(&io) !=3D 'c') return -EINVAL; - if (io__get_char(&io) !=3D 'p') return -EINVAL; - if (io__get_char(&io) !=3D 'u') return -EINVAL; - - /* Skip N of cpuN. */ - if (!read_until_char(&io, ' ')) - return -EINVAL; - - i =3D 1; - while (true) { - if (io__get_dec(&io, val) !=3D ' ') - break; - if (field =3D=3D i) - return 0; - i++; - } - return -EINVAL; -} - -static int read_pid_stat_field(int fd, int field, __u64 *val) -{ - char buf[256]; - struct io io; - int c, i; - - io__init(&io, fd, buf, sizeof(buf)); - if (io__get_dec(&io, val) !=3D ' ') - return -EINVAL; - if (field =3D=3D 1) - return 0; - - /* Skip comm. */ - if (io__get_char(&io) !=3D '(' || !read_until_char(&io, ')')) - return -EINVAL; - if (field =3D=3D 2) - return -EINVAL; /* String can't be returned. */ - - /* Skip state */ - if (io__get_char(&io) !=3D ' ' || io__get_char(&io) =3D=3D -1) - return -EINVAL; - if (field =3D=3D 3) - return -EINVAL; /* String can't be returned. */ - - /* Loop over numeric fields*/ - if (io__get_char(&io) !=3D ' ') - return -EINVAL; - - i =3D 4; - while (true) { - c =3D io__get_dec(&io, val); - if (c =3D=3D -1) - return -EINVAL; - if (c =3D=3D -2) { - /* Assume a -ve was read */ - c =3D io__get_dec(&io, val); - *val *=3D -1; - } - if (c !=3D ' ') - return -EINVAL; - if (field =3D=3D i) - return 0; - i++; - } - return -EINVAL; -} - -static int evsel__read_tool(struct evsel *evsel, int cpu_map_idx, int thre= ad) -{ - __u64 *start_time, cur_time, delta_start; - int fd, err =3D 0; - struct perf_counts_values *count; - bool adjust =3D false; - - count =3D perf_counts(evsel->counts, cpu_map_idx, thread); - - switch (evsel__tool_event(evsel)) { - case PERF_TOOL_DURATION_TIME: - /* - * Pretend duration_time is only on the first CPU and thread, or - * else aggregation will scale duration_time by the number of - * CPUs/threads. - */ - start_time =3D &evsel->start_time; - if (cpu_map_idx =3D=3D 0 && thread =3D=3D 0) - cur_time =3D rdclock(); - else - cur_time =3D *start_time; - break; - case PERF_TOOL_USER_TIME: - case PERF_TOOL_SYSTEM_TIME: { - bool system =3D evsel__tool_event(evsel) =3D=3D PERF_TOOL_SYSTEM_TIME; - - start_time =3D xyarray__entry(evsel->start_times, cpu_map_idx, thread); - fd =3D FD(evsel, cpu_map_idx, thread); - lseek(fd, SEEK_SET, 0); - if (evsel->pid_stat) { - /* The event exists solely on 1 CPU. */ - if (cpu_map_idx =3D=3D 0) - err =3D read_pid_stat_field(fd, system ? 15 : 14, &cur_time); - else - cur_time =3D 0; - } else { - /* The event is for all threads. */ - if (thread =3D=3D 0) { - struct perf_cpu cpu =3D perf_cpu_map__cpu(evsel->core.cpus, - cpu_map_idx); - - err =3D read_stat_field(fd, cpu, system ? 3 : 1, &cur_time); - } else { - cur_time =3D 0; - } - } - adjust =3D true; - break; - } - case PERF_TOOL_NONE: - case PERF_TOOL_MAX: - default: - err =3D -EINVAL; - } - if (err) - return err; - - delta_start =3D cur_time - *start_time; - if (adjust) { - __u64 ticks_per_sec =3D sysconf(_SC_CLK_TCK); - - delta_start *=3D 1000000000 / ticks_per_sec; - } - count->val =3D delta_start; - count->ena =3D count->run =3D delta_start; - count->lost =3D 0; - return 0; -} - int evsel__read_counter(struct evsel *evsel, int cpu_map_idx, int thread) { if (evsel__is_tool(evsel)) @@ -2042,6 +1849,7 @@ static struct perf_thread_map *empty_thread_map; static int __evsel__prepare_open(struct evsel *evsel, struct perf_cpu_map = *cpus, struct perf_thread_map *threads) { + int ret =3D 0; int nthreads =3D perf_thread_map__nr(threads); =20 if ((perf_missing_features.write_backward && evsel->core.attr.write_backw= ard) || @@ -2072,19 +1880,14 @@ static int __evsel__prepare_open(struct evsel *evse= l, struct perf_cpu_map *cpus, perf_evsel__alloc_fd(&evsel->core, perf_cpu_map__nr(cpus), nthreads) = < 0) return -ENOMEM; =20 - if ((evsel__tool_event(evsel) =3D=3D PERF_TOOL_SYSTEM_TIME || - evsel__tool_event(evsel) =3D=3D PERF_TOOL_USER_TIME) && - !evsel->start_times) { - evsel->start_times =3D xyarray__new(perf_cpu_map__nr(cpus), nthreads, si= zeof(__u64)); - if (!evsel->start_times) - return -ENOMEM; - } + if (evsel__is_tool(evsel)) + ret =3D evsel__tool_pmu_prepare_open(evsel, cpus, nthreads); =20 evsel->open_flags =3D PERF_FLAG_FD_CLOEXEC; if (evsel->cgrp) evsel->open_flags |=3D PERF_FLAG_PID_CGROUP; =20 - return 0; + return ret; } =20 static void evsel__disable_missing_features(struct evsel *evsel) @@ -2262,13 +2065,6 @@ static int evsel__open_cpu(struct evsel *evsel, stru= ct perf_cpu_map *cpus, int pid =3D -1, err, old_errno; enum rlimit_action set_rlimit =3D NO_CHANGE; =20 - if (evsel__tool_event(evsel) =3D=3D PERF_TOOL_DURATION_TIME) { - if (evsel->core.attr.sample_period) /* no sampling */ - return -EINVAL; - evsel->start_time =3D rdclock(); - return 0; - } - if (evsel__is_retire_lat(evsel)) return tpebs_start(evsel->evlist); =20 @@ -2293,6 +2089,12 @@ static int evsel__open_cpu(struct evsel *evsel, stru= ct perf_cpu_map *cpus, pr_debug3("Opening: %s\n", evsel__name(evsel)); display_attr(&evsel->core.attr); =20 + if (evsel__is_tool(evsel)) { + return evsel__tool_pmu_open(evsel, threads, + start_cpu_map_idx, + end_cpu_map_idx); + } + for (idx =3D start_cpu_map_idx; idx < end_cpu_map_idx; idx++) { =20 for (thread =3D 0; thread < nthreads; thread++) { @@ -2304,46 +2106,6 @@ static int evsel__open_cpu(struct evsel *evsel, stru= ct perf_cpu_map *cpus, if (!evsel->cgrp && !evsel->core.system_wide) pid =3D perf_thread_map__pid(threads, thread); =20 - if (evsel__tool_event(evsel) =3D=3D PERF_TOOL_USER_TIME || - evsel__tool_event(evsel) =3D=3D PERF_TOOL_SYSTEM_TIME) { - bool system =3D evsel__tool_event(evsel) =3D=3D PERF_TOOL_SYSTEM_TIME; - __u64 *start_time =3D NULL; - - if (evsel->core.attr.sample_period) { - /* no sampling */ - err =3D -EINVAL; - goto out_close; - } - if (pid > -1) { - char buf[64]; - - snprintf(buf, sizeof(buf), "/proc/%d/stat", pid); - fd =3D open(buf, O_RDONLY); - evsel->pid_stat =3D true; - } else { - fd =3D open("/proc/stat", O_RDONLY); - } - FD(evsel, idx, thread) =3D fd; - if (fd < 0) { - err =3D -errno; - goto out_close; - } - start_time =3D xyarray__entry(evsel->start_times, idx, thread); - if (pid > -1) { - err =3D read_pid_stat_field(fd, system ? 15 : 14, - start_time); - } else { - struct perf_cpu cpu; - - cpu =3D perf_cpu_map__cpu(evsel->core.cpus, idx); - err =3D read_stat_field(fd, cpu, system ? 3 : 1, - start_time); - } - if (err) - goto out_close; - continue; - } - group_fd =3D get_group_fd(evsel, idx, thread); =20 if (group_fd =3D=3D -2) { diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index 15e745a9a798..bc30491bd490 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -11,6 +11,7 @@ #include #include "symbol_conf.h" #include "pmus.h" +#include "pmu.h" =20 struct bpf_object; struct cgroup; @@ -22,25 +23,9 @@ struct target; struct hashmap; struct bperf_leader_bpf; struct bperf_follower_bpf; -struct perf_pmu; =20 typedef int (evsel__sb_cb_t)(union perf_event *event, void *data); =20 -enum perf_tool_event { - PERF_TOOL_NONE =3D 0, - PERF_TOOL_DURATION_TIME =3D 1, - PERF_TOOL_USER_TIME =3D 2, - PERF_TOOL_SYSTEM_TIME =3D 3, - - PERF_TOOL_MAX, -}; - -const char *perf_tool_event__to_str(enum perf_tool_event ev); -enum perf_tool_event perf_tool_event__from_str(const char *str); - -#define perf_tool_event__for_each_event(ev) \ - for ((ev) =3D PERF_TOOL_DURATION_TIME; (ev) < PERF_TOOL_MAX; ev++) - /** struct evsel - event selector * * @evlist - evlist this evsel is in, if it is in one. @@ -83,7 +68,6 @@ struct evsel { const char *unit; struct cgroup *cgrp; const char *metric_id; - enum perf_tool_event tool_event; /* parse modifier helper */ int exclude_GH; int sample_read; @@ -320,21 +304,11 @@ const char *evsel__name(struct evsel *evsel); bool evsel__name_is(struct evsel *evsel, const char *name); const char *evsel__metric_id(const struct evsel *evsel); =20 -static inline bool evsel__is_tool(const struct evsel *evsel) -{ - return evsel->tool_event !=3D PERF_TOOL_NONE; -} - static inline bool evsel__is_retire_lat(const struct evsel *evsel) { return evsel->retire_lat; } =20 -static inline enum perf_tool_event evsel__tool_event(const struct evsel *e= vsel) -{ - return evsel->tool_event; -} - const char *evsel__group_name(struct evsel *evsel); int evsel__group_desc(struct evsel *evsel, char *buf, size_t size); =20 diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index 4dff3e925a47..9181548e8881 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -14,6 +14,7 @@ #include "pmus.h" #include "print-events.h" #include "smt.h" +#include "tool_pmu.h" #include "expr.h" #include "rblist.h" #include diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 776812460dad..cb5ecc6bfdc3 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -298,37 +298,6 @@ static int add_event(struct list_head *list, int *idx, /*auto_merge_stats=3D*/false, /*cpu_list=3D*/NULL) ? 0 : -ENOMEM; } =20 -static int add_event_tool(struct list_head *list, int *idx, - enum perf_tool_event tool_event) -{ - struct evsel *evsel; - struct perf_event_attr attr =3D { - .type =3D PERF_TYPE_SOFTWARE, - .config =3D PERF_COUNT_SW_DUMMY, - }; - struct perf_cpu_map *cpu_list =3D NULL; - - if (tool_event =3D=3D PERF_TOOL_DURATION_TIME) { - /* Duration time is gathered globally, pretend it is only on CPU0. */ - cpu_list =3D perf_cpu_map__new("0"); - } - evsel =3D __add_event(list, idx, &attr, /*init_attr=3D*/true, /*name=3D*/= NULL, - /*metric_id=3D*/NULL, /*pmu=3D*/NULL, - /*config_terms=3D*/NULL, /*auto_merge_stats=3D*/false, - cpu_list); - perf_cpu_map__put(cpu_list); - if (!evsel) - return -ENOMEM; - evsel->tool_event =3D tool_event; - if (tool_event =3D=3D PERF_TOOL_DURATION_TIME - || tool_event =3D=3D PERF_TOOL_USER_TIME - || tool_event =3D=3D PERF_TOOL_SYSTEM_TIME) { - free((char *)evsel->unit); - evsel->unit =3D strdup("ns"); - } - return 0; -} - /** * parse_aliases - search names for entries beginning or equalling str ign= oring * case. If mutliple entries in names match str then the l= ongest @@ -1422,13 +1391,6 @@ int parse_events_add_numeric(struct parse_events_sta= te *parse_state, type, /*extended_type=3D*/0, config, head_config); } =20 -int parse_events_add_tool(struct parse_events_state *parse_state, - struct list_head *list, - int tool_event) -{ - return add_event_tool(list, &parse_state->idx, tool_event); -} - static bool config_term_percore(struct list_head *config_terms) { struct evsel_config_term *term; diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h index bbe6c5700828..336ef5df13c5 100644 --- a/tools/perf/util/parse-events.h +++ b/tools/perf/util/parse-events.h @@ -223,9 +223,6 @@ int parse_events_add_numeric(struct parse_events_state = *parse_state, u32 type, u64 config, const struct parse_events_terms *head_config, bool wildcard); -int parse_events_add_tool(struct parse_events_state *parse_state, - struct list_head *list, - int tool_event); int parse_events_add_cache(struct list_head *list, int *idx, const char *n= ame, struct parse_events_state *parse_state, struct parse_events_terms *parsed_terms); diff --git a/tools/perf/util/parse-events.l b/tools/perf/util/parse-events.l index 5a0bcd7f166a..14e5bd856a18 100644 --- a/tools/perf/util/parse-events.l +++ b/tools/perf/util/parse-events.l @@ -121,14 +121,6 @@ static int sym(yyscan_t scanner, int type, int config) return type =3D=3D PERF_TYPE_HARDWARE ? PE_VALUE_SYM_HW : PE_VALUE_SYM_SW; } =20 -static int tool(yyscan_t scanner, enum perf_tool_event event) -{ - YYSTYPE *yylval =3D parse_events_get_lval(scanner); - - yylval->num =3D event; - return PE_VALUE_SYM_TOOL; -} - static int term(yyscan_t scanner, enum parse_events__term_type type) { YYSTYPE *yylval =3D parse_events_get_lval(scanner); @@ -404,9 +396,6 @@ cpu-migrations|migrations { return sym(yyscanner, PER= F_TYPE_SOFTWARE, PERF_COU alignment-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT= _SW_ALIGNMENT_FAULTS); } emulation-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT= _SW_EMULATION_FAULTS); } dummy { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_DUMMY= ); } -duration_time { return tool(yyscanner, PERF_TOOL_DURATION_TIME); } -user_time { return tool(yyscanner, PERF_TOOL_USER_TIME); } -system_time { return tool(yyscanner, PERF_TOOL_SYSTEM_TIME); } bpf-output { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_B= PF_OUTPUT); } cgroup-switches { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT= _SW_CGROUP_SWITCHES); } =20 diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y index b3c51f06cbdc..5c4669264177 100644 --- a/tools/perf/util/parse-events.y +++ b/tools/perf/util/parse-events.y @@ -56,7 +56,6 @@ static void free_list_evsel(struct list_head* list_evsel) =20 %token PE_START_EVENTS PE_START_TERMS %token PE_VALUE PE_VALUE_SYM_HW PE_VALUE_SYM_SW PE_TERM -%token PE_VALUE_SYM_TOOL %token PE_EVENT_NAME %token PE_RAW PE_NAME %token PE_MODIFIER_EVENT PE_MODIFIER_BP PE_BP_COLON PE_BP_SLASH @@ -68,7 +67,6 @@ static void free_list_evsel(struct list_head* list_evsel) %type PE_VALUE %type PE_VALUE_SYM_HW %type PE_VALUE_SYM_SW -%type PE_VALUE_SYM_TOOL %type PE_MODIFIER_EVENT %type PE_TERM %type value_sym @@ -350,20 +348,6 @@ value_sym sep_slash_slash_dc PE_ABORT(err); $$ =3D list; } -| -PE_VALUE_SYM_TOOL sep_slash_slash_dc -{ - struct list_head *list; - int err; - - list =3D alloc_list(); - if (!list) - YYNOMEM; - err =3D parse_events_add_tool(_parse_state, list, $1); - if (err) - YYNOMEM; - $$ =3D list; -} =20 event_legacy_cache: PE_LEGACY_CACHE opt_event_config diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index c020fc34b635..f17e21455498 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -19,6 +19,7 @@ #include "evsel.h" #include "pmu.h" #include "pmus.h" +#include "tool_pmu.h" #include #include #include "parse-events.h" @@ -1548,6 +1549,9 @@ int perf_pmu__config(struct perf_pmu *pmu, struct per= f_event_attr *attr, { bool zero =3D !!pmu->perf_event_attr_init_default; =20 + if (perf_pmu__is_tool(pmu)) + return tool_pmu__config_terms(attr, head_terms, err); + /* Fake PMU doesn't have proper terms so nothing to configure in attr. */ if (perf_pmu__is_fake(pmu)) return 0; @@ -1660,8 +1664,8 @@ int perf_pmu__check_alias(struct perf_pmu *pmu, struc= t parse_events_terms *head_ info->scale =3D 0.0; info->snapshot =3D false; =20 - /* Fake PMU doesn't rewrite terms. */ - if (perf_pmu__is_fake(pmu)) + /* Tool/fake PMU doesn't rewrite terms. */ + if (perf_pmu__is_tool(pmu) || perf_pmu__is_fake(pmu)) goto out; =20 list_for_each_entry_safe(term, h, &head_terms->terms, list) { @@ -1827,6 +1831,8 @@ bool perf_pmu__have_event(struct perf_pmu *pmu, const= char *name) { if (!name) return false; + if (perf_pmu__is_tool(pmu)) + return perf_tool_event__from_str(name) !=3D PERF_TOOL_NONE; if (perf_pmu__find_alias(pmu, name, /*load=3D*/ true) !=3D NULL) return true; if (pmu->cpu_aliases_added || !pmu->events_table) @@ -1838,6 +1844,9 @@ size_t perf_pmu__num_events(struct perf_pmu *pmu) { size_t nr; =20 + if (perf_pmu__is_tool(pmu)) + return tool_pmu__num_events(); + pmu_aliases_parse(pmu); nr =3D pmu->sysfs_aliases + pmu->sys_json_aliases; =20 @@ -1898,6 +1907,9 @@ int perf_pmu__for_each_event(struct perf_pmu *pmu, bo= ol skip_duplicate_pmus, int ret =3D 0; struct strbuf sb; =20 + if (perf_pmu__is_tool(pmu)) + return tool_pmu__for_each_event_cb(pmu, state, cb); + strbuf_init(&sb, /*hint=3D*/ 0); pmu_aliases_parse(pmu); pmu_add_cpu_aliases(pmu); @@ -1986,6 +1998,7 @@ bool perf_pmu__is_software(const struct perf_pmu *pmu) case PERF_TYPE_HW_CACHE: return false; case PERF_TYPE_RAW: return false; case PERF_TYPE_BREAKPOINT: return true; + case PERF_PMU_TYPE_TOOL: return true; default: break; } for (size_t i =3D 0; i < ARRAY_SIZE(known_sw_pmus); i++) { @@ -2313,6 +2326,9 @@ const char *perf_pmu__name_from_config(struct perf_pm= u *pmu, u64 config) if (!pmu) return NULL; =20 + if (perf_pmu__is_tool(pmu)) + return perf_tool_event__to_str(config); + pmu_aliases_parse(pmu); pmu_add_cpu_aliases(pmu); list_for_each_entry(event, &pmu->aliases, list) { diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h index af7532ca7fb1..880a8dc661b7 100644 --- a/tools/perf/util/pmu.h +++ b/tools/perf/util/pmu.h @@ -37,6 +37,7 @@ struct perf_pmu_caps { }; =20 enum { + PERF_PMU_TYPE_TOOL =3D 0xFFFFFFFE, PERF_PMU_TYPE_FAKE =3D 0xFFFFFFFF, }; =20 @@ -282,6 +283,7 @@ struct perf_pmu *perf_pmu__lookup(struct list_head *pmu= s, int dirfd, const char struct perf_pmu *perf_pmu__create_placeholder_core_pmu(struct list_head *c= ore_pmus); void perf_pmu__delete(struct perf_pmu *pmu); struct perf_pmu *perf_pmus__find_core_pmu(void); + const char *perf_pmu__name_from_config(struct perf_pmu *pmu, u64 config); =20 #endif /* __PMU_H */ diff --git a/tools/perf/util/pmus.c b/tools/perf/util/pmus.c index 52109af5f2f1..6e657c44de58 100644 --- a/tools/perf/util/pmus.c +++ b/tools/perf/util/pmus.c @@ -15,6 +15,7 @@ #include "evsel.h" #include "pmus.h" #include "pmu.h" +#include "tool_pmu.h" #include "print-events.h" #include "strbuf.h" =20 @@ -200,6 +201,7 @@ static void pmu_read_sysfs(bool core_only) int fd; DIR *dir; struct dirent *dent; + struct perf_pmu *tool_pmu; =20 if (read_sysfs_all_pmus || (core_only && read_sysfs_core_pmus)) return; @@ -229,6 +231,10 @@ static void pmu_read_sysfs(bool core_only) pr_err("Failure to set up any core PMUs\n"); } list_sort(NULL, &core_pmus, pmus_cmp); + if (!core_only) { + tool_pmu =3D perf_pmus__tool_pmu(); + list_add_tail(&tool_pmu->list, &other_pmus); + } list_sort(NULL, &other_pmus, pmus_cmp); if (!list_empty(&core_pmus)) { read_sysfs_core_pmus =3D true; @@ -584,6 +590,9 @@ void perf_pmus__print_raw_pmu_events(const struct print= _callbacks *print_cb, voi int len =3D pmu_name_len_no_suffix(pmu->name); const char *desc =3D "(see 'man perf-list' or 'man perf-record' on how t= o encode it)"; =20 + if (perf_pmu__is_tool(pmu)) + continue; + if (!pmu->is_core) desc =3D NULL; =20 diff --git a/tools/perf/util/print-events.c b/tools/perf/util/print-events.c index 81e0135cddf0..a786cbfb0ff5 100644 --- a/tools/perf/util/print-events.c +++ b/tools/perf/util/print-events.c @@ -29,6 +29,7 @@ #include "tracepoint.h" #include "pfm.h" #include "thread_map.h" +#include "tool_pmu.h" #include "util.h" =20 #define MAX_NAME_LEN 100 @@ -43,21 +44,6 @@ static const char * const event_type_descriptors[] =3D { "Hardware breakpoint", }; =20 -static const struct event_symbol event_symbols_tool[PERF_TOOL_MAX] =3D { - [PERF_TOOL_DURATION_TIME] =3D { - .symbol =3D "duration_time", - .alias =3D "", - }, - [PERF_TOOL_USER_TIME] =3D { - .symbol =3D "user_time", - .alias =3D "", - }, - [PERF_TOOL_SYSTEM_TIME] =3D { - .symbol =3D "system_time", - .alias =3D "", - }, -}; - /* * Print the events from /tracing/events */ @@ -341,24 +327,6 @@ int print_hwcache_events(const struct print_callbacks = *print_cb, void *print_sta return 0; } =20 -void print_tool_events(const struct print_callbacks *print_cb, void *print= _state) -{ - // Start at 1 because the first enum entry means no tool event. - for (int i =3D 1; i < PERF_TOOL_MAX; ++i) { - print_cb->print_event(print_state, - "tool", - /*pmu_name=3D*/NULL, - event_symbols_tool[i].symbol, - event_symbols_tool[i].alias, - /*scale_unit=3D*/NULL, - /*deprecated=3D*/false, - "Tool event", - /*desc=3D*/NULL, - /*long_desc=3D*/NULL, - /*encoding_desc=3D*/NULL); - } -} - void print_symbol_events(const struct print_callbacks *print_cb, void *pri= nt_state, unsigned int type, const struct event_symbol *syms, unsigned int max) @@ -422,8 +390,6 @@ void print_events(const struct print_callbacks *print_c= b, void *print_state) print_symbol_events(print_cb, print_state, PERF_TYPE_SOFTWARE, event_symbols_sw, PERF_COUNT_SW_MAX); =20 - print_tool_events(print_cb, print_state); - print_hwcache_events(print_cb, print_state); =20 perf_pmus__print_pmu_events(print_cb, print_state); diff --git a/tools/perf/util/print-events.h b/tools/perf/util/print-events.h index bf4290bef0cd..445efa1636c1 100644 --- a/tools/perf/util/print-events.h +++ b/tools/perf/util/print-events.h @@ -36,7 +36,6 @@ void print_sdt_events(const struct print_callbacks *print= _cb, void *print_state) void print_symbol_events(const struct print_callbacks *print_cb, void *pri= nt_state, unsigned int type, const struct event_symbol *syms, unsigned int max); -void print_tool_events(const struct print_callbacks *print_cb, void *print= _state); void print_tracepoint_events(const struct print_callbacks *print_cb, void = *print_state); bool is_event_supported(u8 type, u64 config); =20 diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index ea96e4ebad8c..a82a8ec79b39 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -21,6 +21,7 @@ #include "iostat.h" #include "pmu.h" #include "pmus.h" +#include "tool_pmu.h" =20 #define CNTR_NOT_SUPPORTED "" #define CNTR_NOT_COUNTED "" @@ -946,7 +947,10 @@ static bool should_skip_zero_counter(struct perf_stat_= config *config, if (config->aggr_mode =3D=3D AGGR_THREAD && config->system_wide) return true; =20 - /* Tool events have the software PMU but are only gathered on 1. */ + /* + * Many tool events are only gathered on the first index, skip other + * zero values. + */ if (evsel__is_tool(counter)) return true; =20 diff --git a/tools/perf/util/stat-shadow.c b/tools/perf/util/stat-shadow.c index 99376c12dd8e..2d653f91400e 100644 --- a/tools/perf/util/stat-shadow.c +++ b/tools/perf/util/stat-shadow.c @@ -15,6 +15,7 @@ #include #include "iostat.h" #include "util/hashmap.h" +#include "tool_pmu.h" =20 struct stats walltime_nsecs_stats; struct rusage_stats ru_stats; diff --git a/tools/perf/util/tool_pmu.c b/tools/perf/util/tool_pmu.c new file mode 100644 index 000000000000..702c1131a2a8 --- /dev/null +++ b/tools/perf/util/tool_pmu.c @@ -0,0 +1,413 @@ +// SPDX-License-Identifier: GPL-2.0-only +#include "cgroup.h" +#include "counts.h" +#include "evsel.h" +#include "pmu.h" +#include "print-events.h" +#include "time-utils.h" +#include "tool_pmu.h" +#include +#include +#include +#include +#include + +static const char *const tool_pmu__event_names[PERF_TOOL_MAX] =3D { + NULL, + "duration_time", + "user_time", + "system_time", +}; + + +const char *perf_tool_event__to_str(enum perf_tool_event ev) +{ + if (ev > PERF_TOOL_NONE && ev < PERF_TOOL_MAX) + return tool_pmu__event_names[ev]; + + return NULL; +} + +enum perf_tool_event perf_tool_event__from_str(const char *str) +{ + int i; + + perf_tool_event__for_each_event(i) { + if (!strcasecmp(str, tool_pmu__event_names[i])) + return i; + } + return PERF_TOOL_NONE; +} + +static int tool_pmu__config_term(struct perf_event_attr *attr, + struct parse_events_term *term, + struct parse_events_error *err) +{ + if (term->type_term =3D=3D PARSE_EVENTS__TERM_TYPE_USER) { + enum perf_tool_event ev =3D perf_tool_event__from_str(term->config); + + if (ev =3D=3D PERF_TOOL_NONE) + goto err_out; + + attr->config =3D ev; + return 0; + } +err_out: + if (err) { + char *err_str; + + parse_events_error__handle(err, term->err_val, + asprintf(&err_str, + "unexpected tool event term (%s) %s", + parse_events__term_type_str(term->type_term), + term->config) < 0 + ? strdup("unexpected tool event term") + : err_str, + NULL); + } + return -EINVAL; +} + +int tool_pmu__config_terms(struct perf_event_attr *attr, + struct parse_events_terms *terms, + struct parse_events_error *err) +{ + struct parse_events_term *term; + + list_for_each_entry(term, &terms->terms, list) { + if (tool_pmu__config_term(attr, term, err)) + return -EINVAL; + } + + return 0; + +} + +int tool_pmu__for_each_event_cb(struct perf_pmu *pmu, void *state, pmu_eve= nt_callback cb) +{ + struct pmu_event_info info =3D { + .pmu =3D pmu, + .event_type_desc =3D "Tool event", + }; + int i; + + perf_tool_event__for_each_event(i) { + int ret; + + info.name =3D perf_tool_event__to_str(i); + info.alias =3D NULL; + info.scale_unit =3D NULL; + info.desc =3D NULL; + info.long_desc =3D NULL; + info.encoding_desc =3D NULL; + info.topic =3D NULL; + info.pmu_name =3D pmu->name; + info.deprecated =3D false; + ret =3D cb(state, &info); + if (ret) + return ret; + } + return 0; +} + +bool perf_pmu__is_tool(const struct perf_pmu *pmu) +{ + return pmu && pmu->type =3D=3D PERF_PMU_TYPE_TOOL; +} + +bool evsel__is_tool(const struct evsel *evsel) +{ + return perf_pmu__is_tool(evsel->pmu); +} + +enum perf_tool_event evsel__tool_event(const struct evsel *evsel) +{ + if (!evsel__is_tool(evsel)) + return PERF_TOOL_NONE; + + return (enum perf_tool_event)evsel->core.attr.config; +} + +const char *evsel__tool_pmu_event_name(const struct evsel *evsel) +{ + return perf_tool_event__to_str(evsel->core.attr.config); +} + +static bool read_until_char(struct io *io, char e) +{ + int c; + + do { + c =3D io__get_char(io); + if (c =3D=3D -1) + return false; + } while (c !=3D e); + return true; +} + +static int read_stat_field(int fd, struct perf_cpu cpu, int field, __u64 *= val) +{ + char buf[256]; + struct io io; + int i; + + io__init(&io, fd, buf, sizeof(buf)); + + /* Skip lines to relevant CPU. */ + for (i =3D -1; i < cpu.cpu; i++) { + if (!read_until_char(&io, '\n')) + return -EINVAL; + } + /* Skip to "cpu". */ + if (io__get_char(&io) !=3D 'c') return -EINVAL; + if (io__get_char(&io) !=3D 'p') return -EINVAL; + if (io__get_char(&io) !=3D 'u') return -EINVAL; + + /* Skip N of cpuN. */ + if (!read_until_char(&io, ' ')) + return -EINVAL; + + i =3D 1; + while (true) { + if (io__get_dec(&io, val) !=3D ' ') + break; + if (field =3D=3D i) + return 0; + i++; + } + return -EINVAL; +} + +static int read_pid_stat_field(int fd, int field, __u64 *val) +{ + char buf[256]; + struct io io; + int c, i; + + io__init(&io, fd, buf, sizeof(buf)); + if (io__get_dec(&io, val) !=3D ' ') + return -EINVAL; + if (field =3D=3D 1) + return 0; + + /* Skip comm. */ + if (io__get_char(&io) !=3D '(' || !read_until_char(&io, ')')) + return -EINVAL; + if (field =3D=3D 2) + return -EINVAL; /* String can't be returned. */ + + /* Skip state */ + if (io__get_char(&io) !=3D ' ' || io__get_char(&io) =3D=3D -1) + return -EINVAL; + if (field =3D=3D 3) + return -EINVAL; /* String can't be returned. */ + + /* Loop over numeric fields*/ + if (io__get_char(&io) !=3D ' ') + return -EINVAL; + + i =3D 4; + while (true) { + c =3D io__get_dec(&io, val); + if (c =3D=3D -1) + return -EINVAL; + if (c =3D=3D -2) { + /* Assume a -ve was read */ + c =3D io__get_dec(&io, val); + *val *=3D -1; + } + if (c !=3D ' ') + return -EINVAL; + if (field =3D=3D i) + return 0; + i++; + } + return -EINVAL; +} + + + +int evsel__tool_pmu_prepare_open(struct evsel *evsel, + struct perf_cpu_map *cpus, + int nthreads) +{ + if ((evsel__tool_event(evsel) =3D=3D PERF_TOOL_SYSTEM_TIME || + evsel__tool_event(evsel) =3D=3D PERF_TOOL_USER_TIME) && + !evsel->start_times) { + evsel->start_times =3D xyarray__new(perf_cpu_map__nr(cpus), + nthreads, + sizeof(__u64)); + if (!evsel->start_times) + return -ENOMEM; + } + return 0; +} + +#define FD(e, x, y) (*(int *)xyarray__entry(e->core.fd, x, y)) + +int evsel__tool_pmu_open(struct evsel *evsel, + struct perf_thread_map *threads, + int start_cpu_map_idx, int end_cpu_map_idx) +{ + enum perf_tool_event ev =3D evsel__tool_event(evsel); + int pid =3D -1, idx =3D 0, thread =3D 0, nthreads, err =3D 0, old_errno; + + if (ev =3D=3D PERF_TOOL_DURATION_TIME) { + if (evsel->core.attr.sample_period) /* no sampling */ + return -EINVAL; + evsel->start_time =3D rdclock(); + return 0; + } + + if (evsel->cgrp) + pid =3D evsel->cgrp->fd; + + nthreads =3D perf_thread_map__nr(threads); + for (idx =3D start_cpu_map_idx; idx < end_cpu_map_idx; idx++) { + for (thread =3D 0; thread < nthreads; thread++) { + if (thread >=3D nthreads) + break; + + if (!evsel->cgrp && !evsel->core.system_wide) + pid =3D perf_thread_map__pid(threads, thread); + + if (ev =3D=3D PERF_TOOL_USER_TIME || ev =3D=3D PERF_TOOL_SYSTEM_TIME) { + bool system =3D ev =3D=3D PERF_TOOL_SYSTEM_TIME; + __u64 *start_time =3D NULL; + int fd; + + if (evsel->core.attr.sample_period) { + /* no sampling */ + err =3D -EINVAL; + goto out_close; + } + if (pid > -1) { + char buf[64]; + + snprintf(buf, sizeof(buf), "/proc/%d/stat", pid); + fd =3D open(buf, O_RDONLY); + evsel->pid_stat =3D true; + } else { + fd =3D open("/proc/stat", O_RDONLY); + } + FD(evsel, idx, thread) =3D fd; + if (fd < 0) { + err =3D -errno; + goto out_close; + } + start_time =3D xyarray__entry(evsel->start_times, idx, thread); + if (pid > -1) { + err =3D read_pid_stat_field(fd, system ? 15 : 14, + start_time); + } else { + struct perf_cpu cpu; + + cpu =3D perf_cpu_map__cpu(evsel->core.cpus, idx); + err =3D read_stat_field(fd, cpu, system ? 3 : 1, + start_time); + } + if (err) + goto out_close; + } + + } + } + return 0; +out_close: + if (err) + threads->err_thread =3D thread; + + old_errno =3D errno; + do { + while (--thread >=3D 0) { + if (FD(evsel, idx, thread) >=3D 0) + close(FD(evsel, idx, thread)); + FD(evsel, idx, thread) =3D -1; + } + thread =3D nthreads; + } while (--idx >=3D 0); + errno =3D old_errno; + return err; +} + +int evsel__read_tool(struct evsel *evsel, int cpu_map_idx, int thread) +{ + __u64 *start_time, cur_time, delta_start; + int fd, err =3D 0; + struct perf_counts_values *count; + bool adjust =3D false; + + count =3D perf_counts(evsel->counts, cpu_map_idx, thread); + + switch (evsel__tool_event(evsel)) { + case PERF_TOOL_DURATION_TIME: + /* + * Pretend duration_time is only on the first CPU and thread, or + * else aggregation will scale duration_time by the number of + * CPUs/threads. + */ + start_time =3D &evsel->start_time; + if (cpu_map_idx =3D=3D 0 && thread =3D=3D 0) + cur_time =3D rdclock(); + else + cur_time =3D *start_time; + break; + case PERF_TOOL_USER_TIME: + case PERF_TOOL_SYSTEM_TIME: { + bool system =3D evsel__tool_event(evsel) =3D=3D PERF_TOOL_SYSTEM_TIME; + + start_time =3D xyarray__entry(evsel->start_times, cpu_map_idx, thread); + fd =3D FD(evsel, cpu_map_idx, thread); + lseek(fd, SEEK_SET, 0); + if (evsel->pid_stat) { + /* The event exists solely on 1 CPU. */ + if (cpu_map_idx =3D=3D 0) + err =3D read_pid_stat_field(fd, system ? 15 : 14, &cur_time); + else + cur_time =3D 0; + } else { + /* The event is for all threads. */ + if (thread =3D=3D 0) { + struct perf_cpu cpu =3D perf_cpu_map__cpu(evsel->core.cpus, + cpu_map_idx); + + err =3D read_stat_field(fd, cpu, system ? 3 : 1, &cur_time); + } else { + cur_time =3D 0; + } + } + adjust =3D true; + break; + } + case PERF_TOOL_NONE: + case PERF_TOOL_MAX: + default: + err =3D -EINVAL; + } + if (err) + return err; + + delta_start =3D cur_time - *start_time; + if (adjust) { + __u64 ticks_per_sec =3D sysconf(_SC_CLK_TCK); + + delta_start *=3D 1000000000 / ticks_per_sec; + } + count->val =3D delta_start; + count->ena =3D count->run =3D delta_start; + count->lost =3D 0; + return 0; +} + +struct perf_pmu *perf_pmus__tool_pmu(void) +{ + static struct perf_pmu tool =3D { + .name =3D "tool", + .type =3D PERF_PMU_TYPE_TOOL, + .aliases =3D LIST_HEAD_INIT(tool.aliases), + .caps =3D LIST_HEAD_INIT(tool.caps), + .format =3D LIST_HEAD_INIT(tool.format), + }; + + return &tool; +} diff --git a/tools/perf/util/tool_pmu.h b/tools/perf/util/tool_pmu.h new file mode 100644 index 000000000000..05a4052c8b9d --- /dev/null +++ b/tools/perf/util/tool_pmu.h @@ -0,0 +1,51 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __TOOL_PMU_H +#define __TOOL_PMU_H + +#include "pmu.h" + +struct evsel; +struct perf_thread_map; +struct print_callbacks; + +enum perf_tool_event { + PERF_TOOL_NONE =3D 0, + PERF_TOOL_DURATION_TIME =3D 1, + PERF_TOOL_USER_TIME =3D 2, + PERF_TOOL_SYSTEM_TIME =3D 3, + + PERF_TOOL_MAX, +}; + +#define perf_tool_event__for_each_event(ev) \ + for ((ev) =3D PERF_TOOL_DURATION_TIME; (ev) < PERF_TOOL_MAX; ev++) + +static inline size_t tool_pmu__num_events(void) +{ + return PERF_TOOL_MAX - 1; +} + +const char *perf_tool_event__to_str(enum perf_tool_event ev); +enum perf_tool_event perf_tool_event__from_str(const char *str); +int tool_pmu__config_terms(struct perf_event_attr *attr, + struct parse_events_terms *terms, + struct parse_events_error *err); +int tool_pmu__for_each_event_cb(struct perf_pmu *pmu, void *state, pmu_eve= nt_callback cb); + +bool perf_pmu__is_tool(const struct perf_pmu *pmu); + + +bool evsel__is_tool(const struct evsel *evsel); +enum perf_tool_event evsel__tool_event(const struct evsel *evsel); +const char *evsel__tool_pmu_event_name(const struct evsel *evsel); +int evsel__tool_pmu_prepare_open(struct evsel *evsel, + struct perf_cpu_map *cpus, + int nthreads); +int evsel__tool_pmu_open(struct evsel *evsel, + struct perf_thread_map *threads, + int start_cpu_map_idx, int end_cpu_map_idx); +int evsel__read_tool(struct evsel *evsel, int cpu_map_idx, int thread); + +struct perf_pmu *perf_pmus__tool_pmu(void); + +#endif /* __TOOL_PMU_H */ --=20 2.46.0.662.g92d0881bb0-goog From nobody Sat Nov 30 02:52:27 2024 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.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 20A771C1AC7 for ; Thu, 12 Sep 2024 19:04:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726167843; cv=none; b=o8R4pS0JJv5ICWwFn4aE/rck3+IdVUnhLYxIuhzhMN/doNObvDeNenUBKI9HaEX/Lt+YfFugiEU1qmWk1WaFci2Dz1L682n3ZKP6NPQRcHJFIWgqCMD0pidJUK0TcJpn6eGRPsWnS67gsR7GisCy9btxisbd/qJUF0QFgaNlcNg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726167843; c=relaxed/simple; bh=9FWIieCrSHJSKwCFDqEEhz9udJYjo0ugqaVRuO1/AxY=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=JVCYKU4FobHGp7QRhH+LBhgyRt/hP74T3/OQl5Q2pcV8K+1QppK4R/+mw4p/3DYcY6jdYEziAhyS+lTkyAHm2dSYEE9fioo7/Hfff352CakDB84QjEkqXDoI3anSpbiE5SAp71RSvvUuO3eWji7CW8nEv+c6HWnoT3SA2huf3ys= 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=mjxIkPe0; arc=none smtp.client-ip=209.85.128.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="mjxIkPe0" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6d3aa5a672dso27721317b3.2 for ; Thu, 12 Sep 2024 12:04:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1726167841; x=1726772641; 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=RIe6eWIujUXnJEIE2MN3RNTRUcp19WY30IesPPBI6A8=; b=mjxIkPe017261j0ypGfJQPXF3hD0grU2AS95FmhcGjlYWxanuNDqXwuGIhx0imvTmJ zY52K7ew9Jy1Xwp6g7/0XJKcFzmy36brPxLdPWXqKUeFKZ0ydGAFgz3SOYs0YEgTwliq BZTUbViWGPuZbNGdBDslK+GQtA5khFbLvpJdnMT6JETfjAhNlWTFne4vH/0HlIjb8UXO heZEAv3iAOUbcBUVsfhJCQ7864k9LQoSZB+BEk/G2MutUK1UHVam1NbQZYSJKJe2kuII Jt2njti/l8GIkpjeaut05vqoB7lZElsl3UREAbOq2qv285+bOvH/dGrsimtsZL/GKeyx m+tQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726167841; x=1726772641; 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=RIe6eWIujUXnJEIE2MN3RNTRUcp19WY30IesPPBI6A8=; b=d5pX+dDeHgm1O5U9q5vw1CYj74Dh7/GjO2eS6z9wAl2AHPjia/MZP6fuB2StdzGK3g 3CTY3tDfewAG4oQFRuOAmlh6hIreQZ8lVNxnGMVa4gfjNZ+pZiFkBATImr+GeoWPeUtU KZ2h15S3CDA9M3Ev526mHJE+EgTUV0LdfV97j4SDAVV7T+JsqOvr7LN3GjNvIj3JAFjU 2oYE68Vp6SxrHHCA9GN+KawPCODeOiBPO6RliH/EykEBcAe0Qe67UUwONLeBcEDuQh7B 6CyHK/tIwQ3DnJ6dR50W9Vr9MEJc2lmpoPVAnGxgBYNaS/Atw1QVkElZ6YTraIByX47n EdGQ== X-Forwarded-Encrypted: i=1; AJvYcCXbo73waHtDgSuVTmPqYbcyH4QVdaRrDDcmK5tXpgl3eSxomKCdhvPuEv37h1HUkP7LHeeevlkVXtv0HZk=@vger.kernel.org X-Gm-Message-State: AOJu0YzA5RG/oJDrn8icWHh+GK/W++yhJ/HiwoufqTeG9C/J+TDam60m QNQRZBVoCncYy1LNCcaTYyL00NRUbJXk7EnoaowxVeVi3PF192XJc2NIrcuiHeiw9L5r9iwD2VZ jM5CZ/w== X-Google-Smtp-Source: AGHT+IEcXEOeMXGZFMtZnVJqscVGYLWWEnWwHykwGNk7dkqC1vb2k16m1zqYAsupxYdxB4UrmSPK4RIQLIDT X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:cf0e:7a99:e672:3862]) (user=irogers job=sendgmr) by 2002:a81:b2c6:0:b0:6d6:cacb:c6d5 with SMTP id 00721157ae682-6dbb6bb8ec2mr1072857b3.8.1726167841113; Thu, 12 Sep 2024 12:04:01 -0700 (PDT) Date: Thu, 12 Sep 2024 12:03:32 -0700 In-Reply-To: <20240912190341.919229-1-irogers@google.com> Message-Id: <20240912190341.919229-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: <20240912190341.919229-1-irogers@google.com> X-Mailer: git-send-email 2.46.0.662.g92d0881bb0-goog Subject: [PATCH v2 05/13] perf tool_pmu: Rename enum perf_tool_event to tool_pmu_event 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 , John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Ravi Bangoria , Weilin Wang , Jing Zhang , Xu Yang , Sandipan Das , Benjamin Gray , Athira Jajeev , Howard Chu , Dominique Martinet , Yang Jihong , Colin Ian King , Veronika Molnarova , "Dr. David Alan Gilbert" , Oliver Upton , Changbin Du , Ze Gao , Andi Kleen , "=?UTF-8?q?Cl=C3=A9ment=20Le=20Goffic?=" , Sun Haiyong , Junhao He , Tiezhu Yang , Yicong Yang , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-arm-kernel@lists.infradead.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" To better reflect the events listed are from the tool PMU. Rename the enum values from PERF_TOOL_* to TOOL_PMU__EVENT_*. Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- tools/perf/builtin-stat.c | 6 ++--- tools/perf/util/evsel.c | 4 ++-- tools/perf/util/metricgroup.c | 12 +++++----- tools/perf/util/pmu.c | 2 +- tools/perf/util/stat-shadow.c | 10 ++++---- tools/perf/util/tool_pmu.c | 44 +++++++++++++++++------------------ tools/perf/util/tool_pmu.h | 22 +++++++++--------- 7 files changed, 50 insertions(+), 50 deletions(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index ae525fdcfbde..a6b4d1b98b3a 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -295,14 +295,14 @@ static int read_single_counter(struct evsel *counter,= int cpu_map_idx, int threa * terminates. Use the wait4 values in that case. */ if (err && cpu_map_idx =3D=3D 0 && - (evsel__tool_event(counter) =3D=3D PERF_TOOL_USER_TIME || - evsel__tool_event(counter) =3D=3D PERF_TOOL_SYSTEM_TIME)) { + (evsel__tool_event(counter) =3D=3D TOOL_PMU__EVENT_USER_TIME || + evsel__tool_event(counter) =3D=3D TOOL_PMU__EVENT_SYSTEM_TIME)) { u64 val, *start_time; struct perf_counts_values *count =3D perf_counts(counter->counts, cpu_map_idx, thread); =20 start_time =3D xyarray__entry(counter->start_times, cpu_map_idx, thread); - if (evsel__tool_event(counter) =3D=3D PERF_TOOL_USER_TIME) + if (evsel__tool_event(counter) =3D=3D TOOL_PMU__EVENT_USER_TIME) val =3D ru_stats.ru_utime_usec_stat.mean; else val =3D ru_stats.ru_stime_usec_stat.mean; diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index b75c4a4c7aa7..c0b49c5dd3cf 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -1471,8 +1471,8 @@ void evsel__exit(struct evsel *evsel) evsel->per_pkg_mask =3D NULL; zfree(&evsel->metric_events); perf_evsel__object.fini(evsel); - if (evsel__tool_event(evsel) =3D=3D PERF_TOOL_SYSTEM_TIME || - evsel__tool_event(evsel) =3D=3D PERF_TOOL_USER_TIME) + if (evsel__tool_event(evsel) =3D=3D TOOL_PMU__EVENT_SYSTEM_TIME || + evsel__tool_event(evsel) =3D=3D TOOL_PMU__EVENT_USER_TIME) xyarray__delete(evsel->start_times); } =20 diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index 9181548e8881..0e21e2f9c170 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -674,20 +674,20 @@ static int metricgroup__build_event_string(struct str= buf *events, struct hashmap_entry *cur; size_t bkt; bool no_group =3D true, has_tool_events =3D false; - bool tool_events[PERF_TOOL_MAX] =3D {false}; + bool tool_events[TOOL_PMU__EVENT_MAX] =3D {false}; int ret =3D 0; =20 #define RETURN_IF_NON_ZERO(x) do { if (x) return x; } while (0) =20 hashmap__for_each_entry(ctx->ids, cur, bkt) { const char *sep, *rsep, *id =3D cur->pkey; - enum perf_tool_event ev; + enum tool_pmu_event ev; =20 pr_debug("found event %s\n", id); =20 /* Always move tool events outside of the group. */ ev =3D perf_tool_event__from_str(id); - if (ev !=3D PERF_TOOL_NONE) { + if (ev !=3D TOOL_PMU__EVENT_NONE) { has_tool_events =3D true; tool_events[ev] =3D true; continue; @@ -1375,7 +1375,7 @@ static void metricgroup__free_metrics(struct list_hea= d *metric_list) * to true if tool event is found. */ static void find_tool_events(const struct list_head *metric_list, - bool tool_events[PERF_TOOL_MAX]) + bool tool_events[TOOL_PMU__EVENT_MAX]) { struct metric *m; =20 @@ -1447,7 +1447,7 @@ static int build_combined_expr_ctx(const struct list_= head *metric_list, */ static int parse_ids(bool metric_no_merge, bool fake_pmu, struct expr_parse_ctx *ids, const char *modifier, - bool group_events, const bool tool_events[PERF_TOOL_MAX], + bool group_events, const bool tool_events[TOOL_PMU__EVENT_MAX], struct evlist **out_evlist) { struct parse_events_error parse_error; @@ -1536,7 +1536,7 @@ static int parse_groups(struct evlist *perf_evlist, struct evlist *combined_evlist =3D NULL; LIST_HEAD(metric_list); struct metric *m; - bool tool_events[PERF_TOOL_MAX] =3D {false}; + bool tool_events[TOOL_PMU__EVENT_MAX] =3D {false}; bool is_default =3D !strcmp(str, "Default"); int ret; =20 diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index f17e21455498..fadb705fd9a7 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -1832,7 +1832,7 @@ bool perf_pmu__have_event(struct perf_pmu *pmu, const= char *name) if (!name) return false; if (perf_pmu__is_tool(pmu)) - return perf_tool_event__from_str(name) !=3D PERF_TOOL_NONE; + return perf_tool_event__from_str(name) !=3D TOOL_PMU__EVENT_NONE; if (perf_pmu__find_alias(pmu, name, /*load=3D*/ true) !=3D NULL) return true; if (pmu->cpu_aliases_added || !pmu->events_table) diff --git a/tools/perf/util/stat-shadow.c b/tools/perf/util/stat-shadow.c index 2d653f91400e..e56969d1e39d 100644 --- a/tools/perf/util/stat-shadow.c +++ b/tools/perf/util/stat-shadow.c @@ -382,22 +382,22 @@ static int prepare_metric(const struct metric_expr *m= exp, double scale; =20 switch (evsel__tool_event(metric_events[i])) { - case PERF_TOOL_DURATION_TIME: + case TOOL_PMU__EVENT_DURATION_TIME: stats =3D &walltime_nsecs_stats; scale =3D 1e-9; break; - case PERF_TOOL_USER_TIME: + case TOOL_PMU__EVENT_USER_TIME: stats =3D &ru_stats.ru_utime_usec_stat; scale =3D 1e-6; break; - case PERF_TOOL_SYSTEM_TIME: + case TOOL_PMU__EVENT_SYSTEM_TIME: stats =3D &ru_stats.ru_stime_usec_stat; scale =3D 1e-6; break; - case PERF_TOOL_NONE: + case TOOL_PMU__EVENT_NONE: pr_err("Invalid tool event 'none'"); abort(); - case PERF_TOOL_MAX: + case TOOL_PMU__EVENT_MAX: pr_err("Invalid tool event 'max'"); abort(); default: diff --git a/tools/perf/util/tool_pmu.c b/tools/perf/util/tool_pmu.c index 702c1131a2a8..7ef559532f5b 100644 --- a/tools/perf/util/tool_pmu.c +++ b/tools/perf/util/tool_pmu.c @@ -12,7 +12,7 @@ #include #include =20 -static const char *const tool_pmu__event_names[PERF_TOOL_MAX] =3D { +static const char *const tool_pmu__event_names[TOOL_PMU__EVENT_MAX] =3D { NULL, "duration_time", "user_time", @@ -20,15 +20,15 @@ static const char *const tool_pmu__event_names[PERF_TOO= L_MAX] =3D { }; =20 =20 -const char *perf_tool_event__to_str(enum perf_tool_event ev) +const char *perf_tool_event__to_str(enum tool_pmu_event ev) { - if (ev > PERF_TOOL_NONE && ev < PERF_TOOL_MAX) + if (ev > TOOL_PMU__EVENT_NONE && ev < TOOL_PMU__EVENT_MAX) return tool_pmu__event_names[ev]; =20 return NULL; } =20 -enum perf_tool_event perf_tool_event__from_str(const char *str) +enum tool_pmu_event perf_tool_event__from_str(const char *str) { int i; =20 @@ -36,7 +36,7 @@ enum perf_tool_event perf_tool_event__from_str(const char= *str) if (!strcasecmp(str, tool_pmu__event_names[i])) return i; } - return PERF_TOOL_NONE; + return TOOL_PMU__EVENT_NONE; } =20 static int tool_pmu__config_term(struct perf_event_attr *attr, @@ -44,9 +44,9 @@ static int tool_pmu__config_term(struct perf_event_attr *= attr, struct parse_events_error *err) { if (term->type_term =3D=3D PARSE_EVENTS__TERM_TYPE_USER) { - enum perf_tool_event ev =3D perf_tool_event__from_str(term->config); + enum tool_pmu_event ev =3D perf_tool_event__from_str(term->config); =20 - if (ev =3D=3D PERF_TOOL_NONE) + if (ev =3D=3D TOOL_PMU__EVENT_NONE) goto err_out; =20 attr->config =3D ev; @@ -120,12 +120,12 @@ bool evsel__is_tool(const struct evsel *evsel) return perf_pmu__is_tool(evsel->pmu); } =20 -enum perf_tool_event evsel__tool_event(const struct evsel *evsel) +enum tool_pmu_event evsel__tool_event(const struct evsel *evsel) { if (!evsel__is_tool(evsel)) - return PERF_TOOL_NONE; + return TOOL_PMU__EVENT_NONE; =20 - return (enum perf_tool_event)evsel->core.attr.config; + return (enum tool_pmu_event)evsel->core.attr.config; } =20 const char *evsel__tool_pmu_event_name(const struct evsel *evsel) @@ -231,8 +231,8 @@ int evsel__tool_pmu_prepare_open(struct evsel *evsel, struct perf_cpu_map *cpus, int nthreads) { - if ((evsel__tool_event(evsel) =3D=3D PERF_TOOL_SYSTEM_TIME || - evsel__tool_event(evsel) =3D=3D PERF_TOOL_USER_TIME) && + if ((evsel__tool_event(evsel) =3D=3D TOOL_PMU__EVENT_SYSTEM_TIME || + evsel__tool_event(evsel) =3D=3D TOOL_PMU__EVENT_USER_TIME) && !evsel->start_times) { evsel->start_times =3D xyarray__new(perf_cpu_map__nr(cpus), nthreads, @@ -249,10 +249,10 @@ int evsel__tool_pmu_open(struct evsel *evsel, struct perf_thread_map *threads, int start_cpu_map_idx, int end_cpu_map_idx) { - enum perf_tool_event ev =3D evsel__tool_event(evsel); + enum tool_pmu_event ev =3D evsel__tool_event(evsel); int pid =3D -1, idx =3D 0, thread =3D 0, nthreads, err =3D 0, old_errno; =20 - if (ev =3D=3D PERF_TOOL_DURATION_TIME) { + if (ev =3D=3D TOOL_PMU__EVENT_DURATION_TIME) { if (evsel->core.attr.sample_period) /* no sampling */ return -EINVAL; evsel->start_time =3D rdclock(); @@ -271,8 +271,8 @@ int evsel__tool_pmu_open(struct evsel *evsel, if (!evsel->cgrp && !evsel->core.system_wide) pid =3D perf_thread_map__pid(threads, thread); =20 - if (ev =3D=3D PERF_TOOL_USER_TIME || ev =3D=3D PERF_TOOL_SYSTEM_TIME) { - bool system =3D ev =3D=3D PERF_TOOL_SYSTEM_TIME; + if (ev =3D=3D TOOL_PMU__EVENT_USER_TIME || ev =3D=3D TOOL_PMU__EVENT_SY= STEM_TIME) { + bool system =3D ev =3D=3D TOOL_PMU__EVENT_SYSTEM_TIME; __u64 *start_time =3D NULL; int fd; =20 @@ -340,7 +340,7 @@ int evsel__read_tool(struct evsel *evsel, int cpu_map_i= dx, int thread) count =3D perf_counts(evsel->counts, cpu_map_idx, thread); =20 switch (evsel__tool_event(evsel)) { - case PERF_TOOL_DURATION_TIME: + case TOOL_PMU__EVENT_DURATION_TIME: /* * Pretend duration_time is only on the first CPU and thread, or * else aggregation will scale duration_time by the number of @@ -352,9 +352,9 @@ int evsel__read_tool(struct evsel *evsel, int cpu_map_i= dx, int thread) else cur_time =3D *start_time; break; - case PERF_TOOL_USER_TIME: - case PERF_TOOL_SYSTEM_TIME: { - bool system =3D evsel__tool_event(evsel) =3D=3D PERF_TOOL_SYSTEM_TIME; + case TOOL_PMU__EVENT_USER_TIME: + case TOOL_PMU__EVENT_SYSTEM_TIME: { + bool system =3D evsel__tool_event(evsel) =3D=3D TOOL_PMU__EVENT_SYSTEM_T= IME; =20 start_time =3D xyarray__entry(evsel->start_times, cpu_map_idx, thread); fd =3D FD(evsel, cpu_map_idx, thread); @@ -379,8 +379,8 @@ int evsel__read_tool(struct evsel *evsel, int cpu_map_i= dx, int thread) adjust =3D true; break; } - case PERF_TOOL_NONE: - case PERF_TOOL_MAX: + case TOOL_PMU__EVENT_NONE: + case TOOL_PMU__EVENT_MAX: default: err =3D -EINVAL; } diff --git a/tools/perf/util/tool_pmu.h b/tools/perf/util/tool_pmu.h index 05a4052c8b9d..b27a26133927 100644 --- a/tools/perf/util/tool_pmu.h +++ b/tools/perf/util/tool_pmu.h @@ -8,25 +8,25 @@ struct evsel; struct perf_thread_map; struct print_callbacks; =20 -enum perf_tool_event { - PERF_TOOL_NONE =3D 0, - PERF_TOOL_DURATION_TIME =3D 1, - PERF_TOOL_USER_TIME =3D 2, - PERF_TOOL_SYSTEM_TIME =3D 3, +enum tool_pmu_event { + TOOL_PMU__EVENT_NONE =3D 0, + TOOL_PMU__EVENT_DURATION_TIME =3D 1, + TOOL_PMU__EVENT_USER_TIME =3D 2, + TOOL_PMU__EVENT_SYSTEM_TIME =3D 3, =20 - PERF_TOOL_MAX, + TOOL_PMU__EVENT_MAX, }; =20 #define perf_tool_event__for_each_event(ev) \ - for ((ev) =3D PERF_TOOL_DURATION_TIME; (ev) < PERF_TOOL_MAX; ev++) + for ((ev) =3D TOOL_PMU__EVENT_DURATION_TIME; (ev) < TOOL_PMU__EVENT_MAX; = ev++) =20 static inline size_t tool_pmu__num_events(void) { - return PERF_TOOL_MAX - 1; + return TOOL_PMU__EVENT_MAX - 1; } =20 -const char *perf_tool_event__to_str(enum perf_tool_event ev); -enum perf_tool_event perf_tool_event__from_str(const char *str); +const char *perf_tool_event__to_str(enum tool_pmu_event ev); +enum tool_pmu_event perf_tool_event__from_str(const char *str); int tool_pmu__config_terms(struct perf_event_attr *attr, struct parse_events_terms *terms, struct parse_events_error *err); @@ -36,7 +36,7 @@ bool perf_pmu__is_tool(const struct perf_pmu *pmu); =20 =20 bool evsel__is_tool(const struct evsel *evsel); -enum perf_tool_event evsel__tool_event(const struct evsel *evsel); +enum tool_pmu_event evsel__tool_event(const struct evsel *evsel); const char *evsel__tool_pmu_event_name(const struct evsel *evsel); int evsel__tool_pmu_prepare_open(struct evsel *evsel, struct perf_cpu_map *cpus, --=20 2.46.0.662.g92d0881bb0-goog From nobody Sat Nov 30 02:52:27 2024 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 8EF2B1BFE02 for ; Thu, 12 Sep 2024 19:04:04 +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=1726167846; cv=none; b=Ocpt6IKu3a9vUYeR+h9r5XgUec+JHuDx4nA+yHl5IIUIFADpYgicFjP7Wuwi1gQZ1qr5id+rCEZFYQvo06j4GoeCPFWJtLVpOpkCPX6a8UEiIHrZT2HuDl1jurybCR1GQ+SGUNH+EeQXrW+cJa7G2hjU03NeX4TjeQN2CMjvx/w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726167846; c=relaxed/simple; bh=uQ4KFUwL/NCeIgiOA9uomLhotkcV7/jm55QdrlRYrLM=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=F4XDnkKbNd5iLvj/g3mHnifwXgLCYGfHo3QscduqbVHa6tIKmM4DM31MbaFqfBeKbZGeSMwk9DXHsNbnz9Er3W7sds1S6BqmGBJYYGNaxBCHq2ZyQIX6xhHv5VXVslM+tSVD/JR+4SNU5EfYtOO7LUTDPyis8pZiCDLKGWVsiaA= 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=xkk7hyVx; 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="xkk7hyVx" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e17bb508bb9so515391276.2 for ; Thu, 12 Sep 2024 12:04:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1726167843; x=1726772643; 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=HR/8SRR0M3K67/iTjnIUMjJYRP6I/W64CEGjcVbEDQc=; b=xkk7hyVxSNdMn7HNmUL2aStXT8nTlYf3xyTlfYQ+LkZVin4GUnj5lJlWUcccR8qV9E tWaNqX7+PDGfyzNzQj53L656qI26GWhUenH9tUW88v47yu4o5gXwpjRQM/WWqIuL3vFP VQ95YB1JVsTG4cdNRAu4BraNS2e2fk0tAQYrOGgRCTpUOBxKGYuw/xxA2ud7MAQKzy89 azZLQG40LmeQ9lflEFQCU8fNUNdP3agDZu+bwaK/s7B9zmJkCPzBvF4/tshbukgKeyb3 z4RhfnpKsjYyz7AHFjMPBbau6AulkWk2eEpLfYJdOzm7xaaz+Nccgn9rWS6xqZPcbvtt fjbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726167843; x=1726772643; 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=HR/8SRR0M3K67/iTjnIUMjJYRP6I/W64CEGjcVbEDQc=; b=v1SZhVQy5oBkLvX+8i7KYjv2XMucZY1kn2bRWP01MMAE8BkQoDFvWtZq7bpiafgJMl GSOV7dPKaBziV72YSaqCjpOiLlam88Zhh+ZRoyLS5Ri1+iQX/kqktCaBMTKrUDllzK+g feEI3wELvokoKyNFojKiMwkXv6hg9+uVohRHJ6XddIgEicE9nLT6Jw+X8yPbtGKNBoFF NO3sUAmL/bT307gtTb5N8YQAjOG82nkAbsgVQhdGo+bd6JrrJ60AaECjENp7CQU3LQaI /lDHW+XTtjZjbzLp8oxxmske6SMZrHRbxMdWRdcsWTVtf2+Bl8N6BK07I6/rTFuIl/R+ OOnA== X-Forwarded-Encrypted: i=1; AJvYcCXgElJ+k1sTdN5vYXkGbGJNEcIXuvEEfZZZo43Cj1edoLwbzqQmZDZrrMrnBKUid1cDFMVs/yxbriiFWXM=@vger.kernel.org X-Gm-Message-State: AOJu0YydSqDWdhKW/6Bovj5OZJE9kfR3CLFU9td92awf11W20sFbIATx AkMDVuUCgafAAh/35sCJDkxf63KvEWbViascp4KE8Ijvh5KtEswEIJGmsaeYV/hJcOXpp+iq+CU u91tn9A== X-Google-Smtp-Source: AGHT+IFGQ+QNtBNjpI8Pmkiek6z9XLomsRs6D3HxUgxM5twDVfucPdjntzoXypmzUrxiQ6g31+nV2nRrtQq2 X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:cf0e:7a99:e672:3862]) (user=irogers job=sendgmr) by 2002:a25:b18b:0:b0:e1a:aa41:5170 with SMTP id 3f1490d57ef6-e1db00f346emr447276.8.1726167843454; Thu, 12 Sep 2024 12:04:03 -0700 (PDT) Date: Thu, 12 Sep 2024 12:03:33 -0700 In-Reply-To: <20240912190341.919229-1-irogers@google.com> Message-Id: <20240912190341.919229-7-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240912190341.919229-1-irogers@google.com> X-Mailer: git-send-email 2.46.0.662.g92d0881bb0-goog Subject: [PATCH v2 06/13] perf tool_pmu: Rename perf_tool_event__* to tool_pmu__* 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 , John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Ravi Bangoria , Weilin Wang , Jing Zhang , Xu Yang , Sandipan Das , Benjamin Gray , Athira Jajeev , Howard Chu , Dominique Martinet , Yang Jihong , Colin Ian King , Veronika Molnarova , "Dr. David Alan Gilbert" , Oliver Upton , Changbin Du , Ze Gao , Andi Kleen , "=?UTF-8?q?Cl=C3=A9ment=20Le=20Goffic?=" , Sun Haiyong , Junhao He , Tiezhu Yang , Yicong Yang , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-arm-kernel@lists.infradead.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Now the events are associated with the tool PMU, rename the functions to reflect this. Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- tools/perf/util/evsel.c | 2 +- tools/perf/util/metricgroup.c | 22 +++++++++++----------- tools/perf/util/pmu.c | 4 ++-- tools/perf/util/tool_pmu.c | 16 ++++++++-------- tools/perf/util/tool_pmu.h | 8 ++++---- 5 files changed, 26 insertions(+), 26 deletions(-) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index c0b49c5dd3cf..9e748ed20988 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -1655,7 +1655,7 @@ static int evsel__read_group(struct evsel *leader, in= t cpu_map_idx, int thread) int evsel__read_counter(struct evsel *evsel, int cpu_map_idx, int thread) { if (evsel__is_tool(evsel)) - return evsel__read_tool(evsel, cpu_map_idx, thread); + return evsel__tool_pmu_read(evsel, cpu_map_idx, thread); =20 if (evsel__is_retire_lat(evsel)) return evsel__read_retire_lat(evsel, cpu_map_idx, thread); diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index 0e21e2f9c170..e5dd932e4d3f 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -686,7 +686,7 @@ static int metricgroup__build_event_string(struct strbu= f *events, pr_debug("found event %s\n", id); =20 /* Always move tool events outside of the group. */ - ev =3D perf_tool_event__from_str(id); + ev =3D tool_pmu__str_to_event(id); if (ev !=3D TOOL_PMU__EVENT_NONE) { has_tool_events =3D true; tool_events[ev] =3D true; @@ -755,14 +755,14 @@ static int metricgroup__build_event_string(struct str= buf *events, if (has_tool_events) { int i; =20 - perf_tool_event__for_each_event(i) { + tool_pmu__for_each_event(i) { if (tool_events[i]) { if (!no_group) { ret =3D strbuf_addch(events, ','); RETURN_IF_NON_ZERO(ret); } no_group =3D false; - ret =3D strbuf_addstr(events, perf_tool_event__to_str(i)); + ret =3D strbuf_addstr(events, tool_pmu__event_to_str(i)); RETURN_IF_NON_ZERO(ret); } } @@ -1148,14 +1148,14 @@ static int metric_list_cmp(void *priv __maybe_unuse= d, const struct list_head *l, int i, left_count, right_count; =20 left_count =3D hashmap__size(left->pctx->ids); - perf_tool_event__for_each_event(i) { - if (!expr__get_id(left->pctx, perf_tool_event__to_str(i), &data)) + tool_pmu__for_each_event(i) { + if (!expr__get_id(left->pctx, tool_pmu__event_to_str(i), &data)) left_count--; } =20 right_count =3D hashmap__size(right->pctx->ids); - perf_tool_event__for_each_event(i) { - if (!expr__get_id(right->pctx, perf_tool_event__to_str(i), &data)) + tool_pmu__for_each_event(i) { + if (!expr__get_id(right->pctx, tool_pmu__event_to_str(i), &data)) right_count--; } =20 @@ -1382,11 +1382,11 @@ static void find_tool_events(const struct list_head= *metric_list, list_for_each_entry(m, metric_list, nd) { int i; =20 - perf_tool_event__for_each_event(i) { + tool_pmu__for_each_event(i) { struct expr_id_data *data; =20 if (!tool_events[i] && - !expr__get_id(m->pctx, perf_tool_event__to_str(i), &data)) + !expr__get_id(m->pctx, tool_pmu__event_to_str(i), &data)) tool_events[i] =3D true; } } @@ -1472,9 +1472,9 @@ static int parse_ids(bool metric_no_merge, bool fake_= pmu, * event1 if #smt_on else 0 * Add a tool event to avoid a parse error on an empty string. */ - perf_tool_event__for_each_event(i) { + tool_pmu__for_each_event(i) { if (tool_events[i]) { - char *tmp =3D strdup(perf_tool_event__to_str(i)); + char *tmp =3D strdup(tool_pmu__event_to_str(i)); =20 if (!tmp) return -ENOMEM; diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index fadb705fd9a7..d6310fa1b8bd 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -1832,7 +1832,7 @@ bool perf_pmu__have_event(struct perf_pmu *pmu, const= char *name) if (!name) return false; if (perf_pmu__is_tool(pmu)) - return perf_tool_event__from_str(name) !=3D TOOL_PMU__EVENT_NONE; + return tool_pmu__str_to_event(name) !=3D TOOL_PMU__EVENT_NONE; if (perf_pmu__find_alias(pmu, name, /*load=3D*/ true) !=3D NULL) return true; if (pmu->cpu_aliases_added || !pmu->events_table) @@ -2327,7 +2327,7 @@ const char *perf_pmu__name_from_config(struct perf_pm= u *pmu, u64 config) return NULL; =20 if (perf_pmu__is_tool(pmu)) - return perf_tool_event__to_str(config); + return tool_pmu__event_to_str(config); =20 pmu_aliases_parse(pmu); pmu_add_cpu_aliases(pmu); diff --git a/tools/perf/util/tool_pmu.c b/tools/perf/util/tool_pmu.c index 7ef559532f5b..b8116c5c7250 100644 --- a/tools/perf/util/tool_pmu.c +++ b/tools/perf/util/tool_pmu.c @@ -20,7 +20,7 @@ static const char *const tool_pmu__event_names[TOOL_PMU__= EVENT_MAX] =3D { }; =20 =20 -const char *perf_tool_event__to_str(enum tool_pmu_event ev) +const char *tool_pmu__event_to_str(enum tool_pmu_event ev) { if (ev > TOOL_PMU__EVENT_NONE && ev < TOOL_PMU__EVENT_MAX) return tool_pmu__event_names[ev]; @@ -28,11 +28,11 @@ const char *perf_tool_event__to_str(enum tool_pmu_event= ev) return NULL; } =20 -enum tool_pmu_event perf_tool_event__from_str(const char *str) +enum tool_pmu_event tool_pmu__str_to_event(const char *str) { int i; =20 - perf_tool_event__for_each_event(i) { + tool_pmu__for_each_event(i) { if (!strcasecmp(str, tool_pmu__event_names[i])) return i; } @@ -44,7 +44,7 @@ static int tool_pmu__config_term(struct perf_event_attr *= attr, struct parse_events_error *err) { if (term->type_term =3D=3D PARSE_EVENTS__TERM_TYPE_USER) { - enum tool_pmu_event ev =3D perf_tool_event__from_str(term->config); + enum tool_pmu_event ev =3D tool_pmu__str_to_event(term->config); =20 if (ev =3D=3D TOOL_PMU__EVENT_NONE) goto err_out; @@ -91,10 +91,10 @@ int tool_pmu__for_each_event_cb(struct perf_pmu *pmu, v= oid *state, pmu_event_cal }; int i; =20 - perf_tool_event__for_each_event(i) { + tool_pmu__for_each_event(i) { int ret; =20 - info.name =3D perf_tool_event__to_str(i); + info.name =3D tool_pmu__event_to_str(i); info.alias =3D NULL; info.scale_unit =3D NULL; info.desc =3D NULL; @@ -130,7 +130,7 @@ enum tool_pmu_event evsel__tool_event(const struct evse= l *evsel) =20 const char *evsel__tool_pmu_event_name(const struct evsel *evsel) { - return perf_tool_event__to_str(evsel->core.attr.config); + return tool_pmu__event_to_str(evsel->core.attr.config); } =20 static bool read_until_char(struct io *io, char e) @@ -330,7 +330,7 @@ int evsel__tool_pmu_open(struct evsel *evsel, return err; } =20 -int evsel__read_tool(struct evsel *evsel, int cpu_map_idx, int thread) +int evsel__tool_pmu_read(struct evsel *evsel, int cpu_map_idx, int thread) { __u64 *start_time, cur_time, delta_start; int fd, err =3D 0; diff --git a/tools/perf/util/tool_pmu.h b/tools/perf/util/tool_pmu.h index b27a26133927..b156645206c4 100644 --- a/tools/perf/util/tool_pmu.h +++ b/tools/perf/util/tool_pmu.h @@ -17,7 +17,7 @@ enum tool_pmu_event { TOOL_PMU__EVENT_MAX, }; =20 -#define perf_tool_event__for_each_event(ev) \ +#define tool_pmu__for_each_event(ev) \ for ((ev) =3D TOOL_PMU__EVENT_DURATION_TIME; (ev) < TOOL_PMU__EVENT_MAX; = ev++) =20 static inline size_t tool_pmu__num_events(void) @@ -25,8 +25,8 @@ static inline size_t tool_pmu__num_events(void) return TOOL_PMU__EVENT_MAX - 1; } =20 -const char *perf_tool_event__to_str(enum tool_pmu_event ev); -enum tool_pmu_event perf_tool_event__from_str(const char *str); +const char *tool_pmu__event_to_str(enum tool_pmu_event ev); +enum tool_pmu_event tool_pmu__str_to_event(const char *str); int tool_pmu__config_terms(struct perf_event_attr *attr, struct parse_events_terms *terms, struct parse_events_error *err); @@ -44,7 +44,7 @@ int evsel__tool_pmu_prepare_open(struct evsel *evsel, int evsel__tool_pmu_open(struct evsel *evsel, struct perf_thread_map *threads, int start_cpu_map_idx, int end_cpu_map_idx); -int evsel__read_tool(struct evsel *evsel, int cpu_map_idx, int thread); +int evsel__tool_pmu_read(struct evsel *evsel, int cpu_map_idx, int thread); =20 struct perf_pmu *perf_pmus__tool_pmu(void); =20 --=20 2.46.0.662.g92d0881bb0-goog From nobody Sat Nov 30 02:52:27 2024 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.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 BE26D1C230F for ; Thu, 12 Sep 2024 19:04:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726167848; cv=none; b=TbIT8PQ2wkGVthHJGQuZWB6HezJZSByPFQXoIn2qTj5DT8g9KnFzPXzSATwX18KISofFzlVscoOF+TaaTB23tQjMMUX2WtF0wNIMTtPk2snoUq2sBgEOw0BtjIpPR1n6QNr7mVDU6LcUvy3d0eID09QNRaU7NgM9ePYxnxhAwgI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726167848; c=relaxed/simple; bh=TTIjCYxP53lHBDp2SF08jsCX5D/qc73CFDZaIm095c0=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=H87izZ3msUyUNdIZBA7Hq0oZPxWc8f6DAYn8rK7ZB7HRcy0HW0a43vnoipHpOAq9vf6M/6cykRMgVR5DCKw4q5xIsr4y0R4Q3IkfQjlEDHKbUaEDoBkM9RImKCF8PA6G+nhS5dfbvL+2+tmRqxLy4zwKMTf8JigyHdB05e8Tzao= 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=fi7HFSmT; arc=none smtp.client-ip=209.85.128.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="fi7HFSmT" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6d3e062dbeeso20864867b3.0 for ; Thu, 12 Sep 2024 12:04:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1726167846; x=1726772646; 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=6jIvOGb3G7M9uAjA6lvLhCc81s2AI2IMSCiiBY2eqtE=; b=fi7HFSmTKr8LuDk62bYTv5aLmMPIZdaxABmeVBHYLexh38vYXRrJACkZSFQery5X7W kZrQLKrzZZ0CeiJ2lYZ8GfQgUefBJmlzSO/9Dokyu2qNwEkktySbWkSQ12S0q05DL0bQ Hrj1Rj7H3XPi0IlgqgQdpzQ0u4wLYeaVI+iv56ULVMm115NtEX3hg9e4BVye5j3aTA2E ocvaLkYc58Mxjdd2o9MhliidSAUjQ8t00NQtbk/P+nGiVa6ZU92sEsbO3rKAvtXAjqpD f+AAeg/pBtOdn6ZEOq00nJvgMnh/mzWhIzDNavVi+PC7XEwmnshMTjUtTivf0PfEKZkR w+Cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726167846; x=1726772646; 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=6jIvOGb3G7M9uAjA6lvLhCc81s2AI2IMSCiiBY2eqtE=; b=hhBwjumL6mbQrOJi/woLqpAvIuQKOJ3lzwn0szbrvau8rfDI7jWjSh+Qg1EeghKNQZ Fs7bszM/jdwBWLY2NnxIDWGL7xN36wBaYtx/nsHNOzjJOGbCAPpzQ5L/2nQOM5EL99Lo LP3ki50BRPRsPGmrcmTUyG81EefoLGI97xkvUB2MK1n9zFrDjy10Iw3Q7tjgAmzAqHg0 UIHry0h0KRXvxqhGHc5b/gt5+NHmGeb4vVJYhuYHvf0zuoYIi2RnBP8mzXIsNy0Y8Hz7 ndgOQgS612h+zH/Y36CCHN+pcmk61TM5M2hxhn/7ZbEWO8BF9981EjXWyJBuC4x8C6e2 hiBg== X-Forwarded-Encrypted: i=1; AJvYcCWtad3QeZ88i3EPIxo6hJRP+ZLQL0k9gldgiBcVlxNd/m4HwL79vTbb3Kxp6xG37fNyUKZ/zNkqKliFVs4=@vger.kernel.org X-Gm-Message-State: AOJu0YycCNXWeBCWjXF3rDX6m6Y+QLun0DzDfiMC72951TKJh91dAxyk zsDnGlXvt1sukHHtwTcB9S+RiP+X6l5rCsCQ2Eka7miB8jd9Ad39KwFZQ0cnMNFn/IhahLqPtpM dZwCc9Q== X-Google-Smtp-Source: AGHT+IF7haVn28lDdEjpyTvp9F1KQfVVD/Td0eI6oNlSn0fEyOoqG3BkKHLDOsvbaLbXpHgiZ78n2sjns68N X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:cf0e:7a99:e672:3862]) (user=irogers job=sendgmr) by 2002:a81:a883:0:b0:6d3:e7e6:8462 with SMTP id 00721157ae682-6db952f5ee5mr2188327b3.1.1726167845806; Thu, 12 Sep 2024 12:04:05 -0700 (PDT) Date: Thu, 12 Sep 2024 12:03:34 -0700 In-Reply-To: <20240912190341.919229-1-irogers@google.com> Message-Id: <20240912190341.919229-8-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240912190341.919229-1-irogers@google.com> X-Mailer: git-send-email 2.46.0.662.g92d0881bb0-goog Subject: [PATCH v2 07/13] perf tool_pmu: Move expr literals to tool_pmu 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 , John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Ravi Bangoria , Weilin Wang , Jing Zhang , Xu Yang , Sandipan Das , Benjamin Gray , Athira Jajeev , Howard Chu , Dominique Martinet , Yang Jihong , Colin Ian King , Veronika Molnarova , "Dr. David Alan Gilbert" , Oliver Upton , Changbin Du , Ze Gao , Andi Kleen , "=?UTF-8?q?Cl=C3=A9ment=20Le=20Goffic?=" , Sun Haiyong , Junhao He , Tiezhu Yang , Yicong Yang , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-arm-kernel@lists.infradead.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add the expr literals like "#smt_on" as tool events, this allows stat events to give the values. On my laptop with hyperthreading enabled: ``` $ perf stat -e "has_pmem,num_cores,num_cpus,num_cpus_online,num_dies,num_pa= ckages,smt_on,system_tsc_freq" true Performance counter stats for 'true': 0 has_pmem 8 num_cores 16 num_cpus 16 num_cpus_online 1 num_dies 1 num_packages 1 smt_on 2,496,000,000 system_tsc_freq 0.001113637 seconds time elapsed 0.001218000 seconds user 0.000000000 seconds sys ``` And with hyperthreading disabled: ``` $ perf stat -e "has_pmem,num_cores,num_cpus,num_cpus_online,num_dies,num_pa= ckages,smt_on,system_tsc_freq" true Performance counter stats for 'true': 0 has_pmem 8 num_cores 16 num_cpus 8 num_cpus_online 1 num_dies 1 num_packages 0 smt_on 2,496,000,000 system_tsc_freq 0.000802115 seconds time elapsed 0.000000000 seconds user 0.000806000 seconds sys ``` As zero matters for these values, in stat-display should_skip_zero_counter only skip the zero value if it is not the first aggregation index. The tool event implementations are used in expr but not evaluated as events for simplicity. Also core_wide isn't made a tool event as it requires command line parameters. Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- tools/perf/arch/arm64/util/pmu.c | 5 +- tools/perf/arch/x86/util/tsc.c | 18 ++-- tools/perf/util/expr.c | 93 +++----------------- tools/perf/util/pmu.c | 5 -- tools/perf/util/pmu.h | 1 - tools/perf/util/stat-display.c | 8 +- tools/perf/util/stat-shadow.c | 11 ++- tools/perf/util/tool_pmu.c | 146 ++++++++++++++++++++++++++++++- tools/perf/util/tool_pmu.h | 19 +++- tools/perf/util/tsc.h | 2 +- 10 files changed, 201 insertions(+), 107 deletions(-) diff --git a/tools/perf/arch/arm64/util/pmu.c b/tools/perf/arch/arm64/util/= pmu.c index 2a4eab2d160e..a0964b191fcb 100644 --- a/tools/perf/arch/arm64/util/pmu.c +++ b/tools/perf/arch/arm64/util/pmu.c @@ -5,6 +5,7 @@ #include "../../../util/header.h" #include "../../../util/pmu.h" #include "../../../util/pmus.h" +#include "../../../util/tool_pmu.h" #include #include =20 @@ -24,7 +25,7 @@ const struct pmu_metrics_table *pmu_metrics_table__find(v= oid) return NULL; } =20 -double perf_pmu__cpu_slots_per_cycle(void) +u64 tool_pmu__cpu_slots_per_cycle(void) { char path[PATH_MAX]; unsigned long long slots =3D 0; @@ -41,5 +42,5 @@ double perf_pmu__cpu_slots_per_cycle(void) filename__read_ull(path, &slots); } =20 - return slots ? (double)slots : NAN; + return slots; } diff --git a/tools/perf/arch/x86/util/tsc.c b/tools/perf/arch/x86/util/tsc.c index e2d6cfe21057..3a439e4b12d2 100644 --- a/tools/perf/arch/x86/util/tsc.c +++ b/tools/perf/arch/x86/util/tsc.c @@ -24,9 +24,9 @@ u64 rdtsc(void) * ... * will return 3000000000. */ -static double cpuinfo_tsc_freq(void) +static u64 cpuinfo_tsc_freq(void) { - double result =3D 0; + u64 result =3D 0; FILE *cpuinfo; char *line =3D NULL; size_t len =3D 0; @@ -34,20 +34,22 @@ static double cpuinfo_tsc_freq(void) cpuinfo =3D fopen("/proc/cpuinfo", "r"); if (!cpuinfo) { pr_err("Failed to read /proc/cpuinfo for TSC frequency\n"); - return NAN; + return 0; } while (getline(&line, &len, cpuinfo) > 0) { if (!strncmp(line, "model name", 10)) { char *pos =3D strstr(line + 11, " @ "); + double float_result; =20 - if (pos && sscanf(pos, " @ %lfGHz", &result) =3D=3D 1) { - result *=3D 1000000000; + if (pos && sscanf(pos, " @ %lfGHz", &float_result) =3D=3D 1) { + float_result *=3D 1000000000; + result =3D (u64)float_result; goto out; } } } out: - if (fpclassify(result) =3D=3D FP_ZERO) + if (result =3D=3D 0) pr_err("Failed to find TSC frequency in /proc/cpuinfo\n"); =20 free(line); @@ -55,7 +57,7 @@ static double cpuinfo_tsc_freq(void) return result; } =20 -double arch_get_tsc_freq(void) +u64 arch_get_tsc_freq(void) { unsigned int a, b, c, d, lvl; static bool cached; @@ -86,6 +88,6 @@ double arch_get_tsc_freq(void) return tsc; } =20 - tsc =3D (double)c * (double)b / (double)a; + tsc =3D (u64)c * (u64)b / (u64)a; return tsc; } diff --git a/tools/perf/util/expr.c b/tools/perf/util/expr.c index b2536a59c44e..5e3732bc2fa5 100644 --- a/tools/perf/util/expr.c +++ b/tools/perf/util/expr.c @@ -5,25 +5,22 @@ #include #include #include "metricgroup.h" -#include "cpumap.h" -#include "cputopo.h" #include "debug.h" #include "evlist.h" #include "expr.h" +#include "pmu.h" +#include "smt.h" +#include "tool_pmu.h" #include #include #include "util/hashmap.h" #include "util/header.h" #include "util/pmu.h" -#include "smt.h" -#include "tsc.h" -#include #include #include #include #include #include -#include "pmu.h" =20 struct expr_id_data { union { @@ -393,90 +390,26 @@ double expr_id_data__source_count(const struct expr_i= d_data *data) return data->val.source_count; } =20 -#if !defined(__i386__) && !defined(__x86_64__) -double arch_get_tsc_freq(void) -{ - return 0.0; -} -#endif - -static double has_pmem(void) -{ - static bool has_pmem, cached; - const char *sysfs =3D sysfs__mountpoint(); - char path[PATH_MAX]; - - if (!cached) { - snprintf(path, sizeof(path), "%s/firmware/acpi/tables/NFIT", sysfs); - has_pmem =3D access(path, F_OK) =3D=3D 0; - cached =3D true; - } - return has_pmem ? 1.0 : 0.0; -} - double expr__get_literal(const char *literal, const struct expr_scanner_ct= x *ctx) { - const struct cpu_topology *topology; double result =3D NAN; + enum tool_pmu_event ev =3D tool_pmu__str_to_event(literal + 1); =20 - if (!strcmp("#num_cpus", literal)) { - result =3D cpu__max_present_cpu().cpu; - goto out; - } - if (!strcmp("#num_cpus_online", literal)) { - struct perf_cpu_map *online =3D cpu_map__online(); - - if (online) - result =3D perf_cpu_map__nr(online); - goto out; - } + if (ev !=3D TOOL_PMU__EVENT_NONE) { + u64 count; =20 - if (!strcasecmp("#system_tsc_freq", literal)) { - result =3D arch_get_tsc_freq(); - goto out; - } + if (tool_pmu__read_event(ev, &count)) + result =3D count; + else + pr_err("Failure to read '%s'", literal); =20 - /* - * Assume that topology strings are consistent, such as CPUs "0-1" - * wouldn't be listed as "0,1", and so after deduplication the number of - * these strings gives an indication of the number of packages, dies, - * etc. - */ - if (!strcasecmp("#smt_on", literal)) { - result =3D smt_on() ? 1.0 : 0.0; - goto out; - } - if (!strcmp("#core_wide", literal)) { + } else if (!strcmp("#core_wide", literal)) { result =3D core_wide(ctx->system_wide, ctx->user_requested_cpu_list) ? 1.0 : 0.0; - goto out; - } - if (!strcmp("#num_packages", literal)) { - topology =3D online_topology(); - result =3D topology->package_cpus_lists; - goto out; - } - if (!strcmp("#num_dies", literal)) { - topology =3D online_topology(); - result =3D topology->die_cpus_lists; - goto out; - } - if (!strcmp("#num_cores", literal)) { - topology =3D online_topology(); - result =3D topology->core_cpus_lists; - goto out; - } - if (!strcmp("#slots", literal)) { - result =3D perf_pmu__cpu_slots_per_cycle(); - goto out; - } - if (!strcmp("#has_pmem", literal)) { - result =3D has_pmem(); - goto out; + } else { + pr_err("Unrecognized literal '%s'", literal); } =20 - pr_err("Unrecognized literal '%s'", literal); -out: pr_debug2("literal: %s =3D %f\n", literal, result); return result; } diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index d6310fa1b8bd..9cb7a4e5e7d4 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -2250,11 +2250,6 @@ bool perf_pmu__match(const struct perf_pmu *pmu, con= st char *tok) (need_fnmatch && !fnmatch(tok, name, 0)); } =20 -double __weak perf_pmu__cpu_slots_per_cycle(void) -{ - return NAN; -} - int perf_pmu__event_source_devices_scnprintf(char *pathname, size_t size) { const char *sysfs =3D sysfs__mountpoint(); diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h index 880a8dc661b7..c4ca359d4215 100644 --- a/tools/perf/util/pmu.h +++ b/tools/perf/util/pmu.h @@ -271,7 +271,6 @@ void perf_pmu__warn_invalid_formats(struct perf_pmu *pm= u); =20 bool perf_pmu__match(const struct perf_pmu *pmu, const char *tok); =20 -double perf_pmu__cpu_slots_per_cycle(void); int perf_pmu__event_source_devices_scnprintf(char *pathname, size_t size); int perf_pmu__pathname_scnprintf(char *buf, size_t size, const char *pmu_name, const char *filename); diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index a82a8ec79b39..ad8baf33fdba 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -951,8 +951,12 @@ static bool should_skip_zero_counter(struct perf_stat_= config *config, * Many tool events are only gathered on the first index, skip other * zero values. */ - if (evsel__is_tool(counter)) - return true; + if (evsel__is_tool(counter)) { + struct aggr_cpu_id own_id =3D + config->aggr_get_id(config, (struct perf_cpu){ .cpu =3D 0 }); + + return !aggr_cpu_id__equal(id, &own_id); + } =20 /* * Skip value 0 when it's an uncore event and the given aggr id diff --git a/tools/perf/util/stat-shadow.c b/tools/perf/util/stat-shadow.c index e56969d1e39d..aa367c667926 100644 --- a/tools/perf/util/stat-shadow.c +++ b/tools/perf/util/stat-shadow.c @@ -400,8 +400,17 @@ static int prepare_metric(const struct metric_expr *me= xp, case TOOL_PMU__EVENT_MAX: pr_err("Invalid tool event 'max'"); abort(); + case TOOL_PMU__EVENT_HAS_PMEM: + case TOOL_PMU__EVENT_NUM_CORES: + case TOOL_PMU__EVENT_NUM_CPUS: + case TOOL_PMU__EVENT_NUM_CPUS_ONLINE: + case TOOL_PMU__EVENT_NUM_DIES: + case TOOL_PMU__EVENT_NUM_PACKAGES: + case TOOL_PMU__EVENT_SLOTS: + case TOOL_PMU__EVENT_SMT_ON: + case TOOL_PMU__EVENT_SYSTEM_TSC_FREQ: default: - pr_err("Unknown tool event '%s'", evsel__name(metric_events[i])); + pr_err("Unexpected tool event '%s'", evsel__name(metric_events[i])); abort(); } val =3D avg_stats(stats) * scale; diff --git a/tools/perf/util/tool_pmu.c b/tools/perf/util/tool_pmu.c index b8116c5c7250..3768c6a42ff6 100644 --- a/tools/perf/util/tool_pmu.c +++ b/tools/perf/util/tool_pmu.c @@ -1,11 +1,16 @@ // SPDX-License-Identifier: GPL-2.0-only #include "cgroup.h" #include "counts.h" +#include "cputopo.h" #include "evsel.h" #include "pmu.h" #include "print-events.h" +#include "smt.h" #include "time-utils.h" #include "tool_pmu.h" +#include "tsc.h" +#include +#include #include #include #include @@ -17,6 +22,15 @@ static const char *const tool_pmu__event_names[TOOL_PMU_= _EVENT_MAX] =3D { "duration_time", "user_time", "system_time", + "has_pmem", + "num_cores", + "num_cpus", + "num_cpus_online", + "num_dies", + "num_packages", + "slots", + "smt_on", + "system_tsc_freq", }; =20 =20 @@ -33,8 +47,14 @@ enum tool_pmu_event tool_pmu__str_to_event(const char *s= tr) int i; =20 tool_pmu__for_each_event(i) { - if (!strcasecmp(str, tool_pmu__event_names[i])) + if (!strcasecmp(str, tool_pmu__event_names[i])) { +#if !defined(__aarch64__) + /* The slots event should only appear on arm64. */ + if (i =3D=3D TOOL_PMU__EVENT_SLOTS) + return TOOL_PMU__EVENT_NONE; +#endif return i; + } } return TOOL_PMU__EVENT_NONE; } @@ -252,6 +272,9 @@ int evsel__tool_pmu_open(struct evsel *evsel, enum tool_pmu_event ev =3D evsel__tool_event(evsel); int pid =3D -1, idx =3D 0, thread =3D 0, nthreads, err =3D 0, old_errno; =20 + if (ev =3D=3D TOOL_PMU__EVENT_NUM_CPUS) + return 0; + if (ev =3D=3D TOOL_PMU__EVENT_DURATION_TIME) { if (evsel->core.attr.sample_period) /* no sampling */ return -EINVAL; @@ -330,16 +353,133 @@ int evsel__tool_pmu_open(struct evsel *evsel, return err; } =20 +#if !defined(__i386__) && !defined(__x86_64__) +u64 arch_get_tsc_freq(void) +{ + return 0; +} +#endif + +#if !defined(__aarch64__) +u64 tool_pmu__cpu_slots_per_cycle(void) +{ + return 0; +} +#endif + +static bool has_pmem(void) +{ + static bool has_pmem, cached; + const char *sysfs =3D sysfs__mountpoint(); + char path[PATH_MAX]; + + if (!cached) { + snprintf(path, sizeof(path), "%s/firmware/acpi/tables/NFIT", sysfs); + has_pmem =3D access(path, F_OK) =3D=3D 0; + cached =3D true; + } + return has_pmem; +} + +bool tool_pmu__read_event(enum tool_pmu_event ev, u64 *result) +{ + const struct cpu_topology *topology; + + switch (ev) { + case TOOL_PMU__EVENT_HAS_PMEM: + *result =3D has_pmem() ? 1 : 0; + return true; + + case TOOL_PMU__EVENT_NUM_CORES: + topology =3D online_topology(); + *result =3D topology->core_cpus_lists; + return true; + + case TOOL_PMU__EVENT_NUM_CPUS: + *result =3D cpu__max_present_cpu().cpu; + return true; + + case TOOL_PMU__EVENT_NUM_CPUS_ONLINE: { + struct perf_cpu_map *online =3D cpu_map__online(); + + if (online) { + *result =3D perf_cpu_map__nr(online); + return true; + } + return false; + } + case TOOL_PMU__EVENT_NUM_DIES: + topology =3D online_topology(); + *result =3D topology->die_cpus_lists; + return true; + + case TOOL_PMU__EVENT_NUM_PACKAGES: + topology =3D online_topology(); + *result =3D topology->package_cpus_lists; + return true; + + case TOOL_PMU__EVENT_SLOTS: + *result =3D tool_pmu__cpu_slots_per_cycle(); + return *result ? true : false; + + case TOOL_PMU__EVENT_SMT_ON: + *result =3D smt_on() ? 1 : 0; + return true; + + case TOOL_PMU__EVENT_SYSTEM_TSC_FREQ: + *result =3D arch_get_tsc_freq(); + return true; + + case TOOL_PMU__EVENT_NONE: + case TOOL_PMU__EVENT_DURATION_TIME: + case TOOL_PMU__EVENT_USER_TIME: + case TOOL_PMU__EVENT_SYSTEM_TIME: + case TOOL_PMU__EVENT_MAX: + default: + return false; + } +} + int evsel__tool_pmu_read(struct evsel *evsel, int cpu_map_idx, int thread) { __u64 *start_time, cur_time, delta_start; + unsigned long val; int fd, err =3D 0; - struct perf_counts_values *count; + struct perf_counts_values *count, *old_count =3D NULL; bool adjust =3D false; + enum tool_pmu_event ev =3D evsel__tool_event(evsel); =20 count =3D perf_counts(evsel->counts, cpu_map_idx, thread); =20 - switch (evsel__tool_event(evsel)) { + switch (ev) { + case TOOL_PMU__EVENT_HAS_PMEM: + case TOOL_PMU__EVENT_NUM_CORES: + case TOOL_PMU__EVENT_NUM_CPUS: + case TOOL_PMU__EVENT_NUM_CPUS_ONLINE: + case TOOL_PMU__EVENT_NUM_DIES: + case TOOL_PMU__EVENT_NUM_PACKAGES: + case TOOL_PMU__EVENT_SLOTS: + case TOOL_PMU__EVENT_SMT_ON: + case TOOL_PMU__EVENT_SYSTEM_TSC_FREQ: + if (evsel->prev_raw_counts) + old_count =3D perf_counts(evsel->prev_raw_counts, cpu_map_idx, thread); + val =3D 0; + if (cpu_map_idx =3D=3D 0 && thread =3D=3D 0) { + if (!tool_pmu__read_event(ev, &val)) { + count->lost++; + val =3D 0; + } + } + if (old_count) { + count->val =3D old_count->val + val; + count->run =3D old_count->run + 1; + count->ena =3D old_count->ena + 1; + } else { + count->val =3D val; + count->run++; + count->ena++; + } + return 0; case TOOL_PMU__EVENT_DURATION_TIME: /* * Pretend duration_time is only on the first CPU and thread, or diff --git a/tools/perf/util/tool_pmu.h b/tools/perf/util/tool_pmu.h index b156645206c4..ecdf316525bb 100644 --- a/tools/perf/util/tool_pmu.h +++ b/tools/perf/util/tool_pmu.h @@ -10,9 +10,18 @@ struct print_callbacks; =20 enum tool_pmu_event { TOOL_PMU__EVENT_NONE =3D 0, - TOOL_PMU__EVENT_DURATION_TIME =3D 1, - TOOL_PMU__EVENT_USER_TIME =3D 2, - TOOL_PMU__EVENT_SYSTEM_TIME =3D 3, + TOOL_PMU__EVENT_DURATION_TIME, + TOOL_PMU__EVENT_USER_TIME, + TOOL_PMU__EVENT_SYSTEM_TIME, + TOOL_PMU__EVENT_HAS_PMEM, + TOOL_PMU__EVENT_NUM_CORES, + TOOL_PMU__EVENT_NUM_CPUS, + TOOL_PMU__EVENT_NUM_CPUS_ONLINE, + TOOL_PMU__EVENT_NUM_DIES, + TOOL_PMU__EVENT_NUM_PACKAGES, + TOOL_PMU__EVENT_SLOTS, + TOOL_PMU__EVENT_SMT_ON, + TOOL_PMU__EVENT_SYSTEM_TSC_FREQ, =20 TOOL_PMU__EVENT_MAX, }; @@ -31,9 +40,11 @@ int tool_pmu__config_terms(struct perf_event_attr *attr, struct parse_events_terms *terms, struct parse_events_error *err); int tool_pmu__for_each_event_cb(struct perf_pmu *pmu, void *state, pmu_eve= nt_callback cb); +bool tool_pmu__read_event(enum tool_pmu_event ev, u64 *result); =20 -bool perf_pmu__is_tool(const struct perf_pmu *pmu); +u64 tool_pmu__cpu_slots_per_cycle(void); =20 +bool perf_pmu__is_tool(const struct perf_pmu *pmu); =20 bool evsel__is_tool(const struct evsel *evsel); enum tool_pmu_event evsel__tool_event(const struct evsel *evsel); diff --git a/tools/perf/util/tsc.h b/tools/perf/util/tsc.h index 88fd1c4c1cb8..57ce8449647f 100644 --- a/tools/perf/util/tsc.h +++ b/tools/perf/util/tsc.h @@ -25,7 +25,7 @@ int perf_read_tsc_conversion(const struct perf_event_mmap= _page *pc, u64 perf_time_to_tsc(u64 ns, struct perf_tsc_conversion *tc); u64 tsc_to_perf_time(u64 cyc, struct perf_tsc_conversion *tc); u64 rdtsc(void); -double arch_get_tsc_freq(void); +u64 arch_get_tsc_freq(void); =20 size_t perf_event__fprintf_time_conv(union perf_event *event, FILE *fp); =20 --=20 2.46.0.662.g92d0881bb0-goog From nobody Sat Nov 30 02:52:27 2024 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (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 380651C2333 for ; Thu, 12 Sep 2024 19:04:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726167851; cv=none; b=fy+Umd/VZx7q3SNc3RZ0vFHgYCORbfpU/Q8tPGrAPFZ/An1lmwCVqosN/LDAzeE4z5K+IL7OVVqm84W7B5GEmEW2re+y6+cFqUrqlnWg5nFuy20Hp4ptDBzSSVMdByDOvtftmQpr0/SgTJoZ69HO3D45XrgKKgrK9C+n3Ter1Ks= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726167851; c=relaxed/simple; bh=qSFD9UJsixuX5E+fyLm8TamSqzIZEYuZ12M/d0UqrwE=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=eHzxCnKyaJxsGyZcK5yANCfdejyzj7vTvcn4fcMC/5+Bb06VCRAXctuLBmRJFXXIfoQGmmP6rDaPZHIixHzr+OIm/4RZA5jTBYwcM4SdgXXKBGtvBP9dYX+opdIDYMAJmD10EQ7c3o9V8D2O7orOLcer8ILs8M45kJQ7Df+3alo= 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=2R8bI2N0; arc=none smtp.client-ip=209.85.219.202 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="2R8bI2N0" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e1ce98dcafaso352088276.0 for ; Thu, 12 Sep 2024 12:04:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1726167848; x=1726772648; darn=vger.kernel.org; h=content-transfer-encoding:to:from:subject:references:mime-version :message-id:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=+472Fb06EIJP3cxa/5FqwrgwVibXZ+dWdRiYP+vxfIk=; b=2R8bI2N0o14HZe6JWnZEg9uzT9abK6Ee0rzYg4QhazXbCqQYWE13tfWfnVV4CvhpJZ p4Khb76tB3LEXH9x9IXfjYVBIjdvzZV+mFpHl7+FvNtguRFwnskEr8/E3xpfp5IS+4NN i6PpJTGN64fxREcRt2pOi7fd1mV7nzIvTrGGGwN/EbpHKcz4a6Ukm34knTbNzMNiksyG r+acBEjX0jgoFRdyh23AoZBUkH26hU7ulse31W8uinkZNLultry7NBkBSIOHUBM+qaGy fzhjQILht8pldKxj6zoS+M1q/2U/k3+d7YL2wJEpyQJTz9tIQk+01BebqwrM/qAxsZ9e WijQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726167848; x=1726772648; h=content-transfer-encoding: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=+472Fb06EIJP3cxa/5FqwrgwVibXZ+dWdRiYP+vxfIk=; b=eyp8klqq1lD9NG5pT7XEMzSvnqIKw1p44W2+dwoo5Dj7wmZ2YrTBqTuGPHnKw7rw41 LyJNEXxaC0B7hlUer4CU672GYMntfQI1ub2RVwFF5AF6mjZ0oDveocevLWVG2oWrYsmR 2mD6FXMkqAmr2G+ueo4RFRk6Q9y4qIcRuADwgcy99InWUpPzXVuvyOErUI1/BztlZUkB PUHsGVxxDHfs3vnGXgS16RYaJK9BoszwrZFFDa+WjMcHBWVaFOmStf4A4sS2+9UATX/W QeHX7yNKHU19JnS0RrkITWZymUtTnpRFns7ITHYZBqORfNMNHeMTckQhAnGzr8+wX9nh hikg== X-Forwarded-Encrypted: i=1; AJvYcCVLl6Lbm4JOI72hxiALPYDDACXG5qYW0k/jh4co8UCFAcXd+XRmdjAM/FXttz2y4sjKI7YySU1NMj479o0=@vger.kernel.org X-Gm-Message-State: AOJu0Yy3Jvv2lPDWd4MSwz8Z+uuuznpta+Phb7kYnTuisO7n8PZUpeqM fcoBgNLVDNzmIfZvsQ+XV9QUZ4kbcdxb2eGs+LzhebhybpZ3RJ2ZqKyuhMjh5S4/MUyES3WXmMp SEzC+VQ== X-Google-Smtp-Source: AGHT+IFhqdbQSwXXMOHSax4pmGKG+7n06slmOOHWZfRK4G8h3HrNV/ph4MO5mlXi+6Z3jeuEN2lNaX7c6g+D X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:cf0e:7a99:e672:3862]) (user=irogers job=sendgmr) by 2002:a25:c586:0:b0:e03:53a4:1a7 with SMTP id 3f1490d57ef6-e1db0122872mr395276.10.1726167848084; Thu, 12 Sep 2024 12:04:08 -0700 (PDT) Date: Thu, 12 Sep 2024 12:03:35 -0700 In-Reply-To: <20240912190341.919229-1-irogers@google.com> Message-Id: <20240912190341.919229-9-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240912190341.919229-1-irogers@google.com> X-Mailer: git-send-email 2.46.0.662.g92d0881bb0-goog Subject: [PATCH v2 08/13] perf jevents: Add tool event json under a common architecture 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 , John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Ravi Bangoria , Weilin Wang , Jing Zhang , Xu Yang , Sandipan Das , Benjamin Gray , Athira Jajeev , Howard Chu , Dominique Martinet , Yang Jihong , Colin Ian King , Veronika Molnarova , "Dr. David Alan Gilbert" , Oliver Upton , Changbin Du , Ze Gao , Andi Kleen , "=?UTF-8?q?Cl=C3=A9ment=20Le=20Goffic?=" , Sun Haiyong , Junhao He , Tiezhu Yang , Yicong Yang , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-arm-kernel@lists.infradead.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Introduce the notion of a common architecture/model that can be used to find event tables for common PMUs like the tool PMU. By having tool events be json standard PMU attribute configuration, descriptions, etc. can be used and these routines are already optimized for things like binary searching. Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- .../pmu-events/arch/common/common/tool.json | 74 +++++++ tools/perf/pmu-events/empty-pmu-events.c | 208 +++++++++++------- tools/perf/pmu-events/jevents.py | 16 +- 3 files changed, 215 insertions(+), 83 deletions(-) create mode 100644 tools/perf/pmu-events/arch/common/common/tool.json diff --git a/tools/perf/pmu-events/arch/common/common/tool.json b/tools/per= f/pmu-events/arch/common/common/tool.json new file mode 100644 index 000000000000..12f2ef1813a6 --- /dev/null +++ b/tools/perf/pmu-events/arch/common/common/tool.json @@ -0,0 +1,74 @@ +[ + { + "Unit": "tool", + "EventName": "duration_time", + "BriefDescription": "Wall clock interval time in nanoseconds", + "ConfigCode": "1" + }, + { + "Unit": "tool", + "EventName": "user_time", + "BriefDescription": "User (non-kernel) time in nanoseconds", + "ConfigCode": "2" + }, + { + "Unit": "tool", + "EventName": "system_time", + "BriefDescription": "System/kernel time in nanoseconds", + "ConfigCode": "3" + }, + { + "Unit": "tool", + "EventName": "has_pmem", + "BriefDescription": "1 if persistent memory installed otherwise 0", + "ConfigCode": "4" + }, + { + "Unit": "tool", + "EventName": "num_cores", + "BriefDescription": "Number of cores. A core consists of 1 or more thr= ead, with each thread being associated with a logical Linux CPU", + "ConfigCode": "5" + }, + { + "Unit": "tool", + "EventName": "num_cpus", + "BriefDescription": "Number of logical Linux CPUs. There may be multip= le such CPUs on a core", + "ConfigCode": "6" + }, + { + "Unit": "tool", + "EventName": "num_cpus_online", + "BriefDescription": "Number of online logical Linux CPUs. There may be= multiple such CPUs on a core", + "ConfigCode": "7" + }, + { + "Unit": "tool", + "EventName": "num_dies", + "BriefDescription": "Number of dies. Each die has 1 or more cores", + "ConfigCode": "8" + }, + { + "Unit": "tool", + "EventName": "num_packages", + "BriefDescription": "Number of packages. Each package has 1 or more di= e", + "ConfigCode": "9" + }, + { + "Unit": "tool", + "EventName": "slots", + "BriefDescription": "Number of functional units that in parallel can e= xecute parts of an instruction", + "ConfigCode": "10" + }, + { + "Unit": "tool", + "EventName": "smt_on", + "BriefDescription": "1 if simultaneous multithreading (aka hyperthread= ing) is enable otherwise 0", + "ConfigCode": "11" + }, + { + "Unit": "tool", + "EventName": "system_tsc_freq", + "BriefDescription": "The amount a Time Stamp Counter (TSC) increases p= er second", + "ConfigCode": "12" + } +] diff --git a/tools/perf/pmu-events/empty-pmu-events.c b/tools/perf/pmu-even= ts/empty-pmu-events.c index c592079982fb..47ed8b03e445 100644 --- a/tools/perf/pmu-events/empty-pmu-events.c +++ b/tools/perf/pmu-events/empty-pmu-events.c @@ -19,72 +19,109 @@ struct pmu_table_entry { }; =20 static const char *const big_c_string =3D -/* offset=3D0 */ "default_core\000" -/* offset=3D13 */ "bp_l1_btb_correct\000branch\000L1 BTB Correction\000eve= nt=3D0x8a\000\00000\000\000" -/* offset=3D72 */ "bp_l2_btb_correct\000branch\000L2 BTB Correction\000eve= nt=3D0x8b\000\00000\000\000" -/* offset=3D131 */ "l3_cache_rd\000cache\000L3 cache access, read\000event= =3D0x40\000\00000\000Attributable Level 3 cache access, read\000" -/* offset=3D226 */ "segment_reg_loads.any\000other\000Number of segment re= gister loads\000event=3D6,period=3D200000,umask=3D0x80\000\00000\000\000" -/* offset=3D325 */ "dispatch_blocked.any\000other\000Memory cluster signal= s to block micro-op dispatch for any reason\000event=3D9,period=3D200000,um= ask=3D0x20\000\00000\000\000" -/* offset=3D455 */ "eist_trans\000other\000Number of Enhanced Intel SpeedS= tep(R) Technology (EIST) transitions\000event=3D0x3a,period=3D200000\000\00= 000\000\000" -/* offset=3D570 */ "hisi_sccl,ddrc\000" -/* offset=3D585 */ "uncore_hisi_ddrc.flux_wcmd\000uncore\000DDRC write com= mands\000event=3D2\000\00000\000DDRC write commands\000" -/* offset=3D671 */ "uncore_cbox\000" -/* offset=3D683 */ "unc_cbo_xsnp_response.miss_eviction\000uncore\000A cro= ss-core snoop resulted from L3 Eviction which misses in some processor core= \000event=3D0x22,umask=3D0x81\000\00000\000A cross-core snoop resulted from= L3 Eviction which misses in some processor core\000" -/* offset=3D914 */ "event-hyphen\000uncore\000UNC_CBO_HYPHEN\000event=3D0x= e0\000\00000\000UNC_CBO_HYPHEN\000" -/* offset=3D979 */ "event-two-hyph\000uncore\000UNC_CBO_TWO_HYPH\000event= =3D0xc0\000\00000\000UNC_CBO_TWO_HYPH\000" -/* offset=3D1050 */ "hisi_sccl,l3c\000" -/* offset=3D1064 */ "uncore_hisi_l3c.rd_hit_cpipe\000uncore\000Total read = hits\000event=3D7\000\00000\000Total read hits\000" -/* offset=3D1144 */ "uncore_imc_free_running\000" -/* offset=3D1168 */ "uncore_imc_free_running.cache_miss\000uncore\000Total= cache misses\000event=3D0x12\000\00000\000Total cache misses\000" -/* offset=3D1263 */ "uncore_imc\000" -/* offset=3D1274 */ "uncore_imc.cache_hits\000uncore\000Total cache hits\0= 00event=3D0x34\000\00000\000Total cache hits\000" -/* offset=3D1352 */ "uncore_sys_ddr_pmu\000" -/* offset=3D1371 */ "sys_ddr_pmu.write_cycles\000uncore\000ddr write-cycle= s event\000event=3D0x2b\000v8\00000\000\000" -/* offset=3D1444 */ "uncore_sys_ccn_pmu\000" -/* offset=3D1463 */ "sys_ccn_pmu.read_cycles\000uncore\000ccn read-cycles = event\000config=3D0x2c\0000x01\00000\000\000" -/* offset=3D1537 */ "uncore_sys_cmn_pmu\000" -/* offset=3D1556 */ "sys_cmn_pmu.hnf_cache_miss\000uncore\000Counts total = cache misses in first lookup result (high priority)\000eventid=3D1,type=3D5= \000(434|436|43c|43a).*\00000\000\000" -/* offset=3D1696 */ "CPI\000\0001 / IPC\000\000\000\000\000\000\000\00000" -/* offset=3D1718 */ "IPC\000group1\000inst_retired.any / cpu_clk_unhalted.= thread\000\000\000\000\000\000\000\00000" -/* offset=3D1781 */ "Frontend_Bound_SMT\000\000idq_uops_not_delivered.core= / (4 * (cpu_clk_unhalted.thread / 2 * (1 + cpu_clk_unhalted.one_thread_act= ive / cpu_clk_unhalted.ref_xclk)))\000\000\000\000\000\000\000\00000" -/* offset=3D1947 */ "dcache_miss_cpi\000\000l1d\\-loads\\-misses / inst_re= tired.any\000\000\000\000\000\000\000\00000" -/* offset=3D2011 */ "icache_miss_cycles\000\000l1i\\-loads\\-misses / inst= _retired.any\000\000\000\000\000\000\000\00000" -/* offset=3D2078 */ "cache_miss_cycles\000group1\000dcache_miss_cpi + icac= he_miss_cycles\000\000\000\000\000\000\000\00000" -/* offset=3D2149 */ "DCache_L2_All_Hits\000\000l2_rqsts.demand_data_rd_hit= + l2_rqsts.pf_hit + l2_rqsts.rfo_hit\000\000\000\000\000\000\000\00000" -/* offset=3D2243 */ "DCache_L2_All_Miss\000\000max(l2_rqsts.all_demand_dat= a_rd - l2_rqsts.demand_data_rd_hit, 0) + l2_rqsts.pf_miss + l2_rqsts.rfo_mi= ss\000\000\000\000\000\000\000\00000" -/* offset=3D2377 */ "DCache_L2_All\000\000DCache_L2_All_Hits + DCache_L2_A= ll_Miss\000\000\000\000\000\000\000\00000" -/* offset=3D2441 */ "DCache_L2_Hits\000\000d_ratio(DCache_L2_All_Hits, DCa= che_L2_All)\000\000\000\000\000\000\000\00000" -/* offset=3D2509 */ "DCache_L2_Misses\000\000d_ratio(DCache_L2_All_Miss, D= Cache_L2_All)\000\000\000\000\000\000\000\00000" -/* offset=3D2579 */ "M1\000\000ipc + M2\000\000\000\000\000\000\000\00000" -/* offset=3D2601 */ "M2\000\000ipc + M1\000\000\000\000\000\000\000\00000" -/* offset=3D2623 */ "M3\000\0001 / M3\000\000\000\000\000\000\000\00000" -/* offset=3D2643 */ "L1D_Cache_Fill_BW\000\00064 * l1d.replacement / 1e9 /= duration_time\000\000\000\000\000\000\000\00000" +/* offset=3D0 */ "tool\000" +/* offset=3D5 */ "duration_time\000tool\000Wall clock interval time in nan= oseconds\000config=3D1\000\00000\000\000" +/* offset=3D78 */ "user_time\000tool\000User (non-kernel) time in nanoseco= nds\000config=3D2\000\00000\000\000" +/* offset=3D145 */ "system_time\000tool\000System/kernel time in nanosecon= ds\000config=3D3\000\00000\000\000" +/* offset=3D210 */ "has_pmem\000tool\0001 if persistent memory installed o= therwise 0\000config=3D4\000\00000\000\000" +/* offset=3D283 */ "num_cores\000tool\000Number of cores. A core consists = of 1 or more thread, with each thread being associated with a logical Linux= CPU\000config=3D5\000\00000\000\000" +/* offset=3D425 */ "num_cpus\000tool\000Number of logical Linux CPUs. Ther= e may be multiple such CPUs on a core\000config=3D6\000\00000\000\000" +/* offset=3D525 */ "num_cpus_online\000tool\000Number of online logical Li= nux CPUs. There may be multiple such CPUs on a core\000config=3D7\000\00000= \000\000" +/* offset=3D639 */ "num_dies\000tool\000Number of dies. Each die has 1 or = more cores\000config=3D8\000\00000\000\000" +/* offset=3D712 */ "num_packages\000tool\000Number of packages. Each packa= ge has 1 or more die\000config=3D9\000\00000\000\000" +/* offset=3D795 */ "slots\000tool\000Number of functional units that in pa= rallel can execute parts of an instruction\000config=3D0xa\000\00000\000\00= 0" +/* offset=3D902 */ "smt_on\000tool\0001 if simultaneous multithreading (ak= a hyperthreading) is enable otherwise 0\000config=3D0xb\000\00000\000\000" +/* offset=3D1006 */ "system_tsc_freq\000tool\000The amount a Time Stamp Co= unter (TSC) increases per second\000config=3D0xc\000\00000\000\000" +/* offset=3D1102 */ "default_core\000" +/* offset=3D1115 */ "bp_l1_btb_correct\000branch\000L1 BTB Correction\000e= vent=3D0x8a\000\00000\000\000" +/* offset=3D1174 */ "bp_l2_btb_correct\000branch\000L2 BTB Correction\000e= vent=3D0x8b\000\00000\000\000" +/* offset=3D1233 */ "l3_cache_rd\000cache\000L3 cache access, read\000even= t=3D0x40\000\00000\000Attributable Level 3 cache access, read\000" +/* offset=3D1328 */ "segment_reg_loads.any\000other\000Number of segment r= egister loads\000event=3D6,period=3D200000,umask=3D0x80\000\00000\000\000" +/* offset=3D1427 */ "dispatch_blocked.any\000other\000Memory cluster signa= ls to block micro-op dispatch for any reason\000event=3D9,period=3D200000,u= mask=3D0x20\000\00000\000\000" +/* offset=3D1557 */ "eist_trans\000other\000Number of Enhanced Intel Speed= Step(R) Technology (EIST) transitions\000event=3D0x3a,period=3D200000\000\0= 0000\000\000" +/* offset=3D1672 */ "hisi_sccl,ddrc\000" +/* offset=3D1687 */ "uncore_hisi_ddrc.flux_wcmd\000uncore\000DDRC write co= mmands\000event=3D2\000\00000\000DDRC write commands\000" +/* offset=3D1773 */ "uncore_cbox\000" +/* offset=3D1785 */ "unc_cbo_xsnp_response.miss_eviction\000uncore\000A cr= oss-core snoop resulted from L3 Eviction which misses in some processor cor= e\000event=3D0x22,umask=3D0x81\000\00000\000A cross-core snoop resulted fro= m L3 Eviction which misses in some processor core\000" +/* offset=3D2016 */ "event-hyphen\000uncore\000UNC_CBO_HYPHEN\000event=3D0= xe0\000\00000\000UNC_CBO_HYPHEN\000" +/* offset=3D2081 */ "event-two-hyph\000uncore\000UNC_CBO_TWO_HYPH\000event= =3D0xc0\000\00000\000UNC_CBO_TWO_HYPH\000" +/* offset=3D2152 */ "hisi_sccl,l3c\000" +/* offset=3D2166 */ "uncore_hisi_l3c.rd_hit_cpipe\000uncore\000Total read = hits\000event=3D7\000\00000\000Total read hits\000" +/* offset=3D2246 */ "uncore_imc_free_running\000" +/* offset=3D2270 */ "uncore_imc_free_running.cache_miss\000uncore\000Total= cache misses\000event=3D0x12\000\00000\000Total cache misses\000" +/* offset=3D2365 */ "uncore_imc\000" +/* offset=3D2376 */ "uncore_imc.cache_hits\000uncore\000Total cache hits\0= 00event=3D0x34\000\00000\000Total cache hits\000" +/* offset=3D2454 */ "uncore_sys_ddr_pmu\000" +/* offset=3D2473 */ "sys_ddr_pmu.write_cycles\000uncore\000ddr write-cycle= s event\000event=3D0x2b\000v8\00000\000\000" +/* offset=3D2546 */ "uncore_sys_ccn_pmu\000" +/* offset=3D2565 */ "sys_ccn_pmu.read_cycles\000uncore\000ccn read-cycles = event\000config=3D0x2c\0000x01\00000\000\000" +/* offset=3D2639 */ "uncore_sys_cmn_pmu\000" +/* offset=3D2658 */ "sys_cmn_pmu.hnf_cache_miss\000uncore\000Counts total = cache misses in first lookup result (high priority)\000eventid=3D1,type=3D5= \000(434|436|43c|43a).*\00000\000\000" +/* offset=3D2798 */ "CPI\000\0001 / IPC\000\000\000\000\000\000\000\00000" +/* offset=3D2820 */ "IPC\000group1\000inst_retired.any / cpu_clk_unhalted.= thread\000\000\000\000\000\000\000\00000" +/* offset=3D2883 */ "Frontend_Bound_SMT\000\000idq_uops_not_delivered.core= / (4 * (cpu_clk_unhalted.thread / 2 * (1 + cpu_clk_unhalted.one_thread_act= ive / cpu_clk_unhalted.ref_xclk)))\000\000\000\000\000\000\000\00000" +/* offset=3D3049 */ "dcache_miss_cpi\000\000l1d\\-loads\\-misses / inst_re= tired.any\000\000\000\000\000\000\000\00000" +/* offset=3D3113 */ "icache_miss_cycles\000\000l1i\\-loads\\-misses / inst= _retired.any\000\000\000\000\000\000\000\00000" +/* offset=3D3180 */ "cache_miss_cycles\000group1\000dcache_miss_cpi + icac= he_miss_cycles\000\000\000\000\000\000\000\00000" +/* offset=3D3251 */ "DCache_L2_All_Hits\000\000l2_rqsts.demand_data_rd_hit= + l2_rqsts.pf_hit + l2_rqsts.rfo_hit\000\000\000\000\000\000\000\00000" +/* offset=3D3345 */ "DCache_L2_All_Miss\000\000max(l2_rqsts.all_demand_dat= a_rd - l2_rqsts.demand_data_rd_hit, 0) + l2_rqsts.pf_miss + l2_rqsts.rfo_mi= ss\000\000\000\000\000\000\000\00000" +/* offset=3D3479 */ "DCache_L2_All\000\000DCache_L2_All_Hits + DCache_L2_A= ll_Miss\000\000\000\000\000\000\000\00000" +/* offset=3D3543 */ "DCache_L2_Hits\000\000d_ratio(DCache_L2_All_Hits, DCa= che_L2_All)\000\000\000\000\000\000\000\00000" +/* offset=3D3611 */ "DCache_L2_Misses\000\000d_ratio(DCache_L2_All_Miss, D= Cache_L2_All)\000\000\000\000\000\000\000\00000" +/* offset=3D3681 */ "M1\000\000ipc + M2\000\000\000\000\000\000\000\00000" +/* offset=3D3703 */ "M2\000\000ipc + M1\000\000\000\000\000\000\000\00000" +/* offset=3D3725 */ "M3\000\0001 / M3\000\000\000\000\000\000\000\00000" +/* offset=3D3745 */ "L1D_Cache_Fill_BW\000\00064 * l1d.replacement / 1e9 /= duration_time\000\000\000\000\000\000\000\00000" ; =20 +static const struct compact_pmu_event pmu_events__common_tool[] =3D { +{ 5 }, /* duration_time\000tool\000Wall clock interval time in nanoseconds= \000config=3D1\000\00000\000\000 */ +{ 210 }, /* has_pmem\000tool\0001 if persistent memory installed otherwise= 0\000config=3D4\000\00000\000\000 */ +{ 283 }, /* num_cores\000tool\000Number of cores. A core consists of 1 or = more thread, with each thread being associated with a logical Linux CPU\000= config=3D5\000\00000\000\000 */ +{ 425 }, /* num_cpus\000tool\000Number of logical Linux CPUs. There may be= multiple such CPUs on a core\000config=3D6\000\00000\000\000 */ +{ 525 }, /* num_cpus_online\000tool\000Number of online logical Linux CPUs= . There may be multiple such CPUs on a core\000config=3D7\000\00000\000\000= */ +{ 639 }, /* num_dies\000tool\000Number of dies. Each die has 1 or more cor= es\000config=3D8\000\00000\000\000 */ +{ 712 }, /* num_packages\000tool\000Number of packages. Each package has 1= or more die\000config=3D9\000\00000\000\000 */ +{ 795 }, /* slots\000tool\000Number of functional units that in parallel c= an execute parts of an instruction\000config=3D0xa\000\00000\000\000 */ +{ 902 }, /* smt_on\000tool\0001 if simultaneous multithreading (aka hypert= hreading) is enable otherwise 0\000config=3D0xb\000\00000\000\000 */ +{ 145 }, /* system_time\000tool\000System/kernel time in nanoseconds\000co= nfig=3D3\000\00000\000\000 */ +{ 1006 }, /* system_tsc_freq\000tool\000The amount a Time Stamp Counter (T= SC) increases per second\000config=3D0xc\000\00000\000\000 */ +{ 78 }, /* user_time\000tool\000User (non-kernel) time in nanoseconds\000c= onfig=3D2\000\00000\000\000 */ + +}; + +const struct pmu_table_entry pmu_events__common[] =3D { +{ + .entries =3D pmu_events__common_tool, + .num_entries =3D ARRAY_SIZE(pmu_events__common_tool), + .pmu_name =3D { 0 /* tool\000 */ }, +}, +}; + static const struct compact_pmu_event pmu_events__test_soc_cpu_default_cor= e[] =3D { -{ 13 }, /* bp_l1_btb_correct\000branch\000L1 BTB Correction\000event=3D0x8= a\000\00000\000\000 */ -{ 72 }, /* bp_l2_btb_correct\000branch\000L2 BTB Correction\000event=3D0x8= b\000\00000\000\000 */ -{ 325 }, /* dispatch_blocked.any\000other\000Memory cluster signals to blo= ck micro-op dispatch for any reason\000event=3D9,period=3D200000,umask=3D0x= 20\000\00000\000\000 */ -{ 455 }, /* eist_trans\000other\000Number of Enhanced Intel SpeedStep(R) T= echnology (EIST) transitions\000event=3D0x3a,period=3D200000\000\00000\000\= 000 */ -{ 131 }, /* l3_cache_rd\000cache\000L3 cache access, read\000event=3D0x40\= 000\00000\000Attributable Level 3 cache access, read\000 */ -{ 226 }, /* segment_reg_loads.any\000other\000Number of segment register l= oads\000event=3D6,period=3D200000,umask=3D0x80\000\00000\000\000 */ +{ 1115 }, /* bp_l1_btb_correct\000branch\000L1 BTB Correction\000event=3D0= x8a\000\00000\000\000 */ +{ 1174 }, /* bp_l2_btb_correct\000branch\000L2 BTB Correction\000event=3D0= x8b\000\00000\000\000 */ +{ 1427 }, /* dispatch_blocked.any\000other\000Memory cluster signals to bl= ock micro-op dispatch for any reason\000event=3D9,period=3D200000,umask=3D0= x20\000\00000\000\000 */ +{ 1557 }, /* eist_trans\000other\000Number of Enhanced Intel SpeedStep(R) = Technology (EIST) transitions\000event=3D0x3a,period=3D200000\000\00000\000= \000 */ +{ 1233 }, /* l3_cache_rd\000cache\000L3 cache access, read\000event=3D0x40= \000\00000\000Attributable Level 3 cache access, read\000 */ +{ 1328 }, /* segment_reg_loads.any\000other\000Number of segment register = loads\000event=3D6,period=3D200000,umask=3D0x80\000\00000\000\000 */ }; static const struct compact_pmu_event pmu_events__test_soc_cpu_hisi_sccl_d= drc[] =3D { -{ 585 }, /* uncore_hisi_ddrc.flux_wcmd\000uncore\000DDRC write commands\00= 0event=3D2\000\00000\000DDRC write commands\000 */ +{ 1687 }, /* uncore_hisi_ddrc.flux_wcmd\000uncore\000DDRC write commands\0= 00event=3D2\000\00000\000DDRC write commands\000 */ }; static const struct compact_pmu_event pmu_events__test_soc_cpu_hisi_sccl_l= 3c[] =3D { -{ 1064 }, /* uncore_hisi_l3c.rd_hit_cpipe\000uncore\000Total read hits\000= event=3D7\000\00000\000Total read hits\000 */ +{ 2166 }, /* uncore_hisi_l3c.rd_hit_cpipe\000uncore\000Total read hits\000= event=3D7\000\00000\000Total read hits\000 */ }; static const struct compact_pmu_event pmu_events__test_soc_cpu_uncore_cbox= [] =3D { -{ 914 }, /* event-hyphen\000uncore\000UNC_CBO_HYPHEN\000event=3D0xe0\000\0= 0000\000UNC_CBO_HYPHEN\000 */ -{ 979 }, /* event-two-hyph\000uncore\000UNC_CBO_TWO_HYPH\000event=3D0xc0\0= 00\00000\000UNC_CBO_TWO_HYPH\000 */ -{ 683 }, /* unc_cbo_xsnp_response.miss_eviction\000uncore\000A cross-core = snoop resulted from L3 Eviction which misses in some processor core\000even= t=3D0x22,umask=3D0x81\000\00000\000A cross-core snoop resulted from L3 Evic= tion which misses in some processor core\000 */ +{ 2016 }, /* event-hyphen\000uncore\000UNC_CBO_HYPHEN\000event=3D0xe0\000\= 00000\000UNC_CBO_HYPHEN\000 */ +{ 2081 }, /* event-two-hyph\000uncore\000UNC_CBO_TWO_HYPH\000event=3D0xc0\= 000\00000\000UNC_CBO_TWO_HYPH\000 */ +{ 1785 }, /* unc_cbo_xsnp_response.miss_eviction\000uncore\000A cross-core= snoop resulted from L3 Eviction which misses in some processor core\000eve= nt=3D0x22,umask=3D0x81\000\00000\000A cross-core snoop resulted from L3 Evi= ction which misses in some processor core\000 */ }; static const struct compact_pmu_event pmu_events__test_soc_cpu_uncore_imc[= ] =3D { -{ 1274 }, /* uncore_imc.cache_hits\000uncore\000Total cache hits\000event= =3D0x34\000\00000\000Total cache hits\000 */ +{ 2376 }, /* uncore_imc.cache_hits\000uncore\000Total cache hits\000event= =3D0x34\000\00000\000Total cache hits\000 */ }; static const struct compact_pmu_event pmu_events__test_soc_cpu_uncore_imc_= free_running[] =3D { -{ 1168 }, /* uncore_imc_free_running.cache_miss\000uncore\000Total cache m= isses\000event=3D0x12\000\00000\000Total cache misses\000 */ +{ 2270 }, /* uncore_imc_free_running.cache_miss\000uncore\000Total cache m= isses\000event=3D0x12\000\00000\000Total cache misses\000 */ =20 }; =20 @@ -92,51 +129,51 @@ const struct pmu_table_entry pmu_events__test_soc_cpu[= ] =3D { { .entries =3D pmu_events__test_soc_cpu_default_core, .num_entries =3D ARRAY_SIZE(pmu_events__test_soc_cpu_default_core), - .pmu_name =3D { 0 /* default_core\000 */ }, + .pmu_name =3D { 1102 /* default_core\000 */ }, }, { .entries =3D pmu_events__test_soc_cpu_hisi_sccl_ddrc, .num_entries =3D ARRAY_SIZE(pmu_events__test_soc_cpu_hisi_sccl_ddrc), - .pmu_name =3D { 570 /* hisi_sccl,ddrc\000 */ }, + .pmu_name =3D { 1672 /* hisi_sccl,ddrc\000 */ }, }, { .entries =3D pmu_events__test_soc_cpu_hisi_sccl_l3c, .num_entries =3D ARRAY_SIZE(pmu_events__test_soc_cpu_hisi_sccl_l3c), - .pmu_name =3D { 1050 /* hisi_sccl,l3c\000 */ }, + .pmu_name =3D { 2152 /* hisi_sccl,l3c\000 */ }, }, { .entries =3D pmu_events__test_soc_cpu_uncore_cbox, .num_entries =3D ARRAY_SIZE(pmu_events__test_soc_cpu_uncore_cbox), - .pmu_name =3D { 671 /* uncore_cbox\000 */ }, + .pmu_name =3D { 1773 /* uncore_cbox\000 */ }, }, { .entries =3D pmu_events__test_soc_cpu_uncore_imc, .num_entries =3D ARRAY_SIZE(pmu_events__test_soc_cpu_uncore_imc), - .pmu_name =3D { 1263 /* uncore_imc\000 */ }, + .pmu_name =3D { 2365 /* uncore_imc\000 */ }, }, { .entries =3D pmu_events__test_soc_cpu_uncore_imc_free_running, .num_entries =3D ARRAY_SIZE(pmu_events__test_soc_cpu_uncore_imc_free_= running), - .pmu_name =3D { 1144 /* uncore_imc_free_running\000 */ }, + .pmu_name =3D { 2246 /* uncore_imc_free_running\000 */ }, }, }; =20 static const struct compact_pmu_event pmu_metrics__test_soc_cpu_default_co= re[] =3D { -{ 1696 }, /* CPI\000\0001 / IPC\000\000\000\000\000\000\000\00000 */ -{ 2377 }, /* DCache_L2_All\000\000DCache_L2_All_Hits + DCache_L2_All_Miss\= 000\000\000\000\000\000\000\00000 */ -{ 2149 }, /* DCache_L2_All_Hits\000\000l2_rqsts.demand_data_rd_hit + l2_rq= sts.pf_hit + l2_rqsts.rfo_hit\000\000\000\000\000\000\000\00000 */ -{ 2243 }, /* DCache_L2_All_Miss\000\000max(l2_rqsts.all_demand_data_rd - l= 2_rqsts.demand_data_rd_hit, 0) + l2_rqsts.pf_miss + l2_rqsts.rfo_miss\000\0= 00\000\000\000\000\000\00000 */ -{ 2441 }, /* DCache_L2_Hits\000\000d_ratio(DCache_L2_All_Hits, DCache_L2_A= ll)\000\000\000\000\000\000\000\00000 */ -{ 2509 }, /* DCache_L2_Misses\000\000d_ratio(DCache_L2_All_Miss, DCache_L2= _All)\000\000\000\000\000\000\000\00000 */ -{ 1781 }, /* Frontend_Bound_SMT\000\000idq_uops_not_delivered.core / (4 * = (cpu_clk_unhalted.thread / 2 * (1 + cpu_clk_unhalted.one_thread_active / cp= u_clk_unhalted.ref_xclk)))\000\000\000\000\000\000\000\00000 */ -{ 1718 }, /* IPC\000group1\000inst_retired.any / cpu_clk_unhalted.thread\0= 00\000\000\000\000\000\000\00000 */ -{ 2643 }, /* L1D_Cache_Fill_BW\000\00064 * l1d.replacement / 1e9 / duratio= n_time\000\000\000\000\000\000\000\00000 */ -{ 2579 }, /* M1\000\000ipc + M2\000\000\000\000\000\000\000\00000 */ -{ 2601 }, /* M2\000\000ipc + M1\000\000\000\000\000\000\000\00000 */ -{ 2623 }, /* M3\000\0001 / M3\000\000\000\000\000\000\000\00000 */ -{ 2078 }, /* cache_miss_cycles\000group1\000dcache_miss_cpi + icache_miss_= cycles\000\000\000\000\000\000\000\00000 */ -{ 1947 }, /* dcache_miss_cpi\000\000l1d\\-loads\\-misses / inst_retired.an= y\000\000\000\000\000\000\000\00000 */ -{ 2011 }, /* icache_miss_cycles\000\000l1i\\-loads\\-misses / inst_retired= .any\000\000\000\000\000\000\000\00000 */ +{ 2798 }, /* CPI\000\0001 / IPC\000\000\000\000\000\000\000\00000 */ +{ 3479 }, /* DCache_L2_All\000\000DCache_L2_All_Hits + DCache_L2_All_Miss\= 000\000\000\000\000\000\000\00000 */ +{ 3251 }, /* DCache_L2_All_Hits\000\000l2_rqsts.demand_data_rd_hit + l2_rq= sts.pf_hit + l2_rqsts.rfo_hit\000\000\000\000\000\000\000\00000 */ +{ 3345 }, /* DCache_L2_All_Miss\000\000max(l2_rqsts.all_demand_data_rd - l= 2_rqsts.demand_data_rd_hit, 0) + l2_rqsts.pf_miss + l2_rqsts.rfo_miss\000\0= 00\000\000\000\000\000\00000 */ +{ 3543 }, /* DCache_L2_Hits\000\000d_ratio(DCache_L2_All_Hits, DCache_L2_A= ll)\000\000\000\000\000\000\000\00000 */ +{ 3611 }, /* DCache_L2_Misses\000\000d_ratio(DCache_L2_All_Miss, DCache_L2= _All)\000\000\000\000\000\000\000\00000 */ +{ 2883 }, /* Frontend_Bound_SMT\000\000idq_uops_not_delivered.core / (4 * = (cpu_clk_unhalted.thread / 2 * (1 + cpu_clk_unhalted.one_thread_active / cp= u_clk_unhalted.ref_xclk)))\000\000\000\000\000\000\000\00000 */ +{ 2820 }, /* IPC\000group1\000inst_retired.any / cpu_clk_unhalted.thread\0= 00\000\000\000\000\000\000\00000 */ +{ 3745 }, /* L1D_Cache_Fill_BW\000\00064 * l1d.replacement / 1e9 / duratio= n_time\000\000\000\000\000\000\000\00000 */ +{ 3681 }, /* M1\000\000ipc + M2\000\000\000\000\000\000\000\00000 */ +{ 3703 }, /* M2\000\000ipc + M1\000\000\000\000\000\000\000\00000 */ +{ 3725 }, /* M3\000\0001 / M3\000\000\000\000\000\000\000\00000 */ +{ 3180 }, /* cache_miss_cycles\000group1\000dcache_miss_cpi + icache_miss_= cycles\000\000\000\000\000\000\000\00000 */ +{ 3049 }, /* dcache_miss_cpi\000\000l1d\\-loads\\-misses / inst_retired.an= y\000\000\000\000\000\000\000\00000 */ +{ 3113 }, /* icache_miss_cycles\000\000l1i\\-loads\\-misses / inst_retired= .any\000\000\000\000\000\000\000\00000 */ =20 }; =20 @@ -144,18 +181,18 @@ const struct pmu_table_entry pmu_metrics__test_soc_cp= u[] =3D { { .entries =3D pmu_metrics__test_soc_cpu_default_core, .num_entries =3D ARRAY_SIZE(pmu_metrics__test_soc_cpu_default_core), - .pmu_name =3D { 0 /* default_core\000 */ }, + .pmu_name =3D { 1102 /* default_core\000 */ }, }, }; =20 static const struct compact_pmu_event pmu_events__test_soc_sys_uncore_sys_= ccn_pmu[] =3D { -{ 1463 }, /* sys_ccn_pmu.read_cycles\000uncore\000ccn read-cycles event\00= 0config=3D0x2c\0000x01\00000\000\000 */ +{ 2565 }, /* sys_ccn_pmu.read_cycles\000uncore\000ccn read-cycles event\00= 0config=3D0x2c\0000x01\00000\000\000 */ }; static const struct compact_pmu_event pmu_events__test_soc_sys_uncore_sys_= cmn_pmu[] =3D { -{ 1556 }, /* sys_cmn_pmu.hnf_cache_miss\000uncore\000Counts total cache mi= sses in first lookup result (high priority)\000eventid=3D1,type=3D5\000(434= |436|43c|43a).*\00000\000\000 */ +{ 2658 }, /* sys_cmn_pmu.hnf_cache_miss\000uncore\000Counts total cache mi= sses in first lookup result (high priority)\000eventid=3D1,type=3D5\000(434= |436|43c|43a).*\00000\000\000 */ }; static const struct compact_pmu_event pmu_events__test_soc_sys_uncore_sys_= ddr_pmu[] =3D { -{ 1371 }, /* sys_ddr_pmu.write_cycles\000uncore\000ddr write-cycles event\= 000event=3D0x2b\000v8\00000\000\000 */ +{ 2473 }, /* sys_ddr_pmu.write_cycles\000uncore\000ddr write-cycles event\= 000event=3D0x2b\000v8\00000\000\000 */ =20 }; =20 @@ -163,17 +200,17 @@ const struct pmu_table_entry pmu_events__test_soc_sys= [] =3D { { .entries =3D pmu_events__test_soc_sys_uncore_sys_ccn_pmu, .num_entries =3D ARRAY_SIZE(pmu_events__test_soc_sys_uncore_sys_ccn_p= mu), - .pmu_name =3D { 1444 /* uncore_sys_ccn_pmu\000 */ }, + .pmu_name =3D { 2546 /* uncore_sys_ccn_pmu\000 */ }, }, { .entries =3D pmu_events__test_soc_sys_uncore_sys_cmn_pmu, .num_entries =3D ARRAY_SIZE(pmu_events__test_soc_sys_uncore_sys_cmn_p= mu), - .pmu_name =3D { 1537 /* uncore_sys_cmn_pmu\000 */ }, + .pmu_name =3D { 2639 /* uncore_sys_cmn_pmu\000 */ }, }, { .entries =3D pmu_events__test_soc_sys_uncore_sys_ddr_pmu, .num_entries =3D ARRAY_SIZE(pmu_events__test_soc_sys_uncore_sys_ddr_p= mu), - .pmu_name =3D { 1352 /* uncore_sys_ddr_pmu\000 */ }, + .pmu_name =3D { 2454 /* uncore_sys_ddr_pmu\000 */ }, }, }; =20 @@ -210,6 +247,15 @@ struct pmu_events_map { * table of PMU events. */ const struct pmu_events_map pmu_events_map[] =3D { +{ + .arch =3D "common", + .cpuid =3D "common", + .event_table =3D { + .pmus =3D pmu_events__common, + .num_pmus =3D ARRAY_SIZE(pmu_events__common), + }, + .metric_table =3D {}, +}, { .arch =3D "testarch", .cpuid =3D "testcpu", diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jeven= ts.py index bb0a5d92df4a..3d2c4e6efeb4 100755 --- a/tools/perf/pmu-events/jevents.py +++ b/tools/perf/pmu-events/jevents.py @@ -292,6 +292,7 @@ class JsonEvent: 'cpu_atom': 'cpu_atom', 'ali_drw': 'ali_drw', 'arm_cmn': 'arm_cmn', + 'tool': 'tool', } return table[unit] if unit in table else f'uncore_{unit.lower()}' =20 @@ -721,6 +722,17 @@ const struct pmu_events_map pmu_events_map[] =3D { \t\t.num_pmus =3D ARRAY_SIZE(pmu_metrics__test_soc_cpu), \t} }, +""") + elif arch =3D=3D 'common': + _args.output_file.write("""{ +\t.arch =3D "common", +\t.cpuid =3D "common", +\t.event_table =3D { +\t\t.pmus =3D pmu_events__common, +\t\t.num_pmus =3D ARRAY_SIZE(pmu_events__common), +\t}, +\t.metric_table =3D {}, +}, """) else: with open(f'{_args.starting_dir}/{arch}/mapfile.csv') as csvfile: @@ -1241,7 +1253,7 @@ def main() -> None: if len(parents) =3D=3D _args.model.split(',')[0].count('/'): # We're testing the correct directory. item_path =3D '/'.join(parents) + ('/' if len(parents) > 0 else = '') + item.name - if 'test' not in item_path and item_path not in _args.model.spli= t(','): + if 'test' not in item_path and 'common' not in item_path and ite= m_path not in _args.model.split(','): continue action(parents, item) if item.is_dir(): @@ -1289,7 +1301,7 @@ struct pmu_table_entry { for item in os.scandir(_args.starting_dir): if not item.is_dir(): continue - if item.name =3D=3D _args.arch or _args.arch =3D=3D 'all' or item.name= =3D=3D 'test': + if item.name =3D=3D _args.arch or _args.arch =3D=3D 'all' or item.name= =3D=3D 'test' or item.name =3D=3D 'common': archs.append(item.name) =20 if len(archs) < 2 and _args.arch !=3D 'none': --=20 2.46.0.662.g92d0881bb0-goog From nobody Sat Nov 30 02:52:27 2024 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (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 508D91C2430 for ; Thu, 12 Sep 2024 19:04:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726167853; cv=none; b=GSc4zCu9LqgItrAGZa0LBm2kdhDdDm77d3oSyD8nIsmo85l+UP7rZlLz4c0H4MzHGFCSMCtvBFskjcSRISELgwva1D2+UjPa6BbxBk3fBADXwXF+u6Mdw+pDumguLXvzqKDTq2rEOZeNghh88fZZkEfwX6FytR2Szz4nkXiH3uA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726167853; c=relaxed/simple; bh=zapSEGsQgIL61ZEsU5YA58q0vIiAHQfaNjf0YF8DeB0=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=Zs+WDuOspYYmOu93bYa1Wsg4Za0DFdJs3dYVtLAvHYRbSat08DuLdNgYi9rz0zPJBkEQFnKlhmzQU49d+qF+Zyd7ZGX37l9SwCofiz8WkJT2hH+mdktBDuEvIV/keT2kQ4c515YoN4YAn7Zh3WGgx3Ib90R4yZgk1a7CkeXuhGU= 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=vFCzIZEE; arc=none smtp.client-ip=209.85.128.202 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="vFCzIZEE" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6d4426ad833so31698977b3.2 for ; Thu, 12 Sep 2024 12:04:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1726167850; x=1726772650; 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=Qwi2Sac9s+asJZx0ZDodmxFO/gJn7Y8byoQSP/zeaw0=; b=vFCzIZEE0+qcwIFeyOA8uLuuUZXW2ppsBBZMEA9gGJYaXqgSQiN1//YijvnwzSrM9k aTkEZaEkDWlsKz5wn4cFjtTT/M8XGbr1g3JbRUHnLcgL8/Wy/zji9axgtZS9ZfZV5Vwy Ydh/w2WWIxGAoCG/0mUE2ExDZAS882sgMU+aPoMdGh+OnUq7v4JA8uU6K1zD8mvvCWYl BuRIonj7LsINnrfKXF8ZvJhVcj1SA/VvRxOqHOdQDYMYlTs0tvpPY5v20k7yDIKfmA6T A4wfMPt/26wHJagz2HlNu1AuRV5MrHAed5JE08DALiC0HXnRWdJY28Tb9SJ6tigPk9el aqqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726167850; x=1726772650; 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=Qwi2Sac9s+asJZx0ZDodmxFO/gJn7Y8byoQSP/zeaw0=; b=PIZeE0uQ1rNHMZP1fx+udtLHuxL4U7KOCqBtmZq15P5YWe3eI4DCOA2hrQJJ5I6KET qbIg7AJlJxs3SEGIFoRVSRM4UpGY2E1VkV+Hu+uOWzt9xLpBfOQSbbuGHTVxsLtEqOTP xywEM51WwE07nma+KuDhNt0/Cx6xrAeIdzG8U40SRUOeUsfjtlRUktdSuML0j1p1Z6DI 3yLWMbyhrQszS0byV/VUzVFv5bPzM9OeAbQa4TZaZQHas+693zdace18PuioEWr9fZAT aBCSJ79ROCk3am8Tt+hrROFy1ekgOMHMBrNPvu25EpDwe0VU0idDYLVhUNe/FEAuJ9zP JQyQ== X-Forwarded-Encrypted: i=1; AJvYcCW8HLBwoQVttw5ylP3z02KI4bJKh8B2r6BT1NhWPAafOCslIQZ9HlQQKsZqlUgIpHwR5bcWdZXsTjqSOFA=@vger.kernel.org X-Gm-Message-State: AOJu0YzAnjK2MZ93KE0tU/2zzf8o9i0fd4KXMf8uJnCYz49RpEvLRyk6 6X8nDYa+3pHGigtLn1hroDonwvLHYFhpVUSIVjoT6WrL5ofB1MsSC+4gbZ389ZJxR3vuSW6/DiJ 6sAsrxw== X-Google-Smtp-Source: AGHT+IHiG/7TeNX7kdEoKK0lWn5nwEpRZ+1ylyJ4Rp1/rDpABHnz8K1NHY3kjCjIaqVvhOSJz7IMjVmSQDru X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:cf0e:7a99:e672:3862]) (user=irogers job=sendgmr) by 2002:a05:690c:620e:b0:6db:b2ed:7625 with SMTP id 00721157ae682-6dbb69be9dbmr457287b3.0.1726167850371; Thu, 12 Sep 2024 12:04:10 -0700 (PDT) Date: Thu, 12 Sep 2024 12:03:36 -0700 In-Reply-To: <20240912190341.919229-1-irogers@google.com> Message-Id: <20240912190341.919229-10-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240912190341.919229-1-irogers@google.com> X-Mailer: git-send-email 2.46.0.662.g92d0881bb0-goog Subject: [PATCH v2 09/13] perf tool_pmu: Switch to standard pmu functions and json descriptions 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 , John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Ravi Bangoria , Weilin Wang , Jing Zhang , Xu Yang , Sandipan Das , Benjamin Gray , Athira Jajeev , Howard Chu , Dominique Martinet , Yang Jihong , Colin Ian King , Veronika Molnarova , "Dr. David Alan Gilbert" , Oliver Upton , Changbin Du , Ze Gao , Andi Kleen , "=?UTF-8?q?Cl=C3=A9ment=20Le=20Goffic?=" , Sun Haiyong , Junhao He , Tiezhu Yang , Yicong Yang , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-arm-kernel@lists.infradead.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use the regular PMU approaches with tool json events to reduce the amount of special tool_pmu code - tool_pmu__config_terms and tool_pmu__for_each_event_cb are removed. Some functions remain, like tool_pmu__str_to_event, as conveniences to metricgroups. Add tool_pmu__skip_event/tool_pmu__num_skip_events to handle the case that tool json events shouldn't appear on certain architectures. This isn't done in jevents.py due to complexity in the empty-pmu-events.c and when all vendor json is built into the tool. Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- tools/perf/util/pmu.c | 26 ++++----- tools/perf/util/pmus.c | 4 +- tools/perf/util/tool_pmu.c | 109 +++++++++++-------------------------- tools/perf/util/tool_pmu.h | 12 +--- 4 files changed, 46 insertions(+), 105 deletions(-) diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 9cb7a4e5e7d4..beb93e2603e2 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -1549,9 +1549,6 @@ int perf_pmu__config(struct perf_pmu *pmu, struct per= f_event_attr *attr, { bool zero =3D !!pmu->perf_event_attr_init_default; =20 - if (perf_pmu__is_tool(pmu)) - return tool_pmu__config_terms(attr, head_terms, err); - /* Fake PMU doesn't have proper terms so nothing to configure in attr. */ if (perf_pmu__is_fake(pmu)) return 0; @@ -1664,8 +1661,8 @@ int perf_pmu__check_alias(struct perf_pmu *pmu, struc= t parse_events_terms *head_ info->scale =3D 0.0; info->snapshot =3D false; =20 - /* Tool/fake PMU doesn't rewrite terms. */ - if (perf_pmu__is_tool(pmu) || perf_pmu__is_fake(pmu)) + /* Fake PMU doesn't rewrite terms. */ + if (perf_pmu__is_fake(pmu)) goto out; =20 list_for_each_entry_safe(term, h, &head_terms->terms, list) { @@ -1831,8 +1828,8 @@ bool perf_pmu__have_event(struct perf_pmu *pmu, const= char *name) { if (!name) return false; - if (perf_pmu__is_tool(pmu)) - return tool_pmu__str_to_event(name) !=3D TOOL_PMU__EVENT_NONE; + if (perf_pmu__is_tool(pmu) && tool_pmu__skip_event(name)) + return false; if (perf_pmu__find_alias(pmu, name, /*load=3D*/ true) !=3D NULL) return true; if (pmu->cpu_aliases_added || !pmu->events_table) @@ -1844,9 +1841,6 @@ size_t perf_pmu__num_events(struct perf_pmu *pmu) { size_t nr; =20 - if (perf_pmu__is_tool(pmu)) - return tool_pmu__num_events(); - pmu_aliases_parse(pmu); nr =3D pmu->sysfs_aliases + pmu->sys_json_aliases; =20 @@ -1857,6 +1851,9 @@ size_t perf_pmu__num_events(struct perf_pmu *pmu) else assert(pmu->cpu_json_aliases =3D=3D 0); =20 + if (perf_pmu__is_tool(pmu)) + nr -=3D tool_pmu__num_skip_events(); + return pmu->selectable ? nr + 1 : nr; } =20 @@ -1907,15 +1904,15 @@ int perf_pmu__for_each_event(struct perf_pmu *pmu, = bool skip_duplicate_pmus, int ret =3D 0; struct strbuf sb; =20 - if (perf_pmu__is_tool(pmu)) - return tool_pmu__for_each_event_cb(pmu, state, cb); - strbuf_init(&sb, /*hint=3D*/ 0); pmu_aliases_parse(pmu); pmu_add_cpu_aliases(pmu); list_for_each_entry(event, &pmu->aliases, list) { size_t buf_used, pmu_name_len; =20 + if (perf_pmu__is_tool(pmu) && tool_pmu__skip_event(event->name)) + continue; + info.pmu_name =3D event->pmu_name ?: pmu->name; pmu_name_len =3D pmu_deduped_name_len(pmu, info.pmu_name, skip_duplicate_pmus); @@ -2321,9 +2318,6 @@ const char *perf_pmu__name_from_config(struct perf_pm= u *pmu, u64 config) if (!pmu) return NULL; =20 - if (perf_pmu__is_tool(pmu)) - return tool_pmu__event_to_str(config); - pmu_aliases_parse(pmu); pmu_add_cpu_aliases(pmu); list_for_each_entry(event, &pmu->aliases, list) { diff --git a/tools/perf/util/pmus.c b/tools/perf/util/pmus.c index 6e657c44de58..107de86c2637 100644 --- a/tools/perf/util/pmus.c +++ b/tools/perf/util/pmus.c @@ -440,6 +440,7 @@ static int perf_pmus__print_pmu_events__callback(void *= vstate, pr_err("Unexpected event %s/%s/\n", info->pmu->name, info->name); return 1; } + assert(info->pmu !=3D NULL || info->name !=3D NULL); s =3D &state->aliases[state->index]; s->pmu =3D info->pmu; #define COPY_STR(str) s->str =3D info->str ? strdup(info->str) : NULL @@ -590,9 +591,6 @@ void perf_pmus__print_raw_pmu_events(const struct print= _callbacks *print_cb, voi int len =3D pmu_name_len_no_suffix(pmu->name); const char *desc =3D "(see 'man perf-list' or 'man perf-record' on how t= o encode it)"; =20 - if (perf_pmu__is_tool(pmu)) - continue; - if (!pmu->is_core) desc =3D NULL; =20 diff --git a/tools/perf/util/tool_pmu.c b/tools/perf/util/tool_pmu.c index 3768c6a42ff6..488c9db33e27 100644 --- a/tools/perf/util/tool_pmu.c +++ b/tools/perf/util/tool_pmu.c @@ -33,101 +33,54 @@ static const char *const tool_pmu__event_names[TOOL_PM= U__EVENT_MAX] =3D { "system_tsc_freq", }; =20 - -const char *tool_pmu__event_to_str(enum tool_pmu_event ev) -{ - if (ev > TOOL_PMU__EVENT_NONE && ev < TOOL_PMU__EVENT_MAX) - return tool_pmu__event_names[ev]; - - return NULL; -} - -enum tool_pmu_event tool_pmu__str_to_event(const char *str) +bool tool_pmu__skip_event(const char *name __maybe_unused) { - int i; - - tool_pmu__for_each_event(i) { - if (!strcasecmp(str, tool_pmu__event_names[i])) { #if !defined(__aarch64__) - /* The slots event should only appear on arm64. */ - if (i =3D=3D TOOL_PMU__EVENT_SLOTS) - return TOOL_PMU__EVENT_NONE; + /* The slots event should only appear on arm64. */ + if (strcasecmp(name, "slots") =3D=3D 0) + return true; #endif - return i; - } - } - return TOOL_PMU__EVENT_NONE; +#if !defined(__i386__) && !defined(__x86_64__) + /* The system_tsc_freq event should only appear on x86. */ + if (strcasecmp(name, "system_tsc_freq") =3D=3D 0) + return true; +#endif + return false; } =20 -static int tool_pmu__config_term(struct perf_event_attr *attr, - struct parse_events_term *term, - struct parse_events_error *err) +int tool_pmu__num_skip_events(void) { - if (term->type_term =3D=3D PARSE_EVENTS__TERM_TYPE_USER) { - enum tool_pmu_event ev =3D tool_pmu__str_to_event(term->config); + int num =3D 0; =20 - if (ev =3D=3D TOOL_PMU__EVENT_NONE) - goto err_out; - - attr->config =3D ev; - return 0; - } -err_out: - if (err) { - char *err_str; - - parse_events_error__handle(err, term->err_val, - asprintf(&err_str, - "unexpected tool event term (%s) %s", - parse_events__term_type_str(term->type_term), - term->config) < 0 - ? strdup("unexpected tool event term") - : err_str, - NULL); - } - return -EINVAL; +#if !defined(__aarch64__) + num++; +#endif +#if !defined(__i386__) && !defined(__x86_64__) + num++; +#endif + return num; } =20 -int tool_pmu__config_terms(struct perf_event_attr *attr, - struct parse_events_terms *terms, - struct parse_events_error *err) +const char *tool_pmu__event_to_str(enum tool_pmu_event ev) { - struct parse_events_term *term; - - list_for_each_entry(term, &terms->terms, list) { - if (tool_pmu__config_term(attr, term, err)) - return -EINVAL; - } - - return 0; + if (ev > TOOL_PMU__EVENT_NONE && ev < TOOL_PMU__EVENT_MAX) + return tool_pmu__event_names[ev]; =20 + return NULL; } =20 -int tool_pmu__for_each_event_cb(struct perf_pmu *pmu, void *state, pmu_eve= nt_callback cb) +enum tool_pmu_event tool_pmu__str_to_event(const char *str) { - struct pmu_event_info info =3D { - .pmu =3D pmu, - .event_type_desc =3D "Tool event", - }; int i; =20 + if (tool_pmu__skip_event(str)) + return TOOL_PMU__EVENT_NONE; + tool_pmu__for_each_event(i) { - int ret; - - info.name =3D tool_pmu__event_to_str(i); - info.alias =3D NULL; - info.scale_unit =3D NULL; - info.desc =3D NULL; - info.long_desc =3D NULL; - info.encoding_desc =3D NULL; - info.topic =3D NULL; - info.pmu_name =3D pmu->name; - info.deprecated =3D false; - ret =3D cb(state, &info); - if (ret) - return ret; + if (!strcasecmp(str, tool_pmu__event_names[i])) + return i; } - return 0; + return TOOL_PMU__EVENT_NONE; } =20 bool perf_pmu__is_tool(const struct perf_pmu *pmu) @@ -548,6 +501,8 @@ struct perf_pmu *perf_pmus__tool_pmu(void) .caps =3D LIST_HEAD_INIT(tool.caps), .format =3D LIST_HEAD_INIT(tool.format), }; + if (!tool.events_table) + tool.events_table =3D find_core_events_table("common", "common"); =20 return &tool; } diff --git a/tools/perf/util/tool_pmu.h b/tools/perf/util/tool_pmu.h index ecdf316525bb..a60184859080 100644 --- a/tools/perf/util/tool_pmu.h +++ b/tools/perf/util/tool_pmu.h @@ -29,17 +29,11 @@ enum tool_pmu_event { #define tool_pmu__for_each_event(ev) \ for ((ev) =3D TOOL_PMU__EVENT_DURATION_TIME; (ev) < TOOL_PMU__EVENT_MAX; = ev++) =20 -static inline size_t tool_pmu__num_events(void) -{ - return TOOL_PMU__EVENT_MAX - 1; -} - const char *tool_pmu__event_to_str(enum tool_pmu_event ev); enum tool_pmu_event tool_pmu__str_to_event(const char *str); -int tool_pmu__config_terms(struct perf_event_attr *attr, - struct parse_events_terms *terms, - struct parse_events_error *err); -int tool_pmu__for_each_event_cb(struct perf_pmu *pmu, void *state, pmu_eve= nt_callback cb); +bool tool_pmu__skip_event(const char *name); +int tool_pmu__num_skip_events(void); + bool tool_pmu__read_event(enum tool_pmu_event ev, u64 *result); =20 u64 tool_pmu__cpu_slots_per_cycle(void); --=20 2.46.0.662.g92d0881bb0-goog From nobody Sat Nov 30 02:52:27 2024 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 D96F81C2435 for ; Thu, 12 Sep 2024 19:04:13 +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=1726167855; cv=none; b=smBckkPF8sSYGQW03h+NJETDVCgPQopXZKM2yer4ptvTcJOOaWUiuhX//XET8gimzZE5ruEbT0PVjxyOXLVOrgxLxR+MaRqnOX1VeYE6GUb9kNM6Y5WDau6Uc9UzAYoV2nCC6bMpaudpxQZHW3P+NiegdHn62OKqMdJsFNe73hM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726167855; c=relaxed/simple; bh=15Nc/OwWurUUacjqwVltwlzbPJZfDu3Guj0Nm4r/qc4=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=MfVqTa+6zZHZqu16UDuKHQdHSRche+90GcadvrHF2/aMT5RH7NUKTWNrowmqw7CQX473o0uOBSJn7/52ZHEx/qdALjGXRtLtX4Ku7IZ7XNLs5NPJzv1lwLlaLrcJk3sxWQMXmm4nX4fhmMciEOPMOMiwp8C0jfUCb9THqubDQiQ= 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=TuOw07y8; 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="TuOw07y8" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e1d46cee0b0so2317403276.2 for ; Thu, 12 Sep 2024 12:04:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1726167853; x=1726772653; 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=FX+r6SVFIqGib21jmzvlNHWAGVIuITyDyogStZXuwgU=; b=TuOw07y8oKvj2Z8kOPnIw886EEKnJDiu5/WAD7gr24PUuXJI4XPab3yY5J67CoV4+w GZZumz9Rc2bQXu0i+gxj/ucpBsF/tNUZ2K1M3DWi/k5Al/4//PTq3KVjTKeqQxH22/ZA 5z3X+FofC0Xbv2ttk2BUDGYvFuAw0DaYzH/qS4L1XaoTp374v63oO+MPZ0kMX4LuyjPP hXsdxGeHgGnZgPZ0FMxVd/ghPjTmf7Jsk1b2ZDSJqxgHOGjXga57xqVt0ti5YTIVgP6M IPnmLGNIJYe+pW8khrV9mK4gNPn/09DvNHH8eun3jRw+Yb9MbnzuckCa8IgyHT8B+Pvu uH+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726167853; x=1726772653; 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=FX+r6SVFIqGib21jmzvlNHWAGVIuITyDyogStZXuwgU=; b=p/Pg4HISUVjBEks4FLU93xCrmX7RmJv5O+hKTWXPcQCfwVR5tC3Gh8vXyEuVBu1a1o QFtF87Y1CDQBnFBmZY7hi89hoi2RQIr0j2SWKBiwy8p+dwSCBolC04AQgu2J/AcDYcHg /m9h0+lBVfjcZcK9hPI/YnJebj20PY17JdKpdUlMB2Yg1uATKNfrbRhA0xaJAB6Vn2R5 o8DGD5m5KhzW2RQv+anVT7KaEbiZSZDNV2eHGojs0+pySVOsjDJgvpsHU21quGowQpwd EQEXiUQAThlKy4qW+h46v4GnLsp+mvvUFm6tgSClaniGsuoxFsKpl9S9ddckj3D99/s0 K6pg== X-Forwarded-Encrypted: i=1; AJvYcCXhXfhCtvGa21GIY6AzIascEQ6IdEg86mYp3NA0woKLfF7mi6QlnbPU/kto4Cfvx3ZFkg4CKoQ1T+1BO0c=@vger.kernel.org X-Gm-Message-State: AOJu0Yy197pO5mdNfc90945stzCbVnXXsuhaI5JqJXtkBc9aaYxIfk7B EsxjL0OsqQ108nsYDhGxt2fz3LTUgfkU0DSlnhwtoBQcKB5UR0ZKcD6cmZAhIFwNJ+bKJvNT8K6 5RAzWMQ== X-Google-Smtp-Source: AGHT+IGvofSNWStqV0FQzod3PiS0/dd5eh6QGon7LzpPoW9cWLn4mOIWytpk9Z8xbGbtLTwR8S/zRT7oQlDW X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:cf0e:7a99:e672:3862]) (user=irogers job=sendgmr) by 2002:a25:e812:0:b0:e16:51f9:59da with SMTP id 3f1490d57ef6-e1d9dc1b42emr12659276.6.1726167852675; Thu, 12 Sep 2024 12:04:12 -0700 (PDT) Date: Thu, 12 Sep 2024 12:03:37 -0700 In-Reply-To: <20240912190341.919229-1-irogers@google.com> Message-Id: <20240912190341.919229-11-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240912190341.919229-1-irogers@google.com> X-Mailer: git-send-email 2.46.0.662.g92d0881bb0-goog Subject: [PATCH v2 10/13] perf tests: Add tool PMU test 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 , John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Ravi Bangoria , Weilin Wang , Jing Zhang , Xu Yang , Sandipan Das , Benjamin Gray , Athira Jajeev , Howard Chu , Dominique Martinet , Yang Jihong , Colin Ian King , Veronika Molnarova , "Dr. David Alan Gilbert" , Oliver Upton , Changbin Du , Ze Gao , Andi Kleen , "=?UTF-8?q?Cl=C3=A9ment=20Le=20Goffic?=" , Sun Haiyong , Junhao He , Tiezhu Yang , Yicong Yang , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-arm-kernel@lists.infradead.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Ensure parsing with and without PMU creates events with the expected config values. This ensures the tool.json doesn't get out of sync with tool_pmu_event enum. Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- tools/perf/tests/Build | 1 + tools/perf/tests/builtin-test.c | 1 + tools/perf/tests/tests.h | 1 + tools/perf/tests/tool_pmu.c | 111 ++++++++++++++++++++++++++++++++ 4 files changed, 114 insertions(+) create mode 100644 tools/perf/tests/tool_pmu.c diff --git a/tools/perf/tests/Build b/tools/perf/tests/Build index 5671ee530019..a771e4928247 100644 --- a/tools/perf/tests/Build +++ b/tools/perf/tests/Build @@ -67,6 +67,7 @@ perf-test-y +=3D sigtrap.o perf-test-y +=3D event_groups.o perf-test-y +=3D symbols.o perf-test-y +=3D util.o +perf-test-y +=3D tool_pmu.o =20 ifeq ($(SRCARCH),$(filter $(SRCARCH),x86 arm arm64 powerpc)) perf-test-$(CONFIG_DWARF_UNWIND) +=3D dwarf-unwind.o diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-tes= t.c index 470a9709427d..3b30f258c395 100644 --- a/tools/perf/tests/builtin-test.c +++ b/tools/perf/tests/builtin-test.c @@ -73,6 +73,7 @@ static struct test_suite *generic_tests[] =3D { &suite__PERF_RECORD, &suite__pmu, &suite__pmu_events, + &suite__tool_pmu, &suite__dso_data, &suite__perf_evsel__roundtrip_name_test, #ifdef HAVE_LIBTRACEEVENT diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h index 6ea2be86b7bf..1ed76d4156b6 100644 --- a/tools/perf/tests/tests.h +++ b/tools/perf/tests/tests.h @@ -83,6 +83,7 @@ DECLARE_SUITE(perf_evsel__tp_sched_test); DECLARE_SUITE(syscall_openat_tp_fields); DECLARE_SUITE(pmu); DECLARE_SUITE(pmu_events); +DECLARE_SUITE(tool_pmu); DECLARE_SUITE(attr); DECLARE_SUITE(dso_data); DECLARE_SUITE(dso_data_cache); diff --git a/tools/perf/tests/tool_pmu.c b/tools/perf/tests/tool_pmu.c new file mode 100644 index 000000000000..94d0dd8fd3cb --- /dev/null +++ b/tools/perf/tests/tool_pmu.c @@ -0,0 +1,111 @@ +// SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) +#include "debug.h" +#include "evlist.h" +#include "parse-events.h" +#include "tests.h" +#include "tool_pmu.h" + +static int do_test(enum tool_pmu_event ev, bool with_pmu) +{ + struct evlist *evlist =3D evlist__new(); + struct evsel *evsel; + struct parse_events_error err; + int ret; + char str[128]; + bool found =3D false; + + if (!evlist) { + pr_err("evlist allocation failed\n"); + return TEST_FAIL; + } + + if (with_pmu) + snprintf(str, sizeof(str), "tool/%s/", tool_pmu__event_to_str(ev)); + else + strncpy(str, tool_pmu__event_to_str(ev), sizeof(str)); + + parse_events_error__init(&err); + ret =3D parse_events(evlist, str, &err); + if (ret) { + evlist__delete(evlist); + if (tool_pmu__skip_event(tool_pmu__event_to_str(ev))) { + ret =3D TEST_OK; + goto out; + } + + pr_debug("FAILED %s:%d failed to parse event '%s', err %d\n", + __FILE__, __LINE__, str, ret); + parse_events_error__print(&err, str); + ret =3D TEST_FAIL; + goto out; + } + + ret =3D TEST_OK; + if (with_pmu ? (evlist->core.nr_entries !=3D 1) : (evlist->core.nr_entrie= s < 1)) { + pr_debug("FAILED %s:%d Unexpected number of events for '%s' of %d\n", + __FILE__, __LINE__, str, evlist->core.nr_entries); + ret =3D TEST_FAIL; + goto out; + } + + evlist__for_each_entry(evlist, evsel) { + if (perf_pmu__is_tool(evsel->pmu)) { + if (evsel->core.attr.config !=3D ev) { + pr_debug("FAILED %s:%d Unexpected config for '%s', %lld !=3D %d\n", + __FILE__, __LINE__, str, evsel->core.attr.config, ev); + ret =3D TEST_FAIL; + goto out; + } + found =3D true; + } + } + + if (!found && !tool_pmu__skip_event(tool_pmu__event_to_str(ev))) { + pr_debug("FAILED %s:%d Didn't find tool event '%s' in parsed evsels\n", + __FILE__, __LINE__, str); + ret =3D TEST_FAIL; + } + +out: + evlist__delete(evlist); + return ret; +} + +static int test__tool_pmu_without_pmu(struct test_suite *test __maybe_unus= ed, + int subtest __maybe_unused) +{ + int i; + + tool_pmu__for_each_event(i) { + int ret =3D do_test(i, /*with_pmu=3D*/false); + + if (ret !=3D TEST_OK) + return ret; + } + return TEST_OK; +} + +static int test__tool_pmu_with_pmu(struct test_suite *test __maybe_unused, + int subtest __maybe_unused) +{ + int i; + + tool_pmu__for_each_event(i) { + int ret =3D do_test(i, /*with_pmu=3D*/true); + + if (ret !=3D TEST_OK) + return ret; + } + return TEST_OK; +} + +static struct test_case tests__tool_pmu[] =3D { + TEST_CASE("Parsing without PMU name", tool_pmu_without_pmu), + TEST_CASE("Parsing with PMU name", tool_pmu_with_pmu), + { .name =3D NULL, } +}; + +struct test_suite suite__tool_pmu =3D { + .desc =3D "Tool PMU", + .test_cases =3D tests__tool_pmu, +}; --=20 2.46.0.662.g92d0881bb0-goog From nobody Sat Nov 30 02:52:27 2024 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.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 CF1551C2448 for ; Thu, 12 Sep 2024 19:04:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726167858; cv=none; b=Gixx7a7z+M+OfVMRhqZthX02Ctnva3vZ6/iFevghTvrpCa5+EAMXn0KEh82vAASrAplFwqpLEL8TCYsxiToMFNOwhDuW7eEQwNVdOLjQnDKTPvzMubnqXYykohvLF6CPIDl12zWJxUQcPx5rSbrz2EiTAVzmBJwzOb/G9xbhQNE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726167858; c=relaxed/simple; bh=dOHiJHinTURMOotqII3kGvV9NerIwi05Z+FqRJU6Bpk=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=FgwLfQwLx8WjdxfjVbTpawXjrcbbpshtn0jAy9sRePmUhNMF+6qtrPr2L52WQWq0pZGy6THmLFOQzQKFvSFPMEvMFN5sSP2XaFSV1kxofoZp1kTa34XWKIm7TcY8uQuU71ceWOBi6dq04KTc6garJ6JTJxF3+pMBRTTbCmMgv9Q= 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=W7W7DyIw; arc=none smtp.client-ip=209.85.128.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="W7W7DyIw" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6d3aa5a6715so3281867b3.2 for ; Thu, 12 Sep 2024 12:04:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1726167855; x=1726772655; 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=F0QjCacNbQoN6oM8iVP9OnKgMeij+BlfBlBP0ZY+ABo=; b=W7W7DyIwMgyA+Yb5pBLOqcQW7rTUPFN3/a1XqvMO6rzQckBoqG2nGAnw9fbXGq39NS hkFcsLFfVbNi/BbDzxQQFckOf5NXR+RO3B7LSpH6th1Gg/6ySsW48zINAbSGN6n9z2G1 VBX07IUTn780PJE3vQ4v8OnrfVpG1m5RBQAtnooS5MhObkRSwvyONo8FZvjda5UuxXNp s2JqhJNH4QYPqKlqQ37i5e4VFyY8Oe0ycByIoyw9BtC4u8G3Wc8J+Kza1eyBbtXo1tFk dSpIS7dz2Ntp93bupcsNuoGwT/z7yPXUKeaESc8NTJDf0tuLvhAt3jutf6yGjzN3QFl8 jO3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726167855; x=1726772655; 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=F0QjCacNbQoN6oM8iVP9OnKgMeij+BlfBlBP0ZY+ABo=; b=gJjwWxI9EBHrHrhJxoXT3+FExl/fzd4B1B3hHhwVeBONJI4kCVQP+iRJjGE3/MUHEm cLywY0Lor0rGgsBWCQpfhoxqtftyna0vINXpOgu9u6s+a5kK9wH9s2bHRdhe4XPtvh5b r+QG0MIRl6BkNpKl/T8wG3zFRoaVZVfhx8PbudJIdu8kbDptxGfZptekmSfuAVLZi6cp QItGYLZE3k4bxGrsEP2jHbtyEMmdRmZZrtjjZpoaT8WNYQmdZJnOjq9Gxr1wSQ2A0tpa Ly0igTfi3mHbjNf5XKHxZcGTMfMADNp7TmZL+cLDwt/sAWvUrpP1rEiKgRy8C7+RjTg6 JBBA== X-Forwarded-Encrypted: i=1; AJvYcCU/91PwtpKQ/HsbC/wrcS08MlnUJarYLdr5q+UqI9Q8lxxlSU5+V9z6Pyj5SBo1e7ti1/LJvoBq8QQJLno=@vger.kernel.org X-Gm-Message-State: AOJu0Yw7LiKyesZMbZIdzLkUv+ZEKYcM6Xm83fo00L2D4gwn4RQggJRy M0g8+vCI47++HXnOmbGBVyyZ4flWEamsXVrbofqOi5oepS6IeeefYbK/x+tLtNmRUc/2VUn+R8d wBn/Jug== X-Google-Smtp-Source: AGHT+IEUeoTNaPk9UEh9Qr2ajKs1iW7Lchn+DRe+ii7aVm3FjWDDV6vs/wOiR53MhsmSIE3fet0bImjpa0Hr X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:cf0e:7a99:e672:3862]) (user=irogers job=sendgmr) by 2002:a05:690c:640b:b0:6db:c34f:9e4f with SMTP id 00721157ae682-6dbcc59d518mr185027b3.8.1726167854979; Thu, 12 Sep 2024 12:04:14 -0700 (PDT) Date: Thu, 12 Sep 2024 12:03:38 -0700 In-Reply-To: <20240912190341.919229-1-irogers@google.com> Message-Id: <20240912190341.919229-12-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240912190341.919229-1-irogers@google.com> X-Mailer: git-send-email 2.46.0.662.g92d0881bb0-goog Subject: [PATCH v2 11/13] perf hwmon_pmu: Add a tool PMU exposing events from hwmon in sysfs 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 , John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Ravi Bangoria , Weilin Wang , Jing Zhang , Xu Yang , Sandipan Das , Benjamin Gray , Athira Jajeev , Howard Chu , Dominique Martinet , Yang Jihong , Colin Ian King , Veronika Molnarova , "Dr. David Alan Gilbert" , Oliver Upton , Changbin Du , Ze Gao , Andi Kleen , "=?UTF-8?q?Cl=C3=A9ment=20Le=20Goffic?=" , Sun Haiyong , Junhao He , Tiezhu Yang , Yicong Yang , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-arm-kernel@lists.infradead.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The hwmon sysfs ABI is defined in Documentation/hwmon/sysfs-interface.rst. Create a PMU that reads the hwmon input and can be used in `perf stat` and metrics much as an uncore PMU can. For example, the following shows reading the CPU temperature and 2 fan speeds alongside the uncore frequency: ``` $ perf stat -e temp_cpu,fan1,hwmon_thinkpad/fan2/,tool/num_cpus_online/ -M = UNCORE_FREQ -I 1000 1.001153138 52.00 'C temp_cpu 1.001153138 2,588 rpm fan1 1.001153138 2,482 rpm hwmon_thinkpad/fan2/ 1.001153138 8 tool/num_cpus_online/ 1.001153138 1,077,101,397 UNC_CLOCK.SOCKET #= 1.08 UNCORE_FREQ 1.001153138 1,012,773,595 duration_time ... ``` The PMUs are named from /sys/class/hwmon/hwmon/name and have an alias of hwmon. The events are naned using the _label files as well as the prefix, the latter guaranteed to be unique. In `perf list` the other hwmon files are used to give a richer description, for example: ``` hwmon: temp1 [Temperature in unit acpitz named temp1. Unit: hwmon_acpitz] in0 [Voltage in unit bat0 named in0. Unit: hwmon_bat0] temp_core_0 OR temp2 [Temperature in unit coretemp named Core 0. crit=3D100'C,max=3D100'C= crit_alarm=3D0'C. Unit: hwmon_coretemp] temp_core_1 OR temp3 [Temperature in unit coretemp named Core 1. crit=3D100'C,max=3D100'C= crit_alarm=3D0'C. Unit: hwmon_coretemp] ... temp_package_id_0 OR temp1 [Temperature in unit coretemp named Package id 0. crit=3D100'C,max= =3D100'C crit_alarm=3D0'C. Unit: hwmon_coretemp] temp1 [Temperature in unit iwlwifi_1 named temp1. Unit: hwmon_iwlwifi_1] temp_composite OR temp1 [Temperature in unit nvme named Composite. alarm=3D0'C,crit=3D86.85'= C,max=3D75.85'C, min=3D-273.15'C. Unit: hwmon_nvme] temp_sensor_1 OR temp2 [Temperature in unit nvme named Sensor 1. max=3D65261.8'C,min=3D-273= .15'C. Unit: hwmon_nvme] temp_sensor_2 OR temp3 [Temperature in unit nvme named Sensor 2. max=3D65261.8'C,min=3D-273= .15'C. Unit: hwmon_nvme] fan1 [Fan in unit thinkpad named fan1. Unit: hwmon_thinkpad] fan2 [Fan in unit thinkpad named fan2. Unit: hwmon_thinkpad] ... temp_cpu OR temp1 [Temperature in unit thinkpad named CPU. Unit: hwmon_thinkpad] temp_gpu OR temp2 [Temperature in unit thinkpad named GPU. Unit: hwmon_thinkpad] curr1 [Current in unit ucsi_source_psy_usbc000_0 named curr1. max=3D1.5A. = Unit: hwmon_ucsi_source_psy_usbc000_0] in0 [Voltage in unit ucsi_source_psy_usbc000_0 named in0. max=3D5V,min= =3D5V. Unit: hwmon_ucsi_source_psy_usbc000_0] ``` As there may be multiple hwmon devices a range of PMU types are reserved for their use and to identify the PMU as belonging to the hwmon types. Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- tools/perf/util/Build | 1 + tools/perf/util/evsel.c | 9 + tools/perf/util/hwmon_pmu.c | 818 ++++++++++++++++++++++++++++++++++++ tools/perf/util/hwmon_pmu.h | 154 +++++++ tools/perf/util/pmu.c | 20 + tools/perf/util/pmu.h | 2 + tools/perf/util/pmus.c | 2 + 7 files changed, 1006 insertions(+) create mode 100644 tools/perf/util/hwmon_pmu.c create mode 100644 tools/perf/util/hwmon_pmu.h diff --git a/tools/perf/util/Build b/tools/perf/util/Build index fa508e113dd0..9eb8b1c3df94 100644 --- a/tools/perf/util/Build +++ b/tools/perf/util/Build @@ -83,6 +83,7 @@ perf-util-y +=3D pmu.o perf-util-y +=3D pmus.o perf-util-y +=3D pmu-flex.o perf-util-y +=3D pmu-bison.o +perf-util-y +=3D hwmon_pmu.o perf-util-y +=3D tool_pmu.o perf-util-y +=3D svghelper.o perf-util-$(CONFIG_LIBTRACEEVENT) +=3D trace-event-info.o diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 9e748ed20988..64883d2aa1bb 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -50,6 +50,7 @@ #include "off_cpu.h" #include "pmu.h" #include "pmus.h" +#include "hwmon_pmu.h" #include "tool_pmu.h" #include "rlimit.h" #include "../perf-sys.h" @@ -1657,6 +1658,9 @@ int evsel__read_counter(struct evsel *evsel, int cpu_= map_idx, int thread) if (evsel__is_tool(evsel)) return evsel__tool_pmu_read(evsel, cpu_map_idx, thread); =20 + if (evsel__is_hwmon(evsel)) + return evsel__hwmon_pmu_read(evsel, cpu_map_idx, thread); + if (evsel__is_retire_lat(evsel)) return evsel__read_retire_lat(evsel, cpu_map_idx, thread); =20 @@ -2094,6 +2098,11 @@ static int evsel__open_cpu(struct evsel *evsel, stru= ct perf_cpu_map *cpus, start_cpu_map_idx, end_cpu_map_idx); } + if (evsel__is_hwmon(evsel)) { + return evsel__hwmon_pmu_open(evsel, threads, + start_cpu_map_idx, + end_cpu_map_idx); + } =20 for (idx =3D start_cpu_map_idx; idx < end_cpu_map_idx; idx++) { =20 diff --git a/tools/perf/util/hwmon_pmu.c b/tools/perf/util/hwmon_pmu.c new file mode 100644 index 000000000000..142584018a4f --- /dev/null +++ b/tools/perf/util/hwmon_pmu.c @@ -0,0 +1,818 @@ +// SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) +#include "counts.h" +#include "debug.h" +#include "evsel.h" +#include "hashmap.h" +#include "hwmon_pmu.h" +#include "pmu.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +const char * const hwmon_type_strs[HWMON_TYPE_MAX] =3D { + NULL, + "cpu", + "curr", + "energy", + "fan", + "humidity", + "in", + "intrusion", + "power", + "pwm", + "temp", +}; + +static const char *const hwmon_units[HWMON_TYPE_MAX] =3D { + NULL, + "V", /* cpu */ + "A", /* curr */ + "J", /* energy */ + "rpm", /* fan */ + "%", /* humidity */ + "V", /* in */ + "", /* intrusion */ + "W", /* power */ + "Hz", /* pwm */ + "'C", /* temp */ +}; + +const char * const hwmon_item_strs[HWMON_ITEM__MAX] =3D { + NULL, + "accuracy", + "alarm", + "auto_channels_temp", + "average", + "average_highest", + "average_interval", + "average_interval_max", + "average_interval_min", + "average_lowest", + "average_max", + "average_min", + "beep", + "cap", + "cap_hyst", + "cap_max", + "cap_min", + "crit", + "crit_hyst", + "div", + "emergency", + "emergency_hist", + "enable", + "fault", + "freq", + "highest", + "input", + "label", + "lcrit", + "lcrit_hyst", + "lowest", + "max", + "max_hyst", + "min", + "min_hyst", + "mod", + "offset", + "pulses", + "rated_max", + "rated_min", + "reset_history", + "target", + "type", + "vid", +}; + +struct hwmon_pmu { + struct perf_pmu pmu; + struct hashmap events; + int hwmon_dir_fd; +}; + +/** + * union hwmon_pmu_event_key: Key for hwmon_pmu->events as such each key + * represents an event. + * + * Related hwmon files start that this key represents. + */ +union hwmon_pmu_event_key { + long type_and_num; + struct { + int num :16; + enum hwmon_type type :8; + }; +}; + +/** + * struct hwmon_pmu_event_value: Value in hwmon_pmu->events. + * + * Hwmon files are of the form _ and may have a suffix + * _alarm. + */ +struct hwmon_pmu_event_value { + /** @items: which item files are present. */ + DECLARE_BITMAP(items, HWMON_ITEM__MAX); + /** @alarm_items: which item files are present. */ + DECLARE_BITMAP(alarm_items, HWMON_ITEM__MAX); + /** @label: contents of _label if present. */ + char *label; + /** @name: name computed from label of the form _