On Tue, Jun 26, 2018 at 07:22:44PM +0100, Andrew Cooper wrote:
> One reoccuring code pattern is to read an MSR, modify one or more bits,
> and write the result back.  Introduce helpers for this purpose.
> 
> First, introduce rdmsr_split() and wrmsr_split() which are tiny static inline
> wrappers which deal with the MSR value in two 32bit halves.
> 
> Next, construct msr_{set,clear}_bits() in terms of the {rdmsr,wrmsr}_split().
> The mask operations are deliberately performed as 32bit operations, because
> all callers pass in a constant to the mask parameter, and in all current
> cases, one of the two operations can be elided.
> 
> For MSR_IA32_PSR_L3_QOS_CFG, switch PSR_L3_QOS_CDP_ENABLE from being a bit
> position variable to being a plain number.
> 
> The resulting C is shorter, and doesn't require a temporary variable.  The
> generated ASM is also more efficient, because of avoiding the
> packing/unpacking operations.  e.g. the delta in the first hunk is from:
> 
>   b9 1b 00 00 00          mov    $0x1b,%ecx
>   0f 32                   rdmsr
>   48 c1 e2 20             shl    $0x20,%rdx
>   48 09 d0                or     %rdx,%rax
>   80 e4 f3                and    $0xf3,%ah
>   48 89 c2                mov    %rax,%rdx
>   48 c1 ea 20             shr    $0x20,%rdx
>   0f 30                   wrmsr
> 
> to:
> 
>   b9 1b 00 00 00          mov    $0x1b,%ecx
>   0f 32                   rdmsr
>   80 e4 f3                and    $0xf3,%ah
>   0f 30                   wrmsr
> 
> Signed-off-by: Andrew Cooper <andrew.coop...@citrix.com>

Reviewed-by: Wei Liu <wei.l...@citrix.com>

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Reply via email to