Skip to content

Commit de157ab

Browse files
Shuo A Liuacrnsi
authored andcommitted
hv: sched: remove runqueue from current schedule logic
Currently we are using a 1:1 mapping logic for pcpu:vcpu. So don't need a runqueue for it. Removing it as preparation work to abstract scheduler framework. Tracked-On: #3813 Signed-off-by: Jason Chen CJ <jason.cj.chen@intel.com> Signed-off-by: Yu Wang <yu1.wang@intel.com> Signed-off-by: Shuo A Liu <shuo.a.liu@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent 837e4d8 commit de157ab

File tree

3 files changed

+16
-26
lines changed

3 files changed

+16
-26
lines changed

hypervisor/arch/x86/guest/vcpu.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ void pause_vcpu(struct acrn_vcpu *vcpu, enum vcpu_state new_state)
667667
vcpu->state = new_state;
668668

669669
if (vcpu->running) {
670-
remove_from_cpu_runqueue(&vcpu->thread_obj);
670+
remove_thread_obj(&vcpu->thread_obj, vcpu->pcpu_id);
671671

672672
if (is_lapic_pt_enabled(vcpu)) {
673673
make_reschedule_request(vcpu->pcpu_id, DEL_MODE_INIT);
@@ -683,7 +683,7 @@ void pause_vcpu(struct acrn_vcpu *vcpu, enum vcpu_state new_state)
683683
}
684684
}
685685
} else {
686-
remove_from_cpu_runqueue(&vcpu->thread_obj);
686+
remove_thread_obj(&vcpu->thread_obj, vcpu->pcpu_id);
687687
release_schedule_lock(vcpu->pcpu_id);
688688
}
689689
}
@@ -696,7 +696,7 @@ void resume_vcpu(struct acrn_vcpu *vcpu)
696696
vcpu->state = vcpu->prev_state;
697697

698698
if (vcpu->state == VCPU_RUNNING) {
699-
add_to_cpu_runqueue(&vcpu->thread_obj, vcpu->pcpu_id);
699+
insert_thread_obj(&vcpu->thread_obj, vcpu->pcpu_id);
700700
make_reschedule_request(vcpu->pcpu_id, DEL_MODE_IPI);
701701
}
702702
release_schedule_lock(vcpu->pcpu_id);
@@ -733,7 +733,7 @@ void schedule_vcpu(struct acrn_vcpu *vcpu)
733733
pr_dbg("vcpu%hu scheduled", vcpu->vcpu_id);
734734

735735
get_schedule_lock(vcpu->pcpu_id);
736-
add_to_cpu_runqueue(&vcpu->thread_obj, vcpu->pcpu_id);
736+
insert_thread_obj(&vcpu->thread_obj, vcpu->pcpu_id);
737737
make_reschedule_request(vcpu->pcpu_id, DEL_MODE_IPI);
738738
release_schedule_lock(vcpu->pcpu_id);
739739
}
@@ -747,7 +747,6 @@ int32_t prepare_vcpu(struct acrn_vm *vm, uint16_t pcpu_id)
747747

748748
ret = create_vcpu(pcpu_id, vm, &vcpu);
749749
if (ret == 0) {
750-
INIT_LIST_HEAD(&vcpu->thread_obj.run_list);
751750
snprintf(thread_name, 16U, "vm%hu:vcpu%hu", vm->vm_id, vcpu->vcpu_id);
752751
(void)strncpy_s(vcpu->thread_obj.name, 16U, thread_name, 16U);
753752
vcpu->thread_obj.thread_entry = vcpu_thread;

hypervisor/common/schedule.c

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ void init_scheduler(void)
2323
ctl = &per_cpu(sched_ctl, i);
2424

2525
spinlock_init(&ctl->scheduler_lock);
26-
INIT_LIST_HEAD(&ctl->runqueue);
2726
ctl->flags = 0UL;
2827
ctl->curr_obj = NULL;
2928
}
@@ -41,31 +40,23 @@ void release_schedule_lock(uint16_t pcpu_id)
4140
spinlock_release(&ctl->scheduler_lock);
4241
}
4342

44-
void add_to_cpu_runqueue(struct thread_object *obj, uint16_t pcpu_id)
43+
void insert_thread_obj(struct thread_object *obj, uint16_t pcpu_id)
4544
{
4645
struct sched_control *ctl = &per_cpu(sched_ctl, pcpu_id);
4746

48-
if (list_empty(&obj->run_list)) {
49-
list_add_tail(&obj->run_list, &ctl->runqueue);
50-
}
47+
ctl->thread_obj = obj;
5148
}
5249

53-
void remove_from_cpu_runqueue(struct thread_object *obj)
50+
void remove_thread_obj(__unused struct thread_object *obj, uint16_t pcpu_id)
5451
{
55-
list_del_init(&obj->run_list);
52+
struct sched_control *ctl = &per_cpu(sched_ctl, pcpu_id);
53+
54+
ctl->thread_obj = NULL;
5655
}
5756

58-
static struct thread_object *get_next_sched_obj(struct sched_control *ctl)
57+
static struct thread_object *get_next_sched_obj(const struct sched_control *ctl)
5958
{
60-
struct thread_object *obj = NULL;
61-
62-
if (!list_empty(&ctl->runqueue)) {
63-
obj = get_first_item(&ctl->runqueue, struct thread_object, run_list);
64-
} else {
65-
obj = &get_cpu_var(idle);
66-
}
67-
68-
return obj;
59+
return ctl->thread_obj == NULL ? &get_cpu_var(idle) : ctl->thread_obj;
6960
}
7061

7162
/**

hypervisor/include/common/schedule.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,27 @@ typedef void (*thread_entry_t)(struct thread_object *obj);
1818
typedef void (*switch_t)(struct thread_object *obj);
1919
struct thread_object {
2020
char name[16];
21-
struct list_head run_list;
2221
uint64_t host_sp;
2322
thread_entry_t thread_entry;
2423
switch_t switch_out;
2524
switch_t switch_in;
2625
};
2726

2827
struct sched_control {
29-
struct list_head runqueue;
3028
uint64_t flags;
3129
struct thread_object *curr_obj;
3230
spinlock_t scheduler_lock; /* to protect sched_control and thread_object */
31+
32+
struct thread_object *thread_obj;
3333
};
3434

3535
void init_scheduler(void);
3636
void switch_to_idle(thread_entry_t idle_thread);
3737
void get_schedule_lock(uint16_t pcpu_id);
3838
void release_schedule_lock(uint16_t pcpu_id);
3939

40-
void add_to_cpu_runqueue(struct thread_object *obj, uint16_t pcpu_id);
41-
void remove_from_cpu_runqueue(struct thread_object *obj);
40+
void insert_thread_obj(struct thread_object *obj, uint16_t pcpu_id);
41+
void remove_thread_obj(struct thread_object *obj, uint16_t pcpu_id);
4242

4343
void make_reschedule_request(uint16_t pcpu_id, uint16_t delmode);
4444
bool need_reschedule(uint16_t pcpu_id);

0 commit comments

Comments
 (0)