Skip to content

Commit d4861fc

Browse files
peilin-yedavem330
authored andcommitted
netdevsim: Add multi-queue support
Currently netdevsim only supports a single queue per port, which is insufficient for testing multi-queue TC schedulers e.g. sch_mq. Extend the current sysfs interface so that users can create ports with multiple queues: $ echo "[ID] [PORT_COUNT] [NUM_QUEUES]" > /sys/bus/netdevsim/new_device As an example, echoing "2 4 8" creates 4 ports, with 8 queues per port. Note, this is compatible with the current interface, with default number of queues set to 1. For example, echoing "2 4" creates 4 ports with 1 queue per port; echoing "2" simply creates 1 port with 1 queue. Reviewed-by: Cong Wang <[email protected]> Signed-off-by: Peilin Ye <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent b83d23a commit d4861fc

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

drivers/net/netdevsim/bus.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -262,29 +262,31 @@ static struct device_type nsim_bus_dev_type = {
262262
};
263263

264264
static struct nsim_bus_dev *
265-
nsim_bus_dev_new(unsigned int id, unsigned int port_count);
265+
nsim_bus_dev_new(unsigned int id, unsigned int port_count, unsigned int num_queues);
266266

267267
static ssize_t
268268
new_device_store(struct bus_type *bus, const char *buf, size_t count)
269269
{
270+
unsigned int id, port_count, num_queues;
270271
struct nsim_bus_dev *nsim_bus_dev;
271-
unsigned int port_count;
272-
unsigned int id;
273272
int err;
274273

275-
err = sscanf(buf, "%u %u", &id, &port_count);
274+
err = sscanf(buf, "%u %u %u", &id, &port_count, &num_queues);
276275
switch (err) {
277276
case 1:
278277
port_count = 1;
279278
fallthrough;
280279
case 2:
280+
num_queues = 1;
281+
fallthrough;
282+
case 3:
281283
if (id > INT_MAX) {
282284
pr_err("Value of \"id\" is too big.\n");
283285
return -EINVAL;
284286
}
285287
break;
286288
default:
287-
pr_err("Format for adding new device is \"id port_count\" (uint uint).\n");
289+
pr_err("Format for adding new device is \"id port_count num_queues\" (uint uint unit).\n");
288290
return -EINVAL;
289291
}
290292

@@ -295,7 +297,7 @@ new_device_store(struct bus_type *bus, const char *buf, size_t count)
295297
goto err;
296298
}
297299

298-
nsim_bus_dev = nsim_bus_dev_new(id, port_count);
300+
nsim_bus_dev = nsim_bus_dev_new(id, port_count, num_queues);
299301
if (IS_ERR(nsim_bus_dev)) {
300302
err = PTR_ERR(nsim_bus_dev);
301303
goto err;
@@ -397,7 +399,7 @@ static struct bus_type nsim_bus = {
397399
#define NSIM_BUS_DEV_MAX_VFS 4
398400

399401
static struct nsim_bus_dev *
400-
nsim_bus_dev_new(unsigned int id, unsigned int port_count)
402+
nsim_bus_dev_new(unsigned int id, unsigned int port_count, unsigned int num_queues)
401403
{
402404
struct nsim_bus_dev *nsim_bus_dev;
403405
int err;
@@ -413,6 +415,7 @@ nsim_bus_dev_new(unsigned int id, unsigned int port_count)
413415
nsim_bus_dev->dev.bus = &nsim_bus;
414416
nsim_bus_dev->dev.type = &nsim_bus_dev_type;
415417
nsim_bus_dev->port_count = port_count;
418+
nsim_bus_dev->num_queues = num_queues;
416419
nsim_bus_dev->initial_net = current->nsproxy->net_ns;
417420
nsim_bus_dev->max_vfs = NSIM_BUS_DEV_MAX_VFS;
418421
mutex_init(&nsim_bus_dev->nsim_bus_reload_lock);

drivers/net/netdevsim/netdev.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,8 @@ nsim_create(struct nsim_dev *nsim_dev, struct nsim_dev_port *nsim_dev_port)
347347
struct netdevsim *ns;
348348
int err;
349349

350-
dev = alloc_netdev(sizeof(*ns), "eth%d", NET_NAME_UNKNOWN, nsim_setup);
350+
dev = alloc_netdev_mq(sizeof(*ns), "eth%d", NET_NAME_UNKNOWN, nsim_setup,
351+
nsim_dev->nsim_bus_dev->num_queues);
351352
if (!dev)
352353
return ERR_PTR(-ENOMEM);
353354

@@ -392,7 +393,8 @@ void nsim_destroy(struct netdevsim *ns)
392393
static int nsim_validate(struct nlattr *tb[], struct nlattr *data[],
393394
struct netlink_ext_ack *extack)
394395
{
395-
NL_SET_ERR_MSG_MOD(extack, "Please use: echo \"[ID] [PORT_COUNT]\" > /sys/bus/netdevsim/new_device");
396+
NL_SET_ERR_MSG_MOD(extack,
397+
"Please use: echo \"[ID] [PORT_COUNT] [NUM_QUEUES]\" > /sys/bus/netdevsim/new_device");
396398
return -EOPNOTSUPP;
397399
}
398400

drivers/net/netdevsim/netdevsim.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ struct nsim_bus_dev {
352352
struct device dev;
353353
struct list_head list;
354354
unsigned int port_count;
355+
unsigned int num_queues; /* Number of queues for each port on this bus */
355356
struct net *initial_net; /* Purpose of this is to carry net pointer
356357
* during the probe time only.
357358
*/

0 commit comments

Comments
 (0)