diff mbox

[RFC,05/16] xen/arm: Add cpu_hwcap bitmap

Message ID 1462466065-30212-6-git-send-email-julien.grall@arm.com (mailing list archive)
State New, archived
Headers show

Commit Message

Julien Grall May 5, 2016, 4:34 p.m. UTC
This will be used to know if a feature, which Xen cares, is available accross
all the CPUs.

This code is a light version of arch/arm64/kernel/cpufeature.c from
Linux v4.6-rc3.

Signed-off-by: Julien Grall <julien.grall@arm.com>
---
 xen/arch/arm/Makefile            |  1 +
 xen/arch/arm/cpufeature.c        | 34 ++++++++++++++++++++++++++++++++++
 xen/include/asm-arm/cpufeature.h | 29 +++++++++++++++++++++++++++++
 3 files changed, 64 insertions(+)
 create mode 100644 xen/arch/arm/cpufeature.c

Comments

Stefano Stabellini May 9, 2016, 9:53 a.m. UTC | #1
On Thu, 5 May 2016, Julien Grall wrote:
> This will be used to know if a feature, which Xen cares, is available accross
> all the CPUs.
> 
> This code is a light version of arch/arm64/kernel/cpufeature.c from
> Linux v4.6-rc3.
> 
> Signed-off-by: Julien Grall <julien.grall@arm.com>
> ---
>  xen/arch/arm/Makefile            |  1 +
>  xen/arch/arm/cpufeature.c        | 34 ++++++++++++++++++++++++++++++++++
>  xen/include/asm-arm/cpufeature.h | 29 +++++++++++++++++++++++++++++
>  3 files changed, 64 insertions(+)
>  create mode 100644 xen/arch/arm/cpufeature.c
> 
> diff --git a/xen/arch/arm/Makefile b/xen/arch/arm/Makefile
> index 8e0d2f6..9122f78 100644
> --- a/xen/arch/arm/Makefile
> +++ b/xen/arch/arm/Makefile
> @@ -6,6 +6,7 @@ subdir-$(CONFIG_ACPI) += acpi
>  
>  obj-y += bootfdt.o
>  obj-y += cpu.o
> +obj-y += cpufeature.o
>  obj-y += decode.o
>  obj-y += device.o
>  obj-y += domain.o
> diff --git a/xen/arch/arm/cpufeature.c b/xen/arch/arm/cpufeature.c
> new file mode 100644
> index 0000000..7a1b56b
> --- /dev/null
> +++ b/xen/arch/arm/cpufeature.c
> @@ -0,0 +1,34 @@
> +/*
> + * Contains CPU feature definitions
> + *
> + * Copyright (C) 2015 ARM Ltd.
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 as
> + * published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program.  If not, see <http://www.gnu.org/licenses/>.
> + */
> +
> +#include <xen/config.h>
> +#include <xen/types.h>
> +#include <xen/init.h>
> +#include <xen/smp.h>
> +#include <asm/cpufeature.h>
> +
> +DECLARE_BITMAP(cpu_hwcaps, ARM_NCAPS);
> +
> +/*
> + * Local variables:
> + * mode: C
> + * c-file-style: "BSD"
> + * c-basic-offset: 4
> + * indent-tabs-mode: nil
> + * End:
> + */
> diff --git a/xen/include/asm-arm/cpufeature.h b/xen/include/asm-arm/cpufeature.h
> index 7b519cd..2bebad1 100644
> --- a/xen/include/asm-arm/cpufeature.h
> +++ b/xen/include/asm-arm/cpufeature.h
> @@ -35,6 +35,35 @@
>  #endif
>  #define cpu_has_security  (boot_cpu_feature32(security) > 0)
>  
> +#define ARM_NCAPS           0
> +
> +#ifndef __ASSEMBLY__
> +
> +#include <xen/types.h>
> +#include <xen/lib.h>
> +#include <xen/bitops.h>
> +
> +extern DECLARE_BITMAP(cpu_hwcaps, ARM_NCAPS);
> +
> +static inline bool_t cpus_have_cap(unsigned int num)
> +{
> +    if ( num >= ARM_NCAPS )
> +        return 0;
> +
> +    return test_bit(num, cpu_hwcaps);
> +}
> +
> +static inline void cpus_set_cap(unsigned int num)
> +{
> +    if (num >= ARM_NCAPS)
> +        printk(XENLOG_WARNING "Attempt to set an illegal CPU capability (%d >= %d)\n",
> +               num, ARM_NCAPS);
> +    else
> +        __set_bit(num, cpu_hwcaps);
> +}
> +
> +#endif /* __ASSEMBLY__ */

Why everything static line? Wouldn't it better to add the functions to
cpufeature.c? They are not going to be called too many times, right?


>  #endif
>  /*
>   * Local variables:
> -- 
> 1.9.1
>
Julien Grall May 9, 2016, 10:02 a.m. UTC | #2
Hi Stefano,

On 09/05/2016 10:53, Stefano Stabellini wrote:
> On Thu, 5 May 2016, Julien Grall wrote:
>> diff --git a/xen/include/asm-arm/cpufeature.h b/xen/include/asm-arm/cpufeature.h
>> index 7b519cd..2bebad1 100644
>> --- a/xen/include/asm-arm/cpufeature.h
>> +++ b/xen/include/asm-arm/cpufeature.h
>> @@ -35,6 +35,35 @@
>>   #endif
>>   #define cpu_has_security  (boot_cpu_feature32(security) > 0)
>>
>> +#define ARM_NCAPS           0
>> +
>> +#ifndef __ASSEMBLY__
>> +
>> +#include <xen/types.h>
>> +#include <xen/lib.h>
>> +#include <xen/bitops.h>
>> +
>> +extern DECLARE_BITMAP(cpu_hwcaps, ARM_NCAPS);
>> +
>> +static inline bool_t cpus_have_cap(unsigned int num)
>> +{
>> +    if ( num >= ARM_NCAPS )
>> +        return 0;
>> +
>> +    return test_bit(num, cpu_hwcaps);
>> +}
>> +
>> +static inline void cpus_set_cap(unsigned int num)
>> +{
>> +    if (num >= ARM_NCAPS)
>> +        printk(XENLOG_WARNING "Attempt to set an illegal CPU capability (%d >= %d)\n",
>> +               num, ARM_NCAPS);
>> +    else
>> +        __set_bit(num, cpu_hwcaps);
>> +}
>> +
>> +#endif /* __ASSEMBLY__ */
>
> Why everything static line? Wouldn't it better to add the functions to
> cpufeature.c? They are not going to be called too many times, right?

This code is based on Linux where the 2 functions were already static 
inline.

I agree that cpus_set_cap won't be called often (mostly CPU bring up), 
however cpus_have_cap could be used at runtime to check whether the 
AArch32 mode is present...

But I think those 2 functions should be kept together.

Note that today, we always use the boot CPU data to know if a feature 
exists (see include/asm-arm/cpufeatures.h).

Regards,
diff mbox

Patch

diff --git a/xen/arch/arm/Makefile b/xen/arch/arm/Makefile
index 8e0d2f6..9122f78 100644
--- a/xen/arch/arm/Makefile
+++ b/xen/arch/arm/Makefile
@@ -6,6 +6,7 @@  subdir-$(CONFIG_ACPI) += acpi
 
 obj-y += bootfdt.o
 obj-y += cpu.o
+obj-y += cpufeature.o
 obj-y += decode.o
 obj-y += device.o
 obj-y += domain.o
diff --git a/xen/arch/arm/cpufeature.c b/xen/arch/arm/cpufeature.c
new file mode 100644
index 0000000..7a1b56b
--- /dev/null
+++ b/xen/arch/arm/cpufeature.c
@@ -0,0 +1,34 @@ 
+/*
+ * Contains CPU feature definitions
+ *
+ * Copyright (C) 2015 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <xen/config.h>
+#include <xen/types.h>
+#include <xen/init.h>
+#include <xen/smp.h>
+#include <asm/cpufeature.h>
+
+DECLARE_BITMAP(cpu_hwcaps, ARM_NCAPS);
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/xen/include/asm-arm/cpufeature.h b/xen/include/asm-arm/cpufeature.h
index 7b519cd..2bebad1 100644
--- a/xen/include/asm-arm/cpufeature.h
+++ b/xen/include/asm-arm/cpufeature.h
@@ -35,6 +35,35 @@ 
 #endif
 #define cpu_has_security  (boot_cpu_feature32(security) > 0)
 
+#define ARM_NCAPS           0
+
+#ifndef __ASSEMBLY__
+
+#include <xen/types.h>
+#include <xen/lib.h>
+#include <xen/bitops.h>
+
+extern DECLARE_BITMAP(cpu_hwcaps, ARM_NCAPS);
+
+static inline bool_t cpus_have_cap(unsigned int num)
+{
+    if ( num >= ARM_NCAPS )
+        return 0;
+
+    return test_bit(num, cpu_hwcaps);
+}
+
+static inline void cpus_set_cap(unsigned int num)
+{
+    if (num >= ARM_NCAPS)
+        printk(XENLOG_WARNING "Attempt to set an illegal CPU capability (%d >= %d)\n",
+               num, ARM_NCAPS);
+    else
+        __set_bit(num, cpu_hwcaps);
+}
+
+#endif /* __ASSEMBLY__ */
+
 #endif
 /*
  * Local variables: