~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/lib/perf/threadmap.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0
  2 #include <perf/threadmap.h>
  3 #include <stdlib.h>
  4 #include <linux/refcount.h>
  5 #include <internal/threadmap.h>
  6 #include <string.h>
  7 #include <asm/bug.h>
  8 #include <stdio.h>
  9 
 10 static void perf_thread_map__reset(struct perf_thread_map *map, int start, int nr)
 11 {
 12         size_t size = (nr - start) * sizeof(map->map[0]);
 13 
 14         memset(&map->map[start], 0, size);
 15         map->err_thread = -1;
 16 }
 17 
 18 struct perf_thread_map *perf_thread_map__realloc(struct perf_thread_map *map, int nr)
 19 {
 20         size_t size = sizeof(*map) + sizeof(map->map[0]) * nr;
 21         int start = map ? map->nr : 0;
 22 
 23         map = realloc(map, size);
 24         /*
 25          * We only realloc to add more items, let's reset new items.
 26          */
 27         if (map)
 28                 perf_thread_map__reset(map, start, nr);
 29 
 30         return map;
 31 }
 32 
 33 #define thread_map__alloc(__nr) perf_thread_map__realloc(NULL, __nr)
 34 
 35 void perf_thread_map__set_pid(struct perf_thread_map *map, int idx, pid_t pid)
 36 {
 37         map->map[idx].pid = pid;
 38 }
 39 
 40 char *perf_thread_map__comm(struct perf_thread_map *map, int idx)
 41 {
 42         return map->map[idx].comm;
 43 }
 44 
 45 struct perf_thread_map *perf_thread_map__new_array(int nr_threads, pid_t *array)
 46 {
 47         struct perf_thread_map *threads = thread_map__alloc(nr_threads);
 48         int i;
 49 
 50         if (!threads)
 51                 return NULL;
 52 
 53         for (i = 0; i < nr_threads; i++)
 54                 perf_thread_map__set_pid(threads, i, array ? array[i] : -1);
 55 
 56         threads->nr = nr_threads;
 57         refcount_set(&threads->refcnt, 1);
 58 
 59         return threads;
 60 }
 61 
 62 struct perf_thread_map *perf_thread_map__new_dummy(void)
 63 {
 64         return perf_thread_map__new_array(1, NULL);
 65 }
 66 
 67 static void perf_thread_map__delete(struct perf_thread_map *threads)
 68 {
 69         if (threads) {
 70                 int i;
 71 
 72                 WARN_ONCE(refcount_read(&threads->refcnt) != 0,
 73                           "thread map refcnt unbalanced\n");
 74                 for (i = 0; i < threads->nr; i++)
 75                         free(perf_thread_map__comm(threads, i));
 76                 free(threads);
 77         }
 78 }
 79 
 80 struct perf_thread_map *perf_thread_map__get(struct perf_thread_map *map)
 81 {
 82         if (map)
 83                 refcount_inc(&map->refcnt);
 84         return map;
 85 }
 86 
 87 void perf_thread_map__put(struct perf_thread_map *map)
 88 {
 89         if (map && refcount_dec_and_test(&map->refcnt))
 90                 perf_thread_map__delete(map);
 91 }
 92 
 93 int perf_thread_map__nr(struct perf_thread_map *threads)
 94 {
 95         return threads ? threads->nr : 1;
 96 }
 97 
 98 pid_t perf_thread_map__pid(struct perf_thread_map *map, int idx)
 99 {
100         return map->map[idx].pid;
101 }
102 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php