From: Zhen Lei <thunder.leizhen@huawei.com>
To: Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will@kernel.org>,
linux-arm-kernel <linux-arm-kernel@lists.infradead.org>,
<linux-kernel@vger.kernel.org>
Cc: Zhen Lei <thunder.leizhen@huawei.com>,
Mark Rutland <mark.rutland@arm.com>
Subject: [PATCH] arm64: entry: Improve the performance of system calls
Date: Fri, 3 Sep 2021 20:19:50 +0800 [thread overview]
Message-ID: <20210903121950.2284-1-thunder.leizhen@huawei.com> (raw)
Commit 582f95835a8f ("arm64: entry: convert el0_sync to C") converted lots
of functions from assembly to C, this greatly improves readability. But
el0_svc()/el0_svc_compat() is in response to system call requests from
user mode and may be in the hot path.
Although the SVC is in the first case of the switch statement in C, the
compiler optimizes the switch statement as a whole, and does not give SVC
a small boost.
Use "likely()" to help SVC directly invoke its handler after a simple
judgment to avoid entering the switch table lookup process.
After:
0000000000000ff0 <el0t_64_sync_handler>:
ff0: d503245f bti c
ff4: d503233f paciasp
ff8: a9bf7bfd stp x29, x30, [sp, #-16]!
ffc: 910003fd mov x29, sp
1000: d5385201 mrs x1, esr_el1
1004: 531a7c22 lsr w2, w1, #26
1008: f100545f cmp x2, #0x15
100c: 540000a1 b.ne 1020 <el0t_64_sync_handler+0x30>
1010: 97fffe14 bl 860 <el0_svc>
1014: a8c17bfd ldp x29, x30, [sp], #16
1018: d50323bf autiasp
101c: d65f03c0 ret
1020: f100705f cmp x2, #0x1c
Execute "./lat_syscall null" on my board (BogoMIPS : 200.00), it can save
about 10ns.
Before:
Simple syscall: 0.2365 microseconds
Simple syscall: 0.2354 microseconds
Simple syscall: 0.2339 microseconds
After:
Simple syscall: 0.2255 microseconds
Simple syscall: 0.2254 microseconds
Simple syscall: 0.2256 microseconds
Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
---
arch/arm64/kernel/entry-common.c | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
diff --git a/arch/arm64/kernel/entry-common.c b/arch/arm64/kernel/entry-common.c
index 32f9796c4ffe77b..062eb5a895ec6f3 100644
--- a/arch/arm64/kernel/entry-common.c
+++ b/arch/arm64/kernel/entry-common.c
@@ -607,11 +607,14 @@ static void noinstr el0_fpac(struct pt_regs *regs, unsigned long esr)
asmlinkage void noinstr el0t_64_sync_handler(struct pt_regs *regs)
{
unsigned long esr = read_sysreg(esr_el1);
+ unsigned long ec = ESR_ELx_EC(esr);
- switch (ESR_ELx_EC(esr)) {
- case ESR_ELx_EC_SVC64:
+ if (likely(ec == ESR_ELx_EC_SVC64)) {
el0_svc(regs);
- break;
+ return;
+ }
+
+ switch (ec) {
case ESR_ELx_EC_DABT_LOW:
el0_da(regs, esr);
break;
@@ -730,11 +733,14 @@ static void noinstr el0_svc_compat(struct pt_regs *regs)
asmlinkage void noinstr el0t_32_sync_handler(struct pt_regs *regs)
{
unsigned long esr = read_sysreg(esr_el1);
+ unsigned long ec = ESR_ELx_EC(esr);
- switch (ESR_ELx_EC(esr)) {
- case ESR_ELx_EC_SVC32:
+ if (likely(ec == ESR_ELx_EC_SVC32)) {
el0_svc_compat(regs);
- break;
+ return;
+ }
+
+ switch (ec) {
case ESR_ELx_EC_DABT_LOW:
el0_da(regs, esr);
break;
--
2.25.1
next reply other threads:[~2021-09-03 12:22 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-03 12:19 Zhen Lei [this message]
2021-09-13 23:01 ` Punit Agrawal
2021-09-14 2:01 ` Leizhen (ThunderTown)
2021-09-14 9:55 ` Mark Rutland
2021-09-14 11:23 ` Leizhen (ThunderTown)
2021-09-14 11:48 ` Leizhen (ThunderTown)
2021-09-14 15:17 ` Joey Gouly
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=20210903121950.2284-1-thunder.leizhen@huawei.com \
--to=thunder.leizhen@huawei.com \
--cc=catalin.marinas@arm.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=will@kernel.org \
/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®