From: Bruce Richardson <bruce.richardson@intel.com>
To: Andre Muezerie <andremue@linux.microsoft.com>
Cc: Stephen Hemminger <stephen@networkplumber.org>, <dev@dpdk.org>
Subject: Re: [PATCH v11 0/3] add diagnostics macros to make code portable
Date: Wed, 15 Jan 2025 11:11:28 +0000 [thread overview]
Message-ID: <Z4eX4NK8_-qIX9qQ@bricha3-mobl1.ger.corp.intel.com> (raw)
In-Reply-To: <20250114192005.GA19265@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net>
On Tue, Jan 14, 2025 at 11:20:05AM -0800, Andre Muezerie wrote:
> On Wed, Jan 08, 2025 at 09:20:27AM +0000, Bruce Richardson wrote:
> > On Tue, Jan 07, 2025 at 06:46:48PM -0800, Andre Muezerie wrote:
> > > On Mon, Jan 06, 2025 at 11:00:15AM +0000, Bruce Richardson wrote:
> > > > On Fri, Jan 03, 2025 at 01:26:34PM -0800, Andre Muezerie wrote:
> > > > > On Fri, Jan 03, 2025 at 11:24:02AM -0800, Stephen Hemminger wrote:
> > > > > > On Fri, 3 Jan 2025 07:36:48 -0800
> > > > > > Andre Muezerie <andremue@linux.microsoft.com> wrote:
> > > > > >
> > > > > > > From: Andre Muezerie <andremue@linux.microsoft.com>
> > > > > > > To: andremue@linux.microsoft.com
> > > > > > > Cc: dev@dpdk.org, stephen@networkplumber.org
> > > > > > > Subject: [PATCH v11 0/3] add diagnostics macros to make code portable
> > > > > > > Date: Fri, 3 Jan 2025 07:36:48 -0800
> > > > > > > X-Mailer: git-send-email 1.8.3.1
> > > > > > >
> > > > > > > It was a common pattern to have "GCC diagnostic ignored" pragmas
> > > > > > > sprinkled over the code and only activate these pragmas for certain
> > > > > > > compilers (gcc and clang). Clang supports GCC's pragma for
> > > > > > > compatibility with existing source code, so #pragma GCC diagnostic
> > > > > > > and #pragma clang diagnostic are synonyms for Clang
> > > > > > > (https://clang.llvm.org/docs/UsersManual.html).
> > > > > > >
> > > > > > > Now that effort is being made to make the code compatible with MSVC
> > > > > > > these expressions would become more complex. It makes sense to hide
> > > > > > > this complexity behind macros. This makes maintenance easier as these
> > > > > > > macros are defined in a single place. As a plus the code becomes
> > > > > > > more readable as well.
> > > > > >
> > > > > > Since 90% of these cases are about removing const from a pointer,
> > > > > > maybe it would be better to have a macro that did that?
> > > > > >
> > > > > > Would not work for base driver code which is pretending to be platform independent.
> > > > >
> > > > > Most of the warnings I've seen were about dropping the volatile qualifier, like the one below:
> > > > >
> > > > > ../drivers/net/i40e/i40e_rxtx_vec_sse.c:42:32: warning: cast from 'volatile struct i40e_32byte_rx_desc::(unnamed at ../drivers/net/i40e/base/i40e_type.h:803:2) *' to '__attribute__((__vector_size__(2 * sizeof(long long)))) long long *' drops volatile qualifier [-Wcast-qual]
> > > > > 42 | _mm_store_si128((__m128i *)&rxdp[i].read,
> > > > > | ^
> > > > >
> > > > > To make sure I understood your suggestion correctly, you're proposing to replace this
> > > > >
> > > > > __rte_diagnostic_push
> > > > > __rte_diagnostic_ignored_wcast_qual
> > > > > _mm_store_si128((__m128i *)&rxdp[i].read, dma_addr0);
> > > > > __rte_diagnostic_pop
> > > > >
> > > > >
> > > > > with something like this?
> > > > >
> > > > > _mm_store_si128(RTE_IGNORE_CAST_QUAL((__m128i *)&rxdp[i].read), dma_addr0);
> > > > >
> > > > > This could be done, and I think it does look better, despite the slight line length increase.
> > > >
> > > > +1 for this option. One macro can be used to drop all qualifiers, both
> > > > const and volatile, right?
> > >
> > > Yes, a single macro can drop all qualifiers. I did realize though that the macro must involve the entire expression - it cannot be used just around one parameter, unfortunately.
> > >
> > For many use cases, those involving pointers, the qualifiers can be cast
> > away by passing through a uintptr_t. Just tested this with gcc and clang:
> >
> > volatile int x = 5;
> > int *y = (int *)(uintptr_t)&x;
> > printf("*y = %d\n", *y);
> >
> > works without warnings or errors. Does this similarly work with MSVC? If
> > so, we can do a macro specifically for pointers types, which should cover
> > 99% of what we need.
> >
> > /Bruce
>
> Yes, that also works with MSVC. So for the macro you mentioned, is this what you had in mind?
>
> old code:
> _mm_store_si128((__m128i *)&rxdp[i].read, dma_addr0);
>
>
> new code:
> #define RTE_IGNORE_CAST_QUAL(X) \
> (uintptr_t)(X)
>
> _mm_store_si128((__m128i *)RTE_IGNORE_CAST_QUAL(&rxdp[i].read), dma_addr0);
Something like that. However, I'd actually include a (void *) in the macro
which should avoid the need for the cast in the store function call:
#define RTE_IGNORE_CAST_QUAL(X) (void *)(uintptr_t)(X)
Since void pointers are automatically cast to any other pointer type, we
save typecasting in lots of other places.
If we want to avoid risk of someone trying to use this on non-pointer
values, we may also be able to do this as an inline function to give a
little type-safety (untested to verify, sadly :-(, just sharing as possible
idea):
static inline void *
rte_ignore_ptr_qualifiers(const volatile void *x)
{
return (void *)(uintptr_t)x;
}
/Bruce
next prev parent reply other threads:[~2025-01-15 11:11 UTC|newest]
Thread overview: 60+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-27 1:33 [PATCH " Andre Muezerie
2024-12-27 1:33 ` [PATCH 1/3] lib/eal: " Andre Muezerie
2024-12-27 1:33 ` [PATCH 2/3] drivers/common: " Andre Muezerie
2024-12-27 17:57 ` Stephen Hemminger
2024-12-27 19:43 ` Andre Muezerie
2024-12-27 1:33 ` [PATCH 3/3] drivers/net: " Andre Muezerie
2024-12-28 0:45 ` [PATCH v2 0/3] " Andre Muezerie
2024-12-28 0:45 ` [PATCH v2 1/3] lib/eal: " Andre Muezerie
2024-12-28 0:45 ` [PATCH v2 2/3] drivers/common: " Andre Muezerie
2024-12-28 0:45 ` [PATCH v2 3/3] drivers/net: " Andre Muezerie
2024-12-28 3:18 ` [PATCH v3 0/3] " Andre Muezerie
2024-12-28 3:18 ` [PATCH v3 1/3] lib/eal: " Andre Muezerie
2024-12-28 3:18 ` [PATCH v3 2/3] drivers/common: " Andre Muezerie
2024-12-28 3:18 ` [PATCH v3 3/3] drivers/net: " Andre Muezerie
2024-12-30 15:59 ` [PATCH v4 0/3] " Andre Muezerie
2024-12-30 15:59 ` [PATCH v4 1/3] lib/eal: " Andre Muezerie
2024-12-30 15:59 ` [PATCH v4 2/3] drivers/common: " Andre Muezerie
2024-12-30 15:59 ` [PATCH v4 3/3] drivers/net: " Andre Muezerie
2024-12-30 17:44 ` [PATCH v4 0/3] " Stephen Hemminger
2024-12-31 18:55 ` [PATCH v5 " Andre Muezerie
2024-12-31 18:55 ` [PATCH v5 1/3] lib/eal: " Andre Muezerie
2024-12-31 18:55 ` [PATCH v5 2/3] drivers/common: " Andre Muezerie
2024-12-31 18:55 ` [PATCH v5 3/3] drivers/net: " Andre Muezerie
2024-12-31 20:15 ` [PATCH v6 0/3] " Andre Muezerie
2024-12-31 20:15 ` [PATCH v6 1/3] lib/eal: " Andre Muezerie
2024-12-31 20:15 ` [PATCH v6 2/3] drivers/common: " Andre Muezerie
2024-12-31 20:15 ` [PATCH v6 3/3] drivers/net: " Andre Muezerie
2024-12-31 22:30 ` [PATCH v7 0/3] " Andre Muezerie
2024-12-31 22:30 ` [PATCH v7 1/3] lib/eal: " Andre Muezerie
2024-12-31 22:30 ` [PATCH v7 2/3] drivers/common: " Andre Muezerie
2024-12-31 22:30 ` [PATCH v7 3/3] drivers/net: " Andre Muezerie
2025-01-01 0:48 ` [PATCH v8 0/3] " Andre Muezerie
2025-01-01 0:48 ` [PATCH v8 1/3] lib/eal: " Andre Muezerie
2025-01-01 0:48 ` [PATCH v8 2/3] drivers/common: " Andre Muezerie
2025-01-01 0:48 ` [PATCH v8 3/3] drivers/net: " Andre Muezerie
2025-01-01 3:36 ` [PATCH v9 0/3] " Andre Muezerie
2025-01-01 3:36 ` [PATCH v9 1/3] lib/eal: " Andre Muezerie
2025-01-01 3:36 ` [PATCH v9 2/3] drivers/common: " Andre Muezerie
2025-01-01 3:36 ` [PATCH v9 3/3] drivers/net: " Andre Muezerie
2025-01-03 0:12 ` [PATCH v10 0/3] " Andre Muezerie
2025-01-03 0:12 ` [PATCH v10 1/3] lib/eal: " Andre Muezerie
2025-01-03 0:12 ` [PATCH v10 2/3] drivers/common: " Andre Muezerie
2025-01-03 0:12 ` [PATCH v10 3/3] drivers/net: " Andre Muezerie
2025-01-03 15:36 ` [PATCH v11 0/3] " Andre Muezerie
2025-01-03 15:36 ` [PATCH v11 1/3] lib/eal: " Andre Muezerie
2025-01-03 15:36 ` [PATCH v11 2/3] drivers/common: " Andre Muezerie
2025-01-03 15:36 ` [PATCH v11 3/3] drivers/net: " Andre Muezerie
2025-01-03 19:24 ` [PATCH v11 0/3] " Stephen Hemminger
2025-01-03 21:26 ` Andre Muezerie
2025-01-06 11:00 ` Bruce Richardson
2025-01-08 2:46 ` Andre Muezerie
2025-01-08 9:20 ` Bruce Richardson
2025-01-14 19:20 ` Andre Muezerie
2025-01-15 11:11 ` Bruce Richardson [this message]
2025-01-15 4:27 ` [PATCH v12 " Andre Muezerie
2025-01-15 4:27 ` [PATCH v12 1/3] lib/eal: " Andre Muezerie
2025-01-15 9:05 ` Morten Brørup
2025-01-15 4:27 ` [PATCH v12 2/3] drivers/common: " Andre Muezerie
2025-01-15 11:13 ` Bruce Richardson
2025-01-15 4:27 ` [PATCH v12 3/3] drivers/net: " Andre Muezerie
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Z4eX4NK8_-qIX9qQ@bricha3-mobl1.ger.corp.intel.com \
--to=bruce.richardson@intel.com \
--cc=andremue@linux.microsoft.com \
--cc=dev@dpdk.org \
--cc=stephen@networkplumber.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).