public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: "H.J. Lu" <hjl.tools@gmail.com>
To: Noah Goldstein <goldstein.w.n@gmail.com>
Cc: GNU C Library <libc-alpha@sourceware.org>,
	"Carlos O'Donell" <carlos@systemhalted.org>
Subject: Re: [PATCH v5 2/2] x86: Add bounds `x86_non_temporal_threshold`
Date: Wed, 15 Jun 2022 11:43:03 -0700	[thread overview]
Message-ID: <CAMe9rOr6BSrPuMDR8r=8tKeLCL0vKBVr2ECBNakwbHkaFDT56A@mail.gmail.com> (raw)
In-Reply-To: <20220615183240.623735-1-goldstein.w.n@gmail.com>

On Wed, Jun 15, 2022 at 11:32 AM Noah Goldstein <goldstein.w.n@gmail.com> wrote:
>
> The lower-bound (131072) and upper-bound (SIZE_MAX / 16) are assumed
> by memmove-vec-unaligned-erms.
>
> The lower-bound is needed because memmove-vec-unaligned-erms unrolls
> the loop aggressively in the L(large_memset_4x) case.
>
> The upper-bound is needed because memmove-vec-unaligned-erms
> right-shifts the value of `x86_non_temporal_threshold` by
> LOG_4X_MEMCPY_THRESH (4) which without a bound may overflow.
>
> The lack of lower-bound can be a correctness issue. The lack of
> upper-bound cannot.
> ---
>  manual/tunables.texi       | 2 +-
>  sysdeps/x86/dl-cacheinfo.h | 7 ++++++-
>  2 files changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/manual/tunables.texi b/manual/tunables.texi
> index 1482412078..a420ed6206 100644
> --- a/manual/tunables.texi
> +++ b/manual/tunables.texi
> @@ -47,7 +47,7 @@ glibc.malloc.mxfast: 0x0 (min: 0x0, max: 0xffffffffffffffff)
>  glibc.elision.skip_lock_busy: 3 (min: -2147483648, max: 2147483647)
>  glibc.malloc.top_pad: 0x0 (min: 0x0, max: 0xffffffffffffffff)
>  glibc.cpu.x86_rep_stosb_threshold: 0x800 (min: 0x1, max: 0xffffffffffffffff)
> -glibc.cpu.x86_non_temporal_threshold: 0xc0000 (min: 0x0, max: 0xffffffffffffffff)
> +glibc.cpu.x86_non_temporal_threshold: 0xc0000 (min: 0x20000, max: 0x0fffffffffffffff)
>  glibc.cpu.x86_shstk:
>  glibc.cpu.hwcap_mask: 0x6 (min: 0x0, max: 0xffffffffffffffff)
>  glibc.malloc.mmap_max: 0 (min: -2147483648, max: 2147483647)
> diff --git a/sysdeps/x86/dl-cacheinfo.h b/sysdeps/x86/dl-cacheinfo.h
> index cc3b840f9c..b4ff385ae1 100644
> --- a/sysdeps/x86/dl-cacheinfo.h
> +++ b/sysdeps/x86/dl-cacheinfo.h
> @@ -931,8 +931,13 @@ dl_init_cacheinfo (struct cpu_features *cpu_features)
>
>    TUNABLE_SET_WITH_BOUNDS (x86_data_cache_size, data, 0, SIZE_MAX);
>    TUNABLE_SET_WITH_BOUNDS (x86_shared_cache_size, shared, 0, SIZE_MAX);
> +  /* SIZE_MAX >> 4 because memmove-vec-unaligned-erms right-shifts the value of
> +     'x86_non_temporal_threshold' by `LOG_4X_MEMCPY_THRESH` (4) and it is best
> +     if that operation cannot overflow. 0x20000 (131072) because the
> +     L(large_memset_4x) case aggressively unrolls the loop.  Both values are

How is 0x20000 computed?  Shouldn't it depend on vector size?

> +     reflected in the manual.  */
>    TUNABLE_SET_WITH_BOUNDS (x86_non_temporal_threshold, non_temporal_threshold,
> -                          0, SIZE_MAX);
> +                          0x20000, SIZE_MAX >> 4);
>    TUNABLE_SET_WITH_BOUNDS (x86_rep_movsb_threshold, rep_movsb_threshold,
>                            minimum_rep_movsb_threshold, SIZE_MAX);
>    TUNABLE_SET_WITH_BOUNDS (x86_rep_stosb_threshold, rep_stosb_threshold, 1,
> --
> 2.34.1
>


-- 
H.J.

  reply	other threads:[~2022-06-15 18:43 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-15  0:25 [PATCH v1 1/3] x86: Fix misordered logic for setting `rep_movsb_stop_threshold` Noah Goldstein
2022-06-15  0:25 ` [PATCH v1 2/3] x86: Cleanup bounds checking in large memcpy case Noah Goldstein
2022-06-15  1:07   ` H.J. Lu
2022-06-15  3:57     ` Noah Goldstein
2022-06-15  3:57   ` [PATCH v2] " Noah Goldstein
2022-06-15 14:52     ` H.J. Lu
2022-06-15 15:13       ` Noah Goldstein
2022-06-15 15:12   ` [PATCH v3] " Noah Goldstein
2022-06-15 16:48     ` H.J. Lu
2022-06-15 17:44       ` Noah Goldstein
2022-06-15 17:41   ` [PATCH v4 1/2] " Noah Goldstein
2022-06-15 17:41     ` [PATCH v4 2/2] x86: Add bounds `x86_non_temporal_threshold` Noah Goldstein
2022-06-15 18:22       ` H.J. Lu
2022-06-15 18:33         ` Noah Goldstein
2022-06-15 18:32       ` [PATCH v5 " Noah Goldstein
2022-06-15 18:43         ` H.J. Lu [this message]
2022-06-15 19:52       ` [PATCH v6 2/3] " Noah Goldstein
2022-06-15 20:27         ` H.J. Lu
2022-06-15 20:35           ` Noah Goldstein
2022-06-15 20:34       ` [PATCH v7 " Noah Goldstein
2022-06-15 20:48         ` H.J. Lu
2022-07-14  2:55           ` Sunil Pandey
2022-06-15 18:22     ` [PATCH v4 1/2] x86: Cleanup bounds checking in large memcpy case H.J. Lu
2022-07-14  2:57       ` Sunil Pandey
2022-06-15  0:25 ` [PATCH v1 3/3] x86: Add sse42 implementation to strcmp's ifunc Noah Goldstein
2022-06-15  1:08   ` H.J. Lu
2022-07-14  2:54     ` Sunil Pandey
2022-06-15  1:02 ` [PATCH v1 1/3] x86: Fix misordered logic for setting `rep_movsb_stop_threshold` H.J. Lu
2022-07-14  2:53   ` Sunil Pandey

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='CAMe9rOr6BSrPuMDR8r=8tKeLCL0vKBVr2ECBNakwbHkaFDT56A@mail.gmail.com' \
    --to=hjl.tools@gmail.com \
    --cc=carlos@systemhalted.org \
    --cc=goldstein.w.n@gmail.com \
    --cc=libc-alpha@sourceware.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 read-only IMAP folder(s) and NNTP newsgroup(s).