Skip to content
Permalink
Browse files
IB/core: Obtain subnet_prefix from cache in IB devices
ib_query_port() calls device->ops.query_port() to get the port
attributes. The method of querying is device driver specific.
The same function calls device->ops.query_gid() to get the GID and
extract the subnet_prefix (gid_prefix).

The GID and subnet_prefix are stored in a cache. But they do not get
read from the cache if the device is an Infiniband device. The
following change takes advantage of the cached subnet_prefix.
Testing with RDBMS has shown a significant improvement in performance
with this change.

The function ib_cache_is_initialised() is introduced because
ib_query_port() gets called early in the stage when the cache is not
built while reading port immutable property.

In that case, the default GID still gets read from HCA for IB link-
layer devices.

In the situation of an event causing cache update, the subnet_prefix
will get retrieved from newly updated GID cache in ib_cache_update(),
so that we do not end up reading a stale value from cache via
ib_query_port().

Fixes: fad61ad ("IB/core: Add subnet prefix to port info")
Suggested-by: Leon Romanovsky <leonro@nvidia.com>
Suggested-by: Aru Kolappan <aru.kolappan@oracle.com>
Signed-off-by: Anand Khoje <anand.a.khoje@oracle.com>
Signed-off-by: Haakon Bugge <haakon.bugge@oracle.com>
  • Loading branch information
Anand Khoje authored and intel-lab-lkp committed Jun 17, 2021
1 parent 717e706 commit 495253a987df586d8c5f4c525999cdf39c5823f0
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
@@ -917,9 +917,11 @@ static void gid_table_cleanup_one(struct ib_device *ib_dev)
{
u32 p;

rdma_for_each_port (ib_dev, p)
rdma_for_each_port (ib_dev, p) {
ib_dev->port_data[p].cache_is_initialized = 0;
cleanup_gid_table_port(ib_dev, p,
ib_dev->port_data[p].cache.gid);
}
}

static int gid_table_setup_one(struct ib_device *ib_dev)
@@ -1466,6 +1468,7 @@ ib_cache_update(struct ib_device *device, u32 port, bool update_gids,
struct ib_port_attr *tprops = NULL;
struct ib_pkey_cache *pkey_cache = NULL;
struct ib_pkey_cache *old_pkey_cache = NULL;
union ib_gid gid;
int i;
int ret;

@@ -1523,13 +1526,21 @@ ib_cache_update(struct ib_device *device, u32 port, bool update_gids,
device->port_data[port].cache.lmc = tprops->lmc;
device->port_data[port].cache.port_state = tprops->state;

device->port_data[port].cache.subnet_prefix = tprops->subnet_prefix;
ret = rdma_query_gid(device, port, 0, &gid);
if (ret) {
write_unlock_irq(&device->cache.lock);
goto err;
}

device->port_data[port].cache.subnet_prefix =
be64_to_cpu(gid.global.subnet_prefix);

write_unlock_irq(&device->cache_lock);

if (enforce_security)
ib_security_cache_change(device,
port,
tprops->subnet_prefix);
be64_to_cpu(gid.global.subnet_prefix));

kfree(old_pkey_cache);
kfree(tprops);
@@ -1629,6 +1640,7 @@ int ib_cache_setup_one(struct ib_device *device)
err = ib_cache_update(device, p, true, true, true);
if (err)
return err;
device->port_data[p].cache_is_initialized = 1;
}

return 0;
@@ -2057,6 +2057,15 @@ static int __ib_query_port(struct ib_device *device,
IB_LINK_LAYER_INFINIBAND)
return 0;

if (!ib_cache_is_initialised(device, port_num))
goto query_gid_from_device;

ib_get_cached_subnet_prefix(device, port_num,
&port_attr->subnet_prefix);

return 0;

query_gid_from_device:
err = device->ops.query_gid(device, port_num, 0, &gid);
if (err)
return err;
@@ -114,4 +114,9 @@ ssize_t rdma_query_gid_table(struct ib_device *device,
struct ib_uverbs_gid_entry *entries,
size_t max_entries);

static inline bool ib_cache_is_initialised(struct ib_device *device,
u32 port_num)
{
return device->port_data[port_num].cache_is_initialized;
}
#endif /* _IB_CACHE_H */
@@ -2177,6 +2177,7 @@ struct ib_port_data {

spinlock_t netdev_lock;

u8 cache_is_initialized:1;
struct list_head pkey_list;

struct ib_port_cache cache;

0 comments on commit 495253a

Please sign in to comment.