Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp3659483iog; Tue, 21 Jun 2022 03:22:33 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vGBOJIHHXQUTWOwUTcmVVqSjlNaxv1UAw4a+SqHSkAN/P++uIOPb6y67hTP3Noa0fD1XjU X-Received: by 2002:a05:6402:2933:b0:435:80dd:f75c with SMTP id ee51-20020a056402293300b0043580ddf75cmr11373276edb.302.1655806952852; Tue, 21 Jun 2022 03:22:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655806952; cv=none; d=google.com; s=arc-20160816; b=bKBghkbCUTG6VCShxg9Oq2ThiMimvrc+2y8K5OrsXoRUEPXoVF8MsAYP1alXuINR9Y EmJDLVIbvpei9KNCP5F0e81NaDFrRS6W8Rmn6Oq8M8Asr8RrWyjHlDgVR6oHp/9fIjr2 zkGG+qJSbkgraEaW1OiYgN5lr8VyU902UI0SV+HwxlyWzu2aSYFBgALwRxZ5d6Mf/D+R gD9Qd68wjBmiVOTevuTJwaCgnbycjywsgxG6NoLIqNa8HCK7BLnTtq8D2WSqeFS3H7nC 1vWcCpeDN2M1LesMkquPpf7rxDrGG018vpDkDMuxdWAsP2Zb1Z5b2uUdJTgyV4HRNszZ 7Q6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=3lycRphMEgQNLyM34HMfiBCPAhd6xsyd+Wajcnm8no8=; b=uI5KvuwGvd7KFvByIk2+tjIgY5X0Hed6am+kxQW5NrjjODAE5XRduOoLBmxKsYc2KE hZl4L/5c0tYr3jUP5HpvkW9eE2MIqxRmQTJ+jBe7RBBBRxstlHxmxDAVWoqLSQbAK3NX ViAEiIhQsT4whIycpMhNFgr62n9dpBjwNgrEd1671edxSu92Ve5vdX8PbtwTZG3wiOQA jdZCiCApey6jarFVSduEV3yaXt8+imZBHZ1f968hZF+/1Z8MAgFF5VzLLd1FZJgct5v7 Lbr4nEl5njv/vtN8hI18125BUh3Ca4EAAqzYImaCshWgj2TsbLoqE9VAEPSA4EqiIx5B LeyA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z7-20020a05640240c700b0043595ef4ad2si1998448edb.414.2022.06.21.03.22.04; Tue, 21 Jun 2022 03:22:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349366AbiFUKAa (ORCPT + 99 others); Tue, 21 Jun 2022 06:00:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39686 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349359AbiFUKAI (ORCPT ); Tue, 21 Jun 2022 06:00:08 -0400 Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0CB0427FCF for ; Tue, 21 Jun 2022 03:00:05 -0700 (PDT) Received: from linux.localdomain (unknown [113.200.148.30]) by mail.loongson.cn (Coremail) with SMTP id AQAAf9DxX06hlrFi26RRAA--.25344S4; Tue, 21 Jun 2022 18:00:04 +0800 (CST) From: Tiezhu Yang To: Huacai Chen , WANG Xuerui Cc: Xuefeng Li , Jianmin Lv , Jun Yi , Rui Wang , linux-kernel@vger.kernel.org Subject: [PATCH 2/2] LoongArch: No need to call RESTORE_ALL_AND_RET for all syscalls Date: Tue, 21 Jun 2022 18:00:01 +0800 Message-Id: <1655805601-16677-3-git-send-email-yangtiezhu@loongson.cn> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1655805601-16677-1-git-send-email-yangtiezhu@loongson.cn> References: <1655805601-16677-1-git-send-email-yangtiezhu@loongson.cn> X-CM-TRANSID: AQAAf9DxX06hlrFi26RRAA--.25344S4 X-Coremail-Antispam: 1UD129KBjvJXoWxGFyrCryDtFW8Aw1kJrWkWFg_yoW5CF17pF ZFyFnYkr4vgrn7Ary3KFyv9rZxAws7GF43WF40krWruw1kXrn8Xr4vya4qqFnrtw4FgrW0 qFWrXwnYgas8XaUanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUBS14x267AKxVW5JVWrJwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_Jryl82xGYIkIc2 x26xkF7I0E14v26r4j6ryUM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0 Y4vE2Ix0cI8IcVAFwI0_Xr0_Ar1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJw A2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq3wAS 0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2 IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Gr0_Cr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0 Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwCY02Avz4vE14v_Gw1l42xK82 IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC2 0s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r126r1DMIIYrxkI7VAKI48JMI IF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF 0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87 Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjfUjVysUUUUU X-CM-SenderInfo: p1dqw3xlh2x3gn0dqz5rrqw2lrqou0/ X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 [1]: 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 --- 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 #include #include +#include .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