Skip to contentSkip to conversation

x86/svm: Improve code generation from cpu_has_svm_feature()

PATCH In review Andrew Cooper 2 participants 4 messages Mar 15, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/svm: Improve code generation from cpu_has_svm_feature()

Taking svm_feature_flags by pointer and using test_bit() results in generated code which loads svm_feature_flags into a 32bit register, then does a bitwise operation.

The logic can be expressed in terms of a straight bitwise operation, resulting in the following minor improvement.

add/remove: 0/0 grow/shrink: 0/4 up/down: 0/-136 (-136)

  Function                                     old     new   delta
  svm_nested_features_on_efer_update           281     273      -8
  svm_create_vmcb                             1404    1388     -16
  svm_vmexit_handler                          6271    6239     -32
  start_svm                                    818     738     -80

Total: Before=3347569, After=3347433, chg -0.00%

---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Boris Ostrovsky <[email protected]>
CC: Suravee Suthikulpanit <[email protected]>
CC: Brian Woods <[email protected]>

---
 xen/include/asm-x86/hvm/svm/svm.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
xen/include/asm-x86/hvm/svm/svm.h +1 -2
index 49dca39..6e688a8 100644
@@ -21,7 +21,6 @@
 #define __ASM_X86_HVM_SVM_H__
 
 #include <xen/types.h>
-#include <xen/bitmap.h>
 
 #define svm_vmload(x)     svm_vmload_pa(__pa(x))
 #define svm_vmsave(x)     svm_vmsave_pa(__pa(x))
@@ -77,7 +76,7 @@ extern u32 svm_feature_flags;
 #define SVM_FEATURE_VLOADSAVE     15 /* virtual vmload/vmsave */
 #define SVM_FEATURE_VGIF          16 /* Virtual GIF */
 
-#define cpu_has_svm_feature(f) test_bit(f, &svm_feature_flags)
+#define cpu_has_svm_feature(f) (svm_feature_flags & (1u << (f)))
 #define cpu_has_svm_npt       cpu_has_svm_feature(SVM_FEATURE_NPT)
 #define cpu_has_svm_lbrv      cpu_has_svm_feature(SVM_FEATURE_LBRV)
 #define cpu_has_svm_svml      cpu_has_svm_feature(SVM_FEATURE_SVML)
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Andrew Cooper

Taking svm_feature_flags by pointer and using test_bit() results in generated code which loads svm_feature_flags into a 32bit register, then does a bitwise operation.

The logic can be expressed in terms of a straight bitwise operation, resulting in the following minor improvement.

add/remove: 0/0 grow/shrink: 0/4 up/down: 0/-136 (-136)

Quoted 8 lines
  Function                                     old     new   delta
  svm_nested_features_on_efer_update           281     273      -8
  svm_create_vmcb                             1404    1388     -16
  svm_vmexit_handler                          6271    6239     -32
  start_svm                                    818     738     -80

Total: Before=3347569, After=3347433, chg -0.00%

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#2 lore raw
Quoted 16 lines · Boris Ostrovsky
Quoted 15 lines · Andrew Cooper

Taking svm_feature_flags by pointer and using test_bit() results in generated code which loads svm_feature_flags into a 32bit register, then does a bitwise operation.

The logic can be expressed in terms of a straight bitwise operation, resulting in the following minor improvement.

add/remove: 0/0 grow/shrink: 0/4 up/down: 0/-136 (-136)

  Function                                     old     new   delta
  svm_nested_features_on_efer_update           281     273      -8
  svm_create_vmcb                             1404    1388     -16
  svm_vmexit_handler                          6271    6239     -32
  start_svm                                    818     738     -80

Total: Before=3347569, After=3347433, chg -0.00%

Quoted 3 lines
Quoted 1 line

I suppose you'd like me to fix up Oracle on commit? ;)

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#3 lore raw
Quoted 17 lines · Andrew Cooper
Quoted 16 lines · Boris Ostrovsky
Quoted 15 lines · Andrew Cooper

Taking svm_feature_flags by pointer and using test_bit() results in generated code which loads svm_feature_flags into a 32bit register, then does a bitwise operation.

The logic can be expressed in terms of a straight bitwise operation, resulting in the following minor improvement.

add/remove: 0/0 grow/shrink: 0/4 up/down: 0/-136 (-136)

  Function                                     old     new   delta
  svm_nested_features_on_efer_update           281     273      -8
  svm_create_vmcb                             1404    1388     -16
  svm_vmexit_handler                          6271    6239     -32
  start_svm                                    818     738     -80

Total: Before=3347569, After=3347433, chg -0.00%

Quoted 4 lines
Quoted 3 lines
Quoted 1 line

I suppose you'd like me to fix up Oracle on commit? ;)

Oops, yes please.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel