Merge branch 'linus' into sched/core
authorIngo Molnar <mingo@elte.hu>
Thu, 21 Jul 2011 15:59:54 +0000 (17:59 +0200)
committerIngo Molnar <mingo@elte.hu>
Thu, 21 Jul 2011 16:00:01 +0000 (18:00 +0200)
Merge reason: pick up the latest scheduler fixes.

Signed-off-by: Ingo Molnar <mingo@elte.hu>
21 files changed:
Documentation/DocBook/kernel-hacking.tmpl
Documentation/SubmitChecklist
Documentation/development-process/4.Coding
Documentation/ja_JP/SubmitChecklist
Documentation/zh_CN/SubmitChecklist
arch/h8300/Kconfig.cpu
arch/m32r/Kconfig
arch/xtensa/Kconfig
include/linux/bit_spinlock.h
include/linux/hardirq.h
include/linux/kernel.h
include/linux/pagemap.h
include/linux/preempt.h
include/linux/rcupdate.h
include/linux/sched.h
kernel/Kconfig.preempt
kernel/sched.c
kernel/sched_autogroup.h
kernel/sched_fair.c
kernel/sched_rt.c
lib/Kconfig.debug

index 7b3f493634133b7cf9ac8a0697074e8185b64096..07a9c48de5a2e6ce5f820b4e0123d6de0a4ce4e2 100644 (file)
@@ -409,7 +409,7 @@ cond_resched(); /* Will sleep */
 
   <para>
    You should always compile your kernel
-   <symbol>CONFIG_DEBUG_SPINLOCK_SLEEP</symbol> on, and it will warn
+   <symbol>CONFIG_DEBUG_ATOMIC_SLEEP</symbol> on, and it will warn
    you if you break these rules.  If you <emphasis>do</emphasis> break
    the rules, you will eventually lock up your box.
   </para>
index da0382daa39556939dcc94717b658b5917e4009f..7b13be41c085684a2bdfb629cc926d69891a108d 100644 (file)
@@ -53,7 +53,7 @@ kernel patches.
 
 12: Has been tested with CONFIG_PREEMPT, CONFIG_DEBUG_PREEMPT,
     CONFIG_DEBUG_SLAB, CONFIG_DEBUG_PAGEALLOC, CONFIG_DEBUG_MUTEXES,
-    CONFIG_DEBUG_SPINLOCK, CONFIG_DEBUG_SPINLOCK_SLEEP all simultaneously
+    CONFIG_DEBUG_SPINLOCK, CONFIG_DEBUG_ATOMIC_SLEEP all simultaneously
     enabled.
 
 13: Has been build- and runtime tested with and without CONFIG_SMP and
index f3f1a469443cd2daca59e0234952c4a4598d1000..83f5f5b365a3fdb5a79e0cf9106697d937994cf4 100644 (file)
@@ -244,7 +244,7 @@ testing purposes.  In particular, you should turn on:
  - DEBUG_SLAB can find a variety of memory allocation and use errors; it
    should be used on most development kernels.
 
- - DEBUG_SPINLOCK, DEBUG_SPINLOCK_SLEEP, and DEBUG_MUTEXES will find a
+ - DEBUG_SPINLOCK, DEBUG_ATOMIC_SLEEP, and DEBUG_MUTEXES will find a
    number of common locking errors.
 
 There are quite a few other debugging options, some of which will be
index 2df4576f11732743ddb22f044cf87902d349f00c..cb5507b1ac8189596875edc65e9b0d38a539729b 100644 (file)
@@ -68,7 +68,7 @@ Linux カーネルパッチ投稿者向けチェックリスト
 
 12: CONFIG_PREEMPT, CONFIG_DEBUG_PREEMPT, CONFIG_DEBUG_SLAB,
     CONFIG_DEBUG_PAGEALLOC, CONFIG_DEBUG_MUTEXES, CONFIG_DEBUG_SPINLOCK,
-    CONFIG_DEBUG_SPINLOCK_SLEEP これら全てを同時に有効にして動作確認を
+    CONFIG_DEBUG_ATOMIC_SLEEP これら全てを同時に有効にして動作確認を
     行ってください。
 
 13: CONFIG_SMP, CONFIG_PREEMPT を有効にした場合と無効にした場合の両方で
index 951415bbab0c42db76faf98245c1c5fffb919360..4c741d6bc048d2dbc86790ba754b492b134f860a 100644 (file)
@@ -67,7 +67,7 @@ Linux
 
 12£ºÒѾ­Í¨¹ýCONFIG_PREEMPT, CONFIG_DEBUG_PREEMPT,
     CONFIG_DEBUG_SLAB, CONFIG_DEBUG_PAGEALLOC, CONFIG_DEBUG_MUTEXES,
-    CONFIG_DEBUG_SPINLOCK, CONFIG_DEBUG_SPINLOCK_SLEEP²âÊÔ£¬²¢ÇÒͬʱ¶¼
+    CONFIG_DEBUG_SPINLOCK, CONFIG_DEBUG_ATOMIC_SLEEP²âÊÔ£¬²¢ÇÒͬʱ¶¼
     Ê¹ÄÜ¡£
 
 13£ºÒѾ­¶¼¹¹½¨²¢ÇÒʹÓûòÕß²»Ê¹ÓàCONFIG_SMP ºÍ CONFIG_PREEMPT²âÊÔÖ´ÐÐʱ¼ä¡£
index d236ab4232ca4540d5e9d9d6cf515e71a6d9d807..15c22286ae7951534cf24aa1950de38c26d1bc17 100644 (file)
@@ -162,9 +162,7 @@ config H8300_TPU_CH
        int "TPU channel"
        depends on H8300_TPU
 
-config PREEMPT
-       bool "Preemptible Kernel"
-       default n
+source "kernel/Kconfig.preempt"
 
 source "mm/Kconfig"
 
index 85b44e8582254a5f154ecc2c49455e5f7b0f3157..b92b9445255d36bdf1734dfcb94d78b30892c755 100644 (file)
@@ -268,17 +268,7 @@ config SCHED_OMIT_FRAME_POINTER
         bool
         default y
 
-config PREEMPT
-       bool "Preemptible Kernel"
-       help
-         This option reduces the latency of the kernel when reacting to
-         real-time or interactive events by allowing a low priority process to
-         be preempted even if it is in kernel mode executing a system call.
-         This allows applications to run more reliably even when the system is
-         under load.
-
-         Say Y here if you are building a kernel for a desktop, embedded
-         or real-time system.  Say N if you are unsure.
+source "kernel/Kconfig.preempt"
 
 config SMP
        bool "Symmetric multi-processing support"
index 5d43c1f8ada8b1406e5b7784c063c157274f1155..c346ccdce0df55043dbdac8c87096addc0dd5b37 100644 (file)
@@ -80,18 +80,7 @@ config XTENSA_UNALIGNED_USER
 
          Say Y here to enable unaligned memory access in user space.
 
-config PREEMPT
-       bool "Preemptible Kernel"
-       help
-          This option reduces the latency of the kernel when reacting to
-          real-time or interactive events by allowing a low priority process to
-          be preempted even if it is in kernel mode executing a system call.
-          Unfortunately the kernel code has some race conditions if both
-          CONFIG_SMP and CONFIG_PREEMPT are enabled, so this option is
-          currently disabled if you are building an SMP kernel.
-
-          Say Y here if you are building a kernel for a desktop, embedded
-          or real-time system.  Say N if you are unsure.
+source "kernel/Kconfig.preempt"
 
 config MATH_EMULATION
        bool "Math emulation"
index b4326bfa684f24c3ad147de3cb7d63a9f066da80..564d997e216887f13c18d0b65cfafaf6aba26e71 100644 (file)
@@ -88,7 +88,7 @@ static inline int bit_spin_is_locked(int bitnum, unsigned long *addr)
 {
 #if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)
        return test_bit(bitnum, addr);
-#elif defined CONFIG_PREEMPT
+#elif defined CONFIG_PREEMPT_COUNT
        return preempt_count();
 #else
        return 1;
index ba362171e8aeb75076570647ee4c1d65e84d3773..f743883f769e9bb38d82c901e19b5fdd7a1eada8 100644 (file)
@@ -93,7 +93,7 @@
  */
 #define in_nmi()       (preempt_count() & NMI_MASK)
 
-#if defined(CONFIG_PREEMPT)
+#if defined(CONFIG_PREEMPT_COUNT)
 # define PREEMPT_CHECK_OFFSET 1
 #else
 # define PREEMPT_CHECK_OFFSET 0
 #define in_atomic_preempt_off() \
                ((preempt_count() & ~PREEMPT_ACTIVE) != PREEMPT_CHECK_OFFSET)
 
-#ifdef CONFIG_PREEMPT
+#ifdef CONFIG_PREEMPT_COUNT
 # define preemptible() (preempt_count() == 0 && !irqs_disabled())
 # define IRQ_EXIT_OFFSET (HARDIRQ_OFFSET-1)
 #else
index 953352a88336c0385e2e385f93e41c278513be7b..567a6f7bbeed00b76d5b8ccd56555c593ffefd6f 100644 (file)
@@ -121,7 +121,7 @@ extern int _cond_resched(void);
 # define might_resched() do { } while (0)
 #endif
 
-#ifdef CONFIG_DEBUG_SPINLOCK_SLEEP
+#ifdef CONFIG_DEBUG_ATOMIC_SLEEP
   void __might_sleep(const char *file, int line, int preempt_offset);
 /**
  * might_sleep - annotation for functions that can sleep
index 716875e53520ecb4afe8ae7edd1e39a7eb75032a..8e38d4c140ffb52b4dfcaeb2add5722e3654f318 100644 (file)
@@ -134,7 +134,7 @@ static inline int page_cache_get_speculative(struct page *page)
        VM_BUG_ON(in_interrupt());
 
 #if !defined(CONFIG_SMP) && defined(CONFIG_TREE_RCU)
-# ifdef CONFIG_PREEMPT
+# ifdef CONFIG_PREEMPT_COUNT
        VM_BUG_ON(!in_atomic());
 # endif
        /*
@@ -172,7 +172,7 @@ static inline int page_cache_add_speculative(struct page *page, int count)
        VM_BUG_ON(in_interrupt());
 
 #if !defined(CONFIG_SMP) && defined(CONFIG_TREE_RCU)
-# ifdef CONFIG_PREEMPT
+# ifdef CONFIG_PREEMPT_COUNT
        VM_BUG_ON(!in_atomic());
 # endif
        VM_BUG_ON(page_count(page) == 0);
index 2e681d9555bdfd5db5326a6d37aab860cd417152..58969b2a8a8292deb33a215006eade8659764d6d 100644 (file)
 
 asmlinkage void preempt_schedule(void);
 
+#define preempt_check_resched() \
+do { \
+       if (unlikely(test_thread_flag(TIF_NEED_RESCHED))) \
+               preempt_schedule(); \
+} while (0)
+
+#else /* !CONFIG_PREEMPT */
+
+#define preempt_check_resched()                do { } while (0)
+
+#endif /* CONFIG_PREEMPT */
+
+
+#ifdef CONFIG_PREEMPT_COUNT
+
 #define preempt_disable() \
 do { \
        inc_preempt_count(); \
@@ -39,12 +54,6 @@ do { \
        dec_preempt_count(); \
 } while (0)
 
-#define preempt_check_resched() \
-do { \
-       if (unlikely(test_thread_flag(TIF_NEED_RESCHED))) \
-               preempt_schedule(); \
-} while (0)
-
 #define preempt_enable() \
 do { \
        preempt_enable_no_resched(); \
@@ -80,18 +89,17 @@ do { \
        preempt_check_resched(); \
 } while (0)
 
-#else
+#else /* !CONFIG_PREEMPT_COUNT */
 
 #define preempt_disable()              do { } while (0)
 #define preempt_enable_no_resched()    do { } while (0)
 #define preempt_enable()               do { } while (0)
-#define preempt_check_resched()                do { } while (0)
 
 #define preempt_disable_notrace()              do { } while (0)
 #define preempt_enable_no_resched_notrace()    do { } while (0)
 #define preempt_enable_notrace()               do { } while (0)
 
-#endif
+#endif /* CONFIG_PREEMPT_COUNT */
 
 #ifdef CONFIG_PREEMPT_NOTIFIERS
 
index 99f9aa7c2804e2775ff552a87aeb2f27de7bac97..8f4f881a0ad8153dd82150745aee03881448a3b0 100644 (file)
@@ -239,7 +239,7 @@ extern int rcu_read_lock_bh_held(void);
  * Check debug_lockdep_rcu_enabled() to prevent false positives during boot
  * and while lockdep is disabled.
  */
-#ifdef CONFIG_PREEMPT
+#ifdef CONFIG_PREEMPT_COUNT
 static inline int rcu_read_lock_sched_held(void)
 {
        int lockdep_opinion = 0;
@@ -250,12 +250,12 @@ static inline int rcu_read_lock_sched_held(void)
                lockdep_opinion = lock_is_held(&rcu_sched_lock_map);
        return lockdep_opinion || preempt_count() != 0 || irqs_disabled();
 }
-#else /* #ifdef CONFIG_PREEMPT */
+#else /* #ifdef CONFIG_PREEMPT_COUNT */
 static inline int rcu_read_lock_sched_held(void)
 {
        return 1;
 }
-#endif /* #else #ifdef CONFIG_PREEMPT */
+#endif /* #else #ifdef CONFIG_PREEMPT_COUNT */
 
 #else /* #ifdef CONFIG_DEBUG_LOCK_ALLOC */
 
@@ -276,17 +276,17 @@ static inline int rcu_read_lock_bh_held(void)
        return 1;
 }
 
-#ifdef CONFIG_PREEMPT
+#ifdef CONFIG_PREEMPT_COUNT
 static inline int rcu_read_lock_sched_held(void)
 {
        return preempt_count() != 0 || irqs_disabled();
 }
-#else /* #ifdef CONFIG_PREEMPT */
+#else /* #ifdef CONFIG_PREEMPT_COUNT */
 static inline int rcu_read_lock_sched_held(void)
 {
        return 1;
 }
-#endif /* #else #ifdef CONFIG_PREEMPT */
+#endif /* #else #ifdef CONFIG_PREEMPT_COUNT */
 
 #endif /* #else #ifdef CONFIG_DEBUG_LOCK_ALLOC */
 
index 14a6c7b545de5bf3ad51dea50d5d484cfc8bfbb5..341a4d78ddaa9836172239846e29d7cd4850bc40 100644 (file)
@@ -2510,7 +2510,7 @@ extern int _cond_resched(void);
 
 extern int __cond_resched_lock(spinlock_t *lock);
 
-#ifdef CONFIG_PREEMPT
+#ifdef CONFIG_PREEMPT_COUNT
 #define PREEMPT_LOCK_OFFSET    PREEMPT_OFFSET
 #else
 #define PREEMPT_LOCK_OFFSET    0
index bf987b95b3560fbd0a7d8a820335100a55e1d105..24e7cb0ba26a9b534eab5ef5b0ed39226f4cd802 100644 (file)
@@ -35,6 +35,7 @@ config PREEMPT_VOLUNTARY
 
 config PREEMPT
        bool "Preemptible Kernel (Low-Latency Desktop)"
+       select PREEMPT_COUNT
        help
          This option reduces the latency of the kernel by making
          all kernel code (that is not executing in a critical section)
@@ -52,3 +53,5 @@ config PREEMPT
 
 endchoice
 
+config PREEMPT_COUNT
+       bool
\ No newline at end of file
index fde6ff90352583d65ff890a407200f2fb0c3073e..b0e7ad796d3b5aeeed9ce47169c51296af6e7d1c 100644 (file)
 
 static inline int rt_policy(int policy)
 {
-       if (unlikely(policy == SCHED_FIFO || policy == SCHED_RR))
+       if (policy == SCHED_FIFO || policy == SCHED_RR)
                return 1;
        return 0;
 }
@@ -2497,7 +2497,7 @@ ttwu_do_wakeup(struct rq *rq, struct task_struct *p, int wake_flags)
        if (p->sched_class->task_woken)
                p->sched_class->task_woken(rq, p);
 
-       if (unlikely(rq->idle_stamp)) {
+       if (rq->idle_stamp) {
                u64 delta = rq->clock - rq->idle_stamp;
                u64 max = 2*sysctl_sched_migration_cost;
 
@@ -2886,7 +2886,7 @@ void sched_fork(struct task_struct *p)
 #if defined(CONFIG_SMP)
        p->on_cpu = 0;
 #endif
-#ifdef CONFIG_PREEMPT
+#ifdef CONFIG_PREEMPT_COUNT
        /* Want to start with kernel preemption disabled. */
        task_thread_info(p)->preempt_count = 1;
 #endif
@@ -4338,11 +4338,8 @@ EXPORT_SYMBOL(schedule);
 
 static inline bool owner_running(struct mutex *lock, struct task_struct *owner)
 {
-       bool ret = false;
-
-       rcu_read_lock();
        if (lock->owner != owner)
-               goto fail;
+               return false;
 
        /*
         * Ensure we emit the owner->on_cpu, dereference _after_ checking
@@ -4352,11 +4349,7 @@ static inline bool owner_running(struct mutex *lock, struct task_struct *owner)
         */
        barrier();
 
-       ret = owner->on_cpu;
-fail:
-       rcu_read_unlock();
-
-       return ret;
+       return owner->on_cpu;
 }
 
 /*
@@ -4368,21 +4361,21 @@ int mutex_spin_on_owner(struct mutex *lock, struct task_struct *owner)
        if (!sched_feat(OWNER_SPIN))
                return 0;
 
+       rcu_read_lock();
        while (owner_running(lock, owner)) {
                if (need_resched())
-                       return 0;
+                       break;
 
                arch_mutex_cpu_relax();
        }
+       rcu_read_unlock();
 
        /*
-        * If the owner changed to another task there is likely
-        * heavy contention, stop spinning.
+        * We break out the loop above on need_resched() and when the
+        * owner changed, which is a sign for heavy contention. Return
+        * success only when lock->owner is NULL.
         */
-       if (lock->owner)
-               return 0;
-
-       return 1;
+       return lock->owner == NULL;
 }
 #endif
 
@@ -8185,7 +8178,7 @@ void __init sched_init(void)
        scheduler_running = 1;
 }
 
-#ifdef CONFIG_DEBUG_SPINLOCK_SLEEP
+#ifdef CONFIG_DEBUG_ATOMIC_SLEEP
 static inline int preempt_count_equals(int preempt_offset)
 {
        int nested = (preempt_count() & ~PREEMPT_ACTIVE) + rcu_preempt_depth();
@@ -8195,7 +8188,6 @@ static inline int preempt_count_equals(int preempt_offset)
 
 void __might_sleep(const char *file, int line, int preempt_offset)
 {
-#ifdef in_atomic
        static unsigned long prev_jiffy;        /* ratelimiting */
 
        if ((preempt_count_equals(preempt_offset) && !irqs_disabled()) ||
@@ -8217,7 +8209,6 @@ void __might_sleep(const char *file, int line, int preempt_offset)
        if (irqs_disabled())
                print_irqtrace_events(current);
        dump_stack();
-#endif
 }
 EXPORT_SYMBOL(__might_sleep);
 #endif
index 05577055cfcaa4dc7ac055cb495f8e4ac97d96c4..c2f0e7248dca354bc2e96ea95984c3457d28e75d 100644 (file)
@@ -13,6 +13,7 @@ struct autogroup {
        int                     nice;
 };
 
+static inline bool task_group_is_autogroup(struct task_group *tg);
 static inline struct task_group *
 autogroup_task_group(struct task_struct *p, struct task_group *tg);
 
index c768588e180b5ae7a83bebad45ace3ac34da0d19..e7d67a9e259a7eda9c7050b63f006f90aca943d8 100644 (file)
@@ -1481,7 +1481,6 @@ static int wake_affine(struct sched_domain *sd, struct task_struct *p, int sync)
         * effect of the currently running task from the load
         * of the current CPU:
         */
-       rcu_read_lock();
        if (sync) {
                tg = task_group(current);
                weight = current->se.load.weight;
@@ -1517,7 +1516,6 @@ static int wake_affine(struct sched_domain *sd, struct task_struct *p, int sync)
                balanced = this_eff_load <= prev_eff_load;
        } else
                balanced = true;
-       rcu_read_unlock();
 
        /*
         * If the currently running task will sleep within
index 10d018212bab8b1ad2f53e1ed388a4bbd56d4656..97540f0c9e47849543bc8a32e64b7bdff8ac4e01 100644 (file)
@@ -185,11 +185,23 @@ static inline u64 sched_rt_period(struct rt_rq *rt_rq)
 
 typedef struct task_group *rt_rq_iter_t;
 
-#define for_each_rt_rq(rt_rq, iter, rq) \
-       for (iter = list_entry_rcu(task_groups.next, typeof(*iter), list); \
-            (&iter->list != &task_groups) && \
-            (rt_rq = iter->rt_rq[cpu_of(rq)]); \
-            iter = list_entry_rcu(iter->list.next, typeof(*iter), list))
+static inline struct task_group *next_task_group(struct task_group *tg)
+{
+       do {
+               tg = list_entry_rcu(tg->list.next,
+                       typeof(struct task_group), list);
+       } while (&tg->list != &task_groups && task_group_is_autogroup(tg));
+
+       if (&tg->list == &task_groups)
+               tg = NULL;
+
+       return tg;
+}
+
+#define for_each_rt_rq(rt_rq, iter, rq)                                        \
+       for (iter = container_of(&task_groups, typeof(*iter), list);    \
+               (iter = next_task_group(iter)) &&                       \
+               (rt_rq = iter->rt_rq[cpu_of(rq)]);)
 
 static inline void list_add_leaf_rt_rq(struct rt_rq *rt_rq)
 {
@@ -1126,7 +1138,7 @@ static struct task_struct *_pick_next_task_rt(struct rq *rq)
 
        rt_rq = &rq->rt;
 
-       if (unlikely(!rt_rq->rt_nr_running))
+       if (!rt_rq->rt_nr_running)
                return NULL;
 
        if (rt_rq_throttled(rt_rq))
@@ -1548,7 +1560,7 @@ skip:
 static void pre_schedule_rt(struct rq *rq, struct task_struct *prev)
 {
        /* Try to pull RT tasks here if we lower this rq's prio */
-       if (unlikely(rt_task(prev)) && rq->rt.highest_prio.curr > prev->prio)
+       if (rq->rt.highest_prio.curr > prev->prio)
                pull_rt_task(rq);
 }
 
index dd373c8ee94399efad67ad5bc3adf57e51cf4a3d..9f0d826cadc3721a98348e4649b7f5fd45a06a16 100644 (file)
@@ -648,12 +648,15 @@ config TRACE_IRQFLAGS
          Enables hooks to interrupt enabling and disabling for
          either tracing or lock debugging.
 
-config DEBUG_SPINLOCK_SLEEP
-       bool "Spinlock debugging: sleep-inside-spinlock checking"
+config DEBUG_ATOMIC_SLEEP
+       bool "Sleep inside atomic section checking"
+       select PREEMPT_COUNT
        depends on DEBUG_KERNEL
        help
          If you say Y here, various routines which may sleep will become very
-         noisy if they are called with a spinlock held.
+         noisy if they are called inside atomic sections: when a spinlock is
+         held, inside an rcu read side critical section, inside preempt disabled
+         sections, inside an interrupt, etc...
 
 config DEBUG_LOCKING_API_SELFTESTS
        bool "Locking API boot-time self-tests"