From nobody Tue Nov 26 17:36:05 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 360891AC441 for ; Thu, 17 Oct 2024 06:36:10 +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=1729146971; cv=none; b=qqxdKAt3dJt+i3gpFwEDVPkRqAdTmkhWcl3GaQ7VUdDC342i+tnoXKa/wTaJVlF8pPLvBjd91xJGLADXceE67pdMRJS4a7r0woEOoo6ejNILTNN1z8cWh1ju4B+MeDVWV2sMoBZRQlJMMIaW6IW75uO6C32uIzqycSn2lR9RE14= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729146971; c=relaxed/simple; bh=n5VGbVbIfWopbvxBSE9Fbd9YTAZQp0tnb73cgCCPVDg=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=lbBX5V4GUXPeQAugs/5MYJT3t/NgKhJCT7kkLRgmxaL9BPA3XwqPw0+wjIwBMqFHoMS2RLttkzc8wrTeMavA0sQaODQUgiVG5ypXA/CDbX99mxiKwjRTClkvR1igFg/+/SBUoRL5rV1SJNT4Mmt4EnvvuXuLzNCAM+pNhDrwS9Q= 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=olL5O8j7; 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="olL5O8j7" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6e390b164c7so11943887b3.1 for ; Wed, 16 Oct 2024 23:36:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1729146969; x=1729751769; 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=zzleqe3kmLRg5+eGrbjz7UsbdXSTfhSGlheshYgrndY=; b=olL5O8j7Jm3VJr44WZN4KufMkeTF7SobO/oWZ1TaWgW1QMyDZaX311diCCnIzwvjHy ioIfI9653ee/9Mly4Mzbgzvtw0bsazvRe+xSS5GtamiPA4lS33AUSxyBFEexPGy8cvA+ 0OPWamxYPltszPCmEhCa3DPDN5QE3QHtcuG75yxtR0fWtOhgzwsbQBXibdKyXF3uGNZS g0JfRBNjgUNNIdRpIk6K+KTkvWfnJjWW4NSxqBx22ibrCmSGprow6dfY/GYaOOphDYtl KjFsn7Ejun8Aa9umsJwQh65Mex6oW5/u0hu/yHN8oMKBJs1KmCAA9C3m/EGlr3uAclaV /IEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729146969; x=1729751769; 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=zzleqe3kmLRg5+eGrbjz7UsbdXSTfhSGlheshYgrndY=; b=Kz68igjWGDaZlPgZ9zjbPxQM0aEU/nrWDq2gn9K6RjaeQDCaISpwdqSugzbIxDMOlv WO44Ejpve7spy0Lo2hfkOIRU4HEsL2XGjUrEduVDlexMdOeLXCHFLIRGZ/2H+KbBo0Mo FzSy7nrCNxGv5WUD+fz6y4iPyaZqL04Xeu5u47+b7v3R9H0rHRqe/l3NPRCswtxcQr5J G+bH0tnV9ppCAIPABEdLBDDGtNmhpBoEJBWRB5daAzs5GNYyBKxhMT3euzGjEKQdBaTi v/04LbGGgrOvck7RoQVLTJzanZjXXHv9s2OCvagIhS1BVNFyJGlr45KEwbuGUjc8qhC4 sWLw== X-Forwarded-Encrypted: i=1; AJvYcCXT40XaLRQpEGuMIVYBXRqJsu4ajOmdgd8s8h7uNlxt9kmXxBO9Dm1a7/oIAjLE7h/O2hqEt61oKZg08CI=@vger.kernel.org X-Gm-Message-State: AOJu0Yy6+2m03eFxl3uzEwQ7ZOdwud0PFiXF7GIbNMZVb5srQTtrq4kP 6bzZFqJkz5SkegUJfTUywc3mdHl4IzixZCjnTI1qFAqyygFohYrjjMrgMpxRKCOQtoFJRpjqE/F w+J/uvA== X-Google-Smtp-Source: AGHT+IG8CxRgZG8NMXRMmSnYhJ137xxxYI8PX+vj5KaN3IWd02e/50n0jvwu2BqWOmiH6x1Cw2jnrZIuWQzT X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:98a5:142e:8c2e:e9e5]) (user=irogers job=sendgmr) by 2002:a05:690c:6993:b0:6e3:f32:5fc8 with SMTP id 00721157ae682-6e3d3f80022mr1086047b3.1.1729146969132; Wed, 16 Oct 2024 23:36:09 -0700 (PDT) Date: Wed, 16 Oct 2024 23:35:53 -0700 In-Reply-To: <20241017063555.366065-1-irogers@google.com> Message-Id: <20241017063555.366065-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: <20241017063555.366065-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.105.g07ac214952-goog Subject: [PATCH v5 3/5] perf pmu: Add calls enabling the hwmon_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 , Ravi Bangoria , Weilin Wang , Yoshihiro Furudera , James Clark , Athira Jajeev , Howard Chu , Oliver Upton , Changbin Du , Ze Gao , Junhao He , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add the base PMU calls necessary for hwmon_pmu(s) to be created/deleted and events found, listed, opened and read. Signed-off-by: Ian Rogers --- tools/perf/util/evsel.c | 9 +++++++++ tools/perf/util/pmu.c | 20 ++++++++++++++++++++ tools/perf/util/pmus.c | 2 ++ 3 files changed, 31 insertions(+) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index ed0d4d20e357..f5e528a5d177 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" @@ -1680,6 +1681,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 @@ -2124,6 +2128,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/pmu.c b/tools/perf/util/pmu.c index 0789758598c0..a02df2c80f42 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -18,6 +18,7 @@ #include "debug.h" #include "evsel.h" #include "pmu.h" +#include "hwmon_pmu.h" #include "pmus.h" #include "tool_pmu.h" #include @@ -1529,6 +1530,9 @@ int perf_pmu__config_terms(const struct perf_pmu *pmu, { struct parse_events_term *term; =20 + if (perf_pmu__is_hwmon(pmu)) + return hwmon_pmu__config_terms(pmu, attr, terms, err); + list_for_each_entry(term, &terms->terms, list) { if (pmu_config_term(pmu, attr, term, terms, zero, apply_hardcoded, err)) return -EINVAL; @@ -1661,6 +1665,11 @@ int perf_pmu__check_alias(struct perf_pmu *pmu, stru= ct parse_events_terms *head_ info->scale =3D 0.0; info->snapshot =3D false; =20 + if (perf_pmu__is_hwmon(pmu)) { + ret =3D hwmon_pmu__check_alias(head_terms, info, err); + goto out; + } + /* Fake PMU doesn't rewrite terms. */ if (perf_pmu__is_fake(pmu)) goto out; @@ -1834,6 +1843,8 @@ bool perf_pmu__have_event(struct perf_pmu *pmu, const= char *name) return false; if (perf_pmu__is_tool(pmu) && tool_pmu__skip_event(name)) return false; + if (perf_pmu__is_hwmon(pmu)) + return hwmon_pmu__have_event(pmu, name); if (perf_pmu__find_alias(pmu, name, /*load=3D*/ true) !=3D NULL) return true; if (pmu->cpu_aliases_added || !pmu->events_table) @@ -1845,6 +1856,9 @@ size_t perf_pmu__num_events(struct perf_pmu *pmu) { size_t nr; =20 + if (perf_pmu__is_hwmon(pmu)) + return hwmon_pmu__num_events(pmu); + pmu_aliases_parse(pmu); nr =3D pmu->sysfs_aliases + pmu->sys_json_aliases; =20 @@ -1908,6 +1922,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_hwmon(pmu)) + return hwmon_pmu__for_each_event(pmu, state, cb); + strbuf_init(&sb, /*hint=3D*/ 0); pmu_aliases_parse(pmu); pmu_add_cpu_aliases(pmu); @@ -2303,6 +2320,9 @@ int perf_pmu__pathname_fd(int dirfd, const char *pmu_= name, const char *filename, =20 void perf_pmu__delete(struct perf_pmu *pmu) { + if (perf_pmu__is_hwmon(pmu)) + hwmon_pmu__exit(pmu); + perf_pmu__del_formats(&pmu->format); perf_pmu__del_aliases(pmu); perf_pmu__del_caps(pmu); diff --git a/tools/perf/util/pmus.c b/tools/perf/util/pmus.c index 107de86c2637..5c3e88adb9e6 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 "hwmon_pmu.h" #include "tool_pmu.h" #include "print-events.h" #include "strbuf.h" @@ -234,6 +235,7 @@ static void pmu_read_sysfs(bool core_only) if (!core_only) { tool_pmu =3D perf_pmus__tool_pmu(); list_add_tail(&tool_pmu->list, &other_pmus); + perf_pmus__read_hwmon_pmus(&other_pmus); } list_sort(NULL, &other_pmus, pmus_cmp); if (!list_empty(&core_pmus)) { --=20 2.47.0.105.g07ac214952-goog