patch-2.1.23 linux/include/asm-i386/smp_lock.h

Next file: linux/include/asm-i386/system.h
Previous file: linux/include/asm-i386/smp.h
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.1.22/linux/include/asm-i386/smp_lock.h linux/include/asm-i386/smp_lock.h
@@ -1,69 +1,50 @@
 #ifndef __I386_SMPLOCK_H
 #define __I386_SMPLOCK_H
 
-#ifdef __SMP__
+#ifndef __SMP__
 
-/*
- *	Locking the kernel 
- */
- 
-extern __inline void lock_kernel(void)
+#define lock_kernel()		do { } while(0)
+#define unlock_kernel()		do { } while(0)
+
+#else
+
+/* Locking the kernel */
+extern __inline__ void lock_kernel(void)
 {
-	unsigned long flags;
-	int proc = smp_processor_id();
+	int cpu = smp_processor_id();
 
-	save_flags(flags);
-	cli();
-	/* set_bit works atomic in SMP machines */
-	while(set_bit(0, (void *)&kernel_flag)) 
-	{
-		/*
-		 *	We just start another level if we have the lock 
-		 */
-		if (proc == active_kernel_processor)
-			break;
-		do 
-		{
-#ifdef __SMP_PROF__		
-			smp_spins[smp_processor_id()]++;
-#endif			
-			/*
-			 *	Doing test_bit here doesn't lock the bus 
-			 */
-			if (test_bit(proc, (void *)&smp_invalidate_needed))
-				if (clear_bit(proc, (void *)&smp_invalidate_needed))
-					local_flush_tlb();
-		}
-		while(test_bit(0, (void *)&kernel_flag));
-	}
-	/* 
-	 *	We got the lock, so tell the world we are here and increment
-	 *	the level counter 
-	 */
-	active_kernel_processor = proc;
-	kernel_counter++;
-	restore_flags(flags);
+	__asm__ __volatile__("
+	pushfl
+	cli
+	cmpl	$0, %0
+	jne	0f
+	movl	$0f, %%eax
+	jmp	__lock_kernel
+0:
+	incl	%0
+	popfl
+"	:
+	: "m" (current_set[cpu]->lock_depth), "d" (cpu)
+	: "ax", "memory");
 }
 
-extern __inline void unlock_kernel(void)
+extern __inline__ void unlock_kernel(void)
 {
-	unsigned long flags;
-	save_flags(flags);
-	cli();
-	/*
-	 *	If it's the last level we have in the kernel, then
-	 *	free the lock 
-	 */
-	if (kernel_counter == 0)
-		panic("Kernel counter wrong.\n"); /* FIXME: Why is kernel_counter sometimes 0 here? */
-	
-	if(! --kernel_counter) 
-	{
-		active_kernel_processor = NO_PROC_ID;
-		clear_bit(0, (void *)&kernel_flag);
-	}
-	restore_flags(flags);
+	__asm__ __volatile__("
+	pushfl
+	cli
+	decl	%0
+	jnz	1f
+	movb	%1, active_kernel_processor
+	lock
+	btrl	$0, kernel_flag
+1:
+	popfl
+"	: /* no outputs */
+	: "m" (current->lock_depth), "i" (NO_PROC_ID)
+	: "ax", "memory");
 }
 
-#endif
-#endif
+#endif /* __SMP__ */
+
+#endif /* __I386_SMPLOCK_H */

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen, slshen@lbl.gov