2 * \brief Process Management test.
6 * Copyright (c) 2017, ETH Zurich.
9 * This file is distributed under the terms in the attached LICENSE file.
10 * If you do not find this file, copies can be found by writing to:
11 * ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group.
16 #include <barrelfish/barrelfish.h>
17 #include <barrelfish/deferred.h>
18 #include <barrelfish/proc_mgmt_client.h>
19 #include <barrelfish/spawn_client.h>
20 #include <bench/bench.h>
22 #define PROC_MGMT_BENCH 1
23 #define PROC_MGMT_BENCH_MIN_RUNS 20
26 static errval_t test_spawn(coreid_t core_id, char *argv[],
27 struct capref *ret_domain_cap)
29 assert(ret_domain_cap != NULL);
31 errval_t err = proc_mgmt_spawn_program(core_id,
32 "/x86_64/sbin/proc_mgmt_test",
33 argv, NULL, 0, ret_domain_cap);
34 if (err_is_fail(err)) {
41 static void test_span(coreid_t core_id)
43 errval_t err = proc_mgmt_span(core_id);
44 if (err_is_fail(err)) {
48 static void test_kill(struct capref domain_cap)
50 errval_t err = proc_mgmt_kill(domain_cap);
52 USER_PANIC("Failed killing domain")
56 static void test_wait(struct capref domain_cap)
59 errval_t err = proc_mgmt_wait(domain_cap, &code);
60 if (err_is_fail(err)) {
61 USER_PANIC("Failed waiting for domain");
65 static inline cycles_t calculate_time(cycles_t tsc_start, cycles_t tsc_end)
68 if (tsc_end < tsc_start) {
69 result = (LONG_MAX - tsc_start) + tsc_end - bench_tscoverhead();
71 result = (tsc_end - tsc_start - bench_tscoverhead());
76 static void run_benchmark_spawn(coreid_t target_core)
80 cycles_t tsc_start, tsc_end;
84 bench_ctl_t *ctl = calloc(1, sizeof(*ctl));
85 ctl->mode = BENCH_MODE_FIXEDRUNS;
86 ctl->result_dimensions = 1;
87 ctl->min_runs = PROC_MGMT_BENCH_MIN_RUNS;
88 ctl->data = calloc(ctl->min_runs * ctl->result_dimensions,
91 errval_t err = sys_debug_get_tsc_per_ms(&tscperus);
92 assert(err_is_ok(err));
95 struct capref domain_cap;
97 char *spawn_argv[] = { "proc_mgmt_test", "0", "norun", NULL};
99 tsc_start = bench_tsc();
101 test_spawn(target_core, spawn_argv, &domain_cap);
103 tsc_end = bench_tsc();
104 result = calculate_time(tsc_start, tsc_end);
105 } while (!bench_ctl_add_run(ctl, &result));
107 cap_destroy(domain_cap);
108 bench_ctl_dump_analysis(ctl, 0, "client", tscperus);
110 bench_ctl_destroy(ctl);
114 int main(int argc, char **argv)
118 if (strcmp("starter", argv[2]) == 0) {
120 } else if (strcmp("norun", argv[2]) == 0) {
123 } else if (strcmp("run", argv[2]) == 0) {
125 printf("Running infinite Loop");
127 printf("Running infinite Loop");
128 barrelfish_usleep(1000*1000);
129 event_dispatch_non_block(get_default_waitset());
131 } else if (strcmp("sleeper", argv[2]) == 0) {
132 // Process that we wait for to finish
133 printf("Running for a few seconds \n");
134 barrelfish_usleep(10*1000*1000);
135 printf("Sleeper exit\n");
137 } else if (strcmp("span", argv[2]) == 0) {
138 // Process that spans domains
139 if (disp_get_core_id() == 0) {
145 event_dispatch(get_default_waitset());
148 USER_PANIC("Unknown Role \n ");
152 USER_PANIC("Not enough arguments to run test \n ");
155 struct capref domain_cap;
156 printf("Testing kill on same core\n");
157 char *spawn_argv[] = { "proc_mgmt_test", "0", "run", NULL};
158 err = test_spawn(2, spawn_argv, &domain_cap);
159 if (err_is_fail(err)) {
160 USER_PANIC("Failed spawning program proc_mgmt_test \n");
163 //starting a process takes some time ...
164 barrelfish_usleep(5*1000*1000);
166 printf("Killing process \n");
167 err = proc_mgmt_kill(domain_cap);
168 if (err_is_fail(err)) {
169 USER_PANIC("Failed waiting for domain \n");
172 // Killing a process takes some time ...
173 barrelfish_usleep(5*1000*1000);
175 printf("Testing kill on other core\n");
176 err = test_spawn(1, spawn_argv, &domain_cap);
177 if (err_is_fail(err)) {
178 USER_PANIC("Failed spawning program proc_mgmt_test \n");
181 barrelfish_usleep(5*1000*1000);
183 printf("Killing process \n");
184 err = proc_mgmt_kill(domain_cap);
185 if (err_is_fail(err)) {
186 USER_PANIC("Failed waiting for domain \n");
189 // TODO check if process was killed
190 printf("Testing spaning on different core\n");
191 char *spawn_argv3[] = { "proc_mgmt_test", "0", "span", NULL};
192 err = test_spawn(0, spawn_argv3, &domain_cap);
193 if (err_is_fail(err)) {
194 USER_PANIC("Failed spawning program proc_mgmt_test \n");
197 printf("Testing spaning on same core\n");
198 err = test_spawn(2, spawn_argv3, &domain_cap);
199 if (err_is_fail(err)) {
200 USER_PANIC("Failed spawning program proc_mgmt_test \n");
203 printf("Testing wait on different core process\n");
204 char *spawn_argv2[] = { "proc_mgmt_test", "0", "sleeper"};
205 err = test_spawn(0, spawn_argv2, &domain_cap);
206 if (err_is_fail(err)) {
207 USER_PANIC("Failed spawning program proc_mgmt_test \n");
210 barrelfish_usleep(5*1000*1000);
213 printf("Waiting for process on different core to finish \n");
214 err = proc_mgmt_wait(domain_cap, &code);
215 if (err_is_fail(err)) {
216 USER_PANIC("Failed waiting for domain \n");
218 printf("Unblocked \n");
220 printf("Testing wait on same core process\n");
221 err = test_spawn(2, spawn_argv2, &domain_cap);
222 if (err_is_fail(err)) {
223 USER_PANIC("Failed spawning program proc_mgmt_test \n");
226 barrelfish_usleep(5*1000*1000);
228 printf("Waiting for process on same core to finish \n");
229 err = proc_mgmt_wait(domain_cap, &code);
230 if (err_is_fail(err)) {
231 USER_PANIC("Failed waiting for domain \n");
233 printf("Unblocked \n");
236 printf("Running benchmarks core 0 \n");
237 run_benchmark_spawn(0);
238 printf("Running benchmarks core 3 \n");
239 run_benchmark_spawn(3);
241 printf("TEST DONE\n");