Skip to content

Commit 055422d

Browse files
Alexander ChiangRoland Dreier
authored andcommitted
IB/uverbs: Convert *cdev to cdev in struct ib_uverbs_device
Instead of storing a pointer to a cdev, embed the entire struct cdev. This change allows us to use the container_of() macro in ib_uverbs_open() in a future patch. This change increases the size of struct ib_uverbs_device to 168 bytes across 3 cachelines from 80 bytes in 2 cachelines. However, we rearrange the members so that everything fits into the first cacheline except for the struct cdev. Finally, we don't touch the cdev in any fastpaths, so this change shouldn't negatively affect performance. Signed-off-by: Alex Chiang <achiang@hp.com> Signed-off-by: Roland Dreier <rolandd@cisco.com>
1 parent 676ad58 commit 055422d

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

drivers/infiniband/core/uverbs.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include <linux/idr.h>
4242
#include <linux/mutex.h>
4343
#include <linux/completion.h>
44+
#include <linux/cdev.h>
4445

4546
#include <rdma/ib_verbs.h>
4647
#include <rdma/ib_umem.h>
@@ -69,12 +70,12 @@
6970

7071
struct ib_uverbs_device {
7172
struct kref ref;
73+
int num_comp_vectors;
7274
struct completion comp;
73-
int devnum;
74-
struct cdev *cdev;
7575
struct device *dev;
7676
struct ib_device *ib_dev;
77-
int num_comp_vectors;
77+
int devnum;
78+
struct cdev cdev;
7879
};
7980

8081
struct ib_uverbs_event_file {

drivers/infiniband/core/uverbs_main.c

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
#include <linux/sched.h>
4444
#include <linux/file.h>
4545
#include <linux/mount.h>
46-
#include <linux/cdev.h>
4746

4847
#include <asm/uaccess.h>
4948

@@ -761,17 +760,15 @@ static void ib_uverbs_add_one(struct ib_device *device)
761760
uverbs_dev->ib_dev = device;
762761
uverbs_dev->num_comp_vectors = device->num_comp_vectors;
763762

764-
uverbs_dev->cdev = cdev_alloc();
765-
if (!uverbs_dev->cdev)
766-
goto err;
767-
uverbs_dev->cdev->owner = THIS_MODULE;
768-
uverbs_dev->cdev->ops = device->mmap ? &uverbs_mmap_fops : &uverbs_fops;
769-
kobject_set_name(&uverbs_dev->cdev->kobj, "uverbs%d", uverbs_dev->devnum);
770-
if (cdev_add(uverbs_dev->cdev, IB_UVERBS_BASE_DEV + uverbs_dev->devnum, 1))
763+
cdev_init(&uverbs_dev->cdev, NULL);
764+
uverbs_dev->cdev.owner = THIS_MODULE;
765+
uverbs_dev->cdev.ops = device->mmap ? &uverbs_mmap_fops : &uverbs_fops;
766+
kobject_set_name(&uverbs_dev->cdev.kobj, "uverbs%d", uverbs_dev->devnum);
767+
if (cdev_add(&uverbs_dev->cdev, IB_UVERBS_BASE_DEV + uverbs_dev->devnum, 1))
771768
goto err_cdev;
772769

773770
uverbs_dev->dev = device_create(uverbs_class, device->dma_device,
774-
uverbs_dev->cdev->dev, uverbs_dev,
771+
uverbs_dev->cdev.dev, uverbs_dev,
775772
"uverbs%d", uverbs_dev->devnum);
776773
if (IS_ERR(uverbs_dev->dev))
777774
goto err_cdev;
@@ -790,10 +787,10 @@ static void ib_uverbs_add_one(struct ib_device *device)
790787
return;
791788

792789
err_class:
793-
device_destroy(uverbs_class, uverbs_dev->cdev->dev);
790+
device_destroy(uverbs_class, uverbs_dev->cdev.dev);
794791

795792
err_cdev:
796-
cdev_del(uverbs_dev->cdev);
793+
cdev_del(&uverbs_dev->cdev);
797794
clear_bit(uverbs_dev->devnum, dev_map);
798795

799796
err:
@@ -811,8 +808,8 @@ static void ib_uverbs_remove_one(struct ib_device *device)
811808
return;
812809

813810
dev_set_drvdata(uverbs_dev->dev, NULL);
814-
device_destroy(uverbs_class, uverbs_dev->cdev->dev);
815-
cdev_del(uverbs_dev->cdev);
811+
device_destroy(uverbs_class, uverbs_dev->cdev.dev);
812+
cdev_del(&uverbs_dev->cdev);
816813

817814
spin_lock(&map_lock);
818815
dev_table[uverbs_dev->devnum] = NULL;

0 commit comments

Comments
 (0)