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 mail.librecores.org (lists.librecores.org [88.198.125.70]) by smtp.lore.kernel.org (Postfix) with ESMTP id 761F3C4332F for ; Thu, 22 Dec 2022 14:12:37 +0000 (UTC) Received: from [172.31.1.100] (localhost.localdomain [127.0.0.1]) by mail.librecores.org (Postfix) with ESMTP id 3D3AC24A0D; Thu, 22 Dec 2022 15:12:36 +0100 (CET) Received: from mail-yw1-f182.google.com (mail-yw1-f182.google.com [209.85.128.182]) by mail.librecores.org (Postfix) with ESMTPS id 15F7C25C18 for ; Thu, 22 Dec 2022 15:12:34 +0100 (CET) Received: by mail-yw1-f182.google.com with SMTP id 00721157ae682-3e45d25de97so28231127b3.6 for ; Thu, 22 Dec 2022 06:12:34 -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=C6L0zTNspbLFPhRHzR1lsNbmL9IzKRDDs7M1jeG+6oVYqWwrRb5RWqyLaHS7SVdApP t/hgCIHGhUriHSKrP3xP5AVcVkD8SdZwvd6Ntcem2m50s5yksckvu8y+AWWghfwq2YDi R2z44Zh6dWs9tdIJixaJQsaQnMda7saTWD3BMgGGGYeVwzx1X7/Fl8193UomKq/NSQ6o d7LsCEvxv2SELRIPFqnd8O8uAEWDlZ1AB3joNKMtOnbOUFOkADpApak73BAAUU9vj5GP KEVAV8nD3rDwa2zb5VinA+IWFdFVgxIMB1OE6xUHzfcsxxr+P/n47j50kTzERuKf1Tzy g8Ag== X-Gm-Message-State: AFqh2krwoxo1fKTW2TJTFsVHByM2J0YRW22Kje+CFCS8pOle8NUHquFL exkF42n/9YNXfQQVzLG5dRFV3I8lVYYL5Q== X-Google-Smtp-Source: AMrXdXsnZvdviKQyLOxpTz8KipdUUQAw4qzjko/WVU5uX0rfhkU0oO+m5s8SR5G4ZvN+q597/6TOFA== X-Received: by 2002:a05:7500:2b92:b0:ea:4bf3:b1cf with SMTP id dr18-20020a0575002b9200b000ea4bf3b1cfmr331350gab.18.1671718352585; Thu, 22 Dec 2022 06:12:32 -0800 (PST) Received: from mail-yb1-f176.google.com (mail-yb1-f176.google.com. [209.85.219.176]) by smtp.gmail.com with ESMTPSA id bj11-20020a05620a190b00b006fa2cc1b0fbsm376765qkb.11.2022.12.22.06.12.31 for (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-f176.google.com with SMTP id 186so2068429ybe.8 for ; 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 Content-Type: text/plain; charset="UTF-8" X-BeenThere: openrisc@lists.librecores.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: Discussion around the OpenRISC processor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , linux-ia64@vger.kernel.org, linux-sh@vger.kernel.org, Peter Zijlstra , dri-devel@lists.freedesktop.org, linux-mips@vger.kernel.org, sparclinux@vger.kernel.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, linux-hexagon@vger.kernel.org, linux-snps-arc@lists.infradead.org, Boqun Feng , linux-xtensa@linux-xtensa.org, Arnd Bergmann , intel-gfx@lists.freedesktop.org, linux-m68k@lists.linux-m68k.org, openrisc@lists.librecores.org, loongarch@lists.linux.dev, Rodrigo Vivi , Andy Shevchenko , linux-arm-kernel@lists.infradead.org, linux-parisc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-alpha@vger.kernel.org, Andrew Morton , linuxppc-dev@lists.ozlabs.org Errors-To: openrisc-bounces@lists.librecores.org Sender: "OpenRISC" 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