Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/prg-localcount2]: src Restore all work from the former pgoyette-localcou...



details:   https://anonhg.NetBSD.org/src/rev/a80b91845e6f
branches:  prg-localcount2
changeset: 823510:a80b91845e6f
user:      pgoyette <pgoyette%NetBSD.org@localhost>
date:      Thu Apr 27 05:36:30 2017 +0000

description:
Restore all work from the former pgoyette-localcount branch (which is
now abandoned doe to cvs merge botch).

The branch now builds, and installs via anita.  There are still some
problems (cgd is non-functional and all atf tests time-out) but they
will get resolved soon.

diffstat:

 distrib/sets/lists/comp/mi                   |    6 +-
 share/man/man9/Makefile                      |    4 +-
 share/man/man9/devsw_attach.9                |   57 ++++-
 share/man/man9/localcount.9                  |  199 ++++++++++++++++++
 sys/arch/acorn26/ioc/arcpp.c                 |   18 +-
 sys/arch/acorn32/mainbus/fd.c                |  134 +++++++----
 sys/arch/acorn32/podulebus/asc.c             |   10 +-
 sys/arch/alpha/alpha/machdep.c               |   23 +-
 sys/arch/alpha/pci/mcpcia.c                  |   12 +-
 sys/arch/alpha/tc/ioasic.c                   |   10 +-
 sys/arch/amd64/amd64/machdep.c               |   36 ++-
 sys/arch/amiga/amiga/autoconf.c              |   25 +-
 sys/arch/amiga/amiga/machdep.c               |   19 +-
 sys/arch/amiga/dev/afsc.c                    |    9 +-
 sys/arch/amiga/dev/ahsc.c                    |   10 +-
 sys/arch/amiga/dev/atzsc.c                   |   10 +-
 sys/arch/amiga/dev/bppcsc.c                  |   10 +-
 sys/arch/amiga/dev/cbiiisc.c                 |   10 +-
 sys/arch/amiga/dev/drsc.c                    |   10 +-
 sys/arch/amiga/dev/fd.c                      |   98 +++++---
 sys/arch/amiga/dev/gtsc.c                    |   10 +-
 sys/arch/amiga/dev/mfc.c                     |  159 ++++++++++----
 sys/arch/amiga/dev/mgnsc.c                   |   10 +-
 sys/arch/amiga/dev/ms.c                      |   65 ++++-
 sys/arch/amiga/dev/ser.c                     |   41 +++-
 sys/arch/amiga/dev/wesc.c                    |   10 +-
 sys/arch/amiga/dev/zssc.c                    |   11 +-
 sys/arch/arc/dev/opms.c                      |   90 +++++++-
 sys/arch/arc/dev/pccons.c                    |  144 +++++++++++--
 sys/arch/arc/jazz/fd.c                       |   42 ++-
 sys/arch/arm/amlogic/amlogic_com.c           |   53 +++-
 sys/arch/arm/arm32/stubs.c                   |   23 +-
 sys/arch/arm/at91/at91dbgu.c                 |  136 ++++++++---
 sys/arch/arm/at91/at91usart.c                |  134 ++++++++---
 sys/arch/atari/atari/autoconf.c              |   20 +-
 sys/arch/atari/atari/machdep.c               |    9 +-
 sys/arch/atari/dev/md_root.c                 |    8 +-
 sys/arch/cesfic/cesfic/machdep.c             |   29 +-
 sys/arch/emips/include/disklabel.h           |    2 +-
 sys/arch/hp300/dev/dcm.c                     |   10 +-
 sys/arch/hp300/hp300/machdep.c               |   26 +-
 sys/arch/hppa/hppa/machdep.c                 |   16 +-
 sys/arch/i386/i386/dumpsys.c                 |   36 ++-
 sys/arch/luna68k/luna68k/machdep.c           |   18 +-
 sys/arch/mac68k/dev/zs_kgdb.c                |   12 +-
 sys/arch/mac68k/mac68k/machdep.c             |   18 +-
 sys/arch/mips/mips/mips_machdep.c            |   23 +-
 sys/arch/mvme68k/mvme68k/machdep.c           |   15 +-
 sys/arch/news68k/news68k/machdep.c           |   20 +-
 sys/arch/next68k/dev/zs_kgdb.c               |   12 +-
 sys/arch/next68k/next68k/machdep.c           |   17 +-
 sys/arch/sgimips/dev/zs_kgdb.c               |   11 +-
 sys/arch/sparc/dev/zs_kgdb.c                 |   11 +-
 sys/arch/sparc/sparc/machdep.c               |   15 +-
 sys/arch/sparc64/sparc64/machdep.c           |   16 +-
 sys/arch/sun2/dev/consinit.c                 |   12 +-
 sys/arch/sun2/dev/zs_kgdb.c                  |   12 +-
 sys/arch/sun2/sun2/machdep.c                 |   15 +-
 sys/arch/sun3/dev/zs_kgdb.c                  |   12 +-
 sys/arch/sun3/sun3/machdep.c                 |   16 +-
 sys/arch/sun3/sun3x/machdep.c                |   16 +-
 sys/arch/vax/vax/machdep.c                   |    8 +-
 sys/arch/x68k/include/cdefs.h                |    2 +-
 sys/arch/x68k/include/cpufunc.h              |    2 +-
 sys/arch/x68k/include/ieeefp.h               |    2 +-
 sys/arch/x68k/include/profile.h              |    2 +-
 sys/arch/x68k/include/setjmp.h               |    2 +-
 sys/arch/x68k/x68k/machdep.c                 |   18 +-
 sys/arch/xen/xen/xbdback_xenbus.c            |   16 +-
 sys/coda/coda_vfsops.c                       |   13 +-
 sys/compat/common/tty_60.c                   |   26 +-
 sys/compat/linux/arch/amd64/linux_machdep.c  |   36 +-
 sys/compat/linux/arch/i386/linux_machdep.c   |   23 +-
 sys/compat/linux/common/linux_ioctl.c        |   20 +-
 sys/dev/acpi/pckbc_acpi.c                    |   13 +-
 sys/dev/audio.c                              |   31 ++-
 sys/dev/cgd.c                                |  189 +++++++++++++----
 sys/dev/clockctl.c                           |   18 +-
 sys/dev/dkwedge/dk.c                         |    7 +-
 sys/dev/dm/device-mapper.c                   |    6 +-
 sys/dev/fss.c                                |   47 +++-
 sys/dev/ir/irframe_tty.c                     |    8 +-
 sys/dev/isa/fd.c                             |  106 ++++++--
 sys/dev/isa/isv.c                            |   73 ++++-
 sys/dev/isa/mcd.c                            |  129 +++++++---
 sys/dev/ld.c                                 |  140 ++++++++++--
 sys/dev/md.c                                 |   75 +++++-
 sys/dev/midi.c                               |   88 ++++++-
 sys/dev/mscp/mscp_disk.c                     |   29 ++-
 sys/dev/pad/pad.c                            |    6 +-
 sys/dev/pci/pci_usrreq.c                     |    6 +-
 sys/dev/pud/pud_dev.c                        |    7 +-
 sys/dev/putter/putter.c                      |    7 +-
 sys/dev/raidframe/rf_netbsdkintf.c           |   21 +-
 sys/dev/rndpseudo.c                          |    6 +-
 sys/dev/scsipi/cd.c                          |    7 +-
 sys/dev/scsipi/sd.c                          |    6 +-
 sys/dev/sysmon/sysmon.c                      |    6 +-
 sys/dev/usb/ucom.c                           |    6 +-
 sys/dev/usb/ulpt.c                           |    6 +-
 sys/dev/video.c                              |  222 +++++++++++++------
 sys/dev/vnd.c                                |  199 ++++++++++++++----
 sys/dev/wscons/wskbd.c                       |    6 +-
 sys/dev/wscons/wsmouse.c                     |    6 +-
 sys/external/bsd/ipf/netinet/ip_fil_netbsd.c |   10 +-
 sys/fs/adosfs/advfsops.c                     |   15 +-
 sys/fs/cd9660/cd9660_vfsops.c                |   14 +-
 sys/fs/filecorefs/filecore_vfsops.c          |   15 +-
 sys/fs/hfs/hfs_vfsops.c                      |   13 +-
 sys/fs/msdosfs/msdosfs_vfsops.c              |   19 +-
 sys/fs/nilfs/nilfs_vfsops.c                  |   12 +-
 sys/fs/ntfs/ntfs_vfsops.c                    |   11 +-
 sys/fs/sysvbfs/sysvbfs_vfsops.c              |   18 +-
 sys/fs/udf/udf_vfsops.c                      |   15 +-
 sys/fs/v7fs/v7fs_vfsops.c                    |   22 +-
 sys/kern/files.kern                          |    3 +-
 sys/kern/init_main.c                         |    7 +-
 sys/kern/kern_drvctl.c                       |    6 +-
 sys/kern/subr_autoconf.c                     |  110 +++++++++-
 sys/kern/subr_devsw.c                        |  297 +++++++++++++++++++++++---
 sys/kern/subr_localcount.c                   |  248 ++++++++++++++++++++++
 sys/kern/tty.c                               |    7 +-
 sys/kern/tty_ptm.c                           |    9 +-
 sys/kern/tty_pty.c                           |   37 ++-
 sys/kern/tty_tty.c                           |    6 +-
 sys/kern/vfs_mount.c                         |   38 ++-
 sys/miscfs/specfs/spec_vnops.c               |   27 +-
 sys/net/bpf.c                                |    6 +-
 sys/net/if_tap.c                             |    5 +-
 sys/net/npf/npf.c                            |    5 +-
 sys/net/ppp_tty.c                            |    9 +-
 sys/netsmb/smb_dev.c                         |    6 +-
 sys/opencrypto/cryptodev.c                   |    6 +-
 sys/rump/librump/rumpkern/Makefile.rumpkern  |    3 +-
 sys/rump/librump/rumpkern/rump.c             |    5 +-
 sys/rump/librump/rumpvfs/devnull.c           |    6 +-
 sys/rump/librump/rumpvfs/rumpblk.c           |    8 +-
 sys/sys/Makefile                             |    4 +-
 sys/sys/conf.h                               |   12 +-
 sys/sys/device.h                             |    9 +-
 sys/sys/localcount.h                         |   65 +++++
 sys/ufs/chfs/chfs_vfsops.c                   |   19 +-
 sys/ufs/ffs/ffs_vfsops.c                     |   26 +-
 sys/ufs/lfs/lfs_vfsops.c                     |   12 +-
 sys/uvm/uvm_device.c                         |   18 +-
 sys/uvm/uvm_swap.c                           |   14 +-
 146 files changed, 3720 insertions(+), 1188 deletions(-)

diffs (truncated from 13773 to 300 lines):

diff -r ca533b80d52e -r a80b91845e6f distrib/sets/lists/comp/mi
--- a/distrib/sets/lists/comp/mi        Wed Apr 26 08:36:32 2017 +0000
+++ b/distrib/sets/lists/comp/mi        Thu Apr 27 05:36:30 2017 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: mi,v 1.2125 2017/04/20 13:11:03 joerg Exp $
+#      $NetBSD: mi,v 1.2125.2.1 2017/04/27 05:36:30 pgoyette Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 ./etc/mtree/set.comp                           comp-sys-root
@@ -2873,6 +2873,7 @@
 ./usr/include/sys/ksyms.h                      comp-c-include
 ./usr/include/sys/ktrace.h                     comp-c-include
 ./usr/include/sys/lkm.h                                comp-obsolete           obsolete
+./usr/include/sys/localcount.h                 comp-c-include
 ./usr/include/sys/localedef.h                  comp-c-include
 ./usr/include/sys/lock.h                       comp-c-include
 ./usr/include/sys/lockf.h                      comp-c-include
@@ -10740,6 +10741,7 @@
 ./usr/share/man/cat9/le64enc.0                 comp-sys-catman         .cat
 ./usr/share/man/cat9/le64toh.0                 comp-sys-catman         .cat
 ./usr/share/man/cat9/linedisc.0                        comp-sys-catman         .cat
+./usr/share/man/cat9/localcount.0              comp-sys-catman         .cat
 ./usr/share/man/cat9/lock.0                    comp-sys-catman         .cat
 ./usr/share/man/cat9/locking.0                 comp-sys-catman         .cat
 ./usr/share/man/cat9/lockinit.0                        comp-sys-catman         .cat
@@ -18181,6 +18183,7 @@
 ./usr/share/man/html9/le64enc.html             comp-sys-htmlman        html
 ./usr/share/man/html9/le64toh.html             comp-sys-htmlman        html
 ./usr/share/man/html9/linedisc.html            comp-sys-htmlman        html
+./usr/share/man/html9/localcount.html          comp-sys-htmlman        html
 ./usr/share/man/html9/lock.html                        comp-sys-htmlman        html
 ./usr/share/man/html9/locking.html             comp-sys-htmlman        html
 ./usr/share/man/html9/lockinit.html            comp-sys-htmlman        html
@@ -25776,6 +25779,7 @@
 ./usr/share/man/man9/le64enc.9                 comp-sys-man            .man
 ./usr/share/man/man9/le64toh.9                 comp-sys-man            .man
 ./usr/share/man/man9/linedisc.9                        comp-sys-man            .man
+./usr/share/man/man9/localcount.9              comp-sys-man            .man
 ./usr/share/man/man9/lock.9                    comp-sys-man            .man
 ./usr/share/man/man9/locking.9                 comp-sys-man            .man
 ./usr/share/man/man9/lockinit.9                        comp-sys-man            .man
diff -r ca533b80d52e -r a80b91845e6f share/man/man9/Makefile
--- a/share/man/man9/Makefile   Wed Apr 26 08:36:32 2017 +0000
+++ b/share/man/man9/Makefile   Thu Apr 27 05:36:30 2017 +0000
@@ -1,4 +1,4 @@
-#       $NetBSD: Makefile,v 1.409 2017/04/15 13:52:51 kamil Exp $
+#       $NetBSD: Makefile,v 1.409.2.1 2017/04/27 05:36:31 pgoyette Exp $
 
 #      Makefile for section 9 (kernel function and variable) manual pages.
 
@@ -32,7 +32,7 @@
        kcpuset.9 kernhist.9 klua_lock.9 klua_mod_register.9 kmem.9 kpause.9 \
        kfilter_register.9 knote.9 \
        kprintf.9 kthread.9 linedisc.9 lock.9 locking.9 log.9 ltsleep.9 \
-       LWP_CACHE_CREDS.9 \
+       localcount.9 LWP_CACHE_CREDS.9 \
        makeiplcookie.9 \
        malloc.9 mb.9 mbuf.9 mca.9 memcmp.9 memcpy.9 memoryallocators.9 \
        memmove.9 memset.9 \
diff -r ca533b80d52e -r a80b91845e6f share/man/man9/devsw_attach.9
--- a/share/man/man9/devsw_attach.9     Wed Apr 26 08:36:32 2017 +0000
+++ b/share/man/man9/devsw_attach.9     Thu Apr 27 05:36:30 2017 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: devsw_attach.9,v 1.2 2015/05/14 13:59:15 wiz Exp $
+.\"    $NetBSD: devsw_attach.9,v 1.2.6.1 2017/04/27 05:36:31 pgoyette Exp $
 .\"
 .\" Copyright (c) 2015 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -27,16 +27,20 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd May 13, 2015
+.Dd July 17, 2016
 .Dt DEVSW_ATTACH 9
 .Os
 .Sh NAME
 .Nm devsw_attach ,
 .Nm devsw_detach ,
 .Nm bdevsw_lookup ,
+.Nm bdevsw_lookup_acquire ,
 .Nm cdevsw_lookup ,
+.Nm cdevsw_lookup_acquire ,
 .Nm bdevsw_lookup_major ,
-.Nm cdevsw_lookup_major
+.Nm cdevsw_lookup_major,
+.Nm bdevsw_release ,
+.Nm cdevsw_release
 .Nd character and block device switch functions
 .Sh SYNOPSIS
 .In sys/conf.h
@@ -57,10 +61,26 @@
 .Fo bdevsw_lookup
 .Fa "dev_t dev"
 .Fc
+.Ft "const struct bdevsw *"
+.Fo bdevsw_lookup_acquire
+.Fa "dev_t dev"
+.Fc
+.Ft "void"
+.Fo bdevsw_release
+.Fa "const struct bdevsw *bdev"
+.Fc
 .Ft "const struct cdevsw *"
 .Fo cdevsw_lookup
 .Fa "dev_t dev"
 .Fc
+.Ft "const struct cdevsw *"
+.Fo cdevsw_lookup_acquire
+.Fa "dev_t dev"
+.Fc
+.Ft "void"
+.Fo cdevsw_release
+.Fa "const struct cdevsw *cdev"
+.Fc
 .Ft devmajor_t
 .Fo bdevsw_lookup_major
 .Fa "const struct bdevsw *bdev"
@@ -129,17 +149,38 @@
 structures.
 .Fn devsw_detach
 should be called before a loaded device driver is unloaded.
+For loadable drivers,
+.Fn devsw_detach
+will wait until the device's reference count is zero (see
+.Fn bdevsw_release
+and
+.Fn cdevsw_release
+below) before returning.
 .Pp
 The
-.Fn bdevsw_lookup
+.Fn bdevsw_lookup ,
+.Fn bdevsw_lookup_acquire ,
+.Fn cdevsw_lookup ,
 and
-.Fn cdevsw_lookup
+.Fn cdevsw_lookup_acquire
 functions return
 .Em "const struct bdevsw *"
 and
 .Em "const struct cdevsw *"
 for the given
 .Em dev .
+The
+.Fn bdevsw_lookup_acquire
+and
+.Fn cdevsw_lookup_acquire
+functions will additionally increment a reference count for loadable
+drivers.
+Callers must invoke
+.Fn bdevsw_release
+or
+.Fn cdevsw_release
+to decrement the reference counter when access to the device is no longer
+needed.
 .Pp
 The
 .Fn bdevsw_lookup_major
@@ -160,9 +201,11 @@
 Otherwise they return an error value.
 .Pp
 In case of failure,
-.Fn bdevsw_lookup
+.Fn bdevsw_lookup ,
+.Fn bdevsw_lookup_acquire ,
+.Fn cdevsw_lookup ,
 and
-.Fn cdevsw_lookup
+.Fn cdevsw_lookup_acquire
 return the
 .Dv NULL
 value.
diff -r ca533b80d52e -r a80b91845e6f share/man/man9/localcount.9
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/share/man/man9/localcount.9       Thu Apr 27 05:36:30 2017 +0000
@@ -0,0 +1,199 @@
+.\"    $NetBSD: localcount.9,v 1.1.6.1 2017/04/27 05:36:31 pgoyette Exp $
+.\"
+.\" Copyright (c) 2016
+.\" All rights reserved.
+.\"
+.\" This code is derived from software contributed to The NetBSD Foundation
+.\" by Taylor R. Campbell.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in the
+.\"    documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+.\" POSSIBILITY OF SUCH DAMAGE.
+.\"
+.Dd December 8, 2016
+.Dt LOCALCOUNT 9
+.Os
+.Sh NAME
+.Nm localcount ,
+.Nm localcount_init ,
+.Nm localcount_fini ,
+.Nm localcount_acquire ,
+.Nm localcount_release ,
+.Nm localcount_drain
+.Sh SYNOPSIS
+.In sys/localcount.h
+.Ft int
+.Fn localcount_init "struct localcount *lc"
+.Ft void
+.Fn localcount_fini "struct localcount *lc"
+.Ft void
+.Fn localcount_acquire "struct localcount *lc"
+.Ft void
+.Fn localcount_release "struct localcount *lc" "struct kcondvar *cv" \
+"struct kmutex *mtx"
+.Ft void
+.Fn localcount_drain "struct localcount *lc" "struct kcondvar *cv" \
+"struct kmutex *mtx"
+.Sh DESCRIPTION
+Localcounts are used in the kernel to implement a medium-weight reference
+counting mechanism.
+During normal operations, localcounts do not need the interprocessor
+synchronization associated with
+.Xr atomic_ops 3
+atomic memory operations, and (unlike
+.Xr psref 9 )
+.Nm
+references can be held across sleeps and can migrate between CPUs.
+Draining a
+.Nm localcount
+requires more expensive interprocessor synchronization than
+.Xr atomic_ops 3
+(similar to
+.Xr psref 9 ) .
+And
+.Nm
+references require eight bytes of memory per object per-CPU, significantly
+more than
+.Xr atomic_ops 3
+and almost always more than
+.Xr psref 9 .
+.Pp
+As a rough heuristic,
+.Nm
+should be used for classes of objects of which there are perhaps a few dozen
+instances (such as
+.Xr autoconf 9
+devices) but not thousands of instances (such as
+network flows) and on which there may be a mixture of long-term I/O waits,
+such as xyzread for a device xyz(4), and short-term fast operations, such as
+.Dv xyzioctl(IOC_READ_A_CPU_REG) .
+.Pp
+Currently,
+.Nm
+is used within the autoconfigure (
+.Xr autoconf 9 )
+and character and block device switch (
+.Xr cdevsw_attach 9 )
+subsystems.
+.Sh FUNCTIONS
+.Bl -tag -width abcd
+.It Fn localcount_init "lc"
+.Pp
+Dynamically initialize localcount
+.Ar lc
+for use.
+.Pp
+No other operations can be performed on a localcount until it has been
+initialized.
+.It Fn localcount_fini "lc"
+.Pp
+Release resources used by localcount
+.Ar lc .
+The caller must have already called
+.Fn localcount_drain .
+The localcount may not be used after
+.Fn localcount_fini
+has been called until it has been re-initialized by
+.Fn localcount_init .
+.It Fn localcount_acquire "lc"
+.Pp
+Acquire a reference to the localcount
+.Ar lc .
+.It Fn localcount_release "lc" "cv" "mtx"
+.Pp
+Release a reference to the localcount
+.Ar lc .
+If the localcount is currently being drained, the mutex



Home | Main Index | Thread Index | Old Index