Skip to contentSkip to conversation

perf tool_pmu: Add procfs memory, network and schedstat events

PATCH New Ian Rogers 2 participants 9 messages Nov 13 – Nov 14 perf events

lore
Share & tools
lore

Ian Rogers

author reviewer
#0 lore raw

v2 cover perf tool_pmu: Add procfs memory, network and schedstat events

Add tool PMU events for memory usage, network activity, and scheduler runqueue statistics based on procfs data in /proc/<pid>/statm, /proc/<pid>/smaps_rollup, /proc/net/dev, and /proc/schedstat:

- Patch 1 adds 26 memory_* events (such as memory_rss, memory_pss, memory_uss, memory_size, memory_swap) aggregated across processes in system-wide mode or read per-process. Per-process mode holds a /proc/<pid> directory descriptor and opens statm/smaps_rollup on each read (observing post-exec address spaces without PID-reuse races), deduplicates sibling threads sharing a Tgid, and falls back to wait4 rusage ru_maxrss for memory_rss when a forked workload has already exited.
- Patch 2 adds 16 system-wide net_rx_* and net_tx_* events from /proc/net/dev, tracking deltas across enable/disable transitions and handling mixed CPU-map event groups safely. Per-process and cgroup modes are rejected with -EINVAL since /proc/<pid>/net/dev reports statistics for the entire network namespace rather than an individual process.
- Patch 3 adds 8 per-CPU schedstat_* events from /proc/schedstat, tracking per-CPU deltas across enable/disable transitions.
- Patch 4 extends the 'Tool PMU' unit test suite with tests for memory events (including multi-threaded Tgid deduplication), network events, schedstat events, and mixed CPU-map tool groups.

Because these events are exposed on tool_pmu with JSON descriptions, they can be used in metrics, listed via 'perf list', and inspected in the Python ilist application.

This series was developed and reviewed with assistance from an AI coding agent (Gemini 3.1 Pro) and reviewed with Sashiko.

v2:
- Rebase onto perf-tools-next (adapting to reads_only_on_cpu_idx0 and tool_pmu enable/disable support).
- Restrict net_* events to system-wide mode (-EINVAL on per-process or cgroup open) and report deltas over the enabled interval rather than cumulative boot totals (Namhyung Kim).
- Fix unpadded /proc/net/dev column parsing after ':' and fix memory unit scaling and statm field offsets.
- Open /proc/<pid> with O_DIRECTORY for per-process memory_* events so post-exec mm_struct changes are observed, deduplicate threads sharing a Tgid, and refine the wait4 ru_maxrss fallback for memory_rss.
- Handle non-leader attr.disabled and mismatched CPU maps when single- CPU and per-CPU tool events are grouped.
- Add per-CPU schedstat_* tool PMU events and 'Tool PMU' unit tests.

v1: https://lore.kernel.org/linux-perf-users/[email protected]/

Ian Rogers (4):
perf tool_pmu: Add memory events
perf tool_pmu: Add network events
perf tool_pmu: Add schedstat events
perf test tool_pmu: Add memory, network and schedstat tests

 tools/perf/builtin-stat.c                     |  81 +-
 .../pmu-events/arch/common/common/tool.json   | 300 ++++++
 tools/perf/pmu-events/empty-pmu-events.c      | 422 +++++---
 tools/perf/tests/tool_pmu.c                   | 689 +++++++++++++
 tools/perf/util/evsel.c                       |  53 +-
 tools/perf/util/pmu.c                         |   4 +-
 tools/perf/util/stat-display.c                |   8 +-
 tools/perf/util/tool_pmu.c                    | 916 ++++++++++++++++--
 tools/perf/util/tool_pmu.h                    |  52 +
 9 files changed, 2316 insertions(+), 209 deletions(-)
Signature · 1 line
2.56.1.703.gf848ed807c-goog
author reviewer
#1 lore raw

PATCH v2 1/4 perf tool_pmu: Add memory events

Add tool PMU events to report memory usage information exposed by /proc/pid/smaps_rollup and /proc/pid/statm.

The following events are added:
- memory_anon_huge_pages: Anonymous Huge Pages memory in bytes.
- memory_anonymous: Anonymous (non-file-backed) memory in bytes.
- memory_data: Data and stack segment memory in bytes.
- memory_file_pmd_mapped: File-backed PMD-mapped memory in bytes.
- memory_ksm: Kernel Samepage Merging (KSM) memory in bytes.
- memory_lazyfree: LazyFree marked memory in bytes.
- memory_locked: RAM-locked memory in bytes.
- memory_private_clean: Private clean memory in bytes.
- memory_private_dirty: Private dirty memory in bytes.
- memory_private_hugetlb: Private Huge Pages memory in bytes.
- memory_pss: Proportional Set Size (PSS) in bytes.
- memory_pss_anon: Anonymous PSS memory in bytes.
- memory_pss_dirty: Dirty PSS memory in bytes.
- memory_pss_file: File-backed PSS memory in bytes.
- memory_pss_shmem: Shared PSS memory in bytes.
- memory_referenced: Referenced/accessed memory in bytes.
- memory_rss: Resident Set Size (RSS) in bytes.
- memory_shared_clean: Shared clean memory in bytes.
- memory_shared_dirty: Shared dirty memory in bytes.
- memory_shared_hugetlb: Shared Huge Pages memory in bytes.
- memory_shmem_pmd_mapped: Shared PMD-mapped memory in bytes.
- memory_size: Virtual memory size in bytes.
- memory_swap: Swapped-out memory in bytes.
- memory_swap_pss: Proportional swap memory (SwapPss) in bytes.
- memory_text: Code (text segment) memory in bytes.
- memory_uss: Unique Set Size (USS) in bytes.

The events are aggregated across processes in system-wide mode, or reported per-process when monitoring specific tasks. In per-process mode, open a /proc/<pid> directory descriptor and resolve statm or smaps_rollup on each read so post-exec address spaces are observed without PID-reuse races, and deduplicate sibling threads sharing a Tgid so multi-threaded processes are not multiplied by thread count.

Because /proc/<pid>/statm and /proc/<pid>/smaps_rollup require a live mm_struct at counter read time, non-memory_rss per-process events require an active target at read time (such as -p <pid> or -I interval mode while a workload runs). For memory_rss, fall back to wait4 rusage ru_maxrss when a forked workload has already terminated at counter read time.

Example per-process and system-wide output:

  $ perf stat -e memory_size,memory_rss,memory_pss,memory_uss \
      -e memory_data,memory_text -p 3558512 -- sleep 0.1

Performance counter stats for process id '3558512':

           7,520,256      memory_size
           4,542,464      memory_rss
             585,728      memory_pss
             356,352      memory_uss
             458,752      memory_data
             892,928      memory_text
         0.101111221 seconds time elapsed
  $ perf stat -a -e memory_size,memory_rss,memory_pss,memory_uss sleep 0.1

Performance counter stats for 'system wide':

104,040,572,162,048 memory_size

      40,880,496,640      memory_rss
      24,085,870,592      memory_pss
      22,840,549,376      memory_uss
         0.101068461 seconds time elapsed
---
 tools/perf/builtin-stat.c                     |  81 ++-
 .../pmu-events/arch/common/common/tool.json   | 156 +++++
 tools/perf/pmu-events/empty-pmu-events.c      | 326 +++++++----
 tools/perf/util/tool_pmu.c                    | 552 ++++++++++++++++--
 tools/perf/util/tool_pmu.h                    |  26 +
 5 files changed, 954 insertions(+), 187 deletions(-)
tools/perf/builtin-stat.c +53 -28
index 37752d6bfef4..d2c8c0ccea49 100644
@@ -139,6 +139,7 @@ static const char		*output_name;
 static int			output_fd;
 static char			*metrics;
 static struct rusage_stats	ru_stats;
+static bool			ru_stats_valid;
 
 struct perf_stat {
 	bool			 record;
@@ -283,12 +284,13 @@ static int read_single_counter(struct evsel *counter, int cpu_map_idx, int threa
 	int err = evsel__read_counter(counter, cpu_map_idx, thread);
 
 	/*
-	 * Reading user and system time will fail when the process
-	 * terminates. Use the wait4 values in that case.
+	 * Reading user, system time and memory_rss will fail when a forked
+	 * workload terminates. Use the wait4 values in that case.
 	 */
-	if (err && cpu_map_idx == 0 &&
+	if (err && cpu_map_idx == 0 && thread == 0 && ru_stats_valid &&
 	    (evsel__tool_event(counter) == TOOL_PMU__EVENT_USER_TIME ||
-	     evsel__tool_event(counter) == TOOL_PMU__EVENT_SYSTEM_TIME)) {
+	     evsel__tool_event(counter) == TOOL_PMU__EVENT_SYSTEM_TIME ||
+	     evsel__tool_event(counter) == TOOL_PMU__EVENT_MEMORY_RSS)) {
 		struct perf_counts_values *count =
 			perf_counts(counter->counts, cpu_map_idx, thread);
 		struct perf_counts_values *old_count = NULL;
@@ -299,10 +301,15 @@ static int read_single_counter(struct evsel *counter, int cpu_map_idx, int threa
 
 		if (evsel__tool_event(counter) == TOOL_PMU__EVENT_USER_TIME)
 			val = ru_stats.ru_utime_usec_stat.mean;
-		else
+		else if (evsel__tool_event(counter) == TOOL_PMU__EVENT_SYSTEM_TIME)
 			val = ru_stats.ru_stime_usec_stat.mean;
+		else
+			val = (u64)stat_config.ru_data.ru_maxrss * 1024ULL;
 
-		count->val = val;
+		if (evsel__tool_event(counter) == TOOL_PMU__EVENT_MEMORY_RSS && old_count)
+			count->val = old_count->val + val;
+		else
+			count->val = val;
 		if (old_count) {
 			count->run = old_count->run + 1;
 			count->ena = old_count->ena + 1;
@@ -612,6 +619,34 @@ static void compute_tts(struct timespec *time_start, struct timespec *time_stop,
 	*time_to_sleep = tts;
 }
 
+static void update_rusage_stats(const struct rusage *rusage)
+{
+	const u64 us_to_ns = 1000;
+	const u64 s_to_ns = 1000000000;
+
+	update_stats(&ru_stats.ru_utime_usec_stat,
+		(rusage->ru_utime.tv_usec * us_to_ns + rusage->ru_utime.tv_sec * s_to_ns));
+	update_stats(&ru_stats.ru_stime_usec_stat,
+		(rusage->ru_stime.tv_usec * us_to_ns + rusage->ru_stime.tv_sec * s_to_ns));
+	ru_stats_valid = true;
+}
+
+static bool reap_workload(int *status, int options)
+{
+	pid_t pid = evlist__workload_pid(evsel_list);
+
+	if (pid <= 0)
+		return false;
+
+	if (wait4(pid, status, options, &stat_config.ru_data) <= 0)
+		return false;
+
+	child_pid = -1;
+	evlist__set_workload_pid(evsel_list, -1);
+	update_rusage_stats(&stat_config.ru_data);
+	return true;
+}
+
 static int dispatch_events(bool forks, int timeout, int interval, int *times)
 {
 	int child_exited = 0, status = 0;
@@ -628,18 +663,20 @@ static int dispatch_events(bool forks, int timeout, int interval, int *times)
 	time_to_sleep = sleep_time;
 
 	while (!done) {
-		if (forks) {
-			child_exited = waitpid(child_pid, &status, WNOHANG);
-		} else {
+		if (forks)
+			child_exited = reap_workload(&status, WNOHANG) ? 1 : 0;
+		else
 			child_exited = !is_target_alive(&target,
 							evlist__core(evsel_list)->threads) ? 1 : 0;
-		}
+
 		if (child_exited)
 			break;
 
 		clock_gettime(CLOCK_MONOTONIC, &time_start);
 		if (!(evlist__poll(evsel_list, time_to_sleep) > 0)) { /* poll timeout or EINTR */
-			if (timeout || handle_interval(interval, times))
+			if (forks && reap_workload(&status, WNOHANG))
+				child_exited = 1;
+			if (timeout || handle_interval(interval, times) || child_exited)
 				break;
 			time_to_sleep = sleep_time;
 		} else { /* fd revent */
@@ -761,17 +798,6 @@ static int create_perf_stat_counter(struct evsel *evsel,
 					      evsel->core.threads);
 }
 
-static void update_rusage_stats(const struct rusage *rusage)
-{
-	const u64 us_to_ns = 1000;
-	const u64 s_to_ns = 1000000000;
-
-	update_stats(&ru_stats.ru_utime_usec_stat,
-		(rusage->ru_utime.tv_usec * us_to_ns + rusage->ru_utime.tv_sec * s_to_ns));
-	update_stats(&ru_stats.ru_stime_usec_stat,
-		(rusage->ru_stime.tv_usec * us_to_ns + rusage->ru_stime.tv_sec * s_to_ns));
-}
-
 static int __run_perf_stat(int argc, const char **argv, int run_idx)
 {
 	int interval = stat_config.interval;
@@ -787,6 +813,8 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx)
 	int err, open_err = 0;
 	bool second_pass = false, has_supported_counters;
 
+	ru_stats_valid = false;
+
 	if (forks) {
 		if (evlist__prepare_workload(evsel_list, &target, argv, is_pipe,
 					     workload_exec_failed_signal) < 0) {
@@ -979,11 +1007,9 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx)
 	if (forks) {
 		if (interval || timeout || evlist__ctlfd_initialized(evsel_list))
 			status = dispatch_events(forks, timeout, interval, &times);
-		if (child_pid != -1) {
-			if (timeout)
-				kill(child_pid, SIGTERM);
-			wait4(child_pid, &status, 0, &stat_config.ru_data);
-		}
+		if (child_pid != -1 && timeout)
+			kill(child_pid, SIGTERM);
+		reap_workload(&status, 0);
 
 		if (workload_exec_errno) {
 			errno = workload_exec_errno;
@@ -1026,7 +1052,6 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx)
 		evlist__reset_aggr_stats(evsel_list);
 	} else {
 		update_stats(stat_config.walltime_nsecs_stats, t1 - t0);
-		update_rusage_stats(&stat_config.ru_data);
 	}
 
 	/*
tools/perf/pmu-events/arch/common/common/tool.json +156 -0

161 lines not on this page · raw message

tools/perf/pmu-events/empty-pmu-events.c +215 -111

510 lines not on this page · raw message

tools/perf/util/tool_pmu.c +504 -48

632 lines not on this page · raw message

tools/perf/util/tool_pmu.h +26 -0
index f66d24cf3502..99a2ea1548f8 100644
@@ -24,6 +24,32 @@ enum tool_pmu_event {
 	TOOL_PMU__EVENT_SYSTEM_TSC_FREQ,
 	TOOL_PMU__EVENT_CORE_WIDE,
 	TOOL_PMU__EVENT_TARGET_CPU,
+	TOOL_PMU__EVENT_MEMORY_ANON_HUGE_PAGES,
+	TOOL_PMU__EVENT_MEMORY_ANONYMOUS,
+	TOOL_PMU__EVENT_MEMORY_DATA,
+	TOOL_PMU__EVENT_MEMORY_FILE_PMD_MAPPED,
+	TOOL_PMU__EVENT_MEMORY_KSM,
+	TOOL_PMU__EVENT_MEMORY_LAZYFREE,
+	TOOL_PMU__EVENT_MEMORY_LOCKED,
+	TOOL_PMU__EVENT_MEMORY_PRIVATE_CLEAN,
+	TOOL_PMU__EVENT_MEMORY_PRIVATE_DIRTY,
+	TOOL_PMU__EVENT_MEMORY_PRIVATE_HUGETLB,
+	TOOL_PMU__EVENT_MEMORY_PSS,
+	TOOL_PMU__EVENT_MEMORY_PSS_ANON,
+	TOOL_PMU__EVENT_MEMORY_PSS_DIRTY,
+	TOOL_PMU__EVENT_MEMORY_PSS_FILE,
+	TOOL_PMU__EVENT_MEMORY_PSS_SHMEM,
+	TOOL_PMU__EVENT_MEMORY_REFERENCED,
+	TOOL_PMU__EVENT_MEMORY_RSS,
+	TOOL_PMU__EVENT_MEMORY_SHARED_CLEAN,
+	TOOL_PMU__EVENT_MEMORY_SHARED_DIRTY,
+	TOOL_PMU__EVENT_MEMORY_SHARED_HUGETLB,
+	TOOL_PMU__EVENT_MEMORY_SHMEM_PMD_MAPPED,
+	TOOL_PMU__EVENT_MEMORY_SIZE,
+	TOOL_PMU__EVENT_MEMORY_SWAP,
+	TOOL_PMU__EVENT_MEMORY_SWAP_PSS,
+	TOOL_PMU__EVENT_MEMORY_TEXT,
+	TOOL_PMU__EVENT_MEMORY_USS,
 
 	TOOL_PMU__EVENT_MAX,
 };
Signature · 1 line
2.56.1.703.gf848ed807c-goog
#2 lore raw

Re: [PATCH v2 1/4] perf tool_pmu: Add memory events

Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] perf stat: wrong rusage fallback on exited target in read_single_counter() - [Medium] perf…

Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [Medium] perf stat: wrong rusage fallback on exited target in read_single_counter()
- [Medium] perf tool_pmu: -ENOENT/-EINVAL on exiting thread in open_memory_pid_dir()
--

commit 8ab23533dd054a2605a53d9e5d6408d9b222edde
Author: Ian Rogers <[email protected]>

perf tool_pmu: Add memory events

This commit adds tool PMU events exposing process and system-wide memory usage metrics from /proc/<pid>/smaps_rollup and /proc/<pid>/statm, with a wait4() rusage fallback for memory_rss when a forked workload exits.

Quoted 35 lines
tools/perf/builtin-stat.c +6 -5
index 37752d6bfef45..d2c8c0ccea495 100644
@@ -139,6 +139,7 @@ static const char		*output_name;
 static int			output_fd;
 static char			*metrics;
 static struct rusage_stats	ru_stats;
+static bool			ru_stats_valid;
 
 struct perf_stat {
 	bool			 record;
@@ -283,12 +284,13 @@ static int read_single_counter(struct evsel *counter, int cpu_map_idx, int threa
 	int err = evsel__read_counter(counter, cpu_map_idx, thread);
 
 	/*
-	 * Reading user and system time will fail when the process
-	 * terminates. Use the wait4 values in that case.
+	 * Reading user, system time and memory_rss will fail when a forked
+	 * workload terminates. Use the wait4 values in that case.
 	 */
-	if (err && cpu_map_idx == 0 &&
+	if (err && cpu_map_idx == 0 && thread == 0 && ru_stats_valid &&
 	    (evsel__tool_event(counter) == TOOL_PMU__EVENT_USER_TIME ||
-	     evsel__tool_event(counter) == TOOL_PMU__EVENT_SYSTEM_TIME)) {
+	     evsel__tool_event(counter) == TOOL_PMU__EVENT_SYSTEM_TIME ||
+	     evsel__tool_event(counter) == TOOL_PMU__EVENT_MEMORY_RSS)) {
 		struct perf_counts_values *count =
 			perf_counts(counter->counts, cpu_map_idx, thread);
 		struct perf_counts_values *old_count = NULL;
@@ -299,10 +301,15 @@ static int read_single_counter(struct evsel *counter, int cpu_map_idx, int threa
 
 		if (evsel__tool_event(counter) == TOOL_PMU__EVENT_USER_TIME)
 			val = ru_stats.ru_utime_usec_stat.mean;
-		else

tools/perf/builtin-stat.c static int read_single_counter(struct evsel *counter, int cpu_map_idx, int threa · line 312

Quoted 10 lines
tools/perf/builtin-stat.c +7 -1
+		else if (evsel__tool_event(counter) == TOOL_PMU__EVENT_SYSTEM_TIME)
 			val = ru_stats.ru_stime_usec_stat.mean;
+		else
+			val = (u64)stat_config.ru_data.ru_maxrss * 1024ULL;
 
-		count->val = val;
+		if (evsel__tool_event(counter) == TOOL_PMU__EVENT_MEMORY_RSS && old_count)
+			count->val = old_count->val + val;
+		else
+			count->val = val;

[Severity: Medium]
Can read_single_counter() substitute the forked command's wait4() rusage for an exited -p or -t target?

When profiling an explicit target while a child command bounds the measurement (for example, perf stat -e memory_rss -p <pid> -- sleep 0.1), reap_workload() -> update_rusage_stats() sets ru_stats_valid = true from the child command without checking target__none(&target). If the monitored target exits before read_counters() runs, evsel__read_counter() fails on thread == 0 and read_single_counter() reports the child command's ru_maxrss (or user/system time) as the target's counter value instead of not counted. On multi-threaded -p targets, sibling threads have dir_fd == -1 after Tgid deduplication and return 0 from evsel__tool_pmu_read(), so the fallback value succeeds for the whole target.

Quoted 4 lines
tools/perf/util/tool_pmu.c +0 -0
index d2f7591747d94..0ae08cd910bc4 100644

[ ... ]

Quoted 1 line
tools/perf/util/tool_pmu.c +0 -0
@@ -203,6 +236,205 @@ static int read_pid_stat_field(int fd, int field, __u64 *val)

[ ... ]

Quoted 18 lines
tools/perf/util/tool_pmu.c +18 -0
+static int read_pid_tgid(int dir_fd, int *tgid)
+{
+	char buf[1024];
+	struct io io;
+	u64 val;
+	int fd, ret;
+
+	fd = openat(dir_fd, "status", O_RDONLY);
+	if (fd < 0)
+		return -errno;
+
+	io__init(&io, fd, buf, sizeof(buf));
+	ret = read_proc_status_u64(&io, "Tgid:", &val);
+	close(fd);
+	if (!ret)
+		*tgid = (int)val;
+	return ret;
+}

[ ... ]

Quoted 34 lines
tools/perf/util/tool_pmu.c +30 -0
@@ -258,19 +490,138 @@ static int tool_pmu__read_stat(struct evsel *evsel, int cpu_map_idx, int thread,
 	return err;
 }
 
+static int open_memory_pid_dir(enum tool_pmu_event ev, int pid,
+			       int *seen_tgids, int *nr_seen_tgids, int *out_fd)
+{
+	const char *file = "smaps_rollup";
+	int dir_fd, test_fd, tgid = -1;
+	char buf[PATH_MAX];
+
+	*out_fd = -1;
+	snprintf(buf, sizeof(buf), "%s/%d", procfs__mountpoint(), pid);
+	dir_fd = open(buf, O_RDONLY | O_DIRECTORY);
+	if (dir_fd < 0)
+		return -errno;
+
+	if (seen_tgids) {
+		int err = read_pid_tgid(dir_fd, &tgid);
+
+		if (err) {
+			close(dir_fd);
+			return err;
+		}
+		for (int i = 0; i < *nr_seen_tgids; i++) {
+			if (seen_tgids[i] == tgid) {
+				close(dir_fd);
+				return 0;
+			}
+		}
+	}
+
+	if (ev == TOOL_PMU__EVENT_MEMORY_SIZE ||
+	    ev == TOOL_PMU__EVENT_MEMORY_DATA ||

tools/perf/util/tool_pmu.c static int tool_pmu__read_stat(struct evsel *evsel, int cpu_map_idx, int thread, · line 532

Quoted 10 lines
tools/perf/util/tool_pmu.c +10 -0
+	    ev == TOOL_PMU__EVENT_MEMORY_TEXT)
+		file = "statm";
+
+	test_fd = openat(dir_fd, file, O_RDONLY);
+	if (test_fd < 0) {
+		int err = -errno;
+
+		close(dir_fd);
+		return err;
+	}

[Severity: Medium]
Does open_memory_pid_dir() returning -ENOENT or -EINVAL when a thread exits during counter setup cause stat_handle_error() to skip the memory event as unsupported?

When a thread in the thread map terminates between enumeration and open_memory_pid_dir(), open() or openat() fails with ENOENT, or read() on status fails with ESRCH and makes read_proc_status_u64() return -EINVAL. In builtin-stat.c, stat_handle_error() treats both ENOENT and EINVAL as COUNTER_SKIP ("event is not supported by the kernel") before reaching the vanished-thread retry path:

tools/perf/builtin-stat.c:stat_handle_error() {
	if (err == EINVAL || err == ENOSYS || err == ENOENT || err == ENXIO) {
		...
		return COUNTER_SKIP;
	}
	...
	if (target__has_per_thread(&target) &&
	    evlist__core(evsel_list)->threads &&
	    evlist__core(evsel_list)->threads->err_thread != -1) {

Instead of ignoring the exited thread in --per-thread or multi-threaded -p mode, perf stat skips the memory counter for the entire run.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
author reviewer
#3 lore raw

PATCH v2 2/4 perf tool_pmu: Add network events

In reply to Ian Rogers

Add system-wide tool PMU events to report network statistics from /proc/net/dev. Since /proc/pid/net/dev reports statistics for the entire network namespace rather than an individual process, reject opening these events in per-process or cgroup mode.

The following events are added for both RX (receive) and TX (transmit):
- bytes
- packets
- errors
- drop
- fifo
- frame (RX only) / colls (TX only)
- compressed
- multicast (RX only) / carrier (TX only)

Track initial and accumulated values across enable/disable transitions so perf stat reports deltas over the measurement period rather than cumulative totals since boot. Also honor the group leader's attr.disabled state when opening grouped tool events and map CPU indices safely in evsel__enable_cpu(), evsel__disable_cpu(), and tool_pmu xyarray lookups when single-CPU tool events are grouped with per-CPU events.

Example output:

  $ perf stat -a -e net_rx_bytes,net_rx_packets,net_tx_bytes \
      -e net_tx_packets -- sleep 0.02

Performance counter stats for 'system wide':

              16,971      net_rx_bytes
                  10      net_rx_packets
              17,214      net_tx_bytes
                  10      net_tx_packets
         0.017721776 seconds time elapsed
---
 .../pmu-events/arch/common/common/tool.json   |  96 ++++++
 tools/perf/pmu-events/empty-pmu-events.c      | 286 +++++++++++-------
 tools/perf/util/evsel.c                       |  53 +++-
 tools/perf/util/tool_pmu.c                    | 263 ++++++++++++++--
 tools/perf/util/tool_pmu.h                    |  17 ++
 5 files changed, 571 insertions(+), 144 deletions(-)
tools/perf/pmu-events/arch/common/common/tool.json +96 -0
index 9e0e89553847..a332cbf842f7 100644
@@ -238,5 +238,101 @@
     "EventName": "memory_uss",
     "BriefDescription": "Unique Set Size (USS) in bytes",
     "ConfigCode": "40"
+  },
+  {
+    "Unit": "tool",
+    "EventName": "net_rx_bytes",
+    "BriefDescription": "System-wide network received bytes",
+    "ConfigCode": "41"
+  },
+  {
+    "Unit": "tool",
+    "EventName": "net_rx_packets",
+    "BriefDescription": "System-wide network received packets",
+    "ConfigCode": "42"
+  },
+  {
+    "Unit": "tool",
+    "EventName": "net_rx_errors",
+    "BriefDescription": "System-wide network received errors",
+    "ConfigCode": "43"
+  },
+  {
+    "Unit": "tool",
+    "EventName": "net_rx_drop",
+    "BriefDescription": "System-wide network received dropped packets",
+    "ConfigCode": "44"
+  },
+  {
+    "Unit": "tool",
+    "EventName": "net_rx_fifo",
+    "BriefDescription": "System-wide network received fifo overruns",
+    "ConfigCode": "45"
+  },
+  {
+    "Unit": "tool",
+    "EventName": "net_rx_frame",
+    "BriefDescription": "System-wide network received framing errors",
+    "ConfigCode": "46"
+  },
+  {
+    "Unit": "tool",
+    "EventName": "net_rx_compressed",
+    "BriefDescription": "System-wide network received compressed packets",
+    "ConfigCode": "47"
+  },
+  {
+    "Unit": "tool",
+    "EventName": "net_rx_multicast",
+    "BriefDescription": "System-wide network received multicast packets",
+    "ConfigCode": "48"
+  },
+  {
+    "Unit": "tool",
+    "EventName": "net_tx_bytes",
+    "BriefDescription": "System-wide network transmitted bytes",
+    "ConfigCode": "49"
+  },
+  {
+    "Unit": "tool",
+    "EventName": "net_tx_packets",
+    "BriefDescription": "System-wide network transmitted packets",
+    "ConfigCode": "50"
+  },
+  {
+    "Unit": "tool",
+    "EventName": "net_tx_errors",
+    "BriefDescription": "System-wide network transmitted errors",
+    "ConfigCode": "51"
+  },
+  {
+    "Unit": "tool",
+    "EventName": "net_tx_drop",
+    "BriefDescription": "System-wide network transmitted dropped packets",
+    "ConfigCode": "52"
+  },
+  {
+    "Unit": "tool",
+    "EventName": "net_tx_fifo",
+    "BriefDescription": "System-wide network transmitted fifo overruns",
+    "ConfigCode": "53"
+  },
+  {
+    "Unit": "tool",
+    "EventName": "net_tx_colls",
+    "BriefDescription": "System-wide network transmitted collisions",
+    "ConfigCode": "54"
+  },
+  {
+    "Unit": "tool",
+    "EventName": "net_tx_carrier",
+    "BriefDescription": "System-wide network transmitted carrier losses",
+    "ConfigCode": "55"
+  },
+  {
+    "Unit": "tool",
+    "EventName": "net_tx_compressed",
+    "BriefDescription": "System-wide network transmitted compressed packets",
+    "ConfigCode": "56"
   }
 ]
tools/perf/pmu-events/empty-pmu-events.c +175 -111

470 lines not on this page · raw message

tools/perf/util/evsel.c +46 -7

77 lines not on this page · raw message

tools/perf/util/tool_pmu.c +237 -26

379 lines not on this page · raw message

tools/perf/util/tool_pmu.h +17 -0
index 99a2ea1548f8..f972995bb8ed 100644
@@ -50,6 +50,22 @@ enum tool_pmu_event {
 	TOOL_PMU__EVENT_MEMORY_SWAP_PSS,
 	TOOL_PMU__EVENT_MEMORY_TEXT,
 	TOOL_PMU__EVENT_MEMORY_USS,
+	TOOL_PMU__EVENT_NET_RX_BYTES,
+	TOOL_PMU__EVENT_NET_RX_PACKETS,
+	TOOL_PMU__EVENT_NET_RX_ERRORS,
+	TOOL_PMU__EVENT_NET_RX_DROP,
+	TOOL_PMU__EVENT_NET_RX_FIFO,
+	TOOL_PMU__EVENT_NET_RX_FRAME,
+	TOOL_PMU__EVENT_NET_RX_COMPRESSED,
+	TOOL_PMU__EVENT_NET_RX_MULTICAST,
+	TOOL_PMU__EVENT_NET_TX_BYTES,
+	TOOL_PMU__EVENT_NET_TX_PACKETS,
+	TOOL_PMU__EVENT_NET_TX_ERRORS,
+	TOOL_PMU__EVENT_NET_TX_DROP,
+	TOOL_PMU__EVENT_NET_TX_FIFO,
+	TOOL_PMU__EVENT_NET_TX_COLLS,
+	TOOL_PMU__EVENT_NET_TX_CARRIER,
+	TOOL_PMU__EVENT_NET_TX_COMPRESSED,
 
 	TOOL_PMU__EVENT_MAX,
 };
@@ -87,6 +103,7 @@ int evsel__tool_pmu_enable(struct evsel *evsel);
 int evsel__tool_pmu_disable_cpu(struct evsel *evsel, int cpu_map_idx);
 int evsel__tool_pmu_disable(struct evsel *evsel);
 int evsel__tool_pmu_read(struct evsel *evsel, int cpu_map_idx, int thread);
+void evsel__tool_pmu_exit(struct evsel *evsel);
 
 struct perf_pmu *tool_pmu__new(void);
 
Signature · 1 line
2.56.1.703.gf848ed807c-goog
#4 lore raw

Re: [PATCH v2 2/4] perf tool_pmu: Add network events

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] perf tool_pmu: grouped tool events stay disabled when enable_on_exec is set --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] perf tool_pmu: grouped tool events stay disabled when enable_on_exec is set
--

commit 8a5f1d91c8102e028647607058772cadeb3a4c93
Author: Ian Rogers <[email protected]>

perf tool_pmu: Add network events

This commit adds system-wide network tool PMU events read from /proc/net/dev and updates tool PMU enable, disable, and group leader handling.

Quoted 4 lines
tools/perf/util/tool_pmu.c +0 -0
index 0ae08cd910bc4..655b221043201 100644

[ ... ]

Quoted 15 lines
tools/perf/util/tool_pmu.c +7 -0
@@ -539,40 +676,58 @@ static int open_memory_pid_dir(enum tool_pmu_event ev, int pid,
 	return 0;
 }
 
+static bool tool_pmu__is_initially_disabled(const struct evsel *evsel)
+{
+	const struct evsel *leader = evsel__leader(evsel);
+
+	return evsel->core.attr.disabled || (leader && leader->core.attr.disabled);
+}
+
 static int evsel__tool_pmu_open_one(struct evsel *evsel, enum tool_pmu_event ev,
 				    int pid, int idx, int thread,
 				    int *seen_tgids, int *nr_seen_tgids)
 {

[ ... ]

tools/perf/util/tool_pmu.c static int open_memory_pid_dir(enum tool_pmu_event ev, int pid, · line 725

Quoted 5 lines
tools/perf/util/tool_pmu.c +1 -1
-		if (evsel->core.attr.disabled) {
+		if (tool_pmu__is_initially_disabled(evsel)) {
 			evsel->disabled = true;
 			*start_time = INVALID_START_TIME;
 		} else {

[Severity: Medium]
Does tool_pmu__is_initially_disabled() leave grouped tool events permanently disabled when profiling a forked workload?

When target__enable_on_exec(&target) is true (for example, perf stat -e '{cycles,duration_time}' -- <workload>), create_perf_stat_counter() sets both attr->disabled = 1 and attr->enable_on_exec = 1 on the group leader:

tools/perf/builtin-stat.c:create_perf_stat_counter() {
	...
	if (evsel__is_group_leader(evsel)) {
		attr->disabled = 1;

		if (target__enable_on_exec(&target))
			attr->enable_on_exec = 1;
	}
	...
}

With this change, tool_pmu__is_initially_disabled() returns true for the grouped tool event, so evsel__tool_pmu_open() and evsel__tool_pmu_open_one() set evsel->disabled = true and start_time = INVALID_START_TIME. Because enable_counters() skips evlist__enable() when target__enable_on_exec(&target) is true and userspace tool events have no kernel exec hook, evsel->disabled remains true for the entire run and perf stat reports 0 for the grouped tool counter.

Checking !leader->core.attr.enable_on_exec (and !evsel->core.attr.enable_on_exec) in tool_pmu__is_initially_disabled() would avoid leaving these counters disabled.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
author reviewer
#5 lore raw

PATCH v2 3/4 perf tool_pmu: Add schedstat events

In reply to Ian Rogers

Add per-CPU tool PMU events backed by /proc/schedstat runqueue statistics:
- schedstat_yield: Calls to sched_yield().
- schedstat_schedule: Calls to schedule().
- schedstat_schedule_idle: Calls to schedule() leaving the CPU idle.
- schedstat_wake: Calls to try_to_wake_up().
- schedstat_wake_local: Calls to try_to_wake_up() for the local CPU.
- schedstat_runtime: Task runtime on this CPU in nanoseconds.
- schedstat_wait: Task runqueue wait time on this CPU in nanoseconds.
- schedstat_timeslices: Number of timeslices run on this CPU.

Because /proc/schedstat reports per-CPU runqueue counters, reject per-process and cgroup modes, exclude schedstat events from perf_pmu__reads_only_on_cpu_idx0(), and update should_skip_zero_counter() so zero-valued per-CPU tool events are not suppressed on CPUs > 0. Track initial and accumulated values across enable/disable transitions to report deltas over the measurement interval.

Example system-wide and per-CPU output:

  $ perf stat -a -e schedstat_yield,schedstat_schedule \
      -e schedstat_runtime,schedstat_wait,schedstat_timeslices sleep 0.1

Performance counter stats for 'system wide':

                   0      schedstat_yield
                   0      schedstat_schedule
         455,566,105      schedstat_runtime
             348,262      schedstat_wait
              63,336      schedstat_timeslices
         0.112807668 seconds time elapsed
  $ perf stat -A -C 0,1 -e schedstat_schedule,schedstat_runtime \
      -e schedstat_wait,schedstat_timeslices sleep 0.1

Performance counter stats for 'CPU(s) 0,1':

  CPU0                    0      tool/schedstat_schedule/
  CPU1                    0      tool/schedstat_schedule/
  CPU0            6,217,341      tool/schedstat_runtime/
  CPU1           25,243,949      tool/schedstat_runtime/
  CPU0               11,005      tool/schedstat_wait/
  CPU1               20,921      tool/schedstat_wait/
  CPU0                  115      tool/schedstat_timeslices/
  CPU1                3,535      tool/schedstat_timeslices/
         0.101808548 seconds time elapsed
---
 .../pmu-events/arch/common/common/tool.json   |  48 ++++
 tools/perf/pmu-events/empty-pmu-events.c      | 254 ++++++++++--------
 tools/perf/util/pmu.c                         |   4 +-
 tools/perf/util/stat-display.c                |   8 +-
 tools/perf/util/tool_pmu.c                    | 133 ++++++++-
 tools/perf/util/tool_pmu.h                    |   9 +
 6 files changed, 340 insertions(+), 116 deletions(-)
tools/perf/pmu-events/arch/common/common/tool.json +48 -0
index a332cbf842f7..7c6e03055ca3 100644
@@ -334,5 +334,53 @@
     "EventName": "net_tx_compressed",
     "BriefDescription": "System-wide network transmitted compressed packets",
     "ConfigCode": "56"
+  },
+  {
+    "Unit": "tool",
+    "EventName": "schedstat_yield",
+    "BriefDescription": "Number of times sched_yield() was called",
+    "ConfigCode": "57"
+  },
+  {
+    "Unit": "tool",
+    "EventName": "schedstat_schedule",
+    "BriefDescription": "Number of times schedule() was called",
+    "ConfigCode": "58"
+  },
+  {
+    "Unit": "tool",
+    "EventName": "schedstat_schedule_idle",
+    "BriefDescription": "Number of times schedule() left the processor idle",
+    "ConfigCode": "59"
+  },
+  {
+    "Unit": "tool",
+    "EventName": "schedstat_wake",
+    "BriefDescription": "Number of times try_to_wake_up() was called",
+    "ConfigCode": "60"
+  },
+  {
+    "Unit": "tool",
+    "EventName": "schedstat_wake_local",
+    "BriefDescription": "Number of times try_to_wake_up() was called to wake up the local cpu",
+    "ConfigCode": "61"
+  },
+  {
+    "Unit": "tool",
+    "EventName": "schedstat_runtime",
+    "BriefDescription": "Sum of all time spent running by tasks on this processor (in nanoseconds)",
+    "ConfigCode": "62"
+  },
+  {
+    "Unit": "tool",
+    "EventName": "schedstat_wait",
+    "BriefDescription": "Sum of all time spent waiting to run by tasks on this processor (in nanoseconds)",
+    "ConfigCode": "63"
+  },
+  {
+    "Unit": "tool",
+    "EventName": "schedstat_timeslices",
+    "BriefDescription": "Number of timeslices run on this cpu",
+    "ConfigCode": "64"
   }
 ]
tools/perf/pmu-events/empty-pmu-events.c +143 -111

438 lines not on this page · raw message

tools/perf/util/pmu.c +3 -1
index 01753d5c69d1..f4560a0ec1db 100644
@@ -2830,5 +2830,7 @@ bool perf_pmu__reads_only_on_cpu_idx0(const struct perf_event_attr *attr)
 		return false;
 
 	event = (enum tool_pmu_event)attr->config;
-	return event != TOOL_PMU__EVENT_USER_TIME && event != TOOL_PMU__EVENT_SYSTEM_TIME;
+	return event != TOOL_PMU__EVENT_USER_TIME &&
+	       event != TOOL_PMU__EVENT_SYSTEM_TIME &&
+	       !tool_pmu__is_sched_stat_event(event);
 }
tools/perf/util/stat-display.c +6 -2
index b337cc23f413..6671403c587c 100644
@@ -929,9 +929,13 @@ static bool should_skip_zero_counter(struct perf_stat_config *config,
 	 * system_time, but for many the first index is the only one used, for
 	 * example num_cores. Don't skip for the first index.
 	 */
-	if (evsel__is_tool(counter)) {
+	if (evsel__is_tool(counter) &&
+	    (counter->core.reads_only_on_cpu_idx0 || counter->pid_stat)) {
+		struct perf_cpu first_cpu = perf_cpu_map__cpu(counter->core.cpus, 0);
 		struct aggr_cpu_id own_id =
-			config->aggr_get_id(config, (struct perf_cpu){ .cpu = 0 });
+			config->aggr_get_id(config,
+					    first_cpu.cpu >= 0 ? first_cpu
+							       : (struct perf_cpu){ .cpu = 0 });
 
 		return !aggr_cpu_id__equal(id, &own_id);
 	}
tools/perf/util/tool_pmu.c +131 -2

181 lines not on this page · raw message

tools/perf/util/tool_pmu.h +9 -0
index f972995bb8ed..5a290a9e7555 100644
@@ -66,6 +66,14 @@ enum tool_pmu_event {
 	TOOL_PMU__EVENT_NET_TX_COLLS,
 	TOOL_PMU__EVENT_NET_TX_CARRIER,
 	TOOL_PMU__EVENT_NET_TX_COMPRESSED,
+	TOOL_PMU__EVENT_SCHEDSTAT_YIELD,
+	TOOL_PMU__EVENT_SCHEDSTAT_SCHEDULE,
+	TOOL_PMU__EVENT_SCHEDSTAT_SCHEDULE_IDLE,
+	TOOL_PMU__EVENT_SCHEDSTAT_WAKE,
+	TOOL_PMU__EVENT_SCHEDSTAT_WAKE_LOCAL,
+	TOOL_PMU__EVENT_SCHEDSTAT_RUNTIME,
+	TOOL_PMU__EVENT_SCHEDSTAT_WAIT,
+	TOOL_PMU__EVENT_SCHEDSTAT_TIMESLICES,
 
 	TOOL_PMU__EVENT_MAX,
 };
@@ -77,6 +85,7 @@ const char *tool_pmu__event_to_str(enum tool_pmu_event ev);
 enum tool_pmu_event tool_pmu__str_to_event(const char *str);
 bool tool_pmu__skip_event(const char *name);
 int tool_pmu__num_skip_events(void);
+bool tool_pmu__is_sched_stat_event(enum tool_pmu_event ev);
 
 bool tool_pmu__read_event(enum tool_pmu_event ev,
 			  struct evsel *evsel,
Signature · 1 line
2.56.1.703.gf848ed807c-goog
#6 lore raw

Re: [PATCH v2 3/4] perf tool_pmu: Add schedstat events

Sashiko has reviewed this patch and found no issues.
Quoted 18 lines

Add per-CPU tool PMU events backed by /proc/schedstat runqueue statistics:
- schedstat_yield: Calls to sched_yield().
- schedstat_schedule: Calls to schedule().
- schedstat_schedule_idle: Calls to schedule() leaving the CPU idle.
- schedstat_wake: Calls to try_to_wake_up().
- schedstat_wake_local: Calls to try_to_wake_up() for the local CPU.
- schedstat_runtime: Task runtime on this CPU in nanoseconds.
- schedstat_wait: Task runqueue wait time on this CPU in nanoseconds.
- schedstat_timeslices: Number of timeslices run on this CPU.

Because /proc/schedstat reports per-CPU runqueue counters, reject per-process and cgroup modes, exclude schedstat events from perf_pmu__reads_only_on_cpu_idx0(), and update should_skip_zero_counter() so zero-valued per-CPU tool events are not suppressed on CPUs > 0. Track [ ... ]
CPU1 3,535 tool/schedstat_timeslices/

Quoted 3 lines
         0.101808548 seconds time elapsed

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
author reviewer
#7 lore raw

PATCH v2 4/4 perf test tool_pmu: Add memory, network and schedstat tests

In reply to Ian Rogers

Extend the Tool PMU unit test suite with subtests covering:
- Per-process, multi-threaded Tgid deduplication, and system-wide reading of memory events (smaps_rollup and statm).
- Per-process open rejection (-EINVAL) and synthetic /proc/net/dev parsing (including space-padded and unpadded columns) across enable/disable transitions for network events.
- Per-process open rejection (-EINVAL) and per-CPU synthetic /proc/schedstat delta accumulation across enable/disable transitions for schedstat events.
- Mixed CPU-map tool groups ({schedstat_yield,net_rx_bytes} and {net_rx_bytes,schedstat_yield}) across evlist__enable() and evlist__disable().

---
 tools/perf/tests/tool_pmu.c | 689 ++++++++++++++++++++++++++++++++++++
 1 file changed, 689 insertions(+)
tools/perf/tests/tool_pmu.c +689 -0
index 667160f9e2cd..783aa13abe40 100644
@@ -1,14 +1,20 @@
 // SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
 #include <errno.h>
 #include <fcntl.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
+#include <sys/types.h>
 #include <unistd.h>
 #include <internal/xyarray.h>
+#include "counts.h"
 #include "cpumap.h"
 #include "debug.h"
 #include "evlist.h"
 #include "evsel.h"
 #include "parse-events.h"
+#include "target.h"
 #include "tests.h"
 #include "thread_map.h"
 #include "tool_pmu.h"
@@ -178,10 +184,693 @@ static int test__tool_pmu_incremental_open_unwind(struct test_suite *test __mayb
 	return ret;
 }
 
+static int write_temp_file(int fd, const char *contents)
+{
+	size_t len = strlen(contents);
+
+	if (ftruncate(fd, 0) < 0)
+		return -1;
+	if (lseek(fd, 0, SEEK_SET) < 0)
+		return -1;
+	if ((size_t)write(fd, contents, len) != len)
+		return -1;
+	return 0;
+}
+
+struct sleeper_thread_args {
+	int ready_fd;
+	int stop_fd;
+};
+
+static void *sleeper_thread_fn(void *arg)
+{
+	struct sleeper_thread_args *args = arg;
+	char ch = '1';
+
+	if (write(args->ready_fd, &ch, 1) == 1) {
+		while (read(args->stop_fd, &ch, 1) < 0 && errno == EINTR)
+			;
+	}
+	return NULL;
+}
+
+static int check_multithread_memory_dedup(struct perf_cpu_map *cpus)
+{
+	struct evlist *evlist = NULL;
+	struct perf_thread_map *mt_threads = NULL;
+	struct parse_events_error err;
+	struct sleeper_thread_args args;
+	struct evsel *evsel;
+	int ready_pipe[2] = { -1, -1 }, stop_pipe[2] = { -1, -1 };
+	pthread_t th;
+	bool th_started = false;
+	int nthreads, non_zero = 0, ret = TEST_FAIL;
+	u64 total_rss = 0;
+	char ch;
+
+	if (pipe(ready_pipe) < 0 || pipe(stop_pipe) < 0)
+		goto out;
+
+	args.ready_fd = ready_pipe[1];
+	args.stop_fd = stop_pipe[0];
+	if (pthread_create(&th, NULL, sleeper_thread_fn, &args) != 0)
+		goto out;
+	th_started = true;
+
+	if (read(ready_pipe[0], &ch, 1) != 1)
+		goto out;
+
+	mt_threads = thread_map__new_by_pid(getpid());
+	nthreads = perf_thread_map__nr(mt_threads);
+	if (!mt_threads || nthreads < 2) {
+		pr_debug("Expected >= 2 threads for getpid(), got %d\n", nthreads);
+		goto out;
+	}
+
+	evlist = evlist__new();
+	if (!evlist)
+		goto out;
+
+	parse_events_error__init(&err);
+	if (parse_events(evlist, "memory_rss", &err)) {
+		parse_events_error__exit(&err);
+		goto out;
+	}
+	parse_events_error__exit(&err);
+
+	perf_evlist__set_maps(evlist__core(evlist), cpus, mt_threads);
+	evsel = evlist__first(evlist);
+	if (evsel__alloc_counts(evsel) < 0 ||
+	    evsel__open(evsel, cpus, mt_threads) < 0)
+		goto out;
+
+	for (int t = 0; t < nthreads; t++) {
+		u64 val;
+
+		if (evsel__read_counter(evsel, 0, t) < 0)
+			goto out;
+		val = perf_counts(evsel->counts, 0, t)->val;
+		if (val > 0)
+			non_zero++;
+		total_rss += val;
+	}
+
+	if (non_zero != 1 || total_rss == 0) {
+		pr_debug("Expected 1 non-zero thread slot for memory_rss, got %d (sum=%llu)\n",
+			 non_zero, (unsigned long long)total_rss);
+		goto out;
+	}
+
+	ret = TEST_OK;
+out:
+	if (stop_pipe[1] >= 0) {
+		close(stop_pipe[1]);
+		stop_pipe[1] = -1;
+	}
+	if (th_started)
+		pthread_join(th, NULL);
+	if (ready_pipe[0] >= 0)
+		close(ready_pipe[0]);
+	if (ready_pipe[1] >= 0)
+		close(ready_pipe[1]);
+	if (stop_pipe[0] >= 0)
+		close(stop_pipe[0]);
+	if (evlist) {
+		evlist__for_each_entry(evlist, evsel)
+			evsel__close(evsel);
+		evlist__put(evlist);
+	}
+	perf_thread_map__put(mt_threads);
+	return ret;
+}
+
+static int test__tool_pmu_memory_events(struct test_suite *test __maybe_unused,
+					int subtest __maybe_unused)
+{
+	struct evlist *evlist = evlist__new();
+	struct parse_events_error err;
+	struct perf_cpu_map *cpus = NULL;
+	struct perf_thread_map *threads = NULL, *sys_threads = NULL;
+	struct evsel *evsel;
+	u64 pid_rss = 0, pid_uss = 0, pid_size = 0, pid_text = 0, pid_data = 0;
+	u64 sys_size = 0;
+	const char *events =
+		"memory_rss,memory_uss,memory_size,memory_text,memory_data";
+	int ret = TEST_FAIL;
+
+	if (!evlist)
+		return TEST_FAIL;
+
+	parse_events_error__init(&err);
+	if (parse_events(evlist, events, &err)) {
+		parse_events_error__exit(&err);
+		evlist__put(evlist);
+		return TEST_FAIL;
+	}
+	parse_events_error__exit(&err);
+
+	cpus = perf_cpu_map__new_int(0);
+	threads = thread_map__new_by_tid(getpid());
+	if (!cpus || !threads)
+		goto out;
+	perf_evlist__set_maps(evlist__core(evlist), cpus, threads);
+
+	evlist__for_each_entry(evlist, evsel) {
+		enum tool_pmu_event ev = evsel__tool_event(evsel);
+		struct perf_counts_values *count;
+
+		if (evsel__alloc_counts(evsel) < 0)
+			goto out;
+		if (evsel__open(evsel, cpus, threads) < 0) {
+			pr_debug("Failed to open %s per-process\n", evsel__name(evsel));
+			goto out;
+		}
+		if (evsel__read_counter(evsel, 0, 0) < 0) {
+			pr_debug("Failed to read %s per-process\n", evsel__name(evsel));
+			goto out;
+		}
+		count = perf_counts(evsel->counts, 0, 0);
+		if (ev == TOOL_PMU__EVENT_MEMORY_RSS)
+			pid_rss = count->val;
+		else if (ev == TOOL_PMU__EVENT_MEMORY_USS)
+			pid_uss = count->val;
+		else if (ev == TOOL_PMU__EVENT_MEMORY_SIZE)
+			pid_size = count->val;
+		else if (ev == TOOL_PMU__EVENT_MEMORY_TEXT)
+			pid_text = count->val;
+		else if (ev == TOOL_PMU__EVENT_MEMORY_DATA)
+			pid_data = count->val;
+		else
+			goto out;
+		evsel__close(evsel);
+	}
+
+	if (pid_rss == 0 || pid_size < pid_rss || pid_uss > pid_rss ||
+	    pid_text == 0 || pid_data == 0) {
+		pr_debug("Unexpected per-pid memory values: rss=%llu uss=%llu size=%llu text=%llu data=%llu\n",
+			 (unsigned long long)pid_rss, (unsigned long long)pid_uss,
+			 (unsigned long long)pid_size, (unsigned long long)pid_text,
+			 (unsigned long long)pid_data);
+		goto out;
+	}
+
+	/* Verify system-wide aggregation on memory_size. */
+	sys_threads = perf_thread_map__new_dummy();
+	if (!sys_threads)
+		goto out;
+
+	evlist__for_each_entry(evlist, evsel) {
+		if (evsel__tool_event(evsel) != TOOL_PMU__EVENT_MEMORY_SIZE)
+			continue;
+		evsel->pid_stat = false;
+		evsel->core.system_wide = true;
+		if (evsel__open(evsel, cpus, sys_threads) < 0)
+			goto out;
+		if (evsel__read_counter(evsel, 0, 0) < 0)
+			goto out;
+		sys_size = perf_counts(evsel->counts, 0, 0)->val;
+		evsel__close(evsel);
+	}
+
+	if (sys_size < pid_size) {
+		pr_debug("System-wide memory_size (%llu) < pid memory_size (%llu)\n",
+			 (unsigned long long)sys_size, (unsigned long long)pid_size);
+		goto out;
+	}
+
+	if (check_multithread_memory_dedup(cpus) != TEST_OK)
+		goto out;
+
+	ret = TEST_OK;
+out:
+	evlist__for_each_entry(evlist, evsel)
+		evsel__close(evsel);
+	perf_thread_map__put(sys_threads);
+	perf_thread_map__put(threads);
+	perf_cpu_map__put(cpus);
+	evlist__put(evlist);
+	return ret;
+}
+
+static int test__tool_pmu_net_events(struct test_suite *test __maybe_unused,
+				     int subtest __maybe_unused)
+{
+	static const char snap1[] =
+		"Inter-|   Receive |  Transmit\n"
+		" face |bytes packets errs drop fifo frame compressed multicast|bytes packets...\n"
+		"    lo:    1000   10  0  0  0  0  0  0    2000   20  0  0  0  0  0   5\n"
+		"  eth0:123456789012  100  0  0  0  0  0  0    3000   30  0  0  0  0  0   7\n";
+	static const char snap2[] =
+		"Inter-|   Receive |  Transmit\n"
+		" face |bytes packets errs drop fifo frame compressed multicast|bytes packets...\n"
+		"    lo:    1500   12  0  0  0  0  0  0    2250   20  0  0  0  0  0   8\n"
+		"  eth0:123456789612  105  0  0  0  0  0  0    3750   30  0  0  0  0  0  11\n";
+	static const char snap3[] =
+		"Inter-|   Receive |  Transmit\n"
+		" face |bytes packets errs drop fifo frame compressed multicast|bytes packets...\n"
+		"    lo:    9999   99  0  0  0  0  0  0    9999   99  0  0  0  0  0  99\n"
+		"  eth0:123456799999  999  0  0  0  0  0  0    9999   99  0  0  0  0  0  99\n";
+	const char *events =
+		"net_rx_bytes,net_rx_packets,net_tx_bytes,net_tx_compressed";
+	char tmp_path[] = "/tmp/perf-tool-net-XXXXXX";
+	struct evlist *evlist = evlist__new();
+	struct parse_events_error err;
+	struct perf_cpu_map *cpus = NULL;
+	struct perf_thread_map *pid_threads = NULL, *sys_threads = NULL;
+	struct evsel *evsel;
+	int ret = TEST_FAIL, tmp_fd = -1;
+
+	if (!evlist)
+		return TEST_FAIL;
+
+	parse_events_error__init(&err);
+	if (parse_events(evlist, events, &err)) {
+		parse_events_error__exit(&err);
+		evlist__put(evlist);
+		return TEST_FAIL;
+	}
+	parse_events_error__exit(&err);
+
+	cpus = perf_cpu_map__new_int(0);
+	pid_threads = thread_map__new_by_tid(getpid());
+	sys_threads = perf_thread_map__new_dummy();
+	if (!cpus || !pid_threads || !sys_threads)
+		goto out;
+
+	/* Per-process open must fail with EINVAL. */
+	evsel = evlist__first(evlist);
+	errno = 0;
+	if (evsel__open(evsel, cpus, pid_threads) != -EINVAL || errno != EINVAL) {
+		pr_debug("Expected -EINVAL opening net_rx_bytes per-process\n");
+		goto out;
+	}
+
+	if (access("/proc/net/dev", R_OK) != 0) {
+		ret = TEST_SKIP;
+		goto out;
+	}
+
+	tmp_fd = mkstemp(tmp_path);
+	if (tmp_fd < 0)
+		goto out;
+	unlink(tmp_path);
+
+	if (write_temp_file(tmp_fd, snap1) < 0)
+		goto out;
+
+	evlist__for_each_entry(evlist, evsel) {
+		int fd;
+
+		evsel->supported = true;
+		evsel->core.system_wide = true;
+		evsel->core.attr.disabled = 1;
+		perf_cpu_map__put(evsel->core.cpus);
+		evsel->core.cpus = perf_cpu_map__get(cpus);
+		perf_thread_map__put(evsel->core.threads);
+		evsel->core.threads = perf_thread_map__get(sys_threads);
+		if (evsel__alloc_counts(evsel) < 0)
+			goto out;
+		if (evsel__open(evsel, cpus, sys_threads) < 0)
+			goto out;
+		fd = *(int *)xyarray__entry(evsel->core.fd, 0, 0);
+		if (fd < 0 || dup2(tmp_fd, fd) < 0)
+			goto out;
+
+		/* Reading while initially disabled must return 0. */
+		if (evsel__read_counter(evsel, 0, 0) < 0 ||
+		    perf_counts(evsel->counts, 0, 0)->val != 0)
+			goto out;
+		if (evsel__enable(evsel) < 0)
+			goto out;
+	}
+
+	if (write_temp_file(tmp_fd, snap2) < 0)
+		goto out;
+
+	evlist__for_each_entry(evlist, evsel) {
+		if (evsel__disable(evsel) < 0)
+			goto out;
+	}
+
+	/* Traffic occurring while disabled must not change accumulated counts. */
+	if (write_temp_file(tmp_fd, snap3) < 0)
+		goto out;
+
+	evlist__for_each_entry(evlist, evsel) {
+		enum tool_pmu_event ev = evsel__tool_event(evsel);
+		u64 got, expected;
+
+		if (evsel__read_counter(evsel, 0, 0) < 0)
+			goto out;
+		got = perf_counts(evsel->counts, 0, 0)->val;
+		if (ev == TOOL_PMU__EVENT_NET_RX_BYTES)
+			expected = 1100;
+		else if (ev == TOOL_PMU__EVENT_NET_RX_PACKETS)
+			expected = 7;
+		else if (ev == TOOL_PMU__EVENT_NET_TX_BYTES)
+			expected = 1000;
+		else if (ev == TOOL_PMU__EVENT_NET_TX_COMPRESSED)
+			expected = 7;
+		else
+			goto out;
+		if (got != expected) {
+			pr_debug("Mismatch for %s: got %llu, expected %llu\n",
+				 evsel__name(evsel), (unsigned long long)got,
+				 (unsigned long long)expected);
+			goto out;
+		}
+	}
+
+	ret = TEST_OK;
+out:
+	if (tmp_fd >= 0)
+		close(tmp_fd);
+	evlist__for_each_entry(evlist, evsel)
+		evsel__close(evsel);
+	perf_thread_map__put(sys_threads);
+	perf_thread_map__put(pid_threads);
+	perf_cpu_map__put(cpus);
+	evlist__put(evlist);
+	return ret;
+}
+
+static int test__tool_pmu_schedstat_events(struct test_suite *test __maybe_unused,
+					   int subtest __maybe_unused)
+{
+	static const char snap1[] =
+		"version 17\n"
+		"timestamp 4295733968\n"
+		"cpu0 10 0 100 50 80 40 1000000 200000 300\n"
+		"domain0 SMT 0000003 0 0 0\n"
+		"cpu1 20 0 200 60 90 45 5000000 400000 700\n";
+	static const char snap2[] =
+		"version 17\n"
+		"timestamp 4295734068\n"
+		"cpu0 13 0 110 55 85 42 1250000 210000 315\n"
+		"domain0 SMT 0000003 0 0 0\n"
+		"cpu1 20 0 220 70 95 48 5750000 420000 725\n";
+	char tmp_path[] = "/tmp/perf-tool-sched-XXXXXX";
+	struct evlist *evlist = evlist__new();
+	struct parse_events_error err;
+	struct perf_cpu_map *cpus = NULL;
+	struct perf_thread_map *pid_threads = NULL, *sys_threads = NULL;
+	struct evsel *evsel;
+	const char *events =
+		"tool/schedstat_yield/,tool/schedstat_runtime/,tool/schedstat_timeslices/";
+	int ret = TEST_FAIL, tmp_fd = -1;
+
+	if (!evlist)
+		return TEST_FAIL;
+
+	parse_events_error__init(&err);
+	if (parse_events(evlist, events, &err)) {
+		parse_events_error__exit(&err);
+		evlist__put(evlist);
+		return TEST_FAIL;
+	}
+	parse_events_error__exit(&err);
+
+	cpus = perf_cpu_map__new("0,1");
+	pid_threads = thread_map__new_by_tid(getpid());
+	sys_threads = perf_thread_map__new_dummy();
+	if (!cpus || !pid_threads || !sys_threads)
+		goto out;
+
+	/* Per-process open must fail with EINVAL. */
+	evsel = evlist__first(evlist);
+	errno = 0;
+	if (evsel__open(evsel, cpus, pid_threads) != -EINVAL || errno != EINVAL) {
+		pr_debug("Expected -EINVAL opening schedstat_yield per-process\n");
+		goto out;
+	}
+
+	if (access("/proc/schedstat", R_OK) != 0) {
+		ret = TEST_SKIP;
+		goto out;
+	}
+
+	tmp_fd = mkstemp(tmp_path);
+	if (tmp_fd < 0)
+		goto out;
+	unlink(tmp_path);
+
+	if (write_temp_file(tmp_fd, snap1) < 0)
+		goto out;
+
+	evlist__for_each_entry(evlist, evsel) {
+		evsel->supported = true;
+		evsel->core.system_wide = true;
+		evsel->core.attr.disabled = 1;
+		perf_cpu_map__put(evsel->core.cpus);
+		evsel->core.cpus = perf_cpu_map__get(cpus);
+		perf_thread_map__put(evsel->core.threads);
+		evsel->core.threads = perf_thread_map__get(sys_threads);
+		if (evsel__alloc_counts(evsel) < 0)
+			goto out;
+		if (evsel__open(evsel, cpus, sys_threads) < 0)
+			goto out;
+		for (int cpu_idx = 0; cpu_idx < 2; cpu_idx++) {
+			int fd = *(int *)xyarray__entry(evsel->core.fd, cpu_idx, 0);
+
+			if (fd < 0 || dup2(tmp_fd, fd) < 0)
+				goto out;
+		}
+		if (evsel__enable(evsel) < 0)
+			goto out;
+	}
+
+	if (write_temp_file(tmp_fd, snap2) < 0)
+		goto out;
+
+	evlist__for_each_entry(evlist, evsel) {
+		enum tool_pmu_event ev = evsel__tool_event(evsel);
+		u64 c0, c1, exp0, exp1;
+
+		if (evsel__disable(evsel) < 0)
+			goto out;
+		if (evsel__read_counter(evsel, 0, 0) < 0 ||
+		    evsel__read_counter(evsel, 1, 0) < 0)
+			goto out;
+		c0 = perf_counts(evsel->counts, 0, 0)->val;
+		c1 = perf_counts(evsel->counts, 1, 0)->val;
+		if (ev == TOOL_PMU__EVENT_SCHEDSTAT_YIELD) {
+			exp0 = 3;
+			exp1 = 0;
+		} else if (ev == TOOL_PMU__EVENT_SCHEDSTAT_RUNTIME) {
+			exp0 = 250000;
+			exp1 = 750000;
+		} else if (ev == TOOL_PMU__EVENT_SCHEDSTAT_TIMESLICES) {
+			exp0 = 15;
+			exp1 = 25;
+		} else {
+			goto out;
+		}
+		if (c0 != exp0 || c1 != exp1) {
+			pr_debug("Mismatch for %s: got (%llu, %llu), expected (%llu, %llu)\n",
+				 evsel__name(evsel),
+				 (unsigned long long)c0, (unsigned long long)c1,
+				 (unsigned long long)exp0, (unsigned long long)exp1);
+			goto out;
+		}
+	}
+
+	ret = TEST_OK;
+out:
+	if (tmp_fd >= 0)
+		close(tmp_fd);
+	evlist__for_each_entry(evlist, evsel)
+		evsel__close(evsel);
+	perf_thread_map__put(sys_threads);
+	perf_thread_map__put(pid_threads);
+	perf_cpu_map__put(cpus);
+	evlist__put(evlist);
+	return ret;
+}
+
+static int run_mixed_group_case(const char *group_str, const char *cpu_list,
+				int c0, int c1, int net_fd, int sched_fd)
+{
+	static const char net_snap1[] =
+		"Inter-|   Receive |  Transmit\n"
+		" face |bytes packets errs drop fifo frame compressed multicast|bytes packets...\n"
+		"    lo:    1000   10  0  0  0  0  0  0    2000   20  0  0  0  0  0   0\n";
+	static const char net_snap2[] =
+		"Inter-|   Receive |  Transmit\n"
+		" face |bytes packets errs drop fifo frame compressed multicast|bytes packets...\n"
+		"    lo:    1600   15  0  0  0  0  0  0    2000   20  0  0  0  0  0   0\n";
+	struct target target = {
+		.system_wide = true,
+		.cpu_list = cpu_list,
+	};
+	struct evlist *evlist = evlist__new();
+	struct parse_events_error err;
+	struct evsel *evsel, *net_evsel = NULL, *sched_evsel = NULL;
+	char sched_snap1[256], sched_snap2[256];
+	int ret = TEST_FAIL;
+
+	if (!evlist)
+		return TEST_FAIL;
+
+	snprintf(sched_snap1, sizeof(sched_snap1),
+		 "version 17\ncpu%d 10 0 0 0 0 0 0 0 0\ncpu%d 20 0 0 0 0 0 0 0 0\n",
+		 c0, c1);
+	snprintf(sched_snap2, sizeof(sched_snap2),
+		 "version 17\ncpu%d 13 0 0 0 0 0 0 0 0\ncpu%d 27 0 0 0 0 0 0 0 0\n",
+		 c0, c1);
+
+	parse_events_error__init(&err);
+	if (parse_events(evlist, group_str, &err)) {
+		parse_events_error__exit(&err);
+		goto out;
+	}
+	parse_events_error__exit(&err);
+
+	if (evlist__create_maps(evlist, &target) < 0)
+		goto out;
+
+	if (write_temp_file(net_fd, net_snap1) < 0 ||
+	    write_temp_file(sched_fd, sched_snap1) < 0)
+		goto out;
+
+	evlist__for_each_entry(evlist, evsel) {
+		enum tool_pmu_event ev = evsel__tool_event(evsel);
+
+		evsel->supported = true;
+		evsel->core.system_wide = true;
+		/* Only group leaders set attr.disabled = 1 in perf stat/evsel__config. */
+		if (evsel__is_group_leader(evsel))
+			evsel->core.attr.disabled = 1;
+		if (evsel__alloc_counts(evsel) < 0 ||
+		    evsel__open(evsel, evsel->core.cpus, evsel->core.threads) < 0)
+			goto out;
+		if (!evsel->disabled)
+			goto out;
+
+		if (ev == TOOL_PMU__EVENT_NET_RX_BYTES) {
+			int fd;
+
+			net_evsel = evsel;
+			if (perf_cpu_map__nr(evsel->core.cpus) != 1)
+				goto out;
+			fd = *(int *)xyarray__entry(evsel->core.fd, 0, 0);
+			if (fd < 0 || dup2(net_fd, fd) < 0)
+				goto out;
+		} else if (ev == TOOL_PMU__EVENT_SCHEDSTAT_YIELD) {
+			sched_evsel = evsel;
+			if (perf_cpu_map__nr(evsel->core.cpus) != 2)
+				goto out;
+			for (int idx = 0; idx < 2; idx++) {
+				int fd = *(int *)xyarray__entry(evsel->core.fd, idx, 0);
+
+				if (fd < 0 || dup2(sched_fd, fd) < 0)
+					goto out;
+			}
+		} else {
+			goto out;
+		}
+	}
+
+	if (!net_evsel || !sched_evsel)
+		goto out;
+
+	/* Both leader and member must read 0 while the group is still disabled. */
+	if (evsel__read_counter(net_evsel, 0, 0) < 0 ||
+	    evsel__read_counter(sched_evsel, 0, 0) < 0 ||
+	    evsel__read_counter(sched_evsel, 1, 0) < 0 ||
+	    perf_counts(net_evsel->counts, 0, 0)->val != 0 ||
+	    perf_counts(sched_evsel->counts, 0, 0)->val != 0 ||
+	    perf_counts(sched_evsel->counts, 1, 0)->val != 0)
+		goto out;
+
+	evlist__enable(evlist);
+
+	if (write_temp_file(net_fd, net_snap2) < 0 ||
+	    write_temp_file(sched_fd, sched_snap2) < 0)
+		goto out;
+
+	evlist__disable(evlist);
+
+	if (evsel__read_counter(net_evsel, 0, 0) < 0 ||
+	    evsel__read_counter(sched_evsel, 0, 0) < 0 ||
+	    evsel__read_counter(sched_evsel, 1, 0) < 0)
+		goto out;
+
+	if (perf_counts(net_evsel->counts, 0, 0)->val != 600 ||
+	    perf_counts(sched_evsel->counts, 0, 0)->val != 3 ||
+	    perf_counts(sched_evsel->counts, 1, 0)->val != 7) {
+		pr_debug("Unexpected mixed group counts for %s: net=%llu sched=(%llu, %llu)\n",
+			 group_str,
+			 (unsigned long long)perf_counts(net_evsel->counts, 0, 0)->val,
+			 (unsigned long long)perf_counts(sched_evsel->counts, 0, 0)->val,
+			 (unsigned long long)perf_counts(sched_evsel->counts, 1, 0)->val);
+		goto out;
+	}
+
+	ret = TEST_OK;
+out:
+	evlist__for_each_entry(evlist, evsel)
+		evsel__close(evsel);
+	evlist__put(evlist);
+	return ret;
+}
+
+static int test__tool_pmu_mixed_group_events(struct test_suite *test __maybe_unused,
+					     int subtest __maybe_unused)
+{
+	char net_path[] = "/tmp/perf-tool-grp-net-XXXXXX";
+	char sched_path[] = "/tmp/perf-tool-grp-sched-XXXXXX";
+	struct perf_cpu_map *online = NULL;
+	char cpu_list[64];
+	int net_fd = -1, sched_fd = -1, c0, c1, ret = TEST_FAIL;
+
+	if (access("/proc/net/dev", R_OK) != 0 ||
+	    access("/proc/schedstat", R_OK) != 0)
+		return TEST_SKIP;
+
+	online = cpu_map__online();
+	if (!online || perf_cpu_map__nr(online) < 2) {
+		perf_cpu_map__put(online);
+		return TEST_SKIP;
+	}
+	c0 = perf_cpu_map__cpu(online, 0).cpu;
+	c1 = perf_cpu_map__cpu(online, 1).cpu;
+	perf_cpu_map__put(online);
+	snprintf(cpu_list, sizeof(cpu_list), "%d,%d", c0, c1);
+
+	net_fd = mkstemp(net_path);
+	if (net_fd < 0)
+		goto out;
+	unlink(net_path);
+
+	sched_fd = mkstemp(sched_path);
+	if (sched_fd < 0)
+		goto out;
+	unlink(sched_path);
+
+	if (run_mixed_group_case("{schedstat_yield,net_rx_bytes}",
+				 cpu_list, c0, c1, net_fd, sched_fd) != TEST_OK)
+		goto out;
+	if (run_mixed_group_case("{net_rx_bytes,schedstat_yield}",
+				 cpu_list, c0, c1, net_fd, sched_fd) != TEST_OK)
+		goto out;
+
+	ret = TEST_OK;
+out:
+	if (net_fd >= 0)
+		close(net_fd);
+	if (sched_fd >= 0)
+		close(sched_fd);
+	return ret;
+}
+
 static struct test_case tests__tool_pmu[] = {
 	TEST_CASE("Parsing without PMU name", tool_pmu_without_pmu),
 	TEST_CASE("Parsing with PMU name", tool_pmu_with_pmu),
 	TEST_CASE("Incremental open error unwind boundary", tool_pmu_incremental_open_unwind),
+	TEST_CASE("Memory events", tool_pmu_memory_events),
+	TEST_CASE("Network events", tool_pmu_net_events),
+	TEST_CASE("Schedstat events", tool_pmu_schedstat_events),
+	TEST_CASE("Mixed CPU-map tool groups", tool_pmu_mixed_group_events),
 	{	.name = NULL, }
 };
 
Signature · 1 line
2.56.1.703.gf848ed807c-goog
#8 lore raw

Re: [PATCH v2 4/4] perf test tool_pmu: Add memory, network and schedstat tests

Sashiko has reviewed this patch and found no issues.
Quoted 13 lines

Extend the Tool PMU unit test suite with subtests covering:
- Per-process, multi-threaded Tgid deduplication, and system-wide reading of memory events (smaps_rollup and statm).
- Per-process open rejection (-EINVAL) and synthetic /proc/net/dev parsing (including space-padded and unpadded columns) across enable/disable transitions for network events.
- Per-process open rejection (-EINVAL) and per-CPU synthetic /proc/schedstat delta accumulation across enable/disable transitions for schedstat events.
- Mixed CPU-map tool groups ({schedstat_yield,net_rx_bytes} and {net_rx_bytes,schedstat_yield}) across evlist__enable() and evlist__disable().

Quoted 1 line

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4