Lines Matching +full:cpu +full:- +full:nr
1 // SPDX-License-Identifier: GPL-2.0
15 #include "parse-events.h"
75 union perf_event *event, const char *comm, int nr) in check_comm() argument
77 if (event->header.type == PERF_RECORD_COMM && in check_comm()
78 (pid_t)event->comm.pid == getpid() && in check_comm()
79 (pid_t)event->comm.tid == getpid() && in check_comm()
80 strcmp(event->comm.comm, comm) == 0) { in check_comm()
81 if (switch_tracking->comm_seen[nr]) { in check_comm()
83 return -1; in check_comm()
85 switch_tracking->comm_seen[nr] = 1; in check_comm()
86 pr_debug3("comm event: %s nr: %d\n", event->comm.comm, nr); in check_comm()
92 static int check_cpu(struct switch_tracking *switch_tracking, int cpu) in check_cpu() argument
94 int i, nr = cpu + 1; in check_cpu() local
96 if (cpu < 0) in check_cpu()
97 return -1; in check_cpu()
99 if (!switch_tracking->tids) { in check_cpu()
100 switch_tracking->tids = calloc(nr, sizeof(pid_t)); in check_cpu()
101 if (!switch_tracking->tids) in check_cpu()
102 return -1; in check_cpu()
103 for (i = 0; i < nr; i++) in check_cpu()
104 switch_tracking->tids[i] = -1; in check_cpu()
105 switch_tracking->nr_tids = nr; in check_cpu()
109 if (cpu >= switch_tracking->nr_tids) { in check_cpu()
112 addr = realloc(switch_tracking->tids, nr * sizeof(pid_t)); in check_cpu()
114 return -1; in check_cpu()
115 switch_tracking->tids = addr; in check_cpu()
116 for (i = switch_tracking->nr_tids; i < nr; i++) in check_cpu()
117 switch_tracking->tids[i] = -1; in check_cpu()
118 switch_tracking->nr_tids = nr; in check_cpu()
132 int cpu, err; in process_sample_event() local
136 return -1; in process_sample_event()
140 if (evsel == switch_tracking->switch_evsel) { in process_sample_event()
143 cpu = sample.cpu; in process_sample_event()
144 pr_debug3("sched_switch: cpu: %d prev_tid %d next_tid %d\n", in process_sample_event()
145 cpu, prev_tid, next_tid); in process_sample_event()
146 err = check_cpu(switch_tracking, cpu); in process_sample_event()
151 * evsel->core.system_wide flag has worked. in process_sample_event()
153 if (switch_tracking->tids[cpu] != -1 && in process_sample_event()
154 switch_tracking->tids[cpu] != prev_tid) { in process_sample_event()
156 return -1; in process_sample_event()
158 switch_tracking->tids[cpu] = next_tid; in process_sample_event()
161 if (evsel == switch_tracking->cycles_evsel) { in process_sample_event()
163 if (!switch_tracking->comm_seen[0]) in process_sample_event()
164 switch_tracking->cycles_before_comm_1 = 1; in process_sample_event()
165 if (switch_tracking->comm_seen[1] && in process_sample_event()
166 !switch_tracking->comm_seen[2]) in process_sample_event()
167 switch_tracking->cycles_between_comm_2_and_comm_3 = 1; in process_sample_event()
168 if (switch_tracking->comm_seen[3]) in process_sample_event()
169 switch_tracking->cycles_after_comm_4 = 1; in process_sample_event()
178 if (event->header.type == PERF_RECORD_SAMPLE) in process_event()
181 if (event->header.type == PERF_RECORD_COMM) { in process_event()
186 return -1; in process_event()
190 return -1; in process_event()
194 return -1; in process_event()
198 return -1; in process_event()
202 return -1; in process_event()
224 return -1; in add_event()
226 node->event = event; in add_event()
227 list_add(&node->list, events); in add_event()
231 return -1; in add_event()
236 return -1; in add_event()
239 node->event_time = sample.time; in add_event()
249 node = list_entry(events->next, struct event_node, list); in free_event_nodes()
250 list_del_init(&node->list); in free_event_nodes()
259 s64 cmp = nodea->event_time - nodeb->event_time; in compar()
274 for (i = 0; i < evlist->core.nr_mmaps; i++) { in process_events()
275 md = &evlist->mmap[i]; in process_events()
276 if (perf_mmap__read_init(&md->core) < 0) in process_events()
279 while ((event = perf_mmap__read_event(&md->core)) != NULL) { in process_events()
282 perf_mmap__consume(&md->core); in process_events()
286 perf_mmap__read_done(&md->core); in process_events()
292 ret = -1; in process_events()
319 * test__switch_tracking - test using sched_switch and tracking events.
323 * evsel->core.system_wide and evsel->tracking flags (respectively) with other events
346 int err = -1; in test__switch_tracking()
348 threads = thread_map__new(-1, getpid(), UINT_MAX); in test__switch_tracking()
366 perf_evlist__set_maps(&evlist->core, cpus, threads); in test__switch_tracking()
369 err = parse_event(evlist, "cpu-clock:u"); in test__switch_tracking()
400 switch_evsel->immediate = true; in test__switch_tracking()
413 evsel__set_sample_bit(cycles_evsel, CPU); in test__switch_tracking()
427 tracking_evsel->core.attr.freq = 0; in test__switch_tracking()
428 tracking_evsel->core.attr.sample_period = 1; in test__switch_tracking()
442 if (!tracking_evsel->core.attr.mmap || !tracking_evsel->core.attr.comm) { in test__switch_tracking()
447 /* Check non-tracking events are not tracking */ in test__switch_tracking()
450 if (evsel->core.attr.mmap || evsel->core.attr.comm) { in test__switch_tracking()
451 pr_debug("Non-tracking event is tracking\n"); in test__switch_tracking()
547 /* Check all 4 comm events were seen i.e. that evsel->tracking works */ in test__switch_tracking()
582 err = -1; in test__switch_tracking()