From: Rasmus Villemoes Date: Thu, 15 Apr 2021 08:46:49 +0200 Subject: [PATCH v2 2/2] powerpc: introduce CONFIG_CACHE_FLUSH_WATCHDOG_THRESHOLD In-Reply-To: <8b26b614-87ed-f53e-c87a-3c9b33e1e91d@denx.de> References: <20210413193827.2632540-1-rasmus.villemoes@prevas.dk> <20210413193827.2632540-3-rasmus.villemoes@prevas.dk> <8b26b614-87ed-f53e-c87a-3c9b33e1e91d@denx.de> Message-ID: <43258040-7813-cb35-2dde-180446c6704f@prevas.dk> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de On 15/04/2021 07.34, Stefan Roese wrote: > On 13.04.21 21:38, Rasmus Villemoes wrote: >> >> I have checked with objdump that the generated code doesn't change >> when this option is left at its default value of 0: gcc is smart >> enough to see that wd_limit is constant 0, the ">=" comparisons are >> tautologically true, hence all assignments to "flushed" are eliminated > > Nitpicking: > s/tautologically/autologically. No. https://www.merriam-webster.com/dictionary/tautological https://en.wikipedia.org/wiki/Tautology_(logic) "In Mathematical logic, a tautology (from Greek: ??????????) is a formula or assertion that is true in every possible interpretation." It even exists in gcc docs in the form of -Wtautological-compare. [But I do admit that "tautologically true" is a pleonasm; "tautologies" or "automatically true" could have been used instead. And going full meta, now that I look up pleonasm in wikipedia to check that I'm using it right, that article has a reference to "tautology (language)" in its second sentence.] >> ????? /* wait for all dcbst to complete on bus */ >> ????? asm volatile("sync" : : : "memory"); >> @@ -27,7 +33,11 @@ void flush_cache(ulong start_addr, ulong size) >> ????? for (addr = start; (addr <= end) && (addr >= start); >> ????????????? addr += CONFIG_SYS_CACHELINE_SIZE) { >> ????????? asm volatile("icbi 0,%0" : : "r" (addr) : "memory"); >> -??????? WATCHDOG_RESET(); >> +??????? flushed += CONFIG_SYS_CACHELINE_SIZE; >> +??????? if (flushed >= wd_limit) { >> +??????????? WATCHDOG_RESET(); >> +??????????? flushed = 0; >> +??????? } > > It might make sense to pull these 2 identical code snippets into a > function to not duplicate this code. Something like static ulong maybe_reset(ulong flushed) { const ulong wd_limit = ...; flushed += CONFIG_SYS_CACHELINE_SIZE; if (flushed >= wd_limit) { WATCHDOG_RESET(); flushed = 0; } return flushed; } and "flushed = maybe_reset(flushed);"? I don't think that improves readability. Thanks, Rasmus