From owner-freebsd-current Fri Dec 8 17:37: 5 2000 From owner-freebsd-current@FreeBSD.ORG Fri Dec 8 17:37:03 2000 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from earth.backplane.com (placeholder-dcat-1076843399.broadbandoffice.net [64.47.83.135]) by hub.freebsd.org (Postfix) with ESMTP id 481FA37B400; Fri, 8 Dec 2000 17:37:02 -0800 (PST) Received: (from dillon@localhost) by earth.backplane.com (8.11.1/8.9.3) id eB91b2w25635; Fri, 8 Dec 2000 17:37:02 -0800 (PST) (envelope-from dillon) Date: Fri, 8 Dec 2000 17:37:02 -0800 (PST) From: Matt Dillon Message-Id: <200012090137.eB91b2w25635@earth.backplane.com> To: Mike Smith Cc: Julian Elischer , John Baldwin , current@FreeBSD.ORG Subject: Re: __asm help.. References: <200012082356.eB8NukF02878@mass.osd.bsdi.com> Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG : :> :> Since all I WANT to do is :> pushf :> disable intr :> fiddle :> popf (chache hit) :> :> I am annoyed by the fact that I have all those extra bus cycles going on. :> I can live with it for development but it still annoys me. : :You haven't yet explained how you plan to disable interrupts on the other :CPUs... : :-- :... every activity meets with opposition, everyone who acts has his Julian, I would recommend using the cmpxchgl instruction to implement atomic operations. Look at /usr/src/sys/i386/i386/mplock.s for an example. You will be in much better shape if you can avoid cli/sti (as Mike points out, it doesn't work across cpu's). mplock.s already has basic MP-compatible lock recursion and should provide a ready example on how you need to do the locking. There is a serious issue you need to consider when implementing an SMP-capable lock, and that is cpu-cpu synchronization. In order to synchronize an operation across multiple cpu's on IA32 you have to use the 'lock;' instruction prefix. Typically, the cmpxchgl must be locked. However, you only need to lock it when there is possible contention.. when you are aquiring the lock. You do not need to lock it when you are releasing the lock. If your assembly gets too complex, just make the assembly a subroutine call. Believe me, subroutine overhead is *nothing* compared to bus locking overhead. For that matter, the cli/sti alone will have more overhead then a subroutine call. Just write it in assembly and forget about trying to use the C __asm() directive. You'll be happier. -Matt To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message