All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] MIPS: Use ARCH_USE_BUILTIN_BSWAP.
@ 2015-09-29 10:28 Ralf Baechle
  2015-09-29 11:52 ` Ralf Baechle
  0 siblings, 1 reply; 7+ messages in thread
From: Ralf Baechle @ 2015-09-29 10:28 UTC (permalink / raw)
  To: linux-mips

ARCH_USE_BUILTIN_BSWAP will use __builtin_bswap16(), __builtin_bswap32()
and __builtin_bswap64() where available.  This allows better instruction
scheduling.  On pre-R2 processors it will result in 32 bit and 64 bit
swapping being performed in a call to a __bswapsi2() rsp. __bswapdi2()
functions, so we add these, too.

For a 4.2 kernel with GCC 4.9 this yields the following kernel sizes:

   text    data     bss     dec     hex filename
3996071  155804   88992 4240867  40b5e3 vmlinux         ip22 baseline
3985687  159900   88992 4234579  409d53 vmlinux         ip22 + bswap patch
6913157  378552  251024 7542733  7317cd vmlinux         ip27 baseline
6878581  378552  251024 7508157  7290bd vmlinux         ip27 + bswap patch
5773777  268752  187424 6229953  5f0fc1 vmlinux         malta baseline
5773401  268752  187424 6229577  5f0e49 vmlinux         malta + bswap patch

Presumably the code size improvments yield better cache hit rate thus
better performance compensating for the extra function call but this
will still need to be benchmarked.

Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
---
 arch/mips/Kconfig       |  1 +
 arch/mips/lib/Makefile  |  2 +-
 arch/mips/lib/bswapdi.c | 11 +++++++++++
 arch/mips/lib/bswapsi.c |  7 +++++++
 4 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index a228e34..4ccb683 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -3,6 +3,7 @@ config MIPS
 	default y
 	select ARCH_MIGHT_HAVE_PC_PARPORT
 	select ARCH_MIGHT_HAVE_PC_SERIO
+	select ARCH_USE_BUILTIN_BSWAP
 	select HAVE_CONTEXT_TRACKING
 	select HAVE_GENERIC_DMA_COHERENT
 	select HAVE_IDE
diff --git a/arch/mips/lib/Makefile b/arch/mips/lib/Makefile
index 1e9e900..0344e57 100644
--- a/arch/mips/lib/Makefile
+++ b/arch/mips/lib/Makefile
@@ -15,4 +15,4 @@ obj-$(CONFIG_CPU_R3000)		+= r3k_dump_tlb.o
 obj-$(CONFIG_CPU_TX39XX)	+= r3k_dump_tlb.o
 
 # libgcc-style stuff needed in the kernel
-obj-y += ashldi3.o ashrdi3.o cmpdi2.o lshrdi3.o ucmpdi2.o
+obj-y += ashldi3.o ashrdi3.o bswapsi.o bswapdi.o cmpdi2.o lshrdi3.o ucmpdi2.o
diff --git a/arch/mips/lib/bswapdi.c b/arch/mips/lib/bswapdi.c
new file mode 100644
index 0000000..f69c41f
--- /dev/null
+++ b/arch/mips/lib/bswapdi.c
@@ -0,0 +1,11 @@
+unsigned long long __bswapdi2 (unsigned long long u)
+{
+	return (((u) & 0xff00000000000000ull) >> 56) |
+	       (((u) & 0x00ff000000000000ull) >> 40) |
+	       (((u) & 0x0000ff0000000000ull) >> 24) |
+	       (((u) & 0x000000ff00000000ull) >>  8) |
+	       (((u) & 0x00000000ff000000ull) <<  8) |
+	       (((u) & 0x0000000000ff0000ull) << 24) |
+	       (((u) & 0x000000000000ff00ull) << 40) |
+	       (((u) & 0x00000000000000ffull) << 56);
+}
diff --git a/arch/mips/lib/bswapsi.c b/arch/mips/lib/bswapsi.c
new file mode 100644
index 0000000..2e3ba7f
--- /dev/null
+++ b/arch/mips/lib/bswapsi.c
@@ -0,0 +1,7 @@
+unsigned int __bswapsi2 (unsigned int u)
+{
+	return (((u) & 0xff000000) >> 24) |
+	       (((u) & 0x00ff0000) >>  8) |
+	       (((u) & 0x0000ff00) <<  8) |
+	       (((u) & 0x000000ff) << 24);
+}

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] MIPS: Use ARCH_USE_BUILTIN_BSWAP.
  2015-09-29 10:28 [PATCH] MIPS: Use ARCH_USE_BUILTIN_BSWAP Ralf Baechle
@ 2015-09-29 11:52 ` Ralf Baechle
  2015-09-29 11:59   ` Måns Rullgård
  0 siblings, 1 reply; 7+ messages in thread
From: Ralf Baechle @ 2015-09-29 11:52 UTC (permalink / raw)
  To: linux-mips

On Tue, Sep 29, 2015 at 12:28:55PM +0200, Ralf Baechle wrote:

>    text    data     bss     dec     hex filename
> 3996071  155804   88992 4240867  40b5e3 vmlinux         ip22 baseline
> 3985687  159900   88992 4234579  409d53 vmlinux         ip22 + bswap patch
> 6913157  378552  251024 7542733  7317cd vmlinux         ip27 baseline
> 6878581  378552  251024 7508157  7290bd vmlinux         ip27 + bswap patch
> 5773777  268752  187424 6229953  5f0fc1 vmlinux         malta baseline
> 5773401  268752  187424 6229577  5f0e49 vmlinux         malta + bswap patch

A still unexplained effect of this patch and the reason why I have not
committed this patch is the increase of the data size for the ip22
configuration by 4096 bytes.  There is no change in data size expected.
Also this affects only the test with ip22_defconfig not any of the others
I've tried.

  Ralf

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] MIPS: Use ARCH_USE_BUILTIN_BSWAP.
  2015-09-29 11:52 ` Ralf Baechle
@ 2015-09-29 11:59   ` Måns Rullgård
  2015-09-29 12:09     ` Ralf Baechle
  2015-09-29 13:28     ` Ralf Baechle
  0 siblings, 2 replies; 7+ messages in thread
From: Måns Rullgård @ 2015-09-29 11:59 UTC (permalink / raw)
  To: Ralf Baechle; +Cc: linux-mips

Ralf Baechle <ralf@linux-mips.org> writes:

> On Tue, Sep 29, 2015 at 12:28:55PM +0200, Ralf Baechle wrote:
>
>>    text    data     bss     dec     hex filename
>> 3996071  155804   88992 4240867  40b5e3 vmlinux         ip22 baseline
>> 3985687  159900   88992 4234579  409d53 vmlinux         ip22 + bswap patch
>> 6913157  378552  251024 7542733  7317cd vmlinux         ip27 baseline
>> 6878581  378552  251024 7508157  7290bd vmlinux         ip27 + bswap patch
>> 5773777  268752  187424 6229953  5f0fc1 vmlinux         malta baseline
>> 5773401  268752  187424 6229577  5f0e49 vmlinux         malta + bswap patch
>
> A still unexplained effect of this patch and the reason why I have not
> committed this patch is the increase of the data size for the ip22
> configuration by 4096 bytes.  There is no change in data size expected.
> Also this affects only the test with ip22_defconfig not any of the others
> I've tried.

Have you checked which object file(s) the increase comes from?

-- 
Måns Rullgård
mans@mansr.com

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] MIPS: Use ARCH_USE_BUILTIN_BSWAP.
  2015-09-29 11:59   ` Måns Rullgård
@ 2015-09-29 12:09     ` Ralf Baechle
  2015-09-29 13:28     ` Ralf Baechle
  1 sibling, 0 replies; 7+ messages in thread
From: Ralf Baechle @ 2015-09-29 12:09 UTC (permalink / raw)
  To: Måns Rullgård; +Cc: linux-mips

On Tue, Sep 29, 2015 at 12:59:56PM +0100, Måns Rullgård wrote:

> Ralf Baechle <ralf@linux-mips.org> writes:
> 
> > On Tue, Sep 29, 2015 at 12:28:55PM +0200, Ralf Baechle wrote:
> >
> >>    text    data     bss     dec     hex filename
> >> 3996071  155804   88992 4240867  40b5e3 vmlinux         ip22 baseline
> >> 3985687  159900   88992 4234579  409d53 vmlinux         ip22 + bswap patch
> >> 6913157  378552  251024 7542733  7317cd vmlinux         ip27 baseline
> >> 6878581  378552  251024 7508157  7290bd vmlinux         ip27 + bswap patch
> >> 5773777  268752  187424 6229953  5f0fc1 vmlinux         malta baseline
> >> 5773401  268752  187424 6229577  5f0e49 vmlinux         malta + bswap patch
> >
> > A still unexplained effect of this patch and the reason why I have not
> > committed this patch is the increase of the data size for the ip22
> > configuration by 4096 bytes.  There is no change in data size expected.
> > Also this affects only the test with ip22_defconfig not any of the others
> > I've tried.
> 
> Have you checked which object file(s) the increase comes from?

Working on that.

  Ralf

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] MIPS: Use ARCH_USE_BUILTIN_BSWAP.
  2015-09-29 11:59   ` Måns Rullgård
  2015-09-29 12:09     ` Ralf Baechle
@ 2015-09-29 13:28     ` Ralf Baechle
  2015-09-29 13:34       ` Måns Rullgård
  1 sibling, 1 reply; 7+ messages in thread
From: Ralf Baechle @ 2015-09-29 13:28 UTC (permalink / raw)
  To: Måns Rullgård; +Cc: linux-mips

On Tue, Sep 29, 2015 at 12:59:56PM +0100, Måns Rullgård wrote:

> Ralf Baechle <ralf@linux-mips.org> writes:
> 
> > On Tue, Sep 29, 2015 at 12:28:55PM +0200, Ralf Baechle wrote:
> >
> >>    text    data     bss     dec     hex filename
> >> 3996071  155804   88992 4240867  40b5e3 vmlinux         ip22 baseline
> >> 3985687  159900   88992 4234579  409d53 vmlinux         ip22 + bswap patch
> >> 6913157  378552  251024 7542733  7317cd vmlinux         ip27 baseline
> >> 6878581  378552  251024 7508157  7290bd vmlinux         ip27 + bswap patch
> >> 5773777  268752  187424 6229953  5f0fc1 vmlinux         malta baseline
> >> 5773401  268752  187424 6229577  5f0e49 vmlinux         malta + bswap patch
> >
> > A still unexplained effect of this patch and the reason why I have not
> > committed this patch is the increase of the data size for the ip22
> > configuration by 4096 bytes.  There is no change in data size expected.
> > Also this affects only the test with ip22_defconfig not any of the others
> > I've tried.
> 
> Have you checked which object file(s) the increase comes from?

The data size difference is created in the final link stage.  data for
all inividual .o files even vmlinux.o; only vmlinux differs.

  Ralf

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] MIPS: Use ARCH_USE_BUILTIN_BSWAP.
  2015-09-29 13:28     ` Ralf Baechle
@ 2015-09-29 13:34       ` Måns Rullgård
  2015-09-29 14:27         ` Ralf Baechle
  0 siblings, 1 reply; 7+ messages in thread
From: Måns Rullgård @ 2015-09-29 13:34 UTC (permalink / raw)
  To: Ralf Baechle; +Cc: linux-mips

Ralf Baechle <ralf@linux-mips.org> writes:

> On Tue, Sep 29, 2015 at 12:59:56PM +0100, Måns Rullgård wrote:
>
>> Ralf Baechle <ralf@linux-mips.org> writes:
>> 
>> > On Tue, Sep 29, 2015 at 12:28:55PM +0200, Ralf Baechle wrote:
>> >
>> >>    text    data     bss     dec     hex filename
>> >> 3996071  155804   88992 4240867  40b5e3 vmlinux         ip22 baseline
>> >> 3985687  159900   88992 4234579  409d53 vmlinux         ip22 + bswap patch
>> >> 6913157  378552  251024 7542733  7317cd vmlinux         ip27 baseline
>> >> 6878581  378552  251024 7508157  7290bd vmlinux         ip27 + bswap patch
>> >> 5773777  268752  187424 6229953  5f0fc1 vmlinux         malta baseline
>> >> 5773401  268752  187424 6229577  5f0e49 vmlinux         malta + bswap patch
>> >
>> > A still unexplained effect of this patch and the reason why I have not
>> > committed this patch is the increase of the data size for the ip22
>> > configuration by 4096 bytes.  There is no change in data size expected.
>> > Also this affects only the test with ip22_defconfig not any of the others
>> > I've tried.
>> 
>> Have you checked which object file(s) the increase comes from?
>
> The data size difference is created in the final link stage.  data for
> all inividual .o files even vmlinux.o; only vmlinux differs.

Could it be an alignment thing.  Check if the alignment of some data
section has changed from something smaller to 4096.

-- 
Måns Rullgård
mans@mansr.com

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] MIPS: Use ARCH_USE_BUILTIN_BSWAP.
  2015-09-29 13:34       ` Måns Rullgård
@ 2015-09-29 14:27         ` Ralf Baechle
  0 siblings, 0 replies; 7+ messages in thread
From: Ralf Baechle @ 2015-09-29 14:27 UTC (permalink / raw)
  To: Måns Rullgård; +Cc: linux-mips

On Tue, Sep 29, 2015 at 02:34:12PM +0100, Måns Rullgård wrote:

> >> >>    text    data     bss     dec     hex filename
> >> >> 3996071  155804   88992 4240867  40b5e3 vmlinux         ip22 baseline
> >> >> 3985687  159900   88992 4234579  409d53 vmlinux         ip22 + bswap patch
> >> >> 6913157  378552  251024 7542733  7317cd vmlinux         ip27 baseline
> >> >> 6878581  378552  251024 7508157  7290bd vmlinux         ip27 + bswap patch
> >> >> 5773777  268752  187424 6229953  5f0fc1 vmlinux         malta baseline
> >> >> 5773401  268752  187424 6229577  5f0e49 vmlinux         malta + bswap patch
> >> >
> >> > A still unexplained effect of this patch and the reason why I have not
> >> > committed this patch is the increase of the data size for the ip22
> >> > configuration by 4096 bytes.  There is no change in data size expected.
> >> > Also this affects only the test with ip22_defconfig not any of the others
> >> > I've tried.
> >> 
> >> Have you checked which object file(s) the increase comes from?
> >
> > The data size difference is created in the final link stage.  data for
> > all inividual .o files even vmlinux.o; only vmlinux differs.
> 
> Could it be an alignment thing.  Check if the alignment of some data
> section has changed from something smaller to 4096.

Almost.  Alignment has changed but 8k alignment of init_thread_union
forced the linker to waste an extra 4k.

I always knew this could happen but never actually observed this.  Hard to
avoid but it's yet another reason to minimize stack size which on MIPS
may be up to 4 pages for 64 bit kernels with 4k pages.

  Ralf

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2015-09-29 14:27 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-29 10:28 [PATCH] MIPS: Use ARCH_USE_BUILTIN_BSWAP Ralf Baechle
2015-09-29 11:52 ` Ralf Baechle
2015-09-29 11:59   ` Måns Rullgård
2015-09-29 12:09     ` Ralf Baechle
2015-09-29 13:28     ` Ralf Baechle
2015-09-29 13:34       ` Måns Rullgård
2015-09-29 14:27         ` Ralf Baechle

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.