Overhaul time support API
This patch changes the duration_* API in several ways. First, it updates the API to use better names. Second, string formatting has been removed from the API (with its associated malloc). Finally, a new function added to convert the time into seconds, which can be used (or formatted) by the caller. This eliminates hidden calls to malloc that require associated calls to free(). This patch also removes the useless extern keyword from prototypes, and it eliminates the duration_t typedef (use 'struct duration'). These API also allows proper error checking, as it is possible for gettimeofday to fail in certain circumstances. The consumers have all been chased to use this new API as well, as there were relatively few cases doing this type of measurement. In most cases, the code performs additional checks for errors, but the calling code looks much cleaner in every case.__archive__
parent
da3196bf5e
commit
2689f58f2a
|
@ -503,8 +503,6 @@ static int handle_flash_erase_address_command(struct command_context_s *cmd_ctx,
|
||||||
int retval;
|
int retval;
|
||||||
int address;
|
int address;
|
||||||
int length;
|
int length;
|
||||||
duration_t duration;
|
|
||||||
char *duration_text;
|
|
||||||
|
|
||||||
target_t *target = get_current_target(cmd_ctx);
|
target_t *target = get_current_target(cmd_ctx);
|
||||||
|
|
||||||
|
@ -528,16 +526,16 @@ static int handle_flash_erase_address_command(struct command_context_s *cmd_ctx,
|
||||||
/* We can't know if we did a resume + halt, in which case we no longer know the erased state */
|
/* We can't know if we did a resume + halt, in which case we no longer know the erased state */
|
||||||
flash_set_dirty();
|
flash_set_dirty();
|
||||||
|
|
||||||
duration_start_measure(&duration);
|
struct duration bench;
|
||||||
|
duration_start(&bench);
|
||||||
|
|
||||||
if ((retval = flash_erase_address_range(target, address, length)) == ERROR_OK)
|
retval = flash_erase_address_range(target, address, length);
|
||||||
|
|
||||||
|
if ((ERROR_OK == retval) && (duration_measure(&bench) == ERROR_OK))
|
||||||
{
|
{
|
||||||
if ((retval = duration_stop_measure(&duration, &duration_text)) != ERROR_OK)
|
command_print(cmd_ctx, "erased address 0x%8.8x (length %i)"
|
||||||
{
|
" in %fs (%0.3f kb/s)", address, length,
|
||||||
return retval;
|
duration_elapsed(&bench), duration_kbps(&bench, length));
|
||||||
}
|
|
||||||
command_print(cmd_ctx, "erased address 0x%8.8x length %i in %s", address, length, duration_text);
|
|
||||||
free(duration_text);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
|
@ -613,19 +611,16 @@ static int handle_flash_erase_command(struct command_context_s *cmd_ctx,
|
||||||
first, last, p->num_sectors)) != ERROR_OK)
|
first, last, p->num_sectors)) != ERROR_OK)
|
||||||
return retval;
|
return retval;
|
||||||
|
|
||||||
duration_t duration;
|
struct duration bench;
|
||||||
char *duration_text;
|
duration_start(&bench);
|
||||||
duration_start_measure(&duration);
|
|
||||||
|
|
||||||
if ((retval = flash_driver_erase(p, first, last)) == ERROR_OK) {
|
retval = flash_driver_erase(p, first, last);
|
||||||
if ((retval = duration_stop_measure(&duration,
|
|
||||||
&duration_text)) != ERROR_OK)
|
if ((ERROR_OK == retval) && (duration_measure(&bench) == ERROR_OK))
|
||||||
return retval;
|
{
|
||||||
command_print(cmd_ctx, "erased sectors %i through %i "
|
command_print(cmd_ctx, "erased sectors %" PRIu32 " "
|
||||||
"on flash bank %i in %s",
|
"through %" PRIu32" on flash bank %" PRIu32 " "
|
||||||
(int) first, (int) last, (int) bank_nr,
|
"in %fs", first, last, bank_nr, duration_elapsed(&bench));
|
||||||
duration_text);
|
|
||||||
free(duration_text);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ERROR_OK;
|
return ERROR_OK;
|
||||||
|
@ -683,10 +678,7 @@ static int handle_flash_write_image_command(struct command_context_s *cmd_ctx, c
|
||||||
image_t image;
|
image_t image;
|
||||||
uint32_t written;
|
uint32_t written;
|
||||||
|
|
||||||
duration_t duration;
|
int retval;
|
||||||
char *duration_text;
|
|
||||||
|
|
||||||
int retval, retvaltemp;
|
|
||||||
|
|
||||||
if (argc < 1)
|
if (argc < 1)
|
||||||
{
|
{
|
||||||
|
@ -728,7 +720,8 @@ static int handle_flash_write_image_command(struct command_context_s *cmd_ctx, c
|
||||||
return ERROR_FAIL;
|
return ERROR_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
duration_start_measure(&duration);
|
struct duration bench;
|
||||||
|
duration_start(&bench);
|
||||||
|
|
||||||
if (argc >= 2)
|
if (argc >= 2)
|
||||||
{
|
{
|
||||||
|
@ -756,23 +749,13 @@ static int handle_flash_write_image_command(struct command_context_s *cmd_ctx, c
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((retvaltemp = duration_stop_measure(&duration, &duration_text)) != ERROR_OK)
|
if ((ERROR_OK == retval) && (duration_measure(&bench) == ERROR_OK))
|
||||||
{
|
{
|
||||||
image_close(&image);
|
command_print(cmd_ctx, "wrote %" PRIu32 " byte from file %s "
|
||||||
return retvaltemp;
|
"in %fs (%0.3f kb/s)", written, args[0],
|
||||||
|
duration_elapsed(&bench), duration_kbps(&bench, written));
|
||||||
}
|
}
|
||||||
|
|
||||||
float speed;
|
|
||||||
|
|
||||||
speed = written / 1024.0;
|
|
||||||
speed /= ((float)duration.duration.tv_sec
|
|
||||||
+ ((float)duration.duration.tv_usec / 1000000.0));
|
|
||||||
command_print(cmd_ctx,
|
|
||||||
"wrote %" PRIu32 " byte from file %s in %s (%f kb/s)",
|
|
||||||
written, args[0], duration_text, speed);
|
|
||||||
|
|
||||||
free(duration_text);
|
|
||||||
|
|
||||||
image_close(&image);
|
image_close(&image);
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
|
@ -780,7 +763,7 @@ static int handle_flash_write_image_command(struct command_context_s *cmd_ctx, c
|
||||||
|
|
||||||
static int handle_flash_fill_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
|
static int handle_flash_fill_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
|
||||||
{
|
{
|
||||||
int err = ERROR_OK, retval;
|
int err = ERROR_OK;
|
||||||
uint32_t address;
|
uint32_t address;
|
||||||
uint32_t pattern;
|
uint32_t pattern;
|
||||||
uint32_t count;
|
uint32_t count;
|
||||||
|
@ -789,8 +772,6 @@ static int handle_flash_fill_command(struct command_context_s *cmd_ctx, char *cm
|
||||||
uint32_t wrote = 0;
|
uint32_t wrote = 0;
|
||||||
uint32_t cur_size = 0;
|
uint32_t cur_size = 0;
|
||||||
uint32_t chunk_count;
|
uint32_t chunk_count;
|
||||||
char *duration_text;
|
|
||||||
duration_t duration;
|
|
||||||
target_t *target = get_current_target(cmd_ctx);
|
target_t *target = get_current_target(cmd_ctx);
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
uint32_t wordsize;
|
uint32_t wordsize;
|
||||||
|
@ -843,7 +824,8 @@ static int handle_flash_fill_command(struct command_context_s *cmd_ctx, char *cm
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
duration_start_measure(&duration);
|
struct duration bench;
|
||||||
|
duration_start(&bench);
|
||||||
|
|
||||||
for (wrote = 0; wrote < (count*wordsize); wrote += cur_size)
|
for (wrote = 0; wrote < (count*wordsize); wrote += cur_size)
|
||||||
{
|
{
|
||||||
|
@ -872,24 +854,14 @@ static int handle_flash_fill_command(struct command_context_s *cmd_ctx, char *cm
|
||||||
return ERROR_FAIL;
|
return ERROR_FAIL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((retval = duration_stop_measure(&duration, &duration_text)) != ERROR_OK)
|
if (duration_measure(&bench) == ERROR_OK)
|
||||||
{
|
{
|
||||||
return retval;
|
command_print(cmd_ctx, "wrote %" PRIu32 " bytes to 0x%8.8" PRIx32
|
||||||
|
" in %fs (%0.3f kb/s)", wrote, address,
|
||||||
|
duration_elapsed(&bench), duration_kbps(&bench, wrote));
|
||||||
}
|
}
|
||||||
|
|
||||||
float speed;
|
|
||||||
|
|
||||||
speed = wrote / 1024.0;
|
|
||||||
speed /= ((float)duration.duration.tv_sec
|
|
||||||
+ ((float)duration.duration.tv_usec / 1000000.0));
|
|
||||||
command_print(cmd_ctx,
|
|
||||||
"wrote %" PRIu32 " bytes to 0x%8.8" PRIx32 " in %s (%f kb/s)",
|
|
||||||
wrote, address, duration_text, speed);
|
|
||||||
|
|
||||||
free(duration_text);
|
|
||||||
return ERROR_OK;
|
return ERROR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -898,17 +870,13 @@ static int handle_flash_write_bank_command(struct command_context_s *cmd_ctx, ch
|
||||||
uint32_t offset;
|
uint32_t offset;
|
||||||
uint8_t *buffer;
|
uint8_t *buffer;
|
||||||
uint32_t buf_cnt;
|
uint32_t buf_cnt;
|
||||||
|
|
||||||
fileio_t fileio;
|
fileio_t fileio;
|
||||||
|
|
||||||
duration_t duration;
|
|
||||||
char *duration_text;
|
|
||||||
|
|
||||||
|
|
||||||
if (argc != 3)
|
if (argc != 3)
|
||||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||||
|
|
||||||
duration_start_measure(&duration);
|
struct duration bench;
|
||||||
|
duration_start(&bench);
|
||||||
|
|
||||||
flash_bank_t *p;
|
flash_bank_t *p;
|
||||||
int retval = flash_command_get_bank_by_num(cmd_ctx, args[0], &p);
|
int retval = flash_command_get_bank_by_num(cmd_ctx, args[0], &p);
|
||||||
|
@ -935,24 +903,13 @@ static int handle_flash_write_bank_command(struct command_context_s *cmd_ctx, ch
|
||||||
free(buffer);
|
free(buffer);
|
||||||
buffer = NULL;
|
buffer = NULL;
|
||||||
|
|
||||||
int retvaltemp;
|
if ((ERROR_OK == retval) && (duration_measure(&bench) == ERROR_OK))
|
||||||
if ((retvaltemp = duration_stop_measure(&duration, &duration_text)) != ERROR_OK)
|
|
||||||
{
|
{
|
||||||
fileio_close(&fileio);
|
command_print(cmd_ctx, "wrote %lld byte from file %s to flash bank %u"
|
||||||
return retvaltemp;
|
" at offset 0x%8.8" PRIx32 " in %fs (%0.3f kb/s)",
|
||||||
}
|
|
||||||
if (retval == ERROR_OK)
|
|
||||||
{
|
|
||||||
float elapsed = (float)duration.duration.tv_sec;
|
|
||||||
elapsed += (float)duration.duration.tv_usec / 1000000.0;
|
|
||||||
float speed = (float)fileio.size / elapsed;
|
|
||||||
command_print(cmd_ctx,
|
|
||||||
"wrote %lld byte from file %s to flash bank %u "
|
|
||||||
"at offset 0x%8.8" PRIx32 " in %s (%f kb/s)",
|
|
||||||
fileio.size, args[1], p->bank_number, offset,
|
fileio.size, args[1], p->bank_number, offset,
|
||||||
duration_text, speed / 1024);
|
duration_elapsed(&bench), duration_kbps(&bench, fileio.size));
|
||||||
}
|
}
|
||||||
free(duration_text);
|
|
||||||
|
|
||||||
fileio_close(&fileio);
|
fileio_close(&fileio);
|
||||||
|
|
||||||
|
|
|
@ -215,11 +215,11 @@ static int mg_dsk_wait(mg_io_type_wait wait, uint32_t time)
|
||||||
uint8_t status, error;
|
uint8_t status, error;
|
||||||
target_t *target = mflash_bank->target;
|
target_t *target = mflash_bank->target;
|
||||||
uint32_t mg_task_reg = mflash_bank->base + MG_REG_OFFSET;
|
uint32_t mg_task_reg = mflash_bank->base + MG_REG_OFFSET;
|
||||||
duration_t duration;
|
|
||||||
int ret;
|
int ret;
|
||||||
long long t = 0;
|
long long t = 0;
|
||||||
|
|
||||||
duration_start_measure(&duration);
|
struct duration bench;
|
||||||
|
duration_start(&bench);
|
||||||
|
|
||||||
while (time) {
|
while (time) {
|
||||||
|
|
||||||
|
@ -275,10 +275,11 @@ static int mg_dsk_wait(mg_io_type_wait wait, uint32_t time)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
duration_stop_measure(&duration, NULL);
|
ret = duration_measure(&bench);
|
||||||
|
if (ERROR_OK == ret)
|
||||||
t = duration.duration.tv_usec/1000;
|
t = duration_elapsed(&bench) * 1000.0;
|
||||||
t += duration.duration.tv_sec*1000;
|
else
|
||||||
|
LOG_ERROR("mflash: duration measurement failed: %d", ret);
|
||||||
|
|
||||||
if (t > time)
|
if (t > time)
|
||||||
break;
|
break;
|
||||||
|
@ -427,14 +428,14 @@ static int mg_mflash_do_read_sects(void *buff, uint32_t sect_num, uint32_t sect_
|
||||||
int ret;
|
int ret;
|
||||||
target_t *target = mflash_bank->target;
|
target_t *target = mflash_bank->target;
|
||||||
uint8_t *buff_ptr = buff;
|
uint8_t *buff_ptr = buff;
|
||||||
duration_t duration;
|
|
||||||
|
|
||||||
if ((ret = mg_dsk_io_cmd(sect_num, sect_cnt, mg_io_cmd_read)) != ERROR_OK)
|
if ((ret = mg_dsk_io_cmd(sect_num, sect_cnt, mg_io_cmd_read)) != ERROR_OK)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
address = mflash_bank->base + MG_BUFFER_OFFSET;
|
address = mflash_bank->base + MG_BUFFER_OFFSET;
|
||||||
|
|
||||||
duration_start_measure(&duration);
|
struct duration bench;
|
||||||
|
duration_start(&bench);
|
||||||
|
|
||||||
for (i = 0; i < sect_cnt; i++) {
|
for (i = 0; i < sect_cnt; i++) {
|
||||||
ret = mg_dsk_wait(mg_io_wait_drq, MG_OEM_DISK_WAIT_TIME_NORMAL);
|
ret = mg_dsk_wait(mg_io_wait_drq, MG_OEM_DISK_WAIT_TIME_NORMAL);
|
||||||
|
@ -453,11 +454,10 @@ static int mg_mflash_do_read_sects(void *buff, uint32_t sect_num, uint32_t sect_
|
||||||
|
|
||||||
LOG_DEBUG("mflash: %" PRIu32 " (0x%8.8" PRIx32 ") sector read", sect_num + i, (sect_num + i) * MG_MFLASH_SECTOR_SIZE);
|
LOG_DEBUG("mflash: %" PRIu32 " (0x%8.8" PRIx32 ") sector read", sect_num + i, (sect_num + i) * MG_MFLASH_SECTOR_SIZE);
|
||||||
|
|
||||||
duration_stop_measure(&duration, NULL);
|
ret = duration_measure(&bench);
|
||||||
|
if ((ERROR_OK == ret) && (duration_elapsed(&bench) > 3)) {
|
||||||
if ((duration.duration.tv_sec * 1000 + duration.duration.tv_usec / 1000) > 3000) {
|
|
||||||
LOG_INFO("mflash: read %" PRIu32 "'th sectors", sect_num + i);
|
LOG_INFO("mflash: read %" PRIu32 "'th sectors", sect_num + i);
|
||||||
duration_start_measure(&duration);
|
duration_start(&bench);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -500,14 +500,14 @@ static int mg_mflash_do_write_sects(void *buff, uint32_t sect_num, uint32_t sect
|
||||||
int ret;
|
int ret;
|
||||||
target_t *target = mflash_bank->target;
|
target_t *target = mflash_bank->target;
|
||||||
uint8_t *buff_ptr = buff;
|
uint8_t *buff_ptr = buff;
|
||||||
duration_t duration;
|
|
||||||
|
|
||||||
if ((ret = mg_dsk_io_cmd(sect_num, sect_cnt, cmd)) != ERROR_OK)
|
if ((ret = mg_dsk_io_cmd(sect_num, sect_cnt, cmd)) != ERROR_OK)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
address = mflash_bank->base + MG_BUFFER_OFFSET;
|
address = mflash_bank->base + MG_BUFFER_OFFSET;
|
||||||
|
|
||||||
duration_start_measure(&duration);
|
struct duration bench;
|
||||||
|
duration_start(&bench);
|
||||||
|
|
||||||
for (i = 0; i < sect_cnt; i++) {
|
for (i = 0; i < sect_cnt; i++) {
|
||||||
ret = mg_dsk_wait(mg_io_wait_drq, MG_OEM_DISK_WAIT_TIME_NORMAL);
|
ret = mg_dsk_wait(mg_io_wait_drq, MG_OEM_DISK_WAIT_TIME_NORMAL);
|
||||||
|
@ -526,11 +526,10 @@ static int mg_mflash_do_write_sects(void *buff, uint32_t sect_num, uint32_t sect
|
||||||
|
|
||||||
LOG_DEBUG("mflash: %" PRIu32 " (0x%8.8" PRIx32 ") sector write", sect_num + i, (sect_num + i) * MG_MFLASH_SECTOR_SIZE);
|
LOG_DEBUG("mflash: %" PRIu32 " (0x%8.8" PRIx32 ") sector write", sect_num + i, (sect_num + i) * MG_MFLASH_SECTOR_SIZE);
|
||||||
|
|
||||||
duration_stop_measure(&duration, NULL);
|
ret = duration_measure(&bench);
|
||||||
|
if ((ERROR_OK == ret) && (duration_elapsed(&bench) > 3)) {
|
||||||
if ((duration.duration.tv_sec * 1000 + duration.duration.tv_usec / 1000) > 3000) {
|
|
||||||
LOG_INFO("mflash: wrote %" PRIu32 "'th sectors", sect_num + i);
|
LOG_INFO("mflash: wrote %" PRIu32 "'th sectors", sect_num + i);
|
||||||
duration_start_measure(&duration);
|
duration_start(&bench);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -708,8 +707,6 @@ static int mg_write_cmd(struct command_context_s *cmd_ctx, char *cmd, char **arg
|
||||||
uint32_t address, buf_cnt, cnt, res, i;
|
uint32_t address, buf_cnt, cnt, res, i;
|
||||||
uint8_t *buffer;
|
uint8_t *buffer;
|
||||||
fileio_t fileio;
|
fileio_t fileio;
|
||||||
duration_t duration;
|
|
||||||
char *duration_text;
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (argc != 3) {
|
if (argc != 3) {
|
||||||
|
@ -731,7 +728,8 @@ static int mg_write_cmd(struct command_context_s *cmd_ctx, char *cmd, char **arg
|
||||||
cnt = fileio.size / MG_FILEIO_CHUNK;
|
cnt = fileio.size / MG_FILEIO_CHUNK;
|
||||||
res = fileio.size % MG_FILEIO_CHUNK;
|
res = fileio.size % MG_FILEIO_CHUNK;
|
||||||
|
|
||||||
duration_start_measure(&duration);
|
struct duration bench;
|
||||||
|
duration_start(&bench);
|
||||||
|
|
||||||
for (i = 0; i < cnt; i++) {
|
for (i = 0; i < cnt; i++) {
|
||||||
if ((ret = fileio_read(&fileio, MG_FILEIO_CHUNK, buffer, &buf_cnt)) !=
|
if ((ret = fileio_read(&fileio, MG_FILEIO_CHUNK, buffer, &buf_cnt)) !=
|
||||||
|
@ -749,21 +747,19 @@ static int mg_write_cmd(struct command_context_s *cmd_ctx, char *cmd, char **arg
|
||||||
goto mg_write_cmd_err;
|
goto mg_write_cmd_err;
|
||||||
}
|
}
|
||||||
|
|
||||||
duration_stop_measure(&duration, &duration_text);
|
if (duration_measure(&bench) == ERROR_OK)
|
||||||
|
{
|
||||||
|
command_print(cmd_ctx, "wrote %lli byte from file %s "
|
||||||
|
"in %fs (%0.3f kB/s)", fileio.size, args[1],
|
||||||
|
duration_elapsed(&bench), duration_kbps(&bench, fileio.size));
|
||||||
|
}
|
||||||
|
|
||||||
command_print(cmd_ctx, "wrote %lli byte from file %s in %s (%f kB/s)",
|
|
||||||
fileio.size, args[1], duration_text,
|
|
||||||
(float)fileio.size / 1024.0 / ((float)duration.duration.tv_sec + ((float)duration.duration.tv_usec / 1000000.0)));
|
|
||||||
|
|
||||||
free(duration_text);
|
|
||||||
free(buffer);
|
free(buffer);
|
||||||
fileio_close(&fileio);
|
fileio_close(&fileio);
|
||||||
|
|
||||||
return ERROR_OK;
|
return ERROR_OK;
|
||||||
|
|
||||||
mg_write_cmd_err:
|
mg_write_cmd_err:
|
||||||
duration_stop_measure(&duration, &duration_text);
|
|
||||||
free(duration_text);
|
|
||||||
free(buffer);
|
free(buffer);
|
||||||
fileio_close(&fileio);
|
fileio_close(&fileio);
|
||||||
|
|
||||||
|
@ -775,8 +771,6 @@ static int mg_dump_cmd(struct command_context_s *cmd_ctx, char *cmd, char **args
|
||||||
uint32_t address, size_written, size, cnt, res, i;
|
uint32_t address, size_written, size, cnt, res, i;
|
||||||
uint8_t *buffer;
|
uint8_t *buffer;
|
||||||
fileio_t fileio;
|
fileio_t fileio;
|
||||||
duration_t duration;
|
|
||||||
char *duration_text;
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (argc != 4) {
|
if (argc != 4) {
|
||||||
|
@ -799,7 +793,8 @@ static int mg_dump_cmd(struct command_context_s *cmd_ctx, char *cmd, char **args
|
||||||
cnt = size / MG_FILEIO_CHUNK;
|
cnt = size / MG_FILEIO_CHUNK;
|
||||||
res = size % MG_FILEIO_CHUNK;
|
res = size % MG_FILEIO_CHUNK;
|
||||||
|
|
||||||
duration_start_measure(&duration);
|
struct duration bench;
|
||||||
|
duration_start(&bench);
|
||||||
|
|
||||||
for (i = 0; i < cnt; i++) {
|
for (i = 0; i < cnt; i++) {
|
||||||
if ((ret = mg_mflash_read(address, buffer, MG_FILEIO_CHUNK)) != ERROR_OK)
|
if ((ret = mg_mflash_read(address, buffer, MG_FILEIO_CHUNK)) != ERROR_OK)
|
||||||
|
@ -817,21 +812,20 @@ static int mg_dump_cmd(struct command_context_s *cmd_ctx, char *cmd, char **args
|
||||||
goto mg_dump_cmd_err;
|
goto mg_dump_cmd_err;
|
||||||
}
|
}
|
||||||
|
|
||||||
duration_stop_measure(&duration, &duration_text);
|
if (duration_measure(&bench) == ERROR_OK)
|
||||||
|
{
|
||||||
|
command_print(cmd_ctx, "dump image (address 0x%8.8" PRIx32 " "
|
||||||
|
"size %" PRIu32 ") to file %s in %fs (%0.3f kB/s)",
|
||||||
|
address, size, args[1],
|
||||||
|
duration_elapsed(&bench), duration_kbps(&bench, size));
|
||||||
|
}
|
||||||
|
|
||||||
command_print(cmd_ctx, "dump image (address 0x%8.8" PRIx32 " size %" PRIu32 ") to file %s in %s (%f kB/s)",
|
|
||||||
address, size, args[1], duration_text,
|
|
||||||
(float)size / 1024.0 / ((float)duration.duration.tv_sec + ((float)duration.duration.tv_usec / 1000000.0)));
|
|
||||||
|
|
||||||
free(duration_text);
|
|
||||||
free(buffer);
|
free(buffer);
|
||||||
fileio_close(&fileio);
|
fileio_close(&fileio);
|
||||||
|
|
||||||
return ERROR_OK;
|
return ERROR_OK;
|
||||||
|
|
||||||
mg_dump_cmd_err:
|
mg_dump_cmd_err:
|
||||||
duration_stop_measure(&duration, &duration_text);
|
|
||||||
free(duration_text);
|
|
||||||
free(buffer);
|
free(buffer);
|
||||||
fileio_close(&fileio);
|
fileio_close(&fileio);
|
||||||
|
|
||||||
|
|
|
@ -1330,8 +1330,6 @@ static int handle_nand_write_command(struct command_context_s *cmd_ctx, char *cm
|
||||||
|
|
||||||
fileio_t fileio;
|
fileio_t fileio;
|
||||||
|
|
||||||
duration_t duration;
|
|
||||||
char *duration_text;
|
|
||||||
|
|
||||||
if (argc < 3)
|
if (argc < 3)
|
||||||
{
|
{
|
||||||
|
@ -1372,7 +1370,8 @@ static int handle_nand_write_command(struct command_context_s *cmd_ctx, char *cm
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
duration_start_measure(&duration);
|
struct duration bench;
|
||||||
|
duration_start(&bench);
|
||||||
|
|
||||||
if (fileio_open(&fileio, args[1], FILEIO_READ, FILEIO_BINARY) != ERROR_OK)
|
if (fileio_open(&fileio, args[1], FILEIO_READ, FILEIO_BINARY) != ERROR_OK)
|
||||||
{
|
{
|
||||||
|
@ -1478,11 +1477,13 @@ static int handle_nand_write_command(struct command_context_s *cmd_ctx, char *cm
|
||||||
free(page);
|
free(page);
|
||||||
oob = NULL;
|
oob = NULL;
|
||||||
page = NULL;
|
page = NULL;
|
||||||
duration_stop_measure(&duration, &duration_text);
|
if (duration_measure(&bench) == ERROR_OK)
|
||||||
command_print(cmd_ctx, "wrote file %s to NAND flash %s up to offset 0x%8.8" PRIx32 " in %s",
|
{
|
||||||
args[1], args[0], offset, duration_text);
|
command_print(cmd_ctx, "wrote file %s to NAND flash %s "
|
||||||
free(duration_text);
|
"up to offset 0x%8.8" PRIx32 " in %fs (%0.3f kb/s)",
|
||||||
duration_text = NULL;
|
args[1], args[0], offset, duration_elapsed(&bench),
|
||||||
|
duration_kbps(&bench, fileio.size));
|
||||||
|
}
|
||||||
|
|
||||||
return ERROR_OK;
|
return ERROR_OK;
|
||||||
}
|
}
|
||||||
|
@ -1506,8 +1507,6 @@ static int handle_nand_dump_command(struct command_context_s *cmd_ctx, char *cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
fileio_t fileio;
|
fileio_t fileio;
|
||||||
duration_t duration;
|
|
||||||
char *duration_text;
|
|
||||||
|
|
||||||
uint8_t *page = NULL;
|
uint8_t *page = NULL;
|
||||||
uint32_t page_size = 0;
|
uint32_t page_size = 0;
|
||||||
|
@ -1560,7 +1559,8 @@ static int handle_nand_dump_command(struct command_context_s *cmd_ctx, char *cmd
|
||||||
return ERROR_OK;
|
return ERROR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
duration_start_measure(&duration);
|
struct duration bench;
|
||||||
|
duration_start(&bench);
|
||||||
|
|
||||||
while (size > 0)
|
while (size > 0)
|
||||||
{
|
{
|
||||||
|
@ -1596,10 +1596,12 @@ static int handle_nand_dump_command(struct command_context_s *cmd_ctx, char *cmd
|
||||||
oob = NULL;
|
oob = NULL;
|
||||||
fileio_close(&fileio);
|
fileio_close(&fileio);
|
||||||
|
|
||||||
duration_stop_measure(&duration, &duration_text);
|
if (duration_measure(&bench) == ERROR_OK)
|
||||||
command_print(cmd_ctx, "dumped %lld byte in %s", fileio.size, duration_text);
|
{
|
||||||
free(duration_text);
|
command_print(cmd_ctx, "dumped %lld byte in %fs (%0.3f kb/s)",
|
||||||
duration_text = NULL;
|
fileio.size, duration_elapsed(&bench),
|
||||||
|
duration_kbps(&bench, fileio.size));
|
||||||
|
}
|
||||||
|
|
||||||
return ERROR_OK;
|
return ERROR_OK;
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,6 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "time_support.h"
|
#include "time_support.h"
|
||||||
#include "log.h"
|
|
||||||
|
|
||||||
|
|
||||||
/* calculate difference between two struct timeval values */
|
/* calculate difference between two struct timeval values */
|
||||||
|
@ -83,29 +82,30 @@ int timeval_add_time(struct timeval *result, int sec, int usec)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void duration_start_measure(duration_t *duration)
|
int duration_start(struct duration *duration)
|
||||||
{
|
{
|
||||||
gettimeofday(&duration->start, NULL);
|
return gettimeofday(&duration->start, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
int duration_stop_measure(duration_t *duration, char **text)
|
int duration_measure(struct duration *duration)
|
||||||
{
|
{
|
||||||
struct timeval end;
|
struct timeval end;
|
||||||
|
int retval = gettimeofday(&end, NULL);
|
||||||
|
if (0 == retval)
|
||||||
|
timeval_subtract(&duration->elapsed, &end, &duration->start);
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
gettimeofday(&end, NULL);
|
float duration_elapsed(struct duration *duration)
|
||||||
|
{
|
||||||
|
float t = duration->elapsed.tv_sec;
|
||||||
|
t += (float)duration->elapsed.tv_usec / 1000000.0;
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
timeval_subtract(&duration->duration, &end, &duration->start);
|
float duration_kbps(struct duration *duration, size_t count)
|
||||||
|
{
|
||||||
if (text)
|
return count / (1024.0 * duration_elapsed(duration));
|
||||||
{
|
|
||||||
float t;
|
|
||||||
t = duration->duration.tv_sec;
|
|
||||||
t += (float)duration->duration.tv_usec/1000000.0;
|
|
||||||
*text = malloc(100);
|
|
||||||
snprintf(*text, 100, "%fs", t);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ERROR_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
long long timeval_ms()
|
long long timeval_ms()
|
||||||
|
|
|
@ -37,19 +37,27 @@
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern int timeval_subtract(struct timeval *result, struct timeval *x, struct timeval *y);
|
int timeval_subtract(struct timeval *result, struct timeval *x, struct timeval *y);
|
||||||
extern int timeval_add(struct timeval *result, struct timeval *x, struct timeval *y);
|
int timeval_add(struct timeval *result, struct timeval *x, struct timeval *y);
|
||||||
extern int timeval_add_time(struct timeval *result, int sec, int usec);
|
int timeval_add_time(struct timeval *result, int sec, int usec);
|
||||||
/* gettimeofday() timeval in 64 bit ms */
|
|
||||||
extern long long timeval_ms(void);
|
|
||||||
|
|
||||||
typedef struct duration_s
|
/// @returns gettimeofday() timeval as 64-bit in ms
|
||||||
|
long long timeval_ms(void);
|
||||||
|
|
||||||
|
struct duration
|
||||||
{
|
{
|
||||||
struct timeval start;
|
struct timeval start;
|
||||||
struct timeval duration;
|
struct timeval elapsed;
|
||||||
} duration_t;
|
};
|
||||||
|
|
||||||
extern void duration_start_measure(duration_t *duration);
|
/// Update the duration->start field to start the @a duration measurement.
|
||||||
extern int duration_stop_measure(duration_t *duration, char **text);
|
int duration_start(struct duration *duration);
|
||||||
|
/// Update the duration->elapsed field to finish the @a duration measurment.
|
||||||
|
int duration_measure(struct duration *duration);
|
||||||
|
|
||||||
|
/// @returns Elapsed time in seconds.
|
||||||
|
float duration_elapsed(struct duration *duration);
|
||||||
|
/// @returns KB/sec for the elapsed @a duration and @a count bytes.
|
||||||
|
float duration_kbps(struct duration *duration, size_t count);
|
||||||
|
|
||||||
#endif /* TIME_SUPPORT_H */
|
#endif /* TIME_SUPPORT_H */
|
||||||
|
|
|
@ -2507,20 +2507,17 @@ static int handle_load_image_command(struct command_context_s *cmd_ctx, char *cm
|
||||||
uint32_t min_address = 0;
|
uint32_t min_address = 0;
|
||||||
uint32_t max_address = 0xffffffff;
|
uint32_t max_address = 0xffffffff;
|
||||||
int i;
|
int i;
|
||||||
int retvaltemp;
|
|
||||||
|
|
||||||
image_t image;
|
image_t image;
|
||||||
|
|
||||||
duration_t duration;
|
|
||||||
char *duration_text;
|
|
||||||
|
|
||||||
int retval = parse_load_image_command_args(cmd_ctx, args, argc,
|
int retval = parse_load_image_command_args(cmd_ctx, args, argc,
|
||||||
&image, &min_address, &max_address);
|
&image, &min_address, &max_address);
|
||||||
if (ERROR_OK != retval)
|
if (ERROR_OK != retval)
|
||||||
return retval;
|
return retval;
|
||||||
|
|
||||||
target_t *target = get_current_target(cmd_ctx);
|
target_t *target = get_current_target(cmd_ctx);
|
||||||
duration_start_measure(&duration);
|
|
||||||
|
struct duration bench;
|
||||||
|
duration_start(&bench);
|
||||||
|
|
||||||
if (image_open(&image, args[0], (argc >= 3) ? args[2] : NULL) != ERROR_OK)
|
if (image_open(&image, args[0], (argc >= 3) ? args[2] : NULL) != ERROR_OK)
|
||||||
{
|
{
|
||||||
|
@ -2580,20 +2577,13 @@ static int handle_load_image_command(struct command_context_s *cmd_ctx, char *cm
|
||||||
free(buffer);
|
free(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((retvaltemp = duration_stop_measure(&duration, &duration_text)) != ERROR_OK)
|
if ((ERROR_OK == retval) && (duration_measure(&bench) == ERROR_OK))
|
||||||
{
|
{
|
||||||
image_close(&image);
|
command_print(cmd_ctx, "downloaded %" PRIu32 " bytes "
|
||||||
return retvaltemp;
|
"in %fs (%0.3f kb/s)", image_size,
|
||||||
|
duration_elapsed(&bench), duration_kbps(&bench, image_size));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (retval == ERROR_OK)
|
|
||||||
{
|
|
||||||
command_print(cmd_ctx, "downloaded %u byte in %s",
|
|
||||||
(unsigned int)image_size,
|
|
||||||
duration_text);
|
|
||||||
}
|
|
||||||
free(duration_text);
|
|
||||||
|
|
||||||
image_close(&image);
|
image_close(&image);
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
|
@ -2607,8 +2597,6 @@ static int handle_dump_image_command(struct command_context_s *cmd_ctx, char *cm
|
||||||
uint8_t buffer[560];
|
uint8_t buffer[560];
|
||||||
int retvaltemp;
|
int retvaltemp;
|
||||||
|
|
||||||
duration_t duration;
|
|
||||||
char *duration_text;
|
|
||||||
|
|
||||||
target_t *target = get_current_target(cmd_ctx);
|
target_t *target = get_current_target(cmd_ctx);
|
||||||
|
|
||||||
|
@ -2628,7 +2616,8 @@ static int handle_dump_image_command(struct command_context_s *cmd_ctx, char *cm
|
||||||
return ERROR_OK;
|
return ERROR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
duration_start_measure(&duration);
|
struct duration bench;
|
||||||
|
duration_start(&bench);
|
||||||
|
|
||||||
int retval = ERROR_OK;
|
int retval = ERROR_OK;
|
||||||
while (size > 0)
|
while (size > 0)
|
||||||
|
@ -2654,14 +2643,11 @@ static int handle_dump_image_command(struct command_context_s *cmd_ctx, char *cm
|
||||||
if ((retvaltemp = fileio_close(&fileio)) != ERROR_OK)
|
if ((retvaltemp = fileio_close(&fileio)) != ERROR_OK)
|
||||||
return retvaltemp;
|
return retvaltemp;
|
||||||
|
|
||||||
if ((retvaltemp = duration_stop_measure(&duration, &duration_text)) != ERROR_OK)
|
if ((ERROR_OK == retval) && (duration_measure(&bench) == ERROR_OK))
|
||||||
return retvaltemp;
|
|
||||||
|
|
||||||
if (retval == ERROR_OK)
|
|
||||||
{
|
{
|
||||||
command_print(cmd_ctx, "dumped %lld byte in %s",
|
command_print(cmd_ctx,
|
||||||
fileio.size, duration_text);
|
"dumped %lld bytes in %fs (%0.3f kb/s)", fileio.size,
|
||||||
free(duration_text);
|
duration_elapsed(&bench), duration_kbps(&bench, fileio.size));
|
||||||
}
|
}
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
|
@ -2673,15 +2659,12 @@ static int handle_verify_image_command_internal(struct command_context_s *cmd_ct
|
||||||
uint32_t buf_cnt;
|
uint32_t buf_cnt;
|
||||||
uint32_t image_size;
|
uint32_t image_size;
|
||||||
int i;
|
int i;
|
||||||
int retval, retvaltemp;
|
int retval;
|
||||||
uint32_t checksum = 0;
|
uint32_t checksum = 0;
|
||||||
uint32_t mem_checksum = 0;
|
uint32_t mem_checksum = 0;
|
||||||
|
|
||||||
image_t image;
|
image_t image;
|
||||||
|
|
||||||
duration_t duration;
|
|
||||||
char *duration_text;
|
|
||||||
|
|
||||||
target_t *target = get_current_target(cmd_ctx);
|
target_t *target = get_current_target(cmd_ctx);
|
||||||
|
|
||||||
if (argc < 1)
|
if (argc < 1)
|
||||||
|
@ -2695,7 +2678,8 @@ static int handle_verify_image_command_internal(struct command_context_s *cmd_ct
|
||||||
return ERROR_FAIL;
|
return ERROR_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
duration_start_measure(&duration);
|
struct duration bench;
|
||||||
|
duration_start(&bench);
|
||||||
|
|
||||||
if (argc >= 2)
|
if (argc >= 2)
|
||||||
{
|
{
|
||||||
|
@ -2802,21 +2786,13 @@ static int handle_verify_image_command_internal(struct command_context_s *cmd_ct
|
||||||
image_size += buf_cnt;
|
image_size += buf_cnt;
|
||||||
}
|
}
|
||||||
done:
|
done:
|
||||||
|
if ((ERROR_OK == retval) && (duration_measure(&bench) == ERROR_OK))
|
||||||
if ((retvaltemp = duration_stop_measure(&duration, &duration_text)) != ERROR_OK)
|
|
||||||
{
|
{
|
||||||
image_close(&image);
|
command_print(cmd_ctx, "verified %" PRIu32 " bytes "
|
||||||
return retvaltemp;
|
"in %fs (%0.3f kb/s)", image_size,
|
||||||
|
duration_elapsed(&bench), duration_kbps(&bench, image_size));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (retval == ERROR_OK)
|
|
||||||
{
|
|
||||||
command_print(cmd_ctx, "verified %u bytes in %s",
|
|
||||||
(unsigned int)image_size,
|
|
||||||
duration_text);
|
|
||||||
}
|
|
||||||
free(duration_text);
|
|
||||||
|
|
||||||
image_close(&image);
|
image_close(&image);
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
|
@ -4672,15 +4648,13 @@ static int handle_fast_load_image_command(struct command_context_s *cmd_ctx, cha
|
||||||
|
|
||||||
image_t image;
|
image_t image;
|
||||||
|
|
||||||
duration_t duration;
|
|
||||||
char *duration_text;
|
|
||||||
|
|
||||||
int retval = parse_load_image_command_args(cmd_ctx, args, argc,
|
int retval = parse_load_image_command_args(cmd_ctx, args, argc,
|
||||||
&image, &min_address, &max_address);
|
&image, &min_address, &max_address);
|
||||||
if (ERROR_OK != retval)
|
if (ERROR_OK != retval)
|
||||||
return retval;
|
return retval;
|
||||||
|
|
||||||
duration_start_measure(&duration);
|
struct duration bench;
|
||||||
|
duration_start(&bench);
|
||||||
|
|
||||||
if (image_open(&image, args[0], (argc >= 3) ? args[2] : NULL) != ERROR_OK)
|
if (image_open(&image, args[0], (argc >= 3) ? args[2] : NULL) != ERROR_OK)
|
||||||
{
|
{
|
||||||
|
@ -4753,13 +4727,16 @@ static int handle_fast_load_image_command(struct command_context_s *cmd_ctx, cha
|
||||||
free(buffer);
|
free(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
duration_stop_measure(&duration, &duration_text);
|
if ((ERROR_OK == retval) && (duration_measure(&bench) == ERROR_OK))
|
||||||
if (retval == ERROR_OK)
|
|
||||||
{
|
{
|
||||||
command_print(cmd_ctx, "Loaded %u bytes in %s", (unsigned int)image_size, duration_text);
|
command_print(cmd_ctx, "Loaded %" PRIu32 " bytes "
|
||||||
command_print(cmd_ctx, "NB!!! image has not been loaded to target, issue a subsequent 'fast_load' to do so.");
|
"in %fs (%0.3f kb/s)", image_size,
|
||||||
|
duration_elapsed(&bench), duration_kbps(&bench, image_size));
|
||||||
|
|
||||||
|
command_print(cmd_ctx,
|
||||||
|
"WARNING: image has not been loaded to target!"
|
||||||
|
"You can issue a 'fast_load' to finish loading.");
|
||||||
}
|
}
|
||||||
free(duration_text);
|
|
||||||
|
|
||||||
image_close(&image);
|
image_close(&image);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue