Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 09 Sep 2015 16:57:35 -0700
From:      John Baldwin <john@baldwin.cx>
To:        freebsd-virtualization@freebsd.org
Cc:        Stefan Andritoiu <stefan.andritoiu@gmail.com>
Subject:   Re: What is the sequence of context switches when an IPI is received?
Message-ID:  <2128444.4xLqUoZl3s@ralph.baldwin.cx>
In-Reply-To: <CAO3d8=b3c6AJaX=yTanZYpe8uV=3qUts8QQQsBXGJRLbneXueg@mail.gmail.com>
References:  <CAO3d8=b3c6AJaX=yTanZYpe8uV=3qUts8QQQsBXGJRLbneXueg@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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



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