netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Nicolas Escande" <nico.escande@gmail.com>
To: "Baligh Gasmi" <gasmibal@gmail.com>,
	"Johannes Berg" <johannes@sipsolutions.net>
Cc: "David S . Miller" <davem@davemloft.net>,
	"Eric Dumazet" <edumazet@google.com>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Paolo Abeni" <pabeni@redhat.com>,
	<linux-wireless@vger.kernel.org>, <netdev@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>, "Felix Fietkau" <nbd@nbd.name>,
	"Toke Hoiland-Jorgensen" <toke@redhat.com>,
	"Linus Lussing" <linus.luessing@c0d3.blue>,
	"Kalle Valo" <kvalo@kernel.org>
Subject: Re: [RFC/RFT v5 2/4] mac80211: add periodic monitor for channel busy time
Date: Thu, 25 Aug 2022 15:35:13 +0200	[thread overview]
Message-ID: <CMF5DQR5IOKQ.1AHXQ8IDOC7IT@syracuse> (raw)
In-Reply-To: <20220719123525.3448926-3-gasmibal@gmail.com>

On Tue Jul 19, 2022 at 2:35 PM CEST, Baligh Gasmi wrote:
> Add a worker scheduled periodicaly to calculate the busy time average of
> the current channel.
>
> This will be used in the estimation for expected throughput.
>
> Signed-off-by: Baligh Gasmi <gasmibal@gmail.com>
> ---
>  net/mac80211/ieee80211_i.h |  6 ++++
>  net/mac80211/iface.c       | 65 ++++++++++++++++++++++++++++++++++++++
>  2 files changed, 71 insertions(+)
>
> diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
> index 86ef0a46a68c..2cb388335ce8 100644
> --- a/net/mac80211/ieee80211_i.h
> +++ b/net/mac80211/ieee80211_i.h
> @@ -901,6 +901,7 @@ struct ieee80211_if_nan {
>  	struct idr function_inst_ids;
>  };
>
> +DECLARE_EWMA(avg_busy, 8, 4)
>  struct ieee80211_sub_if_data {
>  	struct list_head list;
>
> @@ -1024,6 +1025,11 @@ struct ieee80211_sub_if_data {
>  	} debugfs;
>  #endif
>
> +	struct delayed_work monitor_work;
> +	u64 last_time;
> +	u64 last_time_busy;
> +	struct ewma_avg_busy avg_busy;
> +
>  	/* must be last, dynamically sized area in this! */
>  	struct ieee80211_vif vif;
>  };
> diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
> index 15a73b7fdd75..e1b20964933c 100644
> --- a/net/mac80211/iface.c
> +++ b/net/mac80211/iface.c
> @@ -1972,6 +1972,64 @@ static void ieee80211_assign_perm_addr(struct ieee80211_local *local,
>  	mutex_unlock(&local->iflist_mtx);
>  }
>
> +#define DEFAULT_MONITOR_INTERVAL_MS 1000
> +
> +static void ieee80211_if_monitor_work(struct work_struct *work)
> +{
> +	struct delayed_work *delayed_work = to_delayed_work(work);
> +	struct ieee80211_sub_if_data *sdata > +		container_of(delayed_work, struct ieee80211_sub_if_data,
> +				monitor_work);
> +	struct survey_info survey;
> +	struct ieee80211_local *local = sdata->local;
> +	struct ieee80211_chanctx_conf *chanctx_conf;
> +	struct ieee80211_channel *channel = NULL;
> +	int q = 0;
> +	u64 interval = DEFAULT_MONITOR_INTERVAL_MS;
> +
> +	rcu_read_lock();
> +	chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
> +	if (chanctx_conf)
> +		channel = chanctx_conf->def.chan;
> +	rcu_read_unlock();
> +
> +	if (!channel)
> +		goto end;
> +
> +	if (!local->started)
> +		goto end;
> +
> +	do {
> +		survey.filled = 0;
> +		if (drv_get_survey(local, q++, &survey) != 0) {
> +			survey.filled = 0;
> +			break;
> +		}
> +	} while (channel != survey.channel);
> +
> +	if (survey.filled & SURVEY_INFO_TIME) {
> +		/* real interval */
> +		interval = survey.time - sdata->last_time;
> +		/* store last time */
> +		sdata->last_time = survey.time;
> +	}
> +
> +	if (survey.filled & SURVEY_INFO_TIME_BUSY) {
> +		/* busy */
> +		u64 busy = survey.time_busy < sdata->last_time_busy ? 0 :
> +			survey.time_busy - sdata->last_time_busy;
> +		/* average percent busy time */
> +		ewma_avg_busy_add(&sdata->avg_busy,
> +				(busy * 100) / interval);
This could use a div_u64()
> +		/* store last busy time */
> +		sdata->last_time_busy = survey.time_busy;
> +	}
> +
> +end:
> +	schedule_delayed_work(&sdata->monitor_work,
> +			msecs_to_jiffies(DEFAULT_MONITOR_INTERVAL_MS));
> +}
> +
>  int ieee80211_if_add(struct ieee80211_local *local, const char *name,
>  		     unsigned char name_assign_type,
>  		     struct wireless_dev **new_wdev, enum nl80211_iftype type,
> @@ -2085,6 +2143,8 @@ int ieee80211_if_add(struct ieee80211_local *local, const char *name,
>  			  ieee80211_dfs_cac_timer_work);
>  	INIT_DELAYED_WORK(&sdata->dec_tailroom_needed_wk,
>  			  ieee80211_delayed_tailroom_dec);
> +	INIT_DELAYED_WORK(&sdata->monitor_work,
> +			ieee80211_if_monitor_work);
>
>  	for (i = 0; i < NUM_NL80211_BANDS; i++) {
>  		struct ieee80211_supported_band *sband;
> @@ -2156,6 +2216,9 @@ int ieee80211_if_add(struct ieee80211_local *local, const char *name,
>  	list_add_tail_rcu(&sdata->list, &local->interfaces);
>  	mutex_unlock(&local->iflist_mtx);
>
> +	schedule_delayed_work(&sdata->monitor_work,
> +			msecs_to_jiffies(DEFAULT_MONITOR_INTERVAL_MS));
> +
>  	if (new_wdev)
>  		*new_wdev = &sdata->wdev;
>
> @@ -2166,6 +2229,8 @@ void ieee80211_if_remove(struct ieee80211_sub_if_data *sdata)
>  {
>  	ASSERT_RTNL();
>
> +	cancel_delayed_work_sync(&sdata->monitor_work);
> +
>  	mutex_lock(&sdata->local->iflist_mtx);
>  	list_del_rcu(&sdata->list);
>  	mutex_unlock(&sdata->local->iflist_mtx);
> --
> 2.37.1


  parent reply	other threads:[~2022-08-25 13:49 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-19 12:35 [RFC/RFT v5 0/4] expected throughput from AQL airtime Baligh Gasmi
2022-07-19 12:35 ` [RFC/RFT v5 1/4] mac80211: use AQL airtime for expected throughput Baligh Gasmi
2022-08-25 13:31   ` Nicolas Escande
2022-08-25 14:17     ` Baligh GASMI
2022-07-19 12:35 ` [RFC/RFT v5 2/4] mac80211: add periodic monitor for channel busy time Baligh Gasmi
2022-08-25  8:58   ` Johannes Berg
2022-08-25  9:27     ` Baligh GASMI
2022-08-25 13:35   ` Nicolas Escande [this message]
2022-07-19 12:35 ` [RFC/RFT v5 3/4] mac80211: add busy time factor into expected throughput Baligh Gasmi
2022-08-25 13:36   ` Nicolas Escande
2022-07-19 12:35 ` [RFC/RFT v5 4/4] mac80211: extend channel info with average busy time Baligh Gasmi

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=CMF5DQR5IOKQ.1AHXQ8IDOC7IT@syracuse \
    --to=nico.escande@gmail.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=gasmibal@gmail.com \
    --cc=johannes@sipsolutions.net \
    --cc=kuba@kernel.org \
    --cc=kvalo@kernel.org \
    --cc=linus.luessing@c0d3.blue \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=nbd@nbd.name \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=toke@redhat.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).