From owner-svn-src-all@freebsd.org Thu Apr 21 18:37:38 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 7FD9EB184AD; Thu, 21 Apr 2016 18:37:38 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 3D8F41D97; Thu, 21 Apr 2016 18:37:38 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u3LIbbi1092258; Thu, 21 Apr 2016 18:37:37 GMT (envelope-from jhb@FreeBSD.org) Received: (from jhb@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u3LIbalm092252; Thu, 21 Apr 2016 18:37:36 GMT (envelope-from jhb@FreeBSD.org) Message-Id: <201604211837.u3LIbalm092252@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jhb set sender to jhb@FreeBSD.org using -f From: John Baldwin Date: Thu, 21 Apr 2016 18:37:36 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r298426 - head/sys/dev/fdc X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 21 Apr 2016 18:37:38 -0000 Author: jhb Date: Thu Apr 21 18:37:36 2016 New Revision: 298426 URL: https://svnweb.freebsd.org/changeset/base/298426 Log: Adjust the fdc worker thread startup to work when APs are started earlier. - Enable the commented out locking in fd_probe(). The worker thread should not be running yet (even after these changes), but better to be safe than sorry. - Defer starting the worker thread until after the child drives have been probed. The worker thread startup is moved into a fdc_start_worker() thread that the various front ends call at the end of attach. As a side effect this fixes a few edge cases that weren't shutting down the worker thread if attach encountered a late failure. - When executing the initial reset requested by attach in the worker thread, use DELAY() instead of a tsleep() if cold is set. Tested by: Howard Su Sponsored by: Netflix Modified: head/sys/dev/fdc/fdc.c head/sys/dev/fdc/fdc_acpi.c head/sys/dev/fdc/fdc_cbus.c head/sys/dev/fdc/fdc_isa.c head/sys/dev/fdc/fdc_pccard.c head/sys/dev/fdc/fdcvar.h Modified: head/sys/dev/fdc/fdc.c ============================================================================== --- head/sys/dev/fdc/fdc.c Thu Apr 21 18:27:05 2016 (r298425) +++ head/sys/dev/fdc/fdc.c Thu Apr 21 18:37:36 2016 (r298426) @@ -953,7 +953,10 @@ fdc_worker(struct fdc_data *fdc) if (fdc->flags & FDC_NEEDS_RESET) { fdc->flags &= ~FDC_NEEDS_RESET; fdc_reset(fdc); - tsleep(fdc, PRIBIO, "fdcrst", hz); + if (cold) + DELAY(1000000); + else + tsleep(fdc, PRIBIO, "fdcrst", hz); /* Discard results */ for (i = 0; i < 4; i++) fdc_sense_int(fdc, &st0, &cyl); @@ -2055,14 +2058,21 @@ fdc_attach(device_t dev) #endif bioq_init(&fdc->head); - kproc_create(fdc_thread, fdc, &fdc->fdc_thread, 0, 0, - "fdc%d", device_get_unit(dev)); - settle = hz / 8; return (0); } +void +fdc_start_worker(device_t dev) +{ + struct fdc_data *fdc; + + fdc = device_get_softc(dev); + kproc_create(fdc_thread, fdc, &fdc->fdc_thread, 0, 0, + "fdc%d", device_get_unit(dev)); +} + int fdc_hints_probe(device_t dev) { @@ -2155,9 +2165,8 @@ fd_probe(device_t dev) return (ENXIO); #ifndef PC98 -/* mtx_lock(&fdc->fdc_mtx); -*/ + /* select it */ fd_select(fd); fd_motor(fd, 1); @@ -2200,9 +2209,7 @@ fd_probe(device_t dev) fd_motor(fd, 0); fdc->fd = NULL; -/* mtx_unlock(&fdc->fdc_mtx); -*/ if ((flags & FD_NO_PROBE) == 0 && (st0 & NE7_ST0_EC) != 0) /* no track 0 -> no drive present */ Modified: head/sys/dev/fdc/fdc_acpi.c ============================================================================== --- head/sys/dev/fdc/fdc_acpi.c Thu Apr 21 18:27:05 2016 (r298425) +++ head/sys/dev/fdc/fdc_acpi.c Thu Apr 21 18:37:36 2016 (r298426) @@ -135,6 +135,9 @@ fdc_acpi_attach(device_t dev) obj = buf.Pointer; error = fdc_acpi_probe_children(bus, dev, obj->Buffer.Pointer); + if (error == 0) + fdc_start_worker(dev); + out: if (buf.Pointer) free(buf.Pointer, M_TEMP); Modified: head/sys/dev/fdc/fdc_cbus.c ============================================================================== --- head/sys/dev/fdc/fdc_cbus.c Thu Apr 21 18:27:05 2016 (r298425) +++ head/sys/dev/fdc/fdc_cbus.c Thu Apr 21 18:37:36 2016 (r298426) @@ -150,7 +150,9 @@ fdc_cbus_attach(device_t dev) error = fdc_attach(dev); if (error == 0) error = fdc_hints_probe(dev); - if (error) + if (error == 0) + fdc_start_worker(dev); + else fdc_release_resources(fdc); return (error); } Modified: head/sys/dev/fdc/fdc_isa.c ============================================================================== --- head/sys/dev/fdc/fdc_isa.c Thu Apr 21 18:27:05 2016 (r298425) +++ head/sys/dev/fdc/fdc_isa.c Thu Apr 21 18:37:36 2016 (r298426) @@ -190,7 +190,9 @@ fdc_isa_attach(device_t dev) error = fdc_attach(dev); if (error == 0) error = fdc_hints_probe(dev); - if (error) + if (error == 0) + fdc_start_worker(dev); + else fdc_release_resources(fdc); return (error); } Modified: head/sys/dev/fdc/fdc_pccard.c ============================================================================== --- head/sys/dev/fdc/fdc_pccard.c Thu Apr 21 18:27:05 2016 (r298425) +++ head/sys/dev/fdc/fdc_pccard.c Thu Apr 21 18:37:36 2016 (r298426) @@ -108,7 +108,9 @@ fdc_pccard_attach(device_t dev) device_set_flags(child, 0x24); error = bus_generic_attach(dev); } - if (error) + if (error == 0) + fdc_start_worker(dev); + else fdc_release_resources(fdc); return (error); } Modified: head/sys/dev/fdc/fdcvar.h ============================================================================== --- head/sys/dev/fdc/fdcvar.h Thu Apr 21 18:27:05 2016 (r298425) +++ head/sys/dev/fdc/fdcvar.h Thu Apr 21 18:37:36 2016 (r298426) @@ -83,6 +83,7 @@ __BUS_ACCESSOR(fdc, fdtype, FDC, FDTYPE, void fdc_release_resources(struct fdc_data *); int fdc_attach(device_t); +void fdc_start_worker(device_t); int fdc_hints_probe(device_t); int fdc_detach(device_t dev); device_t fdc_add_child(device_t, const char *, int);