Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf thread_map: Don't access the array entries directly

Instead provide a method to set the array entries, and another to access
the contents.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/1435012588-9007-2-git-send-email-jolsa@kernel.org
[ Split providing the set/get accessors from transforming the entries structs ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Jiri Olsa and committed by
Arnaldo Carvalho de Melo
e13798c7 7c31bb8c

+34 -22
+2 -2
tools/perf/builtin-trace.c
··· 2325 2325 */ 2326 2326 if (trace->filter_pids.nr > 0) 2327 2327 err = perf_evlist__set_filter_pids(evlist, trace->filter_pids.nr, trace->filter_pids.entries); 2328 - else if (evlist->threads->map[0] == -1) 2328 + else if (thread_map__pid(evlist->threads, 0) == -1) 2329 2329 err = perf_evlist__set_filter_pid(evlist, getpid()); 2330 2330 2331 2331 if (err < 0) { ··· 2343 2343 if (forks) 2344 2344 perf_evlist__start_workload(evlist); 2345 2345 2346 - trace->multiple_threads = evlist->threads->map[0] == -1 || 2346 + trace->multiple_threads = thread_map__pid(evlist->threads, 0) == -1 || 2347 2347 evlist->threads->nr > 1 || 2348 2348 perf_evlist__first(evlist)->attr.inherit; 2349 2349 again:
+1 -1
tools/perf/tests/openat-syscall-tp-fields.c
··· 45 45 46 46 perf_evsel__config(evsel, &opts); 47 47 48 - evlist->threads->map[0] = getpid(); 48 + thread_map__set_pid(evlist->threads, 0, getpid()); 49 49 50 50 err = perf_evlist__open(evlist); 51 51 if (err < 0) {
+2 -2
tools/perf/util/auxtrace.c
··· 119 119 if (per_cpu) { 120 120 mp->cpu = evlist->cpus->map[idx]; 121 121 if (evlist->threads) 122 - mp->tid = evlist->threads->map[0]; 122 + mp->tid = thread_map__pid(evlist->threads, 0); 123 123 else 124 124 mp->tid = -1; 125 125 } else { 126 126 mp->cpu = -1; 127 - mp->tid = evlist->threads->map[idx]; 127 + mp->tid = thread_map__pid(evlist->threads, idx); 128 128 } 129 129 } 130 130
+3 -3
tools/perf/util/event.c
··· 504 504 for (thread = 0; thread < threads->nr; ++thread) { 505 505 if (__event__synthesize_thread(comm_event, mmap_event, 506 506 fork_event, 507 - threads->map[thread], 0, 507 + thread_map__pid(threads, thread), 0, 508 508 process, tool, machine, 509 509 mmap_data, proc_map_timeout)) { 510 510 err = -1; ··· 515 515 * comm.pid is set to thread group id by 516 516 * perf_event__synthesize_comm 517 517 */ 518 - if ((int) comm_event->comm.pid != threads->map[thread]) { 518 + if ((int) comm_event->comm.pid != thread_map__pid(threads, thread)) { 519 519 bool need_leader = true; 520 520 521 521 /* is thread group leader in thread_map? */ 522 522 for (j = 0; j < threads->nr; ++j) { 523 - if ((int) comm_event->comm.pid == threads->map[j]) { 523 + if ((int) comm_event->comm.pid == thread_map__pid(threads, j)) { 524 524 need_leader = false; 525 525 break; 526 526 }
+2 -2
tools/perf/util/evlist.c
··· 548 548 else 549 549 sid->cpu = -1; 550 550 if (!evsel->system_wide && evlist->threads && thread >= 0) 551 - sid->tid = evlist->threads->map[thread]; 551 + sid->tid = thread_map__pid(evlist->threads, thread); 552 552 else 553 553 sid->tid = -1; 554 554 } ··· 1475 1475 __func__, __LINE__); 1476 1476 goto out_close_pipes; 1477 1477 } 1478 - evlist->threads->map[0] = evlist->workload.pid; 1478 + thread_map__set_pid(evlist->threads, 0, evlist->workload.pid); 1479 1479 } 1480 1480 1481 1481 close(child_ready_pipe[1]);
+1 -1
tools/perf/util/evsel.c
··· 1167 1167 int group_fd; 1168 1168 1169 1169 if (!evsel->cgrp && !evsel->system_wide) 1170 - pid = threads->map[thread]; 1170 + pid = thread_map__pid(threads, thread); 1171 1171 1172 1172 group_fd = get_group_fd(evsel, cpu, thread); 1173 1173 retry_open:
+13 -11
tools/perf/util/thread_map.c
··· 45 45 threads = thread_map__alloc(items); 46 46 if (threads != NULL) { 47 47 for (i = 0; i < items; i++) 48 - threads->map[i] = atoi(namelist[i]->d_name); 48 + thread_map__set_pid(threads, i, atoi(namelist[i]->d_name)); 49 49 threads->nr = items; 50 50 } 51 51 ··· 61 61 struct thread_map *threads = thread_map__alloc(1); 62 62 63 63 if (threads != NULL) { 64 - threads->map[0] = tid; 65 - threads->nr = 1; 64 + thread_map__set_pid(threads, 0, tid); 65 + threads->nr = 1; 66 66 } 67 67 68 68 return threads; ··· 123 123 threads = tmp; 124 124 } 125 125 126 - for (i = 0; i < items; i++) 127 - threads->map[threads->nr + i] = atoi(namelist[i]->d_name); 126 + for (i = 0; i < items; i++) { 127 + thread_map__set_pid(threads, threads->nr + i, 128 + atoi(namelist[i]->d_name)); 129 + } 128 130 129 131 for (i = 0; i < items; i++) 130 132 zfree(&namelist[i]); ··· 203 201 threads = nt; 204 202 205 203 for (i = 0; i < items; i++) { 206 - threads->map[j++] = atoi(namelist[i]->d_name); 204 + thread_map__set_pid(threads, j++, atoi(namelist[i]->d_name)); 207 205 zfree(&namelist[i]); 208 206 } 209 207 threads->nr = total_tasks; ··· 229 227 struct thread_map *threads = thread_map__alloc(1); 230 228 231 229 if (threads != NULL) { 232 - threads->map[0] = -1; 233 - threads->nr = 1; 230 + thread_map__set_pid(threads, 0, -1); 231 + threads->nr = 1; 234 232 } 235 233 return threads; 236 234 } ··· 269 267 goto out_free_threads; 270 268 271 269 threads = nt; 272 - threads->map[ntasks - 1] = tid; 273 - threads->nr = ntasks; 270 + thread_map__set_pid(threads, ntasks - 1, tid); 271 + threads->nr = ntasks; 274 272 } 275 273 out: 276 274 return threads; ··· 303 301 size_t printed = fprintf(fp, "%d thread%s: ", 304 302 threads->nr, threads->nr > 1 ? "s" : ""); 305 303 for (i = 0; i < threads->nr; ++i) 306 - printed += fprintf(fp, "%s%d", i ? ", " : "", threads->map[i]); 304 + printed += fprintf(fp, "%s%d", i ? ", " : "", thread_map__pid(threads, i)); 307 305 308 306 return printed + fprintf(fp, "\n"); 309 307 }
+10
tools/perf/util/thread_map.h
··· 27 27 return threads ? threads->nr : 1; 28 28 } 29 29 30 + static inline pid_t thread_map__pid(struct thread_map *map, int thread) 31 + { 32 + return map->map[thread]; 33 + } 34 + 35 + static inline void 36 + thread_map__set_pid(struct thread_map *map, int thread, pid_t pid) 37 + { 38 + map->map[thread] = pid; 39 + } 30 40 #endif /* __PERF_THREAD_MAP_H */