[mpp_time]: Change old timer to clock

The MppClock is used to record and sum the time only.
The MppTimer will have new implement.

Signed-off-by: Herman Chen <herman.chen@rock-chips.com>
Change-Id: I6cace6968d50db611e7493b69b14b46853070d78
This commit is contained in:
Herman Chen 2020-04-03 11:18:58 +08:00
parent ead0f9c96f
commit b83158b23b
5 changed files with 113 additions and 113 deletions

View File

@ -94,7 +94,7 @@ typedef struct MppDecImpl_t {
// statistics data
RK_U32 statistics_en;
MppTimer timers[DEC_TIMING_BUTT];
MppClock clocks[DEC_TIMING_BUTT];
} MppDecImpl;
#ifdef __cplusplus

View File

@ -563,9 +563,9 @@ static MPP_RET try_proc_dec_task(Mpp *mpp, DecTask *task)
mpp_log("input packet pts %lld\n",
mpp_packet_get_pts(dec->mpp_pkt_in));
mpp_timer_start(dec->timers[DEC_PRS_PREPARE]);
mpp_clock_start(dec->clocks[DEC_PRS_PREPARE]);
mpp_parser_prepare(dec->parser, dec->mpp_pkt_in, task_dec);
mpp_timer_pause(dec->timers[DEC_PRS_PREPARE]);
mpp_clock_pause(dec->clocks[DEC_PRS_PREPARE]);
if (0 == mpp_packet_get_length(dec->mpp_pkt_in)) {
mpp_packet_deinit(&dec->mpp_pkt_in);
@ -692,9 +692,9 @@ static MPP_RET try_proc_dec_task(Mpp *mpp, DecTask *task)
* 4. detect whether output index has MppBuffer and task valid
*/
if (!task->status.task_parsed_rdy) {
mpp_timer_start(dec->timers[DEC_PRS_PARSE]);
mpp_clock_start(dec->clocks[DEC_PRS_PARSE]);
mpp_parser_parse(dec->parser, task_dec);
mpp_timer_pause(dec->timers[DEC_PRS_PARSE]);
mpp_clock_pause(dec->clocks[DEC_PRS_PARSE]);
task->status.task_parsed_rdy = 1;
}
@ -800,14 +800,14 @@ static MPP_RET try_proc_dec_task(Mpp *mpp, DecTask *task)
return MPP_NOK;
/* generating registers table */
mpp_timer_start(dec->timers[DEC_HAL_GEN_REG]);
mpp_clock_start(dec->clocks[DEC_HAL_GEN_REG]);
mpp_hal_reg_gen(dec->hal, &task->info);
mpp_timer_pause(dec->timers[DEC_HAL_GEN_REG]);
mpp_clock_pause(dec->clocks[DEC_HAL_GEN_REG]);
/* send current register set to hardware */
mpp_timer_start(dec->timers[DEC_HW_START]);
mpp_clock_start(dec->clocks[DEC_HW_START]);
mpp_hal_hw_start(dec->hal, &task->info);
mpp_timer_pause(dec->timers[DEC_HW_START]);
mpp_clock_pause(dec->clocks[DEC_HW_START]);
/*
* 12. send dxva output information and buffer information to hal thread
@ -841,7 +841,7 @@ void *mpp_dec_parser_thread(void *data)
dec_task_init(&task);
mpp_timer_start(dec->timers[DEC_PRS_TOTAL]);
mpp_clock_start(dec->clocks[DEC_PRS_TOTAL]);
while (1) {
{
@ -857,9 +857,9 @@ void *mpp_dec_parser_thread(void *data)
* 3. no buffer on analyzing output task
*/
if (check_task_wait(dec, &task)) {
mpp_timer_start(dec->timers[DEC_PRS_WAIT]);
mpp_clock_start(dec->clocks[DEC_PRS_WAIT]);
parser->wait();
mpp_timer_pause(dec->timers[DEC_PRS_WAIT]);
mpp_clock_pause(dec->clocks[DEC_PRS_WAIT]);
}
}
@ -874,12 +874,12 @@ void *mpp_dec_parser_thread(void *data)
// NOTE: ignore return value here is to fast response to reset.
// Otherwise we can loop all dec task until it is failed.
mpp_timer_start(dec->timers[DEC_PRS_PROC]);
mpp_clock_start(dec->clocks[DEC_PRS_PROC]);
try_proc_dec_task(mpp, &task);
mpp_timer_pause(dec->timers[DEC_PRS_PROC]);
mpp_clock_pause(dec->clocks[DEC_PRS_PROC]);
}
mpp_timer_pause(dec->timers[DEC_PRS_TOTAL]);
mpp_clock_pause(dec->clocks[DEC_PRS_TOTAL]);
mpp_dbg(MPP_DBG_INFO, "mpp_dec_parser_thread is going to exit\n");
if (task.hnd && task_dec->valid) {
@ -905,7 +905,7 @@ void *mpp_dec_hal_thread(void *data)
HalTaskInfo task_info;
HalDecTask *task_dec = &task_info.dec;
mpp_timer_start(dec->timers[DEC_HAL_TOTAL]);
mpp_clock_start(dec->clocks[DEC_HAL_TOTAL]);
while (1) {
/* hal thread wait for dxva interface intput first */
@ -926,9 +926,9 @@ void *mpp_dec_hal_thread(void *data)
}
mpp_dec_notify(dec, MPP_DEC_NOTIFY_TASK_ALL_DONE);
mpp_timer_start(dec->timers[DEC_HAL_WAIT]);
mpp_clock_start(dec->clocks[DEC_HAL_WAIT]);
hal->wait();
mpp_timer_pause(dec->timers[DEC_HAL_WAIT]);
mpp_clock_pause(dec->clocks[DEC_HAL_WAIT]);
continue;
}
}
@ -936,7 +936,7 @@ void *mpp_dec_hal_thread(void *data)
if (task) {
RK_U32 notify_flag = MPP_DEC_NOTIFY_TASK_HND_VALID;
mpp_timer_start(dec->timers[DEC_HAL_PROC]);
mpp_clock_start(dec->clocks[DEC_HAL_PROC]);
mpp->mTaskGetCount++;
hal_task_hnd_get_info(task, &task_info);
@ -954,7 +954,7 @@ void *mpp_dec_hal_thread(void *data)
hal_task_hnd_set_status(task, TASK_IDLE);
task = NULL;
mpp_dec_notify(dec, notify_flag);
mpp_timer_pause(dec->timers[DEC_HAL_PROC]);
mpp_clock_pause(dec->clocks[DEC_HAL_PROC]);
continue;
}
/*
@ -977,13 +977,13 @@ void *mpp_dec_hal_thread(void *data)
hal_task_hnd_set_status(task, TASK_IDLE);
task = NULL;
mpp_dec_notify(dec, notify_flag);
mpp_timer_pause(dec->timers[DEC_HAL_PROC]);
mpp_clock_pause(dec->clocks[DEC_HAL_PROC]);
continue;
}
mpp_timer_start(dec->timers[DEC_HW_WAIT]);
mpp_clock_start(dec->clocks[DEC_HW_WAIT]);
mpp_hal_hw_wait(dec->hal, &task_info);
mpp_timer_pause(dec->timers[DEC_HW_WAIT]);
mpp_clock_pause(dec->clocks[DEC_HW_WAIT]);
/*
* when hardware decoding is done:
@ -1018,11 +1018,11 @@ void *mpp_dec_hal_thread(void *data)
mpp_dec_push_display(mpp, task_dec->flags);
mpp_dec_notify(dec, notify_flag);
mpp_timer_pause(dec->timers[DEC_HAL_PROC]);
mpp_clock_pause(dec->clocks[DEC_HAL_PROC]);
}
}
mpp_timer_pause(dec->timers[DEC_HAL_TOTAL]);
mpp_clock_pause(dec->clocks[DEC_HAL_TOTAL]);
mpp_assert(mpp->mTaskPutCount == mpp->mTaskGetCount);
mpp_dbg(MPP_DBG_INFO, "mpp_dec_hal_thread exited\n");
@ -1348,9 +1348,9 @@ MPP_RET mpp_dec_init(MppDec *dec, MppDecCfg *cfg)
p->statistics_en = (mpp_dec_debug & MPP_DEC_DBG_TIMING) ? 1 : 0;
for (i = 0; i < DEC_TIMING_BUTT; i++) {
p->timers[i] = mpp_timer_get(timing_str[i]);
mpp_assert(p->timers[i]);
mpp_timer_enable(p->timers[i], p->statistics_en);
p->clocks[i] = mpp_clock_get(timing_str[i]);
mpp_assert(p->clocks[i]);
mpp_clock_enable(p->clocks[i], p->statistics_en);
}
sem_init(&p->parser_reset, 0, 0);
@ -1381,23 +1381,23 @@ MPP_RET mpp_dec_deinit(MppDec ctx)
dec->parser_work_count, dec->parser_wait_count);
for (i = 0; i < DEC_TIMING_BUTT; i++) {
MppTimer timer = dec->timers[i];
MppClock timer = dec->clocks[i];
RK_S32 base = (i < DEC_HAL_TOTAL) ? (DEC_PRS_TOTAL) : (DEC_HAL_TOTAL);
RK_S64 time = mpp_timer_get_sum(timer);
RK_S64 total = mpp_timer_get_sum(dec->timers[base]);
RK_S64 time = mpp_clock_get_sum(timer);
RK_S64 total = mpp_clock_get_sum(dec->clocks[base]);
if (!time || !total)
continue;
mpp_log("%p %s - %6.2f %-12lld avg %-12lld\n", dec,
mpp_timer_get_name(timer), time * 100.0 / total, time,
time / mpp_timer_get_count(timer));
mpp_clock_get_name(timer), time * 100.0 / total, time,
time / mpp_clock_get_count(timer));
}
}
for (i = 0; i < DEC_TIMING_BUTT; i++) {
mpp_timer_put(dec->timers[i]);
dec->timers[i] = NULL;
mpp_clock_put(dec->clocks[i]);
dec->clocks[i] = NULL;
}
if (dec->parser) {

View File

@ -30,7 +30,7 @@
#define msleep(x) usleep((x)*1000)
#endif
typedef void* MppTimer;
typedef void* MppClock;
#ifdef __cplusplus
extern "C" {
@ -40,34 +40,34 @@ RK_S64 mpp_time();
void mpp_time_diff(RK_S64 start, RK_S64 end, RK_S64 limit, const char *fmt);
/*
* Timer create / destroy / enable / disable function
* Note when timer is create it is default disabled user need to call enable
* fucntion with enable = 1 to enable the timer.
* User can use enable function with enable = 0 to disable the timer.
* Clock create / destroy / enable / disable function
* Note when clock is create it is default disabled user need to call enable
* fucntion with enable = 1 to enable the clock.
* User can use enable function with enable = 0 to disable the clock.
*/
MppTimer mpp_timer_get(const char *name);
void mpp_timer_put(MppTimer timer);
void mpp_timer_enable(MppTimer timer, RK_U32 enable);
MppClock mpp_clock_get(const char *name);
void mpp_clock_put(MppClock clock);
void mpp_clock_enable(MppClock clock, RK_U32 enable);
/*
* Timer basic operation function:
* start : let timer start timing counter
* pause : let timer pause and return the diff to start time
* reset : let timer counter to all zero
* Clock basic operation function:
* start : let clock start timing counter
* pause : let clock pause and return the diff to start time
* reset : let clock counter to all zero
*/
RK_S64 mpp_timer_start(MppTimer timer);
RK_S64 mpp_timer_pause(MppTimer timer);
RK_S64 mpp_timer_reset(MppTimer timer);
RK_S64 mpp_clock_start(MppClock clock);
RK_S64 mpp_clock_pause(MppClock clock);
RK_S64 mpp_clock_reset(MppClock clock);
/*
* These timer helper function can only be call when timer is paused:
* mpp_timer_get_sum - Return timer sum up total value
* mpp_timer_get_count - Return timer sum up counter value
* mpp_timer_get_name - Return timer name
* These clock helper function can only be call when clock is paused:
* mpp_clock_get_sum - Return clock sum up total value
* mpp_clock_get_count - Return clock sum up counter value
* mpp_clock_get_name - Return clock name
*/
RK_S64 mpp_timer_get_sum(MppTimer timer);
RK_S64 mpp_timer_get_count(MppTimer timer);
const char *mpp_timer_get_name(MppTimer timer);
RK_S64 mpp_clock_get_sum(MppClock clock);
RK_S64 mpp_clock_get_count(MppClock clock);
const char *mpp_clock_get_name(MppClock clock);
#ifdef __cplusplus
}

View File

@ -51,7 +51,7 @@ void mpp_time_diff(RK_S64 start, RK_S64 end, RK_S64 limit, const char *fmt)
mpp_dbg(MPP_DBG_TIMING, "%s timing %lld us\n", fmt, diff);
}
typedef struct MppTimerImpl_t {
typedef struct MppClockImpl_t {
const char *check;
char name[16];
RK_U32 enable;
@ -59,23 +59,23 @@ typedef struct MppTimerImpl_t {
RK_S64 time;
RK_S64 sum;
RK_S64 count;
} MppTimerImpl;
} MppClockImpl;
static const char *module_name = MODULE_TAG;
MPP_RET check_is_mpp_timer(void *timer)
MPP_RET check_is_mpp_clock(void *clock)
{
if (timer && ((MppTimerImpl*)timer)->check == module_name)
if (clock && ((MppClockImpl*)clock)->check == module_name)
return MPP_OK;
mpp_err_f("pointer %p failed on check\n", timer);
mpp_err_f("pointer %p failed on check\n", clock);
mpp_abort();
return MPP_NOK;
}
MppTimer mpp_timer_get(const char *name)
MppClock mpp_clock_get(const char *name)
{
MppTimerImpl *impl = mpp_calloc(MppTimerImpl, 1);
MppClockImpl *impl = mpp_calloc(MppClockImpl, 1);
if (impl) {
impl->check = module_name;
snprintf(impl->name, sizeof(impl->name), name, NULL);
@ -85,34 +85,34 @@ MppTimer mpp_timer_get(const char *name)
return impl;
}
void mpp_timer_put(MppTimer timer)
void mpp_clock_put(MppClock clock)
{
if (NULL == timer || check_is_mpp_timer(timer)) {
mpp_err_f("invalid timer %p\n", timer);
if (NULL == clock || check_is_mpp_clock(clock)) {
mpp_err_f("invalid clock %p\n", clock);
return ;
}
mpp_free(timer);
mpp_free(clock);
}
void mpp_timer_enable(MppTimer timer, RK_U32 enable)
void mpp_clock_enable(MppClock clock, RK_U32 enable)
{
if (NULL == timer || check_is_mpp_timer(timer)) {
mpp_err_f("invalid timer %p\n", timer);
if (NULL == clock || check_is_mpp_clock(clock)) {
mpp_err_f("invalid clock %p\n", clock);
} else {
MppTimerImpl *p = (MppTimerImpl *)timer;
MppClockImpl *p = (MppClockImpl *)clock;
p->enable = (enable) ? (1) : (0);
}
}
RK_S64 mpp_timer_start(MppTimer timer)
RK_S64 mpp_clock_start(MppClock clock)
{
if (NULL == timer || check_is_mpp_timer(timer)) {
mpp_err_f("invalid timer %p\n", timer);
if (NULL == clock || check_is_mpp_clock(clock)) {
mpp_err_f("invalid clock %p\n", clock);
return 0;
}
MppTimerImpl *p = (MppTimerImpl *)timer;
MppClockImpl *p = (MppClockImpl *)clock;
if (!p->enable)
return 0;
@ -122,14 +122,14 @@ RK_S64 mpp_timer_start(MppTimer timer)
return p->base;
}
RK_S64 mpp_timer_pause(MppTimer timer)
RK_S64 mpp_clock_pause(MppClock clock)
{
if (NULL == timer || check_is_mpp_timer(timer)) {
mpp_err_f("invalid timer %p\n", timer);
if (NULL == clock || check_is_mpp_clock(clock)) {
mpp_err_f("invalid clock %p\n", clock);
return 0;
}
MppTimerImpl *p = (MppTimerImpl *)timer;
MppClockImpl *p = (MppClockImpl *)clock;
if (!p->enable)
return 0;
@ -145,12 +145,12 @@ RK_S64 mpp_timer_pause(MppTimer timer)
return p->time - p->base;
}
RK_S64 mpp_timer_reset(MppTimer timer)
RK_S64 mpp_clock_reset(MppClock clock)
{
if (NULL == timer || check_is_mpp_timer(timer)) {
mpp_err_f("invalid timer %p\n", timer);
if (NULL == clock || check_is_mpp_clock(clock)) {
mpp_err_f("invalid clock %p\n", clock);
} else {
MppTimerImpl *p = (MppTimerImpl *)timer;
MppClockImpl *p = (MppClockImpl *)clock;
p->base = 0;
p->time = 0;
@ -161,35 +161,35 @@ RK_S64 mpp_timer_reset(MppTimer timer)
return 0;
}
RK_S64 mpp_timer_get_sum(MppTimer timer)
RK_S64 mpp_clock_get_sum(MppClock clock)
{
if (NULL == timer || check_is_mpp_timer(timer)) {
mpp_err_f("invalid timer %p\n", timer);
if (NULL == clock || check_is_mpp_clock(clock)) {
mpp_err_f("invalid clock %p\n", clock);
return 0;
}
MppTimerImpl *p = (MppTimerImpl *)timer;
MppClockImpl *p = (MppClockImpl *)clock;
return (p->enable) ? (p->sum) : (0);
}
RK_S64 mpp_timer_get_count(MppTimer timer)
RK_S64 mpp_clock_get_count(MppClock clock)
{
if (NULL == timer || check_is_mpp_timer(timer)) {
mpp_err_f("invalid timer %p\n", timer);
if (NULL == clock || check_is_mpp_clock(clock)) {
mpp_err_f("invalid clock %p\n", clock);
return 0;
}
MppTimerImpl *p = (MppTimerImpl *)timer;
MppClockImpl *p = (MppClockImpl *)clock;
return (p->enable) ? (p->count) : (0);
}
const char *mpp_timer_get_name(MppTimer timer)
const char *mpp_clock_get_name(MppClock clock)
{
if (NULL == timer || check_is_mpp_timer(timer)) {
mpp_err_f("invalid timer %p\n", timer);
if (NULL == clock || check_is_mpp_clock(clock)) {
mpp_err_f("invalid clock %p\n", clock);
return NULL;
}
MppTimerImpl *p = (MppTimerImpl *)timer;
MppClockImpl *p = (MppClockImpl *)clock;
return p->name;
}

View File

@ -23,7 +23,7 @@ int main()
{
RK_S64 time_0;
RK_S64 time_1;
MppTimer timer;
MppClock clock;
RK_S32 i;
mpp_log("mpp time test start\n");
@ -40,40 +40,40 @@ int main()
mpp_log("mpp time test done\n");
mpp_log("mpp timer test start\n");
mpp_log("mpp clock test start\n");
timer = mpp_timer_get("timer loop test");
clock = mpp_clock_get("clock loop test");
mpp_timer_enable(timer, 1);
mpp_clock_enable(clock, 1);
for (i = 0; i < 1000; i++) {
mpp_timer_start(timer);
mpp_clock_start(clock);
msleep(2);
mpp_timer_pause(timer);
mpp_clock_pause(clock);
}
mpp_log("loop 1000 times timer 2ms start/pause operation:\n");
mpp_log("total time %8.3f ms\n", mpp_timer_get_sum(timer) / 1000.0);
mpp_log("loop 1000 times clock 2ms start/pause operation:\n");
mpp_log("total time %8.3f ms\n", mpp_clock_get_sum(clock) / 1000.0);
mpp_log("average time %8.3f ms\n",
mpp_timer_get_sum(timer) / mpp_timer_get_count(timer) / 1000.0);
mpp_clock_get_sum(clock) / mpp_clock_get_count(clock) / 1000.0);
mpp_timer_reset(timer);
mpp_clock_reset(clock);
for (i = 0; i < 10000; i++) {
mpp_timer_start(timer);
mpp_clock_start(clock);
mpp_time();
mpp_timer_pause(timer);
mpp_clock_pause(clock);
}
mpp_log("mpp_time cost %.3f ms\n",
mpp_timer_get_sum(timer) / mpp_timer_get_count(timer) / 1000.0);
mpp_clock_get_sum(clock) / mpp_clock_get_count(clock) / 1000.0);
mpp_timer_reset(timer);
mpp_timer_start(timer);
mpp_clock_reset(clock);
mpp_clock_start(clock);
msleep(20);
time_0 = mpp_timer_pause(timer);
time_0 = mpp_clock_pause(clock);
msleep(20);
time_1 = mpp_timer_pause(timer);
time_1 = mpp_clock_pause(clock);
mpp_log("mpp_time pause 0 at %.3f ms pause 1 at %.3f ms\n",
time_0 / 1000.0, time_1 / 1000.0);