[Xen-devel,4/6] xen/arm: cpufeature: Add helper to check constant caps

Message ID 20180824165820.32620-5-julien.grall@arm.com
State Superseded
Headers show
Series
  • xen/arm: SMCCC fixup and improvement
Related show

Commit Message

Julien Grall Aug. 24, 2018, 4:58 p.m.
Some capababilities are set right during boot and will never change
afterwards. At the moment, the function cpu_have_caps will check whether
the cap is enabled from the memory.

It is possible to avoid the load from the memory by using an
ALTERNATIVE. With that the check is just reduced to 1 instruction.

Signed-off-by: Julien Grall <julien.grall@arm.com>

---

This is the static key for the poor. At some point we might want to
introduce something similar to static key in Xen.
---
 xen/include/asm-arm/cpufeature.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)

Comments

Volodymyr Babchuk Aug. 30, 2018, 5:43 p.m. | #1
Hi Julien,

On 24.08.18 19:58, Julien Grall wrote:
> Some capababilities are set right during boot and will never change
> afterwards. At the moment, the function cpu_have_caps will check whether
> the cap is enabled from the memory.
> 
> It is possible to avoid the load from the memory by using an
> ALTERNATIVE. With that the check is just reduced to 1 instruction.
> 
> Signed-off-by: Julien Grall <julien.grall@arm.com>
> 
> ---
> 
> This is the static key for the poor. At some point we might want to
> introduce something similar to static key in Xen.
> ---
>   xen/include/asm-arm/cpufeature.h | 12 ++++++++++++
>   1 file changed, 12 insertions(+)
> 
> diff --git a/xen/include/asm-arm/cpufeature.h b/xen/include/asm-arm/cpufeature.h
> index 3de6b54301..9c297c521c 100644
> --- a/xen/include/asm-arm/cpufeature.h
> +++ b/xen/include/asm-arm/cpufeature.h
> @@ -63,6 +63,18 @@ static inline bool cpus_have_cap(unsigned int num)
>       return test_bit(num, cpu_hwcaps);
>   }
>   

+#include <asm/alternative.h>


> +/* System capability check for constant cap */
> +#define cpus_have_const_cap(num) ({                 \
> +        bool __ret;                                 \
> +                                                    \
> +        asm volatile (ALTERNATIVE("mov %0, #0",     \
> +                                  "mov %0, #1",     \
> +                                  num)              \
> +                      : "=r" (__ret));              \
> +                                                    \
> +        __ret;                                      \
> +        })
> +
>   static inline void cpus_set_cap(unsigned int num)
>   {
>       if (num >= ARM_NCAPS)
>
Julien Grall Sept. 25, 2018, 4:53 p.m. | #2
On 30/08/18 18:43, Volodymyr Babchuk wrote:
> Hi Julien,

Hi,

> On 24.08.18 19:58, Julien Grall wrote:
>> Some capababilities are set right during boot and will never change
>> afterwards. At the moment, the function cpu_have_caps will check whether
>> the cap is enabled from the memory.
>>
>> It is possible to avoid the load from the memory by using an
>> ALTERNATIVE. With that the check is just reduced to 1 instruction.
>>
>> Signed-off-by: Julien Grall <julien.grall@arm.com>
>>
>> ---
>>
>> This is the static key for the poor. At some point we might want to
>> introduce something similar to static key in Xen.
>> ---
>>   xen/include/asm-arm/cpufeature.h | 12 ++++++++++++
>>   1 file changed, 12 insertions(+)
>>
>> diff --git a/xen/include/asm-arm/cpufeature.h 
>> b/xen/include/asm-arm/cpufeature.h
>> index 3de6b54301..9c297c521c 100644
>> --- a/xen/include/asm-arm/cpufeature.h
>> +++ b/xen/include/asm-arm/cpufeature.h
>> @@ -63,6 +63,18 @@ static inline bool cpus_have_cap(unsigned int num)
>>       return test_bit(num, cpu_hwcaps);
>>   }
> 
> +#include <asm/alternative.h>

I would rather not, alternative.h already includes cpufeature.h.

My preference would be the user of cpus_have_const_cap() to include 
alternative.h.

Cheers,

> 
> 
>> +/* System capability check for constant cap */
>> +#define cpus_have_const_cap(num) ({                 \
>> +        bool __ret;                                 \
>> +                                                    \
>> +        asm volatile (ALTERNATIVE("mov %0, #0",     \
>> +                                  "mov %0, #1",     \
>> +                                  num)              \
>> +                      : "=r" (__ret));              \
>> +                                                    \
>> +        __ret;                                      \
>> +        })
>> +
>>   static inline void cpus_set_cap(unsigned int num)
>>   {
>>       if (num >= ARM_NCAPS)
>>
>

Patch

diff --git a/xen/include/asm-arm/cpufeature.h b/xen/include/asm-arm/cpufeature.h
index 3de6b54301..9c297c521c 100644
--- a/xen/include/asm-arm/cpufeature.h
+++ b/xen/include/asm-arm/cpufeature.h
@@ -63,6 +63,18 @@  static inline bool cpus_have_cap(unsigned int num)
     return test_bit(num, cpu_hwcaps);
 }
 
+/* System capability check for constant cap */
+#define cpus_have_const_cap(num) ({                 \
+        bool __ret;                                 \
+                                                    \
+        asm volatile (ALTERNATIVE("mov %0, #0",     \
+                                  "mov %0, #1",     \
+                                  num)              \
+                      : "=r" (__ret));              \
+                                                    \
+        __ret;                                      \
+        })
+
 static inline void cpus_set_cap(unsigned int num)
 {
     if (num >= ARM_NCAPS)