Skip to content

Commit a015422

Browse files
Shuo A Liuwenlingz
authored andcommitted
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 <shuo.a.liu@intel.com> Reviewed-by: Yin Fengwei <fengwei.yin@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent e8ac976 commit a015422

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

hypervisor/common/hv_main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ void vcpu_thread(struct sched_object *obj)
4545
continue;
4646
}
4747

48-
if (need_reschedule(vcpu->pcpu_id) != 0) {
48+
if (need_reschedule(vcpu->pcpu_id)) {
4949
/*
5050
* In extrem case, schedule() could return. Which
5151
* means the vcpu resume happens before schedule()
@@ -95,7 +95,7 @@ void default_idle(__unused struct sched_object *obj)
9595
uint16_t pcpu_id = get_cpu_id();
9696

9797
while (1) {
98-
if (need_reschedule(pcpu_id) != 0) {
98+
if (need_reschedule(pcpu_id)) {
9999
schedule();
100100
} else if (need_offline(pcpu_id) != 0) {
101101
cpu_dead();

hypervisor/common/schedule.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,8 @@ void remove_from_cpu_runqueue(struct sched_object *obj, uint16_t pcpu_id)
8181
spinlock_release(&ctx->runqueue_lock);
8282
}
8383

84-
static struct sched_object *get_next_sched_obj(uint16_t pcpu_id)
84+
static struct sched_object *get_next_sched_obj(struct sched_context *ctx)
8585
{
86-
struct sched_context *ctx = &per_cpu(sched_ctx, pcpu_id);
8786
struct sched_object *obj = NULL;
8887

8988
spinlock_obtain(&ctx->runqueue_lock);
@@ -105,11 +104,11 @@ void make_reschedule_request(uint16_t pcpu_id)
105104
}
106105
}
107106

108-
int32_t need_reschedule(uint16_t pcpu_id)
107+
bool need_reschedule(uint16_t pcpu_id)
109108
{
110109
struct sched_context *ctx = &per_cpu(sched_ctx, pcpu_id);
111110

112-
return bitmap_test_and_clear_lock(NEED_RESCHEDULE, &ctx->flags);
111+
return bitmap_test(NEED_RESCHEDULE, &ctx->flags);
113112
}
114113

115114
void make_pcpu_offline(uint16_t pcpu_id)
@@ -173,11 +172,13 @@ static void prepare_switch(struct sched_object *prev, struct sched_object *next)
173172
void schedule(void)
174173
{
175174
uint16_t pcpu_id = get_cpu_id();
175+
struct sched_context *ctx = &per_cpu(sched_ctx, pcpu_id);
176176
struct sched_object *next = NULL;
177-
struct sched_object *prev = per_cpu(sched_ctx, pcpu_id).curr_obj;
177+
struct sched_object *prev = ctx->curr_obj;
178178

179179
get_schedule_lock(pcpu_id);
180-
next = get_next_sched_obj(pcpu_id);
180+
next = get_next_sched_obj(ctx);
181+
bitmap_clear_lock(NEED_RESCHEDULE, &ctx->flags);
181182

182183
if (prev == next) {
183184
release_schedule_lock(pcpu_id);

hypervisor/include/common/schedule.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ void add_to_cpu_runqueue(struct sched_object *obj, uint16_t pcpu_id);
4141
void remove_from_cpu_runqueue(struct sched_object *obj, uint16_t pcpu_id);
4242

4343
void make_reschedule_request(uint16_t pcpu_id);
44-
int32_t need_reschedule(uint16_t pcpu_id);
44+
bool need_reschedule(uint16_t pcpu_id);
4545
void make_pcpu_offline(uint16_t pcpu_id);
4646
int32_t need_offline(uint16_t pcpu_id);
4747

0 commit comments

Comments
 (0)