[PATCH v5 1/4] eal: add thread set name API operating on rte thread

David Marchand david.marchand at redhat.com
Wed Jan 18 15:50:43 CET 2023


On Tue, Jan 17, 2023 at 7:21 PM Tyler Retzlaff
<roretzla at linux.microsoft.com> wrote:
>
> Add a rte_thread_set_name that sets the name of an rte_thread_t thread.
> This is a replacement for the rte_thread_setname(pthread_t, ...) which
> exposes platform-specific details.
>
> Signed-off-by: Tyler Retzlaff <roretzla at linux.microsoft.com>
> ---
>
> Series-acked-by: Morten Brørup <mb at smartsharesystems.com>
>
>  lib/eal/common/eal_common_thread.c |  9 +++-----
>  lib/eal/freebsd/eal.c              |  4 +++-
>  lib/eal/freebsd/eal_thread.c       | 11 +++++++++
>  lib/eal/include/rte_thread.h       | 17 ++++++++++++++
>  lib/eal/linux/eal.c                |  8 +++----
>  lib/eal/linux/eal_thread.c         | 22 ++++++++++++++++++
>  lib/eal/version.map                |  3 +++
>  lib/eal/windows/rte_thread.c       | 46 ++++++++++++++++++++++++++++++++++++++
>  8 files changed, 108 insertions(+), 12 deletions(-)
>

[snip]

There is no update in lib/eal/windows/eal.c.
Windows worker threads are not renamed like on Linux/FreeBSD.

I'd rather fix this in this series now that Windows EAL offers such facility.
Either in this current patch, or a followup patch, as you prefer.


> diff --git a/lib/eal/windows/rte_thread.c b/lib/eal/windows/rte_thread.c
> index 1c1e9d0..c26659d 100644
> --- a/lib/eal/windows/rte_thread.c
> +++ b/lib/eal/windows/rte_thread.c
> @@ -4,7 +4,9 @@
>   */
>
>  #include <errno.h>
> +#include <wchar.h>
>
> +#include <rte_eal.h>
>  #include <rte_common.h>
>  #include <rte_errno.h>
>  #include <rte_thread.h>
> @@ -305,6 +307,50 @@ struct thread_routine_ctx {
>         return thread_id;
>  }
>
> +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];
> +       mbstate_t state = {0};
> +       size_t rv;
> +       HANDLE thread_handle;
> +
> +       thread_handle = OpenThread(THREAD_ALL_ACCESS, FALSE,
> +               thread_id.opaque_id);
> +       if (thread_handle == NULL) {
> +               ret = thread_log_last_error("OpenThread()");
> +               goto cleanup;
> +       }
> +
> +       memset(wname, 0, sizeof(wname));
> +       rv = mbsrtowcs(wname, &thread_name, RTE_DIM(wname) - 1, &state);
> +       if (rv == (size_t)-1) {
> +               ret = EILSEQ;
> +               goto cleanup;
> +       }
> +
> +       if (wcslen(wname) < strlen(thread_name))
> +               RTE_LOG(DEBUG, EAL, "Truncated thread name\n");
> +
> +#ifndef RTE_TOOLCHAIN_GCC
> +       if (FAILED(SetThreadDescription(thread_handle, wname))) {
> +               ret = EINVAL;
> +               goto cleanup;
> +       }
> +#else
> +       ret = ENOTSUP;
> +       goto cleanup;
> +#endif
> +
> +cleanup:
> +       if (thread_handle != NULL)
> +               CloseHandle(thread_handle);
> +
> +       if (ret != 0)
> +               RTE_LOG(DEBUG, EAL, "Failed to set thread name\n");
> +}
> +
>  int
>  rte_thread_get_priority(rte_thread_t thread_id,
>         enum rte_thread_priority *priority)
> --
> 1.8.3.1
>


-- 
David Marchand



More information about the dev mailing list