Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 25 Nov 2010 19:36:00 -0800
From:      Max Laier <max@laiers.net>
To:        Andriy Gapon <avg@freebsd.org>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: smp_rendezvous_cpus() vs sched_bind()
Message-ID:  <4CEF2B20.4060102@laiers.net>
In-Reply-To: <4CEB5C4C.90003@freebsd.org>
References:  <4CEB5C4C.90003@freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
Am 22.11.2010 22:16, schrieb Andriy Gapon:
> If I need to call a function func on a specific CPU which one of the following I
> should use?
>
> 1.
> smp_rendezvous_cpus(1<<  cpuid, ..., func, ...);
>
> 2.
> sched_bind(cpuid);
> func();
> sched_unbind();
>
> Or does it depend on some additional factors?
> What are the main differences here?
>
> And also by extension.
> If I need to execute func() on all CPUs - which one is better again -
> smp_rendezvous_cpus() or CPU_FOREACH+sched_bind?
>
It depends on what you are trying to do in func() really.  One huge 
caveat against smp_rendezvous is that func will be running from 
interrupt context in an unknown lock state with interrupts disabled.

Most of the time sched_bind() should be sufficient/preferrable.  You 
should think of smp_rendezvous as a basic building block rather than a 
general purpose API ... unless you really need the rendezvous part and 
the preemption and all that other stuff ... stay clear of it.

It might make sense to have one of the deferred action APIs 
(callout/taskqueue/...) provide means to run a task on a specific 
CPU/all of them ...

I hope this helps.

Best,
   Max



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4CEF2B20.4060102>