From owner-freebsd-smp Tue Dec 3 13:09:01 1996 Return-Path: owner-smp Received: (from root@localhost) by freefall.freebsd.org (8.7.5/8.7.3) id NAA11898 for smp-outgoing; Tue, 3 Dec 1996 13:09:01 -0800 (PST) Received: from friley216.res.iastate.edu (friley216.res.iastate.edu [129.186.78.216]) by freefall.freebsd.org (8.7.5/8.7.3) with ESMTP id NAA11893 for ; Tue, 3 Dec 1996 13:08:57 -0800 (PST) Received: from friley216.res.iastate.edu (loopback [127.0.0.1]) by friley216.res.iastate.edu (8.8.3/8.7.3) with ESMTP id PAA15610 for ; Tue, 3 Dec 1996 15:08:32 -0600 (CST) Message-Id: <199612032108.PAA15610@friley216.res.iastate.edu> X-Mailer: exmh version 1.6.9 8/22/96 cc: freebsd-smp@freebsd.org Subject: Finished locks.. In-reply-to: Your message of Tue, 03 Dec 1996 00:54:40 -0600. <199612030654.AAA12221@friley216.res.iastate.edu> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Tue, 03 Dec 1996 15:08:32 -0600 From: Chris Csanady Sender: owner-smp@freebsd.org X-Loop: FreeBSD.org Precedence: bulk For what it's worth, I have completed a simple implementation of spin locks. (However, I'm sure someone will tell me different.. :) Either way, it was nice to learn a bit of assembly. If these are not sufficient, how can I improve upon them? I'd like to move some of the locking around, and they would help. In particular, I am planning to move the global lock out into the syscalls, and perhaps create a seperate lock for the run queues and such. Then from there, we can we can reduce the graininess a bit. :) Anyway, I'd just like to thank all of you for helping me out. Chris .text /*********************************************************************** * void LOCK() * ----------------- * All registers preserved */ .align 2,0x90 .globl _LOCK _LOCK: pushl %eax pushl %ecx pushl %edx movl $_smp_active, %eax cmpl $0, %eax je 4f 1: movl 16(%esp), %edx movl $1, %ecx movl $0, %eax 2: lock cmpxchg %ecx, (%edx) jne 3f jmp 4f 3: cmpl %ecx, (%edx) je 3b jmp 2b 4: popl %edx popl %ecx popl %eax ret /*********************************************************************** * int TRY_LOCK() * ----------------- * reg %eax == 1 if success */ .align 2,0x90 .globl _TRY_LOCK _TRY_LOCK: pushl %ecx pushl %edx movl $_smp_active, %eax cmpl $0, %eax je 1f movl 12(%esp), %edx movl $1, %ecx movl $0, %eax lock cmpxchg %ecx, (%edx) jne 1f movl $1, %eax jmp 2f 1: movl $0, %eax 2: popl %edx popl %ecx ret /*********************************************************************** * void UNLOCK() * ----------------- * All registers preserved */ .align 2,0x90 .globl _UNLOCK _UNLOCK: pushl %ecx movl 8(%esp), %ecx movl $0, (%ecx) popl %ecx ret