Files
codezero/include/l4/generic/scheduler.h
Bora Sahin 2571dabc18 Fixes to the scheduler timeslice management.
One is related to the time distribution when a new child is created.
If the parent has one tick left, then both child and parent received
zero tick. When combined with
	current_irq_nest_count = 1
	voluntary_preempt = 0
values, this caused the scheduler from being invoked.

Second is related to the overall time distribution. When a thread
runs out of time, its new time slice is calculated by the below
formula:
	new_timeslice = (thread_prio * SCHED_TICKS) / total_prio
If we consider total_prio is equal to the sum of the priorities of
all the threads in the system, it imposes a problem of getting
zero tick. In the new scenario, total_prio is equal to the priority
types in the system so it is fixed. Every thread gets a timeslice
in proportion of their priorities. Thus, there is no risk of taking
zero tick.
2009-10-31 15:08:53 +02:00

75 lines
1.8 KiB
C

/*
* Scheduler and runqueue API definitions.
*
* Copyright (C) 2007 Bahadir Balban
*/
#ifndef __SCHEDULER_H__
#define __SCHEDULER_H__
#include <l4/generic/tcb.h>
#include INC_SUBARCH(mm.h)
#include INC_GLUE(memory.h)
/* Task priorities */
#define TASK_PRIO_MAX 10
#define TASK_PRIO_REALTIME 10
#define TASK_PRIO_PAGER 8
#define TASK_PRIO_SERVER 6
#define TASK_PRIO_NORMAL 4
#define TASK_PRIO_LOW 2
#define TASK_PRIO_TOTAL 30
/* Ticks per second, try ticks = 1000 + timeslice = 1 for regressed preemption test. */
#define SCHED_TICKS 100
/*
* A task can run continuously at this granularity,
* even if it has a greater total time slice.
*/
#define SCHED_GRANULARITY SCHED_TICKS/50
static inline struct ktcb *current_task(void)
{
register u32 stack asm("sp");
return (struct ktcb *)(stack & (~PAGE_MASK));
}
#define current current_task()
#define need_resched (current->ts_need_resched)
#define SCHED_RQ_TOTAL 2
/* A basic runqueue */
struct runqueue {
struct spinlock lock; /* Lock */
struct link task_list; /* List of tasks in rq */
unsigned int total; /* Total tasks */
};
/* Contains per-container scheduling structures */
struct scheduler {
struct runqueue sched_rq[SCHED_RQ_TOTAL];
struct runqueue *rq_runnable;
struct runqueue *rq_expired;
/* Total priority of all tasks in container */
int prio_total;
};
extern struct scheduler scheduler;
void sched_init_runqueue(struct runqueue *rq);
void sched_init_task(struct ktcb *task, int priority);
void sched_prepare_sleep(void);
void sched_pager_exit(void);
void sched_exit_sync(void);
void sched_suspend_sync(void);
void sched_suspend_async(void);
void sched_resume_sync(struct ktcb *task);
void sched_resume_async(struct ktcb *task);
void scheduler_start(void);
void schedule(void);
void sched_init(struct scheduler *scheduler);
#endif /* __SCHEDULER_H__ */