* Re: [PATCH v18 2/8] eal: add thread attributes
@ 2022-02-04 19:21 Ananyev, Konstantin
2022-02-05 4:41 ` Tyler Retzlaff
0 siblings, 1 reply; 6+ messages in thread
From: Ananyev, Konstantin @ 2022-02-04 19:21 UTC (permalink / raw)
To: navasile
Cc: Richardson, Bruce, david.marchand, dev, dmitry.kozliuk, dmitrym,
khot, navasile, ocardona, Kadam, Pallavi, roretzla, talshn,
thomas
> Implement thread attributes for:
> * thread affinity
> * thread priority
> Implement functions for managing thread attributes.
>
> Priority is represented through an enum that allows for two levels:
> - RTE_THREAD_PRIORITY_NORMAL
> - RTE_THREAD_PRIORITY_REALTIME_CRITICAL
>
> Affinity is described by the rte_cpuset_t type.
>
> An rte_thread_attr_t object can be set to the default values
> by calling rte_thread_attr_init().
>
> Signed-off-by: Narcisa Vasile <navasile@microsoft.com>
> ---
> lib/eal/common/rte_thread.c | 46 ++++++++++++++++++
> lib/eal/include/rte_thread.h | 91 ++++++++++++++++++++++++++++++++++++
> lib/eal/version.map | 4 ++
> lib/eal/windows/rte_thread.c | 44 +++++++++++++++++
> 4 files changed, 185 insertions(+)
>
> diff --git a/lib/eal/common/rte_thread.c b/lib/eal/common/rte_thread.c
> index 92a7451b0a..27ad1c7eb0 100644
> --- a/lib/eal/common/rte_thread.c
> +++ b/lib/eal/common/rte_thread.c
> @@ -9,6 +9,7 @@
> #include <string.h>
>
> #include <rte_common.h>
> +#include <rte_debug.h>
> #include <rte_errno.h>
> #include <rte_log.h>
> #include <rte_thread.h>
> @@ -33,6 +34,51 @@ rte_thread_equal(rte_thread_t t1, rte_thread_t t2)
> return pthread_equal((pthread_t)t1.opaque_id, (pthread_t)t2.opaque_id);
> }
>
> +int
> +rte_thread_attr_init(rte_thread_attr_t *attr)
> +{
> + RTE_VERIFY(attr != NULL);
As a generic one, here and everywhere:
Please don't use RTE_VERIFY() for checking input function parameters.
We don't want to panic in case of just invalid parameter from user.
> +
> + CPU_ZERO(&attr->cpuset);
> + attr->priority = RTE_THREAD_PRIORITY_NORMAL;
> +
> + return 0;
> +}
> +
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v18 2/8] eal: add thread attributes
2022-02-04 19:21 [PATCH v18 2/8] eal: add thread attributes Ananyev, Konstantin
@ 2022-02-05 4:41 ` Tyler Retzlaff
2022-02-05 9:00 ` Thomas Monjalon
2022-02-05 12:51 ` Ananyev, Konstantin
0 siblings, 2 replies; 6+ messages in thread
From: Tyler Retzlaff @ 2022-02-05 4:41 UTC (permalink / raw)
To: Ananyev, Konstantin
Cc: navasile, Richardson, Bruce, david.marchand, dev, dmitry.kozliuk,
dmitrym, khot, navasile, ocardona, Kadam, Pallavi, roretzla,
talshn, thomas
On Fri, Feb 04, 2022 at 07:21:10PM +0000, Ananyev, Konstantin wrote:
> > Implement thread attributes for:
> > * thread affinity
> > * thread priority
> > Implement functions for managing thread attributes.
> >
> > Priority is represented through an enum that allows for two levels:
> > - RTE_THREAD_PRIORITY_NORMAL
> > - RTE_THREAD_PRIORITY_REALTIME_CRITICAL
> >
> > Affinity is described by the rte_cpuset_t type.
> >
> > An rte_thread_attr_t object can be set to the default values
> > by calling rte_thread_attr_init().
> >
> > Signed-off-by: Narcisa Vasile <navasile@microsoft.com>
> > ---
> > lib/eal/common/rte_thread.c | 46 ++++++++++++++++++
> > lib/eal/include/rte_thread.h | 91 ++++++++++++++++++++++++++++++++++++
> > lib/eal/version.map | 4 ++
> > lib/eal/windows/rte_thread.c | 44 +++++++++++++++++
> > 4 files changed, 185 insertions(+)
> >
> > diff --git a/lib/eal/common/rte_thread.c b/lib/eal/common/rte_thread.c
> > index 92a7451b0a..27ad1c7eb0 100644
> > --- a/lib/eal/common/rte_thread.c
> > +++ b/lib/eal/common/rte_thread.c
> > @@ -9,6 +9,7 @@
> > #include <string.h>
> >
> > #include <rte_common.h>
> > +#include <rte_debug.h>
> > #include <rte_errno.h>
> > #include <rte_log.h>
> > #include <rte_thread.h>
> > @@ -33,6 +34,51 @@ rte_thread_equal(rte_thread_t t1, rte_thread_t t2)
> > return pthread_equal((pthread_t)t1.opaque_id, (pthread_t)t2.opaque_id);
> > }
> >
> > +int
> > +rte_thread_attr_init(rte_thread_attr_t *attr)
> > +{
> > + RTE_VERIFY(attr != NULL);
>
> As a generic one, here and everywhere:
> Please don't use RTE_VERIFY() for checking input function parameters.
> We don't want to panic in case of just invalid parameter from user.
i ask this question again. what useful thing will the user application
do when handling -EINVAL or rte_errno = EINVAL is returned for
incorrectly supplied parameters?
again, there should be a mechanism that allows a policy for how these
non-recoverable errors are handled rather than defaulting to tossing
it over the fence and expecting the application to do something
sensible when the only thing it could do is conclusively more
complicated than having passed the correct parameters in the first place.
more often then not application programmers will ignore superfluous
return values from functions like this resulting in the bug remaining
longer and the state / reason being lost.
please reconsider.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v18 2/8] eal: add thread attributes
2022-02-05 4:41 ` Tyler Retzlaff
@ 2022-02-05 9:00 ` Thomas Monjalon
2022-02-06 3:45 ` Tyler Retzlaff
2022-02-05 12:51 ` Ananyev, Konstantin
1 sibling, 1 reply; 6+ messages in thread
From: Thomas Monjalon @ 2022-02-05 9:00 UTC (permalink / raw)
To: Ananyev, Konstantin, Tyler Retzlaff, navasile
Cc: Richardson, Bruce, david.marchand, dev, dmitry.kozliuk, dmitrym,
khot, navasile, ocardona, Kadam, Pallavi, roretzla, talshn
05/02/2022 05:41, Tyler Retzlaff:
> On Fri, Feb 04, 2022 at 07:21:10PM +0000, Ananyev, Konstantin wrote:
> > > +int
> > > +rte_thread_attr_init(rte_thread_attr_t *attr)
> > > +{
> > > + RTE_VERIFY(attr != NULL);
> >
> > As a generic one, here and everywhere:
> > Please don't use RTE_VERIFY() for checking input function parameters.
> > We don't want to panic in case of just invalid parameter from user.
>
> i ask this question again. what useful thing will the user application
> do when handling -EINVAL or rte_errno = EINVAL is returned for
> incorrectly supplied parameters?
>
> again, there should be a mechanism that allows a policy for how these
> non-recoverable errors are handled rather than defaulting to tossing
> it over the fence and expecting the application to do something
> sensible when the only thing it could do is conclusively more
> complicated than having passed the correct parameters in the first place.
>
> more often then not application programmers will ignore superfluous
> return values from functions like this resulting in the bug remaining
> longer and the state / reason being lost.
>
> please reconsider.
The application should just abort this feature indeed.
But remember the application can have other features.
In some applications, the DPDK features are a minor part.
So we don't want to crash the entire application just because
a DPDK feature has a bug.
More generally, a library should never crash an entire application.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v18 2/8] eal: add thread attributes
2022-02-05 9:00 ` Thomas Monjalon
@ 2022-02-06 3:45 ` Tyler Retzlaff
0 siblings, 0 replies; 6+ messages in thread
From: Tyler Retzlaff @ 2022-02-06 3:45 UTC (permalink / raw)
To: Thomas Monjalon
Cc: Ananyev, Konstantin, navasile, Richardson, Bruce, david.marchand,
dev, dmitry.kozliuk, dmitrym, khot, navasile, ocardona, Kadam,
Pallavi, roretzla, talshn
On Sat, Feb 05, 2022 at 10:00:01AM +0100, Thomas Monjalon wrote:
> 05/02/2022 05:41, Tyler Retzlaff:
> > On Fri, Feb 04, 2022 at 07:21:10PM +0000, Ananyev, Konstantin wrote:
> > > > +int
> > > > +rte_thread_attr_init(rte_thread_attr_t *attr)
> > > > +{
> > > > + RTE_VERIFY(attr != NULL);
> > >
> > > As a generic one, here and everywhere:
> > > Please don't use RTE_VERIFY() for checking input function parameters.
> > > We don't want to panic in case of just invalid parameter from user.
> >
> > i ask this question again. what useful thing will the user application
> > do when handling -EINVAL or rte_errno = EINVAL is returned for
> > incorrectly supplied parameters?
> >
> > again, there should be a mechanism that allows a policy for how these
> > non-recoverable errors are handled rather than defaulting to tossing
> > it over the fence and expecting the application to do something
> > sensible when the only thing it could do is conclusively more
> > complicated than having passed the correct parameters in the first place.
> >
> > more often then not application programmers will ignore superfluous
> > return values from functions like this resulting in the bug remaining
> > longer and the state / reason being lost.
> >
> > please reconsider.
>
> The application should just abort this feature indeed.
> But remember the application can have other features.
> In some applications, the DPDK features are a minor part.
> So we don't want to crash the entire application just because
> a DPDK feature has a bug.
> More generally, a library should never crash an entire application.
>
>
you haven't addressed my concern. when deployed at scale i need to be
able to capture the state of what was wrong in order to debug the
problem. a crash dump does this.
i agree that the dpdk functionality may be shared/hosted in a process
that does other work but this api hard-codes a behavior that does not
permit easy diagnostics of buggy usage of api vs actual errors. there
is a distinction and it is important.
with the api hard-coded to a single policy you leave the application
author only the option of wrapping every single api in some boilerplate
error handling logic that has to teadeously log part of the application
state (hopefully the part you need) from the current scope before
explicitly exiting.
as i explained previously i'm not asking that dpdk hard-codes a policy
of crashing either. we just need it to be a choice rather than forcing a
single hard-coded behavior.
^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: [PATCH v18 2/8] eal: add thread attributes
2022-02-05 4:41 ` Tyler Retzlaff
2022-02-05 9:00 ` Thomas Monjalon
@ 2022-02-05 12:51 ` Ananyev, Konstantin
1 sibling, 0 replies; 6+ messages in thread
From: Ananyev, Konstantin @ 2022-02-05 12:51 UTC (permalink / raw)
To: Tyler Retzlaff
Cc: navasile, Richardson, Bruce, david.marchand, dev, dmitry.kozliuk,
dmitrym, khot, navasile, ocardona, Kadam, Pallavi, roretzla,
talshn, thomas
>
> On Fri, Feb 04, 2022 at 07:21:10PM +0000, Ananyev, Konstantin wrote:
> > > Implement thread attributes for:
> > > * thread affinity
> > > * thread priority
> > > Implement functions for managing thread attributes.
> > >
> > > Priority is represented through an enum that allows for two levels:
> > > - RTE_THREAD_PRIORITY_NORMAL
> > > - RTE_THREAD_PRIORITY_REALTIME_CRITICAL
> > >
> > > Affinity is described by the rte_cpuset_t type.
> > >
> > > An rte_thread_attr_t object can be set to the default values
> > > by calling rte_thread_attr_init().
> > >
> > > Signed-off-by: Narcisa Vasile <navasile@microsoft.com>
> > > ---
> > > lib/eal/common/rte_thread.c | 46 ++++++++++++++++++
> > > lib/eal/include/rte_thread.h | 91 ++++++++++++++++++++++++++++++++++++
> > > lib/eal/version.map | 4 ++
> > > lib/eal/windows/rte_thread.c | 44 +++++++++++++++++
> > > 4 files changed, 185 insertions(+)
> > >
> > > diff --git a/lib/eal/common/rte_thread.c b/lib/eal/common/rte_thread.c
> > > index 92a7451b0a..27ad1c7eb0 100644
> > > --- a/lib/eal/common/rte_thread.c
> > > +++ b/lib/eal/common/rte_thread.c
> > > @@ -9,6 +9,7 @@
> > > #include <string.h>
> > >
> > > #include <rte_common.h>
> > > +#include <rte_debug.h>
> > > #include <rte_errno.h>
> > > #include <rte_log.h>
> > > #include <rte_thread.h>
> > > @@ -33,6 +34,51 @@ rte_thread_equal(rte_thread_t t1, rte_thread_t t2)
> > > return pthread_equal((pthread_t)t1.opaque_id, (pthread_t)t2.opaque_id);
> > > }
> > >
> > > +int
> > > +rte_thread_attr_init(rte_thread_attr_t *attr)
> > > +{
> > > + RTE_VERIFY(attr != NULL);
> >
> > As a generic one, here and everywhere:
> > Please don't use RTE_VERIFY() for checking input function parameters.
> > We don't want to panic in case of just invalid parameter from user.
>
> i ask this question again. what useful thing will the user application
> do when handling -EINVAL or rte_errno = EINVAL is returned for
> incorrectly supplied parameters?
Let the user application to decide.
But inside the lib we shouldn't just crash if user provided invalid parameters
for one of our functions.
>
> again, there should be a mechanism that allows a policy for how these
> non-recoverable errors are handled rather than defaulting to tossing
> it over the fence and expecting the application to do something
> sensible when the only thing it could do is conclusively more
> complicated than having passed the correct parameters in the first place.
>
> more often then not application programmers will ignore superfluous
> return values from functions like this resulting in the bug remaining
> longer and the state / reason being lost.
>
> please reconsider.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [dpdk-dev] [PATCH v17 00/13] eal: Add EAL API for threading
@ 2021-11-10 3:01 Narcisa Ana Maria Vasile
2021-11-11 1:33 ` [PATCH v18 0/8] " Narcisa Ana Maria Vasile
0 siblings, 1 reply; 6+ messages in thread
From: Narcisa Ana Maria Vasile @ 2021-11-10 3:01 UTC (permalink / raw)
To: dev, thomas, dmitry.kozliuk, khot, navasile, dmitrym, roretzla,
talshn, ocardona
Cc: bruce.richardson, david.marchand, pallavi.kadam
From: Narcisa Vasile <navasile@microsoft.com>
EAL thread API
**Problem Statement**
DPDK currently uses the pthread interface to create and manage threads.
Windows does not support the POSIX thread programming model,
so it currently
relies on a header file that hides the Windows calls under
pthread matched interfaces. Given that EAL should isolate the environment
specifics from the applications and libraries and mediate
all the communication with the operating systems, a new EAL interface
is needed for thread management.
**Goals**
* Introduce a generic EAL API for threading support that will remove
the current Windows pthread.h shim.
* Replace references to pthread_* across the DPDK codebase with the new
RTE_THREAD_* API.
* Allow users to choose between using the RTE_THREAD_* API or a
3rd party thread library through a configuration option.
**Design plan**
New API main files:
* rte_thread.h (librte_eal/include)
* rte_thread.c (librte_eal/windows)
* rte_thread.c (librte_eal/common)
**A schematic example of the design**
--------------------------------------------------
lib/librte_eal/include/rte_thread.h
int rte_thread_create();
lib/librte_eal/common/rte_thread.c
int rte_thread_create()
{
return pthread_create();
}
lib/librte_eal/windows/rte_thread.c
int rte_thread_create()
{
return CreateThread();
}
-----------------------------------------------------
**Thread attributes**
When or after a thread is created, specific characteristics of the thread
can be adjusted. Currently in DPDK most threads operate at the OS-default
priority level but there are cases when increasing the priority is useful.
For example, high-performance applications require elevated priority to
avoid being preempted by other threads on the system.
The following structure that represents thread attributes has been
defined:
typedef struct
{
enum rte_thread_priority priority;
rte_cpuset_t cpuset;
} rte_thread_attr_t;
The *rte_thread_create()* function can optionally receive
an rte_thread_attr_t
object that will cause the thread to be created with the
affinity and priority
described by the attributes object. If no rte_thread_attr_t is passed
(parameter is NULL), the default affinity and priority are used.
An rte_thread_attr_t object can also be set to the default values
by calling *rte_thread_attr_init()*.
*Priority* is represented through an enum that currently advertises
two values for priority:
- RTE_THREAD_PRIORITY_NORMAL
- RTE_THREAD_PRIORITY_REALTIME_CRITICAL
The enum can be extended to allow for multiple priority levels.
rte_thread_set_priority - sets the priority of a thread
rte_thread_get_priority - retrieves the priority of a thread
from the OS
rte_thread_attr_set_priority - updates an rte_thread_attr_t object
with a new value for priority
*Affinity* is described by the already known “rte_cpuset_t” type.
rte_thread_attr_set/get_affinity - sets/gets the affinity field in a
rte_thread_attr_t object
rte_thread_set/get_affinity – sets/gets the affinity of a thread
**Errors**
As different platforms have different error codes, the approach here
is to translate the Windows error to POSIX-style ones to have
uniformity over the values returned.
**Future work**
The long term plan is for EAL to provide full threading support:
* Add support for conditional variables
* Additional functionality offered by pthread_*
(such as pthread_setname_np, etc.)
v17:
- Move unrelated changes to the correct patch.
- Rename RTE_STATIC_MUTEX to avoid confusion, since
the mutex is still dynamically initialized behind the scenes.
- Break down the unit tests into smaller patches and reorder them.
- Remove duplicated code in header.
- Improve commit messages and cover letter.
v16:
- Fix warning on freebsd by adding cast
- Change affinity unit test to consider ases when the requested CPU
are not available on the system.
- Fix priority unit test to avoid termination of thread before the
priority is checked.
v15:
- Add try_lock mutex functionality. If the mutex is already owned by a
different thread, the function returns immediately. Otherwise,
the mutex will be acquired.
- Add function for getting the priority of a thread.
An auxiliary function that translates the OS priority to the
EAL accepted ones is added.
- Fix unit tests logging, add descriptive asserts that mark test failures.
Verify mutex locking, verify barrier return values. Add test for
statically initialized mutexes.
- Fix Alpine build by removing the use of pthread_attr_set_affinity() and
using pthread_set_affinity() after the thread is created.
v14:
- Remove patch "eal: add EAL argument for setting thread priority"
This will be added later when enabling the new threading API.
- Remove priority enum value "_UNDEFINED". NORMAL is used
as the default.
- Fix issue with thread return value.
v13:
- Fix syntax error in unit tests
v12:
- Fix freebsd warning about initializer in unit tests
v11:
- Add unit tests for thread API
- Rebase
v10:
- Remove patch no. 10. It will be broken down in subpatches
and sent as a different patchset that depends on this one.
This is done due to the ABI breaks that would be caused by patch 10.
- Replace unix/rte_thread.c with common/rte_thread.c
- Remove initializations that may prevent compiler from issuing useful
warnings.
- Remove rte_thread_types.h and rte_windows_thread_types.h
- Remove unneeded priority macros (EAL_THREAD_PRIORITY*)
- Remove functions that retrieves thread handle from process handle
- Remove rte_thread_cancel() until same behavior is obtained on
all platforms.
- Fix rte_thread_detach() function description,
return value and remove empty line.
- Reimplement mutex functions. Add compatible representation for mutex
identifier. Add macro to replace static mutex initialization instances.
- Fix commit messages (lines too long, remove unicode symbols)
v9:
- Sign patches
v8:
- Rebase
- Add rte_thread_detach() API
- Set default priority, when user did not specify a value
v7:
Based on DmitryK's review:
- Change thread id representation
- Change mutex id representation
- Implement static mutex inititalizer for Windows
- Change barrier identifier representation
- Improve commit messages
- Add missing doxygen comments
- Split error translation function
- Improve name for affinity function
- Remove cpuset_size parameter
- Fix eal_create_cpu_map function
- Map EAL priority values to OS specific values
- Add thread wrapper for start routine
- Do not export rte_thread_cancel() on Windows
- Cleanup, fix comments, fix typos.
v6:
- improve error-translation function
- call the error translation function in rte_thread_value_get()
v5:
- update cover letter with more details on the priority argument
v4:
- fix function description
- rebase
v3:
- rebase
v2:
- revert changes that break ABI
- break up changes into smaller patches
- fix coding style issues
- fix issues with errors
- fix parameter type in examples/kni.c
Narcisa Vasile (13):
eal: add basic threading functions
eal: add thread attributes
eal/windows: translate Windows errors to errno-style errors
eal: implement functions for thread affinity management
eal: implement thread priority management functions
eal: add thread lifetime management
app/test: add unit tests for rte_thread_self
app/test: add unit tests for thread attributes
app/test: add unit tests for thread lifetime management
eal: implement functions for thread barrier management
app/test: add unit tests for barrier
eal: implement functions for mutex management
app/test: add unit tests for mutex
app/test/meson.build | 2 +
app/test/test_threads.c | 372 ++++++++++++++++++
lib/eal/common/meson.build | 1 +
lib/eal/common/rte_thread.c | 497 ++++++++++++++++++++++++
lib/eal/include/rte_thread.h | 412 +++++++++++++++++++-
lib/eal/unix/meson.build | 1 -
lib/eal/unix/rte_thread.c | 92 -----
lib/eal/version.map | 22 ++
lib/eal/windows/eal_lcore.c | 176 ++++++---
lib/eal/windows/eal_windows.h | 10 +
lib/eal/windows/include/sched.h | 2 +-
lib/eal/windows/rte_thread.c | 656 ++++++++++++++++++++++++++++++--
12 files changed, 2070 insertions(+), 173 deletions(-)
create mode 100644 app/test/test_threads.c
create mode 100644 lib/eal/common/rte_thread.c
delete mode 100644 lib/eal/unix/rte_thread.c
--
2.31.0.vfs.0.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v18 0/8] eal: Add EAL API for threading
2021-11-10 3:01 [dpdk-dev] [PATCH v17 00/13] eal: Add EAL API for threading Narcisa Ana Maria Vasile
@ 2021-11-11 1:33 ` Narcisa Ana Maria Vasile
2021-11-11 1:33 ` [PATCH v18 2/8] eal: add thread attributes Narcisa Ana Maria Vasile
0 siblings, 1 reply; 6+ messages in thread
From: Narcisa Ana Maria Vasile @ 2021-11-11 1:33 UTC (permalink / raw)
To: dev, thomas, dmitry.kozliuk, khot, navasile, dmitrym, roretzla,
talshn, ocardona
Cc: bruce.richardson, david.marchand, pallavi.kadam
From: Narcisa Vasile <navasile@microsoft.com>
EAL thread API
**Problem Statement**
DPDK currently uses the pthread interface to create and manage threads.
Windows does not support the POSIX thread programming model,
so it currently
relies on a header file that hides the Windows calls under
pthread matched interfaces. Given that EAL should isolate the environment
specifics from the applications and libraries and mediate
all the communication with the operating systems, a new EAL interface
is needed for thread management.
**Goals**
* Introduce a generic EAL API for threading support that will remove
the current Windows pthread.h shim.
* Replace references to pthread_* across the DPDK codebase with the new
RTE_THREAD_* API.
* Allow users to choose between using the RTE_THREAD_* API or a
3rd party thread library through a configuration option.
**Design plan**
New API main files:
* rte_thread.h (librte_eal/include)
* rte_thread.c (librte_eal/windows)
* rte_thread.c (librte_eal/common)
**A schematic example of the design**
--------------------------------------------------
lib/librte_eal/include/rte_thread.h
int rte_thread_create();
lib/librte_eal/common/rte_thread.c
int rte_thread_create()
{
return pthread_create();
}
lib/librte_eal/windows/rte_thread.c
int rte_thread_create()
{
return CreateThread();
}
-----------------------------------------------------
**Thread attributes**
When or after a thread is created, specific characteristics of the thread
can be adjusted. Currently in DPDK most threads operate at the OS-default
priority level but there are cases when increasing the priority is useful.
For example, high-performance applications require elevated priority to
avoid being preempted by other threads on the system.
The following structure that represents thread attributes has been
defined:
typedef struct
{
enum rte_thread_priority priority;
rte_cpuset_t cpuset;
} rte_thread_attr_t;
The *rte_thread_create()* function can optionally receive
an rte_thread_attr_t
object that will cause the thread to be created with the
affinity and priority
described by the attributes object. If no rte_thread_attr_t is passed
(parameter is NULL), the default affinity and priority are used.
An rte_thread_attr_t object can also be set to the default values
by calling *rte_thread_attr_init()*.
*Priority* is represented through an enum that currently advertises
two values for priority:
- RTE_THREAD_PRIORITY_NORMAL
- RTE_THREAD_PRIORITY_REALTIME_CRITICAL
The enum can be extended to allow for multiple priority levels.
rte_thread_set_priority - sets the priority of a thread
rte_thread_get_priority - retrieves the priority of a thread
from the OS
rte_thread_attr_set_priority - updates an rte_thread_attr_t object
with a new value for priority
*Affinity* is described by the already known “rte_cpuset_t” type.
rte_thread_attr_set/get_affinity - sets/gets the affinity field in a
rte_thread_attr_t object
rte_thread_set/get_affinity – sets/gets the affinity of a thread
**Errors**
As different platforms have different error codes, the approach here
is to translate the Windows error to POSIX-style ones to have
uniformity over the values returned.
**Future work**
The long term plan is for EAL to provide full threading support:
* Add support for conditional variables
* Additional functionality offered by pthread_*
(such as pthread_setname_np, etc.)
v18:
- Squash unit tests in corresponding patches.
- Prevent priority to be set to realtime on non-Windows systems.
- Use already existing affinity function in rte_thread_create()
v17:
- Move unrelated changes to the correct patch.
- Rename RTE_STATIC_MUTEX to avoid confusion, since
the mutex is still dynamically initialized behind the scenes.
- Break down the unit tests into smaller patches and reorder them.
- Remove duplicated code in header
- Improve commit messages and cover letter.
v16:
- Fix warning on freebsd by adding cast
- Change affinity unit test to consider ases when the requested CPU
are not available on the system.
- Fix priority unit test to avoid termination of thread before the
priority is checked.
v15:
- Add try_lock mutex functionality. If the mutex is already owned by a
different thread, the function returns immediately. Otherwise,
the mutex will be acquired.
- Add function for getting the priority of a thread.
An auxiliary function that translates the OS priority to the
EAL accepted ones is added.
- Fix unit tests logging, add descriptive asserts that mark test failures.
Verify mutex locking, verify barrier return values. Add test for
statically initialized mutexes.
- Fix Alpine build by removing the use of pthread_attr_set_affinity() and
using pthread_set_affinity() after the thread is created.
v14:
- Remove patch "eal: add EAL argument for setting thread priority"
This will be added later when enabling the new threading API.
- Remove priority enum value "_UNDEFINED". NORMAL is used
as the default.
- Fix issue with thread return value.
v13:
- Fix syntax error in unit tests
v12:
- Fix freebsd warning about initializer in unit tests
v11:
- Add unit tests for thread API
- Rebase
v10:
- Remove patch no. 10. It will be broken down in subpatches
and sent as a different patchset that depends on this one.
This is done due to the ABI breaks that would be caused by patch 10.
- Replace unix/rte_thread.c with common/rte_thread.c
- Remove initializations that may prevent compiler from issuing useful
warnings.
- Remove rte_thread_types.h and rte_windows_thread_types.h
- Remove unneeded priority macros (EAL_THREAD_PRIORITY*)
- Remove functions that retrieves thread handle from process handle
- Remove rte_thread_cancel() until same behavior is obtained on
all platforms.
- Fix rte_thread_detach() function description,
return value and remove empty line.
- Reimplement mutex functions. Add compatible representation for mutex
identifier. Add macro to replace static mutex initialization instances.
- Fix commit messages (lines too long, remove unicode symbols)
v9:
- Sign patches
v8:
- Rebase
- Add rte_thread_detach() API
- Set default priority, when user did not specify a value
v7:
Based on DmitryK's review:
- Change thread id representation
- Change mutex id representation
- Implement static mutex inititalizer for Windows
- Change barrier identifier representation
- Improve commit messages
- Add missing doxygen comments
- Split error translation function
- Improve name for affinity function
- Remove cpuset_size parameter
- Fix eal_create_cpu_map function
- Map EAL priority values to OS specific values
- Add thread wrapper for start routine
- Do not export rte_thread_cancel() on Windows
- Cleanup, fix comments, fix typos.
v6:
- improve error-translation function
- call the error translation function in rte_thread_value_get()
v5:
- update cover letter with more details on the priority argument
v4:
- fix function description
- rebase
v3:
- rebase
v2:
- revert changes that break ABI
- break up changes into smaller patches
- fix coding style issues
- fix issues with errors
- fix parameter type in examples/kni.c
Narcisa Vasile (8):
eal: add basic threading functions
eal: add thread attributes
eal/windows: translate Windows errors to errno-style errors
eal: implement functions for thread affinity management
eal: implement thread priority management functions
eal: add thread lifetime management
eal: implement functions for thread barrier management
eal: implement functions for mutex management
app/test/meson.build | 2 +
app/test/test_threads.c | 372 ++++++++++++++++++
lib/eal/common/meson.build | 1 +
lib/eal/common/rte_thread.c | 511 +++++++++++++++++++++++++
lib/eal/include/rte_thread.h | 412 +++++++++++++++++++-
lib/eal/unix/meson.build | 1 -
lib/eal/unix/rte_thread.c | 92 -----
lib/eal/version.map | 22 ++
lib/eal/windows/eal_lcore.c | 176 ++++++---
lib/eal/windows/eal_windows.h | 10 +
lib/eal/windows/include/sched.h | 2 +-
lib/eal/windows/rte_thread.c | 656 ++++++++++++++++++++++++++++++--
12 files changed, 2084 insertions(+), 173 deletions(-)
create mode 100644 app/test/test_threads.c
create mode 100644 lib/eal/common/rte_thread.c
delete mode 100644 lib/eal/unix/rte_thread.c
--
2.31.0.vfs.0.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v18 2/8] eal: add thread attributes
2021-11-11 1:33 ` [PATCH v18 0/8] " Narcisa Ana Maria Vasile
@ 2021-11-11 1:33 ` Narcisa Ana Maria Vasile
0 siblings, 0 replies; 6+ messages in thread
From: Narcisa Ana Maria Vasile @ 2021-11-11 1:33 UTC (permalink / raw)
To: dev, thomas, dmitry.kozliuk, khot, navasile, dmitrym, roretzla,
talshn, ocardona
Cc: bruce.richardson, david.marchand, pallavi.kadam
From: Narcisa Vasile <navasile@microsoft.com>
Implement thread attributes for:
* thread affinity
* thread priority
Implement functions for managing thread attributes.
Priority is represented through an enum that allows for two levels:
- RTE_THREAD_PRIORITY_NORMAL
- RTE_THREAD_PRIORITY_REALTIME_CRITICAL
Affinity is described by the rte_cpuset_t type.
An rte_thread_attr_t object can be set to the default values
by calling rte_thread_attr_init().
Signed-off-by: Narcisa Vasile <navasile@microsoft.com>
---
lib/eal/common/rte_thread.c | 46 ++++++++++++++++++
lib/eal/include/rte_thread.h | 91 ++++++++++++++++++++++++++++++++++++
lib/eal/version.map | 4 ++
lib/eal/windows/rte_thread.c | 44 +++++++++++++++++
4 files changed, 185 insertions(+)
diff --git a/lib/eal/common/rte_thread.c b/lib/eal/common/rte_thread.c
index 92a7451b0a..27ad1c7eb0 100644
--- a/lib/eal/common/rte_thread.c
+++ b/lib/eal/common/rte_thread.c
@@ -9,6 +9,7 @@
#include <string.h>
#include <rte_common.h>
+#include <rte_debug.h>
#include <rte_errno.h>
#include <rte_log.h>
#include <rte_thread.h>
@@ -33,6 +34,51 @@ rte_thread_equal(rte_thread_t t1, rte_thread_t t2)
return pthread_equal((pthread_t)t1.opaque_id, (pthread_t)t2.opaque_id);
}
+int
+rte_thread_attr_init(rte_thread_attr_t *attr)
+{
+ RTE_VERIFY(attr != NULL);
+
+ CPU_ZERO(&attr->cpuset);
+ attr->priority = RTE_THREAD_PRIORITY_NORMAL;
+
+ return 0;
+}
+
+int
+rte_thread_attr_set_affinity(rte_thread_attr_t *thread_attr,
+ rte_cpuset_t *cpuset)
+{
+ RTE_VERIFY(thread_attr != NULL);
+ RTE_VERIFY(cpuset != NULL);
+
+ thread_attr->cpuset = *cpuset;
+
+ return 0;
+}
+
+int
+rte_thread_attr_get_affinity(rte_thread_attr_t *thread_attr,
+ rte_cpuset_t *cpuset)
+{
+ RTE_VERIFY(thread_attr != NULL);
+ RTE_VERIFY(cpuset != NULL);
+
+ *cpuset = thread_attr->cpuset;
+
+ return 0;
+}
+
+int
+rte_thread_attr_set_priority(rte_thread_attr_t *thread_attr,
+ enum rte_thread_priority priority)
+{
+ RTE_VERIFY(thread_attr != NULL);
+
+ thread_attr->priority = priority;
+ return 0;
+}
+
int
rte_thread_key_create(rte_thread_key *key, void (*destructor)(void *))
{
diff --git a/lib/eal/include/rte_thread.h b/lib/eal/include/rte_thread.h
index c9cdeb07aa..8a20215a94 100644
--- a/lib/eal/include/rte_thread.h
+++ b/lib/eal/include/rte_thread.h
@@ -31,6 +31,28 @@ typedef struct rte_thread_tag {
uintptr_t opaque_id; /**< thread identifier */
} rte_thread_t;
+/**
+ * Thread priority values.
+ */
+enum rte_thread_priority {
+ RTE_THREAD_PRIORITY_NORMAL = 0,
+ /**< normal thread priority, the default */
+ RTE_THREAD_PRIORITY_REALTIME_CRITICAL = 1,
+ /**< highest thread priority allowed */
+};
+
+#ifdef RTE_HAS_CPUSET
+
+/**
+ * Representation for thread attributes.
+ */
+typedef struct {
+ enum rte_thread_priority priority; /**< thread priority */
+ rte_cpuset_t cpuset; /**< thread affinity */
+} rte_thread_attr_t;
+
+#endif /* RTE_HAS_CPUSET */
+
/**
* TLS key type, an opaque pointer.
*/
@@ -63,6 +85,75 @@ int rte_thread_equal(rte_thread_t t1, rte_thread_t t2);
#ifdef RTE_HAS_CPUSET
+/**
+ * Initialize the attributes of a thread.
+ * These attributes can be passed to the rte_thread_create() function
+ * that will create a new thread and set its attributes according to attr.
+ *
+ * @param attr
+ * Thread attributes to initialize.
+ *
+ * @return
+ * On success, return 0.
+ * On failure, return a positive errno-style error number.
+ */
+__rte_experimental
+int rte_thread_attr_init(rte_thread_attr_t *attr);
+
+/**
+ * Set the CPU affinity value in the thread attributes pointed to
+ * by 'thread_attr'.
+ *
+ * @param thread_attr
+ * Points to the thread attributes in which affinity will be updated.
+ *
+ * @param cpuset
+ * Points to the value of the affinity to be set.
+ *
+ * @return
+ * On success, return 0.
+ * On failure, return a positive errno-style error number.
+ */
+__rte_experimental
+int rte_thread_attr_set_affinity(rte_thread_attr_t *thread_attr,
+ rte_cpuset_t *cpuset);
+
+/**
+ * Get the value of CPU affinity that is set in the thread attributes pointed
+ * to by 'thread_attr'.
+ *
+ * @param thread_attr
+ * Points to the thread attributes from which affinity will be retrieved.
+ *
+ * @param cpuset
+ * Pointer to the memory that will store the affinity.
+ *
+ * @return
+ * On success, return 0.
+ * On failure, return a positive errno-style error number.
+ */
+__rte_experimental
+int rte_thread_attr_get_affinity(rte_thread_attr_t *thread_attr,
+ rte_cpuset_t *cpuset);
+
+/**
+ * Set the thread priority value in the thread attributes pointed to
+ * by 'thread_attr'.
+ *
+ * @param thread_attr
+ * Points to the thread attributes in which priority will be updated.
+ *
+ * @param priority
+ * Points to the value of the priority to be set.
+ *
+ * @return
+ * On success, return 0.
+ * On failure, return a positive errno-style error number.
+ */
+__rte_experimental
+int rte_thread_attr_set_priority(rte_thread_attr_t *thread_attr,
+ enum rte_thread_priority priority);
+
/**
* Set core affinity of the current thread.
* Support both EAL and non-EAL thread and update TLS.
diff --git a/lib/eal/version.map b/lib/eal/version.map
index 24e9747795..3fc33fcd70 100644
--- a/lib/eal/version.map
+++ b/lib/eal/version.map
@@ -423,6 +423,10 @@ EXPERIMENTAL {
rte_thread_self;
rte_thread_equal;
+ rte_thread_attr_init;
+ rte_thread_attr_get_affinity;
+ rte_thread_attr_set_affinity;
+ rte_thread_attr_set_priority;
};
INTERNAL {
diff --git a/lib/eal/windows/rte_thread.c b/lib/eal/windows/rte_thread.c
index 26c8dd4ebe..f65919f46d 100644
--- a/lib/eal/windows/rte_thread.c
+++ b/lib/eal/windows/rte_thread.c
@@ -4,6 +4,7 @@
*/
#include <rte_common.h>
+#include <rte_debug.h>
#include <rte_errno.h>
#include <rte_thread.h>
#include <rte_windows.h>
@@ -28,6 +29,49 @@ rte_thread_equal(rte_thread_t t1, rte_thread_t t2)
return t1.opaque_id == t2.opaque_id;
}
+int
+rte_thread_attr_init(rte_thread_attr_t *attr)
+{
+ RTE_VERIFY(attr != NULL);
+
+ attr->priority = RTE_THREAD_PRIORITY_NORMAL;
+ CPU_ZERO(&attr->cpuset);
+
+ return 0;
+}
+
+int
+rte_thread_attr_set_affinity(rte_thread_attr_t *thread_attr,
+ rte_cpuset_t *cpuset)
+{
+ RTE_VERIFY(thread_attr != NULL);
+ thread_attr->cpuset = *cpuset;
+
+ return 0;
+}
+
+int
+rte_thread_attr_get_affinity(rte_thread_attr_t *thread_attr,
+ rte_cpuset_t *cpuset)
+{
+ RTE_VERIFY(thread_attr != NULL);
+
+ *cpuset = thread_attr->cpuset;
+
+ return 0;
+}
+
+int
+rte_thread_attr_set_priority(rte_thread_attr_t *thread_attr,
+ enum rte_thread_priority priority)
+{
+ RTE_VERIFY(thread_attr != NULL);
+
+ thread_attr->priority = priority;
+
+ return 0;
+}
+
int
rte_thread_key_create(rte_thread_key *key,
__rte_unused void (*destructor)(void *))
--
2.31.0.vfs.0.1
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2022-02-06 3:45 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-04 19:21 [PATCH v18 2/8] eal: add thread attributes Ananyev, Konstantin
2022-02-05 4:41 ` Tyler Retzlaff
2022-02-05 9:00 ` Thomas Monjalon
2022-02-06 3:45 ` Tyler Retzlaff
2022-02-05 12:51 ` Ananyev, Konstantin
-- strict thread matches above, loose matches on Subject: below --
2021-11-10 3:01 [dpdk-dev] [PATCH v17 00/13] eal: Add EAL API for threading Narcisa Ana Maria Vasile
2021-11-11 1:33 ` [PATCH v18 0/8] " Narcisa Ana Maria Vasile
2021-11-11 1:33 ` [PATCH v18 2/8] eal: add thread attributes Narcisa Ana Maria Vasile
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).