Skip to content

Commit 0f70a5c

Browse files
Shuo A Liuacrnsi
authored andcommitted
hv: sched: decouple idle stuff from schedule module
Let init thread end with run_idle_thread(), then idle thread take over and start to do scheduling. Change enter_guest_mode() to init_guest_mode() as run_idle_thread() is removed out of it. Also add run_thread() in schedule module to run thread_object's thread loop directly. rename: switch_to_idle -> run_idle_thread Tracked-On: #3813 Signed-off-by: Shuo A Liu <shuo.a.liu@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent 27163df commit 0f70a5c

File tree

5 files changed

+36
-32
lines changed

5 files changed

+36
-32
lines changed

hypervisor/arch/x86/guest/vcpu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ static uint64_t build_stack_frame(struct acrn_vcpu *vcpu)
611611
frame -= 1;
612612

613613
frame->magic = SP_BOTTOM_MAGIC;
614-
frame->rip = (uint64_t)run_sched_thread; /*return address*/
614+
frame->rip = (uint64_t)vcpu->thread_obj.thread_entry; /*return address*/
615615
frame->rflag = 0UL;
616616
frame->rbx = 0UL;
617617
frame->rbp = 0UL;

hypervisor/arch/x86/init.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,11 @@ static void init_debug_post(uint16_t pcpu_id)
4949
}
5050

5151
/*TODO: move into guest-vcpu module */
52-
static void enter_guest_mode(uint16_t pcpu_id)
52+
static void init_guest_mode(uint16_t pcpu_id)
5353
{
5454
vmx_on();
5555

5656
launch_vms(pcpu_id);
57-
58-
switch_to_idle(default_idle);
59-
60-
/* Control should not come here */
61-
cpu_dead();
6257
}
6358

6459
static void init_primary_pcpu_post(void)
@@ -71,7 +66,9 @@ static void init_primary_pcpu_post(void)
7166

7267
init_debug_post(BOOT_CPU_ID);
7368

74-
enter_guest_mode(BOOT_CPU_ID);
69+
init_guest_mode(BOOT_CPU_ID);
70+
71+
run_idle_thread();
7572
}
7673

7774
/* NOTE: this function is using temp stack, and after SWITCH_TO(runtime_sp, to)
@@ -101,5 +98,7 @@ void init_secondary_pcpu(void)
10198

10299
init_debug_post(pcpu_id);
103100

104-
enter_guest_mode(pcpu_id);
101+
init_guest_mode(pcpu_id);
102+
103+
run_idle_thread();
105104
}

hypervisor/common/hv_main.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <irq.h>
1212
#include <schedule.h>
1313
#include <profiling.h>
14+
#include <sprintf.h>
1415
#include <trace.h>
1516
#include <logmsg.h>
1617

@@ -90,3 +91,22 @@ void default_idle(__unused struct thread_object *obj)
9091
}
9192
}
9293
}
94+
95+
void run_idle_thread(void)
96+
{
97+
uint16_t pcpu_id = get_pcpu_id();
98+
struct thread_object *idle = &per_cpu(idle, pcpu_id);
99+
char idle_name[16];
100+
101+
snprintf(idle_name, 16U, "idle%hu", pcpu_id);
102+
(void)strncpy_s(idle->name, 16U, idle_name, 16U);
103+
idle->pcpu_id = pcpu_id;
104+
idle->thread_entry = default_idle;
105+
idle->switch_out = NULL;
106+
idle->switch_in = NULL;
107+
108+
run_thread(idle);
109+
110+
/* Control should not come here */
111+
cpu_dead();
112+
}

hypervisor/common/schedule.c

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -194,29 +194,14 @@ void wake_thread(struct thread_object *obj)
194194
release_schedule_lock(pcpu_id);
195195
}
196196

197-
void run_sched_thread(struct thread_object *obj)
197+
void run_thread(struct thread_object *obj)
198198
{
199+
get_schedule_lock(obj->pcpu_id);
200+
get_cpu_var(sched_ctl).curr_obj = obj;
201+
set_thread_status(obj, THREAD_STS_RUNNING);
202+
release_schedule_lock(obj->pcpu_id);
203+
199204
if (obj->thread_entry != NULL) {
200205
obj->thread_entry(obj);
201206
}
202-
203-
ASSERT(false, "Shouldn't go here, invalid thread entry!");
204-
}
205-
206-
void switch_to_idle(thread_entry_t idle_thread)
207-
{
208-
uint16_t pcpu_id = get_pcpu_id();
209-
struct thread_object *idle = &per_cpu(idle, pcpu_id);
210-
char idle_name[16];
211-
212-
snprintf(idle_name, 16U, "idle%hu", pcpu_id);
213-
(void)strncpy_s(idle->name, 16U, idle_name, 16U);
214-
idle->pcpu_id = pcpu_id;
215-
idle->thread_entry = idle_thread;
216-
idle->switch_out = NULL;
217-
idle->switch_in = NULL;
218-
get_cpu_var(sched_ctl).curr_obj = idle;
219-
set_thread_status(idle, THREAD_STS_RUNNING);
220-
221-
run_sched_thread(idle);
222207
}

hypervisor/include/common/schedule.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ uint16_t sched_get_pcpuid(const struct thread_object *obj);
5353
struct thread_object *sched_get_current(uint16_t pcpu_id);
5454

5555
void init_sched(uint16_t pcpu_id);
56-
void switch_to_idle(thread_entry_t idle_thread);
5756
void get_schedule_lock(uint16_t pcpu_id);
5857
void release_schedule_lock(uint16_t pcpu_id);
5958

@@ -63,11 +62,12 @@ void remove_thread_obj(struct thread_object *obj, uint16_t pcpu_id);
6362
void make_reschedule_request(uint16_t pcpu_id, uint16_t delmode);
6463
bool need_reschedule(uint16_t pcpu_id);
6564

65+
void run_thread(struct thread_object *obj);
6666
void sleep_thread(struct thread_object *obj);
6767
void wake_thread(struct thread_object *obj);
6868
void schedule(void);
69-
void run_sched_thread(struct thread_object *obj);
7069

7170
void arch_switch_to(void *prev_sp, void *next_sp);
71+
void run_idle_thread(void);
7272
#endif /* SCHEDULE_H */
7373

0 commit comments

Comments
 (0)