From: Pintu Kumar <quic_pintu@quicinc.com>
To: <shuah@kernel.org>, <hannes@cmpxchg.org>, <surenb@google.com>,
<quic_pintu@quicinc.com>, <peterz@infradead.org>,
<linux-kernel@vger.kernel.org>, <linux-kselftest@vger.kernel.org>
Cc: <skhan@linuxfoundation.org>, <pintu.ping@gmail.com>
Subject: [PATCH] selftests/sched: add basic test for psi
Date: Tue, 22 Oct 2024 17:51:58 +0530 [thread overview]
Message-ID: <20241022122158.2136-1-quic_pintu@quicinc.com> (raw)
There is a psi module that exists under kernel/sched/psi.
Add a basic test to test the psi.
This test just add the basic support to check cpu/memory/io interface.
Further test will be added on top of this.
Signed-off-by: Pintu Kumar <quic_pintu@quicinc.com>
---
MAINTAINERS | 2 +
tools/testing/selftests/sched/.gitignore | 1 +
tools/testing/selftests/sched/Makefile | 4 +-
tools/testing/selftests/sched/config | 1 +
tools/testing/selftests/sched/psi_test.c | 85 ++++++++++++++++++++++++
tools/testing/selftests/sched/run_psi.sh | 36 ++++++++++
6 files changed, 127 insertions(+), 2 deletions(-)
create mode 100644 tools/testing/selftests/sched/psi_test.c
create mode 100755 tools/testing/selftests/sched/run_psi.sh
diff --git a/MAINTAINERS b/MAINTAINERS
index 84a73e90cfe8..d84ff9ca36a9 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -18548,10 +18548,12 @@ F: include/uapi/linux/pps.h
PRESSURE STALL INFORMATION (PSI)
M: Johannes Weiner <hannes@cmpxchg.org>
M: Suren Baghdasaryan <surenb@google.com>
+M: Pintu Kumar <quic_pintu@quicinc.com>
R: Peter Ziljstra <peterz@infradead.org>
S: Maintained
F: include/linux/psi*
F: kernel/sched/psi.c
+F: tools/testing/selftests/sched/psi_test.c
PRINTK
M: Petr Mladek <pmladek@suse.com>
diff --git a/tools/testing/selftests/sched/.gitignore b/tools/testing/selftests/sched/.gitignore
index 6996d4654d92..2b15c11b93e6 100644
--- a/tools/testing/selftests/sched/.gitignore
+++ b/tools/testing/selftests/sched/.gitignore
@@ -1 +1,2 @@
cs_prctl_test
+psi_test
diff --git a/tools/testing/selftests/sched/Makefile b/tools/testing/selftests/sched/Makefile
index 099ee9213557..795f6613eb2c 100644
--- a/tools/testing/selftests/sched/Makefile
+++ b/tools/testing/selftests/sched/Makefile
@@ -8,7 +8,7 @@ CFLAGS += -O2 -Wall -g -I./ $(KHDR_INCLUDES) -Wl,-rpath=./ \
$(CLANG_FLAGS)
LDLIBS += -lpthread
-TEST_GEN_FILES := cs_prctl_test
-TEST_PROGS := cs_prctl_test
+TEST_GEN_FILES := cs_prctl_test psi_test
+TEST_PROGS := cs_prctl_test run_psi.sh
include ../lib.mk
diff --git a/tools/testing/selftests/sched/config b/tools/testing/selftests/sched/config
index e8b09aa7c0c4..287cccd434fd 100644
--- a/tools/testing/selftests/sched/config
+++ b/tools/testing/selftests/sched/config
@@ -1 +1,2 @@
CONFIG_SCHED_DEBUG=y
+CONFIG_PSI=y
diff --git a/tools/testing/selftests/sched/psi_test.c b/tools/testing/selftests/sched/psi_test.c
new file mode 100644
index 000000000000..eeba138d2b39
--- /dev/null
+++ b/tools/testing/selftests/sched/psi_test.c
@@ -0,0 +1,85 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <stdio.h>
+#include <string.h>
+#include <fcntl.h>
+
+
+struct load_avg {
+ float avg10;
+ float avg60;
+ float avg300;
+ unsigned long long total;
+};
+
+struct pressure {
+ struct load_avg some;
+ struct load_avg full;
+};
+
+
+int psi_get_data_from_proc_pressure(const char *path, struct pressure *p)
+{
+ FILE *fp;
+ int rc = -1;
+ int ret = 0;
+
+ if (path == NULL || p == NULL)
+ return -1;
+
+ fp = fopen(path, "r");
+ if (fp == NULL)
+ return -1;
+
+ while (!feof(fp)) {
+ rc = fscanf(fp, "some avg10=%f avg60=%f avg300=%f total=%llu\n",
+ &p->some.avg10, &p->some.avg60, &p->some.avg300, &p->some.total);
+ if (rc < 1) {
+ ret = -1;
+ break;
+ }
+
+ /* Note: In some cases (cpu) full may not exists */
+ rc = fscanf(fp, "full avg10=%f avg60=%f avg300=%f total=%llu\n",
+ &p->full.avg10, &p->full.avg60, &p->full.avg300, &p->full.total);
+ /* We don't care about full case. This is needed to avoid warnings */
+ rc = 0;
+ }
+
+ fclose(fp);
+
+ return ret;
+}
+
+int main(int argc, char *argv[])
+{
+ int ret;
+ struct pressure rs = {0,};
+ char path[32];
+
+ if (argc < 2) {
+ fprintf(stderr, "usage: %s <path>\n", argv[0]);
+ return -1;
+ }
+
+ memset(&rs, 0, sizeof(rs));
+ printf("Pressure data: %s\n", argv[1]);
+ snprintf(path, sizeof(path)-1, "/proc/pressure/%s", argv[1]);
+
+ ret = psi_get_data_from_proc_pressure(path, &rs);
+ if (ret < 0) {
+ printf("PSI <%s>: FAIL\n", argv[1]);
+ return -1;
+ }
+ printf("Some Avg10 = %5.2f\n", rs.some.avg10);
+ printf("Some Avg60 = %5.2f\n", rs.some.avg60);
+ printf("Some Avg300 = %5.2f\n", rs.some.avg300);
+ printf("Some Total = %llu\n", rs.some.total);
+ printf("Full Avg10 = %5.2f\n", rs.full.avg10);
+ printf("Full Avg60 = %5.2f\n", rs.full.avg60);
+ printf("Full Avg300 = %5.2f\n", rs.full.avg300);
+ printf("Full Total = %llu\n", rs.full.total);
+
+
+ return 0;
+}
diff --git a/tools/testing/selftests/sched/run_psi.sh b/tools/testing/selftests/sched/run_psi.sh
new file mode 100755
index 000000000000..d0b1c7ae3736
--- /dev/null
+++ b/tools/testing/selftests/sched/run_psi.sh
@@ -0,0 +1,36 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+
+
+# Kselftest framework requirement - SKIP code is 4.
+ksft_skip=4
+
+# Just one node check is enough to detect psi
+if [ ! -e /proc/pressure/cpu ]; then
+ echo "PSI not present..."
+ exit $ksft_skip
+fi
+
+echo ""
+./psi_test cpu
+if [ $? -ne 0 ]; then
+ echo "CPU - [FAIL]"
+else
+ echo "CPU - [PASS]"
+fi
+
+echo ""
+./psi_test memory
+if [ $? -ne 0 ]; then
+ echo "MEMORY - [FAIL]"
+else
+ echo "MEMORY - [PASS]"
+fi
+
+echo ""
+./psi_test io
+if [ $? -ne 0 ]; then
+ echo "IO - [FAIL]"
+else
+ echo "IO - [PASS]"
+fi
--
2.17.1
next reply other threads:[~2024-10-22 12:22 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-22 12:21 Pintu Kumar [this message]
2024-10-22 14:05 ` Johannes Weiner
2024-10-22 18:23 ` Pintu Agarwal
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=20241022122158.2136-1-quic_pintu@quicinc.com \
--to=quic_pintu@quicinc.com \
--cc=hannes@cmpxchg.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=pintu.ping@gmail.com \
--cc=shuah@kernel.org \
--cc=skhan@linuxfoundation.org \
--cc=surenb@google.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®