From: Tiezhu Yang <yangtiezhu@loongson.cn>
To: Huacai Chen <chenhuacai@kernel.org>, WANG Xuerui <kernel@xen0n.name>
Cc: Xuefeng Li <lixuefeng@loongson.cn>,
Jianmin Lv <lvjianmin@loongson.cn>, Jun Yi <yijun@loongson.cn>,
Rui Wang <wangrui@loongson.cn>,
linux-kernel@vger.kernel.org
Subject: [PATCH v2 2/2] LoongArch: No need to call RESTORE_ALL_AND_RET for all syscalls
Date: Tue, 21 Jun 2022 18:07:54 +0800 [thread overview]
Message-ID: <1655806074-17454-3-git-send-email-yangtiezhu@loongson.cn> (raw)
In-Reply-To: <1655806074-17454-1-git-send-email-yangtiezhu@loongson.cn>
In handle_syscall, it is unnecessary to call RESTORE_ALL_AND_RET
for all syscalls.
(1) rt_sigreturn call RESTORE_ALL_AND_RET.
(2) The other syscalls call RESTORE_STATIC_SOME_SP_AND_RET.
This patch only adds the minimal changes as simple as possible
to reduce the code complexity, at the same time, it can reduce
many load instructions.
Here are the test environments:
Hardware: Loongson-LS3A5000-7A1000-1w-A2101
Firmware: UDK2018-LoongArch-A2101-pre-beta8 [1]
System: loongarch64-clfs-system-5.0 [2]
The system passed functional testing used with the following
test case without and with this patch:
git clone https://github.com/hevz/sigaction-test.git
cd sigaction-test
make check
Additionally, use UnixBench syscall to test the performance:
git clone https://github.com/kdlucas/byte-unixbench.git
cd byte-unixbench/UnixBench/
make
pgms/syscall 600
In order to avoid the performance impact, add init=/bin/bash
to the boot cmdline.
Here is the test result, the bigger the better, it shows about
1.2% gain tested with close, getpid and exec [3]:
duration without_this_patch with_this_patch
600 s 626558267 lps 634244079 lps
[1] https://github.com/loongson/Firmware/tree/main/5000Series/PC/A2101
[2] https://github.com/sunhaiyong1978/CLFS-for-LoongArch/releases/tag/5.0
[3] https://github.com/kdlucas/byte-unixbench/blob/master/UnixBench/src/syscall.c
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
---
arch/loongarch/include/asm/stackframe.h | 5 +++++
arch/loongarch/kernel/entry.S | 15 +++++++++++++++
2 files changed, 20 insertions(+)
diff --git a/arch/loongarch/include/asm/stackframe.h b/arch/loongarch/include/asm/stackframe.h
index 4ca9530..551ab8f 100644
--- a/arch/loongarch/include/asm/stackframe.h
+++ b/arch/loongarch/include/asm/stackframe.h
@@ -216,4 +216,9 @@
RESTORE_SP_AND_RET \docfi
.endm
+ .macro RESTORE_STATIC_SOME_SP_AND_RET docfi=0
+ RESTORE_STATIC \docfi
+ RESTORE_SOME \docfi
+ RESTORE_SP_AND_RET \docfi
+ .endm
#endif /* _ASM_STACKFRAME_H */
diff --git a/arch/loongarch/kernel/entry.S b/arch/loongarch/kernel/entry.S
index d5b3dbc..c764c99 100644
--- a/arch/loongarch/kernel/entry.S
+++ b/arch/loongarch/kernel/entry.S
@@ -14,6 +14,7 @@
#include <asm/regdef.h>
#include <asm/stackframe.h>
#include <asm/thread_info.h>
+#include <asm/unistd.h>
.text
.cfi_sections .debug_frame
@@ -62,9 +63,23 @@ SYM_FUNC_START(handle_syscall)
li.d tp, ~_THREAD_MASK
and tp, tp, sp
+ /* Syscall number held in a7, we can store it in TI_SYSCALL. */
+ LONG_S a7, tp, TI_SYSCALL
+
move a0, sp
bl do_syscall
+ /*
+ * Syscall number held in a7 which is stored in TI_SYSCALL.
+ * rt_sigreturn call RESTORE_ALL_AND_RET.
+ * The other syscalls call RESTORE_STATIC_SOME_SP_AND_RET.
+ */
+ LONG_L t3, tp, TI_SYSCALL
+ li.w t4, __NR_rt_sigreturn
+ beq t3, t4, 1f
+
+ RESTORE_STATIC_SOME_SP_AND_RET
+1:
RESTORE_ALL_AND_RET
SYM_FUNC_END(handle_syscall)
--
2.1.0
next prev parent reply other threads:[~2022-06-21 10:08 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-21 10:07 [PATCH v2 0/2] LoongArch: Modify handle_syscall Tiezhu Yang
2022-06-21 10:07 ` [PATCH v2 1/2] LoongArch: Add TI_SYSCALL in output_thread_info_defines() Tiezhu Yang
2022-06-21 10:07 ` Tiezhu Yang [this message]
2022-06-22 10:01 ` [PATCH v2 2/2] LoongArch: No need to call RESTORE_ALL_AND_RET for all syscalls Huacai Chen
2022-06-23 0:43 ` Tiezhu Yang
2022-06-25 2:09 ` Tiezhu Yang
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=1655806074-17454-3-git-send-email-yangtiezhu@loongson.cn \
--to=yangtiezhu@loongson.cn \
--cc=chenhuacai@kernel.org \
--cc=kernel@xen0n.name \
--cc=linux-kernel@vger.kernel.org \
--cc=lixuefeng@loongson.cn \
--cc=lvjianmin@loongson.cn \
--cc=wangrui@loongson.cn \
--cc=yijun@loongson.cn \
/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;
as well as URLs for NNTP newsgroup(s).