netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* The proper way of delaying tx in a driver
@ 2008-07-23  6:37 Benjamin Herrenschmidt
  2008-07-23  8:11 ` David Miller
  0 siblings, 1 reply; 3+ messages in thread
From: Benjamin Herrenschmidt @ 2008-07-23  6:37 UTC (permalink / raw)
  To: netdev; +Cc: David S. Miller

Hi !

(Dave: this is basically the conversation we had on IRC, I think at that
point it's worth discussing here and I'll see if I can update the
documentation along fix fixing a handful of drivers).

So the problem: various drivers need to temporarily stop TX, ie, make
sure their hard_hard_xmit() is not running and will not be called for a
certain amount of time, in order to perform various housekeeping tasks.

This ranges from things like change_mtu() to reset tasks, or whatever
other things driver may want to do that require that locking.

For a short amount of time, just locking the tx lock
(netif_tx_lock{_bh}) does the job just fine. So let's ignore that. We
are in the case of a driver that wants to do something long, such as
reallocating the entire RX ring (change_mtu) or resetting hardware, and
potentially want to sleep / schedule.

The drivers historically use netif_stop_queue()/netif_wake_queue() to do
that. This is fishy due to locking, but let's assume that at this stage
we have a clueful driver writer, and thus like tg3, we do
netif_tx_disable / netif_wake_queue instead.

The above unfortunately hits the new WARN_ON() as Dave pointed out, it's
not legal to call netif_wake_queue() before a driver's open() function
called netif_start_queue().

Drivers like tg3 seem to be at least -somewhat- careful, and only do
those things when netif_running(). However, unless I missed something,
this is true from just before the driver open() is called, that is, too
early for closing the race.

So the question is, what is the proper approach ?

I'm happy to help fixing tg3, sungem and emac at least as I'm somewhat
familiar with those 3 drivers once we decide what is the right sequence
of operations here.

Cheers,
Ben.



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

* Re: The proper way of delaying tx in a driver
  2008-07-23  6:37 The proper way of delaying tx in a driver Benjamin Herrenschmidt
@ 2008-07-23  8:11 ` David Miller
  2008-07-23  8:19   ` Benjamin Herrenschmidt
  0 siblings, 1 reply; 3+ messages in thread
From: David Miller @ 2008-07-23  8:11 UTC (permalink / raw)
  To: benh; +Cc: netdev

From: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Date: Wed, 23 Jul 2008 16:37:23 +1000

> Drivers like tg3 seem to be at least -somewhat- careful, and only do
> those things when netif_running(). However, unless I missed something,
> this is true from just before the driver open() is called, that is, too
> early for closing the race.
> 
> So the question is, what is the proper approach ?
> 
> I'm happy to help fixing tg3, sungem and emac at least as I'm somewhat
> familiar with those 3 drivers once we decide what is the right sequence
> of operations here.

The other problematic case is netif_device_attach(), which many
drivers use for resume.  It triggers the same WARN_ON() case as
well.

I'm going to attack this as follows:

1) Make running netif_schedule() on the builtin' qdiscs such
   as noop_qdisc and noqueue_qdisc a NOP and not WARN any more.

2) Come up with a "netif_freeze_tx()" or similar to give these
   drivers what they want.

The truth is that neither netif_stop_queue() nor netif_carrier_off()
stop ->hard_start_xmit() execution immediately.

Taking the TX lock(s) and doing netif_stop_queue() comes close, but
it is also not a full solution.

netif_stop_queue() just sets a bit, but a cpu could already be in
the ->hard_start_xmit() handler.

netif_carrier_off() defers the qdisc reset it does into the link_watch
work queue, so it's effect is not immediate either.

To me the most effective queue stopper would be a sequence of three
operations:

1) Set netdev_queue->qdisc to &noop_qdisc

2) Lock the previous qdisc and call ->reset() on it

3) Grab and release TX lock

That guarentees nobody is inside of ->hard_start_xmit() and that
no future packets are pending for the device.

At least for non-LLTX driver.  For LLTX ones, oh well, too bad, they
have to find their own ways to ensure such things.  It's deprecated
for a reason :)


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

* Re: The proper way of delaying tx in a driver
  2008-07-23  8:11 ` David Miller
@ 2008-07-23  8:19   ` Benjamin Herrenschmidt
  0 siblings, 0 replies; 3+ messages in thread
From: Benjamin Herrenschmidt @ 2008-07-23  8:19 UTC (permalink / raw)
  To: David Miller; +Cc: netdev

On Wed, 2008-07-23 at 01:11 -0700, David Miller wrote:

 .../...

> At least for non-LLTX driver.  For LLTX ones, oh well, too bad, they
> have to find their own ways to ensure such things.  It's deprecated
> for a reason :)

Thanks. I'm happy to remove LLTX from sungem (in fact, I started doing
it when stumbled upon the problem of how the heck do I freeze my tx
queue ?).

Cheers,
Ben.



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

end of thread, other threads:[~2008-07-23  8:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-07-23  6:37 The proper way of delaying tx in a driver Benjamin Herrenschmidt
2008-07-23  8:11 ` David Miller
2008-07-23  8:19   ` Benjamin Herrenschmidt

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).