From nobody Sun Nov 24 07:32:10 2024 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E9D5B1CD202; Thu, 21 Nov 2024 10:20:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.176.79.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732184426; cv=none; b=LD/SrYJw4K+4fHFhS6efl0UYPj+6w2HbPK0k7sZn+MVBkFWuOaYP3M6u2JkwDRBY5TDzzAVp5oYsncAA8Pj3/grfQv9ut8AASYNzDiaLtsAN84QoYU+M7uCqpaaPhLz6QRuuCChjKxU64LqWiCO0K3Ebqi9bVNTE9a086nJUvRE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732184426; c=relaxed/simple; bh=wET4jVx2tdalfskgRlTBrhP5cfdwuvk8NCiNoM2i+Uw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=mec+IWymKtogHJr5rDR05Up2TumdidaEsCHCuXhSSFWotlQd8sA1t/7tMze8pSBxLLV4OE0uhUpHSY5GAlAbkvP6GmnY5x0hQyY4KQakrkLCfWTNjZqGEASxsGaYVZhHyi9lyZX5Zxff+tQKOmG/2r2CiTfjbD4USX+iK0BmBlw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=185.176.79.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.18.186.216]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4XvDkP70XHz6L74P; Thu, 21 Nov 2024 18:19:57 +0800 (CST) Received: from frapeml500008.china.huawei.com (unknown [7.182.85.71]) by mail.maildlp.com (Postfix) with ESMTPS id CBE59140A86; Thu, 21 Nov 2024 18:20:21 +0800 (CST) Received: from SecurePC-101-06.china.huawei.com (10.122.19.247) by frapeml500008.china.huawei.com (7.182.85.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Thu, 21 Nov 2024 11:20:20 +0100 From: Jonathan Cameron To: , , , CC: , , Yicong Yang , Niyas Sait , , Vandana Salve , Davidlohr Bueso , Dave Jiang , Alison Schofield , Ira Weiny , Dan Williams , Alexander Shishkin , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Gregory Price , Huang Ying Subject: [RFC PATCH 3/4] perf: Add support for CXL Hotness Monitoring Units (CHMU) Date: Thu, 21 Nov 2024 10:18:44 +0000 Message-ID: <20241121101845.1815660-4-Jonathan.Cameron@huawei.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241121101845.1815660-1-Jonathan.Cameron@huawei.com> References: <20241121101845.1815660-1-Jonathan.Cameron@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: lhrpeml500004.china.huawei.com (7.191.163.9) To frapeml500008.china.huawei.com (7.182.85.71) Content-Type: text/plain; charset="utf-8" Based closely on existing support for hisi_ptt. Provides basic record and report --dump-raw-traces support. Example output. With a counter_width of 16 (0x10) the least significant 4 bytes are the counter value and the unit index is bits 16-63. Here all units are over the threshold and the indexes are 0,1,2 etc. . ... CXL_HMU data: size 33512 bytes Header 0: units: 29c counter_width 10 Header 1 : deadbeef 0000000000000283 0000000000010364 0000000000020366 000000000003033c 0000000000040343 00000000000502ff 000000000006030d 000000000007031a Note this is definitely RFC quality code. Before merging should reduce the code duplication that already exists and this code makes sorse. Signed-off-by: Jonathan Cameron --- tools/perf/arch/arm/util/auxtrace.c | 58 +++++ tools/perf/arch/x86/util/auxtrace.c | 76 ++++++ tools/perf/util/Build | 1 + tools/perf/util/auxtrace.c | 4 + tools/perf/util/auxtrace.h | 1 + tools/perf/util/cxl-hmu.c | 367 ++++++++++++++++++++++++++++ tools/perf/util/cxl-hmu.h | 18 ++ 7 files changed, 525 insertions(+) diff --git a/tools/perf/arch/arm/util/auxtrace.c b/tools/perf/arch/arm/util= /auxtrace.c index 3b8eca0ffb17..07ff41800808 100644 --- a/tools/perf/arch/arm/util/auxtrace.c +++ b/tools/perf/arch/arm/util/auxtrace.c @@ -18,6 +18,7 @@ #include "cs-etm.h" #include "arm-spe.h" #include "hisi-ptt.h" +#include "cxl-hmu.h" =20 static struct perf_pmu **find_all_arm_spe_pmus(int *nr_spes, int *err) { @@ -99,6 +100,49 @@ static struct perf_pmu **find_all_hisi_ptt_pmus(int *nr= _ptts, int *err) return hisi_ptt_pmus; } =20 +static struct perf_pmu **find_all_cxl_hmu_pmus(int *nr_hmus, int *err) +{ + struct perf_pmu **cxl_hmu_pmus =3D NULL; + struct dirent *dent; + char path[PATH_MAX]; + DIR *dir =3D NULL; + int idx =3D 0; + + perf_pmu__event_source_devices_scnprintf(path, sizeof(path)); + dir =3D opendir(path); + if (!dir) { + *err =3D -EINVAL; + return NULL; + } + + while ((dent =3D readdir(dir))) { + if (strstr(dent->d_name, "cxl_hmu")) + (*nr_hmus)++; + } + + if (!(*nr_hmus)) + goto out; + + cxl_hmu_pmus =3D zalloc(sizeof(struct perf_pmu *) * (*nr_hmus)); + if (!cxl_hmu_pmus) { + *err =3D -ENOMEM; + goto out; + } + + rewinddir(dir); + while ((dent =3D readdir(dir))) { + if (strstr(dent->d_name, "cxl_hmu") && idx < *nr_hmus) { + cxl_hmu_pmus[idx] =3D perf_pmus__find(dent->d_name); + if (cxl_hmu_pmus[idx]) + idx++; + } + } + +out: + closedir(dir); + return cxl_hmu_pmus; +} + static struct perf_pmu *find_pmu_for_event(struct perf_pmu **pmus, int pmu_nr, struct evsel *evsel) { @@ -121,13 +165,16 @@ struct auxtrace_record struct perf_pmu *cs_etm_pmu =3D NULL; struct perf_pmu **arm_spe_pmus =3D NULL; struct perf_pmu **hisi_ptt_pmus =3D NULL; + struct perf_pmu **chmu_pmus =3D NULL; struct evsel *evsel; struct perf_pmu *found_etm =3D NULL; struct perf_pmu *found_spe =3D NULL; struct perf_pmu *found_ptt =3D NULL; + struct perf_pmu *found_chmu =3D NULL; int auxtrace_event_cnt =3D 0; int nr_spes =3D 0; int nr_ptts =3D 0; + int nr_chmus =3D 0; =20 if (!evlist) return NULL; @@ -135,6 +182,7 @@ struct auxtrace_record cs_etm_pmu =3D perf_pmus__find(CORESIGHT_ETM_PMU_NAME); arm_spe_pmus =3D find_all_arm_spe_pmus(&nr_spes, err); hisi_ptt_pmus =3D find_all_hisi_ptt_pmus(&nr_ptts, err); + chmu_pmus =3D find_all_cxl_hmu_pmus(&nr_chmus, err); =20 evlist__for_each_entry(evlist, evsel) { if (cs_etm_pmu && !found_etm) @@ -145,10 +193,14 @@ struct auxtrace_record =20 if (hisi_ptt_pmus && !found_ptt) found_ptt =3D find_pmu_for_event(hisi_ptt_pmus, nr_ptts, evsel); + + if (chmu_pmus && !found_chmu) + found_chmu =3D find_pmu_for_event(chmu_pmus, nr_chmus, evsel); } =20 free(arm_spe_pmus); free(hisi_ptt_pmus); + free(chmu_pmus); =20 if (found_etm) auxtrace_event_cnt++; @@ -159,6 +211,9 @@ struct auxtrace_record if (found_ptt) auxtrace_event_cnt++; =20 + if (found_chmu) + auxtrace_event_cnt++; + if (auxtrace_event_cnt > 1) { pr_err("Concurrent AUX trace operation not currently supported\n"); *err =3D -EOPNOTSUPP; @@ -174,6 +229,9 @@ struct auxtrace_record =20 if (found_ptt) return hisi_ptt_recording_init(err, found_ptt); + + if (found_chmu) + return chmu_recording_init(err, found_chmu); #endif =20 /* diff --git a/tools/perf/arch/x86/util/auxtrace.c b/tools/perf/arch/x86/util= /auxtrace.c index 354780ff1605..30d84ce41394 100644 --- a/tools/perf/arch/x86/util/auxtrace.c +++ b/tools/perf/arch/x86/util/auxtrace.c @@ -4,6 +4,7 @@ * Copyright (c) 2013-2014, Intel Corporation. */ =20 +#include #include #include =20 @@ -14,6 +15,7 @@ #include "../../../util/auxtrace.h" #include "../../../util/intel-pt.h" #include "../../../util/intel-bts.h" +#include "../../../util/cxl-hmu.h" #include "../../../util/evlist.h" =20 static @@ -51,14 +53,88 @@ struct auxtrace_record *auxtrace_record__init_intel(str= uct evlist *evlist, return NULL; } =20 +static struct perf_pmu **find_all_cxl_hmu_pmus(int *nr_hmus, int *err) +{ + struct perf_pmu **cxl_hmu_pmus =3D NULL; + struct dirent *dent; + char path[PATH_MAX]; + DIR *dir =3D NULL; + int idx =3D 0; + + perf_pmu__event_source_devices_scnprintf(path, sizeof(path)); + dir =3D opendir(path); + if (!dir) { + *err =3D -EINVAL; + return NULL; + } + + while ((dent =3D readdir(dir))) { + if (strstr(dent->d_name, "cxl_hmu")) + (*nr_hmus)++; + } + + if (!(*nr_hmus)) + goto out; + + cxl_hmu_pmus =3D zalloc(sizeof(struct perf_pmu *) * (*nr_hmus)); + if (!cxl_hmu_pmus) { + *err =3D -ENOMEM; + goto out; + } + + rewinddir(dir); + while ((dent =3D readdir(dir))) { + if (strstr(dent->d_name, "cxl_hmu") && idx < *nr_hmus) { + cxl_hmu_pmus[idx] =3D perf_pmus__find(dent->d_name); + if (cxl_hmu_pmus[idx]) + idx++; + } + } + +out: + closedir(dir); + return cxl_hmu_pmus; +} + +static struct perf_pmu *find_pmu_for_event(struct perf_pmu **pmus, + int pmu_nr, struct evsel *evsel) +{ + int i; + + if (!pmus) + return NULL; + + for (i =3D 0; i < pmu_nr; i++) { + if (evsel->core.attr.type =3D=3D pmus[i]->type) + return pmus[i]; + } + + return NULL; +} + struct auxtrace_record *auxtrace_record__init(struct evlist *evlist, int *err) { char buffer[64]; int ret; + struct perf_pmu **chmu_pmus =3D NULL; + struct perf_pmu *found_chmu =3D NULL; + struct evsel *evsel; + int nr_chmus =3D 0; =20 *err =3D 0; =20 + chmu_pmus =3D find_all_cxl_hmu_pmus(&nr_chmus, err); + + evlist__for_each_entry(evlist, evsel) { + if (chmu_pmus && !found_chmu) + found_chmu =3D find_pmu_for_event(chmu_pmus, nr_chmus, evsel); + } + free(chmu_pmus); + + if (found_chmu) + return chmu_recording_init(err, found_chmu); + ret =3D get_cpuid(buffer, sizeof(buffer)); if (ret) { *err =3D ret; diff --git a/tools/perf/util/Build b/tools/perf/util/Build index dc616292b2dd..40c645fd0cb3 100644 --- a/tools/perf/util/Build +++ b/tools/perf/util/Build @@ -127,6 +127,7 @@ perf-util-$(CONFIG_AUXTRACE) +=3D arm-spe.o perf-util-$(CONFIG_AUXTRACE) +=3D arm-spe-decoder/ perf-util-$(CONFIG_AUXTRACE) +=3D hisi-ptt.o perf-util-$(CONFIG_AUXTRACE) +=3D hisi-ptt-decoder/ +perf-util-$(CONFIG_AUXTRACE) +=3D cxl-hmu.o perf-util-$(CONFIG_AUXTRACE) +=3D s390-cpumsf.o =20 ifdef CONFIG_LIBOPENCSD diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c index ca8682966fae..0efc15732a03 100644 --- a/tools/perf/util/auxtrace.c +++ b/tools/perf/util/auxtrace.c @@ -53,6 +53,7 @@ #include "intel-bts.h" #include "arm-spe.h" #include "hisi-ptt.h" +#include "cxl-hmu.h" #include "s390-cpumsf.h" #include "util/mmap.h" =20 @@ -1333,6 +1334,9 @@ int perf_event__process_auxtrace_info(struct perf_ses= sion *session, case PERF_AUXTRACE_HISI_PTT: err =3D hisi_ptt_process_auxtrace_info(event, session); break; + case PERF_AUXTRACE_CXL_HMU: + err =3D cxl_hmu_process_auxtrace_info(event, session); + break; case PERF_AUXTRACE_UNKNOWN: default: return -EINVAL; diff --git a/tools/perf/util/auxtrace.h b/tools/perf/util/auxtrace.h index a1895a4f530b..8a7a5b7dc2d6 100644 --- a/tools/perf/util/auxtrace.h +++ b/tools/perf/util/auxtrace.h @@ -49,6 +49,7 @@ enum auxtrace_type { PERF_AUXTRACE_ARM_SPE, PERF_AUXTRACE_S390_CPUMSF, PERF_AUXTRACE_HISI_PTT, + PERF_AUXTRACE_CXL_HMU, }; =20 enum itrace_period_type { diff --git a/tools/perf/util/cxl-hmu.c b/tools/perf/util/cxl-hmu.c new file mode 100644 index 000000000000..31844f16e4f9 --- /dev/null +++ b/tools/perf/util/cxl-hmu.c @@ -0,0 +1,367 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * CXL HMU support + * Copyright (c) 2024 Huawei + * + * Based on: + * HiSilicon PCIe Trace and Tuning (PTT) support + * Copyright (c) 2022 HiSilicon Technologies Co., Ltd. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "auxtrace.h" +#include "color.h" +#include "debug.h" +#include "evlist.h" +#include "evsel.h" +#include "cxl-hmu.h" +#include "machine.h" +#include "record.h" +#include "session.h" +#include "tool.h" +#include "tsc.h" +#include + +#define KiB(x) ((x) * 1024) +#define MiB(x) ((x) * 1024 * 1024) + +struct chmu_recording { + struct auxtrace_record itr; + struct perf_pmu *chmu_pmu; + struct evlist *evlist; +}; + +static size_t +chmu_info_priv_size(struct auxtrace_record *itr __maybe_unused, + struct evlist *evlist __maybe_unused) +{ + return CXL_HMU_AUXTRACE_PRIV_SIZE; +} + +static int chmu_info_fill(struct auxtrace_record *itr, + struct perf_session *session, + struct perf_record_auxtrace_info *auxtrace_info, + size_t priv_size) +{ + struct chmu_recording *pttr =3D + container_of(itr, struct chmu_recording, itr); + struct perf_pmu *chmu_pmu =3D pttr->chmu_pmu; + + if (priv_size !=3D CXL_HMU_AUXTRACE_PRIV_SIZE) + return -EINVAL; + + if (!session->evlist->core.nr_mmaps) + return -EINVAL; + + auxtrace_info->type =3D PERF_AUXTRACE_CXL_HMU; + auxtrace_info->priv[0] =3D chmu_pmu->type; + + return 0; +} + +static int chmu_set_auxtrace_mmap_page(struct record_opts *opts) +{ + bool privileged =3D perf_event_paranoid_check(-1); + + if (!opts->full_auxtrace) + return 0; + + if (opts->full_auxtrace && !opts->auxtrace_mmap_pages) { + if (privileged) { + opts->auxtrace_mmap_pages =3D MiB(16) / page_size; + } else { + opts->auxtrace_mmap_pages =3D KiB(128) / page_size; + if (opts->mmap_pages =3D=3D UINT_MAX) + opts->mmap_pages =3D KiB(256) / page_size; + } + } + + /* Validate auxtrace_mmap_pages */ + if (opts->auxtrace_mmap_pages) { + size_t sz =3D opts->auxtrace_mmap_pages * (size_t)page_size; + size_t min_sz =3D KiB(8); + + if (sz < min_sz || !is_power_of_2(sz)) { + pr_err("Invalid mmap size for CXL_HMU: must be at least %zuKiB and a po= wer of 2\n", + min_sz / 1024); + return -EINVAL; + } + } + + return 0; +} + +static int chmu_recording_options(struct auxtrace_record *itr, + struct evlist *evlist, + struct record_opts *opts) +{ + struct chmu_recording *pttr =3D + container_of(itr, struct chmu_recording, itr); + struct perf_pmu *chmu_pmu =3D pttr->chmu_pmu; + struct evsel *evsel, *chmu_evsel =3D NULL; + struct evsel *tracking_evsel; + int err; + + pttr->evlist =3D evlist; + evlist__for_each_entry(evlist, evsel) { + if (evsel->core.attr.type =3D=3D chmu_pmu->type) { + if (chmu_evsel) { + pr_err("There may be only one cxl_hmu x event\n"); + return -EINVAL; + } + evsel->core.attr.freq =3D 0; + evsel->core.attr.sample_period =3D 1; + evsel->needs_auxtrace_mmap =3D true; + chmu_evsel =3D evsel; + opts->full_auxtrace =3D true; + } + } + + err =3D chmu_set_auxtrace_mmap_page(opts); + if (err) + return err; + /* + * To obtain the auxtrace buffer file descriptor, the auxtrace event + * must come first. + */ + evlist__to_front(evlist, chmu_evsel); + evsel__set_sample_bit(chmu_evsel, TIME); + + /* Add dummy event to keep tracking */ + err =3D parse_event(evlist, "dummy:u"); + if (err) + return err; + + tracking_evsel =3D evlist__last(evlist); + evlist__set_tracking_event(evlist, tracking_evsel); + + tracking_evsel->core.attr.freq =3D 0; + tracking_evsel->core.attr.sample_period =3D 1; + evsel__set_sample_bit(tracking_evsel, TIME); + + return 0; +} + +static u64 chmu_reference(struct auxtrace_record *itr __maybe_unused) +{ + return rdtsc(); +} + +static void chmu_recording_free(struct auxtrace_record *itr) +{ + struct chmu_recording *pttr =3D + container_of(itr, struct chmu_recording, itr); + + free(pttr); +} + +struct auxtrace_record *chmu_recording_init(int *err, + struct perf_pmu *chmu_pmu) +{ + struct chmu_recording *pttr; + + if (!chmu_pmu) { + *err =3D -ENODEV; + return NULL; + } + + pttr =3D zalloc(sizeof(*pttr)); + if (!pttr) { + *err =3D -ENOMEM; + return NULL; + } + + pttr->chmu_pmu =3D chmu_pmu; + pttr->itr.recording_options =3D chmu_recording_options; + pttr->itr.info_priv_size =3D chmu_info_priv_size; + pttr->itr.info_fill =3D chmu_info_fill; + pttr->itr.free =3D chmu_recording_free; + pttr->itr.reference =3D chmu_reference; + pttr->itr.read_finish =3D auxtrace_record__read_finish; + pttr->itr.alignment =3D 0; + + *err =3D 0; + return &pttr->itr; +} + +struct cxl_hmu { + struct auxtrace auxtrace; + u32 auxtrace_type; + struct perf_session *session; + struct machine *machine; + u32 pmu_type; +}; + +struct cxl_hmu_queue { + struct cxl_hmu *hmu; + struct auxtrace_buffer *buffer; +}; + +static void cxl_hmu_dump(struct cxl_hmu *hmu __maybe_unused, + unsigned char *buf, size_t len) +{ + const char *color =3D PERF_COLOR_BLUE; + size_t pos =3D 0; + size_t packet_offset =3D 0, hotlist_entries_in_packet; + + len =3D round_down(len, 8); + color_fprintf(stdout, color, ". ... CXL_HMU data: size %zu bytes\n", + len); + + while (len > 0) { + if (!packet_offset) { + hotlist_entries_in_packet =3D ((uint64_t *)(buf + pos))[0] & 0xFFFF; + color_fprintf(stdout, PERF_COLOR_BLUE, + "Header 0: units: %x counter_width %x\n", + hotlist_entries_in_packet, + (((uint64_t *)(buf + pos))[0] >> 16) & 0xFF); + } else if (packet_offset =3D=3D 1) { + color_fprintf(stdout, PERF_COLOR_BLUE, + "Header 1 : %lx\n", ((uint64_t *)(buf + pos))[0]); + } else { + color_fprintf(stdout, PERF_COLOR_BLUE, + "%016lx\n", ((uint64_t *)(buf + pos))[0]); + } + pos +=3D 8; + len -=3D 8; + packet_offset++; + if (packet_offset =3D=3D hotlist_entries_in_packet + 2) + packet_offset =3D 0; + } +} + +static void cxl_hmu_dump_event(struct cxl_hmu *hmu, unsigned char *buf, + size_t len) +{ + printf(".\n"); + + cxl_hmu_dump(hmu, buf, len); +} + +static int cxl_hmu_process_event(struct perf_session *session __maybe_unus= ed, + union perf_event *event __maybe_unused, + struct perf_sample *sample __maybe_unused, + const struct perf_tool *tool __maybe_unused) +{ + return 0; +} + +static int cxl_hmu_process_auxtrace_event(struct perf_session *session, + union perf_event *event, + const struct perf_tool *tool __maybe_unused) +{ + struct cxl_hmu *hmu =3D container_of(session->auxtrace, struct cxl_hmu, + auxtrace); + int fd =3D perf_data__fd(session->data); + int size =3D event->auxtrace.size; + void *data =3D malloc(size); + off_t data_offset; + int err; + + if (!data) { + printf("no data\n"); + return -errno; + } + + if (perf_data__is_pipe(session->data)) { + data_offset =3D 0; + } else { + data_offset =3D lseek(fd, 0, SEEK_CUR); + if (data_offset =3D=3D -1) { + free(data); + printf("failed to seek\n"); + return -errno; + } + } + + err =3D readn(fd, data, size); + if (err !=3D (ssize_t)size) { + free(data); + printf("failed to rread\n"); + return -errno; + } + + if (dump_trace) + cxl_hmu_dump_event(hmu, data, size); + + free(data); + return 0; +} + +static int cxl_hmu_flush(struct perf_session *session __maybe_unused, + const struct perf_tool *tool __maybe_unused) +{ + return 0; +} + +static void cxl_hmu_free_events(struct perf_session *session __maybe_unuse= d) +{ +} + +static void cxl_hmu_free(struct perf_session *session) +{ + struct cxl_hmu *hmu =3D container_of(session->auxtrace, struct cxl_hmu, + auxtrace); + + session->auxtrace =3D NULL; + free(hmu); +} + +static bool cxl_hmu_evsel_is_auxtrace(struct perf_session *session, + struct evsel *evsel) +{ + struct cxl_hmu *hmu =3D container_of(session->auxtrace, struct cxl_hmu, a= uxtrace); + + return evsel->core.attr.type =3D=3D hmu->pmu_type; +} + +static void cxl_hmu_print_info(__u64 type) +{ + if (!dump_trace) + return; + + fprintf(stdout, " PMU Type %" PRId64 "\n", (s64) type); +} + +int cxl_hmu_process_auxtrace_info(union perf_event *event, + struct perf_session *session) +{ + struct perf_record_auxtrace_info *auxtrace_info =3D &event->auxtrace_info; + struct cxl_hmu *hmu; + + if (auxtrace_info->header.size < CXL_HMU_AUXTRACE_PRIV_SIZE + + sizeof(struct perf_record_auxtrace_info)) + return -EINVAL; + + hmu =3D zalloc(sizeof(*hmu)); + if (!hmu) + return -ENOMEM; + + hmu->session =3D session; + hmu->machine =3D &session->machines.host; /* No kvm support */ + hmu->auxtrace_type =3D auxtrace_info->type; + hmu->pmu_type =3D auxtrace_info->priv[0]; + + hmu->auxtrace.process_event =3D cxl_hmu_process_event; + hmu->auxtrace.process_auxtrace_event =3D cxl_hmu_process_auxtrace_event; + hmu->auxtrace.flush_events =3D cxl_hmu_flush; + hmu->auxtrace.free_events =3D cxl_hmu_free_events; + hmu->auxtrace.free =3D cxl_hmu_free; + hmu->auxtrace.evsel_is_auxtrace =3D cxl_hmu_evsel_is_auxtrace; + session->auxtrace =3D &hmu->auxtrace; + + cxl_hmu_print_info(auxtrace_info->priv[0]); + + return 0; +} diff --git a/tools/perf/util/cxl-hmu.h b/tools/perf/util/cxl-hmu.h new file mode 100644 index 000000000000..9b4d83219711 --- /dev/null +++ b/tools/perf/util/cxl-hmu.h @@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * CXL Hotness Monitoring Unit Support + */ + +#ifndef INCLUDE__PERF_CXL_HMU_H__ +#define INCLUDE__PERF_CXL_HMU_H__ + +#define CXL_HMU_PMU_NAME "cxl_hmu" +#define CXL_HMU_AUXTRACE_PRIV_SIZE sizeof(u64) + +struct auxtrace_record *chmu_recording_init(int *err, + struct perf_pmu *cxl_hmu_pmu); + +int cxl_hmu_process_auxtrace_info(union perf_event *event, + struct perf_session *session); + +#endif --=20 2.43.0