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 AEFC1A04C0; Mon, 28 Sep 2020 04:31:04 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 365FB1D584; Mon, 28 Sep 2020 04:31:02 +0200 (CEST) Received: from nat-hk.nvidia.com (nat-hk.nvidia.com [203.18.50.4]) by dpdk.org (Postfix) with ESMTP id 2F50B1D583 for ; Mon, 28 Sep 2020 04:30:59 +0200 (CEST) Received: from HKMAIL102.nvidia.com (Not Verified[10.18.92.100]) by nat-hk.nvidia.com (using TLS: TLSv1.2, AES256-SHA) id ; Mon, 28 Sep 2020 10:30:57 +0800 Received: from HKMAIL102.nvidia.com (10.18.16.11) by HKMAIL102.nvidia.com (10.18.16.11) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Mon, 28 Sep 2020 02:30:47 +0000 Received: from NAM02-CY1-obe.outbound.protection.outlook.com (104.47.37.58) by HKMAIL102.nvidia.com (10.18.16.11) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Mon, 28 Sep 2020 02:30:47 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VTYEf3Wqqul0QZYt5CSSo+CHVZMoG+0XdmICuRhlFS98qsvnOGpHU+zKkVOZrCxLYKTGFyQpza/1D+VQXGfxbtD1Lsdy6F1W5GNe/M1pP5Q3b/8KGpbuHeQZNZG9/Yss6Eg3qjexetGxCg0I8JlxRaanrtPAQNL07sc3URrWH2O7l0maciOUyWKURAPvQZO/Lh1H7U/MCSmdgOvXpZKydnjTh26HhgiwuMtyNiv2BxJH70JzRYMm5Zj4gPIaCAwl74xi1dFIeGIKcH0zhGzOSUmcJSH4iVEiJceHXSBzAtAo7cVAVuqhslv29RLkIwclJVF3HW5MdArYo6OUzrulyQ== 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=a0Aa/al0NrGxCAUPv0ot73gqU4oqsIMXV4Tp2CJFjWY=; b=AmM95uH6ZJTyBc14ucDybQf5TcT5iZPuCLsgDexpozLCQixuIsSSFq8HiR84u5qbBV1KUO2r74lJkjIwECv27O6E80YwNhRHwvi+F98HilOpr5O6pgMkoss4Bx1RTQ3XSzz29S10ZoaqKzmFAVuPOqR0UKXM8ibL61SBoMOt0SgcinucEp8RP9C/u0D71OAM4XiMN/6vTO/Hh6INTmjF47NjfBAllisEz7fDh1Bf3N8vPIXwk8dsoh9RMGoED3adYl7vlz60Mi7aVVWTz8ywXbEcFEaEEvXTHfwb6RCprkC8OTXb3RyKeK24bLA7A8FnWxoz3EnGVViLZJ8XHD0leA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none Received: from MN2PR12MB3550.namprd12.prod.outlook.com (2603:10b6:208:108::22) by MN2PR12MB3133.namprd12.prod.outlook.com (2603:10b6:208:c7::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3412.21; Mon, 28 Sep 2020 02:30:37 +0000 Received: from MN2PR12MB3550.namprd12.prod.outlook.com ([fe80::b514:9492:7a05:75bf]) by MN2PR12MB3550.namprd12.prod.outlook.com ([fe80::b514:9492:7a05:75bf%4]) with mapi id 15.20.3412.025; Mon, 28 Sep 2020 02:30:37 +0000 From: Suanming Mou To: Dmitry Kozlyuk CC: Narcisa Ana Maria Vasile , Dmitry Malloy , Pallavi Kadam , "dev@dpdk.org" Thread-Topic: [PATCH 1/2] eal/windows: add pthread mutex lock Thread-Index: AQHWlObZTv+o9JdgY0uAmc64XCZCjal9TrYg Date: Mon, 28 Sep 2020 02:30:37 +0000 Message-ID: References: <1601194817-208834-1-git-send-email-suanmingm@nvidia.com> <1601194817-208834-2-git-send-email-suanmingm@nvidia.com> <20200927185657.6bbfdc1b@sovereign> In-Reply-To: <20200927185657.6bbfdc1b@sovereign> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: gmail.com; dkim=none (message not signed) header.d=none;gmail.com; dmarc=none action=none header.from=nvidia.com; x-originating-ip: [60.176.163.47] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 2335e2e3-1c3f-4b78-666f-08d863567c4f x-ms-traffictypediagnostic: MN2PR12MB3133: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:8882; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: nm31VxbufjMOzD4sP7F3LUP8w+gxcGWhcfJqs7JobYbxVJJCUlr/FIU0Vj9TZ5B/BIbNr/Z5K3L3UQkNmbpDZdryCzs7L7s0aXfMRuA01kvsMVWvjzxoCq4xwvjOONX5TZdjYHT9YSA/wSREzZRzvleOvD/0mX7xkGTUAwEX2HyKO/Mfu6K94JUXqoKKjazjCszC3nNplgyjH/9/XGrI5cGzRxQCzD5zz4/hqchsi5s2xP8WKJvfeMFtUI4iYGqkm6Y/bjZAy40jcwPEchLF+ivJJbJBcYBpBSp6VkYaS971ITBh7ECuE92Wuf2uNmftORpVYwBO5lempd5s0Q22Spdl1zktuZ/+Ce31Pm5nlTFwT1lhTtJ5s9fkjb1RD58S x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MN2PR12MB3550.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(346002)(376002)(136003)(366004)(39860400002)(396003)(4326008)(8936002)(52536014)(55016002)(8676002)(71200400001)(9686003)(2906002)(66446008)(64756008)(6916009)(45080400002)(6506007)(53546011)(7696005)(76116006)(86362001)(26005)(66946007)(83380400001)(33656002)(478600001)(54906003)(316002)(5660300002)(186003)(66556008)(66476007); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata: q506cZL+eIDx/M08YVKIOnK/TTmWRDyHHvXyz6O0xGOBp8Awi3XOTfRd6VzFlGJdahgJjGltmLlOAsM6U9UkkuE1sauODnrfAOdPnN6UD076NpRLBcznSwyyyt9fFUQDphE2/aKj9JpzCfBeOQ2SYtBzU88Ere8IpymMkaEZIb1YPM0gj8S2vPAkMSUkvPH2u3pfrwTdShmy/2oh08fqYnfw8eCWm1YrN+FTx3M11lf13zkdASue1NvHLdTAKoaYDYhO6DB/BqQMQ9i7gZF6qDjAYfltegJe91np85tCxI6siK1LM7Qf4jOCNcKzTNYUeXyp5KDAJSX7ixusS+1AmjQpPJExfglAVQGdTlTGveuilGQsdClRc7Fsu6CQAphLHAZKPZRrLkrAwS+MCUPWb8dQGa/pHvwofbOdo7modciQo3s/GLsCpII0Rz53+XJPKcKxJ0sZAF0VRALDpAzXkGQfMODRof/xcIH2bFLBeuWnj7lsWR75XsQ1xEUf1D/lecUClSpPI3RJivYgM3kY5Lm4nbpkbIINs3JVeHNXxtJRhJFMFwejzXcmOAKehMdyg6HA3l88L+jqZYCvnIS0I1Sd/XK2UONO2X7s91xrpf7HJZMpET5GJ8aB+awbWhK8tntLL72KBXWS+7OXzeX/gw== x-ms-exchange-transport-forked: True 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: MN2PR12MB3550.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2335e2e3-1c3f-4b78-666f-08d863567c4f X-MS-Exchange-CrossTenant-originalarrivaltime: 28 Sep 2020 02:30:37.6411 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: Hl/aUwHMX6ZjckaxBcl0GONIyZFBEQtD+o0J+tfZPIDhfBaRD+kETumCRtjjpIIqmPzLZjuTTb9hzTjKDTtOsQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB3133 X-OriginatorOrg: Nvidia.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1601260257; bh=a0Aa/al0NrGxCAUPv0ot73gqU4oqsIMXV4Tp2CJFjWY=; h=ARC-Seal:ARC-Message-Signature:ARC-Authentication-Results:From:To: CC:Subject:Thread-Topic:Thread-Index:Date:Message-ID:References: In-Reply-To:Accept-Language:Content-Language:X-MS-Has-Attach: X-MS-TNEF-Correlator:authentication-results:x-originating-ip: x-ms-publictraffictype:x-ms-office365-filtering-correlation-id: x-ms-traffictypediagnostic:x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers:x-ms-exchange-senderadcheck: x-microsoft-antispam:x-microsoft-antispam-message-info: x-forefront-antispam-report:x-ms-exchange-antispam-messagedata: x-ms-exchange-transport-forked:Content-Type: Content-Transfer-Encoding:MIME-Version: X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-AuthSource: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-originalarrivaltime: X-MS-Exchange-CrossTenant-fromentityheader: X-MS-Exchange-CrossTenant-id:X-MS-Exchange-CrossTenant-mailboxtype: X-MS-Exchange-CrossTenant-userprincipalname: X-MS-Exchange-Transport-CrossTenantHeadersStamped:X-OriginatorOrg; b=RmvfdY2kHMCg6HvZSkgdMt9YS2lv+cVbYfHSWrX0N2hPlCT1xokqR97y2n6ZwPgSS vaCMzke8mVJmtcvkUMUEaIfs0PYL1D/uFW95zwrAUc7lltFxqjf46TjWidAV7T6BlW aOdrkn7YSaGCb5GJwpZCTb/E5nbxCzYRsqu11ctqG9Su48f+S/ReL6aPKcnrI1RIi5 mghcMddMsnVxBFfCHSMI0eRJ9zR05mPHRSVmDL5T3AhvjbgSO0FDXCyFEnkgDvjAtk njGz2Dv1zesFHocpfI6JipEAORdYg7hiWFSHyzzFd8/e6DtkxxMPUUEN46JkYMNkjC rmtY38148Pl1Q== Subject: Re: [dpdk-dev] [PATCH 1/2] eal/windows: add pthread mutex lock 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" Hi Dmitry, > -----Original Message----- > From: Dmitry Kozlyuk > Sent: Sunday, September 27, 2020 11:57 PM > To: Suanming Mou > Cc: Narcisa Ana Maria Vasile ; Dmitry Mallo= y > ; Pallavi Kadam ; > dev@dpdk.org > Subject: Re: [PATCH 1/2] eal/windows: add pthread mutex lock >=20 > Hi Suanming, >=20 > There's a remark in patch 2/2 and cover letter: >=20 > > If no lock contention > > with the added rte flow level mutex, the mutex only does the atomic > > increasing in pthread_mutex_lock() and decreasing in > > pthread_mutex_unlock(). No futex() syscall will be involved. >=20 > Is this property important? To get the described behavior on Windows, you > should've used CRITICAL_SECTION (preferably wrapped in a struct). Mutexes= are > kernel objects on Windows and always require syscalls. Otherwise, if mute= xes > are sufficient, see a comment inline. The description was valid only for the standard posix pthread functions. Go= od to know that there are similar functions on Windows. I will prefer to change it to CRICTIAL_SECTION functions, in this case the = pthread wrap functions on Windows will also have less impact with the curre= nt applications. Thank you very much for the information. >=20 > > Add pthread mutex lock as it is needed for the thread safe rte flow > > functions. > > > > Signed-off-by: Suanming Mou > > --- > > lib/librte_eal/windows/include/pthread.h | 46 > > ++++++++++++++++++++++++++++++++ > > 1 file changed, 46 insertions(+) > > > > diff --git a/lib/librte_eal/windows/include/pthread.h > > b/lib/librte_eal/windows/include/pthread.h > > index 99013dc..4e2e0b3 100644 > > --- a/lib/librte_eal/windows/include/pthread.h > > +++ b/lib/librte_eal/windows/include/pthread.h > > @@ -28,6 +28,10 @@ > > /* defining pthread_attr_t type on Windows since there is no in > > Microsoft libc*/ typedef void *pthread_attr_t; > > > > +typedef void *pthread_mutexattr_t; > > + > > +typedef HANDLE pthread_mutex_t; > > + > > typedef SYNCHRONIZATION_BARRIER pthread_barrier_t; > > > > #define pthread_barrier_init(barrier, attr, count) \ @@ -139,6 > > +143,48 @@ > > return 0; > > } > > > > +static inline int > > +pthread_mutex_init(pthread_mutex_t *mutex, > > + __rte_unused pthread_mutexattr_t *attr) { > > + *mutex =3D CreateMutex(NULL, FALSE, NULL); > > + if (*mutex =3D=3D NULL) { > > + RTE_LOG_WIN32_ERR("CreateMutex()"); > > + return -1; > > + } > > + return 0; > > +} > > + > > +static inline int > > +pthread_mutex_lock(pthread_mutex_t *mutex) { > > + if (WaitForSingleObject(*mutex, INFINITE) !=3D WAIT_OBJECT_0) { > > + RTE_LOG_WIN32_ERR("WaitForSingleObject()"); > > + return -1; >=20 > A relevant error code must be returned according to POSIX. Searching the = code > for pthread_mutex_lock() calls, I can see that hinic PMD checks for > EOWNERDEAD (corresponding to WAIT_OBJECT_ABANDONED in Windows) and > failsafe PMD supplies return value of pthread_mutex_unlock() to strerror(= ), i.e. it > should be an errno. Same applies to other functions. These PMDs should not be valid on Windows now, or the build will be failed = as no pthread_mutex on Windows. I guess we will have a much general solution with the posix APIs support on= Windows? Now the wrap functions solution is much like a WA to fix the build. >=20 > > + } > > + return 0; > > +} > > + > > +static inline int > > +pthread_mutex_unlock(pthread_mutex_t *mutex) { > > + if (!ReleaseMutex(*mutex)) { > > + RTE_LOG_WIN32_ERR("ReleaseMutex()"); > > + return -1; > > + } > > + return 0; > > +} > > + > > +static inline int > > +pthread_mutex_destroy(pthread_mutex_t *mutex) { > > + if (!CloseHandle(*mutex)) { > > + RTE_LOG_WIN32_ERR("CloseHandle()"); > > + return -1; > > + } > > + return 0; > > +} > > + > > #ifdef __cplusplus > > } > > #endif