Module Name: src Committed By: ad Date: Sun May 24 21:41:44 UTC 2009
Modified Files: src/dist/ipf/ipsend: sock.c src/usr.bin/fstat: fstat.c Log Message: 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. To generate a diff of this commit: cvs rdiff -u -r1.14 -r1.15 src/dist/ipf/ipsend/sock.c cvs rdiff -u -r1.88 -r1.89 src/usr.bin/fstat/fstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/dist/ipf/ipsend/sock.c diff -u src/dist/ipf/ipsend/sock.c:1.14 src/dist/ipf/ipsend/sock.c:1.15 --- src/dist/ipf/ipsend/sock.c:1.14 Tue May 20 07:08:06 2008 +++ src/dist/ipf/ipsend/sock.c Sun May 24 21:41:44 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: sock.c,v 1.14 2008/05/20 07:08:06 darrenr Exp $ */ +/* $NetBSD: sock.c,v 1.15 2009/05/24 21:41:44 ad Exp $ */ /* * sock.c (C) 1995-1998 Darren Reed @@ -329,12 +329,21 @@ t = NULL; o = (struct file **)calloc(1, sizeof(*o) * (fd->fd_lastfile + 1)); +#if defined(__NetBSD_Version__) && __NetBSD__Version__ >= 599001200 if (KMCPY(o, fd->fd_ofiles, (fd->fd_lastfile + 1) * sizeof(*o)) == -1) { fprintf(stderr, "read(%#lx,%#lx,%lu) - u_ofile - failed\n", (u_long)fd->fd_ofiles, (u_long)o, (u_long)sizeof(*o)); goto finderror; } +#else + if (KMCPY(o, &fd->fd_dt->dt_ff, (fd->fd_lastfile + 1) * sizeof(*o)) == -1) + { + fprintf(stderr, "read(%#lx,%#lx,%lu) - u_ofile - failed\n", + (u_long)fd->fd_dt->dt_ff, (u_long)o, (u_long)sizeof(*o)); + goto finderror; + } +#endif f = (struct file *)calloc(1, sizeof(*f)); if (KMCPY(f, o[tfd], sizeof(*f)) == -1) { Index: src/usr.bin/fstat/fstat.c diff -u src/usr.bin/fstat/fstat.c:1.88 src/usr.bin/fstat/fstat.c:1.89 --- src/usr.bin/fstat/fstat.c:1.88 Sun Apr 12 06:36:12 2009 +++ src/usr.bin/fstat/fstat.c Sun May 24 21:41:44 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: fstat.c,v 1.88 2009/04/12 06:36:12 lukem Exp $ */ +/* $NetBSD: fstat.c,v 1.89 2009/05/24 21:41:44 ad Exp $ */ /*- * Copyright (c) 1988, 1993 @@ -39,7 +39,7 @@ #if 0 static char sccsid[] = "@(#)fstat.c 8.3 (Berkeley) 5/2/95"; #else -__RCSID("$NetBSD: fstat.c,v 1.88 2009/04/12 06:36:12 lukem Exp $"); +__RCSID("$NetBSD: fstat.c,v 1.89 2009/05/24 21:41:44 ad Exp $"); #endif #endif /* not lint */ @@ -313,6 +313,7 @@ int i; struct filedesc filed; struct cwdinfo cwdi; + struct fdtab dt; Uname = user_from_uid(p->p_uid, 0); Pid = p->p_pid; @@ -321,16 +322,20 @@ if (p->p_fd == 0 || p->p_cwdi == 0) return; if (!KVM_READ(p->p_fd, &filed, sizeof (filed))) { - warnx("can't read filedesc at %#llx for pid %d", (unsigned long long)p->p_fd, Pid); + warnx("can't read filedesc at %p for pid %d", (void *)(uintptr_t)p->p_fd, Pid); return; } if (!KVM_READ(p->p_cwdi, &cwdi, sizeof(cwdi))) { - warnx("can't read cwdinfo at %#llx for pid %d", (unsigned long long)p->p_cwdi, Pid); + warnx("can't read cwdinfo at %p for pid %d", (void *)(uintptr_t)p->p_cwdi, Pid); return; } - if (filed.fd_nfiles < 0 || filed.fd_lastfile >= filed.fd_nfiles || + if (!KVM_READ(filed.fd_dt, &dt, sizeof(dt))) { + warnx("can't read dtab at %p for pid %d", filed.fd_dt, Pid); + return; + } + if ((unsigned)filed.fd_lastfile >= dt.dt_nfiles || filed.fd_freefile > filed.fd_lastfile + 1) { - dprintf("filedesc corrupted at %#llx for pid %d", (unsigned long long)p->p_fd, Pid); + dprintf("filedesc corrupted at %p for pid %d", (void *)(uintptr_t)p->p_fd, Pid); return; } /* @@ -355,10 +360,10 @@ */ #define FPSIZE (sizeof (fdfile_t *)) ALLOC_OFILES(filed.fd_lastfile+1); - if (!KVM_READ(filed.fd_ofiles, ofiles, + if (!KVM_READ(&filed.fd_dt->dt_ff, ofiles, (filed.fd_lastfile+1) * FPSIZE)) { dprintf("can't read file structures at %p for pid %d", - filed.fd_ofiles, Pid); + &filed.fd_dt->dt_ff, Pid); return; } for (i = 0; i <= filed.fd_lastfile; i++) {