From patchwork Thu Dec 19 08:37:58 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Pedersen X-Patchwork-Id: 3375661 Return-Path: X-Original-To: patchwork-linux-wireless@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 396C39F344 for ; Thu, 19 Dec 2013 08:39:34 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 37B0F2062F for ; Thu, 19 Dec 2013 08:39:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 180E52061D for ; Thu, 19 Dec 2013 08:39:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752727Ab3LSIjS (ORCPT ); Thu, 19 Dec 2013 03:39:18 -0500 Received: from mail-pd0-f182.google.com ([209.85.192.182]:36665 "EHLO mail-pd0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752692Ab3LSIjQ (ORCPT ); Thu, 19 Dec 2013 03:39:16 -0500 Received: by mail-pd0-f182.google.com with SMTP id v10so833565pde.27 for ; Thu, 19 Dec 2013 00:39:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=k3vj3/OqkQv6WpGMYzpohmRsUhM83f3GhZQWGOoehL0=; b=jAd4NM2LQtMXKq5TUJfiD4Sm88P97ioIx3fck95GRRsz7N1K0Wr0v6ylDJgjugmDn7 +9bYnYXjDkNkVq3hR5Y9RjTbN1GnNgJEvAcC2vvSxkXn1vb+J/wzyM5JWW298PlrUxaB 3y1MBCIj3oVUkXTWl+Rq0mcBbZbEtiLBwpmro/SJA7aFqgQTaHIQSeKDZRFptAQfjd89 7i0SD9XjHwOv6aOQGH+GLi2aKW3BPBwSFuAFQ9M4cqSdyp4M9Rnn6SResvFT+3gcpxtd zxsJiEoBkna3j3BZijtLyIPoOrJg0K5Eyxyi/Qg1mVIqSuKJJjRmM4FvAGRfTgtcFjne FEUg== X-Received: by 10.68.164.131 with SMTP id yq3mr344627pbb.56.1387442355834; Thu, 19 Dec 2013 00:39:15 -0800 (PST) Received: from localhost.localdomain (c-69-181-202-165.hsd1.ca.comcast.net. [69.181.202.165]) by mx.google.com with ESMTPSA id om6sm5406493pbc.43.2013.12.19.00.39.14 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Dec 2013 00:39:15 -0800 (PST) From: Thomas Pedersen To: Johannes Berg Cc: linux-wireless , open80211s , Thomas Pedersen Subject: [PATCH 1/2] mac80211_hwsim: fix duplicate beacons on TSF adjust Date: Thu, 19 Dec 2013 00:37:58 -0800 Message-Id: <1387442279-1526-1-git-send-email-twpedersen@gmail.com> X-Mailer: git-send-email 1.7.10.4 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Thomas Pedersen There was some bug when rescheduling the next beacon from the beacon tasklet after adjusting TSF which would cause the beacon timer to trigger twice. Beaconing at "old" TBT (previously scheduled interface TBTT) with new timestamp was incorrect anyway. Instead, reschedule the beacon straight away when adjusting TSF. Signed-off-by: Thomas Pedersen --- v2: don't kill hrtimer tasklet if currently running to avoid deadlock (Johannes) The wpa_supplicant hwsim tests pass with this patch now. drivers/net/wireless/mac80211_hwsim.c | 57 +++++++++++++++------------------ 1 file changed, 26 insertions(+), 31 deletions(-) diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c index 9c0cc8d..cf3b9d3 100644 --- a/drivers/net/wireless/mac80211_hwsim.c +++ b/drivers/net/wireless/mac80211_hwsim.c @@ -442,17 +442,36 @@ static u64 mac80211_hwsim_get_tsf(struct ieee80211_hw *hw, return le64_to_cpu(__mac80211_hwsim_get_tsf(data)); } +static void mac80211_hwsim_beacon_sched(struct ieee80211_hw *hw) +{ + struct mac80211_hwsim_data *data = hw->priv; + u64 tsf = mac80211_hwsim_get_tsf(hw, NULL); + u32 bcn_int = data->beacon_int; + u64 until_tbtt; + + if (!bcn_int) + return; + + until_tbtt = bcn_int - do_div(tsf, bcn_int); + if (!hrtimer_callback_running(&data->beacon_timer.timer) && + !test_bit(TASKLET_STATE_RUN, &data->beacon_timer.tasklet.state)) + tasklet_hrtimer_cancel(&data->beacon_timer); + tasklet_hrtimer_start(&data->beacon_timer, + ns_to_ktime(until_tbtt * 1000), + HRTIMER_MODE_REL); +} + static void mac80211_hwsim_set_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif, u64 tsf) { struct mac80211_hwsim_data *data = hw->priv; u64 now = mac80211_hwsim_get_tsf(hw, vif); - u32 bcn_int = data->beacon_int; s64 delta = tsf - now; data->tsf_offset += delta; - /* adjust after beaconing with new timestamp at old TBTT */ - data->bcn_delta = do_div(delta, bcn_int); + + /* reschedule next beacon to happen at new TBTT */ + mac80211_hwsim_beacon_sched(hw); } static void mac80211_hwsim_monitor_rx(struct ieee80211_hw *hw, @@ -1075,8 +1094,6 @@ mac80211_hwsim_beacon(struct hrtimer *timer) container_of(timer, struct mac80211_hwsim_data, beacon_timer.timer); struct ieee80211_hw *hw = data->hw; - u64 bcn_int = data->beacon_int; - ktime_t next_bcn; if (!data->started) goto out; @@ -1085,15 +1102,7 @@ mac80211_hwsim_beacon(struct hrtimer *timer) hw, IEEE80211_IFACE_ITER_NORMAL, mac80211_hwsim_beacon_tx, data); - /* beacon at new TBTT + beacon interval */ - if (data->bcn_delta) { - bcn_int -= data->bcn_delta; - data->bcn_delta = 0; - } - - next_bcn = ktime_add(hrtimer_get_expires(timer), - ns_to_ktime(bcn_int * 1000)); - tasklet_hrtimer_start(&data->beacon_timer, next_bcn, HRTIMER_MODE_ABS); + mac80211_hwsim_beacon_sched(hw); out: return HRTIMER_NORESTART; } @@ -1146,15 +1155,8 @@ static int mac80211_hwsim_config(struct ieee80211_hw *hw, u32 changed) data->power_level = conf->power_level; if (!data->started || !data->beacon_int) tasklet_hrtimer_cancel(&data->beacon_timer); - else if (!hrtimer_is_queued(&data->beacon_timer.timer)) { - u64 tsf = mac80211_hwsim_get_tsf(hw, NULL); - u32 bcn_int = data->beacon_int; - u64 until_tbtt = bcn_int - do_div(tsf, bcn_int); - - tasklet_hrtimer_start(&data->beacon_timer, - ns_to_ktime(until_tbtt * 1000), - HRTIMER_MODE_REL); - } + else + mac80211_hwsim_beacon_sched(hw); return 0; } @@ -1224,16 +1226,9 @@ static void mac80211_hwsim_bss_info_changed(struct ieee80211_hw *hw, if (data->started && !hrtimer_is_queued(&data->beacon_timer.timer) && info->enable_beacon) { - u64 tsf, until_tbtt; - u32 bcn_int; if (WARN_ON(!data->beacon_int)) data->beacon_int = 1000 * 1024; - tsf = mac80211_hwsim_get_tsf(hw, vif); - bcn_int = data->beacon_int; - until_tbtt = bcn_int - do_div(tsf, bcn_int); - tasklet_hrtimer_start(&data->beacon_timer, - ns_to_ktime(until_tbtt * 1000), - HRTIMER_MODE_REL); + mac80211_hwsim_beacon_sched(hw); } else if (!info->enable_beacon) { unsigned int count = 0; ieee80211_iterate_active_interfaces_atomic(