[PATCH v4 06/16] perf intel-tpebs: Reduce scope of tpebs_events_size

Ian Rogers
2025-04-09T06:11:04Z

Moved to record argument computation rather than being global.

Signed-off-by: Ian Rogers <irogers@google.com>
---
tools/perf/util/intel-tpebs.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/tools/perf/util/intel-tpebs.c b/tools/perf/util/intel-tpebs.c
index 2b04deaf66ff..e3bed86145b9 100644
--- a/tools/perf/util/intel-tpebs.c
+++ b/tools/perf/util/intel-tpebs.c
@@ -29,7 +29,6 @@
#define PERF_DATA "-"

bool tpebs_recording;
-static size_t tpebs_event_size;
static LIST_HEAD(tpebs_results);
static pthread_t tpebs_reader_thread;
static struct child_process tpebs_cmd;
@@ -86,15 +85,20 @@ static int get_perf_record_args(const char **record_argv, char buf[],
static int evsel__tpebs_start_perf_record(struct evsel *evsel, int control_fd[], int ack_fd[])
{
const char **record_argv;
+ size_t tpebs_event_size = 0;
int ret;
char buf[32];
char cpumap_buf[50];
+ struct tpebs_retire_lat *t;

cpu_map__snprint(evsel->evlist->core.user_requested_cpus, cpumap_buf,
sizeof(cpumap_buf));

scnprintf(buf, sizeof(buf), "--control=fd:%d,%d", control_fd[0], ack_fd[1]);

+ list_for_each_entry(t, &tpebs_results, nd)
+ tpebs_event_size++;
+
record_argv = calloc(12 + 2 * tpebs_event_size, sizeof(char *));
if (!record_argv)
return -ENOMEM;
@@ -226,7 +230,6 @@ static struct tpebs_retire_lat *tpebs_retire_lat__new(struct evsel *evsel)
return NULL;
}
list_add_tail(&result->nd, &tpebs_results);
- tpebs_event_size++;
return result;
}

@@ -289,7 +292,7 @@ int evsel__tpebs_open(struct evsel *evsel)
if (ret)
return ret;

- if (tpebs_event_size > 0) {
+ if (!list_empty(&tpebs_results)) {
struct pollfd pollfd = { .events = POLLIN, };
int control_fd[2], ack_fd[2], len;
char ack_buf[8];
--
2.49.0.504.g3bcea36a83-goog