Skip to content

Commit ec25716

Browse files
paulusmackagraf
authored andcommitted
KVM: PPC: Book3S HV: Make use of unused threads when running guests
When running a virtual core of a guest that is configured with fewer threads per core than the physical cores have, the extra physical threads are currently unused. This makes it possible to use them to run one or more other virtual cores from the same guest when certain conditions are met. This applies on POWER7, and on POWER8 to guests with one thread per virtual core. (It doesn't apply to POWER8 guests with multiple threads per vcore because they require a 1-1 virtual to physical thread mapping in order to be able to use msgsndp and the TIR.) The idea is that we maintain a list of preempted vcores for each physical cpu (i.e. each core, since the host runs single-threaded). Then, when a vcore is about to run, it checks to see if there are any vcores on the list for its physical cpu that could be piggybacked onto this vcore's execution. If so, those additional vcores are put into state VCORE_PIGGYBACK and their runnable VCPU threads are started as well as the original vcore, which is called the master vcore. After the vcores have exited the guest, the extra ones are put back onto the preempted list if any of their VCPUs are still runnable and not idle. This means that vcpu->arch.ptid is no longer necessarily the same as the physical thread that the vcpu runs on. In order to make it easier for code that wants to send an IPI to know which CPU to target, we now store that in a new field in struct vcpu_arch, called thread_cpu. Reviewed-by: David Gibson <[email protected]> Tested-by: Laurent Vivier <[email protected]> Signed-off-by: Paul Mackerras <[email protected]> Signed-off-by: Alexander Graf <[email protected]>
1 parent 845ac98 commit ec25716

File tree

6 files changed

+298
-72
lines changed

6 files changed

+298
-72
lines changed

arch/powerpc/include/asm/kvm_host.h

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,9 @@ struct kvmppc_vcore {
278278
u16 last_cpu;
279279
u8 vcore_state;
280280
u8 in_guest;
281+
struct kvmppc_vcore *master_vcore;
281282
struct list_head runnable_threads;
283+
struct list_head preempt_list;
282284
spinlock_t lock;
283285
wait_queue_head_t wq;
284286
spinlock_t stoltb_lock; /* protects stolen_tb and preempt_tb */
@@ -300,12 +302,18 @@ struct kvmppc_vcore {
300302
#define VCORE_EXIT_MAP(vc) ((vc)->entry_exit_map >> 8)
301303
#define VCORE_IS_EXITING(vc) (VCORE_EXIT_MAP(vc) != 0)
302304

303-
/* Values for vcore_state */
305+
/*
306+
* Values for vcore_state.
307+
* Note that these are arranged such that lower values
308+
* (< VCORE_SLEEPING) don't require stolen time accounting
309+
* on load/unload, and higher values do.
310+
*/
304311
#define VCORE_INACTIVE 0
305-
#define VCORE_SLEEPING 1
306-
#define VCORE_PREEMPT 2
307-
#define VCORE_RUNNING 3
308-
#define VCORE_EXITING 4
312+
#define VCORE_PREEMPT 1
313+
#define VCORE_PIGGYBACK 2
314+
#define VCORE_SLEEPING 3
315+
#define VCORE_RUNNING 4
316+
#define VCORE_EXITING 5
309317

310318
/*
311319
* Struct used to manage memory for a virtual processor area
@@ -619,6 +627,7 @@ struct kvm_vcpu_arch {
619627
int trap;
620628
int state;
621629
int ptid;
630+
int thread_cpu;
622631
bool timer_running;
623632
wait_queue_head_t cpu_run;
624633

arch/powerpc/kernel/asm-offsets.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,8 @@ int main(void)
512512
DEFINE(VCPU_VPA, offsetof(struct kvm_vcpu, arch.vpa.pinned_addr));
513513
DEFINE(VCPU_VPA_DIRTY, offsetof(struct kvm_vcpu, arch.vpa.dirty));
514514
DEFINE(VCPU_HEIR, offsetof(struct kvm_vcpu, arch.emul_inst));
515+
DEFINE(VCPU_CPU, offsetof(struct kvm_vcpu, cpu));
516+
DEFINE(VCPU_THREAD_CPU, offsetof(struct kvm_vcpu, arch.thread_cpu));
515517
#endif
516518
#ifdef CONFIG_PPC_BOOK3S
517519
DEFINE(VCPU_VCPUID, offsetof(struct kvm_vcpu, vcpu_id));

0 commit comments

Comments
 (0)