From: Tero Kristo <tero.kristo@linux.intel.com>
To: axboe@kernel.dk
Cc: hch@lst.de, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCHv2 1/2] block/genhd: add sysfs knobs for the CPU latency PM QoS settings
Date: Fri, 18 Oct 2024 10:30:37 +0300 [thread overview]
Message-ID: <20241018075416.436916-2-tero.kristo@linux.intel.com> (raw)
In-Reply-To: <20241018075416.436916-1-tero.kristo@linux.intel.com>
Add sysfs knobs for the following parameters:
cpu_lat_limit_us: for limiting the CPU latency to given value when block IO
is running
cpu_lat_timeout_ms: for clearing up the CPU latency limit after block IO
is complete
This can be used to prevent the CPU from entering deep idle states when
block IO is running and waiting for an interrupt, potentially causing
large latencies to the operation.
Signed-off-by: Tero Kristo <tero.kristo@linux.intel.com>
---
block/genhd.c | 47 ++++++++++++++++++++++++++++++++++++++++++
include/linux/blkdev.h | 3 +++
2 files changed, 50 insertions(+)
diff --git a/block/genhd.c b/block/genhd.c
index 1c05dd4c6980..e60af2639136 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -1046,6 +1046,48 @@ static ssize_t partscan_show(struct device *dev,
return sprintf(buf, "%u\n", disk_has_partscan(dev_to_disk(dev)));
}
+static ssize_t cpu_lat_limit_us_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct gendisk *disk = dev_to_disk(dev);
+
+ return sprintf(buf, "%d\n", disk->cpu_lat_limit);
+}
+
+static ssize_t cpu_lat_limit_us_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct gendisk *disk = dev_to_disk(dev);
+ int i;
+
+ if (count > 0 && !kstrtoint(buf, 10, &i))
+ disk->cpu_lat_limit = i;
+
+ return count;
+}
+
+static ssize_t cpu_lat_timeout_ms_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct gendisk *disk = dev_to_disk(dev);
+
+ return sprintf(buf, "%d\n", disk->cpu_lat_timeout);
+}
+
+static ssize_t cpu_lat_timeout_ms_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct gendisk *disk = dev_to_disk(dev);
+ int i;
+
+ if (count > 0 && !kstrtoint(buf, 10, &i))
+ disk->cpu_lat_timeout = i;
+
+ return count;
+}
+
static DEVICE_ATTR(range, 0444, disk_range_show, NULL);
static DEVICE_ATTR(ext_range, 0444, disk_ext_range_show, NULL);
static DEVICE_ATTR(removable, 0444, disk_removable_show, NULL);
@@ -1060,6 +1102,8 @@ static DEVICE_ATTR(inflight, 0444, part_inflight_show, NULL);
static DEVICE_ATTR(badblocks, 0644, disk_badblocks_show, disk_badblocks_store);
static DEVICE_ATTR(diskseq, 0444, diskseq_show, NULL);
static DEVICE_ATTR(partscan, 0444, partscan_show, NULL);
+static DEVICE_ATTR_RW(cpu_lat_limit_us);
+static DEVICE_ATTR_RW(cpu_lat_timeout_ms);
#ifdef CONFIG_FAIL_MAKE_REQUEST
ssize_t part_fail_show(struct device *dev,
@@ -1111,6 +1155,8 @@ static struct attribute *disk_attrs[] = {
&dev_attr_events_poll_msecs.attr,
&dev_attr_diskseq.attr,
&dev_attr_partscan.attr,
+ &dev_attr_cpu_lat_limit_us.attr,
+ &dev_attr_cpu_lat_timeout_ms.attr,
#ifdef CONFIG_FAIL_MAKE_REQUEST
&dev_attr_fail.attr,
#endif
@@ -1377,6 +1423,7 @@ struct gendisk *__alloc_disk_node(struct request_queue *q, int node_id,
#ifdef CONFIG_BLOCK_HOLDER_DEPRECATED
INIT_LIST_HEAD(&disk->slave_bdevs);
#endif
+ disk->cpu_lat_limit = -1;
return disk;
out_erase_part0:
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 50c3b959da28..8bf76da2efac 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -213,6 +213,9 @@ struct gendisk {
u64 diskseq;
blk_mode_t open_mode;
+ int cpu_lat_limit;
+ int cpu_lat_timeout;
+
/*
* Independent sector access ranges. This is always NULL for
* devices that do not have multiple independent access ranges.
--
2.43.1
next prev parent reply other threads:[~2024-10-18 7:54 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-18 7:30 [PATCHv2 0/2] blk-mq: add CPU latency limit control Tero Kristo
2024-10-18 7:30 ` Tero Kristo [this message]
2024-10-18 7:30 ` [PATCHv2 2/2] blk-mq: add support for CPU latency limits Tero Kristo
2024-10-18 14:21 ` Jens Axboe
2024-10-23 13:26 ` Tero Kristo
2024-10-23 13:48 ` Jens Axboe
2024-10-23 14:06 ` [PATCH v3 " Tero Kristo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241018075416.436916-2-tero.kristo@linux.intel.com \
--to=tero.kristo@linux.intel.com \
--cc=axboe@kernel.dk \
--cc=hch@lst.de \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox