DIRTY benchmark commit
[barrelfish] / usr / tests / proc_mgmt_test / main.c
1 /** \file
2  *  \brief Process Management test.
3  */
4
5 /*
6  * Copyright (c) 2017, ETH Zurich.
7  * All rights reserved.
8  *
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.
12  */
13
14 #include <stdlib.h>
15
16 #include <barrelfish/barrelfish.h>
17 #include <barrelfish/deferred.h>
18 #include <barrelfish/proc_mgmt_client.h>
19 #include <bench/bench.h>
20
21 #define PROC_MGMT_BENCH 1
22 #define PROC_MGMT_BENCH_MIN_RUNS 120
23
24 int my_id;
25 // int total_ids;
26
27 static void test_spawn(coreid_t core_id, char *argv[],
28                            struct capref *ret_domain_cap)
29 {
30         assert(ret_domain_cap != NULL);
31
32         errval_t err = proc_mgmt_spawn_program(core_id,
33                                                    "/x86_64/sbin/proc_mgmt_test",
34                                                    argv, NULL, 0, ret_domain_cap);
35         if (err_is_ok(err)) {
36                 // printf("OK: my_id=%i, spawn(%u, proc_mgmt_test)\n", my_id, core_id);
37         } else {
38                 // printf("FAIL: spawn(%u, proc_mgmt_test), err=%s\n", core_id,
39                 //         err_getstring(err));
40         }
41 }
42
43 // static void test_span(coreid_t core_id)
44 // {
45 //      errval_t err = proc_mgmt_span(core_id);
46 //      if (err_is_ok(err)) {
47 //              printf("OK: span(%u)\n", core_id);
48 //      } else {
49 //              printf("FAIL: span(%u), err=%s\n", core_id, err_getstring(err));
50 //      }
51 // }
52
53 // static void test_kill(struct capref domain_cap)
54 // {
55 //      errval_t err = proc_mgmt_kill(domain_cap);
56 //      if (err_is_ok(err)) {
57 //              printf("OK: kill\n");
58 //      } else {
59 //              printf("FAIL: kill, err=%s\n", err_getstring(err));
60 //      }
61 // }
62
63 // static void test_wait(struct capref domain_cap)
64 // {
65 //      uint8_t code;
66 //      errval_t err = proc_mgmt_wait(domain_cap, &code);
67 //      if (err_is_ok(err)) {
68 //              printf("OK: wait, code=%u\n", code);
69 //      } else {
70 //              printf("FAIL: wait, err=%s\n", err_getstring(err));
71 //      }
72 // }
73
74 static inline cycles_t calculate_time(cycles_t tsc_start, cycles_t tsc_end)
75 {
76     cycles_t result;
77     if (tsc_end < tsc_start) {
78         result = (LONG_MAX - tsc_start) + tsc_end - bench_tscoverhead();
79     } else {
80         result = (tsc_end - tsc_start - bench_tscoverhead());
81     }
82     return result;
83 }
84
85 int main(int argc, char **argv)
86 {
87         if (argc == 3) {
88                 bench_init();
89                 
90                 cycles_t tsc_start, tsc_end;
91         cycles_t result;
92         uint64_t tscperus;
93         
94         bench_ctl_t *ctl = calloc(1, sizeof(*ctl));
95             ctl->mode = BENCH_MODE_FIXEDRUNS;
96             ctl->result_dimensions = 1;
97             ctl->min_runs = PROC_MGMT_BENCH_MIN_RUNS;
98         ctl->data = calloc(ctl->min_runs * ctl->result_dimensions,
99                                sizeof(*ctl->data));
100
101                 errval_t err = sys_debug_get_tsc_per_ms(&tscperus);
102             assert(err_is_ok(err));
103             tscperus /= 1000;
104
105                 coreid_t target_core = 0;//strcmp(argv[1], "1") == 0 ? 1 : 2;
106                 char *spawn_argv[] = { "proc_mgmt_test", "noop", NULL };
107                 my_id = atoi(argv[1]);
108         struct capref domain_cap;
109                 // total_ids = atoi(argv[2]);
110
111         barrelfish_usleep((0 - 10 * my_id) * 1000 * 1000);
112
113             // ctl = bench_ctl_init(BENCH_MODE_FIXEDRUNS, 1, 100);
114             do {
115                 // debug_printf("BEFORE test_spawn\n");
116                 tsc_start = bench_tsc();
117
118                         test_spawn(target_core, spawn_argv, &domain_cap);
119                         // test_wait(domain_cap);
120
121                 tsc_end = bench_tsc();
122                 result = calculate_time(tsc_start, tsc_end);
123
124                         barrelfish_usleep(2 * 1000 * 1000);
125             }while (!bench_ctl_add_run(ctl, &result));
126             // } while (true);
127
128             bench_ctl_dump_analysis(ctl, 0, "client", tscperus);
129
130         bench_ctl_destroy(ctl);
131
132                 barrelfish_usleep(5 * 1000 * 1000);
133                 while (true);
134
135                 printf("TEST DONE\n");
136         } else {
137                 // for(;;) {
138   //            errval_t err = event_dispatch(get_default_waitset());
139   //            if(err_is_fail(err)) {
140   //            USER_PANIC_ERR(err, "event_dispatch");
141   //            }
142   //       }
143         }
144
145         // printf("HELLO from proc_mgmt_test, argc=%u\n", argc);
146         // // errval_t err;
147         // if (argc == 1) {
148         //      struct capref domain_cap_0;
149         //      char *argv_0[] = { "proc_mgmt_test", "1", NULL };
150         //      test_spawn(0, argv_0, &domain_cap_0);
151         //      barrelfish_usleep(5*1000*1000);
152         //      // while (true);
153         //      test_kill(domain_cap_0);
154         //      test_wait(domain_cap_0);
155         //      // barrelfish_usleep(0 * 1*1*1);
156
157         //      struct capref domain_cap_1;
158         //      char *argv_1[] = { "proc_mgmt_test", "1", "2", NULL };
159         //      test_spawn(1, argv_1, &domain_cap_1);
160         //      test_wait(domain_cap_1);
161
162         //      printf("TEST DONE\n");
163         //      // barrelfish_usleep(5*1000*1000);
164
165         //      // err = proc_mgmt_kill(domain_cap);
166         //      // if (err_is_fail(err)) {
167         //      //      USER_PANIC_ERR(err, "failed to kill proc_mgmt_test");
168         //      // }
169
170         //      // uint8_t status;
171         //      // err = proc_mgmt_wait(domain_cap, &status);
172         //      // printf("2nd proc_mgmt_test finished with status %u\n", status);
173         // } else if (argc == 2) {
174         //      // test_span(disp_get_core_id() == 0 ? 1 : 0);
175
176         //      // // struct capability ret;
177         //      // // err = debug_cap_identify(cap_domainid, &ret);
178         //      // // if (err_is_fail(err)) {
179         //      // //   USER_PANIC_ERR(err, "failed to identify cap_domainid");
180         //      // // }
181         //      // // assert(ret.type == ObjType_Domain);
182         //      // // printf("proc_mgmt_test: cap_domainid = { .coreid=%u, .core_local_id=%u "
183         //      // //      "}\n", ret.u.domain.coreid, ret.u.domain.core_local_id);
184
185         //      // // coreid_t other_core = disp_get_core_id() == 0 ? 1 : 0;
186         //      // // err = proc_mgmt_span(other_core);//domain_new_dispatcher(other_core, span_cb, NULL);
187         //      // // if (err_is_fail(err)) {
188         //      // //   USER_PANIC_ERR(err, "failed to span proc_mgmt_test on core %u\n",
189         //      // //                      other_core);
190         //      // // }
191
192         //      // // barrelfish_usleep(5*1000*1000);
193         //      // // printf("Main dispatcher exiting...\n");
194
195         //      for(;;) {
196  //             errval_t err = event_dispatch(get_default_waitset());
197  //             if(err_is_fail(err)) {
198  //             USER_PANIC_ERR(err, "event_dispatch");
199  //             }
200  //        }
201         // } else {
202         //      // barrelfish_usleep(5 * 1000 * 1000);
203         //      // We'll just exit normally here, spawner should be waiting for us.
204         // }
205
206     return 0;
207 }