@@ -20,17 +20,20 @@ char _license[] SEC("license") = "GPL";
20
20
const unsigned int data_sizes [] = {16 , 32 , 64 , 96 , 128 , 192 , 256 , 512 , 1024 , 2048 , 4096 };
21
21
const volatile unsigned int data_btf_ids [ARRAY_SIZE (data_sizes )] = {};
22
22
23
+ const unsigned int percpu_data_sizes [] = {8 , 16 , 32 , 64 , 96 , 128 , 192 , 256 , 512 };
24
+ const volatile unsigned int percpu_data_btf_ids [ARRAY_SIZE (data_sizes )] = {};
25
+
23
26
int err = 0 ;
24
27
u32 pid = 0 ;
25
28
26
29
#define DEFINE_ARRAY_WITH_KPTR (_size ) \
27
30
struct bin_data_##_size { \
28
31
char data[_size - sizeof(void *)]; \
29
32
}; \
33
+ /* See Commit 5d8d6634ccc, force btf generation for type bin_data_##_size */ \
34
+ struct bin_data_ ##_size * __bin_data_ ##_size ; \
30
35
struct map_value_ ##_size { \
31
36
struct bin_data_ ##_size __kptr * data ; \
32
- /* To emit BTF info for bin_data_xx */ \
33
- struct bin_data_ ##_size not_used ; \
34
37
}; \
35
38
struct { \
36
39
__uint (type , BPF_MAP_TYPE_ARRAY ); \
@@ -40,8 +43,12 @@ u32 pid = 0;
40
43
} array_ ##_size SEC (".maps ")
41
44
42
45
#define DEFINE_ARRAY_WITH_PERCPU_KPTR (_size ) \
46
+ struct percpu_bin_data_##_size { \
47
+ char data[_size]; \
48
+ }; \
49
+ struct percpu_bin_data_##_size *__percpu_bin_data_##_size; \
43
50
struct map_value_percpu_##_size { \
44
- struct bin_data_ ##_size __percpu_kptr * data; \
51
+ struct percpu_bin_data_ ##_size __percpu_kptr * data; \
45
52
}; \
46
53
struct { \
47
54
__uint(type, BPF_MAP_TYPE_ARRAY); \
@@ -114,7 +121,7 @@ static __always_inline void batch_percpu_alloc(struct bpf_map *map, unsigned int
114
121
return ;
115
122
}
116
123
/* per-cpu allocator may not be able to refill in time */
117
- new = bpf_percpu_obj_new_impl (data_btf_ids [idx ], NULL );
124
+ new = bpf_percpu_obj_new_impl (percpu_data_btf_ids [idx ], NULL );
118
125
if (!new )
119
126
continue ;
120
127
@@ -179,7 +186,7 @@ DEFINE_ARRAY_WITH_KPTR(1024);
179
186
DEFINE_ARRAY_WITH_KPTR (2048 );
180
187
DEFINE_ARRAY_WITH_KPTR (4096 );
181
188
182
- /* per-cpu kptr doesn't support bin_data_8 which is a zero-sized array */
189
+ DEFINE_ARRAY_WITH_PERCPU_KPTR ( 8 );
183
190
DEFINE_ARRAY_WITH_PERCPU_KPTR (16 );
184
191
DEFINE_ARRAY_WITH_PERCPU_KPTR (32 );
185
192
DEFINE_ARRAY_WITH_PERCPU_KPTR (64 );
@@ -188,9 +195,6 @@ DEFINE_ARRAY_WITH_PERCPU_KPTR(128);
188
195
DEFINE_ARRAY_WITH_PERCPU_KPTR (192 );
189
196
DEFINE_ARRAY_WITH_PERCPU_KPTR (256 );
190
197
DEFINE_ARRAY_WITH_PERCPU_KPTR (512 );
191
- DEFINE_ARRAY_WITH_PERCPU_KPTR (1024 );
192
- DEFINE_ARRAY_WITH_PERCPU_KPTR (2048 );
193
- DEFINE_ARRAY_WITH_PERCPU_KPTR (4096 );
194
198
195
199
SEC ("?fentry/" SYS_PREFIX "sys_nanosleep" )
196
200
int test_batch_alloc_free (void * ctx )
@@ -246,20 +250,18 @@ int test_batch_percpu_alloc_free(void *ctx)
246
250
if ((u32 )bpf_get_current_pid_tgid () != pid )
247
251
return 0 ;
248
252
249
- /* Alloc 128 16 -bytes per-cpu objects in batch to trigger refilling,
250
- * then free 128 16 -bytes per-cpu objects in batch to trigger freeing.
253
+ /* Alloc 128 8 -bytes per-cpu objects in batch to trigger refilling,
254
+ * then free 128 8 -bytes per-cpu objects in batch to trigger freeing.
251
255
*/
252
- CALL_BATCH_PERCPU_ALLOC_FREE (16 , 128 , 0 );
253
- CALL_BATCH_PERCPU_ALLOC_FREE (32 , 128 , 1 );
254
- CALL_BATCH_PERCPU_ALLOC_FREE (64 , 128 , 2 );
255
- CALL_BATCH_PERCPU_ALLOC_FREE (96 , 128 , 3 );
256
- CALL_BATCH_PERCPU_ALLOC_FREE (128 , 128 , 4 );
257
- CALL_BATCH_PERCPU_ALLOC_FREE (192 , 128 , 5 );
258
- CALL_BATCH_PERCPU_ALLOC_FREE (256 , 128 , 6 );
259
- CALL_BATCH_PERCPU_ALLOC_FREE (512 , 64 , 7 );
260
- CALL_BATCH_PERCPU_ALLOC_FREE (1024 , 32 , 8 );
261
- CALL_BATCH_PERCPU_ALLOC_FREE (2048 , 16 , 9 );
262
- CALL_BATCH_PERCPU_ALLOC_FREE (4096 , 8 , 10 );
256
+ CALL_BATCH_PERCPU_ALLOC_FREE (8 , 128 , 0 );
257
+ CALL_BATCH_PERCPU_ALLOC_FREE (16 , 128 , 1 );
258
+ CALL_BATCH_PERCPU_ALLOC_FREE (32 , 128 , 2 );
259
+ CALL_BATCH_PERCPU_ALLOC_FREE (64 , 128 , 3 );
260
+ CALL_BATCH_PERCPU_ALLOC_FREE (96 , 128 , 4 );
261
+ CALL_BATCH_PERCPU_ALLOC_FREE (128 , 128 , 5 );
262
+ CALL_BATCH_PERCPU_ALLOC_FREE (192 , 128 , 6 );
263
+ CALL_BATCH_PERCPU_ALLOC_FREE (256 , 128 , 7 );
264
+ CALL_BATCH_PERCPU_ALLOC_FREE (512 , 64 , 8 );
263
265
264
266
return 0 ;
265
267
}
@@ -270,20 +272,18 @@ int test_percpu_free_through_map_free(void *ctx)
270
272
if ((u32 )bpf_get_current_pid_tgid () != pid )
271
273
return 0 ;
272
274
273
- /* Alloc 128 16 -bytes per-cpu objects in batch to trigger refilling,
275
+ /* Alloc 128 8 -bytes per-cpu objects in batch to trigger refilling,
274
276
* then free these object through map free.
275
277
*/
276
- CALL_BATCH_PERCPU_ALLOC (16 , 128 , 0 );
277
- CALL_BATCH_PERCPU_ALLOC (32 , 128 , 1 );
278
- CALL_BATCH_PERCPU_ALLOC (64 , 128 , 2 );
279
- CALL_BATCH_PERCPU_ALLOC (96 , 128 , 3 );
280
- CALL_BATCH_PERCPU_ALLOC (128 , 128 , 4 );
281
- CALL_BATCH_PERCPU_ALLOC (192 , 128 , 5 );
282
- CALL_BATCH_PERCPU_ALLOC (256 , 128 , 6 );
283
- CALL_BATCH_PERCPU_ALLOC (512 , 64 , 7 );
284
- CALL_BATCH_PERCPU_ALLOC (1024 , 32 , 8 );
285
- CALL_BATCH_PERCPU_ALLOC (2048 , 16 , 9 );
286
- CALL_BATCH_PERCPU_ALLOC (4096 , 8 , 10 );
278
+ CALL_BATCH_PERCPU_ALLOC (8 , 128 , 0 );
279
+ CALL_BATCH_PERCPU_ALLOC (16 , 128 , 1 );
280
+ CALL_BATCH_PERCPU_ALLOC (32 , 128 , 2 );
281
+ CALL_BATCH_PERCPU_ALLOC (64 , 128 , 3 );
282
+ CALL_BATCH_PERCPU_ALLOC (96 , 128 , 4 );
283
+ CALL_BATCH_PERCPU_ALLOC (128 , 128 , 5 );
284
+ CALL_BATCH_PERCPU_ALLOC (192 , 128 , 6 );
285
+ CALL_BATCH_PERCPU_ALLOC (256 , 128 , 7 );
286
+ CALL_BATCH_PERCPU_ALLOC (512 , 64 , 8 );
287
287
288
288
return 0 ;
289
289
}
0 commit comments