linux-fbdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH resend 0/5] video: fbdev: ssd1307fb: Optimizations and improvements
@ 2021-07-14 14:57 Geert Uytterhoeven
  2021-07-14 14:58 ` [PATCH resend 1/5] video: fbdev: ssd1307fb: Propagate errors via ssd1307fb_update_display() Geert Uytterhoeven
                   ` (6 more replies)
  0 siblings, 7 replies; 13+ messages in thread
From: Geert Uytterhoeven @ 2021-07-14 14:57 UTC (permalink / raw)
  To: David Airlie, Daniel Vetter, Maxime Ripard
  Cc: linux-fbdev, dri-devel, linux-kernel, Geert Uytterhoeven

	Hi all,

This patch series optimizes console operations on ssd1307fb, after the
customary fixes and cleanups.

Currently, each screen update triggers an I2C transfer of all screen
data, up to 1 KiB of data for a 128x64 display, which takes at least 20
ms in Fast mode.  While many displays are smaller, and thus require less
data to be transferred, 20 ms is still an optimistic value, as the
actual data transfer may be much slower, especially on bitbanged I2C
drivers.  After this series, the amount of data transfer is reduced, as
fillrect, copyarea, and imageblit only update the rectangle that
changed.

This has been tested on an Adafruit FeatherWing OLED with an SSD1306
controller and a 128x32 OLED, connected to an OrangeCrab ECP5 FPGA board
running a 64 MHz VexRiscv RISC-V softcore, where it reduced the CPU
usage for blinking the cursor from more than 70% to ca. 10%.

Thanks for your comments!

Geert Uytterhoeven (5):
  video: fbdev: ssd1307fb: Propagate errors via
    ssd1307fb_update_display()
  video: fbdev: ssd1307fb: Simplify ssd1307fb_update_display()
  video: fbdev: ssd1307fb: Extract ssd1307fb_set_address_range()
  video: fbdev: ssd1307fb: Optimize screen updates
  video: fbdev: ssd1307fb: Cache address ranges

 drivers/video/fbdev/ssd1307fb.c | 143 +++++++++++++++++++++-----------
 1 file changed, 96 insertions(+), 47 deletions(-)

-- 
2.25.1

Gr{oetje,eeting}s,

						Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
							    -- Linus Torvalds

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

* [PATCH resend 1/5] video: fbdev: ssd1307fb: Propagate errors via ssd1307fb_update_display()
  2021-07-14 14:57 [PATCH resend 0/5] video: fbdev: ssd1307fb: Optimizations and improvements Geert Uytterhoeven
@ 2021-07-14 14:58 ` Geert Uytterhoeven
  2021-07-14 14:58 ` [PATCH resend 2/5] video: fbdev: ssd1307fb: Simplify ssd1307fb_update_display() Geert Uytterhoeven
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 13+ messages in thread
From: Geert Uytterhoeven @ 2021-07-14 14:58 UTC (permalink / raw)
  To: David Airlie, Daniel Vetter, Maxime Ripard
  Cc: linux-fbdev, dri-devel, linux-kernel, Geert Uytterhoeven

Make ssd1307fb_update_display() return an error code, so callers that
can handle failures can propagate it.

Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
---
 drivers/video/fbdev/ssd1307fb.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/drivers/video/fbdev/ssd1307fb.c b/drivers/video/fbdev/ssd1307fb.c
index eda448b7a0c9d8ce..e6b6263e3bef847f 100644
--- a/drivers/video/fbdev/ssd1307fb.c
+++ b/drivers/video/fbdev/ssd1307fb.c
@@ -152,17 +152,17 @@ static inline int ssd1307fb_write_cmd(struct i2c_client *client, u8 cmd)
 	return ret;
 }
 
-static void ssd1307fb_update_display(struct ssd1307fb_par *par)
+static int ssd1307fb_update_display(struct ssd1307fb_par *par)
 {
 	struct ssd1307fb_array *array;
 	u8 *vmem = par->info->screen_buffer;
 	unsigned int line_length = par->info->fix.line_length;
 	unsigned int pages = DIV_ROUND_UP(par->height, 8);
-	int i, j, k;
+	int ret, i, j, k;
 
 	array = ssd1307fb_alloc_array(par->width * pages, SSD1307FB_DATA);
 	if (!array)
-		return;
+		return -ENOMEM;
 
 	/*
 	 * The screen is divided in pages, each having a height of 8
@@ -210,8 +210,9 @@ static void ssd1307fb_update_display(struct ssd1307fb_par *par)
 		}
 	}
 
-	ssd1307fb_write_array(par->client, array, par->width * pages);
+	ret = ssd1307fb_write_array(par->client, array, par->width * pages);
 	kfree(array);
+	return ret;
 }
 
 
@@ -222,6 +223,7 @@ static ssize_t ssd1307fb_write(struct fb_info *info, const char __user *buf,
 	unsigned long total_size;
 	unsigned long p = *ppos;
 	void *dst;
+	int ret;
 
 	total_size = info->fix.smem_len;
 
@@ -239,7 +241,9 @@ static ssize_t ssd1307fb_write(struct fb_info *info, const char __user *buf,
 	if (copy_from_user(dst, buf, count))
 		return -EFAULT;
 
-	ssd1307fb_update_display(par);
+	ret = ssd1307fb_update_display(par);
+	if (ret < 0)
+		return ret;
 
 	*ppos += count;
 
@@ -483,7 +487,9 @@ static int ssd1307fb_init(struct ssd1307fb_par *par)
 		return ret;
 
 	/* Clear the screen */
-	ssd1307fb_update_display(par);
+	ret = ssd1307fb_update_display(par);
+	if (ret < 0)
+		return ret;
 
 	/* Turn on the display */
 	ret = ssd1307fb_write_cmd(par->client, SSD1307FB_DISPLAY_ON);
-- 
2.25.1


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

* [PATCH resend 2/5] video: fbdev: ssd1307fb: Simplify ssd1307fb_update_display()
  2021-07-14 14:57 [PATCH resend 0/5] video: fbdev: ssd1307fb: Optimizations and improvements Geert Uytterhoeven
  2021-07-14 14:58 ` [PATCH resend 1/5] video: fbdev: ssd1307fb: Propagate errors via ssd1307fb_update_display() Geert Uytterhoeven
@ 2021-07-14 14:58 ` Geert Uytterhoeven
       [not found]   ` <YPXM8AXNje7GXf+i@ravnborg.org>
  2021-07-14 14:58 ` [PATCH resend 3/5] video: fbdev: ssd1307fb: Extract ssd1307fb_set_address_range() Geert Uytterhoeven
                   ` (4 subsequent siblings)
  6 siblings, 1 reply; 13+ messages in thread
From: Geert Uytterhoeven @ 2021-07-14 14:58 UTC (permalink / raw)
  To: David Airlie, Daniel Vetter, Maxime Ripard
  Cc: linux-fbdev, dri-devel, linux-kernel, Geert Uytterhoeven

Simplify the nested loops to handle conversion from linear frame buffer
to ssd1307 page layout:
  1. Move last page handling one level up, as the value of "m" is the
     same inside a page,
  2. array->data[] is filled linearly, so there is no need to
     recalculate array_idx over and over again; a simple increment is
     sufficient.

Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
---
 drivers/video/fbdev/ssd1307fb.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/drivers/video/fbdev/ssd1307fb.c b/drivers/video/fbdev/ssd1307fb.c
index e6b6263e3bef847f..6d7bd025bca1a175 100644
--- a/drivers/video/fbdev/ssd1307fb.c
+++ b/drivers/video/fbdev/ssd1307fb.c
@@ -158,6 +158,7 @@ static int ssd1307fb_update_display(struct ssd1307fb_par *par)
 	u8 *vmem = par->info->screen_buffer;
 	unsigned int line_length = par->info->fix.line_length;
 	unsigned int pages = DIV_ROUND_UP(par->height, 8);
+	u32 array_idx = 0;
 	int ret, i, j, k;
 
 	array = ssd1307fb_alloc_array(par->width * pages, SSD1307FB_DATA);
@@ -194,19 +195,21 @@ static int ssd1307fb_update_display(struct ssd1307fb_par *par)
 	 */
 
 	for (i = 0; i < pages; i++) {
+		int m = 8;
+
+		/* Last page may be partial */
+		if (i + 1 == pages && par->height % 8)
+			m = par->height % 8;
 		for (j = 0; j < par->width; j++) {
-			int m = 8;
-			u32 array_idx = i * par->width + j;
-			array->data[array_idx] = 0;
-			/* Last page may be partial */
-			if (i + 1 == pages && par->height % 8)
-				m = par->height % 8;
+			u8 data = 0;
+
 			for (k = 0; k < m; k++) {
 				u8 byte = vmem[(8 * i + k) * line_length +
 					       j / 8];
 				u8 bit = (byte >> (j % 8)) & 1;
-				array->data[array_idx] |= bit << k;
+				data |= bit << k;
 			}
+			array->data[array_idx++] = data;
 		}
 	}
 
-- 
2.25.1


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

* [PATCH resend 3/5] video: fbdev: ssd1307fb: Extract ssd1307fb_set_address_range()
  2021-07-14 14:57 [PATCH resend 0/5] video: fbdev: ssd1307fb: Optimizations and improvements Geert Uytterhoeven
  2021-07-14 14:58 ` [PATCH resend 1/5] video: fbdev: ssd1307fb: Propagate errors via ssd1307fb_update_display() Geert Uytterhoeven
  2021-07-14 14:58 ` [PATCH resend 2/5] video: fbdev: ssd1307fb: Simplify ssd1307fb_update_display() Geert Uytterhoeven
@ 2021-07-14 14:58 ` Geert Uytterhoeven
       [not found]   ` <YPXNdJNpYoPSpxSb@ravnborg.org>
  2021-07-14 14:58 ` [PATCH resend 4/5] video: fbdev: ssd1307fb: Optimize screen updates Geert Uytterhoeven
                   ` (3 subsequent siblings)
  6 siblings, 1 reply; 13+ messages in thread
From: Geert Uytterhoeven @ 2021-07-14 14:58 UTC (permalink / raw)
  To: David Airlie, Daniel Vetter, Maxime Ripard
  Cc: linux-fbdev, dri-devel, linux-kernel, Geert Uytterhoeven

Extract the code to set the column and page ranges into a helper
function.

Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
---
 drivers/video/fbdev/ssd1307fb.c | 61 +++++++++++++++++++--------------
 1 file changed, 36 insertions(+), 25 deletions(-)

diff --git a/drivers/video/fbdev/ssd1307fb.c b/drivers/video/fbdev/ssd1307fb.c
index 6d7bd025bca1a175..cfa27ea0feab4f01 100644
--- a/drivers/video/fbdev/ssd1307fb.c
+++ b/drivers/video/fbdev/ssd1307fb.c
@@ -152,6 +152,38 @@ static inline int ssd1307fb_write_cmd(struct i2c_client *client, u8 cmd)
 	return ret;
 }
 
+static int ssd1307fb_set_address_range(struct ssd1307fb_par *par, u8 col_start,
+				       u8 cols, u8 page_start, u8 pages)
+{
+	u8 col_end = col_start + cols - 1;
+	u8 page_end = page_start + pages - 1;
+	int ret;
+
+	/* Set column range */
+	ret = ssd1307fb_write_cmd(par->client, SSD1307FB_SET_COL_RANGE);
+	if (ret < 0)
+		return ret;
+
+	ret = ssd1307fb_write_cmd(par->client, col_start);
+	if (ret < 0)
+		return ret;
+
+	ret = ssd1307fb_write_cmd(par->client, col_end);
+	if (ret < 0)
+		return ret;
+
+	/* Set page range */
+	ret = ssd1307fb_write_cmd(par->client, SSD1307FB_SET_PAGE_RANGE);
+	if (ret < 0)
+		return ret;
+
+	ret = ssd1307fb_write_cmd(par->client, page_start);
+	if (ret < 0)
+		return ret;
+
+	return ssd1307fb_write_cmd(par->client, page_end);
+}
+
 static int ssd1307fb_update_display(struct ssd1307fb_par *par)
 {
 	struct ssd1307fb_array *array;
@@ -461,31 +493,10 @@ static int ssd1307fb_init(struct ssd1307fb_par *par)
 	if (ret < 0)
 		return ret;
 
-	/* Set column range */
-	ret = ssd1307fb_write_cmd(par->client, SSD1307FB_SET_COL_RANGE);
-	if (ret < 0)
-		return ret;
-
-	ret = ssd1307fb_write_cmd(par->client, par->col_offset);
-	if (ret < 0)
-		return ret;
-
-	ret = ssd1307fb_write_cmd(par->client, par->col_offset + par->width - 1);
-	if (ret < 0)
-		return ret;
-
-	/* Set page range */
-	ret = ssd1307fb_write_cmd(par->client, SSD1307FB_SET_PAGE_RANGE);
-	if (ret < 0)
-		return ret;
-
-	ret = ssd1307fb_write_cmd(par->client, par->page_offset);
-	if (ret < 0)
-		return ret;
-
-	ret = ssd1307fb_write_cmd(par->client,
-				  par->page_offset +
-				  DIV_ROUND_UP(par->height, 8) - 1);
+	/* Set column and page range */
+	ret = ssd1307fb_set_address_range(par, par->col_offset, par->width,
+					  par->page_offset,
+					  DIV_ROUND_UP(par->height, 8));
 	if (ret < 0)
 		return ret;
 
-- 
2.25.1


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

* [PATCH resend 4/5] video: fbdev: ssd1307fb: Optimize screen updates
  2021-07-14 14:57 [PATCH resend 0/5] video: fbdev: ssd1307fb: Optimizations and improvements Geert Uytterhoeven
                   ` (2 preceding siblings ...)
  2021-07-14 14:58 ` [PATCH resend 3/5] video: fbdev: ssd1307fb: Extract ssd1307fb_set_address_range() Geert Uytterhoeven
@ 2021-07-14 14:58 ` Geert Uytterhoeven
       [not found]   ` <YPXQnlpWUa1QaZKd@ravnborg.org>
  2021-07-14 14:58 ` [PATCH resend 5/5] video: fbdev: ssd1307fb: Cache address ranges Geert Uytterhoeven
                   ` (2 subsequent siblings)
  6 siblings, 1 reply; 13+ messages in thread
From: Geert Uytterhoeven @ 2021-07-14 14:58 UTC (permalink / raw)
  To: David Airlie, Daniel Vetter, Maxime Ripard
  Cc: linux-fbdev, dri-devel, linux-kernel, Geert Uytterhoeven

Currently, each screen update triggers an I2C transfer of all screen
data, up to 1 KiB of data for a 128x64 display, which takes at least 20
ms in Fast mode.

Reduce the amount of transferred data by only updating the rectangle
that changed.  Remove the call to ssd1307fb_set_address_range() during
initialization, as ssd1307fb_update_rect() now takes care of that.

Note that for now the optimized operation is only used for fillrect,
copyarea, and imageblit, which are used by fbcon.

Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
---
 drivers/video/fbdev/ssd1307fb.c | 43 ++++++++++++++++++++-------------
 1 file changed, 26 insertions(+), 17 deletions(-)

diff --git a/drivers/video/fbdev/ssd1307fb.c b/drivers/video/fbdev/ssd1307fb.c
index cfa27ea0feab4f01..8e3d4be74723b9bf 100644
--- a/drivers/video/fbdev/ssd1307fb.c
+++ b/drivers/video/fbdev/ssd1307fb.c
@@ -184,16 +184,18 @@ static int ssd1307fb_set_address_range(struct ssd1307fb_par *par, u8 col_start,
 	return ssd1307fb_write_cmd(par->client, page_end);
 }
 
-static int ssd1307fb_update_display(struct ssd1307fb_par *par)
+static int ssd1307fb_update_rect(struct ssd1307fb_par *par, unsigned int x,
+				 unsigned int y, unsigned int width,
+				 unsigned int height)
 {
 	struct ssd1307fb_array *array;
 	u8 *vmem = par->info->screen_buffer;
 	unsigned int line_length = par->info->fix.line_length;
-	unsigned int pages = DIV_ROUND_UP(par->height, 8);
+	unsigned int pages = DIV_ROUND_UP(height + y % 8, 8);
 	u32 array_idx = 0;
 	int ret, i, j, k;
 
-	array = ssd1307fb_alloc_array(par->width * pages, SSD1307FB_DATA);
+	array = ssd1307fb_alloc_array(width * pages, SSD1307FB_DATA);
 	if (!array)
 		return -ENOMEM;
 
@@ -226,13 +228,18 @@ static int ssd1307fb_update_display(struct ssd1307fb_par *par)
 	 *  (5) A4 B4 C4 D4 E4 F4 G4 H4
 	 */
 
-	for (i = 0; i < pages; i++) {
+	ret = ssd1307fb_set_address_range(par, par->col_offset + x, width,
+					  par->page_offset + y / 8, pages);
+	if (ret < 0)
+		goto out_free;
+
+	for (i = y / 8; i < y / 8 + pages; i++) {
 		int m = 8;
 
 		/* Last page may be partial */
-		if (i + 1 == pages && par->height % 8)
+		if (8 * (i + 1) > par->height)
 			m = par->height % 8;
-		for (j = 0; j < par->width; j++) {
+		for (j = x; j < x + width; j++) {
 			u8 data = 0;
 
 			for (k = 0; k < m; k++) {
@@ -245,11 +252,17 @@ static int ssd1307fb_update_display(struct ssd1307fb_par *par)
 		}
 	}
 
-	ret = ssd1307fb_write_array(par->client, array, par->width * pages);
+	ret = ssd1307fb_write_array(par->client, array, width * pages);
+
+out_free:
 	kfree(array);
 	return ret;
 }
 
+static int ssd1307fb_update_display(struct ssd1307fb_par *par)
+{
+	return ssd1307fb_update_rect(par, 0, 0, par->width, par->height);
+}
 
 static ssize_t ssd1307fb_write(struct fb_info *info, const char __user *buf,
 		size_t count, loff_t *ppos)
@@ -299,21 +312,24 @@ static void ssd1307fb_fillrect(struct fb_info *info, const struct fb_fillrect *r
 {
 	struct ssd1307fb_par *par = info->par;
 	sys_fillrect(info, rect);
-	ssd1307fb_update_display(par);
+	ssd1307fb_update_rect(par, rect->dx, rect->dy, rect->width,
+			      rect->height);
 }
 
 static void ssd1307fb_copyarea(struct fb_info *info, const struct fb_copyarea *area)
 {
 	struct ssd1307fb_par *par = info->par;
 	sys_copyarea(info, area);
-	ssd1307fb_update_display(par);
+	ssd1307fb_update_rect(par, area->dx, area->dy, area->width,
+			      area->height);
 }
 
 static void ssd1307fb_imageblit(struct fb_info *info, const struct fb_image *image)
 {
 	struct ssd1307fb_par *par = info->par;
 	sys_imageblit(info, image);
-	ssd1307fb_update_display(par);
+	ssd1307fb_update_rect(par, image->dx, image->dy, image->width,
+			      image->height);
 }
 
 static const struct fb_ops ssd1307fb_ops = {
@@ -493,13 +509,6 @@ static int ssd1307fb_init(struct ssd1307fb_par *par)
 	if (ret < 0)
 		return ret;
 
-	/* Set column and page range */
-	ret = ssd1307fb_set_address_range(par, par->col_offset, par->width,
-					  par->page_offset,
-					  DIV_ROUND_UP(par->height, 8));
-	if (ret < 0)
-		return ret;
-
 	/* Clear the screen */
 	ret = ssd1307fb_update_display(par);
 	if (ret < 0)
-- 
2.25.1


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

* [PATCH resend 5/5] video: fbdev: ssd1307fb: Cache address ranges
  2021-07-14 14:57 [PATCH resend 0/5] video: fbdev: ssd1307fb: Optimizations and improvements Geert Uytterhoeven
                   ` (3 preceding siblings ...)
  2021-07-14 14:58 ` [PATCH resend 4/5] video: fbdev: ssd1307fb: Optimize screen updates Geert Uytterhoeven
@ 2021-07-14 14:58 ` Geert Uytterhoeven
       [not found] ` <YO8CT+Hcw1wfhnH5@ravnborg.org>
       [not found] ` <YPXRMXQxCW+Agaz8@ravnborg.org>
  6 siblings, 0 replies; 13+ messages in thread
From: Geert Uytterhoeven @ 2021-07-14 14:58 UTC (permalink / raw)
  To: David Airlie, Daniel Vetter, Maxime Ripard
  Cc: linux-fbdev, dri-devel, linux-kernel, Geert Uytterhoeven

Cache the column and page ranges, to avoid doing unneeded I2C transfers
when the values haven't changed.

Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
---
 drivers/video/fbdev/ssd1307fb.c | 52 +++++++++++++++++++++++----------
 1 file changed, 36 insertions(+), 16 deletions(-)

diff --git a/drivers/video/fbdev/ssd1307fb.c b/drivers/video/fbdev/ssd1307fb.c
index 8e3d4be74723b9bf..23b43ce479898813 100644
--- a/drivers/video/fbdev/ssd1307fb.c
+++ b/drivers/video/fbdev/ssd1307fb.c
@@ -82,6 +82,11 @@ struct ssd1307fb_par {
 	struct regulator *vbat_reg;
 	u32 vcomh;
 	u32 width;
+	/* Cached address ranges */
+	u8 col_start;
+	u8 col_end;
+	u8 page_start;
+	u8 page_end;
 };
 
 struct ssd1307fb_array {
@@ -160,28 +165,43 @@ static int ssd1307fb_set_address_range(struct ssd1307fb_par *par, u8 col_start,
 	int ret;
 
 	/* Set column range */
-	ret = ssd1307fb_write_cmd(par->client, SSD1307FB_SET_COL_RANGE);
-	if (ret < 0)
-		return ret;
+	if (col_start != par->col_start || col_end != par->col_end) {
+		ret = ssd1307fb_write_cmd(par->client, SSD1307FB_SET_COL_RANGE);
+		if (ret < 0)
+			return ret;
 
-	ret = ssd1307fb_write_cmd(par->client, col_start);
-	if (ret < 0)
-		return ret;
+		ret = ssd1307fb_write_cmd(par->client, col_start);
+		if (ret < 0)
+			return ret;
 
-	ret = ssd1307fb_write_cmd(par->client, col_end);
-	if (ret < 0)
-		return ret;
+		ret = ssd1307fb_write_cmd(par->client, col_end);
+		if (ret < 0)
+			return ret;
+
+		par->col_start = col_start;
+		par->col_end = col_end;
+	}
 
 	/* Set page range */
-	ret = ssd1307fb_write_cmd(par->client, SSD1307FB_SET_PAGE_RANGE);
-	if (ret < 0)
-		return ret;
+	if (page_start != par->page_start || page_end != par->page_end) {
+		ret = ssd1307fb_write_cmd(par->client,
+					  SSD1307FB_SET_PAGE_RANGE);
+		if (ret < 0)
+			return ret;
 
-	ret = ssd1307fb_write_cmd(par->client, page_start);
-	if (ret < 0)
-		return ret;
+		ret = ssd1307fb_write_cmd(par->client, page_start);
+		if (ret < 0)
+			return ret;
+
+		ret = ssd1307fb_write_cmd(par->client, page_end);
+		if (ret < 0)
+			return ret;
 
-	return ssd1307fb_write_cmd(par->client, page_end);
+		par->page_start = page_start;
+		par->page_end = page_end;
+	}
+
+	return 0;
 }
 
 static int ssd1307fb_update_rect(struct ssd1307fb_par *par, unsigned int x,
-- 
2.25.1


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

* Re: [PATCH resend 0/5] video: fbdev: ssd1307fb: Optimizations and improvements
       [not found] ` <YO8CT+Hcw1wfhnH5@ravnborg.org>
@ 2021-07-15  6:54   ` Geert Uytterhoeven
  2021-07-20 14:53     ` Daniel Vetter
  0 siblings, 1 reply; 13+ messages in thread
From: Geert Uytterhoeven @ 2021-07-15  6:54 UTC (permalink / raw)
  To: Sam Ravnborg
  Cc: David Airlie, Daniel Vetter, Maxime Ripard,
	Linux Fbdev development list, Linux Kernel Mailing List,
	DRI Development

Hi Sam,

On Wed, Jul 14, 2021 at 5:27 PM Sam Ravnborg <sam@ravnborg.org> wrote:
> On Wed, Jul 14, 2021 at 04:57:59PM +0200, Geert Uytterhoeven wrote:
> > This patch series optimizes console operations on ssd1307fb, after the
> > customary fixes and cleanups.
>
> What is required to to have a drm driver that could do the same?

Add monochrome support to DRM?

> Note: I will take a look at the patches a bit later.

TIA!

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

* Re: [PATCH resend 0/5] video: fbdev: ssd1307fb: Optimizations and improvements
       [not found] ` <YPXRMXQxCW+Agaz8@ravnborg.org>
@ 2021-07-20  7:33   ` Geert Uytterhoeven
  0 siblings, 0 replies; 13+ messages in thread
From: Geert Uytterhoeven @ 2021-07-20  7:33 UTC (permalink / raw)
  To: Sam Ravnborg
  Cc: David Airlie, Daniel Vetter, Maxime Ripard,
	Linux Fbdev development list, Linux Kernel Mailing List,
	DRI Development

Hi Sam,

On Mon, Jul 19, 2021 at 9:23 PM Sam Ravnborg <sam@ravnborg.org> wrote:
> On Wed, Jul 14, 2021 at 04:57:59PM +0200, Geert Uytterhoeven wrote:
> > This patch series optimizes console operations on ssd1307fb, after the
> > customary fixes and cleanups.
> >
> > Currently, each screen update triggers an I2C transfer of all screen
> > data, up to 1 KiB of data for a 128x64 display, which takes at least 20
> > ms in Fast mode.  While many displays are smaller, and thus require less
> > data to be transferred, 20 ms is still an optimistic value, as the
> > actual data transfer may be much slower, especially on bitbanged I2C
> > drivers.  After this series, the amount of data transfer is reduced, as
> > fillrect, copyarea, and imageblit only update the rectangle that
> > changed.
> >
> > This has been tested on an Adafruit FeatherWing OLED with an SSD1306
> > controller and a 128x32 OLED, connected to an OrangeCrab ECP5 FPGA board
> > running a 64 MHz VexRiscv RISC-V softcore, where it reduced the CPU
> > usage for blinking the cursor from more than 70% to ca. 10%.
> >
> > Thanks for your comments!
> >
> > Geert Uytterhoeven (5):
> >   video: fbdev: ssd1307fb: Propagate errors via
> >     ssd1307fb_update_display()
> >   video: fbdev: ssd1307fb: Simplify ssd1307fb_update_display()
> >   video: fbdev: ssd1307fb: Extract ssd1307fb_set_address_range()
> >   video: fbdev: ssd1307fb: Optimize screen updates
> >   video: fbdev: ssd1307fb: Cache address ranges
>
> A few comments left for a couple of patches.
> The remaining patches are:
> Acked-by: Sam Ravnborg <sam@ravnborg.org>

Thank you!

> Do you have commit rights to drm-misc-next?

No I have not (and I don't think I should).

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

* Re: [PATCH resend 2/5] video: fbdev: ssd1307fb: Simplify ssd1307fb_update_display()
       [not found]   ` <YPXM8AXNje7GXf+i@ravnborg.org>
@ 2021-07-20  7:43     ` Geert Uytterhoeven
  0 siblings, 0 replies; 13+ messages in thread
From: Geert Uytterhoeven @ 2021-07-20  7:43 UTC (permalink / raw)
  To: Sam Ravnborg
  Cc: David Airlie, Daniel Vetter, Maxime Ripard,
	Linux Fbdev development list, Linux Kernel Mailing List,
	DRI Development

Hi Sam,

On Mon, Jul 19, 2021 at 9:05 PM Sam Ravnborg <sam@ravnborg.org> wrote:
> On Wed, Jul 14, 2021 at 04:58:01PM +0200, Geert Uytterhoeven wrote:
> > Simplify the nested loops to handle conversion from linear frame buffer
> > to ssd1307 page layout:
> >   1. Move last page handling one level up, as the value of "m" is the
> >      same inside a page,
> >   2. array->data[] is filled linearly, so there is no need to
> >      recalculate array_idx over and over again; a simple increment is
> >      sufficient.
> >
> > Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
> > ---
> >  drivers/video/fbdev/ssd1307fb.c | 17 ++++++++++-------
> >  1 file changed, 10 insertions(+), 7 deletions(-)
> >
> > diff --git a/drivers/video/fbdev/ssd1307fb.c b/drivers/video/fbdev/ssd1307fb.c
> > index e6b6263e3bef847f..6d7bd025bca1a175 100644
> > --- a/drivers/video/fbdev/ssd1307fb.c
> > +++ b/drivers/video/fbdev/ssd1307fb.c
> > @@ -158,6 +158,7 @@ static int ssd1307fb_update_display(struct ssd1307fb_par *par)
> >       u8 *vmem = par->info->screen_buffer;
> >       unsigned int line_length = par->info->fix.line_length;
> >       unsigned int pages = DIV_ROUND_UP(par->height, 8);
> > +     u32 array_idx = 0;
> >       int ret, i, j, k;
> >
> >       array = ssd1307fb_alloc_array(par->width * pages, SSD1307FB_DATA);
> > @@ -194,19 +195,21 @@ static int ssd1307fb_update_display(struct ssd1307fb_par *par)
> >        */
> >
> >       for (i = 0; i < pages; i++) {
> > +             int m = 8;
> > +
> > +             /* Last page may be partial */
> > +             if (i + 1 == pages && par->height % 8)
> > +                     m = par->height % 8;
> >               for (j = 0; j < par->width; j++) {
> > -                     int m = 8;
> > -                     u32 array_idx = i * par->width + j;
> > -                     array->data[array_idx] = 0;
> > -                     /* Last page may be partial */
> > -                     if (i + 1 == pages && par->height % 8)
> > -                             m = par->height % 8;
> > +                     u8 data = 0;
> > +
> >                       for (k = 0; k < m; k++) {
> If the last page is partial then m will be less than 8 for all bytes in
> j = 0..par-width - but m should only be less than 8 for the last
> iteration of the loop.
>
> Do I miss something or is the code buggy?

"the loop" is the j-loop?
If m is less than 8 for the last page, it should be less than 8 for
all iterations of j, as all last bytes in each "line" (visible
row) are partial, cfr. the comments above the code, explaining the
representation of the screen.

> >                               u8 byte = vmem[(8 * i + k) * line_length +
> >                                              j / 8];
> >                               u8 bit = (byte >> (j % 8)) & 1;
> > -                             array->data[array_idx] |= bit << k;
> > +                             data |= bit << k;
> >                       }
> > +                     array->data[array_idx++] = data;
> >               }
> >       }

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

* Re: [PATCH resend 3/5] video: fbdev: ssd1307fb: Extract ssd1307fb_set_address_range()
       [not found]   ` <YPXNdJNpYoPSpxSb@ravnborg.org>
@ 2021-07-20  7:51     ` Geert Uytterhoeven
  0 siblings, 0 replies; 13+ messages in thread
From: Geert Uytterhoeven @ 2021-07-20  7:51 UTC (permalink / raw)
  To: Sam Ravnborg
  Cc: David Airlie, Daniel Vetter, Maxime Ripard,
	Linux Fbdev development list, Linux Kernel Mailing List,
	DRI Development

Hi Sam,

On Mon, Jul 19, 2021 at 9:07 PM Sam Ravnborg <sam@ravnborg.org> wrote:
> On Wed, Jul 14, 2021 at 04:58:02PM +0200, Geert Uytterhoeven wrote:
> > Extract the code to set the column and page ranges into a helper
> > function.
> >
> > Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
> > ---
> >  drivers/video/fbdev/ssd1307fb.c | 61 +++++++++++++++++++--------------
> >  1 file changed, 36 insertions(+), 25 deletions(-)
> >
> > diff --git a/drivers/video/fbdev/ssd1307fb.c b/drivers/video/fbdev/ssd1307fb.c
> > index 6d7bd025bca1a175..cfa27ea0feab4f01 100644
> > --- a/drivers/video/fbdev/ssd1307fb.c
> > +++ b/drivers/video/fbdev/ssd1307fb.c
> > @@ -152,6 +152,38 @@ static inline int ssd1307fb_write_cmd(struct i2c_client *client, u8 cmd)
> >       return ret;
> >  }
> >
> > +static int ssd1307fb_set_address_range(struct ssd1307fb_par *par, u8 col_start,
> > +                                    u8 cols, u8 page_start, u8 pages)
> > +{
> Bikeshedding, but I think a dedicated function for col_range and another
> for page_range had been simpler to read.

I agree.
Originally, before I removed the call during initialization, there were
two calls to this function, so it made sense to have a single function.

> With or wihout this change:
> Acked-by: Sam Ravnborg <sam@ravnborg.org>

Thanks!

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

* Re: [PATCH resend 4/5] video: fbdev: ssd1307fb: Optimize screen updates
       [not found]   ` <YPXQnlpWUa1QaZKd@ravnborg.org>
@ 2021-07-20  7:56     ` Geert Uytterhoeven
  2021-07-20  9:16       ` Geert Uytterhoeven
  0 siblings, 1 reply; 13+ messages in thread
From: Geert Uytterhoeven @ 2021-07-20  7:56 UTC (permalink / raw)
  To: Sam Ravnborg
  Cc: David Airlie, Daniel Vetter, Maxime Ripard,
	Linux Fbdev development list, Linux Kernel Mailing List,
	DRI Development

Hi Sam,

On Mon, Jul 19, 2021 at 9:21 PM Sam Ravnborg <sam@ravnborg.org> wrote:
> On Wed, Jul 14, 2021 at 04:58:03PM +0200, Geert Uytterhoeven wrote:
> > Currently, each screen update triggers an I2C transfer of all screen
> > data, up to 1 KiB of data for a 128x64 display, which takes at least 20
> > ms in Fast mode.
> >
> > Reduce the amount of transferred data by only updating the rectangle
> > that changed.  Remove the call to ssd1307fb_set_address_range() during
> > initialization, as ssd1307fb_update_rect() now takes care of that.
> >
> > Note that for now the optimized operation is only used for fillrect,
> > copyarea, and imageblit, which are used by fbcon.
> >
> > Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>

> > --- a/drivers/video/fbdev/ssd1307fb.c
> > +++ b/drivers/video/fbdev/ssd1307fb.c
> > @@ -184,16 +184,18 @@ static int ssd1307fb_set_address_range(struct ssd1307fb_par *par, u8 col_start,
> >       return ssd1307fb_write_cmd(par->client, page_end);
> >  }
> >
> > -static int ssd1307fb_update_display(struct ssd1307fb_par *par)
> > +static int ssd1307fb_update_rect(struct ssd1307fb_par *par, unsigned int x,
> > +                              unsigned int y, unsigned int width,
> > +                              unsigned int height)
> >  {
> >       struct ssd1307fb_array *array;
> >       u8 *vmem = par->info->screen_buffer;
> >       unsigned int line_length = par->info->fix.line_length;
> > -     unsigned int pages = DIV_ROUND_UP(par->height, 8);
> > +     unsigned int pages = DIV_ROUND_UP(height + y % 8, 8);
>
> Add () like this - at least it helps me:
> > +     unsigned int pages = DIV_ROUND_UP((height + y) % 8, 8);

Thanks, that's actually a genuine bug.

> > @@ -226,13 +228,18 @@ static int ssd1307fb_update_display(struct ssd1307fb_par *par)
> >        *  (5) A4 B4 C4 D4 E4 F4 G4 H4
> >        */
> >
> > -     for (i = 0; i < pages; i++) {
> > +     ret = ssd1307fb_set_address_range(par, par->col_offset + x, width,
> > +                                       par->page_offset + y / 8, pages);
> > +     if (ret < 0)
> > +             goto out_free;
> > +
> > +     for (i = y / 8; i < y / 8 + pages; i++) {
> >               int m = 8;
> >
> >               /* Last page may be partial */
> > -             if (i + 1 == pages && par->height % 8)
> > +             if (8 * (i + 1) > par->height)
> >                       m = par->height % 8;
> As before, this looks wrong to me.

Let's sort that out in the other thread...

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

* Re: [PATCH resend 4/5] video: fbdev: ssd1307fb: Optimize screen updates
  2021-07-20  7:56     ` Geert Uytterhoeven
@ 2021-07-20  9:16       ` Geert Uytterhoeven
  0 siblings, 0 replies; 13+ messages in thread
From: Geert Uytterhoeven @ 2021-07-20  9:16 UTC (permalink / raw)
  To: Sam Ravnborg
  Cc: David Airlie, Daniel Vetter, Maxime Ripard,
	Linux Fbdev development list, Linux Kernel Mailing List,
	DRI Development

Hi Sam,

On Tue, Jul 20, 2021 at 9:56 AM Geert Uytterhoeven <geert@linux-m68k.org> wrote:
> On Mon, Jul 19, 2021 at 9:21 PM Sam Ravnborg <sam@ravnborg.org> wrote:
> > On Wed, Jul 14, 2021 at 04:58:03PM +0200, Geert Uytterhoeven wrote:
> > > Currently, each screen update triggers an I2C transfer of all screen
> > > data, up to 1 KiB of data for a 128x64 display, which takes at least 20
> > > ms in Fast mode.
> > >
> > > Reduce the amount of transferred data by only updating the rectangle
> > > that changed.  Remove the call to ssd1307fb_set_address_range() during
> > > initialization, as ssd1307fb_update_rect() now takes care of that.
> > >
> > > Note that for now the optimized operation is only used for fillrect,
> > > copyarea, and imageblit, which are used by fbcon.
> > >
> > > Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
>
> > > --- a/drivers/video/fbdev/ssd1307fb.c
> > > +++ b/drivers/video/fbdev/ssd1307fb.c
> > > @@ -184,16 +184,18 @@ static int ssd1307fb_set_address_range(struct ssd1307fb_par *par, u8 col_start,
> > >       return ssd1307fb_write_cmd(par->client, page_end);
> > >  }
> > >
> > > -static int ssd1307fb_update_display(struct ssd1307fb_par *par)
> > > +static int ssd1307fb_update_rect(struct ssd1307fb_par *par, unsigned int x,
> > > +                              unsigned int y, unsigned int width,
> > > +                              unsigned int height)
> > >  {
> > >       struct ssd1307fb_array *array;
> > >       u8 *vmem = par->info->screen_buffer;
> > >       unsigned int line_length = par->info->fix.line_length;
> > > -     unsigned int pages = DIV_ROUND_UP(par->height, 8);
> > > +     unsigned int pages = DIV_ROUND_UP(height + y % 8, 8);
> >
> > Add () like this - at least it helps me:
> > > +     unsigned int pages = DIV_ROUND_UP((height + y) % 8, 8);
>
> Thanks, that's actually a genuine bug.

No it's not "(height + y) % 8" is wrong.

Better if I reorder the operands like below?

    unsigned int pages = DIV_ROUND_UP(y % 8 + height, 8);

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

* Re: [PATCH resend 0/5] video: fbdev: ssd1307fb: Optimizations and improvements
  2021-07-15  6:54   ` [PATCH resend 0/5] video: fbdev: ssd1307fb: Optimizations and improvements Geert Uytterhoeven
@ 2021-07-20 14:53     ` Daniel Vetter
  0 siblings, 0 replies; 13+ messages in thread
From: Daniel Vetter @ 2021-07-20 14:53 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Sam Ravnborg, David Airlie, Maxime Ripard,
	Linux Fbdev development list, Linux Kernel Mailing List,
	DRI Development

On Thu, Jul 15, 2021 at 8:54 AM Geert Uytterhoeven <geert@linux-m68k.org> wrote:
>
> Hi Sam,
>
> On Wed, Jul 14, 2021 at 5:27 PM Sam Ravnborg <sam@ravnborg.org> wrote:
> > On Wed, Jul 14, 2021 at 04:57:59PM +0200, Geert Uytterhoeven wrote:
> > > This patch series optimizes console operations on ssd1307fb, after the
> > > customary fixes and cleanups.
> >
> > What is required to to have a drm driver that could do the same?
>
> Add monochrome support to DRM?

I think the bits that are missing for that are
- wiring up the conversion from R* formats to their fbdev counterparts
in the emulation helper (if you want to support userspace sending the
native format directly through fbdev

Everything else is there and we have drivers doing this, e.g.
drm/tiny/repaper.c.
-Daniel

>
> > Note: I will take a look at the patches a bit later.
>
> TIA!
>
> Gr{oetje,eeting}s,
>
>                         Geert
>
> --
> Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
>
> In personal conversations with technical people, I call myself a hacker. But
> when I'm talking to journalists I just say "programmer" or something like that.
>                                 -- Linus Torvalds



-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

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

end of thread, other threads:[~2021-07-20 15:19 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-14 14:57 [PATCH resend 0/5] video: fbdev: ssd1307fb: Optimizations and improvements Geert Uytterhoeven
2021-07-14 14:58 ` [PATCH resend 1/5] video: fbdev: ssd1307fb: Propagate errors via ssd1307fb_update_display() Geert Uytterhoeven
2021-07-14 14:58 ` [PATCH resend 2/5] video: fbdev: ssd1307fb: Simplify ssd1307fb_update_display() Geert Uytterhoeven
     [not found]   ` <YPXM8AXNje7GXf+i@ravnborg.org>
2021-07-20  7:43     ` Geert Uytterhoeven
2021-07-14 14:58 ` [PATCH resend 3/5] video: fbdev: ssd1307fb: Extract ssd1307fb_set_address_range() Geert Uytterhoeven
     [not found]   ` <YPXNdJNpYoPSpxSb@ravnborg.org>
2021-07-20  7:51     ` Geert Uytterhoeven
2021-07-14 14:58 ` [PATCH resend 4/5] video: fbdev: ssd1307fb: Optimize screen updates Geert Uytterhoeven
     [not found]   ` <YPXQnlpWUa1QaZKd@ravnborg.org>
2021-07-20  7:56     ` Geert Uytterhoeven
2021-07-20  9:16       ` Geert Uytterhoeven
2021-07-14 14:58 ` [PATCH resend 5/5] video: fbdev: ssd1307fb: Cache address ranges Geert Uytterhoeven
     [not found] ` <YO8CT+Hcw1wfhnH5@ravnborg.org>
2021-07-15  6:54   ` [PATCH resend 0/5] video: fbdev: ssd1307fb: Optimizations and improvements Geert Uytterhoeven
2021-07-20 14:53     ` Daniel Vetter
     [not found] ` <YPXRMXQxCW+Agaz8@ravnborg.org>
2021-07-20  7:33   ` Geert Uytterhoeven

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).