From 7cd8d145ef938700efebd9fc85a6c81db0275869 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Sun, 4 Jun 2006 21:09:50 +0000 Subject: [PATCH] Remove LWKT reader-writer locks (kern/lwkt_rwlock.c). Remove lwkt_wait queues (only RW locks used them). Convert remaining uses of RW locks to LOCKMGR locks. In recent months lockmgr locks have been simplified to the point where we no longer need a lighter-weight fully blocking lock. The removal also simplifies lwkt_schedule() in that it no longer needs a special case to deal with wait lists. --- sys/amd64/amd64/genassym.c | 4 +- sys/conf/files | 3 +- sys/dev/acpica5/Osd/OsdSynch.c | 33 +++--- sys/dev/acpica5/acpi_ec.c | 15 +-- sys/dev/drm/drm_os_freebsd.h | 12 +- sys/dev/raid/aac/aacvar.h | 10 +- sys/dev/raid/ips/ips.c | 14 +-- sys/dev/raid/ips/ips.h | 5 +- sys/dev/raid/ips/ips_disk.c | 6 +- sys/dev/raid/ips/ips_ioctl.c | 8 +- sys/dev/raid/ips/ips_pci.c | 4 +- sys/i386/i386/genassym.c | 4 +- sys/kern/lwkt_rwlock.c | 164 --------------------------- sys/kern/lwkt_thread.c | 150 ++---------------------- sys/kern/lwkt_token.c | 4 +- sys/netproto/smb/smb_subr.h | 3 +- sys/platform/pc32/i386/genassym.c | 4 +- sys/platform/vkernel/i386/genassym.c | 4 +- sys/sys/thread.h | 41 +------ 19 files changed, 70 insertions(+), 418 deletions(-) delete mode 100644 sys/kern/lwkt_rwlock.c diff --git a/sys/amd64/amd64/genassym.c b/sys/amd64/amd64/genassym.c index 866dfdefe8..72b6dd6112 100644 --- a/sys/amd64/amd64/genassym.c +++ b/sys/amd64/amd64/genassym.c @@ -35,7 +35,7 @@ * * from: @(#)genassym.c 5.11 (Berkeley) 5/10/91 * $FreeBSD: src/sys/i386/i386/genassym.c,v 1.86.2.3 2002/03/03 05:42:49 nyan Exp $ - * $DragonFly: src/sys/amd64/amd64/Attic/genassym.c,v 1.10 2006/04/30 17:22:13 dillon Exp $ + * $DragonFly: src/sys/amd64/amd64/Attic/genassym.c,v 1.11 2006/06/04 21:09:44 dillon Exp $ */ #include @@ -93,8 +93,6 @@ ASSYM(TDF_RUNNING, TDF_RUNNING); ASSYM(MP_FREE_LOCK, MP_FREE_LOCK); #endif -ASSYM(RW_OWNER, offsetof(struct lwkt_rwlock, rw_owner)); - ASSYM(TDPRI_CRIT, TDPRI_CRIT); ASSYM(TDPRI_INT_SUPPORT, TDPRI_INT_SUPPORT); diff --git a/sys/conf/files b/sys/conf/files index 70bdeb5d84..185055b4e9 100644 --- a/sys/conf/files +++ b/sys/conf/files @@ -1,5 +1,5 @@ # $FreeBSD: src/sys/conf/files,v 1.340.2.137 2003/06/04 17:10:30 sam Exp $ -# $DragonFly: src/sys/conf/files,v 1.126 2006/05/29 03:57:16 dillon Exp $ +# $DragonFly: src/sys/conf/files,v 1.127 2006/06/04 21:09:45 dillon Exp $ # # The long compile-with and dependency lines are required because of # limitations in config: backslash-newline doesn't work in strings, and @@ -537,7 +537,6 @@ kern/lwkt_thread.c standard kern/lwkt_ipiq.c standard kern/lwkt_token.c standard kern/lwkt_msgport.c standard -kern/lwkt_rwlock.c standard kern/lwkt_serialize.c standard kern/lwkt_caps.c standard kern/kern_spinlock.c standard diff --git a/sys/dev/acpica5/Osd/OsdSynch.c b/sys/dev/acpica5/Osd/OsdSynch.c index 0be7f28b2a..3d9907af76 100644 --- a/sys/dev/acpica5/Osd/OsdSynch.c +++ b/sys/dev/acpica5/Osd/OsdSynch.c @@ -25,7 +25,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/acpica/Osd/OsdSynch.c,v 1.21 2004/05/05 20:07:52 njl Exp $ - * $DragonFly: src/sys/dev/acpica5/Osd/OsdSynch.c,v 1.6 2005/10/30 04:20:49 y0netan1 Exp $ + * $DragonFly: src/sys/dev/acpica5/Osd/OsdSynch.c,v 1.7 2006/06/04 21:09:48 dillon Exp $ */ /* @@ -38,6 +38,7 @@ #include #include #include +#include #include #include @@ -345,15 +346,12 @@ AcpiOsSignalSemaphore(ACPI_HANDLE Handle, UINT32 Units) ACPI_STATUS AcpiOsCreateLock(ACPI_HANDLE *OutHandle) { - lwkt_rwlock_t lock; + struct lock *lock; if (OutHandle == NULL) return (AE_BAD_PARAMETER); - MALLOC(lock, lwkt_rwlock_t, sizeof(*lock), M_ACPISEM, M_INTWAIT | M_ZERO); - if (lock == NULL) - return (AE_NO_MEMORY); - - lwkt_rwlock_init(lock); + lock = malloc(sizeof(*lock), M_ACPISEM, M_INTWAIT|M_ZERO); + lockinit(lock, "oslck", 0, 0); *OutHandle = (ACPI_HANDLE)lock; return (AE_OK); } @@ -361,11 +359,10 @@ AcpiOsCreateLock(ACPI_HANDLE *OutHandle) void AcpiOsDeleteLock (ACPI_HANDLE Handle) { - lwkt_rwlock_t lock = (lwkt_rwlock_t)Handle; + struct lock *lock; - if (Handle == NULL) - return; - lwkt_rwlock_uninit(lock); + if ((lock = (struct lock *)Handle) != NULL) + free(lock, M_ACPISEM); } /* @@ -376,21 +373,19 @@ AcpiOsDeleteLock (ACPI_HANDLE Handle) void AcpiOsAcquireLock (ACPI_HANDLE Handle, UINT32 Flags) { - lwkt_rwlock_t lock = (lwkt_rwlock_t)Handle; + struct lock *lock; - if (Handle == NULL) - return; - lwkt_exlock(lock, "acpi1"); + if ((lock = (struct lock *)Handle) != NULL) + lockmgr(lock, LK_EXCLUSIVE|LK_RETRY); } void AcpiOsReleaseLock (ACPI_HANDLE Handle, UINT32 Flags) { - lwkt_rwlock_t lock = (lwkt_rwlock_t)Handle; + struct lock *lock; - if (Handle == NULL) - return; - lwkt_exunlock(lock); + if ((lock = (struct lock *)Handle) != NULL) + lockmgr(lock, LK_RELEASE); } #ifdef notyet diff --git a/sys/dev/acpica5/acpi_ec.c b/sys/dev/acpica5/acpi_ec.c index 362f71111a..fb5c171916 100644 --- a/sys/dev/acpica5/acpi_ec.c +++ b/sys/dev/acpica5/acpi_ec.c @@ -26,7 +26,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/acpica/acpi_ec.c,v 1.51 2004/05/30 20:08:23 phk Exp $ - * $DragonFly: src/sys/dev/acpica5/acpi_ec.c,v 1.6 2005/10/30 04:41:15 dillon Exp $ + * $DragonFly: src/sys/dev/acpica5/acpi_ec.c,v 1.7 2006/06/04 21:09:47 dillon Exp $ */ /****************************************************************************** * @@ -138,7 +138,7 @@ *****************************************************************************/ /* * $FreeBSD: src/sys/dev/acpica/acpi_ec.c,v 1.51 2004/05/30 20:08:23 phk Exp $ - * $DragonFly: src/sys/dev/acpica5/acpi_ec.c,v 1.6 2005/10/30 04:41:15 dillon Exp $ + * $DragonFly: src/sys/dev/acpica5/acpi_ec.c,v 1.7 2006/06/04 21:09:47 dillon Exp $ * */ @@ -149,6 +149,7 @@ #include #include #include +#include #include #include @@ -273,7 +274,7 @@ struct acpi_ec_softc { int ec_glk; int ec_glkhandle; - struct lwkt_rwlock ec_rwlock; + struct lock ec_lock; }; /* @@ -304,13 +305,13 @@ EcLock(struct acpi_ec_softc *sc) ACPI_STATUS status = AE_OK; /* Always acquire this EC's mutex. */ - lwkt_exlock(&sc->ec_rwlock, "acpi2"); + lockmgr(&sc->ec_lock, LK_EXCLUSIVE|LK_RETRY); /* If _GLK is non-zero, also acquire the global lock. */ if (sc->ec_glk) { status = AcpiAcquireGlobalLock(EC_LOCK_TIMEOUT, &sc->ec_glkhandle); if (ACPI_FAILURE(status)) - lwkt_exunlock(&sc->ec_rwlock); + lockmgr(&sc->ec_lock, LK_RELEASE); } return (status); @@ -321,7 +322,7 @@ EcUnlock(struct acpi_ec_softc *sc) { if (sc->ec_glk) AcpiReleaseGlobalLock(sc->ec_glkhandle); - lwkt_exunlock(&sc->ec_rwlock); + lockmgr(&sc->ec_lock, LK_RELEASE); } static uint32_t EcGpeHandler(void *Context); @@ -549,7 +550,7 @@ acpi_ec_attach(device_t dev) params = acpi_get_private(dev); sc->ec_dev = dev; sc->ec_handle = acpi_get_handle(dev); - lwkt_rwlock_init(&sc->ec_rwlock); + lockinit(&sc->ec_lock, "eclock", 0, 0); /* Retrieve previously probed values via device ivars. */ sc->ec_glk = params->glk; diff --git a/sys/dev/drm/drm_os_freebsd.h b/sys/dev/drm/drm_os_freebsd.h index 6568382bb5..b2181da478 100644 --- a/sys/dev/drm/drm_os_freebsd.h +++ b/sys/dev/drm/drm_os_freebsd.h @@ -1,6 +1,6 @@ /* * $FreeBSD: src/sys/dev/drm/drm_os_freebsd.h,v 1.10.2.1 2003/04/26 07:05:28 anholt Exp $ - * $DragonFly: src/sys/dev/drm/Attic/drm_os_freebsd.h,v 1.16 2006/05/16 12:34:15 sephe Exp $ + * $DragonFly: src/sys/dev/drm/Attic/drm_os_freebsd.h,v 1.17 2006/06/04 21:09:49 dillon Exp $ */ #include #include @@ -95,11 +95,11 @@ #else #define DRM_CURPROC curthread #define DRM_STRUCTPROC struct thread -#define DRM_SPINTYPE struct lwkt_rwlock -#define DRM_SPININIT(l,name) lwkt_rwlock_init(&l) +#define DRM_SPINTYPE struct lock +#define DRM_SPININIT(l,name) lockinit(&l, name, 0, 0) #define DRM_SPINUNINIT(l) -#define DRM_SPINLOCK(l) lwkt_exlock(l, "drm") -#define DRM_SPINUNLOCK(u) lwkt_exunlock(u); +#define DRM_SPINLOCK(l) lockmgr(l, LK_EXCLUSIVE|LK_RETRY) +#define DRM_SPINUNLOCK(u) lockmgr(u, LK_RELEASE); #define DRM_CURRENTPID curthread->td_proc->p_pid #endif @@ -108,7 +108,7 @@ * code for that is not yet written */ #define DRMFILE void * #define DRM_IOCTL_ARGS dev_t kdev, u_long cmd, caddr_t data, int flags, DRM_STRUCTPROC *p, DRMFILE filp -#define DRM_LOCK lockmgr(&dev->dev_lock, LK_EXCLUSIVE) +#define DRM_LOCK lockmgr(&dev->dev_lock, LK_EXCLUSIVE | LK_RETRY) #define DRM_UNLOCK lockmgr(&dev->dev_lock, LK_RELEASE) #define DRM_SUSER(td) suser(td) #define DRM_TASKQUEUE_ARGS void *arg, int pending diff --git a/sys/dev/raid/aac/aacvar.h b/sys/dev/raid/aac/aacvar.h index c98fdb0003..81a368dd4f 100644 --- a/sys/dev/raid/aac/aacvar.h +++ b/sys/dev/raid/aac/aacvar.h @@ -27,7 +27,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/aac/aacvar.h,v 1.4.2.7 2003/04/08 13:22:08 scottl Exp $ - * $DragonFly: src/sys/dev/raid/aac/aacvar.h,v 1.11 2006/02/17 19:18:05 dillon Exp $ + * $DragonFly: src/sys/dev/raid/aac/aacvar.h,v 1.12 2006/06/04 21:09:49 dillon Exp $ */ #include @@ -261,10 +261,10 @@ typedef struct mtx aac_lock_t; #define AAC_LOCK_ACQUIRE(l) mtx_lock(l) #define AAC_LOCK_RELEASE(l) mtx_unlock(l) #else -typedef struct lwkt_rwlock aac_lock_t; -#define AAC_LOCK_INIT(l, s) lwkt_rwlock_init(l) -#define AAC_LOCK_ACQUIRE(l) lwkt_exlock(l, "aac") -#define AAC_LOCK_RELEASE(l) lwkt_exunlock(l) +typedef struct lock aac_lock_t; +#define AAC_LOCK_INIT(l, s) lockinit(l, "aac", 0, 0) +#define AAC_LOCK_ACQUIRE(l) lockmgr(l, LK_EXCLUSIVE|LK_RETRY) +#define AAC_LOCK_RELEASE(l) lockmgr(l, LK_RELEASE) #endif #if defined(__FreeBSD__) && __FreeBSD_version >= 500005 diff --git a/sys/dev/raid/ips/ips.c b/sys/dev/raid/ips/ips.c index 4a750272c3..345f8739fb 100644 --- a/sys/dev/raid/ips/ips.c +++ b/sys/dev/raid/ips/ips.c @@ -25,7 +25,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/ips/ips.c,v 1.12 2004/05/30 04:01:29 scottl Exp $ - * $DragonFly: src/sys/dev/raid/ips/ips.c,v 1.12 2005/08/09 16:23:13 dillon Exp $ + * $DragonFly: src/sys/dev/raid/ips/ips.c,v 1.13 2006/06/04 21:09:50 dillon Exp $ */ #include @@ -334,7 +334,7 @@ ips_timeout(void *arg) ips_softc_t *sc = arg; int i, state = 0; - lwkt_exlock(&sc->queue_lock, __func__); + lockmgr(&sc->queue_lock, LK_EXCLUSIVE|LK_RETRY); command = &sc->commandarray[0]; for (i = 0; i < sc->max_cmds; i++) { if (!command[i].timeout) @@ -367,7 +367,7 @@ ips_timeout(void *arg) } if (sc->state != IPS_OFFLINE) callout_reset(&sc->timer, 10 * hz, ips_timeout, sc); - lwkt_exunlock(&sc->queue_lock); + lockmgr(&sc->queue_lock, LK_RELEASE); } /* check card and initialize it */ @@ -585,9 +585,9 @@ ips_morpheus_intr(void *void_sc) { ips_softc_t *sc = void_sc; - lwkt_exlock(&sc->queue_lock, __func__); + lockmgr(&sc->queue_lock, LK_EXCLUSIVE|LK_RETRY); ips_morpheus_check_intr(sc); - lwkt_exunlock(&sc->queue_lock); + lockmgr(&sc->queue_lock, LK_RELEASE); } void @@ -771,7 +771,7 @@ ips_copperhead_intr(void *void_sc) ips_cmd_status_t status; int cmdnumber; - lwkt_exlock(&sc->queue_lock, __func__); + lockmgr(&sc->queue_lock, LK_EXCLUSIVE|LK_RETRY); while (ips_read_1(sc, COPPER_REG_HISR) & COPPER_SCE_BIT) { status.value = ips_copperhead_cmd_status(sc); cmdnumber = status.fields.command_id; @@ -780,7 +780,7 @@ ips_copperhead_intr(void *void_sc) sc->commandarray[cmdnumber].callback(&(sc->commandarray[cmdnumber])); PRINTF(9, "ips: got command %d\n", cmdnumber); } - lwkt_exunlock(&sc->queue_lock); + lockmgr(&sc->queue_lock, LK_RELEASE); return; } diff --git a/sys/dev/raid/ips/ips.h b/sys/dev/raid/ips/ips.h index 9e6d0d8ce9..b8a8316185 100644 --- a/sys/dev/raid/ips/ips.h +++ b/sys/dev/raid/ips/ips.h @@ -26,7 +26,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/ips/ips.h,v 1.10 2004/05/30 20:08:34 phk Exp $ - * $DragonFly: src/sys/dev/raid/ips/ips.h,v 1.9 2006/04/30 17:22:16 dillon Exp $ + * $DragonFly: src/sys/dev/raid/ips/ips.h,v 1.10 2006/06/04 21:09:50 dillon Exp $ */ @@ -44,6 +44,7 @@ #include #include #include +#include #include #include @@ -454,7 +455,7 @@ typedef struct ips_softc { void (*ips_poll_cmd)(ips_command_t *command); ips_copper_queue_t *copper_queue; - struct lwkt_rwlock queue_lock; + struct lock queue_lock; struct bio_queue_head bio_queue; } ips_softc_t; diff --git a/sys/dev/raid/ips/ips_disk.c b/sys/dev/raid/ips/ips_disk.c index cc4572b0d8..37b08c369f 100644 --- a/sys/dev/raid/ips/ips_disk.c +++ b/sys/dev/raid/ips/ips_disk.c @@ -25,7 +25,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/ips/ips_disk.c,v 1.4 2003/09/22 04:59:07 njl Exp $ - * $DragonFly: src/sys/dev/raid/ips/ips_disk.c,v 1.7 2006/02/17 19:18:05 dillon Exp $ + * $DragonFly: src/sys/dev/raid/ips/ips_disk.c,v 1.8 2006/06/04 21:09:50 dillon Exp $ */ #include @@ -138,10 +138,10 @@ ipsd_strategy(dev_t dev, struct bio *bio) DEVICE_PRINTF(8, dsc->dev, "in strategy\n"); bio->bio_driver_info = dsc; devstat_start_transaction(&dsc->stats); - lwkt_exlock(&dsc->sc->queue_lock, __func__); + lockmgr(&dsc->sc->queue_lock, LK_EXCLUSIVE|LK_RETRY); bioq_insert_tail(&dsc->sc->bio_queue, bio); ips_start_io_request(dsc->sc); - lwkt_exunlock(&dsc->sc->queue_lock); + lockmgr(&dsc->sc->queue_lock, LK_RELEASE); } static int diff --git a/sys/dev/raid/ips/ips_ioctl.c b/sys/dev/raid/ips/ips_ioctl.c index a7efa66e3c..eb92dcc316 100644 --- a/sys/dev/raid/ips/ips_ioctl.c +++ b/sys/dev/raid/ips/ips_ioctl.c @@ -25,7 +25,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/ips/ips_ioctl.c,v 1.5 2004/05/30 04:01:29 scottl Exp $ - * $DragonFly: src/sys/dev/raid/ips/ips_ioctl.c,v 1.5 2005/08/09 16:23:13 dillon Exp $ + * $DragonFly: src/sys/dev/raid/ips/ips_ioctl.c,v 1.6 2006/06/04 21:09:50 dillon Exp $ */ #include @@ -126,10 +126,10 @@ ips_ioctl_cmd(ips_softc_t *sc, ips_ioctl_t *ioctl_cmd, ioctl_cmd->datasize)) goto exit; ioctl_cmd->status.value = 0xffffffff; - lwkt_exlock(&sc->queue_lock, __func__); + lockmgr(&sc->queue_lock, LK_EXCLUSIVE|LK_RETRY); if ((error = ips_get_free_cmd(sc, &command, 0)) > 0) { error = ENOMEM; - lwkt_exunlock(&sc->queue_lock); + lockmgr(&sc->queue_lock, LK_RELEASE); goto exit; } command->arg = ioctl_cmd; @@ -140,7 +140,7 @@ ips_ioctl_cmd(ips_softc_t *sc, ips_ioctl_t *ioctl_cmd, error = EIO; else error = 0; - lwkt_exunlock(&sc->queue_lock); + lockmgr(&sc->queue_lock, LK_RELEASE); if (copyout(ioctl_cmd->data_buffer, user_request->data_buffer, ioctl_cmd->datasize)) diff --git a/sys/dev/raid/ips/ips_pci.c b/sys/dev/raid/ips/ips_pci.c index 7ed2e84a1a..ddd763977b 100644 --- a/sys/dev/raid/ips/ips_pci.c +++ b/sys/dev/raid/ips/ips_pci.c @@ -26,7 +26,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/ips/ips_pci.c,v 1.10 2004/03/19 17:36:47 scottl Exp $ - * $DragonFly: src/sys/dev/raid/ips/ips_pci.c,v 1.15 2006/02/17 19:18:05 dillon Exp $ + * $DragonFly: src/sys/dev/raid/ips/ips_pci.c,v 1.16 2006/06/04 21:09:50 dillon Exp $ */ #include @@ -154,7 +154,7 @@ ips_pci_attach(device_t dev) sc->ips_ich.ich_func = ips_intrhook; sc->ips_ich.ich_arg = sc; sc->ips_ich.ich_desc = "ips"; - lwkt_rwlock_init(&sc->queue_lock); + lockinit(&sc->queue_lock, "ipslk", 0, 0); bioq_init(&sc->bio_queue); if (config_intrhook_establish(&sc->ips_ich) != 0) { printf("IPS can't establish configuration hook\n"); diff --git a/sys/i386/i386/genassym.c b/sys/i386/i386/genassym.c index 316ebe09b1..fca111f981 100644 --- a/sys/i386/i386/genassym.c +++ b/sys/i386/i386/genassym.c @@ -35,7 +35,7 @@ * * from: @(#)genassym.c 5.11 (Berkeley) 5/10/91 * $FreeBSD: src/sys/i386/i386/genassym.c,v 1.86.2.3 2002/03/03 05:42:49 nyan Exp $ - * $DragonFly: src/sys/i386/i386/Attic/genassym.c,v 1.49 2006/04/30 17:22:17 dillon Exp $ + * $DragonFly: src/sys/i386/i386/Attic/genassym.c,v 1.50 2006/06/04 21:09:50 dillon Exp $ */ #include @@ -97,8 +97,6 @@ ASSYM(MP_FREE_LOCK, MP_FREE_LOCK); #endif ASSYM(MACHINTR_INTREN, offsetof(struct machintr_abi, intren)); -ASSYM(RW_OWNER, offsetof(struct lwkt_rwlock, rw_owner)); - ASSYM(TD_SAVEFPU, offsetof(struct thread, td_mach) + offsetof(struct md_thread, mtd_savefpu)); ASSYM(TDPRI_CRIT, TDPRI_CRIT); diff --git a/sys/kern/lwkt_rwlock.c b/sys/kern/lwkt_rwlock.c deleted file mode 100644 index 61fd3f68a6..0000000000 --- a/sys/kern/lwkt_rwlock.c +++ /dev/null @@ -1,164 +0,0 @@ -/* - * LWKT_RWLOCK.C (MP SAFE) - * - * Copyright (c) 2003-2006 The DragonFly Project. All rights reserved. - * - * This code is derived from software contributed to The DragonFly Project - * by Matthew Dillon - * - * 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. - * 3. Neither the name of The DragonFly Project nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific, prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 - * COPYRIGHT HOLDERS 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. - * - * Implements simple shared/exclusive locks using LWKT. - * - * $DragonFly: src/sys/kern/Attic/lwkt_rwlock.c,v 1.11 2006/05/21 20:23:25 dillon Exp $ - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* - * lwkt_rwlock_init() (MP SAFE) - * - * NOTE! called from low level boot, we cannot do anything fancy. - */ -void -lwkt_rwlock_init(lwkt_rwlock_t lock) -{ - lwkt_wait_init(&lock->rw_wait); - lock->rw_owner = NULL; - lock->rw_count = 0; - lock->rw_requests = 0; -} - -/* - * lwkt_rwlock_uninit() (MP SAFE) - */ -void -lwkt_rwlock_uninit(lwkt_rwlock_t lock) -{ - /* empty */ -} - -/* - * lwkt_exlock() (MP SAFE) - * - * NOTE: We need to use a critical section in addition to the token to - * interlock against IPI lwkt_schedule calls which may manipulate the - * rw_wait structure's list. This is because the IPI runs in the context of - * the current thread and thus cannot use any token calls (if it did the - * token would just share with the thread's token and not provide any - * protection). This needs a rewrite. - */ -void -lwkt_exlock(lwkt_rwlock_t lock, const char *wmesg) -{ - int gen; - - spin_lock_wr(&lock->rw_spinlock); - gen = lock->rw_wait.wa_gen; - while (lock->rw_owner != curthread) { - if (lock->rw_owner == NULL && lock->rw_count == 0) { - lock->rw_owner = curthread; - break; - } - ++lock->rw_requests; - spin_unlock_wr(&lock->rw_spinlock); - lwkt_block(&lock->rw_wait, wmesg, &gen); - spin_lock_wr(&lock->rw_spinlock); - --lock->rw_requests; - } - ++lock->rw_count; - spin_unlock_wr(&lock->rw_spinlock); -} - -/* - * lwkt_shlock() (MP SAFE) - */ -void -lwkt_shlock(lwkt_rwlock_t lock, const char *wmesg) -{ - int gen; - - spin_lock_wr(&lock->rw_spinlock); - gen = lock->rw_wait.wa_gen; - while (lock->rw_owner != NULL) { - ++lock->rw_requests; - spin_unlock_wr(&lock->rw_spinlock); - lwkt_block(&lock->rw_wait, wmesg, &gen); - spin_lock_wr(&lock->rw_spinlock); - --lock->rw_requests; - } - ++lock->rw_count; - spin_unlock_wr(&lock->rw_spinlock); -} - -/* - * lwkt_exunlock() (MP SAFE) - */ -void -lwkt_exunlock(lwkt_rwlock_t lock) -{ - KASSERT(lock->rw_owner != NULL, ("lwkt_exunlock: shared lock")); - KASSERT(lock->rw_owner == curthread, ("lwkt_exunlock: not owner")); - spin_lock_wr(&lock->rw_spinlock); - if (--lock->rw_count == 0) { - lock->rw_owner = NULL; - if (lock->rw_requests) { - spin_unlock_wr(&lock->rw_spinlock); - lwkt_signal(&lock->rw_wait, 1); - return; - } - } - spin_unlock_wr(&lock->rw_spinlock); -} - -/* - * lwkt_shunlock() (MP SAFE) - */ -void -lwkt_shunlock(lwkt_rwlock_t lock) -{ - KASSERT(lock->rw_owner == NULL, ("lwkt_shunlock: exclusive lock")); - spin_lock_wr(&lock->rw_spinlock); - if (--lock->rw_count == 0) { - if (lock->rw_requests) { - spin_unlock_wr(&lock->rw_spinlock); - lwkt_signal(&lock->rw_wait, 1); - return; - } - } - spin_unlock_wr(&lock->rw_spinlock); -} - diff --git a/sys/kern/lwkt_thread.c b/sys/kern/lwkt_thread.c index 49a4ad9158..2e327e1e7e 100644 --- a/sys/kern/lwkt_thread.c +++ b/sys/kern/lwkt_thread.c @@ -31,7 +31,7 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $DragonFly: src/sys/kern/lwkt_thread.c,v 1.100 2006/06/01 19:02:38 dillon Exp $ + * $DragonFly: src/sys/kern/lwkt_thread.c,v 1.101 2006/06/04 21:09:50 dillon Exp $ */ /* @@ -188,7 +188,6 @@ void lwkt_schedule_self(thread_t td) { crit_enter_quick(td); - KASSERT(td->td_wait == NULL, ("lwkt_schedule_self(): td_wait not NULL!")); KASSERT(td != &td->td_gd->gd_idlethread, ("lwkt_schedule_self(): scheduling gd_idlethread is illegal!")); KKASSERT(td->td_proc == NULL || (td->td_proc->p_flag & P_ONRUNQ) == 0); _lwkt_enqueue(td); @@ -204,7 +203,6 @@ void lwkt_deschedule_self(thread_t td) { crit_enter_quick(td); - KASSERT(td->td_wait == NULL, ("lwkt_schedule_self(): td_wait not NULL!")); _lwkt_dequeue(td); crit_exit_quick(td); } @@ -229,20 +227,6 @@ lwkt_gdinit(struct globaldata *gd) #endif /* _KERNEL */ -/* - * Initialize a thread wait structure prior to first use. - * - * NOTE! called from low level boot code, we cannot do anything fancy! - */ -void -lwkt_wait_init(lwkt_wait_t w) -{ - spin_init(&w->wa_spinlock); - TAILQ_INIT(&w->wa_waitq); - w->wa_gen = 0; - w->wa_count = 0; -} - /* * Create a new thread. The thread must be associated with a process context * or LWKT start address before it can be scheduled. If the target cpu is @@ -1013,68 +997,22 @@ lwkt_schedule(thread_t td) if (td == mygd->gd_curthread) { _lwkt_enqueue(td); } else { - lwkt_wait_t w; - /* - * If the thread is on a wait list we have to send our scheduling - * request to the owner of the wait structure. Otherwise we send - * the scheduling request to the cpu owning the thread. Races - * are ok, the target will forward the message as necessary (the - * message may chase the thread around before it finally gets - * acted upon). - * - * (remember, wait structures use stable storage) - * - * NOTE: we have to account for the number of critical sections - * under our control when calling _lwkt_schedule_post() so it - * can figure out whether preemption is allowed. - * - * NOTE: The wait structure algorithms are a mess and need to be - * rewritten. - * - * NOTE: We cannot safely acquire or release a token, even - * non-blocking, because this routine may be called in the context - * of a thread already holding the token and thus not provide any - * interlock protection. We cannot safely manipulate the td_toks - * list for the same reason. Instead we depend on our critical - * section if the token is owned by our cpu. + * If we own the thread, there is no race (since we are in a + * critical section). If we do not own the thread there might + * be a race but the target cpu will deal with it. */ - if ((w = td->td_wait) != NULL) { - spin_lock_wr(&w->wa_spinlock); - TAILQ_REMOVE(&w->wa_waitq, td, td_threadq); - --w->wa_count; - td->td_wait = NULL; - spin_unlock_wr(&w->wa_spinlock); #ifdef SMP - if (td->td_gd == mygd) { - _lwkt_enqueue(td); - _lwkt_schedule_post(mygd, td, TDPRI_CRIT); - } else { - lwkt_send_ipiq(td->td_gd, (ipifunc1_t)lwkt_schedule, td); - } -#else + if (td->td_gd == mygd) { _lwkt_enqueue(td); _lwkt_schedule_post(mygd, td, TDPRI_CRIT); -#endif } else { - /* - * If the wait structure is NULL and we own the thread, there - * is no race (since we are in a critical section). If we - * do not own the thread there might be a race but the - * target cpu will deal with it. - */ -#ifdef SMP - if (td->td_gd == mygd) { - _lwkt_enqueue(td); - _lwkt_schedule_post(mygd, td, TDPRI_CRIT); - } else { - lwkt_send_ipiq(td->td_gd, (ipifunc1_t)lwkt_schedule, td); - } + lwkt_send_ipiq(td->td_gd, (ipifunc1_t)lwkt_schedule, td); + } #else - _lwkt_enqueue(td); - _lwkt_schedule_post(mygd, td, TDPRI_CRIT); + _lwkt_enqueue(td); + _lwkt_schedule_post(mygd, td, TDPRI_CRIT); #endif - } } crit_exit_gd(mygd); } @@ -1312,76 +1250,6 @@ lwkt_preempted_proc(void) return(td->td_lwp); } -/* - * Block on the specified wait queue until signaled. A generation number - * must be supplied to interlock the wait queue. The function will - * return immediately if the generation number does not match the wait - * structure's generation number. - */ -void -lwkt_block(lwkt_wait_t w, const char *wmesg, int *gen) -{ - thread_t td = curthread; - - spin_lock_wr(&w->wa_spinlock); - if (w->wa_gen == *gen) { - _lwkt_dequeue(td); - td->td_flags |= TDF_BLOCKQ; - TAILQ_INSERT_TAIL(&w->wa_waitq, td, td_threadq); - ++w->wa_count; - td->td_wait = w; - td->td_wmesg = wmesg; - spin_unlock_wr(&w->wa_spinlock); - lwkt_switch(); - KKASSERT((td->td_flags & TDF_BLOCKQ) == 0); - td->td_wmesg = NULL; - *gen = w->wa_gen; - } else { - *gen = w->wa_gen; - spin_unlock_wr(&w->wa_spinlock); - } -} - -/* - * Signal a wait queue. We gain ownership of the wait queue in order to - * signal it. Once a thread is removed from the wait queue we have to - * deal with the cpu owning the thread. - * - * Note: alternatively we could message the target cpu owning the wait - * queue. YYY implement as sysctl. - */ -void -lwkt_signal(lwkt_wait_t w, int count) -{ - thread_t td; - - spin_lock_wr(&w->wa_spinlock); - ++w->wa_gen; - if (count < 0) - count = w->wa_count; - while ((td = TAILQ_FIRST(&w->wa_waitq)) != NULL && count) { - --count; - --w->wa_count; - KKASSERT(td->td_flags & TDF_BLOCKQ); - TAILQ_REMOVE(&w->wa_waitq, td, td_threadq); - td->td_flags &= ~TDF_BLOCKQ; - td->td_wait = NULL; - spin_unlock_wr(&w->wa_spinlock); - KKASSERT(td->td_proc == NULL || (td->td_proc->p_flag & P_ONRUNQ) == 0); -#ifdef SMP - if (td->td_gd == mycpu) { - _lwkt_enqueue(td); - } else { - lwkt_send_ipiq(td->td_gd, (ipifunc1_t)lwkt_schedule, td); - } -#else - _lwkt_enqueue(td); -#endif - spin_lock_wr(&w->wa_spinlock); - } - spin_unlock_wr(&w->wa_spinlock); -} - /* * Create a kernel process/thread/whatever. It shares it's address space * with proc0 - ie: kernel only. diff --git a/sys/kern/lwkt_token.c b/sys/kern/lwkt_token.c index 2d3a2e79e3..4e26165baa 100644 --- a/sys/kern/lwkt_token.c +++ b/sys/kern/lwkt_token.c @@ -31,7 +31,7 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $DragonFly: src/sys/kern/lwkt_token.c,v 1.26 2006/05/21 20:23:25 dillon Exp $ + * $DragonFly: src/sys/kern/lwkt_token.c,v 1.27 2006/06/04 21:09:50 dillon Exp $ */ #ifdef _KERNEL @@ -110,7 +110,7 @@ KTR_INFO_MASTER(tokens); KTR_INFO(KTR_TOKENS, tokens, try, 0, TOKEN_STRING, sizeof(void *) * 3); KTR_INFO(KTR_TOKENS, tokens, get, 1, TOKEN_STRING, sizeof(void *) * 3); KTR_INFO(KTR_TOKENS, tokens, release, 2, TOKEN_STRING, sizeof(void *) * 3); -#ifdef SMP +#if 0 KTR_INFO(KTR_TOKENS, tokens, remote, 3, TOKEN_STRING, sizeof(void *) * 3); KTR_INFO(KTR_TOKENS, tokens, reqremote, 4, TOKEN_STRING, sizeof(void *) * 3); KTR_INFO(KTR_TOKENS, tokens, reqfail, 5, TOKEN_STRING, sizeof(void *) * 3); diff --git a/sys/netproto/smb/smb_subr.h b/sys/netproto/smb/smb_subr.h index eea5710db9..b47570fcbd 100644 --- a/sys/netproto/smb/smb_subr.h +++ b/sys/netproto/smb/smb_subr.h @@ -30,7 +30,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/netsmb/smb_subr.h,v 1.1.2.1 2001/05/22 08:32:34 bp Exp $ - * $DragonFly: src/sys/netproto/smb/smb_subr.h,v 1.13 2006/05/21 20:23:28 dillon Exp $ + * $DragonFly: src/sys/netproto/smb/smb_subr.h,v 1.14 2006/06/04 21:09:50 dillon Exp $ */ #ifndef _NETSMB_SMB_SUBR_H_ #define _NETSMB_SMB_SUBR_H_ @@ -142,7 +142,6 @@ struct mbchain; struct proc; struct thread; struct lwkt_tokref; -struct lwkt_rwlock; struct smb_vc; struct smb_rq; diff --git a/sys/platform/pc32/i386/genassym.c b/sys/platform/pc32/i386/genassym.c index 61ac66f6c3..311be7b59f 100644 --- a/sys/platform/pc32/i386/genassym.c +++ b/sys/platform/pc32/i386/genassym.c @@ -35,7 +35,7 @@ * * from: @(#)genassym.c 5.11 (Berkeley) 5/10/91 * $FreeBSD: src/sys/i386/i386/genassym.c,v 1.86.2.3 2002/03/03 05:42:49 nyan Exp $ - * $DragonFly: src/sys/platform/pc32/i386/genassym.c,v 1.49 2006/04/30 17:22:17 dillon Exp $ + * $DragonFly: src/sys/platform/pc32/i386/genassym.c,v 1.50 2006/06/04 21:09:50 dillon Exp $ */ #include @@ -97,8 +97,6 @@ ASSYM(MP_FREE_LOCK, MP_FREE_LOCK); #endif ASSYM(MACHINTR_INTREN, offsetof(struct machintr_abi, intren)); -ASSYM(RW_OWNER, offsetof(struct lwkt_rwlock, rw_owner)); - ASSYM(TD_SAVEFPU, offsetof(struct thread, td_mach) + offsetof(struct md_thread, mtd_savefpu)); ASSYM(TDPRI_CRIT, TDPRI_CRIT); diff --git a/sys/platform/vkernel/i386/genassym.c b/sys/platform/vkernel/i386/genassym.c index 3fe3569a17..24b7653b59 100644 --- a/sys/platform/vkernel/i386/genassym.c +++ b/sys/platform/vkernel/i386/genassym.c @@ -35,7 +35,7 @@ * * from: @(#)genassym.c 5.11 (Berkeley) 5/10/91 * $FreeBSD: src/sys/i386/i386/genassym.c,v 1.86.2.3 2002/03/03 05:42:49 nyan Exp $ - * $DragonFly: src/sys/platform/vkernel/i386/genassym.c,v 1.49 2006/04/30 17:22:17 dillon Exp $ + * $DragonFly: src/sys/platform/vkernel/i386/genassym.c,v 1.50 2006/06/04 21:09:50 dillon Exp $ */ #include @@ -97,8 +97,6 @@ ASSYM(MP_FREE_LOCK, MP_FREE_LOCK); #endif ASSYM(MACHINTR_INTREN, offsetof(struct machintr_abi, intren)); -ASSYM(RW_OWNER, offsetof(struct lwkt_rwlock, rw_owner)); - ASSYM(TD_SAVEFPU, offsetof(struct thread, td_mach) + offsetof(struct md_thread, mtd_savefpu)); ASSYM(TDPRI_CRIT, TDPRI_CRIT); diff --git a/sys/sys/thread.h b/sys/sys/thread.h index 6b086a076c..8e9b03e162 100644 --- a/sys/sys/thread.h +++ b/sys/sys/thread.h @@ -7,7 +7,7 @@ * Types which must already be defined when this header is included by * userland: struct md_thread * - * $DragonFly: src/sys/sys/thread.h,v 1.85 2006/06/01 05:38:46 dillon Exp $ + * $DragonFly: src/sys/sys/thread.h,v 1.86 2006/06/04 21:09:50 dillon Exp $ */ #ifndef _SYS_THREAD_H_ @@ -42,11 +42,9 @@ struct thread; struct lwkt_queue; struct lwkt_token; struct lwkt_tokref; -struct lwkt_wait; struct lwkt_ipiq; struct lwkt_cpu_msg; struct lwkt_cpu_port; -struct lwkt_rwlock; struct lwkt_msg; struct lwkt_port; struct lwkt_cpusync; @@ -55,10 +53,8 @@ union sysunion; typedef struct lwkt_queue *lwkt_queue_t; typedef struct lwkt_token *lwkt_token_t; typedef struct lwkt_tokref *lwkt_tokref_t; -typedef struct lwkt_wait *lwkt_wait_t; typedef struct lwkt_cpu_msg *lwkt_cpu_msg_t; typedef struct lwkt_cpu_port *lwkt_cpu_port_t; -typedef struct lwkt_rwlock *lwkt_rwlock_t; typedef struct lwkt_ipiq *lwkt_ipiq_t; typedef struct lwkt_cpusync *lwkt_cpusync_t; typedef struct thread *thread_t; @@ -133,17 +129,6 @@ typedef struct lwkt_tokref { #define LWKT_TOKREF_DECLARE(name, tok) \ lwkt_tokref name = LWKT_TOKREF_INIT(tok) -/* - * Wait structures deal with blocked threads. Due to the way remote cpus - * interact with these structures stable storage must be used. - */ -typedef struct lwkt_wait { - lwkt_queue wa_waitq; /* list of waiting threads */ - struct spinlock wa_spinlock; - int wa_gen; - int wa_count; -} lwkt_wait; - #define MAXCPUFIFO 16 /* power of 2 */ #define MAXCPUFIFO_MASK (MAXCPUFIFO - 1) #define LWKT_MAXTOKENS 16 /* max tokens beneficially held by thread */ @@ -197,18 +182,6 @@ typedef struct lwkt_cpu_msg { thread_t cm_originator; /* originating thread for wakeup */ } lwkt_cpu_msg; -/* - * reader/writer lock - */ -typedef struct lwkt_rwlock { - lwkt_wait rw_wait; - thread_t rw_owner; - int rw_count; - int rw_requests; -} lwkt_rwlock; - -#define rw_spinlock rw_wait.wa_spinlock - /* * Thread structure. Note that ownership of a thread structure is special * cased and there is no 'token'. A thread is always owned by the cpu @@ -241,7 +214,6 @@ struct thread { int td_kstack_size; /* size of kernel stack */ char *td_sp; /* kernel stack pointer for LWKT restore */ void (*td_switch)(struct thread *ntd); - lwkt_wait_t td_wait; /* thread sitting on wait structure */ __uint64_t td_uticks; /* Statclock hits in user mode (uS) */ __uint64_t td_sticks; /* Statclock hits in system mode (uS) */ __uint64_t td_iticks; /* Statclock hits processing intr (uS) */ @@ -366,7 +338,6 @@ extern void lwkt_init_thread(struct thread *td, void *stack, int stksize, extern void lwkt_set_comm(thread_t td, const char *ctl, ...); extern void lwkt_wait_free(struct thread *td); extern void lwkt_free_thread(struct thread *td); -extern void lwkt_wait_init(struct lwkt_wait *w); extern void lwkt_gdinit(struct globaldata *gd); extern void lwkt_switch(void); extern void lwkt_preempt(thread_t ntd, int critpri); @@ -380,9 +351,6 @@ extern void lwkt_token_wait(void); extern void lwkt_hold(thread_t td); extern void lwkt_rele(thread_t td); -extern void lwkt_block(lwkt_wait_t w, const char *wmesg, int *gen); -extern void lwkt_signal(lwkt_wait_t w, int count); - extern void lwkt_gettoken(lwkt_tokref_t ref, lwkt_token_t tok); extern int lwkt_trytoken(lwkt_tokref_t ref, lwkt_token_t tok); extern void lwkt_gettokref(lwkt_tokref_t ref); @@ -397,13 +365,6 @@ extern void lwkt_token_uninit(lwkt_token_t tok); extern void lwkt_token_pool_init(void); extern lwkt_token_t lwkt_token_pool_get(void *ptraddr); -extern void lwkt_rwlock_init(lwkt_rwlock_t lock); -extern void lwkt_rwlock_uninit(lwkt_rwlock_t lock); -extern void lwkt_exlock(lwkt_rwlock_t lock, const char *wmesg); -extern void lwkt_shlock(lwkt_rwlock_t lock, const char *wmesg); -extern void lwkt_exunlock(lwkt_rwlock_t lock); -extern void lwkt_shunlock(lwkt_rwlock_t lock); - extern void lwkt_setpri(thread_t td, int pri); extern void lwkt_setpri_self(int pri); extern int lwkt_checkpri_self(void); -- 2.41.0