From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by dpdk.space (Postfix) with ESMTP id A6D98A05D3 for ; Wed, 24 Apr 2019 10:52:18 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 4F0612F42; Wed, 24 Apr 2019 10:52:17 +0200 (CEST) Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-eopbgr130085.outbound.protection.outlook.com [40.107.13.85]) by dpdk.org (Postfix) with ESMTP id D02E329D2 for ; Wed, 24 Apr 2019 10:52:15 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Mellanox.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=3AXI8BxClnYookTEwtwdOGdzthOFZjbPRYnZxja8KIo=; b=EBmPblMtG3ziKVoNRcWlzmPPxgtcjsrbYJF3YDWTKC7aiXOVCLW33roQOgZGF9oW27mY0igGWPL6ruUBcTk1ABa5Y60Mz7af31ejnaYsR81Ds/d3bNqRmygh5nejrzosBMFa/TXt+V8bd3EQ0bdHmfEV9KmnqdmXQrMrGR79hHo= Received: from DB3PR0502MB3980.eurprd05.prod.outlook.com (52.134.72.27) by DB3PR0502MB4074.eurprd05.prod.outlook.com (52.134.72.155) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1835.12; Wed, 24 Apr 2019 08:52:14 +0000 Received: from DB3PR0502MB3980.eurprd05.prod.outlook.com ([fe80::e8d5:4aff:902d:6e98]) by DB3PR0502MB3980.eurprd05.prod.outlook.com ([fe80::e8d5:4aff:902d:6e98%5]) with mapi id 15.20.1835.010; Wed, 24 Apr 2019 08:52:14 +0000 From: Yongseok Koh To: Slava Ovsiienko CC: Shahaf Shuler , "dev@dpdk.org" Thread-Topic: [PATCH v2] net/mlx5: share Memory Regions for multiport device Thread-Index: AQHU+nn/dnTWk+FmFke1B27aCCYj86ZLARCA Date: Wed, 24 Apr 2019 08:52:14 +0000 Message-ID: References: <1555083940-24539-1-git-send-email-viacheslavo@mellanox.com> <1556095470-11407-1-git-send-email-viacheslavo@mellanox.com> In-Reply-To: <1556095470-11407-1-git-send-email-viacheslavo@mellanox.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=yskoh@mellanox.com; x-originating-ip: [69.181.245.183] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: bed975a1-e837-4b1d-ea0d-08d6c89225ad x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600141)(711020)(4605104)(4618075)(2017052603328)(7193020); SRVR:DB3PR0502MB4074; x-ms-traffictypediagnostic: DB3PR0502MB4074: x-ms-exchange-purlcount: 2 x-microsoft-antispam-prvs: x-forefront-prvs: 00179089FD x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(366004)(346002)(136003)(39860400002)(396003)(376002)(189003)(199004)(2906002)(97736004)(6436002)(86362001)(966005)(8676002)(6486002)(8936002)(229853002)(81156014)(14454004)(81166006)(6862004)(45080400002)(478600001)(6636002)(99286004)(37006003)(4326008)(6246003)(316002)(25786009)(76176011)(54906003)(33656002)(7736002)(305945005)(53936002)(53946003)(66556008)(6512007)(73956011)(66066001)(6506007)(66446008)(102836004)(91956017)(3846002)(64756008)(76116006)(6116002)(66476007)(53546011)(66946007)(71190400001)(36756003)(71200400001)(256004)(5660300002)(30864003)(26005)(486006)(476003)(446003)(11346002)(2616005)(82746002)(83716004)(68736007)(186003)(14444005)(6306002)(579004)(559001); DIR:OUT; SFP:1101; SCL:1; SRVR:DB3PR0502MB4074; H:DB3PR0502MB3980.eurprd05.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: mellanox.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: JAAtq8HB/ApJ87LCxdNwFjZdFOgYugU9Us/hjTZqG4eDaqfZugoB+12TSOVS1JGCi4+sYHuikVWWOJiMFzVD3kY81dw2zMSFC17PtgKbhiML0xLjjveKzP2Kp08oIB9Wzi3cYRNiQn010EGYELEVDKX6Itt5vdxdsFyO0w7dKbpv5V6xB0ixjrr5vhbhzIvwEf5EBl2gG663rMd1B2rqugIwJE9+offGR7d+yN4EJt4RUF45mmpv6pqE6E+FFGyFdo/2CDgzIx2V+DUiqbpgOdNcEdHPfjruTKoWybXynvwkKhCk0vQEXXxIurdDiy/m/91Uj5E15w1N41Ep4c5FYACRyxiGuFQWwY9qnqPDwxFZSSl9SvWLy3TmpbagLELMbnBYQF1wkOeQfaD62PKFF1uJ6KZ1e8sV0jIR6MXc35A= Content-Type: text/plain; charset="UTF-8" Content-ID: <7A4A06FD03DB0348A29CF249ED553031@eurprd05.prod.outlook.com> Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-Network-Message-Id: bed975a1-e837-4b1d-ea0d-08d6c89225ad X-MS-Exchange-CrossTenant-originalarrivaltime: 24 Apr 2019 08:52:14.1598 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB3PR0502MB4074 Subject: Re: [dpdk-dev] [PATCH v2] net/mlx5: share Memory Regions for multiport device 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" Message-ID: <20190424085214.WENY-XQ8Gh4DTFoouvhWWzlY-sr0cGCw6fIrBauaI0o@z> > On Apr 24, 2019, at 1:44 AM, Viacheslav Ovsiienko wrote: >=20 > The multiport Infiniband device support was introduced [1]. > All active ports, belonging to the same Infiniband device use the signle > shared Infiniband context of that device and share the resources: > - QPs are created within shared context > - Verbs flows are also created with specifying port index > - DV/DR resources > - Protection Domain > - Event Handlers >=20 > This patchset adds support for Memory Regions sharing between > portes, created on the base of multiport Infiniban device. > The datapath of mlx5 uses the layered cache subsystem for > allocating/releasing Memory Regions, only the lowest layer L3 > is subject to share due to performance issues. >=20 > [1] http://patches.dpdk.org/cover/51800/ >=20 > Signed-off-by: Viacheslav Ovsiienko > --- Acked-by: Yongseok Koh > v2: > - intendation issues > - comments cleanup >=20 > v1: > http://patches.dpdk.org/patch/52723/ >=20 > drivers/net/mlx5/mlx5.c | 40 +++++++---- > drivers/net/mlx5/mlx5.h | 15 ++-- > drivers/net/mlx5/mlx5_mr.c | 164 ++++++++++++++++++++++-----------------= ----- > drivers/net/mlx5/mlx5_mr.h | 5 +- > drivers/net/mlx5/mlx5_txq.c | 2 +- > 5 files changed, 121 insertions(+), 105 deletions(-) >=20 > diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c > index 1bb58b1..b563e0f 100644 > --- a/drivers/net/mlx5/mlx5.c > +++ b/drivers/net/mlx5/mlx5.c > @@ -147,6 +147,7 @@ struct mlx5_dev_spawn_data { > struct mlx5_switch_info info; /**< Switch information. */ > struct ibv_device *ibv_dev; /**< Associated IB device. */ > struct rte_eth_dev *eth_dev; /**< Associated Ethernet device. */ > + struct rte_pci_device *pci_dev; /**< Backend PCI device. */ > }; >=20 > static LIST_HEAD(, mlx5_ibv_shared) mlx5_ibv_list =3D LIST_HEAD_INITIALIZ= ER(); > @@ -225,6 +226,7 @@ struct mlx5_dev_spawn_data { > sizeof(sh->ibdev_name)); > strncpy(sh->ibdev_path, sh->ctx->device->ibdev_path, > sizeof(sh->ibdev_path)); > + sh->pci_dev =3D spawn->pci_dev; > pthread_mutex_init(&sh->intr_mutex, NULL); > /* > * Setting port_id to max unallowed value means > @@ -239,6 +241,22 @@ struct mlx5_dev_spawn_data { > err =3D ENOMEM; > goto error; > } > + /* > + * Once the device is added to the list of memory event > + * callback, its global MR cache table cannot be expanded > + * on the fly because of deadlock. If it overflows, lookup > + * should be done by searching MR list linearly, which is slow. > + * > + * At this point the device is not added to the memory > + * event list yet, context is just being created. > + */ > + err =3D mlx5_mr_btree_init(&sh->mr.cache, > + MLX5_MR_BTREE_CACHE_N * 2, > + sh->pci_dev->device.numa_node); > + if (err) { > + err =3D rte_errno; > + goto error; > + } > LIST_INSERT_HEAD(&mlx5_ibv_list, sh, next); > exit: > pthread_mutex_unlock(&mlx5_ibv_list_mutex); > @@ -286,6 +304,8 @@ struct mlx5_dev_spawn_data { > assert(rte_eal_process_type() =3D=3D RTE_PROC_PRIMARY); > if (--sh->refcnt) > goto exit; > + /* Release created Memory Regions. */ > + mlx5_mr_release(sh); > LIST_REMOVE(sh, next); > /* > * Ensure there is no async event handler installed. > @@ -651,7 +671,10 @@ struct mlx5_dev_spawn_data { > } > mlx5_proc_priv_uninit(dev); > mlx5_mprq_free_mp(dev); > - mlx5_mr_release(dev); > + /* Remove from memory callback device list. */ > + rte_rwlock_write_lock(&mlx5_shared_data->mem_event_rwlock); > + LIST_REMOVE(priv, mem_event_cb); > + rte_rwlock_write_unlock(&mlx5_shared_data->mem_event_rwlock); > assert(priv->sh); > mlx5_free_shared_dr(priv); > if (priv->rss_conf.rss_key !=3D NULL) > @@ -1548,19 +1571,6 @@ struct mlx5_dev_spawn_data { > goto error; > } > priv->config.flow_prio =3D err; > - /* > - * Once the device is added to the list of memory event > - * callback, its global MR cache table cannot be expanded > - * on the fly because of deadlock. If it overflows, lookup > - * should be done by searching MR list linearly, which is slow. > - */ > - err =3D mlx5_mr_btree_init(&priv->mr.cache, > - MLX5_MR_BTREE_CACHE_N * 2, > - eth_dev->device->numa_node); > - if (err) { > - err =3D rte_errno; > - goto error; > - } > /* Add device to memory callback list. */ > rte_rwlock_write_lock(&mlx5_shared_data->mem_event_rwlock); > LIST_INSERT_HEAD(&mlx5_shared_data->mem_event_cb_list, > @@ -1757,6 +1767,7 @@ struct mlx5_dev_spawn_data { > list[ns].ibv_port =3D i; > list[ns].ibv_dev =3D ibv_match[0]; > list[ns].eth_dev =3D NULL; > + list[ns].pci_dev =3D pci_dev; > list[ns].ifindex =3D mlx5_nl_ifindex > (nl_rdma, list[ns].ibv_dev->name, i); > if (!list[ns].ifindex) { > @@ -1823,6 +1834,7 @@ struct mlx5_dev_spawn_data { > list[ns].ibv_port =3D 1; > list[ns].ibv_dev =3D ibv_match[i]; > list[ns].eth_dev =3D NULL; > + list[ns].pci_dev =3D pci_dev; > list[ns].ifindex =3D 0; > if (nl_rdma >=3D 0) > list[ns].ifindex =3D mlx5_nl_ifindex > diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h > index 0a6d7f1..2575732 100644 > --- a/drivers/net/mlx5/mlx5.h > +++ b/drivers/net/mlx5/mlx5.h > @@ -275,6 +275,14 @@ struct mlx5_ibv_shared { > char ibdev_name[IBV_SYSFS_NAME_MAX]; /* IB device name. */ > char ibdev_path[IBV_SYSFS_PATH_MAX]; /* IB device path for secondary */ > struct ibv_device_attr_ex device_attr; /* Device properties. */ > + struct rte_pci_device *pci_dev; /* Backend PCI device. */ > + struct { > + uint32_t dev_gen; /* Generation number to flush local caches. */ > + rte_rwlock_t rwlock; /* MR Lock. */ > + struct mlx5_mr_btree cache; /* Global MR cache table. */ > + struct mlx5_mr_list mr_list; /* Registered MR list. */ > + struct mlx5_mr_list mr_free_list; /* Freed MR list. */ > + } mr; > /* Shared DV/DR flow data section. */ > pthread_mutex_t dv_mutex; /* DV context mutex. */ > uint32_t dv_refcnt; /* DV/DR data reference counter. */ > @@ -347,13 +355,6 @@ struct mlx5_priv { > struct mlx5_flows ctrl_flows; /* Control flow rules. */ > LIST_HEAD(counters, mlx5_flow_counter) flow_counters; > /* Flow counters. */ > - struct { > - uint32_t dev_gen; /* Generation number to flush local caches. */ > - rte_rwlock_t rwlock; /* MR Lock. */ > - struct mlx5_mr_btree cache; /* Global MR cache table. */ > - struct mlx5_mr_list mr_list; /* Registered MR list. */ > - struct mlx5_mr_list mr_free_list; /* Freed MR list. */ > - } mr; > LIST_HEAD(rxq, mlx5_rxq_ctrl) rxqsctrl; /* DPDK Rx queues. */ > LIST_HEAD(rxqibv, mlx5_rxq_ibv) rxqsibv; /* Verbs Rx queues. */ > LIST_HEAD(hrxq, mlx5_hrxq) hrxqs; /* Verbs Hash Rx queues. */ > diff --git a/drivers/net/mlx5/mlx5_mr.c b/drivers/net/mlx5/mlx5_mr.c > index e4957a4..a7a63b1 100644 > --- a/drivers/net/mlx5/mlx5_mr.c > +++ b/drivers/net/mlx5/mlx5_mr.c > @@ -36,7 +36,7 @@ struct mr_update_mp_data { >=20 > /** > * Expand B-tree table to a given size. Can't be called with holding > - * memory_hotplug_lock or priv->mr.rwlock due to rte_realloc(). > + * memory_hotplug_lock or sh->mr.rwlock due to rte_realloc(). > * > * @param bt > * Pointer to B-tree structure. > @@ -350,7 +350,7 @@ struct mr_update_mp_data { > n =3D mr_find_next_chunk(mr, &entry, n); > if (!entry.end) > break; > - if (mr_btree_insert(&priv->mr.cache, &entry) < 0) { > + if (mr_btree_insert(&priv->sh->mr.cache, &entry) < 0) { > /* > * Overflowed, but the global table cannot be expanded > * because of deadlock. > @@ -382,7 +382,7 @@ struct mr_update_mp_data { > struct mlx5_mr *mr; >=20 > /* Iterate all the existing MRs. */ > - LIST_FOREACH(mr, &priv->mr.mr_list, mr) { > + LIST_FOREACH(mr, &priv->sh->mr.mr_list, mr) { > unsigned int n; >=20 > if (mr->ms_n =3D=3D 0) > @@ -420,6 +420,7 @@ struct mr_update_mp_data { > uintptr_t addr) > { > struct mlx5_priv *priv =3D dev->data->dev_private; > + struct mlx5_ibv_shared *sh =3D priv->sh; > uint16_t idx; > uint32_t lkey =3D UINT32_MAX; > struct mlx5_mr *mr; > @@ -430,10 +431,10 @@ struct mr_update_mp_data { > * has to be searched by traversing the original MR list instead, which > * is very slow path. Otherwise, the global cache is all inclusive. > */ > - if (!unlikely(priv->mr.cache.overflow)) { > - lkey =3D mr_btree_lookup(&priv->mr.cache, &idx, addr); > + if (!unlikely(sh->mr.cache.overflow)) { > + lkey =3D mr_btree_lookup(&sh->mr.cache, &idx, addr); > if (lkey !=3D UINT32_MAX) > - *entry =3D (*priv->mr.cache.table)[idx]; > + *entry =3D (*sh->mr.cache.table)[idx]; > } else { > /* Falling back to the slowest path. */ > mr =3D mr_lookup_dev_list(dev, entry, addr); > @@ -468,13 +469,12 @@ struct mr_update_mp_data { > /** > * Release resources of detached MR having no online entry. > * > - * @param dev > - * Pointer to Ethernet device. > + * @param sh > + * Pointer to Ethernet device shared context. > */ > static void > -mlx5_mr_garbage_collect(struct rte_eth_dev *dev) > +mlx5_mr_garbage_collect(struct mlx5_ibv_shared *sh) > { > - struct mlx5_priv *priv =3D dev->data->dev_private; > struct mlx5_mr *mr_next; > struct mlx5_mr_list free_list =3D LIST_HEAD_INITIALIZER(free_list); >=20 > @@ -484,11 +484,11 @@ struct mr_update_mp_data { > * MR can't be freed with holding the lock because rte_free() could call > * memory free callback function. This will be a deadlock situation. > */ > - rte_rwlock_write_lock(&priv->mr.rwlock); > + rte_rwlock_write_lock(&sh->mr.rwlock); > /* Detach the whole free list and release it after unlocking. */ > - free_list =3D priv->mr.mr_free_list; > - LIST_INIT(&priv->mr.mr_free_list); > - rte_rwlock_write_unlock(&priv->mr.rwlock); > + free_list =3D sh->mr.mr_free_list; > + LIST_INIT(&sh->mr.mr_free_list); > + rte_rwlock_write_unlock(&sh->mr.rwlock); > /* Release resources. */ > mr_next =3D LIST_FIRST(&free_list); > while (mr_next !=3D NULL) { > @@ -548,12 +548,12 @@ struct mr_update_mp_data { > dev->data->port_id, (void *)addr); > return UINT32_MAX; > } > - rte_rwlock_read_lock(&priv->mr.rwlock); > + rte_rwlock_read_lock(&priv->sh->mr.rwlock); > /* Fill in output data. */ > mr_lookup_dev(dev, entry, addr); > /* Lookup can't fail. */ > assert(entry->lkey !=3D UINT32_MAX); > - rte_rwlock_read_unlock(&priv->mr.rwlock); > + rte_rwlock_read_unlock(&priv->sh->mr.rwlock); > DEBUG("port %u MR CREATED by primary process for %p:\n" > " [0x%" PRIxPTR ", 0x%" PRIxPTR "), lkey=3D0x%x", > dev->data->port_id, (void *)addr, > @@ -582,6 +582,7 @@ struct mr_update_mp_data { > uintptr_t addr) > { > struct mlx5_priv *priv =3D dev->data->dev_private; > + struct mlx5_ibv_shared *sh =3D priv->sh; > struct mlx5_dev_config *config =3D &priv->config; > struct rte_mem_config *mcfg =3D rte_eal_get_configuration()->mem_config; > const struct rte_memseg_list *msl; > @@ -602,12 +603,12 @@ struct mr_update_mp_data { > dev->data->port_id, (void *)addr); > /* > * Release detached MRs if any. This can't be called with holding either > - * memory_hotplug_lock or priv->mr.rwlock. MRs on the free list have > + * memory_hotplug_lock or sh->mr.rwlock. MRs on the free list have > * been detached by the memory free event but it couldn't be released > * inside the callback due to deadlock. As a result, releasing resources > * is quite opportunistic. > */ > - mlx5_mr_garbage_collect(dev); > + mlx5_mr_garbage_collect(sh); > /* > * If enabled, find out a contiguous virtual address chunk in use, to > * which the given address belongs, in order to register maximum range. > @@ -710,7 +711,7 @@ struct mr_update_mp_data { > goto alloc_resources; > } > assert(data.msl =3D=3D data_re.msl); > - rte_rwlock_write_lock(&priv->mr.rwlock); > + rte_rwlock_write_lock(&sh->mr.rwlock); > /* > * Check the address is really missing. If other thread already created > * one or it is not found due to overflow, abort and return. > @@ -721,10 +722,10 @@ struct mr_update_mp_data { > * low-on-memory. Then, this entry will have to be searched > * here again. > */ > - mr_btree_insert(&priv->mr.cache, entry); > + mr_btree_insert(&sh->mr.cache, entry); > DEBUG("port %u found MR for %p on final lookup, abort", > dev->data->port_id, (void *)addr); > - rte_rwlock_write_unlock(&priv->mr.rwlock); > + rte_rwlock_write_unlock(&sh->mr.rwlock); > rte_rwlock_read_unlock(&mcfg->memory_hotplug_lock); > /* > * Must be unlocked before calling rte_free() because > @@ -769,7 +770,7 @@ struct mr_update_mp_data { > * mlx5_alloc_buf_extern() which eventually calls rte_malloc_socket() > * through mlx5_alloc_verbs_buf(). > */ > - mr->ibv_mr =3D mlx5_glue->reg_mr(priv->sh->pd, (void *)data.start, len, > + mr->ibv_mr =3D mlx5_glue->reg_mr(sh->pd, (void *)data.start, len, > IBV_ACCESS_LOCAL_WRITE); > if (mr->ibv_mr =3D=3D NULL) { > DEBUG("port %u fail to create a verbs MR for address (%p)", > @@ -779,7 +780,7 @@ struct mr_update_mp_data { > } > assert((uintptr_t)mr->ibv_mr->addr =3D=3D data.start); > assert(mr->ibv_mr->length =3D=3D len); > - LIST_INSERT_HEAD(&priv->mr.mr_list, mr, mr); > + LIST_INSERT_HEAD(&sh->mr.mr_list, mr, mr); > DEBUG("port %u MR CREATED (%p) for %p:\n" > " [0x%" PRIxPTR ", 0x%" PRIxPTR ")," > " lkey=3D0x%x base_idx=3D%u ms_n=3D%u, ms_bmp_n=3D%u", > @@ -792,11 +793,11 @@ struct mr_update_mp_data { > mr_lookup_dev(dev, entry, addr); > /* Lookup can't fail. */ > assert(entry->lkey !=3D UINT32_MAX); > - rte_rwlock_write_unlock(&priv->mr.rwlock); > + rte_rwlock_write_unlock(&sh->mr.rwlock); > rte_rwlock_read_unlock(&mcfg->memory_hotplug_lock); > return entry->lkey; > err_mrlock: > - rte_rwlock_write_unlock(&priv->mr.rwlock); > + rte_rwlock_write_unlock(&sh->mr.rwlock); > err_memlock: > rte_rwlock_read_unlock(&mcfg->memory_hotplug_lock); > err_nolock: > @@ -854,14 +855,15 @@ struct mr_update_mp_data { > mr_rebuild_dev_cache(struct rte_eth_dev *dev) > { > struct mlx5_priv *priv =3D dev->data->dev_private; > + struct mlx5_ibv_shared *sh =3D priv->sh; > struct mlx5_mr *mr; >=20 > DRV_LOG(DEBUG, "port %u rebuild dev cache[]", dev->data->port_id); > /* Flush cache to rebuild. */ > - priv->mr.cache.len =3D 1; > - priv->mr.cache.overflow =3D 0; > + sh->mr.cache.len =3D 1; > + sh->mr.cache.overflow =3D 0; > /* Iterate all the existing MRs. */ > - LIST_FOREACH(mr, &priv->mr.mr_list, mr) > + LIST_FOREACH(mr, &sh->mr.mr_list, mr) > if (mr_insert_dev_cache(dev, mr) < 0) > return; > } > @@ -888,6 +890,7 @@ struct mr_update_mp_data { > mlx5_mr_mem_event_free_cb(struct rte_eth_dev *dev, const void *addr, size= _t len) > { > struct mlx5_priv *priv =3D dev->data->dev_private; > + struct mlx5_ibv_shared *sh =3D priv->sh; > const struct rte_memseg_list *msl; > struct mlx5_mr *mr; > int ms_n; > @@ -901,7 +904,7 @@ struct mr_update_mp_data { > assert((uintptr_t)addr =3D=3D RTE_ALIGN((uintptr_t)addr, msl->page_sz)); > assert(len =3D=3D RTE_ALIGN(len, msl->page_sz)); > ms_n =3D len / msl->page_sz; > - rte_rwlock_write_lock(&priv->mr.rwlock); > + rte_rwlock_write_lock(&sh->mr.rwlock); > /* Clear bits of freed memsegs from MR. */ > for (i =3D 0; i < ms_n; ++i) { > const struct rte_memseg *ms; > @@ -928,7 +931,7 @@ struct mr_update_mp_data { > rte_bitmap_clear(mr->ms_bmp, pos); > if (--mr->ms_n =3D=3D 0) { > LIST_REMOVE(mr, mr); > - LIST_INSERT_HEAD(&priv->mr.mr_free_list, mr, mr); > + LIST_INSERT_HEAD(&sh->mr.mr_free_list, mr, mr); > DEBUG("port %u remove MR(%p) from list", > dev->data->port_id, (void *)mr); > } > @@ -949,12 +952,12 @@ struct mr_update_mp_data { > * generation below) will be guaranteed to be seen by other core > * before the core sees the newly allocated memory. > */ > - ++priv->mr.dev_gen; > + ++sh->mr.dev_gen; > DEBUG("broadcasting local cache flush, gen=3D%d", > - priv->mr.dev_gen); > + sh->mr.dev_gen); > rte_smp_wmb(); > } > - rte_rwlock_write_unlock(&priv->mr.rwlock); > + rte_rwlock_write_unlock(&sh->mr.rwlock); > } >=20 > /** > @@ -1013,6 +1016,7 @@ struct mr_update_mp_data { > struct mlx5_mr_cache *entry, uintptr_t addr) > { > struct mlx5_priv *priv =3D dev->data->dev_private; > + struct mlx5_ibv_shared *sh =3D priv->sh; > struct mlx5_mr_btree *bt =3D &mr_ctrl->cache_bh; > uint16_t idx; > uint32_t lkey; > @@ -1021,12 +1025,12 @@ struct mr_update_mp_data { > if (unlikely(bt->len =3D=3D bt->size)) > mr_btree_expand(bt, bt->size << 1); > /* Look up in the global cache. */ > - rte_rwlock_read_lock(&priv->mr.rwlock); > - lkey =3D mr_btree_lookup(&priv->mr.cache, &idx, addr); > + rte_rwlock_read_lock(&sh->mr.rwlock); > + lkey =3D mr_btree_lookup(&sh->mr.cache, &idx, addr); > if (lkey !=3D UINT32_MAX) { > /* Found. */ > - *entry =3D (*priv->mr.cache.table)[idx]; > - rte_rwlock_read_unlock(&priv->mr.rwlock); > + *entry =3D (*sh->mr.cache.table)[idx]; > + rte_rwlock_read_unlock(&sh->mr.rwlock); > /* > * Update local cache. Even if it fails, return the found entry > * to update top-half cache. Next time, this entry will be found > @@ -1035,7 +1039,7 @@ struct mr_update_mp_data { > mr_btree_insert(bt, entry); > return lkey; > } > - rte_rwlock_read_unlock(&priv->mr.rwlock); > + rte_rwlock_read_unlock(&sh->mr.rwlock); > /* First time to see the address? Create a new MR. */ > lkey =3D mlx5_mr_create(dev, entry, addr); > /* > @@ -1261,6 +1265,7 @@ struct mr_update_mp_data { > struct mr_update_mp_data *data =3D opaque; > struct rte_eth_dev *dev =3D data->dev; > struct mlx5_priv *priv =3D dev->data->dev_private; > + struct mlx5_ibv_shared *sh =3D priv->sh; > struct mlx5_mr_ctrl *mr_ctrl =3D data->mr_ctrl; > struct mlx5_mr *mr =3D NULL; > uintptr_t addr =3D (uintptr_t)memhdr->addr; > @@ -1270,9 +1275,9 @@ struct mr_update_mp_data { >=20 > assert(rte_eal_process_type() =3D=3D RTE_PROC_PRIMARY); > /* If already registered, it should return. */ > - rte_rwlock_read_lock(&priv->mr.rwlock); > + rte_rwlock_read_lock(&sh->mr.rwlock); > lkey =3D mr_lookup_dev(dev, &entry, addr); > - rte_rwlock_read_unlock(&priv->mr.rwlock); > + rte_rwlock_read_unlock(&sh->mr.rwlock); > if (lkey !=3D UINT32_MAX) > return; > DRV_LOG(DEBUG, "port %u register MR for chunk #%d of mempool (%s)", > @@ -1286,11 +1291,11 @@ struct mr_update_mp_data { > data->ret =3D -1; > return; > } > - rte_rwlock_write_lock(&priv->mr.rwlock); > - LIST_INSERT_HEAD(&priv->mr.mr_list, mr, mr); > + rte_rwlock_write_lock(&sh->mr.rwlock); > + LIST_INSERT_HEAD(&sh->mr.mr_list, mr, mr); > /* Insert to the global cache table. */ > mr_insert_dev_cache(dev, mr); > - rte_rwlock_write_unlock(&priv->mr.rwlock); > + rte_rwlock_write_unlock(&sh->mr.rwlock); > /* Insert to the local cache table */ > mlx5_mr_addr2mr_bh(dev, mr_ctrl, addr); > } > @@ -1339,6 +1344,7 @@ struct mr_update_mp_data { > struct rte_eth_dev *dev; > struct mlx5_mr *mr; > struct mlx5_priv *priv; > + struct mlx5_ibv_shared *sh; >=20 > dev =3D pci_dev_to_eth_dev(pdev); > if (!dev) { > @@ -1355,11 +1361,12 @@ struct mr_update_mp_data { > rte_errno =3D EINVAL; > return -1; > } > - rte_rwlock_write_lock(&priv->mr.rwlock); > - LIST_INSERT_HEAD(&priv->mr.mr_list, mr, mr); > + sh =3D priv->sh; > + rte_rwlock_write_lock(&sh->mr.rwlock); > + LIST_INSERT_HEAD(&sh->mr.mr_list, mr, mr); > /* Insert to the global cache table. */ > mr_insert_dev_cache(dev, mr); > - rte_rwlock_write_unlock(&priv->mr.rwlock); > + rte_rwlock_write_unlock(&sh->mr.rwlock); > return 0; > } >=20 > @@ -1384,6 +1391,7 @@ struct mr_update_mp_data { > { > struct rte_eth_dev *dev; > struct mlx5_priv *priv; > + struct mlx5_ibv_shared *sh; > struct mlx5_mr *mr; > struct mlx5_mr_cache entry; >=20 > @@ -1395,10 +1403,11 @@ struct mr_update_mp_data { > return -1; > } > priv =3D dev->data->dev_private; > - rte_rwlock_read_lock(&priv->mr.rwlock); > + sh =3D priv->sh; > + rte_rwlock_read_lock(&sh->mr.rwlock); > mr =3D mr_lookup_dev_list(dev, &entry, (uintptr_t)addr); > if (!mr) { > - rte_rwlock_read_unlock(&priv->mr.rwlock); > + rte_rwlock_read_unlock(&sh->mr.rwlock); > DRV_LOG(WARNING, "address 0x%" PRIxPTR " wasn't registered " > "to PCI device %p", (uintptr_t)addr, > (void *)pdev); > @@ -1406,7 +1415,7 @@ struct mr_update_mp_data { > return -1; > } > LIST_REMOVE(mr, mr); > - LIST_INSERT_HEAD(&priv->mr.mr_free_list, mr, mr); > + LIST_INSERT_HEAD(&sh->mr.mr_free_list, mr, mr); > DEBUG("port %u remove MR(%p) from list", dev->data->port_id, > (void *)mr); > mr_rebuild_dev_cache(dev); > @@ -1419,11 +1428,10 @@ struct mr_update_mp_data { > * generation below) will be guaranteed to be seen by other core > * before the core sees the newly allocated memory. > */ > - ++priv->mr.dev_gen; > - DEBUG("broadcasting local cache flush, gen=3D%d", > - priv->mr.dev_gen); > + ++sh->mr.dev_gen; > + DEBUG("broadcasting local cache flush, gen=3D%d", sh->mr.dev_gen); > rte_smp_wmb(); > - rte_rwlock_read_unlock(&priv->mr.rwlock); > + rte_rwlock_read_unlock(&sh->mr.rwlock); > return 0; > } >=20 > @@ -1544,25 +1552,24 @@ struct mr_update_mp_data { > /** > * Dump all the created MRs and the global cache entries. > * > - * @param dev > - * Pointer to Ethernet device. > + * @param sh > + * Pointer to Ethernet device shared context. > */ > void > -mlx5_mr_dump_dev(struct rte_eth_dev *dev __rte_unused) > +mlx5_mr_dump_dev(struct mlx5_ibv_shared *sh __rte_unused) > { > #ifndef NDEBUG > - struct mlx5_priv *priv =3D dev->data->dev_private; > struct mlx5_mr *mr; > int mr_n =3D 0; > int chunk_n =3D 0; >=20 > - rte_rwlock_read_lock(&priv->mr.rwlock); > + rte_rwlock_read_lock(&sh->mr.rwlock); > /* Iterate all the existing MRs. */ > - LIST_FOREACH(mr, &priv->mr.mr_list, mr) { > + LIST_FOREACH(mr, &sh->mr.mr_list, mr) { > unsigned int n; >=20 > - DEBUG("port %u MR[%u], LKey =3D 0x%x, ms_n =3D %u, ms_bmp_n =3D %u", > - dev->data->port_id, mr_n++, > + DEBUG("device %s MR[%u], LKey =3D 0x%x, ms_n =3D %u, ms_bmp_n =3D %u", > + sh->ibdev_name, mr_n++, > rte_cpu_to_be_32(mr->ibv_mr->lkey), > mr->ms_n, mr->ms_bmp_n); > if (mr->ms_n =3D=3D 0) > @@ -1577,45 +1584,40 @@ struct mr_update_mp_data { > chunk_n++, ret.start, ret.end); > } > } > - DEBUG("port %u dumping global cache", dev->data->port_id); > - mlx5_mr_btree_dump(&priv->mr.cache); > - rte_rwlock_read_unlock(&priv->mr.rwlock); > + DEBUG("device %s dumping global cache", sh->ibdev_name); > + mlx5_mr_btree_dump(&sh->mr.cache); > + rte_rwlock_read_unlock(&sh->mr.rwlock); > #endif > } >=20 > /** > - * Release all the created MRs and resources. Remove device from memory = callback > + * Release all the created MRs and resources for shared device context. > * list. > * > - * @param dev > - * Pointer to Ethernet device. > + * @param sh > + * Pointer to Ethernet device shared context. > */ > void > -mlx5_mr_release(struct rte_eth_dev *dev) > +mlx5_mr_release(struct mlx5_ibv_shared *sh) > { > - struct mlx5_priv *priv =3D dev->data->dev_private; > struct mlx5_mr *mr_next; >=20 > - /* Remove from memory callback device list. */ > - rte_rwlock_write_lock(&mlx5_shared_data->mem_event_rwlock); > - LIST_REMOVE(priv, mem_event_cb); > - rte_rwlock_write_unlock(&mlx5_shared_data->mem_event_rwlock); > if (rte_log_get_level(mlx5_logtype) =3D=3D RTE_LOG_DEBUG) > - mlx5_mr_dump_dev(dev); > - rte_rwlock_write_lock(&priv->mr.rwlock); > + mlx5_mr_dump_dev(sh); > + rte_rwlock_write_lock(&sh->mr.rwlock); > /* Detach from MR list and move to free list. */ > - mr_next =3D LIST_FIRST(&priv->mr.mr_list); > + mr_next =3D LIST_FIRST(&sh->mr.mr_list); > while (mr_next !=3D NULL) { > struct mlx5_mr *mr =3D mr_next; >=20 > mr_next =3D LIST_NEXT(mr, mr); > LIST_REMOVE(mr, mr); > - LIST_INSERT_HEAD(&priv->mr.mr_free_list, mr, mr); > + LIST_INSERT_HEAD(&sh->mr.mr_free_list, mr, mr); > } > - LIST_INIT(&priv->mr.mr_list); > + LIST_INIT(&sh->mr.mr_list); > /* Free global cache. */ > - mlx5_mr_btree_free(&priv->mr.cache); > - rte_rwlock_write_unlock(&priv->mr.rwlock); > + mlx5_mr_btree_free(&sh->mr.cache); > + rte_rwlock_write_unlock(&sh->mr.rwlock); > /* Free all remaining MRs. */ > - mlx5_mr_garbage_collect(dev); > + mlx5_mr_garbage_collect(sh); > } > diff --git a/drivers/net/mlx5/mlx5_mr.h b/drivers/net/mlx5/mlx5_mr.h > index 786f6a3..89e89b7 100644 > --- a/drivers/net/mlx5/mlx5_mr.h > +++ b/drivers/net/mlx5/mlx5_mr.h > @@ -62,6 +62,7 @@ struct mlx5_mr_ctrl { > struct mlx5_mr_btree cache_bh; /* Cache for bottom-half. */ > } __rte_packed; >=20 > +struct mlx5_ibv_shared; > extern struct mlx5_dev_list mlx5_mem_event_cb_list; > extern rte_rwlock_t mlx5_mem_event_rwlock; >=20 > @@ -76,11 +77,11 @@ void mlx5_mr_mem_event_cb(enum rte_mem_event event_ty= pe, const void *addr, > size_t len, void *arg); > int mlx5_mr_update_mp(struct rte_eth_dev *dev, struct mlx5_mr_ctrl *mr_ct= rl, > struct rte_mempool *mp); > -void mlx5_mr_release(struct rte_eth_dev *dev); > +void mlx5_mr_release(struct mlx5_ibv_shared *sh); >=20 > /* Debug purpose functions. */ > void mlx5_mr_btree_dump(struct mlx5_mr_btree *bt); > -void mlx5_mr_dump_dev(struct rte_eth_dev *dev); > +void mlx5_mr_dump_dev(struct mlx5_ibv_shared *sh); >=20 > /** > * Look up LKey from given lookup table by linear search. Firstly look up= the > diff --git a/drivers/net/mlx5/mlx5_txq.c b/drivers/net/mlx5/mlx5_txq.c > index dbe074f..4d55fd4 100644 > --- a/drivers/net/mlx5/mlx5_txq.c > +++ b/drivers/net/mlx5/mlx5_txq.c > @@ -814,7 +814,7 @@ struct mlx5_txq_ctrl * > goto error; > } > /* Save pointer of global generation number to check memory event. */ > - tmpl->txq.mr_ctrl.dev_gen_ptr =3D &priv->mr.dev_gen; > + tmpl->txq.mr_ctrl.dev_gen_ptr =3D &priv->sh->mr.dev_gen; > assert(desc > MLX5_TX_COMP_THRESH); > tmpl->txq.offloads =3D conf->offloads | > dev->data->dev_conf.txmode.offloads; > --=20 > 1.8.3.1 >=20