aboutsummaryrefslogtreecommitdiff
path: root/sys/sys/interrupt.h
diff options
context:
space:
mode:
authorAndriy Gapon <avg@FreeBSD.org>2018-08-03 14:27:28 +0000
committerAndriy Gapon <avg@FreeBSD.org>2018-08-03 14:27:28 +0000
commite0fa977ea5803b06f2f33badcb8e8aaad2a7c322 (patch)
treee4a1624db697884808eb46afdb1e9be84ef3d8e7 /sys/sys/interrupt.h
parent380122186ebca75e49c7772052707810aae15130 (diff)
downloadsrc-e0fa977ea5803b06f2f33badcb8e8aaad2a7c322.tar.gz
src-e0fa977ea5803b06f2f33badcb8e8aaad2a7c322.zip
safer wait-free iteration of shared interrupt handlers
The code that iterates a list of interrupt handlers for a (shared) interrupt, whether in the ISR context or in the context of an interrupt thread, does so in a lock-free fashion. Thus, the routines that modify the list need to take special steps to ensure that the iterating code has a consistent view of the list. Previously, those routines tried to play nice only with the code running in the ithread context. The iteration in the ISR context was left to a chance. After commit r336635 atomic operations and memory fences are used to ensure that ie_handlers list is always safe to navigate with respect to inserting and removal of list elements. There is still a question of when it is safe to actually free a removed element. The idea of this change is somewhat similar to the idea of the epoch based reclamation. There are some simplifications comparing to the general epoch based reclamation. All writers are serialized using a mutex, so we do not need to worry about concurrent modifications. Also, all read accesses from the open context are serialized too. So, we can get away just two epochs / phases. When a thread removes an element it switches the global phase from the current phase to the other and then drains the previous phase. Only after the draining the removed element gets actually freed. The code that iterates the list in the ISR context takes a snapshot of the global phase and then increments the use count of that phase before iterating the list. The use count (in the same phase) is decremented after the iteration. This should ensure that there should be no iteration over the removed element when its gets freed. This commit also simplifies the coordination with the interrupt thread context. Now we always schedule the interrupt thread when removing one of handlers for its interrupt. This makes the code both simpler and safer as the interrupt thread masks the interrupt thus ensuring that there is no interaction with the ISR context. P.S. This change matters only for shared interrupts and I realize that those are becoming a thing of the past (and quickly). I also understand that the problem that I am trying to solve is extremely rare. PR: 229106 Reviewed by: cem Discussed with: Samy Al Bahra MFC after: 5 weeks Differential Revision: https://reviews.freebsd.org/D15905
Notes
Notes: svn path=/head/; revision=337255
Diffstat (limited to 'sys/sys/interrupt.h')
-rw-r--r--sys/sys/interrupt.h2
1 files changed, 2 insertions, 0 deletions
diff --git a/sys/sys/interrupt.h b/sys/sys/interrupt.h
index de064bf5d430..d3432c078f51 100644
--- a/sys/sys/interrupt.h
+++ b/sys/sys/interrupt.h
@@ -122,6 +122,8 @@ struct intr_event {
struct timeval ie_warntm;
int ie_irq; /* Physical irq number if !SOFT. */
int ie_cpu; /* CPU this event is bound to. */
+ volatile int ie_phase; /* Switched to establish a barrier. */
+ volatile int ie_active[2]; /* Filters in ISR context. */
};
/* Interrupt event flags kept in ie_flags. */