cobalt/rtdm: introduce new interfaces to init task
PATCH 1/2 cobalt/rtdm: introduce new interfaces to init task
Initialise and start a real-time task on specified cpu.
Introduce rtdm_task_init_with_affinity as base called by other init task services to avoid code duplication.
include/cobalt/kernel/rtdm/driver.h +5 -0
@@ -1024,6 +1024,11 @@ 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 +70 -5
107 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH 2/2 cobalt/rtdm: introduce new interface to init timer
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 +32 -3
@@ -583,15 +583,44 @@ EXPORT_SYMBOL_GPL(rtdm_task_busy_sleep);int rtdm_timer_init (rtdm_timer_t *timer,rtdm_timer_handler_t handler,const char *name) { +/*cpu0 is used when no affinity was given*/ +return rtdm_timer_init_on_cpu (timer, handler, name,0 ); +} +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; +if (!realtime_core_enabled ())return -ENOSYS ; -xntimer_init ((timer), &nkclock, handler,NULL ,XNTIMER_IGRAVITY ); +if (!cpu_online (cpu)) +return -EINVAL ; + + sched =xnsched_struct (cpu); +if (sched ==NULL ) +return -EINVAL ; + +xntimer_init ((timer), &nkclock, handler, sched,XNTIMER_IGRAVITY );xntimer_set_name ((timer), (name)); +return 0 ; } - -EXPORT_SYMBOL_GPL (rtdm_timer_init); +EXPORT_SYMBOL_GPL (rtdm_timer_init_on_cpu);/** * @brief Destroy a timer
Signature · 1 line
2.17.1
Re: [PATCH 2/2] cobalt/rtdm: introduce new interface to init timer
Quoted 60 lines · hongzha1 via Xenomai <[email protected]> writes:
Initialise timer on specified cpu.
Signed-off-by hongzha1 <[email protected]>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 +30
-1@@ -583,15 +583,44 @@ EXPORT_SYMBOL_GPL(rtdm_task_busy_sleep);int rtdm_timer_init (rtdm_timer_t *timer,rtdm_timer_handler_t handler,const char *name) { +/*cpu0 is used when no affinity was given*/ +return rtdm_timer_init_on_cpu (timer, handler, name,0 ); +} +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; +if (!realtime_core_enabled ())return -ENOSYS ; -xntimer_init ((timer), &nkclock, handler,NULL ,XNTIMER_IGRAVITY ); +if (!cpu_online (cpu)) +return -EINVAL ; + + sched =xnsched_struct (cpu); +if (sched ==NULL ) +return -EINVAL ; + +xntimer_init ((timer), &nkclock, handler, sched,XNTIMER_IGRAVITY );
kernel/cobalt/rtdm/drvlib.c EXPORT_SYMBOL_GPL(rtdm_task_busy_sleep); · line 626
Quoted 10 lines
kernel/cobalt/rtdm/drvlib.c +2
-2xntimer_set_name ((timer), (name)); +return 0 ; } - -EXPORT_SYMBOL_GPL (rtdm_timer_init); +EXPORT_SYMBOL_GPL (rtdm_timer_init_on_cpu);/** * @brief Destroy a timer
Do we have a potential user for this call?
Signature · 1 line
Philippe.
RE: [PATCH 2/2] cobalt/rtdm: introduce new interface to init timer
Quoted 83 lines
-----Original Message-----
From: Philippe Gerum <[email protected]>
Sent: Thursday, March 11, 2021 4:14 PM
To: Chen, Hongzhan <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH 2/2] cobalt/rtdm: introduce new interface to init timerQuoted 60 lines · hongzha1 via Xenomai <[email protected]> writes:
Initialise timer on specified cpu.
Signed-off-by hongzha1 <[email protected]>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 +30
-1@@ -583,15 +583,44 @@ EXPORT_SYMBOL_GPL(rtdm_task_busy_sleep);int rtdm_timer_init (rtdm_timer_t *timer,rtdm_timer_handler_t handler,const char *name) { +/*cpu0 is used when no affinity was given*/ +return rtdm_timer_init_on_cpu (timer, handler, name,0 ); +} +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; +if (!realtime_core_enabled ())return -ENOSYS ; -xntimer_init ((timer), &nkclock, handler,NULL ,XNTIMER_IGRAVITY ); +if (!cpu_online (cpu)) +return -EINVAL ; + + sched =xnsched_struct (cpu); +if (sched ==NULL ) +return -EINVAL ; + +xntimer_init ((timer), &nkclock, handler, sched,XNTIMER_IGRAVITY );kernel/cobalt/rtdm/drvlib.c +2
-2xntimer_set_name ((timer), (name)); +return 0 ; } - -EXPORT_SYMBOL_GPL (rtdm_timer_init); +EXPORT_SYMBOL_GPL (rtdm_timer_init_on_cpu);/** * @brief Destroy a timer
Quoted 1 line
Do we have a potential user for this call?
Yes. Latmus is supposed to use it. Evl Latmus is calling evl_init_timer_on_cpu in create_uthread_runner. So I think Xenomai should have corresponding one.
Regards
Hongzhan Chen
Quoted 3 lines
Signature · 2 lines
-- Philippe.
Re: [PATCH 2/2] cobalt/rtdm: introduce new interface to init timer
Quoted 78 lines · Hongzhan
Quoted 78 lines
-----Original Message-----
From: Philippe Gerum <[email protected]>
Sent: Thursday, March 11, 2021 4:14 PM
To: Chen, Hongzhan <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH 2/2] cobalt/rtdm: introduce new interface to init timerQuoted 60 lines · hongzha1 via Xenomai <[email protected]> writes:
Initialise timer on specified cpu.
Signed-off-by hongzha1 <[email protected]>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 +30
-1@@ -583,15 +583,44 @@ EXPORT_SYMBOL_GPL(rtdm_task_busy_sleep);int rtdm_timer_init (rtdm_timer_t *timer,rtdm_timer_handler_t handler,const char *name) { +/*cpu0 is used when no affinity was given*/ +return rtdm_timer_init_on_cpu (timer, handler, name,0 ); +} +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; +if (!realtime_core_enabled ())return -ENOSYS ; -xntimer_init ((timer), &nkclock, handler,NULL ,XNTIMER_IGRAVITY ); +if (!cpu_online (cpu)) +return -EINVAL ; + + sched =xnsched_struct (cpu); +if (sched ==NULL ) +return -EINVAL ; + +xntimer_init ((timer), &nkclock, handler, sched,XNTIMER_IGRAVITY );kernel/cobalt/rtdm/drvlib.c +2
-2xntimer_set_name ((timer), (name)); +return 0 ; } - -EXPORT_SYMBOL_GPL (rtdm_timer_init); +EXPORT_SYMBOL_GPL (rtdm_timer_init_on_cpu);
Quoted 8 lines
Quoted 4 lines
/**
* @brief Destroy a timerDo we have a potential user for this call?
Yes. Latmus is supposed to use it. Evl Latmus is calling
evl_init_timer_on_cpuincreate_uthread_runner. So I think Xenomai should have corresponding one.
Agreed. Today, the timer benchmarking code can only land on CPU0, regardless of the affinity instruction given to 'latency', which is wrong. So we need this new call in order to be able to place the sampling timer on the tested CPU.
Signature · 1 line
Philippe.
Re: [PATCH 2/2] cobalt/rtdm: introduce new interface to init timer
In reply to hongzha1Quoted 45 lines · hongzha1 via Xenomai <[email protected]> writes:
Initialise timer on specified cpu.
Signed-off-by hongzha1 <[email protected]>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 +19
-0@@ -583,15 +583,44 @@ EXPORT_SYMBOL_GPL(rtdm_task_busy_sleep);int rtdm_timer_init (rtdm_timer_t *timer,rtdm_timer_handler_t handler,const char *name) { +/*cpu0 is used when no affinity was given*/ +return rtdm_timer_init_on_cpu (timer, handler, name,0 ); +} +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)
kernel/cobalt/rtdm/drvlib.c EXPORT_SYMBOL_GPL(rtdm_task_busy_sleep); · line 613
Quoted 10 lines
kernel/cobalt/rtdm/drvlib.c +6
-1+{ +struct xnsched *sched; +if (!realtime_core_enabled ())return -ENOSYS ; -xntimer_init ((timer), &nkclock, handler,NULL ,XNTIMER_IGRAVITY ); +if (!cpu_online (cpu)) +return -EINVAL ; +
We also have to check the CPU against the xnsched_realtime_cpus mask. Only the CPUs set in the latter receive clock ticks.
Signature · 1 line
Philippe.
Quoted 44 lines · hongzha1 via Xenomai <[email protected]> writes:
Initialise and start a real-time task on specified cpu.
Introduce
rtdm_task_init_with_affinityas base called by other init task services to avoid code duplication.Signed-off-by hongzha1 <[email protected]>include/cobalt/kernel/rtdm/driver.h +5
-0@@ -1024,6 +1024,11 @@ 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 +2
-1@@ -86,13 +86,14 @@ nanosecs_abs_t rtdm_clock_read_monotonic(void);*/ /** -* @brief Initialise and start a real-time task +* @brief Initialise and start a real-time task with cpu affinity * * 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 affinity that task want to run with * @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
kernel/cobalt/rtdm/drvlib.c nanosecs_abs_t rtdm_clock_read_monotonic(void); · line 113
Quoted 10 lines
kernel/cobalt/rtdm/drvlib.c +4
-3@@ -106,9 +107,10 @@ nanosecs_abs_t rtdm_clock_read_monotonic(void);* * @coretags{secondary-only, might-switch} */ -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) +static inline int rtdm_task_init_with_affinity (rtdm_task_t *task, +cpumask_t affinity,const char *name, +rtdm_task_proc_t task_proc,void *arg, +int priority,nanosecs_rel_t period)
In general, I would refrain from passing CPU masks by value; these may represent pretty large data on x86 platforms, although the optimizer might find its way using a reference internally in this specific case. Receiving struct cpumask * would be better nevertheless. xnintr_affinity() is another candidate for such a change.
Quoted 84 lines
kernel/cobalt/rtdm/drvlib.c +64
-1{union xnsched_policy_param param;struct xnthread_start_attr sattr;@@ -121,7 +123,7 @@ int rtdm_task_init(rtdm_task_t *task, const char *name, iattr.name = name; iattr.flags =0 ; iattr.personality = &xenomai_personality; - iattr.affinity =CPU_MASK_ALL ; + iattr.affinity = affinity; param.rt.prio = priority; err =xnthread_init (task, &iattr, &xnsched_class_rt, ¶m);@@ -155,8 +157,71 @@ int rtdm_task_init(rtdm_task_t *task, const char *name,return err; } +/** +* @brief Initialise and start a real-time task +* +* 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] 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 (rtdm_task_t *task,const char *name, +rtdm_task_proc_t task_proc,void *arg, +int priority,nanosecs_rel_t period) +{ +return rtdm_task_init_with_affinity (task,CPU_MASK_ALL , + name, task_proc, arg, priority, period); +}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) +{ +if (!cpu_online (cpu)) +return -EINVAL ; + +return rtdm_task_init_with_affinity (task, *cpumask_of (cpu), + name, task_proc, arg, priority, period); + +} +EXPORT_SYMBOL_GPL (rtdm_task_init_on_cpu); +#ifdef DOXYGEN_CPP /* Only used for doxygen doc generation */ /** * @brief Destroy a real-time task
Signature · 1 line
Philippe.