#include <barrelfish/barrelfish.h>
#include <collections/hash_table.h>
+#include <if/spawn_defs.h>
#include "domain.h"
+#include "spawnd_state.h"
#define HASH_INDEX_BUCKETS 6151
static collections_hash_table* domain_table = NULL;
-errval_t domain_cap_hash(struct capref domain_cap, uint64_t *ret_hash)
-{
- assert(ret_hash != NULL);
-
- struct capability ret_cap;
- errval_t err = debug_cap_identify(domain_cap, &ret_cap);
- if (err_is_fail(err)) {
- return err_push(err, PROC_MGMT_ERR_DOMAIN_CAP_HASH);
- }
- assert(ret_cap.type == ObjType_Domain);
-
- static uint64_t base = 1 + (uint64_t) MAX_COREID;
- *ret_hash = base * ret_cap.u.domain.coreid + ret_cap.u.domain.core_local_id;
-
- return SYS_ERR_OK;
-}
-
errval_t domain_new(struct capref domain_cap, struct domain_entry **ret_entry)
{
assert(ret_entry != NULL);
entry->domain_cap = domain_cap;
entry->status = DOMAIN_STATUS_NIL;
- entry->spawnds = NULL;
+ memset(entry->spawnds, 0, sizeof(entry->spawnds));
+ entry->num_spawnds_running = 0;
+ entry->num_spawnds_resources = 0;
entry->waiters = NULL;
if (domain_table == NULL) {
return SYS_ERR_OK;
}
-void domain_run_on_spawnd(struct domain_entry *entry,
- struct spawnd_state *spawnd)
+void domain_run_on_core(struct domain_entry *entry, coreid_t core_id)
{
assert(entry != NULL);
- assert(spawnd != NULL);
+ assert(core_id < MAX_COREID);
assert(entry->status == DOMAIN_STATUS_NIL ||
entry->status == DOMAIN_STATUS_RUNNING);
entry->status = DOMAIN_STATUS_RUNNING;
- struct domain_spawnd_state *st = (struct domain_spawnd_state*) malloc(
- sizeof(struct domain_spawnd_state));
- st->spawnd_state = spawnd;
- st->next = entry->spawnds;
- entry->spawnds = st;
+ entry->spawnds[core_id] = spawnd_state_get(core_id);
+ ++entry->num_spawnds_running;
+ ++entry->num_spawnds_resources;
}
errval_t domain_spawn(struct capref domain_cap, coreid_t core_id)
return err;
}
- domain_run_on_spawnd(entry, spawnd_state_get(core_id));
-
- return SYS_ERR_OK;
-}
-
-errval_t domain_can_span(struct capref domain_cap, coreid_t core_id)
-{
- struct domain_entry *entry = NULL;
- errval_t err = domain_get_by_cap(domain_cap, &entry);
- if (err_is_fail(err)) {
- return err;
- }
-
- assert(entry != NULL);
- if (entry->status != DOMAIN_STATUS_RUNNING) {
- return PROC_MGMT_ERR_DOMAIN_NOT_RUNNING;
- }
-
- struct domain_spawnd_state *st = entry->spawnds;
- while (st != NULL) {
- if (st->spawnd_state->core_id == core_id) {
- // TODO(razvan): Maybe we want to allow the same domain to span
- // multiple dispatcher onto the same core?
- return PROC_MGMT_ERR_ALREADY_SPANNED;
- }
- st = st->next;
- }
+ domain_run_on_core(entry, core_id);
return SYS_ERR_OK;
}
}
assert(entry != NULL);
- domain_run_on_spawnd(entry, spawnd_state_get(core_id));
+ domain_run_on_core(entry, core_id);
return SYS_ERR_OK;
}
-
-void domain_send_stop(struct domain_entry *entry)
-{
- assert(entry != NULL);
-
- struct domain_spawnd_state *st = entry->spawnds;
- while (st != NULL) {
- debug_printf("Simulating STOP message to spawnd at binding %p\n",
- st->spawnd_state->b);
- st = st->next;
- }
-}