Эх сурвалжийг харах

qcacmn: Modify the get chan enum API to binary search

Modify the get API that fetches the channel index given a frequency,
from a linear search to a binary search to improve the search time.

CRs-Fixed: 3230932
Change-Id: Id6a1a20d80989a797505772954fb913c4f57d227
Vignesh Mohan 3 жил өмнө
parent
commit
93eaeb9799

+ 13 - 4
umac/regulatory/core/src/reg_services_common.c

@@ -3236,11 +3236,20 @@ QDF_STATUS reg_get_channel_list_with_power_for_freq(struct wlan_objmgr_pdev
 
 enum channel_enum reg_get_chan_enum_for_freq(qdf_freq_t freq)
 {
-	uint32_t count;
+	int16_t start = 0;
+	int16_t end = NUM_CHANNELS - 1;
+
+	while (start <= end) {
+		int16_t middle = (start + end) / 2;
+		qdf_freq_t mid_freq_elem = channel_map[middle].center_freq;
 
-	for (count = 0; count < NUM_CHANNELS; count++)
-		if (channel_map[count].center_freq == freq)
-			return count;
+		if (freq == mid_freq_elem)
+			return middle;
+		if (freq > mid_freq_elem)
+			start = middle + 1;
+		else
+			end = middle - 1;
+	}
 
 	reg_debug_rl("invalid channel center frequency %d", freq);