From: Clement Courbet <courbet@google.com>
To: unlisted-recipients:; (no To-header on input)
Cc: Nathan Chancellor <natechancellor@gmail.com>,
Kees Cook <keescook@chromium.org>,
Nick Desaulniers <ndesaulniers@google.com>,
Joe Perches <joe@perches.com>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
"H. Peter Anvin" <hpa@zytor.com>,
x86@kernel.org, Clement Courbet <courbet@google.com>,
linux-kernel@vger.kernel.org, clang-built-linux@googlegroups.com
Subject: [PATCH] x86: Alias memset to __builtin_memset.
Date: Wed, 25 Mar 2020 08:59:22 +0100 [thread overview]
Message-ID: <20200325075924.109330-1-courbet@google.com> (raw)
In-Reply-To: <20200323114207.222412-1-courbet@google.com>
> Not sure we should modify this for someone's downstream tree to work
> around an issue they introduced. If you want to file a bug
> internally, I'd be happy to comment on it.
I don't have a strong opinion on that. I don't know the policy of the
linux kernel w.r.t. this. There is an internal bug for this, where
kernel maintainers suggested I upstream this patch.
> Does __builtin_memset detect support for `rep stosb`, then patch the
> kernel to always use it or not?
__builtin_memset just allows the compiler to recognize that this has the
semantics of a memset, exactly like it happens when -freestanding is not
specified.
In terms of what compilers do when expanding the memset, it depends on
the size.
gcc or clang obviously do not generate vector code when -no-sse is
specified, as this would break promises.
clang inlines stores for small sizes and switches to memset as the size
increases: https://godbolt.org/z/_X16xt
gcc inlines stores for tiny sizes, then switches to repstos for larger
sizes: https://godbolt.org/z/m-G233 This behaviour is additionally
configurable through command line flags: https://godbolt.org/z/wsoJpQ
> Did you verify what this change does for other compilers?
Are there other compilers are used to build the kernel on x86 ?
icc does the same as gcc and clang: https://godbolt.org/z/yCju_D
> yet it doesn't use vector operations for the general case
I'm not sure how vector operations relate to freestanding, or this change.
> Adding -ffreestanding to optimize one hot memset in
> one function is using a really big hammer to solve the wrong
> problem.
-ffreestanding was not added to optimize anything. It was already there.
If anything -ffreestanding actually pessimizes a lot of the code
generation, as it prevents the compiler from recognizing the semantics
of common primitives. This is what this change is trying to fix.
Removing -ffreestanding from the options is another (easier?) way to fix
the problem. This change is a stab at accomodating both those who want
freestanding and those who want performance.
The hot memset I mentionned was just the hottest one. But as you can imagine
there are many constant-size memsets spread across many functions, some of
which are also very hot, the others constituting a long tail which is not
negligible.
next prev parent reply other threads:[~2020-03-25 7:59 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-23 11:42 Clement Courbet
2020-03-23 15:47 ` Nathan Chancellor
2020-03-24 1:22 ` Nick Desaulniers
2020-03-24 1:26 ` Nick Desaulniers
2020-03-24 14:06 ` Clement Courbet
2020-03-24 17:29 ` Nick Desaulniers
2020-03-24 14:07 ` [PATCH v2] " Clement Courbet
2020-03-24 15:08 ` Joe Perches
2020-03-24 15:59 ` [PATCH v3] " Clement Courbet
2020-03-25 11:33 ` Bernd Petrovitsch
2020-03-24 16:02 ` [PATCH] " Clement Courbet
2020-03-25 7:59 ` Clement Courbet [this message]
2020-03-26 12:25 ` [PATCH v4] " Clement Courbet
2020-03-26 12:38 ` [PATCH] " Clement Courbet
2020-03-26 17:18 ` Nick Desaulniers
2020-03-27 4:06 ` Michael Ellerman
2020-03-27 17:12 ` Segher Boessenkool
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=20200325075924.109330-1-courbet@google.com \
--to=courbet@google.com \
--cc=bp@alien8.de \
--cc=clang-built-linux@googlegroups.com \
--cc=hpa@zytor.com \
--cc=joe@perches.com \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=natechancellor@gmail.com \
--cc=ndesaulniers@google.com \
--cc=tglx@linutronix.de \
--cc=x86@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
all inboxes | Powered by JetHome®