From owner-freebsd-virtualization@freebsd.org Thu Sep 10 00:02:00 2015 Return-Path: Delivered-To: freebsd-virtualization@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id C941B9CD50F for ; Thu, 10 Sep 2015 00:02:00 +0000 (UTC) (envelope-from john@baldwin.cx) Received: from bigwig.baldwin.cx (bigwig.baldwin.cx [IPv6:2001:470:1f11:75::1]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id A69C3102F for ; Thu, 10 Sep 2015 00:02:00 +0000 (UTC) (envelope-from john@baldwin.cx) Received: from ralph.baldwin.cx (c-73-231-226-104.hsd1.ca.comcast.net [73.231.226.104]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id B462EB939; Wed, 9 Sep 2015 20:01:59 -0400 (EDT) From: John Baldwin To: freebsd-virtualization@freebsd.org Cc: Stefan Andritoiu Subject: Re: What is the sequence of context switches when an IPI is received? Date: Wed, 09 Sep 2015 16:57:35 -0700 Message-ID: <2128444.4xLqUoZl3s@ralph.baldwin.cx> User-Agent: KMail/4.14.3 (FreeBSD/10.2-PRERELEASE; KDE/4.14.3; amd64; ; ) In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.7 (bigwig.baldwin.cx); Wed, 09 Sep 2015 20:01:59 -0400 (EDT) X-BeenThere: freebsd-virtualization@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "Discussion of various virtualization techniques FreeBSD supports." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 10 Sep 2015 00:02:00 -0000 On Thursday, June 11, 2015 04:50:52 PM Stefan Andritoiu wrote: > Hello, > > From the FreeBSD Handbook: "FreeBSD deals with interrupt handlers by > giving them their own thread context". > From my understanding when a IPI is received the thread that will run > it is placed on the real-time runq, and the scheduler will be invoked > to schedule it. > > So the sequence should be: > currently running thread -> scheduler thread -> interrupt handler -> > scheduler thread -> previously interrupted thread (if no thread > priority change took place inside the interrupt handler) > > Is this correct? (Sorry these replies are dated.) IPIs do not run in a dedicated thread. Only device interrupt handlers run in a dedicated thread. IPIs (and some device handlers such as timer interrupts) borrow the stack of the currently executing thread to run their handler. As a result, you should have no context switches when an IPI is received unless the IPI handler specifically invokes one. One IPI that explicitly swithes is IPI_PREEMPT. However, other IPIs can result in a switch if the interrupted thread is running in userland and a context switch to another thread is performed via the checks in userret() and/or ast(). This is how IPI_AST is used. It has a NULL handler and is only sent to trigger the side effects in userret() in case the thread is executing in userland. -- John Baldwin