From patchwork Thu Sep 15 09:09:29 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 670286 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3sZXhT2Z3dz9s9N for ; Thu, 15 Sep 2016 19:11:05 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=Xw03baVp; dkim-atps=neutral Received: from ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3sZXhT1JW5zDsX5 for ; Thu, 15 Sep 2016 19:11:05 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=Xw03baVp; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Received: from mail-pa0-x243.google.com (mail-pa0-x243.google.com [IPv6:2607:f8b0:400e:c03::243]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3sZXft4SKTzDrfR for ; Thu, 15 Sep 2016 19:09:42 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=Xw03baVp; dkim-atps=neutral Received: by mail-pa0-x243.google.com with SMTP id p2so1888781pap.3 for ; Thu, 15 Sep 2016 02:09:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=SnyL8U1HJ9AeA1QjCfa5L2DuuGRSsBind/ahmrSrE2A=; b=Xw03baVp2LAqLJf5QTwfBxtt3iYXPS4PBaI+Ssmu/J68BwJJGqv5jASYln2LFLw2aD +0g/1ICQ6phv5FIDBk0a9RVEhtJ5uRjj3bKXrZq8ECojDIr3YZapJ+gvdv38EnW8chZo qnVYZvgyeLBwU8zZMZXdSr3rNnrjIC4lt1hSWXBqZSC7RsBUAPFToSYE6elOi+OrG7Is vxFFD3lDU7T/pBJDN78/fvXRmyFHoveCrXGvKgAxLQ8I05JcgyoD/+wkvttE8e/oaiPK bkvrgtvxOy+bDkX4FQ06ezmm6JN3Ofs/wJM7QN5E2HmscT8z4YoLTWNBpy+GLZx11Zjh CXqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=SnyL8U1HJ9AeA1QjCfa5L2DuuGRSsBind/ahmrSrE2A=; b=i42FAVSTVEseYjWVHnBSf1kmWwjE8lZCepQqfWXv00BBZgf2vcBmTHramE0yAe3l8U /JcrnB4VGKTIY/cQwBpIiP3K9rCzk7Yy57tRb7XBU4ZXInrXvg1D+adeKG64UiBbdazG 0F1XfAwBoV+zlI6JOnTCAEboX5EnHyXlKK/HCLcRweO8uxo7J3z/dwztPu+f56urdS4M c4wDHqqsxaSaQ1x/GTJS/17srE/+GIcrdFUvcSXpSN8voOymPdEPDQId6VyVQo9bWEyQ QAhRVrlnLYkLo76Xu0B5I3EHOOCBUPd9YSkU8EtvFQcYMp/PbcrCoyW/gYM2Eyh75TlD LEUQ== X-Gm-Message-State: AE9vXwNSU924eaDDwbEY9EcZOXs3A1b/vtzNILROOFAZ9pKbHTu/GAps5rS4SR1eHKCOiQ== X-Received: by 10.66.100.225 with SMTP id fb1mr12662695pab.4.1473930580820; Thu, 15 Sep 2016 02:09:40 -0700 (PDT) Received: from roar.ozlabs.ibm.com ([122.99.82.10]) by smtp.gmail.com with ESMTPSA id y3sm43576386pfy.36.2016.09.15.02.09.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Sep 2016 02:09:40 -0700 (PDT) From: Nicholas Piggin To: linuxppc-dev@lists.ozlabs.org Subject: [PATCH][RFC] powerpc/64: exception exit do not reload SRR[01] if unchanged Date: Thu, 15 Sep 2016 19:09:29 +1000 Message-Id: <20160915090929.1380-1-npiggin@gmail.com> X-Mailer: git-send-email 2.9.3 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Nicholas Piggin Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" This is not ready yet, but it's a proof of concept for the approach to speed up exception exit: avoid the mtspr instructions if the yare not required. This saves 20 cycles per call on a getppid syscall microbenchmark, so it seems worth looking into. A few issues to be solved. Firstly, realmode exceptions use an rfid to switch on relocation and branch to common handler. This trashes SRR[01], so realmode exceptions will always miss and be pessimised with this patch. We can avoid that by doing a bctr to 0xc000... from realmode to enter the handler, and then use mtmsrd to switch on relocation. The ISA actually suggests this might be faster in some implementations, and on POWER8 it does seem to be faster by about 6 cycles. Secondly, avoiding the mfsprs would be nice if possible, and should give a couple more cycles. We could use a byte in the paca to track whether the SPRs are valid for the current exception. Anything modifying SPRs including nested exceptions would clear the bit when they're done. This is a bit more intrusive. Finally, should gather some statistics for success vs failure. --- arch/powerpc/kernel/entry_64.S | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/arch/powerpc/kernel/entry_64.S b/arch/powerpc/kernel/entry_64.S index 585b9ca..c836967 100644 --- a/arch/powerpc/kernel/entry_64.S +++ b/arch/powerpc/kernel/entry_64.S @@ -250,12 +250,21 @@ BEGIN_FTR_SECTION END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR) ld r13,GPR13(r1) /* only restore r13 if returning to usermode */ -1: ld r2,GPR2(r1) +1: + mfspr r11,SPRN_SRR0 + mfspr r12,SPRN_SRR1 + cmpld r7,r11 + beq 5f + mtspr SPRN_SRR0,r7 +5: + cmpld r8,r12 + beq 6f + mtspr SPRN_SRR1,r8 +6: + ld r2,GPR2(r1) ld r1,GPR1(r1) mtlr r4 mtcr r5 - mtspr SPRN_SRR0,r7 - mtspr SPRN_SRR1,r8 RFI b . /* prevent speculative execution */ @@ -859,12 +868,21 @@ END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR) ACCOUNT_CPU_USER_EXIT(r13, r2, r4) REST_GPR(13, r1) 1: + mfspr r0,SPRN_SRR0 + mfspr r2,SPRN_SRR1 + ld r4,_NIP(r1) + + cmpld r0,r4 + beq 5f + mtspr SPRN_SRR0,r4 +5: + cmpld r2,r3 + beq 6f mtspr SPRN_SRR1,r3 +6: ld r2,_CCR(r1) mtcrf 0xFF,r2 - ld r2,_NIP(r1) - mtspr SPRN_SRR0,r2 ld r0,GPR0(r1) ld r2,GPR2(r1)