From owner-svn-src-all@freebsd.org Fri Mar 27 15:28:42 2020 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 5CF84278984; Fri, 27 Mar 2020 15:28:42 +0000 (UTC) (envelope-from chuck@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 48pm3G04ytz4K8G; Fri, 27 Mar 2020 15:28:41 +0000 (UTC) (envelope-from chuck@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 mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 724A5234D2; Fri, 27 Mar 2020 15:28:17 +0000 (UTC) (envelope-from chuck@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 02RFSHqp001978; Fri, 27 Mar 2020 15:28:17 GMT (envelope-from chuck@FreeBSD.org) Received: (from chuck@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 02RFSHH5001977; Fri, 27 Mar 2020 15:28:17 GMT (envelope-from chuck@FreeBSD.org) Message-Id: <202003271528.02RFSHH5001977@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: chuck set sender to chuck@FreeBSD.org using -f From: Chuck Tuffli Date: Fri, 27 Mar 2020 15:28:17 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r359365 - head/usr.sbin/bhyve X-SVN-Group: head X-SVN-Commit-Author: chuck X-SVN-Commit-Paths: head/usr.sbin/bhyve X-SVN-Commit-Revision: 359365 X-SVN-Commit-Repository: base 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.29 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: Fri, 27 Mar 2020 15:28:42 -0000 Author: chuck Date: Fri Mar 27 15:28:16 2020 New Revision: 359365 URL: https://svnweb.freebsd.org/changeset/base/359365 Log: bhyve: use STAILQ in NVMe emulation Use the standard queue(3) macros instead of hand-crafted linked list code. Reviewed by: imp, jhb Approved by: jhb (maintainer) MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D24081 Modified: head/usr.sbin/bhyve/pci_nvme.c Modified: head/usr.sbin/bhyve/pci_nvme.c ============================================================================== --- head/usr.sbin/bhyve/pci_nvme.c Fri Mar 27 15:28:11 2020 (r359364) +++ head/usr.sbin/bhyve/pci_nvme.c Fri Mar 27 15:28:16 2020 (r359365) @@ -185,7 +185,7 @@ struct pci_nvme_blockstore { struct pci_nvme_ioreq { struct pci_nvme_softc *sc; - struct pci_nvme_ioreq *next; + STAILQ_ENTRY(pci_nvme_ioreq) link; struct nvme_submission_queue *nvme_sq; uint16_t sqid; @@ -240,7 +240,7 @@ struct pci_nvme_softc { uint32_t num_squeues; struct pci_nvme_ioreq *ioreqs; - struct pci_nvme_ioreq *ioreqs_free; /* free list of ioreqs */ + STAILQ_HEAD(, pci_nvme_ioreq) ioreqs_free; /* free list of ioreqs */ uint32_t pending_ios; uint32_t ioslots; sem_t iosemlock; @@ -1319,8 +1319,7 @@ pci_nvme_release_ioreq(struct pci_nvme_softc *sc, stru pthread_mutex_lock(&sc->mtx); - req->next = sc->ioreqs_free; - sc->ioreqs_free = req; + STAILQ_INSERT_TAIL(&sc->ioreqs_free, req, link); sc->pending_ios--; /* when no more IO pending, can set to ready if device reset/enabled */ @@ -1341,12 +1340,10 @@ pci_nvme_get_ioreq(struct pci_nvme_softc *sc) sem_wait(&sc->iosemlock); pthread_mutex_lock(&sc->mtx); - req = sc->ioreqs_free; + req = STAILQ_FIRST(&sc->ioreqs_free); assert(req != NULL); + STAILQ_REMOVE_HEAD(&sc->ioreqs_free, link); - sc->ioreqs_free = req->next; - - req->next = NULL; req->sc = sc; sc->pending_ios++; @@ -2151,14 +2148,13 @@ pci_nvme_init(struct vmctx *ctx, struct pci_devinst *p else error = 0; + STAILQ_INIT(&sc->ioreqs_free); sc->ioreqs = calloc(sc->ioslots, sizeof(struct pci_nvme_ioreq)); for (int i = 0; i < sc->ioslots; i++) { - if (i < (sc->ioslots-1)) - sc->ioreqs[i].next = &sc->ioreqs[i+1]; + STAILQ_INSERT_TAIL(&sc->ioreqs_free, &sc->ioreqs[i], link); pthread_mutex_init(&sc->ioreqs[i].mtx, NULL); pthread_cond_init(&sc->ioreqs[i].cv, NULL); } - sc->ioreqs_free = sc->ioreqs; sc->intr_coales_aggr_thresh = 1; pci_set_cfgdata16(pi, PCIR_DEVICE, 0x0A0A);