From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 563BFC433E0 for ; Wed, 17 Mar 2021 13:44:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0200564F50 for ; Wed, 17 Mar 2021 13:44:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231313AbhCQNni (ORCPT ); Wed, 17 Mar 2021 09:43:38 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:26075 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231340AbhCQNn2 (ORCPT ); Wed, 17 Mar 2021 09:43:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615988608; h=from:from: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=J6W2NAAyf0FpcLn99G024NFc9PBWLRHCwNHkA7HcE9I=; b=fIvYRH8zZswK5Q4HWLQcbGi+2+k3jZxoHdSkth+b0Nc/qQi6NNSdF7djXaH9Hxdaf6QMR6 QVjtfdiM2g1W2LAr019AQQEYTfLn/B79FoECU77C8RZkCx+4YqRfO8Ck8YiX/R6opdi9TE EgV81bzqr7LRlJtqQJCKky2dIm4ucKU= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-12-ceukJS8bOdiaPWc7vaRhjg-1; Wed, 17 Mar 2021 09:43:23 -0400 X-MC-Unique: ceukJS8bOdiaPWc7vaRhjg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6CF27108BD08; Wed, 17 Mar 2021 13:43:21 +0000 (UTC) Received: from llong.remote.csb (ovpn-117-171.rdu2.redhat.com [10.10.117.171]) by smtp.corp.redhat.com (Postfix) with ESMTP id C2319610F1; Wed, 17 Mar 2021 13:43:20 +0000 (UTC) Subject: Re: [tip: locking/urgent] locking/ww_mutex: Simplify use_ww_ctx & ww_ctx handling To: Peter Zijlstra , linux-kernel@vger.kernel.org Cc: linux-tip-commits@vger.kernel.org, Ingo Molnar , Davidlohr Bueso , x86@kernel.org References: <20210316153119.13802-2-longman@redhat.com> <161598470257.398.5006518584847290113.tip-bot2@tip-bot2> From: Waiman Long Organization: Red Hat Message-ID: <85fbce04-c544-6041-6e7d-76f47b90e263@redhat.com> Date: Wed, 17 Mar 2021 09:43:20 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 3/17/21 8:59 AM, Peter Zijlstra wrote: > On Wed, Mar 17, 2021 at 12:38:22PM -0000, tip-bot2 for Waiman Long wrote: >> The following commit has been merged into the locking/urgent branch of tip: >> >> Commit-ID: 5de2055d31ea88fd9ae9709ac95c372a505a60fa >> Gitweb: https://git.kernel.org/tip/5de2055d31ea88fd9ae9709ac95c372a505a60fa >> Author: Waiman Long >> AuthorDate: Tue, 16 Mar 2021 11:31:16 -04:00 >> Committer: Ingo Molnar >> CommitterDate: Wed, 17 Mar 2021 09:56:44 +01:00 >> >> locking/ww_mutex: Simplify use_ww_ctx & ww_ctx handling >> >> The use_ww_ctx flag is passed to mutex_optimistic_spin(), but the >> function doesn't use it. The frequent use of the (use_ww_ctx && ww_ctx) >> combination is repetitive. >> >> In fact, ww_ctx should not be used at all if !use_ww_ctx. Simplify >> ww_mutex code by dropping use_ww_ctx from mutex_optimistic_spin() an >> clear ww_ctx if !use_ww_ctx. In this way, we can replace (use_ww_ctx && >> ww_ctx) by just (ww_ctx). > The reason this code was like this is because GCC could constant > propagage use_ww_ctx but could not do the same for ww_ctx (since that's > external). > > Please double check generated code to make sure you've not introduced a > bunch of extra branches. > I see, but this patch just replaces (use_ww_ctx && ww_ctx) by (ww_ctx). Even if constant propagation isn't happening for ww_ctx, gcc shouldn't generate any worse code wrt ww_ctx. It could be that the generated machine code are more or less the same, but the source code will look cleaner with just one variable in the conditional clauses. Using gcc 8.4.1, the generated __mutex_lock function has the same size (with last instruction at offset +5179) with or without this patch. Well, you can say that this patch is an no-op wrt generated code. Cheers, Longman