summaryrefslogtreecommitdiff
path: root/sys/kern/init_sysctl.c
diff options
context:
space:
mode:
authorad <ad@NetBSD.org>2009-05-24 21:41:25 +0000
committerad <ad@NetBSD.org>2009-05-24 21:41:25 +0000
commitd991fcb3b6084e8abc162cd006cfe3ad32a3bbf3 (patch)
treea72683aa4722bcaccc1875447f3f65e8cd5a472c /sys/kern/init_sysctl.c
parent13573078f8c68c3135a250c496868137890c2edd (diff)
More changes to improve kern_descrip.c.
- Avoid atomics in more places. - Remove the per-descriptor mutex, and just use filedesc_t::fd_lock. It was only being used to synchronize close, and in any case we needed to take fd_lock to free the descriptor slot. - Optimize certain paths for the <NDFDFILE case. - Sprinkle more comments and assertions. - Cache more stuff in filedesc_t. - Fix numerous minor bugs spotted along the way. - Restructure how the open files array is maintained, for clarity and so that we can eliminate the membar_consumer() call in fd_getfile(). This is mostly syntactic sugar; the main functional change is that fd_nfiles now lives alongside the open file array. Some measurements with libmicro: - simple file syscalls are like close() are between 1 to 10% faster. - some nice improvements, e.g. poll(1000) which is ~50% faster.
Diffstat (limited to 'sys/kern/init_sysctl.c')
-rw-r--r--sys/kern/init_sysctl.c17
1 files changed, 7 insertions, 10 deletions
diff --git a/sys/kern/init_sysctl.c b/sys/kern/init_sysctl.c
index fc966b0fe17..c503a6e89ec 100644
--- a/sys/kern/init_sysctl.c
+++ b/sys/kern/init_sysctl.c
@@ -1,7 +1,7 @@
-/* $NetBSD: init_sysctl.c,v 1.163 2009/05/16 12:02:00 yamt Exp $ */
+/* $NetBSD: init_sysctl.c,v 1.164 2009/05/24 21:41:26 ad Exp $ */
/*-
- * Copyright (c) 2003, 2007, 2008 The NetBSD Foundation, Inc.
+ * Copyright (c) 2003, 2007, 2008, 2009 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: init_sysctl.c,v 1.163 2009/05/16 12:02:00 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: init_sysctl.c,v 1.164 2009/05/24 21:41:26 ad Exp $");
#include "opt_sysv.h"
#include "opt_compat_netbsd32.h"
@@ -1970,6 +1970,7 @@ sysctl_kern_file2(SYSCTLFN_ARGS)
size_t len, needed, elem_size, out_size;
int error, arg, elem_count;
fdfile_t *ff;
+ fdtab_t *dt;
if (namelen == 1 && name[0] == CTL_QUERY)
return (sysctl_query(SYSCTLFN_CALL(rnode)));
@@ -2089,20 +2090,18 @@ sysctl_kern_file2(SYSCTLFN_ARGS)
/* XXX Do we need to check permission per file? */
fd = p->p_fd;
mutex_enter(&fd->fd_lock);
- for (i = 0; i < fd->fd_nfiles; i++) {
- if ((ff = fd->fd_ofiles[i]) == NULL) {
+ dt = fd->fd_dt;
+ for (i = 0; i < dt->dt_nfiles; i++) {
+ if ((ff = dt->dt_ff[i]) == NULL) {
continue;
}
- mutex_enter(&ff->ff_lock);
if ((fp = ff->ff_file) == NULL) {
- mutex_exit(&ff->ff_lock);
continue;
}
if (len >= elem_size && elem_count > 0) {
mutex_enter(&fp->f_lock);
fill_file(&kf, fp, ff, i, p->p_pid);
mutex_exit(&fp->f_lock);
- mutex_exit(&ff->ff_lock);
mutex_exit(&fd->fd_lock);
error = dcopyout(l, &kf, dp, out_size);
mutex_enter(&fd->fd_lock);
@@ -2110,8 +2109,6 @@ sysctl_kern_file2(SYSCTLFN_ARGS)
break;
dp += elem_size;
len -= elem_size;
- } else {
- mutex_exit(&ff->ff_lock);
}
needed += elem_size;
if (elem_count > 0 && elem_count != INT_MAX)