Skip to contentSkip to conversation

cobalt/rtdm: add new interface to init task on specified cpu

PATCH In review hongzha1 3 participants 9 messages Feb 20, 2021 – Mar 5, 2021

lore
Share & tools
lore

hongzha1

author
#0 lore raw

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
index 733c49df8..6cdace324 100644
@@ -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
author
#1 lore raw

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
index 6cdace324..6a431e7c5 100644
@@ -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
index 7452850b7..e6145b353 100644
@@ -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
author
#2 lore raw

PATCH 3/5 rtdm/testing: latmus: introduce latmus driver

In reply to hongzha1
include/rtdm/uapi/testing.h +63 -0
index f8207b8c7..b1723b9f8 100644
@@ -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
index 88c043c82..5478dfe97 100644
@@ -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
index 09b076348..cad4ad50d 100644
@@ -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
author
#3 lore raw

PATCH 4/5 drivers/gpio: core: introduce helper to find gpiochip

In reply to hongzha1

To find gpiochip for non-OF platforms like x86

include/cobalt/kernel/rtdm/gpio.h +3 -0
index 00055ec0a..1d1e67bf7 100644
@@ -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
index 600ef9789..7ab989e94 100644
@@ -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
author
#4 lore raw

PATCH 5/5 testsuite/latmus: introduce latmus app

In reply to hongzha1
configure.ac +1 -0
index abe538dbd..8416bc013 100644
@@ -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
index b1723b9f8..d7e2707e1 100644
@@ -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
index 4932f6d33..4baff2f19 100644
@@ -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
new file mode 100644
index 000000000..8eab3d740
@@ -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
#5 lore raw
In reply to hongzha1

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

include/cobalt/kernel/rtdm/driver.h +3 -0
index 733c49df8..6cdace324 100644
@@ -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
index b914fa312..7452850b7 100644
@@ -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, &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
#6 lore raw
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 cpu

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?

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

include/cobalt/kernel/rtdm/driver.h +3 -0
index 733c49df8..6cdace324 100644
@@ -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
index b914fa312..7452850b7 100644
@@ -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, &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
#7 lore raw
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 cpu

why 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_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

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.
#8 lore raw
In reply to hongzha1
Quoted 54 lines · hongzha1 via Xenomai <[email protected]> writes:

Initialise and start a real-time task on specified cpu

include/cobalt/kernel/rtdm/driver.h +3 -0
index 733c49df8..6cdace324 100644
@@ -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
index b914fa312..7452850b7 100644
@@ -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, &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;

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.