Re: [PATCH v2] x86/paravirt: useless assignment instructions cause Unixbench full core performance degradation

From: Waiman Long
Date: Mon Jun 27 2022 - 09:26:07 EST


On 6/27/22 01:54, Guo Hui wrote:
Thank you very much Longman, my patch is as you said, only disable node_cpu on X86, enable node_cpu on arm64, powerpc, s390 architectures;
the code is in file arch/x86/kernel/paravirt-spinlocks.c:
    DECLARE_STATIC_KEY_FALSE(preemted_key);
    static_branch_enable(&preemted_key);

the default value of preemted_key is false and the if conditional statement is reversed,
the code is in file kernel/locking/osq_lock.c:
    DEFINE_STATIC_KEY_FALSE(preemted_key);

    static inline int node_cpu(struct optimistic_spin_node *node)
    {
        int cpu = 0;

        if (!static_branch_unlikely(&preemted_key))
            cpu = node->cpu - 1;

        return cpu;
  }

In this way, only one nop instruction is added to architectures arm64, powerpc and s390, including virtual machines, without any other changes.

You are right. I am probably too tired last night to read the patch more carefully.

Cheers,
Longman