Lines Matching +full:cpu +full:- +full:nr
1 // SPDX-License-Identifier: GPL-2.0
14 #include "parse-events.h"
72 union perf_event *event, const char *comm, int nr) in check_comm() argument
74 if (event->header.type == PERF_RECORD_COMM && in check_comm()
75 (pid_t)event->comm.pid == getpid() && in check_comm()
76 (pid_t)event->comm.tid == getpid() && in check_comm()
77 strcmp(event->comm.comm, comm) == 0) { in check_comm()
78 if (switch_tracking->comm_seen[nr]) { in check_comm()
80 return -1; in check_comm()
82 switch_tracking->comm_seen[nr] = 1; in check_comm()
83 pr_debug3("comm event: %s nr: %d\n", event->comm.comm, nr); in check_comm()
89 static int check_cpu(struct switch_tracking *switch_tracking, int cpu) in check_cpu() argument
91 int i, nr = cpu + 1; in check_cpu() local
93 if (cpu < 0) in check_cpu()
94 return -1; in check_cpu()
96 if (!switch_tracking->tids) { in check_cpu()
97 switch_tracking->tids = calloc(nr, sizeof(pid_t)); in check_cpu()
98 if (!switch_tracking->tids) in check_cpu()
99 return -1; in check_cpu()
100 for (i = 0; i < nr; i++) in check_cpu()
101 switch_tracking->tids[i] = -1; in check_cpu()
102 switch_tracking->nr_tids = nr; in check_cpu()
106 if (cpu >= switch_tracking->nr_tids) { in check_cpu()
109 addr = realloc(switch_tracking->tids, nr * sizeof(pid_t)); in check_cpu()
111 return -1; in check_cpu()
112 switch_tracking->tids = addr; in check_cpu()
113 for (i = switch_tracking->nr_tids; i < nr; i++) in check_cpu()
114 switch_tracking->tids[i] = -1; in check_cpu()
115 switch_tracking->nr_tids = nr; in check_cpu()
129 int cpu, err; in process_sample_event() local
133 return -1; in process_sample_event()
137 if (evsel == switch_tracking->switch_evsel) { in process_sample_event()
140 cpu = sample.cpu; in process_sample_event()
141 pr_debug3("sched_switch: cpu: %d prev_tid %d next_tid %d\n", in process_sample_event()
142 cpu, prev_tid, next_tid); in process_sample_event()
143 err = check_cpu(switch_tracking, cpu); in process_sample_event()
148 * evsel->core.system_wide flag has worked. in process_sample_event()
150 if (switch_tracking->tids[cpu] != -1 && in process_sample_event()
151 switch_tracking->tids[cpu] != prev_tid) { in process_sample_event()
153 return -1; in process_sample_event()
155 switch_tracking->tids[cpu] = next_tid; in process_sample_event()
158 if (evsel == switch_tracking->cycles_evsel) { in process_sample_event()
160 if (!switch_tracking->comm_seen[0]) in process_sample_event()
161 switch_tracking->cycles_before_comm_1 = 1; in process_sample_event()
162 if (switch_tracking->comm_seen[1] && in process_sample_event()
163 !switch_tracking->comm_seen[2]) in process_sample_event()
164 switch_tracking->cycles_between_comm_2_and_comm_3 = 1; in process_sample_event()
165 if (switch_tracking->comm_seen[3]) in process_sample_event()
166 switch_tracking->cycles_after_comm_4 = 1; in process_sample_event()
175 if (event->header.type == PERF_RECORD_SAMPLE) in process_event()
178 if (event->header.type == PERF_RECORD_COMM) { in process_event()
183 return -1; in process_event()
187 return -1; in process_event()
191 return -1; in process_event()
195 return -1; in process_event()
199 return -1; in process_event()
221 return -1; in add_event()
223 node->event = event; in add_event()
224 list_add(&node->list, events); in add_event()
228 return -1; in add_event()
233 return -1; in add_event()
236 node->event_time = sample.time; in add_event()
246 node = list_entry(events->next, struct event_node, list); in free_event_nodes()
247 list_del_init(&node->list); in free_event_nodes()
256 s64 cmp = nodea->event_time - nodeb->event_time; in compar()
271 for (i = 0; i < evlist->core.nr_mmaps; i++) { in process_events()
272 md = &evlist->mmap[i]; in process_events()
273 if (perf_mmap__read_init(&md->core) < 0) in process_events()
276 while ((event = perf_mmap__read_event(&md->core)) != NULL) { in process_events()
279 perf_mmap__consume(&md->core); in process_events()
283 perf_mmap__read_done(&md->core); in process_events()
289 ret = -1; in process_events()
316 * test__switch_tracking - test using sched_switch and tracking events.
320 * evsel->core.system_wide and evsel->tracking flags (respectively) with other events
342 int err = -1; in test__switch_tracking()
344 threads = thread_map__new(-1, getpid(), UINT_MAX); in test__switch_tracking()
362 perf_evlist__set_maps(&evlist->core, cpus, threads); in test__switch_tracking()
365 err = parse_events(evlist, "cpu-clock:u", NULL); in test__switch_tracking()
397 evsel__set_sample_bit(switch_evsel, CPU); in test__switch_tracking()
400 switch_evsel->core.system_wide = true; in test__switch_tracking()
401 switch_evsel->no_aux_samples = true; in test__switch_tracking()
402 switch_evsel->immediate = true; in test__switch_tracking()
415 evsel__set_sample_bit(cycles_evsel, CPU); in test__switch_tracking()
429 tracking_evsel->core.attr.freq = 0; in test__switch_tracking()
430 tracking_evsel->core.attr.sample_period = 1; in test__switch_tracking()
444 if (!tracking_evsel->core.attr.mmap || !tracking_evsel->core.attr.comm) { in test__switch_tracking()
449 /* Check non-tracking events are not tracking */ in test__switch_tracking()
452 if (evsel->core.attr.mmap || evsel->core.attr.comm) { in test__switch_tracking()
453 pr_debug("Non-tracking event is tracking\n"); in test__switch_tracking()
549 /* Check all 4 comm events were seen i.e. that evsel->tracking works */ in test__switch_tracking()
585 err = -1; in test__switch_tracking()