All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH V2 1/2] cobalt/rtdm: introduce new interfaces to init task
@ 2021-03-10  0:57 hongzha1
  2021-03-10  0:57 ` [PATCH 2/2] cobalt/rtdm: introduce new interfaces to init timer hongzha1
  2021-03-10  8:25 ` [PATCH V2 1/2] cobalt/rtdm: introduce new interfaces to init task Jan Kiszka
  0 siblings, 2 replies; 5+ messages in thread
From: hongzha1 @ 2021-03-10  0:57 UTC (permalink / raw)
  To: xenomai

Initialise and start a real-time task on specified cpu or current
cpu.

Signed-off-by: hongzha1 <hongzhan.chen@intel.com>

diff --git a/include/cobalt/kernel/rtdm/driver.h b/include/cobalt/kernel/rtdm/driver.h
index 733c49df8..42daaa5b2 100644
--- a/include/cobalt/kernel/rtdm/driver.h
+++ b/include/cobalt/kernel/rtdm/driver.h
@@ -1024,6 +1024,20 @@ 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);
+
+static inline int rtdm_task_init_cpu(rtdm_task_t *task, const char *name,
+		rtdm_task_proc_t task_proc, void *arg,
+		int priority, nanosecs_rel_t period)
+{
+	int cpu = raw_smp_processor_id();
+
+	return rtdm_task_init_on_cpu(task, cpu, name, task_proc, arg,
+			priority, period);
+}
+
 int __rtdm_task_sleep(xnticks_t timeout, xntmode_t mode);
 void rtdm_task_busy_sleep(nanosecs_rel_t delay);
 
diff --git a/kernel/cobalt/rtdm/drvlib.c b/kernel/cobalt/rtdm/drvlib.c
index b914fa312..1c999362e 100644
--- a/kernel/cobalt/rtdm/drvlib.c
+++ b/kernel/cobalt/rtdm/drvlib.c
@@ -157,6 +157,82 @@ 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;
+
+	if (!cpu_online(cpu))
+		return -EINVAL;
+
+	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, &param);
+	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
-- 
2.17.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] cobalt/rtdm: introduce new interfaces to init timer
  2021-03-10  0:57 [PATCH V2 1/2] cobalt/rtdm: introduce new interfaces to init task hongzha1
@ 2021-03-10  0:57 ` hongzha1
  2021-03-10  8:25 ` [PATCH V2 1/2] cobalt/rtdm: introduce new interfaces to init task Jan Kiszka
  1 sibling, 0 replies; 5+ messages in thread
From: hongzha1 @ 2021-03-10  0:57 UTC (permalink / raw)
  To: xenomai

Initialise timer on specified cpu or current cpu.

Signed-off-by: hongzha1 <hongzhan.chen@intel.com>

diff --git a/include/cobalt/kernel/rtdm/driver.h b/include/cobalt/kernel/rtdm/driver.h
index 42daaa5b2..4b4ee965d 100644
--- a/include/cobalt/kernel/rtdm/driver.h
+++ b/include/cobalt/kernel/rtdm/driver.h
@@ -966,6 +966,17 @@ 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);
+
+static inline int rtdm_timer_init_cpu(rtdm_timer_t *timer,
+		rtdm_timer_handler_t handler, const char *name)
+{
+	int cpu = raw_smp_processor_id();
+
+	return rtdm_timer_init_on_cpu(timer, handler, name, cpu);
+}
+
 void rtdm_timer_destroy(rtdm_timer_t *timer);
 
 int rtdm_timer_start(rtdm_timer_t *timer, nanosecs_abs_t expiry,
diff --git a/kernel/cobalt/rtdm/drvlib.c b/kernel/cobalt/rtdm/drvlib.c
index 1c999362e..4e00d4e02 100644
--- a/kernel/cobalt/rtdm/drvlib.c
+++ b/kernel/cobalt/rtdm/drvlib.c
@@ -604,6 +604,37 @@ 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;
+
+	if (!realtime_core_enabled())
+		return -ENOSYS;
+
+	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_on_cpu);
+
 /**
  * @brief Destroy a timer
  *
-- 
2.17.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH V2 1/2] cobalt/rtdm: introduce new interfaces to init task
  2021-03-10  0:57 [PATCH V2 1/2] cobalt/rtdm: introduce new interfaces to init task hongzha1
  2021-03-10  0:57 ` [PATCH 2/2] cobalt/rtdm: introduce new interfaces to init timer hongzha1
@ 2021-03-10  8:25 ` Jan Kiszka
  2021-03-10  9:04   ` Philippe Gerum
  1 sibling, 1 reply; 5+ messages in thread
From: Jan Kiszka @ 2021-03-10  8:25 UTC (permalink / raw)
  To: hongzha1, xenomai

On 10.03.21 01:57, hongzha1 via Xenomai wrote:
> Initialise and start a real-time task on specified cpu or current
> cpu.
> 
> Signed-off-by: hongzha1 <hongzhan.chen@intel.com>
> 
> diff --git a/include/cobalt/kernel/rtdm/driver.h b/include/cobalt/kernel/rtdm/driver.h
> index 733c49df8..42daaa5b2 100644
> --- a/include/cobalt/kernel/rtdm/driver.h
> +++ b/include/cobalt/kernel/rtdm/driver.h
> @@ -1024,6 +1024,20 @@ 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);
> +
> +static inline int rtdm_task_init_cpu(rtdm_task_t *task, const char *name,
> +		rtdm_task_proc_t task_proc, void *arg,
> +		int priority, nanosecs_rel_t period)

I think this was a typo of Philippe:

rtdm_task_init should be implemented as a wrapper around
rtdm_task_init_on_cpu. We don't need another call.

Jan

> +{
> +	int cpu = raw_smp_processor_id();
> +
> +	return rtdm_task_init_on_cpu(task, cpu, name, task_proc, arg,
> +			priority, period);
> +}
> +
>  int __rtdm_task_sleep(xnticks_t timeout, xntmode_t mode);
>  void rtdm_task_busy_sleep(nanosecs_rel_t delay);
>  
> diff --git a/kernel/cobalt/rtdm/drvlib.c b/kernel/cobalt/rtdm/drvlib.c
> index b914fa312..1c999362e 100644
> --- a/kernel/cobalt/rtdm/drvlib.c
> +++ b/kernel/cobalt/rtdm/drvlib.c
> @@ -157,6 +157,82 @@ 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;
> +
> +	if (!cpu_online(cpu))
> +		return -EINVAL;
> +
> +	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, &param);
> +	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
> 


-- 
Siemens AG, T RDA IOT
Corporate Competence Center Embedded Linux


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH V2 1/2] cobalt/rtdm: introduce new interfaces to init task
  2021-03-10  8:25 ` [PATCH V2 1/2] cobalt/rtdm: introduce new interfaces to init task Jan Kiszka
@ 2021-03-10  9:04   ` Philippe Gerum
  2021-03-11  7:08     ` Chen, Hongzhan
  0 siblings, 1 reply; 5+ messages in thread
From: Philippe Gerum @ 2021-03-10  9:04 UTC (permalink / raw)
  To: Jan Kiszka; +Cc: hongzha1, xenomai


Jan Kiszka via Xenomai <xenomai@xenomai.org> writes:

> On 10.03.21 01:57, hongzha1 via Xenomai wrote:
>> Initialise and start a real-time task on specified cpu or current
>> cpu.
>> 
>> Signed-off-by: hongzha1 <hongzhan.chen@intel.com>
>> 
>> diff --git a/include/cobalt/kernel/rtdm/driver.h b/include/cobalt/kernel/rtdm/driver.h
>> index 733c49df8..42daaa5b2 100644
>> --- a/include/cobalt/kernel/rtdm/driver.h
>> +++ b/include/cobalt/kernel/rtdm/driver.h
>> @@ -1024,6 +1024,20 @@ 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);
>> +
>> +static inline int rtdm_task_init_cpu(rtdm_task_t *task, const char *name,
>> +		rtdm_task_proc_t task_proc, void *arg,
>> +		int priority, nanosecs_rel_t period)
>
> I think this was a typo of Philippe:
>
> rtdm_task_init should be implemented as a wrapper around
> rtdm_task_init_on_cpu. We don't need another call.
>

Correct.

-- 
Philippe.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: [PATCH V2 1/2] cobalt/rtdm: introduce new interfaces to init task
  2021-03-10  9:04   ` Philippe Gerum
@ 2021-03-11  7:08     ` Chen, Hongzhan
  0 siblings, 0 replies; 5+ messages in thread
From: Chen, Hongzhan @ 2021-03-11  7:08 UTC (permalink / raw)
  To: Philippe Gerum, Jan Kiszka; +Cc: xenomai

                                                                             
>Jan Kiszka via Xenomai <xenomai@xenomai.org> writes:                                     
>                                                                                         
>> On 10.03.21 01:57, hongzha1 via Xenomai wrote:                                         
>>> Initialise and start a real-time task on specified cpu or current                     
>>> cpu.                                                                                  
>>>                                                                                       
>>> Signed-off-by: hongzha1 <hongzhan.chen@intel.com>                                     
>>>                                                                                       
>>> diff --git a/include/cobalt/kernel/rtdm/driver.h b/include/cobalt/kernel/rtdm/driver.h
>>> index 733c49df8..42daaa5b2 100644                                                     
>>> --- a/include/cobalt/kernel/rtdm/driver.h                                             
>>> +++ b/include/cobalt/kernel/rtdm/driver.h                                             
>>> @@ -1024,6 +1024,20 @@ 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);                                            
>>> +                                                                                     
>>> +static inline int rtdm_task_init_cpu(rtdm_task_t *task, const char *name,            
>>> +		rtdm_task_proc_t task_proc, void *arg,                                           
>>> +		int priority, nanosecs_rel_t period)                                             
>>                                                                                        
>> I think this was a typo of Philippe:                                                   
>>                                                                                        
>> rtdm_task_init should be implemented as a wrapper around                               
> rtdm_task_init_on_cpu. We don't need another call.  

I misunderstood something. Thanks for helping clarify it.                                   
>                                                                                        
>                                                                                         
>Correct.                 

New patches updated. Please review.
                                                                
>                                                                                         
>--                                                                                       
>Philippe.                                                                                


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-03-11  7:08 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-10  0:57 [PATCH V2 1/2] cobalt/rtdm: introduce new interfaces to init task hongzha1
2021-03-10  0:57 ` [PATCH 2/2] cobalt/rtdm: introduce new interfaces to init timer hongzha1
2021-03-10  8:25 ` [PATCH V2 1/2] cobalt/rtdm: introduce new interfaces to init task Jan Kiszka
2021-03-10  9:04   ` Philippe Gerum
2021-03-11  7:08     ` Chen, Hongzhan

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.