From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by dpdk.org (Postfix) with ESMTP id 1DD991B4EE for ; Tue, 26 Jun 2018 13:53:30 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Jun 2018 04:53:26 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,274,1526367600"; d="scan'208";a="67369631" Received: from aburakov-mobl.ger.corp.intel.com (HELO [10.237.220.28]) ([10.237.220.28]) by fmsmga001.fm.intel.com with ESMTP; 26 Jun 2018 04:53:24 -0700 To: Qi Zhang , thomas@monjalon.net Cc: konstantin.ananyev@intel.com, dev@dpdk.org, bruce.richardson@intel.com, ferruh.yigit@intel.com, benjamin.h.shelton@intel.com, narender.vangati@intel.com References: <20180607123849.14439-1-qi.z.zhang@intel.com> <20180626070832.3055-1-qi.z.zhang@intel.com> <20180626070832.3055-5-qi.z.zhang@intel.com> From: "Burakov, Anatoly" Message-ID: <01fad681-5298-1c3a-715c-d421e7f692f7@intel.com> Date: Tue, 26 Jun 2018 12:53:23 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: <20180626070832.3055-5-qi.z.zhang@intel.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Subject: Re: [dpdk-dev] [PATCH v4 04/24] eal: enable multi process init callback X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 26 Jun 2018 11:53:31 -0000 On 26-Jun-18 8:08 AM, Qi Zhang wrote: > Introduce new API rte_eal_register_mp_init that help to register > a callback function which will be invoked right after multi-process > channel be established (rte_mp_channel_init). Typically the API > will be used by other module that want it's mp channel action callbacks > can be registered during rte_eal_init automatically. > > Signed-off-by: Qi Zhang > --- > lib/librte_eal/common/eal_common_proc.c | 51 ++++++++++++++++++++++++++++++++- > lib/librte_eal/common/eal_private.h | 5 ++++ > lib/librte_eal/common/include/rte_eal.h | 34 ++++++++++++++++++++++ > lib/librte_eal/linuxapp/eal/eal.c | 2 ++ > 4 files changed, 91 insertions(+), 1 deletion(-) > > diff --git a/lib/librte_eal/common/eal_common_proc.c b/lib/librte_eal/common/eal_common_proc.c > index 707d8ab30..fc0eb4d17 100644 > --- a/lib/librte_eal/common/eal_common_proc.c > +++ b/lib/librte_eal/common/eal_common_proc.c > @@ -619,6 +619,42 @@ unlink_sockets(const char *filter) > return 0; > } > > +struct mp_init_entry { > + TAILQ_ENTRY(mp_init_entry) next; > + rte_eal_mp_init_callback_t callback; > +}; > + > +TAILQ_HEAD(mp_init_entry_list, mp_init_entry); > +static struct mp_init_entry_list mp_init_entry_list = > + TAILQ_HEAD_INITIALIZER(mp_init_entry_list); > + > +static int process_mp_init_callbacks(void) > +{ > + struct mp_init_entry *entry; > + int ret; > + > + TAILQ_FOREACH(entry, &mp_init_entry_list, next) { > + ret = entry->callback(); > + if (ret) > + return ret; > + } > + return 0; > +} > + > +int __rte_experimental > +rte_eal_register_mp_init(rte_eal_mp_init_callback_t callback) > +{ > + struct mp_init_entry *entry = calloc(1, sizeof(struct mp_init_entry)); > + > + if (entry == NULL) > + return -ENOMEM; > + > + entry->callback = callback; > + TAILQ_INSERT_TAIL(&mp_init_entry_list, entry, next); > + > + return 0; > +} > + > int > rte_mp_channel_init(void) > { > @@ -686,7 +722,20 @@ rte_mp_channel_init(void) > flock(dir_fd, LOCK_UN); > close(dir_fd); > > - return 0; > + return process_mp_init_callbacks(); > +} > + Perhaps some kind of log message in case of failure would be useful? Otherwise this failure would be pretty silent - neither process_mp_init_callbacks() nor rte_mp_channel_init() logs any errors. > +void rte_mp_init_callback_cleanup(void) > +{ > + struct mp_init_entry *entry; > + > + while (!TAILQ_EMPTY(&mp_init_entry_list)) { > + TAILQ_FOREACH(entry, &mp_init_entry_list, next) { > + TAILQ_REMOVE(&mp_init_entry_list, entry, next); > + free(entry); > + break; > + } > + } > } > > /** > diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h > index bdadc4d50..bc230ee23 100644 > --- a/lib/librte_eal/common/eal_private.h > +++ b/lib/librte_eal/common/eal_private.h > @@ -247,6 +247,11 @@ struct rte_bus *rte_bus_find_by_device_name(const char *str); > int rte_mp_channel_init(void); > > /** > + * Cleanup all mp channel init callbacks. > + */ > +void rte_mp_init_callback_cleanup(void); This is a good idea, however i should note that none of the other services (EAL or otherwise) clean up after themselves. They leave open file descriptors, malloc'd memory etc. all over the place. Maybe this is something to fix for the future... > + > +/** > * Internal Executes all the user application registered callbacks for > * the specific device. It is for DPDK internal user only. User > * application should not call it directly. > diff --git a/lib/librte_eal/common/include/rte_eal.h b/lib/librte_eal/common/include/rte_eal.h > index 8de5d69e8..506f17f34 100644 > --- a/lib/librte_eal/common/include/rte_eal.h > +++ b/lib/librte_eal/common/include/rte_eal.h > @@ -512,6 +512,40 @@ __rte_deprecated > const char * > rte_eal_mbuf_default_mempool_ops(void); Otherwise, Acked-by: Anatoly Burakov -- Thanks, Anatoly