[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v2 2/8] xen: Refactor xen/features{.c,.h}



Improve various aspects of xen/features{.c,.h}
 * Use a bitmap instead of a array of u8 (effectively bool).
 * Mark xen_setup_features as __init, as it's only called in __init
   paths.
 * Return bool instead of int in xen_feature()

Suggested-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
Signed-off-by: Teddy Astie <teddy.astie@xxxxxxxxxx>
---
CC: Juergen Gross <jgross@xxxxxxxx>
CC: Boris Ostrovsky <boris.ostrovsky@xxxxxxxxxx>
CC: Stefano Stabellini <sstabellini@xxxxxxxxxx>
CC: Oleksandr Tyshchenko <oleksandr_tyshchenko@xxxxxxxx>
CC: x86@xxxxxxxxxx
CC: linux-kernel@xxxxxxxxxxxxxxx

 drivers/xen/features.c | 11 ++++++-----
 include/xen/features.h | 10 ++++++----
 2 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/drivers/xen/features.c b/drivers/xen/features.c
index 87f1828d40d5..c4a6da6419c5 100644
--- a/drivers/xen/features.c
+++ b/drivers/xen/features.c
@@ -7,6 +7,7 @@
  * Copyright (c) 2006, Ian Campbell, XenSource Inc.
  */
 #include <linux/types.h>
+#include <linux/bitmap.h>
 #include <linux/cache.h>
 #include <linux/export.h>
 #include <linux/printk.h>
@@ -29,20 +30,20 @@
                        panic("Xen: feature %s not available!\n", #f);  \
        }
 
-u8 xen_features[XENFEAT_NR_SUBMAPS * 32] __read_mostly;
+__ro_after_init DECLARE_BITMAP(xen_features, XENFEAT_NR_SUBMAPS * 32);
 EXPORT_SYMBOL_GPL(xen_features);
 
-void xen_setup_features(void)
+void __init xen_setup_features(void)
 {
        struct xen_feature_info fi;
-       int i, j;
+       int i;
 
        for (i = 0; i < XENFEAT_NR_SUBMAPS; i++) {
                fi.submap_idx = i;
                if (HYPERVISOR_xen_version(XENVER_get_features, &fi) < 0)
                        break;
-               for (j = 0; j < 32; j++)
-                       xen_features[i * 32 + j] = !!(fi.submap & 1U << j);
+
+               bitmap_write(xen_features, fi.submap, i * 32, 32);
        }
 
        if (xen_pv_domain()) {
diff --git a/include/xen/features.h b/include/xen/features.h
index e4cb464386a9..8cca0741d77d 100644
--- a/include/xen/features.h
+++ b/include/xen/features.h
@@ -10,15 +10,17 @@
 #ifndef __XEN_FEATURES_H__
 #define __XEN_FEATURES_H__
 
+#include <linux/cache.h>
+#include <linux/bitops.h>
 #include <xen/interface/features.h>
 
-void xen_setup_features(void);
+void __init xen_setup_features(void);
 
-extern u8 xen_features[XENFEAT_NR_SUBMAPS * 32];
+extern __ro_after_init DECLARE_BITMAP(xen_features, XENFEAT_NR_SUBMAPS * 32);
 
-static inline int xen_feature(int flag)
+static inline bool xen_feature(unsigned int flag)
 {
-       return xen_features[flag];
+       return test_bit(flag, xen_features);
 }
 
 #endif /* __ASM_XEN_FEATURES_H__ */
-- 
2.56.0



--
Teddy Astie | Vates XCP-ng Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.