xen/x86: Fix cflush()'s parameter tracking
PATCH 1/1 xen/x86: Fix cflush()'s parameter tracking
Foring a register operand hides (from the compiler) the fact that clflush behaves as a read from the memory operand (wrt memory order, faults, etc.). It also reduces the compilers flexibility with register schedulling.
Reimplement clfush() (and wbinvd() for consistency) as a static inline rather than a macro, and have it take a const void pointer.
In practice, the only generated code which gets modified by this is in mwait_idle_with_hints(), where a memory operand can now be used.
While here, I noticed that &mwait_wakeup(cpu) was being calculated twice. This is caused by the memory clobber in mb(), so take the opportunity to help the optimiser by calculating it once, ahead of time. bloat-o-meter reports a delta of -26 as a result of this change.
---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
--- xen/arch/x86/acpi/cpu_idle.c | 5 +++-- xen/include/asm-x86/system.h | 12 ++++++++---- 2 files changed, 11 insertions(+), 6 deletions(-)
xen/arch/x86/acpi/cpu_idle.c +3 -2
@@ -401,15 +401,16 @@ void mwait_idle_with_hints(unsigned int eax, unsigned int ecx) {unsigned int cpu =smp_processor_id ();s_time_t expires =per_cpu (timer_deadline, cpu); +const void *monitor_addr = &mwait_wakeup (cpu);if (boot_cpu_has (X86_FEATURE_CLFLUSH_MONITOR ) ) {mb (); -clflush ((void *)&mwait_wakeup (cpu)); +clflush (monitor_addr);mb (); } -__monitor ((void *)&mwait_wakeup (cpu),0 ,0 ); +__monitor (monitor_addr,0 ,0 );smp_mb ();/*
xen/include/asm-x86/system.h +8 -4
@@ -11,11 +11,15 @@ __sel; \ }) -#define wbinvd () \ - asm volatile ( "wbinvd" : : : "memory" ) +static inline void wbinvd (void ) +{ + asmvolatile ("wbinvd" :::"memory" ); +} -#define clflush (a) \ - asm volatile ( "clflush (%0)" : : "r"(a) ) +static inline void clflush (const void *p) +{ + asmvolatile ("clflush %0" ::"m" (*(const char *)p) ); +}#define xchg (ptr,v) \ ((__typeof__(*(ptr)))__xchg((unsigned long)(v),(ptr),sizeof(*(ptr))))
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 15.03.19 at 15:20, <[email protected]> wrote:
Foring a register operand hides (from the compiler) the fact that clflush behaves as a read from the memory operand (wrt memory order, faults, etc.). It also reduces the compilers flexibility with register schedulling.
Reimplement
clfush()(andwbinvd()for consistency) as a static inline rather than a macro, and have it take a const void pointer.In practice, the only generated code which gets modified by this is in
mwait_idle_with_hints(), where a memory operand can now be used.
Quoted 6 lines
While here, I noticed that
&mwait_wakeup(cpu)was being calculated twice. This is caused by the memory clobber inmb(), so take the opportunity to help the optimiser by calculating it once, ahead of time. bloat-o-meter reports a delta of -26 as a result of this change.Signed-off-by Andrew Cooper <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel