From 30761c266bc4d97d73f38f37e6a37b3e7b90f839 Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Date: Fri, 24 Feb 2023 16:57:59 +0100 Subject: [PATCH] Emit the rank too when switching Nanos6 tasks The task type and rank are allowed to emit PRV duplicates. --- src/emu/nanos6/event.c | 13 ++++++++----- src/emu/nanos6/setup.c | 12 ++++++++++-- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/emu/nanos6/event.c b/src/emu/nanos6/event.c index 29f2d18..ad8f6ab 100644 --- a/src/emu/nanos6/event.c +++ b/src/emu/nanos6/event.c @@ -177,6 +177,7 @@ chan_task_switch(struct emu *emu, struct task *prev, struct task *next) { struct nanos6_thread *th = EXT(emu->thread, '6'); + struct proc *proc = emu->proc; if (!prev || !next) { err("cannot switch to or from a NULL task"); @@ -203,19 +204,21 @@ chan_task_switch(struct emu *emu, return -1; } - /* No need to change the rank as we will switch to tasks from - * same thread */ if (chan_set(&th->m.ch[CH_TASKID], value_int64(next->id)) != 0) { err("chan_set taskid failed"); return -1; } - - /* TODO: test when switching to another task with the same type. We - * should emit the same type state value as previous task. */ if (chan_set(&th->m.ch[CH_TYPE], value_int64(next->type->gid)) != 0) { err("chan_set type failed"); return -1; } + if (proc->rank >= 0) { + struct value vrank = value_int64(proc->rank + 1); + if (chan_set(&th->m.ch[CH_RANK], vrank) != 0) { + err("chan_set rank failed"); + return -1; + } + } return 0; } diff --git a/src/emu/nanos6/setup.c b/src/emu/nanos6/setup.c index ced6b9c..f35da85 100644 --- a/src/emu/nanos6/setup.c +++ b/src/emu/nanos6/setup.c @@ -30,6 +30,12 @@ static const int chan_stack[CH_MAX] = { [CH_THREAD] = 1, }; +static const int chan_dup[CH_MAX] = { + [CH_TYPE] = 1, + [CH_RANK] = 1, +}; + + /* ----------------- pvt ------------------ */ static const int pvt_type[] = { @@ -96,9 +102,9 @@ static const struct pcf_value_label (*pcf_labels[CH_MAX])[] = { static const long prv_flags[CH_MAX] = { [CH_TASKID] = PRV_SKIPDUP, - [CH_TYPE] = PRV_SKIPDUP, + [CH_TYPE] = PRV_EMITDUP, /* Switch to task of same type */ [CH_SUBSYSTEM] = PRV_SKIPDUP, - [CH_RANK] = PRV_SKIPDUP, + [CH_RANK] = PRV_EMITDUP, /* Switch to task of same rank */ [CH_THREAD] = PRV_SKIPDUP, }; @@ -134,6 +140,7 @@ static const struct model_chan_spec th_chan = { .prefix = model_name, .ch_names = chan_name, .ch_stack = chan_stack, + .ch_dup = chan_dup, .pvt = &pvt_spec, .track = th_track, }; @@ -143,6 +150,7 @@ static const struct model_chan_spec cpu_chan = { .prefix = model_name, .ch_names = chan_name, .ch_stack = chan_stack, + .ch_dup = chan_dup, .pvt = &pvt_spec, .track = cpu_track, };