2020-03-04 11:33:16

by Maciej S. Szmigiero

[permalink] [raw]
Subject: [PATCH v2] cpuidle-haltpoll: allow force loading on hosts without the REALTIME hint

From: "Maciej S. Szmigiero" <[email protected]>

Before commit 1328edca4a14 ("cpuidle-haltpoll: Enable kvm guest polling
when dedicated physical CPUs are available") the cpuidle-haltpoll driver
could also be used in scenarios when the host does not advertise the
KVM_HINTS_REALTIME hint.

While the behavior introduced by the aforementioned commit makes sense as
the default there are cases where the old behavior is desired, for example,
when other kernel changes triggered by presence by this hint are unwanted,
for some workloads where the latency benefit from polling overweights the
loss from idle CPU capacity that otherwise would be available, or just when
running under older Qemu versions that lack this hint.

Let's provide a typical "force" module parameter that allows restoring the
old behavior.

Signed-off-by: Maciej S. Szmigiero <[email protected]>
---
drivers/cpuidle/cpuidle-haltpoll.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)

Changes from v1:
Make the module parameter description more general, don't unnecessarily
break a line in haltpoll_init().

diff --git a/drivers/cpuidle/cpuidle-haltpoll.c b/drivers/cpuidle/cpuidle-haltpoll.c
index b0ce9bc78113..db124bc1ca2c 100644
--- a/drivers/cpuidle/cpuidle-haltpoll.c
+++ b/drivers/cpuidle/cpuidle-haltpoll.c
@@ -18,6 +18,10 @@
#include <linux/kvm_para.h>
#include <linux/cpuidle_haltpoll.h>

+static bool force __read_mostly;
+module_param(force, bool, 0444);
+MODULE_PARM_DESC(force, "Load unconditionally");
+
static struct cpuidle_device __percpu *haltpoll_cpuidle_devices;
static enum cpuhp_state haltpoll_hp_state;

@@ -90,6 +94,11 @@ static void haltpoll_uninit(void)
haltpoll_cpuidle_devices = NULL;
}

+static bool haltpool_want(void)
+{
+ return kvm_para_has_hint(KVM_HINTS_REALTIME) || force;
+}
+
static int __init haltpoll_init(void)
{
int ret;
@@ -101,8 +110,7 @@ static int __init haltpoll_init(void)

cpuidle_poll_state_init(drv);

- if (!kvm_para_available() ||
- !kvm_para_has_hint(KVM_HINTS_REALTIME))
+ if (!kvm_para_available() || !haltpool_want())
return -ENODEV;

ret = cpuidle_register_driver(drv);


2020-03-12 16:36:40

by Marcelo Tosatti

[permalink] [raw]
Subject: Re: [PATCH v2] cpuidle-haltpoll: allow force loading on hosts without the REALTIME hint

On Wed, Mar 04, 2020 at 12:32:48PM +0100, Maciej S. Szmigiero wrote:
> From: "Maciej S. Szmigiero" <[email protected]>
>
> Before commit 1328edca4a14 ("cpuidle-haltpoll: Enable kvm guest polling
> when dedicated physical CPUs are available") the cpuidle-haltpoll driver
> could also be used in scenarios when the host does not advertise the
> KVM_HINTS_REALTIME hint.
>
> While the behavior introduced by the aforementioned commit makes sense as
> the default there are cases where the old behavior is desired, for example,
> when other kernel changes triggered by presence by this hint are unwanted,
> for some workloads where the latency benefit from polling overweights the
> loss from idle CPU capacity that otherwise would be available, or just when
> running under older Qemu versions that lack this hint.
>
> Let's provide a typical "force" module parameter that allows restoring the
> old behavior.
>
> Signed-off-by: Maciej S. Szmigiero <[email protected]>
> ---
> drivers/cpuidle/cpuidle-haltpoll.c | 12 ++++++++++--
> 1 file changed, 10 insertions(+), 2 deletions(-)
>
> Changes from v1:
> Make the module parameter description more general, don't unnecessarily
> break a line in haltpoll_init().
>
> diff --git a/drivers/cpuidle/cpuidle-haltpoll.c b/drivers/cpuidle/cpuidle-haltpoll.c
> index b0ce9bc78113..db124bc1ca2c 100644
> --- a/drivers/cpuidle/cpuidle-haltpoll.c
> +++ b/drivers/cpuidle/cpuidle-haltpoll.c
> @@ -18,6 +18,10 @@
> #include <linux/kvm_para.h>
> #include <linux/cpuidle_haltpoll.h>
>
> +static bool force __read_mostly;
> +module_param(force, bool, 0444);
> +MODULE_PARM_DESC(force, "Load unconditionally");
> +
> static struct cpuidle_device __percpu *haltpoll_cpuidle_devices;
> static enum cpuhp_state haltpoll_hp_state;
>
> @@ -90,6 +94,11 @@ static void haltpoll_uninit(void)
> haltpoll_cpuidle_devices = NULL;
> }
>
> +static bool haltpool_want(void)
> +{
> + return kvm_para_has_hint(KVM_HINTS_REALTIME) || force;
> +}
> +
> static int __init haltpoll_init(void)
> {
> int ret;
> @@ -101,8 +110,7 @@ static int __init haltpoll_init(void)
>
> cpuidle_poll_state_init(drv);
>
> - if (!kvm_para_available() ||
> - !kvm_para_has_hint(KVM_HINTS_REALTIME))
> + if (!kvm_para_available() || !haltpool_want())
> return -ENODEV;
>
> ret = cpuidle_register_driver(drv);

Signed-off-by: Marcelo Tosatti <[email protected]>

2020-03-13 17:51:30

by Rafael J. Wysocki

[permalink] [raw]
Subject: Re: [PATCH v2] cpuidle-haltpoll: allow force loading on hosts without the REALTIME hint

On Thu, Mar 12, 2020 at 5:36 PM Marcelo Tosatti <[email protected]> wrote:
>
> On Wed, Mar 04, 2020 at 12:32:48PM +0100, Maciej S. Szmigiero wrote:
> > From: "Maciej S. Szmigiero" <[email protected]>
> >
> > Before commit 1328edca4a14 ("cpuidle-haltpoll: Enable kvm guest polling
> > when dedicated physical CPUs are available") the cpuidle-haltpoll driver
> > could also be used in scenarios when the host does not advertise the
> > KVM_HINTS_REALTIME hint.
> >
> > While the behavior introduced by the aforementioned commit makes sense as
> > the default there are cases where the old behavior is desired, for example,
> > when other kernel changes triggered by presence by this hint are unwanted,
> > for some workloads where the latency benefit from polling overweights the
> > loss from idle CPU capacity that otherwise would be available, or just when
> > running under older Qemu versions that lack this hint.
> >
> > Let's provide a typical "force" module parameter that allows restoring the
> > old behavior.
> >
> > Signed-off-by: Maciej S. Szmigiero <[email protected]>
> > ---
> > drivers/cpuidle/cpuidle-haltpoll.c | 12 ++++++++++--
> > 1 file changed, 10 insertions(+), 2 deletions(-)
> >
> > Changes from v1:
> > Make the module parameter description more general, don't unnecessarily
> > break a line in haltpoll_init().
> >
> > diff --git a/drivers/cpuidle/cpuidle-haltpoll.c b/drivers/cpuidle/cpuidle-haltpoll.c
> > index b0ce9bc78113..db124bc1ca2c 100644
> > --- a/drivers/cpuidle/cpuidle-haltpoll.c
> > +++ b/drivers/cpuidle/cpuidle-haltpoll.c
> > @@ -18,6 +18,10 @@
> > #include <linux/kvm_para.h>
> > #include <linux/cpuidle_haltpoll.h>
> >
> > +static bool force __read_mostly;
> > +module_param(force, bool, 0444);
> > +MODULE_PARM_DESC(force, "Load unconditionally");
> > +
> > static struct cpuidle_device __percpu *haltpoll_cpuidle_devices;
> > static enum cpuhp_state haltpoll_hp_state;
> >
> > @@ -90,6 +94,11 @@ static void haltpoll_uninit(void)
> > haltpoll_cpuidle_devices = NULL;
> > }
> >
> > +static bool haltpool_want(void)
> > +{
> > + return kvm_para_has_hint(KVM_HINTS_REALTIME) || force;
> > +}
> > +
> > static int __init haltpoll_init(void)
> > {
> > int ret;
> > @@ -101,8 +110,7 @@ static int __init haltpoll_init(void)
> >
> > cpuidle_poll_state_init(drv);
> >
> > - if (!kvm_para_available() ||
> > - !kvm_para_has_hint(KVM_HINTS_REALTIME))
> > + if (!kvm_para_available() || !haltpool_want())
> > return -ENODEV;
> >
> > ret = cpuidle_register_driver(drv);
>
> Signed-off-by: Marcelo Tosatti <[email protected]>

I'm taking this as a Reviewed-by, thanks!

2020-03-15 03:41:24

by Rafael J. Wysocki

[permalink] [raw]
Subject: Re: [PATCH v2] cpuidle-haltpoll: allow force loading on hosts without the REALTIME hint

On Fri, Mar 13, 2020 at 6:49 PM Rafael J. Wysocki <[email protected]> wrote:
>
> On Thu, Mar 12, 2020 at 5:36 PM Marcelo Tosatti <[email protected]> wrote:
> >
> > On Wed, Mar 04, 2020 at 12:32:48PM +0100, Maciej S. Szmigiero wrote:
> > > From: "Maciej S. Szmigiero" <[email protected]>
> > >
> > > Before commit 1328edca4a14 ("cpuidle-haltpoll: Enable kvm guest polling
> > > when dedicated physical CPUs are available") the cpuidle-haltpoll driver
> > > could also be used in scenarios when the host does not advertise the
> > > KVM_HINTS_REALTIME hint.
> > >
> > > While the behavior introduced by the aforementioned commit makes sense as
> > > the default there are cases where the old behavior is desired, for example,
> > > when other kernel changes triggered by presence by this hint are unwanted,
> > > for some workloads where the latency benefit from polling overweights the
> > > loss from idle CPU capacity that otherwise would be available, or just when
> > > running under older Qemu versions that lack this hint.
> > >
> > > Let's provide a typical "force" module parameter that allows restoring the
> > > old behavior.
> > >
> > > Signed-off-by: Maciej S. Szmigiero <[email protected]>
> > > ---
> > > drivers/cpuidle/cpuidle-haltpoll.c | 12 ++++++++++--
> > > 1 file changed, 10 insertions(+), 2 deletions(-)
> > >
> > > Changes from v1:
> > > Make the module parameter description more general, don't unnecessarily
> > > break a line in haltpoll_init().
> > >
> > > diff --git a/drivers/cpuidle/cpuidle-haltpoll.c b/drivers/cpuidle/cpuidle-haltpoll.c
> > > index b0ce9bc78113..db124bc1ca2c 100644
> > > --- a/drivers/cpuidle/cpuidle-haltpoll.c
> > > +++ b/drivers/cpuidle/cpuidle-haltpoll.c
> > > @@ -18,6 +18,10 @@
> > > #include <linux/kvm_para.h>
> > > #include <linux/cpuidle_haltpoll.h>
> > >
> > > +static bool force __read_mostly;
> > > +module_param(force, bool, 0444);
> > > +MODULE_PARM_DESC(force, "Load unconditionally");
> > > +
> > > static struct cpuidle_device __percpu *haltpoll_cpuidle_devices;
> > > static enum cpuhp_state haltpoll_hp_state;
> > >
> > > @@ -90,6 +94,11 @@ static void haltpoll_uninit(void)
> > > haltpoll_cpuidle_devices = NULL;
> > > }
> > >
> > > +static bool haltpool_want(void)
> > > +{
> > > + return kvm_para_has_hint(KVM_HINTS_REALTIME) || force;
> > > +}
> > > +
> > > static int __init haltpoll_init(void)
> > > {
> > > int ret;
> > > @@ -101,8 +110,7 @@ static int __init haltpoll_init(void)
> > >
> > > cpuidle_poll_state_init(drv);
> > >
> > > - if (!kvm_para_available() ||
> > > - !kvm_para_has_hint(KVM_HINTS_REALTIME))
> > > + if (!kvm_para_available() || !haltpool_want())
> > > return -ENODEV;
> > >
> > > ret = cpuidle_register_driver(drv);
> >
> > Signed-off-by: Marcelo Tosatti <[email protected]>
>
> I'm taking this as a Reviewed-by, thanks!

Patch applied as 5.7 material, thanks!