From owner-freebsd-hackers Sat Mar 18 12:31:36 2000 Delivered-To: freebsd-hackers@freebsd.org Received: from rover.village.org (rover.village.org [204.144.255.49]) by hub.freebsd.org (Postfix) with ESMTP id F0BAE37B866 for ; Sat, 18 Mar 2000 12:31:32 -0800 (PST) (envelope-from imp@harmony.village.org) Received: from harmony.village.org (harmony.village.org [10.0.0.6]) by rover.village.org (8.9.3/8.9.3) with ESMTP id NAA10789 for ; Sat, 18 Mar 2000 13:31:31 -0700 (MST) (envelope-from imp@harmony.village.org) Received: from harmony.village.org (localhost.village.org [127.0.0.1]) by harmony.village.org (8.9.3/8.8.3) with ESMTP id NAA97975 for ; Sat, 18 Mar 2000 13:31:28 -0700 (MST) Message-Id: <200003182031.NAA97975@harmony.village.org> To: hackers@freebsd.org Subject: splFoo() question Date: Sat, 18 Mar 2000 13:31:28 -0700 From: Warner Losh Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG I'd like to be able to do some simple spl locking in a driver that I'm writing. While I could go the splhigh() route, I'm concerned that spending lots of time at splhigh could cause problems, and some of my critical sections look to be very expensive. They only need protection against the card itself, not against the entire system. It just seems to be an overly large hammer. In addition to the driver I'm working on now, I've watned to do this in the pccard system so that we block interrupts for the cards when we're mucking around with the pccard bridge chipset on eject events. Right now, I'm using splhigh() for that, but that strikes me as excessive. I've wanted to do something like this for a long time, so I thought I'd spend some time diving down into the spl code and digging around. Always a dangerous thing to do, I know. My first thought was to use splx, but that's for lowering the spl (eg clearing bits) rather than raising it. So instead, I'd like to have a code that looks like: s = splirq(n); ... splx(s); in my code. A nieve implementation would be static __inline int splirq(int n) { int oldcpl; oldcpl = cpl; cpl |= (1 << n); return oldcpl; } This strikes me rather dangerous, machine dependent, and making unwise assumptions. It wouldn't work on MP. I'm sure that there are lots of other reasons that this won't work which aren't immediately obvious... Except for shift vs mask differences, this looks identical to the splq code in the UP case. I also notice that splq doesn't appear in the spl(9) man page and thus might disappear in the future. I further notice that it appears to be a i386 only routine, appearing only in: i386/include/lock.h i386/isa/intr_machdep.c i386/isa/intr_machdep.h i386/isa/ipl_funcs.c There's got to be a simple, MI way to do things like this, but I'm not sure that I'm seeing any. Warner To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message