how to bind CPU with taskqueue thread
John Baldwin
jhb at freebsd.org
Fri Aug 22 20:15:53 UTC 2008
On Wednesday 20 August 2008 08:09:14 pm Ji wrote:
> Hi all,
>
> I use "taskqueue_start_threads(&tq, 1, PI_NET, tq_name)" to create a
> thread working for the task queue, and I have multiple CPUs.
> Can I bind the thread with a specific CPU so that the thread is only
> running on that CPU permanently? Thank you a lot.
> I tried sched_bind(FIRST_THREAD_IN_PROC(*tq->tq_pproc), 1) but it does
> not work. BTW, the kernel uses ULE scheduler.
> Thanks.
With sched_bind() you can only bind curthread. What you can do for your case
since you have 1 thread is to queue a task whose function does:
struct thread *td;
td = curthread;
thread_lock(td);
sched_bind(td, 1);
thread_unlock(td);
For a queue with multiple threads there isn't a good way to do that currently,
though you might can have a task function that does a bind and then blocks on
a condition variable after bumping up a counter, except that if the counter
hits N, you do a wakeup on the cv instead. This would ensure that N threads
run the tasks (i.e. no thread runs two of the bind tasks).
--
John Baldwin
More information about the freebsd-smp
mailing list