From nobody Mon Jul 25 21:53:13 2022 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4LsDLd473zz4WtHm; Mon, 25 Jul 2022 21:53:13 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4LsDLd3Ytvz3vn6; Mon, 25 Jul 2022 21:53:13 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1658785993; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=fs4E9zlNR0gsYPAR2oy07IIFoeur3VLHG61nFE9Qaps=; b=Cv1uBpjixfwGgn2j+hpk/ruNYa7jEP8Bxdyx1QOGXmGM+RO7Kfwbrwaeq/s4ce0T7ZxDMD vEjuiBPVn8NZjqM7UyZhOWDc3I6IbDbO+buwq8oW1DA3u73L+jLZHPy8qSsfthou83UK3n 2BTdMPZn5VpxWJ3uhalOm2w24cxdNScUZULnvK3sQIICEVPjodHaV9EX2exZBEZFtqs6YI LwtZ8eQz6GHQVyH/C1Z308jl4h6hwLNCNtXU7tIqfqyZoDoe7vz1nc5V7ML0R/5SkET2Zp XNpxj9u81kAKI6QbLbdnbQOpVTMMabeD4E5b4DVNk01xZlb38s0H91CFOKQAMQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4LsDLd2c04z1CVg; Mon, 25 Jul 2022 21:53:13 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 26PLrDgW070991; Mon, 25 Jul 2022 21:53:13 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 26PLrDE2070990; Mon, 25 Jul 2022 21:53:13 GMT (envelope-from git) Date: Mon, 25 Jul 2022 21:53:13 GMT Message-Id: <202207252153.26PLrDE2070990@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: 30253da1a982 - main - atomic: Add some type checking to plain atomic_load/store helpers List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 30253da1a982285b0ae6e89e22369a61cf9266eb Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1658785993; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=fs4E9zlNR0gsYPAR2oy07IIFoeur3VLHG61nFE9Qaps=; b=XMvg9jkghoAQHP9DARwhM5RP+OLhfNhOqCTmUNoCx2TxfO8hPTq1msotctEPsdSBtezj+X 9lXW0oifFVf26WpcTvOwfRd4m00zxXAhEV4qxsC6pr4aYyALsyLv1ctUe9Foypnmvp6XYA 5VGIuT8MzWsxqeeFR3zS7akdda3NNBOA5pM9bvAolBeFw9+k8CsDNy2Jyn+TmsSBLSSpi0 nbacPfbcolKnO60aAegN9l8794elFSIZ7unXetdNElMxA9WUqhtRHU/++sF7xboVbFJ14+ 7u+MPcgSvV/gjXJUvOpww19T0HFxVv/Lw6SvMXWoUiqLGSnLh71/GzKbRfWNOA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1658785993; a=rsa-sha256; cv=none; b=cntY24fGpOLIx7WuvVYvmnUknkzpcYuOYE2vh7CmqDtaB/1Zij0P86GS0wzKYcEg+pNQfH 2HV0ghO9mkD6JdBcqs6n9c24++YCbvh4fo7F2Mow6dCbGRf+mFWnHb6tf+nkFYprz/P7bS z45oaAQscgx8ih4ERosTAnVoNK+9qpVNlPb9jHwCAWqy2rsdd7l7scdA8YF1MxxuwWMoqr fLLkmv4gPtotWw7mX4rnGFyIAtGZ3YuuQVSdhUmUAyajYYHy0CtiRlIbwEEXiDFYaRutZv mb1x3ULQ9I7mtLH5qN8JtM7F6U7Amk+pvWAdX49gSDT4c8JxoaTYjHD4ORUbCg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=30253da1a982285b0ae6e89e22369a61cf9266eb commit 30253da1a982285b0ae6e89e22369a61cf9266eb Author: Mark Johnston AuthorDate: 2022-07-25 21:48:46 +0000 Commit: Mark Johnston CommitDate: 2022-07-25 21:52:58 +0000 atomic: Add some type checking to plain atomic_load/store helpers Reviewed by: rpokala, mjg, imp, kib MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D35828 --- sys/sys/atomic_common.h | 88 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 66 insertions(+), 22 deletions(-) diff --git a/sys/sys/atomic_common.h b/sys/sys/atomic_common.h index e3969b241a8c..a34198fda88a 100644 --- a/sys/sys/atomic_common.h +++ b/sys/sys/atomic_common.h @@ -36,39 +36,83 @@ #error do not include this header, use machine/atomic.h #endif -#define atomic_load_char(p) (*(volatile u_char *)(p)) -#define atomic_load_short(p) (*(volatile u_short *)(p)) -#define atomic_load_int(p) (*(volatile u_int *)(p)) -#define atomic_load_long(p) (*(volatile u_long *)(p)) -#define atomic_load_ptr(p) (*(volatile __typeof(*p) *)(p)) -#define atomic_load_8(p) (*(volatile uint8_t *)(p)) -#define atomic_load_16(p) (*(volatile uint16_t *)(p)) -#define atomic_load_32(p) (*(volatile uint32_t *)(p)) -#ifdef _LP64 -#define atomic_load_64(p) (*(volatile uint64_t *)(p)) -#endif +#include +#include -#define atomic_store_char(p, v) \ +#define __atomic_load_char_relaxed(p) (*(volatile u_char *)(p)) +#define __atomic_load_short_relaxed(p) (*(volatile u_short *)(p)) +#define __atomic_load_int_relaxed(p) (*(volatile u_int *)(p)) +#define __atomic_load_long_relaxed(p) (*(volatile u_long *)(p)) +#define __atomic_load_8_relaxed(p) (*(volatile uint8_t *)(p)) +#define __atomic_load_16_relaxed(p) (*(volatile uint16_t *)(p)) +#define __atomic_load_32_relaxed(p) (*(volatile uint32_t *)(p)) +#define __atomic_load_64_relaxed(p) (*(volatile uint64_t *)(p)) + +#define __atomic_store_char_relaxed(p, v) \ (*(volatile u_char *)(p) = (u_char)(v)) -#define atomic_store_short(p, v) \ +#define __atomic_store_short_relaxed(p, v) \ (*(volatile u_short *)(p) = (u_short)(v)) -#define atomic_store_int(p, v) \ +#define __atomic_store_int_relaxed(p, v) \ (*(volatile u_int *)(p) = (u_int)(v)) -#define atomic_store_long(p, v) \ +#define __atomic_store_long_relaxed(p, v) \ (*(volatile u_long *)(p) = (u_long)(v)) -#define atomic_store_ptr(p, v) \ - (*(volatile __typeof(*p) *)(p) = (v)) -#define atomic_store_8(p, v) \ +#define __atomic_store_8_relaxed(p, v) \ (*(volatile uint8_t *)(p) = (uint8_t)(v)) -#define atomic_store_16(p, v) \ +#define __atomic_store_16_relaxed(p, v) \ (*(volatile uint16_t *)(p) = (uint16_t)(v)) -#define atomic_store_32(p, v) \ +#define __atomic_store_32_relaxed(p, v) \ (*(volatile uint32_t *)(p) = (uint32_t)(v)) -#ifdef _LP64 -#define atomic_store_64(p, v) \ +#define __atomic_store_64_relaxed(p, v) \ (*(volatile uint64_t *)(p) = (uint64_t)(v)) + +/* + * When _Generic is available, try to provide some type checking. + */ +#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) || \ + __has_extension(c_generic_selections) +#define __atomic_load_generic(p, t, ut, n) \ + _Generic(*(p), \ + t: __atomic_load_ ## n ## _relaxed(p), ut: __atomic_load_ ## n ## _relaxed(p)) +#define __atomic_store_generic(p, v, t, ut, n) \ + _Generic(*(p), \ + t: __atomic_store_ ## n ## _relaxed(p, v), ut: __atomic_store_ ## n ## _relaxed(p, v)) +#else +#define __atomic_load_generic(p, t, ut, n) __atomic_load_ ## n ## _relaxed(p) +#define __atomic_store_generic(p, v, t, ut, n) __atomic_store_ ## n ## _relaxed(p, v) #endif +#define atomic_load_char(p) __atomic_load_generic(p, char, u_char, char) +#define atomic_load_short(p) __atomic_load_generic(p, short, u_short, short) +#define atomic_load_int(p) __atomic_load_generic(p, int, u_int, int) +#define atomic_load_long(p) __atomic_load_generic(p, long, u_long, long) +#define atomic_load_8(p) __atomic_load_generic(p, int8_t, uint8_t, 8) +#define atomic_load_16(p) __atomic_load_generic(p, int16_t, uint16_t, 16) +#define atomic_load_32(p) __atomic_load_generic(p, int32_t, uint32_t, 32) +#ifdef __LP64__ +#define atomic_load_64(p) __atomic_load_generic(p, int64_t, uint64_t, 64) +#endif +#define atomic_store_char(p, v) \ + __atomic_store_generic(p, v, char, u_char, char) +#define atomic_store_short(p, v) \ + __atomic_store_generic(p, v, short, u_short, short) +#define atomic_store_int(p, v) \ + __atomic_store_generic(p, v, int, u_int, int) +#define atomic_store_long(p, v) \ + __atomic_store_generic(p, v, long, u_long, long) +#define atomic_store_8(p, v) \ + __atomic_store_generic(p, v, int8_t, uint8_t, 8) +#define atomic_store_16(p, v) \ + __atomic_store_generic(p, v, int16_t, uint16_t, 16) +#define atomic_store_32(p, v) \ + __atomic_store_generic(p, v, int32_t, uint32_t, 32) +#ifdef __LP64__ +#define atomic_store_64(p, v) \ + __atomic_store_generic(p, v, int64_t, uint64_t, 64) +#endif + +#define atomic_load_ptr(p) (*(volatile __typeof(*p) *)(p)) +#define atomic_store_ptr(p, v) (*(volatile __typeof(*p) *)(p) = (v)) + /* * Currently all architectures provide acquire and release fences on their own, * but they don't provide consume. Kludge below allows relevant code to stop