|author||Linus Torvalds <firstname.lastname@example.org>||2005-04-16 15:20:36 -0700|
|committer||Linus Torvalds <email@example.com>||2005-04-16 15:20:36 -0700|
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'Documentation/sched-coding.txt')
1 files changed, 126 insertions, 0 deletions
diff --git a/Documentation/sched-coding.txt b/Documentation/sched-coding.txt
new file mode 100644
@@ -0,0 +1,126 @@
+ Reference for various scheduler-related methods in the O(1) scheduler
+ Robert Love <firstname.lastname@example.org>, MontaVista Software
+Note most of these methods are local to kernel/sched.c - this is by design.
+The scheduler is meant to be self-contained and abstracted away. This document
+is primarily for understanding the scheduler, not interfacing to it. Some of
+the discussed interfaces, however, are general process/scheduling methods.
+They are typically defined in include/linux/sched.h.
+Main Scheduling Methods
+void load_balance(runqueue_t *this_rq, int idle)
+ Attempts to pull tasks from one cpu to another to balance cpu usage,
+ if needed. This method is called explicitly if the runqueues are
+ inbalanced or periodically by the timer tick. Prior to calling,
+ the current runqueue must be locked and interrupts disabled.
+ The main scheduling function. Upon return, the highest priority
+ process will be active.
+Each runqueue has its own lock, rq->lock. When multiple runqueues need
+to be locked, lock acquires must be ordered by ascending &runqueue value.
+A specific runqueue is locked via
+ task_rq_lock(task_t pid, unsigned long *flags)
+which disables preemption, disables interrupts, and locks the runqueue pid is
+running on. Likewise,
+ task_rq_unlock(task_t pid, unsigned long *flags)
+unlocks the runqueue pid is running on, restores interrupts to their previous
+state, and reenables preemption.
+ double_rq_lock(runqueue_t *rq1, runqueue_t *rq2)
+ double_rq_unlock(runqueue_t *rq1, runqueue_t *rq2)
+safely lock and unlock, respectively, the two specified runqueues. They do
+not, however, disable and restore interrupts. Users are required to do so
+manually before and after calls.
+ The maximum priority of the system, stored in the task as task->prio.
+ Lower priorities are higher. Normal (non-RT) priorities range from
+ MAX_RT_PRIO to (MAX_PRIO - 1).
+ The maximum real-time priority of the system. Valid RT priorities
+ range from 0 to (MAX_RT_PRIO - 1).
+ The maximum real-time priority that is exported to user-space. Should
+ always be equal to or less than MAX_RT_PRIO. Setting it less allows
+ kernel threads to have higher priorities than any user-space task.
+ Respectively, the minimum and maximum timeslices (quanta) of a process.
+ The main per-CPU runqueue data structure.
+ The main per-process data structure.
+ Returns the runqueue of the specified cpu.
+ Returns the runqueue of the current cpu.
+ Returns the runqueue which holds the specified pid.
+ Returns the task currently running on the given cpu.
+ Returns true if pid is real-time, false if not.
+Process Control Methods
+void set_user_nice(task_t *p, long nice)
+ Sets the "nice" value of task p to the given value.
+int setscheduler(pid_t pid, int policy, struct sched_param *param)
+ Sets the scheduling policy and parameters for the given pid.
+int set_cpus_allowed(task_t *p, unsigned long new_mask)
+ Sets a given task's CPU affinity and migrates it to a proper cpu.
+ Callers must have a valid reference to the task and assure the
+ task not exit prematurely. No locks can be held during the call.
+ Sets the given task's state to the given value.
+ Sets the current task's state to the given value.
+void set_tsk_need_resched(struct task_struct *tsk)
+ Sets need_resched in the given task.
+void clear_tsk_need_resched(struct task_struct *tsk)
+ Clears need_resched in the given task.
+ Sets need_resched in the current task.
+ Clears need_resched in the current task.
+ Returns true if need_resched is set in the current task, false
+ Place the current process at the end of the runqueue and call schedule.