Skip to contentSkip to conversation

xen/evtchn: Cleanup for virq_is_global() infrastructure

PATCH In review Andrew Cooper 3 participants 3 messages Jan 29, 2018 – Jan 30, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen/evtchn: Cleanup for virq_is_global() infrastructure

Switch it, and the arch infrastructure, to return bool. Drop the unnecessary rc parameter, and remove a redundant assertion from send_global_virq().

No functional change.

---
CC: Jan Beulich <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>

---
 xen/common/event_channel.c  | 21 +++++++--------------
 xen/include/asm-arm/event.h |  4 ++--
 xen/include/asm-x86/event.h |  4 ++--
 3 files changed, 11 insertions(+), 18 deletions(-)
xen/common/event_channel.c +7 -14
index be834c5..4c5ca46 100644
@@ -93,29 +93,23 @@ static uint8_t get_xen_consumer(xen_event_channel_notification_t fn)
 /* Get the notification function for a given Xen-bound event channel. */
 #define xen_notification_fn(e) (xen_consumers[(e)->xen_consumer-1])
 
-static int virq_is_global(uint32_t virq)
+static bool virq_is_global(uint32_t virq)
 {
-    int rc;
-
-    ASSERT(virq < NR_VIRQS);
-
     switch ( virq )
     {
     case VIRQ_TIMER:
     case VIRQ_DEBUG:
     case VIRQ_XENOPROF:
     case VIRQ_XENPMU:
-        rc = 0;
-        break;
+        return false;
+
     case VIRQ_ARCH_0 ... VIRQ_ARCH_7:
-        rc = arch_virq_is_global(virq);
-        break;
+        return arch_virq_is_global(virq);
+
     default:
-        rc = 1;
-        break;
+        ASSERT(virq < NR_VIRQS);
+        return true;
     }
-
-    return rc;
 }
 
 
@@ -809,7 +803,6 @@ static DEFINE_SPINLOCK(global_virq_handlers_lock);
 
 void send_global_virq(uint32_t virq)
 {
-    ASSERT(virq < NR_VIRQS);
     ASSERT(virq_is_global(virq));
 
     send_guest_global_virq(global_virq_handlers[virq] ?: hardware_domain, virq);
xen/include/asm-arm/event.h +2 -2
index caefa50..bfb1899 100644
@@ -54,9 +54,9 @@ static inline void local_event_delivery_enable(void)
 }
 
 /* No arch specific virq definition now. Default to global. */
-static inline int arch_virq_is_global(int virq)
+static inline bool arch_virq_is_global(int virq)
 {
-    return 1;
+    return true;
 }
 
 #endif
xen/include/asm-x86/event.h +2 -2
index a91599d..df0232b 100644
@@ -42,9 +42,9 @@ static inline void local_event_delivery_enable(void)
 }
 
 /* No arch specific virq definition now. Default to global. */
-static inline int arch_virq_is_global(uint32_t virq)
+static inline bool arch_virq_is_global(uint32_t virq)
 {
-    return 1;
+    return true;
 }
 
 #endif
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Acked-by on v1 1/1
#1 lore raw
Quoted 6 lines · Andrew Cooper

Switch it, and the arch infrastructure, to return bool. Drop the unnecessary rc parameter, and remove a redundant assertion from send_global_virq().

No functional change.

Quoted 94 lines

---
CC: Jan Beulich <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>

---
 xen/common/event_channel.c  | 21 +++++++--------------
 xen/include/asm-arm/event.h |  4 ++--
 xen/include/asm-x86/event.h |  4 ++--
 3 files changed, 11 insertions(+), 18 deletions(-)
xen/common/event_channel.c +7 -14
index be834c5..4c5ca46 100644
@@ -93,29 +93,23 @@ static uint8_t get_xen_consumer(xen_event_channel_notification_t fn)
 /* Get the notification function for a given Xen-bound event channel. */
 #define xen_notification_fn(e) (xen_consumers[(e)->xen_consumer-1])
 
-static int virq_is_global(uint32_t virq)
+static bool virq_is_global(uint32_t virq)
 {
-    int rc;
-
-    ASSERT(virq < NR_VIRQS);
-
     switch ( virq )
     {
     case VIRQ_TIMER:
     case VIRQ_DEBUG:
     case VIRQ_XENOPROF:
     case VIRQ_XENPMU:
-        rc = 0;
-        break;
+        return false;
+
     case VIRQ_ARCH_0 ... VIRQ_ARCH_7:
-        rc = arch_virq_is_global(virq);
-        break;
+        return arch_virq_is_global(virq);
+
     default:
-        rc = 1;
-        break;
+        ASSERT(virq < NR_VIRQS);
+        return true;
     }
-
-    return rc;
 }
 
 
@@ -809,7 +803,6 @@ static DEFINE_SPINLOCK(global_virq_handlers_lock);
 
 void send_global_virq(uint32_t virq)
 {
-    ASSERT(virq < NR_VIRQS);
     ASSERT(virq_is_global(virq));
 
     send_guest_global_virq(global_virq_handlers[virq] ?: hardware_domain, virq);
xen/include/asm-arm/event.h +2 -2
index caefa50..bfb1899 100644
@@ -54,9 +54,9 @@ static inline void local_event_delivery_enable(void)
 }
 
 /* No arch specific virq definition now. Default to global. */
-static inline int arch_virq_is_global(int virq)
+static inline bool arch_virq_is_global(int virq)
 {
-    return 1;
+    return true;
 }
 
 #endif
xen/include/asm-x86/event.h +2 -2
index a91599d..df0232b 100644
@@ -42,9 +42,9 @@ static inline void local_event_delivery_enable(void)
 }
 
 /* No arch specific virq definition now. Default to global. */
-static inline int arch_virq_is_global(uint32_t virq)
+static inline bool arch_virq_is_global(uint32_t virq)
 {
-    return 1;
+    return true;
 }
 
 #endif
Signature · 1 line
2.1.4

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

Reviewed-by on v1 1/1
#2 lore raw
In reply to Andrew Cooper
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 29.01.18 at 17:16, <[email protected]> wrote:

Switch it, and the arch infrastructure, to return bool. Drop the unnecessary rc parameter, and remove a redundant assertion from send_global_virq().

s/parameter/variable/?

Quoted 3 lines

No functional change.

with two further remarks:

xen/common/event_channel.c static uint8_t get_xen_consumer(xen_event_channel_notification_t fn) · line 96

Quoted 8 lines
xen/common/event_channel.c +1 -1
@@ -93,29 +93,23 @@ static uint8_t get_xen_consumer(xen_event_channel_notification_t fn)
 /* Get the notification function for a given Xen-bound event channel. */
 #define xen_notification_fn(e) (xen_consumers[(e)->xen_consumer-1])
 
-static int virq_is_global(uint32_t virq)
+static bool virq_is_global(uint32_t virq)

Also make the parameter unsigned int at this occasion?

Quoted 19 lines
xen/common/event_channel.c +3 -8
 {
-    int rc;
-
-    ASSERT(virq < NR_VIRQS);
-
     switch ( virq )
     {
     case VIRQ_TIMER:
     case VIRQ_DEBUG:
     case VIRQ_XENOPROF:
     case VIRQ_XENPMU:
-        rc = 0;
-        break;
+        return false;
+
     case VIRQ_ARCH_0 ... VIRQ_ARCH_7:
-        rc = arch_virq_is_global(virq);
-        break;
+        return arch_virq_is_global(virq);

xen/common/event_channel.c static uint8_t get_xen_consumer(xen_event_channel_notification_t fn) · line 113

Quoted 10 lines
xen/common/event_channel.c +3 -4
+
     default:
-        rc = 1;
-        break;
+        ASSERT(virq < NR_VIRQS);
+        return true;
     }
-
-    return rc;
 }

Could I talk you into dropping the "default:" and instead put ASSERT() and return outside of the switch()? I generally think that where this is possible without causing compiler warnings, it results in a more "normal" look of the overall function (in particular with a return at the function's end, rather than giving the appearance - without looking at all the case blocks inside the switch - that the function returns void).

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel