From patchwork Tue Oct 3 07:45:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 147689 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2a8e:b0:403:3b70:6f57 with SMTP id in14csp1919229vqb; Tue, 3 Oct 2023 00:46:29 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGLzV6sL5t/T0JsO+sr+V23gOZlJ/CdkOMH4v6WELxq72vcDLRQxdTKa4CceYYCT/aDa1BK X-Received: by 2002:a17:90a:117:b0:279:e5e:ea1e with SMTP id b23-20020a17090a011700b002790e5eea1emr11039305pjb.9.1696319189774; Tue, 03 Oct 2023 00:46:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696319189; cv=none; d=google.com; s=arc-20160816; b=sP5bQFn1/oaQ1BqhroxN+8600WumutzK0glVq4N1Lgw+30GiT+CbUfbtwXUEXHhvU0 gMtSligNijHVrqiOPCS0f6fzY2nHoB/72E0slreAiTh2/7qEw9NOsqLmJu5eClwWXH+y +3JnKl58FKhotHCuRePodClqhhikilY3K983VZhJfkirxzjPauJuoUa+Z4jtCwfBS7kx nPacnPWCWNNHmHsp4dDLBb9daz1Dxexl/Izwxz8F9VgeD365B8zxTkaNoD/oLZyzcuyI auGkSI2Ns1vkl60VL5BLphFd1bRwSXNFet5ADyV+ZwFDoHsaLd3QIqQ96yybfA/4P475 xWyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=upHOqm9ZlfS4CRKOxbhW/yLyTqSD3syqj4fBx15H5dQ=; fh=lC3L+tLu9jMrTwLXdci/D+zTDmYl6oRylGrfIkeVy60=; b=pvShjHGxozJSY7C6CDAjB28ZGFs9uXnmDoH5Bp/l/1/Z583f+U6CJANZMEUbllXYmT 8H9F42+D7Trf93XudbAs8ajPY3rIbmXXogKaDcF8yP9sHyg/DOPQn5/i0u+tRKpJOuUl wE2tJZiMApfOTLwmED2AQ0QIcZ5rwpCSD5++/LqLEK+oa5qJfyfl/2R68IIkLql0dXug /R6pg7UfefOUc3SwC45unZHx9Q0HrlLN5coKXIAKnjDKBcXzOa465+v1xer2qG/ir0TZ 230rd9xjDnPX0CpsM3Be6r1/VBrGXTaiV5pgROTYuwj6wYzEP/DiujeRXOR/fikf/51u 2Q8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=itovq23D; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id r7-20020a17090a560700b0027766994586si9279375pjf.71.2023.10.03.00.46.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 00:46:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=itovq23D; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 99DD5801D145; Tue, 3 Oct 2023 00:46:07 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230401AbjJCHqE (ORCPT + 18 others); Tue, 3 Oct 2023 03:46:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230355AbjJCHqC (ORCPT ); Tue, 3 Oct 2023 03:46:02 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4BE83A9; Tue, 3 Oct 2023 00:45:56 -0700 (PDT) Date: Tue, 03 Oct 2023 07:45:54 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1696319155; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=upHOqm9ZlfS4CRKOxbhW/yLyTqSD3syqj4fBx15H5dQ=; b=itovq23DX9jPAAdl6M1L/+1rfnV0il1nCuesJjXCxeX5IDS77YqJlAqTluq9OQLAdgLSjv 23rL5702xxnCRNRZ4aEhQ16eKbcNNmLK3MCi/Pm22M5DjiIYgSECuv5Ntak9Zsvd/gFVRp 7f+tSprGYrE6/pt3rAH0h9gGsnSDPrgtO3uL0GFKrBGoKbnyotfDsIBFA5phyL41C/u5lm 77qM0Lhh5B/dJrg0wULxq3tjWnIEHls14AdPklQsc1CTiil6b/TbtmJUuvAMSUAtvIRKLk hq39cQ4OJqt4eaYg86icNnscCUD4dSIfu9GYtGEW+MXn0z9LqlnXCZB5gynEmA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1696319155; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=upHOqm9ZlfS4CRKOxbhW/yLyTqSD3syqj4fBx15H5dQ=; b=6jRj2UFeMs7XXcEZOTelpNioWeoXE5zwYzcQUccJuI+wvZTHdzlLtrAa7wagXW2F+/aHOp GdI+ubWCuEQA+aAQ== From: "tip-bot2 for Uros Bizjak" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: perf/core] perf/x86/rapl: Use local64_try_cmpxchg in rapl_event_update() Cc: Uros Bizjak , Ingo Molnar , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20230807145134.3176-2-ubizjak@gmail.com> References: <20230807145134.3176-2-ubizjak@gmail.com> MIME-Version: 1.0 Message-ID: <169631915427.3135.14176807779791264532.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 03 Oct 2023 00:46:07 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778719590714079533 X-GMAIL-MSGID: 1778719590714079533 The following commit has been merged into the perf/core branch of tip: Commit-ID: df60e18058bb6792c85e4ede43876c1df44f5b9a Gitweb: https://git.kernel.org/tip/df60e18058bb6792c85e4ede43876c1df44f5b9a Author: Uros Bizjak AuthorDate: Mon, 07 Aug 2023 16:51:15 +02:00 Committer: Ingo Molnar CommitterDate: Tue, 03 Oct 2023 09:36:18 +02:00 perf/x86/rapl: Use local64_try_cmpxchg in rapl_event_update() Use local64_try_cmpxchg() instead of local64_cmpxchg(*ptr, old, new) == old. X86 CMPXCHG instruction returns success in ZF flag, so this change saves a compare after CMPXCHG (and related move instruction in front of CMPXCHG). Also, try_cmpxchg() implicitly assigns old *ptr value to "old" when CMPXCHG fails. There is no need to re-read the value in the loop. No functional change intended. Signed-off-by: Uros Bizjak Signed-off-by: Ingo Molnar Link: https://lore.kernel.org/r/20230807145134.3176-2-ubizjak@gmail.com Cc. "H. Peter Anvin" --- arch/x86/events/rapl.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/arch/x86/events/rapl.c b/arch/x86/events/rapl.c index e8f53b2..6d3e738 100644 --- a/arch/x86/events/rapl.c +++ b/arch/x86/events/rapl.c @@ -179,13 +179,11 @@ static u64 rapl_event_update(struct perf_event *event) s64 delta, sdelta; int shift = RAPL_CNTR_WIDTH; -again: prev_raw_count = local64_read(&hwc->prev_count); - rdmsrl(event->hw.event_base, new_raw_count); - - if (local64_cmpxchg(&hwc->prev_count, prev_raw_count, - new_raw_count) != prev_raw_count) - goto again; + do { + rdmsrl(event->hw.event_base, new_raw_count); + } while (!local64_try_cmpxchg(&hwc->prev_count, + &prev_raw_count, new_raw_count)); /* * Now we have the new raw value and have updated the prev