On Wed, Dec 21, 2022 at 05:12:54PM +0100, David Marchand wrote:
> On Sun, Dec 18, 2022 at 11:01 AM Morten Brørup <m...@smartsharesystems.com> 
> wrote:
> >
> > This RFC introduces per-thread constructors/destructors:
> > * Per-thread constructors are functions called as the first thing from 
> > newly created threads. This can be used to initialize variables in 
> > thread-local storage, variables depending on the (tid_t) thread id, and to 
> > call setup functions that must be called from the thread itself.
> > * Per-thread destructors are functions called (from the thread) as the last 
> > thing when a thread ends.
> >
> > At this time, I am seeking feedback on the concept and the proposed 
> > limitations.
> >
> > Processes have __attribute__(constructor/destructor) to set up functions to 
> > be called before main(). Nothing similar exists for threads, so we have to 
> > design it ourselves.
> >
> > The proposed per-thread constructors/destructors should not apply to all 
> > threads - only to threads created through the DPDK threads API. Agree?

i'm not sure what threads you mean here, but i guess you mean only
threads created with rte_thread_create? so this excludes the ``main''
thread and any threads created by the application via any other api that
causes a thread to be created? - seems reasonable.

> >
> > DPDK has the RTE_INIT()/RTE_FINI() macros for adding process 
> > constructors/destructors at build time, so I propose a similar API, i.e. 
> > adding RTE_THREAD_INIT() and RTE_THREAD_FINI() macros to build a list of 
> > per-thread constructors and destructors at build time.
> >
> > Two functions that call the list of per-thread constructors respectively 
> > destructors will be introduced.
> >
> > The per-thread constructor function will be called from the newly created 
> > threads within DPDK:
> > 1. EAL/SERVICE threads: In eal_thread_loop() before the loop.
> > 2. CTRL threads: In ctrl_thread_init() before start_routine().
> > 3. Non-EAL threads: In rte_thread_register().
> >
> > Are any thread types missing in the list above?
> 
> I noticed a few drivers doing stuff behind EAL back.. you might want
> to grep pthread_create.
> They should probably be converted to control threads, or if there is a
> reason, it could give more inputs on this topic.

yes, there are drivers that probably pre-date the rte_ctrl_thread_create
api that ought to be converted to using rte_ctrl_thread_create or
ideally (if we can get more review / merged) the series where i have
added the rte_control_thread_create api that operates with rte_thread_t.

> 
> 
> >
> >
> > The per-thread destructor function will also be registered by the 
> > per-thread constructor, using the POSIX pthread_cleanup_push() function.
> 
> What about Windows?
> Cc: Tyler.

yes, i had noticed this rfc and haven't had time to research properly to
respond. in principal it seems like something that would be useful.

in general if it is going to be part of eal we need to understand if
the functionality can be feasibly provided for all supported platforms
otherwise it doesn't belong in the abstraction layer.

so long as it can be consistently provided on windows i certainly have
no objection and if a windows implementation and working unit test is
present i'm happy to prioritize review and testing to facilitate the
work.

i appreciate any assistance given that moves the windows port closer
to parity with linux/freebsd.

thanks!

ty

Reply via email to