From owner-freebsd-arch Tue Jan 16 23:29:17 2001 Delivered-To: freebsd-arch@freebsd.org Received: from mailman.zeta.org.au (mailman.zeta.org.au [203.26.10.16]) by hub.freebsd.org (Postfix) with ESMTP id C1FDE37B400 for ; Tue, 16 Jan 2001 23:28:56 -0800 (PST) Received: from bde.zeta.org.au (bde.zeta.org.au [203.2.228.102]) by mailman.zeta.org.au (8.9.3/8.8.7) with ESMTP id SAA24533; Wed, 17 Jan 2001 18:28:37 +1100 Date: Wed, 17 Jan 2001 18:28:43 +1100 (EST) From: Bruce Evans X-Sender: bde@besplex.bde.org To: Kirk McKusick Cc: Alfred Perlstein , arch@FreeBSD.ORG Subject: Re: dynamic vs static sysctls? In-Reply-To: <200101152345.PAA22257@beastie.mckusick.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-arch@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG On Mon, 15 Jan 2001, Kirk McKusick wrote: > I have an example where sysctl is still useful. In my work on a > background version of fsck, I have used sysctl to allow me to > pass information into the kernel that I want to have updated in > the filesystem. In the case of lost blocks, there may be hundreds > or even thousands of blocks that need to be put back into the > bit maps. Each non-contiguous block is passed in separately > which results in hundreds or thousands of sysctl calls. I want > to do one call to sysctlnametomib (a new, but obviously trivial > function) to return the numeric mib, and then use that mib on all > the subsequent sysctl calls. That dramatically cuts down on the > time it takes to return the blocks since I do not have to translate > the same name repeatedly (which takes far longer than the block > release itself). I would think that this might be an issue for > any application that uses sysctl to get/set the same information > repeatedly. There is no reason why numeric mibs should be significantly faster than string mibs. Syscall overhead would dominate string lookup time if the implementation was even moderately efficient. However, out current implementation is inefficient for numeric mibs and worse for string mibs. The enclosed test program gives the following times on a Celeron522 for related lookups via getppid(), sysctl(), sysctlbyname() and open()/read()/close(). GETPPID: 1.3 usec/call SYSCTL: 8.6 usec/call SYSCTLBYNAME: 21.9 usec/call FS: 22.0 usec/call (reading /COPYRIGHT) FS: 34.5 usec/call (reading /proc/curproc/regs) getppid() isn't closely related, but it performs the same amount of useful work as the other operations -- it copies a single integer from the kernel to the application. --- #include #include #include #include main() { int fd; int hw_float; int i; size_t len; int mib[2]; for (i = 0; i < 1000000; ++i) { len = sizeof(hw_float); #ifdef GETPPID (void)getppid(); #endif #ifdef SYSCTL mib[0] = CTL_HW; mib[1] = HW_FLOATINGPT; if (sysctl(mib, 2, &hw_float, &len, (void *)0, 0) == -1) err(1, "sysctl"); #endif #ifdef SYSCTLBYNAME if (sysctlbyname("hw.floatingpoint", &hw_float, &len, (void *)0, 0) == -1) err(1, "sysctl"); #endif #ifdef FS if ((fd = open("/COPYRIGHT", 0)) == -1) err(1, "open"); if (read(fd, &hw_float, sizeof(hw_float)) != sizeof(hw_float)) err(1, "read"); if (close(fd) != 0) err(1, "close"); #endif } } --- Bruce To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-arch" in the body of the message