Skip to contentSkip to conversation

scan: fix double space

PATCH Applied James Prestwood 2 participants 6 messages Jan 11, 2022

lore
Share & tools
lore

James Prestwood

author
#0 lore raw

PATCH 1/3 scan: fix double space

---
 src/scan.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/scan.c +1 -1
index 97b0a933..54159dfd 100644
@@ -1695,7 +1695,7 @@ static void scan_finished(struct scan_context *sc,
 	if (bss_list)
 		discover_hidden_network_bsses(sc, bss_list);
 
-	if  (sr) {
+	if (sr) {
 		l_queue_remove(sc->requests, sr);
 		sc->started = false;
 		sc->work_started = false;
Signature · 1 line
2.31.1
author
#1 lore raw

PATCH 2/3 scan: set scan priority via scan_common

This adds a priority argument to scan_common rather than hard coding it when inserting the work item

---
 src/scan.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)
src/scan.c +12 -7
index 54159dfd..96907e59 100644
@@ -52,6 +52,8 @@
 #include "src/band.h"
 #include "src/scan.h"
 
+#define SCAN_WORK_PRIORITY 2
+
 /* User configurable options */
 static double RANK_5G_FACTOR;
 static uint32_t SCAN_MAX_INTERVAL;
@@ -607,6 +609,7 @@ static struct scan_request *scan_request_new(struct scan_context *sc,
 
 static uint32_t scan_common(uint64_t wdev_id, bool passive,
 				const struct scan_parameters *params,
+				int priority,
 				scan_trigger_func_t trigger,
 				scan_notify_func_t notify, void *userdata,
 				scan_destroy_func_t destroy)
@@ -625,7 +628,8 @@ static uint32_t scan_common(uint64_t wdev_id, bool passive,
 
 	l_queue_push_tail(sc->requests, sr);
 
-	return wiphy_radio_work_insert(sc->wiphy, &sr->work, 2, &work_ops);
+	return wiphy_radio_work_insert(sc->wiphy, &sr->work,
+					priority, &work_ops);
 }
 
 uint32_t scan_passive(uint64_t wdev_id, struct scan_freq_set *freqs,
@@ -634,8 +638,8 @@ uint32_t scan_passive(uint64_t wdev_id, struct scan_freq_set *freqs,
 {
 	struct scan_parameters params = { .freqs = freqs };
 
-	return scan_common(wdev_id, true, &params, trigger, notify,
-							userdata, destroy);
+	return scan_common(wdev_id, true, &params, SCAN_WORK_PRIORITY, trigger,
+				notify, userdata, destroy);
 }
 
 uint32_t scan_passive_full(uint64_t wdev_id,
@@ -644,7 +648,7 @@ uint32_t scan_passive_full(uint64_t wdev_id,
 			scan_notify_func_t notify, void *userdata,
 			scan_destroy_func_t destroy)
 {
-	return scan_common(wdev_id, true, params, trigger,
+	return scan_common(wdev_id, true, params, SCAN_WORK_PRIORITY, trigger,
 				notify, userdata, destroy);
 }
 
@@ -658,7 +662,7 @@ uint32_t scan_active(uint64_t wdev_id, uint8_t *extra_ie, size_t extra_ie_size,
 	params.extra_ie = extra_ie;
 	params.extra_ie_size = extra_ie_size;
 
-	return scan_common(wdev_id, false, &params,
+	return scan_common(wdev_id, false, &params, SCAN_WORK_PRIORITY,
 					trigger, notify, userdata, destroy);
 }
 
@@ -667,7 +671,7 @@ uint32_t scan_active_full(uint64_t wdev_id,
 			scan_trigger_func_t trigger, scan_notify_func_t notify,
 			void *userdata, scan_destroy_func_t destroy)
 {
-	return scan_common(wdev_id, false, params,
+	return scan_common(wdev_id, false, params, SCAN_WORK_PRIORITY,
 					trigger, notify, userdata, destroy);
 }
 
@@ -795,7 +799,8 @@ uint32_t scan_owe_hidden(uint64_t wdev_id, struct l_queue *list,
 done:
 	l_queue_push_tail(sc->requests, sr);
 
-	return wiphy_radio_work_insert(sc->wiphy, &sr->work, 2, &work_ops);
+	return wiphy_radio_work_insert(sc->wiphy, &sr->work,
+					SCAN_WORK_PRIORITY, &work_ops);
 }
 
 bool scan_cancel(uint64_t wdev_id, uint32_t id)
Signature · 1 line
2.31.1
#2 lore raw

Re: [PATCH 2/3] scan: set scan priority via scan_common

Quoted 11 lines · James Prestwood

This adds a priority argument to scan_common rather than hard coding it when inserting the work item

---
  src/scan.c | 19 ++++++++++++-------
  1 file changed, 12 insertions(+), 7 deletions(-)
src/scan.c +0 -0
index 54159dfd..96907e59 100644

src/scan.c line 55

Quoted 4 lines
src/scan.c +1 -0
@@ -52,6 +52,8 @@
  #include "src/band.h"
  #include "src/scan.h"
 
+#define SCAN_WORK_PRIORITY 2

Can we name this SCAN_REQUEST_PRIORITY, or even simply REQUEST_PRIORITY?

Also, I wonder if we should put the priority numbers into wiphy.h instead of relying on hard-coded 1/2/3 everywhere.

Regards,
-Denis

author
#3 lore raw

PATCH 3/3 scan: don't special case periodic scan work

In reply to James Prestwood

Periodic scans were handled specially where they were only started if no other requests were pending in the scan queue. This is fine, and what we want, but this can actually be handled automatically by nature of the wiphy work queue rather than needing to check the request queue explicitly.

Instead we can insert periodic scans at a lower priority than other scans. This puts them at the end of the work queue, as well as allows future requests to jump ahead if a periodic scan has not yet started.

Eventually, once all pending scans are done, the peridoic scan may begin. This is no different than the preivous behavior and avoids the need for any special checks once scan requests complete.

One check was added to address the problem of the periodic scan timer firing before the scan could even start. Currently this happened to be handled fine in scan_periodic_queue, as it checks the queue length. Since this check was removed we must see check for this condition inside scan_periodic_timeout.

---
 src/scan.c | 48 +++++++++++++++++++++++++++---------------------
 1 file changed, 27 insertions(+), 21 deletions(-)
src/scan.c +27 -21
index 96907e59..cfcbbd3a 100644
@@ -71,7 +71,6 @@ struct scan_periodic {
 	scan_trigger_func_t trigger;
 	scan_notify_func_t callback;
 	void *userdata;
-	bool retry:1;
 	uint32_t id;
 	bool needs_active_scan:1;
 };
@@ -883,27 +882,30 @@ static bool scan_periodic_notify(int err, struct l_queue *bss_list,
 	return false;
 }
 
+static void scan_periodic_destroy(void *user_data)
+{
+	struct scan_context *sc = user_data;
+
+	sc->sp.id = 0;
+}
+
 static bool scan_periodic_queue(struct scan_context *sc)
 {
-	if (!l_queue_isempty(sc->requests)) {
-		sc->sp.retry = true;
-		return false;
-	}
+	struct scan_parameters params = {};
 
 	if (sc->sp.needs_active_scan && known_networks_has_hidden()) {
-		struct scan_parameters params = {
-			.randomize_mac_addr_hint = true
-		};
+		params.randomize_mac_addr_hint = true;
 
 		sc->sp.needs_active_scan = false;
-
-		sc->sp.id = scan_active_full(sc->wdev_id, &params,
-						scan_periodic_triggered,
-						scan_periodic_notify, sc, NULL);
+		sc->sp.id = scan_common(sc->wdev_id, false, &params,
+					SCAN_WORK_PRIORITY + 1,
+					scan_periodic_triggered,
+					scan_periodic_notify, sc, NULL);
 	} else
-		sc->sp.id = scan_passive(sc->wdev_id, NULL,
-						scan_periodic_triggered,
-						scan_periodic_notify, sc, NULL);
+		sc->sp.id = scan_common(sc->wdev_id, true, &params,
+					SCAN_WORK_PRIORITY + 1,
+					scan_periodic_triggered,
+					scan_periodic_notify, sc, NULL);
 
 	return sc->sp.id != 0;
 }
@@ -975,7 +977,6 @@ bool scan_periodic_stop(uint64_t wdev_id)
 	sc->sp.trigger = NULL;
 	sc->sp.callback = NULL;
 	sc->sp.userdata = NULL;
-	sc->sp.retry = false;
 	sc->sp.needs_active_scan = false;
 
 	return true;
@@ -1006,6 +1007,16 @@ static void scan_periodic_timeout(struct l_timeout *timeout, void *user_data)
 
 	l_debug("scan_periodic_timeout: %" PRIx64, sc->wdev_id);
 
+	/*
+	 * Timeout triggered before periodic scan could even start, just rearm
+	 * with the same interval.
+	 */
+	if (sc->sp.id) {
+		l_warn("Periodic scan timer called before scan could start!");
+		scan_periodic_rearm(sc);
+		return;
+	}
+
 	sc->sp.interval *= 2;
 	if (sc->sp.interval > SCAN_MAX_INTERVAL)
 		sc->sp.interval = SCAN_MAX_INTERVAL;
@@ -1050,11 +1061,6 @@ static bool start_next_scan_request(struct wiphy_radio_work_item *item)
 
 	scan_request_failed(sc, sr, -EIO);
 
-	if (sc->sp.retry) {
-		sc->sp.retry = false;
-		scan_periodic_queue(sc);
-	}
-
 	return true;
 }
 
Signature · 1 line
2.31.1
#4 lore raw

Re: [PATCH 3/3] scan: don't special case periodic scan work

Hi James,

Quoted 25 lines · James Prestwood

Periodic scans were handled specially where they were only started if no other requests were pending in the scan queue. This is fine, and what we want, but this can actually be handled automatically by nature of the wiphy work queue rather than needing to check the request queue explicitly.

Instead we can insert periodic scans at a lower priority than other scans. This puts them at the end of the work queue, as well as allows future requests to jump ahead if a periodic scan has not yet started.

Eventually, once all pending scans are done, the peridoic scan may begin. This is no different than the preivous behavior and avoids the need for any special checks once scan requests complete.

One check was added to address the problem of the periodic scan timer firing before the scan could even start. Currently this happened to be handled fine in scan_periodic_queue, as it checks the queue length. Since this check was removed we must see check for this condition inside scan_periodic_timeout.

---
  src/scan.c | 48 +++++++++++++++++++++++++++---------------------
  1 file changed, 27 insertions(+), 21 deletions(-)

<snip>

src/scan.c static bool scan_periodic_notify(int err, struct l_queue *bss_list, · line 891

Quoted 11 lines
src/scan.c +7 -0
@@ -883,27 +882,30 @@ static bool scan_periodic_notify(int err, struct l_queue *bss_list,
  	return false;
  }
 
+static void scan_periodic_destroy(void *user_data)
+{
+	struct scan_context *sc = user_data;
+
+	sc->sp.id = 0;
+}
+

This isn't being used?

Quoted 11 lines
src/scan.c +1 -6
  static bool scan_periodic_queue(struct scan_context *sc)
  {
-	if (!l_queue_isempty(sc->requests)) {
-		sc->sp.retry = true;
-		return false;
-	}
+	struct scan_parameters params = {};
 
  	if (sc->sp.needs_active_scan && known_networks_has_hidden()) {
-		struct scan_parameters params = {
-			.randomize_mac_addr_hint = true

src/scan.c static bool scan_periodic_notify(int err, struct l_queue *bss_list, · line 901

Quoted 10 lines
src/scan.c +3 -5
-		};
+		params.randomize_mac_addr_hint = true;
 
  		sc->sp.needs_active_scan = false;
-
-		sc->sp.id = scan_active_full(sc->wdev_id, &params,
-						scan_periodic_triggered,
-						scan_periodic_notify, sc, NULL);
+		sc->sp.id = scan_common(sc->wdev_id, false, &params,
+					SCAN_WORK_PRIORITY + 1,

This probably warrants its own define

Quoted 13 lines
src/scan.c +6 -3
+					scan_periodic_triggered,
+					scan_periodic_notify, sc, NULL);
  	} else
-		sc->sp.id = scan_passive(sc->wdev_id, NULL,
-						scan_periodic_triggered,
-						scan_periodic_notify, sc, NULL);
+		sc->sp.id = scan_common(sc->wdev_id, true, &params,
+					SCAN_WORK_PRIORITY + 1,
+					scan_periodic_triggered,
+					scan_periodic_notify, sc, NULL);
 
  	return sc->sp.id != 0;
  }

<snip>

src/scan.c static void scan_periodic_timeout(struct l_timeout *timeout, void *user_data) · line 1015

Quoted 10 lines
src/scan.c +6 -0
@@ -1006,6 +1007,16 @@ static void scan_periodic_timeout(struct l_timeout *timeout, void *user_data)
 
  	l_debug("scan_periodic_timeout: %" PRIx64, sc->wdev_id);
 
+	/*
+	 * Timeout triggered before periodic scan could even start, just rearm
+	 * with the same interval.
+	 */
+	if (sc->sp.id) {
+		l_warn("Periodic scan timer called before scan could start!");

Not sure this is l_warn worthy. I would downgrade this to l_debug.

src/scan.c static void scan_periodic_timeout(struct l_timeout *timeout, void *user_data) · line 1022

Quoted 7 lines
src/scan.c +4 -0
+		scan_periodic_rearm(sc);
+		return;
+	}
+
  	sc->sp.interval *= 2;
  	if (sc->sp.interval > SCAN_MAX_INTERVAL)
  		sc->sp.interval = SCAN_MAX_INTERVAL;

Regards,
-Denis

Applied
#5 lore raw
In reply to James Prestwood

Hi James,

Quoted 4 lines · James Prestwood
---
  src/scan.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

Applied, thanks.

Regards,
-Denis