From: Ian Rogers Date: Thu, 13 Nov 2025 18:05:11 +0000 (-0800) Subject: perf stat: Reduce scope of ru_stats X-Git-Tag: v6.19-rc1~61^2~100 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=557c34435b4492860452d6c0e8444320f8614f62;p=thirdparty%2Fkernel%2Flinux.git perf stat: Reduce scope of ru_stats The ru_stats are used to capture user and system time stats when a process exits. These are then applied to user and system time tool events if their reads fail due to the process terminating. Reduce the scope now the metric code no longer reads these values. Signed-off-by: Ian Rogers Signed-off-by: Namhyung Kim --- diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 654f840f7a2f1..d6f4c84f7d7e5 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -104,6 +104,11 @@ #define DEFAULT_SEPARATOR " " #define FREEZE_ON_SMI_PATH "bus/event_source/devices/cpu/freeze_on_smi" +struct rusage_stats { + struct stats ru_utime_usec_stat; + struct stats ru_stime_usec_stat; +}; + static void print_counters(struct timespec *ts, int argc, const char **argv); static struct evlist *evsel_list; @@ -133,6 +138,7 @@ static bool interval_count; static const char *output_name; static int output_fd; static char *metrics; +static struct rusage_stats ru_stats; struct perf_stat { bool record; @@ -730,6 +736,17 @@ 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; @@ -979,7 +996,7 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx) evlist__reset_aggr_stats(evsel_list); } else { update_stats(&walltime_nsecs_stats, t1 - t0); - update_rusage_stats(&ru_stats, &stat_config.ru_data); + update_rusage_stats(&stat_config.ru_data); } /* diff --git a/tools/perf/util/config.c b/tools/perf/util/config.c index 6f914620c6ff2..cc0746f494f48 100644 --- a/tools/perf/util/config.c +++ b/tools/perf/util/config.c @@ -45,7 +45,6 @@ struct perf_stat_config stat_config = { .run_count = 1, .metric_only_len = METRIC_ONLY_LEN, .walltime_nsecs_stats = &walltime_nsecs_stats, - .ru_stats = &ru_stats, .big_num = true, .ctl_fd = -1, .ctl_fd_ack = -1, diff --git a/tools/perf/util/stat-shadow.c b/tools/perf/util/stat-shadow.c index 8622ed64c617c..337a8aa547c3d 100644 --- a/tools/perf/util/stat-shadow.c +++ b/tools/perf/util/stat-shadow.c @@ -19,12 +19,10 @@ #include "tool_pmu.h" struct stats walltime_nsecs_stats; -struct rusage_stats ru_stats; void perf_stat__reset_shadow_stats(void) { memset(&walltime_nsecs_stats, 0, sizeof(walltime_nsecs_stats)); - memset(&ru_stats, 0, sizeof(ru_stats)); } static bool tool_pmu__is_time_event(const struct perf_stat_config *config, diff --git a/tools/perf/util/stat.h b/tools/perf/util/stat.h index b42da4a29c442..055b95d18106a 100644 --- a/tools/perf/util/stat.h +++ b/tools/perf/util/stat.h @@ -56,11 +56,6 @@ enum aggr_mode { AGGR_MAX }; -struct rusage_stats { - struct stats ru_utime_usec_stat; - struct stats ru_stime_usec_stat; -}; - typedef struct aggr_cpu_id (*aggr_get_id_t)(struct perf_stat_config *config, struct perf_cpu cpu); struct perf_stat_config { @@ -102,7 +97,6 @@ struct perf_stat_config { const char *csv_sep; struct stats *walltime_nsecs_stats; struct rusage ru_data; - struct rusage_stats *ru_stats; struct cpu_aggr_map *aggr_map; aggr_get_id_t aggr_get_id; struct cpu_aggr_map *cpus_aggr_map; @@ -132,25 +126,10 @@ static inline void init_stats(struct stats *stats) stats->max = 0; } -static inline void init_rusage_stats(struct rusage_stats *ru_stats) { - init_stats(&ru_stats->ru_utime_usec_stat); - init_stats(&ru_stats->ru_stime_usec_stat); -} - -static inline void update_rusage_stats(struct rusage_stats *ru_stats, 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)); -} - struct evsel; struct evlist; extern struct stats walltime_nsecs_stats; -extern struct rusage_stats ru_stats; enum metric_threshold_classify { METRIC_THRESHOLD_UNKNOWN,