]>
git.proxmox.com Git - ceph.git/blob - ceph/src/spdk/test/event/event_perf/event_perf.c
4 * Copyright (c) Intel Corporation.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include "spdk/stdinc.h"
37 #include "spdk/event.h"
38 #include "spdk_internal/event.h"
41 static uint64_t g_tsc_rate
;
42 static uint64_t g_tsc_us_rate
;
43 static uint64_t g_tsc_end
;
45 static int g_time_in_sec
;
47 static uint64_t *call_count
;
49 static bool g_app_stopped
= false;
52 submit_new_event(void *arg1
, void *arg2
)
54 struct spdk_event
*event
;
55 static __thread
uint32_t next_lcore
= UINT32_MAX
;
57 if (spdk_get_ticks() > g_tsc_end
) {
58 if (__sync_bool_compare_and_swap(&g_app_stopped
, false, true)) {
64 if (next_lcore
== UINT32_MAX
) {
65 next_lcore
= spdk_env_get_next_core(spdk_env_get_current_core());
66 if (next_lcore
== UINT32_MAX
) {
67 next_lcore
= spdk_env_get_first_core();
71 call_count
[next_lcore
]++;
72 event
= spdk_event_allocate(next_lcore
, submit_new_event
, NULL
, NULL
);
73 spdk_event_call(event
);
77 event_work_fn(void *arg1
, void *arg2
)
80 submit_new_event(NULL
, NULL
);
81 submit_new_event(NULL
, NULL
);
82 submit_new_event(NULL
, NULL
);
83 submit_new_event(NULL
, NULL
);
87 event_perf_start(void *arg1
, void *arg2
)
91 call_count
= calloc(spdk_env_get_last_core() + 1, sizeof(*call_count
));
92 if (call_count
== NULL
) {
93 fprintf(stderr
, "call_count allocation failed\n");
98 g_tsc_rate
= spdk_get_ticks_hz();
99 g_tsc_us_rate
= g_tsc_rate
/ (1000 * 1000);
100 g_tsc_end
= spdk_get_ticks() + g_time_in_sec
* g_tsc_rate
;
102 printf("Running I/O for %d seconds...", g_time_in_sec
);
105 SPDK_ENV_FOREACH_CORE(i
) {
106 spdk_event_call(spdk_event_allocate(i
, event_work_fn
,
113 usage(char *program_name
)
115 printf("%s options\n", program_name
);
116 printf("\t[-m core mask for distributing I/O submission/completion work\n");
117 printf("\t\t(default: 0x1 - use core 0 only)]\n");
118 printf("\t[-t time in seconds]\n");
122 performance_dump(int io_time
)
126 if (call_count
== NULL
) {
131 SPDK_ENV_FOREACH_CORE(i
) {
132 printf("lcore %2d: %8ju\n", i
, call_count
[i
] / g_time_in_sec
);
140 main(int argc
, char **argv
)
142 struct spdk_app_opts opts
= {};
146 opts
.name
= "event_perf";
151 while ((op
= getopt(argc
, argv
, "m:t:")) != -1) {
154 opts
.reactor_mask
= optarg
;
157 g_time_in_sec
= atoi(optarg
);
165 if (!g_time_in_sec
) {
170 printf("Running I/O for %d seconds...", g_time_in_sec
);
173 rc
= spdk_app_start(&opts
, event_perf_start
, NULL
, NULL
);
176 performance_dump(g_time_in_sec
);