Lines Matching +full:no +full:- +full:can +full:- +full:fd
1 // SPDX-License-Identifier: GPL-2.0-only
7 #include "print-events.h"
9 #include "time-utils.h"
88 return pmu && pmu->type == PERF_PMU_TYPE_TOOL; in perf_pmu__is_tool()
93 return perf_pmu__is_tool(evsel->pmu); in evsel__is_tool()
101 return (enum tool_pmu_event)evsel->core.attr.config; in evsel__tool_event()
106 return tool_pmu__event_to_str(evsel->core.attr.config); in evsel__tool_pmu_event_name()
115 if (c == -1) in read_until_char()
121 static int read_stat_field(int fd, struct perf_cpu cpu, int field, __u64 *val) in read_stat_field() argument
127 io__init(&io, fd, buf, sizeof(buf)); in read_stat_field()
130 for (i = -1; i < cpu.cpu; i++) { in read_stat_field()
132 return -EINVAL; in read_stat_field()
135 if (io__get_char(&io) != 'c') return -EINVAL; in read_stat_field()
136 if (io__get_char(&io) != 'p') return -EINVAL; in read_stat_field()
137 if (io__get_char(&io) != 'u') return -EINVAL; in read_stat_field()
141 return -EINVAL; in read_stat_field()
151 return -EINVAL; in read_stat_field()
154 static int read_pid_stat_field(int fd, int field, __u64 *val) in read_pid_stat_field() argument
160 io__init(&io, fd, buf, sizeof(buf)); in read_pid_stat_field()
162 return -EINVAL; in read_pid_stat_field()
168 return -EINVAL; in read_pid_stat_field()
170 return -EINVAL; /* String can't be returned. */ in read_pid_stat_field()
173 if (io__get_char(&io) != ' ' || io__get_char(&io) == -1) in read_pid_stat_field()
174 return -EINVAL; in read_pid_stat_field()
176 return -EINVAL; /* String can't be returned. */ in read_pid_stat_field()
180 return -EINVAL; in read_pid_stat_field()
185 if (c == -1) in read_pid_stat_field()
186 return -EINVAL; in read_pid_stat_field()
187 if (c == -2) { in read_pid_stat_field()
188 /* Assume a -ve was read */ in read_pid_stat_field()
190 *val *= -1; in read_pid_stat_field()
193 return -EINVAL; in read_pid_stat_field()
198 return -EINVAL; in read_pid_stat_field()
207 !evsel->start_times) { in evsel__tool_pmu_prepare_open()
208 evsel->start_times = xyarray__new(perf_cpu_map__nr(cpus), in evsel__tool_pmu_prepare_open()
211 if (!evsel->start_times) in evsel__tool_pmu_prepare_open()
212 return -ENOMEM; in evsel__tool_pmu_prepare_open()
217 #define FD(e, x, y) (*(int *)xyarray__entry(e->core.fd, x, y)) macro
224 int pid = -1, idx = 0, thread = 0, nthreads, err = 0, old_errno; in evsel__tool_pmu_open()
230 if (evsel->core.attr.sample_period) /* no sampling */ in evsel__tool_pmu_open()
231 return -EINVAL; in evsel__tool_pmu_open()
232 evsel->start_time = rdclock(); in evsel__tool_pmu_open()
236 if (evsel->cgrp) in evsel__tool_pmu_open()
237 pid = evsel->cgrp->fd; in evsel__tool_pmu_open()
242 if (!evsel->cgrp && !evsel->core.system_wide) in evsel__tool_pmu_open()
248 int fd; in evsel__tool_pmu_open() local
250 if (evsel->core.attr.sample_period) { in evsel__tool_pmu_open()
251 /* no sampling */ in evsel__tool_pmu_open()
252 err = -EINVAL; in evsel__tool_pmu_open()
255 if (pid > -1) { in evsel__tool_pmu_open()
259 fd = open(buf, O_RDONLY); in evsel__tool_pmu_open()
260 evsel->pid_stat = true; in evsel__tool_pmu_open()
262 fd = open("/proc/stat", O_RDONLY); in evsel__tool_pmu_open()
264 FD(evsel, idx, thread) = fd; in evsel__tool_pmu_open()
265 if (fd < 0) { in evsel__tool_pmu_open()
266 err = -errno; in evsel__tool_pmu_open()
269 start_time = xyarray__entry(evsel->start_times, idx, thread); in evsel__tool_pmu_open()
270 if (pid > -1) { in evsel__tool_pmu_open()
271 err = read_pid_stat_field(fd, system ? 15 : 14, in evsel__tool_pmu_open()
276 cpu = perf_cpu_map__cpu(evsel->core.cpus, idx); in evsel__tool_pmu_open()
277 err = read_stat_field(fd, cpu, system ? 3 : 1, in evsel__tool_pmu_open()
289 threads->err_thread = thread; in evsel__tool_pmu_open()
293 while (--thread >= 0) { in evsel__tool_pmu_open()
294 if (FD(evsel, idx, thread) >= 0) in evsel__tool_pmu_open()
295 close(FD(evsel, idx, thread)); in evsel__tool_pmu_open()
296 FD(evsel, idx, thread) = -1; in evsel__tool_pmu_open()
299 } while (--idx >= 0); in evsel__tool_pmu_open()
343 *result = topology->core_cpus_lists; in tool_pmu__read_event()
347 if (!evsel || perf_cpu_map__is_empty(evsel->core.cpus)) { in tool_pmu__read_event()
348 /* No evsel to be specific to. */ in tool_pmu__read_event()
350 } else if (!perf_cpu_map__has_any_cpu(evsel->core.cpus)) { in tool_pmu__read_event()
352 *result = perf_cpu_map__nr(evsel->core.cpus); in tool_pmu__read_event()
355 * "Any CPU" event that can be scheduled on any CPU in in tool_pmu__read_event()
359 if (!perf_cpu_map__is_empty(evsel->core.pmu_cpus)) in tool_pmu__read_event()
360 *result = perf_cpu_map__nr(evsel->core.pmu_cpus); in tool_pmu__read_event()
372 if (!evsel || perf_cpu_map__is_empty(evsel->core.cpus)) { in tool_pmu__read_event()
373 /* No evsel to be specific to. */ in tool_pmu__read_event()
375 } else if (!perf_cpu_map__has_any_cpu(evsel->core.cpus)) { in tool_pmu__read_event()
378 perf_cpu_map__intersect(online, evsel->core.cpus); in tool_pmu__read_event()
384 * "Any CPU" event that can be scheduled on any CPU in in tool_pmu__read_event()
389 if (!perf_cpu_map__is_empty(evsel->core.pmu_cpus)) { in tool_pmu__read_event()
391 perf_cpu_map__intersect(online, evsel->core.pmu_cpus); in tool_pmu__read_event()
404 *result = topology->die_cpus_lists; in tool_pmu__read_event()
409 *result = topology->package_cpus_lists; in tool_pmu__read_event()
438 int fd, err = 0; in evsel__tool_pmu_read() local
443 count = perf_counts(evsel->counts, cpu_map_idx, thread); in evsel__tool_pmu_read()
455 if (evsel->prev_raw_counts) in evsel__tool_pmu_read()
456 old_count = perf_counts(evsel->prev_raw_counts, cpu_map_idx, thread); in evsel__tool_pmu_read()
460 count->lost++; in evsel__tool_pmu_read()
465 count->val = old_count->val + val; in evsel__tool_pmu_read()
466 count->run = old_count->run + 1; in evsel__tool_pmu_read()
467 count->ena = old_count->ena + 1; in evsel__tool_pmu_read()
469 count->val = val; in evsel__tool_pmu_read()
470 count->run++; in evsel__tool_pmu_read()
471 count->ena++; in evsel__tool_pmu_read()
480 start_time = &evsel->start_time; in evsel__tool_pmu_read()
490 start_time = xyarray__entry(evsel->start_times, cpu_map_idx, thread); in evsel__tool_pmu_read()
491 fd = FD(evsel, cpu_map_idx, thread); in evsel__tool_pmu_read()
492 lseek(fd, SEEK_SET, 0); in evsel__tool_pmu_read()
493 if (evsel->pid_stat) { in evsel__tool_pmu_read()
496 err = read_pid_stat_field(fd, system ? 15 : 14, &cur_time); in evsel__tool_pmu_read()
502 struct perf_cpu cpu = perf_cpu_map__cpu(evsel->core.cpus, in evsel__tool_pmu_read()
505 err = read_stat_field(fd, cpu, system ? 3 : 1, &cur_time); in evsel__tool_pmu_read()
516 err = -EINVAL; in evsel__tool_pmu_read()
521 delta_start = cur_time - *start_time; in evsel__tool_pmu_read()
527 count->val = delta_start; in evsel__tool_pmu_read()
528 count->lost = 0; in evsel__tool_pmu_read()
531 * exact values don't matter as long as they are non-zero to avoid in evsel__tool_pmu_read()
534 count->ena++; in evsel__tool_pmu_read()
535 count->run++; in evsel__tool_pmu_read()
550 tool->events_table = find_core_events_table("common", "common"); in tool_pmu__new()