Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 29 May 2013 11:56:28 -0400
From:      John Baldwin <jhb@freebsd.org>
To:        freebsd-drivers@freebsd.org
Cc:        Orit Moskovich <oritm@mellanox.com>
Subject:   Re: taskqueues
Message-ID:  <201305291156.29230.jhb@freebsd.org>
In-Reply-To: <981733489AB3BD4DB24B48340F53E0A55B0D5206@MTLDAG01.mtl.com>
References:  <981733489AB3BD4DB24B48340F53E0A55B0D5206@MTLDAG01.mtl.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Thursday, May 23, 2013 9:47:14 am Orit Moskovich wrote:
> Hi,
> 
> Can you please specify the difference between interrupt threads and regular 
kernel threads in the context of the different default taskqueues?
> Meaning, I saw that the taskqueue taskqueue_thread is actually a kernel 
thread running the function taskqueue_thread_loop,
> And the 3 other default taskqueues are working with ithreads.
> 
> Which of the above preempts the other? What should I use if performance is 
critical (something equivalent to Linux softirq...)?

ithreads use the most important priority range:

#define	PRI_MIN			(0)		/* Highest priority. */
#define	PRI_MAX			(255)		/* Lowest priority. */

#define	PRI_MIN_ITHD		(PRI_MIN)
#define	PRI_MAX_ITHD		(PRI_MIN_REALTIME - 1)

#define	PI_REALTIME		(PRI_MIN_ITHD + 0)
#define	PI_AV			(PRI_MIN_ITHD + 4)
#define	PI_NET			(PRI_MIN_ITHD + 8)
#define	PI_DISK			(PRI_MIN_ITHD + 12)
#define	PI_TTY			(PRI_MIN_ITHD + 16)
#define	PI_DULL			(PRI_MIN_ITHD + 20)
#define	PI_SOFT			(PRI_MIN_ITHD + 24)
#define	PI_SWI(x)		(PI_SOFT + (x) * RQ_PPQ)

For example, an INTR_TYPE_NET interrupt will generally run in an ithread with 
the PI_NET priority.  For software interrupt threads the priority is generally
PI_SWI(SWI_xxx).  The SWI_xxx constants are:

/*
 * Software interrupt numbers in priority order.  The priority determines
 * the priority of the corresponding interrupt thread.
 */
#define	SWI_TTY		0
#define	SWI_NET		1
#define	SWI_CAMBIO	2
#define	SWI_VM		3
#define	SWI_CLOCK	4
#define	SWI_TQ_FAST	5
#define	SWI_TQ		6
#define	SWI_TQ_GIANT	6

For taskqueues you have three global taskqueues to choose from:

taskqueue_fast: runs at PI_SWI(SWI_TQ_FAST) = 44
taskqueue_swi: runs at PI_SWI(SWI_TQ) = 48
taskqueue_thread: runs at PWAIT = 108

However, you can create your own thread-backed taskqueue that can run at 
whatever priority you choose.  There is nothing really special about having 
the taskqueue be an SWI vs a normal thread.  If you wanted a taskqueue that 
ran at PI_NET you could do:

TASKQUEUE_DEFINE(foo, taskqueue_thread_enqueue, &taskqueue_foo,
    taskqueue_start_threads(&taskqueue_foo, 1, PI_NET, "foo taskq");

If you needed to queue tasks from an interrupt filter you would want to use
a fast taskqueue instead:

TASKQUEUE_FAST_DEFINE(< same args as above >)

-- 
John Baldwin



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