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 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 36F4AC4332F for ; Thu, 22 Dec 2022 14:32:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:Subject:Message-ID:Date:From: In-Reply-To:References:MIME-Version:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=x2rnRgwq7nCeUtLa0OWgN+eFm+eBKO4HyqiOfyQKX7s=; b=T1ZuAdWJlAa/pg Y9MrfWJClUHoWsHqEm0LRmVRvLUcIe/K4bplEocuvVRJQ2EF/c5YpdShOgu/SMS/HT2Mtkh6p64Lg c4xjUFcn+Hw+aiR2NHgA3HpYuyNzg7r0MFKsAGbw5nWBTLKn/rRArF8eZHDlV9krvXyB0YGEyhRbD 7z5e7fjiYW+imeooTcAErr3uD9pRa/r+HctW8eGChaYCKaDgK8hlyvc/Mo2TJ+DMjVMuh9kv0V6KE pG4fMiZal9JUl0pKLhJ8950IHYhexyb9jRZFzFE7fN4rPOJQS5QCsp1IGU8MdT6QdNhDJCuYk2tDA P2kB/WcoDYW4aAQUZsXw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1p8Mcg-00D0BL-8T; Thu, 22 Dec 2022 14:32:38 +0000 Received: from mail-yw1-f170.google.com ([209.85.128.170]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1p8MJH-00Cp3d-PQ; Thu, 22 Dec 2022 14:12:38 +0000 Received: by mail-yw1-f170.google.com with SMTP id 00721157ae682-3b56782b3f6so27832347b3.13; Thu, 22 Dec 2022 06:12:32 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=DaSeJ7b4XoTWS2Tt6rTxmu6n/STTyq8+F8PwIAXlFPg=; b=EP2netqO83SeCjpen4/V7aw5M+ZzVyMVBdVCpQzkJIYfLqea+yDV+SVBo1XFhjq63H HeNnkVz8ZQna4ttoytGXAS3KFyjXM4XgVT3W0cIpBtAMrz3E2P08+invk0Hdr4p9DULX kYolAPiLa6svS8vWSVxNzd2qOysieFEK4jkdHejO9o2dTNz8a8lyOpn5AKUybnkqw3Mt iCpntaJgdNDf9Vru3KaDLQ/azhEf7ci/XVTnHHSRl7bO0m1kdrF2r8t7ar2+2fRFcPoi JYpWlpLk8w3zu3qkFG2bnjEUOOyuyGPgj2gC/tKV89eWceIod04nD9BBGkYoUi7T94vz RxuA== X-Gm-Message-State: AFqh2kqEx7HqU9dipuFPuaFD3j65csJIT0Jko3I9iy4XdW8nuW9TJEzC x9o4R6JjDUdtB7U+JK0CX3RJpWd7J4OADQ== X-Google-Smtp-Source: AMrXdXvLYBI+JMO+Wm3kqdXfh5rVa0X+ZxkBSP1FYS2fmdiNHM6HKT+AtvVTO0ybMXQ/qxneMFQW/w== X-Received: by 2002:a05:7500:b8e:b0:ea:6282:47fb with SMTP id fx14-20020a0575000b8e00b000ea628247fbmr372784gab.63.1671718351806; Thu, 22 Dec 2022 06:12:31 -0800 (PST) Received: from mail-yb1-f170.google.com (mail-yb1-f170.google.com. [209.85.219.170]) by smtp.gmail.com with ESMTPSA id y1-20020a37f601000000b006cbe3be300esm359758qkj.12.2022.12.22.06.12.31 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 22 Dec 2022 06:12:31 -0800 (PST) Received: by mail-yb1-f170.google.com with SMTP id j206so2097170ybj.1; Thu, 22 Dec 2022 06:12:31 -0800 (PST) X-Received: by 2002:a25:d243:0:b0:702:90b4:2e24 with SMTP id j64-20020a25d243000000b0070290b42e24mr417369ybg.365.1671718351056; Thu, 22 Dec 2022 06:12:31 -0800 (PST) MIME-Version: 1.0 References: <20221222114635.1251934-1-andrzej.hajda@intel.com> In-Reply-To: <20221222114635.1251934-1-andrzej.hajda@intel.com> From: Geert Uytterhoeven Date: Thu, 22 Dec 2022 15:12:19 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 00/19] Introduce __xchg, non-atomic xchg To: Andrzej Hajda Cc: linux-alpha@vger.kernel.org, linux-kernel@vger.kernel.org, linux-snps-arc@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-hexagon@vger.kernel.org, linux-ia64@vger.kernel.org, loongarch@lists.linux.dev, linux-m68k@lists.linux-m68k.org, linux-mips@vger.kernel.org, openrisc@lists.librecores.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, sparclinux@vger.kernel.org, linux-xtensa@linux-xtensa.org, intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, Arnd Bergmann , Rodrigo Vivi , Andrew Morton , Andy Shevchenko , Peter Zijlstra , Boqun Feng , Mark Rutland X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221222_061236_058556_0FC2DAE6 X-CRM114-Status: GOOD ( 26.82 ) X-BeenThere: linux-snps-arc@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux on Synopsys ARC Processors List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-snps-arc" Errors-To: linux-snps-arc-bounces+linux-snps-arc=archiver.kernel.org@lists.infradead.org Hi Andrzej, Thanks for your series! On Thu, Dec 22, 2022 at 12:49 PM Andrzej Hajda wrote: > I hope there will be place for such tiny helper in kernel. > Quick cocci analyze shows there is probably few thousands places > where it could be useful. > I am not sure who is good person to review/ack such patches, > so I've used my intuition to construct to/cc lists, sorry for mistakes. > This is the 2nd approach of the same idea, with comments addressed[0]. > > The helper is tiny and there are advices we can leave without it, so > I want to present few arguments why it would be good to have it: > > 1. Code readability/simplification/number of lines: > > Real example from drivers/net/ethernet/mellanox/mlx5/core/esw/qos.c: > - previous_min_rate = evport->qos.min_rate; > - evport->qos.min_rate = min_rate; > + previous_min_rate = __xchg(evport->qos.min_rate, min_rate); Upon closer look, shouldn't that be previous_min_rate = __xchg(&evport->qos.min_rate, min_rate); ? > For sure the code is more compact, and IMHO more readable. > > 2. Presence of similar helpers in other somehow related languages/libs: > > a) Rust[1]: 'replace' from std::mem module, there is also 'take' > helper (__xchg(&x, 0)), which is the same as private helper in > i915 - fetch_and_zero, see latest patch. > b) C++ [2]: 'exchange' from utility header. > > If the idea is OK there are still 2 qestions to answer: > > 1. Name of the helper, __xchg follows kernel conventions, > but for me Rust names are also OK. Before I realized the missing "&", I wondered how this is different from swap(), so naming is important. https://elixir.bootlin.com/linux/latest/source/include/linux/minmax.h#L139 Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds _______________________________________________ linux-snps-arc mailing list linux-snps-arc@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-snps-arc