Skip to contentSkip to conversation

drm/log: Add an automatic integer scaling

PATCH In review Jocelyn Falempe 2 participants 7 messages Nov 24 – Nov 30

Subsystems (3)
lore
Share & tools
lore

Jocelyn Falempe

author maintainer
#0 lore raw

PATCH 1/1 drm/log: Add an automatic integer scaling

On HiDPI screen, the default font might be too small, so if no scaling is specified, try to upscale reasonably.
The auto scaling is computed for each display.

---
 drivers/gpu/drm/clients/drm_log.c | 36 ++++++++++++++++++++-----------
 1 file changed, 24 insertions(+), 12 deletions(-)
drivers/gpu/drm/clients/drm_log.c +24 -12
index 4654091fe11a..7a0db2690b55 100644
@@ -25,9 +25,9 @@ MODULE_AUTHOR("Jocelyn Falempe");
 MODULE_DESCRIPTION("DRM boot logger");
 MODULE_LICENSE("GPL");
 
-static unsigned int scale = 1;
+static unsigned int scale = 0;
 module_param(scale, uint, 0444);
-MODULE_PARM_DESC(scale, "Integer scaling factor for drm_log, default is 1");
+MODULE_PARM_DESC(scale, "Integer scaling factor for drm_log, default is 0 (auto)");
 
 /**
  * DOC: overview
@@ -42,6 +42,7 @@ struct drm_log_scanout {
 	const struct font_desc *font;
 	u32 rows;
 	u32 columns;
+	u32 scale;
 	u32 scaled_font_h;
 	u32 scaled_font_w;
 	u32 line;
@@ -72,17 +73,17 @@ static struct drm_log *console_to_drm_log(struct console *con)
 
 static void drm_log_blit(struct iosys_map *dst, unsigned int dst_pitch,
 			 const u8 *src, unsigned int src_pitch,
-			 u32 height, u32 width, u32 px_width, u32 color)
+			 u32 height, u32 width, u32 blit_scale, u32 px_width, u32 color)
 {
 	switch (px_width) {
 	case 2:
-		drm_draw_blit16(dst, dst_pitch, src, src_pitch, height, width, scale, color);
+		drm_draw_blit16(dst, dst_pitch, src, src_pitch, height, width, blit_scale, color);
 		break;
 	case 3:
-		drm_draw_blit24(dst, dst_pitch, src, src_pitch, height, width, scale, color);
+		drm_draw_blit24(dst, dst_pitch, src, src_pitch, height, width, blit_scale, color);
 		break;
 	case 4:
-		drm_draw_blit32(dst, dst_pitch, src, src_pitch, height, width, scale, color);
+		drm_draw_blit32(dst, dst_pitch, src, src_pitch, height, width, blit_scale, color);
 		break;
 	default:
 		WARN_ONCE(1, "Can't blit with pixel width %d\n", px_width);
@@ -122,7 +123,7 @@ static void drm_log_draw_line(struct drm_log_scanout *scanout, const char *s,
 		if (src)
 			drm_log_blit(&map, fb->pitches[0], src, font_pitch,
 				     scanout->scaled_font_h, scanout->scaled_font_w,
-				     px_width, color);
+				     scanout->scale, px_width, color);
 		iosys_map_incr(&map, scanout->scaled_font_w * px_width);
 	}
 
@@ -206,6 +207,15 @@ static u32 drm_log_find_usable_format(struct drm_plane *plane)
 	return DRM_FORMAT_INVALID;
 }
 
+/* Find the biggest integer scaling to get about 120x50 chars on the screen */
+static int auto_scale(unsigned int cols, unsigned int rows)
+{
+	unsigned int scale_w = DIV_ROUND_CLOSEST(cols, 120);
+	unsigned int scale_h = DIV_ROUND_CLOSEST(rows, 50);
+
+	return max(min(scale_w, scale_h), 1);
+}
+
 static int drm_log_setup_modeset(struct drm_client_dev *client,
 				 struct drm_mode_set *mode_set,
 				 struct drm_log_scanout *scanout)
@@ -230,8 +240,13 @@ static int drm_log_setup_modeset(struct drm_client_dev *client,
 		return -ENOMEM;
 	}
 	mode_set->fb = scanout->buffer->fb;
-	scanout->scaled_font_h = scanout->font->height * scale;
-	scanout->scaled_font_w = scanout->font->width * scale;
+	if (scale)
+		scanout->scale = scale;
+	else
+		scanout->scale = auto_scale(width / scanout->font->width,
+			                    height / scanout->font->height);
+	scanout->scaled_font_h = scanout->font->height * scanout->scale;
+	scanout->scaled_font_w = scanout->font->width * scanout->scale;
 	scanout->rows = height / scanout->scaled_font_h;
 	scanout->columns = width / scanout->scaled_font_w;
 	if (!scanout->rows || !scanout->columns) {
@@ -444,9 +459,6 @@ void drm_log_register(struct drm_device *dev)
 {
 	struct drm_log *new;
 
-	if (!scale)
-		scale = 1;
-
 	new = kzalloc_obj(*new);
 	if (!new)
 		goto err_warn;

base-commit: bcf5c42d6ed136cc407cea896f131d6893c830af

Signature · 1 line
2.56.1
#1 lore raw

Hi Jocelyn

Am 24.11.26 um 23:42 schrieb Jocelyn Falempe:

Quoted 65 lines

On HiDPI screen, the default font might be too small, so if no scaling is specified, try to upscale reasonably.
The auto scaling is computed for each display.

---
  drivers/gpu/drm/clients/drm_log.c | 36 ++++++++++++++++++++-----------
  1 file changed, 24 insertions(+), 12 deletions(-)
drivers/gpu/drm/clients/drm_log.c +8 -7
index 4654091fe11a..7a0db2690b55 100644
@@ -25,9 +25,9 @@ MODULE_AUTHOR("Jocelyn Falempe");
  MODULE_DESCRIPTION("DRM boot logger");
  MODULE_LICENSE("GPL");
 
-static unsigned int scale = 1;
+static unsigned int scale = 0;
  module_param(scale, uint, 0444);
-MODULE_PARM_DESC(scale, "Integer scaling factor for drm_log, default is 1");
+MODULE_PARM_DESC(scale, "Integer scaling factor for drm_log, default is 0 (auto)");
 
  /**
   * DOC: overview
@@ -42,6 +42,7 @@ struct drm_log_scanout {
  	const struct font_desc *font;
  	u32 rows;
  	u32 columns;
+	u32 scale;
  	u32 scaled_font_h;
  	u32 scaled_font_w;
  	u32 line;
@@ -72,17 +73,17 @@ static struct drm_log *console_to_drm_log(struct console *con)
 
  static void drm_log_blit(struct iosys_map *dst, unsigned int dst_pitch,
  			 const u8 *src, unsigned int src_pitch,
-			 u32 height, u32 width, u32 px_width, u32 color)
+			 u32 height, u32 width, u32 blit_scale, u32 px_width, u32 color)
  {
  	switch (px_width) {
  	case 2:
-		drm_draw_blit16(dst, dst_pitch, src, src_pitch, height, width, scale, color);
+		drm_draw_blit16(dst, dst_pitch, src, src_pitch, height, width, blit_scale, color);
  		break;
  	case 3:
-		drm_draw_blit24(dst, dst_pitch, src, src_pitch, height, width, scale, color);
+		drm_draw_blit24(dst, dst_pitch, src, src_pitch, height, width, blit_scale, color);
  		break;
  	case 4:
-		drm_draw_blit32(dst, dst_pitch, src, src_pitch, height, width, scale, color);
+		drm_draw_blit32(dst, dst_pitch, src, src_pitch, height, width, blit_scale, color);
  		break;
  	default:
  		WARN_ONCE(1, "Can't blit with pixel width %d\n", px_width);
@@ -122,7 +123,7 @@ static void drm_log_draw_line(struct drm_log_scanout *scanout, const char *s,
  		if (src)
  			drm_log_blit(&map, fb->pitches[0], src, font_pitch,
  				     scanout->scaled_font_h, scanout->scaled_font_w,
-				     px_width, color);
+				     scanout->scale, px_width, color);
  		iosys_map_incr(&map, scanout->scaled_font_w * px_width);
  	}
 

drivers/gpu/drm/clients/drm_log.c static u32 drm_log_find_usable_format(struct drm_plane *plane) · line 210

Quoted 4 lines
drivers/gpu/drm/clients/drm_log.c +1 -0
@@ -206,6 +207,15 @@ static u32 drm_log_find_usable_format(struct drm_plane *plane)
  	return DRM_FORMAT_INVALID;
  }
 
+/* Find the biggest integer scaling to get about 120x50 chars on the screen */

Something like 80x30 (VGA mode 0x17) or 80x50 (VGA mode 0x102) seems natural. But what is the reason for 120x50?

Best regards
Thomas

Quoted 39 lines
drivers/gpu/drm/clients/drm_log.c +15 -5
+static int auto_scale(unsigned int cols, unsigned int rows)
+{
+	unsigned int scale_w = DIV_ROUND_CLOSEST(cols, 120);
+	unsigned int scale_h = DIV_ROUND_CLOSEST(rows, 50);
+
+	return max(min(scale_w, scale_h), 1);
+}
+
  static int drm_log_setup_modeset(struct drm_client_dev *client,
  				 struct drm_mode_set *mode_set,
  				 struct drm_log_scanout *scanout)
@@ -230,8 +240,13 @@ static int drm_log_setup_modeset(struct drm_client_dev *client,
  		return -ENOMEM;
  	}
  	mode_set->fb = scanout->buffer->fb;
-	scanout->scaled_font_h = scanout->font->height * scale;
-	scanout->scaled_font_w = scanout->font->width * scale;
+	if (scale)
+		scanout->scale = scale;
+	else
+		scanout->scale = auto_scale(width / scanout->font->width,
+			                    height / scanout->font->height);
+	scanout->scaled_font_h = scanout->font->height * scanout->scale;
+	scanout->scaled_font_w = scanout->font->width * scanout->scale;
  	scanout->rows = height / scanout->scaled_font_h;
  	scanout->columns = width / scanout->scaled_font_w;
  	if (!scanout->rows || !scanout->columns) {
@@ -444,9 +459,6 @@ void drm_log_register(struct drm_device *dev)
  {
  	struct drm_log *new;
 
-	if (!scale)
-		scale = 1;
-
  	new = kzalloc_obj(*new);
  	if (!new)
  		goto err_warn;

base-commit: bcf5c42d6ed136cc407cea896f131d6893c830af

Signature · 6 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Stefan Gaiser, Jochen Jaser, Abhinav Puri, (HRB 36809, AG Nürnberg)
author maintainer
#2 lore raw
Quoted 74 lines · Thomas Zimmermann

Hi Jocelyn

Am 24.11.26 um 23:42 schrieb Jocelyn Falempe:

Quoted 71 lines

On HiDPI screen, the default font might be too small, so if no scaling is specified, try to upscale reasonably.
The auto scaling is computed for each display.

---
  drivers/gpu/drm/clients/drm_log.c | 36 ++++++++++++++++++++-----------

  1 file changed, 24 insertions(+), 12 deletions(-)
drivers/gpu/drm/clients/drm_log.c +4 -3
index 4654091fe11a..7a0db2690b55 100644
@@ -25,9 +25,9 @@ MODULE_AUTHOR("Jocelyn Falempe");
   MODULE_DESCRIPTION("DRM boot logger");
   MODULE_LICENSE("GPL");
-static unsigned int scale = 1;
+static unsigned int scale = 0;
   module_param(scale, uint, 0444);
-MODULE_PARM_DESC(scale, "Integer scaling factor for drm_log, default 
 is 1");
+MODULE_PARM_DESC(scale, "Integer scaling factor for drm_log, default 
 is 0 (auto)");
   /**
    * DOC: overview
@@ -42,6 +42,7 @@ struct drm_log_scanout {
       const struct font_desc *font;
       u32 rows;
       u32 columns;
+    u32 scale;
       u32 scaled_font_h;
       u32 scaled_font_w;
       u32 line;
@@ -72,17 +73,17 @@ static struct drm_log *console_to_drm_log(struct 
 console *con)
   static void drm_log_blit(struct iosys_map *dst, unsigned int dst_pitch,
                const u8 *src, unsigned int src_pitch,
-             u32 height, u32 width, u32 px_width, u32 color)
+             u32 height, u32 width, u32 blit_scale, u32 px_width, u32 
 color)
   {
       switch (px_width) {

      case 2:
-        drm_draw_blit16(dst, dst_pitch, src, src_pitch, height, width, scale, color);
+        drm_draw_blit16(dst, dst_pitch, src, src_pitch, height, width, blit_scale, color);
          break;
      case 3:
-        drm_draw_blit24(dst, dst_pitch, src, src_pitch, height, width, scale, color);
+        drm_draw_blit24(dst, dst_pitch, src, src_pitch, height, width, blit_scale, color);
          break;
      case 4:
-        drm_draw_blit32(dst, dst_pitch, src, src_pitch, height, width, scale, color);
+        drm_draw_blit32(dst, dst_pitch, src, src_pitch, height, width, blit_scale, color);
          break;
      default:
          WARN_ONCE(1, "Can't blit with pixel width %d\n", px_width);

drivers/gpu/drm/clients/drm_log.c +1 -1
@@ -122,7 +123,7 @@ static void drm_log_draw_line(struct 
 drm_log_scanout *scanout, const char *s,
           if (src)
               drm_log_blit(&map, fb->pitches[0], src, font_pitch,
                        scanout->scaled_font_h, scanout->scaled_font_w,
-                     px_width, color);
+                     scanout->scale, px_width, color);
           iosys_map_incr(&map, scanout->scaled_font_w * px_width);
       }
Quoted 8 lines
Quoted 6 lines
drivers/gpu/drm/clients/drm_log.c +1 -0
@@ -206,6 +207,15 @@ static u32 drm_log_find_usable_format(struct 
 drm_plane *plane)
       return DRM_FORMAT_INVALID;
   }
+/* Find the biggest integer scaling to get about 120x50 chars on the 

screen */

Something like 80x30 (VGA mode 0x17) or 80x50 (VGA mode 0x102) seems natural. But what is the reason for 120x50?

I think this was a good default with old 15" CRT at 640x480. But for example for code line length, it's now configured in the 100-120 range in most codebase. When looking at dmesg, a lot of lines are longer than 100, so 120 allows to avoid too much line splitting.
For the number of rows, it's important to have some log history, so 50 looks to be the sweet spot.
User can set a scaling manually, or build the kernel with bigger fonts if they don't like the default.

Currently, with 8x16 font (which is the most common), the default in full HD is 240x67. In 4K it's 480x135. So doing some integer scaling make the default experience much better.

Best regards,

Signature · 1 line
Jocelyn
Quoted 44 lines

Best regards
Thomas

Quoted 39 lines
drivers/gpu/drm/clients/drm_log.c +8 -0
+static int auto_scale(unsigned int cols, unsigned int rows)
+{
+    unsigned int scale_w = DIV_ROUND_CLOSEST(cols, 120);
+    unsigned int scale_h = DIV_ROUND_CLOSEST(rows, 50);
+
+    return max(min(scale_w, scale_h), 1);
+}
+

  static int drm_log_setup_modeset(struct drm_client_dev *client, struct drm_mode_set *mode_set, struct drm_log_scanout *scanout)

drivers/gpu/drm/clients/drm_log.c +7 -2
@@ -230,8 +240,13 @@ static int drm_log_setup_modeset(struct 
 drm_client_dev *client,
           return -ENOMEM;
       }
       mode_set->fb = scanout->buffer->fb;
-    scanout->scaled_font_h = scanout->font->height * scale;
-    scanout->scaled_font_w = scanout->font->width * scale;
+    if (scale)
+        scanout->scale = scale;
+    else
+        scanout->scale = auto_scale(width / scanout->font->width,
+                                height / scanout->font->height);
+    scanout->scaled_font_h = scanout->font->height * scanout->scale;
+    scanout->scaled_font_w = scanout->font->width * scanout->scale;
       scanout->rows = height / scanout->scaled_font_h;
       scanout->columns = width / scanout->scaled_font_w;

      if (!scanout->rows || !scanout->columns) {

drivers/gpu/drm/clients/drm_log.c +0 -3
@@ -444,9 +459,6 @@ void drm_log_register(struct drm_device *dev)
   {
       struct drm_log *new;
-    if (!scale)
-        scale = 1;
-
       new = kzalloc_obj(*new);
       if (!new)
           goto err_warn;
 

base-commit: bcf5c42d6ed136cc407cea896f131d6893c830af

#3 lore raw

Hi

Am 26.11.26 um 10:02 schrieb Jocelyn Falempe:

Quoted 85 lines · Thomas Zimmermann
Quoted 75 lines

Hi Jocelyn

Am 24.11.26 um 23:42 schrieb Jocelyn Falempe:

Quoted 72 lines

On HiDPI screen, the default font might be too small, so if no scaling is specified, try to upscale reasonably.
The auto scaling is computed for each display.

---
  drivers/gpu/drm/clients/drm_log.c | 36
++++++++++++++++++++-----------

  1 file changed, 24 insertions(+), 12 deletions(-)
drivers/gpu/drm/clients/drm_log.c +4 -3
index 4654091fe11a..7a0db2690b55 100644
@@ -25,9 +25,9 @@ MODULE_AUTHOR("Jocelyn Falempe");
   MODULE_DESCRIPTION("DRM boot logger");
   MODULE_LICENSE("GPL");
-static unsigned int scale = 1;
+static unsigned int scale = 0;
   module_param(scale, uint, 0444);
-MODULE_PARM_DESC(scale, "Integer scaling factor for drm_log, 
 default is 1");
+MODULE_PARM_DESC(scale, "Integer scaling factor for drm_log, 
 default is 0 (auto)");
   /**
    * DOC: overview
@@ -42,6 +42,7 @@ struct drm_log_scanout {
       const struct font_desc *font;
       u32 rows;
       u32 columns;
+    u32 scale;
       u32 scaled_font_h;
       u32 scaled_font_w;
       u32 line;
@@ -72,17 +73,17 @@ static struct drm_log *console_to_drm_log(struct 
 console *con)
   static void drm_log_blit(struct iosys_map *dst, unsigned int dst_pitch,
                const u8 *src, unsigned int src_pitch,
-             u32 height, u32 width, u32 px_width, u32 color)
+             u32 height, u32 width, u32 blit_scale, u32 px_width, 
 u32 color)
   {
       switch (px_width) {

      case 2:
-        drm_draw_blit16(dst, dst_pitch, src, src_pitch, height, width, scale, color);
+        drm_draw_blit16(dst, dst_pitch, src, src_pitch, height, width, blit_scale, color);
          break;
      case 3:
-        drm_draw_blit24(dst, dst_pitch, src, src_pitch, height, width, scale, color);
+        drm_draw_blit24(dst, dst_pitch, src, src_pitch, height, width, blit_scale, color);
          break;
      case 4:
-        drm_draw_blit32(dst, dst_pitch, src, src_pitch, height, width, scale, color);
+        drm_draw_blit32(dst, dst_pitch, src, src_pitch, height, width, blit_scale, color);
          break;
      default:
          WARN_ONCE(1, "Can't blit with pixel width %d\n", px_width);

drivers/gpu/drm/clients/drm_log.c +1 -1
@@ -122,7 +123,7 @@ static void drm_log_draw_line(struct 
 drm_log_scanout *scanout, const char *s,
           if (src)
               drm_log_blit(&map, fb->pitches[0], src, font_pitch,
                        scanout->scaled_font_h, scanout->scaled_font_w,
-                     px_width, color);
+                     scanout->scale, px_width, color);
           iosys_map_incr(&map, scanout->scaled_font_w * px_width);
       }
Quoted 8 lines
Quoted 6 lines
drivers/gpu/drm/clients/drm_log.c +1 -0
@@ -206,6 +207,15 @@ static u32 drm_log_find_usable_format(struct 
 drm_plane *plane)
       return DRM_FORMAT_INVALID;
   }
+/* Find the biggest integer scaling to get about 120x50 chars on 

the screen */

Something like 80x30 (VGA mode 0x17) or 80x50 (VGA mode 0x102) seems natural. But what is the reason for 120x50?

Quoted 4 lines

I think this was a good default with old 15" CRT at 640x480. But for example for code line length, it's now configured in the 100-120 range in most codebase. When looking at dmesg, a lot of lines are longer than 100, so 120 allows to avoid too much line splitting.
For the number of rows, it's important to have some log history, so 50 looks to be the sweet spot.
User can set a scaling manually, or build the kernel with bigger fonts if they don't like the default.

Some general thoughts on this:

Each font is designed for it's specific glyph resolution. Therefore, I think it is a problem to scale x and y independent from each other. That can mess up the font. I'd suggest to make the output aim for a certain display height. Text runs from top to bottom and number of lines is usually what people care for most. OTOH the display's right side is usually empty.

I agree that the original VGA mode 0x17 is a bit short one lines. The 50 lines you choose seem right to me. For the number of lines, I'd start with the current font and scale if the number of lines becomes too large. So that the resulting console has between 30 and 70 lines.

For the number of columns, why not pick the preferred number of columns in relation to the scaled font height and the display-mode resolution? That keeps the font geometry at a correct ratio.

I know all this is close to nitpicking and maybe the code does some of this already. I just think it's important to make it look good on a variety of displays.

Quoted 2 lines

Currently, with 8x16 font (which is the most common), the default in full HD is 240x67. In 4K it's 480x135. So doing some integer scaling make the default experience much better.

Right, the current fonts are too small on modern displays.

Best regards
Thomas

Quoted 3 lines

Best regards,

Signature · 6 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Stefan Gaiser, Jochen Jaser, Abhinav Puri, (HRB 36809, AG Nürnberg)
author maintainer
#4 lore raw
Quoted 88 lines · Thomas Zimmermann

Hi

Am 26.11.26 um 10:02 schrieb Jocelyn Falempe:

Quoted 85 lines · Thomas Zimmermann
Quoted 83 lines

Hi Jocelyn

Am 24.11.26 um 23:42 schrieb Jocelyn Falempe:

Quoted 77 lines

On HiDPI screen, the default font might be too small, so if no scaling is specified, try to upscale reasonably.
The auto scaling is computed for each display.

---
  drivers/gpu/drm/clients/drm_log.c | 36 +++++++++++++++++++
+-----------

  1 file changed, 24 insertions(+), 12 deletions(-)
drivers/gpu/drm/clients/drm_log.c +4 -3
index 4654091fe11a..7a0db2690b55 100644
@@ -25,9 +25,9 @@ MODULE_AUTHOR("Jocelyn Falempe");
   MODULE_DESCRIPTION("DRM boot logger");
   MODULE_LICENSE("GPL");
-static unsigned int scale = 1;
+static unsigned int scale = 0;
   module_param(scale, uint, 0444);
-MODULE_PARM_DESC(scale, "Integer scaling factor for drm_log, 
 default is 1");
+MODULE_PARM_DESC(scale, "Integer scaling factor for drm_log, 
 default is 0 (auto)");
   /**
    * DOC: overview
@@ -42,6 +42,7 @@ struct drm_log_scanout {
       const struct font_desc *font;
       u32 rows;
       u32 columns;
+    u32 scale;
       u32 scaled_font_h;
       u32 scaled_font_w;
       u32 line;
@@ -72,17 +73,17 @@ static struct drm_log *console_to_drm_log(struct 
 console *con)
   static void drm_log_blit(struct iosys_map *dst, unsigned int dst_pitch,
                const u8 *src, unsigned int src_pitch,
-             u32 height, u32 width, u32 px_width, u32 color)
+             u32 height, u32 width, u32 blit_scale, u32 px_width, 
 u32 color)
   {
       switch (px_width) {

      case 2:
-        drm_draw_blit16(dst, dst_pitch, src, src_pitch, height, width, scale, color);
+        drm_draw_blit16(dst, dst_pitch, src, src_pitch, height, width, blit_scale, color);
          break;
      case 3:
-        drm_draw_blit24(dst, dst_pitch, src, src_pitch, height, width, scale, color);
+        drm_draw_blit24(dst, dst_pitch, src, src_pitch, height, width, blit_scale, color);
          break;
      case 4:
-        drm_draw_blit32(dst, dst_pitch, src, src_pitch, height, width, scale, color);
+        drm_draw_blit32(dst, dst_pitch, src, src_pitch, height, width, blit_scale, color);
          break;
      default:
          WARN_ONCE(1, "Can't blit with pixel width %d\n", px_width);

drivers/gpu/drm/clients/drm_log.c +2 -1
@@ -122,7 +123,7 @@ static void drm_log_draw_line(struct 
 drm_log_scanout *scanout, const char *s,
           if (src)
               drm_log_blit(&map, fb->pitches[0], src, font_pitch,
                        scanout->scaled_font_h, scanout->scaled_font_w,
-                     px_width, color);
+                     scanout->scale, px_width, color);
           iosys_map_incr(&map, scanout->scaled_font_w * px_width);
       }
@@ -206,6 +207,15 @@ static u32 drm_log_find_usable_format(struct 
 drm_plane *plane)
       return DRM_FORMAT_INVALID;
   }
+/* Find the biggest integer scaling to get about 120x50 chars on 
Quoted 1 line

the screen */

Something like 80x30 (VGA mode 0x17) or 80x50 (VGA mode 0x102) seems natural. But what is the reason for 120x50?

Quoted 8 lines
Quoted 4 lines

I think this was a good default with old 15" CRT at 640x480. But for example for code line length, it's now configured in the 100-120 range in most codebase. When looking at dmesg, a lot of lines are longer than 100, so 120 allows to avoid too much line splitting.
For the number of rows, it's important to have some log history, so 50 looks to be the sweet spot.
User can set a scaling manually, or build the kernel with bigger fonts if they don't like the default.

Some general thoughts on this:

Each font is designed for it's specific glyph resolution. Therefore, I think it is a problem to scale x and y independent from each other. That can mess up the font. I'd suggest to make the output aim for a certain display height. Text runs from top to bottom and number of lines is usually what people care for most. OTOH the display's right side is usually empty.

Integer scaling is the same for x and y, otherwise I agree, the font would be distorted.

static int auto_scale(unsigned int cols, unsigned int rows)

{
	unsigned int scale_w = DIV_ROUND_CLOSEST(cols, 120);
	unsigned int scale_h = DIV_ROUND_CLOSEST(rows, 50);

	return max(min(scale_w, scale_h), 1);
}

This calculates the "optimal" scaling for width and height but then takes the min of both, and make sure it's 1 or more.

Quoted 2 lines

I agree that the original VGA mode 0x17 is a bit short one lines. The 50 lines you choose seem right to me. For the number of lines, I'd start with the current font and scale if the number of lines becomes too large. So that the resulting console has between 30 and 70 lines.

I think the minimum number of lines, is if you have 76 rows with scale=1, then autoscale will apply a scale of 2, ending up with 38 rows. for larger number of rows, it will be closer to 50.

Quoted 7 lines

For the number of columns, why not pick the preferred number of columns in relation to the scaled font height and the display-mode resolution? That keeps the font geometry at a correct ratio.

I know all this is close to nitpicking and maybe the code does some of this already. I just think it's important to make it look good on a variety of displays.

Quoted 1 line
Quoted 11 lines
Quoted 1 line

Currently, with 8x16 font (which is the most common), the default in full HD is 240x67. In 4K it's 480x135. So doing some integer scaling make the default experience much better.

Right, the current fonts are too small on modern displays.

Best regards
Thomas

Quoted 3 lines

Best regards,

Thanks for the review.

Best regards,

Signature · 1 line
Jocelyn
maintainer Reviewed-by on v1 1/1
#5 lore raw
In reply to Jocelyn Falempe

Am 24.11.26 um 23:42 schrieb Jocelyn Falempe:

Quoted 5 lines

On HiDPI screen, the default font might be too small, so if no scaling is specified, try to upscale reasonably.
The auto scaling is computed for each display.

I think this change could be merged, but please see my thoughts on picking the optimal sizes.

Quoted 103 lines
---
  drivers/gpu/drm/clients/drm_log.c | 36 ++++++++++++++++++++-----------
  1 file changed, 24 insertions(+), 12 deletions(-)
drivers/gpu/drm/clients/drm_log.c +24 -12
index 4654091fe11a..7a0db2690b55 100644
@@ -25,9 +25,9 @@ MODULE_AUTHOR("Jocelyn Falempe");
  MODULE_DESCRIPTION("DRM boot logger");
  MODULE_LICENSE("GPL");
 
-static unsigned int scale = 1;
+static unsigned int scale = 0;
  module_param(scale, uint, 0444);
-MODULE_PARM_DESC(scale, "Integer scaling factor for drm_log, default is 1");
+MODULE_PARM_DESC(scale, "Integer scaling factor for drm_log, default is 0 (auto)");
 
  /**
   * DOC: overview
@@ -42,6 +42,7 @@ struct drm_log_scanout {
  	const struct font_desc *font;
  	u32 rows;
  	u32 columns;
+	u32 scale;
  	u32 scaled_font_h;
  	u32 scaled_font_w;
  	u32 line;
@@ -72,17 +73,17 @@ static struct drm_log *console_to_drm_log(struct console *con)
 
  static void drm_log_blit(struct iosys_map *dst, unsigned int dst_pitch,
  			 const u8 *src, unsigned int src_pitch,
-			 u32 height, u32 width, u32 px_width, u32 color)
+			 u32 height, u32 width, u32 blit_scale, u32 px_width, u32 color)
  {
  	switch (px_width) {
  	case 2:
-		drm_draw_blit16(dst, dst_pitch, src, src_pitch, height, width, scale, color);
+		drm_draw_blit16(dst, dst_pitch, src, src_pitch, height, width, blit_scale, color);
  		break;
  	case 3:
-		drm_draw_blit24(dst, dst_pitch, src, src_pitch, height, width, scale, color);
+		drm_draw_blit24(dst, dst_pitch, src, src_pitch, height, width, blit_scale, color);
  		break;
  	case 4:
-		drm_draw_blit32(dst, dst_pitch, src, src_pitch, height, width, scale, color);
+		drm_draw_blit32(dst, dst_pitch, src, src_pitch, height, width, blit_scale, color);
  		break;
  	default:
  		WARN_ONCE(1, "Can't blit with pixel width %d\n", px_width);
@@ -122,7 +123,7 @@ static void drm_log_draw_line(struct drm_log_scanout *scanout, const char *s,
  		if (src)
  			drm_log_blit(&map, fb->pitches[0], src, font_pitch,
  				     scanout->scaled_font_h, scanout->scaled_font_w,
-				     px_width, color);
+				     scanout->scale, px_width, color);
  		iosys_map_incr(&map, scanout->scaled_font_w * px_width);
  	}
 
@@ -206,6 +207,15 @@ static u32 drm_log_find_usable_format(struct drm_plane *plane)
  	return DRM_FORMAT_INVALID;
  }
 
+/* Find the biggest integer scaling to get about 120x50 chars on the screen */
+static int auto_scale(unsigned int cols, unsigned int rows)
+{
+	unsigned int scale_w = DIV_ROUND_CLOSEST(cols, 120);
+	unsigned int scale_h = DIV_ROUND_CLOSEST(rows, 50);
+
+	return max(min(scale_w, scale_h), 1);
+}
+
  static int drm_log_setup_modeset(struct drm_client_dev *client,
  				 struct drm_mode_set *mode_set,
  				 struct drm_log_scanout *scanout)
@@ -230,8 +240,13 @@ static int drm_log_setup_modeset(struct drm_client_dev *client,
  		return -ENOMEM;
  	}
  	mode_set->fb = scanout->buffer->fb;
-	scanout->scaled_font_h = scanout->font->height * scale;
-	scanout->scaled_font_w = scanout->font->width * scale;
+	if (scale)
+		scanout->scale = scale;
+	else
+		scanout->scale = auto_scale(width / scanout->font->width,
+			                    height / scanout->font->height);
+	scanout->scaled_font_h = scanout->font->height * scanout->scale;
+	scanout->scaled_font_w = scanout->font->width * scanout->scale;
  	scanout->rows = height / scanout->scaled_font_h;
  	scanout->columns = width / scanout->scaled_font_w;
  	if (!scanout->rows || !scanout->columns) {
@@ -444,9 +459,6 @@ void drm_log_register(struct drm_device *dev)
  {
  	struct drm_log *new;
 
-	if (!scale)
-		scale = 1;
-
  	new = kzalloc_obj(*new);
  	if (!new)
  		goto err_warn;

base-commit: bcf5c42d6ed136cc407cea896f131d6893c830af

Signature · 6 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Stefan Gaiser, Jochen Jaser, Abhinav Puri, (HRB 36809, AG Nürnberg)
author maintainer
#6 lore raw
Quoted 7 lines · Thomas Zimmermann

Am 24.11.26 um 23:42 schrieb Jocelyn Falempe:

Quoted 4 lines

On HiDPI screen, the default font might be too small, so if no scaling is specified, try to upscale reasonably.
The auto scaling is computed for each display.

Quoted 5 lines
Quoted 1 line

I think this change could be merged, but please see my thoughts on picking the optimal sizes.

Thanks, I think that's close to what is implemented (scaling is the same for x and y).
I just pushed it to drm-misc-next. I fixed a checkpatch warning, that scale is static and doesn't need to be explicitly set to 0.

Best regards,

Signature · 1 line
Jocelyn
Quoted 114 lines
Quoted 113 lines

---
  drivers/gpu/drm/clients/drm_log.c | 36 ++++++++++++++++++++-----------

  1 file changed, 24 insertions(+), 12 deletions(-)
drivers/gpu/drm/clients/drm_log.c +4 -3
index 4654091fe11a..7a0db2690b55 100644
@@ -25,9 +25,9 @@ MODULE_AUTHOR("Jocelyn Falempe");
   MODULE_DESCRIPTION("DRM boot logger");
   MODULE_LICENSE("GPL");
-static unsigned int scale = 1;
+static unsigned int scale = 0;
   module_param(scale, uint, 0444);
-MODULE_PARM_DESC(scale, "Integer scaling factor for drm_log, default 
 is 1");
+MODULE_PARM_DESC(scale, "Integer scaling factor for drm_log, default 
 is 0 (auto)");
   /**
    * DOC: overview
@@ -42,6 +42,7 @@ struct drm_log_scanout {
       const struct font_desc *font;
       u32 rows;
       u32 columns;
+    u32 scale;
       u32 scaled_font_h;
       u32 scaled_font_w;
       u32 line;
@@ -72,17 +73,17 @@ static struct drm_log *console_to_drm_log(struct 
 console *con)
   static void drm_log_blit(struct iosys_map *dst, unsigned int dst_pitch,
                const u8 *src, unsigned int src_pitch,
-             u32 height, u32 width, u32 px_width, u32 color)
+             u32 height, u32 width, u32 blit_scale, u32 px_width, u32 
 color)
   {
       switch (px_width) {

      case 2:
-        drm_draw_blit16(dst, dst_pitch, src, src_pitch, height, width, scale, color);
+        drm_draw_blit16(dst, dst_pitch, src, src_pitch, height, width, blit_scale, color);
          break;
      case 3:
-        drm_draw_blit24(dst, dst_pitch, src, src_pitch, height, width, scale, color);
+        drm_draw_blit24(dst, dst_pitch, src, src_pitch, height, width, blit_scale, color);
          break;
      case 4:
-        drm_draw_blit32(dst, dst_pitch, src, src_pitch, height, width, scale, color);
+        drm_draw_blit32(dst, dst_pitch, src, src_pitch, height, width, blit_scale, color);
          break;
      default:
          WARN_ONCE(1, "Can't blit with pixel width %d\n", px_width);

drivers/gpu/drm/clients/drm_log.c +2 -1
@@ -122,7 +123,7 @@ static void drm_log_draw_line(struct 
 drm_log_scanout *scanout, const char *s,
           if (src)
               drm_log_blit(&map, fb->pitches[0], src, font_pitch,
                        scanout->scaled_font_h, scanout->scaled_font_w,
-                     px_width, color);
+                     scanout->scale, px_width, color);
           iosys_map_incr(&map, scanout->scaled_font_w * px_width);
       }
@@ -206,6 +207,15 @@ static u32 drm_log_find_usable_format(struct 
 drm_plane *plane)
       return DRM_FORMAT_INVALID;
   }
+/* Find the biggest integer scaling to get about 120x50 chars on the 

screen */

drivers/gpu/drm/clients/drm_log.c +8 -0
+static int auto_scale(unsigned int cols, unsigned int rows)
+{
+    unsigned int scale_w = DIV_ROUND_CLOSEST(cols, 120);
+    unsigned int scale_h = DIV_ROUND_CLOSEST(rows, 50);
+
+    return max(min(scale_w, scale_h), 1);
+}
+

  static int drm_log_setup_modeset(struct drm_client_dev *client, struct drm_mode_set *mode_set, struct drm_log_scanout *scanout)

drivers/gpu/drm/clients/drm_log.c +7 -2
@@ -230,8 +240,13 @@ static int drm_log_setup_modeset(struct 
 drm_client_dev *client,
           return -ENOMEM;
       }
       mode_set->fb = scanout->buffer->fb;
-    scanout->scaled_font_h = scanout->font->height * scale;
-    scanout->scaled_font_w = scanout->font->width * scale;
+    if (scale)
+        scanout->scale = scale;
+    else
+        scanout->scale = auto_scale(width / scanout->font->width,
+                                height / scanout->font->height);
+    scanout->scaled_font_h = scanout->font->height * scanout->scale;
+    scanout->scaled_font_w = scanout->font->width * scanout->scale;
       scanout->rows = height / scanout->scaled_font_h;
       scanout->columns = width / scanout->scaled_font_w;

      if (!scanout->rows || !scanout->columns) {

drivers/gpu/drm/clients/drm_log.c +0 -3
@@ -444,9 +459,6 @@ void drm_log_register(struct drm_device *dev)
   {
       struct drm_log *new;
-    if (!scale)
-        scale = 1;
-
       new = kzalloc_obj(*new);
       if (!new)
           goto err_warn;
 

base-commit: bcf5c42d6ed136cc407cea896f131d6893c830af