All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH AUTOSEL 5.4 01/23] iwlwifi: pcie: limit memory read spin time
@ 2020-12-03 13:29 Sasha Levin
  2020-12-03 13:29   ` Sasha Levin
                   ` (21 more replies)
  0 siblings, 22 replies; 33+ messages in thread
From: Sasha Levin @ 2020-12-03 13:29 UTC (permalink / raw)
  To: linux-kernel, stable
  Cc: Johannes Berg, Mordechay Goodstein, Luca Coelho, Kalle Valo,
	Sasha Levin, linux-wireless, netdev

From: Johannes Berg <johannes.berg@intel.com>

[ Upstream commit 04516706bb99889986ddfa3a769ed50d2dc7ac13 ]

When we read device memory, we lock a spinlock, write the address we
want to read from the device and then spin in a loop reading the data
in 32-bit quantities from another register.

As the description makes clear, this is rather inefficient, incurring
a PCIe bus transaction for every read. In a typical device today, we
want to read 786k SMEM if it crashes, leading to 192k register reads.
Occasionally, we've seen the whole loop take over 20 seconds and then
triggering the soft lockup detector.

Clearly, it is unreasonable to spin here for such extended periods of
time.

To fix this, break the loop down into an outer and an inner loop, and
break out of the inner loop if more than half a second elapsed. To
avoid too much overhead, check for that only every 128 reads, though
there's no particular reason for that number. Then, unlock and relock
to obtain NIC access again, reprogram the start address and continue.

This will keep (interrupt) latencies on the CPU down to a reasonable
time.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Mordechay Goodstein <mordechay.goodstein@intel.com>
Signed-off-by: Luca Coelho <luciano.coelho@intel.com>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
Link: https://lore.kernel.org/r/iwlwifi.20201022165103.45878a7e49aa.I3b9b9c5a10002915072312ce75b68ed5b3dc6e14@changeid
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 .../net/wireless/intel/iwlwifi/pcie/trans.c   | 36 ++++++++++++++-----
 1 file changed, 27 insertions(+), 9 deletions(-)

diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/trans.c b/drivers/net/wireless/intel/iwlwifi/pcie/trans.c
index c76d26708e659..ef5a8ecabc60a 100644
--- a/drivers/net/wireless/intel/iwlwifi/pcie/trans.c
+++ b/drivers/net/wireless/intel/iwlwifi/pcie/trans.c
@@ -2178,18 +2178,36 @@ static int iwl_trans_pcie_read_mem(struct iwl_trans *trans, u32 addr,
 				   void *buf, int dwords)
 {
 	unsigned long flags;
-	int offs, ret = 0;
+	int offs = 0;
 	u32 *vals = buf;
 
-	if (iwl_trans_grab_nic_access(trans, &flags)) {
-		iwl_write32(trans, HBUS_TARG_MEM_RADDR, addr);
-		for (offs = 0; offs < dwords; offs++)
-			vals[offs] = iwl_read32(trans, HBUS_TARG_MEM_RDAT);
-		iwl_trans_release_nic_access(trans, &flags);
-	} else {
-		ret = -EBUSY;
+	while (offs < dwords) {
+		/* limit the time we spin here under lock to 1/2s */
+		ktime_t timeout = ktime_add_us(ktime_get(), 500 * USEC_PER_MSEC);
+
+		if (iwl_trans_grab_nic_access(trans, &flags)) {
+			iwl_write32(trans, HBUS_TARG_MEM_RADDR,
+				    addr + 4 * offs);
+
+			while (offs < dwords) {
+				vals[offs] = iwl_read32(trans,
+							HBUS_TARG_MEM_RDAT);
+				offs++;
+
+				/* calling ktime_get is expensive so
+				 * do it once in 128 reads
+				 */
+				if (offs % 128 == 0 && ktime_after(ktime_get(),
+								   timeout))
+					break;
+			}
+			iwl_trans_release_nic_access(trans, &flags);
+		} else {
+			return -EBUSY;
+		}
 	}
-	return ret;
+
+	return 0;
 }
 
 static int iwl_trans_pcie_write_mem(struct iwl_trans *trans, u32 addr,
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 33+ messages in thread

end of thread, other threads:[~2020-12-03 14:52 UTC | newest]

Thread overview: 33+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-03 13:29 [PATCH AUTOSEL 5.4 01/23] iwlwifi: pcie: limit memory read spin time Sasha Levin
2020-12-03 13:29 ` [PATCH AUTOSEL 5.4 02/23] arm64: dts: rockchip: Assign a fixed index to mmc devices on rk3399 boards Sasha Levin
2020-12-03 13:29   ` Sasha Levin
2020-12-03 13:29   ` Sasha Levin
2020-12-03 13:29 ` [PATCH AUTOSEL 5.4 03/23] iwlwifi: pcie: set LTR to avoid completion timeout Sasha Levin
2020-12-03 13:29 ` [PATCH AUTOSEL 5.4 04/23] iwlwifi: mvm: fix kernel panic in case of assert during CSA Sasha Levin
2020-12-03 13:29 ` [PATCH AUTOSEL 5.4 05/23] powerpc: Drop -me200 addition to build flags Sasha Levin
2020-12-03 13:29   ` Sasha Levin
2020-12-03 13:29 ` [PATCH AUTOSEL 5.4 06/23] arm64: dts: broadcom: clear the warnings caused by empty dma-ranges Sasha Levin
2020-12-03 13:29   ` Sasha Levin
2020-12-03 13:29 ` [PATCH AUTOSEL 5.4 07/23] ARC: stack unwinding: don't assume non-current task is sleeping Sasha Levin
2020-12-03 13:29   ` Sasha Levin
2020-12-03 13:29 ` [PATCH AUTOSEL 5.4 08/23] scsi: ufs: Make sure clk scaling happens only when HBA is runtime ACTIVE Sasha Levin
2020-12-03 13:29   ` Sasha Levin
2020-12-03 13:29   ` Sasha Levin
2020-12-03 13:29 ` [PATCH AUTOSEL 5.4 09/23] interconnect: qcom: qcs404: Remove GPU and display RPM IDs Sasha Levin
2020-12-03 13:29 ` [PATCH AUTOSEL 5.4 10/23] usbnet: ipheth: fix connectivity with iOS 14 Sasha Levin
2020-12-03 13:29 ` [PATCH AUTOSEL 5.4 11/23] tun: honor IOCB_NOWAIT flag Sasha Levin
2020-12-03 13:29 ` [PATCH AUTOSEL 5.4 12/23] ibmvnic: skip tx timeout reset while in resetting Sasha Levin
2020-12-03 13:29   ` Sasha Levin
2020-12-03 13:29 ` [PATCH AUTOSEL 5.4 13/23] irqchip/gic-v3-its: Unconditionally save/restore the ITS state on suspend Sasha Levin
2020-12-03 13:29 ` [PATCH AUTOSEL 5.4 14/23] spi: spi-nxp-fspi: fix fspi panic by unexpected interrupts Sasha Levin
2020-12-03 13:29 ` [PATCH AUTOSEL 5.4 15/23] soc: fsl: dpio: Get the cpumask through cpumask_of(cpu) Sasha Levin
2020-12-03 13:29   ` Sasha Levin
2020-12-03 13:29   ` Sasha Levin
2020-12-03 13:29 ` [PATCH AUTOSEL 5.4 16/23] arm64: tegra: Disable the ACONNECT for Jetson TX2 Sasha Levin
2020-12-03 13:29 ` [PATCH AUTOSEL 5.4 17/23] platform/x86: thinkpad_acpi: Do not report SW_TABLET_MODE on Yoga 11e Sasha Levin
2020-12-03 13:29 ` [PATCH AUTOSEL 5.4 18/23] platform/x86: thinkpad_acpi: Add BAT1 is primary battery quirk for Thinkpad Yoga 11e 4th gen Sasha Levin
2020-12-03 13:29 ` [PATCH AUTOSEL 5.4 19/23] platform/x86: acer-wmi: add automatic keyboard background light toggle key as KEY_LIGHTS_TOGGLE Sasha Levin
2020-12-03 13:29 ` [PATCH AUTOSEL 5.4 20/23] platform/x86: intel-vbtn: Support for tablet mode on HP Pavilion 13 x360 PC Sasha Levin
2020-12-03 13:29 ` [PATCH AUTOSEL 5.4 21/23] platform/x86: touchscreen_dmi: Add info for the Irbis TW118 tablet Sasha Levin
2020-12-03 13:29 ` [PATCH AUTOSEL 5.4 22/23] can: m_can: m_can_dev_setup(): add support for bosch mcan version 3.3.0 Sasha Levin
2020-12-03 13:29 ` [PATCH AUTOSEL 5.4 23/23] can: af_can: can_rx_unregister(): remove WARN() statement from list operation sanity check Sasha Levin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.