Re: [patch 02/13] workqueue: Provide work_on_cpu_safe()

From: Peter Zijlstra
Date: Fri Apr 14 2017 - 04:55:18 EST


On Wed, Apr 12, 2017 at 10:07:28PM +0200, Thomas Gleixner wrote:
> +long work_on_cpu_safe(int cpu, long (*fn)(void *), void *arg)
> +{
> + long ret = -ENODEV;
> +
> + get_online_cpus();
> + if (cpu_online(cpu))
> + ret = work_on_cpu(cpu, fn, arg);
> + put_online_cpus();
> + return ret;
> +}

But doesn't workqueue have this lovelt 'feature' where it will unbind
per-cpu work and run it on random CPUs when hotplug happens?

That is, I think you need a flush_work() before put_online_cpus() if you
want to guarantee anything.