Commit 86f565c2 authored by Adam Wujek's avatar Adam Wujek 💬 Committed by Grzegorz Daniluk

wrc_main: add tracking of a maximum execution time of each task

Also print it in the ps command
Signed-off-by: Adam Wujek's avatarAdam Wujek <adam.wujek@cern.ch>
parent 15242481
......@@ -21,6 +21,7 @@ struct wrc_task {
unsigned long nrun;
unsigned long seconds;
unsigned long nanos;
unsigned long max_run; /* in nanos */
};
/* An helper for periodic tasks, relying on a static varible */
......
......@@ -12,20 +12,29 @@
extern struct wrc_task wrc_tasks[];
extern int wrc_n_tasks;
extern uint32_t print_task_time_threshold;
static int cmd_ps(const char *args[])
{
struct wrc_task *t;
if (args[0] && !strcasecmp(args[0], "reset")) {
for_each_task(t)
t->nrun = t->seconds = t->nanos = 0;
return 0;
if (args[0]) {
if(!strcasecmp(args[0], "reset")) {
for_each_task(t)
t->nrun = t->seconds = t->nanos = t->max_run = 0;
return 0;
} else if (!strcasecmp(args[0], "max")) {
if (args[1])
print_task_time_threshold = atoi(args[1]);
pp_printf("print_task_time_threshold %d\n",
print_task_time_threshold);
return 0;
}
}
pp_printf(" iterations seconds.micros name\n");
pp_printf(" iterations seconds.micros max name\n");
for_each_task(t)
pp_printf(" %9li %9li.%06li %s\n", t->nrun,
t->seconds, t->nanos/1000, t->name);
pp_printf(" %9li %9li.%06li %9ld %s\n", t->nrun,
t->seconds, t->nanos/1000, t->max_run, t->name);
return 0;
}
......
......@@ -44,6 +44,8 @@ uint32_t cal_phase_transition = 2389;
int wrc_vlan_number = CONFIG_VLAN_NR;
static uint32_t prev_nanos_for_profile;
#define DEFAULT_PRINT_TASK_TIME_THRESHOLD 0
uint32_t print_task_time_threshold = DEFAULT_PRINT_TASK_TIME_THRESHOLD;
static void wrc_initialize(void)
{
......@@ -214,6 +216,14 @@ DEFINE_WRC_TASK(spll) = {
.job = spll_update,
};
static void task_time_normalize(struct wrc_task *t)
{
if (t->nanos > 1000 * 1000 * 1000) {
t->nanos -= 1000 * 1000 * 1000;
t->seconds++;
}
}
/* Account the time to either this task or task 0 */
static void account_task(struct wrc_task *t, int done_sth)
{
......@@ -228,10 +238,18 @@ static void account_task(struct wrc_task *t, int done_sth)
delta += 1000 * 1000 * 1000;
t->nanos += delta;
if (t->nanos > 1000 * 1000 * 1000) {
t->nanos -= 1000 * 1000 * 1000;
t->seconds++;
task_time_normalize(t);
if (t->max_run < delta) {/* update max_run */
if (print_task_time_threshold
&& delta > print_task_time_threshold) {
pp_printf("New max run time for a task %s, old %ld, "
"new %d\n",
t->name, t->max_run, delta);
}
t->max_run = delta;
}
if (print_task_time_threshold && delta > print_task_time_threshold)
pp_printf("task %s, run for %d\n", t->name, delta);
prev_nanos_for_profile = nanos;
}
......
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