From 3e9f4b958d98f8da97eab5b0a0d2871a8e3c760d 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 --- hypervisor/common/hv_main.c | 2 +- hypervisor/common/schedule.c | 10 ++++++---- hypervisor/include/common/schedule.h | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/hypervisor/common/hv_main.c b/hypervisor/common/hv_main.c index 96f1d596e..8def2d656 100644 --- a/hypervisor/common/hv_main.c +++ b/hypervisor/common/hv_main.c @@ -44,7 +44,7 @@ void vcpu_thread(struct acrn_vcpu *vcpu) 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() diff --git a/hypervisor/common/schedule.c b/hypervisor/common/schedule.c index 3369a8009..4d749801b 100644 --- a/hypervisor/common/schedule.c +++ b/hypervisor/common/schedule.c @@ -106,11 +106,11 @@ void make_reschedule_request(const struct acrn_vcpu *vcpu) } } -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); } static void context_switch_out(struct acrn_vcpu *vcpu) @@ -172,7 +172,7 @@ void default_idle(void) 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(); @@ -225,11 +225,13 @@ static void switch_to(struct acrn_vcpu *curr) void schedule(void) { uint16_t pcpu_id = get_cpu_id(); + struct sched_context *ctx = &per_cpu(sched_ctx, pcpu_id); struct acrn_vcpu *next = NULL; - struct acrn_vcpu *prev = per_cpu(sched_ctx, pcpu_id).curr_vcpu; + struct acrn_vcpu *prev = ctx->curr_vcpu; get_schedule_lock(pcpu_id); next = select_next_vcpu(pcpu_id); + 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 990b838ab..ac60173c8 100644 --- a/hypervisor/include/common/schedule.h +++ b/hypervisor/include/common/schedule.h @@ -32,7 +32,7 @@ void remove_vcpu_from_runqueue(struct acrn_vcpu *vcpu); void default_idle(void); void make_reschedule_request(const struct acrn_vcpu *vcpu); -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);