Re: preemption when running in the kernel

From: Ingo Oeser
Date: Sat Nov 08 2003 - 08:04:24 EST


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi Frank,

[CC'ed lkml to avoid duplicate answers]

On Friday 07 November 2003 13:04, Frank Cusack wrote:
> (2.4 kernel)
>
> When a process is running in the kernel, can it be pre-empted at
> any time? (Unless you explicity disable preemption.) I think not,
> because wouldn't it be unsafe to grab a spinlock? Or does grabbing a
> spinlock disable preemption. I mean spin_lock(), not spin_lock_irqsave().

While having preemption disabled or while actually holding a spinlock,
preemption is disabled.

Disabling preemption is modifying a count, which must reach 0 again to
have preemption enabled and trigger an reschedule, if needed.

Think of it roughly as a "counter of reasons to not preempt". If there
are no reasons anymore, then we preempt.

> Secondly, can multiple processes be in the kernel at the same time? I
> think so, that's the reason for the fine grained locks instead of the BKL.
> Or do fine grained locks only serve to allow preemption.

Multiple threads can be in the kernel at the same time and even on
different CPUs. But one thread can be only on one CPU at any time.

Threads are parts of processes, so the same applies for processes, too.


Regards

Ingo Oeser

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)

iD8DBQE/rOlHU56oYWuOrkARAqz9AJ9bi71xchjKUJs8kysa6ePKpk13nwCeL1NB
2ti5dqrV6sQjDNbc/RqOItM=
=rb5C
-----END PGP SIGNATURE-----

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/