public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 1/2] efi/earlycon: Replace open coded strnchrnul()
@ 2022-12-08 22:12 Andy Shevchenko
  2022-12-08 22:12 ` [PATCH v1 2/2] efi/earlycon: Speed up scrolling by skiping moving empty space Andy Shevchenko
  2023-01-10 13:58 ` [PATCH v1 1/2] efi/earlycon: Replace open coded strnchrnul() Andy Shevchenko
  0 siblings, 2 replies; 5+ messages in thread
From: Andy Shevchenko @ 2022-12-08 22:12 UTC (permalink / raw)
  To: Andy Shevchenko, linux-efi, linux-kernel
  Cc: Ard Biesheuvel, Hans de Goede, platform-driver-x86

strnchrnul() can be called in the early stages. Replace
open coded variant in the EFI early console driver.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/firmware/efi/earlycon.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)

diff --git a/drivers/firmware/efi/earlycon.c b/drivers/firmware/efi/earlycon.c
index 4d6c5327471a..be7c83b6cd10 100644
--- a/drivers/firmware/efi/earlycon.c
+++ b/drivers/firmware/efi/earlycon.c
@@ -10,6 +10,7 @@
 #include <linux/kernel.h>
 #include <linux/serial_core.h>
 #include <linux/screen_info.h>
+#include <linux/string.h>
 
 #include <asm/early_ioremap.h>
 
@@ -143,16 +144,10 @@ efi_earlycon_write(struct console *con, const char *str, unsigned int num)
 	len = si->lfb_linelength;
 
 	while (num) {
-		unsigned int linemax;
-		unsigned int h, count = 0;
+		unsigned int linemax = (si->lfb_width - efi_x) / font->width;
+		unsigned int h, count;
 
-		for (s = str; *s && *s != '\n'; s++) {
-			if (count == num)
-				break;
-			count++;
-		}
-
-		linemax = (si->lfb_width - efi_x) / font->width;
+		count = strnchrnul(str, num, '\n') - str;
 		if (count > linemax)
 			count = linemax;
 
-- 
2.35.1


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

* [PATCH v1 2/2] efi/earlycon: Speed up scrolling by skiping moving empty space
  2022-12-08 22:12 [PATCH v1 1/2] efi/earlycon: Replace open coded strnchrnul() Andy Shevchenko
@ 2022-12-08 22:12 ` Andy Shevchenko
  2023-01-10 13:58 ` [PATCH v1 1/2] efi/earlycon: Replace open coded strnchrnul() Andy Shevchenko
  1 sibling, 0 replies; 5+ messages in thread
From: Andy Shevchenko @ 2022-12-08 22:12 UTC (permalink / raw)
  To: Andy Shevchenko, linux-efi, linux-kernel
  Cc: Ard Biesheuvel, Hans de Goede, platform-driver-x86

Currently the scroll copies the full screen which is slow on
the hi-resolution displays. At the same time most of the screen
is an empty space which has no need to be copied over and over.

Optimize the scrolling algorithm by caching the x coordinates
of the last printed lines and scroll in accordance with the
maximum x in that cache.

On my Microsoft Surface Book (the first version) this produces
a significant speedup of the console 90 seconds vs. 168 seconds
with the kernel command line having

	ignore_loglevel earlycon=efifb keep_bootcon

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/firmware/efi/earlycon.c | 28 ++++++++++++++++++++++++++--
 1 file changed, 26 insertions(+), 2 deletions(-)

diff --git a/drivers/firmware/efi/earlycon.c b/drivers/firmware/efi/earlycon.c
index be7c83b6cd10..f54e6fdf08e2 100644
--- a/drivers/firmware/efi/earlycon.c
+++ b/drivers/firmware/efi/earlycon.c
@@ -16,6 +16,8 @@
 
 static const struct console *earlycon_console __initdata;
 static const struct font_desc *font;
+static u16 cur_line_y, max_line_y;
+static u32 efi_x_array[1024];
 static u32 efi_x, efi_y;
 static u64 fb_base;
 static bool fb_wb;
@@ -86,9 +88,17 @@ static void efi_earlycon_clear_scanline(unsigned int y)
 static void efi_earlycon_scroll_up(void)
 {
 	unsigned long *dst, *src;
+	u16 maxlen = 0;
 	u16 len;
 	u32 i, height;
 
+	/* Find the cached maximum x coordinate */
+	for (i = 0; i < max_line_y; i++) {
+		if (efi_x_array[i] > maxlen)
+			maxlen = efi_x_array[i];
+	}
+	maxlen *= 4;
+
 	len = screen_info.lfb_linelength;
 	height = screen_info.lfb_height;
 
@@ -103,7 +113,7 @@ static void efi_earlycon_scroll_up(void)
 			return;
 		}
 
-		memmove(dst, src, len);
+		memmove(dst, src, maxlen);
 
 		efi_earlycon_unmap(src, len);
 		efi_earlycon_unmap(dst, len);
@@ -136,6 +146,7 @@ static void
 efi_earlycon_write(struct console *con, const char *str, unsigned int num)
 {
 	struct screen_info *si;
+	u32 cur_efi_x = efi_x;
 	unsigned int len;
 	const char *s;
 	void *dst;
@@ -176,6 +187,7 @@ efi_earlycon_write(struct console *con, const char *str, unsigned int num)
 		str += count;
 
 		if (num > 0 && *s == '\n') {
+			cur_efi_x = efi_x;
 			efi_x = 0;
 			efi_y += font->height;
 			str++;
@@ -183,6 +195,7 @@ efi_earlycon_write(struct console *con, const char *str, unsigned int num)
 		}
 
 		if (efi_x + font->width > si->lfb_width) {
+			cur_efi_x = efi_x;
 			efi_x = 0;
 			efi_y += font->height;
 		}
@@ -190,6 +203,9 @@ efi_earlycon_write(struct console *con, const char *str, unsigned int num)
 		if (efi_y + font->height > si->lfb_height) {
 			u32 i;
 
+			efi_x_array[cur_line_y] = cur_efi_x;
+			cur_line_y = (cur_line_y + 1) % max_line_y;
+
 			efi_y -= font->height;
 			efi_earlycon_scroll_up();
 
@@ -230,7 +246,15 @@ static int __init efi_earlycon_setup(struct earlycon_device *device,
 	if (!font)
 		return -ENODEV;
 
-	efi_y = rounddown(yres, font->height) - font->height;
+	/* Fill the cache with maximum possible value of x coordinate */
+	memset32(efi_x_array, rounddown(xres, font->width), ARRAY_SIZE(efi_x_array));
+	efi_y = rounddown(yres, font->height);
+
+	/* Make sure we have cache for the x coordinate for the full screen */
+	max_line_y = efi_y / font->height + 1;
+	cur_line_y = 0;
+
+	efi_y -= font->height;
 	for (i = 0; i < (yres - efi_y) / font->height; i++)
 		efi_earlycon_scroll_up();
 
-- 
2.35.1


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

* Re: [PATCH v1 1/2] efi/earlycon: Replace open coded strnchrnul()
  2022-12-08 22:12 [PATCH v1 1/2] efi/earlycon: Replace open coded strnchrnul() Andy Shevchenko
  2022-12-08 22:12 ` [PATCH v1 2/2] efi/earlycon: Speed up scrolling by skiping moving empty space Andy Shevchenko
@ 2023-01-10 13:58 ` Andy Shevchenko
  2023-01-10 14:15   ` Ard Biesheuvel
  1 sibling, 1 reply; 5+ messages in thread
From: Andy Shevchenko @ 2023-01-10 13:58 UTC (permalink / raw)
  To: linux-efi, linux-kernel
  Cc: Ard Biesheuvel, Hans de Goede, platform-driver-x86

On Fri, Dec 09, 2022 at 12:12:16AM +0200, Andy Shevchenko wrote:
> strnchrnul() can be called in the early stages. Replace
> open coded variant in the EFI early console driver.

Any comments on the series?

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH v1 1/2] efi/earlycon: Replace open coded strnchrnul()
  2023-01-10 13:58 ` [PATCH v1 1/2] efi/earlycon: Replace open coded strnchrnul() Andy Shevchenko
@ 2023-01-10 14:15   ` Ard Biesheuvel
  2023-01-10 14:56     ` Andy Shevchenko
  0 siblings, 1 reply; 5+ messages in thread
From: Ard Biesheuvel @ 2023-01-10 14:15 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: linux-efi, linux-kernel, Hans de Goede, platform-driver-x86

On Tue, 10 Jan 2023 at 14:58, Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> On Fri, Dec 09, 2022 at 12:12:16AM +0200, Andy Shevchenko wrote:
> > strnchrnul() can be called in the early stages. Replace
> > open coded variant in the EFI early console driver.
>
> Any comments on the series?
>

Looks fine to me. Queued up in efi/next now.

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

* Re: [PATCH v1 1/2] efi/earlycon: Replace open coded strnchrnul()
  2023-01-10 14:15   ` Ard Biesheuvel
@ 2023-01-10 14:56     ` Andy Shevchenko
  0 siblings, 0 replies; 5+ messages in thread
From: Andy Shevchenko @ 2023-01-10 14:56 UTC (permalink / raw)
  To: Ard Biesheuvel
  Cc: linux-efi, linux-kernel, Hans de Goede, platform-driver-x86

On Tue, Jan 10, 2023 at 03:15:28PM +0100, Ard Biesheuvel wrote:
> On Tue, 10 Jan 2023 at 14:58, Andy Shevchenko
> <andriy.shevchenko@linux.intel.com> wrote:
> >
> > On Fri, Dec 09, 2022 at 12:12:16AM +0200, Andy Shevchenko wrote:
> > > strnchrnul() can be called in the early stages. Replace
> > > open coded variant in the EFI early console driver.
> >
> > Any comments on the series?
> 
> Looks fine to me. Queued up in efi/next now.

Thank you and HNY!

-- 
With Best Regards,
Andy Shevchenko



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

end of thread, other threads:[~2023-01-10 14:57 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-08 22:12 [PATCH v1 1/2] efi/earlycon: Replace open coded strnchrnul() Andy Shevchenko
2022-12-08 22:12 ` [PATCH v1 2/2] efi/earlycon: Speed up scrolling by skiping moving empty space Andy Shevchenko
2023-01-10 13:58 ` [PATCH v1 1/2] efi/earlycon: Replace open coded strnchrnul() Andy Shevchenko
2023-01-10 14:15   ` Ard Biesheuvel
2023-01-10 14:56     ` Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox