[02/11] eal: rename thread name length definition

Message ID 20230906162226.1618088-3-thomas@monjalon.net (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series rework thread management |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Thomas Monjalon Sept. 6, 2023, 4:12 p.m. UTC
  RTE_MAX_THREAD_NAME_LEN is including the NUL character,
so it should be named "size" instead of "length".
A new constant RTE_THREAD_NAME_SIZE is introduced for naming accuracy.
For API compatibility, the old name is kept.

At the same time, the original definition is moved
from rte_eal.h to rte_thread.h.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
---
 lib/eal/freebsd/eal.c        | 2 +-
 lib/eal/freebsd/eal_thread.c | 2 +-
 lib/eal/include/rte_eal.h    | 3 ---
 lib/eal/include/rte_thread.h | 9 +++++++--
 lib/eal/linux/eal.c          | 2 +-
 lib/eal/linux/eal_thread.c   | 2 +-
 lib/eal/windows/eal.c        | 2 +-
 lib/eal/windows/rte_thread.c | 2 +-
 8 files changed, 13 insertions(+), 11 deletions(-)
  

Comments

Tyler Retzlaff Sept. 8, 2023, 4 a.m. UTC | #1
On Wed, Sep 06, 2023 at 06:12:19PM +0200, Thomas Monjalon wrote:
> RTE_MAX_THREAD_NAME_LEN is including the NUL character,
> so it should be named "size" instead of "length".
> A new constant RTE_THREAD_NAME_SIZE is introduced for naming accuracy.
> For API compatibility, the old name is kept.
> 
> At the same time, the original definition is moved
> from rte_eal.h to rte_thread.h.
> 
> Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
> ---
lgtm

Acked-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
  

Patch

diff --git a/lib/eal/freebsd/eal.c b/lib/eal/freebsd/eal.c
index 9e1e267955..39a2868523 100644
--- a/lib/eal/freebsd/eal.c
+++ b/lib/eal/freebsd/eal.c
@@ -583,7 +583,7 @@  rte_eal_init(int argc, char **argv)
 	static uint32_t run_once;
 	uint32_t has_run = 0;
 	char cpuset[RTE_CPU_AFFINITY_STR_LEN];
-	char thread_name[RTE_MAX_THREAD_NAME_LEN];
+	char thread_name[RTE_THREAD_NAME_SIZE];
 	const struct rte_config *config = rte_eal_get_configuration();
 	struct internal_config *internal_conf =
 		eal_get_internal_configuration();
diff --git a/lib/eal/freebsd/eal_thread.c b/lib/eal/freebsd/eal_thread.c
index 3227d9b8a2..ba9b25c2c0 100644
--- a/lib/eal/freebsd/eal_thread.c
+++ b/lib/eal/freebsd/eal_thread.c
@@ -34,7 +34,7 @@  int rte_sys_gettid(void)
 
 void rte_thread_set_name(rte_thread_t thread_id, const char *thread_name)
 {
-	char truncated[RTE_MAX_THREAD_NAME_LEN];
+	char truncated[RTE_THREAD_NAME_SIZE];
 	const size_t truncatedsz = sizeof(truncated);
 
 	if (strlcpy(truncated, thread_name, truncatedsz) >= truncatedsz)
diff --git a/lib/eal/include/rte_eal.h b/lib/eal/include/rte_eal.h
index 53c4a5519e..cd318ee141 100644
--- a/lib/eal/include/rte_eal.h
+++ b/lib/eal/include/rte_eal.h
@@ -27,9 +27,6 @@  extern "C" {
 
 #define RTE_MAGIC 19820526 /**< Magic number written by the main partition when ready. */
 
-/* Maximum thread_name length. */
-#define RTE_MAX_THREAD_NAME_LEN 16
-
 /**
  * The type of process in a linux, multi-process setup
  */
diff --git a/lib/eal/include/rte_thread.h b/lib/eal/include/rte_thread.h
index 369e2375f6..6233142322 100644
--- a/lib/eal/include/rte_thread.h
+++ b/lib/eal/include/rte_thread.h
@@ -23,6 +23,11 @@ 
 extern "C" {
 #endif
 
+/** Maximum thread name length (including '\0'). */
+#define RTE_THREAD_NAME_SIZE 16
+/* Old definition, aliased for compatibility. */
+#define RTE_MAX_THREAD_NAME_LEN RTE_THREAD_NAME_SIZE
+
 /**
  * Thread id descriptor.
  */
@@ -110,7 +115,7 @@  int rte_thread_create(rte_thread_t *thread_id,
  *   Filled with the thread id of the new created thread.
  * @param name
  *   The name of the control thread
- *   (max RTE_MAX_THREAD_NAME_LEN characters including '\0').
+ *   (max RTE_THREAD_NAME_SIZE characters including '\0').
  * @param thread_attr
  *   Attributes for the new thread.
  * @param thread_func
@@ -188,7 +193,7 @@  rte_thread_t rte_thread_self(void);
  *    The id of the thread to set name.
  *
  * @param thread_name
- *    The name to set. Truncated to RTE_MAX_THREAD_NAME_LEN,
+ *    The name to set. Truncated to RTE_THREAD_NAME_SIZE,
  *    including terminating NUL if necessary.
  */
 __rte_experimental
diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c
index a26822f667..5f4b2fb005 100644
--- a/lib/eal/linux/eal.c
+++ b/lib/eal/linux/eal.c
@@ -970,7 +970,7 @@  rte_eal_init(int argc, char **argv)
 	static uint32_t run_once;
 	uint32_t has_run = 0;
 	char cpuset[RTE_CPU_AFFINITY_STR_LEN];
-	char thread_name[RTE_MAX_THREAD_NAME_LEN];
+	char thread_name[RTE_THREAD_NAME_SIZE];
 	bool phys_addrs;
 	const struct rte_config *config = rte_eal_get_configuration();
 	struct internal_config *internal_conf =
diff --git a/lib/eal/linux/eal_thread.c b/lib/eal/linux/eal_thread.c
index c07ad9d8a4..b9a126f3a8 100644
--- a/lib/eal/linux/eal_thread.c
+++ b/lib/eal/linux/eal_thread.c
@@ -24,7 +24,7 @@  void rte_thread_set_name(rte_thread_t thread_id, const char *thread_name)
 	int ret = ENOSYS;
 #if defined(__GLIBC__) && defined(__GLIBC_PREREQ)
 #if __GLIBC_PREREQ(2, 12)
-	char truncated[RTE_MAX_THREAD_NAME_LEN];
+	char truncated[RTE_THREAD_NAME_SIZE];
 	const size_t truncatedsz = sizeof(truncated);
 
 	if (strlcpy(truncated, thread_name, truncatedsz) >= truncatedsz)
diff --git a/lib/eal/windows/eal.c b/lib/eal/windows/eal.c
index 16c1ba1596..7ec2152211 100644
--- a/lib/eal/windows/eal.c
+++ b/lib/eal/windows/eal.c
@@ -283,7 +283,7 @@  rte_eal_init(int argc, char **argv)
 	enum rte_iova_mode iova_mode;
 	int ret;
 	char cpuset[RTE_CPU_AFFINITY_STR_LEN];
-	char thread_name[RTE_MAX_THREAD_NAME_LEN];
+	char thread_name[RTE_THREAD_NAME_SIZE];
 
 	eal_log_init(NULL, 0);
 
diff --git a/lib/eal/windows/rte_thread.c b/lib/eal/windows/rte_thread.c
index e528ac9991..acf648456c 100644
--- a/lib/eal/windows/rte_thread.c
+++ b/lib/eal/windows/rte_thread.c
@@ -324,7 +324,7 @@  void
 rte_thread_set_name(rte_thread_t thread_id, const char *thread_name)
 {
 	int ret = 0;
-	wchar_t wname[RTE_MAX_THREAD_NAME_LEN];
+	wchar_t wname[RTE_THREAD_NAME_SIZE];
 	mbstate_t state = {0};
 	size_t rv;
 	HANDLE thread_handle;