Skip to content

Commit ac036f9

Browse files
Matthew Wilcoxtorvalds
authored andcommitted
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>
1 parent 1caffba commit ac036f9

File tree

4 files changed

+53
-0
lines changed

4 files changed

+53
-0
lines changed

arch/mips/include/asm/vga.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#ifndef _ASM_VGA_H
77
#define _ASM_VGA_H
88

9+
#include <linux/string.h>
910
#include <asm/addrspace.h>
1011
#include <asm/byteorder.h>
1112

@@ -40,9 +41,15 @@ static inline u16 scr_readw(volatile const u16 *addr)
4041
return le16_to_cpu(*addr);
4142
}
4243

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+
4349
#define scr_memcpyw(d, s, c) memcpy(d, s, c)
4450
#define scr_memmovew(d, s, c) memmove(d, s, c)
4551
#define VT_BUF_HAVE_MEMCPYW
4652
#define VT_BUF_HAVE_MEMMOVEW
53+
#define VT_BUF_HAVE_MEMSETW
4754

4855
#endif /* _ASM_VGA_H */

arch/powerpc/include/asm/vga.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,16 @@ static inline u16 scr_readw(volatile const u16 *addr)
3333
return le16_to_cpu(*addr);
3434
}
3535

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+
3642
#define VT_BUF_HAVE_MEMCPYW
43+
#define VT_BUF_HAVE_MEMMOVEW
3744
#define scr_memcpyw memcpy
45+
#define scr_memmovew memmove
3846

3947
#endif /* !CONFIG_VGA_CONSOLE && !CONFIG_MDA_CONSOLE */
4048

arch/sparc/include/asm/vga.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@
88
#define _LINUX_ASM_VGA_H_
99

1010
#include <linux/bug.h>
11+
#include <linux/string.h>
1112
#include <asm/types.h>
1213

1314
#define VT_BUF_HAVE_RW
15+
#define VT_BUF_HAVE_MEMSETW
16+
#define VT_BUF_HAVE_MEMCPYW
17+
#define VT_BUF_HAVE_MEMMOVEW
1418

1519
#undef scr_writew
1620
#undef scr_readw
@@ -29,6 +33,27 @@ static inline u16 scr_readw(const u16 *addr)
2933
return *addr;
3034
}
3135

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+
3257
#define VGA_MAP_MEM(x,s) (x)
3358

3459
#endif

include/linux/vt_buffer.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#ifndef _LINUX_VT_BUFFER_H_
1414
#define _LINUX_VT_BUFFER_H_
1515

16+
#include <linux/string.h>
1617

1718
#if defined(CONFIG_VGA_CONSOLE) || defined(CONFIG_MDA_CONSOLE)
1819
#include <asm/vga.h>
@@ -26,24 +27,33 @@
2627
#ifndef VT_BUF_HAVE_MEMSETW
2728
static inline void scr_memsetw(u16 *s, u16 c, unsigned int count)
2829
{
30+
#ifdef VT_BUF_HAVE_RW
2931
count /= 2;
3032
while (count--)
3133
scr_writew(c, s++);
34+
#else
35+
memset16(s, c, count / 2);
36+
#endif
3237
}
3338
#endif
3439

3540
#ifndef VT_BUF_HAVE_MEMCPYW
3641
static inline void scr_memcpyw(u16 *d, const u16 *s, unsigned int count)
3742
{
43+
#ifdef VT_BUF_HAVE_RW
3844
count /= 2;
3945
while (count--)
4046
scr_writew(scr_readw(s++), d++);
47+
#else
48+
memcpy(d, s, count);
49+
#endif
4150
}
4251
#endif
4352

4453
#ifndef VT_BUF_HAVE_MEMMOVEW
4554
static inline void scr_memmovew(u16 *d, const u16 *s, unsigned int count)
4655
{
56+
#ifdef VT_BUF_HAVE_RW
4757
if (d < s)
4858
scr_memcpyw(d, s, count);
4959
else {
@@ -53,6 +63,9 @@ static inline void scr_memmovew(u16 *d, const u16 *s, unsigned int count)
5363
while (count--)
5464
scr_writew(scr_readw(--s), --d);
5565
}
66+
#else
67+
memmove(d, s, count);
68+
#endif
5669
}
5770
#endif
5871

0 commit comments

Comments
 (0)