Message ID | 20181001124639.22885-3-julien.grall@arm.com |
---|---|
State | Accepted |
Commit | 579401fb8e5f33dda461d872bf5a711072662d59 |
Headers | show |
Series | [Xen-devel,[PATCH,v3] 2/4] xen/arm: cpufeature: Add helper to check constant caps | expand |
On Mon, 1 Oct 2018, 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> Reviewed-by: Stefano Stabellini <sstabellini@kernel.org> > --- > > This is the static key for the poor. At some point we might want to > introduce something similar to static key in Xen. > > Changes in v2: > - Use unlikely > --- > 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..c6cbc2ec84 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)); \ > + \ > + unlikely(__ret); \ > + }) > + > static inline void cpus_set_cap(unsigned int num) > { > if (num >= ARM_NCAPS) > -- > 2.11.0 >
diff --git a/xen/include/asm-arm/cpufeature.h b/xen/include/asm-arm/cpufeature.h index 3de6b54301..c6cbc2ec84 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)); \ + \ + unlikely(__ret); \ + }) + static inline void cpus_set_cap(unsigned int num) { if (num >= ARM_NCAPS)
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. Changes in v2: - Use unlikely --- xen/include/asm-arm/cpufeature.h | 12 ++++++++++++ 1 file changed, 12 insertions(+)