public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Alper Nebi Yasak <alpernebiyasak@gmail.com>
To: Simon Glass <sjg@chromium.org>, Alexander Graf <agraf@csgraf.de>
Cc: u-boot@lists.denx.de, Kever Yang <kever.yang@rock-chips.com>,
	Jagan Teki <jagan@amarulasolutions.com>,
	Andre Przywara <andre.przywara@arm.com>,
	Svyatoslav Ryhel <clamor95@gmail.com>,
	Philipp Tomsich <philipp.tomsich@vrull.eu>,
	Andrew Davis <afd@ti.com>, Da Xue <da@libre.computer>,
	Heinrich Schuchardt <xypron.glpk@gmx.de>,
	Patrice Chotard <patrice.chotard@foss.st.com>,
	Patrick Delaunay <patrick.delaunay@foss.st.com>,
	Derald Woods <woods.technical@gmail.com>,
	Anatolij Gustschin <agust@denx.de>,
	uboot-stm32@st-md-mailman.stormreply.com,
	Matthias Brugger <mbrugger@suse.com>,
	u-boot-amlogic@groups.io,
	Ilias Apalodimas <ilias.apalodimas@linaro.org>,
	Neil Armstrong <neil.armstrong@linaro.org>
Subject: Re: [PATCH v5 10/13] video: Only dcache flush damaged lines
Date: Wed, 30 Aug 2023 22:12:44 +0300	[thread overview]
Message-ID: <2f283c6b-bf2c-4893-b286-25a44ff37dd1@gmail.com> (raw)
In-Reply-To: <CAPnjgZ2wivMkM407VxYfgOsgrZnLY7UXVMgZt1OfzJzjiKgKjg@mail.gmail.com>

On 2023-08-22 02:03 +03:00, Simon Glass wrote:
> Hi Alex,
> 
> On Mon, 21 Aug 2023 at 16:44, Alexander Graf <agraf@csgraf.de> wrote:
>>
>>
>> On 22.08.23 00:10, Simon Glass wrote:
>>> Hi Alex,
>>>
>>> On Mon, 21 Aug 2023 at 13:59, Alexander Graf <agraf@csgraf.de> wrote:
>>>>
>>>> On 21.08.23 21:11, Simon Glass wrote:
>>>>> Hi Alper,
>>>>>
>>>>> On Mon, 21 Aug 2023 at 07:51, Alper Nebi Yasak <alpernebiyasak@gmail.com> wrote:
>>>>>> From: Alexander Graf <agraf@csgraf.de>
>>>>>>
>>>>>> Now that we have a damage area tells us which parts of the frame buffer
>>>>>> actually need updating, let's only dcache flush those on video_sync()
>>>>>> calls. With this optimization in place, frame buffer updates - especially
>>>>>> on large screen such as 4k displays - speed up significantly.
>>>>>>
>>>>>> Signed-off-by: Alexander Graf <agraf@csgraf.de>
>>>>>> Reported-by: Da Xue <da@libre.computer>
>>>>>> [Alper: Use damage.xstart/yend, IS_ENABLED()]
>>>>>> Co-developed-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
>>>>>> Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
>>>>>> ---
>>>>>>
>>>>>> Changes in v5:
>>>>>> - Use xstart, ystart, xend, yend as names for damage region
>>>>>> - Use IS_ENABLED() instead of CONFIG_IS_ENABLED()
>>>>>>
>>>>>> Changes in v2:
>>>>>> - Fix dcache range; we were flushing too much before
>>>>>> - Remove ifdefs
>>>>>>
>>>>>>    drivers/video/video-uclass.c | 41 +++++++++++++++++++++++++++++++-----
>>>>>>    1 file changed, 36 insertions(+), 5 deletions(-)
>>>>> This is a little strange, since flushing the whole cache will only
>>>>> actually write out data that was actually written (to the display). Is
>>>>> there a benefit to this patch, in terms of performance?
>>>>
>>>> I'm happy to see you go through the same thought process I went through
>>>> when writing these: "This surely can't be the problem, can it?". The
>>>> answer is "simple" in hindsight:
>>>>
>>>> Have a look at the ARMv8 cache flush function. It does the only "safe"
>>>> thing you can expect it to do: Clean+Invalidate to POC because we use it
>>>> for multiple things, clearing modified code among others:
>>>>
>>>> ENTRY(__asm_flush_dcache_range)
>>>>           mrs     x3, ctr_el0
>>>>           ubfx    x3, x3, #16, #4
>>>>           mov     x2, #4
>>>>           lsl     x2, x2, x3              /* cache line size */
>>>>
>>>>           /* x2 <- minimal cache line size in cache system */
>>>>           sub     x3, x2, #1
>>>>           bic     x0, x0, x3
>>>> 1:      dc      civac, x0       /* clean & invalidate data or unified
>>>> cache */
>>>>           add     x0, x0, x2
>>>>           cmp     x0, x1
>>>>           b.lo    1b
>>>>           dsb     sy
>>>>           ret
>>>> ENDPROC(__asm_flush_dcache_range)
>>>>
>>>>
>>>> Looking at the "dc civac" call, we find this documentation page from
>>>> ARM:
>>>> https://developer.arm.com/documentation/ddi0601/2022-03/AArch64-Instructions/DC-CIVAC--Data-or-unified-Cache-line-Clean-and-Invalidate-by-VA-to-PoC
>>>>
>>>> This says we're writing any dirtyness of this cache line up to the POC
>>>> and then invalidate (remove the cache line) also up to POC. That means
>>>> when you look at a typical SBC, this will either be L2 or system level
>>>> cache. Every read afterwards needs to go and pull it all the way back to
>>>> L1 to modify it (or not) on the next character write and then flush it
>>>> again.
>>>>
>>>> Even worse: Because of the invalidate, we may even evict it from caches
>>>> that the display controller uses to read the frame buffer. So depending
>>>> on the SoC's cache topology and implementation, we may force the display
>>>> controller to refetch the full FB content on its next screen refresh cycle.
>>>>
>>>> I faintly remember that I tried to experiment with CVAC instead to only
>>>> flush without invalidating. I don't fully remember the results anymore
>>>> though. I believe CVAC just behaved identical to CIVAC on the A53
>>>> platform I was working on. And then I looked at Cortex-A53 errata like
>>>> [1] and just accepted that doing anything but restricting the flushing
>>>> range is a waste of time :)
>>> Yuck I didn't know it was invalidating too. That is horrible. Is there
>>> no way to fix it?
>>
>>
>> Before building all of this damage logic, I tried, but failed. I'd
>> welcome anyone else to try again :). I'm not even convinced yet that it
>> is actually fixable: Depending on the SoC's internal cache logic, it may
>> opt to always invalidate I think.
> 
> Wow, that is crazy! How is anyone supposed to make the system run well
> with logic like that??!
> 
>>
>> That said, this patch set really also makes sense outside of the
>> particular invalidate problem. It creates a generic abstraction between
>> the copy and non-copy code path and allows us to reduce the amount of
>> work spent for both, generically for any video sync operation.
> 
> Sure...my question was really why it helps so much, given what I
> understood the caches to be doing. If they are invalidating, then it
> is amazing anything gets done...

I don't really know cache mechanisms and terminology, but AFAIU there's
nothing actionable for this patch regarding this discussion, right?

Meanwhile I noticed this patch only flushes priv->fb, and think it also
needs to flush priv->copy_fb if VIDEO_COPY.

  reply	other threads:[~2023-08-30 19:12 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-21 13:50 [PATCH v5 00/13] Add video damage tracking Alper Nebi Yasak
2023-08-21 13:50 ` [PATCH v5 01/13] video: test: Split copy frame buffer check into a function Alper Nebi Yasak
2023-08-21 19:11   ` Simon Glass
2023-08-21 13:50 ` [PATCH v5 02/13] video: test: Support checking copy frame buffer contents Alper Nebi Yasak
2023-08-21 19:11   ` Simon Glass
2023-08-21 13:51 ` [PATCH v5 03/13] video: test: Test partial updates of hardware frame buffer Alper Nebi Yasak
2023-08-21 19:11   ` Simon Glass
2023-08-21 13:51 ` [PATCH v5 04/13] dm: video: Add damage tracking API Alper Nebi Yasak
2023-08-21 19:11   ` Simon Glass
2023-08-30 19:15     ` Alper Nebi Yasak
2023-08-31  2:49       ` Simon Glass
2023-08-21 13:51 ` [PATCH v5 05/13] dm: video: Add damage notification on display fills Alper Nebi Yasak
2023-08-21 19:11   ` Simon Glass
2023-08-21 13:51 ` [PATCH v5 06/13] vidconsole: Add damage notifications to all vidconsole drivers Alper Nebi Yasak
2023-08-21 19:11   ` Simon Glass
2023-08-21 13:51 ` [PATCH v5 07/13] video: test: Test video damage tracking via vidconsole Alper Nebi Yasak
2023-08-21 19:11   ` Simon Glass
2023-08-21 13:51 ` [PATCH v5 08/13] video: Add damage notification on bmp display Alper Nebi Yasak
2023-08-21 13:51 ` [PATCH v5 09/13] efi_loader: GOP: Add damage notification on BLT Alper Nebi Yasak
2023-08-21 19:11   ` Simon Glass
2023-08-21 13:51 ` [PATCH v5 10/13] video: Only dcache flush damaged lines Alper Nebi Yasak
2023-08-21 19:11   ` Simon Glass
2023-08-21 19:59     ` Alexander Graf
2023-08-21 22:10       ` Simon Glass
2023-08-21 22:44         ` Alexander Graf
2023-08-21 23:03           ` Simon Glass
2023-08-30 19:12             ` Alper Nebi Yasak [this message]
2023-08-30 19:57               ` Alexander Graf
2023-08-21 13:51 ` [PATCH v5 11/13] video: Use VIDEO_DAMAGE for VIDEO_COPY Alper Nebi Yasak
2023-08-21 19:11   ` Simon Glass
2023-08-21 20:06     ` Alexander Graf
2023-08-30 19:07       ` Alper Nebi Yasak
2023-08-31  2:49         ` Simon Glass
2023-08-21 13:51 ` [PATCH v5 12/13] video: Always compile cache flushing code Alper Nebi Yasak
2023-08-21 13:51 ` [PATCH v5 13/13] video: Enable VIDEO_DAMAGE for drivers that need it Alper Nebi Yasak
2023-08-21 19:11   ` Simon Glass
2023-08-21 19:11 ` [PATCH v5 00/13] Add video damage tracking Simon Glass
2023-08-21 19:33   ` Alexander Graf
2023-08-21 19:57     ` Simon Glass
2023-08-21 20:20       ` Alexander Graf
2023-08-21 22:10         ` Simon Glass
2023-08-21 22:40           ` Alexander Graf
2023-08-21 23:03             ` Simon Glass
2023-08-22  7:47               ` Alexander Graf
2023-08-22 18:56                 ` Simon Glass
2023-08-23  8:56                   ` Alexander Graf
2023-08-28 17:54                     ` Simon Glass
2023-08-28 20:24                       ` Alexander Graf
2023-08-28 21:54                         ` Heinrich Schuchardt
2023-08-29  6:20                           ` Alexander Graf
2023-08-29  9:19                             ` Mark Kettenis
2023-08-30 19:55                               ` Alexander Graf
2023-08-28 22:08                         ` Simon Glass
2023-08-29  6:27                           ` Alexander Graf
2023-08-30 18:27                             ` Alper Nebi Yasak
2023-08-30 19:52                               ` Alexander Graf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2f283c6b-bf2c-4893-b286-25a44ff37dd1@gmail.com \
    --to=alpernebiyasak@gmail.com \
    --cc=afd@ti.com \
    --cc=agraf@csgraf.de \
    --cc=agust@denx.de \
    --cc=andre.przywara@arm.com \
    --cc=clamor95@gmail.com \
    --cc=da@libre.computer \
    --cc=ilias.apalodimas@linaro.org \
    --cc=jagan@amarulasolutions.com \
    --cc=kever.yang@rock-chips.com \
    --cc=mbrugger@suse.com \
    --cc=neil.armstrong@linaro.org \
    --cc=patrice.chotard@foss.st.com \
    --cc=patrick.delaunay@foss.st.com \
    --cc=philipp.tomsich@vrull.eu \
    --cc=sjg@chromium.org \
    --cc=u-boot-amlogic@groups.io \
    --cc=u-boot@lists.denx.de \
    --cc=uboot-stm32@st-md-mailman.stormreply.com \
    --cc=woods.technical@gmail.com \
    --cc=xypron.glpk@gmx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox