Skip to content

Commit 7a71422

Browse files
fyin1lijinxia
authored andcommitted
hv: handle cpu offline request in idle thread
Change need_scheduled fileds of schedule context to flags because it's not only used for need_schedule check. Add two functions to request/handle cpu offline. The reason we only handle cpu offline request in idle thread is that we should pause the vcpu running on target pcpu. Then it's only possible that target pcpu get cpu offline request in idle thread. Signed-off-by: Yin Fegnwei <fengwei.yin@intel.com> Acked-by: Eddie Dong <Eddie.dong@intel.com>
1 parent 08139c3 commit 7a71422

File tree

3 files changed

+30
-11
lines changed

3 files changed

+30
-11
lines changed

hypervisor/common/hv_main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ void vcpu_thread(struct vcpu *vcpu)
4444
continue;
4545
}
4646

47-
if (need_rescheduled(vcpu->pcpu_id)) {
47+
if (need_reschedule(vcpu->pcpu_id)) {
4848
/*
4949
* In extrem case, schedule() could return. Which
5050
* means the vcpu resume happens before schedule()

hypervisor/common/schedule.c

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ void init_scheduler(void)
1717
spinlock_init(&per_cpu(sched_ctx, i).runqueue_lock);
1818
spinlock_init(&per_cpu(sched_ctx, i).scheduler_lock);
1919
INIT_LIST_HEAD(&per_cpu(sched_ctx, i).runqueue);
20-
per_cpu(sched_ctx, i).need_scheduled = 0;
20+
per_cpu(sched_ctx, i).flags= 0;
2121
per_cpu(sched_ctx, i).curr_vcpu = NULL;
2222
}
2323
}
@@ -90,15 +90,15 @@ static struct vcpu *select_next_vcpu(int pcpu_id)
9090

9191
void make_reschedule_request(struct vcpu *vcpu)
9292
{
93-
bitmap_set(NEED_RESCHEDULED,
94-
&per_cpu(sched_ctx, vcpu->pcpu_id).need_scheduled);
93+
bitmap_set(NEED_RESCHEDULE,
94+
&per_cpu(sched_ctx, vcpu->pcpu_id).flags);
9595
send_single_ipi(vcpu->pcpu_id, VECTOR_NOTIFY_VCPU);
9696
}
9797

98-
int need_rescheduled(int pcpu_id)
98+
int need_reschedule(int pcpu_id)
9999
{
100-
return bitmap_test_and_clear(NEED_RESCHEDULED,
101-
&per_cpu(sched_ctx, pcpu_id).need_scheduled);
100+
return bitmap_test_and_clear(NEED_RESCHEDULE,
101+
&per_cpu(sched_ctx, pcpu_id).flags);
102102
}
103103

104104
static void context_switch_out(struct vcpu *vcpu)
@@ -136,13 +136,28 @@ static void context_switch_in(struct vcpu *vcpu)
136136
*/
137137
}
138138

139+
void make_pcpu_offline(int pcpu_id)
140+
{
141+
bitmap_set(NEED_OFFLINE,
142+
&per_cpu(sched_ctx, pcpu_id).flags);
143+
send_single_ipi(pcpu_id, VECTOR_NOTIFY_VCPU);
144+
}
145+
146+
int need_offline(int pcpu_id)
147+
{
148+
return bitmap_test_and_clear(NEED_OFFLINE,
149+
&per_cpu(sched_ctx, pcpu_id).flags);
150+
}
151+
139152
void default_idle(void)
140153
{
141154
int pcpu_id = get_cpu_id();
142155

143156
while (1) {
144-
if (need_rescheduled(pcpu_id))
157+
if (need_reschedule(pcpu_id))
145158
schedule();
159+
else if (need_offline(pcpu_id))
160+
cpu_dead(pcpu_id);
146161
else
147162
__asm __volatile("pause" ::: "memory");
148163
}

hypervisor/include/common/schedule.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77
#ifndef _HV_CORE_SCHEDULE_
88
#define _HV_CORE_SCHEDULE_
99

10-
#define NEED_RESCHEDULED (1)
10+
#define NEED_RESCHEDULE (1)
11+
#define NEED_OFFLINE (2)
1112

1213
struct sched_context {
1314
spinlock_t runqueue_lock;
1415
struct list_head runqueue;
15-
unsigned long need_scheduled;
16+
unsigned long flags;
1617
struct vcpu *curr_vcpu;
1718
spinlock_t scheduler_lock;
1819
};
@@ -31,7 +32,10 @@ void remove_vcpu_from_runqueue(struct vcpu *vcpu);
3132
void default_idle(void);
3233

3334
void make_reschedule_request(struct vcpu *vcpu);
34-
int need_rescheduled(int pcpu_id);
35+
int need_reschedule(int pcpu_id);
36+
void make_pcpu_offline(int pcpu_id);
37+
int need_offline(int pcpu_id);
38+
3539
void schedule(void);
3640

3741
void vcpu_thread(struct vcpu *vcpu);

0 commit comments

Comments
 (0)