kvm/ppc/book3s: Move struct kvmppc_vcore from kvm_host.h to kvm_book3s.h
Subsystems (2)
PATCH v3 1/5 kvm/ppc/book3s: Move struct kvmppc_vcore from kvm_host.h to kvm_book3s.h
The next commit will introduce a member to the kvmppc_vcore struct which references MAX_SMT_THREADS which is defined in kvm_book3s_asm.h, however this file isn't included in kvm_host.h directly. Thus compiling for certain platforms such as pmac32_defconfig and ppc64e_defconfig with KVM fails due to MAX_SMT_THREADS not being defined.
Move the struct kvmppc_vcore definition to kvm_book3s.h which explicitly includes kvm_book3s_asm.h.
---
Change Log:
V1 -> V2:
- Added patch to series
V2 -> V3:
- Nothing
--- arch/powerpc/include/asm/kvm_book3s.h | 35 +++++++++++++++++++++++++++++++++++ arch/powerpc/include/asm/kvm_host.h | 35 ----------------------------------- 2 files changed, 35 insertions(+), 35 deletions(-)
arch/powerpc/include/asm/kvm_book3s.h +35 -0
@@ -69,6 +69,41 @@ struct hpte_cache {int pagesize; }; +/* +* Struct for a virtual core. +* Note: entry_exit_map combines a bitmap of threads that have entered +* in the bottom 8 bits and a bitmap of threads that have exited in the +* next 8 bits. This is so that we can atomically set the entry bit +* iff the exit map is 0 without taking a lock. +*/ +struct kvmppc_vcore { +int n_runnable; +int num_threads; +int entry_exit_map; +int napping_threads; +int first_vcpuid; +u16 pcpu; +u16 last_cpu; +u8 vcore_state; +u8 in_guest; +struct kvmppc_vcore *master_vcore; +struct list_head runnable_threads; +struct list_head preempt_list; +spinlock_t lock; +struct swait_queue_head wq; +spinlock_t stoltb_lock;/* protects stolen_tb and preempt_tb */ +u64 stolen_tb; +u64 preempt_tb; +struct kvm_vcpu *runner; +struct kvm *kvm; +u64 tb_offset;/* guest timebase - host timebase */ +ulong lpcr; +u32 arch_compat; +ulong pcr; +ulong dpdes;/* doorbell state (POWER8) */ +ulong conferring_threads; +}; +struct kvmppc_vcpu_book3s {struct kvmppc_sid_map sid_map[SID_MAP_NUM ];struct {
arch/powerpc/include/asm/kvm_host.h +0 -35
@@ -275,41 +275,6 @@ struct kvm_arch {#endif }; -/* -* Struct for a virtual core. -* Note: entry_exit_map combines a bitmap of threads that have entered -* in the bottom 8 bits and a bitmap of threads that have exited in the -* next 8 bits. This is so that we can atomically set the entry bit -* iff the exit map is 0 without taking a lock. -*/ -struct kvmppc_vcore { -int n_runnable; -int num_threads; -int entry_exit_map; -int napping_threads; -int first_vcpuid; -u16 pcpu; -u16 last_cpu; -u8 vcore_state; -u8 in_guest; -struct kvmppc_vcore *master_vcore; -struct list_head runnable_threads; -struct list_head preempt_list; -spinlock_t lock; -struct swait_queue_head wq; -spinlock_t stoltb_lock;/* protects stolen_tb and preempt_tb */ -u64 stolen_tb; -u64 preempt_tb; -struct kvm_vcpu *runner; -struct kvm *kvm; -u64 tb_offset;/* guest timebase - host timebase */ -ulong lpcr; -u32 arch_compat; -ulong pcr; -ulong dpdes;/* doorbell state (POWER8) */ -ulong conferring_threads; -}; -#define VCORE_ENTRY_MAP (vc) ((vc)->entry_exit_map & 0xff)#define VCORE_EXIT_MAP (vc) ((vc)->entry_exit_map >> 8)#define VCORE_IS_EXITING (vc) (VCORE_EXIT_MAP(vc) != 0)
Signature · 1 line
2.5.5
PATCH v3 2/5 kvm/ppc/book3s_hv: Change vcore element runnable_threads from linked-list to array
The struct kvmppc_vcore is a structure used to store various information about a virtual core for a kvm guest. The runnable_threads element of the struct provides a list of all of the currently runnable vcpus on the core (those in the KVMPPC_VCPU_RUNNABLE state). The previous implementation of this list was a linked_list. The next patch requires that the list be able to be iterated over without holding the vcore lock.
Reimplement the runnable_threads list in the kvmppc_vcore struct as an array. Implement function to iterate over valid entries in the array and update access sites accordingly.
---
Change Log:
V1 -> V3:
- Nothing
--- arch/powerpc/include/asm/kvm_book3s.h | 2 +- arch/powerpc/include/asm/kvm_host.h | 1 - arch/powerpc/kvm/book3s_hv.c | 68 +++++++++++++++++++++-------------- 3 files changed, 43 insertions(+), 28 deletions(-)
arch/powerpc/include/asm/kvm_book3s.h +1 -1
@@ -87,7 +87,7 @@ struct kvmppc_vcore {u8 vcore_state;u8 in_guest;struct kvmppc_vcore *master_vcore; -struct list_head runnable_threads; +struct kvm_vcpu *runnable_threads[MAX_SMT_THREADS ];struct list_head preempt_list;spinlock_t lock;struct swait_queue_head wq;
arch/powerpc/include/asm/kvm_host.h +0 -1
@@ -633,7 +633,6 @@ struct kvm_vcpu_arch {long pgfault_index;unsigned long pgfault_hpte[2 ]; -struct list_head run_list;struct task_struct *run_task;struct kvm_run *kvm_run;
arch/powerpc/kvm/book3s_hv.c +42 -26
177 lines not on this page · raw message
Signature · 1 line
2.5.5
PATCH v3 3/5 kvm/ppc/book3s_hv: Implement halt polling in the kvm_hv kernel module
In reply to Suraj Jitindar SinghThis patch introduces new halt polling functionality into the kvm_hv kernel module. When a vcore is idle it will poll for some period of time before scheduling itself out.
When all of the runnable vcpus on a vcore have ceded (and thus the vcore is idle) we schedule ourselves out to allow something else to run. In the event that we need to wake up very quickly (for example an interrupt arrives), we are required to wait until we get scheduled again.
Implement halt polling so that when a vcore is idle, and before scheduling ourselves, we poll for vcpus in the runnable_threads list which have pending exceptions or which leave the ceded state. If we poll successfully then we can get back into the guest very quickly without ever scheduling ourselves, otherwise we schedule ourselves out as before.
Testing of this patch with a TCP round robin test between two guests with virtio network interfaces has found a decrease in round trip time of ~15us on average. A performance gain is only seen when going out of and back into the guest often and quickly, otherwise there is no net benefit from the polling. The polling interval is adjusted such that when we are often scheduled out for long periods of time it is reduced, and when we often poll successfully it is increased. The rate at which the polling interval increases or decreases, and the maximum polling interval, can be set through module parameters.
Based on the implementation in the generic kvm module by Wanpeng Li and Paolo Bonzini, and on direction from Paul Mackerras.
---
Change Log:
V1 -> V3:
- Nothing
--- arch/powerpc/include/asm/kvm_book3s.h | 1 + arch/powerpc/include/asm/kvm_host.h | 1 + arch/powerpc/kvm/book3s_hv.c | 115 +++++++++++++++++++++++++++++----- arch/powerpc/kvm/trace_hv.h | 22 +++++++ 4 files changed, 125 insertions(+), 14 deletions(-)
arch/powerpc/include/asm/kvm_book3s.h +1 -0
@@ -102,6 +102,7 @@ struct kvmppc_vcore {ulong pcr;ulong dpdes;/* doorbell state (POWER8) */ ulong conferring_threads; +unsigned int halt_poll_ns; };struct kvmppc_vcpu_book3s {
arch/powerpc/include/asm/kvm_host.h +1 -0
@@ -294,6 +294,7 @@ struct kvm_arch {#define VCORE_SLEEPING 3#define VCORE_RUNNING 4#define VCORE_EXITING 5 +#define VCORE_POLLING 6/* * Struct used to manage memory for a virtual processor area
arch/powerpc/kvm/book3s_hv.c +101 -14
145 lines not on this page · raw message
arch/powerpc/kvm/trace_hv.h +22 -0
@@ -432,6 +432,28 @@ TRACE_EVENT(kvmppc_vcore_blocked, __entry->runner_vcpu, __entry->n_runnable, __entry->tgid) ); +TRACE_EVENT (kvmppc_vcore_wakeup, + TP_PROTO(int do_sleep, __u64 ns), + +TP_ARGS (do_sleep, ns), + +TP_STRUCT__entry ( + __field(__u64, ns) + __field(int, waited) +__field (pid_t, tgid) + ), + +TP_fast_assign ( + __entry->ns = ns; + __entry->waited = do_sleep; + __entry->tgid = current->tgid; + ), + +TP_printk ("%s time %lld ns, tgid=%d" , + __entry->waited ?"wait" :"poll" , + __entry->ns, __entry->tgid) +); + TRACE_EVENT(kvmppc_run_vcpu_enter, TP_PROTO(struct kvm_vcpu *vcpu),
Signature · 1 line
2.5.5