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 F075DA04B1; Mon, 5 Oct 2020 13:29:02 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 9835E1B669; Mon, 5 Oct 2020 13:29:01 +0200 (CEST) Received: from nat-hk.nvidia.com (nat-hk.nvidia.com [203.18.50.4]) by dpdk.org (Postfix) with ESMTP id 110651B5E1 for ; Mon, 5 Oct 2020 13:28:57 +0200 (CEST) Received: from HKMAIL101.nvidia.com (Not Verified[10.18.92.9]) by nat-hk.nvidia.com (using TLS: TLSv1.2, AES256-SHA) id ; Mon, 05 Oct 2020 19:28:55 +0800 Received: from HKMAIL102.nvidia.com (10.18.16.11) by HKMAIL101.nvidia.com (10.18.16.10) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Mon, 5 Oct 2020 11:28:50 +0000 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (104.47.70.106) by HKMAIL102.nvidia.com (10.18.16.11) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Mon, 5 Oct 2020 11:28:50 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZwubFWA/Dr6Butot3H3c4JR/DFXVtRNH1ne9Ww7PR2TzitdzqM8SFaTfQ3FOWDDZyTSrTMSZKrq/bcqnN/nA98nNXP9PYJsEgpIoFRdl+lZAQfdRdLwBSPtowNllj1aGVWRToYzKi8sVytU7v4JNVcx0V26iUEE9Hv/5l0d+x59YS5z8EeaWDajk92wyiXEO22HO4Qmst02EH4+N343Zp65ch+gzc+jdIVpXyeFxVGTJAhsTImzT5zfyWtJ5C10Cd6FlOJF9vTkUkgSVjzn7eazYjOf1o5cDAGJ1Jv5vyaz2xvoZjRUk966+BjPTuPEFedCZbybqGa/x4DmNobWeIQ== 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=QoY9b7o8eZ6IW5/5Po5jQ/n7JagMEqWQhcqxlpI/hHY=; b=Sy4TmV8d96LFnwooFI7kbVKYvMxALXOEMnwkPEexw7SIA9lnrncn18fPdbMRN9u4qyNQgQshvs7qAJUkUL5lsFEccYNkiRB4zbE2FQHDySSV0VmF+VS0K7avJJAuMigAVHoTVlqG2InfE+yaHSo4OAM5NfYvNcEG+UVcAjnDwhJeHqlAQMa8vsYG8lejKklQJm+sHHwfdAdPW0kB84GDYFfS5BJXztI5YyLgavM1g5g7x0cq8q2aXy4kUE0k6Cr5x7fNJrrR1vSSVkVPYLkEurjV6TdXoZVeoDv1zAW/YYeNQ2Cf4CuU3Vwxuuf9FdnvHPdgG6bYtdFaBIZCutcOvA== 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 MN2PR12MB4286.namprd12.prod.outlook.com (2603:10b6:208:199::22) by BL0PR12MB4611.namprd12.prod.outlook.com (2603:10b6:208:8e::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3433.32; Mon, 5 Oct 2020 11:28:48 +0000 Received: from MN2PR12MB4286.namprd12.prod.outlook.com ([fe80::61fd:a36e:cf4f:2d3f]) by MN2PR12MB4286.namprd12.prod.outlook.com ([fe80::61fd:a36e:cf4f:2d3f%8]) with mapi id 15.20.3433.044; Mon, 5 Oct 2020 11:28:48 +0000 From: Ori Kam To: Suanming Mou , Ori Kam , "John McNamara" , Marko Kovacevic , NBU-Contact-Thomas Monjalon , Ferruh Yigit , "Andrew Rybchenko" CC: "dev@dpdk.org" Thread-Topic: [PATCH v2 2/2] ethdev: make rte_flow API thread safe Thread-Index: AQHWmqjlMdfEf0qUO0qjwyDEt0+4NKmI3i2w Date: Mon, 5 Oct 2020 11:28:47 +0000 Message-ID: References: <1601194817-208834-1-git-send-email-suanmingm@nvidia.com> <1601855286-81511-1-git-send-email-suanmingm@nvidia.com> <1601855286-81511-3-git-send-email-suanmingm@nvidia.com> In-Reply-To: <1601855286-81511-3-git-send-email-suanmingm@nvidia.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: nvidia.com; dkim=none (message not signed) header.d=none;nvidia.com; dmarc=none action=none header.from=nvidia.com; x-originating-ip: [147.236.152.129] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 39f0a69f-2feb-44f3-2fa3-08d86921d3d7 x-ms-traffictypediagnostic: BL0PR12MB4611: x-ld-processed: 43083d15-7273-40c1-b7db-39efd9ccc17a,ExtAddr x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:2399; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: v5kpjpzYOeAxtqbnfHa0OaUDQmMS/69yKKgfET3jXt5rueDVZTdvU8Hw88RGuSl4+E6525Lsoz+xzlctShA42N3JsCNbF6I6eOvXdLQqD5xALK0gMNRpFOXg2Zfn5mc1kUmZFqir/BWBc2lAdeugOvjo1kHv+RlMa/ObNwp07laHwByt3QF9qPAYkQl+SfPMWm7QjPBIcUpEYagGiERZ5fJmWsHgzCQIVaAqh1YHjz2Qm8LCGtrIHJFWSHPd0ywD+l+cA1t+qS7uyy7qdOM349Hm9QvS8yG4YvYQsLYOj2KBNHYg0kIQe988JPn/3z9sV4IY3qikZrS4za7fdV3UnA== x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MN2PR12MB4286.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(396003)(39860400002)(376002)(136003)(346002)(71200400001)(8936002)(2906002)(86362001)(83380400001)(5660300002)(110136005)(66946007)(52536014)(66476007)(66556008)(64756008)(66446008)(186003)(33656002)(26005)(76116006)(4326008)(6506007)(478600001)(7696005)(55016002)(9686003)(8676002)(316002); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata: tipNzbAPKfTfFed2yrDJjSUtz8v4HedaK7wo0DXnSNOE63Sf9QzhM9zaUWTbcHy6Znz3s9SCOMM2JbJE2zzBVkcwFVuuhw7GK1QDA8HB1CM4edMb3jTIURyCtGFuvEBKUXmMQGyiB2oFXi4rSr9sEJqhSqXR8BhkyMxSPUD1BYJ1L9ZKUeC9Ze4x/V6YArKLve6ixaxiUCHf2zrUdEBe4YMWds4VW4WbZP28LzsjmAcCx2UB5VnKBvp/xPTGo1aNW1R8y8DxUYoYYhM/y++OvzB5zveto76/QwyNleKYCf22Nj4IiNSmKpQatvebcs7KkGbCvwg1axUl0rxZbZsokaijFPJgvcgIP0BdTSc3eKesBCuc03aXbG7kAUXkVKGsDzvhxWqhLxmw8O+8QuXbgsrp5aAlJ0XPVAIhbZDCRjeoyJFEA4FFqhvBR+hlyzoJ5XFnobm1WFlJgHR3E4ijwsq+3y4Dj53ta4XAPYkdT68h/oU5hQOgOTH/pM9Rt2L77rbuLwVIV86UNy6d6h4LPW+t1DMA7oGPqMi/koyMCZGMgb1BVBLIKqAoEiKPwQ9SWyJK6nnWUmQ+NKsoBWKx0Ku/TzKFK5YZaazNghhGqPvWeqgVcwj6y0wOeWodZPEfi9cwCWkKLHPxhEeTRpx6EA== 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: MN2PR12MB4286.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 39f0a69f-2feb-44f3-2fa3-08d86921d3d7 X-MS-Exchange-CrossTenant-originalarrivaltime: 05 Oct 2020 11:28:47.9597 (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: Cm1/vxL3B66lX8cpDh7uY1IMBpM3vu3Y/lji+CBiXqeIFYV0dDRs3K5oteZI2GwfTI9pBo9Ru98NPYVlMehBGA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR12MB4611 X-OriginatorOrg: Nvidia.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1601897335; bh=QoY9b7o8eZ6IW5/5Po5jQ/n7JagMEqWQhcqxlpI/hHY=; 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-ld-processed: x-ms-exchange-transport-forked: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: 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=UhTMKrPCv1l/LdD/5o5E9gjnzeuSHD/tsWOz7n1qv8PwQT2tiH+7plIzH7w2azRka OK11J9c0j29w+WqwHzbkAADXYhkbhhz3sUSVwCNVqG0uO0wjPuTm4mXLlsb1ftCuSc seHC1l9cj1FVYSlmpOdd9YWDv4FmBa3n2i7XEzZsR7hWHnjNJLKKS9pQfWKIkOrfyB P4hqhkBSDiHg0ztOHA8JIUP+JeT4Pp3TC9TcY7rXl3NoeLH62C9S/SuDdRFFH2DtIP go4y9ME0VlmLgoQWcz4VOd069BVhG8Bs4w32SIdnVk6X3gVpyZx+lA46c76+Uv1MAD J+lb+Rlbl8aQA== Subject: Re: [dpdk-dev] [PATCH v2 2/2] ethdev: make rte_flow API thread safe 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 Suanming, PSB, Best, Ori > -----Original Message----- > From: Suanming Mou > Subject: [PATCH v2 2/2] ethdev: make rte_flow API thread safe >=20 > Currently, the rte_flow functions are not defined as thread safe. > DPDK applications either call the functions in single thread or add > locks around the functions for the critical section. >=20 [Snip ...] > diff --git a/lib/librte_ethdev/rte_flow.c b/lib/librte_ethdev/rte_flow.c > index f8fdd68..2ac966d 100644 > --- a/lib/librte_ethdev/rte_flow.c > +++ b/lib/librte_ethdev/rte_flow.c > @@ -207,6 +207,20 @@ struct rte_flow_desc_data { > return -rte_errno; > } >=20 > +static inline void > +flow_lock(struct rte_eth_dev *dev) Maybe change the name to flow_safe_enter Since this function doesn't always lock. =20 > +{ > + if (!(dev->data->dev_flags & > RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE)) > + pthread_mutex_lock(&dev->data->fts_mutex); > +} > + > +static inline void > +flow_unlock(struct rte_eth_dev *dev) Maybe change the name flow_safe_leave Same reason as above. > +{ > + if (!(dev->data->dev_flags & > RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE)) > + pthread_mutex_unlock(&dev->data->fts_mutex); > +} > + > static int > flow_err(uint16_t port_id, int ret, struct rte_flow_error *error) > { > @@ -346,12 +360,16 @@ struct rte_flow_desc_data { > { > const struct rte_flow_ops *ops =3D rte_flow_ops_get(port_id, error); > struct rte_eth_dev *dev =3D &rte_eth_devices[port_id]; > + int ret; >=20 > if (unlikely(!ops)) > return -rte_errno; > - if (likely(!!ops->validate)) > - return flow_err(port_id, ops->validate(dev, attr, pattern, > - actions, error), error); > + if (likely(!!ops->validate)) { > + flow_lock(dev); > + ret =3D ops->validate(dev, attr, pattern, actions, error); > + flow_unlock(dev); > + return flow_err(port_id, ret, error); > + } > return rte_flow_error_set(error, ENOSYS, > RTE_FLOW_ERROR_TYPE_UNSPECIFIED, > NULL, rte_strerror(ENOSYS)); > @@ -372,7 +390,9 @@ struct rte_flow * > if (unlikely(!ops)) > return NULL; > if (likely(!!ops->create)) { > + flow_lock(dev); > flow =3D ops->create(dev, attr, pattern, actions, error); > + flow_unlock(dev); > if (flow =3D=3D NULL) > flow_err(port_id, -rte_errno, error); > return flow; > @@ -390,12 +410,16 @@ struct rte_flow * > { > struct rte_eth_dev *dev =3D &rte_eth_devices[port_id]; > const struct rte_flow_ops *ops =3D rte_flow_ops_get(port_id, error); > + int ret; >=20 > if (unlikely(!ops)) > return -rte_errno; > - if (likely(!!ops->destroy)) > - return flow_err(port_id, ops->destroy(dev, flow, error), > - error); > + if (likely(!!ops->destroy)) { > + flow_lock(dev); > + ret =3D ops->destroy(dev, flow, error); > + flow_unlock(dev); > + return flow_err(port_id, ret, error); > + } > return rte_flow_error_set(error, ENOSYS, > RTE_FLOW_ERROR_TYPE_UNSPECIFIED, > NULL, rte_strerror(ENOSYS)); > @@ -408,11 +432,16 @@ struct rte_flow * > { > struct rte_eth_dev *dev =3D &rte_eth_devices[port_id]; > const struct rte_flow_ops *ops =3D rte_flow_ops_get(port_id, error); > + int ret; >=20 > if (unlikely(!ops)) > return -rte_errno; > - if (likely(!!ops->flush)) > - return flow_err(port_id, ops->flush(dev, error), error); > + if (likely(!!ops->flush)) { > + flow_lock(dev); > + ret =3D ops->flush(dev, error); > + flow_unlock(dev); > + return flow_err(port_id, ret, error); > + } > return rte_flow_error_set(error, ENOSYS, > RTE_FLOW_ERROR_TYPE_UNSPECIFIED, > NULL, rte_strerror(ENOSYS)); > @@ -428,12 +457,16 @@ struct rte_flow * > { > struct rte_eth_dev *dev =3D &rte_eth_devices[port_id]; > const struct rte_flow_ops *ops =3D rte_flow_ops_get(port_id, error); > + int ret; >=20 > if (!ops) > return -rte_errno; > - if (likely(!!ops->query)) > - return flow_err(port_id, ops->query(dev, flow, action, data, > - error), error); > + if (likely(!!ops->query)) { > + flow_lock(dev); > + ret =3D ops->query(dev, flow, action, data, error); > + flow_unlock(dev); > + return flow_err(port_id, ret, error); > + } > return rte_flow_error_set(error, ENOSYS, > RTE_FLOW_ERROR_TYPE_UNSPECIFIED, > NULL, rte_strerror(ENOSYS)); > @@ -447,11 +480,16 @@ struct rte_flow * > { > struct rte_eth_dev *dev =3D &rte_eth_devices[port_id]; > const struct rte_flow_ops *ops =3D rte_flow_ops_get(port_id, error); > + int ret; >=20 > if (!ops) > return -rte_errno; > - if (likely(!!ops->isolate)) > - return flow_err(port_id, ops->isolate(dev, set, error), error); > + if (likely(!!ops->isolate)) { > + flow_lock(dev); > + ret =3D ops->isolate(dev, set, error); > + flow_unlock(dev); > + return flow_err(port_id, ret, error); > + } > return rte_flow_error_set(error, ENOSYS, > RTE_FLOW_ERROR_TYPE_UNSPECIFIED, > NULL, rte_strerror(ENOSYS)); > @@ -1224,12 +1262,16 @@ enum rte_flow_conv_item_spec_type { > { > struct rte_eth_dev *dev =3D &rte_eth_devices[port_id]; > const struct rte_flow_ops *ops =3D rte_flow_ops_get(port_id, error); > + int ret; >=20 > if (unlikely(!ops)) > return -rte_errno; > - if (likely(!!ops->dev_dump)) > - return flow_err(port_id, ops->dev_dump(dev, file, error), > - error); > + if (likely(!!ops->dev_dump)) { > + flow_lock(dev); > + ret =3D ops->dev_dump(dev, file, error); > + flow_unlock(dev); > + return flow_err(port_id, ret, error); > + } > return rte_flow_error_set(error, ENOSYS, > RTE_FLOW_ERROR_TYPE_UNSPECIFIED, > NULL, rte_strerror(ENOSYS)); > @@ -1241,12 +1283,16 @@ enum rte_flow_conv_item_spec_type { > { > struct rte_eth_dev *dev =3D &rte_eth_devices[port_id]; > const struct rte_flow_ops *ops =3D rte_flow_ops_get(port_id, error); > + int ret; >=20 > if (unlikely(!ops)) > return -rte_errno; > - if (likely(!!ops->get_aged_flows)) > - return flow_err(port_id, ops->get_aged_flows(dev, contexts, > - nb_contexts, error), error); > + if (likely(!!ops->get_aged_flows)) { > + flow_lock(dev); > + ret =3D ops->get_aged_flows(dev, contexts, nb_contexts, error); > + flow_unlock(dev); > + return flow_err(port_id, ret, error); > + } > return rte_flow_error_set(error, ENOTSUP, > RTE_FLOW_ERROR_TYPE_UNSPECIFIED, > NULL, rte_strerror(ENOTSUP)); > -- > 1.8.3.1