mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Kautuk Consul <kconsul@linux.vnet.ibm.com>
To: Michael Ellerman <mpe@ellerman.id.au>,
	Nicholas Piggin <npiggin@gmail.com>,
	Christophe Leroy <christophe.leroy@csgroup.eu>,
	Fabiano Rosas <farosas@linux.ibm.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Chao Peng <chao.p.peng@linux.intel.com>,
	Sean Christopherson <seanjc@google.com>
Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org,
	Kautuk Consul <kconsul@linux.vnet.ibm.com>
Subject: [PATCH] KVM: PPC: BOOK3S: book3s_hv_nested.c: improve branch prediction for k.alloc
Date: Fri,  7 Apr 2023 05:31:47 -0400	[thread overview]
Message-ID: <20230407093147.3646597-1-kconsul@linux.vnet.ibm.com> (raw)

I used the unlikely() macro on the return values of the k.alloc
calls and found that it changes the code generation a bit.
Optimize all return paths of k.alloc calls by improving
branch prediction on return value of k.alloc.

Signed-off-by: Kautuk Consul <kconsul@linux.vnet.ibm.com>
---
 arch/powerpc/kvm/book3s_hv_nested.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/powerpc/kvm/book3s_hv_nested.c b/arch/powerpc/kvm/book3s_hv_nested.c
index 5a64a1341e6f..dbf2dd073e1f 100644
--- a/arch/powerpc/kvm/book3s_hv_nested.c
+++ b/arch/powerpc/kvm/book3s_hv_nested.c
@@ -446,7 +446,7 @@ long kvmhv_nested_init(void)
 		ptb_order = 12;
 	pseries_partition_tb = kmalloc(sizeof(struct patb_entry) << ptb_order,
 				       GFP_KERNEL);
-	if (!pseries_partition_tb) {
+	if (unlikely(!pseries_partition_tb)) {
 		pr_err("kvm-hv: failed to allocated nested partition table\n");
 		return -ENOMEM;
 	}
@@ -575,7 +575,7 @@ long kvmhv_copy_tofrom_guest_nested(struct kvm_vcpu *vcpu)
 		return H_PARAMETER;
 
 	buf = kzalloc(n, GFP_KERNEL | __GFP_NOWARN);
-	if (!buf)
+	if (unlikely(!buf))
 		return H_NO_MEM;
 
 	gp = kvmhv_get_nested(vcpu->kvm, l1_lpid, false);
@@ -689,7 +689,7 @@ static struct kvm_nested_guest *kvmhv_alloc_nested(struct kvm *kvm, unsigned int
 	long shadow_lpid;
 
 	gp = kzalloc(sizeof(*gp), GFP_KERNEL);
-	if (!gp)
+	if (unlikely(!gp))
 		return NULL;
 	gp->l1_host = kvm;
 	gp->l1_lpid = lpid;
@@ -1633,7 +1633,7 @@ static long int __kvmhv_nested_page_fault(struct kvm_vcpu *vcpu,
 	/* 4. Insert the pte into our shadow_pgtable */
 
 	n_rmap = kzalloc(sizeof(*n_rmap), GFP_KERNEL);
-	if (!n_rmap)
+	if (unlikely(!n_rmap))
 		return RESUME_GUEST; /* Let the guest try again */
 	n_rmap->rmap = (n_gpa & RMAP_NESTED_GPA_MASK) |
 		(((unsigned long) gp->l1_lpid) << RMAP_NESTED_LPID_SHIFT);
-- 
2.39.2


             reply	other threads:[~2023-04-07  9:32 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-07  9:31 Kautuk Consul [this message]
2023-04-07 13:46 ` Bagas Sanjaya
2023-04-07 16:01   ` Sean Christopherson
2023-04-11  4:59     ` Kautuk Consul
2023-04-11  6:35       ` Michael Ellerman
     [not found]         ` <CAKWYkK0hjMiP7yJWWjWX8CqS1Lcqi2z4P1bzj14-AU8SzBkYqw@mail.gmail.com>
2023-04-11  9:04           ` Kautuk Consul
2023-04-12  7:04         ` Kautuk Consul
2023-04-19 10:08           ` Kautuk Consul

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230407093147.3646597-1-kconsul@linux.vnet.ibm.com \
    --to=kconsul@linux.vnet.ibm.com \
    --cc=chao.p.peng@linux.intel.com \
    --cc=christophe.leroy@csgroup.eu \
    --cc=farosas@linux.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=mpe@ellerman.id.au \
    --cc=npiggin@gmail.com \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®