linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 31/37] mac80211_hwsim: Replace hrtimer tasklet with softirq hrtimer
       [not found] <20171022213938.940451689@linutronix.de>
@ 2017-10-22 21:40 ` Anna-Maria Gleixner
  2017-10-23 10:14   ` Johannes Berg
  0 siblings, 1 reply; 6+ messages in thread
From: Anna-Maria Gleixner @ 2017-10-22 21:40 UTC (permalink / raw)
  To: LKML
  Cc: Thomas Gleixner, Peter Zijlstra, Ingo Molnar, keescook,
	Christoph Hellwig, John Stultz, Johannes Berg, Kalle Valo,
	linux-wireless

From: Thomas Gleixner <tglx@linutronix.de>

Switch the timer to HRTIMER_MODE_SOFT, which executed the timer
callback in softirq context and remove the hrtimer_tasklet.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Anna-Maria Gleixner <anna-maria@linutronix.de>
Cc: Johannes Berg <johannes@sipsolutions.net>
Cc: Kalle Valo <kvalo@codeaurora.org>
Cc: linux-wireless@vger.kernel.org

---
 drivers/net/wireless/mac80211_hwsim.c |   44 +++++++++++++++-------------------
 1 file changed, 20 insertions(+), 24 deletions(-)

--- a/drivers/net/wireless/mac80211_hwsim.c
+++ b/drivers/net/wireless/mac80211_hwsim.c
@@ -537,7 +537,7 @@ struct mac80211_hwsim_data {
 	unsigned int rx_filter;
 	bool started, idle, scanning;
 	struct mutex mutex;
-	struct tasklet_hrtimer beacon_timer;
+	struct hrtimer beacon_timer;
 	enum ps_mode {
 		PS_DISABLED, PS_ENABLED, PS_AUTO_POLL, PS_MANUAL_POLL
 	} ps;
@@ -1418,7 +1418,7 @@ static void mac80211_hwsim_stop(struct i
 {
 	struct mac80211_hwsim_data *data = hw->priv;
 	data->started = false;
-	tasklet_hrtimer_cancel(&data->beacon_timer);
+	hrtimer_cancel(&data->beacon_timer);
 	wiphy_debug(hw->wiphy, "%s\n", __func__);
 }
 
@@ -1541,14 +1541,12 @@ static enum hrtimer_restart
 mac80211_hwsim_beacon(struct hrtimer *timer)
 {
 	struct mac80211_hwsim_data *data =
-		container_of(timer, struct mac80211_hwsim_data,
-			     beacon_timer.timer);
+		container_of(timer, struct mac80211_hwsim_data, beacon_timer);
 	struct ieee80211_hw *hw = data->hw;
 	u64 bcn_int = data->beacon_int;
-	ktime_t next_bcn;
 
 	if (!data->started)
-		goto out;
+		return HRTIMER_NORESTART;
 
 	ieee80211_iterate_active_interfaces_atomic(
 		hw, IEEE80211_IFACE_ITER_NORMAL,
@@ -1560,11 +1558,9 @@ mac80211_hwsim_beacon(struct hrtimer *ti
 		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);
-out:
-	return HRTIMER_NORESTART;
+	hrtimer_forward(&data->beacon_timer, hrtimer_get_expires(timer),
+			ns_to_ktime(bcn_int * NSEC_PER_USEC));
+	return HRTIMER_RESTART;
 }
 
 static const char * const hwsim_chanwidths[] = {
@@ -1638,15 +1634,15 @@ static int mac80211_hwsim_config(struct
 	mutex_unlock(&data->mutex);
 
 	if (!data->started || !data->beacon_int)
-		tasklet_hrtimer_cancel(&data->beacon_timer);
-	else if (!hrtimer_is_queued(&data->beacon_timer.timer)) {
+		hrtimer_cancel(&data->beacon_timer);
+	else if (!hrtimer_is_queued(&data->beacon_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);
+		hrtimer_start(&data->beacon_timer,
+			      ns_to_ktime(until_tbtt * 1000),
+			      HRTIMER_MODE_REL_SOFT);
 	}
 
 	return 0;
@@ -1709,7 +1705,7 @@ static void mac80211_hwsim_bss_info_chan
 			    info->enable_beacon, info->beacon_int);
 		vp->bcn_en = info->enable_beacon;
 		if (data->started &&
-		    !hrtimer_is_queued(&data->beacon_timer.timer) &&
+		    !hrtimer_is_queued(&data->beacon_timer) &&
 		    info->enable_beacon) {
 			u64 tsf, until_tbtt;
 			u32 bcn_int;
@@ -1717,9 +1713,9 @@ static void mac80211_hwsim_bss_info_chan
 			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);
+			hrtimer_start(&data->beacon_timer,
+				      ns_to_ktime(until_tbtt * 1000),
+				      HRTIMER_MODE_REL_SOFT);
 		} else if (!info->enable_beacon) {
 			unsigned int count = 0;
 			ieee80211_iterate_active_interfaces_atomic(
@@ -1728,7 +1724,7 @@ static void mac80211_hwsim_bss_info_chan
 			wiphy_debug(hw->wiphy, "  beaconing vifs remaining: %u",
 				    count);
 			if (count == 0) {
-				tasklet_hrtimer_cancel(&data->beacon_timer);
+				hrtimer_cancel(&data->beacon_timer);
 				data->beacon_int = 0;
 			}
 		}
@@ -2720,9 +2716,9 @@ static int mac80211_hwsim_new_radio(stru
 				    data->debugfs,
 				    data, &hwsim_simulate_radar);
 
-	tasklet_hrtimer_init(&data->beacon_timer,
-			     mac80211_hwsim_beacon,
-			     CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
+	hrtimer_init(&data->beacon_timer, CLOCK_MONOTONIC,
+		     HRTIMER_MODE_ABS_SOFT);
+	data->beacon_timer.function = mac80211_hwsim_beacon;
 
 	spin_lock_bh(&hwsim_radio_lock);
 	list_add_tail(&data->list, &hwsim_radios);

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 31/37] mac80211_hwsim: Replace hrtimer tasklet with softirq hrtimer
  2017-10-22 21:40 ` [PATCH v2 31/37] mac80211_hwsim: Replace hrtimer tasklet with softirq hrtimer Anna-Maria Gleixner
@ 2017-10-23 10:14   ` Johannes Berg
  2017-10-23 10:23     ` Thomas Gleixner
  0 siblings, 1 reply; 6+ messages in thread
From: Johannes Berg @ 2017-10-23 10:14 UTC (permalink / raw)
  To: Anna-Maria Gleixner, LKML
  Cc: Thomas Gleixner, Peter Zijlstra, Ingo Molnar, keescook,
	Christoph Hellwig, John Stultz, Kalle Valo, linux-wireless

On Sun, 2017-10-22 at 23:40 +0200, Anna-Maria Gleixner wrote:
> From: Thomas Gleixner <tglx@linutronix.de>
> 
> Switch the timer to HRTIMER_MODE_SOFT, which executed the timer
> callback in softirq context and remove the hrtimer_tasklet.

This doesn't build on my tree, due to HRTIMER_MODE_REL_SOFT not
existing. Neither does HRTIMER_MODE_SOFT mentioned above, but that's
just a commit log mistake.

(It also didn't apply on my tree, but that was a trivial context
change.)

I don't understand why you initialize it with HRTIMER_MODE_ABS_SOFT
either though:

> +       hrtimer_init(&data->beacon_timer, CLOCK_MONOTONIC,
> +                    HRTIMER_MODE_ABS_SOFT);

shouldn't that already be REL?

johannes

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 31/37] mac80211_hwsim: Replace hrtimer tasklet with softirq hrtimer
  2017-10-23 10:14   ` Johannes Berg
@ 2017-10-23 10:23     ` Thomas Gleixner
  2017-10-23 10:25       ` Johannes Berg
  0 siblings, 1 reply; 6+ messages in thread
From: Thomas Gleixner @ 2017-10-23 10:23 UTC (permalink / raw)
  To: Johannes Berg
  Cc: Anna-Maria Gleixner, LKML, Peter Zijlstra, Ingo Molnar, keescook,
	Christoph Hellwig, John Stultz, Kalle Valo, linux-wireless

On Mon, 23 Oct 2017, Johannes Berg wrote:

> On Sun, 2017-10-22 at 23:40 +0200, Anna-Maria Gleixner wrote:
> > From: Thomas Gleixner <tglx@linutronix.de>
> > 
> > Switch the timer to HRTIMER_MODE_SOFT, which executed the timer
> > callback in softirq context and remove the hrtimer_tasklet.

I can't build as its part of the whole hrtimer rework series.

> This doesn't build on my tree, due to HRTIMER_MODE_REL_SOFT not
> existing. Neither does HRTIMER_MODE_SOFT mentioned above, but that's
> just a commit log mistake.

Oops.

> (It also didn't apply on my tree, but that was a trivial context
> change.)
> 
> I don't understand why you initialize it with HRTIMER_MODE_ABS_SOFT
> either though:
> 
> > +       hrtimer_init(&data->beacon_timer, CLOCK_MONOTONIC,
> > +                    HRTIMER_MODE_ABS_SOFT);

Sure, though it does not matter in that case. Will fix that up.

Thanks,

	tglx

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 31/37] mac80211_hwsim: Replace hrtimer tasklet with softirq hrtimer
  2017-10-23 10:23     ` Thomas Gleixner
@ 2017-10-23 10:25       ` Johannes Berg
  2017-10-23 10:33         ` Thomas Gleixner
  0 siblings, 1 reply; 6+ messages in thread
From: Johannes Berg @ 2017-10-23 10:25 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: Anna-Maria Gleixner, LKML, Peter Zijlstra, Ingo Molnar, keescook,
	Christoph Hellwig, John Stultz, Kalle Valo, linux-wireless

On Mon, 2017-10-23 at 12:23 +0200, Thomas Gleixner wrote:
> On Mon, 23 Oct 2017, Johannes Berg wrote:
> 
> > On Sun, 2017-10-22 at 23:40 +0200, Anna-Maria Gleixner wrote:
> > > From: Thomas Gleixner <tglx@linutronix.de>
> > > 
> > > Switch the timer to HRTIMER_MODE_SOFT, which executed the timer
> > > callback in softirq context and remove the hrtimer_tasklet.
> 
> I can't build as its part of the whole hrtimer rework series.

I guess you mean you *can* build it? Surely you're introducing the new
HR timer modes in some patch that I didn't see? :-)

> > > +       hrtimer_init(&data->beacon_timer, CLOCK_MONOTONIC,
> > > +                    HRTIMER_MODE_ABS_SOFT);
> 
> Sure, though it does not matter in that case. Will fix that up.

Right. Then again, why even pass it to init() and start()? Can you
start without going through start()?

johannes

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 31/37] mac80211_hwsim: Replace hrtimer tasklet with softirq hrtimer
  2017-10-23 10:25       ` Johannes Berg
@ 2017-10-23 10:33         ` Thomas Gleixner
  2017-10-23 10:42           ` Johannes Berg
  0 siblings, 1 reply; 6+ messages in thread
From: Thomas Gleixner @ 2017-10-23 10:33 UTC (permalink / raw)
  To: Johannes Berg
  Cc: Anna-Maria Gleixner, LKML, Peter Zijlstra, Ingo Molnar, keescook,
	Christoph Hellwig, John Stultz, Kalle Valo, linux-wireless

On Mon, 23 Oct 2017, Johannes Berg wrote:
> On Mon, 2017-10-23 at 12:23 +0200, Thomas Gleixner wrote:
> > On Mon, 23 Oct 2017, Johannes Berg wrote:
> > 
> > > On Sun, 2017-10-22 at 23:40 +0200, Anna-Maria Gleixner wrote:
> > > > From: Thomas Gleixner <tglx@linutronix.de>
> > > > 
> > > > Switch the timer to HRTIMER_MODE_SOFT, which executed the timer
> > > > callback in softirq context and remove the hrtimer_tasklet.
> > 
> > I can't build as its part of the whole hrtimer rework series.
> 
> I guess you mean you *can* build it? Surely you're introducing the new
> HR timer modes in some patch that I didn't see? :-)

Sorry, we did not want to expose you to 30 patches fiddling with the core
code. They are on LKML though.

> > > > +       hrtimer_init(&data->beacon_timer, CLOCK_MONOTONIC,
> > > > +                    HRTIMER_MODE_ABS_SOFT);
> > 
> > Sure, though it does not matter in that case. Will fix that up.
> 
> Right. Then again, why even pass it to init() and start()? Can you
> start without going through start()?

There is a subtle magic with CLOCK_REALTIME timers.

CLOCK_REALTIME timers differentiate between ABS and REL modes. ABS timers
are exposed to clock modifications (settimeofday() ...), REL timers are
not. We solve that by associating them to different clock bases, which has
to be done at init time, but the start function needs the REL/ABS
information as well.

For CLOCK_MONOTONIC this is not really required, but the function is used
for all clock bases, so we require the mode bits for all.

Thanks,

	tglx

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 31/37] mac80211_hwsim: Replace hrtimer tasklet with softirq hrtimer
  2017-10-23 10:33         ` Thomas Gleixner
@ 2017-10-23 10:42           ` Johannes Berg
  0 siblings, 0 replies; 6+ messages in thread
From: Johannes Berg @ 2017-10-23 10:42 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: Anna-Maria Gleixner, LKML, Peter Zijlstra, Ingo Molnar, keescook,
	Christoph Hellwig, John Stultz, Kalle Valo, linux-wireless


> > I guess you mean you *can* build it? Surely you're introducing the new
> > HR timer modes in some patch that I didn't see? :-)
> 
> Sorry, we did not want to expose you to 30 patches fiddling with the core
> code. They are on LKML though.

Sure, no worries. I just didn't even realize I shouldn't be applying
the patch (myself) :-)

> > Right. Then again, why even pass it to init() and start()? Can you
> > start without going through start()?
> 
> There is a subtle magic with CLOCK_REALTIME timers.
> 
> CLOCK_REALTIME timers differentiate between ABS and REL modes. ABS timers
> are exposed to clock modifications (settimeofday() ...), REL timers are
> not. We solve that by associating them to different clock bases, which has
> to be done at init time, but the start function needs the REL/ABS
> information as well.
> 
> For CLOCK_MONOTONIC this is not really required, but the function is used
> for all clock bases, so we require the mode bits for all.

Hmm. Couldn't you just store that then from init to use in start?

If you don't store it, yet don't verify that you passed the same 
thing, do you at least check that it's compatible? Sounds like
something will totally go wrong if I pass CLOCK_REALTIME/ABS first and
then use REL for start, or vice versa?

Also, in the code I see only checking

if (mode != HRTIMER_MODE_ABS) {
	// change clock ID:
	// realtime -> monotonic
	// realtime_soft -> monotonic_soft
}

but you're passing HRTIMER_MODE_ABS_SOFT too, isn't that considered an
ABS mode?

But then, looking at the code again, I don't even see
HRTIMER_MODE_ABS_SOFT existing, it sounds like it should be

hrtimer_init(..., CLOCK_REALTIME_SOFT, HRTIMER_MODE_REL);

then?

At least then the code I mentioned above makes sense, but it still
feels pretty dangerous to not just store the mode and use it in start,
but to require passing it again. You even just introduced the same bug,
it just happened to not matter in this case since the clock isn't
realtime.

Or am I completely confused now?

johannes

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-10-23 10:42 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20171022213938.940451689@linutronix.de>
2017-10-22 21:40 ` [PATCH v2 31/37] mac80211_hwsim: Replace hrtimer tasklet with softirq hrtimer Anna-Maria Gleixner
2017-10-23 10:14   ` Johannes Berg
2017-10-23 10:23     ` Thomas Gleixner
2017-10-23 10:25       ` Johannes Berg
2017-10-23 10:33         ` Thomas Gleixner
2017-10-23 10:42           ` Johannes Berg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).