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 { ...@@ -18,7 +18,9 @@ struct wrc_task {
void (*init)(void); void (*init)(void);
int (*job)(void); int (*job)(void);
/* And we keep statistics about cpu usage */ /* 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; ...@@ -15,20 +15,21 @@ extern int wrc_n_tasks;
static int cmd_ps(const char *args[]) static int cmd_ps(const char *args[])
{ {
int i, ena; int i;
struct wrc_task *t;
if (args[0] && !strcasecmp(args[0], "reset")) { if (args[0] && !strcasecmp(args[0], "reset")) {
for (i = 0; i < wrc_n_tasks; i++) { 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; return 0;
} }
pp_printf("iterations ena name\n"); pp_printf(" iterations seconds.micros name\n");
for (i = 0; i < wrc_n_tasks; i++) { for (i = 0; i < wrc_n_tasks; i++) {
ena = 1; t = wrc_tasks + i;
if (wrc_tasks[i].enable) ena = (*wrc_tasks[i].enable != 0); pp_printf(" %9li %9li.%06li %s\n", t->nrun,
pp_printf(" %8i %i %s\n", t->seconds, t->nanos/1000, t->name);
wrc_tasks[i].nrun, ena, wrc_tasks[i].name);
} }
return 0; return 0;
} }
......
...@@ -44,6 +44,8 @@ int32_t sfp_deltaTx = 0; ...@@ -44,6 +44,8 @@ int32_t sfp_deltaTx = 0;
int32_t sfp_deltaRx = 0; int32_t sfp_deltaRx = 0;
uint32_t cal_phase_transition = 2389; uint32_t cal_phase_transition = 2389;
static uint32_t prev_nanos_for_profile;
static void wrc_initialize(void) static void wrc_initialize(void)
{ {
uint8_t mac_addr[6]; uint8_t mac_addr[6];
...@@ -97,6 +99,7 @@ static void wrc_initialize(void) ...@@ -97,6 +99,7 @@ static void wrc_initialize(void)
wrc_ptp_set_mode(WRC_MODE_SLAVE); wrc_ptp_set_mode(WRC_MODE_SLAVE);
wrc_ptp_start(); wrc_ptp_start();
shw_pps_gen_get_time(NULL, &prev_nanos_for_profile);
} }
int link_status; int link_status;
...@@ -224,13 +227,40 @@ struct wrc_task wrc_tasks[] = { ...@@ -224,13 +227,40 @@ struct wrc_task wrc_tasks[] = {
int wrc_n_tasks = ARRAY_SIZE(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) static void wrc_run_task(struct wrc_task *t)
{ {
if (t->enable && !*t->enable) int done_sth = 0;
return;
if (t->job) if (!t->job) /* idle task, just count iterations */
t->nrun += t->job(); t->nrun++;
else 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) 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