From: Benjamin Berg The mac80211_hwsim base time for the simulation of the TSF was based on the real time of the system. This clock is subject to unexpected changes. Switch it to use boottime which is always monotonic and also continues to run through times where the system is suspended. Also change the function name from tsf_raw to sim_tsf to better differentiate between the TSF of the mac and the TSF base of the simulation. Signed-off-by: Benjamin Berg --- .../wireless/virtual/mac80211_hwsim_main.c | 33 ++++++++++--------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/drivers/net/wireless/virtual/mac80211_hwsim_main.c b/drivers/net/wireless/virtual/mac80211_hwsim_main.c index dc2e2a2ece7b..75dfb4e51612 100644 --- a/drivers/net/wireless/virtual/mac80211_hwsim_main.c +++ b/drivers/net/wireless/virtual/mac80211_hwsim_main.c @@ -1111,22 +1111,25 @@ static netdev_tx_t hwsim_mon_xmit(struct sk_buff *skb, return NETDEV_TX_OK; } -static inline u64 mac80211_hwsim_get_tsf_raw(void) +static inline u64 mac80211_hwsim_get_sim_tsf(void) { - return ktime_to_us(ktime_get_real()); -} - -static __le64 __mac80211_hwsim_get_tsf(struct mac80211_hwsim_data *data) -{ - u64 now = mac80211_hwsim_get_tsf_raw(); - return cpu_to_le64(now + data->tsf_offset); + return ktime_to_us(ktime_get_boottime()); } u64 mac80211_hwsim_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif) { struct mac80211_hwsim_data *data = hw->priv; - return le64_to_cpu(__mac80211_hwsim_get_tsf(data)); + u64 sim_time = mac80211_hwsim_get_sim_tsf(); + + return sim_time + data->tsf_offset; +} + +static __le64 __mac80211_hwsim_get_tsf(struct mac80211_hwsim_data *data) +{ + u64 sim_time = mac80211_hwsim_get_sim_tsf(); + + return cpu_to_le64(sim_time + data->tsf_offset); } static void mac80211_hwsim_set_tsf(struct ieee80211_hw *hw, @@ -1678,7 +1681,7 @@ static bool mac80211_hwsim_tx_frame_no_nl(struct ieee80211_hw *hw, struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); struct ieee80211_rx_status rx_status; - u64 now; + u64 sim_tsf; memset(&rx_status, 0, sizeof(rx_status)); rx_status.flag |= RX_FLAG_MACTIME_START; @@ -1731,9 +1734,9 @@ static bool mac80211_hwsim_tx_frame_no_nl(struct ieee80211_hw *hw, if (ieee80211_is_beacon(hdr->frame_control) || ieee80211_is_probe_resp(hdr->frame_control)) { rx_status.boottime_ns = ktime_get_boottime_ns(); - now = data->abs_bcn_ts; + sim_tsf = data->abs_bcn_ts; } else { - now = mac80211_hwsim_get_tsf_raw(); + sim_tsf = mac80211_hwsim_get_sim_tsf(); } /* Copy skb to all enabled radios that are on the current frequency */ @@ -1794,7 +1797,7 @@ static bool mac80211_hwsim_tx_frame_no_nl(struct ieee80211_hw *hw, if (mac80211_hwsim_addr_match(data2, hdr->addr1)) ack = true; - rx_status.mactime = now + data2->tsf_offset; + rx_status.mactime = sim_tsf + data2->tsf_offset; mac80211_hwsim_rx(data2, &rx_status, nskb); } @@ -2011,7 +2014,7 @@ static void mac80211_hwsim_tx(struct ieee80211_hw *hw, txrate = ieee80211_get_tx_rate(hw, txi); if (txrate) bitrate = txrate->bitrate; - ts = mac80211_hwsim_get_tsf_raw(); + ts = mac80211_hwsim_get_sim_tsf(); mgmt->u.probe_resp.timestamp = cpu_to_le64(ts + data->tsf_offset + 24 * 8 * 10 / bitrate); @@ -2194,7 +2197,7 @@ static void __mac80211_hwsim_beacon_tx(struct ieee80211_bss_conf *link_conf, mgmt = (struct ieee80211_mgmt *) skb->data; /* fake header transmission time */ - data->abs_bcn_ts = mac80211_hwsim_get_tsf_raw(); + data->abs_bcn_ts = mac80211_hwsim_get_sim_tsf(); if (ieee80211_is_s1g_beacon(mgmt->frame_control)) { struct ieee80211_ext *ext = (void *) mgmt; -- 2.51.1