2
0
mirror of git://git.code.sf.net/p/openocd/code synced 2025-08-16 18:57:55 +10:00

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 <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/9064
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
Tested-by: jenkins
Reviewed-by: Lucien Buchmann <lucien.buchmann@dufour.aero>
This commit is contained in:
Antonio Borneo 2025-08-01 18:02:31 +02:00
parent 37f638bb4c
commit 9fe3780432
7 changed files with 28 additions and 55 deletions

View File

@ -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 */

View File

@ -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();
}
}

View File

@ -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 */

View File

@ -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) {

View File

@ -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;
}

View File

@ -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);

View File

@ -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",