linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kalle Valo <kvalo@codeaurora.org>
To: Felix Fietkau <nbd@nbd.name>
Cc: linux-wireless@vger.kernel.org
Subject: Re: [PATCH 04/11] mt76: add utility functions for deferring work to a kernel thread
Date: Mon, 14 Sep 2020 10:55:08 +0300	[thread overview]
Message-ID: <87363kpzc3.fsf@codeaurora.org> (raw)
In-Reply-To: <7e2b25d9-c6cc-1c78-a96f-e60604408578@nbd.name> (Felix Fietkau's message of "Sat, 12 Sep 2020 07:05:59 +0200")

Felix Fietkau <nbd@nbd.name> writes:

> On 2020-09-11 10:15, Kalle Valo wrote:
>> Felix Fietkau <nbd@nbd.name> writes:
>> 
>>> In order to avoid keeping work like tx scheduling pinned to the CPU it was
>>> scheduled from, it makes sense to switch from tasklets to kernel threads.
>>>
>>> Signed-off-by: Felix Fietkau <nbd@nbd.name>
>> 
>> [...]
>> 
>>> --- a/drivers/net/wireless/mediatek/mt76/util.c
>>> +++ b/drivers/net/wireless/mediatek/mt76/util.c
>>> @@ -110,4 +110,32 @@ int mt76_get_min_avg_rssi(struct mt76_dev *dev, bool ext_phy)
>>>  }
>>>  EXPORT_SYMBOL_GPL(mt76_get_min_avg_rssi);
>>>  
>>> +int __mt76_worker_fn(void *ptr)
>>> +{
>>> +	struct mt76_worker *w = ptr;
>>> +
>>> +	while (!kthread_should_stop()) {
>>> +		set_current_state(TASK_INTERRUPTIBLE);
>>> +
>>> +		if (kthread_should_park()) {
>>> +			kthread_parkme();
>>> +			continue;
>>> +		}
>>> +
>>> +		if (!test_and_clear_bit(MT76_WORKER_SCHEDULED, &w->state)) {
>>> +			schedule();
>>> +			continue;
>>> +		}
>>> +
>>> +		set_bit(MT76_WORKER_RUNNING, &w->state);
>>> +		set_current_state(TASK_RUNNING);
>>> +		w->fn(w);
>>> +		cond_resched();
>>> +		clear_bit(MT76_WORKER_RUNNING, &w->state);
>>> +	}
>>> +
>>> +	return 0;
>>> +}
>>> +EXPORT_SYMBOL_GPL(__mt76_worker_fn);
>> 
>> So how is this better than, for example,
>> create_singlethread_workqueue()? And if this is better, shouldn't it be
>> part of workqueue.h instead of every driver reinventing the wheel?
>
> Unlike a workqueue, this one only allows one fixed worker function to be
> executed by the worker thread. Because of that, there is less locking
> and less code for scheduling involved.
> In fact, the function that schedules the worker is small enough that
> it's just a simple inline function.
> The difference matters in this case, because the tx worker is scheduled
> very often in a hot path.
> I don't think it fits into workqueue.h (because of the lack of
> separation between workqueue and work struct), and I don't know if other
> drivers need this, so let's keep it in mt76 and only move to a generic
> API if we find another user for it.

Ok, fair enough. But please add this info to the commit log so the
reasoning is properly documented.

-- 
https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches

  reply	other threads:[~2020-09-14  7:55 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-08 21:17 [PATCH 01/11] mt76: mt7615: fix MT_ANT_SWITCH_CON register definition Felix Fietkau
2020-09-08 21:17 ` [PATCH 02/11] mt76: mt7615: fix antenna selection for testmode tx_frames Felix Fietkau
2020-09-08 21:17 ` [PATCH 03/11] mt76: testmode: add a limit for queued tx_frames packets Felix Fietkau
2020-09-08 21:17 ` [PATCH 04/11] mt76: add utility functions for deferring work to a kernel thread Felix Fietkau
2020-09-11  8:15   ` Kalle Valo
     [not found]   ` <010101747c3b747d-09af9fc1-2e74-400f-89f5-fae71b7d163b-000000@us-west-2.amazonses.com>
2020-09-12  5:05     ` Felix Fietkau
2020-09-14  7:55       ` Kalle Valo [this message]
2020-09-15  9:09   ` [PATCH v2 4/11] " Felix Fietkau
2020-09-08 21:17 ` [PATCH 05/11] mt76: convert from tx tasklet to tx worker thread Felix Fietkau
2020-09-08 21:17 ` [PATCH 06/11] mt76: mt7915: fix HE BSS info Felix Fietkau
2020-09-08 21:17 ` [PATCH 07/11] mt76: dma: cache dma map address/len in struct mt76_queue_entry Felix Fietkau
2020-09-08 21:17 ` [PATCH 08/11] mt76: mt7915: simplify mt7915_lmac_mapping Felix Fietkau
2020-09-08 21:17 ` [PATCH 09/11] mt76: mt7915: fix queue/tid mapping for airtime reporting Felix Fietkau
2020-09-08 21:17 ` [PATCH 10/11] mt76: move txwi handling code to dma.c, since it is mmio specific Felix Fietkau
2020-09-08 21:17 ` [PATCH 11/11] mt76: remove retry_q from struct mt76_txq and related code Felix Fietkau

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=87363kpzc3.fsf@codeaurora.org \
    --to=kvalo@codeaurora.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=nbd@nbd.name \
    /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).