Skip to contentSkip to conversation

sched_deadline: HRTICK for newer kernels

PATCH New John Kacur 1 participant 3 messages Jul 23, 2021

lore
Share & tools
lore

John Kacur

author
#0 lore raw

cover sched_deadline: HRTICK for newer kernels

Newer kernels have HRTICK_DL which is a HRTICK for the deadline scheduler only.

In addion newer kernels rename
/sys/kernel/debug/sched_features
to
/sys/kernel/debug/sched/features

These changes use HRTICK_DL if available and make use of the new file name in a backwards compatible manner.

These changes are based on changes in util.c in the stalld program. The stalld program itself was based on code in the sched_deadline programs in this suite.

John Kacur (2):
sched_deadline: Accommodate new location of HRTICK file in kernel
sched_deadline: Use HRTICK_DL for sched_deadline tests

 src/sched_deadline/cyclicdeadline.c | 92 +++++++++++++++++++++++------
 src/sched_deadline/deadline_test.c  | 89 ++++++++++++++++++++++------
 2 files changed, 145 insertions(+), 36 deletions(-)
Signature · 1 line
2.31.1
author
#1 lore raw

PATCH 1/2 sched_deadline: Accommodate new location of HRTICK file in kernel

Newer kernels rename /sys/kernel/debug/sched_features to /sys/kernel/debug/sched/features

Modify sched_deadline tests to look for the new file and if that fails look for the old file name

These functions are based on ones in stalld, and stalld itself has functions based on the sched_deadline programs in rt-tests

---
 src/sched_deadline/cyclicdeadline.c | 65 ++++++++++++++++++++++-------
 src/sched_deadline/deadline_test.c  | 61 +++++++++++++++++++++------
 2 files changed, 100 insertions(+), 26 deletions(-)
src/sched_deadline/cyclicdeadline.c +51 -14
index 8447424273ee..4a38ec2274c9 100644
@@ -230,12 +230,53 @@ found:
 	mark_fd = open(files, O_WRONLY);
 }
 
+/*
+ * Return true if file exists
+ */
+static int check_file_exists(char *path)
+{
+	int ret;
+	struct stat st;
+
+	ret = !stat(path, &st);
+
+	return ret;
+
+}
+
+/*
+ * Return 0 on success
+ */
+
+static int fill_sched_features(char *path)
+{
+	int ret;
+	const char *debugfs;
+
+	debugfs = find_debugfs();
+	if (strlen(debugfs) == 0)
+		return -1;
+
+	snprintf(path, MAX_PATH, "%s/sched/features", debugfs);
+	ret = check_file_exists(path);
+	if (ret)
+		return 0;
+
+	snprintf(path, MAX_PATH, "%s/sched_features", debugfs);
+	ret = check_file_exists(path);
+	if (ret)
+		return 0;
+
+	memset(path, 0, MAX_PATH);
+
+	return ret;
+
+}
+
 static int setup_hr_tick(void)
 {
-	const char *debugfs = find_debugfs();
-	char files[strlen(debugfs) + strlen("/sched_features") + 1];
+	char path[MAX_PATH];
 	char buf[500];
-	struct stat st;
 	static int set = 0;
 	char *p;
 	int ret;
@@ -244,27 +285,23 @@ static int setup_hr_tick(void)
 
 	if (set)
 		return 1;
-
 	set = 1;
 
-	if (strlen(debugfs) == 0)
-		return 0;
-
-	sprintf(files, "%s/sched_features", debugfs);
-	ret = stat(files, &st);
-	if (ret < 0)
+	ret = fill_sched_features(path);
+	if (ret)
 		return 0;
 
-	fd = open(files, O_RDWR);
-	perror(files);
-	if (fd < 0)
+	fd = open(path, O_RDWR);
+	if (fd < 0) {
+		perror(path);
 		return 0;
+	}
 
 	len = sizeof(buf);
 
 	ret = read(fd, buf, len);
 	if (ret < 0) {
-		perror(files);
+		perror(path);
 		close(fd);
 		return 0;
 	}
src/sched_deadline/deadline_test.c +49 -12

89 lines not on this page · raw message

Signature · 1 line
2.31.1
author
#2 lore raw

PATCH 2/2 sched_deadline: Use HRTICK_DL for sched_deadline tests

In reply to John Kacur

If the HRTICK_DL feature is available, use it for the sched_deadline tests, otherwise fall back to HRTICK

This code is based on changes in stalld - which in turn was based on these sched_deadline tests

---
 src/sched_deadline/cyclicdeadline.c | 27 ++++++++++++++++++++++-----
 src/sched_deadline/deadline_test.c  | 28 +++++++++++++++++++++++-----
 2 files changed, 45 insertions(+), 10 deletions(-)
src/sched_deadline/cyclicdeadline.c +22 -5
index 4a38ec2274c9..4860a40f5e6b 100644
@@ -278,6 +278,7 @@ static int setup_hr_tick(void)
 	char path[MAX_PATH];
 	char buf[500];
 	static int set = 0;
+	int hrtick_dl = 0;
 	char *p;
 	int ret;
 	int len;
@@ -311,18 +312,34 @@ static int setup_hr_tick(void)
 
 	ret = 1;
 
-	p = strstr(buf, "HRTICK");
-	if (p + 3 >= buf) {
+	p = strstr(buf, "HRTICK_DL");
+	if (p && p - 3 >= buf) {
+		hrtick_dl = 1;
 		p -= 3;
-		if (strncmp(p, "NO_HRTICK", 9) == 0) {
-			ret = write(fd, "HRTICK", 6);
-			if (ret != 6)
+		if (strncmp(p, "NO_HRTICK_DL", 12) == 0) {
+			ret = write(fd, "HRTICK_DL", 9);
+			if (ret != 9)
 				ret = 0;
 			else
 				ret = 1;
 		}
 	}
 
+	/* Backwards compatibility for kernel that only have HRTICK */
+	if (!hrtick_dl) {
+		p = strstr(buf, "HRTICK");
+		if (p && p - 3 >= buf) {
+			p -=3;
+			if (strncmp(p, "NO_HRTICK", 9) == 0) {
+				ret = write(fd, "HRTICK", 6);
+				if (ret != 6)
+					ret = 0;
+				else
+					ret = 1;
+			}
+		}
+	}
+
 	close(fd);
 	return ret;
 }
src/sched_deadline/deadline_test.c +23 -5
index c1e890319895..a48c231c1281 100644
@@ -427,6 +427,7 @@ static int setup_hr_tick(void)
 	char path[MAX_PATH];
 	char buf[500];
 	static int set = 0;
+	int hrtick_dl = 0;
 	char *p;
 	int ret;
 	int len;
@@ -461,18 +462,35 @@ static int setup_hr_tick(void)
 
 	ret = 1;
 
-	p = strstr(buf, "HRTICK");
-	if (p + 3 >= buf) {
+	p = strstr(buf, "HRTICK_DL");
+	if (p && p - 3 >= buf) {
+		hrtick_dl = 1;
 		p -= 3;
-		if (strncmp(p, "NO_HRTICK", 9) == 0) {
-			ret = write(fd, "HRTICK", 6);
-			if (ret != 6)
+		if (strncmp(p, "NO_HRTICK_DL", 12) == 0) {
+			ret = write(fd, "HRTICK_DL", 9);
+			if (ret != 9)
 				ret = 0;
 			else
 				ret = 1;
 		}
 	}
 
+	/* Backwards compatibility for kernel that only have HRTICK */
+	if (!hrtick_dl) {
+		p = strstr(buf, "HRTICK");
+		if (p && p - 3 >= buf) {
+			p -=3;
+			if (strncmp(p, "NO_HRTICK", 9) == 0) {
+				ret = write(fd, "HRTICK", 6);
+				if (ret != 6)
+					ret = 0;
+				else
+					ret = 1;
+			}
+		}
+	}
+
+
 	close(fd);
 	return ret;
 }
Signature · 1 line
2.31.1