From patchwork Mon Jul 10 08:37:50 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: 117725 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp4884268vqx; Mon, 10 Jul 2023 02:03:39 -0700 (PDT) X-Google-Smtp-Source: APBJJlHSkmvn9FzRZMB7+ji7yi3oE4jFkYHAVf6AF/Z0aGNYLKsMp4lK40v0FhOpFvRDrllwpotL X-Received: by 2002:a17:906:943:b0:992:a9ba:b8da with SMTP id j3-20020a170906094300b00992a9bab8damr9707553ejd.70.1688979819609; Mon, 10 Jul 2023 02:03:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688979819; cv=none; d=google.com; s=arc-20160816; b=VxgwJhYretIgy5IpwZsmp8vv6nM4OjMbN/SHyndSWev4sNgY0Q8CqAogyRCp8qipbq 7J/zi4LLaXPIH6SU5qe9tQxhqVtpmzx2qSgRHmN6nj6iiidmQoGde6untZqJUWXrPYnV VvfUuCLAj5VsiZYdaDfnoBtmQJdJs1CK0UnEuMgny56s4CRgcT+3YwomZP2cgAhEyXKt jtDKZwdIofECI2XHrKvxVNccSuVsTEiKBVGsg3BwXe3FpwHN7vHKoe+zSdQsvxK0b/Jj NsKMFj1pqigCX5D4Y3fqb79srd/pnHQKbLnSK0GGA/yncn2mHv8iZQDu8AdevfylTXSn wmZA== 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=ilamyJDbICYtSDb02PIB2zgJt9yweTD8M1ng84MwQtQ=; fh=xq/itMik7sD2N21hAjPsxS2W8lfiEdnTRVa62bPv3f4=; b=JNTpsGzK24CxljUMAWp/YqC3DBR6QxOrUstYiLzH+F4/hk5stVTaymYZN8IQM6ow4g 8D75X6plZxnDOEiXXQkL3gY6SVnQv2bmqSYHGYBQeqT41rBLlpJsApLuGoMsJUj3NfPW KYqAPBY419CovQvEqmv6d5ZcSkFCQ2yzpB+BiAgXn1K2imUx1kCwNYeKsNoeg9XeJdHV sUAEVA7ZnU5m7IZC9J8caT/S0hseP4rtaPD1kFdefdrf2cmxtDWVxGVVtRPLTV7p1xXg PAeiI/zw6F4FYwqKfUzG8hdrqA7QOoYoqyuCDovsAM6/Hy4fg8dufWULoBUZjJAUtkA3 vgiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=yvC0+IPH; dkim=neutral (no key) header.i=@linutronix.de header.b=AtiqU7oQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k9-20020a1709063e0900b009920612b89asi6107171eji.351.2023.07.10.02.03.15; Mon, 10 Jul 2023 02:03:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=yvC0+IPH; dkim=neutral (no key) header.i=@linutronix.de header.b=AtiqU7oQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231226AbjGJIiM (ORCPT + 99 others); Mon, 10 Jul 2023 04:38:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51326 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230298AbjGJIhx (ORCPT ); Mon, 10 Jul 2023 04:37:53 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7DC6DC3; Mon, 10 Jul 2023 01:37:52 -0700 (PDT) Date: Mon, 10 Jul 2023 08:37:50 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1688978271; 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=ilamyJDbICYtSDb02PIB2zgJt9yweTD8M1ng84MwQtQ=; b=yvC0+IPHasmDZAPNA/tb0hmOSfp/3yyOH4FFI8TPzUkrkomA6ew0odlx8y9qf6aZzPnjUR xdRHtaE/YuldyorlD5vcipUXK/FcsdKy4YNW/mqJpSeVvg3ibcXvU/V9dEorv5t3B0CRU4 BIUokeaIxmBcEHjgKepNpYYmSxAPONrqrNwTfhKqA9YAE2g8MaqlPUvacqL5IlDkXetfdd qBuYTmh/B4cBJQx4CX0tTJ7hKrnyy78f9xdvSwNifipK0CONopMDBdkBqKZAnuM9Dz9mkM XlNdhvvpvELX5OnigvsU3l3NB96ERbFwduEDQSoSTkbtbuWzLPOOjhHOfFqiWw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1688978271; 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=ilamyJDbICYtSDb02PIB2zgJt9yweTD8M1ng84MwQtQ=; b=AtiqU7oQOKOd+xFWe3ucgcLxmVux0idjwNTHPEyjZhlikqzfphk/giRBlHB0g0zH0zqrFf 847qAlusQXOm4hDg== 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/ring_buffer: Use local_try_cmpxchg in __perf_output_begin Cc: Uros Bizjak , "Peter Zijlstra (Intel)" , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20230708090048.63046-2-ubizjak@gmail.com> References: <20230708090048.63046-2-ubizjak@gmail.com> MIME-Version: 1.0 Message-ID: <168897827031.404.10627731369793852895.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,T_SCC_BODY_TEXT_LINE 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-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1770843789776581896 X-GMAIL-MSGID: 1771023703747952896 The following commit has been merged into the perf/core branch of tip: Commit-ID: 1af61adb3a23192023fec1733bd4c8500f53e546 Gitweb: https://git.kernel.org/tip/1af61adb3a23192023fec1733bd4c8500f53e546 Author: Uros Bizjak AuthorDate: Sat, 08 Jul 2023 11:00:37 +02:00 Committer: Peter Zijlstra CommitterDate: Mon, 10 Jul 2023 09:52:36 +02:00 perf/ring_buffer: Use local_try_cmpxchg in __perf_output_begin Use local_try_cmpxchg instead of local_cmpxchg (*ptr, old, new) == old in __perf_output_begin. 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: Peter Zijlstra (Intel) Link: https://lkml.kernel.org/r/20230708090048.63046-2-ubizjak@gmail.com --- kernel/events/ring_buffer.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/kernel/events/ring_buffer.c b/kernel/events/ring_buffer.c index a0433f3..fb1e180 100644 --- a/kernel/events/ring_buffer.c +++ b/kernel/events/ring_buffer.c @@ -191,9 +191,10 @@ __perf_output_begin(struct perf_output_handle *handle, perf_output_get_handle(handle); + offset = local_read(&rb->head); do { + head = offset; tail = READ_ONCE(rb->user_page->data_tail); - offset = head = local_read(&rb->head); if (!rb->overwrite) { if (unlikely(!ring_buffer_has_space(head, tail, perf_data_size(rb), @@ -217,7 +218,7 @@ __perf_output_begin(struct perf_output_handle *handle, head += size; else head -= size; - } while (local_cmpxchg(&rb->head, offset, head) != offset); + } while (!local_try_cmpxchg(&rb->head, &offset, head)); if (backward) { offset = head;