From a0154223f64ec82c22f15d8253537863f9ebdc81 Mon Sep 17 00:00:00 2001 From: Shuo A Liu Date: Tue, 25 Dec 2018 14:48:17 +0800 Subject: [PATCH] hv: clear NEED_RESCHEDULE flag in schedule Now, need_reschedule will test_and_clear the bit NEED_RESCHEDULE in schedule context, then call schedule. It is not a exact match with the name. This patch move the flag clearing into scheudle, and need_reschedule just check and return. Tracked-On: #1821 Signed-off-by: Shuo A Liu Reviewed-by: Yin Fengwei Acked-by: Eddie Dong --- hypervisor/common/hv_main.c | 4 ++-- hypervisor/common/schedule.c | 13 +++++++------ hypervisor/include/common/schedule.h | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/hypervisor/common/hv_main.c b/hypervisor/common/hv_main.c index 75ffa8267..138b98d96 100644 --- a/hypervisor/common/hv_main.c +++ b/hypervisor/common/hv_main.c @@ -45,7 +45,7 @@ void vcpu_thread(struct sched_object *obj) continue; } - if (need_reschedule(vcpu->pcpu_id) != 0) { + if (need_reschedule(vcpu->pcpu_id)) { /* * In extrem case, schedule() could return. Which * means the vcpu resume happens before schedule() @@ -95,7 +95,7 @@ void default_idle(__unused struct sched_object *obj) uint16_t pcpu_id = get_cpu_id(); while (1) { - if (need_reschedule(pcpu_id) != 0) { + if (need_reschedule(pcpu_id)) { schedule(); } else if (need_offline(pcpu_id) != 0) { cpu_dead(); diff --git a/hypervisor/common/schedule.c b/hypervisor/common/schedule.c index 0c6c66f92..10efbfaa3 100644 --- a/hypervisor/common/schedule.c +++ b/hypervisor/common/schedule.c @@ -81,9 +81,8 @@ void remove_from_cpu_runqueue(struct sched_object *obj, uint16_t pcpu_id) spinlock_release(&ctx->runqueue_lock); } -static struct sched_object *get_next_sched_obj(uint16_t pcpu_id) +static struct sched_object *get_next_sched_obj(struct sched_context *ctx) { - struct sched_context *ctx = &per_cpu(sched_ctx, pcpu_id); struct sched_object *obj = NULL; spinlock_obtain(&ctx->runqueue_lock); @@ -105,11 +104,11 @@ void make_reschedule_request(uint16_t pcpu_id) } } -int32_t need_reschedule(uint16_t pcpu_id) +bool need_reschedule(uint16_t pcpu_id) { struct sched_context *ctx = &per_cpu(sched_ctx, pcpu_id); - return bitmap_test_and_clear_lock(NEED_RESCHEDULE, &ctx->flags); + return bitmap_test(NEED_RESCHEDULE, &ctx->flags); } void make_pcpu_offline(uint16_t pcpu_id) @@ -173,11 +172,13 @@ static void prepare_switch(struct sched_object *prev, struct sched_object *next) void schedule(void) { uint16_t pcpu_id = get_cpu_id(); + struct sched_context *ctx = &per_cpu(sched_ctx, pcpu_id); struct sched_object *next = NULL; - struct sched_object *prev = per_cpu(sched_ctx, pcpu_id).curr_obj; + struct sched_object *prev = ctx->curr_obj; get_schedule_lock(pcpu_id); - next = get_next_sched_obj(pcpu_id); + next = get_next_sched_obj(ctx); + bitmap_clear_lock(NEED_RESCHEDULE, &ctx->flags); if (prev == next) { release_schedule_lock(pcpu_id); diff --git a/hypervisor/include/common/schedule.h b/hypervisor/include/common/schedule.h index 4cfd9235c..8edfcf964 100644 --- a/hypervisor/include/common/schedule.h +++ b/hypervisor/include/common/schedule.h @@ -41,7 +41,7 @@ void add_to_cpu_runqueue(struct sched_object *obj, uint16_t pcpu_id); void remove_from_cpu_runqueue(struct sched_object *obj, uint16_t pcpu_id); void make_reschedule_request(uint16_t pcpu_id); -int32_t need_reschedule(uint16_t pcpu_id); +bool need_reschedule(uint16_t pcpu_id); void make_pcpu_offline(uint16_t pcpu_id); int32_t need_offline(uint16_t pcpu_id);