From nobody Wed Dec 17 01:09:35 2025 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 36E4B41C6A for ; Wed, 17 Jul 2024 22:47:39 +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=1721256461; cv=none; b=VIgEKDIXhPqgPBOJl3GSTH9x86BZYgF/isDEXQeK1kIEyQDh6lh+BHMt80tCwCfA/kT1mr6rglxVqCa3cpSamxIPNGg4m0AJwzZO4ZbmlDRsPjGPI9+UlEkedu9ObDuVhD/DgIsJzNtlx3QHRZPajCzTWJQiI+YffnfQCGyLf+I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721256461; c=relaxed/simple; bh=wsjyhZb/PdOtvGe00zDU9jMHxWauNU8sJZPK/PLxFSE=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=jtoqxwG302w4bfJf+SJAzkeJ1E5ws/eh4aa6KV6XL8tsibTeS5+4CfewXjNP02J/WRSBObytoMkHU7/rWi15Z53HmEpv45EJDnDco7ZL3d0WVXlOAn77LRbvUKYkMt8xdLVhkFGp4SQJXEoKzLZ11mOSmuIxAzdhbMFiO80LUN8= 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=mkZC3Wm/; 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="mkZC3Wm/" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e036440617fso514566276.1 for ; Wed, 17 Jul 2024 15:47:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1721256458; x=1721861258; 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=VIiZO/q4iRQZ7Xs1eg6KNaj9S7BXW+wk4oVE8PU2qN4=; b=mkZC3Wm/ZEGrsFjtlijyHyGoj+jtUPcLrUOG8cTpDWViOO0+/F5nvYlP/kwg305B3d fZgWU14bYRbfy1PWNUgVa99mpEWjx8bs1TGBEJajt8w0ukeabq5crPWPVEqjFnBxZ+Jr duSPj7udoBCSi1dn9K/2vHFRO1H4t4ppRJMf4giU7fPb42Df+S7fUxLsjEOEdT58lkty vLi/EmOKswF3zWOBk41NNmfd3LloS6yHNSneEN3B02mPcaq389/0yfq9RQcl0XBhVOHF INv5WEUgWRS3TW+OVsCJirqSuMXjOi3N70rJH/JrpFQPFBTLuE32heIbPrPetQMfIORj Ponw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721256458; x=1721861258; 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=VIiZO/q4iRQZ7Xs1eg6KNaj9S7BXW+wk4oVE8PU2qN4=; b=nDsnEH7MJwhCH/Ep4n4Ow+mY4SnB27TLDdtZktEpjalRf3s5v0OnTafQsoSOsNrIet 4+VenKPEURMCsyf0jr+RCpuiz2RrBBWsFqscsKnFX78jD+QUihn9dK04Ld5OiFDobTCH N02+YVnEyoik3WhTf7X/iNRNxS7Nnp8462FkfHEGm1Lw6t1+uukRtKcctRGq718NtOhi ePeAJEKjj6GdeW1Z6hflJmg4eytNxy9d8Wrl0VlCxM8trXjkL3SyNvfiZL+8Gvsnf8az PH4gJxO1gk6BseAQwEEMPSys0Mgh+hoJiPmQCyXz/iTxquQNUbktk6R5O+PDCK6l8Che asZQ== X-Forwarded-Encrypted: i=1; AJvYcCXRZPpIfbghQm+bEQ1Rg5mZrTpkY2ui2zOdbkz4qZ+DPK1dhR3HOuS1JLI3JCfPVI09kpMVa29b24t2DRMg2LXt9vV1xXDY2ICPs2pY X-Gm-Message-State: AOJu0Yx6HhtEIP6OXWtcCIh9xBCFJktc14Fb3zgljupZaJVfv/5Qzitm NywaDNB514eFcTB+7eSpfLvoyzM9goZd/tlDpCh4cE1UoFunvr3XBM68kUSkSRyQ/Zshy2fbR99 Gkub1IA== X-Google-Smtp-Source: AGHT+IFnGIUQ2lhFZ36vDL4qvcmKR2SRBmLdlfHXveMflrvn4LzP54FxAZZnQ/WKEs62+RfsoHjLnbI9BV34 X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:940b:9044:fa83:4060]) (user=irogers job=sendgmr) by 2002:a05:6902:2d86:b0:e03:6405:7428 with SMTP id 3f1490d57ef6-e05febedf75mr2558276.12.1721256458202; Wed, 17 Jul 2024 15:47:38 -0700 (PDT) Date: Wed, 17 Jul 2024 15:47:27 -0700 In-Reply-To: <20240717224732.1465438-1-irogers@google.com> Message-Id: <20240717224732.1465438-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: <20240717224732.1465438-1-irogers@google.com> X-Mailer: git-send-email 2.45.2.1089.g2a221341d9-goog Subject: [PATCH v1 1/6] perf pmu: Merge boolean sysfs event option parsing 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 , Bjorn Helgaas , Jonathan Corbet , James Clark , Ravi Bangoria , Dominique Martinet , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Dhananjay Ugwekar , ananth.narayan@amd.com, gautham.shenoy@amd.com, kprateek.nayak@amd.com, sandipan.das@amd.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Merge perf_pmu__parse_per_pkg and perf_pmu__parse_snapshot that do the same parsing except for the file suffix used. Signed-off-by: Ian Rogers --- tools/perf/util/pmu.c | 47 +++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 986166bc7c78..5148b6639dd3 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -367,8 +367,8 @@ static int perf_pmu__parse_unit(struct perf_pmu *pmu, s= truct perf_pmu_alias *ali return -1; } =20 -static int -perf_pmu__parse_per_pkg(struct perf_pmu *pmu, struct perf_pmu_alias *alias) +static bool perf_pmu__parse_event_source_bool(const char *pmu_name, const = char *event_name, + const char *suffix) { char path[PATH_MAX]; size_t len; @@ -376,37 +376,36 @@ perf_pmu__parse_per_pkg(struct perf_pmu *pmu, struct = perf_pmu_alias *alias) =20 len =3D perf_pmu__event_source_devices_scnprintf(path, sizeof(path)); if (!len) - return 0; - scnprintf(path + len, sizeof(path) - len, "%s/events/%s.per-pkg", pmu->na= me, alias->name); + return false; + + scnprintf(path + len, sizeof(path) - len, "%s/events/%s.%s", pmu_name, ev= ent_name, suffix); =20 fd =3D open(path, O_RDONLY); if (fd =3D=3D -1) - return -1; + return false; =20 - close(fd); +#ifndef NDEBUG + { + char buf[8]; =20 - alias->per_pkg =3D true; - return 0; + len =3D read(fd, buf, sizeof(buf)); + assert(len =3D=3D 1 || len =3D=3D 2); + assert(buf[0] =3D=3D '1'); + } +#endif + + close(fd); + return true; } =20 -static int perf_pmu__parse_snapshot(struct perf_pmu *pmu, struct perf_pmu_= alias *alias) +static void perf_pmu__parse_per_pkg(struct perf_pmu *pmu, struct perf_pmu_= alias *alias) { - char path[PATH_MAX]; - size_t len; - int fd; - - len =3D perf_pmu__event_source_devices_scnprintf(path, sizeof(path)); - if (!len) - return 0; - scnprintf(path + len, sizeof(path) - len, "%s/events/%s.snapshot", pmu->n= ame, alias->name); - - fd =3D open(path, O_RDONLY); - if (fd =3D=3D -1) - return -1; + alias->per_pkg =3D perf_pmu__parse_event_source_bool(pmu->name, alias->na= me, "per-pkg"); +} =20 - alias->snapshot =3D true; - close(fd); - return 0; +static void perf_pmu__parse_snapshot(struct perf_pmu *pmu, struct perf_pmu= _alias *alias) +{ + alias->snapshot =3D perf_pmu__parse_event_source_bool(pmu->name, alias->n= ame, "snapshot"); } =20 /* Delete an alias entry. */ --=20 2.45.2.1089.g2a221341d9-goog From nobody Wed Dec 17 01:09:35 2025 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 3267D558BA for ; Wed, 17 Jul 2024 22:47:41 +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=1721256462; cv=none; b=HedmYuqJVy6VAQLbMBM6moAlpequOnYQ+c1cmXB7Rd0BjYalWNyNqYWl624YuyTTmRfQcKn0AKd0hd21Jat8lHhLJdRtH6SmFcgoc6J9lG60ScLH1Le38uY9rlM+JtMlhmVDSIreTWHqVsXPMGvkBAkGSPg7s0Bl7N6EgLPhwHU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721256462; c=relaxed/simple; bh=vuwys3K/PQPhgggx+tj8r4FNVlkm6yntFgCi4rPb+vk=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=Ro9Mvxl47oXZYv4+1qAd2aT4U3cyKCGspcQ2xjVJtUIosr5teurRInABJ7KI51BbwlZrGqGtMtvQnhl22/t4P8/c8ZZA+HRXnx+IIc/BA+9SFOeL0ko1tYpwBpEqGojNFeGipCyP8BEUwvjHeht+EkLHae4hkVXGMsrzWxBiTOQ= 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=g0UJet6E; 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="g0UJet6E" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e03a694ba5aso453810276.3 for ; Wed, 17 Jul 2024 15:47:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1721256460; x=1721861260; 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=N65oyWVRY7b5fCUl5B9UBHpg82AXZoHzAgm4Amx1vhc=; b=g0UJet6EXiUanAGVhXL6Qzhu/5nJ0foWBDyBjEfycXzC0+NB2uYLG43uFVngQiQM0G LP2Nw9MWTRH3YwchG+731TGu3Mlk/7wYWazOfrScL5QaT2aVmZ6c1b0IxoZ+CF0842qa ScV+ohueBSaGANjONDCYnzi9dCegpG5T/s3TzrLgjOf9sXwCzxpLkRRfvUgjqpKJ4GMN nJJuDTgyTZ2NkOh03D/LTx0H3vDJLRbXc98TnUDQBKR7j1W8fSdYFShXVLgKeynTuZ6B wrgwQQ31Cylc4ZtPWaUxR+ZSDPj7rJWR8h5TtDUy2w+jsJls+zVOe0l94JOSkWBHmvJz TPOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721256460; x=1721861260; 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=N65oyWVRY7b5fCUl5B9UBHpg82AXZoHzAgm4Amx1vhc=; b=F+uPyPstn7PqgvWTaz3+yAMSiRSDd1yJuRFWUvtQxVnIg16Ww322xlS3T+WIbqBOjd 8wIAQnLw1QWBnTXGnn3P4zv2ZfomCgEiPitxcWLW7ZICn+1q2kRhoJL5+JsERR3J+PeK M89CGpDkXQmjMV2M9KIZxhLRV6WTViivhGcILHYAeYUo9X8Op6wO1K03cHOAPkVq0bVV D0C86GR9vvKYrxC4uOJJvXCrFVfTrsYJecwSVFTweilyUTKaVIo3rIEhMjF3zSQMn1+m HJTdlnejMg2WXkzr+xjY6hJ7qTkRLRtlHuzNBi31MS7xVMWS6mXEhO5TBgzirxxO0X1o HyrA== X-Forwarded-Encrypted: i=1; AJvYcCU0BA1KUxuBqSVM0auiv2biiA7aNO/6Bfv02fIq0/s306CLQFkJKTPGR1wPLjC2lVu+K8X3paFpoyjQLFVUxYlLlokdvXuhpLwNhNdi X-Gm-Message-State: AOJu0Yw8iKiG2h+Air030NwqPzWDLcI0FOSInd/JZLF0Cm1iStUhIGW/ FdvZ6UZXrDhGL2Fno2bkoQicuUgmyK9TXti2Npg97WpieyeXn7BMYZELTDQbVNIj7nxmtvDgkqg +/NT9oA== X-Google-Smtp-Source: AGHT+IH9IZ2oWD57Fb/Y14t3IyFK8/OeCj7X6XeVHQP0ivJbYeNiSH3bPsPnwXLrXgMVdYiwKNmfMxPGD8al X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:940b:9044:fa83:4060]) (user=irogers job=sendgmr) by 2002:a05:6902:1024:b0:e02:c84e:61a3 with SMTP id 3f1490d57ef6-e05feb31053mr1385276.6.1721256460154; Wed, 17 Jul 2024 15:47:40 -0700 (PDT) Date: Wed, 17 Jul 2024 15:47:28 -0700 In-Reply-To: <20240717224732.1465438-1-irogers@google.com> Message-Id: <20240717224732.1465438-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: <20240717224732.1465438-1-irogers@google.com> X-Mailer: git-send-email 2.45.2.1089.g2a221341d9-goog Subject: [PATCH v1 2/6] perf parse-events: Pass cpu_list as a perf_cpu_map in __add_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 , Bjorn Helgaas , Jonathan Corbet , James Clark , Ravi Bangoria , Dominique Martinet , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Dhananjay Ugwekar , ananth.narayan@amd.com, gautham.shenoy@amd.com, kprateek.nayak@amd.com, sandipan.das@amd.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Previously the cpu_list is a string and typically no cpu_list is passed to __add_event. Wanting to make events have their cpus distinct from the PMU means that in more occassions we want to pass a cpu_list. If we're reading this from sysfs it is easier to read a perf_cpu_map than allocate and pass around strings that will later be parsed. Signed-off-by: Ian Rogers --- tools/perf/util/parse-events.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 321586fb5556..43501eb56336 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -227,12 +227,12 @@ __add_event(struct list_head *list, int *idx, bool init_attr, const char *name, const char *metric_id, struct perf_pmu *pmu, struct list_head *config_terms, bool auto_merge_stats, - const char *cpu_list) + struct perf_cpu_map *cpu_list) { struct evsel *evsel; - struct perf_cpu_map *cpus =3D pmu ? perf_cpu_map__get(pmu->cpus) : - cpu_list ? perf_cpu_map__new(cpu_list) : NULL; + struct perf_cpu_map *cpus =3D perf_cpu_map__is_empty(cpu_list) && pmu ? p= mu->cpus : cpu_list; =20 + cpus =3D perf_cpu_map__get(cpus); if (pmu) perf_pmu__warn_invalid_formats(pmu); =20 @@ -305,16 +305,17 @@ static int add_event_tool(struct list_head *list, int= *idx, .type =3D PERF_TYPE_SOFTWARE, .config =3D PERF_COUNT_SW_DUMMY, }; - const char *cpu_list =3D NULL; + struct perf_cpu_map *cpu_list =3D NULL; =20 if (tool_event =3D=3D PERF_TOOL_DURATION_TIME) { /* Duration time is gathered globally, pretend it is only on CPU0. */ - cpu_list =3D "0"; + 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; --=20 2.45.2.1089.g2a221341d9-goog From nobody Wed Dec 17 01:09:35 2025 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 CA4726EB56 for ; Wed, 17 Jul 2024 22:47:43 +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=1721256465; cv=none; b=jr89XZAKff/o79AyPfBc8fm+R/7u7hItBN5KI8WC5i6spGTbRnYmWxQJalgaqmk8JRXDiRBGAu3u4zT2lxj2VDNOZyDYg5DEfS/HtwiLrw1OCxLvMp9jOLS3oXusO2OM/DtZNJlBYyYCKW2ee7O9sdRKvuMrRx63PItXtY9Hxw8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721256465; c=relaxed/simple; bh=80YyIwk/8VkjU4yqstE1PlbqioOpSQzgF7vZUjQSVCE=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=LXAndY0HiWoP4Ux6qEnaVyptt2Kl+BAP+YyvFG0Tk3krO8frKcakJ9VUuKm4xbrQwpYd+vYbIr3P6f+AN9NdGIEU+ZHAR/567DPQNeSS+I3TyRm0WAKplyesmpJleEwP6+W+FLpag2RC+Sn+HDQCJG7AN1WNDLHb0YjnreA0KdE= 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=SG9xxzy/; 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="SG9xxzy/" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e036440617fso514682276.1 for ; Wed, 17 Jul 2024 15:47:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1721256463; x=1721861263; 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=gDSkmz2B6LUpQkGELdRI3zhIL2uXO0hylwMkxD4wWcI=; b=SG9xxzy/wajQ/YGJQxo3zLVuu+lccfADWcZRXbYCkL/rSXNdVMd1aas6cURTprbX98 89rPpOyYbaMRJTMtMkn64LvucJjaj2LIld9oQbUPkdOfm7D8WR3bCbuEPNAC+deLRRCx +TpL6HS3SPjH3CjrnqSsqQcmYv8m0XN97jc6GnuKtMxeZVzNZ7kWPo71fxhGdZlEwI3v +SoS7g26ooI971+5ed8Os586zdEY/aLCC0oZdyC+TkM4K8MzyGlqbdXYiwT0MqyRh9tn 4UxXPS0UkjEttFFlqCE9ioVfPccG1HYKnLNM6yRIyoUC+C3WLLOz7cmdC7q2lNuOpYwL HNUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721256463; x=1721861263; 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=gDSkmz2B6LUpQkGELdRI3zhIL2uXO0hylwMkxD4wWcI=; b=SskmjnNgJSpGh2yULI74Xidr2pc3KuRPkrkRb2DFyXPLTOi0b9j/LtmNf01zLyPDW9 0tBeZkMvf6GrYzeYNiJWLwfVpwsI62G0jXWdIanpScGUdlc5WJdb4B3pq6wJw0d7N0gS hndnkOufa5owbCRksRInaZNnajjaf7u2etmYxVcdxhvAmKBGy8qCRwXcFTUjTvFJ5LUP onzFJuyvQOx6UNUI3wAwaPglTFF0wb52In5sPRGV/gL5jVnOGlMFfbiZZegkKQAM38Lj hYXo8w2jAynl2RZirBbdPd/mYV+Un1d6WVwDiCkYuafsXTwNIq1Wkcsh0OkGVXyLdlvc kXrw== X-Forwarded-Encrypted: i=1; AJvYcCWO7gl1rcFsvdsbxVeS8u75CLfvGjO67Ft6BOfo7rwmj9XcIQYpkSlXR8k9d9ge/GpH3GFss65ijDSdenux0YFeoBoR7QL1nuFHRyo4 X-Gm-Message-State: AOJu0Ywyq3vMHvqQZXh7PTUcCv43tkOIuwUn3+iK2BsYZZ5uJS6szoZh Lo3fTTwAOAzQFKz2V6VQ/MmIAC88Ll+y5AY0e6a2DC1au5M/bVzJRc+niqjaqlZfwBCGagRiBOF BCWR0qw== X-Google-Smtp-Source: AGHT+IGKj/kxykoZFxJ3cI2Bub9eKPyxqwq4bQ8DkCCjCD7+sJhfPBqXbN5/mM1PE2I+5Av1eikzl4svPRF5 X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:940b:9044:fa83:4060]) (user=irogers job=sendgmr) by 2002:a05:6902:2d86:b0:e03:6405:7428 with SMTP id 3f1490d57ef6-e05febedf75mr2560276.12.1721256462309; Wed, 17 Jul 2024 15:47:42 -0700 (PDT) Date: Wed, 17 Jul 2024 15:47:29 -0700 In-Reply-To: <20240717224732.1465438-1-irogers@google.com> Message-Id: <20240717224732.1465438-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: <20240717224732.1465438-1-irogers@google.com> X-Mailer: git-send-email 2.45.2.1089.g2a221341d9-goog Subject: [PATCH v1 3/6] perf pmu: Add support for event.cpus files 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 , Bjorn Helgaas , Jonathan Corbet , James Clark , Ravi Bangoria , Dominique Martinet , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Dhananjay Ugwekar , ananth.narayan@amd.com, gautham.shenoy@amd.com, kprateek.nayak@amd.com, sandipan.das@amd.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" If an event file exists in sysfs, check if a event.cpus file exists and read a perf_cpu_map from it if it does. This allows particular events to have a different set of CPUs compared to the PMU. One scenario where this could be useful is when a PMU is set up with a cpumask/events per SMT thread but some events record for all SMT threads. Programming an event on each SMT thread will cause unnecessary counters to be programmed and the aggregate value to be too large. Another scenario where this could be useful if when a PMU has historically had a cpumask at the package level, but now newer per die, core or CPU information is available. Additional context for the motivation is in these patches and conversation: https://lore.kernel.org/lkml/20240711102436.4432-1-Dhananjay.Ugwekar@amd.co= m/ Signed-off-by: Ian Rogers --- .../sysfs-bus-event_source-devices-events | 14 ++++++ tools/perf/util/parse-events.c | 45 ++++++++++--------- tools/perf/util/pmu.c | 44 +++++++++++++++++- tools/perf/util/pmu.h | 1 + 4 files changed, 82 insertions(+), 22 deletions(-) diff --git a/Documentation/ABI/testing/sysfs-bus-event_source-devices-event= s b/Documentation/ABI/testing/sysfs-bus-event_source-devices-events index e7efeab2ee83..d8e3a4dd3ba7 100644 --- a/Documentation/ABI/testing/sysfs-bus-event_source-devices-events +++ b/Documentation/ABI/testing/sysfs-bus-event_source-devices-events @@ -70,6 +70,20 @@ Description: Per-pmu performance monitoring events speci= fic to the running syste This is referred to as "event parameterization". Event parameters have the format 'param=3D?'. =20 +What: /sys/bus/event_source/devices//events/.cpus +Date: 2024/07/17 +Contact: Linux kernel mailing list +Description: Perf event CPUs + + A list of CPUs on which a the perf event should be + opened by default. This is an event specific variant + of /sys/bus/event_source/devices//cpumask. + + Examples (each of these lines would be in a separate file): + + 0,2,4,6 + 0-7 + What: /sys/bus/event_source/devices//events/.unit Date: 2014/02/24 Contact: Linux kernel mailing list diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 43501eb56336..b181f83c9678 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -1425,12 +1425,13 @@ static int parse_events_add_pmu(struct parse_events= _state *parse_state, bool auto_merge_stats) { struct perf_event_attr attr; - struct perf_pmu_info info; + struct perf_pmu_info info =3D {}; struct evsel *evsel; struct parse_events_error *err =3D parse_state->error; LIST_HEAD(config_terms); struct parse_events_terms parsed_terms; bool alias_rewrote_terms =3D false; + int ret =3D 0; =20 if (verbose > 1) { struct strbuf sb; @@ -1465,8 +1466,7 @@ static int parse_events_add_pmu(struct parse_events_s= tate *parse_state, =20 parse_events_terms__init(&parsed_terms); if (const_parsed_terms) { - int ret =3D parse_events_terms__copy(const_parsed_terms, &parsed_terms); - + ret =3D parse_events_terms__copy(const_parsed_terms, &parsed_terms); if (ret) return ret; } @@ -1474,15 +1474,15 @@ static int parse_events_add_pmu(struct parse_events= _state *parse_state, =20 /* Configure attr/terms with a known PMU, this will set hardcoded terms. = */ if (config_attr(&attr, &parsed_terms, parse_state->error, config_term_pmu= )) { - parse_events_terms__exit(&parsed_terms); - return -EINVAL; + ret =3D -EINVAL; + goto out_err; } =20 /* Look for event names in the terms and rewrite into format based terms.= */ if (!parse_state->fake_pmu && perf_pmu__check_alias(pmu, &parsed_terms, &info, &alias_rewrote_terms, err)) { - parse_events_terms__exit(&parsed_terms); - return -EINVAL; + ret =3D -EINVAL; + goto out_err; } =20 if (verbose > 1) { @@ -1497,13 +1497,13 @@ static int parse_events_add_pmu(struct parse_events= _state *parse_state, /* Configure attr/terms again if an alias was expanded. */ if (alias_rewrote_terms && config_attr(&attr, &parsed_terms, parse_state->error, config_term_pmu= )) { - parse_events_terms__exit(&parsed_terms); - return -EINVAL; + ret =3D -EINVAL; + goto out_err; } =20 if (get_config_terms(&parsed_terms, &config_terms)) { - parse_events_terms__exit(&parsed_terms); - return -ENOMEM; + ret =3D -ENOMEM; + goto out_err; } =20 /* @@ -1512,24 +1512,23 @@ static int parse_events_add_pmu(struct parse_events= _state *parse_state, */ if (pmu->perf_event_attr_init_default && get_config_chgs(pmu, &parsed_terms, &config_terms)) { - parse_events_terms__exit(&parsed_terms); - return -ENOMEM; + ret =3D -ENOMEM; + goto out_err; } =20 if (!parse_state->fake_pmu && perf_pmu__config(pmu, &attr, &parsed_terms, parse_state->error)) { - free_config_terms(&config_terms); - parse_events_terms__exit(&parsed_terms); - return -EINVAL; + ret =3D -EINVAL; + goto out_err; } =20 evsel =3D __add_event(list, &parse_state->idx, &attr, /*init_attr=3D*/tru= e, get_config_name(&parsed_terms), get_config_metric_id(&parsed_terms), pmu, - &config_terms, auto_merge_stats, /*cpu_list=3D*/NULL); + &config_terms, auto_merge_stats, info.cpus); if (!evsel) { - parse_events_terms__exit(&parsed_terms); - return -ENOMEM; + ret =3D -ENOMEM; + goto out_err; } =20 if (evsel->name) @@ -1542,13 +1541,17 @@ static int parse_events_add_pmu(struct parse_events= _state *parse_state, return 0; } =20 - parse_events_terms__exit(&parsed_terms); free((char *)evsel->unit); evsel->unit =3D strdup(info.unit); evsel->scale =3D info.scale; evsel->per_pkg =3D info.per_pkg; evsel->snapshot =3D info.snapshot; - return 0; +out_err: + parse_events_terms__exit(&parsed_terms); + if (ret) + free_config_terms(&config_terms); + perf_cpu_map__put(info.cpus); + return ret; } =20 int parse_events_multi_pmu_add(struct parse_events_state *parse_state, diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 5148b6639dd3..280b2499c861 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -73,6 +73,11 @@ struct perf_pmu_alias { * differ from the PMU name as it won't have suffixes. */ char *pmu_name; + /** + * @cpus: A possible per-event cpumap that overrides that given for the + * PMU. + */ + struct perf_cpu_map *cpus; /** @unit: Units for the event, such as bytes or cache lines. */ char unit[UNIT_MAX_LEN+1]; /** @scale: Value to scale read counter values by. */ @@ -332,6 +337,32 @@ static int perf_pmu__parse_scale(struct perf_pmu *pmu,= struct perf_pmu_alias *al return ret; } =20 +static void perf_pmu__parse_cpus(struct perf_pmu *pmu, struct perf_pmu_ali= as *alias) +{ + char path[PATH_MAX]; + size_t len; + FILE *file; + int fd; + + len =3D perf_pmu__event_source_devices_scnprintf(path, sizeof(path)); + if (!len) + return; + scnprintf(path + len, sizeof(path) - len, "%s/events/%s.cpus", pmu->name,= alias->name); + + fd =3D open(path, O_RDONLY); + if (fd =3D=3D -1) + return; /* Expected common case. */ + + file =3D fdopen(fd, "r"); + if (!file) { + close(fd); + return; + } + + alias->cpus =3D perf_cpu_map__read(file); + fclose(file); +} + static int perf_pmu__parse_unit(struct perf_pmu *pmu, struct perf_pmu_alia= s *alias) { char path[PATH_MAX]; @@ -493,6 +524,7 @@ static void read_alias_info(struct perf_pmu *pmu, struc= t perf_pmu_alias *alias) /* * load unit name and scale if available */ + perf_pmu__parse_cpus(pmu, alias); perf_pmu__parse_unit(pmu, alias); perf_pmu__parse_scale(pmu, alias); perf_pmu__parse_per_pkg(pmu, alias); @@ -618,7 +650,7 @@ static inline bool pmu_alias_info_file(const char *name) size_t len; =20 len =3D strlen(name); - if (len > 5 && !strcmp(name + len - 5, ".unit")) + if (len > 5 && (!strcmp(name + len - 5, ".cpus") || !strcmp(name + len - = 5, ".unit"))) return true; if (len > 6 && !strcmp(name + len - 6, ".scale")) return true; @@ -1560,6 +1592,12 @@ static int check_info_data(struct perf_pmu *pmu, * define unit, scale and snapshot, fail * if there's more than one. */ + if (!perf_cpu_map__is_empty(info->cpus) && !perf_cpu_map__is_empty(alias-= >cpus)) { + parse_events_error__handle(err, column, + strdup("Attempt to set event's cpus twice"), + NULL); + return -EINVAL; + } if (info->unit && alias->unit[0]) { parse_events_error__handle(err, column, strdup("Attempt to set event's unit twice"), @@ -1579,6 +1617,9 @@ static int check_info_data(struct perf_pmu *pmu, return -EINVAL; } =20 + if (!perf_cpu_map__is_empty(alias->cpus)) + info->cpus =3D perf_cpu_map__get(alias->cpus); + if (alias->unit[0]) info->unit =3D alias->unit; =20 @@ -1610,6 +1651,7 @@ int perf_pmu__check_alias(struct perf_pmu *pmu, struc= t parse_events_terms *head_ * Mark unit and scale as not set * (different from default values, see below) */ + info->cpus =3D NULL; info->unit =3D NULL; info->scale =3D 0.0; info->snapshot =3D false; diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h index b2d3fd291f02..b1ccfe8d3df4 100644 --- a/tools/perf/util/pmu.h +++ b/tools/perf/util/pmu.h @@ -177,6 +177,7 @@ struct perf_pmu { extern struct perf_pmu perf_pmu__fake; =20 struct perf_pmu_info { + struct perf_cpu_map *cpus; const char *unit; double scale; bool per_pkg; --=20 2.45.2.1089.g2a221341d9-goog From nobody Wed Dec 17 01:09:35 2025 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 EE3D673459 for ; Wed, 17 Jul 2024 22:47:45 +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=1721256467; cv=none; b=WH4ytQN5rSDcM0peCCPieRKV6229WcSHgTgywaYapx4RfFgsPLN/tz8U4i/ZxBnFCop6+9ldSK9fVgRU21LO6rRApRDV20H347kxzYcuctSDDJLvieAQ3PWc4dBQUP1Dif7g4XF8Ub5cBVi/rj6VU7guKJlCiDcUMyQFYDlzFsw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721256467; c=relaxed/simple; bh=xO1LeDUwAlVEwZnVaFmHHPJ2GZce6TEJ/S7/OdCC7Zg=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=TuDBAbqj7T29zZjwuEMJU/JNfiIw3M+PX7a6hR1mVzWsB74LIrZWV6uz7pBn0Lv6nkEeYE0BB+1cBk76Px3dLlsnZRU8KPPDAkumcLcCh9xIAIknvuH6T7WXuCmHLXujfTMIK0zJ3nkpu/Z4yaqLD64ryVNnEsVjw5EArKn+zkY= 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=Lz9XADGm; 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="Lz9XADGm" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e05ec8921fdso445307276.1 for ; Wed, 17 Jul 2024 15:47:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1721256465; x=1721861265; 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=rpNlJN2SGII3MYeevUlf4p1OQiPVTTvbXe1jkW5mOAw=; b=Lz9XADGmqG5ApnzFw3PLMkAyHTwZV61OOTcQnV2szMHn7fxqQ+vm8JIlZE/f30PPyx FNpAQS8AwF0V1dX64OkayFWNoUznP98FBdT2btdYrhB0Sc3tPnCc9UZ1G5nSzTZUUBjF soBvwqTUiH4e+Zv3CYRre8mtRObHtG+s121IsBmhXNWyVONDV7bG0Fl3lVMmzzqaPhGU dVOPwldynZ2YFEfQH1jOimEgvVvzSlvPGHAdGpkqqPcV69liiuT1GL+4AngVJBzJHnv9 KI0FdQ/v46TksSSZIqYsyCZxLWdoUw7ZV5yt8jNXaTrghaIc7zBiwjp2lEOrXo2uOe64 O/LQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721256465; x=1721861265; 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=rpNlJN2SGII3MYeevUlf4p1OQiPVTTvbXe1jkW5mOAw=; b=YLrY8/V538UKPSN/zHjGBbxwqP/eZUkZeFgjYasEsKx0OIpaxir765acqgcSFopUgD b3VQfgCjX/WAu03bp0dnO52gsPff6PcftVsj5qiTUlcOJLb7hqxFDxlNIAFNGESK5gtC k6AuIEKMcyZmO0YTRd43PX//UQhy4wvIsDYp9GeckuD/LBNNqiWXxY6/ochGdCwTBvf2 72kIONjmHyv8zrZucBj1yYMXcDWMpOtELF7qlt0wk16kaFip9JsDRVQg1lx7rh0BhcgG zUcpH3Cclpi/hlOcBNHXC+Sz+PiYMeyDx3HLbmcGfM8LGhwCZFYcEuXTBzoqq2luXSaa 2OVA== X-Forwarded-Encrypted: i=1; AJvYcCVanhIlwL3cYs+TpsGt9QPAaA2hd9vM16QKSgo73Lb85BaHZOLJs+9NIIBczelegClXsbqY1GVyjWdl0XbA4EfDEpIWtAjh+OZFuWhd X-Gm-Message-State: AOJu0Yyr764dKIL1ZOySuAKcQlVsmDMOisc5uJbD3bO7d4XouunwRwF4 vBThYh4ugiNAcOVv9hqGk2ZHfIbxTrSp/3qEYuYZQqDsQgeo7LVNvDiB8CWrQGrvU6MNqKKFhVq 40Mr3NA== X-Google-Smtp-Source: AGHT+IHD579pgm3HArxrQGR94j4J3NgPiAcdglBtctueU/H6FmZ0a/dayddNY5G65oQ1POwqO65dBGQXMvHE X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:940b:9044:fa83:4060]) (user=irogers job=sendgmr) by 2002:a05:6902:1144:b0:e05:fd7c:9cfb with SMTP id 3f1490d57ef6-e05feb3769amr2480276.1.1721256464923; Wed, 17 Jul 2024 15:47:44 -0700 (PDT) Date: Wed, 17 Jul 2024 15:47:30 -0700 In-Reply-To: <20240717224732.1465438-1-irogers@google.com> Message-Id: <20240717224732.1465438-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: <20240717224732.1465438-1-irogers@google.com> X-Mailer: git-send-email 2.45.2.1089.g2a221341d9-goog Subject: [PATCH v1 4/6] libperf cpumap: Add ability to create CPU from a single CPU number 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 , Bjorn Helgaas , Jonathan Corbet , James Clark , Ravi Bangoria , Dominique Martinet , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Dhananjay Ugwekar , ananth.narayan@amd.com, gautham.shenoy@amd.com, kprateek.nayak@amd.com, sandipan.das@amd.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add perf_cpu_map__new_int so that a CPU map can be created from a single integer. Signed-off-by: Ian Rogers --- tools/lib/perf/cpumap.c | 10 ++++++++++ tools/lib/perf/include/perf/cpumap.h | 2 ++ 2 files changed, 12 insertions(+) diff --git a/tools/lib/perf/cpumap.c b/tools/lib/perf/cpumap.c index cae799ad44e1..2c8e36d0efaa 100644 --- a/tools/lib/perf/cpumap.c +++ b/tools/lib/perf/cpumap.c @@ -293,6 +293,16 @@ struct perf_cpu_map *perf_cpu_map__new(const char *cpu= _list) return cpus; } =20 +struct perf_cpu_map *perf_cpu_map__new_int(int cpu) +{ + struct perf_cpu_map *cpus =3D perf_cpu_map__alloc(1); + + if (cpus) + RC_CHK_ACCESS(cpus)->map[0].cpu =3D cpu; + + return cpus; +} + static int __perf_cpu_map__nr(const struct perf_cpu_map *cpus) { return RC_CHK_ACCESS(cpus)->nr; diff --git a/tools/lib/perf/include/perf/cpumap.h b/tools/lib/perf/include/= perf/cpumap.h index 90457d17fb2f..79ed3449d288 100644 --- a/tools/lib/perf/include/perf/cpumap.h +++ b/tools/lib/perf/include/perf/cpumap.h @@ -37,6 +37,8 @@ LIBPERF_API struct perf_cpu_map *perf_cpu_map__new_online= _cpus(void); * perf_cpu_map__new_online_cpus is returned. */ LIBPERF_API struct perf_cpu_map *perf_cpu_map__new(const char *cpu_list); +/** perf_cpu_map__new_int - create a map with the one given cpu. */ +LIBPERF_API struct perf_cpu_map *perf_cpu_map__new_int(int cpu); LIBPERF_API struct perf_cpu_map *perf_cpu_map__read(FILE *file); LIBPERF_API struct perf_cpu_map *perf_cpu_map__get(struct perf_cpu_map *ma= p); LIBPERF_API struct perf_cpu_map *perf_cpu_map__merge(struct perf_cpu_map *= orig, --=20 2.45.2.1089.g2a221341d9-goog From nobody Wed Dec 17 01:09:35 2025 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 762EC757FD for ; Wed, 17 Jul 2024 22:47:48 +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=1721256469; cv=none; b=Gabvq5zzwdAWgH/bcVY3nQVme/xvZY8iWGpYJ6l0yjAhwwSPlXflWAUuBVoa3FIRCiIPcxS8fFwQL7308ayiZ4TzEUl+gshoDC/agVW0BnscAgruxaFFzTVkCp6K/bOL95rBt97G7p0lI6cBSnTTOCsHpESUrHVzQQsWPv13NU8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721256469; c=relaxed/simple; bh=vXnQhbin+nQKx7EvHi/dTqGLgSRRVMsSgXeOitPIA0Q=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=CaJvJ0Wls1n+TGXUGgePzkELIc5+TncFl3rkRS8C65m5URR6yovGNSVv0zQSI24grrg/FF0xNTF3kEaY446/v/JGLZ9xpQ8GkQtcal+BkJhB2ODSKgkuiQx48Nz72rkH62Z1+d7mN/KukYjxI1iMMj/kvW3cDSDdz3D3TbMIJjE= 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=oaARsyLO; 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="oaARsyLO" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-664bc570740so5206787b3.0 for ; Wed, 17 Jul 2024 15:47:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1721256467; x=1721861267; 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=07dbUcOHVzfNvgP42n0WKJm07xg7m6Zt3c+s/XZJ4AY=; b=oaARsyLO0Ux/V9MwhYkcTVGv1HxifjRPi1+fAwjspRLxmHOB/2WcvbhvW9ZaWSZ5ot ErarQmtio/DzmuWjwz7gNtALd9PqBdpQicRsNGiEsAvurEVufEGt5bIaCNRrtK4v8ghx MH7wWlJ1/n9awX5fjA41uSlKUfPAaG+fItJmJSFmeYshCRhdN4hMYbDHGDVfjlgFjm+k vYS/E4L9XXlWZh9wX2CtslkY1W/w5q1YGoRoQAujF1NLHvDMpuQhI+sJ1zCbwa4x1Lg3 RIdOA34u6xQhqkmgkyHEQZtg/rOI3KkKb4a1f9NoxWbjq7FDyXa88AWbG12V4g8gXo6R x7OQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721256467; x=1721861267; 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=07dbUcOHVzfNvgP42n0WKJm07xg7m6Zt3c+s/XZJ4AY=; b=DkcQp7SQj0bbFFBgHZkKClYc8+nEsb1GATqNBOaXqwzP0848BaqmewTVc6KULTwJ68 E+hkS1wij40zj3+uuIRHHAr3BWMe+eGQ3HGj7nrhQI1Z73fSqcDX5G74HKD2vc4z2idO SMgT/BOWGD8Cr1efONCeG5jlsvcpHLbXnZfZwT5eqYunMddTyx2uF+2d9DPSr1deqCKB OHsyVWm4zAlM5hIXtA3ytbyfjaF/83WQEhLyTRjCagd8t6gUAex7N4RUVmQXssKHaslw hM2OlR/ueYrtNbVAHV5VjKWSP+HcMLe3S2/EYD2O8xelUXRGIcu4iS1ZkW5CsXAttcNd OmGA== X-Forwarded-Encrypted: i=1; AJvYcCX/KqP0gN/b8BDR1m6YTRdoP9dQpuWMlcpb2XY7BfIdw4l/8MQtyNVQyJIIAi9Feq9cEsWjliAvZon6/QpZhLTf0aj6bkZZQ0yZk6Zt X-Gm-Message-State: AOJu0YyLREdcLc7BgFwZv7jPIyrM5ObkD/Vozk1y6mfFkfkb1RO55y9t QHSXjTcaKJSEkusH9IOaNpqLSphrE7562zvqr0xUthJISnYd2kAfwqjq4uEytCKBx5MbHNXqUxn Mst8LnA== X-Google-Smtp-Source: AGHT+IEQzUOqt1R2zA4YoYl+BUWxXZw+FnH6EjlXC7f/QZ+1bZXaeM94zJuD8YbypGj3+TlpRIgWzUDjjvB2 X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:940b:9044:fa83:4060]) (user=irogers job=sendgmr) by 2002:a25:ce94:0:b0:e05:7113:920c with SMTP id 3f1490d57ef6-e05ff327141mr12295276.6.1721256467381; Wed, 17 Jul 2024 15:47:47 -0700 (PDT) Date: Wed, 17 Jul 2024 15:47:31 -0700 In-Reply-To: <20240717224732.1465438-1-irogers@google.com> Message-Id: <20240717224732.1465438-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: <20240717224732.1465438-1-irogers@google.com> X-Mailer: git-send-email 2.45.2.1089.g2a221341d9-goog Subject: [PATCH v1 5/6] perf parse-events: Set is_pmu_core for legacy hardware events 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 , Bjorn Helgaas , Jonathan Corbet , James Clark , Ravi Bangoria , Dominique Martinet , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Dhananjay Ugwekar , ananth.narayan@amd.com, gautham.shenoy@amd.com, kprateek.nayak@amd.com, sandipan.das@amd.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Also set the CPU map to all online CPU maps. This is done so the behavior of legacy hardware and hardware cache events better matches that of sysfs and json events during __perf_evlist__propagate_maps. Signed-off-by: Ian Rogers --- tools/perf/util/parse-events.c | 37 +++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index b181f83c9678..8c0c33361c5e 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -230,21 +230,30 @@ __add_event(struct list_head *list, int *idx, struct perf_cpu_map *cpu_list) { struct evsel *evsel; - struct perf_cpu_map *cpus =3D perf_cpu_map__is_empty(cpu_list) && pmu ? p= mu->cpus : cpu_list; + bool is_pmu_core; + struct perf_cpu_map *cpus; =20 - cpus =3D perf_cpu_map__get(cpus); - if (pmu) + if (pmu) { + is_pmu_core =3D pmu->is_core; + cpus =3D perf_cpu_map__get(perf_cpu_map__is_empty(cpu_list) ? pmu->cpus = : cpu_list); perf_pmu__warn_invalid_formats(pmu); - - if (pmu && (attr->type =3D=3D PERF_TYPE_RAW || attr->type >=3D PERF_TYPE_= MAX)) { - perf_pmu__warn_invalid_config(pmu, attr->config, name, - PERF_PMU_FORMAT_VALUE_CONFIG, "config"); - perf_pmu__warn_invalid_config(pmu, attr->config1, name, - PERF_PMU_FORMAT_VALUE_CONFIG1, "config1"); - perf_pmu__warn_invalid_config(pmu, attr->config2, name, - PERF_PMU_FORMAT_VALUE_CONFIG2, "config2"); - perf_pmu__warn_invalid_config(pmu, attr->config3, name, - PERF_PMU_FORMAT_VALUE_CONFIG3, "config3"); + if (attr->type =3D=3D PERF_TYPE_RAW || attr->type >=3D PERF_TYPE_MAX) { + perf_pmu__warn_invalid_config(pmu, attr->config, name, + PERF_PMU_FORMAT_VALUE_CONFIG, "config"); + perf_pmu__warn_invalid_config(pmu, attr->config1, name, + PERF_PMU_FORMAT_VALUE_CONFIG1, "config1"); + perf_pmu__warn_invalid_config(pmu, attr->config2, name, + PERF_PMU_FORMAT_VALUE_CONFIG2, "config2"); + perf_pmu__warn_invalid_config(pmu, attr->config3, name, + PERF_PMU_FORMAT_VALUE_CONFIG3, "config3"); + } + } else { + is_pmu_core =3D (attr->type =3D=3D PERF_TYPE_HARDWARE || + attr->type =3D=3D PERF_TYPE_HW_CACHE); + if (perf_cpu_map__is_empty(cpu_list)) + cpus =3D is_pmu_core ? perf_cpu_map__new_online_cpus() : NULL; + else + cpus =3D perf_cpu_map__get(cpu_list); } if (init_attr) event_attr_init(attr); @@ -259,7 +268,7 @@ __add_event(struct list_head *list, int *idx, evsel->core.cpus =3D cpus; evsel->core.own_cpus =3D perf_cpu_map__get(cpus); evsel->core.requires_cpu =3D pmu ? pmu->is_uncore : false; - evsel->core.is_pmu_core =3D pmu ? pmu->is_core : false; + evsel->core.is_pmu_core =3D is_pmu_core; evsel->auto_merge_stats =3D auto_merge_stats; evsel->pmu =3D pmu; evsel->pmu_name =3D pmu ? strdup(pmu->name) : NULL; --=20 2.45.2.1089.g2a221341d9-goog From nobody Wed Dec 17 01:09:35 2025 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 70441770E1 for ; Wed, 17 Jul 2024 22:47:50 +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=1721256475; cv=none; b=ZrMMokyNrhQ8ejfLXdAdNhRgUZaDJZbNBHT8yuUGGAMCPJrE8qTXgeZs0pCty3CQVNkgZ9lmKoCDVqwPg9nYVW2/+C3quVC1L0IfBtvIGZMQCwyiECZ1bMWxMSgRDZaP/Zus0kRXFRWdvuqxQ/BSEJdSN4ahktpk7uorY1VZah8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721256475; c=relaxed/simple; bh=qBZwJYtPOcxIBCuP7ed5zdH2CrVwWXLQho9fyByEv+Y=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=TCiVBAJa/YOqEmHAWSgHVc7vU3zyjMypJpgQXKIEzbXA96FFkV4EHyK2uuUhZSuUv44DrcbR1nfh2PbRNPs8FrWsJQmOq4SRC4jkJvvjgFIiPs2qMn5RxjDHOQ3KPylkwkBEjQnkxgnkl7hP8iJ7b5Luw/NqdAp6UEN3Bn33vlo= 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=OgAKtOqV; 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="OgAKtOqV" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-664fc7c4e51so2913097b3.3 for ; Wed, 17 Jul 2024 15:47:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1721256469; x=1721861269; 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=vTtg53qw4tgJTmr6Us6eL046MbK+xI+ua5J9nAvmPjM=; b=OgAKtOqVuSHhc2nBzoWacpfrTreWd2SPsiwvSSgHYNb4H9o8aBkTPp+yTiyCYbdXkE wg7omM9dbqcemwKjavKx92Wu8ouyZlqjhklPQRcDcFWQB+MOrHCgeCyPPISo5eHoxCpd RmvqkSx2A2WI4jcywr5sRDuItCJhXDRa38sxaY8BTOrSJ+wkIAOogJGy+lx8kFRO12JT XDQHfWkEZwXtFCdzro2IRnTjZQs+VDyfqdxisow2oF2vT4YOI3B7BTD1E2ufqqZkDwdD xxntwx62oIRdGGbFsm6tPCrMUWGFa0ylVEmqUZmaxWESt7drXGrqbbTBf1OR5RYOeQVB Y2Ow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721256469; x=1721861269; 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=vTtg53qw4tgJTmr6Us6eL046MbK+xI+ua5J9nAvmPjM=; b=eloVIvHVAYYc1pacP4oNkQ6lb+qMnY1nN1sjH7jgV5Izxogpdy5YdMGumb0/RImWKl JmvAo3I/CF80alMP95KLKRgrlkltov4AZZvlHLojcPRhbAC0egsRaXcxwXytdZxf8aR2 Ecsa/zXdfjnyVoVoLY6qXiQzIfvttN5xi9q5fwYP17d1oMXgXLpj3MTCQmOOPDGM57VY V1nt0YaG6duFQrV7dBEy5X1NKn5/3txPwSVXDV+yLwCjHBW8sxxxZxQvz9nCafXfPcPb kWrKe2bmy3g4A/D/66x/WrPJ2ON3la9anU80f9JRBtlO/+NbZgCdJdEF3FIBq2kvQANK 3g8w== X-Forwarded-Encrypted: i=1; AJvYcCWTTiR/C6SKFblgIJoRnFFL3HlpJRY2SstCokPhWhlu4f6vl9GU/sNO/Qm1KddDL5bLAIzHNcCHHqMRuTGrPgCuVIHDUnj9ISqQoAVe X-Gm-Message-State: AOJu0Yz5ozSBxflDu25mMu+A1mFmrRzRHsW4IJit81sQ0BATA25JUUxm i9BELRoZwLGQs/ZnYD4SRA7BrLE6AkCmQwaGYJg3YMZdbWtyOUwMVoDAUMeDJ0sb9GH3trfi24Q gliDBUA== X-Google-Smtp-Source: AGHT+IHSSm/ii+Q0fgt4XLFitdB1ypO5rslVKkP/tfVh0SU4SEkUts8F4aIanL2ZyIAoPo/haz2HT5H/KQUa X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:940b:9044:fa83:4060]) (user=irogers job=sendgmr) by 2002:a05:690c:102:b0:62f:f535:f41 with SMTP id 00721157ae682-666042bc655mr690957b3.9.1721256469548; Wed, 17 Jul 2024 15:47:49 -0700 (PDT) Date: Wed, 17 Jul 2024 15:47:32 -0700 In-Reply-To: <20240717224732.1465438-1-irogers@google.com> Message-Id: <20240717224732.1465438-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: <20240717224732.1465438-1-irogers@google.com> X-Mailer: git-send-email 2.45.2.1089.g2a221341d9-goog Subject: [PATCH v1 6/6] perf parse-events: Add "cpu" term to set the CPU an event is recorded on 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 , Bjorn Helgaas , Jonathan Corbet , James Clark , Ravi Bangoria , Dominique Martinet , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Dhananjay Ugwekar , ananth.narayan@amd.com, gautham.shenoy@amd.com, kprateek.nayak@amd.com, sandipan.das@amd.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The -C option allows the CPUs for a list of events to be specified but its not possible to set the CPU for a single event. Add a term to allow this. The term isn't a general CPU list due to ',' already being a special character in event parsing. An example of mixing different types of events counted on different CPUs: ``` $ perf stat -A -C 0,4,8 -e "instructions/cpu=3D0/,l1d-misses/cpu=3D4/,inst_= retired.any/cpu=3D8/,cycles" -a sleep 0.1 Performance counter stats for 'system wide': CPU0 419,426 instructions/cpu=3D0/ # 0.25= insn per cycle CPU4 instructions/cpu=3D0/ CPU8 instructions/cpu=3D0/ CPU0 l1d-misses [cpu] CPU4 45,574 l1d-misses [cpu] CPU8 l1d-misses [cpu] CPU0 cpu/cpu=3D8/ CPU4 cpu/cpu=3D8/ CPU8 164,073 cpu/cpu=3D8/ CPU0 1,689,993 cycles CPU4 5,204,403 cycles CPU8 668,986 cycles ``` An example of spreading uncore overhead across two CPUs: ``` $ perf stat -A -e "data_read/cpu=3D0/,data_write/cpu=3D1/" -a sleep 0.1 Performance counter stats for 'system wide': CPU0 223.65 MiB uncore_imc_free_running_0/cpu=3D0/ CPU0 223.66 MiB uncore_imc_free_running_1/cpu=3D0/ CPU0 MiB uncore_imc_free_running_0/cpu=3D1/ CPU1 5.78 MiB uncore_imc_free_running_0/cpu=3D1/ CPU0 MiB uncore_imc_free_running_1/cpu=3D1/ CPU1 5.74 MiB uncore_imc_free_running_1/cpu=3D1/ ``` Note, the event names are missing as there are unmerged uniquify fixes like: https://lore.kernel.org/lkml/20240510053705.2462258-3-irogers@google.com/ Manually fixing the output should be: ``` CPU0 223.65 MiB uncore_imc_free_running_0/data_read,cpu=3D0/ CPU0 223.66 MiB uncore_imc_free_running_1/data_read,cpu=3D0/ CPU1 5.78 MiB uncore_imc_free_running_0/data_write,cpu=3D1/ CPU1 5.74 MiB uncore_imc_free_running_1/data_write,cpu=3D1/ ``` That is data_read from 2 PMUs was read on CPU0 and data_write was read on CPU1. Signed-off-by: Ian Rogers --- tools/perf/Documentation/perf-list.txt | 7 +++ tools/perf/util/evsel_config.h | 1 + tools/perf/util/parse-events.c | 67 ++++++++++++++++++++++---- tools/perf/util/parse-events.h | 3 +- tools/perf/util/parse-events.l | 1 + tools/perf/util/pmu.c | 1 + 6 files changed, 69 insertions(+), 11 deletions(-) diff --git a/tools/perf/Documentation/perf-list.txt b/tools/perf/Documentat= ion/perf-list.txt index 6bf2468f59d3..abbff01665eb 100644 --- a/tools/perf/Documentation/perf-list.txt +++ b/tools/perf/Documentation/perf-list.txt @@ -273,6 +273,13 @@ Sums up the event counts for all hardware threads in a= core, e.g.: =20 perf stat -e cpu/event=3D0,umask=3D0x3,percore=3D1/ =20 +cpu: + +Specifies the CPU to open the event upon: + + + perf stat -e data_read/cpu=3D0/,data_write/cpu=3D1/ -a sleep 1 + =20 EVENT GROUPS ------------ diff --git a/tools/perf/util/evsel_config.h b/tools/perf/util/evsel_config.h index aee6f808b512..9630c4a24721 100644 --- a/tools/perf/util/evsel_config.h +++ b/tools/perf/util/evsel_config.h @@ -47,6 +47,7 @@ struct evsel_config_term { u32 aux_sample_size; u64 cfg_chg; char *str; + int cpu; } val; bool weak; }; diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 8c0c33361c5e..86d074aa6c9a 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -7,6 +7,7 @@ #include #include #include +#include "cpumap.h" #include "term.h" #include "evlist.h" #include "evsel.h" @@ -177,6 +178,20 @@ static char *get_config_name(const struct parse_events= _terms *head_terms) return get_config_str(head_terms, PARSE_EVENTS__TERM_TYPE_NAME); } =20 +static struct perf_cpu_map *get_config_cpu(const struct parse_events_terms= *head_terms) +{ + struct parse_events_term *term; + + if (!head_terms) + return NULL; + + list_for_each_entry(term, &head_terms->terms, list) + if (term->type_term =3D=3D PARSE_EVENTS__TERM_TYPE_CPU) + return perf_cpu_map__new_int(term->val.num); + + return NULL; +} + /** * fix_raw - For each raw term see if there is an event (aka alias) in pmu= that * matches the raw's string value. If the string value matches an @@ -468,11 +483,12 @@ int parse_events_add_cache(struct list_head *list, in= t *idx, const char *name, bool found_supported =3D false; const char *config_name =3D get_config_name(parsed_terms); const char *metric_id =3D get_config_metric_id(parsed_terms); + struct perf_cpu_map *cpus =3D get_config_cpu(parsed_terms); + int ret =3D 0; =20 while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { LIST_HEAD(config_terms); struct perf_event_attr attr; - int ret; =20 if (parse_events__filter_pmu(parse_state, pmu)) continue; @@ -486,7 +502,7 @@ int parse_events_add_cache(struct list_head *list, int = *idx, const char *name, parsed_terms, perf_pmu__auto_merge_stats(pmu)); if (ret) - return ret; + goto out_err; continue; } =20 @@ -506,20 +522,27 @@ int parse_events_add_cache(struct list_head *list, in= t *idx, const char *name, =20 if (parsed_terms) { if (config_attr(&attr, parsed_terms, parse_state->error, - config_term_common)) - return -EINVAL; - - if (get_config_terms(parsed_terms, &config_terms)) - return -ENOMEM; + config_term_common)) { + ret =3D -EINVAL; + goto out_err; + } + if (get_config_terms(parsed_terms, &config_terms)) { + ret =3D -ENOMEM; + goto out_err; + } } =20 if (__add_event(list, idx, &attr, /*init_attr*/true, config_name ?: name, metric_id, pmu, &config_terms, /*auto_merge_stats=3D*/false, - /*cpu_list=3D*/NULL) =3D=3D NULL) - return -ENOMEM; + cpus) =3D=3D NULL) + ret =3D -ENOMEM; =20 free_config_terms(&config_terms); + if (ret) + goto out_err; } +out_err: + perf_cpu_map__put(cpus); return found_supported ? 0 : -EINVAL; } =20 @@ -814,6 +837,7 @@ static const char *config_term_name(enum parse_events__= term_type term_type) [PARSE_EVENTS__TERM_TYPE_RAW] =3D "raw", [PARSE_EVENTS__TERM_TYPE_LEGACY_CACHE] =3D "legacy-cache", [PARSE_EVENTS__TERM_TYPE_HARDWARE] =3D "hardware", + [PARSE_EVENTS__TERM_TYPE_CPU] =3D "cpu", }; if ((unsigned int)term_type >=3D __PARSE_EVENTS__TERM_TYPE_NR) return "unknown term"; @@ -843,6 +867,7 @@ config_term_avail(enum parse_events__term_type term_typ= e, struct parse_events_er case PARSE_EVENTS__TERM_TYPE_METRIC_ID: case PARSE_EVENTS__TERM_TYPE_SAMPLE_PERIOD: case PARSE_EVENTS__TERM_TYPE_PERCORE: + case PARSE_EVENTS__TERM_TYPE_CPU: return true; case PARSE_EVENTS__TERM_TYPE_USER: case PARSE_EVENTS__TERM_TYPE_SAMPLE_FREQ: @@ -986,6 +1011,15 @@ do { \ return -EINVAL; } break; + case PARSE_EVENTS__TERM_TYPE_CPU: + CHECK_TYPE_VAL(NUM); + if (term->val.num >=3D (u64)cpu__max_present_cpu().cpu) { + parse_events_error__handle(err, term->err_val, + strdup("too big"), + NULL); + return -EINVAL; + } + break; case PARSE_EVENTS__TERM_TYPE_DRV_CFG: case PARSE_EVENTS__TERM_TYPE_USER: case PARSE_EVENTS__TERM_TYPE_LEGACY_CACHE: @@ -1112,6 +1146,7 @@ static int config_term_tracepoint(struct perf_event_a= ttr *attr, case PARSE_EVENTS__TERM_TYPE_RAW: case PARSE_EVENTS__TERM_TYPE_LEGACY_CACHE: case PARSE_EVENTS__TERM_TYPE_HARDWARE: + case PARSE_EVENTS__TERM_TYPE_CPU: default: if (err) { parse_events_error__handle(err, term->err_term, @@ -1243,6 +1278,7 @@ do { \ case PARSE_EVENTS__TERM_TYPE_RAW: case PARSE_EVENTS__TERM_TYPE_LEGACY_CACHE: case PARSE_EVENTS__TERM_TYPE_HARDWARE: + case PARSE_EVENTS__TERM_TYPE_CPU: default: break; } @@ -1296,6 +1332,7 @@ static int get_config_chgs(struct perf_pmu *pmu, stru= ct parse_events_terms *head case PARSE_EVENTS__TERM_TYPE_RAW: case PARSE_EVENTS__TERM_TYPE_LEGACY_CACHE: case PARSE_EVENTS__TERM_TYPE_HARDWARE: + case PARSE_EVENTS__TERM_TYPE_CPU: default: break; } @@ -1350,6 +1387,7 @@ static int __parse_events_add_numeric(struct parse_ev= ents_state *parse_state, struct perf_event_attr attr; LIST_HEAD(config_terms); const char *name, *metric_id; + struct perf_cpu_map *cpus; int ret; =20 memset(&attr, 0, sizeof(attr)); @@ -1371,9 +1409,11 @@ static int __parse_events_add_numeric(struct parse_e= vents_state *parse_state, =20 name =3D get_config_name(head_config); metric_id =3D get_config_metric_id(head_config); + cpus =3D get_config_cpu(head_config); ret =3D __add_event(list, &parse_state->idx, &attr, /*init_attr*/true, na= me, metric_id, pmu, &config_terms, /*auto_merge_stats=3D*/false, - /*cpu_list=3D*/NULL) ? 0 : -ENOMEM; + cpus) ? 0 : -ENOMEM; + perf_cpu_map__put(cpus); free_config_terms(&config_terms); return ret; } @@ -1440,6 +1480,7 @@ static int parse_events_add_pmu(struct parse_events_s= tate *parse_state, LIST_HEAD(config_terms); struct parse_events_terms parsed_terms; bool alias_rewrote_terms =3D false; + struct perf_cpu_map *term_cpu =3D NULL; int ret =3D 0; =20 if (verbose > 1) { @@ -1531,6 +1572,12 @@ static int parse_events_add_pmu(struct parse_events_= state *parse_state, goto out_err; } =20 + term_cpu =3D get_config_cpu(&parsed_terms); + if (!perf_cpu_map__is_empty(term_cpu)) { + perf_cpu_map__put(info.cpus); + info.cpus =3D term_cpu; + term_cpu =3D NULL; + } evsel =3D __add_event(list, &parse_state->idx, &attr, /*init_attr=3D*/tru= e, get_config_name(&parsed_terms), get_config_metric_id(&parsed_terms), pmu, diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h index e13de2c8b706..b03857499030 100644 --- a/tools/perf/util/parse-events.h +++ b/tools/perf/util/parse-events.h @@ -79,7 +79,8 @@ enum parse_events__term_type { PARSE_EVENTS__TERM_TYPE_RAW, PARSE_EVENTS__TERM_TYPE_LEGACY_CACHE, PARSE_EVENTS__TERM_TYPE_HARDWARE, -#define __PARSE_EVENTS__TERM_TYPE_NR (PARSE_EVENTS__TERM_TYPE_HARDWARE + 1) + PARSE_EVENTS__TERM_TYPE_CPU, +#define __PARSE_EVENTS__TERM_TYPE_NR (PARSE_EVENTS__TERM_TYPE_CPU + 1) }; =20 struct parse_events_term { diff --git a/tools/perf/util/parse-events.l b/tools/perf/util/parse-events.l index 16045c383ada..e06097a62796 100644 --- a/tools/perf/util/parse-events.l +++ b/tools/perf/util/parse-events.l @@ -330,6 +330,7 @@ percore { return term(yyscanner, PARSE_EVENTS__TERM_T= YPE_PERCORE); } aux-output { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_AUX_OUTPUT); } aux-sample-size { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_AUX_SAMP= LE_SIZE); } metric-id { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_METRIC_ID); } +cpu { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_CPU); } cpu-cycles|cycles { return hw_term(yyscanner, PERF_COUNT_HW_CPU_CYCLES)= ; } stalled-cycles-frontend|idle-cycles-frontend { return hw_term(yyscanner, P= ERF_COUNT_HW_STALLED_CYCLES_FRONTEND); } stalled-cycles-backend|idle-cycles-backend { return hw_term(yyscanner, PER= F_COUNT_HW_STALLED_CYCLES_BACKEND); } diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 280b2499c861..27e2ff23799e 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -1767,6 +1767,7 @@ int perf_pmu__for_each_format(struct perf_pmu *pmu, v= oid *state, pmu_format_call "percore", "aux-output", "aux-sample-size=3Dnumber", + "cpu=3Dnumber", }; struct perf_pmu_format *format; int ret; --=20 2.45.2.1089.g2a221341d9-goog