Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Will Deacon <will@kernel.org>
To: Guo Hui <guohui@uniontech.com>
Cc: catalin.marinas@arm.com, linux-arm-kernel@lists.infradead.org,
	quic_jiles@quicinc.com, mark.rutland@arm.com,
	wangxiaohua@uniontech.com
Subject: Re: [PATCH] arm64: mm: Optimize querying asid from reserved_asids
Date: Fri, 29 Sep 2023 17:51:21 +0100	[thread overview]
Message-ID: <20230929165119.GA30869@willie-the-truck> (raw)
In-Reply-To: <20230927055106.14635-1-guohui@uniontech.com>

On Wed, Sep 27, 2023 at 01:51:06PM +0800, Guo Hui wrote:
> Move reserved_asids updates into function flush_context. When
> asid_generation increases, reserved_asids are updated synchronously.
> The execution frequency of function flush_context is far less than
> that of function check_update_reserved_asid. In function
> check_update_reserved_asid, you only need to query whether it is
> in reserved_asids based on the new newasid, and there is no need
> to update it.
> 
> In the function check_update_reserved_asid, among all the times
> reserved_asids are hit, the probability that newasid is equal to
> the reserved_asids of the current CPU is about greater than 70%.

Do you have any performance numbers to justify this change?

> diff --git a/arch/arm64/mm/context.c b/arch/arm64/mm/context.c
> index 188197590fc9..76e0beb14466 100644
> --- a/arch/arm64/mm/context.c
> +++ b/arch/arm64/mm/context.c
> @@ -101,7 +101,7 @@ static void set_reserved_asid_bits(void)
>  #define asid_gen_match(asid) \
>  	(!(((asid) ^ atomic64_read(&asid_generation)) >> asid_bits))
>  
> -static void flush_context(void)
> +static void flush_context(u64 generation)
>  {
>  	int i;
>  	u64 asid;
> @@ -120,6 +120,8 @@ static void flush_context(void)
>  		 */
>  		if (asid == 0)
>  			asid = per_cpu(reserved_asids, i);
> +
> +		asid = generation | (asid & ~ASID_MASK);

I'm struggling to see how this is safe with multiple rollovers. For
example, if we have the following sequence of events on one CPU:

1. Task A runs with ASID 42
2. Context switch to Task C with ASID 66
3. A rollover occurs
4. Task B runs for the first time; gets allocated ASID 42
5. Another rollover occurs
6. Task A runs

Won't task A get ASID 42, even though that's reserved for task B?

But this code is subtle, so maybe I missed something.

Also, if we change this, then you should update the TLA+ model over at

https://git.kernel.org/pub/scm/linux/kernel/git/cmarinas/kernel-tla.git/tree/asidalloc.tla

Cheers,

Will

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

      reply	other threads:[~2023-09-29 16:51 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-27  5:51 [PATCH] arm64: mm: Optimize querying asid from reserved_asids Guo Hui
2023-09-29 16:51 ` Will Deacon [this message]

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=20230929165119.GA30869@willie-the-truck \
    --to=will@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=guohui@uniontech.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=mark.rutland@arm.com \
    --cc=quic_jiles@quicinc.com \
    --cc=wangxiaohua@uniontech.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