This is an automated email from Gerrit.

"Antonio Borneo <[email protected]>" just uploaded a new patch set to 
Gerrit, which you can find at https://review.openocd.org/c/openocd/+/9064

-- gerrit

commit 234f570e3e2fec9f5735ac9f6f7ede2a3b4fb0ed
Author: Antonio Borneo <[email protected]>
Date:   Fri Aug 1 18:02:31 2025 +0200

    openocd: drop iteration downsampling for keep_alive()
    
    The function keep_alive() is optimized and return immediately if
    has nothing to do.
    There is no need to overly-complicate the code with extra counters
    or time computation plus the relative checks to reduce the number
    of calls to keep_alive().
    
    Drop such extra code.
    
    Change-Id: I4574a3f154b5779f44105936c74af8fca1d2c49c
    Signed-off-by: Antonio Borneo <[email protected]>

diff --git a/src/flash/nor/cc26xx.c b/src/flash/nor/cc26xx.c
index 54d61421ce..765a327182 100644
--- a/src/flash/nor/cc26xx.c
+++ b/src/flash/nor/cc26xx.c
@@ -112,10 +112,10 @@ static int cc26xx_wait_algo_done(struct flash_bank *bank, 
uint32_t params_addr)
                        return retval;
 
                elapsed_ms = timeval_ms() - start_ms;
-               if (elapsed_ms > 500)
-                       keep_alive();
                if (elapsed_ms > FLASH_TIMEOUT)
                        break;
+
+               keep_alive();
        };
 
        if (status != CC26XX_BUFFER_EMPTY) {
@@ -321,8 +321,6 @@ static int cc26xx_write(struct flash_bank *bank, const 
uint8_t *buffer,
        struct cc26xx_bank *cc26xx_bank = bank->driver_priv;
        struct cc26xx_algo_params algo_params[2];
        uint32_t size = 0;
-       long long start_ms;
-       long long elapsed_ms;
        uint32_t address;
 
        uint32_t index;
@@ -343,7 +341,6 @@ static int cc26xx_write(struct flash_bank *bank, const 
uint8_t *buffer,
 
        /* Write requested data, ping-ponging between two buffers */
        index = 0;
-       start_ms = timeval_ms();
        address = bank->base + offset;
        while (count > 0) {
 
@@ -381,9 +378,7 @@ static int cc26xx_write(struct flash_bank *bank, const 
uint8_t *buffer,
                buffer += size;
                address += size;
 
-               elapsed_ms = timeval_ms() - start_ms;
-               if (elapsed_ms > 500)
-                       keep_alive();
+               keep_alive();
        }
 
        /* If no error yet, wait for last buffer to finish */
diff --git a/src/flash/nor/cc3220sf.c b/src/flash/nor/cc3220sf.c
index 74cb7aea57..0418aeac2b 100644
--- a/src/flash/nor/cc3220sf.c
+++ b/src/flash/nor/cc3220sf.c
@@ -65,10 +65,10 @@ static int cc3220sf_mass_erase(struct flash_bank *bank)
                        done = true;
                } else {
                        elapsed_ms = timeval_ms() - start_ms;
-                       if (elapsed_ms > 500)
-                               keep_alive();
                        if (elapsed_ms > FLASH_TIMEOUT)
                                break;
+
+                       keep_alive();
                }
        }
 
@@ -152,10 +152,10 @@ static int cc3220sf_erase(struct flash_bank *bank, 
unsigned int first,
                                done = true;
                        } else {
                                elapsed_ms = timeval_ms() - start_ms;
-                               if (elapsed_ms > 500)
-                                       keep_alive();
                                if (elapsed_ms > FLASH_TIMEOUT)
                                        break;
+
+                               keep_alive();
                        }
                }
 
diff --git a/src/flash/nor/msp432.c b/src/flash/nor/msp432.c
index b5e2b0bf86..e79841b47a 100644
--- a/src/flash/nor/msp432.c
+++ b/src/flash/nor/msp432.c
@@ -219,10 +219,10 @@ static int msp432_wait_return_code(struct target *target)
                        return retval;
 
                elapsed_ms = timeval_ms() - start_ms;
-               if (elapsed_ms > 500)
-                       keep_alive();
                if (elapsed_ms > FLASH_TIMEOUT)
                        break;
+
+               keep_alive();
        };
 
        if (return_code != FLASH_SUCCESS) {
@@ -261,10 +261,10 @@ static int msp432_wait_inactive(struct target *target, 
uint32_t buffer)
                        return retval;
 
                elapsed_ms = timeval_ms() - start_ms;
-               if (elapsed_ms > 500)
-                       keep_alive();
                if (elapsed_ms > FLASH_TIMEOUT)
                        break;
+
+               keep_alive();
        };
 
        if (status_code != BUFFER_INACTIVE) {
@@ -678,8 +678,6 @@ static int msp432_write(struct flash_bank *bank, const 
uint8_t *buffer,
        struct msp432_algo_params algo_params;
        uint32_t size;
        uint32_t data_ready = BUFFER_DATA_READY;
-       long long start_ms;
-       long long elapsed_ms;
 
        bool is_info = bank->base == P4_FLASH_INFO_BASE;
 
@@ -753,7 +751,6 @@ static int msp432_write(struct flash_bank *bank, const 
uint8_t *buffer,
        }
 
        /* Write requested data, one buffer at a time */
-       start_ms = timeval_ms();
        while (count > 0) {
 
                if (count > ALGO_BUFFER_SIZE)
@@ -786,9 +783,7 @@ static int msp432_write(struct flash_bank *bank, const 
uint8_t *buffer,
                count -= size;
                buffer += size;
 
-               elapsed_ms = timeval_ms() - start_ms;
-               if (elapsed_ms > 500)
-                       keep_alive();
+               keep_alive();
        }
 
        /* Confirm that the flash helper algorithm is finished */
diff --git a/src/flash/nor/mspm0.c b/src/flash/nor/mspm0.c
index 4731c89ccf..245fcdd0d8 100644
--- a/src/flash/nor/mspm0.c
+++ b/src/flash/nor/mspm0.c
@@ -737,10 +737,10 @@ static int mspm0_fctl_wait_cmd_ok(struct flash_bank *bank)
                        return retval;
 
                elapsed_ms = timeval_ms() - start_ms;
-               if (elapsed_ms > 500)
-                       keep_alive();
                if (elapsed_ms > MSPM0_FLASH_TIMEOUT_MS)
                        break;
+
+               keep_alive();
        }
 
        if ((return_code & FCTL_STATCMD_CMDPASS_MASK) != 
FCTL_STATCMD_CMDPASS_STATPASS) {
diff --git a/src/target/arm7_9_common.c b/src/target/arm7_9_common.c
index 5550fb1e24..319892da82 100644
--- a/src/target/arm7_9_common.c
+++ b/src/target/arm7_9_common.c
@@ -2135,8 +2135,6 @@ int arm7_9_read_memory(struct target *target,
        reg[0] = address;
        arm7_9->write_core_regs(target, 0x1, reg);
 
-       int j = 0;
-
        switch (size) {
                case 4:
                        while (num_accesses < count) {
@@ -2166,8 +2164,7 @@ int arm7_9_read_memory(struct target *target,
                                buffer += thisrun_accesses * 4;
                                num_accesses += thisrun_accesses;
 
-                               if ((j++%1024) == 0)
-                                       keep_alive();
+                               keep_alive();
                        }
                        break;
                case 2:
@@ -2199,8 +2196,7 @@ int arm7_9_read_memory(struct target *target,
                                buffer += thisrun_accesses * 2;
                                num_accesses += thisrun_accesses;
 
-                               if ((j++%1024) == 0)
-                                       keep_alive();
+                               keep_alive();
                        }
                        break;
                case 1:
@@ -2231,8 +2227,7 @@ int arm7_9_read_memory(struct target *target,
                                buffer += thisrun_accesses * 1;
                                num_accesses += thisrun_accesses;
 
-                               if ((j++%1024) == 0)
-                                       keep_alive();
+                               keep_alive();
                        }
                        break;
        }
diff --git a/src/target/armv7a_cache.c b/src/target/armv7a_cache.c
index f2f1097c5a..5eb31d8c08 100644
--- a/src/target/armv7a_cache.c
+++ b/src/target/armv7a_cache.c
@@ -151,9 +151,8 @@ int armv7a_l1_d_cache_inval_virt(struct target *target, 
uint32_t virt,
        struct armv7a_cache_common *armv7a_cache = 
&armv7a->armv7a_mmu.armv7a_cache;
        uint32_t linelen = armv7a_cache->dminline;
        uint32_t va_line, va_end;
-       int retval, i = 0;
 
-       retval = armv7a_l1_d_cache_sanity_check(target);
+       int retval = armv7a_l1_d_cache_sanity_check(target);
        if (retval != ERROR_OK)
                return retval;
 
@@ -185,8 +184,7 @@ int armv7a_l1_d_cache_inval_virt(struct target *target, 
uint32_t virt,
        }
 
        while (va_line < va_end) {
-               if ((i++ & 0x3f) == 0)
-                       keep_alive();
+               keep_alive();
                /* DCIMVAC - Invalidate data cache line by VA to PoC. */
                retval = dpm->instr_write_data_r0(dpm,
                                ARMV4_5_MCR(15, 0, 0, 7, 6, 1), va_line);
@@ -215,9 +213,8 @@ int armv7a_l1_d_cache_clean_virt(struct target *target, 
uint32_t virt,
        struct armv7a_cache_common *armv7a_cache = 
&armv7a->armv7a_mmu.armv7a_cache;
        uint32_t linelen = armv7a_cache->dminline;
        uint32_t va_line, va_end;
-       int retval, i = 0;
 
-       retval = armv7a_l1_d_cache_sanity_check(target);
+       int retval = armv7a_l1_d_cache_sanity_check(target);
        if (retval != ERROR_OK)
                return retval;
 
@@ -229,8 +226,7 @@ int armv7a_l1_d_cache_clean_virt(struct target *target, 
uint32_t virt,
        va_end = virt + size;
 
        while (va_line < va_end) {
-               if ((i++ & 0x3f) == 0)
-                       keep_alive();
+               keep_alive();
                /* DCCMVAC - Data Cache Clean by MVA to PoC */
                retval = dpm->instr_write_data_r0(dpm,
                                ARMV4_5_MCR(15, 0, 0, 7, 10, 1), va_line);
@@ -259,9 +255,8 @@ int armv7a_l1_d_cache_flush_virt(struct target *target, 
uint32_t virt,
        struct armv7a_cache_common *armv7a_cache = 
&armv7a->armv7a_mmu.armv7a_cache;
        uint32_t linelen = armv7a_cache->dminline;
        uint32_t va_line, va_end;
-       int retval, i = 0;
 
-       retval = armv7a_l1_d_cache_sanity_check(target);
+       int retval = armv7a_l1_d_cache_sanity_check(target);
        if (retval != ERROR_OK)
                return retval;
 
@@ -273,8 +268,7 @@ int armv7a_l1_d_cache_flush_virt(struct target *target, 
uint32_t virt,
        va_end = virt + size;
 
        while (va_line < va_end) {
-               if ((i++ & 0x3f) == 0)
-                       keep_alive();
+               keep_alive();
                /* DCCIMVAC */
                retval = dpm->instr_write_data_r0(dpm,
                                ARMV4_5_MCR(15, 0, 0, 7, 14, 1), va_line);
@@ -341,9 +335,8 @@ int armv7a_l1_i_cache_inval_virt(struct target *target, 
uint32_t virt,
                                &armv7a->armv7a_mmu.armv7a_cache;
        uint32_t linelen = armv7a_cache->iminline;
        uint32_t va_line, va_end;
-       int retval, i = 0;
 
-       retval = armv7a_l1_i_cache_sanity_check(target);
+       int retval = armv7a_l1_i_cache_sanity_check(target);
        if (retval != ERROR_OK)
                return retval;
 
@@ -355,8 +348,7 @@ int armv7a_l1_i_cache_inval_virt(struct target *target, 
uint32_t virt,
        va_end = virt + size;
 
        while (va_line < va_end) {
-               if ((i++ & 0x3f) == 0)
-                       keep_alive();
+               keep_alive();
                /* ICIMVAU - Invalidate instruction cache by VA to PoU. */
                retval = dpm->instr_write_data_r0(dpm,
                                ARMV4_5_MCR(15, 0, 0, 7, 5, 1), va_line);
diff --git a/src/target/target.c b/src/target/target.c
index 995adbc9d3..106287eb8b 100644
--- a/src/target/target.c
+++ b/src/target/target.c
@@ -3216,8 +3216,6 @@ COMMAND_HANDLER(handle_wait_halt_command)
 /* wait for target state to change. The trick here is to have a low
  * latency for short waits and not to suck up all the CPU time
  * on longer waits.
- *
- * After 500ms, keep_alive() is invoked
  */
 int target_wait_state(struct target *target, enum target_state state, unsigned 
int ms)
 {
@@ -3239,11 +3237,9 @@ int target_wait_state(struct target *target, enum 
target_state state, unsigned i
                                nvp_value2name(nvp_target_state, state)->name);
                }
 
-               if (cur - then > 500) {
-                       keep_alive();
-                       if (openocd_is_shutdown_pending())
-                               return ERROR_SERVER_INTERRUPTED;
-               }
+               keep_alive();
+               if (openocd_is_shutdown_pending())
+                       return ERROR_SERVER_INTERRUPTED;
 
                if ((cur-then) > ms) {
                        LOG_ERROR("timed out while waiting for target %s",

-- 

Reply via email to