cobalt/rtdm: add new interface to init task on specified cpu
PATCH 1/5 cobalt/rtdm: add new interface to init task on specified cpu
Initialise and start a real-time task on specified cpu
include/cobalt/kernel/rtdm/driver.h +3 -0
@@ -1024,6 +1024,9 @@ typedef void (*rtdm_task_proc_t)(void *arg);int rtdm_task_init (rtdm_task_t *task,const char *name,rtdm_task_proc_t task_proc,void *arg,int priority,nanosecs_rel_t period); +int rtdm_task_init_on_cpu (rtdm_task_t *task,int cpu,const char *name, +rtdm_task_proc_t task_proc,void *arg, +int priority,nanosecs_rel_t period);int __rtdm_task_sleep (xnticks_t timeout,xntmode_t mode);void rtdm_task_busy_sleep (nanosecs_rel_t delay);
kernel/cobalt/rtdm/drvlib.c +73 -0
79 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH 2/5 cobalt/rtdm: add interface to init timer on specified cpu
Initialise timer on specified cpu
include/cobalt/kernel/rtdm/driver.h +3 -0
@@ -966,6 +966,9 @@ enum rtdm_timer_mode {int rtdm_timer_init (rtdm_timer_t *timer,rtdm_timer_handler_t handler,const char *name); +int rtdm_timer_init_on_cpu (rtdm_timer_t *timer,rtdm_timer_handler_t handler, +const char *name,int cpu); +void rtdm_timer_destroy (rtdm_timer_t *timer); int rtdm_timer_start(rtdm_timer_t *timer, nanosecs_abs_t expiry,
kernel/cobalt/rtdm/drvlib.c +28 -0
@@ -601,6 +601,34 @@ int rtdm_timer_init(rtdm_timer_t *timer, rtdm_timer_handler_t handler,EXPORT_SYMBOL_GPL (rtdm_timer_init); +/** +* @brief Initialise a timer on specified cpu +* +* @param[in,out] timer Timer handle +* @param[in] handler Handler to be called on timer expiry +* @param[in] name Optional timer name +* @param[in] cpu that run on +* +* @return 0 on success, otherwise negative error code +* +* @coretags{task-unrestricted} +*/ +int rtdm_timer_init_on_cpu (rtdm_timer_t *timer,rtdm_timer_handler_t handler, +const char *name,int cpu) +{ +struct xnsched *sched =xnsched_struct (cpu); + +if (!realtime_core_enabled ()) +return -ENOSYS ; + + sched =xnsched_struct (cpu); +xntimer_init ((timer), &nkclock, handler, sched,XNTIMER_IGRAVITY ); +xntimer_set_name ((timer), (name)); + +return 0 ; +} +EXPORT_SYMBOL_GPL (rtdm_timer_init_on_cpu); +/** * @brief Destroy a timer *
Signature · 1 line
2.17.1
PATCH 3/5 rtdm/testing: latmus: introduce latmus driver
In reply to hongzha1include/rtdm/uapi/testing.h +63 -0
@@ -118,6 +118,52 @@ struct rttst_heap_stathdr {struct rttst_heap_stats *buf; }; +/* Latmus context types. */ +#define COBALT_LAT_IRQ 0 +#define COBALT_LAT_KERN 1 +#define COBALT_LAT_USER 2 +#define COBALT_LAT_SIRQ 3 +#define COBALT_LAT_LAST COBALT_LAT_SIRQ + +struct latmus_setup { +__u32 type; +__u64 period; +__s32 priority; +__u32 cpu; +union { +struct { +__u32 verbosity; + } tune; +struct { +__u32 xfd; +__u32 hcells; + } measure; + } u; +}; + +/* +* The measurement record which the driver sends to userland each +* second through an xbuf channel. +*/ +struct latmus_measurement { +__s64 sum_lat; +__s32 min_lat; +__s32 max_lat; +__u32 overruns; +__u32 samples; +}; + +struct latmus_measurement_result { +__u64 last_ptr;/* (struct latmus_measurement __user *last) */ +__u64 histogram_ptr;/* (__s32 __user *histogram) */ +__u32 len; +}; + +struct latmus_result { +__u64 data_ptr;/* (void __user *data) */ +__u32 len; +}; +#define RTIOC_TYPE_TESTING RTDM_CLASS_TESTING/*!
@@ -133,6 +179,8 @@ struct rttst_heap_stathdr {#define RTDM_SUBCLASS_RTDMTEST 3/** subclase name: "heapcheck" */ #define RTDM_SUBCLASS_HEAPCHECK 4 +/** subclase name: "latmus" */ +#define RTDM_SUBCLASS_LATMUS 5/** @} */ /*!
@@ -193,6 +241,21 @@ struct rttst_heap_stathdr {#define RTTST_RTIOC_HEAP_STAT_COLLECT \ _IOR(RTIOC_TYPE_TESTING, 0x45, int) +#define RTTST_RTIOC_COBALT_LATIOC_TUNE \ + _IOWR(RTIOC_TYPE_TESTING, 0x50, struct latmus_setup) + +#define RTTST_RTIOC_COBALT_LATIOC_MEASURE \ + _IOWR(RTIOC_TYPE_TESTING, 0x51, struct latmus_setup) + +#define RTTST_RTIOC_COBALT_LATIOC_RUN \ + _IOR(RTIOC_TYPE_TESTING, 0x52, struct latmus_result) + +#define RTTST_RTIOC_COBALT_LATIOC_PULSE \ + _IOW(RTIOC_TYPE_TESTING, 0x53, __u64) + +#define RTTST_RTIOC_COBALT_LATIOC_RESET \ + _IO(RTIOC_TYPE_TESTING, 0x54) +/** @} */ #endif /* !_RTDM_UAPI_TESTING_H */
kernel/drivers/testing/Kconfig +10 -0
@@ -26,4 +26,14 @@ config XENO_DRIVERS_RTDMTEST help Kernel driver for performing RTDM unit tests. +config COBALT_LATMUS + bool "Timer latency calibration and measurement" + depends on XENOMAI + default y + help + This driver supports the latmus application for + determining the best gravity values for the cobalt core + clock, and measuring the response time to timer events. + If in doubt, say 'Y'. + endmenu
kernel/drivers/testing/Makefile +1 -0
@@ -3,6 +3,7 @@ obj-$(CONFIG_XENO_DRIVERS_TIMERBENCH) += xeno_timerbench.o obj-$(CONFIG_XENO_DRIVERS_SWITCHTEST) += xeno_switchtest.o obj-$(CONFIG_XENO_DRIVERS_RTDMTEST) += xeno_rtdmtest.o obj-$(CONFIG_XENO_DRIVERS_HEAPCHECK) += xeno_heapcheck.o +obj-$(CONFIG_COBALT_LATMUS) += latmus.o xeno_timerbench-y := timerbench.o
kernel/drivers/testing/latmus.c new file +1237 -0
1,237 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH 4/5 drivers/gpio: core: introduce helper to find gpiochip
In reply to hongzha1To find gpiochip for non-OF platforms like x86
include/cobalt/kernel/rtdm/gpio.h +3 -0
@@ -61,6 +61,9 @@ int rtdm_gpiochip_add_by_name(struct rtdm_gpio_chip *rgc,int rtdm_gpiochip_post_event (struct rtdm_gpio_chip *rgc,unsigned int offset); +int rtdm_gpiochip_find (struct device_node *from, +void *compat,int type); +#ifdef CONFIG_OF int rtdm_gpiochip_scan_of(struct device_node *from,
kernel/drivers/gpio/gpio-core.c +28 -0
@@ -554,6 +554,34 @@ static int match_gpio_chip(struct gpio_chip *gc, void *data)return 0 ; } +static int chip_match_name (struct gpio_chip *chip,void *data) +{ +return !strncmp (chip->label, data,strlen (data)); +} + +int rtdm_gpiochip_find (struct device_node *from,void *compat, +int type) +{ +struct rtdm_gpio_chip *rgc; +struct gpio_chip *chip; +int ret = -ENODEV ; + +if (!rtdm_available ()) +return -ENOSYS ; + + chip =gpiochip_find (compat, chip_match_name); +if (chip ==NULL ) +return ret; + + ret =0 ; + rgc =rtdm_gpiochip_alloc (chip, type); +if (IS_ERR (rgc)) + ret =PTR_ERR (rgc); + +return ret; +} +EXPORT_SYMBOL_GPL (rtdm_gpiochip_find); +int rtdm_gpiochip_scan_of (struct device_node *from,const char *compat,int type) {
Signature · 1 line
2.17.1
PATCH 5/5 testsuite/latmus: introduce latmus app
In reply to hongzha1configure.ac +1 -0
@@ -954,6 +954,7 @@ AC_CONFIG_FILES([ \ lib/trank/Makefile \ testsuite/Makefile \ testsuite/latency/Makefile \ + testsuite/latmus/Makefile \ testsuite/switchtest/Makefile \ testsuite/gpiotest/Makefile \ testsuite/gpiobench/Makefile \
include/rtdm/uapi/testing.h +16 -0
@@ -256,6 +256,22 @@ struct latmus_result {#define RTTST_RTIOC_COBALT_LATIOC_RESET \ _IO(RTIOC_TYPE_TESTING, 0x54) +#define LATMON_NET_PORT 2306 + +struct latmon_net_request { +uint32_t period_usecs; +uint32_t histogram_cells; +} __attribute__((__packed__ )); + +struct latmon_net_data { +int32_t sum_lat_hi; +int32_t sum_lat_lo; +int32_t min_lat; +int32_t max_lat; +uint32_t overruns; +uint32_t samples; +} __attribute__((__packed__ )); +/** @} */ #endif /* !_RTDM_UAPI_TESTING_H */
testsuite/Makefile.am +3 -1
@@ -1,10 +1,11 @@ -SUBDIRS = latency smokey gpiobench +SUBDIRS = latency latmus smokey gpiobench if XENO_COBALT SUBDIRS += \ clocktest \ gpiotest \ + latmus \ spitest \ switchtest \ xeno-test
@@ -15,6 +16,7 @@ DIST_SUBDIRS = \ gpiotest \ gpiobench \ latency \ + latmus \ smokey \ spitest \ switchtest \
testsuite/latmus/Makefile.am new file +18 -0
@@ -0,0 +1,18 @@ +testdir = @XENO_TEST_DIR@ + +CCLD = $(top_srcdir)/scripts/wrap-link.sh $(CC) + +test_PROGRAMS = latmus + +latmus_SOURCES = latmus.c + +latmus_CPPFLAGS = \ + $(XENO_USER_CFLAGS) \ + -I$(top_srcdir)/include + +latmus_LDFLAGS = @XENO_AUTOINIT_LDFLAGS@ $(XENO_POSIX_WRAPPERS) + +latmus_LDADD = \ + @XENO_CORE_LDADD@ \ + @XENO_USER_LDADD@ \ + -lpthread -lrt -lm
testsuite/latmus/latmus.c new file +1444 -0
1,444 lines not on this page · raw message
Signature · 1 line
2.17.1
why do we need a new interface instead of adding a new parameter(cpu) in old interface, in this case rtdm_task_init.
For backward compatibility?
Quoted 103 lines · On 2021年02月20日 13:53, hongzha1 via Xenomai wrote:
Initialise and start a real-time task on specified cpu
Signed-off-by hongzha1 <[email protected]>include/cobalt/kernel/rtdm/driver.h +3
-0@@ -1024,6 +1024,9 @@ typedef void (*rtdm_task_proc_t)(void *arg);int rtdm_task_init (rtdm_task_t *task,const char *name,rtdm_task_proc_t task_proc,void *arg,int priority,nanosecs_rel_t period); +int rtdm_task_init_on_cpu (rtdm_task_t *task,int cpu,const char *name, +rtdm_task_proc_t task_proc,void *arg, +int priority,nanosecs_rel_t period);int __rtdm_task_sleep (xnticks_t timeout,xntmode_t mode);void rtdm_task_busy_sleep (nanosecs_rel_t delay);kernel/cobalt/rtdm/drvlib.c +73
-0@@ -157,6 +157,79 @@ int rtdm_task_init(rtdm_task_t *task, const char *name,EXPORT_SYMBOL_GPL (rtdm_task_init); +/** +* @brief Initialise and start a real-time task on specified cpu +* +* After initialising a task, the task handle remains valid and can be +* passed to RTDM services until either rtdm_task_destroy() or +* rtdm_task_join() was invoked. +* +* @param[in,out] task Task handle +* @param[in] cpu that task want to run on +* @param[in] name Optional task name +* @param[in] task_proc Procedure to be executed by the task +* @param[in] arg Custom argument passed to @c task_proc() on entry +* @param[in] priority Priority of the task, see also +* @ref rtdmtaskprio "Task Priority Range" +* @param[in] period Period in nanoseconds of a cyclic task, 0 for non-cyclic +* mode. Waiting for the first and subsequent periodic events is +* done using rtdm_task_wait_period(). +* +* @return 0 on success, otherwise negative error code +* +* @coretags{secondary-only, might-switch} +*/ +int rtdm_task_init_on_cpu (rtdm_task_t *task,int cpu,const char *name, +rtdm_task_proc_t task_proc,void *arg, +int priority,nanosecs_rel_t period) +{ +union xnsched_policy_param param; +struct xnthread_start_attr sattr; +struct xnthread_init_attr iattr; +int err; + +if (!realtime_core_enabled ()) +return -ENOSYS ; + + iattr.name = name; + iattr.flags =0 ; + iattr.personality = &xenomai_personality; + iattr.affinity = *cpumask_of (cpu); + param.rt.prio = priority; + + err =xnthread_init (task, &iattr, &xnsched_class_rt, ¶m); +if (err) +return err; + +/* We need an anonymous registry entry to obtain a handle for fast +* mutex locking. +*/ + err =xnthread_register (task,"" ); +if (err) + goto cleanup_out; + +if (period >0 ) { + err =xnthread_set_periodic (task,XN_INFINITE , +XN_RELATIVE , period); +if (err) + goto cleanup_out; + } + + sattr.mode =0 ; + sattr.entry = task_proc; + sattr.cookie = arg; + err =xnthread_start (task, &sattr); +if (err) + goto cleanup_out; + +return 0 ; + +cleanup_out: +xnthread_cancel (task); +return err; +} +EXPORT_SYMBOL_GPL (rtdm_task_init_on_cpu); +#ifdef DOXYGEN_CPP /* Only used for doxygen doc generation */ /** * @brief Destroy a real-time task
Quoted 11 lines
-----Original Message-----
From: chensong <[email protected]>
Sent: Saturday, February 20, 2021 5:40 PM
To: Chen, Hongzhan <[email protected]>; [email protected]
Subject: Re: [PATCH 1/5] cobalt/rtdm: add new interface to init task on specified cpuwhy do we need a new interface instead of adding a new parameter(cpu) in old interface, in this case
rtdm_task_init.For backward compatibility?
We discussed it about introducing rtdm_task_init_on_cpu in [1]. Actually most of contents of rtdm_task_init_on_cpu is really same with rtdm_task_init except cpu affinity. But rtdm_task_init was already called by several drivers such as net and testing. If we modify definition of rtdm_task_init , we have to modify all of these drivers that calling rtdm_task_init.
[1]: https://xenomai.org/pipermail/xenomai/2021-February/044250.html
Quoted 105 lines · On 2021?02?20? 13:53, hongzha1 via Xenomai wrote:
Quoted 103 lines
Initialise and start a real-time task on specified cpu
Signed-off-by hongzha1 <[email protected]>include/cobalt/kernel/rtdm/driver.h +3
-0@@ -1024,6 +1024,9 @@ typedef void (*rtdm_task_proc_t)(void *arg);int rtdm_task_init (rtdm_task_t *task,const char *name,rtdm_task_proc_t task_proc,void *arg,int priority,nanosecs_rel_t period); +int rtdm_task_init_on_cpu (rtdm_task_t *task,int cpu,const char *name, +rtdm_task_proc_t task_proc,void *arg, +int priority,nanosecs_rel_t period);int __rtdm_task_sleep (xnticks_t timeout,xntmode_t mode);void rtdm_task_busy_sleep (nanosecs_rel_t delay);kernel/cobalt/rtdm/drvlib.c +73
-0@@ -157,6 +157,79 @@ int rtdm_task_init(rtdm_task_t *task, const char *name,EXPORT_SYMBOL_GPL (rtdm_task_init); +/** +* @brief Initialise and start a real-time task on specified cpu +* +* After initialising a task, the task handle remains valid and can be +* passed to RTDM services until either rtdm_task_destroy() or +* rtdm_task_join() was invoked. +* +* @param[in,out] task Task handle +* @param[in] cpu that task want to run on +* @param[in] name Optional task name +* @param[in] task_proc Procedure to be executed by the task +* @param[in] arg Custom argument passed to @c task_proc() on entry +* @param[in] priority Priority of the task, see also +* @ref rtdmtaskprio "Task Priority Range" +* @param[in] period Period in nanoseconds of a cyclic task, 0 for non-cyclic +* mode. Waiting for the first and subsequent periodic events is +* done using rtdm_task_wait_period(). +* +* @return 0 on success, otherwise negative error code +* +* @coretags{secondary-only, might-switch} +*/ +int rtdm_task_init_on_cpu (rtdm_task_t *task,int cpu,const char *name, +rtdm_task_proc_t task_proc,void *arg, +int priority,nanosecs_rel_t period) +{ +union xnsched_policy_param param; +struct xnthread_start_attr sattr; +struct xnthread_init_attr iattr; +int err; + +if (!realtime_core_enabled ()) +return -ENOSYS ; + + iattr.name = name; + iattr.flags =0 ; + iattr.personality = &xenomai_personality; + iattr.affinity = *cpumask_of (cpu); + param.rt.prio = priority; + + err =xnthread_init (task, &iattr, &xnsched_class_rt, ¶m); +if (err) +return err; + +/* We need an anonymous registry entry to obtain a handle for fast +* mutex locking. +*/ + err =xnthread_register (task,"" ); +if (err) + goto cleanup_out; + +if (period >0 ) { + err =xnthread_set_periodic (task,XN_INFINITE , +XN_RELATIVE , period); +if (err) + goto cleanup_out; + } + + sattr.mode =0 ; + sattr.entry = task_proc; + sattr.cookie = arg; + err =xnthread_start (task, &sattr); +if (err) + goto cleanup_out; + +return 0 ; + +cleanup_out: +xnthread_cancel (task); +return err; +} +EXPORT_SYMBOL_GPL (rtdm_task_init_on_cpu); +#ifdef DOXYGEN_CPP /* Only used for doxygen doc generation */ /** * @brief Destroy a real-time task
Quoted 9 lines · Hongzhan via Xenomai
Quoted 9 lines
-----Original Message-----
From: chensong <[email protected]>
Sent: Saturday, February 20, 2021 5:40 PM
To: Chen, Hongzhan <[email protected]>; [email protected]
Subject: Re: [PATCH 1/5] cobalt/rtdm: add new interface to init task on specified cpuwhy do we need a new interface instead of adding a new parameter(cpu) in old interface, in this case
rtdm_task_init.
Quoted 8 lines
Quoted 1 line
For backward compatibility?
We discussed it about introducing
rtdm_task_init_on_cpuin [1]. Actually most of contents ofrtdm_task_init_on_cpuis really same withrtdm_task_initexcept cpu affinity. Butrtdm_task_initwas already called by several drivers such as net and testing. If we modify definition ofrtdm_task_init, we have to modify all of these drivers that callingrtdm_task_init.[1]: https://xenomai.org/pipermail/xenomai/2021-February/044250.html
Agreed. Not to speak of the custom drivers in the field, which would break at build due to a new prototype of rtdm_task_init().
Besides, adding such a variant matches the mainline kernel naming scheme (kthread_create vs kthread_create_on_node vs kthread_create_on_cpu).
Signature · 1 line
Philippe.
Quoted 54 lines · hongzha1 via Xenomai <[email protected]> writes:
Initialise and start a real-time task on specified cpu
Signed-off-by hongzha1 <[email protected]>include/cobalt/kernel/rtdm/driver.h +3
-0@@ -1024,6 +1024,9 @@ typedef void (*rtdm_task_proc_t)(void *arg);int rtdm_task_init (rtdm_task_t *task,const char *name,rtdm_task_proc_t task_proc,void *arg,int priority,nanosecs_rel_t period); +int rtdm_task_init_on_cpu (rtdm_task_t *task,int cpu,const char *name, +rtdm_task_proc_t task_proc,void *arg, +int priority,nanosecs_rel_t period);int __rtdm_task_sleep (xnticks_t timeout,xntmode_t mode);void rtdm_task_busy_sleep (nanosecs_rel_t delay);kernel/cobalt/rtdm/drvlib.c +28
-0@@ -157,6 +157,79 @@ int rtdm_task_init(rtdm_task_t *task, const char *name,EXPORT_SYMBOL_GPL (rtdm_task_init); +/** +* @brief Initialise and start a real-time task on specified cpu +* +* After initialising a task, the task handle remains valid and can be +* passed to RTDM services until either rtdm_task_destroy() or +* rtdm_task_join() was invoked. +* +* @param[in,out] task Task handle +* @param[in] cpu that task want to run on +* @param[in] name Optional task name +* @param[in] task_proc Procedure to be executed by the task +* @param[in] arg Custom argument passed to @c task_proc() on entry +* @param[in] priority Priority of the task, see also +* @ref rtdmtaskprio "Task Priority Range" +* @param[in] period Period in nanoseconds of a cyclic task, 0 for non-cyclic +* mode. Waiting for the first and subsequent periodic events is +* done using rtdm_task_wait_period(). +* +* @return 0 on success, otherwise negative error code +* +* @coretags{secondary-only, might-switch} +*/ +int rtdm_task_init_on_cpu (rtdm_task_t *task,int cpu,const char *name, +rtdm_task_proc_t task_proc,void *arg, +int priority,nanosecs_rel_t period) +{ +union xnsched_policy_param param; +struct xnthread_start_attr sattr;
kernel/cobalt/rtdm/drvlib.c int rtdm_task_init(rtdm_task_t *task, const char *name, · line 197
Quoted 10 lines
kernel/cobalt/rtdm/drvlib.c +10
-0+struct xnthread_init_attr iattr; +int err; + +if (!realtime_core_enabled ()) +return -ENOSYS ; + + iattr.name = name; + iattr.flags =0 ; + iattr.personality = &xenomai_personality; + iattr.affinity = *cpumask_of (cpu);
We should probably check cpu for validity first, I don't think cpumask_of() does it (e.g. cpu_online(cpu) would ensure both validity and online presence).
Quoted 28 lines
kernel/cobalt/rtdm/drvlib.c +28
-0+ param.rt.prio = priority; + + err =xnthread_init (task, &iattr, &xnsched_class_rt, ¶m); +if (err) +return err; + +/* We need an anonymous registry entry to obtain a handle for fast +* mutex locking. +*/ + err =xnthread_register (task,"" ); +if (err) + goto cleanup_out; + +if (period >0 ) { + err =xnthread_set_periodic (task,XN_INFINITE , +XN_RELATIVE , period); +if (err) + goto cleanup_out; + } + + sattr.mode =0 ; + sattr.entry = task_proc; + sattr.cookie = arg; + err =xnthread_start (task, &sattr); +if (err) + goto cleanup_out; + +return 0 ;
kernel/cobalt/rtdm/drvlib.c int rtdm_task_init(rtdm_task_t *task, const char *name, · line 235
Quoted 10 lines
kernel/cobalt/rtdm/drvlib.c +7
-0+ +cleanup_out: +xnthread_cancel (task); +return err; +} +EXPORT_SYMBOL_GPL (rtdm_task_init_on_cpu); +#ifdef DOXYGEN_CPP /* Only used for doxygen doc generation */ /** * @brief Destroy a real-time task
Looks good. We may want to implement rtdm_task_init_cpu() as an inline variant calling rtdm_task_init_on_cpu() with the current CPU number, to prevent code duplication.
Signature · 1 line
Philippe.