From patchwork Fri Feb 17 00:49:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 58311 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp618376wrn; Thu, 16 Feb 2023 16:59:07 -0800 (PST) X-Google-Smtp-Source: AK7set9Y0GJzNxEmtsK94I6bShbT9g2Xq+r7IX63Jpc4UQx8E+KxgWczFTTN98wR8GuoCYRQlrQ1 X-Received: by 2002:a05:6a20:4c12:b0:c7:684a:e4ae with SMTP id fm18-20020a056a204c1200b000c7684ae4aemr1167633pzb.15.1676595547425; Thu, 16 Feb 2023 16:59:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676595547; cv=none; d=google.com; s=arc-20160816; b=HpBnfv/D1McOGr80QuBzw/6nYMFtA1s44pIe7xTLXdFKJr2WqHiXfIqmUhFOLxv6cr gz7vTOdJV7d/mL1zjLUj0V0rsCMhrO+1tHtDWILVeeYkhWLS6/W1ZhwwWv4eu3ppPI/3 sOFttBvdNerrFn+TYxyXTmyTseEFaNyLh1eQX0Z0/woCVuSkNnTfZ9nhMyVbbD45j63b B+JJscvFh3FeQyFOWZIASwqDmBeN36Ht7aK6bcrCbgEVW6kTPktPcQ1dXHj0Szs/bmZk NmnBDACjnY3Vc+q/ze+hKuwY5yXCQ0oxKSxgt0wgML3QZRnH2VLgybbjN5wTeoIhypM4 EBag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:feedback-id:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=yLb16cvavpJmJcg3+UwmMJOFkV8ahMSMr+EDxcMpkho=; b=sQpmdWleiKBkXdjtEutXtPD44xYgyn66irf9bxqzOGcs2V3OyWe1c8Y7RO2gj33MP2 gdq0fIq9VVAnH+xJ42mLC39LiM7hFPkGiZpyD98AmpWVDOtfP1plwEbJTkt2OYHwuzbS ZlFGFV4wPPJNtIcQLI+r2Cf8IpweD0t4N6KXjnwqhCidOvXWY80fG0mDi7Bcrymx6J9z GaZUep9nAS/U0trq3S1CfdpTYcgDbPRxL5v49/wTOSXoopISH4N4i5wYdbs3OJxYbNsf CPX4OKSq4JDyKkDbs8JHEtwgBqD95bRjlaN9O8NvNYP+P9ATbG8xMNlYBL2/c5G3mfQ9 GrYA== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i191-20020a6387c8000000b004fb7d5d316esi3375787pge.404.2023.02.16.16.58.54; Thu, 16 Feb 2023 16:59:07 -0800 (PST) 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 S229620AbjBQAxD (ORCPT + 99 others); Thu, 16 Feb 2023 19:53:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229482AbjBQAxB (ORCPT ); Thu, 16 Feb 2023 19:53:01 -0500 Received: from smtpbg153.qq.com (smtpbg153.qq.com [13.245.218.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6FAA27DAB; Thu, 16 Feb 2023 16:52:49 -0800 (PST) X-QQ-mid: bizesmtp76t1676594981tzj20bxn Received: from localhost.localdomain ( [116.30.131.224]) by bizesmtp.qq.com (ESMTP) with id ; Fri, 17 Feb 2023 08:49:37 +0800 (CST) X-QQ-SSF: 01200000000000C0T000000A0000000 X-QQ-FEAT: HH6/KuQOBEYape0K7eNPpGClNte1p9KwHz5G63svXw4+DTBNwFMoPpE5XUhx6 05cCvEABd10oan5cv3LUnUMcUAHqyNqZq4+jTSCoUmilAXTQ9duURc8/ruw7SY6oor0tBev RoFEB3fWfD1W8TD67x5MtiQ+DjwwcYO78oT04ndKAyzBOChBjxfUcAYeQ4FX5k0S5OoK8Ox gFEhgXjlsxlrY99cZIG/3rP3A79PqE/96cPTSu6w0R+hXn7r4u9vMv+S2yzV/ofwTvSCq12 zwDKb63xgVmxw+JXjn9VgOf31CWsu7Tgnd7untYTG8+Nkyy+99r1iatC9zrXPQh7OdEa1UY DB2saWPTsE8kVbMerbuqMOpDMVViphDIwHBwBVQOPZPg8P/98pX6ELE5xO/vKjwq+wBju5K sOzMCFPNoHQ= X-QQ-GoodBg: 0 From: Zhangjin Wu To: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org Cc: Thomas Bogendoerfer , Palmer Dabbelt , Willy Tarreau , Paul Burton , "Paul E . McKenney" , Paul Walmsley , Nicholas Mc Guire , Zhangjin Wu Subject: [RFC PATCH 2/5] MIPS: Add dead syscalls elimination support Date: Fri, 17 Feb 2023 08:49:22 +0800 Message-Id: <29e5a037ac439c40970b40692286feb6f010f8f3.1676594211.git.falcon@tinylab.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvr:qybglogicsvr7 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758037852793947100?= X-GMAIL-MSGID: =?utf-8?q?1758037852793947100?= By enabling CONFIG_HAVE_LD_DEAD_CODE_DATA_ELIMINATION and setting CONFIG_SYSCALLS_USED, It is able to remove the left 'dead' syscalls. For example, if setting CONFIG_SYSCALLS_USED="write exit reboot", a 'used' variant of the *.tbl will be generated, accordingly, the kernel api unistd_nr_*.h and syscall_table_*.h will be generated from the 'used' *tbl variant. the user api version of unistd_*.h is reserved as-is. Here is a test result on qemu with a minimal malta config. | mipsel malta | config ----------------|-----------------|------------------- vmlinux | 5041628 | https://pastebin.com/0bE2ibLD + gc-sections | 4474060 (-11.2%)| CONFIG_HAVE_LD_DEAD_CODE_DATA_ELIMINATION=y + syscalls_used | 4265280 (-4.67%)| CONFIG_SYSCALLS_USED="_newselect" + syscalls_used | 4274364 (-4.46%)| CONFIG_SYSCALLS_USED="write exit reboot" notes: - The shrink ratios of the syscalls_used lines are based on the gc-sections line. - "write exit reboot" are used by a hello.c to simply print "Hello, World!", exit and shutdown qemu. - "_newselect" is used by rcutorture to do a long-time sleep. Signed-off-by: Zhangjin Wu --- arch/mips/Kconfig | 1 + arch/mips/kernel/syscalls/Makefile | 24 ++++++++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig index 15cb692b0a09..868d9a871b3e 100644 --- a/arch/mips/Kconfig +++ b/arch/mips/Kconfig @@ -102,6 +102,7 @@ config MIPS select TRACE_IRQFLAGS_SUPPORT select ARCH_HAS_ELFCORE_COMPAT select HAVE_ARCH_KCSAN if 64BIT + select HAVE_SYSCALLS_USED config MIPS_FIXUP_BIGPHYS_ADDR bool diff --git a/arch/mips/kernel/syscalls/Makefile b/arch/mips/kernel/syscalls/Makefile index e6b21de65cca..8ffba5301cf0 100644 --- a/arch/mips/kernel/syscalls/Makefile +++ b/arch/mips/kernel/syscalls/Makefile @@ -26,10 +26,30 @@ sysnr_pfx_unistd_nr_n32 := N32 sysnr_pfx_unistd_nr_n64 := 64 sysnr_pfx_unistd_nr_o32 := O32 -$(kapi)/unistd_nr_%.h: $(src)/syscall_%.tbl $(sysnr) FORCE +ifdef CONFIG_SYSCALLS_USED +syscalls_used := $(shell echo $(CONFIG_SYSCALLS_USED) | tr -s ' ' | tr ' ' '|') +endif + +ifneq ($(syscalls_used),) +utbl := arch/$(SRCARCH)/include/generated/tbl +_tbl := $(src)/syscall_%.tbl + tbl := $(utbl)/syscall_used_%.tbl + +$(shell mkdir -p $(utbl)) + +quiet_cmd_used = USED $@ + cmd_used = sed -E -e "/^[0-9]*[[:space:]]/{/(^($(syscalls_used))[[:space:]]|[[:space:]]($(syscalls_used))[[:space:]]|[[:space:]]($(syscalls_used))$$)/!{s/^/\#/g}}" $< > $@; + +$(tbl): $(_tbl) $(objtree)/.config + $(call cmd,used) +else +tbl := $(src)/syscall_%.tbl +endif + +$(kapi)/unistd_nr_%.h: $(tbl) $(sysnr) FORCE $(call if_changed,sysnr) -$(kapi)/syscall_table_%.h: $(src)/syscall_%.tbl $(systbl) FORCE +$(kapi)/syscall_table_%.h: $(tbl) $(systbl) FORCE $(call if_changed,systbl) uapisyshdr-y += unistd_n32.h \