From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id B2F9DA0350; Mon, 29 Jun 2020 14:46:14 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 22C9D1BE98; Mon, 29 Jun 2020 14:46:13 +0200 (CEST) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by dpdk.org (Postfix) with ESMTP id CA6BF1B9BF for ; Mon, 29 Jun 2020 14:46:10 +0200 (CEST) IronPort-SDR: pER3OcSNN0RWZApSMuyVDJ7hd9ESTXx/DpWvKC1qK+Bq455UvoMW8rE5oISLjAtRdT/7UEW0YX VF5tGo2SWrKw== X-IronPort-AV: E=McAfee;i="6000,8403,9666"; a="230782822" X-IronPort-AV: E=Sophos;i="5.75,294,1589266800"; d="scan'208";a="230782822" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Jun 2020 05:46:09 -0700 IronPort-SDR: hoBi0sKUuAqc9bfBnHJ1cdc9IwevFfEFN52labJs87FqKfXSUyvlAobP4qbHYoWe4CcRyLDyI+ VeAPMBIhGAoQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,294,1589266800"; d="scan'208";a="355445844" Received: from orsmsx109.amr.corp.intel.com ([10.22.240.7]) by orsmga001.jf.intel.com with ESMTP; 29 Jun 2020 05:46:09 -0700 Received: from ORSEDG001.ED.cps.intel.com (10.7.248.4) by ORSMSX109.amr.corp.intel.com (10.22.240.7) with Microsoft SMTP Server (TLS) id 14.3.439.0; Mon, 29 Jun 2020 05:46:08 -0700 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (104.47.58.109) by edgegateway.intel.com (134.134.137.100) with Microsoft SMTP Server (TLS) id 14.3.439.0; Mon, 29 Jun 2020 05:46:08 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EAD8Z1RQs7L2Lg49A1E2rYt7QR46cvYOWmeLl90aNizN2GnSb1O76Mci16RxZPM1138voQ1MEdvr2lA2qpX2Iydh8GhsxW847hE/uUXkIx1PW40vKlo1RVSY860h4UvFYnTcUJoDBu04Iixu/X+SSXMpSB4KuP7tVguUYElxcfKfCroHFHDl41Dwjldc8AHhE/WbG7fXPrdsR+7DsV0JZTl4csvQChY1qV4JgtDvjnV4FcfTGQt7DLMc2a3wGC1J0liiEjYqjL1o0yyl9PK8Km42znC5N9H5tu6jKOVGaJF1n/O7Dy/ehSGuGHszmxm1Sgt4OSzk/YGvh9NjL3Dsjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Nr2FkmbppYPoxZgTg6TZP2Q1Y48ruoQ5D6N9XALMKtY=; b=nVwoHyGHkTHAbMXk1sv3wMRcld0v1s2uY2k31PMwfnHHrWGBsauRFYSQ0jvNvTCxEPnEdRoaUuVAYsUYPa95/YYB3MhWNuhfBsDBoSsiNGaLZGnBqWle5sFiq+y+vpjmVQSBmGwaAwjhBOPrnAkNR6EkjypOLNQaC1NyvH0OGyJgn+sAwywx9YExosKifO7QFc4QKKJE80j3eVtzBO6SJKfIFqDaTFQbHffSSOine3IxtS76oInddX6yCuiwHs5ry34UogPmaGtYzuaovVaYTZthLlEsIfW49LfAvrlZWjAoUKNPUqk/Y+R/2PlCjZOFhR2VZkTLtBK4Lycy7V+8qQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.onmicrosoft.com; s=selector2-intel-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Nr2FkmbppYPoxZgTg6TZP2Q1Y48ruoQ5D6N9XALMKtY=; b=rR29MFkd8ATuu7lWwOdi11kgWy8kul/6ecmP6Zxz/D/ek04Ubm1EaZlgBcdbiUjxqUSY53FVkATruX1EDRBVZC+qyK7MSGhf5uKOW/IQzoLVkGfiaLti5vcnb9jrBT+oOqbuXWXBt54xSzwQcNzCobPt6vcsoUIVw6JBw2CovaM= Received: from BYAPR11MB3301.namprd11.prod.outlook.com (2603:10b6:a03:7f::26) by BY5PR11MB3894.namprd11.prod.outlook.com (2603:10b6:a03:18c::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3131.25; Mon, 29 Jun 2020 12:46:06 +0000 Received: from BYAPR11MB3301.namprd11.prod.outlook.com ([fe80::f160:29ab:b8f9:4189]) by BYAPR11MB3301.namprd11.prod.outlook.com ([fe80::f160:29ab:b8f9:4189%6]) with mapi id 15.20.3131.027; Mon, 29 Jun 2020 12:46:06 +0000 From: "Ananyev, Konstantin" To: David Marchand , "dev@dpdk.org" CC: "jerinjacobk@gmail.com" , "Richardson, Bruce" , "mdr@ashroe.eu" , "thomas@monjalon.net" , "arybchenko@solarflare.com" , "ktraynor@redhat.com" , "Stokes, Ian" , "i.maximets@ovn.org" , Neil Horman Thread-Topic: [dpdk-dev] [PATCH v4 7/9] eal: add lcore init callbacks Thread-Index: AQHWS8kvZ5FlRPH29Ui6gU2iaPl5tKjvfeag Date: Mon, 29 Jun 2020 12:46:06 +0000 Message-ID: References: <20200610144506.30505-1-david.marchand@redhat.com> <20200626144736.11011-1-david.marchand@redhat.com> <20200626144736.11011-8-david.marchand@redhat.com> In-Reply-To: <20200626144736.11011-8-david.marchand@redhat.com> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-reaction: no-action dlp-version: 11.2.0.6 authentication-results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=intel.com; x-originating-ip: [192.198.151.175] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 0cdda2a0-5e47-4e0f-2ea7-08d81c2a6427 x-ms-traffictypediagnostic: BY5PR11MB3894: x-ld-processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:46; x-forefront-prvs: 044968D9E1 x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: aeaqCP9dLUECOcRJZk9ntgxtQ/dvuL00BKJGvbDKykejGx2YhpJbR/bINRl0PxiBVfNPicNf3SIATK+zgXDLYS97YIBHh+oUHBZonHXUhvaxe/MFMrLsIsPfFqrdfjdu4jUa5ninSggv1i4nx7PHyGarAVt4vBoWVksWFghA5R7spHKW3Nsm5amhmscX9chXdEOMuNmPLCkavCNt/kpqFy3pFG45EYmqc3qHEzm5CLzBcvtUwA0OFGEFgKmIsp/gOiJKw1t/L2ixfHXQS3JvoxBSawd7IJruBOYGcyetunGmNYLlAPw9t6R/3X5M0PgrVeEZ06q2ogvSHeJSjzPq5Q== x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BYAPR11MB3301.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFTY:; SFS:(4636009)(346002)(396003)(39860400002)(376002)(366004)(136003)(83380400001)(6506007)(7696005)(316002)(54906003)(76116006)(110136005)(66476007)(66946007)(66446008)(64756008)(66556008)(26005)(186003)(86362001)(8676002)(71200400001)(2906002)(8936002)(478600001)(4326008)(55016002)(9686003)(52536014)(5660300002)(33656002); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata: is17s7O4/M/o+CaRpCAO3XQqvJuSGti8tOXn3mWIONQ2wWDH0yLYFkrc2uGVEmom89yO0XRq961eOl9+0UooBKZr44Pxu27UCjn/fnR2rXAjpl+gVf+zVYRLqaxPCRaUSjeBoIjCH2TVw1P9yuqtyeUEAxf8/lmGXDlX9AJHL16szEOIEsVbp1obvfNfLRwCWwCaIISWWkfHCqoqo2RLWBsel8ohba8063qoDiLXhOml2sybmtmgh+/OAEKsxGIJHiW/C5wxn8awBxL30lijg8SWryiTEBMZdoXBJstxdrB5d20Jw106oqzlHsK4GyXw+/itwRfrQp7j3XQz1kOudVYTZzmT9ToiDweuYyHsRcCpAHoNyN8joyQ6FEEmcEEX4SdPKKUOohQOof6+YLiEJ17NGJjzRW5o71hlgVTVrWJpktOp7wi8I89kzkn5891/MONM/IWHRHDWYCO5DwXauz6Hrbpp91M3IscjLmBODg92u3qKnOK+G2imhkufmD+S Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: BYAPR11MB3301.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0cdda2a0-5e47-4e0f-2ea7-08d81c2a6427 X-MS-Exchange-CrossTenant-originalarrivaltime: 29 Jun 2020 12:46:06.4180 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: ETcD9OmdCyxz/B8sJs9XPcoz/PFiSnR3UhILbpUS+4i9asjiipMaSCX8rkLhdfthM42kXA/1bGaK+XKq67snOsccPZ+5snpo5JPrLBOuYhI= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR11MB3894 X-OriginatorOrg: intel.com Subject: Re: [dpdk-dev] [PATCH v4 7/9] eal: add lcore init callbacks 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" =20 > diff --git a/lib/librte_eal/common/eal_common_lcore.c b/lib/librte_eal/co= mmon/eal_common_lcore.c > index a61824a779..52c46a4cea 100644 > --- a/lib/librte_eal/common/eal_common_lcore.c > +++ b/lib/librte_eal/common/eal_common_lcore.c > @@ -224,11 +224,114 @@ rte_socket_id_by_idx(unsigned int idx) > } >=20 > static rte_spinlock_t lcore_lock =3D RTE_SPINLOCK_INITIALIZER; > +struct lcore_callback { > + TAILQ_ENTRY(lcore_callback) next; > + char *name; > + rte_lcore_init_cb init; > + rte_lcore_uninit_cb uninit; > + void *arg; > +}; > +static TAILQ_HEAD(lcore_callbacks_head, lcore_callback) lcore_callbacks = =3D > + TAILQ_HEAD_INITIALIZER(lcore_callbacks); > + > +static int > +callback_init(struct lcore_callback *callback, unsigned int lcore_id) > +{ > + if (callback->init =3D=3D NULL) > + return 0; > + RTE_LOG(DEBUG, EAL, "Call init for lcore callback %s, lcore_id %u\n", > + callback->name, lcore_id); > + return callback->init(lcore_id, callback->arg); > +} > + > +static void > +callback_uninit(struct lcore_callback *callback, unsigned int lcore_id) > +{ > + if (callback->uninit =3D=3D NULL) > + return; > + RTE_LOG(DEBUG, EAL, "Call uninit for lcore callback %s, lcore_id %u\n", > + callback->name, lcore_id); > + callback->uninit(lcore_id, callback->arg); > +} > + > +void * > +rte_lcore_callback_register(const char *name, rte_lcore_init_cb init, > + rte_lcore_uninit_cb uninit, void *arg) > +{ > + struct rte_config *cfg =3D rte_eal_get_configuration(); > + struct lcore_callback *callback; > + unsigned int lcore_id; > + > + callback =3D calloc(1, sizeof(*callback)); > + if (callback =3D=3D NULL) > + return NULL; > + if (asprintf(&callback->name, "%s-%p", name, arg) =3D=3D -1) { If name is null, I presume asprintf() would segfault, right? As this is a public (and control-plane) API, I think it is worth to add formal checking for input parameters. Same for other new public functions.=20 > + free(callback); > + return NULL; > + } > + callback->init =3D init; > + callback->uninit =3D uninit; > + callback->arg =3D arg; > + rte_spinlock_lock(&lcore_lock); > + if (callback->init =3D=3D NULL) > + goto no_init; > + for (lcore_id =3D 0; lcore_id < RTE_MAX_LCORE; lcore_id++) { > + if (cfg->lcore_role[lcore_id] =3D=3D ROLE_OFF) > + continue; > + if (callback_init(callback, lcore_id) =3D=3D 0) > + continue; > + /* Callback refused init for this lcore, uninitialize all > + * previous lcore. > + */ > + for (; lcore_id !=3D 0; lcore_id--) { > + if (cfg->lcore_role[lcore_id - 1] =3D=3D ROLE_OFF) > + continue; > + callback_uninit(callback, lcore_id - 1); > + } Just as a nit, you can do here instead: while (lcore_id-- !=3D 0) { if (cfg->lcore_role[lcore_id] =3D=3D ROLE_OFF) = ...} To avoid 'lcore_id -1' inside loop body. Might look a bit nicer. > + free(callback); I think you forgot: free(callback->name); here. Might be worth to have a separate helper function around these 2 frees. > + callback =3D NULL; > + goto out; > + } > +no_init: > + TAILQ_INSERT_TAIL(&lcore_callbacks, callback, next); > + RTE_LOG(DEBUG, EAL, "Registered new lcore callback %s (%sinit, %suninit= ).\n", > + callback->name, callback->init =3D=3D NULL ? "NO " : "", > + callback->uninit =3D=3D NULL ? "NO " : ""); > +out: > + rte_spinlock_unlock(&lcore_lock); > + return callback; > +} > + > +void > +rte_lcore_callback_unregister(void *handle) > +{ > + struct rte_config *cfg =3D rte_eal_get_configuration(); > + struct lcore_callback *callback =3D handle; > + unsigned int lcore_id; > + > + rte_spinlock_lock(&lcore_lock); > + if (callback->uninit =3D=3D NULL) > + goto no_uninit; > + for (lcore_id =3D 0; lcore_id < RTE_MAX_LCORE; lcore_id++) { > + if (cfg->lcore_role[lcore_id] =3D=3D ROLE_OFF) > + continue; > + callback_uninit(callback, lcore_id); > + } > +no_uninit: > + TAILQ_REMOVE(&lcore_callbacks, callback, next); > + rte_spinlock_unlock(&lcore_lock); > + RTE_LOG(DEBUG, EAL, "Unregistered lcore callback %s-%p.\n", > + callback->name, callback->arg); > + free(callback->name); > + free(callback); > +} >=20 > unsigned int > eal_lcore_non_eal_allocate(void) > { > struct rte_config *cfg =3D rte_eal_get_configuration(); > + struct lcore_callback *callback; > + struct lcore_callback *prev; > unsigned int lcore_id; >=20 > if (cfg->process_type =3D=3D RTE_PROC_SECONDARY || > @@ -244,8 +347,29 @@ eal_lcore_non_eal_allocate(void) > cfg->lcore_count++; > break; > } > - if (lcore_id =3D=3D RTE_MAX_LCORE) > + if (lcore_id =3D=3D RTE_MAX_LCORE) { > RTE_LOG(DEBUG, EAL, "No lcore available.\n"); > + goto out; > + } > + TAILQ_FOREACH(callback, &lcore_callbacks, next) { > + if (callback_init(callback, lcore_id) =3D=3D 0) > + continue; > + /* Callback refused init for this lcore, call uninit for all > + * previous callbacks. > + */ > + prev =3D TAILQ_PREV(callback, lcore_callbacks_head, next); > + while (prev !=3D NULL) { > + callback_uninit(prev, lcore_id); > + prev =3D TAILQ_PREV(prev, lcore_callbacks_head, next); > + } > + RTE_LOG(DEBUG, EAL, "Initialization refused for lcore %u.\n", > + lcore_id); > + cfg->lcore_role[lcore_id] =3D ROLE_OFF; > + cfg->lcore_count--; > + lcore_id =3D RTE_MAX_LCORE; > + goto out; > + } > +out: > rte_spinlock_unlock(&lcore_lock); > return lcore_id; > } > @@ -254,11 +378,15 @@ void > eal_lcore_non_eal_release(unsigned int lcore_id) > { > struct rte_config *cfg =3D rte_eal_get_configuration(); > + struct lcore_callback *callback; >=20 > rte_spinlock_lock(&lcore_lock); > - if (cfg->lcore_role[lcore_id] =3D=3D ROLE_NON_EAL) { > - cfg->lcore_role[lcore_id] =3D ROLE_OFF; > - cfg->lcore_count--; > - } > + if (cfg->lcore_role[lcore_id] !=3D ROLE_NON_EAL) > + goto out; > + TAILQ_FOREACH(callback, &lcore_callbacks, next) > + callback_uninit(callback, lcore_id); > + cfg->lcore_role[lcore_id] =3D ROLE_OFF; > + cfg->lcore_count--; > +out: > rte_spinlock_unlock(&lcore_lock); > }