Explorar o código

qcacld-3.0: Convert tx packet send time to Monotonic time

User space timestamping tool expecting Tx packet send time
in Monotonic time and host is sending Tx packet send time in
Qtime.
Currently Qtime is always higher than System monotonic time,
This change is to calculate the drift between Qtime and
System monotonic time during tsf init and adjust calculated
drift to each Tx packet send Qtime to make Qtime and
System monotonic time are in sync.

Change-Id: Ibd686d5fdea6ebcbc0fe5b37c4211cb8dd073d76
CRs-Fixed: 3230594
Balaji Pothunoori %!s(int64=2) %!d(string=hai) anos
pai
achega
f3afa36efa
Modificáronse 2 ficheiros con 23 adicións e 4 borrados
  1. 2 0
      core/hdd/inc/wlan_hdd_main.h
  2. 21 4
      core/hdd/src/wlan_hdd_tsf.c

+ 2 - 0
core/hdd/inc/wlan_hdd_main.h

@@ -1292,6 +1292,7 @@ enum qdisc_filter_status {
  * @is_virtual_iface: Indicates that netdev is called from virtual interface
  * @mon_adapter: hdd_adapter of monitor mode.
  * @set_mac_addr_req_ctx: Set MAC address command request context
+ * @delta_qtime: delta between host qtime and monotonic time
  */
 struct hdd_adapter {
 	/* Magic cookie for adapter sanity verification.  Note that this
@@ -1607,6 +1608,7 @@ struct hdd_adapter {
 #ifdef WLAN_FEATURE_DYNAMIC_MAC_ADDR_UPDATE
 	void *set_mac_addr_req_ctx;
 #endif
+	int64_t delta_qtime;
 };
 
 #define WLAN_HDD_GET_STATION_CTX_PTR(adapter) (&(adapter)->session.station)

+ 21 - 4
core/hdd/src/wlan_hdd_tsf.c

@@ -1468,6 +1468,7 @@ static enum hdd_tsf_op_result hdd_tsf_sync_init(struct hdd_adapter *adapter)
 	QDF_STATUS ret;
 	struct hdd_context *hddctx;
 	struct net_device *net_dev;
+	uint64_t host_time, qtime;
 
 	if (!adapter)
 		return HDD_TSF_OP_FAIL;
@@ -1511,6 +1512,14 @@ static enum hdd_tsf_op_result hdd_tsf_sync_init(struct hdd_adapter *adapter)
 		device_create_file(&net_dev->dev, &dev_attr_tsf);
 	hdd_set_th_sync_status(adapter, true);
 
+	qtime = qdf_get_log_timestamp();
+	host_time = hdd_get_monotonic_host_time(hddctx);
+
+	qtime = qdf_log_timestamp_to_usecs(qtime);
+	do_div(host_time, NSEC_PER_USEC);
+
+	adapter->delta_qtime = (qtime - host_time) * NSEC_PER_USEC;
+
 	return HDD_TSF_OP_SUCC;
 fail:
 	hdd_set_th_sync_status(adapter, false);
@@ -1774,10 +1783,18 @@ enum hdd_tsf_op_result hdd_netbuf_timestamp(qdf_nbuf_t netbuf,
 		int32_t ret = hdd_get_soctime_from_tsf64time(adapter,
 				tsf64_time, &soc_time);
 		if (!ret) {
-			hwtstamps.hwtstamp = soc_time;
-			*skb_hwtstamps(netbuf) = hwtstamps;
-			netbuf->tstamp = ktime_set(0, 0);
-			return HDD_TSF_OP_SUCC;
+			/* Adjust delta_qtime to soc_time(Qtime), so that
+			 * System Monotonic time and Qtime are in sync.
+			 */
+			if (soc_time > (adapter->delta_qtime)) {
+				hwtstamps.hwtstamp =
+				soc_time - (adapter->delta_qtime);
+				*skb_hwtstamps(netbuf) = hwtstamps;
+				netbuf->tstamp = ktime_set(0, 0);
+				return HDD_TSF_OP_SUCC;
+			} else {
+				return HDD_TSF_OP_FAIL;
+			}
 		}
 	}