determine the 1, 5 and 15 minute load

This commit is contained in:
Stefan Lankes 2011-09-20 08:56:58 +02:00
parent a7e57811ac
commit c2ec2800bc
2 changed files with 23 additions and 13 deletions

View file

@ -123,7 +123,7 @@ typedef struct {
/// total number of tasks in the queue
uint32_t nr_tasks;
// current load = average number of tasks in the queue (1-minute average)
uint32_t load;
uint32_t load[3];
// help counter to determine the the cpu load
int32_t load_counter;
// help counter to avoid "over balancing"

View file

@ -53,11 +53,11 @@ static task_t task_table[MAX_TASKS] = { \
static spinlock_irqsave_t table_lock = SPINLOCK_IRQSAVE_INIT;
#if MAX_CORES > 1
static runqueue_t runqueues[MAX_CORES] = { \
[0] = {task_table+0, NULL, 0, 0, 0, 0, 0, {[0 ... MAX_PRIO-1] = {NULL, NULL}}, {NULL, NULL}, SPINLOCK_IRQSAVE_INIT}, \
[1 ... MAX_CORES-1] = {NULL, NULL, 0, 0, 0, 0, 0, {[0 ... MAX_PRIO-1] = {NULL, NULL}}, {NULL, NULL}, SPINLOCK_IRQSAVE_INIT}};
[0] = {task_table+0, NULL, 0, {[0 ... 2] = 0}, TIMER_FREQ/5, 0, 0, {[0 ... MAX_PRIO-1] = {NULL, NULL}}, {NULL, NULL}, SPINLOCK_IRQSAVE_INIT}, \
[1 ... MAX_CORES-1] = {NULL, NULL, 0, {[0 ... 2] = 0}, TIMER_FREQ/5, 0, 0, {[0 ... MAX_PRIO-1] = {NULL, NULL}}, {NULL, NULL}, SPINLOCK_IRQSAVE_INIT}};
#else
static runqueue_t runqueues[1] = { \
[0] = {task_table+0, NULL, 0, 0, 0, 0, 0, {[0 ... MAX_PRIO-1] = {NULL, NULL}}, {NULL, NULL}, SPINLOCK_IRQSAVE_INIT}};
[0] = {task_table+0, NULL, 0, {[0 ... 2] = 0}, TIMER_FREQ/5, 0, 0, {[0 ... MAX_PRIO-1] = {NULL, NULL}}, {NULL, NULL}, SPINLOCK_IRQSAVE_INIT}};
#endif
DEFINE_PER_CORE(task_t*, current_task, task_table+0);
@ -1079,27 +1079,37 @@ int set_timer(uint64_t deadline)
return ret;
}
#define FSHIFT 21 /* nr of bits of precision (e.g. 11) */
#define FIXED_1 (1<<FSHIFT) /* 1.0 as fixed-point */
#define EXP 1884 /* 1/exp(5sec/1min) as fixed-point */
/* determining the load as fix-point */
#define FSHIFT 11 /* nr of bits of precision */
#define FIXED_1 (1<<FSHIFT) /* 1.0 as fixed-point */
#define EXP_1 1884 /* 1/exp(5sec/1min) */
#define EXP_5 2014 /* 1/exp(5sec/5min) */
#define EXP_15 2037 /* 1/exp(5sec/15min) */
void update_load(void)
{
uint32_t core_id = CORE_ID;
runqueues[core_id].load_counter--;
if (runqueues[core_id].balance_counter > 0)
runqueues[core_id].balance_counter--;
runqueues[core_id].load_counter--;
if (runqueues[core_id].load_counter < 0) {
runqueues[core_id].load_counter += 5*TIMER_FREQ;
runqueues[core_id].load_counter += TIMER_FREQ/5 + 1;
spinlock_irqsave_lock(&runqueues[core_id].lock);
runqueues[core_id].load *= EXP;
runqueues[core_id].load += runqueues[core_id].nr_tasks*(FIXED_1-EXP);
runqueues[core_id].load >>= FSHIFT;
runqueues[core_id].load[0] *= EXP_1;
runqueues[core_id].load[0] += (runqueues[core_id].nr_tasks *FIXED_1) * (FIXED_1 - EXP_1);
runqueues[core_id].load[0] >>= FSHIFT;
runqueues[core_id].load[1] *= EXP_5;
runqueues[core_id].load[1] += (runqueues[core_id].nr_tasks *FIXED_1) * (FIXED_1 - EXP_5);
runqueues[core_id].load[1] >>= FSHIFT;
runqueues[core_id].load[2] *= EXP_15;
runqueues[core_id].load[2] += (runqueues[core_id].nr_tasks *FIXED_1) * (FIXED_1 - EXP_15);
runqueues[core_id].load[2] >>= FSHIFT;
spinlock_irqsave_unlock(&runqueues[core_id].lock);
//kprintf("load of core %u: %u, %u\n", core_id, runqueues[core_id].load, runqueues[core_id].nr_tasks);
kprintf("load of core %u: %u, %u, %u, %u\n", core_id, runqueues[core_id].load[0], runqueues[core_id].load[1], runqueues[core_id].load[2], runqueues[core_id].nr_tasks);
}
}