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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

Signed-off-by: John Kacur <jkacur@xxxxxxxxxx>
---
 src/sched_deadline/cyclicdeadline.c | 65 ++++++++++++++++++++++-------
 src/sched_deadline/deadline_test.c  | 61 +++++++++++++++++++++------
 2 files changed, 100 insertions(+), 26 deletions(-)

diff --git a/src/sched_deadline/cyclicdeadline.c b/src/sched_deadline/cyclicdeadline.c
index 8447424273ee..4a38ec2274c9 100644
--- a/src/sched_deadline/cyclicdeadline.c
+++ b/src/sched_deadline/cyclicdeadline.c
@@ -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;
 	}
diff --git a/src/sched_deadline/deadline_test.c b/src/sched_deadline/deadline_test.c
index 395c2370f69a..c1e890319895 100644
--- a/src/sched_deadline/deadline_test.c
+++ b/src/sched_deadline/deadline_test.c
@@ -368,6 +368,49 @@ 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;
+
+}
+
 /**
  * setup_hr_tick - Enable the HRTICK in sched_features (if available)
  *
@@ -381,10 +424,8 @@ found:
  */
 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;
@@ -396,17 +437,13 @@ static int setup_hr_tick(void)
 
 	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);
+	fd = open(path, O_RDWR);
 	if (fd < 0) {
-		perror(files);
+		perror(path);
 		return 0;
 	}
 
@@ -414,7 +451,7 @@ static int setup_hr_tick(void)
 
 	ret = read(fd, buf, len);
 	if (ret < 0) {
-		perror(files);
+		perror(path);
 		close(fd);
 		return 0;
 	}
-- 
2.31.1




[Index of Archives]     [RT Stable]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux