FlorenceOS/Florence

thread: Better load balancing

notYuriy opened this issue · 0 comments

As of now, task allocator is very simplistic

var best_cpu_idx: usize = 0;
{
const state = balancer_lock.lock();
// TODO: maybe something more sophisticated?
for (os.platform.smp.cpus) |*cpu, i| {
if (cpu.tasks_count < os.platform.smp.cpus[best_cpu_idx].tasks_count) {
best_cpu_idx = i;
}
}
task.allocated_core_id = best_cpu_idx;
os.platform.smp.cpus[best_cpu_idx].tasks_count += 1;
balancer_lock.unlock(state);
}

There are two possible ways to improve task allocation algorithm

  • Better way to measure load than simply number of tasks. Ideally, we want to measure how much time is spent in each of those tasks using os.platform.clock() function
  • Use a better data structure than array.