File libperf-add-perf_thread_map__new_dummy-function.patch of Package perf
xxxxxxxxxx
1
From: Jiri Olsa <jolsa@kernel.org>
2
Date: Sun, 21 Jul 2019 13:24:19 +0200
3
Subject: libperf: Add perf_thread_map__new_dummy() function
4
Git-commit: 4b49cce25e719587e934b745fe9bbb5bc8c4ba29
5
Patch-mainline: v5.4-rc1
6
References: jsc#SLE-13661
7
8
Moving the following functions:
9
10
thread_map__new_dummy()
11
thread_map__realloc()
12
thread_map__set_pid()
13
14
to libperf with the following names:
15
16
perf_thread_map__new_dummy()
17
perf_thread_map__realloc()
18
perf_thread_map__set_pid()
19
20
the other 2 functions are dependencies of the
21
perf_thread_map__new_dummy() function.
22
23
The perf_thread_map__realloc() function is not exported.
24
25
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
26
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
27
Cc: Alexey Budankov <alexey.budankov@linux.intel.com>
28
Cc: Andi Kleen <ak@linux.intel.com>
29
Cc: Michael Petlan <mpetlan@redhat.com>
30
Cc: Namhyung Kim <namhyung@kernel.org>
31
Cc: Peter Zijlstra <peterz@infradead.org>
32
Link: http://lkml.kernel.org/r/20190721112506.12306-33-jolsa@kernel.org
33
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
34
Signed-off-by: Tony Jones <tonyj@suse.de>
35
---
36
tools/perf/lib/include/internal/threadmap.h | 2 +
37
tools/perf/lib/include/perf/threadmap.h | 7 ++++
38
tools/perf/lib/libperf.map | 2 +
39
tools/perf/lib/threadmap.c | 43 +++++++++++++++++++++
40
tools/perf/tests/openat-syscall-tp-fields.c | 2 +-
41
tools/perf/tests/thread-map.c | 2 +-
42
tools/perf/util/evlist.c | 4 +-
43
tools/perf/util/thread_map.c | 59 ++++++-----------------------
44
tools/perf/util/thread_map.h | 7 +---
45
9 files changed, 71 insertions(+), 57 deletions(-)
46
47
diff --git a/tools/perf/lib/include/internal/threadmap.h b/tools/perf/lib/include/internal/threadmap.h
48
index c8088005a9ab..df748baf9eda 100644
49
--- a/tools/perf/lib/include/internal/threadmap.h
50
+++ b/tools/perf/lib/include/internal/threadmap.h
51
52
struct thread_map_data map[];
53
};
54
55
+struct perf_thread_map *perf_thread_map__realloc(struct perf_thread_map *map, int nr);
56
+
57
#endif /* __LIBPERF_INTERNAL_THREADMAP_H */
58
diff --git a/tools/perf/lib/include/perf/threadmap.h b/tools/perf/lib/include/perf/threadmap.h
59
index dc3a3837b56f..34ed7f587101 100644
60
--- a/tools/perf/lib/include/perf/threadmap.h
61
+++ b/tools/perf/lib/include/perf/threadmap.h
62
63
#ifndef __LIBPERF_THREADMAP_H
64
#define __LIBPERF_THREADMAP_H
65
66
+#include <perf/core.h>
67
+#include <sys/types.h>
68
+
69
struct perf_thread_map;
70
71
+LIBPERF_API struct perf_thread_map *perf_thread_map__new_dummy(void);
72
+
73
+LIBPERF_API void perf_thread_map__set_pid(struct perf_thread_map *map, int thread, pid_t pid);
74
+
75
#endif /* __LIBPERF_THREADMAP_H */
76
diff --git a/tools/perf/lib/libperf.map b/tools/perf/lib/libperf.map
77
index 76ce3bc59dd8..6b4ec1c4d3f3 100644
78
--- a/tools/perf/lib/libperf.map
79
+++ b/tools/perf/lib/libperf.map
80
81
perf_cpu_map__dummy_new;
82
perf_cpu_map__get;
83
perf_cpu_map__put;
84
+ perf_thread_map__new_dummy;
85
+ perf_thread_map__set_pid;
86
local:
87
*;
88
};
89
diff --git a/tools/perf/lib/threadmap.c b/tools/perf/lib/threadmap.c
90
index 163dc609b909..23e628a1437a 100644
91
--- a/tools/perf/lib/threadmap.c
92
+++ b/tools/perf/lib/threadmap.c
93
94
#include <stdlib.h>
95
#include <linux/refcount.h>
96
#include <internal/threadmap.h>
97
+#include <string.h>
98
+
99
+static void perf_thread_map__reset(struct perf_thread_map *map, int start, int nr)
100
+{
101
+ size_t size = (nr - start) * sizeof(map->map[0]);
102
+
103
+ memset(&map->map[start], 0, size);
104
+ map->err_thread = -1;
105
+}
106
+
107
+struct perf_thread_map *perf_thread_map__realloc(struct perf_thread_map *map, int nr)
108
+{
109
+ size_t size = sizeof(*map) + sizeof(map->map[0]) * nr;
110
+ int start = map ? map->nr : 0;
111
+
112
+ map = realloc(map, size);
113
+ /*
114
+ * We only realloc to add more items, let's reset new items.
115
+ */
116
+ if (map)
117
+ perf_thread_map__reset(map, start, nr);
118
+
119
+ return map;
120
+}
121
+
122
+#define thread_map__alloc(__nr) perf_thread_map__realloc(NULL, __nr)
123
+
124
+void perf_thread_map__set_pid(struct perf_thread_map *map, int thread, pid_t pid)
125
+{
126
+ map->map[thread].pid = pid;
127
+}
128
+
129
+struct perf_thread_map *perf_thread_map__new_dummy(void)
130
+{
131
+ struct perf_thread_map *threads = thread_map__alloc(1);
132
+
133
+ if (threads != NULL) {
134
+ perf_thread_map__set_pid(threads, 0, -1);
135
+ threads->nr = 1;
136
+ refcount_set(&threads->refcnt, 1);
137
+ }
138
+ return threads;
139
+}
140
diff --git a/tools/perf/tests/openat-syscall-tp-fields.c b/tools/perf/tests/openat-syscall-tp-fields.c
141
index c7182b7840e5..1de79208e690 100644
142
--- a/tools/perf/tests/openat-syscall-tp-fields.c
143
+++ b/tools/perf/tests/openat-syscall-tp-fields.c
144
145
146
perf_evsel__config(evsel, &opts, NULL);
147
148
- thread_map__set_pid(evlist->threads, 0, getpid());
149
+ perf_thread_map__set_pid(evlist->threads, 0, getpid());
150
151
err = evlist__open(evlist);
152
if (err < 0) {
153
diff --git a/tools/perf/tests/thread-map.c b/tools/perf/tests/thread-map.c
154
index 367dfe708e4c..73bc404ed390 100644
155
--- a/tools/perf/tests/thread-map.c
156
+++ b/tools/perf/tests/thread-map.c
157
158
thread_map__put(map);
159
160
/* test dummy pid */
161
- map = thread_map__new_dummy();
162
+ map = perf_thread_map__new_dummy();
163
TEST_ASSERT_VAL("failed to alloc map", map);
164
165
thread_map__read_comms(map);
166
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
167
index 35020d50f51e..88d131769df4 100644
168
--- a/tools/perf/util/evlist.c
169
+++ b/tools/perf/util/evlist.c
170
171
if (!cpus)
172
goto out;
173
174
- threads = thread_map__new_dummy();
175
+ threads = perf_thread_map__new_dummy();
176
if (!threads)
177
goto out_put;
178
179
180
__func__, __LINE__);
181
goto out_close_pipes;
182
}
183
- thread_map__set_pid(evlist->threads, 0, evlist->workload.pid);
184
+ perf_thread_map__set_pid(evlist->threads, 0, evlist->workload.pid);
185
}
186
187
close(child_ready_pipe[1]);
188
diff --git a/tools/perf/util/thread_map.c b/tools/perf/util/thread_map.c
189
index e89496c39d58..06dd9f2e4ce5 100644
190
--- a/tools/perf/util/thread_map.c
191
+++ b/tools/perf/util/thread_map.c
192
193
return 1;
194
}
195
196
-static void thread_map__reset(struct perf_thread_map *map, int start, int nr)
197
-{
198
- size_t size = (nr - start) * sizeof(map->map[0]);
199
-
200
- memset(&map->map[start], 0, size);
201
- map->err_thread = -1;
202
-}
203
-
204
-static struct perf_thread_map *thread_map__realloc(struct perf_thread_map *map, int nr)
205
-{
206
- size_t size = sizeof(*map) + sizeof(map->map[0]) * nr;
207
- int start = map ? map->nr : 0;
208
-
209
- map = realloc(map, size);
210
- /*
211
- * We only realloc to add more items, let's reset new items.
212
- */
213
- if (map)
214
- thread_map__reset(map, start, nr);
215
-
216
- return map;
217
-}
218
-
219
-#define thread_map__alloc(__nr) thread_map__realloc(NULL, __nr)
220
+#define thread_map__alloc(__nr) perf_thread_map__realloc(NULL, __nr)
221
222
struct perf_thread_map *thread_map__new_by_pid(pid_t pid)
223
{
224
225
threads = thread_map__alloc(items);
226
if (threads != NULL) {
227
for (i = 0; i < items; i++)
228
- thread_map__set_pid(threads, i, atoi(namelist[i]->d_name));
229
+ perf_thread_map__set_pid(threads, i, atoi(namelist[i]->d_name));
230
threads->nr = items;
231
refcount_set(&threads->refcnt, 1);
232
}
233
234
struct perf_thread_map *threads = thread_map__alloc(1);
235
236
if (threads != NULL) {
237
- thread_map__set_pid(threads, 0, tid);
238
+ perf_thread_map__set_pid(threads, 0, tid);
239
threads->nr = 1;
240
refcount_set(&threads->refcnt, 1);
241
}
242
243
if (grow) {
244
struct perf_thread_map *tmp;
245
246
- tmp = thread_map__realloc(threads, max_threads);
247
+ tmp = perf_thread_map__realloc(threads, max_threads);
248
if (tmp == NULL)
249
goto out_free_namelist;
250
251
252
}
253
254
for (i = 0; i < items; i++) {
255
- thread_map__set_pid(threads, threads->nr + i,
256
- atoi(namelist[i]->d_name));
257
+ perf_thread_map__set_pid(threads, threads->nr + i,
258
+ atoi(namelist[i]->d_name));
259
}
260
261
for (i = 0; i < items; i++)
262
263
goto out_free_threads;
264
265
total_tasks += items;
266
- nt = thread_map__realloc(threads, total_tasks);
267
+ nt = perf_thread_map__realloc(threads, total_tasks);
268
if (nt == NULL)
269
goto out_free_namelist;
270
271
threads = nt;
272
273
for (i = 0; i < items; i++) {
274
- thread_map__set_pid(threads, j++, atoi(namelist[i]->d_name));
275
+ perf_thread_map__set_pid(threads, j++, atoi(namelist[i]->d_name));
276
zfree(&namelist[i]);
277
}
278
threads->nr = total_tasks;
279
280
goto out;
281
}
282
283
-struct perf_thread_map *thread_map__new_dummy(void)
284
-{
285
- struct perf_thread_map *threads = thread_map__alloc(1);
286
-
287
- if (threads != NULL) {
288
- thread_map__set_pid(threads, 0, -1);
289
- threads->nr = 1;
290
- refcount_set(&threads->refcnt, 1);
291
- }
292
- return threads;
293
-}
294
-
295
struct perf_thread_map *thread_map__new_by_tid_str(const char *tid_str)
296
{
297
struct perf_thread_map *threads = NULL, *nt;
298
299
300
/* perf-stat expects threads to be generated even if tid not given */
301
if (!tid_str)
302
- return thread_map__new_dummy();
303
+ return perf_thread_map__new_dummy();
304
305
slist = strlist__new(tid_str, &slist_config);
306
if (!slist)
307
308
continue;
309
310
ntasks++;
311
- nt = thread_map__realloc(threads, ntasks);
312
+ nt = perf_thread_map__realloc(threads, ntasks);
313
314
if (nt == NULL)
315
goto out_free_threads;
316
317
threads = nt;
318
- thread_map__set_pid(threads, ntasks - 1, tid);
319
+ perf_thread_map__set_pid(threads, ntasks - 1, tid);
320
threads->nr = ntasks;
321
}
322
out:
323
324
threads->nr = (int) event->nr;
325
326
for (i = 0; i < event->nr; i++) {
327
- thread_map__set_pid(threads, i, (pid_t) event->entries[i].pid);
328
+ perf_thread_map__set_pid(threads, i, (pid_t) event->entries[i].pid);
329
threads->map[i].comm = strndup(event->entries[i].comm, 16);
330
}
331
332
diff --git a/tools/perf/util/thread_map.h b/tools/perf/util/thread_map.h
333
index 5a7be6f8934f..94a1f9565f5e 100644
334
--- a/tools/perf/util/thread_map.h
335
+++ b/tools/perf/util/thread_map.h
336
337
#include <stdio.h>
338
#include <linux/refcount.h>
339
#include <internal/threadmap.h>
340
+#include <perf/threadmap.h>
341
342
struct thread_map_event;
343
344
345
return map->map[thread].pid;
346
}
347
348
-static inline void
349
-thread_map__set_pid(struct perf_thread_map *map, int thread, pid_t pid)
350
-{
351
- map->map[thread].pid = pid;
352
-}
353
-
354
static inline char *thread_map__comm(struct perf_thread_map *map, int thread)
355
{
356
return map->map[thread].comm;
357
358