DPDK patches and discussions
 help / color / mirror / Atom feed
From: "Mattias Rönnblom" <mattias.ronnblom@ericsson.com>
To: "David Marchand" <david.marchand@redhat.com>,
	"Morten Brørup" <mb@smartsharesystems.com>
Cc: "dev@dpdk.org" <dev@dpdk.org>,
	Tyler Retzlaff <roretzla@linux.microsoft.com>
Subject: Re: [RFC] eal: per-thread constructors/destructors
Date: Wed, 21 Dec 2022 18:56:10 +0000	[thread overview]
Message-ID: <b7b74caa-fec0-e1fe-f20b-fa17530e5c7e@ericsson.com> (raw)
In-Reply-To: <CAJFAV8wfiAX2O9LyPKjp0bgS1d6FL1dDaJodCTqwLUPu-5WeBQ@mail.gmail.com>

On 2022-12-21 17:12, David Marchand wrote:
> On Sun, Dec 18, 2022 at 11:01 AM Morten Brørup <mb@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?
>>
>> 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.
> 
> 
>>
>>
>> The per-thread destructor function will also be registered by the per-thread constructor, using the POSIX pthread_cleanup_push() function.
> 
> What about Windows?

I don't think there's a need to involve pthread_cleanup_push(). For 
DPDK-created threads, EAL could run the destructor in a wrapper 
function. The main lcore's fini callbacks could be run in rte_eal_cleanup().

> Cc: Tyler.
> 
>  >>
>>
>> Examples of where per-thread constructors are useful:
>> PRNG state initialization [1]: http://inbox.dpdk.org/dev/2a5121c7-369f-afde-0898-d45a5b368c3a@ericsson.com/
>> PMU event setup [2]: http://inbox.dpdk.org/dev/a059c403-8c6c-79c3-c3e9-a8c1815f5a14@ericsson.com/T/#m3d29fbc301059f007425ac148a4113e66d2ef983
>>
>>
>> Please also refer to the discussion [3] about lcore init callbacks for further thoughts. Especially the de-facto inability to establish constructors/destructors at runtime.
>>
>> [3]: http://inbox.dpdk.org/dev/98CBD80474FA8B44BF855DF32C47DC35D875B6@smartserver.smartshare.dk/T/#m23b9a930a4050dc6b0305d3653754bd152c09ab7
> 
> 
> 


      parent reply	other threads:[~2022-12-21 18:56 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-18 10:01 Morten Brørup
2022-12-19 15:53 ` Mattias Rönnblom
2022-12-21 16:12 ` David Marchand
2022-12-21 17:54   ` Tyler Retzlaff
2022-12-21 18:56   ` Mattias Rönnblom [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b7b74caa-fec0-e1fe-f20b-fa17530e5c7e@ericsson.com \
    --to=mattias.ronnblom@ericsson.com \
    --cc=david.marchand@redhat.com \
    --cc=dev@dpdk.org \
    --cc=mb@smartsharesystems.com \
    --cc=roretzla@linux.microsoft.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).