1/** 2 * \file 3 * \brief Gathers different information from every single core 4 */ 5 6/* 7 * Copyright (c) 2007, 2008, 2009, 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/waitset.h> 19#include <barrelfish/nameservice_client.h> 20#include <barrelfish/spawn_client.h> 21#include <skb/skb.h> 22#include <barrelfish/dispatch.h> 23#include "datagatherer.h" 24 25#define SPAWN_YOUR_SELF 26 27//prototypes 28#ifdef SPAWN_YOUR_SELF 29static void spawnmyself(void); 30#endif 31 32 33static bool bsp_datagatherer = false; 34static coreid_t core_id; 35 36extern bool rtt_done; 37 38static coreid_t nr_of_running_cores = 0; 39 40 41 42int main(int argc, char **argv) 43{ 44 errval_t err; 45 //this is the bootstrap copy of the domain 46 if (strcmp(argv[argc - 1], "SpAwNeD") != 0) { 47 bsp_datagatherer = true; 48 } else { 49 bsp_datagatherer = false; 50 } 51 52 core_id = disp_get_core_id(); 53 err = skb_client_connect(); 54 if (err_is_fail(err)) { 55 USER_PANIC_ERR(err, "skb_client_connect failed"); 56 return 1; 57 } 58 59#ifdef SPAWN_YOUR_SELF 60 if (bsp_datagatherer) { 61 spawnmyself(); 62 } 63#endif 64 65 //gather different types of data 66 67 //run cpuid 68 err = gather_cpuid_data(core_id); 69 if (err_is_fail(err)) { 70 USER_PANIC_ERR(err, "gather_cpuid_data failed"); 71 } 72 73 //adding the number of cores is the last operation performed by the datagatherer. 74 //therefore the domain can exit after this. process events as long as the number 75 //of cores has not yet been added to the SKB. 76 77 err = skb_add_fact("datagatherer_done."); 78 if (err_is_fail(err)) { 79 USER_PANIC_ERR(err, "skb_add_fact failed"); 80 } 81 82 if (bsp_datagatherer) { 83 int length = nr_of_running_cores + 1; 84 while (length != nr_of_running_cores) { 85 skb_execute_query("findall(X, datagatherer_done, L),length(L,Len),write(Len)."); 86 skb_read_output("%d", &length); 87 thread_yield(); 88 } 89 90 91 err = nameservice_register("datagatherer_done", 0); 92 if (err_is_fail(err)) { 93 DEBUG_ERR(err, "nameservice_register failed"); 94 } 95 } 96 return 0; 97} 98 99 100 101 102#ifdef SPAWN_YOUR_SELF 103//*********** everything needed to spawn myself to all other cores ************* 104 105static void spawnmyself(void) 106{ 107 errval_t err; 108 char *argv[] = {"datagatherer", "SpAwNeD", NULL}; 109 err = spawn_program_on_all_cores(false, argv[0], argv, NULL, 110 SPAWN_FLAGS_DEFAULT, NULL, 111 &nr_of_running_cores); 112 if (err_is_fail(err)) { 113 USER_PANIC_ERR(err, "error spawning other core"); 114 } 115} 116#endif 117