[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID:
<SN6PR02MB4157A6C0CA988FE0381F007BD4B62@SN6PR02MB4157.namprd02.prod.outlook.com>
Date: Sun, 28 Jul 2024 14:06:41 +0000
From: Michael Kelley <mhklinux@...look.com>
To: Saurabh Singh Sengar <ssengar@...ux.microsoft.com>
CC: "kys@...rosoft.com" <kys@...rosoft.com>, "haiyangz@...rosoft.com"
<haiyangz@...rosoft.com>, "wei.liu@...nel.org" <wei.liu@...nel.org>,
"decui@...rosoft.com" <decui@...rosoft.com>, "linux-hyperv@...r.kernel.org"
<linux-hyperv@...r.kernel.org>, "linux-kernel@...r.kernel.org"
<linux-kernel@...r.kernel.org>, "ssengar@...rosoft.com"
<ssengar@...rosoft.com>, "srivatsa@...il.mit.edu" <srivatsa@...il.mit.edu>
Subject: RE: [PATCH] Drivers: hv: vmbus: Deferring per cpu tasks
From: Saurabh Singh Sengar <ssengar@...ux.microsoft.com> Sent: Sunday, July 28, 2024 2:18 AM
>
> On Sun, Jul 28, 2024 at 04:32:23AM +0000, Michael Kelley wrote:
> > From: Saurabh Sengar <ssengar@...ux.microsoft.com> Sent: Wednesday, July 24,
> 2024 10:26 PM
> > >
> > > Currently on a very large system with 1780 CPUs, hv_acpi_init takes
> > > around 3 seconds to complete for all the CPUs. This is because of
> > > sequential synic initialization for each CPU.
> > >
> > > Defer these tasks so that each CPU executes hv_acpi_init in parallel
> > > to take full advantage of multiple CPUs.
> > >
> > > This solution saves around 2 seconds of boot time on a 1780 CPU system,
> > > that around 66% improvement in the existing logic.
> > >
> > > Signed-off-by: Saurabh Sengar <ssengar@...ux.microsoft.com>
> > > ---
> > > drivers/hv/vmbus_drv.c | 33 ++++++++++++++++++++++++++++++---
> > > 1 file changed, 30 insertions(+), 3 deletions(-)
> > >
> > > diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
> > > index c857dc3975be..3395526ad0d0 100644
> > > --- a/drivers/hv/vmbus_drv.c
> > > +++ b/drivers/hv/vmbus_drv.c
> > > @@ -1306,6 +1306,13 @@ static irqreturn_t vmbus_percpu_isr(int irq, void *dev_id)
> > > return IRQ_HANDLED;
> > > }
> > >
> > > +static void vmbus_percpu_work(struct work_struct *work)
> > > +{
> > > + unsigned int cpu = smp_processor_id();
> > > +
> > > + hv_synic_init(cpu);
> > > +}
> > > +
> > > /*
> > > * vmbus_bus_init -Main vmbus driver initialization routine.
> > > *
> > > @@ -1316,7 +1323,8 @@ static irqreturn_t vmbus_percpu_isr(int irq, void *dev_id)
> > > */
> > > static int vmbus_bus_init(void)
> > > {
> > > - int ret;
> > > + int ret, cpu;
> > > + struct work_struct __percpu *works;
> > >
> > > ret = hv_init();
> > > if (ret != 0) {
> > > @@ -1355,12 +1363,31 @@ static int vmbus_bus_init(void)
> > > if (ret)
> > > goto err_alloc;
> > >
> > > + works = alloc_percpu(struct work_struct);
> > > + if (!works) {
> > > + ret = -ENOMEM;
> > > + goto err_alloc;
> > > + }
> > > +
> > > /*
> > > * Initialize the per-cpu interrupt state and stimer state.
> > > * Then connect to the host.
> > > */
> > > - ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "hyperv/vmbus:online",
> > > - hv_synic_init, hv_synic_cleanup);
> > > + cpus_read_lock();
> > > + for_each_online_cpu(cpu) {
> > > + struct work_struct *work = per_cpu_ptr(works, cpu);
> > > +
> > > + INIT_WORK(work, vmbus_percpu_work);
> > > + schedule_work_on(cpu, work);
> > > + }
> > > +
> > > + for_each_online_cpu(cpu)
> > > + flush_work(per_cpu_ptr(works, cpu));
> > > +
> > > + ret = __cpuhp_setup_state_cpuslocked(CPUHP_AP_ONLINE_DYN, "hyperv/vmbus:online", false,
> > > + hv_synic_init, hv_synic_cleanup, false);
> >
> > I'd suggest using cpuhp_setup_state_nocalls_cpuslocked(). It appears to be
> > the interface intended for users outside the cpuhotplug code, whereas
> > __cpuhp_setup_state_cpuslocked() should be private to the cpuhotplug code.
> >
>
> Thanks for your review.
>
> The function cpuhp_setup_state_nocalls_cpuslocked() is commonly used across the
> kernel drivers hence it was a first choice for me as well. However, it includes a
> cpus_read_lock that we already introduced separately in above code. To avoid recursive
> locking, I opted for __cpuhp_setup_state_cpuslocked.
cpuhp_setup_state_nocalls() includes the cpus_read_lock() as you describe.
But cpuhp_setup_state_nocalls_cpuslocked() explicitly assumes that the
cpus_read_lock() is already held, so is suitable for use in this case. There are
several variants with the _cpuslocked suffix, which indicates that the caller
is responsible for the cpus_read_lock().
Michael
>
> One might argue that unlocking and then calling cpuhp_setup_state_nocalls_cpuslocked
> could be a solution, but I am concerned about potential race conditions, as CPUs could
> come online during this interval and in such case synic initialization for those CPUs
> would be missed.
>
> - Saurabh
Powered by blists - more mailing lists