Skip to contentSkip to conversation

Introduce hba performance monitoring sysfs nodes

PATCH Superseded Can Guo 2 participants 8 messages Apr 1, 2021 – Apr 6, 2021 SCSI

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Can Guo

author
#0 lore raw

v4 cover Introduce hba performance monitoring sysfs nodes

Add a new sysfs group which has nodes to monitor data/request transfer performance. This sysfs group has nodes showing total sectors/requests transferred, total busy time spent and max/min/avg/sum latencies. This group can be enhanced later to show more UFS driver layer performance data during runtime.

It works like:
/sys/bus/platform/drivers/ufshcd/*/monitor # echo 4096 > monitor_chunk_size /sys/bus/platform/drivers/ufshcd/*/monitor # echo 1 > monitor_enable /sys/bus/platform/drivers/ufshcd/*/monitor # grep ^ /dev/null * monitor_chunk_size:4096
monitor_enable:1
read_nr_requests:17
read_req_latency_avg:169
read_req_latency_max:594
read_req_latency_min:66
read_req_latency_sum:2887
read_total_busy:2639
read_total_sectors:136
write_nr_requests:116
write_req_latency_avg:440
write_req_latency_max:4921
write_req_latency_min:23
write_req_latency_sum:51052
write_total_busy:19584
write_total_sectors:928

Change since v3:
- Rebased

Change since v2:
- Fixed a sparse error

Change since v1:
- Moved code from ufs-qcom.c to ufshcd.c

Can Guo (2):
scsi: ufs: Introduce hba performance monitor sysfs nodes
scsi: ufs: Add support for hba performance monitor

 Documentation/ABI/testing/sysfs-driver-ufs | 126 +++++++++++++++
 drivers/scsi/ufs/ufs-sysfs.c               | 237 +++++++++++++++++++++++++++++
 drivers/scsi/ufs/ufshcd.c                  |  62 ++++++++
 drivers/scsi/ufs/ufshcd.h                  |  21 +++
 4 files changed, 446 insertions(+)
Signature · 1 line
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.
author
#1 lore raw

PATCH v4 1/2 scsi: ufs: Introduce hba performance monitor sysfs nodes

Add a new sysfs group which has nodes to monitor data/request transfer performance. This sysfs group has nodes showing total sectors/requests transferred, total busy time spent and max/min/avg/sum latencies. This group can be enhanced later to show more UFS driver layer performance statistics data during runtime.

drivers/scsi/ufs/ufs-sysfs.c +237 -0
index acc54f5..348df0e 100644
@@ -278,6 +278,242 @@ static const struct attribute_group ufs_sysfs_default_group = {
 	.attrs = ufs_sysfs_ufshcd_attrs,
 };
 
+static ssize_t monitor_enable_show(struct device *dev,
+				   struct device_attribute *attr, char *buf)
+{
+	struct ufs_hba *hba = dev_get_drvdata(dev);
+
+	return sysfs_emit(buf, "%d\n", hba->monitor.enabled);
+}
+
+static ssize_t monitor_enable_store(struct device *dev,
+				    struct device_attribute *attr,
+				    const char *buf, size_t count)
+{
+	struct ufs_hba *hba = dev_get_drvdata(dev);
+	unsigned long value, flags;
+
+	if (kstrtoul(buf, 0, &value))
+		return -EINVAL;
+
+	value = !!value;
+	spin_lock_irqsave(hba->host->host_lock, flags);
+	if (value == hba->monitor.enabled)
+		goto out_unlock;
+
+	if (!value) {
+		memset(&hba->monitor, 0, sizeof(hba->monitor));
+	} else {
+		hba->monitor.enabled = true;
+		hba->monitor.enabled_ts = ktime_get();
+	}
+
+out_unlock:
+	spin_unlock_irqrestore(hba->host->host_lock, flags);
+	return count;
+}
+
+static ssize_t monitor_chunk_size_show(struct device *dev,
+				   struct device_attribute *attr, char *buf)
+{
+	struct ufs_hba *hba = dev_get_drvdata(dev);
+
+	return sysfs_emit(buf, "%lu\n", hba->monitor.chunk_size);
+}
+
+static ssize_t monitor_chunk_size_store(struct device *dev,
+				    struct device_attribute *attr,
+				    const char *buf, size_t count)
+{
+	struct ufs_hba *hba = dev_get_drvdata(dev);
+	unsigned long value, flags;
+
+	if (kstrtoul(buf, 0, &value))
+		return -EINVAL;
+
+	spin_lock_irqsave(hba->host->host_lock, flags);
+	/* Only allow chunk size change when monitor is disabled */
+	if (!hba->monitor.enabled)
+		hba->monitor.chunk_size = value;
+	spin_unlock_irqrestore(hba->host->host_lock, flags);
+	return count;
+}
+
+static ssize_t read_total_sectors_show(struct device *dev,
+				       struct device_attribute *attr, char *buf)
+{
+	struct ufs_hba *hba = dev_get_drvdata(dev);
+
+	return sysfs_emit(buf, "%lu\n", hba->monitor.nr_sec_rw[READ]);
+}
+
+static ssize_t read_total_busy_show(struct device *dev,
+				    struct device_attribute *attr, char *buf)
+{
+	struct ufs_hba *hba = dev_get_drvdata(dev);
+
+	return sysfs_emit(buf, "%llu\n",
+			  ktime_to_us(hba->monitor.total_busy[READ]));
+}
+
+static ssize_t read_nr_requests_show(struct device *dev,
+				     struct device_attribute *attr, char *buf)
+{
+	struct ufs_hba *hba = dev_get_drvdata(dev);
+
+	return sysfs_emit(buf, "%lu\n", hba->monitor.nr_req[READ]);
+}
+
+static ssize_t read_req_latency_avg_show(struct device *dev,
+					 struct device_attribute *attr,
+					 char *buf)
+{
+	struct ufs_hba *hba = dev_get_drvdata(dev);
+	struct ufs_hba_monitor *m = &hba->monitor;
+
+	return sysfs_emit(buf, "%llu\n", div_u64(ktime_to_us(m->lat_sum[READ]),
+						 m->nr_req[READ]));
+}
+
+static ssize_t read_req_latency_max_show(struct device *dev,
+					 struct device_attribute *attr,
+					 char *buf)
+{
+	struct ufs_hba *hba = dev_get_drvdata(dev);
+
+	return sysfs_emit(buf, "%llu\n",
+			  ktime_to_us(hba->monitor.lat_max[READ]));
+}
+
+static ssize_t read_req_latency_min_show(struct device *dev,
+					 struct device_attribute *attr,
+					 char *buf)
+{
+	struct ufs_hba *hba = dev_get_drvdata(dev);
+
+	return sysfs_emit(buf, "%llu\n",
+			  ktime_to_us(hba->monitor.lat_min[READ]));
+}
+
+static ssize_t read_req_latency_sum_show(struct device *dev,
+					 struct device_attribute *attr,
+					 char *buf)
+{
+	struct ufs_hba *hba = dev_get_drvdata(dev);
+
+	return sysfs_emit(buf, "%llu\n",
+			  ktime_to_us(hba->monitor.lat_sum[READ]));
+}
+
+static ssize_t write_total_sectors_show(struct device *dev,
+					struct device_attribute *attr,
+					char *buf)
+{
+	struct ufs_hba *hba = dev_get_drvdata(dev);
+
+	return sysfs_emit(buf, "%lu\n", hba->monitor.nr_sec_rw[WRITE]);
+}
+
+static ssize_t write_total_busy_show(struct device *dev,
+				     struct device_attribute *attr, char *buf)
+{
+	struct ufs_hba *hba = dev_get_drvdata(dev);
+
+	return sysfs_emit(buf, "%llu\n",
+			  ktime_to_us(hba->monitor.total_busy[WRITE]));
+}
+
+static ssize_t write_nr_requests_show(struct device *dev,
+				      struct device_attribute *attr, char *buf)
+{
+	struct ufs_hba *hba = dev_get_drvdata(dev);
+
+	return sysfs_emit(buf, "%lu\n", hba->monitor.nr_req[WRITE]);
+}
+
+static ssize_t write_req_latency_avg_show(struct device *dev,
+					  struct device_attribute *attr,
+					  char *buf)
+{
+	struct ufs_hba *hba = dev_get_drvdata(dev);
+	struct ufs_hba_monitor *m = &hba->monitor;
+
+	return sysfs_emit(buf, "%llu\n", div_u64(ktime_to_us(m->lat_sum[WRITE]),
+						 m->nr_req[WRITE]));
+}
+
+static ssize_t write_req_latency_max_show(struct device *dev,
+					  struct device_attribute *attr,
+					  char *buf)
+{
+	struct ufs_hba *hba = dev_get_drvdata(dev);
+
+	return sysfs_emit(buf, "%llu\n",
+			  ktime_to_us(hba->monitor.lat_max[WRITE]));
+}
+
+static ssize_t write_req_latency_min_show(struct device *dev,
+					  struct device_attribute *attr,
+					  char *buf)
+{
+	struct ufs_hba *hba = dev_get_drvdata(dev);
+
+	return sysfs_emit(buf, "%llu\n",
+			  ktime_to_us(hba->monitor.lat_min[WRITE]));
+}
+
+static ssize_t write_req_latency_sum_show(struct device *dev,
+					  struct device_attribute *attr,
+					  char *buf)
+{
+	struct ufs_hba *hba = dev_get_drvdata(dev);
+
+	return sysfs_emit(buf, "%llu\n",
+			  ktime_to_us(hba->monitor.lat_sum[WRITE]));
+}
+
+static DEVICE_ATTR_RW(monitor_enable);
+static DEVICE_ATTR_RW(monitor_chunk_size);
+static DEVICE_ATTR_RO(read_total_sectors);
+static DEVICE_ATTR_RO(read_total_busy);
+static DEVICE_ATTR_RO(read_nr_requests);
+static DEVICE_ATTR_RO(read_req_latency_avg);
+static DEVICE_ATTR_RO(read_req_latency_max);
+static DEVICE_ATTR_RO(read_req_latency_min);
+static DEVICE_ATTR_RO(read_req_latency_sum);
+static DEVICE_ATTR_RO(write_total_sectors);
+static DEVICE_ATTR_RO(write_total_busy);
+static DEVICE_ATTR_RO(write_nr_requests);
+static DEVICE_ATTR_RO(write_req_latency_avg);
+static DEVICE_ATTR_RO(write_req_latency_max);
+static DEVICE_ATTR_RO(write_req_latency_min);
+static DEVICE_ATTR_RO(write_req_latency_sum);
+
+static struct attribute *ufs_sysfs_monitor_attrs[] = {
+	&dev_attr_monitor_enable.attr,
+	&dev_attr_monitor_chunk_size.attr,
+	&dev_attr_read_total_sectors.attr,
+	&dev_attr_read_total_busy.attr,
+	&dev_attr_read_nr_requests.attr,
+	&dev_attr_read_req_latency_avg.attr,
+	&dev_attr_read_req_latency_max.attr,
+	&dev_attr_read_req_latency_min.attr,
+	&dev_attr_read_req_latency_sum.attr,
+	&dev_attr_write_total_sectors.attr,
+	&dev_attr_write_total_busy.attr,
+	&dev_attr_write_nr_requests.attr,
+	&dev_attr_write_req_latency_avg.attr,
+	&dev_attr_write_req_latency_max.attr,
+	&dev_attr_write_req_latency_min.attr,
+	&dev_attr_write_req_latency_sum.attr,
+	NULL
+};
+
+static const struct attribute_group ufs_sysfs_monitor_group = {
+	.name = "monitor",
+	.attrs = ufs_sysfs_monitor_attrs,
+};
+
 static ssize_t ufs_sysfs_read_desc_param(struct ufs_hba *hba,
 				  enum desc_idn desc_id,
 				  u8 desc_index,
@@ -881,6 +1117,7 @@ static const struct attribute_group ufs_sysfs_attributes_group = {
 
 static const struct attribute_group *ufs_sysfs_groups[] = {
 	&ufs_sysfs_default_group,
+	&ufs_sysfs_monitor_group,
 	&ufs_sysfs_device_descriptor_group,
 	&ufs_sysfs_interconnect_descriptor_group,
 	&ufs_sysfs_geometry_descriptor_group,
drivers/scsi/ufs/ufshcd.c +62 -0

80 lines not on this page · raw message

drivers/scsi/ufs/ufshcd.h +21 -0
index 18e56c1..2bfe20e 100644
@@ -645,6 +645,25 @@ struct ufs_hba_variant_params {
 	u32 wb_flush_threshold;
 };
 
+struct ufs_hba_monitor {
+	unsigned long chunk_size;
+
+	unsigned long nr_sec_rw[2];
+	ktime_t total_busy[2];
+
+	unsigned long nr_req[2];
+	/* latencies*/
+	ktime_t lat_sum[2];
+	ktime_t lat_max[2];
+	ktime_t lat_min[2];
+
+	u32 nr_queued[2];
+	ktime_t busy_start_ts[2];
+
+	ktime_t enabled_ts;
+	bool enabled;
+};
+
 /**
  * struct ufs_hba - per adapter private structure
  * @mmio_base: UFSHCI base register address
@@ -832,6 +851,8 @@ struct ufs_hba {
 	struct request_queue	*bsg_queue;
 	struct delayed_work rpm_dev_flush_recheck_work;
 
+	struct ufs_hba_monitor	monitor;
+
 #ifdef CONFIG_SCSI_UFS_CRYPTO
 	union ufs_crypto_capabilities crypto_capabilities;
 	union ufs_crypto_cap_entry *crypto_cap_array;
Signature · 1 line
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.
author
#7 lore raw

PATCH v4 2/2 scsi: ufs: Add support for hba performance monitor

In reply to Can Guo

Add a new sysfs group which has nodes to monitor data/request transfer performance. This sysfs group has nodes showing total sectors/requests transferred, total busy time spent and max/min/avg/sum latencies.

Documentation/ABI/testing/sysfs-driver-ufs +126 -0
index d1bc23c..8380866 100644
@@ -995,6 +995,132 @@ Description:	This entry shows the target state of an UFS UIC link
 
 		The file is read only.
 
+What:		/sys/bus/platform/drivers/ufshcd/*/monitor/monitor_enable
+Date:		January 2021
+Contact:	Can Guo <[email protected]>
+Description:	This file shows the status of performance monitor enablement
+		and it can be used to start/stop the monitor. When the monitor
+		is stopped, the performance data collected is also cleared.
+
+What:		/sys/bus/platform/drivers/ufshcd/*/monitor/monitor_chunk_size
+Date:		January 2021
+Contact:	Can Guo <[email protected]>
+Description:	This file tells the monitor to focus on requests transferring
+		data of specific chunk size (in Bytes). 0 means any chunk size.
+		It can only be changed when monitor is disabled.
+
+What:		/sys/bus/platform/drivers/ufshcd/*/monitor/read_total_sectors
+Date:		January 2021
+Contact:	Can Guo <[email protected]>
+Description:	This file shows how many sectors (in 512 Bytes) have been
+		sent from device to host after monitor gets started.
+
+		The file is read only.
+
+What:		/sys/bus/platform/drivers/ufshcd/*/monitor/read_total_busy
+Date:		January 2021
+Contact:	Can Guo <[email protected]>
+Description:	This file shows how long (in micro seconds) has been spent
+		sending data from device to host after monitor gets started.
+
+		The file is read only.
+
+What:		/sys/bus/platform/drivers/ufshcd/*/monitor/read_nr_requests
+Date:		January 2021
+Contact:	Can Guo <[email protected]>
+Description:	This file shows how many read requests have been sent after
+		monitor gets started.
+
+		The file is read only.
+
+What:		/sys/bus/platform/drivers/ufshcd/*/monitor/read_req_latency_max
+Date:		January 2021
+Contact:	Can Guo <[email protected]>
+Description:	This file shows the maximum latency (in micro seconds) of
+		read requests after monitor gets started.
+
+		The file is read only.
+
+What:		/sys/bus/platform/drivers/ufshcd/*/monitor/read_req_latency_min
+Date:		January 2021
+Contact:	Can Guo <[email protected]>
+Description:	This file shows the minimum latency (in micro seconds) of
+		read requests after monitor gets started.
+
+		The file is read only.
+
+What:		/sys/bus/platform/drivers/ufshcd/*/monitor/read_req_latency_avg
+Date:		January 2021
+Contact:	Can Guo <[email protected]>
+Description:	This file shows the average latency (in micro seconds) of
+		read requests after monitor gets started.
+
+		The file is read only.
+
+What:		/sys/bus/platform/drivers/ufshcd/*/monitor/read_req_latency_sum
+Date:		January 2021
+Contact:	Can Guo <[email protected]>
+Description:	This file shows the total latency (in micro seconds) of
+		read requests sent after monitor gets started.
+
+		The file is read only.
+
+What:		/sys/bus/platform/drivers/ufshcd/*/monitor/write_total_sectors
+Date:		January 2021
+Contact:	Can Guo <[email protected]>
+Description:	This file shows how many sectors (in 512 Bytes) have been sent
+		from host to device after monitor gets started.
+
+		The file is read only.
+
+What:		/sys/bus/platform/drivers/ufshcd/*/monitor/write_total_busy
+Date:		January 2021
+Contact:	Can Guo <[email protected]>
+Description:	This file shows how long (in micro seconds) has been spent
+		sending data from host to device after monitor gets started.
+
+		The file is read only.
+
+What:		/sys/bus/platform/drivers/ufshcd/*/monitor/write_nr_requests
+Date:		January 2021
+Contact:	Can Guo <[email protected]>
+Description:	This file shows how many write requests have been sent after
+		monitor gets started.
+
+		The file is read only.
+
+What:		/sys/bus/platform/drivers/ufshcd/*/monitor/write_req_latency_max
+Date:		January 2021
+Contact:	Can Guo <[email protected]>
+Description:	This file shows the maximum latency (in micro seconds) of write
+		requests after monitor gets started.
+
+		The file is read only.
+
+What:		/sys/bus/platform/drivers/ufshcd/*/monitor/write_req_latency_min
+Date:		January 2021
+Contact:	Can Guo <[email protected]>
+Description:	This file shows the minimum latency (in micro seconds) of write
+		requests after monitor gets started.
+
+		The file is read only.
+
+What:		/sys/bus/platform/drivers/ufshcd/*/monitor/write_req_latency_avg
+Date:		January 2021
+Contact:	Can Guo <[email protected]>
+Description:	This file shows the average latency (in micro seconds) of write
+		requests after monitor gets started.
+
+		The file is read only.
+
+What:		/sys/bus/platform/drivers/ufshcd/*/monitor/write_req_latency_sum
+Date:		January 2021
+Contact:	Can Guo <[email protected]>
+Description:	This file shows the total latency (in micro seconds) of write
+		requests after monitor gets started.
+
+		The file is read only.
+
 What:		/sys/bus/platform/drivers/ufshcd/*/device_descriptor/wb_presv_us_en
 Date:		June 2020
 Contact:	Asutosh Das <[email protected]>
Signature · 1 line
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.
#2 lore raw

RE: [PATCH 1/2] scsi: ufs: Introduce hba performance monitor sysfs nodes

In reply to Can Guo

Hi Can Guo,

Quoted 10 lines
drivers/scsi/ufs/ufs-sysfs.c +10 -0
+static ssize_t monitor_enable_store(struct device *dev,
+                                    struct device_attribute *attr,
+                                    const char *buf, size_t count)
+{
+        struct ufs_hba *hba = dev_get_drvdata(dev);
+        unsigned long value, flags;
+
+        if (kstrtoul(buf, 0, &value))
+                return -EINVAL;
+

drivers/scsi/ufs/ufs-sysfs.c static const struct attribute_group ufs_sysfs_default_group = { · line 308

Quoted 10 lines
drivers/scsi/ufs/ufs-sysfs.c +10 -0
+        value = !!value;
+        spin_lock_irqsave(hba->host->host_lock, flags);
+        if (value == hba->monitor.enabled)
+                goto out_unlock;
+
+        if (!value) {
+                memset(&hba->monitor, 0, sizeof(hba->monitor));
+        } else {
+                hba->monitor.enabled = true;
+                hba->monitor.enabled_ts = ktime_get();

How about setting lat_max to and lat_min to KTIME_MAX and 0? I think lat_sum should be 0 at this point.

Quoted 8 lines
drivers/scsi/ufs/ufshcd.c +6 -0
+        }
+
+out_unlock:
+        spin_unlock_irqrestore(hba->host->host_lock, flags);
+        return count;
+}
 
 

drivers/scsi/ufs/ufshcd.c static void ufshcd_clk_scaling_update_busy(struct ufs_hba *hba) · line 2069

Quoted 10 lines
drivers/scsi/ufs/ufshcd.c +10 -0
+static void ufshcd_update_monitor(struct ufs_hba *hba, struct ufshcd_lrb *lrbp)
+{
+        int dir = ufshcd_monitor_opcode2dir(*lrbp->cmd->cmnd);
+
+        if (dir >= 0 && hba->monitor.nr_queued[dir] > 0) {
+                struct request *req = lrbp->cmd->request;
+                struct ufs_hba_monitor *m = &hba->monitor;
+                ktime_t now, inc, lat;
+
+                now = ktime_get();

How about using lrbp->compl_time_stamp instead of getting new value?

drivers/scsi/ufs/ufshcd.c static void ufshcd_clk_scaling_update_busy(struct ufs_hba *hba) · line 2081

Quoted 12 lines
drivers/scsi/ufs/ufshcd.c +12 -0
+                inc = ktime_sub(now, m->busy_start_ts[dir]);
+                m->total_busy[dir] = ktime_add(m->total_busy[dir], inc);
+                m->nr_sec_rw[dir] += blk_rq_sectors(req);
+
+                /* Update latencies */
+                m->nr_req[dir]++;
+                lat = ktime_sub(now, lrbp->issue_time_stamp);
+                m->lat_sum[dir] += lat;
+                if (m->lat_max[dir] < lat || !m->lat_max[dir])
+                        m->lat_max[dir] = lat;
+                if (m->lat_min[dir] > lat || !m->lat_min[dir])
+                        m->lat_min[dir] = lat;

This if statement can be shorted, by setting lat_max / lat_min as default value.

drivers/scsi/ufs/ufshcd.c static void ufshcd_clk_scaling_update_busy(struct ufs_hba *hba) · line 2087

Quoted 6 lines
drivers/scsi/ufs/ufshcd.c +6 -0
+
+                m->nr_queued[dir]--;
+                /* Push forward the busy start of monitor */
+                m->busy_start_ts[dir] = now;
+        }
+}

Thanks,
Daejun

author
#3 lore raw

Re: [PATCH 1/2] scsi: ufs: Introduce hba performance monitor sysfs nodes

Hi Daejun,

Quoted 16 lines · Daejun Park

Hi Can Guo,

Quoted 14 lines
drivers/scsi/ufs/ufs-sysfs.c +14 -0
+static ssize_t monitor_enable_store(struct device *dev,
+                                    struct device_attribute *attr,
+                                    const char *buf, size_t count)
+{
+        struct ufs_hba *hba = dev_get_drvdata(dev);
+        unsigned long value, flags;
+
+        if (kstrtoul(buf, 0, &value))
+                return -EINVAL;
+
+        value = !!value;
+        spin_lock_irqsave(hba->host->host_lock, flags);
+        if (value == hba->monitor.enabled)
+                goto out_unlock;
Quoted 8 lines

drivers/scsi/ufs/ufs-sysfs.c static const struct attribute_group ufs_sysfs_default_group = { · line 308

Quoted 6 lines
drivers/scsi/ufs/ufs-sysfs.c +6 -0
+
+        if (!value) {
+                memset(&hba->monitor, 0, sizeof(hba->monitor));
+        } else {
+                hba->monitor.enabled = true;
+                hba->monitor.enabled_ts = ktime_get();

How about setting lat_max to and lat_min to KTIME_MAX and 0?

lat_min is already 0. What is the benefit of setting lat_max to KTIME_MAX?

Quoted 1 line

I think lat_sum should be 0 at this point.

lat_sum is already 0 at this point, what is the problem?

Quoted 9 lines
Quoted 7 lines
drivers/scsi/ufs/ufs-sysfs.c +6 -0
+        }
+
+out_unlock:
+        spin_unlock_irqrestore(hba->host->host_lock, flags);
+        return count;
+}
Quoted 13 lines

drivers/scsi/ufs/ufshcd.c static void ufshcd_clk_scaling_update_busy(struct ufs_hba *hba) · line 2069

Quoted 11 lines

+static void ufshcd_update_monitor(struct ufs_hba *hba, struct ufshcd_lrb *lrbp)

drivers/scsi/ufs/ufshcd.c +9 -0
+{
+        int dir = ufshcd_monitor_opcode2dir(*lrbp->cmd->cmnd);
+
+        if (dir >= 0 && hba->monitor.nr_queued[dir] > 0) {
+                struct request *req = lrbp->cmd->request;
+                struct ufs_hba_monitor *m = &hba->monitor;
+                ktime_t now, inc, lat;
+
+                now = ktime_get();

How about using lrbp->compl_time_stamp instead of getting new value?

I am expecting "now" keeps increasing and use it to update m->busy_start_s, but if I use lrbp->compl_time_stamp to do that, below line ktime_sub() may give me an unexpected value as lrbp->compl_time_stamp may be smaller than m->busy_start_ts, because the actual requests are not completed by the device in the exact same ordering as the bits set in hba->outstanding_tasks, but driver is completing them from bit 0 to bit 31 in ascending order.

Quoted 15 lines
Quoted 4 lines
(quoted diff) +2 -0
+                inc = ktime_sub(now, m->busy_start_ts[dir]);
+                m->total_busy[dir] = ktime_add(m->total_busy[dir], 

inc);

drivers/scsi/ufs/ufshcd.c static void ufshcd_clk_scaling_update_busy(struct ufs_hba *hba) · line 2081

Quoted 10 lines
drivers/scsi/ufs/ufshcd.c +10 -0
+                m->nr_sec_rw[dir] += blk_rq_sectors(req);
+
+                /* Update latencies */
+                m->nr_req[dir]++;
+                lat = ktime_sub(now, lrbp->issue_time_stamp);
+                m->lat_sum[dir] += lat;
+                if (m->lat_max[dir] < lat || !m->lat_max[dir])
+                        m->lat_max[dir] = lat;
+                if (m->lat_min[dir] > lat || !m->lat_min[dir])
+                        m->lat_min[dir] = lat;
Quoted 1 line

This if statement can be shorted, by setting lat_max / lat_min as default value.

I don't quite get it, can you show me the code sample?

Thanks,
Can Guo

Quoted 10 lines

drivers/scsi/ufs/ufshcd.c static void ufshcd_clk_scaling_update_busy(struct ufs_hba *hba) · line 2087

Quoted 7 lines
drivers/scsi/ufs/ufshcd.c +6 -0
+
+                m->nr_queued[dir]--;
+                /* Push forward the busy start of monitor */
+                m->busy_start_ts[dir] = now;
+        }
+}

Thanks,
Daejun

author
#4 lore raw

Re: [PATCH 1/2] scsi: ufs: Introduce hba performance monitor sysfs nodes

Quoted 57 lines · Can Guo

Hi Daejun,

Quoted 16 lines · Daejun Park

Hi Can Guo,

Quoted 14 lines
drivers/scsi/ufs/ufs-sysfs.c +14 -0
+static ssize_t monitor_enable_store(struct device *dev,
+                                    struct device_attribute *attr,
+                                    const char *buf, size_t count)
+{
+        struct ufs_hba *hba = dev_get_drvdata(dev);
+        unsigned long value, flags;
+
+        if (kstrtoul(buf, 0, &value))
+                return -EINVAL;
+
+        value = !!value;
+        spin_lock_irqsave(hba->host->host_lock, flags);
+        if (value == hba->monitor.enabled)
+                goto out_unlock;
Quoted 8 lines

drivers/scsi/ufs/ufs-sysfs.c static const struct attribute_group ufs_sysfs_default_group = { · line 308

Quoted 6 lines
drivers/scsi/ufs/ufs-sysfs.c +6 -0
+
+        if (!value) {
+                memset(&hba->monitor, 0, sizeof(hba->monitor));
+        } else {
+                hba->monitor.enabled = true;
+                hba->monitor.enabled_ts = ktime_get();

How about setting lat_max to and lat_min to KTIME_MAX and 0?

lat_min is already 0. What is the benefit of setting lat_max to KTIME_MAX?

Quoted 1 line

I think lat_sum should be 0 at this point.

lat_sum is already 0 at this point, what is the problem?

Quoted 9 lines
Quoted 7 lines
drivers/scsi/ufs/ufs-sysfs.c +6 -0
+        }
+
+out_unlock:
+        spin_unlock_irqrestore(hba->host->host_lock, flags);
+        return count;
+}
Quoted 13 lines

drivers/scsi/ufs/ufshcd.c static void ufshcd_clk_scaling_update_busy(struct ufs_hba *hba) · line 2069

Quoted 11 lines

+static void ufshcd_update_monitor(struct ufs_hba *hba, struct ufshcd_lrb *lrbp)

drivers/scsi/ufs/ufshcd.c +9 -0
+{
+        int dir = ufshcd_monitor_opcode2dir(*lrbp->cmd->cmnd);
+
+        if (dir >= 0 && hba->monitor.nr_queued[dir] > 0) {
+                struct request *req = lrbp->cmd->request;
+                struct ufs_hba_monitor *m = &hba->monitor;
+                ktime_t now, inc, lat;
+
+                now = ktime_get();

How about using lrbp->compl_time_stamp instead of getting new value?

Quoted 6 lines

I am expecting "now" keeps increasing and use it to update m->busy_start_s, but if I use lrbp->compl_time_stamp to do that, below line ktime_sub() may give me an unexpected value as lrbp->compl_time_stamp may be smaller than m->busy_start_ts, because the actual requests are not completed by the device in the exact same ordering as the bits set in hba->outstanding_tasks, but driver is completing them from bit 0 to bit 31 in ascending order.

Sorry, I missunderstood your point... Yes, we can use lrbp->compl_time_stamp.

Thanks,
Can Guo.

Quoted 33 lines
Quoted 16 lines
Quoted 5 lines
(quoted diff) +2 -0
+                inc = ktime_sub(now, m->busy_start_ts[dir]);
+                m->total_busy[dir] = ktime_add(m->total_busy[dir], 

inc);

drivers/scsi/ufs/ufshcd.c static void ufshcd_clk_scaling_update_busy(struct ufs_hba *hba) · line 2081

Quoted 10 lines
drivers/scsi/ufs/ufshcd.c +10 -0
+                m->nr_sec_rw[dir] += blk_rq_sectors(req);
+
+                /* Update latencies */
+                m->nr_req[dir]++;
+                lat = ktime_sub(now, lrbp->issue_time_stamp);
+                m->lat_sum[dir] += lat;
+                if (m->lat_max[dir] < lat || !m->lat_max[dir])
+                        m->lat_max[dir] = lat;
+                if (m->lat_min[dir] > lat || !m->lat_min[dir])
+                        m->lat_min[dir] = lat;
Quoted 1 line

This if statement can be shorted, by setting lat_max / lat_min as default value.

I don't quite get it, can you show me the code sample?

Thanks,
Can Guo

Quoted 10 lines

drivers/scsi/ufs/ufshcd.c static void ufshcd_clk_scaling_update_busy(struct ufs_hba *hba) · line 2087

Quoted 7 lines
drivers/scsi/ufs/ufshcd.c +6 -0
+
+                m->nr_queued[dir]--;
+                /* Push forward the busy start of monitor */
+                m->busy_start_ts[dir] = now;
+        }
+}

Thanks,
Daejun

#5 lore raw

RE: Re: [PATCH 1/2] scsi: ufs: Introduce hba performance monitor sysfs nodes

In reply to Can Guo

Hi Can Guo,

Quoted 29 lines

Hi Daejun,

Quoted 16 lines · Daejun Park

Hi Can Guo,

Quoted 14 lines
drivers/scsi/ufs/ufs-sysfs.c +14 -0
+static ssize_t monitor_enable_store(struct device *dev,
+                                    struct device_attribute *attr,
+                                    const char *buf, size_t count)
+{
+        struct ufs_hba *hba = dev_get_drvdata(dev);
+        unsigned long value, flags;
+
+        if (kstrtoul(buf, 0, &value))
+                return -EINVAL;
+
+        value = !!value;
+        spin_lock_irqsave(hba->host->host_lock, flags);
+        if (value == hba->monitor.enabled)
+                goto out_unlock;
Quoted 8 lines

drivers/scsi/ufs/ufs-sysfs.c static const struct attribute_group ufs_sysfs_default_group = { · line 308

Quoted 6 lines
drivers/scsi/ufs/ufs-sysfs.c +6 -0
+
+        if (!value) {
+                memset(&hba->monitor, 0, sizeof(hba->monitor));
+        } else {
+                hba->monitor.enabled = true;
+                hba->monitor.enabled_ts = ktime_get();

How about setting lat_max to and lat_min to KTIME_MAX and 0?

Quoted 6 lines

lat_min is already 0. What is the benefit of setting lat_max to KTIME_MAX?

Quoted 1 line

I think lat_sum should be 0 at this point.

lat_sum is already 0 at this point, what is the problem?

Sorry. I misunderstood about resetting monitor values.

Quoted 24 lines
Quoted 10 lines
Quoted 8 lines
drivers/scsi/ufs/ufs-sysfs.c +6 -0
+        }
+
+out_unlock:
+        spin_unlock_irqrestore(hba->host->host_lock, flags);
+        return count;
+}
Quoted 13 lines

drivers/scsi/ufs/ufshcd.c static void ufshcd_clk_scaling_update_busy(struct ufs_hba *hba) · line 2069

Quoted 11 lines

+static void ufshcd_update_monitor(struct ufs_hba *hba, struct ufshcd_lrb *lrbp)

drivers/scsi/ufs/ufshcd.c +9 -0
+{
+        int dir = ufshcd_monitor_opcode2dir(*lrbp->cmd->cmnd);
+
+        if (dir >= 0 && hba->monitor.nr_queued[dir] > 0) {
+                struct request *req = lrbp->cmd->request;
+                struct ufs_hba_monitor *m = &hba->monitor;
+                ktime_t now, inc, lat;
+
+                now = ktime_get();

How about using lrbp->compl_time_stamp instead of getting new value?

Quoted 11 lines

I am expecting "now" keeps increasing and use it to update m->busy_start_s,
but if I use lrbp->compl_time_stamp to do that, below line ktime_sub() may
give me an unexpected value as lrbp->compl_time_stamp may be smaller than
m->busy_start_ts, because the actual requests are not completed by the device
in the exact same ordering as the bits set in hba->outstanding_tasks, but driver
is completing them from bit 0 to bit 31 in ascending order.

lrbp->compl_time_stamp is set just before calling ufshcd_update_monitor(). And I don't think it can be negative value, because ufshcd_send_command() and __ufshcd_transfer_req_compl() are protected by host lock.

Quoted 16 lines
Quoted 16 lines
Quoted 15 lines
(quoted diff) +2 -0
+                inc = ktime_sub(now, m->busy_start_ts[dir]);
+                m->total_busy[dir] = ktime_add(m->total_busy[dir], 

inc);

drivers/scsi/ufs/ufshcd.c +10 -0
+                m->nr_sec_rw[dir] += blk_rq_sectors(req);
+
+                /* Update latencies */
+                m->nr_req[dir]++;
+                lat = ktime_sub(now, lrbp->issue_time_stamp);
+                m->lat_sum[dir] += lat;
+                if (m->lat_max[dir] < lat || !m->lat_max[dir])
+                        m->lat_max[dir] = lat;
+                if (m->lat_min[dir] > lat || !m->lat_min[dir])
+                        m->lat_min[dir] = lat;
Quoted 4 lines
Quoted 2 lines

This if statement can be shorted, by setting lat_max / lat_min as default value.

I don't quite get it, can you show me the code sample?

I think " || !m->lat_max[dir]" can be removed.

                if (m->lat_max[dir] < lat)
                        m->lat_max[dir] = lat;
                if (m->lat_min[dir] > lat)
                        m->lat_min[dir] = lat;

Thanks,
Daejun

Quoted 14 lines

Thanks,
Can Guo

Quoted 10 lines

drivers/scsi/ufs/ufshcd.c static void ufshcd_clk_scaling_update_busy(struct ufs_hba *hba) · line 2087

Quoted 7 lines
drivers/scsi/ufs/ufshcd.c +6 -0
+
+                m->nr_queued[dir]--;
+                /* Push forward the busy start of monitor */
+                m->busy_start_ts[dir] = now;
+        }
+}

Thanks,
Daejun

author
#6 lore raw

Re: [PATCH 1/2] scsi: ufs: Introduce hba performance monitor sysfs nodes

Quoted 75 lines · Daejun Park

Hi Can Guo,

Quoted 29 lines

Hi Daejun,

Quoted 16 lines · Daejun Park

Hi Can Guo,

Quoted 14 lines
drivers/scsi/ufs/ufs-sysfs.c +14 -0
+static ssize_t monitor_enable_store(struct device *dev,
+                                    struct device_attribute *attr,
+                                    const char *buf, size_t count)
+{
+        struct ufs_hba *hba = dev_get_drvdata(dev);
+        unsigned long value, flags;
+
+        if (kstrtoul(buf, 0, &value))
+                return -EINVAL;
+
+        value = !!value;
+        spin_lock_irqsave(hba->host->host_lock, flags);
+        if (value == hba->monitor.enabled)
+                goto out_unlock;
Quoted 8 lines

drivers/scsi/ufs/ufs-sysfs.c static const struct attribute_group ufs_sysfs_default_group = { · line 308

Quoted 6 lines
drivers/scsi/ufs/ufs-sysfs.c +6 -0
+
+        if (!value) {
+                memset(&hba->monitor, 0, sizeof(hba->monitor));
+        } else {
+                hba->monitor.enabled = true;
+                hba->monitor.enabled_ts = ktime_get();

How about setting lat_max to and lat_min to KTIME_MAX and 0?

Quoted 6 lines

lat_min is already 0. What is the benefit of setting lat_max to KTIME_MAX?

Quoted 1 line

I think lat_sum should be 0 at this point.

lat_sum is already 0 at this point, what is the problem?

Sorry. I misunderstood about resetting monitor values.

Quoted 24 lines
Quoted 10 lines
Quoted 8 lines
drivers/scsi/ufs/ufs-sysfs.c +6 -0
+        }
+
+out_unlock:
+        spin_unlock_irqrestore(hba->host->host_lock, flags);
+        return count;
+}
Quoted 13 lines

drivers/scsi/ufs/ufshcd.c static void ufshcd_clk_scaling_update_busy(struct ufs_hba *hba) · line 2069

Quoted 11 lines

+static void ufshcd_update_monitor(struct ufs_hba *hba, struct ufshcd_lrb *lrbp)

drivers/scsi/ufs/ufshcd.c +9 -0
+{
+        int dir = ufshcd_monitor_opcode2dir(*lrbp->cmd->cmnd);
+
+        if (dir >= 0 && hba->monitor.nr_queued[dir] > 0) {
+                struct request *req = lrbp->cmd->request;
+                struct ufs_hba_monitor *m = &hba->monitor;
+                ktime_t now, inc, lat;
+
+                now = ktime_get();

How about using lrbp->compl_time_stamp instead of getting new value?

Quoted 11 lines

I am expecting "now" keeps increasing and use it to update m->busy_start_s,
but if I use lrbp->compl_time_stamp to do that, below line ktime_sub() may
give me an unexpected value as lrbp->compl_time_stamp may be smaller than
m->busy_start_ts, because the actual requests are not completed by the device
in the exact same ordering as the bits set in hba->outstanding_tasks, but driver
is completing them from bit 0 to bit 31 in ascending order.

Quoted 4 lines

lrbp->compl_time_stamp is set just before calling ufshcd_update_monitor(). And I don't think it can be negative value, because ufshcd_send_command() and __ufshcd_transfer_req_compl() are protected by host lock.

Yes, I replied u in another mail... I will use the compl_time_stamp in next version. And later I will add alloc_time_stamp and release_time_stamp to lrbp so that we can monitor the overall send/compl path, including hpb_prep() and hpb_rsp().

Quoted 19 lines
Quoted 19 lines
Quoted 18 lines
Quoted 5 lines
(quoted diff) +2 -0
+                inc = ktime_sub(now, m->busy_start_ts[dir]);
+                m->total_busy[dir] = ktime_add(m->total_busy[dir],

inc);

drivers/scsi/ufs/ufshcd.c static void ufshcd_clk_scaling_update_busy(struct ufs_hba *hba) · line 2081

Quoted 10 lines
drivers/scsi/ufs/ufshcd.c +10 -0
+                m->nr_sec_rw[dir] += blk_rq_sectors(req);
+
+                /* Update latencies */
+                m->nr_req[dir]++;
+                lat = ktime_sub(now, lrbp->issue_time_stamp);
+                m->lat_sum[dir] += lat;
+                if (m->lat_max[dir] < lat || !m->lat_max[dir])
+                        m->lat_max[dir] = lat;
+                if (m->lat_min[dir] > lat || !m->lat_min[dir])
+                        m->lat_min[dir] = lat;

This if statement can be shorted, by setting lat_max / lat_min as default value.

Quoted 9 lines
Quoted 1 line

I don't quite get it, can you show me the code sample?

I think " || !m->lat_max[dir]" can be removed.

                if (m->lat_max[dir] < lat)
                        m->lat_max[dir] = lat;
                if (m->lat_min[dir] > lat)
                        m->lat_min[dir] = lat;

From the beginning, lat_min is 0, without "!m->lat_min[dir]", m->lat_min will never be updated. Same for lat_max. Meanwhile, !m->lat_min/max will be hit only once in each round, which does not hurt.

Thanks,
Can Guo.

Quoted 17 lines

Thanks,
Daejun

Quoted 14 lines

Thanks,
Can Guo

Quoted 10 lines

drivers/scsi/ufs/ufshcd.c static void ufshcd_clk_scaling_update_busy(struct ufs_hba *hba) · line 2087

Quoted 7 lines
drivers/scsi/ufs/ufshcd.c +6 -0
+
+                m->nr_queued[dir]--;
+                /* Push forward the busy start of monitor */
+                m->busy_start_ts[dir] = now;
+        }
+}

Thanks,
Daejun