[RFC] eal: introduce function to get lcore thread id
diff mbox series

Message ID 20200810093652.102078-1-mattias.ronnblom@ericsson.com
State New
Delegated to: David Marchand
Headers show
Series
  • [RFC] eal: introduce function to get lcore thread id
Related show

Checks

Context Check Description
ci/Intel-compilation success Compilation OK
ci/checkpatch success coding style OK

Commit Message

Mattias Rönnblom Aug. 10, 2020, 9:36 a.m. UTC
Introduce function in <rte_lcore.h> to retrieve a lcore worker
thread's pthread id.

This change allows applications to do things like changing the name of
a lcore thread, or detect if it's getting interrupted (e.g. getting
preempted by another thread).

Signed-off-by: Mattias Rönnblom <mattias.ronnblom@ericsson.com>
---
 lib/librte_eal/common/eal_common_thread.c |  8 ++++++++
 lib/librte_eal/include/rte_lcore.h        | 14 ++++++++++++++
 lib/librte_eal/rte_eal_version.map        |  3 +++
 3 files changed, 25 insertions(+)

Comments

David Marchand Oct. 20, 2020, 1:38 p.m. UTC | #1
On Mon, Aug 10, 2020 at 11:37 AM Mattias Rönnblom
<mattias.ronnblom@ericsson.com> wrote:
>
> Introduce function in <rte_lcore.h> to retrieve a lcore worker
> thread's pthread id.
>
> This change allows applications to do things like changing the name of
> a lcore thread, or detect if it's getting interrupted (e.g. getting
> preempted by another thread).
>
> Signed-off-by: Mattias Rönnblom <mattias.ronnblom@ericsson.com>

I can see no feedback.
I am a bit reluctant at giving access to this info which is not really
abstracted across OS..
Is there no other way to achieve what you wanted?
Mattias Rönnblom Oct. 20, 2020, 6:40 p.m. UTC | #2
On 2020-10-20 15:38, David Marchand wrote:
> On Mon, Aug 10, 2020 at 11:37 AM Mattias Rönnblom
> <mattias.ronnblom@ericsson.com> wrote:
>> Introduce function in <rte_lcore.h> to retrieve a lcore worker
>> thread's pthread id.
>>
>> This change allows applications to do things like changing the name of
>> a lcore thread, or detect if it's getting interrupted (e.g. getting
>> preempted by another thread).
>>
>> Signed-off-by: Mattias Rönnblom <mattias.ronnblom@ericsson.com>
> I can see no feedback.
> I am a bit reluctant at giving access to this info which is not really
> abstracted across OS..
> Is there no other way to achieve what you wanted?
>
>
The fact that POSIX threading, or at least such thread identifiers, are 
used internally is already visible in the lcore API.


What we are using now is a little hack with a service started on each 
core, which calls pthead_self(), stores the result, and turns itself off.

Patch
diff mbox series

diff --git a/lib/librte_eal/common/eal_common_thread.c b/lib/librte_eal/common/eal_common_thread.c
index 73a055902..6233aef11 100644
--- a/lib/librte_eal/common/eal_common_thread.c
+++ b/lib/librte_eal/common/eal_common_thread.c
@@ -294,3 +294,11 @@  rte_thread_unregister(void)
 		RTE_LOG(DEBUG, EAL, "Unregistered non-EAL thread (was lcore %u).\n",
 			lcore_id);
 }
+
+int rte_lcore_thread_id(unsigned int lcore_id, pthread_t *id)
+{
+	if (lcore_id >= RTE_MAX_LCORE)
+		return -1;
+	*id = lcore_config[lcore_id].thread_id;
+	return 0;
+}
diff --git a/lib/librte_eal/include/rte_lcore.h b/lib/librte_eal/include/rte_lcore.h
index b8b64a625..dae8d11ca 100644
--- a/lib/librte_eal/include/rte_lcore.h
+++ b/lib/librte_eal/include/rte_lcore.h
@@ -363,6 +363,20 @@  int rte_thread_set_affinity(rte_cpuset_t *cpusetp);
  */
 void rte_thread_get_affinity(rte_cpuset_t *cpusetp);
 
+/**
+ * Get the thread id of a lcore worker thread.
+ *
+ * @param lcore_id
+ *   The identifier of the lcore, which MUST be between 0 and RTE_MAX_LCORE-1.
+ * @param[out] id
+ *   A pointer that will be filled in with the lcore worker thread's POSIX
+ *   thread id, on success.
+ * @return
+ *   On success, return 0; otherwise return a negative value.
+ */
+__rte_experimental
+int rte_lcore_thread_id(unsigned int lcore_id, pthread_t *id);
+
 /**
  * Set thread names.
  *
diff --git a/lib/librte_eal/rte_eal_version.map b/lib/librte_eal/rte_eal_version.map
index bf0c17c23..571aacd17 100644
--- a/lib/librte_eal/rte_eal_version.map
+++ b/lib/librte_eal/rte_eal_version.map
@@ -403,6 +403,9 @@  EXPERIMENTAL {
 	rte_mp_disable;
 	rte_thread_register;
 	rte_thread_unregister;
+
+	# added in 20.11
+	rte_lcore_thread_id;
 };
 
 INTERNAL {