public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Ingo Molnar <mingo@elte.hu>
To: Andrew Morton <akpm@osdl.org>
Cc: linux-kernel@vger.kernel.org
Subject: [patch] preempt-cleanup.patch, 2.6.9-rc2
Date: Tue, 14 Sep 2004 11:15:29 +0200	[thread overview]
Message-ID: <20040914091529.GA21553@elte.hu> (raw)

[-- Attachment #1: Type: text/plain, Size: 1022 bytes --]


the attached patch is ontop of preempt-smp.patch. This is another
generic fallout from the voluntary-preempt patchset: a cleanup of the
cond_resched() infrastructure, in preparation of the latency reduction
patches. The changes:

 - uninline cond_resched() - this makes the footprint smaller,
   especially once the number of cond_resched() points increase.

 - add a 'was rescheduled' return value to cond_resched. This makes it
   symmetric to cond_resched_lock() and later latency reduction patches
   rely on the ability to tell whether there was any preemption.

 - make cond_resched() more robust by using the same mechanism as
   preempt_kernel(): by using PREEMPT_ACTIVE. This preserves the task's
   state - e.g. if the task is in TASK_ZOMBIE but gets preempted via
   cond_resched() just prior scheduling off then this approach preserves
   TASK_ZOMBIE.

 - the patch also adds need_lockbreak() which critical sections can use 
   to detect lock-break requests.

i've tested the patch on x86 SMP and UP.

	Ingo

[-- Attachment #2: preempt-cleanup.patch --]
[-- Type: text/plain, Size: 2972 bytes --]


the attached patch is ontop of preempt-smp.patch. This is another
generic fallout from the voluntary-preempt patchset: a cleanup of the
cond_resched() infrastructure, in preparation of the latency reduction
patches. The changes:

 - uninline cond_resched() - this makes the footprint smaller,
   especially once the number of cond_resched() points increase.

 - add a 'was rescheduled' return value to cond_resched. This makes it
   symmetric to cond_resched_lock() and later latency reduction patches
   rely on the ability to tell whether there was any preemption.

 - make cond_resched() more robust by using the same mechanism as
   preempt_kernel(): by using PREEMPT_ACTIVE. This preserves the task's
   state - e.g. if the task is in TASK_ZOMBIE but gets preempted via
   cond_resched() just prior scheduling off then this approach preserves
   TASK_ZOMBIE.

 - the patch also adds need_lockbreak() which critical sections can use
   to detect lock-break requests.

i've tested the patch on x86 SMP and UP.

Signed-off-by: Ingo Molnar <mingo@elte.hu>

--- linux/include/linux/sched.h.orig	
+++ linux/include/linux/sched.h	
@@ -951,15 +951,24 @@ static inline int need_resched(void)
 	return unlikely(test_thread_flag(TIF_NEED_RESCHED));
 }
 
-extern void __cond_resched(void);
-static inline void cond_resched(void)
-{
-	if (need_resched())
-		__cond_resched();
-}
-
+/*
+ * cond_resched() and cond_resched_lock(): latency reduction via
+ * explicit rescheduling in places that are safe. The return
+ * value indicates whether a reschedule was done in fact.
+ */
+extern int cond_resched(void);
 extern int cond_resched_lock(spinlock_t * lock);
 
+/*
+ * Does a critical section need to be broken due to another
+ * task waiting?:
+ */
+#if defined(CONFIG_PREEMPT) && defined(CONFIG_SMP)
+# define need_lockbreak(lock) ((lock)->break_lock)
+#else
+# define need_lockbreak(lock) 0
+#endif
+
 /* Reevaluate whether the task has signals pending delivery.
    This is required every time the blocked sigset_t changes.
    callers must hold sighand->siglock.  */
--- linux/kernel/sched.c.orig	
+++ linux/kernel/sched.c	
@@ -3539,13 +3539,25 @@ asmlinkage long sys_sched_yield(void)
 	return 0;
 }
 
-void __sched __cond_resched(void)
+static inline void __cond_resched(void)
 {
-	set_current_state(TASK_RUNNING);
-	schedule();
+	do {
+		preempt_count() += PREEMPT_ACTIVE;
+		schedule();
+		preempt_count() -= PREEMPT_ACTIVE;
+	} while (need_resched());
 }
 
-EXPORT_SYMBOL(__cond_resched);
+int __sched cond_resched(void)
+{
+	if (need_resched()) {
+		__cond_resched();
+		return 1;
+	}
+	return 0;
+}
+
+EXPORT_SYMBOL(cond_resched);
 
 /*
  * cond_resched_lock() - if a reschedule is pending, drop the given lock,
@@ -3568,8 +3580,7 @@ int cond_resched_lock(spinlock_t * lock)
 	if (need_resched()) {
 		_raw_spin_unlock(lock);
 		preempt_enable_no_resched();
-		set_current_state(TASK_RUNNING);
-		schedule();
+		__cond_resched();
 		spin_lock(lock);
 		return 1;
 	}

             reply	other threads:[~2004-09-14  9:17 UTC|newest]

Thread overview: 76+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-09-14  9:15 Ingo Molnar [this message]
2004-09-14  9:34 ` [printk] make console_conditional_schedule() __sched and use cond_resched() William Lee Irwin III
2004-09-14  9:38 ` [patch] preempt-lock-need-resched.patch, 2.6.9-rc2 Ingo Molnar
2004-09-14  9:51   ` [patch] sched: add cond_resched_softirq() Ingo Molnar
2004-09-14  9:57     ` [patch] sched: fix latency in random driver Ingo Molnar
2004-09-14 10:06       ` [patch] sched, ext3: fix scheduling latencies in ext3 Ingo Molnar
2004-09-14 10:13         ` [patch] sched, vfs: fix scheduling latencies in invalidate_inodes() Ingo Molnar
2004-09-14 10:19         ` [patch] sched, vfs: fix scheduling latencies in prune_dcache() and select_parent() Ingo Molnar
2004-09-14 10:25           ` [patch] sched, net: fix scheduling latencies in netstat Ingo Molnar
2004-09-14 10:44             ` [patch] sched, net: fix scheduling latencies in __release_sock Ingo Molnar
2004-09-14 10:50               ` [patch] sched, mm: fix scheduling latencies in copy_page_range() Ingo Molnar
2004-09-14 10:56                 ` [patch] sched, mm: fix scheduling latencies in unmap_vmas() Ingo Molnar
2004-09-14 10:59                 ` [patch] sched, mm: fix scheduling latencies in get_user_pages() Ingo Molnar
2004-09-14 11:02                   ` [patch] sched, mm: fix scheduling latencies in filemap_sync() Ingo Molnar
2004-09-14 11:06                     ` [patch] sched, tty: fix scheduling latencies in tty_io.c Ingo Molnar
2004-09-14 10:53                       ` Alan Cox
2004-09-14 12:00                         ` Ingo Molnar
2004-09-14 11:18                           ` Alan Cox
2004-09-14 12:27                             ` Ingo Molnar
2004-09-14 12:11                               ` Alan Cox
2004-09-14 11:08                       ` [patch] sched, pty: fix scheduling latencies in pty.c Ingo Molnar
2004-09-14 11:12                         ` [patch] might_sleep() additions to fs-writeback.c Ingo Molnar
2004-09-14 11:25                         ` [patch] fix keventd execution dependency Ingo Molnar
2004-09-15 22:18                           ` Rusty Russell
2004-09-14 11:28                       ` [patch] sched: fix scheduling latencies in mttr.c Ingo Molnar
2004-09-14 11:32                         ` [patch] sched: fix scheduling latencies in vgacon.c Ingo Molnar
2004-09-14 11:35                         ` [patch] sched: fix scheduling latencies in NTFS mount Ingo Molnar
2004-09-14 13:31                           ` Anton Altaparmakov
2004-09-14 11:42                         ` [patch] sched: fix scheduling latencies for !PREEMPT kernels Ingo Molnar
2004-09-14 12:55                           ` Nick Piggin
2004-09-14 13:22                             ` Ingo Molnar
2004-09-14 13:33                               ` Nick Piggin
2004-09-14 14:09                                 ` Andrea Arcangeli
2004-09-14 14:28                                   ` Nick Piggin
2004-09-14 15:03                                     ` Andrea Arcangeli
2004-09-14 18:05                                       ` Robert Love
2004-09-14 18:52                                         ` William Lee Irwin III
2004-09-14 19:02                                           ` Robert Love
2004-09-14 19:21                                             ` William Lee Irwin III
2004-09-14 19:19                                               ` Alan Cox
2004-09-15  0:22                                                 ` Lee Revell
2004-09-15  1:46                                                   ` William Lee Irwin III
2004-09-15  2:00                                                     ` Lee Revell
2004-09-15  2:36                                                       ` William Lee Irwin III
2004-09-15  2:59                                                         ` Lee Revell
2004-09-15 13:36                                                         ` Hans Reiser
2004-09-15 20:40                                                           ` William Lee Irwin III
2004-09-15  1:18                                                 ` William Lee Irwin III
2004-09-14 19:26                                               ` Robert Love
2004-09-14 21:06                                               ` William Lee Irwin III
2004-09-14 19:25                                             ` Andrea Arcangeli
2004-09-14 19:29                                               ` Robert Love
2004-09-14 19:34                                               ` William Lee Irwin III
2004-09-15  1:02                                       ` Lee Revell
2004-09-15  1:39                                         ` William Lee Irwin III
2004-09-15  2:11                                           ` Lee Revell
2004-09-15 11:17                                             ` Ingo Molnar
2004-09-15  9:56                                           ` Ingo Molnar
2004-09-15  9:57                                             ` William Lee Irwin III
2004-09-15 10:12                                               ` Ingo Molnar
2004-09-14 16:31                                   ` William Lee Irwin III
2004-09-14 16:39                                     ` Andrea Arcangeli
2004-09-14 14:54                                 ` Ingo Molnar
2004-09-14 22:55                                   ` Nick Piggin
2004-09-15  6:19                                     ` Ingo Molnar
2004-09-15  8:23                                       ` Nick Piggin
2004-09-15  8:43                                         ` Ingo Molnar
2004-09-15 10:09                                           ` William Lee Irwin III
2004-09-15 10:21                                             ` Ingo Molnar
2004-09-16  1:03                                           ` Nick Piggin
2004-09-16  6:14                                             ` Ingo Molnar
2004-09-15  0:35                                   ` Lee Revell
2004-09-14 13:25                         ` [patch] sched: fix scheduling latencies in mtrr.c Ingo Molnar
2004-09-14 13:15                           ` Alan Cox
2004-09-14 15:00                             ` Ingo Molnar
2004-09-14 18:22                           ` Zwane Mwaikambo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20040914091529.GA21553@elte.hu \
    --to=mingo@elte.hu \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox