Nowadays, when running powerKVM(book3s, hv mode), we should make the secondary hwthread
offline. Which means that if we run misc tsks other than dedicated KVM (e.g mix java and KVM),
we will lose the compute power of the secondary hwthread on host env.
This series aim to make the powerpc adaptive to the misc tsks on host.
( This series is just a sketch, with some broken patch. Sorry to bring up it in a hurry,
I am afraid that I am on the wrong direction too far. So I hope I can get some advice and feedback
in advance. I will go on the work on the "place holder" patch if my idea is reasonable.
Please consider the code as the explaining of my idea.
)
The internal:
-1.To enter guest, the primary hwthread schedule stopper func on the secondary to bring them into NAP mode.
The proto will be:
cpu1 cpuX
stop_cpus_async()
bring cpuX to a special state
signal flag and trapped
check for flag
set up guest env and ipi cpuX
-2.When exit to host, the secondary hardcode to jmp back to the stopper func, i.e back to host.
Drawbacks that I can think so far:
-1. increase the sched interval on secondary but the schduler do NOT know it.(can it cause problem?)
-2. lose some presice of hrtime on secondary hwthread for host.(To avoid the primary
has too small time slice, we need to impose a threshold,so we may lose the presice)
Any suggestion? Thanks!
Liu Ping Fan (11):
sched: introduce sys_cpumask in tsk to adapt asymmetric system
powerpc: kvm: ensure vcpu-thread run only on primary hwthread
powerpc: kvm: add interface to control kvm function on a core
powerpc: kvm: introduce a kthread on primary thread to anti tickless
sched: introduce stop_cpus_async() to schedule special tsk on cpu
powerpc: kvm: introduce online in paca to indicate whether cpu is
needed by host
powerpc: kvm: the stopper func to cease secondary hwthread
powerpc: kvm: add a flag in vcore to sync primary with secondry
hwthread
powerpc: kvm: handle time base on secondary hwthread
powerpc: kvm: on_primary_thread() force the secondary threads into NAP
mode
powerpc: kvm: Kconfig add an option for enabling secondary hwthread
arch/powerpc/include/asm/kvm_host.h | 6 ++++
arch/powerpc/include/asm/paca.h | 3 ++
arch/powerpc/kernel/asm-offsets.c | 6 ++++
arch/powerpc/kernel/smp.c | 3 ++
arch/powerpc/kernel/sysfs.c | 41 ++++++++++++++++++++++
arch/powerpc/kvm/Kconfig | 4 +++
arch/powerpc/kvm/book3s_hv.c | 39 +++++++++++++++++++++
arch/powerpc/kvm/book3s_hv_rmhandlers.S | 61 +++++++++++++++++++++++++++++++++
arch/powerpc/sysdev/xics/xics-common.c | 12 +++++++
include/linux/init_task.h | 1 +
include/linux/sched.h | 6 ++++
include/linux/stop_machine.h | 2 ++
kernel/sched/core.c | 10 ++++--
kernel/stop_machine.c | 25 +++++++++++---
14 files changed, 212 insertions(+), 7 deletions(-)
--
1.8.3.1
Some system such as powerpc, some tsk (vcpu thread) can only run on
the dedicated cpu. Since we adapt some asymmetric method to monitor the
whole physical cpu. (powerKVM only allows the primary hwthread to
set up runtime env for the secondary when entering guest).
Nowadays, powerKVM run with all the secondary hwthread offline to ensure
the vcpu threads only run on the primary thread. But we plan to keep all
cpus online when running powerKVM to give more power when switching back
to host, so introduce sys_allowed cpumask to reflect the cpuset which
the vcpu thread can run on.
Signed-off-by: Liu Ping Fan <redacted>
---
include/linux/init_task.h | 1 +
include/linux/sched.h | 6 ++++++
kernel/sched/core.c | 10 ++++++++--
3 files changed, 15 insertions(+), 2 deletions(-)
@@ -1260,7 +1260,10 @@ struct task_struct {unsignedintpolicy;intnr_cpus_allowed;+/* Anded user and sys_allowed */cpumask_tcpus_allowed;+/* due to the feature of asymmetric, some tsk can only run on such cpu */+cpumask_tsys_allowed;#ifdef CONFIG_PREEMPT_RCUintrcu_read_lock_nesting;
When vcpu thread runs at the first time, it will ensure to stick
to the primary thread.
Signed-off-by: Liu Ping Fan <redacted>
---
arch/powerpc/include/asm/kvm_host.h | 3 +++
arch/powerpc/kvm/book3s_hv.c | 17 +++++++++++++++++
2 files changed, 20 insertions(+)
When kvm is enabled on a core, we migrate all external irq to primary
thread. Since currently, the kvmirq logic is handled by the primary
hwthread.
Todo: this patch lacks re-enable of irqbalance when kvm is disable on
the core
Signed-off-by: Liu Ping Fan <redacted>
---
arch/powerpc/kernel/sysfs.c | 39 ++++++++++++++++++++++++++++++++++
arch/powerpc/sysdev/xics/xics-common.c | 12 +++++++++++
2 files changed, 51 insertions(+)
@@ -258,6 +258,18 @@ unlock:raw_spin_unlock_irqrestore(&desc->lock,flags);}}++intxics_migrate_irqs_away_secondary(void*data)+{+intcpu=smp_processor_id();+if(cpu%thread_per_core!=0){+WARN(condition,format...);+return0;+}+/* In fact, if we can migrate the primary, it will be more fine */+xics_migrate_irqs_away();+return0;+}#endif /* CONFIG_HOTPLUG_CPU */#ifdef CONFIG_SMP
(This patch is a place holder.)
If there is only one vcpu thread is ready(the other vcpu thread can
wait for it to execute), the primary thread can enter tickless mode,
which causes the primary keeps running, so the secondary has no
opportunity to exit to host, even they have other tsk on them.
Introduce a kthread (anti_tickless) on primary, so when there is only
one vcpu thread on primary, the secondary can resort to anti_tickless
to keep the primary out of tickless mode.
(I thought that anti_tickless thread can goto NAP, so we can let the
secondary run).
Signed-off-by: Liu Ping Fan <redacted>
---
arch/powerpc/kernel/sysfs.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
The proto will be:
cpu1 cpuX
stop_cpus_async()
bring cpuX to a special state
signal flag and trapped
check for flag
The func help powerpc to reuse the scheme of cpu_stopper_task
to force the secondary hwthread goto NAP state, in which state,
cpu will not run any longer until the master cpu tells them to
go.
Signed-off-by: Liu Ping Fan <redacted>
---
include/linux/stop_machine.h | 2 ++
kernel/stop_machine.c | 25 ++++++++++++++++++++-----
2 files changed, 22 insertions(+), 5 deletions(-)
@@ -398,7 +400,20 @@ int stop_cpus(const struct cpumask *cpumask, cpu_stop_fn_t fn, void *arg)/* static works are used, process one request at a time */mutex_lock(&stop_cpus_mutex);-ret=__stop_cpus(cpumask,fn,arg);+ret=__stop_cpus(cpumask,fn,arg,true);+mutex_unlock(&stop_cpus_mutex);+returnret;+}++/* similar to stop_cpus(), but not wait for the ack. */+intstop_cpus_async(conststructcpumask*cpumask,cpu_stop_fn_tfn,+void*arg)+{+intret;++/* static works are used, process one request at a time */+mutex_lock(&stop_cpus_mutex);+ret=__stop_cpus(cpumask,fn,arg,false);mutex_unlock(&stop_cpus_mutex);returnret;}
@@ -428,7 +443,7 @@ int try_stop_cpus(const struct cpumask *cpumask, cpu_stop_fn_t fn, void *arg)/* static works are used, process one request at a time */if(!mutex_trylock(&stop_cpus_mutex))return-EAGAIN;-ret=__stop_cpus(cpumask,fn,arg);+ret=__stop_cpus(cpumask,fn,arg,true);mutex_unlock(&stop_cpus_mutex);returnret;}
Nowadays, powerKVM runs with secondary hwthread offline. Although
we can make all secondary hwthread online later, we still preserve
this behavior for dedicated KVM env. Achieve this by setting
paca->online as false.
Signed-off-by: Liu Ping Fan <redacted>
---
arch/powerpc/include/asm/paca.h | 3 +++
arch/powerpc/kernel/asm-offsets.c | 3 +++
arch/powerpc/kernel/smp.c | 3 +++
arch/powerpc/kvm/book3s_hv_rmhandlers.S | 12 ++++++++++++
4 files changed, 21 insertions(+)
@@ -84,6 +84,9 @@ struct paca_struct {u8cpu_start;/* At startup, processor spins until *//* this becomes non-zero. */u8kexec_state;/* set when kexec down has irqs off */+#ifdef CONFIG_KVMPPC_ENABLE_SECONDARY+u8online;+#endif#ifdef CONFIG_PPC_STD_MMU_64structslb_shadow*slb_shadow_ptr;structdtl_entry*dispatch_log;
To enter guest, primary hwtherad schedules the stopper func on
secondary threads and force them into NAP mode.
When exit to host,secondary threads hardcode to restore the stack,
then switch back to the stopper func, i.e host.
Signed-off-by: Liu Ping Fan <redacted>
---
arch/powerpc/kvm/book3s_hv.c | 15 +++++++++++++++
arch/powerpc/kvm/book3s_hv_rmhandlers.S | 34 +++++++++++++++++++++++++++++++++
2 files changed, 49 insertions(+)
The secondary thread can only jump back to host until primary has set
up the env. Add host_ready field in kvm_vcore to sync this action.
Signed-off-by: Liu Ping Fan <redacted>
---
arch/powerpc/include/asm/kvm_host.h | 3 +++
arch/powerpc/kernel/asm-offsets.c | 3 +++
arch/powerpc/kvm/book3s_hv_rmhandlers.S | 11 ++++++++++-
3 files changed, 16 insertions(+), 1 deletion(-)
(This is a place holder patch.)
We need to store the time base for host on secondary hwthread.
Later when switching back, we need to reprogram it with elapse
time.
Signed-off-by: Liu Ping Fan <redacted>
---
arch/powerpc/kvm/book3s_hv_rmhandlers.S | 6 ++++++
1 file changed, 6 insertions(+)
The primary hwthread ceases the scheduler of secondary hwthread by
bringing them into NAP. Then, the secondary is ready for guest.
Signed-off-by: Liu Ping Fan <redacted>
---
arch/powerpc/kvm/book3s_hv.c | 7 +++++++
1 file changed, 7 insertions(+)
@@ -1593,15 +1593,22 @@ static int on_primary_thread(void){intcpu=smp_processor_id();intthr;+structcpumaskmsk;/* Are we on a primary subcore? */if(cpu_thread_in_subcore(cpu))return0;thr=0;+#ifdef KVMPPC_ENABLE_SECONDARY+while(++thr<threads_per_subcore)+cpumask_set_cpu(thr,&msk);+stop_cpus_async(&msk,kvmppc_secondary_stopper,NULL);+#elsewhile(++thr<threads_per_subcore)if(cpu_online(cpu+thr))return0;+#endif/* Grab all hw threads so they can't go into the kernel */for(thr=1;thr<threads_per_subcore;++thr){
@@ -93,6 +93,10 @@ config KVM_BOOK3S_64_HVIfunsure,sayN.+configKVMPPC_ENABLE_SECONDARY+tristate"KVM support for running on secondary hwthread in host"+depends onKVM_BOOK3S_64_HV+configKVM_BOOK3S_64_PRtristate"KVM support without using hypervisor mode in host"depends onKVM_BOOK3S_64
From: Preeti U Murthy <hidden> Date: 2014-10-22 07:13:28
Hi Liu,
On 10/17/2014 12:59 AM, kernelfans@gmail.com wrote:
quoted hunk
To enter guest, primary hwtherad schedules the stopper func on
secondary threads and force them into NAP mode.
When exit to host,secondary threads hardcode to restore the stack,
then switch back to the stopper func, i.e host.
Signed-off-by: Liu Ping Fan <redacted>
---
arch/powerpc/kvm/book3s_hv.c | 15 +++++++++++++++
arch/powerpc/kvm/book3s_hv_rmhandlers.S | 34 +++++++++++++++++++++++++++++++++
2 files changed, 49 insertions(+)
This does not look right. Let me explain.
We can get hypervisor decrementer interrupts on the secondary threads
since they are online. And we would ideally want to handle them. They
could be scheduler tick interrupts or some timer queued on that thread
could have fired.
If it is a scheduler tick, we would want to exit to host to schedule the
next task if the timeslice of the vcpu running on the secondary thread
is over.
To the best of my understanding, this is what I can tell happens when we
get a hypervisor decrementer interrupt in the guest. We call all threads
in the core to exit to the kernel. The secondaries now return to the
code in idle_power7.S where the wakeup from idle path takes effect. Then
we do an rfid which lands after the nap code above. And we spin.
From your above code you seem to be indicating that you do not want the
secondary threads to exit to the kernel once they are made to run guest
for the first time. Is this right? Or am I missing something ?
Moreover the changelog in [patch 10/11] says that you cease the
scheduler. This pushes me to think that you do not expect the scheduler
to run on the secondary threads ever again after you have launched the
guest. This does not look right to me.
Regards
Preeti U Murthy
From: Preeti U Murthy <hidden> Date: 2014-10-27 04:05:22
Hi Liu,
On 10/17/2014 12:59 AM, kernelfans@gmail.com wrote:
When kvm is enabled on a core, we migrate all external irq to primary
thread. Since currently, the kvmirq logic is handled by the primary
hwthread.
Todo: this patch lacks re-enable of irqbalance when kvm is disable on
the core
Why is a sysfs file introduced to trigger irq migration? Why is it not
done during kvm module insert ? And similarly spread interrupts when the
module is removed? Isn't this a saner way ?
quoted hunk
Signed-off-by: Liu Ping Fan <redacted>
---
arch/powerpc/kernel/sysfs.c | 39 ++++++++++++++++++++++++++++++++++
arch/powerpc/sysdev/xics/xics-common.c | 12 +++++++++++
2 files changed, 51 insertions(+)
@@ -258,6 +258,18 @@ unlock:raw_spin_unlock_irqrestore(&desc->lock,flags);}}++intxics_migrate_irqs_away_secondary(void*data)+{+intcpu=smp_processor_id();+if(cpu%thread_per_core!=0){+WARN(condition,format...);+return0;+}+/* In fact, if we can migrate the primary, it will be more fine */+xics_migrate_irqs_away();
Isn't the aim of the patch to migrate irqs away from the secondary onto
the primary? But from above it looks like we are returning when we find
out that we are secondary threads, isn't it?
quoted hunk
+ return 0;+} #endif /* CONFIG_HOTPLUG_CPU */
Note that xics_migrate_irqs_away() is defined under CONFIG_CPU_HOTPLUG.
But we will need this option on PowerKVM even when hotplug is not
configured in.
Regards
Preeti U Murthy
From: Preeti U Murthy <hidden> Date: 2014-10-27 04:45:22
On 10/17/2014 12:59 AM, kernelfans@gmail.com wrote:
(This patch is a place holder.)
If there is only one vcpu thread is ready(the other vcpu thread can
wait for it to execute), the primary thread can enter tickless mode,
We do not configure NOHZ_FULL to y by default. Hence no thread would
enter tickless mode.
which causes the primary keeps running, so the secondary has no
opportunity to exit to host, even they have other tsk on them.
The secondary threads can still get scheduling ticks. The decrementer of
the secondary threads is still active. So as long as secondary threads
are busy, scheduling ticks will fire and try to schedule a new task on them.
Regards
Preeti U Murthy
quoted hunk
Introduce a kthread (anti_tickless) on primary, so when there is only
one vcpu thread on primary, the secondary can resort to anti_tickless
to keep the primary out of tickless mode.
(I thought that anti_tickless thread can goto NAP, so we can let the
secondary run).
Signed-off-by: Liu Ping Fan <redacted>
---
arch/powerpc/kernel/sysfs.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
From: Preeti U Murthy <hidden> Date: 2014-10-27 05:32:36
Hi Liu,
On 10/17/2014 12:59 AM, kernelfans@gmail.com wrote:
quoted hunk
Nowadays, powerKVM runs with secondary hwthread offline. Although
we can make all secondary hwthread online later, we still preserve
this behavior for dedicated KVM env. Achieve this by setting
paca->online as false.
Signed-off-by: Liu Ping Fan <redacted>
---
arch/powerpc/include/asm/paca.h | 3 +++
arch/powerpc/kernel/asm-offsets.c | 3 +++
arch/powerpc/kernel/smp.c | 3 +++
arch/powerpc/kvm/book3s_hv_rmhandlers.S | 12 ++++++++++++
4 files changed, 21 insertions(+)
@@ -84,6 +84,9 @@ struct paca_struct {u8cpu_start;/* At startup, processor spins until *//* this becomes non-zero. */u8kexec_state;/* set when kexec down has irqs off */+#ifdef CONFIG_KVMPPC_ENABLE_SECONDARY+u8online;+#endif#ifdef CONFIG_PPC_STD_MMU_64structslb_shadow*slb_shadow_ptr;structdtl_entry*dispatch_log;
Uh? When we have no vcpu to run, we loop here instead of doing a nap?
What are we achieving?
If I understand the intention of the patch well, we are looking to
provide a knob whereby the host can indicate if it needs the secondaries
at all.
Today the host does boot with all threads online. There are some init
scripts which take the secondaries down. So today the host does not have
a say in preventing this, compile time or runtime. So lets see how we
can switch between the two behaviors if we don't have the init script,
which looks like a saner thing to do.
We should set the paca->online flag to false by default. If
KVM_PPC_ENABLE_SECONDARY is configured, we need to set this flag to
true. So at compile time, we resolve the flag.
While booting, we look at the flag and decide whether to get the
secondaries online. So we get the current behavior if we have not
configured KVM_PPC_ENABLE_SECONDARY. Will this achieve the purpose of
this patch?
Regards
Preeti U Murthy
From: Preeti U Murthy <hidden> Date: 2014-10-27 06:07:55
On 10/17/2014 12:59 AM, kernelfans@gmail.com wrote:
quoted hunk
To enter guest, primary hwtherad schedules the stopper func on
secondary threads and force them into NAP mode.
When exit to host,secondary threads hardcode to restore the stack,
then switch back to the stopper func, i.e host.
Signed-off-by: Liu Ping Fan <redacted>
---
arch/powerpc/kvm/book3s_hv.c | 15 +++++++++++++++
arch/powerpc/kvm/book3s_hv_rmhandlers.S | 34 +++++++++++++++++++++++++++++++++
2 files changed, 49 insertions(+)
I see a fundamental issues with this design. Note that the secondaries
are still capable of getting IPIs, timer interrupts and scheduler
interrupts in nap. Scheduling ticks do not get stopped just because we
nap. So the primary thread cannot assume that the secondaries will wait
in nap until it has switched to guest context. There will definitely be
race conditions here between primary switching context and the secondary
handling some interrupt in virtual mode.
So your answer to above could be that we are preventing the secondaries
from entering the kernel by setting the HSTATE_HWTHREAD_REQ above. But
we cannot do this because the secondary thread is as alive and kicking
as the primary thread on the host. There can be hrtimers queued, there
may be an IPI from a thread in another core. We cannot ignore handling
them while we wait for the primary thread to switch context.
There is also a bug as far as I can see with having a b . after nap. I
mentioned that in one of my earlier replies to this patch.
Regards
Preeti U Murthy
quoted hunk
++/* enter with vmode */+kvmppc_secondary_stopper_exit:+ /* fixme, restore the stack which we store on lpaca */++ ld r0, 112+PPC_LR_STKOFF(r1)+ addi r1, r1, 112+ mtlr r0+ blr #endif /******************************************************************************
From: Preeti U Murthy <hidden> Date: 2014-10-27 06:28:40
On 10/17/2014 12:59 AM, kernelfans@gmail.com wrote:
The secondary thread can only jump back to host until primary has set
up the env. Add host_ready field in kvm_vcore to sync this action.
Do we need to do this? We already synchronize among the sibling threads
when there is a need to enter the host. Today too, the secondaries may
require host kernel's intervention and there is already code in which
under such circumstances, the secondaries set the HDEC of the sibling
threads and wait for the primary to switch context. I see the code under
secondary_too_late. Besides this, do we need anything additional to
synchronize the exit to host path? IIUC, we will need synchronization
only in the entry to guest path.
And of course there will be more guest exits now since the secondaries
are as alive in the host as the primary and will have scheduling
interrupts atleast, forcing them to exit to host. This cannot be
trivially solved unless we can isolate these threads in some way.
Regards
Preeti U Murthy
From: Preeti U Murthy <hidden> Date: 2014-10-27 06:41:20
On 10/17/2014 12:59 AM, kernelfans@gmail.com wrote:
quoted hunk
(This is a place holder patch.)
We need to store the time base for host on secondary hwthread.
Later when switching back, we need to reprogram it with elapse
time.
Signed-off-by: Liu Ping Fan <redacted>
---
arch/powerpc/kvm/book3s_hv_rmhandlers.S | 6 ++++++
1 file changed, 6 insertions(+)
This can lead to serious consequences. First of all, even if we set the
decrementer(not tb) to MAX, it is bound to fire after 4s. That is the
maximum time till which you can keep off the decrementer from firing.
In the hotplug path, the offline cpus nap and their decrementers are
programmed to fire at MAX too. But the difference is that we clear the
LPCR_PECE1 wakeup bit which prevents cpus from waking up on a
decrementer interrupt.
We cannot afford to do this here though because there are other tasks on
the secondary threads' runqueue. They need to be scheduled in.
There are also timers besides the tick_sched one, which can be queued on
these secondary threads. These patches have not taken care to migrate
timers or tasks before entering guest as far as I observed. Hence we
cannot just turn off time base like this and expect to handle the above
mentioned events the next time the primary thread decides to exit to the
host.
Regards
Preeti U Murthy
quoted hunk
+ /* prevent us to enter kernel */ li r0, 1 stb r0, HSTATE_HWTHREAD_REQ(r13)
@@ -382,6 +384,10 @@ _GLOBAL_TOC(kvmppc_secondary_stopper_enter) /* enter with vmode */ kvmppc_secondary_stopper_exit:+ /* fixme: restore the tb, with the orig val plus time elapse+ * so we can fire the hrtimer as soon as possible+ */+ /* fixme, restore the stack which we store on lpaca */ ld r0, 112+PPC_LR_STKOFF(r1)
@@ -93,6 +93,10 @@ config KVM_BOOK3S_64_HVIfunsure,sayN.+configKVMPPC_ENABLE_SECONDARY+tristate"KVM support for running on secondary hwthread in host"+depends onKVM_BOOK3S_64_HV
This patch is required ontop of all the rest :) The top patches won't
compile without this one. Every patch in the patchset should be able to
compile successfully without the aid of the patches that come after it.
Regards
Preeti U Murthy
Some system such as powerpc, some tsk (vcpu thread) can only run on
the dedicated cpu. Since we adapt some asymmetric method to monitor the
whole physical cpu. (powerKVM only allows the primary hwthread to
set up runtime env for the secondary when entering guest).
Nowadays, powerKVM run with all the secondary hwthread offline to ensure
the vcpu threads only run on the primary thread. But we plan to keep all
cpus online when running powerKVM to give more power when switching back
to host, so introduce sys_allowed cpumask to reflect the cpuset which
the vcpu thread can run on.
Signed-off-by: Liu Ping Fan <redacted>
---
include/linux/init_task.h | 1 +
include/linux/sched.h | 6 ++++++
kernel/sched/core.c | 10 ++++++++--
3 files changed, 15 insertions(+), 2 deletions(-)
@@ -1260,7 +1260,10 @@ struct task_struct {unsignedintpolicy;intnr_cpus_allowed;+/* Anded user and sys_allowed */cpumask_tcpus_allowed;+/* due to the feature of asymmetric, some tsk can only run on such cpu */+cpumask_tsys_allowed;#ifdef CONFIG_PREEMPT_RCUintrcu_read_lock_nesting;
When vcpu thread runs at the first time, it will ensure to stick
to the primary thread.
Signed-off-by: Liu Ping Fan <redacted>
---
arch/powerpc/include/asm/kvm_host.h | 3 +++
arch/powerpc/kvm/book3s_hv.c | 17 +++++++++++++++++
2 files changed, 20 insertions(+)
Nit: something like cpumask_set seems to be better than cpu_selected
+ for (cpu = 0; cpu < NR_CPUS; cpu+=threads_per_core) {
+ cpumask_set_cpu(cpu, &p->sys_allowed);
Dont we need to reset the cpumask first before we set
the cpumask here?
+ }
+ if (cpu%threads_per_core != 0) {
At this time, cpu should be NR_CPUS and most times it should be a
multiple of threads_per_core. Unfortunately there wont be a cpu with
cpu number NR_CPUS.
When kvm is enabled on a core, we migrate all external irq to primary
thread. Since currently, the kvmirq logic is handled by the primary
hwthread.
Todo: this patch lacks re-enable of irqbalance when kvm is disable on
the core
Signed-off-by: Liu Ping Fan <redacted>
---
arch/powerpc/kernel/sysfs.c | 39 ++++++++++++++++++++++++++++++++++
arch/powerpc/sysdev/xics/xics-common.c | 12 +++++++++++
2 files changed, 51 insertions(+)
Some system such as powerpc, some tsk (vcpu thread) can only run on
the dedicated cpu. Since we adapt some asymmetric method to monitor the
whole physical cpu. (powerKVM only allows the primary hwthread to
set up runtime env for the secondary when entering guest).
Nowadays, powerKVM run with all the secondary hwthread offline to ensure
the vcpu threads only run on the primary thread. But we plan to keep all
cpus online when running powerKVM to give more power when switching back
to host, so introduce sys_allowed cpumask to reflect the cpuset which
the vcpu thread can run on.
Signed-off-by: Liu Ping Fan <redacted>
---
include/linux/init_task.h | 1 +
include/linux/sched.h | 6 ++++++
kernel/sched/core.c | 10 ++++++++--
3 files changed, 15 insertions(+), 2 deletions(-)
@@ -1260,7 +1260,10 @@ struct task_struct {unsignedintpolicy;intnr_cpus_allowed;+/* Anded user and sys_allowed */cpumask_tcpus_allowed;+/* due to the feature of asymmetric, some tsk can only run on such cpu */+cpumask_tsys_allowed;#ifdef CONFIG_PREEMPT_RCUintrcu_read_lock_nesting;
From: Liu ping fan <hidden> Date: 2014-11-18 05:17:20
On Mon, Oct 27, 2014 at 12:04 PM, Preeti U Murthy
[off-list ref] wrote:
Hi Liu,
On 10/17/2014 12:59 AM, kernelfans@gmail.com wrote:
quoted
When kvm is enabled on a core, we migrate all external irq to primary
thread. Since currently, the kvmirq logic is handled by the primary
hwthread.
Todo: this patch lacks re-enable of irqbalance when kvm is disable on
the core
Why is a sysfs file introduced to trigger irq migration? Why is it not
done during kvm module insert ? And similarly spread interrupts when the
module is removed? Isn't this a saner way ?
Consider the scene: coreA and coreB, we want to enable KVM on coreA,
while keeping coreB unchanged.
In fact, I try to acheive something un-symmetric on the platform. Do
you think it is an justification?
quoted
Signed-off-by: Liu Ping Fan <redacted>
---
arch/powerpc/kernel/sysfs.c | 39 ++++++++++++++++++++++++++++++++++
arch/powerpc/sysdev/xics/xics-common.c | 12 +++++++++++
2 files changed, 51 insertions(+)
@@ -258,6 +258,18 @@ unlock:raw_spin_unlock_irqrestore(&desc->lock,flags);}}++intxics_migrate_irqs_away_secondary(void*data)+{+intcpu=smp_processor_id();+if(cpu%thread_per_core!=0){+WARN(condition,format...);+return0;+}+/* In fact, if we can migrate the primary, it will be more fine */+();
Isn't the aim of the patch to migrate irqs away from the secondary onto
the primary? But from above it looks like we are returning when we find
out that we are secondary threads, isn't it?
Yes, will fix in next version.
quoted
+ return 0;+} #endif /* CONFIG_HOTPLUG_CPU */
Note that xics_migrate_irqs_away() is defined under CONFIG_CPU_HOTPLUG.
But we will need this option on PowerKVM even when hotplug is not
configured in.
Yes, will fix the dependency in next version
Thx,
Fan
From: Liu ping fan <hidden> Date: 2014-11-18 05:24:44
On Mon, Oct 27, 2014 at 12:45 PM, Preeti U Murthy
[off-list ref] wrote:
On 10/17/2014 12:59 AM, kernelfans@gmail.com wrote:
quoted
(This patch is a place holder.)
If there is only one vcpu thread is ready(the other vcpu thread can
wait for it to execute), the primary thread can enter tickless mode,
We do not configure NOHZ_FULL to y by default. Hence no thread would
enter tickless mode.
But NOHZ_FULL can be chosen by user, and we should survive from it :)
quoted
which causes the primary keeps running, so the secondary has no
opportunity to exit to host, even they have other tsk on them.
The secondary threads can still get scheduling ticks. The decrementer of
the secondary threads is still active. So as long as secondary threads
are busy, scheduling ticks will fire and try to schedule a new task on them.
No. As my original thought, after enable KVM on core, the HDEC on
secondary is disabled, otherwise the host exit will be too frequent.
Any suggestion?
Thx,
Fan
Regards
Preeti U Murthy
quoted
Introduce a kthread (anti_tickless) on primary, so when there is only
one vcpu thread on primary, the secondary can resort to anti_tickless
to keep the primary out of tickless mode.
(I thought that anti_tickless thread can goto NAP, so we can let the
secondary run).
Signed-off-by: Liu Ping Fan <redacted>
---
arch/powerpc/kernel/sysfs.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
From: Liu ping fan <hidden> Date: 2014-11-18 05:29:14
On Mon, Oct 27, 2014 at 1:32 PM, Preeti U Murthy
[off-list ref] wrote:
Hi Liu,
On 10/17/2014 12:59 AM, kernelfans@gmail.com wrote:
quoted
Nowadays, powerKVM runs with secondary hwthread offline. Although
we can make all secondary hwthread online later, we still preserve
this behavior for dedicated KVM env. Achieve this by setting
paca->online as false.
Signed-off-by: Liu Ping Fan <redacted>
---
arch/powerpc/include/asm/paca.h | 3 +++
arch/powerpc/kernel/asm-offsets.c | 3 +++
arch/powerpc/kernel/smp.c | 3 +++
arch/powerpc/kvm/book3s_hv_rmhandlers.S | 12 ++++++++++++
4 files changed, 21 insertions(+)
@@ -84,6 +84,9 @@ struct paca_struct {u8cpu_start;/* At startup, processor spins until *//* this becomes non-zero. */u8kexec_state;/* set when kexec down has irqs off */+#ifdef CONFIG_KVMPPC_ENABLE_SECONDARY+u8online;+#endif#ifdef CONFIG_PPC_STD_MMU_64structslb_shadow*slb_shadow_ptr;structdtl_entry*dispatch_log;
Uh? When we have no vcpu to run, we loop here instead of doing a nap?
What are we achieving?
If I understand the intention of the patch well, we are looking to
provide a knob whereby the host can indicate if it needs the secondaries
at all.
Yes, you catch it :)
Today the host does boot with all threads online. There are some init
scripts which take the secondaries down. So today the host does not have
a say in preventing this, compile time or runtime. So lets see how we
can switch between the two behaviors if we don't have the init script,
which looks like a saner thing to do.
We should set the paca->online flag to false by default. If
KVM_PPC_ENABLE_SECONDARY is configured, we need to set this flag to
true. So at compile time, we resolve the flag.
While booting, we look at the flag and decide whether to get the
secondaries online. So we get the current behavior if we have not
configured KVM_PPC_ENABLE_SECONDARY. Will this achieve the purpose of
this patch?
At boot time, KVM can not run. So we can achieve the change of the
flag by soft cpu hotplug on/off.
I think this is a more flexible way.
Thx,
Fan
From: Liu ping fan <hidden> Date: 2014-11-18 05:43:13
On Mon, Oct 27, 2014 at 2:40 PM, Preeti U Murthy
[off-list ref] wrote:
On 10/17/2014 12:59 AM, kernelfans@gmail.com wrote:
quoted
(This is a place holder patch.)
We need to store the time base for host on secondary hwthread.
Later when switching back, we need to reprogram it with elapse
time.
Signed-off-by: Liu Ping Fan <redacted>
---
arch/powerpc/kvm/book3s_hv_rmhandlers.S | 6 ++++++
1 file changed, 6 insertions(+)
This can lead to serious consequences. First of all, even if we set the
decrementer(not tb) to MAX, it is bound to fire after 4s. That is the
maximum time till which you can keep off the decrementer from firing.
In the hotplug path, the offline cpus nap and their decrementers are
programmed to fire at MAX too. But the difference is that we clear the
LPCR_PECE1 wakeup bit which prevents cpus from waking up on a
decrementer interrupt.
We cannot afford to do this here though because there are other tasks on
the secondary threads' runqueue. They need to be scheduled in.
There are also timers besides the tick_sched one, which can be queued on
these secondary threads. These patches have not taken care to migrate
timers or tasks before entering guest as far as I observed. Hence we
cannot just turn off time base like this and expect to handle the above
mentioned events the next time the primary thread decides to exit to the
host.
Yes, that is the nut in this series. My plan is to compensate the
hrtimer when the secondary exit.
But as to the scheduler on secondary, if it is ceased, what is side-effect?
Thx,
Fan
Regards
Preeti U Murthy
quoted
+ /* prevent us to enter kernel */ li r0, 1 stb r0, HSTATE_HWTHREAD_REQ(r13)
@@ -382,6 +384,10 @@ _GLOBAL_TOC(kvmppc_secondary_stopper_enter) /* enter with vmode */ kvmppc_secondary_stopper_exit:+ /* fixme: restore the tb, with the orig val plus time elapse+ * so we can fire the hrtimer as soon as possible+ */+ /* fixme, restore the stack which we store on lpaca */ ld r0, 112+PPC_LR_STKOFF(r1)
@@ -93,6 +93,10 @@ config KVM_BOOK3S_64_HVIfunsure,sayN.+configKVMPPC_ENABLE_SECONDARY+tristate"KVM support for running on secondary hwthread in host"+depends onKVM_BOOK3S_64_HV
This patch is required ontop of all the rest :) The top patches won't
compile without this one. Every patch in the patchset should be able to
compile successfully without the aid of the patches that come after it.
I think here is a conflict. If we do so, then we should make effort to
prevent the independent patch to take effect before the whole patchset
is applied.
Thx,
Fan
From: Alexander Graf <hidden> Date: 2014-11-18 17:54:45
On 16.10.14 21:29, kernelfans@gmail.com wrote:
Nowadays, when running powerKVM(book3s, hv mode), we should make the secondary hwthread
offline. Which means that if we run misc tsks other than dedicated KVM (e.g mix java and KVM),
we will lose the compute power of the secondary hwthread on host env.
I'm personally more concerned about IO threads and the likes blocking
CPUs that could do actual work.
But really, IMHO this should just get fixed in hardware. The patch set
looks like quite a good addition of complexity to an already complex
problem - which means it will definitely break :).
Couldn't we just do something as simple as partition the system into SMT
and non-SMT cores? Then the user can just say "keep 2 cores in SMT mode"
and we would refuse to run KVM threads on those.
But then again we would bounce on these threads and increase latency on
entry if we happen to get scheduled there, so it's probably not a win
either.
I really don't have a good answer, except for "POWER8 wasn't designed
for this".
Alex