]> git.proxmox.com Git - ceph.git/blob - ceph/src/spdk/test/event/reactor_perf/reactor_perf.c
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / spdk / test / event / reactor_perf / reactor_perf.c
1 /*-
2 * BSD LICENSE
3 *
4 * Copyright (c) Intel Corporation.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
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
16 * distribution.
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.
20 *
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.
32 */
33
34 #include "spdk/stdinc.h"
35
36 #include "spdk/env.h"
37 #include "spdk/event.h"
38 #include "spdk/string.h"
39 #include "spdk/thread.h"
40
41 static int g_time_in_sec;
42 static int g_queue_depth;
43 static struct spdk_poller *g_test_end_poller;
44 static uint64_t g_call_count = 0;
45
46 static int
47 __test_end(void *arg)
48 {
49 printf("test_end\n");
50 spdk_poller_unregister(&g_test_end_poller);
51 spdk_app_stop(0);
52 return -1;
53 }
54
55 static void
56 __submit_next(void *arg1, void *arg2)
57 {
58 struct spdk_event *event;
59
60 g_call_count++;
61
62 event = spdk_event_allocate(spdk_env_get_current_core(),
63 __submit_next, NULL, NULL);
64 spdk_event_call(event);
65 }
66
67 static void
68 test_start(void *arg1)
69 {
70 int i;
71
72 printf("test_start\n");
73
74 /* Register a poller that will stop the test after the time has elapsed. */
75 g_test_end_poller = SPDK_POLLER_REGISTER(__test_end, NULL,
76 g_time_in_sec * 1000000ULL);
77
78 for (i = 0; i < g_queue_depth; i++) {
79 __submit_next(NULL, NULL);
80 }
81 }
82
83 static void
84 test_cleanup(void)
85 {
86 printf("test_abort\n");
87
88 spdk_poller_unregister(&g_test_end_poller);
89 spdk_app_stop(0);
90 }
91
92 static void
93 usage(const char *program_name)
94 {
95 printf("%s options\n", program_name);
96 printf("\t[-q Queue depth (default: 1)]\n");
97 printf("\t[-t time in seconds]\n");
98 }
99
100 int
101 main(int argc, char **argv)
102 {
103 struct spdk_app_opts opts;
104 int op;
105 int rc;
106 long int val;
107
108 spdk_app_opts_init(&opts);
109 opts.name = "reactor_perf";
110
111 g_time_in_sec = 0;
112 g_queue_depth = 1;
113
114 while ((op = getopt(argc, argv, "q:t:")) != -1) {
115 if (op == '?') {
116 usage(argv[0]);
117 exit(1);
118 }
119 val = spdk_strtol(optarg, 10);
120 if (val < 0) {
121 fprintf(stderr, "Converting a string to integer failed\n");
122 exit(1);
123 }
124 switch (op) {
125 case 'q':
126 g_queue_depth = val;
127 break;
128 case 't':
129 g_time_in_sec = val;
130 break;
131 default:
132 usage(argv[0]);
133 exit(1);
134 }
135 }
136
137 if (!g_time_in_sec) {
138 usage(argv[0]);
139 exit(1);
140 }
141
142 opts.shutdown_cb = test_cleanup;
143
144 rc = spdk_app_start(&opts, test_start, NULL);
145
146 spdk_app_fini();
147
148 printf("Performance: %8ju events per second\n", g_call_count / g_time_in_sec);
149
150 return rc;
151 }