forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/tools/perf/tests/cpumap.c
....@@ -3,8 +3,10 @@
33 #include <stdio.h>
44 #include "cpumap.h"
55 #include "event.h"
6
+#include "util/synthetic-events.h"
67 #include <string.h>
78 #include <linux/bitops.h>
9
+#include <perf/cpumap.h>
810 #include "debug.h"
911
1012 struct machine;
....@@ -14,17 +16,17 @@
1416 struct perf_sample *sample __maybe_unused,
1517 struct machine *machine __maybe_unused)
1618 {
17
- struct cpu_map_event *map_event = &event->cpu_map;
18
- struct cpu_map_mask *mask;
19
- struct cpu_map_data *data;
20
- struct cpu_map *map;
19
+ struct perf_record_cpu_map *map_event = &event->cpu_map;
20
+ struct perf_record_record_cpu_map *mask;
21
+ struct perf_record_cpu_map_data *data;
22
+ struct perf_cpu_map *map;
2123 int i;
2224
2325 data = &map_event->data;
2426
2527 TEST_ASSERT_VAL("wrong type", data->type == PERF_CPU_MAP__MASK);
2628
27
- mask = (struct cpu_map_mask *)data->data;
29
+ mask = (struct perf_record_record_cpu_map *)data->data;
2830
2931 TEST_ASSERT_VAL("wrong nr", mask->nr == 1);
3032
....@@ -39,7 +41,7 @@
3941 TEST_ASSERT_VAL("wrong cpu", map->map[i] == i);
4042 }
4143
42
- cpu_map__put(map);
44
+ perf_cpu_map__put(map);
4345 return 0;
4446 }
4547
....@@ -48,10 +50,10 @@
4850 struct perf_sample *sample __maybe_unused,
4951 struct machine *machine __maybe_unused)
5052 {
51
- struct cpu_map_event *map_event = &event->cpu_map;
53
+ struct perf_record_cpu_map *map_event = &event->cpu_map;
5254 struct cpu_map_entries *cpus;
53
- struct cpu_map_data *data;
54
- struct cpu_map *map;
55
+ struct perf_record_cpu_map_data *data;
56
+ struct perf_cpu_map *map;
5557
5658 data = &map_event->data;
5759
....@@ -68,36 +70,36 @@
6870 TEST_ASSERT_VAL("wrong cpu", map->map[0] == 1);
6971 TEST_ASSERT_VAL("wrong cpu", map->map[1] == 256);
7072 TEST_ASSERT_VAL("wrong refcnt", refcount_read(&map->refcnt) == 1);
71
- cpu_map__put(map);
73
+ perf_cpu_map__put(map);
7274 return 0;
7375 }
7476
7577
7678 int test__cpu_map_synthesize(struct test *test __maybe_unused, int subtest __maybe_unused)
7779 {
78
- struct cpu_map *cpus;
80
+ struct perf_cpu_map *cpus;
7981
8082 /* This one is better stores in mask. */
81
- cpus = cpu_map__new("0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19");
83
+ cpus = perf_cpu_map__new("0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19");
8284
8385 TEST_ASSERT_VAL("failed to synthesize map",
8486 !perf_event__synthesize_cpu_map(NULL, cpus, process_event_mask, NULL));
8587
86
- cpu_map__put(cpus);
88
+ perf_cpu_map__put(cpus);
8789
8890 /* This one is better stores in cpu values. */
89
- cpus = cpu_map__new("1,256");
91
+ cpus = perf_cpu_map__new("1,256");
9092
9193 TEST_ASSERT_VAL("failed to synthesize map",
9294 !perf_event__synthesize_cpu_map(NULL, cpus, process_event_cpus, NULL));
9395
94
- cpu_map__put(cpus);
96
+ perf_cpu_map__put(cpus);
9597 return 0;
9698 }
9799
98100 static int cpu_map_print(const char *str)
99101 {
100
- struct cpu_map *map = cpu_map__new(str);
102
+ struct perf_cpu_map *map = perf_cpu_map__new(str);
101103 char buf[100];
102104
103105 if (!map)
....@@ -118,3 +120,18 @@
118120 TEST_ASSERT_VAL("failed to convert map", cpu_map_print("1-10,12-20,22-30,32-40"));
119121 return 0;
120122 }
123
+
124
+int test__cpu_map_merge(struct test *test __maybe_unused, int subtest __maybe_unused)
125
+{
126
+ struct perf_cpu_map *a = perf_cpu_map__new("4,2,1");
127
+ struct perf_cpu_map *b = perf_cpu_map__new("4,5,7");
128
+ struct perf_cpu_map *c = perf_cpu_map__merge(a, b);
129
+ char buf[100];
130
+
131
+ TEST_ASSERT_VAL("failed to merge map: bad nr", c->nr == 5);
132
+ cpu_map__snprint(c, buf, sizeof(buf));
133
+ TEST_ASSERT_VAL("failed to merge map: bad result", !strcmp(buf, "1-2,4-5,7"));
134
+ perf_cpu_map__put(b);
135
+ perf_cpu_map__put(c);
136
+ return 0;
137
+}