From: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
To: Wanpeng Li <kernellwp@gmail.com>, Marcelo Tosatti <mtosatti@redhat.com>
Cc: kvm-devel <kvm@vger.kernel.org>,
LKML <linux-kernel@vger.kernel.org>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@kernel.org>,
Andrea Arcangeli <aarcange@redhat.com>,
Bandan Das <bsd@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>,
ankur.a.arora@oracle.com,
Boris Ostrovsky <boris.ostrovsky@oracle.com>
Subject: Re: [PATCH] sched: introduce configurable delay before entering idle
Date: Mon, 13 May 2019 07:31:37 -0400 [thread overview]
Message-ID: <D655C66D-8C52-4CE3-A00B-697735CFA51D@oracle.com> (raw)
In-Reply-To: <CANRm+Cx8zCDG6Oz1m9eukkmx_uVFYcQOdMwZrHwsQcbLm_kuPA@mail.gmail.com>
On May 13, 2019 5:20:37 AM EDT, Wanpeng Li <kernellwp@gmail.com> wrote:
>On Wed, 8 May 2019 at 02:57, Marcelo Tosatti <mtosatti@redhat.com>
>wrote:
>>
>>
>> Certain workloads perform poorly on KVM compared to baremetal
>> due to baremetal's ability to perform mwait on NEED_RESCHED
>> bit of task flags (therefore skipping the IPI).
>
>KVM supports expose mwait to the guest, if it can solve this?
>
There is a bit of problem with that. The host will see 100% CPU utilization even if the guest is idle and taking long naps..
Which depending on your dashboard can look like the machine is on fire.
CCing Ankur and Boris
>Regards,
>Wanpeng Li
>
>>
>> This patch introduces a configurable busy-wait delay before entering
>the
>> architecture delay routine, allowing wakeup IPIs to be skipped
>> (if the IPI happens in that window).
>>
>> The real-life workload which this patch improves performance
>> is SAP HANA (by 5-10%) (for which case setting idle_spin to 30
>> is sufficient).
>>
>> This patch improves the attached server.py and client.py example
>> as follows:
>>
>> Host: 31.814230202231556
>> Guest: 38.17718765199993 (83 %)
>> Guest, idle_spin=50us: 33.317709898000004 (95 %)
>> Guest, idle_spin=220us: 32.27826551499999 (98 %)
>>
>> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
>>
>> ---
>> kernel/sched/idle.c | 86
>++++++++++++++++++++++++++++++++++++++++++
>> 1 file changed, 86 insertions(+)
>>
>> diff --git a/kernel/sched/idle.c b/kernel/sched/idle.c
>> index f5516bae0c1b..bca7656a7ea0 100644
>> --- a/kernel/sched/idle.c
>> +++ b/kernel/sched/idle.c
>> @@ -216,6 +216,29 @@ static void cpuidle_idle_call(void)
>> rcu_idle_exit();
>> }
>>
>> +static unsigned int spin_before_idle_us;
>>
>> +static void do_spin_before_idle(void)
>> +{
>> + ktime_t now, end_spin;
>> +
>> + now = ktime_get();
>> + end_spin = ktime_add_ns(now, spin_before_idle_us*1000);
>> +
>> + rcu_idle_enter();
>> + local_irq_enable();
>> + stop_critical_timings();
>> +
>> + do {
>> + cpu_relax();
>> + now = ktime_get();
>> + } while (!tif_need_resched() && ktime_before(now, end_spin));
>> +
>> + start_critical_timings();
>> + rcu_idle_exit();
>> + local_irq_disable();
>> +}
>> +
>> /*
>> * Generic idle loop implementation
>> *
>> @@ -259,6 +282,8 @@ static void do_idle(void)
>> tick_nohz_idle_restart_tick();
>> cpu_idle_poll();
>> } else {
>> + if (spin_before_idle_us)
>> + do_spin_before_idle();
>> cpuidle_idle_call();
>> }
>> arch_cpu_idle_exit();
>> @@ -465,3 +490,64 @@ const struct sched_class idle_sched_class = {
>> .switched_to = switched_to_idle,
>> .update_curr = update_curr_idle,
>> };
>> +
>> +
>> +static ssize_t store_idle_spin(struct kobject *kobj,
>> + struct kobj_attribute *attr,
>> + const char *buf, size_t count)
>> +{
>> + unsigned int val;
>> +
>> + if (kstrtouint(buf, 10, &val) < 0)
>> + return -EINVAL;
>> +
>> + if (val > USEC_PER_SEC)
>> + return -EINVAL;
>> +
>> + spin_before_idle_us = val;
>> + return count;
>> +}
>> +
>> +static ssize_t show_idle_spin(struct kobject *kobj,
>> + struct kobj_attribute *attr,
>> + char *buf)
>> +{
>> + ssize_t ret;
>> +
>> + ret = sprintf(buf, "%d\n", spin_before_idle_us);
>> +
>> + return ret;
>> +}
>> +
>> +static struct kobj_attribute idle_spin_attr =
>> + __ATTR(idle_spin, 0644, show_idle_spin, store_idle_spin);
>> +
>> +static struct attribute *sched_attrs[] = {
>> + &idle_spin_attr.attr,
>> + NULL,
>> +};
>> +
>> +static const struct attribute_group sched_attr_group = {
>> + .attrs = sched_attrs,
>> +};
>> +
>> +static struct kobject *sched_kobj;
>> +
>> +static int __init sched_sysfs_init(void)
>> +{
>> + int error;
>> +
>> + sched_kobj = kobject_create_and_add("sched", kernel_kobj);
>> + if (!sched_kobj)
>> + return -ENOMEM;
>> +
>> + error = sysfs_create_group(sched_kobj, &sched_attr_group);
>> + if (error)
>> + goto err;
>> + return 0;
>> +
>> +err:
>> + kobject_put(sched_kobj);
>> + return error;
>> +}
>> +postcore_initcall(sched_sysfs_init);
next prev parent reply other threads:[~2019-05-13 11:32 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-07 18:56 Marcelo Tosatti
2019-05-07 22:15 ` Peter Zijlstra
2019-05-07 23:44 ` Marcelo Tosatti
2019-05-13 9:20 ` Wanpeng Li
2019-05-13 11:31 ` Konrad Rzeszutek Wilk [this message]
2019-05-13 11:51 ` Raslan, KarimAllah
2019-05-13 12:30 ` Boris Ostrovsky
2019-05-15 1:45 ` Wanpeng Li
2019-05-14 13:50 ` Marcelo Tosatti
2019-05-14 15:20 ` Konrad Rzeszutek Wilk
2019-05-14 17:42 ` Marcelo Tosatti
2019-05-15 1:42 ` Wanpeng Li
2019-05-15 20:26 ` Marcelo Tosatti
2019-05-15 18:42 ` Ankur Arora
2019-05-15 20:43 ` Marcelo Tosatti
2019-05-17 4:32 ` Ankur Arora
2019-05-17 17:49 ` Marcelo Tosatti
2019-05-16 1:07 ` Wanpeng Li
2019-05-17 2:06 ` Ankur Arora
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=D655C66D-8C52-4CE3-A00B-697735CFA51D@oracle.com \
--to=konrad.wilk@oracle.com \
--cc=aarcange@redhat.com \
--cc=ankur.a.arora@oracle.com \
--cc=boris.ostrovsky@oracle.com \
--cc=bsd@redhat.com \
--cc=kernellwp@gmail.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=mtosatti@redhat.com \
--cc=pbonzini@redhat.com \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®