netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Miquel Raynal <miquel.raynal@bootlin.com>
To: Alexander Aring <aahringo@redhat.com>
Cc: Alexander Aring <alex.aring@gmail.com>,
	Stefan Schmidt <stefan@datenfreihafen.org>,
	linux-wpan - ML <linux-wpan@vger.kernel.org>,
	David Girault <david.girault@qorvo.com>,
	Romuald Despres <romuald.despres@qorvo.com>,
	Frederic Blain <frederic.blain@qorvo.com>,
	Nicolas Schodet <nico@ni.fr.eu.org>,
	Thomas Petazzoni <thomas.petazzoni@bootlin.com>,
	"David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Network Development <netdev@vger.kernel.org>
Subject: Re: [PATCH wpan-next v3 05/11] net: mac802154: Bring the ability to hold the transmit queue
Date: Wed, 18 May 2022 10:26:44 +0200	[thread overview]
Message-ID: <20220518102644.2a123e8c@xps-13> (raw)
In-Reply-To: <CAK-6q+jh_PfkWB4odE8Dr+sxwWTqhirr8hyOxFFyEUzLDJC7+w@mail.gmail.com>

Hi Alex,

aahringo@redhat.com wrote on Tue, 17 May 2022 20:37:38 -0400:

> Hi,
> 
> On Tue, May 17, 2022 at 12:35 PM Miquel Raynal
> <miquel.raynal@bootlin.com> wrote:
> >
> > Create a hold_txs atomic variable and increment/decrement it when
> > relevant, ie. when we want to hold the queue or release it: currently
> > all the "stopped" situations are suitable, but very soon we will more
> > extensively use this feature for MLME purposes.
> >
> > Upon release, the atomic counter is decremented and checked. If it is
> > back to 0, then the netif queue gets woken up. This makes the whole
> > process fully transparent, provided that all the users of
> > ieee802154_wake/stop_queue() now call ieee802154_hold/release_queue()
> > instead.
> >
> > In no situation individual drivers should call any of these helpers
> > manually in order to avoid messing with the counters. There are other
> > functions more suited for this purpose which have been introduced, such
> > as the _xmit_complete() and _xmit_error() helpers which will handle all
> > that for them.
> >
> > One advantage is that, as no more drivers call the stop/wake helpers
> > directly, we can safely stop exporting them and only declare the
> > hold/release ones in a header only accessible to the core.
> >
> > Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
> > ---
> >  include/net/cfg802154.h      |  6 +++--
> >  include/net/mac802154.h      | 27 -------------------
> >  net/ieee802154/core.c        |  2 ++
> >  net/mac802154/cfg.c          |  4 +--
> >  net/mac802154/ieee802154_i.h | 19 +++++++++++++
> >  net/mac802154/tx.c           |  6 ++---
> >  net/mac802154/util.c         | 52 +++++++++++++++++++++++++++++++-----
> >  7 files changed, 75 insertions(+), 41 deletions(-)
> >
> > diff --git a/include/net/cfg802154.h b/include/net/cfg802154.h
> > index 473ebcb9b155..7a191418f258 100644
> > --- a/include/net/cfg802154.h
> > +++ b/include/net/cfg802154.h
> > @@ -11,7 +11,7 @@
> >
> >  #include <linux/ieee802154.h>
> >  #include <linux/netdevice.h>
> > -#include <linux/mutex.h>
> > +#include <linux/spinlock.h>
> >  #include <linux/bug.h>
> >
> >  #include <net/nl802154.h>
> > @@ -214,8 +214,10 @@ struct wpan_phy {
> >         /* the network namespace this phy lives in currently */
> >         possible_net_t _net;
> >
> > -       /* Transmission monitoring */
> > +       /* Transmission monitoring and control */
> > +       spinlock_t queue_lock;
> >         atomic_t ongoing_txs;
> > +       atomic_t hold_txs;
> >
> >         char priv[] __aligned(NETDEV_ALIGN);
> >  };
> > diff --git a/include/net/mac802154.h b/include/net/mac802154.h
> > index bdac0ddbdcdb..357d25ef627a 100644
> > --- a/include/net/mac802154.h
> > +++ b/include/net/mac802154.h
> > @@ -460,33 +460,6 @@ void ieee802154_unregister_hw(struct ieee802154_hw *hw);
> >   */
> >  void ieee802154_rx_irqsafe(struct ieee802154_hw *hw, struct sk_buff *skb,
> >                            u8 lqi);
> > -/**
> > - * ieee802154_wake_queue - wake ieee802154 queue
> > - * @hw: pointer as obtained from ieee802154_alloc_hw().
> > - *
> > - * Tranceivers usually have either one transmit framebuffer or one framebuffer
> > - * for both transmitting and receiving. Hence, the core currently only handles
> > - * one frame at a time for each phy, which means we had to stop the queue to
> > - * avoid new skb to come during the transmission. The queue then needs to be
> > - * woken up after the operation.
> > - *
> > - * Drivers should use this function instead of netif_wake_queue.
> > - */
> > -void ieee802154_wake_queue(struct ieee802154_hw *hw);
> > -
> > -/**
> > - * ieee802154_stop_queue - stop ieee802154 queue
> > - * @hw: pointer as obtained from ieee802154_alloc_hw().
> > - *
> > - * Tranceivers usually have either one transmit framebuffer or one framebuffer
> > - * for both transmitting and receiving. Hence, the core currently only handles
> > - * one frame at a time for each phy, which means we need to tell upper layers to
> > - * stop giving us new skbs while we are busy with the transmitted one. The queue
> > - * must then be stopped before transmitting.
> > - *
> > - * Drivers should use this function instead of netif_stop_queue.
> > - */
> > -void ieee802154_stop_queue(struct ieee802154_hw *hw);
> >
> >  /**
> >   * ieee802154_xmit_complete - frame transmission complete
> > diff --git a/net/ieee802154/core.c b/net/ieee802154/core.c
> > index de259b5170ab..47a4de6df88b 100644
> > --- a/net/ieee802154/core.c
> > +++ b/net/ieee802154/core.c
> > @@ -130,6 +130,8 @@ wpan_phy_new(const struct cfg802154_ops *ops, size_t priv_size)
> >
> >         init_waitqueue_head(&rdev->dev_wait);
> >
> > +       spin_lock_init(&rdev->wpan_phy.queue_lock);
> > +
> >         return &rdev->wpan_phy;
> >  }
> >  EXPORT_SYMBOL(wpan_phy_new);
> > diff --git a/net/mac802154/cfg.c b/net/mac802154/cfg.c
> > index 1e4a9f74ed43..b51100fd9e3f 100644
> > --- a/net/mac802154/cfg.c
> > +++ b/net/mac802154/cfg.c
> > @@ -46,7 +46,7 @@ static int ieee802154_suspend(struct wpan_phy *wpan_phy)
> >         if (!local->open_count)
> >                 goto suspend;
> >
> > -       ieee802154_stop_queue(&local->hw);
> > +       ieee802154_hold_queue(local);
> >         synchronize_net();
> >
> >         /* stop hardware - this must stop RX */
> > @@ -72,7 +72,7 @@ static int ieee802154_resume(struct wpan_phy *wpan_phy)
> >                 return ret;
> >
> >  wake_up:
> > -       ieee802154_wake_queue(&local->hw);
> > +       ieee802154_release_queue(local);
> >         local->suspended = false;
> >         return 0;
> >  }
> > diff --git a/net/mac802154/ieee802154_i.h b/net/mac802154/ieee802154_i.h
> > index a8b7b9049f14..0c7ff9e0b632 100644
> > --- a/net/mac802154/ieee802154_i.h
> > +++ b/net/mac802154/ieee802154_i.h
> > @@ -130,6 +130,25 @@ netdev_tx_t
> >  ieee802154_subif_start_xmit(struct sk_buff *skb, struct net_device *dev);
> >  enum hrtimer_restart ieee802154_xmit_ifs_timer(struct hrtimer *timer);
> >
> > +/**
> > + * ieee802154_hold_queue - hold ieee802154 queue
> > + * @local: main mac object
> > + *
> > + * Hold a queue by incrementing an atomic counter and requesting the netif
> > + * queues to be stopped. The queues cannot be woken up while the counter has not
> > + * been reset with as any ieee802154_release_queue() calls as needed.
> > + */
> > +void ieee802154_hold_queue(struct ieee802154_local *local);
> > +
> > +/**
> > + * ieee802154_release_queue - release ieee802154 queue
> > + * @local: main mac object
> > + *
> > + * Release a queue which is held by decrementing an atomic counter and wake it
> > + * up only if the counter reaches 0.
> > + */
> > +void ieee802154_release_queue(struct ieee802154_local *local);
> > +
> >  /* MIB callbacks */
> >  void mac802154_dev_set_page_channel(struct net_device *dev, u8 page, u8 chan);
> >
> > diff --git a/net/mac802154/tx.c b/net/mac802154/tx.c
> > index 33f64ecd96c7..6a53c83cf039 100644
> > --- a/net/mac802154/tx.c
> > +++ b/net/mac802154/tx.c
> > @@ -43,7 +43,7 @@ void ieee802154_xmit_sync_worker(struct work_struct *work)
> >
> >  err_tx:
> >         /* Restart the netif queue on each sub_if_data object. */
> > -       ieee802154_wake_queue(&local->hw);
> > +       ieee802154_release_queue(local);
> >         atomic_dec(&local->phy->ongoing_txs);
> >         kfree_skb(skb);
> >         netdev_dbg(dev, "transmission failed\n");
> > @@ -75,7 +75,7 @@ ieee802154_tx(struct ieee802154_local *local, struct sk_buff *skb)
> >         }
> >
> >         /* Stop the netif queue on each sub_if_data object. */
> > -       ieee802154_stop_queue(&local->hw);
> > +       ieee802154_hold_queue(local);
> >         atomic_inc(&local->phy->ongoing_txs);
> >
> >         /* Drivers should preferably implement the async callback. In some rare
> > @@ -99,7 +99,7 @@ ieee802154_tx(struct ieee802154_local *local, struct sk_buff *skb)
> >         return NETDEV_TX_OK;
> >
> >  err_wake_netif_queue:
> > -       ieee802154_wake_queue(&local->hw);
> > +       ieee802154_release_queue(local);
> >         atomic_dec(&local->phy->ongoing_txs);
> >  err_free_skb:
> >         kfree_skb(skb);
> > diff --git a/net/mac802154/util.c b/net/mac802154/util.c
> > index 76dc663e2af4..6176cc40df91 100644
> > --- a/net/mac802154/util.c
> > +++ b/net/mac802154/util.c
> > @@ -13,7 +13,17 @@
> >  /* privid for wpan_phys to determine whether they belong to us or not */
> >  const void *const mac802154_wpan_phy_privid = &mac802154_wpan_phy_privid;
> >
> > -void ieee802154_wake_queue(struct ieee802154_hw *hw)
> > +/**
> > + * ieee802154_wake_queue - wake ieee802154 queue
> > + * @local: main mac object
> > + *
> > + * Tranceivers usually have either one transmit framebuffer or one framebuffer
> > + * for both transmitting and receiving. Hence, the core currently only handles
> > + * one frame at a time for each phy, which means we had to stop the queue to
> > + * avoid new skb to come during the transmission. The queue then needs to be
> > + * woken up after the operation.
> > + */
> > +static void ieee802154_wake_queue(struct ieee802154_hw *hw)
> >  {
> >         struct ieee802154_local *local = hw_to_local(hw);
> >         struct ieee802154_sub_if_data *sdata;
> > @@ -27,9 +37,18 @@ void ieee802154_wake_queue(struct ieee802154_hw *hw)
> >         }
> >         rcu_read_unlock();
> >  }
> > -EXPORT_SYMBOL(ieee802154_wake_queue);
> >
> > -void ieee802154_stop_queue(struct ieee802154_hw *hw)
> > +/**
> > + * ieee802154_stop_queue - stop ieee802154 queue
> > + * @local: main mac object
> > + *
> > + * Tranceivers usually have either one transmit framebuffer or one framebuffer
> > + * for both transmitting and receiving. Hence, the core currently only handles
> > + * one frame at a time for each phy, which means we need to tell upper layers to
> > + * stop giving us new skbs while we are busy with the transmitted one. The queue
> > + * must then be stopped before transmitting.
> > + */
> > +static void ieee802154_stop_queue(struct ieee802154_hw *hw)
> >  {
> >         struct ieee802154_local *local = hw_to_local(hw);
> >         struct ieee802154_sub_if_data *sdata;
> > @@ -43,14 +62,33 @@ void ieee802154_stop_queue(struct ieee802154_hw *hw)
> >         }
> >         rcu_read_unlock();
> >  }
> > -EXPORT_SYMBOL(ieee802154_stop_queue);
> > +
> > +void ieee802154_hold_queue(struct ieee802154_local *local)
> > +{
> > +       unsigned long flags;
> > +
> > +       spin_lock_irqsave(&local->phy->queue_lock, flags);
> > +       ieee802154_stop_queue(&local->hw);
> > +       atomic_inc(&local->phy->hold_txs);
> > +       spin_unlock_irqrestore(&local->phy->queue_lock, flags);
> > +}  
> 
> I think that works, but I would expect something like:
> 
> if (!atomic_fetch_inc(hold_txs))
>       ieee802154_stop_queue(&local->hw);

I didn't know about the _fetch_ alternative, that looks much better
this way!


  reply	other threads:[~2022-05-18  8:27 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-17 16:34 [PATCH wpan-next v3 00/11] ieee802154: Synchronous Tx support Miquel Raynal
2022-05-17 16:34 ` [PATCH wpan-next v3 01/11] net: mac802154: Rename the synchronous xmit worker Miquel Raynal
2022-05-17 16:34 ` [PATCH wpan-next v3 02/11] net: mac802154: Rename the main tx_work struct Miquel Raynal
2022-05-17 16:34 ` [PATCH wpan-next v3 03/11] net: mac802154: Enhance the error path in the main tx helper Miquel Raynal
2022-05-17 16:34 ` [PATCH wpan-next v3 04/11] net: mac802154: Follow the count of ongoing transmissions Miquel Raynal
2022-05-17 16:34 ` [PATCH wpan-next v3 05/11] net: mac802154: Bring the ability to hold the transmit queue Miquel Raynal
2022-05-18  0:37   ` Alexander Aring
2022-05-18  8:26     ` Miquel Raynal [this message]
2022-05-17 16:34 ` [PATCH wpan-next v3 06/11] net: mac802154: Create a hot tx path Miquel Raynal
2022-05-17 16:34 ` [PATCH wpan-next v3 07/11] net: mac802154: Introduce a helper to disable the queue Miquel Raynal
2022-05-17 16:34 ` [PATCH wpan-next v3 08/11] net: mac802154: Introduce a tx queue flushing mechanism Miquel Raynal
2022-05-17 16:34 ` [PATCH wpan-next v3 09/11] net: mac802154: Introduce a synchronous API for MLME commands Miquel Raynal
2022-05-18  0:41   ` Alexander Aring
2022-05-18  8:44     ` Miquel Raynal
2022-05-18 11:59       ` Alexander Aring
2022-05-18 12:12         ` Alexander Aring
2022-05-18 12:44         ` Miquel Raynal
2022-05-18 13:02           ` Alexander Aring
2022-05-17 16:34 ` [PATCH wpan-next v3 10/11] net: mac802154: Add a warning in the hot path Miquel Raynal
2022-05-18  0:58   ` Alexander Aring
2022-05-18  8:55     ` Miquel Raynal
2022-05-18 14:31       ` Alexander Aring
2022-05-18 16:29         ` Miquel Raynal
2022-05-19  1:52           ` Alexander Aring
2022-05-17 16:34 ` [PATCH wpan-next v3 11/11] net: mac802154: Add a warning in the slow path Miquel Raynal
2022-05-18  0:52   ` Alexander Aring
2022-05-18  9:37     ` Miquel Raynal

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220518102644.2a123e8c@xps-13 \
    --to=miquel.raynal@bootlin.com \
    --cc=aahringo@redhat.com \
    --cc=alex.aring@gmail.com \
    --cc=davem@davemloft.net \
    --cc=david.girault@qorvo.com \
    --cc=frederic.blain@qorvo.com \
    --cc=kuba@kernel.org \
    --cc=linux-wpan@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=nico@ni.fr.eu.org \
    --cc=pabeni@redhat.com \
    --cc=romuald.despres@qorvo.com \
    --cc=stefan@datenfreihafen.org \
    --cc=thomas.petazzoni@bootlin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).