sched: Fix TASK_WAKING vs fork deadlock
[linux-2.6.git] / kernel / sched_idletask.c
1 /*
2  * idle-task scheduling class.
3  *
4  * (NOTE: these are not related to SCHED_IDLE tasks which are
5  *  handled in sched_fair.c)
6  */
7
8 #ifdef CONFIG_SMP
9 static int
10 select_task_rq_idle(struct rq *rq, struct task_struct *p, int sd_flag, int flags)
11 {
12         return task_cpu(p); /* IDLE tasks as never migrated */
13 }
14 #endif /* CONFIG_SMP */
15 /*
16  * Idle tasks are unconditionally rescheduled:
17  */
18 static void check_preempt_curr_idle(struct rq *rq, struct task_struct *p, int flags)
19 {
20         resched_task(rq->idle);
21 }
22
23 static struct task_struct *pick_next_task_idle(struct rq *rq)
24 {
25         schedstat_inc(rq, sched_goidle);
26         /* adjust the active tasks as we might go into a long sleep */
27         calc_load_account_active(rq);
28         return rq->idle;
29 }
30
31 /*
32  * It is not legal to sleep in the idle task - print a warning
33  * message if some code attempts to do it:
34  */
35 static void
36 dequeue_task_idle(struct rq *rq, struct task_struct *p, int sleep)
37 {
38         raw_spin_unlock_irq(&rq->lock);
39         printk(KERN_ERR "bad: scheduling from the idle thread!\n");
40         dump_stack();
41         raw_spin_lock_irq(&rq->lock);
42 }
43
44 static void put_prev_task_idle(struct rq *rq, struct task_struct *prev)
45 {
46 }
47
48 static void task_tick_idle(struct rq *rq, struct task_struct *curr, int queued)
49 {
50 }
51
52 static void set_curr_task_idle(struct rq *rq)
53 {
54 }
55
56 static void switched_to_idle(struct rq *rq, struct task_struct *p,
57                              int running)
58 {
59         /* Can this actually happen?? */
60         if (running)
61                 resched_task(rq->curr);
62         else
63                 check_preempt_curr(rq, p, 0);
64 }
65
66 static void prio_changed_idle(struct rq *rq, struct task_struct *p,
67                               int oldprio, int running)
68 {
69         /* This can happen for hot plug CPUS */
70
71         /*
72          * Reschedule if we are currently running on this runqueue and
73          * our priority decreased, or if we are not currently running on
74          * this runqueue and our priority is higher than the current's
75          */
76         if (running) {
77                 if (p->prio > oldprio)
78                         resched_task(rq->curr);
79         } else
80                 check_preempt_curr(rq, p, 0);
81 }
82
83 static unsigned int get_rr_interval_idle(struct rq *rq, struct task_struct *task)
84 {
85         return 0;
86 }
87
88 /*
89  * Simple, special scheduling class for the per-CPU idle tasks:
90  */
91 static const struct sched_class idle_sched_class = {
92         /* .next is NULL */
93         /* no enqueue/yield_task for idle tasks */
94
95         /* dequeue is not valid, we print a debug message there: */
96         .dequeue_task           = dequeue_task_idle,
97
98         .check_preempt_curr     = check_preempt_curr_idle,
99
100         .pick_next_task         = pick_next_task_idle,
101         .put_prev_task          = put_prev_task_idle,
102
103 #ifdef CONFIG_SMP
104         .select_task_rq         = select_task_rq_idle,
105 #endif
106
107         .set_curr_task          = set_curr_task_idle,
108         .task_tick              = task_tick_idle,
109
110         .get_rr_interval        = get_rr_interval_idle,
111
112         .prio_changed           = prio_changed_idle,
113         .switched_to            = switched_to_idle,
114
115         /* no .task_new for idle tasks */
116 };