Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ll_schedule: add a DSP load tracker to ll_tasks_execute #4943

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/schedule/ll_schedule.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,19 @@ DECLARE_SOF_UUID("ll-schedule", ll_sched_uuid, 0x4f9c3ec7, 0x7b55, 0x400c,

DECLARE_TR_CTX(ll_tr, SOF_UUID(ll_sched_uuid), LOG_LEVEL_INFO);

struct ll_dsp_load {
unsigned int cycles_sum;
unsigned int checks;
};

/* one instance of data allocated per core */
struct ll_schedule_data {
struct list_item tasks; /* list of ll tasks */
atomic_t num_tasks; /* number of ll tasks */
#if CONFIG_PERFORMANCE_COUNTERS
struct perf_cnt_data pcd;
#endif
struct ll_dsp_load dsp_load;
struct ll_schedule_domain *domain; /* scheduling domain */
};

Expand Down Expand Up @@ -113,13 +119,39 @@ static void schedule_ll_task_done(struct ll_schedule_data *sch,
atomic_read(&sch->domain->total_num_tasks));
}

/* perf measurement windows size 2^x */
#define CHECKS_WINDOW_SIZE 10

static inline void dsp_load_check(struct ll_dsp_load *load, uint32_t cycles0, uint32_t cycles1)
{
uint32_t diff, max;

if (cycles1 > cycles0)
diff = cycles1 - cycles0;
else
diff = UINT32_MAX - cycles0 + cycles1;

load->cycles_sum += diff;

if (++load->checks == 1 << CHECKS_WINDOW_SIZE) {
load->cycles_sum >>= CHECKS_WINDOW_SIZE;
max = clock_us_to_ticks(PLATFORM_DEFAULT_CLOCK, CONFIG_SYSTICK_PERIOD);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be light-weight, but the above line performs run-time divisions and multiplications with constants, even if only every N runs. Since clock_us_to_ticks() is a real function, I don't think this will be pre-calculated and optimised away by the compiler. But since it's always the same calculation (as long as the clock frequency doesn't change), this should be calculated once and stored. To also take frequency calculation into account we can also store the frequency (index) that was used to calculate this, and if it changes - recalculate.
But yes, this would also somehow have to account for imprecise XTOS ticks.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only part doing the div/mult is the clock_us_to_ticks() and this will only happen once per second (and you are right, we could do this at init since it's all const), all the rest is shifts which are optimal on xtensa

tr_info(&ll_tr, "ll avg %u/%u", load->cycles_sum, max);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For automatic parsing, using blank as separator for numbers instead of "/" could be nicer?

load->cycles_sum = 0;
load->checks = 0;
}
}

static void schedule_ll_tasks_execute(struct ll_schedule_data *sch)
{
struct ll_schedule_domain *domain = sch->domain;
uint32_t cycles0, cycles1;
struct list_item *wlist;
struct list_item *tlist;
struct task *task;

cycles0 = (uint32_t)platform_timer_get(timer_get());

/* check each task in the list for pending */
list_for_item_safe(wlist, tlist, &sch->tasks) {
task = container_of(wlist, struct task, list);
Expand Down Expand Up @@ -152,6 +184,9 @@ static void schedule_ll_tasks_execute(struct ll_schedule_data *sch)

spin_unlock(&domain->lock);
}

cycles1 = (uint32_t)platform_timer_get(timer_get());
dsp_load_check(&sch->dsp_load, cycles0, cycles1);
}

static void schedule_ll_client_reschedule(struct ll_schedule_data *sch)
Expand Down