linux-riscv.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Palmer Dabbelt <palmer@sifive.com>
To: Christoph Hellwig <hch@lst.de>
Cc: linux-riscv@lists.infradead.org, Christoph Hellwig <hch@lst.de>,
	Paul Walmsley <paul.walmsley@sifive.com>
Subject: Re: [PATCH 8/8] riscv: ignore the SYS_RISCV_FLUSH_ICACHE_LOCAL flag
Date: Tue, 03 Sep 2019 11:46:33 -0700 (PDT)	[thread overview]
Message-ID: <mhng-6070e215-c109-4d92-abbc-e77a2178657d@palmer-si-x1e> (raw)
In-Reply-To: <20190828060942.GA21592@lst.de>

On Tue, 27 Aug 2019 23:09:42 PDT (-0700), Christoph Hellwig wrote:
> On Tue, Aug 27, 2019 at 06:10:33PM -0700, Palmer Dabbelt wrote:
>> This is meant to perform a context-local flush, not a cpu-local flush.  The
>> whole point here is that userspace doesn't know anything about CPUs, just
>> contexts -- that's why we have this deferred flush mechanism.  I think the
>> logic is complicated but sound, and removing this will almost certainly
>> lead to huge performance degradation.
>
> All calls to flush_icache_mm are local to the context.  Take a look at
> what the current code does:
>
>  - set all bits in context.icache_stale_mask
>  - clear the current cpu from context.icache_stale_mask
>  - flush the cpu local icache
>  - create a local others mask containing every cpu running the context
>    except for the current one
>  - now if others is empty OR the local flag is set don't do anything
>    but a memory barrier, else flush the other cpus
>
>>
>> Maybe I'm missing something, what is the specific issue?
>
> The issue is that the current implementation of
> SYS_RISCV_FLUSH_ICACHE_LOCAL only flushes the icache of the currently
> running core, which is an interface that can't be used correctly.

This is used by userspace as a thread-local icache barrier: there's an 
immediate fence on the current hart, and one will be executed before that 
thread makes it to userspace on another hart.  As far as I can tell this is 
implemented correctly but not optimally: there's always a fence, but we emit an 
unnecessary fence when a different thread in the same context is scheduled on a 
different hart.

I suppose maybe we should attach the local fence mask to a task_struct instead of an 
mm_struct, which would trade off an extra load in the scheduler (to check both 
places) or more fences in the global case (on every thread getting scheduled) 
for fewer fences in the local case.  I feel like it's not really worth worrying 
about this for now.

The construct seems reasonable to me.

> riscv_flush_icache without that flag on the other handle already just
> flushes the caches for the cpus that run the current context, and then
> causes a deferred flush if the context gets run on another cpu
> eventually.

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

  reply	other threads:[~2019-09-03 18:46 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-22  6:56 sys_riscv_flush_icache Christoph Hellwig
2019-08-22  6:56 ` [PATCH 1/8] riscv: fix the flags argument type for riscv_riscv_flush_icache Christoph Hellwig
2019-08-22  6:56 ` [PATCH 2/8] riscv: remove SYS_RISCV_FLUSH_ICACHE_LOCAL #define Christoph Hellwig
2019-08-22  6:56 ` [PATCH 3/8] riscv: move sys_riscv_flush_icache to cacheflush.c Christoph Hellwig
2019-08-22  6:56 ` [PATCH 4/8] riscv: remove the active_mm check in sys_riscv_flush_icache Christoph Hellwig
2019-08-22  6:56 ` [PATCH 5/8] riscv: actually clear icache_stale_mask for all harts in mm_cpumask Christoph Hellwig
2019-08-22 18:29   ` Atish Patra
2019-08-26 11:41     ` hch
2019-08-22  6:56 ` [PATCH 6/8] riscv: use get_cpu and put_cpu in sys_riscv_flush_icache Christoph Hellwig
2019-08-22 17:49   ` Atish Patra
2019-08-26 11:38     ` hch
2019-08-27 18:42       ` Atish Patra
2019-08-22  6:56 ` [PATCH 7/8] riscv: improve the local flushing logic " Christoph Hellwig
2019-08-22 17:34   ` Atish Patra
2019-08-26 11:36     ` hch
2019-08-22  6:56 ` [PATCH 8/8] riscv: ignore the SYS_RISCV_FLUSH_ICACHE_LOCAL flag Christoph Hellwig
2019-08-28  1:10   ` Palmer Dabbelt
2019-08-28  6:09     ` Christoph Hellwig
2019-09-03 18:46       ` Palmer Dabbelt [this message]
2019-09-06 17:07         ` Christoph Hellwig
2019-09-13 19:44           ` Palmer Dabbelt

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=mhng-6070e215-c109-4d92-abbc-e77a2178657d@palmer-si-x1e \
    --to=palmer@sifive.com \
    --cc=hch@lst.de \
    --cc=linux-riscv@lists.infradead.org \
    --cc=paul.walmsley@sifive.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).