diff mbox series

[v3] RISC-V: Enable dead code elimination

Message ID 20230517082936.37563-1-falcon@tinylab.org (mailing list archive)
State Superseded
Headers show
Series [v3] RISC-V: Enable dead code elimination | expand

Checks

Context Check Description
conchuod/cover_letter success Single patches do not need cover letters
conchuod/tree_selection success Guessed tree name to be for-next at HEAD ac9a78681b92
conchuod/fixes_present success Fixes tag not required for -next series
conchuod/maintainers_pattern success MAINTAINERS pattern errors before the patch: 6 and now 6
conchuod/verify_signedoff success Signed-off-by tag matches author and committer
conchuod/kdoc success Errors and warnings before: 0 this patch: 0
conchuod/build_rv64_clang_allmodconfig success Errors and warnings before: 627 this patch: 14
conchuod/module_param success Was 0 now: 0
conchuod/build_rv64_gcc_allmodconfig success Errors and warnings before: 2506 this patch: 28
conchuod/build_rv32_defconfig success Build OK
conchuod/dtb_warn_rv64 success Errors and warnings before: 3 this patch: 3
conchuod/header_inline success No static functions without inline keyword in header files
conchuod/checkpatch success total: 0 errors, 0 warnings, 0 checks, 15 lines checked
conchuod/build_rv64_nommu_k210_defconfig success Build OK
conchuod/verify_fixes success No Fixes tag
conchuod/build_rv64_nommu_virt_defconfig success Build OK

Commit Message

Zhangjin Wu May 17, 2023, 8:29 a.m. UTC
Select CONFIG_HAVE_LD_DEAD_CODE_DATA_ELIMINATION for RISC-V, allowing
the user to enable dead code elimination. In order for this to work,
ensure that we keep the alternative table by annotating them with KEEP.

This boots well on qemu with both rv32_defconfig & rv64 defconfig, but
it only shrinks their builds by ~1%, a smaller config is thereforce
customized to test this feature:

          | rv32                   | rv64
  --------|------------------------|---------------------
   No DCE | 4460684                | 4893488
      DCE | 3986716                | 4376400
   Shrink |  473968 (~10.6%)       |  517088 (~10.5%)

The config used above only reserves necessary options to boot on qemu
with serial console, more like the size-critical embedded scenes:

  - rv64 config: https://pastebin.com/crz82T0s
  - rv32 config: rv64 config + 32-bit.config

Signed-off-by: Zhangjin Wu <falcon@tinylab.org>
---
 arch/riscv/Kconfig              | 1 +
 arch/riscv/kernel/vmlinux.lds.S | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

Comments

Zhangjin Wu May 17, 2023, 8:41 a.m. UTC | #1
Hello, Maintainers

No changes from v2 to v3, only rebased on v6.4-rc2, it compiled and
booted.

This is part of my tinylinux work for RISC-V, the other patches are
coming soon.

Thanks,
Zhangjin Wu

> Select CONFIG_HAVE_LD_DEAD_CODE_DATA_ELIMINATION for RISC-V, allowing
> the user to enable dead code elimination. In order for this to work,
> ensure that we keep the alternative table by annotating them with KEEP.
> 
> This boots well on qemu with both rv32_defconfig & rv64 defconfig, but
> it only shrinks their builds by ~1%, a smaller config is thereforce
> customized to test this feature:
> 
>           | rv32                   | rv64
>   --------|------------------------|---------------------
>    No DCE | 4460684                | 4893488
>       DCE | 3986716                | 4376400
>    Shrink |  473968 (~10.6%)       |  517088 (~10.5%)
> 
> The config used above only reserves necessary options to boot on qemu
> with serial console, more like the size-critical embedded scenes:
> 
>   - rv64 config: https://pastebin.com/crz82T0s
>   - rv32 config: rv64 config + 32-bit.config
> 
> Signed-off-by: Zhangjin Wu <falcon@tinylab.org>
> ---
>  arch/riscv/Kconfig              | 1 +
>  arch/riscv/kernel/vmlinux.lds.S | 2 +-
>  2 files changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
> index 348c0fa1fc8c..d2eb1a862ea8 100644
> --- a/arch/riscv/Kconfig
> +++ b/arch/riscv/Kconfig
> @@ -111,6 +111,7 @@ config RISCV
>  	select HAVE_KPROBES_ON_FTRACE if !XIP_KERNEL
>  	select HAVE_KRETPROBES if !XIP_KERNEL
>  	select HAVE_RETHOOK if !XIP_KERNEL
> +	select HAVE_LD_DEAD_CODE_DATA_ELIMINATION
>  	select HAVE_MOVE_PMD
>  	select HAVE_MOVE_PUD
>  	select HAVE_PCI
> diff --git a/arch/riscv/kernel/vmlinux.lds.S b/arch/riscv/kernel/vmlinux.lds.S
> index e5f9f4677bbf..0f5dfbc113d4 100644
> --- a/arch/riscv/kernel/vmlinux.lds.S
> +++ b/arch/riscv/kernel/vmlinux.lds.S
> @@ -112,7 +112,7 @@ SECTIONS
>  	. = ALIGN(8);
>  	.alternative : {
>  		__alt_start = .;
> -		*(.alternative)
> +		KEEP(*(.alternative))
>  		__alt_end = .;
>  	}
>  	__init_end = .;
Guo Ren May 21, 2023, 2:23 a.m. UTC | #2
> 
> Select CONFIG_HAVE_LD_DEAD_CODE_DATA_ELIMINATION for RISC-V, allowing
> the user to enable dead code elimination. In order for this to work,
> ensure that we keep the alternative table by annotating them with KEEP.
> 
> This boots well on qemu with both rv32_defconfig & rv64 defconfig, but
> it only shrinks their builds by ~1%, a smaller config is thereforce
> customized to test this feature:
> 
>           | rv32                   | rv64
>   --------|------------------------|---------------------
>    No DCE | 4460684                | 4893488
>       DCE | 3986716                | 4376400
>    Shrink |  473968 (~10.6%)       |  517088 (~10.5%)
Good point and other arch also support the feature e.g. commit:
c0436b503591 ("MIPS: Enable dead code elimination")

Reviewed-by: Guo Ren <guoren@kernel.org>

> 
> The config used above only reserves necessary options to boot on qemu
> with serial console, more like the size-critical embedded scenes:
> 
>   - rv64 config: https://pastebin.com/crz82T0s
>   - rv32 config: rv64 config + 32-bit.config
> 
> Signed-off-by: Zhangjin Wu <falcon@tinylab.org>
> ---
>  arch/riscv/Kconfig              | 1 +
>  arch/riscv/kernel/vmlinux.lds.S | 2 +-
>  2 files changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
> index 348c0fa1fc8c..d2eb1a862ea8 100644
> --- a/arch/riscv/Kconfig
> +++ b/arch/riscv/Kconfig
> @@ -111,6 +111,7 @@ config RISCV
>  	select HAVE_KPROBES_ON_FTRACE if !XIP_KERNEL
>  	select HAVE_KRETPROBES if !XIP_KERNEL
>  	select HAVE_RETHOOK if !XIP_KERNEL
> +	select HAVE_LD_DEAD_CODE_DATA_ELIMINATION
>  	select HAVE_MOVE_PMD
>  	select HAVE_MOVE_PUD
>  	select HAVE_PCI
> diff --git a/arch/riscv/kernel/vmlinux.lds.S b/arch/riscv/kernel/vmlinux.lds.S
> index e5f9f4677bbf..0f5dfbc113d4 100644
> --- a/arch/riscv/kernel/vmlinux.lds.S
> +++ b/arch/riscv/kernel/vmlinux.lds.S
> @@ -112,7 +112,7 @@ SECTIONS
>  	. = ALIGN(8);
>  	.alternative : {
>  		__alt_start = .;
> -		*(.alternative)
> +		KEEP(*(.alternative))
>  		__alt_end = .;
>  	}
>  	__init_end = .;
> -- 
> 2.25.1
>
Bin Meng May 21, 2023, 4:09 a.m. UTC | #3
> Select CONFIG_HAVE_LD_DEAD_CODE_DATA_ELIMINATION for RISC-V, allowing
> the user to enable dead code elimination. In order for this to work,
> ensure that we keep the alternative table by annotating them with KEEP.
> 
> This boots well on qemu with both rv32_defconfig & rv64 defconfig, but
> it only shrinks their builds by ~1%, a smaller config is thereforce
> customized to test this feature:
> 
>           | rv32                   | rv64
>   --------|------------------------|---------------------
>    No DCE | 4460684                | 4893488
>       DCE | 3986716                | 4376400
>    Shrink |  473968 (~10.6%)       |  517088 (~10.5%)
> 
> The config used above only reserves necessary options to boot on qemu
> with serial console, more like the size-critical embedded scenes:
> 
>   - rv64 config: https://pastebin.com/crz82T0s
>   - rv32 config: rv64 config + 32-bit.config
> 
> Signed-off-by: Zhangjin Wu <falcon@tinylab.org>
> ---
>  arch/riscv/Kconfig              | 1 +
>  arch/riscv/kernel/vmlinux.lds.S | 2 +-
>  2 files changed, 2 insertions(+), 1 deletion(-)

Tested-by: Bin Meng <bmeng@tinylab.org>
Jisheng Zhang May 21, 2023, 8:48 a.m. UTC | #4
On Wed, May 17, 2023 at 04:29:36PM +0800, Zhangjin Wu wrote:
> Select CONFIG_HAVE_LD_DEAD_CODE_DATA_ELIMINATION for RISC-V, allowing
> the user to enable dead code elimination. In order for this to work,
> ensure that we keep the alternative table by annotating them with KEEP.
> 
> This boots well on qemu with both rv32_defconfig & rv64 defconfig, but
> it only shrinks their builds by ~1%, a smaller config is thereforce
> customized to test this feature:

OOPS, I didn't noticed that you have sent out the patch and you are now
in v3. I may read your patch sevral months ago, but I forget it.
But your version missed an important preparation patch which is
to fix the typo in commom vmlinux.lds.h in asm-generic, thus LD_ORPHAN_WARN
will warn loudly. See[1] for more details.

Another missing point is we need to keep the .init.pi* and .init.bss*
sections. See[1] for more details.

Since you are the first person to send out the patch of
HAVE_LD_DEAD_CODE_DATA_ELIMINATION for riscv, do you mind if I update
my series and take your patch in my series v2, make you as the commmit
author, use your commit msg, and add my co-developped tag etc?

Thanks

> 
>           | rv32                   | rv64
>   --------|------------------------|---------------------
>    No DCE | 4460684                | 4893488
>       DCE | 3986716                | 4376400
>    Shrink |  473968 (~10.6%)       |  517088 (~10.5%)
> 
> The config used above only reserves necessary options to boot on qemu
> with serial console, more like the size-critical embedded scenes:
> 
>   - rv64 config: https://pastebin.com/crz82T0s
>   - rv32 config: rv64 config + 32-bit.config
> 
> Signed-off-by: Zhangjin Wu <falcon@tinylab.org>
> ---
>  arch/riscv/Kconfig              | 1 +
>  arch/riscv/kernel/vmlinux.lds.S | 2 +-
>  2 files changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
> index 348c0fa1fc8c..d2eb1a862ea8 100644
> --- a/arch/riscv/Kconfig
> +++ b/arch/riscv/Kconfig
> @@ -111,6 +111,7 @@ config RISCV
>  	select HAVE_KPROBES_ON_FTRACE if !XIP_KERNEL
>  	select HAVE_KRETPROBES if !XIP_KERNEL
>  	select HAVE_RETHOOK if !XIP_KERNEL
> +	select HAVE_LD_DEAD_CODE_DATA_ELIMINATION
>  	select HAVE_MOVE_PMD
>  	select HAVE_MOVE_PUD
>  	select HAVE_PCI
> diff --git a/arch/riscv/kernel/vmlinux.lds.S b/arch/riscv/kernel/vmlinux.lds.S
> index e5f9f4677bbf..0f5dfbc113d4 100644
> --- a/arch/riscv/kernel/vmlinux.lds.S
> +++ b/arch/riscv/kernel/vmlinux.lds.S
> @@ -112,7 +112,7 @@ SECTIONS
>  	. = ALIGN(8);
>  	.alternative : {
>  		__alt_start = .;
> -		*(.alternative)
> +		KEEP(*(.alternative))
>  		__alt_end = .;
>  	}
>  	__init_end = .;
> -- 
> 2.25.1
> 
> 
> _______________________________________________
> linux-riscv mailing list
> linux-riscv@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-riscv
Jisheng Zhang May 21, 2023, 8:51 a.m. UTC | #5
On Sun, May 21, 2023 at 04:48:47PM +0800, Jisheng Zhang wrote:
> On Wed, May 17, 2023 at 04:29:36PM +0800, Zhangjin Wu wrote:
> > Select CONFIG_HAVE_LD_DEAD_CODE_DATA_ELIMINATION for RISC-V, allowing
> > the user to enable dead code elimination. In order for this to work,
> > ensure that we keep the alternative table by annotating them with KEEP.
> > 
> > This boots well on qemu with both rv32_defconfig & rv64 defconfig, but
> > it only shrinks their builds by ~1%, a smaller config is thereforce
> > customized to test this feature:
> 
> OOPS, I didn't noticed that you have sent out the patch and you are now
> in v3. I may read your patch sevral months ago, but I forget it.
> But your version missed an important preparation patch which is
> to fix the typo in commom vmlinux.lds.h in asm-generic, thus LD_ORPHAN_WARN
> will warn loudly. See[1] for more details.
> 
> Another missing point is we need to keep the .init.pi* and .init.bss*
> sections. See[1] for more details.
> 
> Since you are the first person to send out the patch of
> HAVE_LD_DEAD_CODE_DATA_ELIMINATION for riscv, do you mind if I update
> my series and take your patch in my series v2, make you as the commmit
> author, use your commit msg, and add my co-developped tag etc?

forget to add Link reference:

[1] Link: https://lore.kernel.org/linux-riscv/20230511141211.2418-1-jszhang@kernel.org/

> 
> Thanks
> 
> > 
> >           | rv32                   | rv64
> >   --------|------------------------|---------------------
> >    No DCE | 4460684                | 4893488
> >       DCE | 3986716                | 4376400
> >    Shrink |  473968 (~10.6%)       |  517088 (~10.5%)
> > 
> > The config used above only reserves necessary options to boot on qemu
> > with serial console, more like the size-critical embedded scenes:
> > 
> >   - rv64 config: https://pastebin.com/crz82T0s
> >   - rv32 config: rv64 config + 32-bit.config
> > 
> > Signed-off-by: Zhangjin Wu <falcon@tinylab.org>
> > ---
> >  arch/riscv/Kconfig              | 1 +
> >  arch/riscv/kernel/vmlinux.lds.S | 2 +-
> >  2 files changed, 2 insertions(+), 1 deletion(-)
> > 
> > diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
> > index 348c0fa1fc8c..d2eb1a862ea8 100644
> > --- a/arch/riscv/Kconfig
> > +++ b/arch/riscv/Kconfig
> > @@ -111,6 +111,7 @@ config RISCV
> >  	select HAVE_KPROBES_ON_FTRACE if !XIP_KERNEL
> >  	select HAVE_KRETPROBES if !XIP_KERNEL
> >  	select HAVE_RETHOOK if !XIP_KERNEL
> > +	select HAVE_LD_DEAD_CODE_DATA_ELIMINATION
> >  	select HAVE_MOVE_PMD
> >  	select HAVE_MOVE_PUD
> >  	select HAVE_PCI
> > diff --git a/arch/riscv/kernel/vmlinux.lds.S b/arch/riscv/kernel/vmlinux.lds.S
> > index e5f9f4677bbf..0f5dfbc113d4 100644
> > --- a/arch/riscv/kernel/vmlinux.lds.S
> > +++ b/arch/riscv/kernel/vmlinux.lds.S
> > @@ -112,7 +112,7 @@ SECTIONS
> >  	. = ALIGN(8);
> >  	.alternative : {
> >  		__alt_start = .;
> > -		*(.alternative)
> > +		KEEP(*(.alternative))
> >  		__alt_end = .;
> >  	}
> >  	__init_end = .;
> > -- 
> > 2.25.1
> > 
> > 
> > _______________________________________________
> > linux-riscv mailing list
> > linux-riscv@lists.infradead.org
> > http://lists.infradead.org/mailman/listinfo/linux-riscv
Jisheng Zhang May 21, 2023, 9:08 a.m. UTC | #6
On Sun, May 21, 2023 at 04:51:14PM +0800, Jisheng Zhang wrote:
> On Sun, May 21, 2023 at 04:48:47PM +0800, Jisheng Zhang wrote:
> > On Wed, May 17, 2023 at 04:29:36PM +0800, Zhangjin Wu wrote:
> > > Select CONFIG_HAVE_LD_DEAD_CODE_DATA_ELIMINATION for RISC-V, allowing
> > > the user to enable dead code elimination. In order for this to work,
> > > ensure that we keep the alternative table by annotating them with KEEP.
> > > 
> > > This boots well on qemu with both rv32_defconfig & rv64 defconfig, but
> > > it only shrinks their builds by ~1%, a smaller config is thereforce
> > > customized to test this feature:
> > 
> > OOPS, I didn't noticed that you have sent out the patch and you are now
> > in v3. I may read your patch sevral months ago, but I forget it.
> > But your version missed an important preparation patch which is
> > to fix the typo in commom vmlinux.lds.h in asm-generic, thus LD_ORPHAN_WARN
> > will warn loudly. See[1] for more details.
> > 
> > Another missing point is we need to keep the .init.pi* and .init.bss*
> > sections. See[1] for more details.
> > 
> > Since you are the first person to send out the patch of
> > HAVE_LD_DEAD_CODE_DATA_ELIMINATION for riscv, do you mind if I update
> > my series and take your patch in my series v2, make you as the commmit
> > author, use your commit msg, and add my co-developped tag etc?

Another option is: I remove patch4 from my series and you send out an
updated version to fix the missing .init.pi* and .init.bss* KEEP.
> 
> forget to add Link reference:
> 
> [1] Link: https://lore.kernel.org/linux-riscv/20230511141211.2418-1-jszhang@kernel.org/
> 
> > 
> > Thanks
> > 
> > > 
> > >           | rv32                   | rv64
> > >   --------|------------------------|---------------------
> > >    No DCE | 4460684                | 4893488
> > >       DCE | 3986716                | 4376400
> > >    Shrink |  473968 (~10.6%)       |  517088 (~10.5%)
> > > 
> > > The config used above only reserves necessary options to boot on qemu
> > > with serial console, more like the size-critical embedded scenes:
> > > 
> > >   - rv64 config: https://pastebin.com/crz82T0s
> > >   - rv32 config: rv64 config + 32-bit.config
> > > 
> > > Signed-off-by: Zhangjin Wu <falcon@tinylab.org>
> > > ---
> > >  arch/riscv/Kconfig              | 1 +
> > >  arch/riscv/kernel/vmlinux.lds.S | 2 +-
> > >  2 files changed, 2 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
> > > index 348c0fa1fc8c..d2eb1a862ea8 100644
> > > --- a/arch/riscv/Kconfig
> > > +++ b/arch/riscv/Kconfig
> > > @@ -111,6 +111,7 @@ config RISCV
> > >  	select HAVE_KPROBES_ON_FTRACE if !XIP_KERNEL
> > >  	select HAVE_KRETPROBES if !XIP_KERNEL
> > >  	select HAVE_RETHOOK if !XIP_KERNEL
> > > +	select HAVE_LD_DEAD_CODE_DATA_ELIMINATION
> > >  	select HAVE_MOVE_PMD
> > >  	select HAVE_MOVE_PUD
> > >  	select HAVE_PCI
> > > diff --git a/arch/riscv/kernel/vmlinux.lds.S b/arch/riscv/kernel/vmlinux.lds.S
> > > index e5f9f4677bbf..0f5dfbc113d4 100644
> > > --- a/arch/riscv/kernel/vmlinux.lds.S
> > > +++ b/arch/riscv/kernel/vmlinux.lds.S
> > > @@ -112,7 +112,7 @@ SECTIONS
> > >  	. = ALIGN(8);
> > >  	.alternative : {
> > >  		__alt_start = .;
> > > -		*(.alternative)
> > > +		KEEP(*(.alternative))
> > >  		__alt_end = .;
> > >  	}
> > >  	__init_end = .;
> > > -- 
> > > 2.25.1
> > > 
> > > 
> > > _______________________________________________
> > > linux-riscv mailing list
> > > linux-riscv@lists.infradead.org
> > > http://lists.infradead.org/mailman/listinfo/linux-riscv
Zhangjin Wu May 21, 2023, 12:41 p.m. UTC | #7
Hi, Jisheng

> On Wed, May 17, 2023 at 04:29:36PM +0800, Zhangjin Wu wrote:
> > Select CONFIG_HAVE_LD_DEAD_CODE_DATA_ELIMINATION for RISC-V, allowing
> > the user to enable dead code elimination. In order for this to work,
> > ensure that we keep the alternative table by annotating them with KEEP.
> > 
> > This boots well on qemu with both rv32_defconfig & rv64 defconfig, but
> > it only shrinks their builds by ~1%, a smaller config is thereforce
> > customized to test this feature:
> 
> OOPS, I didn't noticed that you have sent out the patch and you are now
> in v3. I may read your patch sevral months ago, but I forget it.

Yeah, I have sent this patch several times, but beside the suggestion from
conor, I have gotten no more responses (before v3), I even thought RISC-V
people are not interested in or not require size shrinking ;-)

As I can see from the mailing list, Guoren just sent out a new series of
patchset [0] about size shrink (-16%), and include the one [1] from you, so,
I'm not alone, the left patchsets I'm working on and upstreaming include dead
syscall elimination [2], vdso configuration [3], nolibc for rv32 [4] and even
the self-decompress vmlinuz support (RFC v1 will be sent out next week), all of
these patchsets are result of my tinylinux [5] porting to RISC-V (got 334k
non-MMU rv64 vmlinuz+nolibc hello).

Is it ok to add you to my future CC list of the coming tinylinux
patchsets for RISC-V? welcome your review suggestions ;-)

From Guoren:
[0]: https://lore.kernel.org/linux-riscv/mhng-24855381-7da8-4c77-bcaf-a3a53c8cb38b@palmer-ri-x1c9/T/

From Jisheng:
[1]: https://lore.kernel.org/linux-riscv/20230511141211.2418-1-jszhang@kernel.org/

From Zhangjin:
[2]: https://lore.kernel.org/linux-riscv/cover.1676594211.git.falcon@tinylab.org/
[3]: https://lore.kernel.org/linux-riscv/cover.1684430522.git.falcon@tinylab.org/T/#t
[4]: https://lore.kernel.org/linux-riscv/cover.1684425792.git.falcon@tinylab.org/T/#t
[5]: http://elinux.org/Work_on_Tiny_Linux_Kernel

> But your version missed an important preparation patch which is
> to fix the typo in commom vmlinux.lds.h in asm-generic, thus LD_ORPHAN_WARN
> will warn loudly. See[1] for more details.
> 

ok, it is a great fix, .init.data.* are really critical sections, so, do we
need to select LD_ORPHAN_WARN by default for HAVE_LD_DEAD_CODE_DATA_ELIMINATION
to dig out such potential issues?

> Another missing point is we need to keep the .init.pi* and .init.bss*
> sections. See[1] for more details.
>

sorry, my v3 has forgotten re-checking the new changes of vmlinux.lds.S, just
checked it again, .init.bss* about efi was added from v6.2 and the .init.pi*
was really a new rv kernel feature from v6.3-rc1, just to mention, this may be
an important review part of the future vmlinux.lds.S changes: the sections
required but not explicitly used by any function or data must be KEEP'ed
manually, for more details, my old paper about kernel gc-sections [6] is a good
reference.

[6]: https://lwn.net/images/conf/rtlws-2011/proc/Yong.pdf

Another work I'm trying to do in toolchain side (in progress) is let the kernel
auto keep part of current KEEP'ed sections, this may eliminate more
functions/data and also reduce the maintain cost of manual KEEPing. This idea
derives from the coming RFC v2 of system call elimination patchset, some of the
unused syscalls can not be eliminated automatically because of the "rough"
exception table KEEPing.

> Since you are the first person to send out the patch of
> HAVE_LD_DEAD_CODE_DATA_ELIMINATION for riscv, do you mind if I update
> my series and take your patch in my series v2, make you as the commmit
> author, use your commit msg, and add my co-developped tag etc?
>

I have found that you have fixed up some other issues, It is better to
merge mine in your series, please don't forget the Tested-by line from
Bin Meng [7] and the Reviewed-by line from Guoren [8].

[7]: https://lore.kernel.org/linux-riscv/20230521040949.1411220-1-bmeng@tinylab.org/#t
[8]: https://lore.kernel.org/linux-riscv/20230521022313.3758709-1-guoren@kernel.org/

Thanks very much,
Zhangjin

> Thanks
> 
> > 
> >           | rv32                   | rv64
> >   --------|------------------------|---------------------
> >    No DCE | 4460684                | 4893488
> >       DCE | 3986716                | 4376400
> >    Shrink |  473968 (~10.6%)       |  517088 (~10.5%)
> > 
> > The config used above only reserves necessary options to boot on qemu
> > with serial console, more like the size-critical embedded scenes:
> > 
> >   - rv64 config: https://pastebin.com/crz82T0s
> >   - rv32 config: rv64 config + 32-bit.config
> > 
> > Signed-off-by: Zhangjin Wu <falcon@tinylab.org>
> > ---
> >  arch/riscv/Kconfig              | 1 +
> >  arch/riscv/kernel/vmlinux.lds.S | 2 +-
> >  2 files changed, 2 insertions(+), 1 deletion(-)
> > 
> > diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
> > index 348c0fa1fc8c..d2eb1a862ea8 100644
> > --- a/arch/riscv/Kconfig
> > +++ b/arch/riscv/Kconfig
> > @@ -111,6 +111,7 @@ config RISCV
> >  	select HAVE_KPROBES_ON_FTRACE if !XIP_KERNEL
> >  	select HAVE_KRETPROBES if !XIP_KERNEL
> >  	select HAVE_RETHOOK if !XIP_KERNEL
> > +	select HAVE_LD_DEAD_CODE_DATA_ELIMINATION
> >  	select HAVE_MOVE_PMD
> >  	select HAVE_MOVE_PUD
> >  	select HAVE_PCI
> > diff --git a/arch/riscv/kernel/vmlinux.lds.S b/arch/riscv/kernel/vmlinux.lds.S
> > index e5f9f4677bbf..0f5dfbc113d4 100644
> > --- a/arch/riscv/kernel/vmlinux.lds.S
> > +++ b/arch/riscv/kernel/vmlinux.lds.S
> > @@ -112,7 +112,7 @@ SECTIONS
> >  	. = ALIGN(8);
> >  	.alternative : {
> >  		__alt_start = .;
> > -		*(.alternative)
> > +		KEEP(*(.alternative))
> >  		__alt_end = .;
> >  	}
> >  	__init_end = .;
Conor Dooley May 21, 2023, 1:32 p.m. UTC | #8
Hey!

On Sun, May 21, 2023 at 08:41:34PM +0800, Zhangjin Wu wrote:
> > On Wed, May 17, 2023 at 04:29:36PM +0800, Zhangjin Wu wrote:
> > > Select CONFIG_HAVE_LD_DEAD_CODE_DATA_ELIMINATION for RISC-V, allowing
> > > the user to enable dead code elimination. In order for this to work,
> > > ensure that we keep the alternative table by annotating them with KEEP.
> > > 
> > > This boots well on qemu with both rv32_defconfig & rv64 defconfig, but
> > > it only shrinks their builds by ~1%, a smaller config is thereforce
> > > customized to test this feature:
> > 
> > OOPS, I didn't noticed that you have sent out the patch and you are now
> > in v3. I may read your patch sevral months ago, but I forget it.
> 
> Yeah, I have sent this patch several times, but beside the suggestion from
> conor,

Half the time my comments are just me forwarding on stuff from
automation complaining. Otherwise I do my best to look at things that
are being ignored.

> I have gotten no more responses (before v3), I even thought RISC-V
> people are not interested in or not require size shrinking ;-)

IIRC, you sent a standalone patch, which might've been picked up had you
not followed it up with a series marked RFC containing the same patch.
The v2 which was sent on 14/2 was marked superseded after the RFC series
on 17/2. And I guess since the RFC generated no comments, but clearly
couldn't be merged, it was ignored?

To be honest, I am not quite sure why you are sending some of these
things as RFC. The VDSO thing looks like something that should be
considered/reviewed properly etc, rather than "hey I have this idea,
does anyone have suggestions".

> As I can see from the mailing list, Guoren just sent out a new series of
> patchset [0] about size shrink (-16%), and include the one [1] from you, so,
> I'm not alone, the left patchsets I'm working on and upstreaming include dead
> syscall elimination [2], vdso configuration [3], nolibc for rv32 [4] and even
> the self-decompress vmlinuz support (RFC v1 will be sent out next week), all of
> these patchsets are result of my tinylinux [5] porting to RISC-V (got 334k
> non-MMU rv64 vmlinuz+nolibc hello).

Ordinarily I would suggest that you contact these people and ask them to
review your work, so that there is less for Palmer to do when he is
going through the list on patchwork for stuff to merge - but it looks
like you are already doing that, which is great :)

> I have found that you have fixed up some other issues, It is better to
> merge mine in your series, please don't forget the Tested-by line from
> Bin Meng [7] and the Reviewed-by line from Guoren [8].

I'll mark this patch as superseded then, yeah?

Thanks,
Conor.
Zhangjin Wu May 21, 2023, 2:56 p.m. UTC | #9
Hi, Conor. 

> Hi, 
> 
> On Sun, May 21, 2023 at 08:41:34PM +0800, Zhangjin Wu wrote:
> > > On Wed, May 17, 2023 at 04:29:36PM +0800, Zhangjin Wu wrote:
> > > > Select CONFIG_HAVE_LD_DEAD_CODE_DATA_ELIMINATION for RISC-V, allowing
> > > > the user to enable dead code elimination. In order for this to work,
> > > > ensure that we keep the alternative table by annotating them with KEEP.
> > > >
> > > > This boots well on qemu with both rv32_defconfig & rv64 defconfig, but
> > > > it only shrinks their builds by ~1%, a smaller config is thereforce
> > > > customized to test this feature:
> > >
> > > OOPS, I didn't noticed that you have sent out the patch and you are now
> > > in v3. I may read your patch sevral months ago, but I forget it.
> >
> > Yeah, I have sent this patch several times, but beside the suggestion from
> > conor,
> 
> Half the time my comments are just me forwarding on stuff from
> automation complaining. Otherwise I do my best to look at things that
> are being ignored.
> 
> > I have gotten no more responses (before v3), I even thought RISC-V
> > people are not interested in or not require size shrinking ;-)
> 
> IIRC, you sent a standalone patch, which might've been picked up had you
> not followed it up with a series marked RFC containing the same patch.
> The v2 which was sent on 14/2 was marked superseded after the RFC series
> on 17/2. And I guess since the RFC generated no comments, but clearly
> couldn't be merged, it was ignored?
>

Yeah, v2 has no feedback (I have put it in the dead syscall elimination
series who depends on it), so, I rebased it on latest v6.4-rc2
and send a v3 ;-)

Btw, where can I check the patch status? 10 years ago, when I worked on
MIPS architecture, I used patchwork to track the status, not sure, which
web site we are currently using, lore.kernel.org or still
patchwork.kernel.org? I use lore to read and send patches now.

> To be honest, I am not quite sure why you are sending some of these
> things as RFC. The VDSO thing looks like something that should be
> considered/reviewed properly etc, rather than "hey I have this idea,
> does anyone have suggestions".
>

"RFC" added in my recent patchset is really want to get some feedbacks,
especially, to learn if it is valuable to continue. As you know, the
VDSO is required by most of the system, so, touch it should be
carefully, and dead syscall elimination is another "big" change.

Thanks for your kindly suggestion, I will remove "RFC" if it is not that
necessary.

> > As I can see from the mailing list, Guoren just sent out a new series of
> > patchset [0] about size shrink (-16%), and include the one [1] from you, so,
> > I'm not alone, the left patchsets I'm working on and upstreaming include dead
> > syscall elimination [2], vdso configuration [3], nolibc for rv32 [4] and even
> > the self-decompress vmlinuz support (RFC v1 will be sent out next week), all of
> > these patchsets are result of my tinylinux [5] porting to RISC-V (got 334k
> > non-MMU rv64 vmlinuz+nolibc hello).
> 
> Ordinarily I would suggest that you contact these people and ask them to
> review your work, so that there is less for Palmer to do when he is
> going through the list on patchwork for stuff to merge - but it looks
> like you are already doing that, which is great :)
>

Yeah, In the past 2 or 3 months, I'm focusing on implementing the other
tinylinux patchsets for RISC-V, and have no enough time to ping
reviewers ;-)

> > I have found that you have fixed up some other issues, It is better to
> > merge mine in your series, please don't forget the Tested-by line from
> > Bin Meng [7] and the Reviewed-by line from Guoren [8].
> 
> I'll mark this patch as superseded then, yeah?
> 

Yes, of course.

Thanks,
Zhangjin

> Thanks,
> Conor.
Conor Dooley May 21, 2023, 3:06 p.m. UTC | #10
On Sun, May 21, 2023 at 10:56:03PM +0800, Zhangjin Wu wrote:
> > On Sun, May 21, 2023 at 08:41:34PM +0800, Zhangjin Wu wrote:
> > > > On Wed, May 17, 2023 at 04:29:36PM +0800, Zhangjin Wu wrote:

> Btw, where can I check the patch status? 10 years ago, when I worked on
> MIPS architecture, I used patchwork to track the status, not sure, which
> web site we are currently using, lore.kernel.org or still
> patchwork.kernel.org? I use lore to read and send patches now.

Yup, still patchwork for status tracking.
https://patchwork.kernel.org/project/linux-riscv/list/

> 
> > To be honest, I am not quite sure why you are sending some of these
> > things as RFC. The VDSO thing looks like something that should be
> > considered/reviewed properly etc, rather than "hey I have this idea,
> > does anyone have suggestions".
> >
> 
> "RFC" added in my recent patchset is really want to get some feedbacks,
> especially, to learn if it is valuable to continue. As you know, the
> VDSO is required by most of the system, so, touch it should be
> carefully, and dead syscall elimination is another "big" change.
> 
> Thanks for your kindly suggestion, I will remove "RFC" if it is not that
> necessary.

Yea, I understand why you're doing it, but if you do & noone replies
there's a good chance that it'll just get skipped for non-RFC patches
when Palmer is merging stuff.

Cheers,
Conor.
Nick Desaulniers June 20, 2023, 8:13 p.m. UTC | #11
On Wed, May 17, 2023 at 04:29:36PM +0800, Zhangjin Wu wrote:
> Select CONFIG_HAVE_LD_DEAD_CODE_DATA_ELIMINATION for RISC-V, allowing
> the user to enable dead code elimination. In order for this to work,
> ensure that we keep the alternative table by annotating them with KEEP.
> 

Just cross referencing the report from Palmer against v2; I see orphan
section warnings from the linker related to the EFI stub when building
allmodconfig with this patch applied.

v2: thread for reference.
https://lore.kernel.org/linux-riscv/CAKwvOdmsgMN5oQpDLh12D0X-CfQDtHC-EtxHcBnADkhnyitMKQ@mail.gmail.com/
Palmer Dabbelt June 20, 2023, 8:17 p.m. UTC | #12
On Tue, 20 Jun 2023 13:13:06 PDT (-0700), ndesaulniers@google.com wrote:
> On Wed, May 17, 2023 at 04:29:36PM +0800, Zhangjin Wu wrote:
>> Select CONFIG_HAVE_LD_DEAD_CODE_DATA_ELIMINATION for RISC-V, allowing
>> the user to enable dead code elimination. In order for this to work,
>> ensure that we keep the alternative table by annotating them with KEEP.
>>
>
> Just cross referencing the report from Palmer against v2; I see orphan
> section warnings from the linker related to the EFI stub when building
> allmodconfig with this patch applied.
>
> v2: thread for reference.
> https://lore.kernel.org/linux-riscv/CAKwvOdmsgMN5oQpDLh12D0X-CfQDtHC-EtxHcBnADkhnyitMKQ@mail.gmail.com/

Sorry for replying to the v2, I'm marking that as superseeded in 
patchwork.  IIUC it is a real issue on your end too?  I'm also not 100% 
sure about the hang, I just let LLD cook for about 10 minutes before I 
noticed it was still running and posted.
Conor Dooley June 20, 2023, 8:22 p.m. UTC | #13
On Tue, Jun 20, 2023 at 01:17:26PM -0700, Palmer Dabbelt wrote:
> On Tue, 20 Jun 2023 13:13:06 PDT (-0700), ndesaulniers@google.com wrote:
> > On Wed, May 17, 2023 at 04:29:36PM +0800, Zhangjin Wu wrote:
> > > Select CONFIG_HAVE_LD_DEAD_CODE_DATA_ELIMINATION for RISC-V, allowing
> > > the user to enable dead code elimination. In order for this to work,
> > > ensure that we keep the alternative table by annotating them with KEEP.
> > > 
> > 
> > Just cross referencing the report from Palmer against v2; I see orphan
> > section warnings from the linker related to the EFI stub when building
> > allmodconfig with this patch applied.
> > 
> > v2: thread for reference.
> > https://lore.kernel.org/linux-riscv/CAKwvOdmsgMN5oQpDLh12D0X-CfQDtHC-EtxHcBnADkhnyitMKQ@mail.gmail.com/
> 
> Sorry for replying to the v2, I'm marking that as superseeded in patchwork.
> IIUC it is a real issue on your end too?  I'm also not 100% sure about the
> hang, I just let LLD cook for about 10 minutes before I noticed it was still
> running and posted.

Repeating myself for the sake of the archives or w/e, two different
submitters with differing version numbers. The v2 from Jisheng is more
recent than the v3 here from Zhangjin, they agreed in this mail thread
to merge their work.

Cheers,
Conor.
Nick Desaulniers June 20, 2023, 8:26 p.m. UTC | #14
On Tue, Jun 20, 2023 at 4:17 PM Palmer Dabbelt <palmer@rivosinc.com> wrote:
>
> On Tue, 20 Jun 2023 13:13:06 PDT (-0700), ndesaulniers@google.com wrote:
> > On Wed, May 17, 2023 at 04:29:36PM +0800, Zhangjin Wu wrote:
> >> Select CONFIG_HAVE_LD_DEAD_CODE_DATA_ELIMINATION for RISC-V, allowing
> >> the user to enable dead code elimination. In order for this to work,
> >> ensure that we keep the alternative table by annotating them with KEEP.
> >>
> >
> > Just cross referencing the report from Palmer against v2; I see orphan
> > section warnings from the linker related to the EFI stub when building
> > allmodconfig with this patch applied.
> >
> > v2: thread for reference.
> > https://lore.kernel.org/linux-riscv/CAKwvOdmsgMN5oQpDLh12D0X-CfQDtHC-EtxHcBnADkhnyitMKQ@mail.gmail.com/
>
> Sorry for replying to the v2, I'm marking that as superseeded in
> patchwork.  IIUC it is a real issue on your end too?  I'm also not 100%
> sure about the hang, I just let LLD cook for about 10 minutes before I
> noticed it was still running and posted.

Yes; if this is merged, our CI builds of ARCH=riscv allmodconfig will go red.

I assume a linker script somewhere needs to be updated, but I haven't
found if/where the efi stub's is.

drivers/firmware/efi/libstub/zboot.lds perhaps?

On Tue, Jun 20, 2023 at 4:22 PM Conor Dooley <conor@kernel.org> wrote:
>
> Repeating myself for the sake of the archives or w/e, two different
> submitters with differing version numbers. The v2 from Jisheng is more
> recent than the v3 here from Zhangjin, they agreed in this mail thread
> to merge their work.
Palmer Dabbelt June 20, 2023, 8:41 p.m. UTC | #15
On Tue, 20 Jun 2023 13:26:53 PDT (-0700), ndesaulniers@google.com wrote:
> On Tue, Jun 20, 2023 at 4:17 PM Palmer Dabbelt <palmer@rivosinc.com> wrote:
>>
>> On Tue, 20 Jun 2023 13:13:06 PDT (-0700), ndesaulniers@google.com wrote:
>> > On Wed, May 17, 2023 at 04:29:36PM +0800, Zhangjin Wu wrote:
>> >> Select CONFIG_HAVE_LD_DEAD_CODE_DATA_ELIMINATION for RISC-V, allowing
>> >> the user to enable dead code elimination. In order for this to work,
>> >> ensure that we keep the alternative table by annotating them with KEEP.
>> >>
>> >
>> > Just cross referencing the report from Palmer against v2; I see orphan
>> > section warnings from the linker related to the EFI stub when building
>> > allmodconfig with this patch applied.
>> >
>> > v2: thread for reference.
>> > https://lore.kernel.org/linux-riscv/CAKwvOdmsgMN5oQpDLh12D0X-CfQDtHC-EtxHcBnADkhnyitMKQ@mail.gmail.com/
>>
>> Sorry for replying to the v2, I'm marking that as superseeded in
>> patchwork.  IIUC it is a real issue on your end too?  I'm also not 100%
>> sure about the hang, I just let LLD cook for about 10 minutes before I
>> noticed it was still running and posted.
>
> Yes; if this is merged, our CI builds of ARCH=riscv allmodconfig will go red.
>
> I assume a linker script somewhere needs to be updated, but I haven't
> found if/where the efi stub's is.
>
> drivers/firmware/efi/libstub/zboot.lds perhaps?
>
> On Tue, Jun 20, 2023 at 4:22 PM Conor Dooley <conor@kernel.org> wrote:
>>
>> Repeating myself for the sake of the archives or w/e, two different
>> submitters with differing version numbers. The v2 from Jisheng is more
>> recent than the v3 here from Zhangjin, they agreed in this mail thread
>> to merge their work.

Thanks, so we're going to jump over there.

>
> -- 
> Thanks,
> ~Nick Desaulniers
diff mbox series

Patch

diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
index 348c0fa1fc8c..d2eb1a862ea8 100644
--- a/arch/riscv/Kconfig
+++ b/arch/riscv/Kconfig
@@ -111,6 +111,7 @@  config RISCV
 	select HAVE_KPROBES_ON_FTRACE if !XIP_KERNEL
 	select HAVE_KRETPROBES if !XIP_KERNEL
 	select HAVE_RETHOOK if !XIP_KERNEL
+	select HAVE_LD_DEAD_CODE_DATA_ELIMINATION
 	select HAVE_MOVE_PMD
 	select HAVE_MOVE_PUD
 	select HAVE_PCI
diff --git a/arch/riscv/kernel/vmlinux.lds.S b/arch/riscv/kernel/vmlinux.lds.S
index e5f9f4677bbf..0f5dfbc113d4 100644
--- a/arch/riscv/kernel/vmlinux.lds.S
+++ b/arch/riscv/kernel/vmlinux.lds.S
@@ -112,7 +112,7 @@  SECTIONS
 	. = ALIGN(8);
 	.alternative : {
 		__alt_start = .;
-		*(.alternative)
+		KEEP(*(.alternative))
 		__alt_end = .;
 	}
 	__init_end = .;