From owner-freebsd-smp Mon Dec 2 23:40:57 1996 Return-Path: owner-smp Received: (from root@localhost) by freefall.freebsd.org (8.7.5/8.7.3) id XAA16889 for smp-outgoing; Mon, 2 Dec 1996 23:40:57 -0800 (PST) Received: from tfs.com (tfs.com [140.145.250.1]) by freefall.freebsd.org (8.7.5/8.7.3) with SMTP id XAA16880 for ; Mon, 2 Dec 1996 23:40:55 -0800 (PST) Received: from critter.tfs.com by tfs.com (smail3.1.28.1) with SMTP id m0vUpSo-0003vuC; Mon, 2 Dec 96 23:40 PST Received: from critter.tfs.com (localhost.phk.dk [127.0.0.1]) by critter.tfs.com (8.8.2/8.8.2) with ESMTP id IAA03917; Tue, 3 Dec 1996 08:42:04 +0100 (MET) To: Chris Csanady cc: freebsd-smp@freebsd.org Subject: Re: spin locks... In-reply-to: Your message of "Tue, 03 Dec 1996 00:54:40 CST." <199612030654.AAA12221@friley216.res.iastate.edu> Date: Tue, 03 Dec 1996 08:42:04 +0100 Message-ID: <3915.849598924@critter.tfs.com> From: Poul-Henning Kamp Sender: owner-smp@freebsd.org X-Loop: FreeBSD.org Precedence: bulk In message <199612030654.AAA12221@friley216.res.iastate.edu>, Chris Csanady wri tes: >Its something we could use, so I thought I'd give it a shot. I thought it >would make a nice first assembly project, right? Yeah.. sure. I have never >been so frustrated with something so obviously simple. > >When I try to link it into a test program, it segfaults. The only way I >could obtain predictable behavior was to take out the cmpxchg and lock. > >Could someone please point out my error here? > >.text > .align 2,0x90 >.globl _get_spinlock >_get_spinlock: > pushl %eax > pushl %ecx > pushl %edx > movl _smp_active, %eax > cmpl $0, %eax + je 4 -> jne 1f -> jmp 4 >1: movl 4(%esp), %edx > movl $1, %ecx >2: lock > cmpxchg %ecx, (%edx) I can't remember, that lock may be implied in the cmpxchg instruction... Check out the smplock() I wrote and see what I do. -> je 3f -> jmp 4 + jne 4 >3: cmpl %ecx, (%edx) + jne 2b > je 3b I'm sure not, but where do you want to go then ? -> jmp 2b >4: popl %edx > popl %ecx > popl %eax > ret > >--Chris Csanady > > > -- Poul-Henning Kamp | phk@FreeBSD.ORG FreeBSD Core-team. http://www.freebsd.org/~phk | phk@login.dknet.dk Private mailbox. whois: [PHK] | phk@tfs.com TRW Financial Systems, Inc. Power and ignorance is a disgusting cocktail.