From owner-freebsd-drivers@FreeBSD.ORG Wed May 29 18:16:45 2013 Return-Path: Delivered-To: freebsd-drivers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 75591AB5 for ; Wed, 29 May 2013 18:16:45 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from bigwig.baldwin.cx (bigwig.baldwin.cx [IPv6:2001:470:1f11:75::1]) by mx1.freebsd.org (Postfix) with ESMTP id 54C47E5A for ; Wed, 29 May 2013 18:16:45 +0000 (UTC) Received: from jhbbsd.localnet (unknown [209.249.190.124]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id 259A0B96F; Wed, 29 May 2013 14:16:42 -0400 (EDT) From: John Baldwin To: freebsd-drivers@freebsd.org Subject: Re: taskqueues Date: Wed, 29 May 2013 11:56:28 -0400 User-Agent: KMail/1.13.5 (FreeBSD/8.2-CBSD-20110714-p25; KDE/4.5.5; amd64; ; ) References: <981733489AB3BD4DB24B48340F53E0A55B0D5206@MTLDAG01.mtl.com> In-Reply-To: <981733489AB3BD4DB24B48340F53E0A55B0D5206@MTLDAG01.mtl.com> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201305291156.29230.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.7 (bigwig.baldwin.cx); Wed, 29 May 2013 14:16:42 -0400 (EDT) Cc: Orit Moskovich X-BeenThere: freebsd-drivers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Writing device drivers for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 29 May 2013 18:16:45 -0000 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