Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp2410426ioo; Sat, 28 May 2022 12:44:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz+stJuLj+IpTChrVHxYgz90CjkVZ6nm5ybAsZKu01uP7gXC9ZDdjEkR9xyXHA0qp7sS+xy X-Received: by 2002:a17:90b:1482:b0:1df:5b39:8a4 with SMTP id js2-20020a17090b148200b001df5b3908a4mr14853455pjb.233.1653767076213; Sat, 28 May 2022 12:44:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653767076; cv=none; d=google.com; s=arc-20160816; b=pxyh/mS1W8Htg44bE8xpYq+t+X5Ct/T38kylP68ZIhm6lqS3g7vyszAfSEFhN/30l4 kdDb+iYv52FmdLCUaKbVwZUUIj7oqUmGReaKipHwE4lQe2+EDIgZsdPiy+YAokhWl8pi wMfOHDV+8vm1XQFootvwZiO8HAjepwigs4WIHQS49knaqaGamROhLOB0/puyr7aCHEpX hmoO/uugN5QLWDCyR7nM6c9yd7jTuZpcHhhrYV4+EYGrGBHvOMy854nxpy88vEu0AlwS 6S8WO2GJmmG9uiu+60d4milcQgTER5pAHjmB/O9+R6wd0+ZxlNGgX1zhv0pzI3simkkp Aafw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=F4isnC1WV1H+0V+3lJAgXeygwiC1DgPFe1wzw0Zc3VU=; b=xpPKsApcq8eXD78EgfDonVj+91xL9a0oO8V514MJLNK5dQb5UK0vAzfwSCQJLbY30h cizdCEIQVCc0SlCdva2KcrtydZh4EbtN7qBKlA0GWdjfDh2uQ9EiEBTFjUJs/iL2+qCR b89Rbf4upRzOYZvmayFMzhClpCqyNColxliyQ8Dj7p0loL5WVu92g4h9o9V7FUV0Ce/D PGXXpg4LvuuiN7tfVhKRuBeY1o5cSZZysZzSdFvvmAquLxxzdNx6/axbfMKkHNBAB2sd EvHlhwKHA8VBiorQXQq9KNRnKQX0ruMehiGLw58MFcFutuwpjD5CemER6TBtsvFDLuFo 0nSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=S+ACfIvz; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id k71-20020a63844a000000b003fbec4a05e2si1318785pgd.271.2022.05.28.12.44.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 May 2022 12:44:36 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=S+ACfIvz; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A42E864BD4; Sat, 28 May 2022 12:07:37 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244300AbiEYQsJ (ORCPT + 99 others); Wed, 25 May 2022 12:48:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38418 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234350AbiEYQsH (ORCPT ); Wed, 25 May 2022 12:48:07 -0400 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B481F13F31 for ; Wed, 25 May 2022 09:48:05 -0700 (PDT) Received: by mail-ej1-x636.google.com with SMTP id rs12so31096894ejb.13 for ; Wed, 25 May 2022 09:48:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=F4isnC1WV1H+0V+3lJAgXeygwiC1DgPFe1wzw0Zc3VU=; b=S+ACfIvzcWJjlMglo+Uy8+sLEk2CQ9HbwaLYlmJKrTBKc1vcpsXurnUVhYGBeP0wlU DpyqNHi/aXQ6zRQ1Dc8Y66siU4BdBur2XHOixq7DX2mt1ijDGVtTi6nkFLq+j6sVcWC/ H3eSkQZj85Ekc/wp2KTVDQlAgCQNXgGdCeIK0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=F4isnC1WV1H+0V+3lJAgXeygwiC1DgPFe1wzw0Zc3VU=; b=E+0B4++QEF8+B5UxENhze2bvHvJvpT3zFLW+MH9FQr6khvr8SRLEZGF5aF779auu7T SE8p4g8WGw53Ip+kJ0PWG9dRpbkyN6mNzLv9COTy4yuSMGHNsL5YfVVNznOHBfuB5GmX iOPyft9KXLGqgvopcnpKbpXOEXMl8+3oEyV/lGRgp2P+3czcSfCuDwcyqa+vdePqPUFq OFbslgRWyVhHZwEKGkNyy6l7JOi2GPUmPs2l0E87EsB2a0I2OmNUDMszUSwF/PRRYify EbFitbQltAW5J853f5rztP6iFrpTI9TjTLbPNjgRAhs21oRBh7giyXSHG5BWzeEU5vfR eNDg== X-Gm-Message-State: AOAM533/x3Ibqn8P3q47By42rNAkManloBZ3p2r2dDJ2P61Nj82cq3Gg hMm7m7CMbnTmql1LkXJmJhryV1G2f6kmSDT4 X-Received: by 2002:a17:906:4fd1:b0:6f3:be23:7ad5 with SMTP id i17-20020a1709064fd100b006f3be237ad5mr30079255ejw.264.1653497283917; Wed, 25 May 2022 09:48:03 -0700 (PDT) Received: from mail-wr1-f54.google.com (mail-wr1-f54.google.com. [209.85.221.54]) by smtp.gmail.com with ESMTPSA id kz12-20020a17090777cc00b006fee13caaeasm3379942ejc.190.2022.05.25.09.48.02 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 25 May 2022 09:48:02 -0700 (PDT) Received: by mail-wr1-f54.google.com with SMTP id e2so19316853wrc.1 for ; Wed, 25 May 2022 09:48:02 -0700 (PDT) X-Received: by 2002:a5d:58c2:0:b0:210:1f7:bfa0 with SMTP id o2-20020a5d58c2000000b0021001f7bfa0mr2533912wrf.281.1653497282053; Wed, 25 May 2022 09:48:02 -0700 (PDT) MIME-Version: 1.0 References: <20220525144013.6481-1-ubizjak@gmail.com> <20220525144013.6481-2-ubizjak@gmail.com> In-Reply-To: <20220525144013.6481-2-ubizjak@gmail.com> From: Linus Torvalds Date: Wed, 25 May 2022 09:47:45 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 1/2] locking/lockref: Use try_cmpxchg64 in CMPXCHG_LOOP macro To: Uros Bizjak , Catalin Marinas , Will Deacon , Russell King , Michael Ellerman , Thomas Bogendoerfer , Heiko Carstens Cc: "the arch/x86 maintainers" , Linux Kernel Mailing List , Peter Zijlstra , Thomas Gleixner , Waiman.Long@hp.com, Paul McKenney Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 On Wed, May 25, 2022 at 7:40 AM Uros Bizjak wrote: > > Use try_cmpxchg64 instead of cmpxchg64 in CMPXCHG_LOOP macro. > x86 CMPXCHG instruction returns success in ZF flag, so this > change saves a compare after cmpxchg (and related move instruction > in front of cmpxchg). The main loop of lockref_get improves from: Ack on this one regardless of the 32-bit x86 question. HOWEVER. I'd like other architectures to pipe up too, because I think right now x86 is the only one that implements that "arch_try_cmpxchg()" family of operations natively, and I think the generic fallback for when it is missing might be kind of nasty. Maybe it ends up generating ok code, but it's also possible that it just didn't matter when it was only used in one place in the scheduler. The lockref_get() case can be quite hot under some loads, it would be sad if this made other architectures worse. Anyway, maybe that try_cmpxchg() fallback is fine, and works out well on architectures that use load-locked / store-conditional as-is. But just to verify, I'm adding arm/powerpc/s390/mips people to the cc. See https://lore.kernel.org/all/20220525144013.6481-2-ubizjak@gmail.com/ for the original email and the x86-64 code example. Linus