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 75785A034C; Wed, 21 Dec 2022 17:13:09 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 18AB740A7F; Wed, 21 Dec 2022 17:13:09 +0100 (CET) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mails.dpdk.org (Postfix) with ESMTP id 307F440A7A for ; Wed, 21 Dec 2022 17:13:08 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671639187; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sj0WJF1DWqKaopU4NqZmKP2TdrnXp5IbkSETWEb55Fg=; b=F2TVr4ujdfJ4ItBJclZ9P/Y7t4wWybSmbN60/KpZABrlLgWK1yxn5qX50WPC1hQIXf01RM 8Hn2zJzZV8v1Auk0vQHynXqy5OHfM4JKp5Drd74QC8rYWwfJ3zWkBQ93DQrzHvMETwG37r 7jss+cfqrjdVMR/v+arYwctIWBIpRVg= Received: from mail-pf1-f199.google.com (mail-pf1-f199.google.com [209.85.210.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-365-T0mSsXUnNDeWXFpo0P1CQg-1; Wed, 21 Dec 2022 11:13:06 -0500 X-MC-Unique: T0mSsXUnNDeWXFpo0P1CQg-1 Received: by mail-pf1-f199.google.com with SMTP id t16-20020aa79390000000b0057fd4bf27fbso4960740pfe.4 for ; Wed, 21 Dec 2022 08:13:06 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sj0WJF1DWqKaopU4NqZmKP2TdrnXp5IbkSETWEb55Fg=; b=4i5AaqYMWN+3vXpyzcYLvfSN5NXawGsPMkUQ6aPLknauhdqwxFnx/S2y9pW7GhnC8N 1zn7Zn50katTgBqZDn4MKI7HJdbRZxdjdPwJMmksdopdS5Zf/Z+a6CcLujC3ZGICrHlx Km/9pqFhSJX9YkdqBSnLVAq3m7aR+VIMUR6JyTymr7Oo5/jAkSjDgd0I/VXCmH1tGp9V +amN/jk2T9VR8n7FYD2xbD/cQwJTd6WIuHmc9ZygEoTJDFwGj2fFshBeA+VtyJWnDdP9 PuZWcvu0EsAI64oRDyh5AA34rY7/zdBMds0ngOWRBef8mcJoGy2r9oNJqMIFa0C7z7QX FdsQ== X-Gm-Message-State: AFqh2kqrve92t4R3UnGd46b6zaBFUJV4pPCSJ7vErEKBKvIy5eLvs45/ PrTJe2PwHUXQU/t/ZAd+k98TnX2FwvUyonIh+qSIimpg4/H3QH1ma7J7undBN3TuhQocslvQWsp Lpt3vOAvSUVe1oYmZwGU= X-Received: by 2002:a17:90a:6e48:b0:218:8f4:bad5 with SMTP id s8-20020a17090a6e4800b0021808f4bad5mr228601pjm.55.1671639185459; Wed, 21 Dec 2022 08:13:05 -0800 (PST) X-Google-Smtp-Source: AMrXdXuegPUMPhTNjwf24LOsFsP97qKuOyTUtShVrec2XnJQuphiOhZS7+MVmm0f0xMsLPWH+1+EBTNMapVBzlTh5hc= X-Received: by 2002:a17:90a:6e48:b0:218:8f4:bad5 with SMTP id s8-20020a17090a6e4800b0021808f4bad5mr228598pjm.55.1671639185155; Wed, 21 Dec 2022 08:13:05 -0800 (PST) MIME-Version: 1.0 References: <98CBD80474FA8B44BF855DF32C47DC35D875C4@smartserver.smartshare.dk> In-Reply-To: <98CBD80474FA8B44BF855DF32C47DC35D875C4@smartserver.smartshare.dk> From: David Marchand Date: Wed, 21 Dec 2022 17:12:54 +0100 Message-ID: Subject: Re: [RFC] eal: per-thread constructors/destructors To: =?UTF-8?Q?Morten_Br=C3=B8rup?= Cc: dev@dpdk.org, mattias.ronnblom@ericsson.com, Tyler Retzlaff X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 On Sun, Dec 18, 2022 at 11:01 AM Morten Br=C3=B8rup wrote: > > This RFC introduces per-thread constructors/destructors: > * Per-thread constructors are functions called as the first thing from ne= wly created threads. This can be used to initialize variables in thread-loc= al 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 la= st thing when a thread ends. > > At this time, I am seeking feedback on the concept and the proposed limit= ations. > > 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_THR= EAD_INIT() and RTE_THREAD_FINI() macros to build a list of per-thread const= ructors 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-thr= ead constructor, using the POSIX pthread_cleanup_push() function. What about Windows? Cc: Tyler. > > > Examples of where per-thread constructors are useful: > PRNG state initialization [1]: http://inbox.dpdk.org/dev/2a5121c7-369f-af= de-0898-d45a5b368c3a@ericsson.com/ > PMU event setup [2]: http://inbox.dpdk.org/dev/a059c403-8c6c-79c3-c3e9-a8= c1815f5a14@ericsson.com/T/#m3d29fbc301059f007425ac148a4113e66d2ef983 > > > Please also refer to the discussion [3] about lcore init callbacks for fu= rther thoughts. Especially the de-facto inability to establish constructors= /destructors at runtime. > > [3]: http://inbox.dpdk.org/dev/98CBD80474FA8B44BF855DF32C47DC35D875B6@sma= rtserver.smartshare.dk/T/#m23b9a930a4050dc6b0305d3653754bd152c09ab7 --=20 David Marchand