Commit 64dd3140 authored by Alessandro Rubini's avatar Alessandro Rubini

wrc_main and cmd_ps: profile time and report it

Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent 9983a058
......@@ -18,7 +18,9 @@ struct wrc_task {
void (*init)(void);
int (*job)(void);
/* And we keep statistics about cpu usage */
unsigned long nrun;
unsigned long nrun;
unsigned long seconds;
unsigned long nanos;
};
......
......@@ -15,20 +15,21 @@ extern int wrc_n_tasks;
static int cmd_ps(const char *args[])
{
int i, ena;
int i;
struct wrc_task *t;
if (args[0] && !strcasecmp(args[0], "reset")) {
for (i = 0; i < wrc_n_tasks; i++) {
wrc_tasks[i].nrun = 0;
t = wrc_tasks + i;
t->nrun = t->seconds = t->nanos = 0;
}
return 0;
}
pp_printf("iterations ena name\n");
pp_printf(" iterations seconds.micros name\n");
for (i = 0; i < wrc_n_tasks; i++) {
ena = 1;
if (wrc_tasks[i].enable) ena = (*wrc_tasks[i].enable != 0);
pp_printf(" %8i %i %s\n",
wrc_tasks[i].nrun, ena, wrc_tasks[i].name);
t = wrc_tasks + i;
pp_printf(" %9li %9li.%06li %s\n", t->nrun,
t->seconds, t->nanos/1000, t->name);
}
return 0;
}
......
......@@ -44,6 +44,8 @@ int32_t sfp_deltaTx = 0;
int32_t sfp_deltaRx = 0;
uint32_t cal_phase_transition = 2389;
static uint32_t prev_nanos_for_profile;
static void wrc_initialize(void)
{
uint8_t mac_addr[6];
......@@ -97,6 +99,7 @@ static void wrc_initialize(void)
wrc_ptp_set_mode(WRC_MODE_SLAVE);
wrc_ptp_start();
shw_pps_gen_get_time(NULL, &prev_nanos_for_profile);
}
int link_status;
......@@ -224,13 +227,40 @@ struct wrc_task wrc_tasks[] = {
int wrc_n_tasks = ARRAY_SIZE(wrc_tasks);
/* Account the time to either this task or task 0 */
static void account_task(struct wrc_task *t, int done_sth)
{
uint32_t nanos;
signed int delta;
if (!done_sth)
t = wrc_tasks;
shw_pps_gen_get_time(NULL, &nanos);
delta = nanos - prev_nanos_for_profile;
if (delta < 0)
delta += 1000 * 1000 * 1000;
t->nanos += delta;
if (t-> nanos > 1000 * 1000 * 1000) {
t->nanos -= 1000 * 1000 * 1000;
t->seconds++;
}
prev_nanos_for_profile = nanos;
}
/* Run a task with profiling */
static void wrc_run_task(struct wrc_task *t)
{
if (t->enable && !*t->enable)
return;
if (t->job)
t->nrun += t->job();
else t->nrun++;
int done_sth = 0;
if (!t->job) /* idle task, just count iterations */
t->nrun++;
else if (!t->enable || *t->enable) {
/* either enabled or without a check variable */
done_sth = t->job();
t->nrun += done_sth;
}
account_task(t, done_sth);
}
int main(void)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment