2 * \brief Domain internals for the process manager.
4 * Copyright (c) 2017, ETH Zurich.
7 * This file is distributed under the terms in the attached LICENSE file.
8 * If you do not find this file, copies can be found by writing to:
9 * ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group.
12 #include <barrelfish/barrelfish.h>
13 #include <collections/hash_table.h>
14 #include <if/spawn_defs.h>
17 #include "spawnd_state.h"
19 #define HASH_INDEX_BUCKETS 6151
20 static collections_hash_table* domain_table = NULL;
22 errval_t domain_new(struct capref domain_cap, struct domain_entry **ret_entry)
24 assert(ret_entry != NULL);
26 struct domain_entry *entry = (struct domain_entry*) malloc(
27 sizeof(struct domain_entry));
29 return LIB_ERR_MALLOC_FAIL;
32 entry->domain_cap = domain_cap;
33 entry->status = DOMAIN_STATUS_NIL;
34 memset(entry->spawnds, 0, sizeof(entry->spawnds));
35 entry->num_spawnds_running = 0;
36 entry->num_spawnds_resources = 0;
37 entry->waiters = NULL;
39 if (domain_table == NULL) {
40 collections_hash_create_with_buckets(&domain_table, HASH_INDEX_BUCKETS,
42 if (domain_table == NULL) {
43 return PROC_MGMT_ERR_CREATE_DOMAIN_TABLE;
48 errval_t err = domain_cap_hash(entry->domain_cap, &key);
49 if (err_is_fail(err)) {
53 collections_hash_insert(domain_table, key, entry);
60 errval_t domain_get_by_cap(struct capref domain_cap,
61 struct domain_entry **ret_entry)
63 assert(ret_entry != NULL);
66 errval_t err = domain_cap_hash(domain_cap, &key);
67 if (err_is_fail(err)) {
71 void *table_entry = collections_hash_find(domain_table, key);
72 if (table_entry == NULL) {
73 return PROC_MGMT_ERR_DOMAIN_TABLE_FIND;
75 *ret_entry = (struct domain_entry*) table_entry;
80 void domain_run_on_core(struct domain_entry *entry, coreid_t core_id)
82 assert(entry != NULL);
83 assert(core_id < MAX_COREID);
84 assert(entry->status == DOMAIN_STATUS_NIL ||
85 entry->status == DOMAIN_STATUS_RUNNING);
87 entry->status = DOMAIN_STATUS_RUNNING;
89 entry->spawnds[core_id] = spawnd_state_get(core_id);
90 ++entry->num_spawnds_running;
91 ++entry->num_spawnds_resources;
94 errval_t domain_spawn(struct capref domain_cap, coreid_t core_id)
96 struct domain_entry *entry = NULL;
97 errval_t err = domain_new(domain_cap, &entry);
98 if (err_is_fail(err)) {
105 domain_run_on_core(entry, core_id);
110 errval_t domain_span(struct capref domain_cap, coreid_t core_id)
112 struct domain_entry *entry = NULL;
113 errval_t err = domain_get_by_cap(domain_cap, &entry);
114 if (err_is_fail(err)) {
117 assert(entry != NULL);
119 domain_run_on_core(entry, core_id);