* [PATCH] staging: fbtft: Optimize partial write()
@ 2026-02-13 8:59 Nam Cao
2026-02-13 10:18 ` Andy Shevchenko
0 siblings, 1 reply; 4+ messages in thread
From: Nam Cao @ 2026-02-13 8:59 UTC (permalink / raw)
To: Andy Shevchenko, Greg Kroah-Hartman, Nam Cao, dri-devel,
linux-fbdev, linux-staging, linux-kernel
When user write() only to part of the screen, the driver still updates the
entire screen. That wastes CPU cycles.
Optimize by updating only the changed lines. Improvement is measured by a
pair of trace_printk() at the beginning of fb_write() and at the end of
fbtft_deferred_io().
Update type Before After
====================================
full screen 196ms 200ms
half screen 200ms 124ms
quarter screen 193ms 81ms
one pixle 199ms 43ms
It is interesting to note that if the deferred IO's delay time (40ms) is
subtracted, then the time amount scales linearly with the write size.
Signed-off-by: Nam Cao <namcao@linutronix.de>
---
drivers/staging/fbtft/fbtft-core.c | 13 +++++--------
1 file changed, 5 insertions(+), 8 deletions(-)
diff --git a/drivers/staging/fbtft/fbtft-core.c b/drivers/staging/fbtft/fbtft-core.c
index 8a5ccc8ae0a1..16899b979623 100644
--- a/drivers/staging/fbtft/fbtft-core.c
+++ b/drivers/staging/fbtft/fbtft-core.c
@@ -300,12 +300,6 @@ static void fbtft_mkdirty(struct fb_info *info, int y, int height)
struct fbtft_par *par = info->par;
struct fb_deferred_io *fbdefio = info->fbdefio;
- /* special case, needed ? */
- if (y == -1) {
- y = 0;
- height = info->var.yres;
- }
-
/* Mark display lines/area as dirty */
spin_lock(&par->dirty_lock);
if (y < par->dirty_lines_start)
@@ -414,9 +408,12 @@ static int fbtft_fb_blank(int blank, struct fb_info *info)
static void fbtft_ops_damage_range(struct fb_info *info, off_t off, size_t len)
{
struct fbtft_par *par = info->par;
+ u32 start, end;
+
+ start = off / info->fix.line_length;
+ end = (off + len - 1) / info->fix.line_length;
- /* TODO: only mark changed area update all for now */
- par->fbtftops.mkdirty(info, -1, 0);
+ par->fbtftops.mkdirty(info, start, end - start + 1);
}
static void fbtft_ops_damage_area(struct fb_info *info, u32 x, u32 y, u32 width, u32 height)
--
2.47.3
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] staging: fbtft: Optimize partial write()
2026-02-13 8:59 [PATCH] staging: fbtft: Optimize partial write() Nam Cao
@ 2026-02-13 10:18 ` Andy Shevchenko
2026-02-14 1:56 ` Nam Cao
0 siblings, 1 reply; 4+ messages in thread
From: Andy Shevchenko @ 2026-02-13 10:18 UTC (permalink / raw)
To: Nam Cao
Cc: Andy Shevchenko, Greg Kroah-Hartman, dri-devel, linux-fbdev,
linux-staging, linux-kernel
On Fri, Feb 13, 2026 at 09:59:46AM +0100, Nam Cao wrote:
> When user write() only to part of the screen, the driver still updates the
> entire screen. That wastes CPU cycles.
>
> Optimize by updating only the changed lines. Improvement is measured by a
> pair of trace_printk() at the beginning of fb_write() and at the end of
> fbtft_deferred_io().
Can you elaborate on the HW (the exact model of the panel and [sub]driver)
in use?
> Update type Before After
> ====================================
> full screen 196ms 200ms
> half screen 200ms 124ms
> quarter screen 193ms 81ms
> one pixle 199ms 43ms
>
> It is interesting to note that if the deferred IO's delay time (40ms) is
> subtracted, then the time amount scales linearly with the write size.
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Some questions below, but they probably won't affect the decision on this change.
...
> - /* special case, needed ? */
Do you know the history of this comment? What is "special case" and when does it appear?
> - if (y == -1) {
> - y = 0;
> - height = info->var.yres;
> - }
...
> static void fbtft_ops_damage_range(struct fb_info *info, off_t off, size_t len)
> {
> struct fbtft_par *par = info->par;
> + u32 start, end;
> +
> + start = off / info->fix.line_length;
> + end = (off + len - 1) / info->fix.line_length;
>
> - /* TODO: only mark changed area update all for now */
Ah, this change actually targets the TODO!
> - par->fbtftops.mkdirty(info, -1, 0);
> + par->fbtftops.mkdirty(info, start, end - start + 1);
> }
...
In light of the last TODO line I think that the change is desired by
the original author. Nevertheless I am wondering about these side effects
that might be (very unlikely?) considered if this code (partial refresh)
runs for a significant period of time:
- some bits of the screen (on non-updated part) might be flipped
- the static picture may lead to wearing of (decolourisation) the panel
- what is the thermal distribution (probably with backlight off)?
Maybe it makes sense to refresh a full screen from time to time, but
TBH my knowledge of TFT panels from last decade is quite limited. I only
think from the point of the general physics and common sense. That's
why this long footnote rather philosophical, but I would be glad to
learn the state of affairs of the modern TFT panels in terms of the
physical parameters lasting over the time under different application
cases.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] staging: fbtft: Optimize partial write()
2026-02-13 10:18 ` Andy Shevchenko
@ 2026-02-14 1:56 ` Nam Cao
2026-02-14 18:06 ` Andy Shevchenko
0 siblings, 1 reply; 4+ messages in thread
From: Nam Cao @ 2026-02-14 1:56 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Andy Shevchenko, Greg Kroah-Hartman, dri-devel, linux-fbdev,
linux-staging, linux-kernel
Andy Shevchenko <andriy.shevchenko@intel.com> writes:
> On Fri, Feb 13, 2026 at 09:59:46AM +0100, Nam Cao wrote:
>> When user write() only to part of the screen, the driver still updates the
>> entire screen. That wastes CPU cycles.
>>
>> Optimize by updating only the changed lines. Improvement is measured by a
>> pair of trace_printk() at the beginning of fb_write() and at the end of
>> fbtft_deferred_io().
>
> Can you elaborate on the HW (the exact model of the panel and [sub]driver)
> in use?
My hardware is the Adafruit's ILI9340. Driver is fbtft/fb_ili9340.c.
...
>> - /* special case, needed ? */
>
> Do you know the history of this comment? What is "special case" and when does it appear?
This allows caller to pass -1 to "make dirty" the entire screen. The
only caller that uses this special case is removed in this patch.
...
>> static void fbtft_ops_damage_range(struct fb_info *info, off_t off, size_t len)
>> {
>> struct fbtft_par *par = info->par;
>> + u32 start, end;
>> +
>> + start = off / info->fix.line_length;
>> + end = (off + len - 1) / info->fix.line_length;
>>
>> - /* TODO: only mark changed area update all for now */
>
> Ah, this change actually targets the TODO!
>
>> - par->fbtftops.mkdirty(info, -1, 0);
>> + par->fbtftops.mkdirty(info, start, end - start + 1);
>> }
>
> ...
>
> In light of the last TODO line I think that the change is desired by
> the original author. Nevertheless I am wondering about these side effects
> that might be (very unlikely?) considered if this code (partial refresh)
> runs for a significant period of time:
>
> - some bits of the screen (on non-updated part) might be flipped
> - the static picture may lead to wearing of (decolourisation) the panel
> - what is the thermal distribution (probably with backlight off)?
>
> Maybe it makes sense to refresh a full screen from time to time, but
> TBH my knowledge of TFT panels from last decade is quite limited. I only
> think from the point of the general physics and common sense. That's
> why this long footnote rather philosophical, but I would be glad to
> learn the state of affairs of the modern TFT panels in terms of the
> physical parameters lasting over the time under different application
> cases.
I can't tell you much about TFT panels, sorry. My company used to do a
demo board with one of them, that's how I have some hardware to play with.
If user uses mmap() instead of write(), then full refresh is never done
(well, unless user writes to the entire screen). So if lack of refresh
is a problem, someone should have noticed already.
Nam
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] staging: fbtft: Optimize partial write()
2026-02-14 1:56 ` Nam Cao
@ 2026-02-14 18:06 ` Andy Shevchenko
0 siblings, 0 replies; 4+ messages in thread
From: Andy Shevchenko @ 2026-02-14 18:06 UTC (permalink / raw)
To: Nam Cao
Cc: Andy Shevchenko, Greg Kroah-Hartman, dri-devel, linux-fbdev,
linux-staging, linux-kernel
On Sat, Feb 14, 2026 at 08:56:09AM +0700, Nam Cao wrote:
> Andy Shevchenko <andriy.shevchenko@intel.com> writes:
> > On Fri, Feb 13, 2026 at 09:59:46AM +0100, Nam Cao wrote:
> >> When user write() only to part of the screen, the driver still updates the
> >> entire screen. That wastes CPU cycles.
> >>
> >> Optimize by updating only the changed lines. Improvement is measured by a
> >> pair of trace_printk() at the beginning of fb_write() and at the end of
> >> fbtft_deferred_io().
> >
> > Can you elaborate on the HW (the exact model of the panel and [sub]driver)
> > in use?
>
> My hardware is the Adafruit's ILI9340. Driver is fbtft/fb_ili9340.c.
Please, add that into commit message.
It will leave the trace that this change has been tested and how.
...
> >> - /* special case, needed ? */
> >
> > Do you know the history of this comment? What is "special case" and when does it appear?
>
> This allows caller to pass -1 to "make dirty" the entire screen. The
> only caller that uses this special case is removed in this patch.
Perhaps a small note (summary of the above) to the commit message as well?
...
> > In light of the last TODO line I think that the change is desired by
> > the original author. Nevertheless I am wondering about these side effects
> > that might be (very unlikely?) considered if this code (partial refresh)
> > runs for a significant period of time:
> >
> > - some bits of the screen (on non-updated part) might be flipped
> > - the static picture may lead to wearing of (decolourisation) the panel
> > - what is the thermal distribution (probably with backlight off)?
> >
> > Maybe it makes sense to refresh a full screen from time to time, but
> > TBH my knowledge of TFT panels from last decade is quite limited. I only
> > think from the point of the general physics and common sense. That's
> > why this long footnote rather philosophical, but I would be glad to
> > learn the state of affairs of the modern TFT panels in terms of the
> > physical parameters lasting over the time under different application
> > cases.
>
> I can't tell you much about TFT panels, sorry. My company used to do a
> demo board with one of them, that's how I have some hardware to play with.
>
> If user uses mmap() instead of write(), then full refresh is never done
> (well, unless user writes to the entire screen). So if lack of refresh
> is a problem, someone should have noticed already.
Right, that's why I asked more for my own learning.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-02-14 18:06 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-13 8:59 [PATCH] staging: fbtft: Optimize partial write() Nam Cao
2026-02-13 10:18 ` Andy Shevchenko
2026-02-14 1:56 ` Nam Cao
2026-02-14 18:06 ` Andy Shevchenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox