From owner-dev-commits-src-all@freebsd.org Mon Oct 4 01:13:26 2021 Return-Path: Delivered-To: dev-commits-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 BF644673258; Mon, 4 Oct 2021 01:13:26 +0000 (UTC) (envelope-from git@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) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4HN2lp531Rz4tDX; Mon, 4 Oct 2021 01:13:26 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 8A6CA1091A; Mon, 4 Oct 2021 01:13:26 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1941DQBW007451; Mon, 4 Oct 2021 01:13:26 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1941DQ9K007450; Mon, 4 Oct 2021 01:13:26 GMT (envelope-from git) Date: Mon, 4 Oct 2021 01:13:26 GMT Message-Id: <202110040113.1941DQ9K007450@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Alexander Motin Subject: git: 36e67f5badbd - stable/13 - pcib(4): Switch from callout to timeout_task. MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mav X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 36e67f5badbd834ff7ea2cf039e003d3aac3efc3 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 04 Oct 2021 01:13:26 -0000 The branch stable/13 has been updated by mav: URL: https://cgit.FreeBSD.org/src/commit/?id=36e67f5badbd834ff7ea2cf039e003d3aac3efc3 commit 36e67f5badbd834ff7ea2cf039e003d3aac3efc3 Author: Alexander Motin AuthorDate: 2021-09-03 19:00:21 +0000 Commit: Alexander Motin CommitDate: 2021-10-04 01:13:24 +0000 pcib(4): Switch from callout to timeout_task. This allows to avoid blocking on Giant in callout context, moving to already existing dedicated taskqueue_pci_hp thread. MFC after: 1 month (cherry picked from commit fa3b03d378546b74582613431bab537d3488d81f) --- sys/dev/pci/pci_pci.c | 77 ++++++++++++++++++++++++---------------------- sys/dev/pci/pcib_private.h | 9 +++--- 2 files changed, 45 insertions(+), 41 deletions(-) diff --git a/sys/dev/pci/pci_pci.c b/sys/dev/pci/pci_pci.c index 33e277ed01ae..2b86f2f50e11 100644 --- a/sys/dev/pci/pci_pci.c +++ b/sys/dev/pci/pci_pci.c @@ -77,9 +77,9 @@ static int pcib_ari_enabled(device_t pcib); static void pcib_ari_decode_rid(device_t pcib, uint16_t rid, int *bus, int *slot, int *func); #ifdef PCI_HP -static void pcib_pcie_ab_timeout(void *arg); -static void pcib_pcie_cc_timeout(void *arg); -static void pcib_pcie_dll_timeout(void *arg); +static void pcib_pcie_ab_timeout(void *arg, int pending); +static void pcib_pcie_cc_timeout(void *arg, int pending); +static void pcib_pcie_dll_timeout(void *arg, int pending); #endif static int pcib_request_feature_default(device_t pcib, device_t dev, enum pci_feature feature); @@ -1027,8 +1027,8 @@ pcib_pcie_hotplug_command(struct pcib_softc *sc, uint16_t val, uint16_t mask) (ctl & new) & PCIEM_SLOT_CTL_CCIE) { sc->flags |= PCIB_HOTPLUG_CMD_PENDING; if (!cold) - callout_reset(&sc->pcie_cc_timer, hz, - pcib_pcie_cc_timeout, sc); + taskqueue_enqueue_timeout(taskqueue_pci_hp, + &sc->pcie_cc_task, hz); } } @@ -1043,7 +1043,7 @@ pcib_pcie_hotplug_command_completed(struct pcib_softc *sc) device_printf(dev, "Command Completed\n"); if (!(sc->flags & PCIB_HOTPLUG_CMD_PENDING)) return; - callout_stop(&sc->pcie_cc_timer); + taskqueue_cancel_timeout(taskqueue_pci_hp, &sc->pcie_cc_task, NULL); sc->flags &= ~PCIB_HOTPLUG_CMD_PENDING; wakeup(sc); } @@ -1156,10 +1156,11 @@ pcib_pcie_hotplug_update(struct pcib_softc *sc, uint16_t val, uint16_t mask, device_printf(sc->dev, "Data Link Layer inactive\n"); else - callout_reset(&sc->pcie_dll_timer, hz, - pcib_pcie_dll_timeout, sc); + taskqueue_enqueue_timeout(taskqueue_pci_hp, + &sc->pcie_dll_task, hz); } else if (sc->pcie_link_sta & PCIEM_LINK_STA_DL_ACTIVE) - callout_stop(&sc->pcie_dll_timer); + taskqueue_cancel_timeout(taskqueue_pci_hp, &sc->pcie_dll_task, + NULL); pcib_pcie_hotplug_command(sc, val, mask); @@ -1198,14 +1199,15 @@ pcib_pcie_intr_hotplug(void *arg) device_printf(dev, "Attention Button Pressed: Detach Cancelled\n"); sc->flags &= ~PCIB_DETACH_PENDING; - callout_stop(&sc->pcie_ab_timer); + taskqueue_cancel_timeout(taskqueue_pci_hp, + &sc->pcie_ab_task, NULL); } else if (old_slot_sta & PCIEM_SLOT_STA_PDS) { /* Only initiate detach sequence if device present. */ device_printf(dev, "Attention Button Pressed: Detaching in 5 seconds\n"); sc->flags |= PCIB_DETACH_PENDING; - callout_reset(&sc->pcie_ab_timer, 5 * hz, - pcib_pcie_ab_timeout, sc); + taskqueue_enqueue_timeout(taskqueue_pci_hp, + &sc->pcie_ab_task, 5 * hz); } } if (sc->pcie_slot_sta & PCIEM_SLOT_STA_PFD) @@ -1257,29 +1259,27 @@ pcib_pcie_hotplug_task(void *context, int pending) } static void -pcib_pcie_ab_timeout(void *arg) +pcib_pcie_ab_timeout(void *arg, int pending) { - struct pcib_softc *sc; + struct pcib_softc *sc = arg; - sc = arg; - PCIB_HP_LOCK_ASSERT(sc); + PCIB_HP_LOCK(sc); if (sc->flags & PCIB_DETACH_PENDING) { sc->flags |= PCIB_DETACHING; sc->flags &= ~PCIB_DETACH_PENDING; pcib_pcie_hotplug_update(sc, 0, 0, true); } + PCIB_HP_UNLOCK(sc); } static void -pcib_pcie_cc_timeout(void *arg) +pcib_pcie_cc_timeout(void *arg, int pending) { - struct pcib_softc *sc; - device_t dev; + struct pcib_softc *sc = arg; + device_t dev = sc->dev; uint16_t sta; - sc = arg; - dev = sc->dev; - PCIB_HP_LOCK_ASSERT(sc); + PCIB_HP_LOCK(sc); sta = pcie_read_config(dev, PCIER_SLOT_STA, 2); if (!(sta & PCIEM_SLOT_STA_CC)) { device_printf(dev, "HotPlug Command Timed Out\n"); @@ -1289,18 +1289,17 @@ pcib_pcie_cc_timeout(void *arg) "Missed HotPlug interrupt waiting for Command Completion\n"); pcib_pcie_intr_hotplug(sc); } + PCIB_HP_UNLOCK(sc); } static void -pcib_pcie_dll_timeout(void *arg) +pcib_pcie_dll_timeout(void *arg, int pending) { - struct pcib_softc *sc; - device_t dev; + struct pcib_softc *sc = arg; + device_t dev = sc->dev; uint16_t sta; - sc = arg; - dev = sc->dev; - PCIB_HP_LOCK_ASSERT(sc); + PCIB_HP_LOCK(sc); sta = pcie_read_config(dev, PCIER_LINK_STA, 2); if (!(sta & PCIEM_LINK_STA_DL_ACTIVE)) { device_printf(dev, @@ -1312,6 +1311,7 @@ pcib_pcie_dll_timeout(void *arg) "Missed HotPlug interrupt waiting for DLL Active\n"); pcib_pcie_intr_hotplug(sc); } + PCIB_HP_UNLOCK(sc); } static int @@ -1390,10 +1390,13 @@ pcib_setup_hotplug(struct pcib_softc *sc) uint16_t mask, val; dev = sc->dev; - callout_init(&sc->pcie_ab_timer, 0); - callout_init(&sc->pcie_cc_timer, 0); - callout_init(&sc->pcie_dll_timer, 0); TASK_INIT(&sc->pcie_hp_task, 0, pcib_pcie_hotplug_task, sc); + TIMEOUT_TASK_INIT(taskqueue_pci_hp, &sc->pcie_ab_task, 0, + pcib_pcie_ab_timeout, sc); + TIMEOUT_TASK_INIT(taskqueue_pci_hp, &sc->pcie_cc_task, 0, + pcib_pcie_cc_timeout, sc); + TIMEOUT_TASK_INIT(taskqueue_pci_hp, &sc->pcie_dll_task, 0, + pcib_pcie_dll_timeout, sc); sc->pcie_hp_lock = &Giant; /* Allocate IRQ. */ @@ -1438,12 +1441,14 @@ pcib_detach_hotplug(struct pcib_softc *sc) /* Disable the card in the slot and force it to detach. */ if (sc->flags & PCIB_DETACH_PENDING) { sc->flags &= ~PCIB_DETACH_PENDING; - callout_stop(&sc->pcie_ab_timer); + taskqueue_cancel_timeout(taskqueue_pci_hp, &sc->pcie_ab_task, + NULL); } sc->flags |= PCIB_DETACHING; if (sc->flags & PCIB_HOTPLUG_CMD_PENDING) { - callout_stop(&sc->pcie_cc_timer); + taskqueue_cancel_timeout(taskqueue_pci_hp, &sc->pcie_cc_task, + NULL); tsleep(sc, 0, "hpcmd", hz); sc->flags &= ~PCIB_HOTPLUG_CMD_PENDING; } @@ -1466,9 +1471,9 @@ pcib_detach_hotplug(struct pcib_softc *sc) if (error) return (error); taskqueue_drain(taskqueue_pci_hp, &sc->pcie_hp_task); - callout_drain(&sc->pcie_ab_timer); - callout_drain(&sc->pcie_cc_timer); - callout_drain(&sc->pcie_dll_timer); + taskqueue_drain_timeout(taskqueue_pci_hp, &sc->pcie_ab_task); + taskqueue_drain_timeout(taskqueue_pci_hp, &sc->pcie_cc_task); + taskqueue_drain_timeout(taskqueue_pci_hp, &sc->pcie_dll_task); return (0); } #endif diff --git a/sys/dev/pci/pcib_private.h b/sys/dev/pci/pcib_private.h index 8be7b2123174..af0b70a7add3 100644 --- a/sys/dev/pci/pcib_private.h +++ b/sys/dev/pci/pcib_private.h @@ -35,8 +35,7 @@ #ifndef __PCIB_PRIVATE_H__ #define __PCIB_PRIVATE_H__ -#include -#include +#include #ifdef NEW_PCIB /* @@ -138,9 +137,9 @@ struct pcib_softc struct resource *pcie_irq; void *pcie_ihand; struct task pcie_hp_task; - struct callout pcie_ab_timer; - struct callout pcie_cc_timer; - struct callout pcie_dll_timer; + struct timeout_task pcie_ab_task; + struct timeout_task pcie_cc_task; + struct timeout_task pcie_dll_task; struct mtx *pcie_hp_lock; };