From nobody Fri Dec 19 09:49:07 2025 Received: from mail-pj1-f52.google.com (mail-pj1-f52.google.com [209.85.216.52]) (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 F353078F5E for ; Tue, 7 Jan 2025 03:40:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736221207; cv=none; b=i2nfubezj+MtWf8hk5tZCy/yNRfvoOIF7pCRUo4fnlTAYmhuNiClJd5ZU/avVHey/KhFriOX3/EkePoKtc5L7GViqYa1gtBfpRZrCRPn0UcL7VHjejlwqjcQ2pjizT7vYOwuh/RF2aiaGoixT8EyWa3FPsDZV+ROc2tnNDLXS2Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736221207; c=relaxed/simple; bh=F5awBpvx4zkj2tGsz/UsWtd72v6Zy6HzR2Mdb/TPfYg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:Cc; b=EVUrde0eEiHFowF7CuIPvwaqwlIOuEgxoEXe+IuhGMf83R37FLd2lrUZ5o/GkirnmTpRwDHnAaR2jOjTp6sAPXZYrOC3fEegccRk6/qwj5JYNr6JiKKbB10kr7iiipWXYtZldKrz5Cd2avHBn0ldrqa8Kt4oS8y6NjTBXpRCaN0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=I7KyD8jo; arc=none smtp.client-ip=209.85.216.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="I7KyD8jo" Received: by mail-pj1-f52.google.com with SMTP id 98e67ed59e1d1-2ee8e8e29f6so17727534a91.0 for ; Mon, 06 Jan 2025 19:40:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1736221202; x=1736826002; darn=vger.kernel.org; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:from:to:cc:subject:date:message-id:reply-to; bh=Fyx3pVShaJ90YkHTQsNhst9gWh0VtzJXnEx45QrL264=; b=I7KyD8joF1vHrtoKhFSWMuh/wvyCkSapZmyPdCZXho0ggxYXUPUXtWbGe/SLVz+sRZ R6pHZSkYUOxYwaN2/xafzDsaaVjM5iI4q6bP/jB27olMaHBO+/NLe0iqR+8qyO1wmVAA StJc1XO3crVUDX8EFcAxx69GNWLps4LgdNT/Gq9PX6aYPayj4q6U8swvhWe+IRhfxZP0 FOzFtBT7BlCBITp1574IzsMsM44vpvrpQytlomxrg5HfRvVM49hjwVU3j1AIPqA6iyfl zgLXN+YH/b8sks6NuxbDCHqD9dxKYjMoOwRtUnROIU6wyVdlxP/nHwEYP48YLC6l1492 ZswQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736221202; x=1736826002; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Fyx3pVShaJ90YkHTQsNhst9gWh0VtzJXnEx45QrL264=; b=skq/sP0zzZbj62pYXAjkYQd0PeJXKiQgpVhl5qyZfG7eUDXrKWUA+Y4NgyHqjW5JnB TV0QAa8Qb9SeFvkPRtFyJzYYGFp1OQVx+dpuA495k4ivhTn/uXhDGhBMhMBTGNrJlQeP W2xQRkyGEgwOMPt7NAKFKtugIsO8rfAN1rZIAk0wbuyAbKSvj/y5BPqJEIaryv/x15/j ideLcnH9Kt4EtYEoR7oXning9qm6V4+7GC32eOpt2m9AvJn7YXHcW6p55QJiK9HssYa8 4zWWR8GPsL3YS7lXOon623LWwGLtF/VvGVbrn0HZzQR9jzVz85nCgXwMqjRZlgzEGsjX FdVw== X-Forwarded-Encrypted: i=1; AJvYcCXQiERJQOJchgdHf3B2QepFA7LZTV/iKFvDhMdvZevfBv98A6qwv154w6/TB2UcmtLgTl5NXqvp5qraSCk=@vger.kernel.org X-Gm-Message-State: AOJu0Yxg/25jHTbSdy1Gw/M3vc5pEeSAgtS5MMthlW2m5bW5JUoO4O4J 2M8+HGuzaWUfrsMYD410HL/KrFAV9sr0Qxs27ebQXwTXOklvv4TfhJ3yk5k1tEc= X-Gm-Gg: ASbGnct3bR09dV+iSXF9Z652LNbKarHcMzCaIwYSODdqNoML/HcVSpUDK8DVNfMbyjw fqWjL+KdVk9Y5Yd8zqS99sH+3CcwJy4dzaPOpwFrfH8hP8KDfwM7966M7vKLE6rgGxJRrXZ9Vxm 60hZnw5p9wALbqQ/1iDOdjhVZFa4pxWcK0+4MPFKaDlMF8RR+AnSf12vhRFdiJaUxa24MVCFFNv /Thnu6ToqiivFnZ6v4WoZAK2x/yyguYDn5J8cAetqVfXSMBn6UAi7n0DmR7AVxhWYxU+uHc X-Google-Smtp-Source: AGHT+IEC9MIQhcggYvCJDm6x9tT/F9gut3g32c9EQWDuw0bmJLjO/nHjnLibjivKrWKmQV+OimKr7Q== X-Received: by 2002:a17:90b:2dc3:b0:2ee:8e75:4ae1 with SMTP id 98e67ed59e1d1-2f452e48804mr78586502a91.21.1736221201959; Mon, 06 Jan 2025 19:40:01 -0800 (PST) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2f4478ac95csm34638466a91.49.2025.01.06.19.40.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jan 2025 19:40:01 -0800 (PST) From: Charlie Jenkins Date: Mon, 06 Jan 2025 19:39:47 -0800 Subject: [PATCH v3] libperf: Add perf_evsel__id() function Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250106-perf_evsel_get_id-v3-1-44eca9194f1e@rivosinc.com> X-B4-Tracking: v=1; b=H4sIAAKifGcC/23N0QqCMBTG8VeRXbfYjnNlV71HhOg80wPlZJNRi O/eFCIIL/8fnN+ZWUBPGNglm5nHSIHckCI/ZMz09dAhpzY1AwFKnAH4iN5WGAM+qg6nilpuTyi llUUhVMPS3ejR0mszb/fUPYXJ+ff2Isp1/Wr5jhYll1xYW4NQRkmtrp6iCzSYo3FPtoIRfkgpy j0EEtKAxhoFWC30H7IsywfcDlMz+gAAAA== X-Change-ID: 20240822-perf_evsel_get_id-f7e11f15504b To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter Cc: linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Charlie Jenkins X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3816; i=charlie@rivosinc.com; h=from:subject:message-id; bh=F5awBpvx4zkj2tGsz/UsWtd72v6Zy6HzR2Mdb/TPfYg=; b=owGbwMvMwCHWx5hUnlvL8Y3xtFoSQ3rNIhYZZnFPi0vpEVU21tKCf9LutB/vurn/8u7MqdZFW 3vfmwl0lLIwiHEwyIopsvBca2BuvaNfdlS0bALMHFYmkCEMXJwCMJHeUEaGTdwnV3L6nP0au36p id7BruxLzwyCfSfeNQ7giq4NEfrWzMhwrt1v9bFt8xdMkPYK53zGVBp5T7YhwW6rb1HLjolmDRa cAA== X-Developer-Key: i=charlie@rivosinc.com; a=openpgp; fpr=7D834FF11B1D8387E61C776FFB10D1F27D6B1354 Introduce perf_evsel__id() to collect the id of an evsel. This allows applications to determine the allocated id of an evsel for each fd. The "ids" argument is expected to be an array the size of the number of open fd's for the evsel. This will allow applications to link the id returned by PERF_SAMPLE_ID to the event being sampled. Signed-off-by: Charlie Jenkins --- Changes in v3: - Replace id argument with array of pointers. IDs is indexed by [cpu][thread]. - Add error handling - Use uint64_t instead of __u64 for consistency - Link to v2: https://lore.kernel.org/r/20240909-perf_evsel_get_id-v2-1-b26= eae02f606@rivosinc.com Changes in v2: - Replaced id argument with array of ids for perf_evsel__id() to support the id for each fd. - Link to v1: https://lore.kernel.org/r/20240823-perf_evsel_get_id-v1-1-0ff= a204c4164@rivosinc.com --- tools/lib/perf/Documentation/libperf.txt | 2 ++ tools/lib/perf/evsel.c | 23 +++++++++++++++++++++++ tools/lib/perf/include/perf/evsel.h | 1 + 3 files changed, 26 insertions(+) diff --git a/tools/lib/perf/Documentation/libperf.txt b/tools/lib/perf/Docu= mentation/libperf.txt index 59aabdd3cabff19c9a4835d9d20a74c6087d9a06..0133547394c296ee3ab7467ebe5= c9a48707bad1d 100644 --- a/tools/lib/perf/Documentation/libperf.txt +++ b/tools/lib/perf/Documentation/libperf.txt @@ -93,6 +93,8 @@ SYNOPSIS void perf_evlist__enable(struct perf_evlist *evlist); void perf_evlist__disable(struct perf_evlist *evlist); =20 + void perf_evsel__id(struct perf_evsel *evsel, u64 *ids[]); + #define perf_evlist__for_each_evsel(evlist, pos) =20 void perf_evlist__set_maps(struct perf_evlist *evlist, diff --git a/tools/lib/perf/evsel.c b/tools/lib/perf/evsel.c index c475319e2e410d31d072d81afb9e6277b16ef1f1..7c84ecaa6c87977edc9c70e960e= 985ffc975fcbf 100644 --- a/tools/lib/perf/evsel.c +++ b/tools/lib/perf/evsel.c @@ -486,6 +486,29 @@ int perf_evsel__disable(struct perf_evsel *evsel) return err; } =20 +static int perf_evsel__get_id(struct perf_evsel *evsel, int cpu_map_idx, i= nt thread, u64 *id) +{ + return perf_evsel__ioctl(evsel, PERF_EVENT_IOC_ID, id, cpu_map_idx, threa= d); +} + +int perf_evsel__id(struct perf_evsel *evsel, u64 *ids[]) +{ + struct perf_thread_map *threads =3D perf_evsel__threads(evsel); + struct perf_cpu_map *cpus =3D perf_evsel__cpus(evsel); + int x, y, err; + + for (x =3D 0; x < perf_cpu_map__nr(cpus); x++) { + for (y =3D 0; y < perf_thread_map__nr(threads); y++) { + err =3D perf_evsel__get_id(evsel, x, y, &ids[x][y]); + + if (err) + return err; + } + } + + return 0; +} + int perf_evsel__apply_filter(struct perf_evsel *evsel, const char *filter) { int err =3D 0, i; diff --git a/tools/lib/perf/include/perf/evsel.h b/tools/lib/perf/include/p= erf/evsel.h index 6f92204075c244bc623b26dc2c97fa4c835a4228..2bb9d6406e405b4ee29b8b13d64= dd40b78edb501 100644 --- a/tools/lib/perf/include/perf/evsel.h +++ b/tools/lib/perf/include/perf/evsel.h @@ -41,6 +41,7 @@ LIBPERF_API int perf_evsel__enable_cpu(struct perf_evsel = *evsel, int cpu_map_idx LIBPERF_API int perf_evsel__enable_thread(struct perf_evsel *evsel, int th= read); LIBPERF_API int perf_evsel__disable(struct perf_evsel *evsel); LIBPERF_API int perf_evsel__disable_cpu(struct perf_evsel *evsel, int cpu_= map_idx); +LIBPERF_API int perf_evsel__id(struct perf_evsel *evsel, uint64_t *ids[]); LIBPERF_API struct perf_cpu_map *perf_evsel__cpus(struct perf_evsel *evsel= ); LIBPERF_API struct perf_thread_map *perf_evsel__threads(struct perf_evsel = *evsel); LIBPERF_API struct perf_event_attr *perf_evsel__attr(struct perf_evsel *ev= sel); --- base-commit: ed60738a9b7ede4a4ae797d90be7fde3e10a36c7 change-id: 20240822-perf_evsel_get_id-f7e11f15504b --=20 - Charlie