Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp539358pxb; Wed, 29 Sep 2021 04:46:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwat/9lDy9s5uB+xFSP13qQnbOgUgAQ6XhrAPV/d6kkFTOvOmOE+Dxsvx21Sbg9eBQpKM9i X-Received: by 2002:a05:6a00:216f:b0:44b:6212:4967 with SMTP id r15-20020a056a00216f00b0044b62124967mr2856297pff.23.1632915962329; Wed, 29 Sep 2021 04:46:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632915962; cv=none; d=google.com; s=arc-20160816; b=Qn2AjACEGjFPqBVINlz+o9OHHgGEAZxwwJ7vn5lpKf1f6SFml20WsIC8F1x3NZNO2z gxoMOF4Cjpb3xzFdZr3DujAqYXSv0KinTYgg8G+4yQp23GZyLnh/tXq5ii1QE6qRcPsc MG32p+Gg+5HnE3F2is8YD5d1qGa8mMcnwgiM2eJ0DKmP2GljVJXzhNChvchB4xnYNnTo QZV1aIm2ar/WyhukzBHYsQUuV2aNUn/+byZ9kvCp31YmHWwZuC5dUcVSRhcMhdiAkRMn HXUhOQrodaZkM8pxVTlGRvKw+KAAS3GiwJ6SVW5ud4iEnlgf6dvh+UVBKWExxhsSuYdK GU2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:to:from; bh=gnotEdm6Pvy6e45sGlwE3YE8mCTN3EfT1w4fAywF0M4=; b=LOV4+zcA7WP0wGx2eWyj9HWrWz7izi6+CpcllTS8mJolLiJFcl9onnlq0+6ym85fQG R7W72/nWLy9RJwp57dGum4zP1P0h2Wu3YnY8sM7hXh1rpsr6Cj8hBkTWt50jDGSPVVMy 0h08NW8PjJB5Fm6679Z7KIkDB8kKE6EjcUxgSKQrwWX8XRJW2jTReNFyxczUP2zIeQLu 4ZJiYihlritXzurQe7NZ4TYhHeKaUdiLLUNX4LQ4J29YWDMeywvzthKz8sFxRUeDrFMu I17eGz9PBvdmtjGrNnDf+0+22udIo2ENCk7X3csc7KOgU+NgBhIuctesfLlz95iHPBFB IR9w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v14si2585603plo.333.2021.09.29.04.45.50; Wed, 29 Sep 2021 04:46:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245026AbhI2JWK (ORCPT + 99 others); Wed, 29 Sep 2021 05:22:10 -0400 Received: from [119.249.100.165] ([119.249.100.165]:15915 "EHLO mx423.baidu.com" rhost-flags-FAIL-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S229487AbhI2JWJ (ORCPT ); Wed, 29 Sep 2021 05:22:09 -0400 Received: from bjhw-sys-rpm015653cc5.bjhw.baidu.com (bjhw-sys-rpm015653cc5.bjhw.baidu.com [10.227.53.39]) by mx423.baidu.com (Postfix) with ESMTP id D45D316E01154; Wed, 29 Sep 2021 17:20:14 +0800 (CST) Received: from localhost (localhost [127.0.0.1]) by bjhw-sys-rpm015653cc5.bjhw.baidu.com (Postfix) with ESMTP id CCAC4D9932; Wed, 29 Sep 2021 17:20:14 +0800 (CST) From: Li RongQing To: lirongqing@baidu.com, linux-kernel@vger.kernel.org, tglx@linutronix.de Subject: [PATCH] KVM: Micro-optimize pvclock_clocksource_read Date: Wed, 29 Sep 2021 17:20:14 +0800 Message-Id: <1632907214-29633-1-git-send-email-lirongqing@baidu.com> X-Mailer: git-send-email 1.7.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Compare the return of atomic64_cmpxchg with previous save for last, to reduce the number of while-loop iterations with atomic operations from two to one in the most common situation Original patch at: https://kvm.vger.kernel.narkive.com/WraXedaQ/patch-kvm-pvclock-clocksource-read-while-loop-optimization Signed-off-by: Li RongQing --- arch/x86/kernel/pvclock.c | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c index eda37df..98d106f 100644 --- a/arch/x86/kernel/pvclock.c +++ b/arch/x86/kernel/pvclock.c @@ -67,8 +67,8 @@ u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src) u64 pvclock_clocksource_read(struct pvclock_vcpu_time_info *src) { unsigned version; + u64 last, save; u64 ret; - u64 last; u8 flags; do { @@ -104,8 +104,9 @@ u64 pvclock_clocksource_read(struct pvclock_vcpu_time_info *src) do { if (ret < last) return last; + save = last; last = atomic64_cmpxchg(&last_value, last, ret); - } while (unlikely(last != ret)); + } while (unlikely(last != save)); return ret; } -- 1.7.1