diff options
author | Matthew Wilcox <mawilcox@microsoft.com> | 2017-09-08 19:14:15 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2017-09-08 21:26:48 -0400 |
commit | ac036f9570a2d318b7d8dbbdbf0e269d7cc68cef (patch) | |
tree | fe4b5aa299c97e2b496d6b1a9e0fe93f1e7b3f22 | |
parent | 1caffba9db4aa27c3e7ebc05668afca1f991ab8d (diff) |
vga: optimise console scrolling
Where possible, call memset16(), memmove() or memcpy() instead of using
open-coded loops. I don't like the calling convention that uses a byte
count instead of a count of u16s, but it's a little late to change that.
Reduces code size of fbcon.o by almost 400 bytes on my laptop build.
[akpm@linux-foundation.org: fix build]
Link: http://lkml.kernel.org/r/20170720184539.31609-9-willy@infradead.org
Signed-off-by: Matthew Wilcox <mawilcox@microsoft.com>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: David Miller <davem@davemloft.net>
Cc: Sam Ravnborg <sam@ravnborg.org>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: "James E.J. Bottomley" <jejb@linux.vnet.ibm.com>
Cc: "Martin K. Petersen" <martin.petersen@oracle.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
Cc: Matt Turner <mattst88@gmail.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Richard Henderson <rth@twiddle.net>
Cc: Russell King <rmk+kernel@armlinux.org.uk>
Cc: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | arch/mips/include/asm/vga.h | 7 | ||||
-rw-r--r-- | arch/powerpc/include/asm/vga.h | 8 | ||||
-rw-r--r-- | arch/sparc/include/asm/vga.h | 25 | ||||
-rw-r--r-- | include/linux/vt_buffer.h | 13 |
4 files changed, 53 insertions, 0 deletions
diff --git a/arch/mips/include/asm/vga.h b/arch/mips/include/asm/vga.h index f82c83749a08..975ff51f80c4 100644 --- a/arch/mips/include/asm/vga.h +++ b/arch/mips/include/asm/vga.h | |||
@@ -6,6 +6,7 @@ | |||
6 | #ifndef _ASM_VGA_H | 6 | #ifndef _ASM_VGA_H |
7 | #define _ASM_VGA_H | 7 | #define _ASM_VGA_H |
8 | 8 | ||
9 | #include <linux/string.h> | ||
9 | #include <asm/addrspace.h> | 10 | #include <asm/addrspace.h> |
10 | #include <asm/byteorder.h> | 11 | #include <asm/byteorder.h> |
11 | 12 | ||
@@ -40,9 +41,15 @@ static inline u16 scr_readw(volatile const u16 *addr) | |||
40 | return le16_to_cpu(*addr); | 41 | return le16_to_cpu(*addr); |
41 | } | 42 | } |
42 | 43 | ||
44 | static inline void scr_memsetw(u16 *s, u16 v, unsigned int count) | ||
45 | { | ||
46 | memset16(s, cpu_to_le16(v), count / 2); | ||
47 | } | ||
48 | |||
43 | #define scr_memcpyw(d, s, c) memcpy(d, s, c) | 49 | #define scr_memcpyw(d, s, c) memcpy(d, s, c) |
44 | #define scr_memmovew(d, s, c) memmove(d, s, c) | 50 | #define scr_memmovew(d, s, c) memmove(d, s, c) |
45 | #define VT_BUF_HAVE_MEMCPYW | 51 | #define VT_BUF_HAVE_MEMCPYW |
46 | #define VT_BUF_HAVE_MEMMOVEW | 52 | #define VT_BUF_HAVE_MEMMOVEW |
53 | #define VT_BUF_HAVE_MEMSETW | ||
47 | 54 | ||
48 | #endif /* _ASM_VGA_H */ | 55 | #endif /* _ASM_VGA_H */ |
diff --git a/arch/powerpc/include/asm/vga.h b/arch/powerpc/include/asm/vga.h index ab3acd2f2786..7a7b541b7493 100644 --- a/arch/powerpc/include/asm/vga.h +++ b/arch/powerpc/include/asm/vga.h | |||
@@ -33,8 +33,16 @@ static inline u16 scr_readw(volatile const u16 *addr) | |||
33 | return le16_to_cpu(*addr); | 33 | return le16_to_cpu(*addr); |
34 | } | 34 | } |
35 | 35 | ||
36 | #define VT_BUF_HAVE_MEMSETW | ||
37 | static inline void scr_memsetw(u16 *s, u16 v, unsigned int n) | ||
38 | { | ||
39 | memset16(s, cpu_to_le16(v), n / 2); | ||
40 | } | ||
41 | |||
36 | #define VT_BUF_HAVE_MEMCPYW | 42 | #define VT_BUF_HAVE_MEMCPYW |
43 | #define VT_BUF_HAVE_MEMMOVEW | ||
37 | #define scr_memcpyw memcpy | 44 | #define scr_memcpyw memcpy |
45 | #define scr_memmovew memmove | ||
38 | 46 | ||
39 | #endif /* !CONFIG_VGA_CONSOLE && !CONFIG_MDA_CONSOLE */ | 47 | #endif /* !CONFIG_VGA_CONSOLE && !CONFIG_MDA_CONSOLE */ |
40 | 48 | ||
diff --git a/arch/sparc/include/asm/vga.h b/arch/sparc/include/asm/vga.h index ec0e9967d93d..f54e8b6fb197 100644 --- a/arch/sparc/include/asm/vga.h +++ b/arch/sparc/include/asm/vga.h | |||
@@ -8,9 +8,13 @@ | |||
8 | #define _LINUX_ASM_VGA_H_ | 8 | #define _LINUX_ASM_VGA_H_ |
9 | 9 | ||
10 | #include <linux/bug.h> | 10 | #include <linux/bug.h> |
11 | #include <linux/string.h> | ||
11 | #include <asm/types.h> | 12 | #include <asm/types.h> |
12 | 13 | ||
13 | #define VT_BUF_HAVE_RW | 14 | #define VT_BUF_HAVE_RW |
15 | #define VT_BUF_HAVE_MEMSETW | ||
16 | #define VT_BUF_HAVE_MEMCPYW | ||
17 | #define VT_BUF_HAVE_MEMMOVEW | ||
14 | 18 | ||
15 | #undef scr_writew | 19 | #undef scr_writew |
16 | #undef scr_readw | 20 | #undef scr_readw |
@@ -29,6 +33,27 @@ static inline u16 scr_readw(const u16 *addr) | |||
29 | return *addr; | 33 | return *addr; |
30 | } | 34 | } |
31 | 35 | ||
36 | static inline void scr_memsetw(u16 *p, u16 v, unsigned int n) | ||
37 | { | ||
38 | BUG_ON((long) p >= 0); | ||
39 | |||
40 | memset16(p, cpu_to_le16(v), n / 2); | ||
41 | } | ||
42 | |||
43 | static inline void scr_memcpyw(u16 *d, u16 *s, unsigned int n) | ||
44 | { | ||
45 | BUG_ON((long) d >= 0); | ||
46 | |||
47 | memcpy(d, s, n); | ||
48 | } | ||
49 | |||
50 | static inline void scr_memmovew(u16 *d, u16 *s, unsigned int n) | ||
51 | { | ||
52 | BUG_ON((long) d >= 0); | ||
53 | |||
54 | memmove(d, s, n); | ||
55 | } | ||
56 | |||
32 | #define VGA_MAP_MEM(x,s) (x) | 57 | #define VGA_MAP_MEM(x,s) (x) |
33 | 58 | ||
34 | #endif | 59 | #endif |
diff --git a/include/linux/vt_buffer.h b/include/linux/vt_buffer.h index f38c10ba3ff5..30b6e0d2a942 100644 --- a/include/linux/vt_buffer.h +++ b/include/linux/vt_buffer.h | |||
@@ -13,6 +13,7 @@ | |||
13 | #ifndef _LINUX_VT_BUFFER_H_ | 13 | #ifndef _LINUX_VT_BUFFER_H_ |
14 | #define _LINUX_VT_BUFFER_H_ | 14 | #define _LINUX_VT_BUFFER_H_ |
15 | 15 | ||
16 | #include <linux/string.h> | ||
16 | 17 | ||
17 | #if defined(CONFIG_VGA_CONSOLE) || defined(CONFIG_MDA_CONSOLE) | 18 | #if defined(CONFIG_VGA_CONSOLE) || defined(CONFIG_MDA_CONSOLE) |
18 | #include <asm/vga.h> | 19 | #include <asm/vga.h> |
@@ -26,24 +27,33 @@ | |||
26 | #ifndef VT_BUF_HAVE_MEMSETW | 27 | #ifndef VT_BUF_HAVE_MEMSETW |
27 | static inline void scr_memsetw(u16 *s, u16 c, unsigned int count) | 28 | static inline void scr_memsetw(u16 *s, u16 c, unsigned int count) |
28 | { | 29 | { |
30 | #ifdef VT_BUF_HAVE_RW | ||
29 | count /= 2; | 31 | count /= 2; |
30 | while (count--) | 32 | while (count--) |
31 | scr_writew(c, s++); | 33 | scr_writew(c, s++); |
34 | #else | ||
35 | memset16(s, c, count / 2); | ||
36 | #endif | ||
32 | } | 37 | } |
33 | #endif | 38 | #endif |
34 | 39 | ||
35 | #ifndef VT_BUF_HAVE_MEMCPYW | 40 | #ifndef VT_BUF_HAVE_MEMCPYW |
36 | static inline void scr_memcpyw(u16 *d, const u16 *s, unsigned int count) | 41 | static inline void scr_memcpyw(u16 *d, const u16 *s, unsigned int count) |
37 | { | 42 | { |
43 | #ifdef VT_BUF_HAVE_RW | ||
38 | count /= 2; | 44 | count /= 2; |
39 | while (count--) | 45 | while (count--) |
40 | scr_writew(scr_readw(s++), d++); | 46 | scr_writew(scr_readw(s++), d++); |
47 | #else | ||
48 | memcpy(d, s, count); | ||
49 | #endif | ||
41 | } | 50 | } |
42 | #endif | 51 | #endif |
43 | 52 | ||
44 | #ifndef VT_BUF_HAVE_MEMMOVEW | 53 | #ifndef VT_BUF_HAVE_MEMMOVEW |
45 | static inline void scr_memmovew(u16 *d, const u16 *s, unsigned int count) | 54 | static inline void scr_memmovew(u16 *d, const u16 *s, unsigned int count) |
46 | { | 55 | { |
56 | #ifdef VT_BUF_HAVE_RW | ||
47 | if (d < s) | 57 | if (d < s) |
48 | scr_memcpyw(d, s, count); | 58 | scr_memcpyw(d, s, count); |
49 | else { | 59 | else { |
@@ -53,6 +63,9 @@ static inline void scr_memmovew(u16 *d, const u16 *s, unsigned int count) | |||
53 | while (count--) | 63 | while (count--) |
54 | scr_writew(scr_readw(--s), --d); | 64 | scr_writew(scr_readw(--s), --d); |
55 | } | 65 | } |
66 | #else | ||
67 | memmove(d, s, count); | ||
68 | #endif | ||
56 | } | 69 | } |
57 | #endif | 70 | #endif |
58 | 71 | ||