All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
To: William Tu <u9012063@gmail.com>
Cc: dev@dpdk.org, nick.connolly@mayadata.io
Subject: Re: [dpdk-dev] [PATCHv3] include: fix sys/queue.h.
Date: Fri, 13 Aug 2021 00:58:38 +0300	[thread overview]
Message-ID: <20210813005838.2655c74f@sovereign> (raw)
In-Reply-To: <20210812200528.60743-1-u9012063@gmail.com>

2021-08-12 20:05 (UTC+0000), William Tu:
> Currently there are a couple of public header files include

Suggested subject: "eal: remove sys/queue.h from public headers".

1. The state before the patch should be described in the past tense.
2. Really ten times more than "a couple", suggesting "some" (nit).
2. "files _that_ include"?

> 'sys/queue.h', which is a POSIX functionality.

It's not POSIX, it's found on many Unix systems.

> When compiling DPDK with OVS on Windows, we encountered issues such as, found the missing
> header.

This sentence is a little hard to parse. Instead, suggesting:

	This file is missing on Windows. During the build, DPDK uses a
	bundled copy, but it cannot be installed because macros it exports
	may conflict with the ones from application code or environment.

> In file included from ../lib/dpdk.c:27:
> C:\temp\dpdk\include\rte_log.h:24:10: fatal error: 'sys/queue.h' file
> not found

An explanation is missing why <sys/queue.h> embedded in DPDK shouldn't be
installed (see above, maybe you can come up with something better).

> 
> The patch fixes it by removing the #include <sys/queue.h> from
> DPDK public headers, so programs including DPDK headers don't depend
> on POSIX sys/queue.h. For Linux/FreeBSD, DPDK public headers only need a
> handful of macros for list/tailq heads and links. Those macros should be
> provided by DPDK, with RTE_ prefix.

It is worth noting that RTE_ macros must be compatible with <sys/queue.h>
at the level of API (to use with <sys/queue.h> macros in C files) and ABI
(to avoid breaking it).

Nit: "Should" is not the right word for things done in the patch. Same below.

> For Linux and FreeBSD it will just be:
>     #include <sys/queue.h>
>     #define RTE_TAILQ_ENTRY(type) TAILQ_ENTRY(type)
>     /* ... */
> For Windows, we copy these definitions from <sys/queue.h> to rte_os.h.

No need to describe what's inside the patch, diff already does it :)

> With this patch, all the public headers should not have
> "#include <sys/queue.h>" or "TAILQ_xxx" macros.
> 
> Suggested-by: Nick Connolly <nick.connolly@mayadata.io>
> Suggested-by: Dmitry Kozliuk <Dmitry.Kozliuk@gmail.com>
> Signed-off-by: William Tu <u9012063@gmail.com>
> ---
> v2->v3:
>   * follow the suggestion by Dmitry
>   * run checkpatches, there are some errors but I think either
>     the original file has over 80-char line due to comments,
>     or some false positive about macro.
> v1->v2:
>   - follow the suggestion by Nick and Dmitry
>   - http://mails.dpdk.org/archives/dev/2021-August/216304.html
> 
> Signed-off-by: William Tu <u9012063@gmail.com>
> ---
[...]
> diff --git a/lib/eal/freebsd/include/rte_os.h b/lib/eal/freebsd/include/rte_os.h
> index 627f0483ab..dc889e5826 100644
> --- a/lib/eal/freebsd/include/rte_os.h
> +++ b/lib/eal/freebsd/include/rte_os.h
> @@ -11,6 +11,39 @@
>   */
>  
>  #include <pthread_np.h>
> +#include <sys/queue.h>
> +
> +/* These macros are compatible with system's sys/queue.h. */
> +#define RTE_TAILQ_INIT(head) TAILQ_INIT(head)
> +#define RTE_TAILQ_HEAD(name, type) TAILQ_HEAD(name, type)
> +#define RTE_TAILQ_LAST(head, headname) TAILQ_LAST(head, headname)
> +#define RTE_TAILQ_ENTRY(type) TAILQ_ENTRY(type)
> +#define RTE_TAILQ_FIRST(head) TAILQ_FIRST(head)
> +#define RTE_TAILQ_EMPTY(head) TAILQ_EMPTY(head)
> +#define RTE_TAILQ_NEXT(elem, field) TAILQ_NEXT(elem, field)
> +#define RTE_TAILQ_HEAD_INITIALIZER(head) TAILQ_HEAD_INITIALIZER(head)
> +#define RTE_TAILQ_FOREACH(var, head, field) TAILQ_FOREACH(var, head, field)
> +#define RTE_TAILQ_INSERT_TAIL(head, elm, field) \
> +	TAILQ_INSERT_TAIL(head, elm, field)
> +#define RTE_TAILQ_REMOVE(head, elm, field) TAILQ_REMOVE(head, elm, field)
> +#define RTE_TAILQ_INSERT_BEFORE(listelm, elm, field) \
> +	TAILQ_INSERT_BEFORE(listelm, elm, field)
> +#define RTE_TAILQ_INSERT_AFTER(head, listelm, elm, field) \
> +	TAILQ_INSERT_AFTER(head, listelm, elm, field)
> +#define RTE_TAILQ_INSERT_HEAD(head, elm, field) \
> +	TAILQ_INSERT_HEAD(head, elm, field)
> +
> +#define RTE_STAILQ_HEAD(name, type) STAILQ_HEAD(name, type)
> +#define RTE_STAILQ_HEAD_INITIALIZER(head) STAILQ_HEAD_INITIALIZER(head)
> +#define RTE_STAILQ_ENTRY(type) STAILQ_ENTRY(type)

Most of these macros are not used in public headers and are not needed.
The idea is that TAILQ_* macros from sys/queue.h can be used in C files
with variables declared with RTE_TAILQ_HEAD/ENTRY in public headers.
Needed macros:
	RTE_TAILQ_HEAD
	RTE_TAILQ_ENTRY
	RTE_TAILQ_FOREACH
	RTE_TAILQ_FIRST (for RTE_TAILQ_FOREACH_SAFE only)
	RTE_TAILQ_NEXT (ditto)
	RTE_STAILQ_HEAD
	RTE_STAILQ_ENTRY

> +
> +/* This is not defined in sys/queue.h */
> +#ifndef TAILQ_FOREACH_SAFE
> +#define TAILQ_FOREACH_SAFE(var, head, field, tvar)		\
> +	for ((var) = RTE_TAILQ_FIRST((head));			\
> +	    (var) && ((tvar) = RTE_TAILQ_NEXT((var), field), 1);	\
> +	    (var) = (tvar))
> +#endif

Please simply change the three usages of TAILQ_FOREACH_SAFE to
RTE_TAILQ_FOREACH_SAFE and remove this one. It cannot be placed in rte_os.h,
because rte_os.h is public and it must not export non-RTE symbols.

All comments to this file obviously apply to Linux version as well.

>  
>  typedef cpuset_t rte_cpuset_t;
>  #define RTE_HAS_CPUSET
[...]
> diff --git a/lib/eal/windows/include/rte_os.h b/lib/eal/windows/include/rte_os.h
> index 66c711d458..d0935c5003 100644
> --- a/lib/eal/windows/include/rte_os.h
> +++ b/lib/eal/windows/include/rte_os.h
> @@ -18,6 +18,144 @@
>  extern "C" {
>  #endif
>  
> +#ifdef QUEUE_MACRO_DEBUG_TRACE

IMO we all these debugging macros should be removed from this header,
including their use in user-facing macros.
They are implementation detail for <sys/queue.h> developers.

> +/* Store the last 2 places the queue element or head was altered */
> +struct qm_trace {
> +	unsigned long	 lastline;
> +	unsigned long	 prevline;
> +	const char	*lastfile;
> +	const char	*prevfile;
> +};
> +
> +/**
> + * These macros are compatible with the sys/queue.h provided
> + * at DPDK source code.
> + */
[...]
> +
> +#define	QMD_TAILQ_CHECK_HEAD(head, field)
> +#define	QMD_TAILQ_CHECK_TAIL(head, headname)
> +#define	QMD_TAILQ_CHECK_NEXT(elm, field)
> +#define	QMD_TAILQ_CHECK_PREV(elm, field)

Redundant empty lines below.

> +
> +
> +#define	RTE_TAILQ_EMPTY(head)	((head)->tqh_first == NULL)
> +
> +#define	RTE_TAILQ_FIRST(head)	((head)->tqh_first)
> +
> +#define	RTE_TAILQ_INIT(head) do {					\

I suggest removing all spaces but one before the backslash
so that you don't need to manually align.
At least please keep the lines within 80 characters.

> +	RTE_TAILQ_FIRST((head)) = NULL;					\
> +	(head)->tqh_last = &RTE_TAILQ_FIRST((head));			\
> +	QMD_TRACE_HEAD(head);						\
> +} while (0)
[...]

  reply	other threads:[~2021-08-12 21:58 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-11 20:46 [dpdk-dev] [PATCHv2] include: fix sys/queue.h William Tu
2021-08-11 15:50 ` Dmitry Kozlyuk
2021-08-11 18:13   ` William Tu
2021-08-12 20:05 ` [dpdk-dev] [PATCHv3] " William Tu
2021-08-12 21:58   ` Dmitry Kozlyuk [this message]
2021-08-13  1:02   ` [dpdk-dev] [PATCHv4] eal: remove sys/queue.h from public headers William Tu
2021-08-13  1:11     ` Stephen Hemminger
2021-08-13  1:36       ` William Tu
2021-08-13  3:36     ` [dpdk-dev] [PATCHv5] " William Tu
2021-08-13 18:59       ` Dmitry Kozlyuk
2021-08-14  2:31         ` William Tu
2021-08-14  2:51       ` [dpdk-dev] [PATCH v6] " William Tu
2021-08-17 22:06         ` Dmitry Kozlyuk
2021-08-18 23:26         ` [dpdk-dev] [PATCH v7] " William Tu
2021-08-19 23:29           ` Dmitry Kozlyuk
2021-08-23 12:34             ` William Tu
2021-08-23 13:03           ` [dpdk-dev] [PATCH v8] " William Tu
2021-08-23 19:14             ` Dmitry Kozlyuk
2021-08-24 16:11               ` William Tu
2021-08-24 16:21             ` [dpdk-dev] [PATCH v9] " William Tu
2021-09-20 20:11               ` Narcisa Ana Maria Vasile
2021-09-30 22:16                 ` William Tu
2021-10-01  7:27                   ` David Marchand
2021-10-01  9:36                     ` Dmitry Kozlyuk
2021-10-01  9:51                       ` Dmitry Kozlyuk
2021-10-01  9:55                         ` David Marchand
2021-10-01 10:12                           ` Bruce Richardson
2021-10-01 10:34                 ` Thomas Monjalon

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=20210813005838.2655c74f@sovereign \
    --to=dmitry.kozliuk@gmail.com \
    --cc=dev@dpdk.org \
    --cc=nick.connolly@mayadata.io \
    --cc=u9012063@gmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.