From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id CEB6AA034C; Sun, 18 Dec 2022 11:01:17 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6A1B540A7A; Sun, 18 Dec 2022 11:01:17 +0100 (CET) Received: from smartserver.smartsharesystems.com (smartserver.smartsharesystems.com [77.243.40.215]) by mails.dpdk.org (Postfix) with ESMTP id A39A440685 for ; Sun, 18 Dec 2022 11:01:15 +0100 (CET) Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Subject: [RFC] eal: per-thread constructors/destructors X-MimeOLE: Produced By Microsoft Exchange V6.5 Date: Sun, 18 Dec 2022 11:01:12 +0100 Message-ID: <98CBD80474FA8B44BF855DF32C47DC35D875C4@smartserver.smartshare.dk> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: [RFC] eal: per-thread constructors/destructors Thread-Index: AdkSx6jT3XE7mP79Qhq+AVV4Hy4BJw== From: =?iso-8859-1?Q?Morten_Br=F8rup?= To: Cc: , X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org 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? The per-thread destructor function will also be registered by the = per-thread constructor, using the POSIX pthread_cleanup_push() function. Examples of where per-thread constructors are useful: PRNG state initialization [1]: = http://inbox.dpdk.org/dev/2a5121c7-369f-afde-0898-d45a5b368c3a@ericsson.c= om/ PMU event setup [2]: = http://inbox.dpdk.org/dev/a059c403-8c6c-79c3-c3e9-a8c1815f5a14@ericsson.c= om/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@smartser= ver.smartshare.dk/T/#m23b9a930a4050dc6b0305d3653754bd152c09ab7 Med venlig hilsen / Kind regards, -Morten Br=F8rup