From 04cbc2588e36a60992d89793dece7f8cc6475ec9 Mon Sep 17 00:00:00 2001 From: Fredrik Holmqvist Date: Thu, 2 Aug 2018 16:24:15 +0200 Subject: [PATCH] Use fast clearing of visible screen for splash memset uses rep stosb on x86 during boot, with memory not set to write-combining, which makes it slow. Instead we do aligned writes of 2 x four bytes at once. Only clear the minimum of size and width * height * 4 UEFI framebuffer size can be huge, upto 512MB here, and rep stosb seems to be around 25-30MB/s This is written as generic as possible to work on old compilers and different platforms, without expecting boot memset to be optimized. This makes it almost unnoticable compared to not clearing. --- .../kernel/boot/platform/generic/video.h | 2 +- src/system/boot/platform/amiga_m68k/video.cpp | 2 +- src/system/boot/platform/atari_m68k/video.cpp | 2 +- src/system/boot/platform/bios_ia32/video.cpp | 2 +- src/system/boot/platform/efi/video.cpp | 2 +- .../boot/platform/generic/video_splash.cpp | 26 +++++++++++++++---- .../boot/platform/openfirmware/video.cpp | 3 +-- src/system/boot/platform/u-boot/video.cpp | 2 +- 8 files changed, 28 insertions(+), 13 deletions(-) diff --git a/headers/private/kernel/boot/platform/generic/video.h b/headers/private/kernel/boot/platform/generic/video.h index 50effc0f5b..b157372b90 100644 --- a/headers/private/kernel/boot/platform/generic/video.h +++ b/headers/private/kernel/boot/platform/generic/video.h @@ -32,7 +32,7 @@ void uncompress_24bit_RLE(const uint8 compressed[], uint8 *uncompressed); void uncompress_8bit_RLE(const uint8 compressed[], uint8 *uncompressed); /* default splash display */ -status_t video_display_splash(addr_t frameBuffer, bool clear); +status_t video_display_splash(addr_t frameBuffer); #ifdef __cplusplus } diff --git a/src/system/boot/platform/amiga_m68k/video.cpp b/src/system/boot/platform/amiga_m68k/video.cpp index 031673a88d..686b043872 100644 --- a/src/system/boot/platform/amiga_m68k/video.cpp +++ b/src/system/boot/platform/amiga_m68k/video.cpp @@ -234,7 +234,7 @@ platform_switch_to_logo(void) sFrameBuffer = gKernelArgs.frame_buffer.physical_buffer.start; - //video_display_splash(sFrameBuffer, true); + //video_display_splash(sFrameBuffer); } diff --git a/src/system/boot/platform/atari_m68k/video.cpp b/src/system/boot/platform/atari_m68k/video.cpp index 5e5cd7daf2..073f492db2 100644 --- a/src/system/boot/platform/atari_m68k/video.cpp +++ b/src/system/boot/platform/atari_m68k/video.cpp @@ -1153,7 +1153,7 @@ platform_switch_to_logo(void) gKernelArgs.frame_buffer.physical_buffer.size, kDefaultPageFlags); } #endif - video_display_splash(sFrameBuffer, true); + video_display_splash(sFrameBuffer); dump_vars(); spin(10000000); platform_switch_to_text_mode(); diff --git a/src/system/boot/platform/bios_ia32/video.cpp b/src/system/boot/platform/bios_ia32/video.cpp index 2800305571..fa9b1fba8c 100644 --- a/src/system/boot/platform/bios_ia32/video.cpp +++ b/src/system/boot/platform/bios_ia32/video.cpp @@ -877,7 +877,7 @@ fallback: gKernelArgs.frame_buffer.physical_buffer.size, kDefaultPageFlags); } - video_display_splash(sFrameBuffer, true); + video_display_splash(sFrameBuffer); } diff --git a/src/system/boot/platform/efi/video.cpp b/src/system/boot/platform/efi/video.cpp index 61ab14120a..bc7e35e6a5 100644 --- a/src/system/boot/platform/efi/video.cpp +++ b/src/system/boot/platform/efi/video.cpp @@ -254,7 +254,7 @@ platform_switch_to_logo(void) sGraphicsOutput->Mode->Info->PixelsPerScanLine * gKernelArgs.frame_buffer.depth / 8; - video_display_splash(gKernelArgs.frame_buffer.physical_buffer.start, false); + video_display_splash(gKernelArgs.frame_buffer.physical_buffer.start); } diff --git a/src/system/boot/platform/generic/video_splash.cpp b/src/system/boot/platform/generic/video_splash.cpp index 53f92763ce..f58588347d 100644 --- a/src/system/boot/platform/generic/video_splash.cpp +++ b/src/system/boot/platform/generic/video_splash.cpp @@ -16,7 +16,6 @@ #include #include -#include #include @@ -81,14 +80,31 @@ uncompress(const uint8 compressed[], unsigned int compressedSize, extern "C" status_t -video_display_splash(addr_t frameBuffer, bool clear) +video_display_splash(addr_t frameBuffer) { if (!gKernelArgs.frame_buffer.enabled) return B_NO_INIT; - if (clear) - memset((void*)frameBuffer, 0, - gKernelArgs.frame_buffer.physical_buffer.size); + addr_t pos = 0; + // Limit area to clear to estimated screen area + // UEFI can happily report a >256M framebuffer + addr_t size = min_c(gKernelArgs.frame_buffer.width + * gKernelArgs.frame_buffer.height * 4, + gKernelArgs.frame_buffer.physical_buffer.size); + + if (size >= 64) { + // Align writes + for (addr_t align = 8 - (frameBuffer & 7); pos < align; pos++) + *(char*)(frameBuffer + pos) = 0; + // Write eight bytes, many many times, but not too many + for (addr_t alignSize = size - 8; pos < alignSize; pos +=8) { + *(uint32*)(frameBuffer + pos) = 0; + *(uint32*)(frameBuffer + pos + 4) = 0; + } + } + // Write a few bytes more + for (; pos < size; pos++) + *(char*)(frameBuffer + pos) = 0; uint8* uncompressedLogo = NULL; unsigned int uncompressedSize = kSplashLogoWidth * kSplashLogoHeight; diff --git a/src/system/boot/platform/openfirmware/video.cpp b/src/system/boot/platform/openfirmware/video.cpp index 38c6646d6e..639723d09b 100644 --- a/src/system/boot/platform/openfirmware/video.cpp +++ b/src/system/boot/platform/openfirmware/video.cpp @@ -93,8 +93,7 @@ platform_switch_to_logo(void) gKernelArgs.frame_buffer.enabled = true; // the memory will be identity-mapped already - video_display_splash(gKernelArgs.frame_buffer.physical_buffer.start, - true); + video_display_splash(gKernelArgs.frame_buffer.physical_buffer.start); } diff --git a/src/system/boot/platform/u-boot/video.cpp b/src/system/boot/platform/u-boot/video.cpp index e2392c1146..1c149b0523 100644 --- a/src/system/boot/platform/u-boot/video.cpp +++ b/src/system/boot/platform/u-boot/video.cpp @@ -89,7 +89,7 @@ platform_switch_to_logo(void) return; } - err = video_display_splash(gFramebuffer->Base(), true); + err = video_display_splash(gFramebuffer->Base()); } }