1/** \file
2 *  \brief Example spaning application
3 */
4
5/*
6 * Copyright (c) 2010, 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 <stdio.h>
15#include <string.h>
16
17#include <barrelfish/barrelfish.h>
18
19int global;
20
21static int do_hello(void *arg)
22{
23    debug_printf("Hello! the global is: %x\n", global);
24    return EXIT_SUCCESS;
25}
26
27bool all_spanned = false;
28int num_span = -1;
29
30static void span_cb(void *arg, errval_t err)
31{
32    if (err_is_fail(err)) {
33        DEBUG_ERR(err, "span failed");
34        return;
35    }
36
37    static int num_spanned = 0;
38
39    num_spanned++;
40    if (num_spanned >= num_span) {
41        all_spanned = true;
42    }
43
44}
45
46int main(int argc, char *argv[])
47{
48    errval_t err;
49    coreid_t mycore = disp_get_core_id();
50
51    if (argc == 2) {
52        num_span = atoi(argv[1]);
53
54        debug_printf("spanning on %d cores\n", num_span);
55
56        for (int i = 1; i <= num_span; i++) {
57
58            err = domain_new_dispatcher(mycore + i, span_cb, NULL);
59
60            if (err_is_fail(err)) {
61                DEBUG_ERR(err, "failed span %d", i);
62            }
63        }
64    } else {
65        debug_printf("usage %s num_span\n", argv[0]);
66        return EXIT_FAILURE;
67    }
68
69    while (!all_spanned) {
70        thread_yield();
71    }
72
73    global = 0xC007;
74
75    for(int i = 1; i <= num_span; i++) {
76        debug_printf("starting thread on %d\n", mycore + i);
77
78        err = domain_thread_create_on(mycore + i, do_hello, NULL, NULL);
79
80        if (err_is_fail(err)) {
81            DEBUG_ERR(err, "failed thread create %d", i);
82        }
83    }
84
85    debug_printf("Finished\n");
86}
87