Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 24 Feb 2002 10:55:08 +1100 (EST)
From:      Bruce Evans <bde@zeta.org.au>
To:        Matthew Dillon <dillon@apollo.backplane.com>
Cc:        Terry Lambert <tlambert2@mindspring.com>, Alfred Perlstein <alfred@FreeBSD.ORG>, Bosko Milekic <bmilekic@unixdaemons.com>, Seigo Tanimura <tanimura@r.dl.itc.u-tokyo.ac.jp>, <current@FreeBSD.ORG>, John Baldwin <jhb@FreeBSD.ORG>
Subject:   Re: malloc_bucket() idea (was Re: How to fix malloc.)
Message-ID:  <20020224105118.L30818-100000@gamplex.bde.org>
In-Reply-To: <200202232312.g1NNCaH54765@apollo.backplane.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sat, 23 Feb 2002, Matthew Dillon wrote:

>     critical_enter() isn't much better then a mutex.  It can
>     be optimized to get rid of the inline cli & sti however.  Actually, it
>     can be optimized trivially for i386, all we have to do is check the
>     critical nesting count from the interrupt code and set the
>     interrupts-disabled bit in the returned (supervisor mode) frame.
>
>     critical_enter() and critical_exit() would then be nearly perfect.

My version of it does less than this.  I only use it to help implement
spinlocks.

Index: kern_switch.c
===================================================================
RCS file: /home/ncvs/src/sys/kern/kern_switch.c,v
retrieving revision 1.20
diff -u -2 -r1.20 kern_switch.c
--- kern_switch.c	11 Feb 2002 20:37:51 -0000	1.20
+++ kern_switch.c	13 Feb 2002 05:34:20 -0000
@@ -70,14 +70,21 @@
 }

-/* Critical sections that prevent preemption. */
+/*-
+ * Critical section handling.
+ * XXX doesn't belong here.
+ *
+ * Entering a critical section only blocks non-fast interrupts.
+ * critical_enter() is similar to splhigh() in a 2-level spl setup under
+ * old versions of FreeBSD.
+ *
+ * Exiting from all critical sections unblocks non-fast interrupts and runs
+ * the handlers of any that were blocked.  critical_exit() is similar to
+ * spl(old_level) in a 2-level spl setup under old versions of FreeBSD.
+ */
 void
 critical_enter(void)
 {
-	struct thread *td;

-	td = curthread;
-	if (td->td_critnest == 0)
-		td->td_savecrit = cpu_critical_enter();
-	td->td_critnest++;
+	curthread->td_critnest++;
 }

@@ -85,12 +92,7 @@
 critical_exit(void)
 {
-	struct thread *td;

-	td = curthread;
-	if (td->td_critnest == 1) {
-		td->td_critnest = 0;
-		cpu_critical_exit(td->td_savecrit);
-	} else
-		td->td_critnest--;
+	if (--curthread->td_critnest == 0 && (ipending | spending) != 0)
+		unpend();
 }

Bruce


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020224105118.L30818-100000>