Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp1129188pxb; Fri, 1 Oct 2021 04:16:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwDBJaoz1PJBssuIBumdKlp/rPWtClqM+Tpe3q3GU0KbYz1akXqBSS3IdleegRoQiEHrH2a X-Received: by 2002:a63:7405:: with SMTP id p5mr9181048pgc.426.1633087000637; Fri, 01 Oct 2021 04:16:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633087000; cv=none; d=google.com; s=arc-20160816; b=pblDZSHT+kQGPr4TTq+j/3dONB7EXFoOeX3U7vIYrjGRDysEy+NZ4kAOm8Ak5NhQRh 9UB9S/xZMNWnetx/qBtZVZesDRw7sBKmDL5GlP05wyyPGqGxfhae8gqw3xIZdaq2o5jD 4ABg/v7vc6OTczVIyuBURac6I4UL7lDA76mA4/rWXBV38/pJhDrx4gfcxpBWfi4nlGBQ c5WEY5thkXivMQVI2EZ5mouIk1/Iv3q07Rzg8dAiknI4PuDtvSdC/7CQOYLe9ylKlVb/ 9CzPgVxrvBQSPnO/YfFO6A+kgWSylPuNKGdFwNIiufJHTucbUWzqPytqIWFF8wk5NDEP QGAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=FttHKMTVGyyZPi4Jt0sv3xNaWOnGQdWbdqCHGfqQouQ=; b=IXmetj9e4qH8FfwB+uZCLNu/OfJ8lJ74WiLWBShVUWoHYvi0s8yAJwL4T+gwyXxy4m PNK+jG5z/+dFWG3qrYSCTHBX9FdeGJVq/hRhUuW7IG82M9TNq331WiP2xzzwbJmK0oae OXSFhQbg1P81UL6t7EQkk+gckHXTVeCAMhNsPDi3oZm1gtYy7DSamM7yqADglNIT6tly Erjge0+vszMcnPjNCMlpPcCrvlopihQLvyRHqbOG46eBH62HhM6Res5MV3vWgx4UVpqA 09mXQF+SQFKdzFn8Cs2AMTpGZZtWDRQB41K8SRbMpBJmelLGCm9g8JlWRH4LqXnOjsWV 3GVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=TT+sxVM4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u15si8687440pjr.51.2021.10.01.04.16.27; Fri, 01 Oct 2021 04:16:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=TT+sxVM4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353677AbhJAK5x (ORCPT + 99 others); Fri, 1 Oct 2021 06:57:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353638AbhJAK5v (ORCPT ); Fri, 1 Oct 2021 06:57:51 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A199C061775; Fri, 1 Oct 2021 03:56:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=FttHKMTVGyyZPi4Jt0sv3xNaWOnGQdWbdqCHGfqQouQ=; b=TT+sxVM4XpJSscjBpvUdqUryAS 03PJVNo8feago5dc2kzACRWXmvgpHivnweO8ab76ZWvv0LhgrDm0G6LTuavZQIiJXTMuVZhEMURNx kNwGy8ELbMEAleQr19XnVjZXzhNpm2pHVcaxFPl5n2VHgXVVHqUvDjnUZ+q9PEL2QEt/FsIgyYJJy m5/bC4Asrz/y6p4KIXMLy5nS/+tm4Aa/BIDe2lbuOEF7GbvxtLND2rbxW2kWF4qDUD3AuWLzRxWEe EdW4hftCDlzP4JVt5x8swVwmdyitw+mUVxkoWpbJsD/bLw7tQrlqyvvx+ODFI+SJMaYqHpGwVv0TB 9UyLHgcg==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1mWG9s-00Dmoc-A5; Fri, 01 Oct 2021 10:53:14 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id C94D7300299; Fri, 1 Oct 2021 12:52:49 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 6ACD626717AC6; Fri, 1 Oct 2021 12:52:49 +0200 (CEST) Date: Fri, 1 Oct 2021 12:52:49 +0200 From: Peter Zijlstra To: Huacai Chen Cc: Arnd Bergmann , Andy Lutomirski , Thomas Gleixner , Andrew Morton , David Airlie , Jonathan Corbet , Linus Torvalds , linux-arch@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Xuefeng Li , Yanteng Si , Huacai Chen , Jiaxun Yang Subject: Re: [PATCH V4 07/22] LoongArch: Add atomic/locking headers Message-ID: References: <20210927064300.624279-1-chenhuacai@loongson.cn> <20210927064300.624279-8-chenhuacai@loongson.cn> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210927064300.624279-8-chenhuacai@loongson.cn> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Sep 27, 2021 at 02:42:44PM +0800, Huacai Chen wrote: > diff --git a/arch/loongarch/include/asm/bitops.h b/arch/loongarch/include/asm/bitops.h > new file mode 100644 > index 000000000000..8b05d9683571 > --- /dev/null > +++ b/arch/loongarch/include/asm/bitops.h > @@ -0,0 +1,220 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +/* > + * Copyright (C) 2020-2021 Loongson Technology Corporation Limited > + */ > +#ifndef _ASM_BITOPS_H > +#define _ASM_BITOPS_H > + > +#ifndef _LINUX_BITOPS_H > +#error only can be included directly > +#endif > + > +#include > +#include > +#include > +#include > +#include > +#include > + > +#if _LOONGARCH_SZLONG == 32 > +#define __LL "ll.w " > +#define __SC "sc.w " > +#define __AMADD "amadd.w " > +#define __AMAND_SYNC "amand_db.w " > +#define __AMOR_SYNC "amor_db.w " > +#define __AMXOR_SYNC "amxor_db.w " > +#elif _LOONGARCH_SZLONG == 64 > +#define __LL "ll.d " > +#define __SC "sc.d " > +#define __AMADD "amadd.d " > +#define __AMAND_SYNC "amand_db.d " > +#define __AMOR_SYNC "amor_db.d " > +#define __AMXOR_SYNC "amxor_db.d " > +#endif > + > +/* > + * set_bit - Atomically set a bit in memory > + * @nr: the bit to set > + * @addr: the address to start counting from > + */ > +static inline void set_bit(unsigned long nr, volatile unsigned long *addr) > +{ > + int bit = nr % BITS_PER_LONG; > + volatile unsigned long *m = &addr[BIT_WORD(nr)]; > + > + __asm__ __volatile__( > + " " __AMOR_SYNC "$zero, %1, %0 \n" > + : "+ZB" (*m) > + : "r" (1UL << bit) > + : "memory"); > +} > + > +/* > + * clear_bit - Clears a bit in memory > + * @nr: Bit to clear > + * @addr: Address to start counting from > + */ > +static inline void clear_bit(unsigned long nr, volatile unsigned long *addr) > +{ > + int bit = nr % BITS_PER_LONG; > + volatile unsigned long *m = &addr[BIT_WORD(nr)]; > + > + __asm__ __volatile__( > + " " __AMAND_SYNC "$zero, %1, %0 \n" > + : "+ZB" (*m) > + : "r" (~(1UL << bit)) > + : "memory"); > +} > + > +/* > + * clear_bit_unlock - Clears a bit in memory > + * @nr: Bit to clear > + * @addr: Address to start counting from > + */ > +static inline void clear_bit_unlock(unsigned long nr, volatile unsigned long *addr) > +{ > + clear_bit(nr, addr); > +} > + > +/* > + * change_bit - Toggle a bit in memory > + * @nr: Bit to change > + * @addr: Address to start counting from > + */ > +static inline void change_bit(unsigned long nr, volatile unsigned long *addr) > +{ > + int bit = nr % BITS_PER_LONG; > + volatile unsigned long *m = &addr[BIT_WORD(nr)]; > + > + __asm__ __volatile__( > + " " __AMXOR_SYNC "$zero, %1, %0 \n" > + : "+ZB" (*m) > + : "r" (1UL << bit) > + : "memory"); > +} > + > +/* > + * test_and_set_bit - Set a bit and return its old value > + * @nr: Bit to set > + * @addr: Address to count from > + */ > +static inline int test_and_set_bit(unsigned long nr, > + volatile unsigned long *addr) > +{ > + int bit = nr % BITS_PER_LONG; > + unsigned long res; > + volatile unsigned long *m = &addr[BIT_WORD(nr)]; > + > + __asm__ __volatile__( > + " " __AMOR_SYNC "%1, %2, %0 \n" > + : "+ZB" (*m), "=&r" (res) > + : "r" (1UL << bit) > + : "memory"); > + > + res = res & (1UL << bit); > + > + return res != 0; > +} > + > +/* > + * test_and_set_bit_lock - Set a bit and return its old value > + * @nr: Bit to set > + * @addr: Address to count from > + */ > +static inline int test_and_set_bit_lock(unsigned long nr, > + volatile unsigned long *addr) > +{ > + int bit = nr % BITS_PER_LONG; > + unsigned long res; > + volatile unsigned long *m = &addr[BIT_WORD(nr)]; > + > + __asm__ __volatile__( > + " " __AMOR_SYNC "%1, %2, %0 \n" > + : "+ZB" (*m), "=&r" (res) > + : "r" (1UL << bit) > + : "memory"); > + > + res = res & (1UL << bit); > + > + return res != 0; > +} > +/* > + * test_and_clear_bit - Clear a bit and return its old value > + * @nr: Bit to clear > + * @addr: Address to count from > + */ > +static inline int test_and_clear_bit(unsigned long nr, > + volatile unsigned long *addr) > +{ > + int bit = nr % BITS_PER_LONG; > + unsigned long res, temp; > + volatile unsigned long *m = &addr[BIT_WORD(nr)]; > + > + __asm__ __volatile__( > + " " __AMAND_SYNC "%1, %2, %0 \n" > + : "+ZB" (*m), "=&r" (temp) > + : "r" (~(1UL << bit)) > + : "memory"); > + > + res = temp & (1UL << bit); > + > + return res != 0; > +} > + > +/* > + * test_and_change_bit - Change a bit and return its old value > + * @nr: Bit to change > + * @addr: Address to count from > + */ > +static inline int test_and_change_bit(unsigned long nr, > + volatile unsigned long *addr) > +{ > + int bit = nr % BITS_PER_LONG; > + unsigned long res; > + volatile unsigned long *m = &addr[BIT_WORD(nr)]; > + > + __asm__ __volatile__( > + " " __AMXOR_SYNC "%1, %2, %0 \n" > + : "+ZB" (*m), "=&r" (res) > + : "r" (1UL << bit) > + : "memory"); > + > + res = res & (1UL << bit); > + > + return res != 0; > +} Why is asm-generic/bitops/atomic.h not working for you?