All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yu Kuai <yukuai1@huaweicloud.com>
To: saranyamohan@google.com, tj@kernel.org, axboe@kernel.dk
Cc: linux-block@vger.kernel.org, yukuai3@huawei.com,
	yukuai1@huaweicloud.com, yangerkun@huawei.com
Subject: [PATCH v2 blktests 1/5] tests/throtl: add first test for blk-throttle
Date: Wed, 17 Apr 2024 10:20:01 +0800	[thread overview]
Message-ID: <20240417022005.1410525-2-yukuai1@huaweicloud.com> (raw)
In-Reply-To: <20240417022005.1410525-1-yukuai1@huaweicloud.com>

From: Yu Kuai <yukuai3@huawei.com>

Test basic functionality.

Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
 tests/throtl/001     | 39 ++++++++++++++++++++++++
 tests/throtl/001.out |  6 ++++
 tests/throtl/rc      | 71 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 116 insertions(+)
 create mode 100755 tests/throtl/001
 create mode 100644 tests/throtl/001.out
 create mode 100644 tests/throtl/rc

diff --git a/tests/throtl/001 b/tests/throtl/001
new file mode 100755
index 0000000..739efe2
--- /dev/null
+++ b/tests/throtl/001
@@ -0,0 +1,39 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-3.0+
+# Copyright (C) 2024 Yu Kuai
+#
+# Test basic functionality of blk-throttle
+
+. tests/throtl/rc
+
+DESCRIPTION="basic functionality"
+QUICK=1
+
+test() {
+	echo "Running ${TEST_NAME}"
+
+	if ! _set_up_test nr_devices=1; then
+		return 1;
+	fi
+
+	bps_limit=$((1024 * 1024))
+
+	_set_limits wbps=$bps_limit
+	_test_io write 4k 256
+	_remove_limits
+
+	_set_limits wiops=256
+	_test_io write 4k 256
+	_remove_limits
+
+	_set_limits rbps=$bps_limit
+	_test_io read 4k 256
+	_remove_limits
+
+	_set_limits riops=256
+	_test_io read 4k 256
+	_remove_limits
+
+	_clean_up_test
+	echo "Test complete"
+}
diff --git a/tests/throtl/001.out b/tests/throtl/001.out
new file mode 100644
index 0000000..a3edfdd
--- /dev/null
+++ b/tests/throtl/001.out
@@ -0,0 +1,6 @@
+Running throtl/001
+1
+1
+1
+1
+Test complete
diff --git a/tests/throtl/rc b/tests/throtl/rc
new file mode 100644
index 0000000..871102c
--- /dev/null
+++ b/tests/throtl/rc
@@ -0,0 +1,71 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-3.0+
+# Copyright (C) 2024 Yu Kuai
+#
+# Tests for blk-throttle
+
+. common/rc
+. common/null_blk
+
+CG=/sys/fs/cgroup
+TEST_DIR=$CG/blktests_throtl
+devname=nullb0
+
+group_requires() {
+	_have_root
+	_have_null_blk
+	_have_kernel_option BLK_DEV_THROTTLING
+	_have_cgroup2_controller io
+}
+
+# Create a new null_blk device, and create a new blk-cgroup for test.
+_set_up_test() {
+	if ! _init_null_blk "$*"; then
+		return 1;
+	fi
+
+	echo +io > $CG/cgroup.subtree_control
+	mkdir $TEST_DIR
+
+	return 0;
+}
+
+_clean_up_test() {
+	rmdir $TEST_DIR
+	echo -io > $CG/cgroup.subtree_control
+	_exit_null_blk
+}
+
+_set_limits() {
+	dev=$(cat /sys/block/$devname/dev)
+	echo "$dev $*" > $TEST_DIR/io.max
+}
+
+_remove_limits() {
+	dev=$(cat /sys/block/$devname/dev)
+	echo "$dev rbps=max wbps=max riops=max wiops=max" > $TEST_DIR/io.max
+}
+
+# Create an asynchronous thread and bind it to the specified blk-cgroup, issue
+# IO and then print time elapsed to the second, blk-throttle limits should be
+# set before this function.
+_test_io() {
+	{
+		sleep 0.1
+		start_time=$(date +%s.%N)
+
+		if [ "$1" == "read" ]; then
+			dd if=/dev/$devname of=/dev/null bs="$2" count="$3" iflag=direct status=none
+		elif [ "$1" == "write" ]; then
+			dd of=/dev/$devname if=/dev/zero bs="$2" count="$3" oflag=direct status=none
+		fi
+
+		end_time=$(date +%s.%N)
+		elapsed=$(echo "$end_time - $start_time" | bc)
+		printf "%.0f\n" "$elapsed"
+	} &
+
+	pid=$!
+	echo "$pid" > $TEST_DIR/cgroup.procs
+	wait $pid
+}
-- 
2.39.2


  reply	other threads:[~2024-04-17  2:28 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-17  2:20 [PATCH v2 blktests 0/5] add new tests for blk-throttle Yu Kuai
2024-04-17  2:20 ` Yu Kuai [this message]
2024-04-19  4:29   ` [PATCH v2 blktests 1/5] tests/throtl: add first test " Shinichiro Kawasaki
2024-04-19  8:01     ` Yu Kuai
2024-04-19  8:50       ` Shinichiro Kawasaki
2024-04-17  2:20 ` [PATCH v2 blktests 2/5] tests/throtl: add a new test 002 Yu Kuai
2024-04-17  2:20 ` [PATCH v2 blktests 3/5] tests/throtl: add a new test 003 Yu Kuai
2024-04-17  2:20 ` [PATCH v2 blktests 4/5] tests/throtl: add a new test 004 Yu Kuai
2024-04-19  4:45   ` Shinichiro Kawasaki
2024-04-19  8:05     ` Yu Kuai
2024-04-17  2:20 ` [PATCH v2 blktests 5/5] tests/throtl: add a new test 005 Yu Kuai

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=20240417022005.1410525-2-yukuai1@huaweicloud.com \
    --to=yukuai1@huaweicloud.com \
    --cc=axboe@kernel.dk \
    --cc=linux-block@vger.kernel.org \
    --cc=saranyamohan@google.com \
    --cc=tj@kernel.org \
    --cc=yangerkun@huawei.com \
    --cc=yukuai3@huawei.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.