From patchwork Tue Oct 3 19:19:05 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: 148036 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2a8e:b0:403:3b70:6f57 with SMTP id in14csp2299899vqb; Tue, 3 Oct 2023 12:19:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH57fOmVrUEYEEOpWM7Gg4cLuhBhCo45I4858tUaY9BghUla8+Oz1ca6lT5yNwpZbVXBRRQ X-Received: by 2002:a05:6808:1446:b0:3ae:26cb:9756 with SMTP id x6-20020a056808144600b003ae26cb9756mr641851oiv.3.1696360776759; Tue, 03 Oct 2023 12:19:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696360776; cv=none; d=google.com; s=arc-20160816; b=oBxUtsXbDPMnX/W+KoadSCa70HTq8pJFztCg2ukAu2bbZwHsnfv/drSdA3bw6eFzyX 0msLgGANR+DEvxC0HD4wq1mXRLZlBbALwxp4yNHinKb+OvwWrRDKoHoM2LJWknFf8L0n lOvmX/K2cqJd2ujiNTWrRkY8CMkiomV1VQi4Q5fSC6qKoCZNF55vbP/qTG4fOsNqZSZx lRkM1lMXaDRCRM7NfCVaESdsGdYra+MNWtBBdLCOteMCG3/CcQfLEukv4MCY88gTmO9E CktEVQZXbsHjrkJnyZaug16+iC5+HgNdMzzLd/B+PirFOjRyKj/MWdGRYW/j5gbLECqf 2lww== 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=vXwvdKEZsex1mUoiT3XttWgQj+pJN6iq2V/O4MOUH1I=; fh=uYmKPeV7trB4++Gfynlrb2b7CUiIMjAO75XF4cOkgXw=; b=NfylsYmWjmH7tJCcKFMvxIJwsWbKss4b7OU2bOmH1OIOpBrWPMIoSmScJZFkX6paO3 GF+a8/5aZw+e+MXxwaIbthaAk+oPxxBQ7ToAYwoI/qoOXYgyJ2i8Fp/A/cM9LpM2Byxh KQnQOtOfKNgtYkN3w4oNJqYueQDypsyZV7+KCBEKZVqpx1napc4blohsILH5U+KeBTGZ N+e4ii4J2T5JD+FL5yR1dgfYBZzeFVzwOODGe4xJjPjKiGOFMeDRTN3S4eNzsrZ//sWg Pb5iqJH95LJPac8+XYDvd9G1cz+mauIidiicoOG1o7zdb3cS/CKH34vmj/OpYUhCEM9m 3pPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=FUxtqVW8; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id q29-20020a63751d000000b00584e52f3ee9si2128226pgc.61.2023.10.03.12.19.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 12:19:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=FUxtqVW8; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (Postfix) with ESMTP id D986D818C7B5; Tue, 3 Oct 2023 12:19:26 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240900AbjJCTTM (ORCPT + 17 others); Tue, 3 Oct 2023 15:19:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33538 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230239AbjJCTTL (ORCPT ); Tue, 3 Oct 2023 15:19:11 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A0759E; Tue, 3 Oct 2023 12:19:08 -0700 (PDT) Date: Tue, 03 Oct 2023 19:19:05 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1696360746; 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=vXwvdKEZsex1mUoiT3XttWgQj+pJN6iq2V/O4MOUH1I=; b=FUxtqVW8OwpMOV8Ywim0HCwzrO6/sb/8hP3enKsQn9QkZhuTQzR+ci9of6smeIDYtvVmDr 9TOIGWRNlMlToaGAzZahrVSznPSWUUQk/yXJwOUbDmdpNHq55bRf/v6EpiAUYJBVMv5wbx sX44BhGWeHGTbzqV8wiDa3eslY+9KGVdAxvBFgGsHHEYBGkmuKvACId8HtLl0U3aKEj16w L3x0wfs7doDdlAKq861bKJ7nTcm3hxZ+ut4XMcL4rSR2D3WB3rm3W8d/DLo+Kzw2sB3JS1 7kYmRzdguc/OQk7BsG/N8yl5EZUdqUAC+Dulhn2wmTWhKod04HVYB5B9b+1GLw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1696360746; 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=vXwvdKEZsex1mUoiT3XttWgQj+pJN6iq2V/O4MOUH1I=; b=9fdDZ6GSljP3XkgxfSA43gwqQi42+Oaae0fwYXfLK2Tz78sS8/L/bbJja9dGmyWpG0FZhZ nTcQ3SCKfQa+iIBg== 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 , Peter Zijlstra , Linus Torvalds , "H. Peter Anvin" , 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: <169636074590.3135.6268444567676526920.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email 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 (agentk.vger.email [0.0.0.0]); Tue, 03 Oct 2023 12:19:26 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778719590714079533 X-GMAIL-MSGID: 1778763197846504223 The following commit has been merged into the perf/core branch of tip: Commit-ID: bcc6ec3d954bbcc8bec34a21c05ea536a2e96d6f Gitweb: https://git.kernel.org/tip/bcc6ec3d954bbcc8bec34a21c05ea536a2e96d6f Author: Uros Bizjak AuthorDate: Mon, 07 Aug 2023 16:51:15 +02:00 Committer: Ingo Molnar CommitterDate: Tue, 03 Oct 2023 21:13:45 +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 Cc: Peter Zijlstra Cc: Linus Torvalds Cc: "H. Peter Anvin" Link: https://lore.kernel.org/r/20230807145134.3176-2-ubizjak@gmail.com --- 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