Date: Thu, 28 Aug 2014 13:01:25 +0000 From: Wei Hu <weh@microsoft.com> To: John Baldwin <jhb@freebsd.org>, "freebsd-drivers@freebsd.org" <freebsd-drivers@freebsd.org> Subject: RE: Way to run a routine on different cpu Message-ID: <a7e9afc09cbf49679257ee01a79c8205@BY1PR0301MB0902.namprd03.prod.outlook.com> In-Reply-To: <201408271427.54394.jhb@freebsd.org> References: <181e94bf68994dd9a67c6504f7fdf0d7@BY1PR0301MB0902.namprd03.prod.outlook.com> <201408271427.54394.jhb@freebsd.org>
index | next in thread | previous in thread | raw e-mail
Many thanks, John! Wei -----Original Message----- From: John Baldwin [mailto:jhb@freebsd.org] Sent: Thursday, August 28, 2014 2:28 AM To: freebsd-drivers@freebsd.org Cc: Wei Hu Subject: Re: Way to run a routine on different cpu On Tuesday, August 26, 2014 9:04:11 am Wei Hu wrote: > Hi, > > I am wondering what is the right way to run a routine on a differnet > cpu and wait for it to complete in FreeBSD kernel. For example, on cpu-0 I want to send a IPI to cpu-1 to let it run a routine called foo(). On cpu-0 I will wait till foo() completes. Is smp_rendezvous() the right way to do it? What if I only want it to run on one cpu, not all cpus? You can use 'sched_bind()' to move yourself to CPU x: struct thread *td; td = curthread; thread_lock(td); sched_bind(td, X); thread_unlock(td); /* Perform work on CPU X. */ thread_lock(td); sched_unbind(td); thread_lock(td); /* Thread can now run anywhere its cpuset permits. */ That might be simpler than a rendezvous as a rendezvous handler runs in a more restricted environment (you can't take any locks, not even spin locks, etc.) -- John Baldwinhome | help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?a7e9afc09cbf49679257ee01a79c8205>
