Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 22 Aug 2008 15:42:34 -0400
From:      John Baldwin <jhb@freebsd.org>
To:        freebsd-smp@freebsd.org
Cc:        Ji <lijimlee@gmail.com>
Subject:   Re: how to bind CPU with taskqueue thread
Message-ID:  <200808221542.34869.jhb@freebsd.org>
In-Reply-To: <8fd8f02c0808201709rcfa8007k5511e1cb2b4a7196@mail.gmail.com>

index | next in thread | previous in thread | raw e-mail

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


home | help

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