From 273834ee84814ba543d17c6c2b8a1a4d2c3ed2fa Mon Sep 17 00:00:00 2001 From: Romain Goyet Date: Sun, 15 Dec 2019 17:13:27 -0500 Subject: [PATCH] [ion/cache] Improve cache cleaning - Avoid fetching CCSIDR twice - Use for loop instead of do/while - Only compute the target register once - Avoid an useless nop --- ion/src/device/n0110/drivers/cache.cpp | 39 +++++++++++++------------- ion/src/device/shared/regs/cortex.h | 1 + 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/ion/src/device/n0110/drivers/cache.cpp b/ion/src/device/n0110/drivers/cache.cpp index f14bee613..87b1a36f2 100644 --- a/ion/src/device/n0110/drivers/cache.cpp +++ b/ion/src/device/n0110/drivers/cache.cpp @@ -17,28 +17,29 @@ void privateCleanInvalidateDisableDCache(bool clean, bool invalidate, bool disab dsb(); } - uint32_t sets = CORTEX.CCSIDR()->getNUMSETS(); - uint32_t ways = CORTEX.CCSIDR()->getASSOCIATIVITY(); + // Pick the right DC??SW register according to invalidate/disable parameters + volatile CORTEX::DCSW * target = nullptr; + if (clean && invalidate) { + target = CORTEX.DCCISW(); + } else if (clean) { + target = CORTEX.DCCSW(); + } else { + assert(invalidate); + target = CORTEX.DCISW(); + } - do { - uint32_t w = ways; - do { + class CORTEX::CCSIDR ccsidr = CORTEX.CCSIDR()->get(); + uint32_t sets = ccsidr.getNUMSETS(); + uint32_t ways = ccsidr.getASSOCIATIVITY(); + + for (int set = sets; set >= 0; set--) { + for (int way = ways; way >= 0; way--) { class CORTEX::DCSW dcsw; - dcsw.setSET(sets); - dcsw.setWAY(w); - volatile CORTEX::DCSW * target = nullptr; - if (clean && invalidate) { - target = CORTEX.DCCISW(); - } else if (clean) { - target = CORTEX.DCCSW(); - } else { - assert(invalidate); - target = CORTEX.DCISW(); - } + dcsw.setSET(set); + dcsw.setWAY(way); target->set(dcsw); - __asm volatile("nop"); - } while (w-- != 0); - } while (sets-- != 0); + } + } dsb(); isb(); diff --git a/ion/src/device/shared/regs/cortex.h b/ion/src/device/shared/regs/cortex.h index 15d6e4ace..2c71c0fa2 100644 --- a/ion/src/device/shared/regs/cortex.h +++ b/ion/src/device/shared/regs/cortex.h @@ -72,6 +72,7 @@ public: #if REGS_CORTEX_CONFIG_CACHE class CCSIDR : public Register32 { public: + using Register32::Register32; REGS_FIELD(ASSOCIATIVITY, uint16_t, 12, 3); REGS_FIELD(NUMSETS, uint16_t, 27, 13); };