Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp464099pxb; Fri, 3 Sep 2021 06:12:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxedFXWnoPNrfCvi7yfFd7z0wWj6s+xdCIO0pOSt8mNCoGx4KUvlbtGeJc616aJ73Zf1yT+ X-Received: by 2002:ac2:4182:: with SMTP id z2mr2837633lfh.503.1630674744417; Fri, 03 Sep 2021 06:12:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630674744; cv=none; d=google.com; s=arc-20160816; b=FQ5BCUbYjwKQ1e+5O47dfW8x1B4fiSDguGXtXYex7UFVNh15myW8gKsH4ZrHbVzPUw B4UzAPlXDySo9p6B4P9AyzDeJ0nhpxFrgpBKeajRkjqjE+DmMDIwh/583ywT8swGv4hv d+XVFh1LTsNJF3ji1PeDmIoF+4CiTVmnnG+LtpalkewSoTsJnwKBRF44RG8t710HG0Vm kQpQDvyqj6s/+1mqh+crCv84K/xhgiLNQTwIlAbe4Rogno/tBq/nlN3oEOq8IGsruwy0 npmtjr8d0vbNAd/K0TEWoUPzacbezkrLqse2rLSk6juP7o7bs28UM9DoSKz22q/yrd7M BYfQ== 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=VvUzqvAZNvokg+Q+LyZYgdP09LJ/NwsK6YOI32X7z9x1lideEz+9CaHqIxC6FlbXTa dZgfo3rLbbiQN/wXVm88wQJ/NtYG4hwTUys1hi+o16472MPF/5i/f47QFFd6yPR/DgvX BkrzSCGjE91dUNaSZrKlRdiuKRNc2Fqn5vzny0BYMHXMNDe+Jwqy6sPQezWlYAG3/R4g /BpPCD9iMGC5sKZeYaX5vYeIYq3Gq0BOaaqQ/O/8BAI5xZ6pb93R7l/BcJH/ZJUJ1Ag3 JkZiM4tSaKd5cXiHc/GqC0vsLPWUt2BXOMie8VnJExWEFgClxy/anYLvGIoRdO2Tk91z PWRg== 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 r21si5840543ejo.665.2021.09.03.06.11.56; Fri, 03 Sep 2021 06:12:24 -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 S235062AbhICMqL (ORCPT + 99 others); Fri, 3 Sep 2021 08:46:11 -0400 Received: from mx449.baidu.com ([119.249.100.41]:57370 "EHLO mx419.baidu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S234262AbhICMqL (ORCPT ); Fri, 3 Sep 2021 08:46:11 -0400 Received: from bjhw-sys-rpm015653cc5.bjhw.baidu.com (bjhw-sys-rpm015653cc5.bjhw.baidu.com [10.227.53.39]) by mx419.baidu.com (Postfix) with ESMTP id 4E53218181B84; Fri, 3 Sep 2021 20:45:08 +0800 (CST) Received: from localhost (localhost [127.0.0.1]) by bjhw-sys-rpm015653cc5.bjhw.baidu.com (Postfix) with ESMTP id 42594D9932; Fri, 3 Sep 2021 20:45:08 +0800 (CST) From: Li RongQing To: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, x86@kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] KVM: Micro-optimize pvclock_clocksource_read Date: Fri, 3 Sep 2021 20:45:08 +0800 Message-Id: <1630673108-9121-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