Skip to contentSkip to conversation

evtchn: double per-channel locking can't hit identical channels

PATCH In review Jan Beulich 3 participants 3 messages Nov 24, 2020 – Nov 25, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 evtchn: double per-channel locking can't hit identical channels

Inter-domain channels can't possibly be bound to themselves, there's always a 2nd channel involved, even when this is a loopback into the same domain. As a result we can drop one conditional each from the two involved functions.

With this, the number of evtchn_write_lock() invocations can also be shrunk by half, swapping the two incoming function arguments instead.

xen/common/event_channel.c +8 -13
@@ -326,23 +326,18 @@ static long evtchn_alloc_unbound(evtchn_
 
 static void double_evtchn_lock(struct evtchn *lchn, struct evtchn *rchn)
 {
-    if ( lchn <= rchn )
-    {
-        evtchn_write_lock(lchn);
-        if ( lchn != rchn )
-            evtchn_write_lock(rchn);
-    }
-    else
-    {
-        evtchn_write_lock(rchn);
-        evtchn_write_lock(lchn);
-    }
+    ASSERT(lchn != rchn);
+
+    if ( lchn > rchn )
+        SWAP(lchn, rchn);
+
+    evtchn_write_lock(lchn);
+    evtchn_write_lock(rchn);
 }
 
 static void double_evtchn_unlock(struct evtchn *lchn, struct evtchn *rchn)
 {
-    if ( lchn != rchn )
-        evtchn_write_unlock(lchn);
+    evtchn_write_unlock(lchn);
     evtchn_write_unlock(rchn);
 }
 
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Jan Beulich

Inter-domain channels can't possibly be bound to themselves, there's always a 2nd channel involved, even when this is a loopback into the same domain. As a result we can drop one conditional each from the two involved functions.

With this, the number of evtchn_write_lock() invocations can also be shrunk by half, swapping the two incoming function arguments instead.

Juergen

Acked-by on v1 1/1
#2 lore raw
In reply to Jan Beulich

Hi Jan,

Quoted 9 lines · Jan Beulich

Inter-domain channels can't possibly be bound to themselves, there's always a 2nd channel involved, even when this is a loopback into the same domain. As a result we can drop one conditional each from the two involved functions.

With this, the number of evtchn_write_lock() invocations can also be shrunk by half, swapping the two incoming function arguments instead.

Cheers,

Signature · 1 line
Julien Grall