Skip to contentSkip to conversation

cobalt/dovetail: Resolve pipeline_clock_name TODO

PATCH In review Jan Kiszka 2 participants 3 messages Nov 29, 2021 – Nov 30, 2021

lore
Share & tools
lore

Jan Kiszka

author
#0 lore raw

PATCH 1/1 cobalt/dovetail: Resolve pipeline_clock_name TODO

From: Jan Kiszka <[email protected]>

We don't have access to the kernel's curr_clocksource variable, so just make a general statement.

---
 include/cobalt/kernel/dovetail/pipeline/clock.h | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
include/cobalt/kernel/dovetail/pipeline/clock.h +1 -4
index d8c94ab435..cdb0dac4fe 100644
@@ -40,10 +40,7 @@ const char *pipeline_timer_name(void);
 
 static inline const char *pipeline_clock_name(void)
 {
-	/* Return the name of the current clock source. */
-	TODO();
-
-	return "?";
+	return "<Linux clocksource>";
 }
 
 static inline int pipeline_get_host_time(struct timespec64 *tp)
Signature · 1 line
2.31.1
#1 lore raw

Hi Jan

What about following patch? Try to get clocksource name via sys fs.

From aa6fdc59a22f9b1ddca145c72a75f2aa1f776e85 Mon Sep 17 00:00:00 2001
From: Hongzhan Chen <[email protected]>
Date: Wed, 24 Nov 2021 02:08:27 -0500
Subject: [PATCH] cobalt/clock: dovetail: get current clocksource name via sys
fs

Dovetail share the same clocksource that in-band is using. We try to get the name of current clocksource under sys filesystem.

include/cobalt/kernel/dovetail/pipeline/clock.h +23 -1
index d8c94ab43..ffe4ad083 100644
@@ -7,11 +7,14 @@
 
 #include <cobalt/uapi/kernel/types.h>
 #include <cobalt/kernel/assert.h>
+#include <linux/fs.h>
 #include <linux/ktime.h>
 #include <linux/errno.h>
 
 struct timespec64;
 
+#define SYS_CUR_CLOCKSOURCE "/sys/devices/system/clocksource/clocksource0/current_clocksource"
+
 static inline u64 pipeline_read_cycle_counter(void)
 {
        /*
@@ -41,7 +44,25 @@ const char *pipeline_timer_name(void);
 static inline const char *pipeline_clock_name(void)
 {
        /* Return the name of the current clock source. */
-       TODO();
+       struct file *curs;
+       static loff_t pos;
+       long r;
+
+       curs = filp_open(SYS_CUR_CLOCKSOURCE, O_RDONLY, 0);
+       if (IS_ERR(curs))
+               goto RTN_UNKNOWN;
+
+       memset(cobalt_pipeline.clocksource_name, 0, CLOCKSOURCE_NAME_MAXLEN);
+       pos = 0;
+       r = kernel_read(curs, cobalt_pipeline.clocksource_name, CLOCKSOURCE_NAME_MAXLEN - 1 , &pos);
+       filp_close(curs, NULL);
+
+
+       if (r < 0)
+               goto RTN_UNKNOWN;
+
+       return cobalt_pipeline.clocksource_name;
+
+RTN_UNKNOWN:
 
        return "?";

}

include/cobalt/kernel/dovetail/pipeline/machine.h +2 -0
index 4f3dd95e0..79f826bdf 100644
@@ -34,10 +34,12 @@ struct cobalt_machine_cpudata {
 
 DECLARE_PER_CPU(struct cobalt_machine_cpudata, cobalt_machine_cpudata);
 
+#define CLOCKSOURCE_NAME_MAXLEN 32
 struct cobalt_pipeline {
 #ifdef CONFIG_SMP
        cpumask_t supported_cpus;
 #endif
+       char clocksource_name[CLOCKSOURCE_NAME_MAXLEN];
 };
 
 int pipeline_init(void);

--
2.17.1

Regards

Hongzhan Chen
-----Original Message-----
From: Jan Kiszka <[email protected]>
Sent: Monday, November 29, 2021 6:03 PM
To: Xenomai <[email protected]>
Cc: Chen, Hongzhan <[email protected]>; Philippe Gerum <[email protected]>
Subject: [PATCH] cobalt/dovetail: Resolve pipeline_clock_name TODO

From: Jan Kiszka <[email protected]>

We don't have access to the kernel's curr_clocksource variable, so just make a general statement.

---
 include/cobalt/kernel/dovetail/pipeline/clock.h | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
include/cobalt/kernel/dovetail/pipeline/clock.h +1 -4
index d8c94ab435..cdb0dac4fe 100644
@@ -40,10 +40,7 @@ const char *pipeline_timer_name(void);
 
 static inline const char *pipeline_clock_name(void)
 {
-	/* Return the name of the current clock source. */
-	TODO();
-
-	return "?";
+	return "<Linux clocksource>";
 }
 
 static inline int pipeline_get_host_time(struct timespec64 *tp)
Signature · 1 line
2.31.1
author
#2 lore raw
Quoted 49 lines · Hongzhan

Hi Jan

What about following patch? Try to get clocksource name via sys fs.

From aa6fdc59a22f9b1ddca145c72a75f2aa1f776e85 Mon Sep 17 00:00:00 2001
From: Hongzhan Chen <[email protected]>
Date: Wed, 24 Nov 2021 02:08:27 -0500
Subject: [PATCH] cobalt/clock: dovetail: get current clocksource name via sys
fs

Dovetail share the same clocksource that in-band is using. We try to get the name of current clocksource under sys filesystem.

include/cobalt/kernel/dovetail/pipeline/clock.h +13 -1
index d8c94ab43..ffe4ad083 100644
@@ -7,11 +7,14 @@
 
 #include <cobalt/uapi/kernel/types.h>
 #include <cobalt/kernel/assert.h>
+#include <linux/fs.h>
 #include <linux/ktime.h>
 #include <linux/errno.h>
 
 struct timespec64;
 
+#define SYS_CUR_CLOCKSOURCE "/sys/devices/system/clocksource/clocksource0/current_clocksource"
+
 static inline u64 pipeline_read_cycle_counter(void)
 {
        /*
@@ -41,7 +44,25 @@ const char *pipeline_timer_name(void);
 static inline const char *pipeline_clock_name(void)
 {
        /* Return the name of the current clock source. */
-       TODO();
+       struct file *curs;
+       static loff_t pos;
+       long r;
+
+       curs = filp_open(SYS_CUR_CLOCKSOURCE, O_RDONLY, 0);
+       if (IS_ERR(curs))
+               goto RTN_UNKNOWN;
+
+       memset(cobalt_pipeline.clocksource_name, 0, CLOCKSOURCE_NAME_MAXLEN);
+       pos = 0;

include/cobalt/kernel/dovetail/pipeline/clock.h const char *pipeline_timer_name(void); · line 66

Quoted 10 lines
include/cobalt/kernel/dovetail/pipeline/clock.h +10 -0
+       r = kernel_read(curs, cobalt_pipeline.clocksource_name, CLOCKSOURCE_NAME_MAXLEN - 1 , &pos);
+       filp_close(curs, NULL);
+
+
+       if (r < 0)
+               goto RTN_UNKNOWN;
+
+       return cobalt_pipeline.clocksource_name;
+
+RTN_UNKNOWN:

I considered this briefly as well, but this is rather ugly (even when using kernel_read_file_from_path), and you can simply get the information from that original path as well - and that reliably, because userspace knows better of there is sysfs under /sys or elsewhere.

Once we remove I-pipe support, we will also simply drop this entry in /proc, thus the need for this abstraction.

Jan

Signature · 2 lines
Siemens AG, T RDA IOT
Corporate Competence Center Embedded Linux