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 2D5CBA04A6; Wed, 9 Feb 2022 13:13:03 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id F29EC41143; Wed, 9 Feb 2022 13:13:02 +0100 (CET) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by mails.dpdk.org (Postfix) with ESMTP id A25B040140 for ; Wed, 9 Feb 2022 13:13:01 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1644408781; x=1675944781; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=V3okC0dxpYdPBVD1AgIDL7Qx60NR+W988W0FaTnqYEo=; b=kuPkdsi4DmxdKy3Dk7YLrpOb86iRpwgd1MRqH12KH9C1NKRH3Kn3oZVr Tcrok8qfpnnW1Z5t/SIfDEGpxVaNfZd7BiuF7YVsF5nRDk3xkCe//xR32 uj/yJtE8QpuldNGhDn0GGCC16/YnbmNqZwaMMFy0TA6mXV52XCuZMQY7Z /uNJX7+GNvQuOf59XW+LuqoGmaOb291GnXOi+6qAAkujKx5ACuuoFN82j uWoZPRjnt2/x0pzXFd1Dpkng/QQmNWDlSAmxhlsAbiRrBwurkHKLRO64z hrn6m/v/xotLpPNu/mFbO56+7YUXEktua932NtoRHSptmw+f2XEUE3OPB Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10252"; a="249397488" X-IronPort-AV: E=Sophos;i="5.88,355,1635231600"; d="scan'208";a="249397488" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Feb 2022 04:13:00 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,355,1635231600"; d="scan'208";a="499948365" Received: from orsmsx606.amr.corp.intel.com ([10.22.229.19]) by orsmga002.jf.intel.com with ESMTP; 09 Feb 2022 04:13:00 -0800 Received: from orsmsx607.amr.corp.intel.com (10.22.229.20) by ORSMSX606.amr.corp.intel.com (10.22.229.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Wed, 9 Feb 2022 04:12:59 -0800 Received: from ORSEDG602.ED.cps.intel.com (10.7.248.7) by orsmsx607.amr.corp.intel.com (10.22.229.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20 via Frontend Transport; Wed, 9 Feb 2022 04:12:59 -0800 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (104.47.66.47) by edgegateway.intel.com (134.134.137.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2308.20; Wed, 9 Feb 2022 04:12:59 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LXjO3aaHq1Io2uvBspPIXMSU86uFVaDqq3z5V1NpLeU0IlNfwC/pv8kORTZ9pxBm3OLJ45Qp4DOhQGc/Cy9AoeMIZrHvVogc7WSgcm86/r08Wpslg4PuWEcEYbdv40xgwJvmo4uVsl+iCteaCZbxMRPEThN6EKcD74MY6qPq8t/GQzgUfEdugyVm4m3/LsX/UwQkBjG+/Uf9RpG4yNwJisR1LW5n73I1EY/XnChfYAYlEBsebaAZ3sJA/CTwOuZ7qgE8vHv87tIwTLJne7FBAsciY9Zx+L+z/iMkSJ8EfzeR5lp+4ygDBe6GOmYsFIS6gvpa0AFrsargo3YtvJYFwg== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ktOsPwMytUZUe6mZflVtS8EBZPQq6Ge98EVrnJgeXLQ=; b=I5dvPyK1cMHdf3eK+EpAg70St6jFPD+1ei76gkihqKOCrXkYxdve7lDbjeZ4tRCWqZn7WyZodBh13qo9svhCuBJZSBstLqpo8ZbYjdrYUzMO8uCTZ5ZhgUQvrlccO9SNpzpirS2ps1WIczkuUZy7Pkf56EQ/RY2xJ01xNxWfSzEB2FR4EtMFtS2q9cRemqfhDgbFCy+O5gOwqZSAsbTHvVJ7Jr9qI5w84J02XV+OIaPrt1qNM1bVKTCQj0yI1FdnJvQWn5nf2U9kQXJUkFJzlAbg55d4a/hRf/10qgvnV3bVkRUiAOQGjp4YAW8z4XAmTnmooE8WxpTme/sBk3eMpA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none Received: from DM6PR11MB4491.namprd11.prod.outlook.com (2603:10b6:5:204::19) by DM6PR11MB3241.namprd11.prod.outlook.com (2603:10b6:5:58::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.11; Wed, 9 Feb 2022 12:12:57 +0000 Received: from DM6PR11MB4491.namprd11.prod.outlook.com ([fe80::8ccc:ed65:78fa:1b07]) by DM6PR11MB4491.namprd11.prod.outlook.com ([fe80::8ccc:ed65:78fa:1b07%4]) with mapi id 15.20.4951.019; Wed, 9 Feb 2022 12:12:57 +0000 From: "Ananyev, Konstantin" To: Narcisa Ana Maria Vasile CC: "Richardson, Bruce" , "david.marchand@redhat.com" , "dev@dpdk.org" , "dmitry.kozliuk@gmail.com" , "dmitrym@microsoft.com" , "khot@microsoft.com" , "navasile@microsoft.com" , "ocardona@microsoft.com" , "Kadam, Pallavi" , "roretzla@microsoft.com" , "talshn@nvidia.com" , "thomas@monjalon.net" Subject: RE: [PATCH v18 8/8] eal: implement functions for mutex management Thread-Topic: [PATCH v18 8/8] eal: implement functions for mutex management Thread-Index: AQHYHWMcyTewtY4yE0+vxrxY3qn2NqyLHGfQ Date: Wed, 9 Feb 2022 12:12:57 +0000 Message-ID: References: <20220209030854.GB9377@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> In-Reply-To: <20220209030854.GB9377@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> 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.6.200.16 authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 4f9d3720-4286-4fad-b023-08d9ebc58233 x-ms-traffictypediagnostic: DM6PR11MB3241:EE_ x-ld-processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:10000; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: lD179kMfQnOE57nvQIOFsV4DEK+9ezo0sXRiAOzpkwaBWVEwWY9PgJBG7DBo6ncLg0DX2Q0EbP3X6oTNQhDF+ostdTkOYj9wE8YAv9BMildrS4K6Gp8s5xSoHolevISaN/oR/aiBhFqYBrn0fc5Je0hJ4KzliqSPS2fZhNLF9O6Af+Fzg+6S1hjUe846pK55cL2XjRFuvcpyWMTsdVAsj49rYSgyuprmpHr1m/y2HRRM9ZPiK7h1MmZ3lM81IK02vS5oCKmpIgI5UIELRIz30RPIuucDmTLkYJsCtr8KH73JV7d5OwbPcu5xXx2ouQLgF9kxPqYOB3UgtP9EAyAfY5YQ+Wqi0dRm09+n0LHtUiEmF18OF02sRl38mnD1nv4y2F9UcXgrCXMOBjAZoMLEQIBsjqSaY1EUXoN26DCmvU3U8EGRnIGa9DgemNvSE9X2Hl6oNXIWCS33yui61svgCrmRZdImFofunrOTEh42dCIu2B42+zYpaYzH7y/sCye9xBDHDpc9l26WlGQxruBL3SaIq1SlUS0JdOFH9JD3jpfUeHtxkYtqM6aBiTRu3O0IHICfG6BOCDCWht3BAB9yNzgfO0x//tfCB0G/BrFrU9NepjdoyQJMQJ3c4W5aCZhXEFZVGGJRGufQXQ6iqDirTDYxzplS5JqHIJ151HIg5uA3fDQz2fjArSgpwU/Gxn5/kHYb2y03YlReum/fhYD2sA== x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM6PR11MB4491.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(66946007)(66476007)(66556008)(66446008)(55016003)(2906002)(64756008)(83380400001)(86362001)(76116006)(8676002)(52536014)(33656002)(38070700005)(8936002)(71200400001)(6506007)(122000001)(508600001)(82960400001)(5660300002)(316002)(38100700002)(7696005)(26005)(6916009)(54906003)(4326008)(9686003)(7416002)(186003); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?9uM9wtjDitG3Om8psdankNLDp4g1wRrzDjv1RsWrANBUDGeXVHpPXdJG/i5z?= =?us-ascii?Q?1iRUMwR0q48gfAMhciPCNreLVU5Znq1YSTBmRrSi+oVEROqpgcaYsEv8r7OD?= =?us-ascii?Q?aUIX+zVwTZ1fAqM5uJpxa7PhDLO2bzS2XyQKuPJ8svFr5SCWeYTNPnxV2oWm?= =?us-ascii?Q?eXDSzIRrmC4+WdBzAkahCjD+NsUAyv6+lsYqMWBCshnc1zvck9u7xeo6qK4d?= =?us-ascii?Q?kDyrAoyJ9bR2mBviNmsBlq9/hsaW0M/oJHCpuY075te2V8bzsh5NHx6Rtfz2?= =?us-ascii?Q?DgBYabj+LYdrM+2nRRgwmMTpiseSKXhDGDSgu2QUenfSwK8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x+IfA0d4SnasWoe7oYy91VOklHU8+DYn/1j/mxEV4cPeGXiaCzBXnbA?= =?us-ascii?Q?FsI5mbfIpYyNjk4aGPwMvqdC88eZHGkP6K/GfmJwrG7wH5c3qUZKF0ohhkBf?= =?us-ascii?Q?Jkd1JlGqsfhZm8htLMVKSslOfbNa4n9ahkUnY/hm2vI95qEr3cKsTrvMQXhf?= =?us-ascii?Q?FbwR2IrhqJnKrZYZ3gZ1hUIxAeA/h0yrOix6vywGIrnPwzMrgUX5agUvawod?= =?us-ascii?Q?LjtXZOESliH2H8D7GPtfWZ3RcmJbgLPESPax/29OGalxh0VOTvR1yRu96JPz?= =?us-ascii?Q?sdANsqDOJxGCjL1ZuEkjmkywKhcX/cBIO6ts9jn1e1EnV8r6SLMRVmVabEuX?= =?us-ascii?Q?1sKa5Z47AmpOtWHb/77In85QltmSG8xK5ewaoJgngJa+TR6CF3xU5u5AXcYj?= =?us-ascii?Q?6LD40MDytull4ecIDm9GI7t0dmOFVI1T7faSArn0CufjENlUKYGFVcIt3d+O?= =?us-ascii?Q?AhrW0w=3D=3D?= 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: DM6PR11MB4491.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4f9d3720-4286-4fad-b023-08d9ebc58233 X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Feb 2022 12:12:57.4208 (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: OX9R9uhkY0vHan20hTVWaaEsyN/EP4/xnZfAqYA6RgB9FxYv6BOtMbKLnDHyfJ9FCd0AZ0MEOI1NAX91cBOVR89sV6fGfmvPDbVxLnaesKQ= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR11MB3241 X-OriginatorOrg: intel.com 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 Mon, Feb 07, 2022 at 04:02:54PM +0000, Ananyev, Konstantin wrote: > > > Add functions for mutex init, destroy, lock, unlock, trylock. > > > > > > Windows does not have a static initializer. Initialization > > > is only done through InitializeCriticalSection(). To overcome this, > > > RTE_INIT_MUTEX macro is added to replace static initialization > > > of mutexes. The macro calls rte_thread_mutex_init(). > > > > > > Add unit tests to verify that the mutex correctly locks/unlocks > > > and protects the data. Check both static and dynamic mutexes. > > > Signed-off-by: Narcisa Vasile > > > > Few comments from me below. > > I am not sure was such approach already discussed, > > if so - apologies for repetition. > > >=20 > No worries, I appreciate your review! >=20 > > > --- > > > app/test/test_threads.c | 106 +++++++++++++++++++++++++++++++++= ++ > > > lib/eal/common/rte_thread.c | 69 +++++++++++++++++++++++ > > > lib/eal/include/rte_thread.h | 85 ++++++++++++++++++++++++++++ > > > lib/eal/version.map | 5 ++ > > > lib/eal/windows/rte_thread.c | 64 +++++++++++++++++++++ > > > 5 files changed, 329 insertions(+) > > > > > > }; > > > diff --git a/lib/eal/common/rte_thread.c b/lib/eal/common/rte_thread.= c > > > index d30a8a7ca3..4a9a1b6e07 100644 > > > --- a/lib/eal/common/rte_thread.c > > > +++ b/lib/eal/common/rte_thread.c > > > @@ -309,6 +309,75 @@ rte_thread_detach(rte_thread_t thread_id) > > > return pthread_detach((pthread_t)thread_id.opaque_id); > > > } > > > > > > +int > > > +rte_thread_mutex_init(rte_thread_mutex *mutex) > > > > Don't we need some sort of mutex_attr here too? > > To be able to create PROCESS_SHARED mutexes? >=20 > Attributes are tricky to implement on Windows. > In order to not overcomplicate this patchset and since the drivers > that need them don't compile on Windows anyway, I decided to omit > them from this patchset. In the future, after enabling the new thread API= , > we can consider implementing them as well. But it could just return ENOTSUP for Windows if 'attr' parameter is not NUL= L, no? >=20 > > > > > +{ > > > + int ret =3D 0; > > > + pthread_mutex_t *m =3D NULL; > > > + > > > + RTE_VERIFY(mutex !=3D NULL); > > > + > > > + m =3D calloc(1, sizeof(*m)); > > > > But is that what we really want for the mutexes? > > It means actual mutex will always be allocated on process heap, > > away from the data it is supposed to guard. > > Even if we'll put performance considerations away, > > that wouldn't work for MP case. > > Is that considered as ok? >=20 > Are you refering to the fact that all mutexes will be dynamically allocat= ed, > due to the static intializer calling _mutex_init() in the background? > Why wouldn't it work in the MP case? No, I am talking about another case: suppose we allocate a structure (with a mutex) inside shared memory and plan to use it for inter-process communication. But with rte_thread_mutex_init() implementation actual mutex object will=20 be allocated on process heap (private area) and wouldn't be accessible by o= ther processes. =20 As an example: struct shared { rte_thread_mutex lock; uint32_t val; }; ... struct shared *p =3D rte_zmalloc(NULL, sizeof(*p), RTE_CACHE_LINE_SIZE); rte_thread_mutex_init(&p->lock); =20 Now p->lock is in shared memory, but actual mutex object: p->lock.mutex_id is within process private memory. >=20 > > > > > + if (m =3D=3D NULL) { > > > + RTE_LOG(DEBUG, EAL, "Unable to initialize mutex. Insufficient memo= ry!\n"); > > > + ret =3D ENOMEM; > > > + goto cleanup; > > > + } > > > + > > > + > > > + return ret; > > > +} > > > + return pthread_mutex_trylock((pthread_mutex_t *)mutex->mutex_id);