powerpc: reduce number of WATCHDOG_RESET calls from flush_cache
PATCH 1/1 powerpc: reduce number of WATCHDOG_RESET calls from flush_cache
Calling WATCHDOG_RESET for each and every cache line is overkill.
In our case, the kernel image is a little over 7MB, and the almost 500000 calls of WATCHDOG_RESET() adds about one second to the boottime.
I very highly doubt there's any real hardware where flushing 64K from cache to memory takes more than a few milliseconds, so this should be completely safe. Since it reduces the number of WATCHDOG_RESET() calls by roughly a factor of 1000, the overhead from those is practically eliminated. (Just in case the range flushed is so small that it doesn't cross a 64K boundary, add a single WATCHDOG_RESET() between the loops).
64K is chosen because that's also the default chunk size used by the hashing algorithms, and when, say, a sha256 digest of a kernel image of a few MB is being verified, that's almost guaranteed to be cache-cold, so apart from the computations being done, the hashing is also bounded by memory speed - so if 64K works for those cases, it should certainly also work when memory access is the only thing being done.
--- arch/powerpc/lib/cache.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
arch/powerpc/lib/cache.c +6 -2
@@ -8,6 +8,7 @@#include <cpu_func.h> #include <asm/cache.h> #include <watchdog.h> +#include <linux/sizes.h> void flush_cache (ulong start_addr,ulong size) {
@@ -21,15 +22,18 @@ void flush_cache(ulong start_addr, ulong size)for (addr = start; (addr <= end) && (addr >= start); addr +=CONFIG_SYS_CACHELINE_SIZE ) { asmvolatile ("dcbst 0,%0" : :"r" (addr) :"memory" ); -WATCHDOG_RESET (); +if ((addr & (SZ_64K -1 )) ==0 ) +WATCHDOG_RESET (); }/* wait for all dcbst to complete on bus */ asmvolatile ("sync" : : :"memory" ); +WATCHDOG_RESET ();for (addr = start; (addr <= end) && (addr >= start); addr +=CONFIG_SYS_CACHELINE_SIZE ) { asmvolatile ("icbi 0,%0" : :"r" (addr) :"memory" ); -WATCHDOG_RESET (); +if ((addr & (SZ_64K -1 )) ==0 ) +WATCHDOG_RESET (); } asmvolatile ("sync" : : :"memory" );/* flush prefetch queue */
Signature · 1 line
2.23.0
PATCH 1/1 powerpc: reduce number of WATCHDOG_RESET calls from flush_cache
Quoted 14 lines · Rasmus Villemoes
Calling
WATCHDOG_RESETfor each and every cache line is overkill.In our case, the kernel image is a little over 7MB, and the almost 500000 calls of
WATCHDOG_RESET()adds about one second to the boottime.I very highly doubt there's any real hardware where flushing 64K from cache to memory takes more than a few milliseconds, so this should be completely safe. Since it reduces the number of
WATCHDOG_RESET()calls by roughly a factor of 1000, the overhead from those is practically eliminated. (Just in case the range flushed is so small that it doesn't cross a 64K boundary, add a singleWATCHDOG_RESET()between the loops).
Quoted 8 lines
64K is chosen because that's also the default chunk size used by the hashing algorithms, and when, say, a sha256 digest of a kernel image of a few MB is being verified, that's almost guaranteed to be cache-cold, so apart from the computations being done, the hashing is also bounded by memory speed - so if 64K works for those cases, it should certainly also work when memory access is the only thing being done.
Signed-off-by Rasmus Villemoes <[email protected]>
Thanks,
Stefan
Quoted 38 lines
--- arch/powerpc/lib/cache.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)arch/powerpc/lib/cache.c +6
-2@@ -8,6 +8,7 @@#include <cpu_func.h> #include <asm/cache.h> #include <watchdog.h> +#include <linux/sizes.h> void flush_cache (ulong start_addr,ulong size) {@@ -21,15 +22,18 @@ void flush_cache(ulong start_addr, ulong size)for (addr = start; (addr <= end) && (addr >= start); addr +=CONFIG_SYS_CACHELINE_SIZE ) { asmvolatile ("dcbst 0,%0" : :"r" (addr) :"memory" ); -WATCHDOG_RESET (); +if ((addr & (SZ_64K -1 )) ==0 ) +WATCHDOG_RESET (); }/* wait for all dcbst to complete on bus */ asmvolatile ("sync" : : :"memory" ); +WATCHDOG_RESET ();for (addr = start; (addr <= end) && (addr >= start); addr +=CONFIG_SYS_CACHELINE_SIZE ) { asmvolatile ("icbi 0,%0" : :"r" (addr) :"memory" ); -WATCHDOG_RESET (); +if ((addr & (SZ_64K -1 )) ==0 ) +WATCHDOG_RESET (); } asmvolatile ("sync" : : :"memory" );/* flush prefetch queue */
PATCH 1/1 powerpc: reduce number of WATCHDOG_RESET calls from flush_cache
Quoted 22 lines · Stefan Roese
Quoted 21 lines · Rasmus Villemoes
Calling
WATCHDOG_RESETfor each and every cache line is overkill.In our case, the kernel image is a little over 7MB, and the almost 500000 calls of
WATCHDOG_RESET()adds about one second to the boottime.I very highly doubt there's any real hardware where flushing 64K from cache to memory takes more than a few milliseconds, so this should be completely safe. Since it reduces the number of
WATCHDOG_RESET()calls by roughly a factor of 1000, the overhead from those is practically eliminated. (Just in case the range flushed is so small that it doesn't cross a 64K boundary, add a singleWATCHDOG_RESET()between the loops).64K is chosen because that's also the default chunk size used by the hashing algorithms, and when, say, a sha256 digest of a kernel image of a few MB is being verified, that's almost guaranteed to be cache-cold, so apart from the computations being done, the hashing is also bounded by memory speed - so if 64K works for those cases, it should certainly also work when memory access is the only thing being done.
Quoted 3 lines
Quoted 1 line
Signed-off-by Rasmus Villemoes <[email protected]>Reviewed-by Stefan Roese <[email protected]>
Ping.
Quoted 39 lines
Thanks,
StefanQuoted 36 lines
---
?arch/powerpc/lib/cache.c| 8 ++++++--
? 1 file changed, 6 insertions(+), 2 deletions(-)arch/powerpc/lib/cache.c +0
-0@@ -8,6 +8,7 @@? #include <
cpu_func.h>
? #include <asm/cache.h>
? #include <watchdog.h>
+#include <linux/sizes.h>
? ? voidflush_cache(ulong start_addr, ulong size)? {arch/powerpc/lib/cache.c +2
-1@@ -21,15 +22,18 @@ void flush_cache(ulong start_addr, ulong size) ????? for (addr = start; (addr <= end) && (addr >= start); ????????????? addr += CONFIG_SYS_CACHELINE_SIZE) { ????????? asm volatile("dcbst 0,%0" : : "r" (addr) : "memory"); -??????? WATCHDOG_RESET(); +??????? if ((addr & (SZ_64K - 1)) == 0) +??????????? WATCHDOG_RESET(); ????? }????? /* wait for all dcbst to complete on bus */ ????? asm
volatile("sync" : : : "memory");
+???WATCHDOG_RESET();
? ????? for (addr = start; (addr <= end) && (addr >= start); ????????????? addr +=CONFIG_SYS_CACHELINE_SIZE) { ????????? asmvolatile("icbi 0,%0" : : "r" (addr) : "memory"); -???????WATCHDOG_RESET();
+??????? if ((addr & (SZ_64K- 1)) == 0) +???????????WATCHDOG_RESET();
????? }
????? asmvolatile("sync" : : : "memory");
????? /* flush prefetch queue */
Signature · 8 lines
Rasmus Villemoes Software Developer Prevas A/S Hedeager 3 DK-8200 Aarhus N +45 51210274 rasmus.villemoes at prevas.dk www.prevas.dk
PATCH 1/1 powerpc: reduce number of WATCHDOG_RESET calls from flush_cache
Quoted 23 lines · Rasmus Villemoes
Quoted 22 lines · Stefan Roese
Quoted 21 lines · Rasmus Villemoes
Calling
WATCHDOG_RESETfor each and every cache line is overkill.In our case, the kernel image is a little over 7MB, and the almost 500000 calls of
WATCHDOG_RESET()adds about one second to the boottime.I very highly doubt there's any real hardware where flushing 64K from cache to memory takes more than a few milliseconds, so this should be completely safe. Since it reduces the number of
WATCHDOG_RESET()calls by roughly a factor of 1000, the overhead from those is practically eliminated. (Just in case the range flushed is so small that it doesn't cross a 64K boundary, add a singleWATCHDOG_RESET()between the loops).64K is chosen because that's also the default chunk size used by the hashing algorithms, and when, say, a sha256 digest of a kernel image of a few MB is being verified, that's almost guaranteed to be cache-cold, so apart from the computations being done, the hashing is also bounded by memory speed - so if 64K works for those cases, it should certainly also work when memory access is the only thing being done.
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
Signed-off-by Rasmus Villemoes <[email protected]>Reviewed-by Stefan Roese <[email protected]>Ping.
This too should end up in -next "soon". Thanks.
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200918/b78f4180/attachment.sig>
PATCH 1/1 powerpc: reduce number of WATCHDOG_RESET calls from flush_cache
In reply to Rasmus VillemoesDear Rasmus,
Quoted 11 lines · In message <[email protected]> you wrote:
Quoted 10 lines · Stefan Roese
Quoted 9 lines · Rasmus Villemoes
Calling
WATCHDOG_RESETfor each and every cache line is overkill.In our case, the kernel image is a little over 7MB, and the almost 500000 calls of
WATCHDOG_RESET()adds about one second to the boottime.I very highly doubt there's any real hardware where flushing 64K from cache to memory takes more than a few milliseconds, so this should be completely safe. Since it reduces the number of
Maybe it is, maybe it is not. I remember boards where the watchdog trigger had to happen in pretty tight intervals, something like min 20, max 60 milliseconds.
Quoted 1 line
Quoted 1 line
Quoted 1 line
+??????? if ((addr & (
SZ_64K- 1)) == 0)
In any case, please write readable code. The use of SZ_ here is not a good idea. Also, you might want to make the actual parameter configurable, so boards with specific timing requirements can adjust this as needed.
Best regards,
Wolfgang Denk
Signature · 6 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Perfection is reached, not when there is no longer anything to add,
but when there is no longer anything to take away.
- Antoine de Saint-ExuperyPATCH 1/1 powerpc: reduce number of WATCHDOG_RESET calls from flush_cache
Quoted 19 lines · Wolfgang Denk
Dear Rasmus,
Quoted 11 lines · In message <[email protected]> you wrote:
Quoted 10 lines · Stefan Roese
Quoted 9 lines · Rasmus Villemoes
Calling
WATCHDOG_RESETfor each and every cache line is overkill.In our case, the kernel image is a little over 7MB, and the almost 500000 calls of
WATCHDOG_RESET()adds about one second to the boottime.I very highly doubt there's any real hardware where flushing 64K from cache to memory takes more than a few milliseconds, so this should be completely safe. Since it reduces the number of
Maybe it is, maybe it is not. I remember boards where the watchdog trigger had to happen in pretty tight intervals, something like min 20, max 60 milliseconds.
Quoted 6 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
+??????? if ((addr & (
SZ_64K- 1)) == 0)In any case, please write readable code. The use of
SZ_here is not a good idea. Also, you might want to make the actual parameter configurable, so boards with specific timing requirements can adjust this as needed.
We should add a comment somewhere here to match the commit message, but since we're flushing on 64K chunks, SZ_64K makes sense. If we make it build-time configurable then it's not a concern. I assume we don't want to make this run time configurable.
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200924/486dbce4/attachment.sig>
PATCH 1/1 powerpc: reduce number of WATCHDOG_RESET calls from flush_cache
In reply to Rasmus VillemoesQuoted 26 lines
-----Original Message-----
From: U-Boot <[email protected]> On Behalf Of Rasmus Villemoes
Sent: Friday, September 18, 2020 1:51 PM
To: Stefan Roese <[email protected]>; u-boot at lists.denx.de
Cc: Christophe Leroy <[email protected]>; Wolfgang Denk <[email protected]>; Simon Glass <[email protected]>; Tom Rini <[email protected]>
Subject: Re: [PATCH] powerpc: reduce number ofWATCHDOG_RESETcalls fromflush_cacheQuoted 15 lines · Stefan Roese
Quoted 14 lines · Rasmus Villemoes
Calling
WATCHDOG_RESETfor each and every cache line is overkill.In our case, the kernel image is a little over 7MB, and the almost 500000 calls of
WATCHDOG_RESET()adds about one second to the boottime.I very highly doubt there's any real hardware where flushing 64K from cache to memory takes more than a few milliseconds, so this should be completely safe. Since it reduces the number of
WATCHDOG_RESET()calls by roughly a factor of 1000, the overhead from those is practically eliminated. (Just in case the range flushed is so small that it doesn't cross a 64K boundary, add a singleWATCHDOG_RESET()between the loops).
Quoted 12 lines
Quoted 6 lines
Quoted 6 lines
64K is chosen because that's also the default chunk size used by the hashing algorithms, and when, say, a sha256 digest of a kernel image of a few MB is being verified, that's almost guaranteed to be cache-cold, so apart from the computations being done, the hashing is also bounded by memory speed - so if 64K works for those cases, it should certainly also work when memory access is the only thing being
done.
Quoted 4 lines
Quoted 2 lines
Signed-off-by Rasmus Villemoes <[email protected]>Reviewed-by Stefan Roese <[email protected]>
<snip>
Applied to u-boot-mpc85xx. Awaiting upstream
Thanks
Priyanka
PATCH 1/1 powerpc: reduce number of WATCHDOG_RESET calls from flush_cache
Dear Priyanka,
Quoted 7 lines · In message <VE1PR04MB649416C255B3379B43E7F7FDE6380@VE1PR04MB6494.eurprd04.prod.…
Quoted 5 lines
Quoted 4 lines
Quoted 2 lines
Signed-off-by Rasmus Villemoes <[email protected]>Reviewed-by Stefan Roese <[email protected]><snip>
Applied to u-boot-mpc85xx. Awaiting upstream
I object. This must at least be configurable, so that boards with tight timing requirements can still work.
Best regards,
Wolfgang Denk
Signature · 5 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de The human mind ordinarily operates at only ten percent of its capacity. The rest is overhead for the operating system.
PATCH 1/1 powerpc: reduce number of WATCHDOG_RESET calls from flush_cache
Quoted 6 lines · Wolfgang Denk
Dear Priyanka,
Quoted 3 lines · In message <VE1PR04MB649416C255B3379B43E7F7FDE6380@VE1PR04MB6494.eurprd04.prod.…
Quoted 3 lines
Quoted 3 lines
Quoted 2 lines
Signed-off-by Rasmus Villemoes <[email protected]>
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Quoted 1 line
Reviewed-by Stefan Roese <[email protected]><snip>
Applied to u-boot-mpc85xx. Awaiting upstreamI object. This must at least be configurable, so that boards with tight timing requirements can still work.
I'm removing just this patch from the -next pull request.
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200924/d8dbaf12/attachment.sig>