From d0539a9cac27e834ca82aab906cbc1ef76d86196 Mon Sep 17 00:00:00 2001 From: Balazs Gerofi Date: Fri, 22 Jul 2016 18:06:11 +0900 Subject: [PATCH] eclair: make idle threads visible --- arch/x86/kernel/syscall.c | 1 + executer/user/eclair.c | 60 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/arch/x86/kernel/syscall.c b/arch/x86/kernel/syscall.c index 84797b00..a37b2d64 100644 --- a/arch/x86/kernel/syscall.c +++ b/arch/x86/kernel/syscall.c @@ -55,6 +55,7 @@ uintptr_t debug_constants[] = { offsetof(struct cpu_local_var, current), offsetof(struct cpu_local_var, runq), offsetof(struct cpu_local_var, status), + offsetof(struct cpu_local_var, idle), offsetof(struct thread, ctx), offsetof(struct thread, sched_list), offsetof(struct thread, proc), diff --git a/executer/user/eclair.c b/executer/user/eclair.c index 9427a5b8..777f827f 100644 --- a/executer/user/eclair.c +++ b/executer/user/eclair.c @@ -167,6 +167,7 @@ enum { CURRENT_OFFSET, RUNQ_OFFSET, CPU_STATUS_OFFSET, + IDLE_THREAD_OFFSET, /* process */ CTX_OFFSET, @@ -204,6 +205,7 @@ static int setup_constants(void) { printf("CURRENT_OFFSET: %ld\n", K(CURRENT_OFFSET)); printf("RUNQ_OFFSET: %ld\n", K(RUNQ_OFFSET)); printf("CPU_STATUS_OFFSET: %ld\n", K(CPU_STATUS_OFFSET)); + printf("IDLE_THREAD_OFFSET: %ld\n", K(IDLE_THREAD_OFFSET)); printf("CTX_OFFSET: %ld\n", K(CTX_OFFSET)); printf("SCHED_LIST_OFFSET: %ld\n", K(SCHED_LIST_OFFSET)); printf("PROC_OFFSET: %ld\n", K(PROC_OFFSET)); @@ -251,6 +253,64 @@ static int setup_threads(void) { ihk_mc_switch_context = lookup_symbol("ihk_mc_switch_context"); if (0) printf("ihk_mc_switch_context: %lx\n", ihk_mc_switch_context); + /* Set up idle threads first */ + for (cpu = 0; cpu < num_processors; ++cpu) { + uintptr_t v; + uintptr_t thread; + uintptr_t proc; + int pid; + int tid; + struct thread_info *ti; + int status; + + v = clv + (cpu * K(CPU_LOCAL_VAR_SIZE)); + + ti = malloc(sizeof(*ti)); + if (!ti) { + perror("malloc"); + return 1; + } + + thread = v+K(IDLE_THREAD_OFFSET); + + error = read_64(thread+K(PROC_OFFSET), &proc); + if (error) { + perror("proc"); + return 1; + } + + error = read_32(thread+K(STATUS_OFFSET), &status); + if (error) { + perror("status"); + return 1; + } + + error = read_32(proc+K(PID_OFFSET), &pid); + if (error) { + perror("pid"); + return 1; + } + + error = read_32(thread+K(TID_OFFSET), &tid); + if (error) { + perror("tid"); + return 1; + } + + ti->next = NULL; + ti->status = status; + ti->pid = pid; + ti->tid = tid; + ti->cpu = cpu; + ti->lcpu = cpu; + ti->process = thread; + ti->clv = v; + ti->x86_clv = locals + locals_span*cpu; + + *titailp = ti; + titailp = &ti->next; + } + for (cpu = 0; cpu < num_processors; ++cpu) { uintptr_t v; uintptr_t head;