[PATCH 4/5] lsblk: introduce 'MQ' column

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Typically a modern block device supports mutil queues feature, count
queues by walking '$sysfs/mq' directory. If no '$sysfs/mq' exists, it
is a legacy single queue.

~# lsblk --nvme -o NAME,TYPE,MODEL,TRAN,RQ-SIZE,MQ
NAME    TYPE MODEL                      TRAN   RQ-SIZE  MQ
nvme0n1 disk INTEL SSDPF2KX038TZ        nvme      1023 135
nvme3n1 disk INTEL SSDPE2KX020T8        nvme      1023 128
nvme1n1 disk SAMSUNG MZQL23T8HCLS-00A07 nvme      1023 129
nvme2n2 disk RP2A03T8RK004LX            nvme      1023  64
nvme2n3 disk RP2A03T8RK004LX            nvme      1023  64

Signed-off-by: zhenwei pi <pizhenwei@xxxxxxxxxxxxx>
---
 bash-completion/lsblk |  2 +-
 misc-utils/lsblk.c    | 33 +++++++++++++++++++++++++++++++++
 2 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/bash-completion/lsblk b/bash-completion/lsblk
index 697dd23d2..6756764b2 100644
--- a/bash-completion/lsblk
+++ b/bash-completion/lsblk
@@ -11,7 +11,7 @@ _lsblk_module()
 		RO RM HOTPLUG MODEL SERIAL SIZE STATE OWNER GROUP MODE ALIGNMENT MIN-IO OPT-IO
 		PHY-SEC LOG-SEC ROTA SCHED RQ-SIZE TYPE DISC-ALN DISC-GRAN DISC-MAX DISC-ZERO
 		WSAME WWN RAND PKNAME HCTL TRAN SUBSYSTEMS REV VENDOR ZONED ZONE-SZ ZONE-WGRAN
-		ZONE-APP ZONE-NR ZONE-OMAX ZONE-AMAX DAX
+		ZONE-APP ZONE-NR ZONE-OMAX ZONE-AMAX DAX MQ
 	"
 
 	case $prev in
diff --git a/misc-utils/lsblk.c b/misc-utils/lsblk.c
index 64d7edad6..d9c4ee982 100644
--- a/misc-utils/lsblk.c
+++ b/misc-utils/lsblk.c
@@ -90,6 +90,7 @@ enum {
 	COL_MINIO,
 	COL_MODE,
 	COL_MODEL,
+	COL_MQ,
 	COL_NAME,
 	COL_OPTIO,
 	COL_OWNER,
@@ -189,6 +190,7 @@ static struct colinfo infos[] = {
 	[COL_MINIO] = { "MIN-IO", 6, SCOLS_FL_RIGHT, N_("minimum I/O size"), COLTYPE_NUM },
 	[COL_MODEL] = { "MODEL", 0.1, SCOLS_FL_TRUNC, N_("device identifier") },
 	[COL_MODE] = { "MODE", 10, 0, N_("device node permissions") },
+	[COL_MQ] = { "MQ", 3, SCOLS_FL_RIGHT, N_("device queues") },
 	[COL_NAME] = { "NAME", 0.25, SCOLS_FL_NOEXTREMES, N_("device name") },
 	[COL_OPTIO] = { "OPT-IO", 6, SCOLS_FL_RIGHT, N_("optimal I/O size"), COLTYPE_NUM },
 	[COL_OWNER] = { "OWNER", 0.1, SCOLS_FL_TRUNC, N_("user name"), },
@@ -746,6 +748,34 @@ static void device_read_bytes(struct lsblk_device *dev, char *path, char **str,
 	}
 }
 
+static void process_mq(struct lsblk_device *dev, char **str)
+{
+	DIR *dir;
+	struct dirent *d;
+	unsigned int queues = 0;
+
+	DBG(DEV, ul_debugobj(dev, "%s: process mq", dev->name));
+
+	dir = ul_path_opendir(dev->sysfs, "mq");
+	if (!dir) {
+		*str = xstrdup("1");
+		DBG(DEV, ul_debugobj(dev, "%s: no mq supported, use a single queue", dev->name));
+		return;
+	}
+
+	while ((d = xreaddir(dir))) {
+		if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, ".."))
+			continue;
+
+		queues++;
+	}
+
+	closedir(dir);
+
+	DBG(DEV, ul_debugobj(dev, "%s: has %d queues", dev->name, queues));
+	xasprintf(str, "%3u", queues);
+}
+
 /*
  * Generates data (string) for column specified by column ID for specified device. If sortdata
  * is not NULL then returns number usable to sort the column if the data are available for the
@@ -1143,6 +1173,9 @@ static char *device_get_data(
 	case COL_DAX:
 		ul_path_read_string(dev->sysfs, &str, "queue/dax");
 		break;
+	case COL_MQ:
+		process_mq(dev, &str);
+		break;
 	};
 
 	return str;
-- 
2.20.1




[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux