diff mbox series

KVM:make cpuid_entry2_find more efficient

Message ID 20220809055138.101470-1-zhiguangni01@gmail.com (mailing list archive)
State New, archived
Headers show
Series KVM:make cpuid_entry2_find more efficient | expand

Commit Message

Liam Ni Aug. 9, 2022, 5:51 a.m. UTC
Compared with the way of obtaining the pointer by
fetching the value of the array and then fetching the pointer,
the way of obtaining the pointer by the pointer offset is more efficient.

Signed-off-by: Liam Ni <zhiguangni01@gmail.com>
---
 arch/x86/kvm/cpuid.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Borislav Petkov Aug. 9, 2022, 7:54 a.m. UTC | #1
On Tue, Aug 09, 2022 at 01:51:38PM +0800, Liam Ni wrote:
> Compared with the way of obtaining the pointer by
> fetching the value of the array and then fetching the pointer,
> the way of obtaining the pointer by the pointer offset is more efficient.

How did you determine that?

Hint: look at the generated assembler before and after your change and
see if there are any differences.

:-)
diff mbox series

Patch

diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
index de6d44e07e34..3bf82a891564 100644
--- a/arch/x86/kvm/cpuid.c
+++ b/arch/x86/kvm/cpuid.c
@@ -75,7 +75,7 @@  static inline struct kvm_cpuid_entry2 *cpuid_entry2_find(
 	int i;
 
 	for (i = 0; i < nent; i++) {
-		e = &entries[i];
+		e = entries + i;
 
 		if (e->function == function &&
 		    (!(e->flags & KVM_CPUID_FLAG_SIGNIFCANT_INDEX) || e->index == index))