1/**
2 * \file
3 * \brief Test spanning of domains across cores
4 */
5
6/*
7 * Copyright (c) 2007, 2008, 2010, ETH Zurich.
8 * All rights reserved.
9 *
10 * This file is distributed under the terms in the attached LICENSE file.
11 * If you do not find this file, copies can be found by writing to:
12 * ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group.
13 */
14
15#include <stdio.h>
16#include <string.h>
17#include <barrelfish/barrelfish.h>
18#include <barrelfish/dispatch.h>
19#include <barrelfish/waitset.h>
20
21
22static int remote(void *dummy)
23{
24    uintptr_t v = (uintptr_t)dummy;
25    debug_printf("v = %"PRIuPTR"\n", v);
26    return v;
27}
28
29int ndispatchers = 1;
30
31static void domain_spanned_callback(void *arg, errval_t err)
32{
33    ndispatchers++;
34}
35
36int main(int argc, char *argv[])
37{
38    errval_t err;
39    if (argc != 2) {
40        printf("Usage %s: <Num additional threads>\n", argv[0]);
41        exit(-1);
42    }
43
44
45    //printf("main running on %d\n", disp_get_core_id());
46
47    int cores = strtol(argv[1], NULL, 10) + 1;
48
49    for(int i = 1; i < cores; i++) {
50        err = domain_new_dispatcher(i + disp_get_core_id(),
51                                    domain_spanned_callback,
52                                    (void*)(uintptr_t)i);
53        if (err_is_fail(err)) {
54            USER_PANIC_ERR(err, "domain_new_dispatcher failed");
55        }
56    }
57
58    while (ndispatchers < cores) {
59        thread_yield();
60    }
61
62    struct thread *threads[cores];
63    for(int i = 1; i < cores; i++) {
64        err = domain_thread_create_on(i, remote, (void*)(uintptr_t)i, &threads[i]);
65        assert(err_is_ok(err));
66        debug_printf("created %p\n", threads[i]);
67    }
68
69    for(int i = 1; i < cores; i++) {
70        int retval;
71        debug_printf("joining %p\n", threads[i]);
72        err = domain_thread_join(threads[i], &retval);
73        assert(err_is_ok(err));
74        debug_printf("retval = %d\n", retval);
75        assert(retval == i);
76    }
77    return 0;
78}
79