1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2020 Facebook */
5 /* COUNT-GLOBAL benchmark */
7 static struct count_global_ctx
{
11 static void *count_global_producer(void *input
)
13 struct count_global_ctx
*ctx
= &count_global_ctx
;
16 atomic_inc(&ctx
->hits
.value
);
21 static void *count_global_consumer(void *input
)
26 static void count_global_measure(struct bench_res
*res
)
28 struct count_global_ctx
*ctx
= &count_global_ctx
;
30 res
->hits
= atomic_swap(&ctx
->hits
.value
, 0);
33 /* COUNT-local benchmark */
35 static struct count_local_ctx
{
39 static void count_local_setup()
41 struct count_local_ctx
*ctx
= &count_local_ctx
;
43 ctx
->hits
= calloc(env
.consumer_cnt
, sizeof(*ctx
->hits
));
48 static void *count_local_producer(void *input
)
50 struct count_local_ctx
*ctx
= &count_local_ctx
;
51 int idx
= (long)input
;
54 atomic_inc(&ctx
->hits
[idx
].value
);
59 static void *count_local_consumer(void *input
)
64 static void count_local_measure(struct bench_res
*res
)
66 struct count_local_ctx
*ctx
= &count_local_ctx
;
69 for (i
= 0; i
< env
.producer_cnt
; i
++) {
70 res
->hits
+= atomic_swap(&ctx
->hits
[i
].value
, 0);
74 const struct bench bench_count_global
= {
75 .name
= "count-global",
76 .producer_thread
= count_global_producer
,
77 .consumer_thread
= count_global_consumer
,
78 .measure
= count_global_measure
,
79 .report_progress
= hits_drops_report_progress
,
80 .report_final
= hits_drops_report_final
,
83 const struct bench bench_count_local
= {
84 .name
= "count-local",
85 .setup
= count_local_setup
,
86 .producer_thread
= count_local_producer
,
87 .consumer_thread
= count_local_consumer
,
88 .measure
= count_local_measure
,
89 .report_progress
= hits_drops_report_progress
,
90 .report_final
= hits_drops_report_final
,