From: Peter Zijlstra <peterz@infradead.org>
To: Guo Hui <guohui@uniontech.com>
Cc: longman@redhat.com, jgross@suse.com, srivatsa@csail.mit.edu,
amakhalov@vmware.com, pv-drivers@vmware.com, tglx@linutronix.de,
mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com,
x86@kernel.org, hpa@zytor.com, will@kernel.org,
boqun.feng@gmail.com, virtualization@lists.linux-foundation.org,
wangxiaohua@uniontech.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] x86/paravirt: useless assignment instructions cause Unixbench full core performance degradation
Date: Mon, 27 Jun 2022 09:49:46 +0200 [thread overview]
Message-ID: <YrlhGqqce0NCQ6hi@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <20220627021350.25714-1-guohui@uniontech.com>
On Mon, Jun 27, 2022 at 10:13:50AM +0800, Guo Hui wrote:
> The instructions assigned to the vcpu_is_preempted function parameter
> in the X86 architecture physical machine are redundant instructions,
> causing the multi-core performance of Unixbench to drop by about 4% to 5%.
> The C function is as follows:
> static bool vcpu_is_preempted(long vcpu);
>
> The parameter 'vcpu' in the function osq_lock
> that calls the function vcpu_is_preempted is assigned as follows:
>
> The C code is in the function node_cpu:
> cpu = node->cpu - 1;
>
> The instructions corresponding to the C code are:
> mov 0x14(%rax),%edi
> sub $0x1,%edi
>
> The above instructions are unnecessary
> in the X86 Native operating environment,
> causing high cache-misses and degrading performance.
The above basically says that argument setup is not patched out and
causes significant pain due to a cache-miss.
> Signed-off-by: Guo Hui <guohui@uniontech.com>
> ---
> arch/x86/kernel/paravirt-spinlocks.c | 4 ++++
> kernel/locking/osq_lock.c | 9 ++++++++-
> 2 files changed, 12 insertions(+), 1 deletion(-)
>
> diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
> index 9e1ea99ad..7a55f8407 100644
> --- a/arch/x86/kernel/paravirt-spinlocks.c
> +++ b/arch/x86/kernel/paravirt-spinlocks.c
> @@ -33,6 +33,8 @@ bool pv_is_native_vcpu_is_preempted(void)
> __raw_callee_save___native_vcpu_is_preempted;
> }
>
> +DECLARE_STATIC_KEY_FALSE(preemted_key);
> +
> void __init paravirt_set_cap(void)
> {
> if (!pv_is_native_spin_unlock())
> @@ -40,4 +42,6 @@ void __init paravirt_set_cap(void)
>
> if (!pv_is_native_vcpu_is_preempted())
> setup_force_cpu_cap(X86_FEATURE_VCPUPREEMPT);
> + else
> + static_branch_enable(&preemted_key);
> }
At least for x86 it makes sense to have the static_key default the other
way around. That is, enable it along with vcpu_is_preempted().
> diff --git a/kernel/locking/osq_lock.c b/kernel/locking/osq_lock.c
> index d5610ad52..a8798e701 100644
> --- a/kernel/locking/osq_lock.c
> +++ b/kernel/locking/osq_lock.c
> @@ -22,9 +22,16 @@ static inline int encode_cpu(int cpu_nr)
> return cpu_nr + 1;
> }
>
> +DEFINE_STATIC_KEY_FALSE(preemted_key);
> +
> static inline int node_cpu(struct optimistic_spin_node *node)
> {
> - return node->cpu - 1;
> + int cpu = 0;
> +
> + if (!static_branch_unlikely(&preemted_key))
> + cpu = node->cpu - 1;
> +
> + return cpu;
> }
Would not something like:
static inline bool
vcpu_is_preempted_node(struct optimistic_spin_node *node)
{
if (!static_branch_unlikely(&vcpu_has_preemption))
return false;
return vcpu_is_preempted(node_cpu(node->prev));
}
And then use that like:
if (smp_cond_load_relaxed(&node->locked, VAL || need_resched() ||
vcpu_is_preempted_node(node)))
Not generate better code still?
next prev parent reply other threads:[~2022-06-27 7:50 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-23 15:50 [PATCH] " Guo Hui
2022-06-23 21:54 ` Waiman Long
2022-06-27 2:13 ` [PATCH v2] " Guo Hui
2022-06-27 3:02 ` Waiman Long
[not found] ` <62b94621.1c69fb81.3a378.57ccSMTPIN_ADDED_BROKEN@mx.google.com>
2022-06-27 13:25 ` Waiman Long
2022-06-27 5:57 ` Juergen Gross
2022-06-27 7:07 ` [PATCH v3] " Guo Hui
2022-06-27 7:49 ` Peter Zijlstra [this message]
[not found] ` <3c020577-2045-fa12-9e33-65ece10bda30@uniontech.com>
2022-06-27 9:30 ` [PATCH v2] " Peter Zijlstra
2022-06-27 14:27 ` [PATCH v4] " Guo Hui
2022-06-27 15:42 ` Juergen Gross
2022-06-27 15:58 ` Waiman Long
2022-06-28 4:31 ` [PATCH v5] " Guo Hui
2022-06-28 12:54 ` [PATCH v6] " Guo Hui
2022-06-28 14:15 ` Waiman Long
2022-06-28 16:12 ` [PATCH v7] " Guo Hui
2022-06-28 17:28 ` Waiman Long
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=YrlhGqqce0NCQ6hi@hirez.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=amakhalov@vmware.com \
--cc=boqun.feng@gmail.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=guohui@uniontech.com \
--cc=hpa@zytor.com \
--cc=jgross@suse.com \
--cc=linux-kernel@vger.kernel.org \
--cc=longman@redhat.com \
--cc=mingo@redhat.com \
--cc=pv-drivers@vmware.com \
--cc=srivatsa@csail.mit.edu \
--cc=tglx@linutronix.de \
--cc=virtualization@lists.linux-foundation.org \
--cc=wangxiaohua@uniontech.com \
--cc=will@kernel.org \
--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®