linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: peterz@infradead.org
To: Christoph Hellwig <hch@lst.de>
Cc: mingo@kernel.org, torvalds@linux-foundation.org,
	linux-kernel@vger.kernel.org, will@kernel.org,
	paulmck@kernel.org, axboe@kernel.dk, chris@chris-wilson.co.uk,
	davem@davemloft.net, kuba@kernel.org, fweisbec@gmail.com,
	oleg@redhat.com, vincent.guittot@linaro.org
Subject: Re: [RFC][PATCH v2 08/10] smp,irq_work: Use the new irq_work API
Date: Thu, 20 Aug 2020 15:40:01 +0200	[thread overview]
Message-ID: <20200820134001.GV2674@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <20200820061927.GA6447@lst.de>

On Thu, Aug 20, 2020 at 08:19:27AM +0200, Christoph Hellwig wrote:
> On Tue, Aug 18, 2020 at 12:51:10PM +0200, Peter Zijlstra wrote:
> >  	if (blk_mq_complete_need_ipi(rq)) {
> > -		INIT_CSD(&rq->csd, __blk_mq_complete_request_remote, rq);
> > -		smp_call_function_single_async(rq->mq_ctx->cpu, &rq->csd);
> > +		rq->work = IRQ_WORK_INIT_HARD(__blk_mq_complete_request_remote);
> > +		irq_work_queue_remote_static(rq->mq_ctx->cpu, &rq->work);
> 
> So given the caller synchronization / use once semantics does it even
> make sense to split the init vs call part here?  What about:
> 
> 		irq_work_queue_remote_static(&rq->work, rq->mq_ctx->cpu,
> 					    __blk_mq_complete_request_remote);
> 
> instead?  And btw, I'm not sure what the "static" stand for.  Maybe
> irq_work_queue_remote_once?

The 'static' came from static storage, but I agree that the naming is
pretty random/poor.

One argument against your proposal is that it makes it even harder to
add warnings that try and catch bad/broken usage.

Also, given Linus' email I now wonder if we still want the
irq_work_remote variant at all.


So the initial use-case was something like:

struct foo {
	struct irq_work work;
	...
};

void foo_func(struct irq_work *work)
{
	struct foo *f = container_of(work, struct foo, work);

	...
}

DEFINE_PER_CPU(struct foo, foo) = IRQ_WORK_INIT_HARD(foo_func);

void raise_foo(int cpu)
{
	irq_work_queue_remote(per_cpu_ptr(&foo, cpu), cpu);
}

Where you can, with IRQs disabled, call raise_foo(cpu) for a remote CPU
and have the guarantee that foo_func() will observe whatever you did
before calling raise_foo().

Specifically, I needed this for what is now __ttwu_queue_wakelist(),
which used to rely on smp_send_reschedule() but needed to be pulled out
of the regular scheduler IPI.

While sorting through the wreckage of me getting this horribly wrong, I
noticed that generic_smp_call_function_single_interrupt() was
unconditionally loading _2_ cachelines, one for the regular CSD llist
and one for the remote irq_work llist.

I then realized we could merge those two lists, and regain the original
intent of that IPI to only touch one line.

At that point I could build the above, but then I realized that since I
already had a mixed type list, I could put the ttwu entries on it as
well, which is cheaper than doing the above.


Anyway, tl;dr, what do we actually want? Do we favour the embedded
irq_work variant over smp_call_function_single_asyn() ?

There's a few subtle differences, where smp_call_function_single_async()
will directly call @func when @cpu == smp_processor_id(),
irq_work_remote will give you WARN -- since irq_work to the local CPU is
defined as a self-IPI, which isn't implemented on all architectures and
is a distinctly different behaviour.

That said, most (if not all) users seem to actually only care about
running things on another CPU, so that seems to not matter (much).




  reply	other threads:[~2020-08-20 13:46 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-18 10:51 [PATCH v2 00/10] smp: irq_work / smp_call_function rework Peter Zijlstra
2020-08-18 10:51 ` [PATCH v2 01/10] irq_work: Cleanup Peter Zijlstra
2020-08-18 10:51 ` [PATCH v2 02/10] smp: Cleanup smp_call_function*() Peter Zijlstra
2020-08-18 10:51 ` [PATCH v2 03/10] irq_work: Optimize irq_work_single() Peter Zijlstra
2020-08-18 10:51 ` [PATCH v2 04/10] irq_work: Unconditionally build on SMP Peter Zijlstra
2020-08-18 10:51 ` [PATCH v2 05/10] irq_work: Provide irq_work_queue_remote() Peter Zijlstra
2020-08-18 10:51 ` [RFC][PATCH v2 06/10] irq_work: Provide irq_work_queue_remote_static() Peter Zijlstra
2020-08-18 10:51 ` [RFC][PATCH v2 07/10] sched/fair: Exclude the current CPU from find_new_ilb() Peter Zijlstra
2020-08-18 10:51 ` [RFC][PATCH v2 08/10] smp,irq_work: Use the new irq_work API Peter Zijlstra
2020-08-18 16:25   ` Christoph Hellwig
2020-08-19  7:22     ` peterz
2020-08-19 18:50       ` Linus Torvalds
2020-08-19 19:41         ` peterz
2020-08-19 22:04           ` Linus Torvalds
2020-08-20 13:08             ` peterz
2020-08-20  6:20         ` Christoph Hellwig
2020-08-20  6:19   ` Christoph Hellwig
2020-08-20 13:40     ` peterz [this message]
2020-09-09  8:03       ` Christoph Hellwig
2020-08-18 10:51 ` [RFC][PATCH v2 09/10] smp: Make smp_call_function_single_async() safer Peter Zijlstra
2020-08-18 10:51 ` [RFC][PATCH v2 10/10] irq_work: Add a few comments Peter Zijlstra
2020-08-18 15:52   ` Randy Dunlap

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=20200820134001.GV2674@hirez.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=axboe@kernel.dk \
    --cc=chris@chris-wilson.co.uk \
    --cc=davem@davemloft.net \
    --cc=fweisbec@gmail.com \
    --cc=hch@lst.de \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=oleg@redhat.com \
    --cc=paulmck@kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=vincent.guittot@linaro.org \
    --cc=will@kernel.org \
    /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).