Skip to contentSkip to conversation

wifi: ath11k: Fix 2 second busywait during stats request

PATCH New Yury Vostrikov 1 participant 2 messages Nov 21, 2024 Qualcomm Atheros ATH11K wireless driver

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 wifi: ath11k: Fix 2 second busywait during stats request

This diff fixes a 2-second busy loop inside
the ath11k_debugfs_fw_stats_request function. The code in question was added during the initial import of the ath11 driver. While the ath11 code is based on ath10, the latter doesn't have this bug. This diffs changes the wait loop to be similar to the ath10 driver. It also adds an explicit delay before retrying. An explicit delay avoids spamming FW with stats requests.

---
 drivers/net/wireless/ath/ath11k/debugfs.c | 33 +++++++++++------------
 1 file changed, 16 insertions(+), 17 deletions(-)
drivers/net/wireless/ath/ath11k/debugfs.c +16 -17
index 57281a135dd7..436197113ced 100644
@@ -182,24 +182,22 @@ static int ath11k_debugfs_fw_stats_request(struct ath11k *ar,
 
 	ath11k_debugfs_fw_stats_reset(ar);
 
-	reinit_completion(&ar->fw_stats_complete);
-
-	ret = ath11k_wmi_send_stats_request_cmd(ar, req_param);
-
-	if (ret) {
-		ath11k_warn(ab, "could not request fw stats (%d)\n",
-			    ret);
-		return ret;
-	}
-
-	time_left = wait_for_completion_timeout(&ar->fw_stats_complete, 1 * HZ);
-
-	if (!time_left)
-		return -ETIMEDOUT;
-
 	for (;;) {
-		if (time_after(jiffies, timeout))
-			break;
+		if (time_after(jiffies, timeout)) {
+			ath11k_warn(ab, "could not request fw stats, timeout\n");
+			return -ETIMEDOUT;
+		}
+
+		reinit_completion(&ar->fw_stats_complete);
+
+		ret = ath11k_wmi_send_stats_request_cmd(ar, req_param);
+		if (ret) {
+			ath11k_warn(ab, "could not request fw stats (%d)\n",
+				    ret);
+			return ret;
+		}
+
+		time_left = wait_for_completion_timeout(&ar->fw_stats_complete, 1 * HZ);
 
 		spin_lock_bh(&ar->data_lock);
 		if (ar->fw_stats_done) {
@@ -207,6 +205,7 @@ static int ath11k_debugfs_fw_stats_request(struct ath11k *ar,
 			break;
 		}
 		spin_unlock_bh(&ar->data_lock);
+		msleep(200);
 	}
 	return 0;
 }
Signature · 1 line
2.39.5
#1 lore raw

PATCH 2/2 wifi: ath11k: Fix race condition during stats processing

This diff fixes the race condition in stats processing. This race condition results in an unbounded loop of stats requests. The loop results in poor network performance because FW is busy with those extra requests. The timeout of ath11k_debugfs_fw_stats_request should be the upper bound of how long the driver retries stats. However, sometimes some other code keeps calling failing ath11k_debugfs_fw_stats_request, repeating a vicious cycle indefinitely.

ath11k_debugfs_fw_stats_process assumes that num_vdev is always less or equal to total_vdevs_started. This is not true. I've captured the state of num_vdev and total_vdev_started during the re-association request:

ath11k_pci 0000:01:00.0: wmi num_vdev:1 total_vdevs_started:0 ath11k_pci 0000:01:00.0: wmi num_vdev:2 total_vdevs_started:0 ath11k_pci 0000:01:00.0: wmi num_vdev:3 total_vdevs_started:1 ath11k_pci 0000:01:00.0: wmi num_vdev:4 total_vdevs_started:1 [...]
ath11k_pci 0000:01:00.0: wmi num_vdev:116 total_vdevs_started:1 [...]

This diff fixes the check to account for this and also adds a warning.

---
 drivers/net/wireless/ath/ath11k/debugfs.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/wireless/ath/ath11k/debugfs.c +3 -1
index 436197113ced..ec4683695e73 100644
@@ -132,7 +132,9 @@ void ath11k_debugfs_fw_stats_process(struct ath11k *ar, struct ath11k_fw_stats *
 				total_vdevs_started += ar->num_started_vdevs;
 		}
 
-		is_end = ((++num_vdev) == total_vdevs_started);
+		is_end = ((++num_vdev) >= total_vdevs_started);
+		if (num_vdev > total_vdevs_started)
+			ath11k_warn(ab, "spurious stats");
 
 		list_splice_tail_init(&stats->vdevs,
 				      &ar->fw_stats.vdevs);
Signature · 1 line
2.39.5