public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Rusty Russell <rusty@rustcorp.com.au>
To: nigel@nrg.org
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH for 2.5] preemptible kernel
Date: Tue, 20 Mar 2001 19:43:50 +1100	[thread overview]
Message-ID: <m14fHk9-001PKgC@mozart> (raw)
In-Reply-To: Your message of "Wed, 14 Mar 2001 17:25:22 -0800." <Pine.LNX.4.05.10103141653350.3094-100000@cosmic.nrg.org>

In message <Pine.LNX.4.05.10103141653350.3094-100000@cosmic.nrg.org> you write:
> Kernel preemption is not allowed while spinlocks are held, which means
> that this patch alone cannot guarantee low preemption latencies.  But
> as long held locks (in particular the BKL) are replaced by finer-grained
> locks, this patch will enable lower latencies as the kernel also becomes
> more scalable on large SMP systems.

Hi Nigel,

	I can see three problems with this approach, only one of which
is serious.

The first is code which is already SMP unsafe is now a problem for
everyone, not just the 0.1% of SMP machines.  I consider this a good
thing for 2.5 though.

The second is that there are "manual" locking schemes which are used
in several places in the kernel which rely on non-preemptability;
de-facto spinlocks if you will.  I consider all these uses flawed: (1)
they are often subtly broken anyway, (2) they make reading those parts
of the code much harder, and (3) they break when things like this are
done.

The third is that preemtivity conflicts with the naive
quiescent-period approach proposed for module unloading in 2.5, and
useful for several other things (eg. hotplugging CPUs).  This method
relies on knowing that when a schedule() has occurred on every CPU, we
know noone is holding certain references.  The simplest example is a
single linked list: you can traverse without a lock as long as you
don't sleep, and then someone can unlink a node, and wait for a
schedule on every other CPU before freeing it.  The non-SMP case is a
noop.  See synchonize_kernel() below.

This, too, is soluble, but it means that synchronize_kernel() must
guarantee that each task which was running or preempted in kernel
space when it was called, has been non-preemtively scheduled before
synchronize_kernel() can exit.  Icky.

Thoughts?
Rusty.
--
Premature optmztion is rt of all evl. --DK

/* We could keep a schedule count for each CPU and make idle tasks
   schedule (some don't unless need_resched), but this scales quite
   well (eg. 64 processors, average time to wait for first schedule =
   jiffie/64.  Total time for all processors = jiffie/63 + jiffie/62...

   At 1024 cpus, this is about 7.5 jiffies.  And that assumes noone
   schedules early. --RR */
void synchronize_kernel(void)
{
	unsigned long cpus_allowed, policy, rt_priority;

	/* Save current state */
	cpus_allowed = current->cpus_allowed;
	policy = current->policy;
	rt_priority = current->rt_priority;

	/* Create an unreal time task. */
	current->policy = SCHED_FIFO;
	current->rt_priority = 1001 + sys_sched_get_priority_max(SCHED_FIFO);

	/* Make us schedulable on all CPUs. */
	current->cpus_allowed = (1UL<<smp_num_cpus)-1;
	
	/* Eliminate current cpu, reschedule */
	while ((current->cpus_allowed &= ~(1 << smp_processor_id())) != 0)
		schedule();

	/* Back to normal. */
	current->cpus_allowed = cpus_allowed;
	current->policy = policy;
	current->rt_priority = rt_priority;
}

  parent reply	other threads:[~2001-03-20  8:41 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-03-15  1:25 [PATCH for 2.5] preemptible kernel Nigel Gamble
2001-03-17 17:34 ` Pavel Machek
2001-03-19 21:01   ` Nigel Gamble
2001-03-20  8:43 ` Rusty Russell [this message]
2001-03-20  9:32   ` Keith Owens
2001-03-21  0:48     ` Nigel Gamble
2001-03-21  1:23       ` Keith Owens
2001-03-21  3:35         ` Nigel Gamble
2001-03-21  8:04           ` george anzinger
2001-03-21  9:04             ` Keith Owens
2001-03-21 14:32             ` Rusty Russell
2001-03-23 20:42               ` Nigel Gamble
2001-03-28 11:47             ` Dipankar Sarma
2001-03-21  9:19           ` Keith Owens
2001-03-21  9:41             ` David S. Miller
2001-03-21 10:05               ` Andrew Morton
2001-03-22  0:20                 ` Nigel Gamble
2001-03-21 10:57               ` george anzinger
2001-03-21 11:30                 ` David S. Miller
2001-03-21 17:07                   ` george anzinger
2001-03-21 18:18               ` Nigel Gamble
2001-03-21 22:25               ` Rusty Russell
2001-03-21 15:46             ` Andrea Arcangeli
2001-03-28 10:20           ` Dipankar Sarma
2001-03-28 20:51             ` george anzinger
2001-03-29  9:43               ` Dipankar Sarma
2001-03-30  6:32               ` Keith Owens
2001-03-21  0:24   ` Nigel Gamble
2001-03-30  0:26     ` Nigel Gamble
2001-03-30 20:11       ` Rusty Russell
2001-04-01  7:48         ` george anzinger
2001-04-01 21:13           ` Nigel Gamble
2001-04-02 19:56             ` george anzinger
2001-04-04 17:59               ` Rusty Russell
2001-04-01 21:07         ` Nigel Gamble
2001-04-04 17:51           ` Rusty Russell
2001-03-20 18:25 ` Roger Larsson
2001-03-20 22:06   ` Nigel Gamble
2001-03-20 22:27     ` george anzinger
  -- strict thread matches above, loose matches on Subject: below --
2001-04-06 23:52 Paul McKenney
2001-04-07  0:45 ` Andi Kleen
2001-04-07  1:25 Paul McKenney
2001-04-07 19:59 ` Rusty Russell

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=m14fHk9-001PKgC@mozart \
    --to=rusty@rustcorp.com.au \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nigel@nrg.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