[Xenomai-git] Philippe Gerum : alchemy/task: allow calling rt_task_shadow() from a plain POSIX thread

2016-04-25 Thread git repository hosting
Module: xenomai-3
Branch: wip/dovetail
Commit: 9d5c34dbc526f79352dce2c3893b88657a3d3c4f
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=9d5c34dbc526f79352dce2c3893b88657a3d3c4f

Author: Philippe Gerum 
Date:   Thu Apr 21 10:01:56 2016 +0200

alchemy/task: allow calling rt_task_shadow() from a plain POSIX thread

The inline documentation was misleading, rt_task_shadow() could not be
called from regular pthreads until this change, but only from Xenomai
threads (i.e. mode-unrestricted vs thread-unrestricted).

---

 lib/alchemy/task.c |   59 +++-
 1 file changed, 31 insertions(+), 28 deletions(-)

diff --git a/lib/alchemy/task.c b/lib/alchemy/task.c
index 857496b..a6ca477 100644
--- a/lib/alchemy/task.c
+++ b/lib/alchemy/task.c
@@ -326,12 +326,12 @@ fail_syncinit:
 
 /**
  * @fn int rt_task_create(RT_TASK *task, const char *name, int stksize, int 
prio, int mode)
- * @brief Create a real-time task.
+ * @brief Create a task with Alchemy personality.
  *
- * This service creates a task with access to the full set of Xenomai
- * real-time services. If @a prio is non-zero, the new task belongs to
- * Xenomai's real-time FIFO scheduling class, aka SCHED_FIFO. If @a
- * prio is zero, the task belongs to the regular SCHED_OTHER class.
+ * This service creates a task with access to the full set of Alchemy
+ * services. If @a prio is non-zero, the new task belongs to Xenomai's
+ * real-time FIFO scheduling class, aka SCHED_FIFO. If @a prio is
+ * zero, the task belongs to the regular SCHED_OTHER class.
  *
  * Creating tasks with zero priority is useful for running non
  * real-time processes which may invoke blocking real-time services,
@@ -650,10 +650,9 @@ out:
  * @fn int rt_task_shadow(RT_TASK *task, const char *name, int prio, int mode)
  * @brief Turn caller into a real-time task.
  *
- * Extends the calling Linux task with Xenomai capabilities, with
- * access to the full set of Xenomai real-time services. This service
- * is typically used for turning the main() thread of an application
- * process into a Xenomai-enabled task.
+ * Set the calling thread personality to the Alchemy API, enabling the
+ * full set of Alchemy services. Upon success, the caller is no more a
+ * regular POSIX thread, but a Xenomai-extended thread.
  *
  * If @a prio is non-zero, the new task moves to Xenomai's real-time
  * FIFO scheduling class, aka SCHED_FIFO. If @a prio is zero, the task
@@ -664,9 +663,6 @@ out:
  * such as pending on a semaphore, reading from a message queue or a
  * buffer, and so on.
  *
- * Once shadowed with the Xenomai extension, the calling task returns
- * and resumes execution normally from the call site.
- *
  * @param task If non-NULL, the address of a task descriptor which can
  * be later used to identify uniquely the task, upon success of this
  * call. If NULL, no descriptor is returned.
@@ -702,16 +698,14 @@ out:
  * - -EEXIST is returned if the @a name is conflicting with an already
  * registered task.
  *
- * - -EBUSY is returned if the caller is already mapped to a Xenomai
- * task context.
- *
- * - -EPERM is returned if this service was called from an invalid
- * context.
+ * - -EBUSY is returned if the caller is not a regular POSIX thread.
  *
- * @apitags{pthread-only, switch-secondary}
+ * @apitags{pthread-only, switch-secondary, switch-primary}
  *
- * @sideeffect Over the Cobalt core, the caller always returns from
- * this service in primary mode.
+ * @sideeffect Over Cobalt, if the caller is a plain POSIX thread, it
+ * is turned into a Xenomai _shadow_ thread, with full access to all
+ * Cobalt services. The caller always returns from this service in
+ * primary mode.
  *
  * @note Tasks can be referred to from multiple processes which all
  * belong to the same Xenomai session.
@@ -739,12 +733,29 @@ int rt_task_shadow(RT_TASK *task, const char *name, int 
prio, int mode)
if (current && threadobj_get_magic(current))
return -EBUSY;
 
+   /*
+* Over Cobalt, the following call turns the current context
+* into a dual-kernel thread. Do this early, since this will
+* be required next for creating the TCB and running the
+* prologue code (i.e. real-time mutexes and monitors are
+* locked there).
+*/
+   self = pthread_self();
+   policy = prio ? SCHED_FIFO : SCHED_OTHER;
+   param_ex.sched_priority = prio;
+   ret = __bt(copperplate_renice_local_thread(self, policy, ¶m_ex));
+   if (ret)
+   goto out;
+
ret = create_tcb(&tcb, task, name, prio, mode);
if (ret)
goto out;
 
CANCEL_RESTORE(svc);
 
+   if (task)
+   task->thread = self;
+
ret = threadobj_shadow(&tcb->thobj, tcb->name);
if (ret)
goto undo;
@@ -754,14 +765,6 @@ int rt_task_shadow(RT_TASK *task, const char *name, int 
prio, int mode)
ret = task_prologue_2(tcb);
if 

[Xenomai-git] Philippe Gerum : cobalt/rtdm: allow setting the kernel device class of a driver

2016-04-25 Thread git repository hosting
Module: xenomai-3
Branch: next
Commit: d5303299657a16d94f971f73f1191202dd2eeb7e
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=d5303299657a16d94f971f73f1191202dd2eeb7e

Author: Philippe Gerum 
Date:   Sat Apr 23 15:05:43 2016 +0200

cobalt/rtdm: allow setting the kernel device class of a driver

It may be convenient to set the Linux device class for a particular
RTDM driver, either to provide a specific set of sysfs attributes for
the attached devices, or using a different hierarchy for the device
nodes (instead of /dev/rtdm).

The new rtdm_drv_set_sysclass() call allows this, provided the
non-default class is set before the first device referring to the
driver is registered by a call rtdm_dev_register().

---

 include/cobalt/kernel/rtdm/driver.h |5 +++
 kernel/cobalt/rtdm/device.c |   57 ---
 2 files changed, 58 insertions(+), 4 deletions(-)

diff --git a/include/cobalt/kernel/rtdm/driver.h 
b/include/cobalt/kernel/rtdm/driver.h
index 01601c3..7d62f13 100644
--- a/include/cobalt/kernel/rtdm/driver.h
+++ b/include/cobalt/kernel/rtdm/driver.h
@@ -225,6 +225,7 @@ struct rtdm_profile_info {
/** Reserved */
unsigned int magic;
struct module *owner;
+   struct class *kdev_class;
 };
 
 struct rtdm_driver;
@@ -314,8 +315,11 @@ struct rtdm_driver {
.version = (__version), \
.magic = ~RTDM_CLASS_MAGIC, \
.owner = THIS_MODULE,   \
+   .kdev_class = NULL, \
 }
 
+int rtdm_drv_set_sysclass(struct rtdm_driver *drv, struct class *cls);
+
 /**
  * @brief RTDM device
  *
@@ -368,6 +372,7 @@ struct rtdm_device {
};
dev_t rdev;
struct device *kdev;
+   struct class *kdev_class;
atomic_t refcount;
struct rtdm_fd_ops ops;
wait_queue_head_t putwq;
diff --git a/kernel/cobalt/rtdm/device.c b/kernel/cobalt/rtdm/device.c
index 660f61c..c760f31 100644
--- a/kernel/cobalt/rtdm/device.c
+++ b/kernel/cobalt/rtdm/device.c
@@ -359,6 +359,7 @@ static void unregister_driver(struct rtdm_driver *drv)
  */
 int rtdm_dev_register(struct rtdm_device *dev)
 {
+   struct class *kdev_class = rtdm_class;
struct device *kdev = NULL;
struct rtdm_driver *drv;
int ret, major, minor;
@@ -390,6 +391,9 @@ int rtdm_dev_register(struct rtdm_device *dev)
dev->ops.close = __rtdm_dev_close; /* Interpose on driver's handler. */
atomic_set(&dev->refcount, 0);
 
+   if (drv->profile_info.kdev_class)
+   kdev_class = drv->profile_info.kdev_class;
+
if (drv->device_flags & RTDM_NAMED_DEVICE) {
if (drv->device_flags & RTDM_FIXED_MINOR) {
minor = dev->minor;
@@ -419,7 +423,7 @@ int rtdm_dev_register(struct rtdm_device *dev)
goto fail;
 
rdev = MKDEV(major, minor);
-   kdev = device_create(rtdm_class, NULL, rdev,
+   kdev = device_create(kdev_class, NULL, rdev,
 dev, dev->label, minor);
if (IS_ERR(kdev)) {
xnregistry_remove(dev->named.handle);
@@ -443,7 +447,7 @@ int rtdm_dev_register(struct rtdm_device *dev)
}
 
rdev = MKDEV(0, minor);
-   kdev = device_create(rtdm_class, NULL, rdev,
+   kdev = device_create(kdev_class, NULL, rdev,
 dev, dev->name);
if (IS_ERR(kdev)) {
ret = PTR_ERR(kdev);
@@ -460,6 +464,7 @@ int rtdm_dev_register(struct rtdm_device *dev)
dev->rdev = rdev;
dev->kdev = kdev;
dev->magic = RTDM_DEVICE_MAGIC;
+   dev->kdev_class = kdev_class;
 
mutex_unlock(®ister_lock);
 
@@ -468,7 +473,7 @@ int rtdm_dev_register(struct rtdm_device *dev)
return 0;
 fail:
if (kdev)
-   device_destroy(rtdm_class, rdev);
+   device_destroy(kdev_class, rdev);
 
if (atomic_dec_and_test(&drv->refcount))
unregister_driver(drv);
@@ -517,7 +522,7 @@ void rtdm_dev_unregister(struct rtdm_device *dev)
__clear_bit(dev->minor, protocol_devices_minor_map);
}
 
-   device_destroy(rtdm_class, dev->rdev);
+   device_destroy(dev->kdev_class, dev->rdev);
 
unregister_driver(drv);
 
@@ -527,6 +532,50 @@ void rtdm_dev_unregister(struct rtdm_device *dev)
 }
 EXPORT_SYMBOL_GPL(rtdm_dev_unregister);
 
+/**
+ * @brief Set the kernel device class of a RTDM driver.
+ *
+ * Set the kernel device class assigned to the RTDM driver. By
+ * default, RTDM drivers belong to Linux's "rtdm" device class,
+ * creating a device node hierarchy rooted at /dev/rtdm, and sysfs
+ * nodes under /sys/class/rtdm.
+ *
+ * This call assigns a user-defined kernel 

[Xenomai-git] Philippe Gerum : cobalt/rtdm: expose wait_context API from the core threads

2016-04-25 Thread git repository hosting
Module: xenomai-3
Branch: wip/dovetail
Commit: eadcb6bf86096c303fa56b13e5a965af71cbe8eb
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=eadcb6bf86096c303fa56b13e5a965af71cbe8eb

Author: Philippe Gerum 
Date:   Mon Apr 25 11:47:21 2016 +0200

cobalt/rtdm: expose wait_context API from the core threads

---

 include/cobalt/kernel/rtdm/driver.h |   25 +++
 kernel/cobalt/rtdm/drvlib.c |   82 +++
 2 files changed, 107 insertions(+)

diff --git a/include/cobalt/kernel/rtdm/driver.h 
b/include/cobalt/kernel/rtdm/driver.h
index 7d62f13..edd92ee 100644
--- a/include/cobalt/kernel/rtdm/driver.h
+++ b/include/cobalt/kernel/rtdm/driver.h
@@ -1114,6 +1114,31 @@ static inline int __deprecated 
rtdm_task_sleep_until(nanosecs_abs_t wakeup_time)
__ret;  
\
})
 
+#define rtdm_wait_context  xnthread_wait_context
+
+static inline
+void rtdm_wait_complete(struct rtdm_wait_context *wc)
+{
+   xnthread_complete_wait(wc);
+}
+
+static inline
+int rtdm_wait_is_completed(struct rtdm_wait_context *wc)
+{
+   return xnthread_wait_complete_p(wc);
+}
+
+static inline void rtdm_wait_prepare(struct rtdm_wait_context *wc)
+{
+   xnthread_prepare_wait(wc);
+}
+
+static inline
+struct rtdm_wait_context *rtdm_wait_get_context(rtdm_task_t *task)
+{
+   return xnthread_get_wait_context(task);
+}
+
 #endif /* !DOXYGEN_CPP */
 
 /* --- event services --- */
diff --git a/kernel/cobalt/rtdm/drvlib.c b/kernel/cobalt/rtdm/drvlib.c
index cdec68d..ae55a4b 100644
--- a/kernel/cobalt/rtdm/drvlib.c
+++ b/kernel/cobalt/rtdm/drvlib.c
@@ -343,6 +343,88 @@ int rtdm_task_sleep_abs(nanosecs_abs_t wakeup_time, enum 
rtdm_timer_mode mode);
 int rtdm_task_busy_wait(bool condition, nanosecs_rel_t spin_ns,
nanosecs_rel_t sleep_ns);
 
+/**
+ * @brief Register wait context
+ *
+ * rtdm_wait_prepare() registers a wait context structure for the
+ * caller, which can be later retrieved by a call to
+ * rtdm_wait_get_context(). This call is normally issued before the
+ * current task blocks on a wait object, waiting for some (producer)
+ * code to wake it up. Arbitrary data can be exchanged between both
+ * sites via the wait context structure, which is allocated by the
+ * waiter (consumer) side.
+ *
+ * @a wc is the address of an anchor object which is commonly embedded
+ * into a larger structure with arbitrary contents, which needs to be
+ * shared between the consumer (waiter) and the producer for
+ * implementing the wait code.
+ *
+ * A typical implementation pattern for the wait side is:
+ *
+ * @code
+ * struct rtdm_waitqueue wq;
+ * struct some_wait_context {
+ *int input_value;
+ *int output_value;
+ *struct rtdm_wait_context wc;
+ * } wait_context;
+ *
+ * wait_context.input_value = 42;
+ * rtdm_wait_prepare(&wait_context);
+ * ret = rtdm_wait_condition(&wq, rtdm_wait_is_completed(&wait_context));
+ * if (ret)
+ * goto wait_failed;
+ * handle_event(wait_context.output_value);
+ * @endcode
+ *
+ * On the producer side, the implementation would look like:
+ *
+ * @code
+ * struct rtdm_waitqueue wq;
+ * struct some_wait_context {
+ *int input_value;
+ *int output_value;
+ *struct rtdm_wait_context wc;
+ * } *wait_context_ptr;
+ * struct rtdm_wait_context *wc;
+ * rtdm_task_t *task;
+ *
+ * rtdm_for_each_waiter(task, &wq) {
+ *wc = rtdm_wait_get_context(task);
+ *wait_context_ptr = container_of(wc, struct some_wait_context, wc);
+ *wait_context_ptr->output_value = 12;
+ * }
+ * rtdm_waitqueue_broadcast(&wq);
+ * @endcode
+ *
+ * @param wc Wait context to register.
+ */
+void rtdm_wait_prepare(struct rtdm_wait_context *wc);
+
+/**
+ * @brief Mark completion for a wait context
+ *
+ * rtdm_complete_wait() marks a wait context as completed, so that
+ * rtdm_wait_is_completed() returns true for such context.
+ *
+ * @param wc Wait context to complete.
+ */
+void rtdm_wait_complete(struct rtdm_wait_context *wc);
+
+/**
+ * @brief Test completion of a wait context
+ *
+ * rtdm_wait_is_completed() returns true if rtdm_complete_wait() was
+ * called for @a wc. The completion mark is reset each time
+ * rtdm_wait_prepare() is called for a wait context.
+ *
+ * @param wc Wait context to check for completion.
+ *
+ * @return non-zero/true if rtdm_wait_complete() was called for @a wc,
+ * zero otherwise.
+ */
+int rtdm_wait_is_completed(struct rtdm_wait_context *wc);
+
 #endif /* DOXYGEN_CPP */
 
 int __rtdm_task_sleep(xnticks_t timeout, xntmode_t mode)


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : cobalt/rtdm: expose wait_context API from the core threads

2016-04-25 Thread git repository hosting
Module: xenomai-3
Branch: next
Commit: eadcb6bf86096c303fa56b13e5a965af71cbe8eb
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=eadcb6bf86096c303fa56b13e5a965af71cbe8eb

Author: Philippe Gerum 
Date:   Mon Apr 25 11:47:21 2016 +0200

cobalt/rtdm: expose wait_context API from the core threads

---

 include/cobalt/kernel/rtdm/driver.h |   25 +++
 kernel/cobalt/rtdm/drvlib.c |   82 +++
 2 files changed, 107 insertions(+)

diff --git a/include/cobalt/kernel/rtdm/driver.h 
b/include/cobalt/kernel/rtdm/driver.h
index 7d62f13..edd92ee 100644
--- a/include/cobalt/kernel/rtdm/driver.h
+++ b/include/cobalt/kernel/rtdm/driver.h
@@ -1114,6 +1114,31 @@ static inline int __deprecated 
rtdm_task_sleep_until(nanosecs_abs_t wakeup_time)
__ret;  
\
})
 
+#define rtdm_wait_context  xnthread_wait_context
+
+static inline
+void rtdm_wait_complete(struct rtdm_wait_context *wc)
+{
+   xnthread_complete_wait(wc);
+}
+
+static inline
+int rtdm_wait_is_completed(struct rtdm_wait_context *wc)
+{
+   return xnthread_wait_complete_p(wc);
+}
+
+static inline void rtdm_wait_prepare(struct rtdm_wait_context *wc)
+{
+   xnthread_prepare_wait(wc);
+}
+
+static inline
+struct rtdm_wait_context *rtdm_wait_get_context(rtdm_task_t *task)
+{
+   return xnthread_get_wait_context(task);
+}
+
 #endif /* !DOXYGEN_CPP */
 
 /* --- event services --- */
diff --git a/kernel/cobalt/rtdm/drvlib.c b/kernel/cobalt/rtdm/drvlib.c
index cdec68d..ae55a4b 100644
--- a/kernel/cobalt/rtdm/drvlib.c
+++ b/kernel/cobalt/rtdm/drvlib.c
@@ -343,6 +343,88 @@ int rtdm_task_sleep_abs(nanosecs_abs_t wakeup_time, enum 
rtdm_timer_mode mode);
 int rtdm_task_busy_wait(bool condition, nanosecs_rel_t spin_ns,
nanosecs_rel_t sleep_ns);
 
+/**
+ * @brief Register wait context
+ *
+ * rtdm_wait_prepare() registers a wait context structure for the
+ * caller, which can be later retrieved by a call to
+ * rtdm_wait_get_context(). This call is normally issued before the
+ * current task blocks on a wait object, waiting for some (producer)
+ * code to wake it up. Arbitrary data can be exchanged between both
+ * sites via the wait context structure, which is allocated by the
+ * waiter (consumer) side.
+ *
+ * @a wc is the address of an anchor object which is commonly embedded
+ * into a larger structure with arbitrary contents, which needs to be
+ * shared between the consumer (waiter) and the producer for
+ * implementing the wait code.
+ *
+ * A typical implementation pattern for the wait side is:
+ *
+ * @code
+ * struct rtdm_waitqueue wq;
+ * struct some_wait_context {
+ *int input_value;
+ *int output_value;
+ *struct rtdm_wait_context wc;
+ * } wait_context;
+ *
+ * wait_context.input_value = 42;
+ * rtdm_wait_prepare(&wait_context);
+ * ret = rtdm_wait_condition(&wq, rtdm_wait_is_completed(&wait_context));
+ * if (ret)
+ * goto wait_failed;
+ * handle_event(wait_context.output_value);
+ * @endcode
+ *
+ * On the producer side, the implementation would look like:
+ *
+ * @code
+ * struct rtdm_waitqueue wq;
+ * struct some_wait_context {
+ *int input_value;
+ *int output_value;
+ *struct rtdm_wait_context wc;
+ * } *wait_context_ptr;
+ * struct rtdm_wait_context *wc;
+ * rtdm_task_t *task;
+ *
+ * rtdm_for_each_waiter(task, &wq) {
+ *wc = rtdm_wait_get_context(task);
+ *wait_context_ptr = container_of(wc, struct some_wait_context, wc);
+ *wait_context_ptr->output_value = 12;
+ * }
+ * rtdm_waitqueue_broadcast(&wq);
+ * @endcode
+ *
+ * @param wc Wait context to register.
+ */
+void rtdm_wait_prepare(struct rtdm_wait_context *wc);
+
+/**
+ * @brief Mark completion for a wait context
+ *
+ * rtdm_complete_wait() marks a wait context as completed, so that
+ * rtdm_wait_is_completed() returns true for such context.
+ *
+ * @param wc Wait context to complete.
+ */
+void rtdm_wait_complete(struct rtdm_wait_context *wc);
+
+/**
+ * @brief Test completion of a wait context
+ *
+ * rtdm_wait_is_completed() returns true if rtdm_complete_wait() was
+ * called for @a wc. The completion mark is reset each time
+ * rtdm_wait_prepare() is called for a wait context.
+ *
+ * @param wc Wait context to check for completion.
+ *
+ * @return non-zero/true if rtdm_wait_complete() was called for @a wc,
+ * zero otherwise.
+ */
+int rtdm_wait_is_completed(struct rtdm_wait_context *wc);
+
 #endif /* DOXYGEN_CPP */
 
 int __rtdm_task_sleep(xnticks_t timeout, xntmode_t mode)


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : cobalt/rtdm: allow setting the kernel device class of a driver

2016-04-25 Thread git repository hosting
Module: xenomai-3
Branch: wip/dovetail
Commit: d5303299657a16d94f971f73f1191202dd2eeb7e
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=d5303299657a16d94f971f73f1191202dd2eeb7e

Author: Philippe Gerum 
Date:   Sat Apr 23 15:05:43 2016 +0200

cobalt/rtdm: allow setting the kernel device class of a driver

It may be convenient to set the Linux device class for a particular
RTDM driver, either to provide a specific set of sysfs attributes for
the attached devices, or using a different hierarchy for the device
nodes (instead of /dev/rtdm).

The new rtdm_drv_set_sysclass() call allows this, provided the
non-default class is set before the first device referring to the
driver is registered by a call rtdm_dev_register().

---

 include/cobalt/kernel/rtdm/driver.h |5 +++
 kernel/cobalt/rtdm/device.c |   57 ---
 2 files changed, 58 insertions(+), 4 deletions(-)

diff --git a/include/cobalt/kernel/rtdm/driver.h 
b/include/cobalt/kernel/rtdm/driver.h
index 01601c3..7d62f13 100644
--- a/include/cobalt/kernel/rtdm/driver.h
+++ b/include/cobalt/kernel/rtdm/driver.h
@@ -225,6 +225,7 @@ struct rtdm_profile_info {
/** Reserved */
unsigned int magic;
struct module *owner;
+   struct class *kdev_class;
 };
 
 struct rtdm_driver;
@@ -314,8 +315,11 @@ struct rtdm_driver {
.version = (__version), \
.magic = ~RTDM_CLASS_MAGIC, \
.owner = THIS_MODULE,   \
+   .kdev_class = NULL, \
 }
 
+int rtdm_drv_set_sysclass(struct rtdm_driver *drv, struct class *cls);
+
 /**
  * @brief RTDM device
  *
@@ -368,6 +372,7 @@ struct rtdm_device {
};
dev_t rdev;
struct device *kdev;
+   struct class *kdev_class;
atomic_t refcount;
struct rtdm_fd_ops ops;
wait_queue_head_t putwq;
diff --git a/kernel/cobalt/rtdm/device.c b/kernel/cobalt/rtdm/device.c
index 660f61c..c760f31 100644
--- a/kernel/cobalt/rtdm/device.c
+++ b/kernel/cobalt/rtdm/device.c
@@ -359,6 +359,7 @@ static void unregister_driver(struct rtdm_driver *drv)
  */
 int rtdm_dev_register(struct rtdm_device *dev)
 {
+   struct class *kdev_class = rtdm_class;
struct device *kdev = NULL;
struct rtdm_driver *drv;
int ret, major, minor;
@@ -390,6 +391,9 @@ int rtdm_dev_register(struct rtdm_device *dev)
dev->ops.close = __rtdm_dev_close; /* Interpose on driver's handler. */
atomic_set(&dev->refcount, 0);
 
+   if (drv->profile_info.kdev_class)
+   kdev_class = drv->profile_info.kdev_class;
+
if (drv->device_flags & RTDM_NAMED_DEVICE) {
if (drv->device_flags & RTDM_FIXED_MINOR) {
minor = dev->minor;
@@ -419,7 +423,7 @@ int rtdm_dev_register(struct rtdm_device *dev)
goto fail;
 
rdev = MKDEV(major, minor);
-   kdev = device_create(rtdm_class, NULL, rdev,
+   kdev = device_create(kdev_class, NULL, rdev,
 dev, dev->label, minor);
if (IS_ERR(kdev)) {
xnregistry_remove(dev->named.handle);
@@ -443,7 +447,7 @@ int rtdm_dev_register(struct rtdm_device *dev)
}
 
rdev = MKDEV(0, minor);
-   kdev = device_create(rtdm_class, NULL, rdev,
+   kdev = device_create(kdev_class, NULL, rdev,
 dev, dev->name);
if (IS_ERR(kdev)) {
ret = PTR_ERR(kdev);
@@ -460,6 +464,7 @@ int rtdm_dev_register(struct rtdm_device *dev)
dev->rdev = rdev;
dev->kdev = kdev;
dev->magic = RTDM_DEVICE_MAGIC;
+   dev->kdev_class = kdev_class;
 
mutex_unlock(®ister_lock);
 
@@ -468,7 +473,7 @@ int rtdm_dev_register(struct rtdm_device *dev)
return 0;
 fail:
if (kdev)
-   device_destroy(rtdm_class, rdev);
+   device_destroy(kdev_class, rdev);
 
if (atomic_dec_and_test(&drv->refcount))
unregister_driver(drv);
@@ -517,7 +522,7 @@ void rtdm_dev_unregister(struct rtdm_device *dev)
__clear_bit(dev->minor, protocol_devices_minor_map);
}
 
-   device_destroy(rtdm_class, dev->rdev);
+   device_destroy(dev->kdev_class, dev->rdev);
 
unregister_driver(drv);
 
@@ -527,6 +532,50 @@ void rtdm_dev_unregister(struct rtdm_device *dev)
 }
 EXPORT_SYMBOL_GPL(rtdm_dev_unregister);
 
+/**
+ * @brief Set the kernel device class of a RTDM driver.
+ *
+ * Set the kernel device class assigned to the RTDM driver. By
+ * default, RTDM drivers belong to Linux's "rtdm" device class,
+ * creating a device node hierarchy rooted at /dev/rtdm, and sysfs
+ * nodes under /sys/class/rtdm.
+ *
+ * This call assigns a user-defined

[Xenomai-git] Philippe Gerum : boilerplate/init: track automatic bootstrap mode in --dump-config

2016-04-25 Thread git repository hosting
Module: xenomai-3
Branch: stable-3.0.x
Commit: b4c28e9bb62bb8f4f2617e2bea8a816c322a9615
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=b4c28e9bb62bb8f4f2617e2bea8a816c322a9615

Author: Philippe Gerum 
Date:   Mon Apr 25 15:09:17 2016 +0200

boilerplate/init: track automatic bootstrap mode in --dump-config

Automatic bootstrapping (or misusage of manual bootstrap mode) is a
frequent source of issues among C++ applications with non-trivial
static constructors. Have --dump-config display the bootstrap mode for
the executable to make investigation easier.

---

 include/xenomai/init.h   |2 ++
 lib/boilerplate/init/bootstrap.c |2 ++
 lib/boilerplate/setup.c  |3 +++
 3 files changed, 7 insertions(+)

diff --git a/include/xenomai/init.h b/include/xenomai/init.h
index 1ec1d43..9adc90d 100644
--- a/include/xenomai/init.h
+++ b/include/xenomai/init.h
@@ -37,6 +37,8 @@ void application_version(void);
 
 extern const char *xenomai_version_string;
 
+extern const int xenomai_auto_bootstrap;
+  
 #ifdef __cplusplus
 }
 #endif
diff --git a/lib/boilerplate/init/bootstrap.c b/lib/boilerplate/init/bootstrap.c
index cee6843..119b405 100644
--- a/lib/boilerplate/init/bootstrap.c
+++ b/lib/boilerplate/init/bootstrap.c
@@ -26,6 +26,8 @@ static int early_argc;
 
 static char *const *early_argv;
 
+const int xenomai_auto_bootstrap = 1;
+
 int __real_main(int argc, char *const argv[]);
 
 int __wrap_main(int argc, char *const argv[])
diff --git a/lib/boilerplate/setup.c b/lib/boilerplate/setup.c
index 7a9334d..dbeb5e1 100644
--- a/lib/boilerplate/setup.c
+++ b/lib/boilerplate/setup.c
@@ -46,6 +46,8 @@ pid_t __node_id = 0;
 
 int __config_done = 0;
 
+const int __weak xenomai_auto_bootstrap = 0;
+
 static int init_done;
 
 static DEFINE_PRIVATE_LIST(setup_list);
@@ -143,6 +145,7 @@ static inline void dump_configuration(void)
puts(config_strings[n]);
 
printf("PTHREAD_STACK_DEFAULT=%d\n", PTHREAD_STACK_DEFAULT);
+   printf("AUTOMATIC_BOOTSTRAP=%d\n", xenomai_auto_bootstrap);
 }
 
 static int collect_cpu_affinity(const char *cpu_list)


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : testsuite/smokey: include errno dependency explicitly

2016-05-01 Thread git repository hosting
Module: xenomai-3
Branch: stable-3.0.x
Commit: 2acd3866d33dfc58a85b9015b124aafefc1e1c81
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=2acd3866d33dfc58a85b9015b124aafefc1e1c81

Author: Philippe Gerum 
Date:   Sat Apr 30 19:03:03 2016 +0200

testsuite/smokey: include errno dependency explicitly

---

 testsuite/smokey/main.c |1 +
 1 file changed, 1 insertion(+)

diff --git a/testsuite/smokey/main.c b/testsuite/smokey/main.c
index 02ccc83..12321df 100644
--- a/testsuite/smokey/main.c
+++ b/testsuite/smokey/main.c
@@ -17,6 +17,7 @@
  */
 #include 
 #include 
+#include 
 #include 
 
 int main(int argc, char *const argv[])


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : cobalt/rtdm: allow device paths with multiple components

2016-05-01 Thread git repository hosting
Module: xenomai-3
Branch: stable-3.0.x
Commit: 43c97bff6164cbab2448cf362dd22ab6ad6f85c6
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=43c97bff6164cbab2448cf362dd22ab6ad6f85c6

Author: Philippe Gerum 
Date:   Sat Apr 30 09:40:10 2016 +0200

cobalt/rtdm: allow device paths with multiple components

---

 kernel/cobalt/rtdm/device.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/cobalt/rtdm/device.c b/kernel/cobalt/rtdm/device.c
index c760f31..46b7965 100644
--- a/kernel/cobalt/rtdm/device.c
+++ b/kernel/cobalt/rtdm/device.c
@@ -424,7 +424,7 @@ int rtdm_dev_register(struct rtdm_device *dev)
 
rdev = MKDEV(major, minor);
kdev = device_create(kdev_class, NULL, rdev,
-dev, dev->label, minor);
+dev, kbasename(dev->label), minor);
if (IS_ERR(kdev)) {
xnregistry_remove(dev->named.handle);
ret = PTR_ERR(kdev);


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : alchemy/queue: allow zero-size message with rt_queue_write()

2016-05-01 Thread git repository hosting
Module: xenomai-3
Branch: stable-3.0.x
Commit: bbc4c122c84b9be558809915190d04bb3b56f07e
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=bbc4c122c84b9be558809915190d04bb3b56f07e

Author: Philippe Gerum 
Date:   Sat Apr 30 17:41:18 2016 +0200

alchemy/queue: allow zero-size message with rt_queue_write()

---

 lib/alchemy/queue.c |8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/lib/alchemy/queue.c b/lib/alchemy/queue.c
index 9c88018..3a45257 100644
--- a/lib/alchemy/queue.c
+++ b/lib/alchemy/queue.c
@@ -630,10 +630,7 @@ int rt_queue_write(RT_QUEUE *queue,
if (mode & ~(Q_URGENT|Q_BROADCAST))
return -EINVAL;
 
-   if (size == 0)
-   return 0;
-
-   if (buf == NULL)
+   if (buf == NULL && size > 0)
return -EINVAL;
 
CANCEL_DEFER(svc);
@@ -683,7 +680,8 @@ enqueue:
 
msg->size = size;
msg->refcount = 0;
-   memcpy(msg + 1, buf, size);
+   if (size > 0)
+   memcpy(msg + 1, buf, size);
 
ret = 0;  /* # of tasks unblocked. */
if (nwaiters == 0) {


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : alchemy/queue: fix calculation of metadata overhead

2016-05-01 Thread git repository hosting
Module: xenomai-3
Branch: stable-3.0.x
Commit: cf20c8bc9581d3c1b01af5032d0932d3f5203eed
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=cf20c8bc9581d3c1b01af5032d0932d3f5203eed

Author: Philippe Gerum 
Date:   Sat Apr 30 07:25:23 2016 +0200

alchemy/queue: fix calculation of metadata overhead

---

 lib/alchemy/queue.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/alchemy/queue.c b/lib/alchemy/queue.c
index 891cfd1..9c88018 100644
--- a/lib/alchemy/queue.c
+++ b/lib/alchemy/queue.c
@@ -232,7 +232,7 @@ int rt_queue_create(RT_QUEUE *queue, const char *name,
 */
if (qlimit == Q_UNLIMITED)
ret = heapobj_init(&qcb->hobj, qcb->name,
-  poolsize + (poolsize / 5));
+  poolsize + (poolsize * 5 / 100));
else
ret = heapobj_init_array(&qcb->hobj, qcb->name,
 (poolsize / qlimit) *


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : cobalt/registry: allow slash in keys without /proc node

2016-05-01 Thread git repository hosting
Module: xenomai-3
Branch: stable-3.0.x
Commit: 46d8f79166b067ceade71f332bbf4d1414f4bffd
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=46d8f79166b067ceade71f332bbf4d1414f4bffd

Author: Philippe Gerum 
Date:   Sat Apr 30 15:06:02 2016 +0200

cobalt/registry: allow slash in keys without /proc node

---

 kernel/cobalt/registry.c |   12 
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/kernel/cobalt/registry.c b/kernel/cobalt/registry.c
index 9d14863..ed8a37f 100644
--- a/kernel/cobalt/registry.c
+++ b/kernel/cobalt/registry.c
@@ -595,7 +595,8 @@ static inline int registry_wakeup_sleepers(const char *key)
  * that such key is stored into the registered object, it will *not*
  * be copied but only kept by reference in the registry. Pass an empty
  * or NULL string if the object shall only occupy a registry slot for
- * handle-based lookups.
+ * handle-based lookups. The slash character is not accepted in @a key
+ * if @a pnode is non-NULL.
  *
  * @param objaddr An opaque pointer to the object to index by @a
  * key.
@@ -613,8 +614,10 @@ static inline int registry_wakeup_sleepers(const char *key)
  *
  * @return 0 is returned upon success. Otherwise:
  *
- * - -EINVAL is returned if @a objaddr is NULL, or if @a key is
- * non-NULL and contains an invalid '/' character.
+ * - -EINVAL is returned if @a objaddr is NULL.
+ *
+ * - -EINVAL if @a pnode is non-NULL, and @a key points to a valid
+ * string containing a '/' character.
  *
  * - -ENOMEM is returned if the system fails to get enough dynamic
  * memory from the global real-time heap in order to register the
@@ -631,7 +634,8 @@ int xnregistry_enter(const char *key, void *objaddr,
spl_t s;
int ret;
 
-   if (objaddr == NULL || (key != NULL && strchr(key, '/')))
+   if (objaddr == NULL ||
+   (pnode != NULL && key != NULL && strchr(key, '/')))
return -EINVAL;
 
xnlock_get_irqsave(&nklock, s);


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : cobalt/rtdm: reinit driver magic after unregistration

2016-05-03 Thread git repository hosting
Module: xenomai-3
Branch: stable-3.0.x
Commit: 56dd2653e12e2c1f899f3f4178f238e3993deeba
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=56dd2653e12e2c1f899f3f4178f238e3993deeba

Author: Philippe Gerum 
Date:   Tue May  3 10:06:11 2016 +0200

cobalt/rtdm: reinit driver magic after unregistration

Failing to do so would prevent the driver to be properly registered
again.

---

 kernel/cobalt/rtdm/device.c |4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/kernel/cobalt/rtdm/device.c b/kernel/cobalt/rtdm/device.c
index 46b7965..aa62169 100644
--- a/kernel/cobalt/rtdm/device.c
+++ b/kernel/cobalt/rtdm/device.c
@@ -325,7 +325,9 @@ static void unregister_driver(struct rtdm_driver *drv)
XENO_BUG_ON(COBALT, drv->profile_info.magic != RTDM_CLASS_MAGIC);
 
cobalt_remove_state_chain(&drv->nb_statechange);
-   
+
+   drv->profile_info.magic = ~RTDM_CLASS_MAGIC;
+
if (drv->device_flags & RTDM_NAMED_DEVICE) {
cdev_del(&drv->named.cdev);
unregister_chrdev_region(MKDEV(drv->named.major, 0),


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : cobalt/rtdm: zero-init the private context area

2016-05-03 Thread git repository hosting
Module: xenomai-3
Branch: stable-3.0.x
Commit: 031888d587b1b471f02ef73ad2436037dff737a3
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=031888d587b1b471f02ef73ad2436037dff737a3

Author: Philippe Gerum 
Date:   Tue May  3 12:16:29 2016 +0200

cobalt/rtdm: zero-init the private context area

---

 include/cobalt/kernel/rtdm/driver.h |9 -
 kernel/cobalt/rtdm/core.c   |2 +-
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/include/cobalt/kernel/rtdm/driver.h 
b/include/cobalt/kernel/rtdm/driver.h
index edd92ee..1354d9a 100644
--- a/include/cobalt/kernel/rtdm/driver.h
+++ b/include/cobalt/kernel/rtdm/driver.h
@@ -258,7 +258,14 @@ struct rtdm_driver {
 * @anchor rtdm_driver_flags
 */
int device_flags;
-   /** Size of driver defined appendix to struct rtdm_dev_context */
+   /**
+* Size of the private memory area the core should
+* automatically allocate for each open file descriptor, which
+* is usable for storing the context data associated to each
+* connection. The allocated memory is zero-initialized. The
+* start of this area can be retrieved by a call to
+* rtdm_fd_to_private().
+*/
size_t context_size;
/** Protocol device identification: protocol family (PF_xxx) */
int protocol_family;
diff --git a/kernel/cobalt/rtdm/core.c b/kernel/cobalt/rtdm/core.c
index 0f68e77..05f273f 100644
--- a/kernel/cobalt/rtdm/core.c
+++ b/kernel/cobalt/rtdm/core.c
@@ -86,7 +86,7 @@ static int create_instance(int ufd, struct rtdm_device *dev,
atomic_read(&dev->refcount) > 1)
return -EBUSY;
 
-   context = kmalloc(sizeof(struct rtdm_dev_context) +
+   context = kzalloc(sizeof(struct rtdm_dev_context) +
  drv->context_size, GFP_KERNEL);
if (unlikely(context == NULL))
return -ENOMEM;


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Jan Kiszka : cobalt/kernel: Introduce __SCHED_CURRENT policy to setschedparam_ex

2016-05-06 Thread git repository hosting
Module: xenomai-jki
Branch: for-forge
Commit: 2e4c540c4eb71eea6eae195d13f8e0df80aba31b
URL:
http://git.xenomai.org/?p=xenomai-jki.git;a=commit;h=2e4c540c4eb71eea6eae195d13f8e0df80aba31b

Author: Jan Kiszka 
Date:   Tue Mar  8 14:41:28 2016 +0100

cobalt/kernel: Introduce __SCHED_CURRENT policy to setschedparam_ex

Define the internal scheduling policy "current": it shall refer to the
target thread's current scheduling policy. This will allow to model
pthread_setschedprio on top of pthread_setschedparam_ex with only a
single syscall.

Signed-off-by: Jan Kiszka 

---

 include/cobalt/uapi/sched.h|3 +++
 kernel/cobalt/posix/thread.c   |   10 ++
 kernel/cobalt/trace/cobalt-posix.h |3 ++-
 3 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/include/cobalt/uapi/sched.h b/include/cobalt/uapi/sched.h
index b672095..2a1df44 100644
--- a/include/cobalt/uapi/sched.h
+++ b/include/cobalt/uapi/sched.h
@@ -21,6 +21,9 @@
 #define SCHED_COBALT   42
 #define SCHED_WEAK 43
 
+/* for internal use */
+#define __SCHED_CURRENT44
+
 #ifndef SCHED_SPORADIC
 #define SCHED_SPORADIC 10
 #define sched_ss_low_priority  sched_u.ss.__sched_low_priority
diff --git a/kernel/cobalt/posix/thread.c b/kernel/cobalt/posix/thread.c
index d87edb1..217b81b 100644
--- a/kernel/cobalt/posix/thread.c
+++ b/kernel/cobalt/posix/thread.c
@@ -242,6 +242,7 @@ struct xnthread_personality *cobalt_thread_finalize(struct 
xnthread *zombie)
 int __cobalt_thread_setschedparam_ex(struct cobalt_thread *thread, int policy,
 const struct sched_param_ex *param_ex)
 {
+   struct xnthread *base_thread = &thread->threadbase;
struct xnsched_class *sched_class;
union xnsched_policy_param param;
xnticks_t tslice;
@@ -256,6 +257,15 @@ int __cobalt_thread_setschedparam_ex(struct cobalt_thread 
*thread, int policy,
goto out;
}
 
+   if (policy == __SCHED_CURRENT) {
+   policy = base_thread->base_class->policy;
+   if (xnthread_base_priority(base_thread) == 0)
+   policy = SCHED_NORMAL;
+   else if (base_thread->base_class == &xnsched_class_rt &&
+xnthread_test_state(base_thread, XNRRB))
+   policy = SCHED_RR;
+   }
+
tslice = thread->threadbase.rrperiod;
sched_class = cobalt_sched_policy_param(¶m, policy,
param_ex, &tslice);
diff --git a/kernel/cobalt/trace/cobalt-posix.h 
b/kernel/cobalt/trace/cobalt-posix.h
index 92f7245..75673d7 100644
--- a/kernel/cobalt/trace/cobalt-posix.h
+++ b/kernel/cobalt/trace/cobalt-posix.h
@@ -90,7 +90,8 @@ DECLARE_EVENT_CLASS(syscall_exit,
 {SCHED_QUOTA, "quota"},\
 {SCHED_SPORADIC, "sporadic"},  \
 {SCHED_COBALT, "cobalt"},  \
-{SCHED_WEAK, "weak"})
+{SCHED_WEAK, "weak"},  \
+{__SCHED_CURRENT, ""})
 
 #define cobalt_print_sched_params(__policy, __p_ex)\
 ({ \


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Jan Kiszka : boilerplate: Allow for enabling Xenomai only in shared libs

2016-05-06 Thread git repository hosting
Module: xenomai-jki
Branch: for-forge
Commit: ee76becdba6faa3e140f3f9a2c98a783bd8515e4
URL:
http://git.xenomai.org/?p=xenomai-jki.git;a=commit;h=ee76becdba6faa3e140f3f9a2c98a783bd8515e4

Author: Jan Kiszka 
Date:   Fri Feb  5 17:33:18 2016 +0100

boilerplate: Allow for enabling Xenomai only in shared libs

Normally, one builds shared libraries with Xenomai awareness by adding
--no-auto-init to xeno-config. This drops bootstrap.o from the linking
steps because - normally - the main application performs the
initialization.

However, if the main application is Xenomai-free and only dlopen() would
pull in Xenomai services via a shared library, we face two problems:

- bootstrap.o is not built with position-independence support

- libboilerplate contains __real_main that expects the main symbol which
  cannot be found from a shared library

This patch solves both issues.

Signed-off-by: Jan Kiszka 

---

 lib/boilerplate/init/Makefile.am |1 +
 lib/boilerplate/wrappers.c   |5 -
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/lib/boilerplate/init/Makefile.am b/lib/boilerplate/init/Makefile.am
index 7a58f54..8c09e28 100644
--- a/lib/boilerplate/init/Makefile.am
+++ b/lib/boilerplate/init/Makefile.am
@@ -4,6 +4,7 @@ libbootstrap_a_SOURCES = bootstrap.c
 
 libbootstrap_a_CPPFLAGS =  \
@XENO_USER_CFLAGS@  \
+   -fPIC   \
-I$(top_srcdir)/include \
-I$(top_srcdir)/lib
 
diff --git a/lib/boilerplate/wrappers.c b/lib/boilerplate/wrappers.c
index 9d2490c..db8d5f7 100644
--- a/lib/boilerplate/wrappers.c
+++ b/lib/boilerplate/wrappers.c
@@ -17,7 +17,10 @@
  */
 #include 
 
-int main(int argc, char *const argv[]);
+__weak int main(int argc, char *const argv[])
+{
+   return 0;
+}
 
 int __real_main(int argc, char *const argv[]);
 


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Jan Kiszka : lib/cobalt: Wrap pthread_setschedprio for proper real-time support

2016-05-06 Thread git repository hosting
Module: xenomai-jki
Branch: for-forge
Commit: cada7dad232bdb7cb78dcca9815abbd0f9b19a39
URL:
http://git.xenomai.org/?p=xenomai-jki.git;a=commit;h=cada7dad232bdb7cb78dcca9815abbd0f9b19a39

Author: Jan Kiszka 
Date:   Tue Mar  8 14:46:59 2016 +0100

lib/cobalt: Wrap pthread_setschedprio for proper real-time support

Implement pthread_setschedprio on top of pthread_setschedparam_ex with
the help of the new __SCHED_CURRENT policy. This ensures that prio
changes are directly applied to the real-time core, and that with just
a single syscall.

Signed-off-by: Jan Kiszka 

---

 include/cobalt/pthread.h   |2 ++
 lib/cobalt/cobalt.wrappers |1 +
 lib/cobalt/thread.c|9 +
 lib/cobalt/wrappers.c  |6 ++
 4 files changed, 18 insertions(+)

diff --git a/include/cobalt/pthread.h b/include/cobalt/pthread.h
index f1b1c8a..3e9bd47 100644
--- a/include/cobalt/pthread.h
+++ b/include/cobalt/pthread.h
@@ -53,6 +53,8 @@ COBALT_DECL(int, pthread_setschedparam(pthread_t thread,
   int policy,
   const struct sched_param *param));
 
+COBALT_DECL(int, pthread_setschedprio(pthread_t thread, int prio));
+
 COBALT_DECL(int, pthread_mutex_init(pthread_mutex_t *mutex,
const pthread_mutexattr_t *attr));
 
diff --git a/lib/cobalt/cobalt.wrappers b/lib/cobalt/cobalt.wrappers
index 75f29d6..19153ae 100644
--- a/lib/cobalt/cobalt.wrappers
+++ b/lib/cobalt/cobalt.wrappers
@@ -2,6 +2,7 @@
 --wrap pthread_create
 --wrap pthread_setschedparam
 --wrap pthread_getschedparam
+--wrap pthread_setschedprio
 --wrap pthread_yield
 --wrap sched_yield
 --wrap sched_get_priority_min
diff --git a/lib/cobalt/thread.c b/lib/cobalt/thread.c
index 908516f..62ca0a0 100644
--- a/lib/cobalt/thread.c
+++ b/lib/cobalt/thread.c
@@ -650,6 +650,15 @@ int pthread_setschedparam_ex(pthread_t thread,
return ret;
 }
 
+COBALT_IMPL(int, pthread_setschedprio, (pthread_t thread, int prio))
+{
+   struct sched_param_ex param_ex = {
+   .sched_priority = prio,
+   };
+
+   return pthread_setschedparam_ex(thread, __SCHED_CURRENT, ¶m_ex);
+}
+
 /**
  * Get the scheduling policy and parameters of the specified thread.
  *
diff --git a/lib/cobalt/wrappers.c b/lib/cobalt/wrappers.c
index 09c74e5..1f1664e 100644
--- a/lib/cobalt/wrappers.c
+++ b/lib/cobalt/wrappers.c
@@ -60,6 +60,12 @@ int __real_pthread_getschedparam(pthread_t thread,
 }
 
 __weak
+int __real_pthread_setschedprio(pthread_t thread, int prio)
+{
+   return pthread_setschedprio(thread, prio);
+}
+
+__weak
 int __real_sched_yield(void)
 {
return sched_yield();


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Jan Kiszka : testsuite/smokey: Add test case for setschedparam & Co,

2016-05-06 Thread git repository hosting
Module: xenomai-jki
Branch: for-forge
Commit: dcd6af76837c1afa2941729919337b932b42bd13
URL:
http://git.xenomai.org/?p=xenomai-jki.git;a=commit;h=dcd6af76837c1afa2941729919337b932b42bd13

Author: Jan Kiszka 
Date:   Mon Feb 29 16:54:26 2016 +0100

testsuite/smokey: Add test case for setschedparam & Co,

This performs basic checks on the correct execution of scheduling
parameter changes from primary mode.

Signed-off-by: Jan Kiszka 

---

 configure.ac  |1 +
 testsuite/smokey/Makefile.am  |1 +
 testsuite/smokey/setsched/Makefile.am |9 +++
 testsuite/smokey/setsched/setsched.c  |  137 +
 4 files changed, 148 insertions(+)

diff --git a/configure.ac b/configure.ac
index cd9f047..667931a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -913,6 +913,7 @@ AC_CONFIG_FILES([ \
testsuite/smokey/arith/Makefile \
testsuite/smokey/sched-quota/Makefile \
testsuite/smokey/sched-tp/Makefile \
+   testsuite/smokey/setsched/Makefile \
testsuite/smokey/rtdm/Makefile \
testsuite/smokey/vdso-access/Makefile \
testsuite/smokey/posix-cond/Makefile \
diff --git a/testsuite/smokey/Makefile.am b/testsuite/smokey/Makefile.am
index 51292f1..e253d6f 100644
--- a/testsuite/smokey/Makefile.am
+++ b/testsuite/smokey/Makefile.am
@@ -24,6 +24,7 @@ COBALT_SUBDIRS =  \
rtdm\
sched-quota \
sched-tp\
+   setsched\
sigdebug\
timerfd \
tsc \
diff --git a/testsuite/smokey/setsched/Makefile.am 
b/testsuite/smokey/setsched/Makefile.am
new file mode 100644
index 000..8c0a59b
--- /dev/null
+++ b/testsuite/smokey/setsched/Makefile.am
@@ -0,0 +1,9 @@
+
+noinst_LIBRARIES = libsetsched.a
+
+libsetsched_a_SOURCES = setsched.c
+
+libsetsched_a_CPPFLAGS =   \
+   @XENO_USER_CFLAGS@  \
+   -I$(top_srcdir) \
+   -I$(top_srcdir)/include
diff --git a/testsuite/smokey/setsched/setsched.c 
b/testsuite/smokey/setsched/setsched.c
new file mode 100644
index 000..b4b4066
--- /dev/null
+++ b/testsuite/smokey/setsched/setsched.c
@@ -0,0 +1,137 @@
+/*
+ * Scheduler live-adjustment test.
+ *
+ * Copyright (c) Siemens AG 2016
+ *
+ * Authors:
+ *  Jan Kiszka 
+ *
+ * Released under the terms of GPLv2.
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+smokey_test_plugin(setsched, SMOKEY_NOARGS,
+   "Validate correct application of scheduling parameters to running threads."
+);
+
+static pid_t thread_pid;
+
+static void __check_linux_schedparams(int expected_policy, int expected_prio,
+ int line)
+{
+   struct sched_param linux_param;
+   int linux_policy;
+
+   linux_policy = syscall(SYS_sched_getscheduler, thread_pid);
+   if (smokey_check_status(syscall(SYS_sched_getparam, thread_pid,
+   &linux_param)))
+   exit(-EINVAL);
+
+   if (!smokey_assert(linux_policy == expected_policy) ||
+   !smokey_assert(linux_param.sched_priority == expected_prio)) {
+   smokey_warning("called from line %d", line);
+   exit(-EINVAL);
+   }
+}
+
+#define check_linux_schedparams(pol, prio) \
+   __check_linux_schedparams(pol, prio, __LINE__)
+
+static void __check_rt_schedparams(int expected_policy, int expected_prio,
+  int line)
+{
+   struct sched_param cobalt_param;
+   int cobalt_policy;
+
+   if (smokey_check_status(pthread_getschedparam(pthread_self(),
+ &cobalt_policy,
+ &cobalt_param)))
+   exit(-EINVAL);
+
+   if (!smokey_assert(cobalt_policy == expected_policy) ||
+   !smokey_assert(cobalt_param.sched_priority == expected_prio)) {
+   smokey_warning("called from line %d", line);
+   exit(-EINVAL);
+   }
+}
+
+#define check_rt_schedparams(pol, prio)\
+   __check_rt_schedparams(pol, prio, __LINE__)
+
+static void *thread_body(void *arg)
+{
+   struct cobalt_threadstat stats;
+   struct sched_param param;
+   unsigned long long msw;
+
+   thread_pid = syscall(SYS_gettid);
+
+   check_rt_schedparams(SCHED_FIFO, 1);
+   check_linux_schedparams(SCHED_FIFO, 1);
+
+   if (smokey_check_status(cobalt_thread_stat(thread_pid, &stats)))
+   exit(-EINVAL);
+   msw = stats.msw;
+
+   param.sched_priority = 2;
+   if (smokey_check_status(pthread_setschedparam(pthread_self(),
+ SCHED_FIFO, ¶m)))
+   exit(-EINVAL);
+
+   check_rt_schedparams(SCHED_FIFO, 2);
+
+   if (smokey_check_status(cobalt_thread_stat(thread_pid, &stats)) ||
+   !smokey_assert(stats.msw == msw))
+   e

[Xenomai-git] Jan Kiszka : cobalt/kernel: Null-terminate cobalt_print_sched_params output

2016-05-06 Thread git repository hosting
Module: xenomai-jki
Branch: for-forge
Commit: dd2c2f5e4320cb898bc8136b857ccc59cd7cf94c
URL:
http://git.xenomai.org/?p=xenomai-jki.git;a=commit;h=dd2c2f5e4320cb898bc8136b857ccc59cd7cf94c

Author: Jan Kiszka 
Date:   Fri May  6 10:42:27 2016 +0200

cobalt/kernel: Null-terminate cobalt_print_sched_params output

Using trace_seq_printf requires to terminate the generated string with
0, or we print additional garbage.

Signed-off-by: Jan Kiszka 

---

 kernel/cobalt/trace/cobalt-posix.h |1 +
 1 file changed, 1 insertion(+)

diff --git a/kernel/cobalt/trace/cobalt-posix.h 
b/kernel/cobalt/trace/cobalt-posix.h
index 75673d7..cc0eb05 100644
--- a/kernel/cobalt/trace/cobalt-posix.h
+++ b/kernel/cobalt/trace/cobalt-posix.h
@@ -130,6 +130,7 @@ DECLARE_EVENT_CLASS(syscall_exit,
 (__p_ex)->sched_priority); \
break;  \
}   \
+   trace_seq_putc(p, '\0');\
__ret;  \
 })
 


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Jan Kiszka : lib/cobalt: Wrap pthread_setschedprio for proper real-time support

2016-05-09 Thread git repository hosting
Module: xenomai-jki
Branch: for-forge
Commit: b839ae85aab927c54da45f32203c299858e23f24
URL:
http://git.xenomai.org/?p=xenomai-jki.git;a=commit;h=b839ae85aab927c54da45f32203c299858e23f24

Author: Jan Kiszka 
Date:   Tue Mar  8 14:46:59 2016 +0100

lib/cobalt: Wrap pthread_setschedprio for proper real-time support

Implement pthread_setschedprio on top of pthread_setschedparam_ex with
the help of the new __SCHED_CURRENT policy. This ensures that prio
changes are directly applied to the real-time core, and that with just
a single syscall.

Signed-off-by: Jan Kiszka 

---

 include/cobalt/pthread.h   |2 ++
 lib/cobalt/cobalt.wrappers |1 +
 lib/cobalt/thread.c|9 +
 lib/cobalt/wrappers.c  |6 ++
 4 files changed, 18 insertions(+)

diff --git a/include/cobalt/pthread.h b/include/cobalt/pthread.h
index f1b1c8a..3e9bd47 100644
--- a/include/cobalt/pthread.h
+++ b/include/cobalt/pthread.h
@@ -53,6 +53,8 @@ COBALT_DECL(int, pthread_setschedparam(pthread_t thread,
   int policy,
   const struct sched_param *param));
 
+COBALT_DECL(int, pthread_setschedprio(pthread_t thread, int prio));
+
 COBALT_DECL(int, pthread_mutex_init(pthread_mutex_t *mutex,
const pthread_mutexattr_t *attr));
 
diff --git a/lib/cobalt/cobalt.wrappers b/lib/cobalt/cobalt.wrappers
index 75f29d6..19153ae 100644
--- a/lib/cobalt/cobalt.wrappers
+++ b/lib/cobalt/cobalt.wrappers
@@ -2,6 +2,7 @@
 --wrap pthread_create
 --wrap pthread_setschedparam
 --wrap pthread_getschedparam
+--wrap pthread_setschedprio
 --wrap pthread_yield
 --wrap sched_yield
 --wrap sched_get_priority_min
diff --git a/lib/cobalt/thread.c b/lib/cobalt/thread.c
index 908516f..62ca0a0 100644
--- a/lib/cobalt/thread.c
+++ b/lib/cobalt/thread.c
@@ -650,6 +650,15 @@ int pthread_setschedparam_ex(pthread_t thread,
return ret;
 }
 
+COBALT_IMPL(int, pthread_setschedprio, (pthread_t thread, int prio))
+{
+   struct sched_param_ex param_ex = {
+   .sched_priority = prio,
+   };
+
+   return pthread_setschedparam_ex(thread, __SCHED_CURRENT, ¶m_ex);
+}
+
 /**
  * Get the scheduling policy and parameters of the specified thread.
  *
diff --git a/lib/cobalt/wrappers.c b/lib/cobalt/wrappers.c
index 09c74e5..1f1664e 100644
--- a/lib/cobalt/wrappers.c
+++ b/lib/cobalt/wrappers.c
@@ -60,6 +60,12 @@ int __real_pthread_getschedparam(pthread_t thread,
 }
 
 __weak
+int __real_pthread_setschedprio(pthread_t thread, int prio)
+{
+   return pthread_setschedprio(thread, prio);
+}
+
+__weak
 int __real_sched_yield(void)
 {
return sched_yield();


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Jan Kiszka : cobalt/kernel: Trigger missing reschedule after PP deboost

2016-05-09 Thread git repository hosting
Module: xenomai-jki
Branch: for-forge
Commit: aed17e71a13608562fc84549777fc79bdb2c1fc7
URL:
http://git.xenomai.org/?p=xenomai-jki.git;a=commit;h=aed17e71a13608562fc84549777fc79bdb2c1fc7

Author: Jan Kiszka 
Date:   Mon May  9 21:22:23 2016 +0200

cobalt/kernel: Trigger missing reschedule after PP deboost

xnsynch_release also needs to tell the caller about the potential need
for a reschedule after deboosting for prio-protection.

Signed-off-by: Jan Kiszka 

---

 kernel/cobalt/synch.c |4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/kernel/cobalt/synch.c b/kernel/cobalt/synch.c
index d9fb5a2..43b8ea4 100644
--- a/kernel/cobalt/synch.c
+++ b/kernel/cobalt/synch.c
@@ -948,8 +948,10 @@ int xnsynch_release(struct xnsynch *synch, struct xnthread 
*curr)
else if (h != currh)/* FLCEIL set, FLCLAIM clear. */
atomic_set(lockp, XN_NO_HANDLE);
 
-   if (synch->status & XNSYNCH_PP)
+   if (synch->status & XNSYNCH_PP) {
clear_pp_boost(synch, curr);
+   need_resched = 1;
+   }
 
xnlock_put_irqrestore(&nklock, s);
 


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Jan Kiszka : cobalt/kernel: Return need_resched flag from xnsynch_release

2016-05-09 Thread git repository hosting
Module: xenomai-jki
Branch: for-forge
Commit: dd2df9a8bfbb7e45e1c262b52050cc1c3f75b3bd
URL:
http://git.xenomai.org/?p=xenomai-jki.git;a=commit;h=dd2df9a8bfbb7e45e1c262b52050cc1c3f75b3bd

Author: Jan Kiszka 
Date:   Mon May  9 21:19:04 2016 +0200

cobalt/kernel: Return need_resched flag from xnsynch_release

We currently return the next owner, but no caller of xnsynch_release
evaluates this beyond != NULL and calls xnsched_run in that case.
Simplify the API by returning a need_resched flag directly. This will
also help with fixing the missing reschedule after PP deboost.

Signed-off-by: Jan Kiszka 

---

 include/cobalt/kernel/synch.h |3 +--
 kernel/cobalt/posix/mutex.c   |2 +-
 kernel/cobalt/rtdm/drvlib.c   |2 +-
 kernel/cobalt/synch.c |   22 ++
 4 files changed, 13 insertions(+), 16 deletions(-)

diff --git a/include/cobalt/kernel/synch.h b/include/cobalt/kernel/synch.h
index 04d7f10..83b82c4 100644
--- a/include/cobalt/kernel/synch.h
+++ b/include/cobalt/kernel/synch.h
@@ -164,8 +164,7 @@ int xnsynch_acquire(struct xnsynch *synch,
 
 int xnsynch_try_acquire(struct xnsynch *synch);
 
-struct xnthread *xnsynch_release(struct xnsynch *synch,
-struct xnthread *thread);
+int xnsynch_release(struct xnsynch *synch, struct xnthread *thread);
 
 struct xnthread *xnsynch_peek_pendq(struct xnsynch *synch);
 
diff --git a/kernel/cobalt/posix/mutex.c b/kernel/cobalt/posix/mutex.c
index c6020ff..f99874b 100644
--- a/kernel/cobalt/posix/mutex.c
+++ b/kernel/cobalt/posix/mutex.c
@@ -128,7 +128,7 @@ int cobalt_mutex_release(struct xnthread *curr,
cobalt_cond_deferred_signals(cond);
}
}
-   need_resched |= xnsynch_release(&mutex->synchbase, curr) != NULL;
+   need_resched |= xnsynch_release(&mutex->synchbase, curr);
 
return need_resched;
 }
diff --git a/kernel/cobalt/rtdm/drvlib.c b/kernel/cobalt/rtdm/drvlib.c
index ae55a4b..1973c37 100644
--- a/kernel/cobalt/rtdm/drvlib.c
+++ b/kernel/cobalt/rtdm/drvlib.c
@@ -1282,7 +1282,7 @@ void rtdm_mutex_unlock(rtdm_mutex_t *mutex)
trace_cobalt_driver_mutex_release(mutex);
 
if (unlikely(xnsynch_release(&mutex->synch_base,
-xnsched_current_thread()) != NULL))
+xnsched_current_thread(
xnsched_run();
 }
 EXPORT_SYMBOL_GPL(rtdm_mutex_unlock);
diff --git a/kernel/cobalt/synch.c b/kernel/cobalt/synch.c
index 976261d..d9fb5a2 100644
--- a/kernel/cobalt/synch.c
+++ b/kernel/cobalt/synch.c
@@ -843,8 +843,7 @@ static inline void clear_pp_boost(struct xnsynch *synch,
drop_booster(synch, owner);
 }
 
-static struct xnthread *transfer_ownership(struct xnsynch *synch,
-  struct xnthread *lastowner)
+static int transfer_ownership(struct xnsynch *synch, struct xnthread 
*lastowner)
 {  /* nklock held, irqs off */
struct xnthread *nextowner;
xnhandle_t nextownerh;
@@ -859,7 +858,7 @@ static struct xnthread *transfer_ownership(struct xnsynch 
*synch,
if (list_empty(&synch->pendq)) {
synch->owner = NULL;
atomic_set(lockp, XN_NO_HANDLE);
-   return NULL;
+   return 0;
}
 
nextowner = list_first_entry(&synch->pendq, struct xnthread, plink);
@@ -879,11 +878,11 @@ static struct xnthread *transfer_ownership(struct xnsynch 
*synch,
 
atomic_set(lockp, nextownerh);
 
-   return nextowner;
+   return 1;
 }
 
 /**
- * @fn struct xnthread *xnsynch_release(struct xnsynch *synch, struct xnthread 
*curr)
+ * @fn int xnsynch_release(struct xnsynch *synch, struct xnthread *curr)
  * @brief Release a resource and pass it to the next waiting thread.
  *
  * This service releases the ownership of the given synchronization
@@ -900,7 +899,7 @@ static struct xnthread *transfer_ownership(struct xnsynch 
*synch,
  * @param curr The descriptor address of the current thread, which
  * must own the object at the time of calling.
  *
- * @return The descriptor address of the unblocked thread.
+ * @return Non-zero if a reschedule is required.
  *
  * @sideeffect
  *
@@ -913,10 +912,9 @@ static struct xnthread *transfer_ownership(struct xnsynch 
*synch,
  *
  * @coretags{primary-only, might-switch}
  */
-struct xnthread *xnsynch_release(struct xnsynch *synch,
-struct xnthread *curr)
+int xnsynch_release(struct xnsynch *synch, struct xnthread *curr)
 {
-   struct xnthread *nextowner = NULL;
+   int need_resched = 0;
xnhandle_t currh, h;
atomic_t *lockp;
spl_t s;
@@ -926,7 +924,7 @@ struct xnthread *xnsynch_release(struct xnsynch *synch,
trace_cobalt_synch_release(synch);
 
if (xnthread_put_resource(curr))
-   return NULL;
+   return 0;
 
lockp = xnsynch_fastlock(synch);
currh

[Xenomai-git] Jan Kiszka : cobalt/kernel: Introduce __SCHED_CURRENT policy to setschedparam_ex

2016-05-09 Thread git repository hosting
Module: xenomai-jki
Branch: for-forge
Commit: 110b97a4770affa6f0888355fc5a7c57e12b4ab9
URL:
http://git.xenomai.org/?p=xenomai-jki.git;a=commit;h=110b97a4770affa6f0888355fc5a7c57e12b4ab9

Author: Jan Kiszka 
Date:   Tue Mar  8 14:41:28 2016 +0100

cobalt/kernel: Introduce __SCHED_CURRENT policy to setschedparam_ex

Define the internal scheduling policy "current": it shall refer to the
target thread's current scheduling policy. This will allow to model
pthread_setschedprio on top of pthread_setschedparam_ex with only a
single syscall.

Signed-off-by: Jan Kiszka 

---

 include/cobalt/uapi/sched.h|3 +++
 kernel/cobalt/posix/thread.c   |   10 ++
 kernel/cobalt/trace/cobalt-posix.h |3 ++-
 3 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/include/cobalt/uapi/sched.h b/include/cobalt/uapi/sched.h
index b672095..2a1df44 100644
--- a/include/cobalt/uapi/sched.h
+++ b/include/cobalt/uapi/sched.h
@@ -21,6 +21,9 @@
 #define SCHED_COBALT   42
 #define SCHED_WEAK 43
 
+/* for internal use */
+#define __SCHED_CURRENT44
+
 #ifndef SCHED_SPORADIC
 #define SCHED_SPORADIC 10
 #define sched_ss_low_priority  sched_u.ss.__sched_low_priority
diff --git a/kernel/cobalt/posix/thread.c b/kernel/cobalt/posix/thread.c
index d87edb1..217b81b 100644
--- a/kernel/cobalt/posix/thread.c
+++ b/kernel/cobalt/posix/thread.c
@@ -242,6 +242,7 @@ struct xnthread_personality *cobalt_thread_finalize(struct 
xnthread *zombie)
 int __cobalt_thread_setschedparam_ex(struct cobalt_thread *thread, int policy,
 const struct sched_param_ex *param_ex)
 {
+   struct xnthread *base_thread = &thread->threadbase;
struct xnsched_class *sched_class;
union xnsched_policy_param param;
xnticks_t tslice;
@@ -256,6 +257,15 @@ int __cobalt_thread_setschedparam_ex(struct cobalt_thread 
*thread, int policy,
goto out;
}
 
+   if (policy == __SCHED_CURRENT) {
+   policy = base_thread->base_class->policy;
+   if (xnthread_base_priority(base_thread) == 0)
+   policy = SCHED_NORMAL;
+   else if (base_thread->base_class == &xnsched_class_rt &&
+xnthread_test_state(base_thread, XNRRB))
+   policy = SCHED_RR;
+   }
+
tslice = thread->threadbase.rrperiod;
sched_class = cobalt_sched_policy_param(¶m, policy,
param_ex, &tslice);
diff --git a/kernel/cobalt/trace/cobalt-posix.h 
b/kernel/cobalt/trace/cobalt-posix.h
index 92f7245..75673d7 100644
--- a/kernel/cobalt/trace/cobalt-posix.h
+++ b/kernel/cobalt/trace/cobalt-posix.h
@@ -90,7 +90,8 @@ DECLARE_EVENT_CLASS(syscall_exit,
 {SCHED_QUOTA, "quota"},\
 {SCHED_SPORADIC, "sporadic"},  \
 {SCHED_COBALT, "cobalt"},  \
-{SCHED_WEAK, "weak"})
+{SCHED_WEAK, "weak"},  \
+{__SCHED_CURRENT, ""})
 
 #define cobalt_print_sched_params(__policy, __p_ex)\
 ({ \


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Jan Kiszka : cobalt/kernel: Null-terminate cobalt_print_sched_params output

2016-05-09 Thread git repository hosting
Module: xenomai-jki
Branch: for-forge
Commit: 459f0de2357214e9ac13411dbe5c22e467cfc5ec
URL:
http://git.xenomai.org/?p=xenomai-jki.git;a=commit;h=459f0de2357214e9ac13411dbe5c22e467cfc5ec

Author: Jan Kiszka 
Date:   Fri May  6 10:42:27 2016 +0200

cobalt/kernel: Null-terminate cobalt_print_sched_params output

Using trace_seq_printf requires to terminate the generated string with
0, or we print additional garbage.

Signed-off-by: Jan Kiszka 

---

 kernel/cobalt/trace/cobalt-posix.h |1 +
 1 file changed, 1 insertion(+)

diff --git a/kernel/cobalt/trace/cobalt-posix.h 
b/kernel/cobalt/trace/cobalt-posix.h
index 75673d7..cc0eb05 100644
--- a/kernel/cobalt/trace/cobalt-posix.h
+++ b/kernel/cobalt/trace/cobalt-posix.h
@@ -130,6 +130,7 @@ DECLARE_EVENT_CLASS(syscall_exit,
 (__p_ex)->sched_priority); \
break;  \
}   \
+   trace_seq_putc(p, '\0');\
__ret;  \
 })
 


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Jan Kiszka : cobalt/kernel: Return need_resched flag from xnsynch_release

2016-05-09 Thread git repository hosting
Module: xenomai-jki
Branch: for-forge
Commit: 3c6a48e0eae6a1b656d18dcbe1dd96f3563bcf7a
URL:
http://git.xenomai.org/?p=xenomai-jki.git;a=commit;h=3c6a48e0eae6a1b656d18dcbe1dd96f3563bcf7a

Author: Jan Kiszka 
Date:   Mon May  9 21:19:04 2016 +0200

cobalt/kernel: Return need_resched flag from xnsynch_release

We currently return the next owner, but no caller of xnsynch_release
evaluates this beyond != NULL and calls xnsched_run in that case.
Simplify the API by returning a need_resched flag directly. This will
also help with fixing the missing reschedule after PP deboost.

Signed-off-by: Jan Kiszka 

---

 include/cobalt/kernel/synch.h |3 +--
 kernel/cobalt/posix/mutex.c   |2 +-
 kernel/cobalt/rtdm/drvlib.c   |2 +-
 kernel/cobalt/synch.c |   23 +++
 4 files changed, 14 insertions(+), 16 deletions(-)

diff --git a/include/cobalt/kernel/synch.h b/include/cobalt/kernel/synch.h
index 04d7f10..1e99c18 100644
--- a/include/cobalt/kernel/synch.h
+++ b/include/cobalt/kernel/synch.h
@@ -164,8 +164,7 @@ int xnsynch_acquire(struct xnsynch *synch,
 
 int xnsynch_try_acquire(struct xnsynch *synch);
 
-struct xnthread *xnsynch_release(struct xnsynch *synch,
-struct xnthread *thread);
+bool xnsynch_release(struct xnsynch *synch, struct xnthread *thread);
 
 struct xnthread *xnsynch_peek_pendq(struct xnsynch *synch);
 
diff --git a/kernel/cobalt/posix/mutex.c b/kernel/cobalt/posix/mutex.c
index c6020ff..f99874b 100644
--- a/kernel/cobalt/posix/mutex.c
+++ b/kernel/cobalt/posix/mutex.c
@@ -128,7 +128,7 @@ int cobalt_mutex_release(struct xnthread *curr,
cobalt_cond_deferred_signals(cond);
}
}
-   need_resched |= xnsynch_release(&mutex->synchbase, curr) != NULL;
+   need_resched |= xnsynch_release(&mutex->synchbase, curr);
 
return need_resched;
 }
diff --git a/kernel/cobalt/rtdm/drvlib.c b/kernel/cobalt/rtdm/drvlib.c
index ae55a4b..1973c37 100644
--- a/kernel/cobalt/rtdm/drvlib.c
+++ b/kernel/cobalt/rtdm/drvlib.c
@@ -1282,7 +1282,7 @@ void rtdm_mutex_unlock(rtdm_mutex_t *mutex)
trace_cobalt_driver_mutex_release(mutex);
 
if (unlikely(xnsynch_release(&mutex->synch_base,
-xnsched_current_thread()) != NULL))
+xnsched_current_thread(
xnsched_run();
 }
 EXPORT_SYMBOL_GPL(rtdm_mutex_unlock);
diff --git a/kernel/cobalt/synch.c b/kernel/cobalt/synch.c
index 976261d..0130844 100644
--- a/kernel/cobalt/synch.c
+++ b/kernel/cobalt/synch.c
@@ -843,8 +843,8 @@ static inline void clear_pp_boost(struct xnsynch *synch,
drop_booster(synch, owner);
 }
 
-static struct xnthread *transfer_ownership(struct xnsynch *synch,
-  struct xnthread *lastowner)
+static bool transfer_ownership(struct xnsynch *synch,
+  struct xnthread *lastowner)
 {  /* nklock held, irqs off */
struct xnthread *nextowner;
xnhandle_t nextownerh;
@@ -859,7 +859,7 @@ static struct xnthread *transfer_ownership(struct xnsynch 
*synch,
if (list_empty(&synch->pendq)) {
synch->owner = NULL;
atomic_set(lockp, XN_NO_HANDLE);
-   return NULL;
+   return false;
}
 
nextowner = list_first_entry(&synch->pendq, struct xnthread, plink);
@@ -879,11 +879,11 @@ static struct xnthread *transfer_ownership(struct xnsynch 
*synch,
 
atomic_set(lockp, nextownerh);
 
-   return nextowner;
+   return true;
 }
 
 /**
- * @fn struct xnthread *xnsynch_release(struct xnsynch *synch, struct xnthread 
*curr)
+ * @fn bool xnsynch_release(struct xnsynch *synch, struct xnthread *curr)
  * @brief Release a resource and pass it to the next waiting thread.
  *
  * This service releases the ownership of the given synchronization
@@ -900,7 +900,7 @@ static struct xnthread *transfer_ownership(struct xnsynch 
*synch,
  * @param curr The descriptor address of the current thread, which
  * must own the object at the time of calling.
  *
- * @return The descriptor address of the unblocked thread.
+ * @return True if a reschedule is required.
  *
  * @sideeffect
  *
@@ -913,10 +913,9 @@ static struct xnthread *transfer_ownership(struct xnsynch 
*synch,
  *
  * @coretags{primary-only, might-switch}
  */
-struct xnthread *xnsynch_release(struct xnsynch *synch,
-struct xnthread *curr)
+bool xnsynch_release(struct xnsynch *synch, struct xnthread *curr)
 {
-   struct xnthread *nextowner = NULL;
+   bool need_resched = false;
xnhandle_t currh, h;
atomic_t *lockp;
spl_t s;
@@ -926,7 +925,7 @@ struct xnthread *xnsynch_release(struct xnsynch *synch,
trace_cobalt_synch_release(synch);
 
if (xnthread_put_resource(curr))
-   return NULL;
+   return 0;
 
loc

[Xenomai-git] Jan Kiszka : cobalt/kernel: Trigger missing reschedule after PP deboost

2016-05-09 Thread git repository hosting
Module: xenomai-jki
Branch: for-forge
Commit: 2f2f4c76b7a79c772d7224ca7591a23136b131f3
URL:
http://git.xenomai.org/?p=xenomai-jki.git;a=commit;h=2f2f4c76b7a79c772d7224ca7591a23136b131f3

Author: Jan Kiszka 
Date:   Mon May  9 21:22:23 2016 +0200

cobalt/kernel: Trigger missing reschedule after PP deboost

xnsynch_release also needs to tell the caller about the potential need
for a reschedule after deboosting for prio-protection.

Signed-off-by: Jan Kiszka 

---

 kernel/cobalt/synch.c |4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/kernel/cobalt/synch.c b/kernel/cobalt/synch.c
index 0130844..ee52dbd 100644
--- a/kernel/cobalt/synch.c
+++ b/kernel/cobalt/synch.c
@@ -949,8 +949,10 @@ bool xnsynch_release(struct xnsynch *synch, struct 
xnthread *curr)
else if (h != currh)/* FLCEIL set, FLCLAIM clear. */
atomic_set(lockp, XN_NO_HANDLE);
 
-   if (synch->status & XNSYNCH_PP)
+   if (synch->status & XNSYNCH_PP) {
clear_pp_boost(synch, curr);
+   need_resched = true;
+   }
 
xnlock_put_irqrestore(&nklock, s);
 


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Jan Kiszka : cobalt/kernel: Trigger missing reschedule after PP deboost

2016-05-10 Thread git repository hosting
Module: xenomai-jki
Branch: for-forge
Commit: 82fa7c398f71478250311f77709cfef93d5c6352
URL:
http://git.xenomai.org/?p=xenomai-jki.git;a=commit;h=82fa7c398f71478250311f77709cfef93d5c6352

Author: Jan Kiszka 
Date:   Mon May  9 21:22:23 2016 +0200

cobalt/kernel: Trigger missing reschedule after PP deboost

xnsynch_release also needs to tell the caller about the potential need
for a reschedule after deboosting for prio-protection.

Signed-off-by: Jan Kiszka 

---

 kernel/cobalt/synch.c |4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/kernel/cobalt/synch.c b/kernel/cobalt/synch.c
index d8b83d9..f3b70a2 100644
--- a/kernel/cobalt/synch.c
+++ b/kernel/cobalt/synch.c
@@ -949,8 +949,10 @@ bool xnsynch_release(struct xnsynch *synch, struct 
xnthread *curr)
else if (h != currh)/* FLCEIL set, FLCLAIM clear. */
atomic_set(lockp, XN_NO_HANDLE);
 
-   if (synch->status & XNSYNCH_PP)
+   if (synch->status & XNSYNCH_PP) {
clear_pp_boost(synch, curr);
+   need_resched = true;
+   }
 
xnlock_put_irqrestore(&nklock, s);
 


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Jan Kiszka : cobalt/kernel: Return need_resched flag from xnsynch_release

2016-05-10 Thread git repository hosting
Module: xenomai-jki
Branch: for-forge
Commit: 5cb254e542e9bb076a24fa0475a2fb17e2cac478
URL:
http://git.xenomai.org/?p=xenomai-jki.git;a=commit;h=5cb254e542e9bb076a24fa0475a2fb17e2cac478

Author: Jan Kiszka 
Date:   Mon May  9 21:19:04 2016 +0200

cobalt/kernel: Return need_resched flag from xnsynch_release

We currently return the next owner, but no caller of xnsynch_release
evaluates this beyond != NULL and calls xnsched_run in that case.
Simplify the API by returning a need_resched flag directly. This will
also help with fixing the missing reschedule after PP deboost.

Signed-off-by: Jan Kiszka 

---

 include/cobalt/kernel/synch.h |3 +--
 kernel/cobalt/posix/mutex.c   |2 +-
 kernel/cobalt/rtdm/drvlib.c   |2 +-
 kernel/cobalt/synch.c |   23 +++
 4 files changed, 14 insertions(+), 16 deletions(-)

diff --git a/include/cobalt/kernel/synch.h b/include/cobalt/kernel/synch.h
index 04d7f10..1e99c18 100644
--- a/include/cobalt/kernel/synch.h
+++ b/include/cobalt/kernel/synch.h
@@ -164,8 +164,7 @@ int xnsynch_acquire(struct xnsynch *synch,
 
 int xnsynch_try_acquire(struct xnsynch *synch);
 
-struct xnthread *xnsynch_release(struct xnsynch *synch,
-struct xnthread *thread);
+bool xnsynch_release(struct xnsynch *synch, struct xnthread *thread);
 
 struct xnthread *xnsynch_peek_pendq(struct xnsynch *synch);
 
diff --git a/kernel/cobalt/posix/mutex.c b/kernel/cobalt/posix/mutex.c
index c6020ff..f99874b 100644
--- a/kernel/cobalt/posix/mutex.c
+++ b/kernel/cobalt/posix/mutex.c
@@ -128,7 +128,7 @@ int cobalt_mutex_release(struct xnthread *curr,
cobalt_cond_deferred_signals(cond);
}
}
-   need_resched |= xnsynch_release(&mutex->synchbase, curr) != NULL;
+   need_resched |= xnsynch_release(&mutex->synchbase, curr);
 
return need_resched;
 }
diff --git a/kernel/cobalt/rtdm/drvlib.c b/kernel/cobalt/rtdm/drvlib.c
index ae55a4b..1973c37 100644
--- a/kernel/cobalt/rtdm/drvlib.c
+++ b/kernel/cobalt/rtdm/drvlib.c
@@ -1282,7 +1282,7 @@ void rtdm_mutex_unlock(rtdm_mutex_t *mutex)
trace_cobalt_driver_mutex_release(mutex);
 
if (unlikely(xnsynch_release(&mutex->synch_base,
-xnsched_current_thread()) != NULL))
+xnsched_current_thread(
xnsched_run();
 }
 EXPORT_SYMBOL_GPL(rtdm_mutex_unlock);
diff --git a/kernel/cobalt/synch.c b/kernel/cobalt/synch.c
index 976261d..d8b83d9 100644
--- a/kernel/cobalt/synch.c
+++ b/kernel/cobalt/synch.c
@@ -843,8 +843,8 @@ static inline void clear_pp_boost(struct xnsynch *synch,
drop_booster(synch, owner);
 }
 
-static struct xnthread *transfer_ownership(struct xnsynch *synch,
-  struct xnthread *lastowner)
+static bool transfer_ownership(struct xnsynch *synch,
+  struct xnthread *lastowner)
 {  /* nklock held, irqs off */
struct xnthread *nextowner;
xnhandle_t nextownerh;
@@ -859,7 +859,7 @@ static struct xnthread *transfer_ownership(struct xnsynch 
*synch,
if (list_empty(&synch->pendq)) {
synch->owner = NULL;
atomic_set(lockp, XN_NO_HANDLE);
-   return NULL;
+   return false;
}
 
nextowner = list_first_entry(&synch->pendq, struct xnthread, plink);
@@ -879,11 +879,11 @@ static struct xnthread *transfer_ownership(struct xnsynch 
*synch,
 
atomic_set(lockp, nextownerh);
 
-   return nextowner;
+   return true;
 }
 
 /**
- * @fn struct xnthread *xnsynch_release(struct xnsynch *synch, struct xnthread 
*curr)
+ * @fn bool xnsynch_release(struct xnsynch *synch, struct xnthread *curr)
  * @brief Release a resource and pass it to the next waiting thread.
  *
  * This service releases the ownership of the given synchronization
@@ -900,7 +900,7 @@ static struct xnthread *transfer_ownership(struct xnsynch 
*synch,
  * @param curr The descriptor address of the current thread, which
  * must own the object at the time of calling.
  *
- * @return The descriptor address of the unblocked thread.
+ * @return True if a reschedule is required.
  *
  * @sideeffect
  *
@@ -913,10 +913,9 @@ static struct xnthread *transfer_ownership(struct xnsynch 
*synch,
  *
  * @coretags{primary-only, might-switch}
  */
-struct xnthread *xnsynch_release(struct xnsynch *synch,
-struct xnthread *curr)
+bool xnsynch_release(struct xnsynch *synch, struct xnthread *curr)
 {
-   struct xnthread *nextowner = NULL;
+   bool need_resched = false;
xnhandle_t currh, h;
atomic_t *lockp;
spl_t s;
@@ -926,7 +925,7 @@ struct xnthread *xnsynch_release(struct xnsynch *synch,
trace_cobalt_synch_release(synch);
 
if (xnthread_put_resource(curr))
-   return NULL;
+   return false;
 
   

[Xenomai-git] Jan Kiszka : cobalt/kernel: Fix xntimer_get_timeout_stopped

2016-05-12 Thread git repository hosting
Module: xenomai-jki
Branch: for-forge
Commit: 29007915ef2345bfe6bd75f9a70b8ecaadf3d06a
URL:
http://git.xenomai.org/?p=xenomai-jki.git;a=commit;h=29007915ef2345bfe6bd75f9a70b8ecaadf3d06a

Author: Jan Kiszka 
Date:   Thu May 12 21:02:40 2016 +0200

cobalt/kernel: Fix xntimer_get_timeout_stopped

xntimer_get_timeout_stopped just called into xntimer_get_timeout, but
the latter returned XN_INFINITE for stopped timers. Restore the desired
behavior from Xenomai 2.

Signed-off-by: Jan Kiszka 

---

 include/cobalt/kernel/timer.h |   12 ++--
 kernel/cobalt/timer.c |7 ++-
 2 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/include/cobalt/kernel/timer.h b/include/cobalt/kernel/timer.h
index 5868fcb..b332fd2 100644
--- a/include/cobalt/kernel/timer.h
+++ b/include/cobalt/kernel/timer.h
@@ -456,7 +456,7 @@ void __xntimer_stop(struct xntimer *timer);
 
 xnticks_t xntimer_get_date(struct xntimer *timer);
 
-xnticks_t xntimer_get_timeout(struct xntimer *timer);
+xnticks_t __xntimer_get_timeout(struct xntimer *timer);
 
 xnticks_t xntimer_get_interval(struct xntimer *timer);
 
@@ -468,9 +468,17 @@ static inline void xntimer_stop(struct xntimer *timer)
__xntimer_stop(timer);
 }
 
+static inline xnticks_t xntimer_get_timeout(struct xntimer *timer)
+{
+   if (!xntimer_running_p(timer))
+   return XN_INFINITE;
+
+   return __xntimer_get_timeout(timer);
+}
+
 static inline xnticks_t xntimer_get_timeout_stopped(struct xntimer *timer)
 {
-   return xntimer_get_timeout(timer);
+   return __xntimer_get_timeout(timer);
 }
 
 static inline void xntimer_enqueue(struct xntimer *timer,
diff --git a/kernel/cobalt/timer.c b/kernel/cobalt/timer.c
index 114c2ed..353fcd5 100644
--- a/kernel/cobalt/timer.c
+++ b/kernel/cobalt/timer.c
@@ -266,14 +266,11 @@ EXPORT_SYMBOL_GPL(xntimer_get_date);
  *
  * @coretags{unrestricted, atomic-entry}
  */
-xnticks_t xntimer_get_timeout(struct xntimer *timer)
+xnticks_t __xntimer_get_timeout(struct xntimer *timer)
 {
struct xnclock *clock;
xnticks_t expiry, now;
 
-   if (!xntimer_running_p(timer))
-   return XN_INFINITE;
-
clock = xntimer_clock(timer);
now = xnclock_read_raw(clock);
expiry = xntimer_expiry(timer);
@@ -282,7 +279,7 @@ xnticks_t xntimer_get_timeout(struct xntimer *timer)
 
return xnclock_ticks_to_ns(clock, expiry - now);
 }
-EXPORT_SYMBOL_GPL(xntimer_get_timeout);
+EXPORT_SYMBOL_GPL(__xntimer_get_timeout);
 
 /**
  * @fn void xntimer_init(struct xntimer *timer,struct xnclock *clock,void 
(*handler)(struct xntimer *timer), struct xnsched *sched, int flags)


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Jan Kiszka : cobalt/kernel: Allow to restart clock_nanosleep and select after signal processing

2016-05-13 Thread git repository hosting
Module: xenomai-jki
Branch: for-forge
Commit: 775197bf4978364baffb66de34f47163682968b9
URL:
http://git.xenomai.org/?p=xenomai-jki.git;a=commit;h=775197bf4978364baffb66de34f47163682968b9

Author: Jan Kiszka 
Date:   Fri May 13 20:35:26 2016 +0200

cobalt/kernel: Allow to restart clock_nanosleep and select after signal 
processing

Only if a signal was actually delivered to a thread that was blocked on
sleep, [clock_]nanosleep or select, those calls should return -EINTR.
Otherwise, they should resume with the timeout, accordingly adjusted in
case of relative timeout. So far we returned -EINTR immediately which
particularly disturbed the debugging of applications (SIGSTOP/CONT
terminated those syscalls).

This approach reuses the Linux restart mechanism to find out if those
syscalls should be restarted or actually terminated after the signal
was handled: Linux sets current->restart_block.fn in case a termination
is required, unconditionally, thus also when the syscall did not return
ERESTART_RESTARTBLOCK. We also use the restart_block.nanosleep.expires
to transfer the remaining timeout to the restarted syscall.

We can't use the original restart mechanism of Linux because it directs
all ERESTART_RESTARTBLOCK through a special, Linux-only syscall. In our
case, we would have to migrate the caller in that context to primary in
order to resume the sleep, but this is not possible under Xenomai (we
need to migration from within the syscall hooks).

Signed-off-by: Jan Kiszka 

---

 include/cobalt/uapi/kernel/thread.h |1 +
 kernel/cobalt/posix/clock.c |   34 ++---
 kernel/cobalt/posix/io.c|   36 ---
 3 files changed, 61 insertions(+), 10 deletions(-)

diff --git a/include/cobalt/uapi/kernel/thread.h 
b/include/cobalt/uapi/kernel/thread.h
index 8d26f16..1f1dca7 100644
--- a/include/cobalt/uapi/kernel/thread.h
+++ b/include/cobalt/uapi/kernel/thread.h
@@ -77,6 +77,7 @@
 
 #define XNMOVED   0x0001 /**< CPU migration in primary mode occurred */
 #define XNLBALERT 0x0002 /**< Scheduler lock break alert (SIGDEBUG sent) */
+#define XNRESTART 0x0004 /**< Thread awaiting syscall restart after signal 
*/
 
 /** @} */
 
diff --git a/kernel/cobalt/posix/clock.c b/kernel/cobalt/posix/clock.c
index b51cb4c..dcb5a91 100644
--- a/kernel/cobalt/posix/clock.c
+++ b/kernel/cobalt/posix/clock.c
@@ -237,7 +237,7 @@ int __cobalt_clock_nanosleep(clockid_t clock_id, int flags,
 struct timespec *rmt)
 {
struct xnthread *cur;
-   xnsticks_t rem;
+   xnsticks_t timeout, rem;
int ret = 0;
spl_t s;
 
@@ -261,10 +261,38 @@ int __cobalt_clock_nanosleep(clockid_t clock_id, int 
flags,
 
xnlock_get_irqsave(&nklock, s);
 
-   xnthread_suspend(cur, XNDELAY, ts2ns(rqt) + 1,
+   if (xnthread_test_localinfo(cur, XNLBALERT)) {
+   xnthread_clear_localinfo(cur, XNLBALERT);
+
+   if (current->restart_block.fn != NULL) {
+   xnlock_put_irqrestore(&nklock, s);
+
+   if (rmt)
+   ns2ts(rmt, rem > 1 ? rem : 0);
+   return -EINTR;
+   }
+
+   timeout = current->restart_block.nanosleep.expires;
+   } else
+   timeout = ts2ns(rqt);
+
+   xnthread_suspend(cur, XNDELAY, timeout + 1,
 clock_flag(flags, clock_id), NULL);
 
if (xnthread_test_info(cur, XNBREAK)) {
+   if (signal_pending(current)) {
+   xnthread_set_localinfo(cur, XNLBALERT);
+
+   current->restart_block.fn = NULL;
+   current->restart_block.nanosleep.expires =
+   (flags & TIMER_ABSTIME) ? timout :
+   xntimer_get_timeout_stopped(&cur->rtimer) :
+
+   xnlock_put_irqrestore(&nklock, s);
+
+   return -ERESTARTSYS;
+   }
+
if (flags == 0 && rmt) {
rem = xntimer_get_timeout_stopped(&cur->rtimer);
xnlock_put_irqrestore(&nklock, s);
@@ -280,7 +308,7 @@ int __cobalt_clock_nanosleep(clockid_t clock_id, int flags,
return ret;
 }
 
-COBALT_SYSCALL(clock_nanosleep, nonrestartable,
+COBALT_SYSCALL(clock_nanosleep, primary,
   (clockid_t clock_id, int flags,
const struct timespec __user *u_rqt,
struct timespec __user *u_rmt))
diff --git a/kernel/cobalt/posix/io.c b/kernel/cobalt/posix/io.c
index 7110d21..99b31ca 100644
--- a/kernel/cobalt/posix/io.c
+++ b/kernel/cobalt/posix/io.c
@@ -170,7 +170,7 @@ int __cobalt_select_bind_all(struct xnselector *selector,
 }
 
 /* int select(int, fd_set *, fd_set *, fd_set *, struct timeval *) */
-COBALT_SYSCALL(select, nonrestartable,
+COBALT_SYSCALL(select, primary,
   (int nfds,
fd_set __user *u_rfd

[Xenomai-git] Jan Kiszka : testsuite/smokey: Add test case for setschedparam & Co,

2016-05-13 Thread git repository hosting
Module: xenomai-jki
Branch: for-forge
Commit: c669e75f9d69b2aa74bfd905f950f3f8cc27dca3
URL:
http://git.xenomai.org/?p=xenomai-jki.git;a=commit;h=c669e75f9d69b2aa74bfd905f950f3f8cc27dca3

Author: Jan Kiszka 
Date:   Mon Feb 29 16:54:26 2016 +0100

testsuite/smokey: Add test case for setschedparam & Co,

This performs basic checks on the correct execution of scheduling
parameter changes from primary mode.

Signed-off-by: Jan Kiszka 

---

 configure.ac  |1 +
 testsuite/smokey/Makefile.am  |1 +
 testsuite/smokey/setsched/Makefile.am |9 +++
 testsuite/smokey/setsched/setsched.c  |  137 +
 4 files changed, 148 insertions(+)

diff --git a/configure.ac b/configure.ac
index cd9f047..667931a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -913,6 +913,7 @@ AC_CONFIG_FILES([ \
testsuite/smokey/arith/Makefile \
testsuite/smokey/sched-quota/Makefile \
testsuite/smokey/sched-tp/Makefile \
+   testsuite/smokey/setsched/Makefile \
testsuite/smokey/rtdm/Makefile \
testsuite/smokey/vdso-access/Makefile \
testsuite/smokey/posix-cond/Makefile \
diff --git a/testsuite/smokey/Makefile.am b/testsuite/smokey/Makefile.am
index 51292f1..e253d6f 100644
--- a/testsuite/smokey/Makefile.am
+++ b/testsuite/smokey/Makefile.am
@@ -24,6 +24,7 @@ COBALT_SUBDIRS =  \
rtdm\
sched-quota \
sched-tp\
+   setsched\
sigdebug\
timerfd \
tsc \
diff --git a/testsuite/smokey/setsched/Makefile.am 
b/testsuite/smokey/setsched/Makefile.am
new file mode 100644
index 000..8c0a59b
--- /dev/null
+++ b/testsuite/smokey/setsched/Makefile.am
@@ -0,0 +1,9 @@
+
+noinst_LIBRARIES = libsetsched.a
+
+libsetsched_a_SOURCES = setsched.c
+
+libsetsched_a_CPPFLAGS =   \
+   @XENO_USER_CFLAGS@  \
+   -I$(top_srcdir) \
+   -I$(top_srcdir)/include
diff --git a/testsuite/smokey/setsched/setsched.c 
b/testsuite/smokey/setsched/setsched.c
new file mode 100644
index 000..359f190
--- /dev/null
+++ b/testsuite/smokey/setsched/setsched.c
@@ -0,0 +1,137 @@
+/*
+ * Scheduler live-adjustment test.
+ *
+ * Copyright (c) Siemens AG 2016
+ *
+ * Authors:
+ *  Jan Kiszka 
+ *
+ * Released under the terms of GPLv2.
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+smokey_test_plugin(setsched, SMOKEY_NOARGS,
+   "Validate correct application of scheduling parameters to running threads."
+);
+
+static pid_t thread_pid;
+
+static void __check_linux_schedparams(int expected_policy, int expected_prio,
+ int line)
+{
+   struct sched_param linux_param;
+   int linux_policy;
+
+   linux_policy = syscall(SYS_sched_getscheduler, thread_pid);
+   if (smokey_check_status(syscall(SYS_sched_getparam, thread_pid,
+   &linux_param)))
+   pthread_exit((void *)(long)-EINVAL);
+
+   if (!smokey_assert(linux_policy == expected_policy) ||
+   !smokey_assert(linux_param.sched_priority == expected_prio)) {
+   smokey_warning("called from line %d", line);
+   pthread_exit((void *)(long)-EINVAL);
+   }
+}
+
+#define check_linux_schedparams(pol, prio) \
+   __check_linux_schedparams(pol, prio, __LINE__)
+
+static void __check_rt_schedparams(int expected_policy, int expected_prio,
+  int line)
+{
+   struct sched_param cobalt_param;
+   int cobalt_policy;
+
+   if (smokey_check_status(pthread_getschedparam(pthread_self(),
+ &cobalt_policy,
+ &cobalt_param)))
+   pthread_exit((void *)(long)-EINVAL);
+
+   if (!smokey_assert(cobalt_policy == expected_policy) ||
+   !smokey_assert(cobalt_param.sched_priority == expected_prio)) {
+   smokey_warning("called from line %d", line);
+   pthread_exit((void *)(long)-EINVAL);
+   }
+}
+
+#define check_rt_schedparams(pol, prio)\
+   __check_rt_schedparams(pol, prio, __LINE__)
+
+static void *thread_body(void *arg)
+{
+   struct cobalt_threadstat stats;
+   struct sched_param param;
+   unsigned long long msw;
+
+   thread_pid = syscall(SYS_gettid);
+
+   check_rt_schedparams(SCHED_FIFO, 1);
+   check_linux_schedparams(SCHED_FIFO, 1);
+
+   if (smokey_check_status(cobalt_thread_stat(thread_pid, &stats)))
+   pthread_exit((void *)(long)-EINVAL);
+   msw = stats.msw;
+
+   param.sched_priority = 2;
+   if (smokey_check_status(pthread_setschedparam(pthread_self(),
+ SCHED_FIFO, ¶m)))
+   pthread_exit((void *)(long)-EINVAL);
+
+   check_rt_schedparams(SCHED_FIFO, 2);
+
+ 

[Xenomai-git] Jan Kiszka : cobalt/kernel: Null-terminate cobalt_print_sched_params output

2016-05-14 Thread git repository hosting
Module: xenomai-3
Branch: stable-3.0.x
Commit: 1022a4b150ded6e9eff6597bdb7b71ea9a90075b
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=1022a4b150ded6e9eff6597bdb7b71ea9a90075b

Author: Jan Kiszka 
Date:   Fri May  6 10:42:27 2016 +0200

cobalt/kernel: Null-terminate cobalt_print_sched_params output

Using trace_seq_printf requires to terminate the generated string with
0, or we print additional garbage.

Signed-off-by: Jan Kiszka 

---

 kernel/cobalt/trace/cobalt-posix.h |1 +
 1 file changed, 1 insertion(+)

diff --git a/kernel/cobalt/trace/cobalt-posix.h 
b/kernel/cobalt/trace/cobalt-posix.h
index 92f7245..3d0e20c 100644
--- a/kernel/cobalt/trace/cobalt-posix.h
+++ b/kernel/cobalt/trace/cobalt-posix.h
@@ -129,6 +129,7 @@ DECLARE_EVENT_CLASS(syscall_exit,
 (__p_ex)->sched_priority); \
break;  \
}   \
+   trace_seq_putc(p, '\0');\
__ret;  \
 })
 


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : rtipc/iddp: fix cleanup on binding error

2016-05-14 Thread git repository hosting
Module: xenomai-3
Branch: stable-3.0.x
Commit: aeb7f49e6d4c4c8ffda61b2e2c317607cc621329
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=aeb7f49e6d4c4c8ffda61b2e2c317607cc621329

Author: Philippe Gerum 
Date:   Sat May 14 15:20:34 2016 +0200

rtipc/iddp: fix cleanup on binding error

---

 kernel/drivers/ipc/iddp.c |   30 +++---
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/kernel/drivers/ipc/iddp.c b/kernel/drivers/ipc/iddp.c
index 59508f6..028e40a 100644
--- a/kernel/drivers/ipc/iddp.c
+++ b/kernel/drivers/ipc/iddp.c
@@ -192,24 +192,24 @@ static void iddp_close(struct rtdm_fd *fd)
void *poolmem;
u32 poolsz;
 
-   if (sk->name.sipc_port > -1) {
-   cobalt_atomic_enter(s);
-   xnmap_remove(portmap, sk->name.sipc_port);
-   cobalt_atomic_leave(s);
-   }
-
rtdm_sem_destroy(&sk->insem);
rtdm_waitqueue_destroy(&sk->privwaitq);
 
-   if (sk->handle)
-   xnregistry_remove(sk->handle);
-
-   if (sk->bufpool != &cobalt_heap) {
-   poolmem = xnheap_get_membase(&sk->privpool);
-   poolsz = xnheap_get_size(&sk->privpool);
-   xnheap_destroy(&sk->privpool);
-   xnheap_vfree(poolmem);
-   return;
+   if (test_bit(_IDDP_BOUND, &sk->status)) {
+   if (sk->handle)
+   xnregistry_remove(sk->handle);
+   if (sk->name.sipc_port > -1) {
+   cobalt_atomic_enter(s);
+   xnmap_remove(portmap, sk->name.sipc_port);
+   cobalt_atomic_leave(s);
+   }
+   if (sk->bufpool != &cobalt_heap) {
+   poolmem = xnheap_get_membase(&sk->privpool);
+   poolsz = xnheap_get_size(&sk->privpool);
+   xnheap_destroy(&sk->privpool);
+   xnheap_vfree(poolmem);
+   return;
+   }
}
 
/* Send unread datagrams back to the system heap. */


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : rtipc/bufp: fix cleanup on binding error

2016-05-14 Thread git repository hosting
Module: xenomai-3
Branch: stable-3.0.x
Commit: ac9484a2ebe7daccb6aefb7ee9fbc924057401a2
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=ac9484a2ebe7daccb6aefb7ee9fbc924057401a2

Author: Philippe Gerum 
Date:   Sat May 14 15:20:21 2016 +0200

rtipc/bufp: fix cleanup on binding error

---

 kernel/drivers/ipc/bufp.c |   20 +++-
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/kernel/drivers/ipc/bufp.c b/kernel/drivers/ipc/bufp.c
index 6fc51d4..f129eaa 100644
--- a/kernel/drivers/ipc/bufp.c
+++ b/kernel/drivers/ipc/bufp.c
@@ -138,17 +138,19 @@ static void bufp_close(struct rtdm_fd *fd)
rtdm_event_destroy(&sk->i_event);
rtdm_event_destroy(&sk->o_event);
 
-   if (sk->name.sipc_port > -1) {
-   cobalt_atomic_enter(s);
-   xnmap_remove(portmap, sk->name.sipc_port);
-   cobalt_atomic_leave(s);
-   }
+   if (test_bit(_BUFP_BOUND, &sk->status)) {
+   if (sk->name.sipc_port > -1) {
+   cobalt_atomic_enter(s);
+   xnmap_remove(portmap, sk->name.sipc_port);
+   cobalt_atomic_leave(s);
+   }
 
-   if (sk->handle)
-   xnregistry_remove(sk->handle);
+   if (sk->handle)
+   xnregistry_remove(sk->handle);
 
-   if (sk->bufmem)
-   xnheap_vfree(sk->bufmem);
+   if (sk->bufmem)
+   xnheap_vfree(sk->bufmem);
+   }
 
kfree(sk);
 }


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : cobalt/registry: allow slash in keys without /proc node

2016-05-14 Thread git repository hosting
Module: xenomai-3
Branch: next
Commit: a1cbf0ee6dc5dd08c96c13b79ddc49e85a25dc86
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=a1cbf0ee6dc5dd08c96c13b79ddc49e85a25dc86

Author: Philippe Gerum 
Date:   Sat Apr 30 15:06:02 2016 +0200

cobalt/registry: allow slash in keys without /proc node

---

 kernel/cobalt/registry.c |   12 
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/kernel/cobalt/registry.c b/kernel/cobalt/registry.c
index 9d14863..ed8a37f 100644
--- a/kernel/cobalt/registry.c
+++ b/kernel/cobalt/registry.c
@@ -595,7 +595,8 @@ static inline int registry_wakeup_sleepers(const char *key)
  * that such key is stored into the registered object, it will *not*
  * be copied but only kept by reference in the registry. Pass an empty
  * or NULL string if the object shall only occupy a registry slot for
- * handle-based lookups.
+ * handle-based lookups. The slash character is not accepted in @a key
+ * if @a pnode is non-NULL.
  *
  * @param objaddr An opaque pointer to the object to index by @a
  * key.
@@ -613,8 +614,10 @@ static inline int registry_wakeup_sleepers(const char *key)
  *
  * @return 0 is returned upon success. Otherwise:
  *
- * - -EINVAL is returned if @a objaddr is NULL, or if @a key is
- * non-NULL and contains an invalid '/' character.
+ * - -EINVAL is returned if @a objaddr is NULL.
+ *
+ * - -EINVAL if @a pnode is non-NULL, and @a key points to a valid
+ * string containing a '/' character.
  *
  * - -ENOMEM is returned if the system fails to get enough dynamic
  * memory from the global real-time heap in order to register the
@@ -631,7 +634,8 @@ int xnregistry_enter(const char *key, void *objaddr,
spl_t s;
int ret;
 
-   if (objaddr == NULL || (key != NULL && strchr(key, '/')))
+   if (objaddr == NULL ||
+   (pnode != NULL && key != NULL && strchr(key, '/')))
return -EINVAL;
 
xnlock_get_irqsave(&nklock, s);


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Jan Kiszka : cobalt/kernel: Null-terminate cobalt_print_sched_params output

2016-05-14 Thread git repository hosting
Module: xenomai-3
Branch: next
Commit: 7fd91d4d9de6704c4975fcd989faca457f72b9a7
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=7fd91d4d9de6704c4975fcd989faca457f72b9a7

Author: Jan Kiszka 
Date:   Fri May  6 10:42:27 2016 +0200

cobalt/kernel: Null-terminate cobalt_print_sched_params output

Using trace_seq_printf requires to terminate the generated string with
0, or we print additional garbage.

Signed-off-by: Jan Kiszka 

---

 kernel/cobalt/trace/cobalt-posix.h |1 +
 1 file changed, 1 insertion(+)

diff --git a/kernel/cobalt/trace/cobalt-posix.h 
b/kernel/cobalt/trace/cobalt-posix.h
index 92f7245..3d0e20c 100644
--- a/kernel/cobalt/trace/cobalt-posix.h
+++ b/kernel/cobalt/trace/cobalt-posix.h
@@ -129,6 +129,7 @@ DECLARE_EVENT_CLASS(syscall_exit,
 (__p_ex)->sched_priority); \
break;  \
}   \
+   trace_seq_putc(p, '\0');\
__ret;  \
 })
 


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : rtipc/bufp: fix cleanup on binding error

2016-05-14 Thread git repository hosting
Module: xenomai-3
Branch: next
Commit: a783d3db5e420b5174a213da210c7e287de9f500
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=a783d3db5e420b5174a213da210c7e287de9f500

Author: Philippe Gerum 
Date:   Sat May 14 15:20:21 2016 +0200

rtipc/bufp: fix cleanup on binding error

---

 kernel/drivers/ipc/bufp.c |   20 +++-
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/kernel/drivers/ipc/bufp.c b/kernel/drivers/ipc/bufp.c
index 6fc51d4..f129eaa 100644
--- a/kernel/drivers/ipc/bufp.c
+++ b/kernel/drivers/ipc/bufp.c
@@ -138,17 +138,19 @@ static void bufp_close(struct rtdm_fd *fd)
rtdm_event_destroy(&sk->i_event);
rtdm_event_destroy(&sk->o_event);
 
-   if (sk->name.sipc_port > -1) {
-   cobalt_atomic_enter(s);
-   xnmap_remove(portmap, sk->name.sipc_port);
-   cobalt_atomic_leave(s);
-   }
+   if (test_bit(_BUFP_BOUND, &sk->status)) {
+   if (sk->name.sipc_port > -1) {
+   cobalt_atomic_enter(s);
+   xnmap_remove(portmap, sk->name.sipc_port);
+   cobalt_atomic_leave(s);
+   }
 
-   if (sk->handle)
-   xnregistry_remove(sk->handle);
+   if (sk->handle)
+   xnregistry_remove(sk->handle);
 
-   if (sk->bufmem)
-   xnheap_vfree(sk->bufmem);
+   if (sk->bufmem)
+   xnheap_vfree(sk->bufmem);
+   }
 
kfree(sk);
 }


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : cobalt/rtdm: allow device paths with multiple components

2016-05-14 Thread git repository hosting
Module: xenomai-3
Branch: next
Commit: 8f1a3d8707553815c7310220bdf17ed35fec4380
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=8f1a3d8707553815c7310220bdf17ed35fec4380

Author: Philippe Gerum 
Date:   Sat Apr 30 09:40:10 2016 +0200

cobalt/rtdm: allow device paths with multiple components

---

 kernel/cobalt/rtdm/device.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/cobalt/rtdm/device.c b/kernel/cobalt/rtdm/device.c
index c760f31..46b7965 100644
--- a/kernel/cobalt/rtdm/device.c
+++ b/kernel/cobalt/rtdm/device.c
@@ -424,7 +424,7 @@ int rtdm_dev_register(struct rtdm_device *dev)
 
rdev = MKDEV(major, minor);
kdev = device_create(kdev_class, NULL, rdev,
-dev, dev->label, minor);
+dev, kbasename(dev->label), minor);
if (IS_ERR(kdev)) {
xnregistry_remove(dev->named.handle);
ret = PTR_ERR(kdev);


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : cobalt/rtdm: zero-init the private context area

2016-05-14 Thread git repository hosting
Module: xenomai-3
Branch: next
Commit: 7cc5c68c085d017183e4d6d91cfa9a59f025b0e6
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=7cc5c68c085d017183e4d6d91cfa9a59f025b0e6

Author: Philippe Gerum 
Date:   Tue May  3 12:16:29 2016 +0200

cobalt/rtdm: zero-init the private context area

---

 include/cobalt/kernel/rtdm/driver.h |9 -
 kernel/cobalt/rtdm/core.c   |2 +-
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/include/cobalt/kernel/rtdm/driver.h 
b/include/cobalt/kernel/rtdm/driver.h
index edd92ee..1354d9a 100644
--- a/include/cobalt/kernel/rtdm/driver.h
+++ b/include/cobalt/kernel/rtdm/driver.h
@@ -258,7 +258,14 @@ struct rtdm_driver {
 * @anchor rtdm_driver_flags
 */
int device_flags;
-   /** Size of driver defined appendix to struct rtdm_dev_context */
+   /**
+* Size of the private memory area the core should
+* automatically allocate for each open file descriptor, which
+* is usable for storing the context data associated to each
+* connection. The allocated memory is zero-initialized. The
+* start of this area can be retrieved by a call to
+* rtdm_fd_to_private().
+*/
size_t context_size;
/** Protocol device identification: protocol family (PF_xxx) */
int protocol_family;
diff --git a/kernel/cobalt/rtdm/core.c b/kernel/cobalt/rtdm/core.c
index 0f68e77..05f273f 100644
--- a/kernel/cobalt/rtdm/core.c
+++ b/kernel/cobalt/rtdm/core.c
@@ -86,7 +86,7 @@ static int create_instance(int ufd, struct rtdm_device *dev,
atomic_read(&dev->refcount) > 1)
return -EBUSY;
 
-   context = kmalloc(sizeof(struct rtdm_dev_context) +
+   context = kzalloc(sizeof(struct rtdm_dev_context) +
  drv->context_size, GFP_KERNEL);
if (unlikely(context == NULL))
return -ENOMEM;


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : testsuite/smokey: include errno dependency explicitly

2016-05-14 Thread git repository hosting
Module: xenomai-3
Branch: next
Commit: 7b61945d8eb022a04bbffcb9527c0c7a4405c92d
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=7b61945d8eb022a04bbffcb9527c0c7a4405c92d

Author: Philippe Gerum 
Date:   Sat Apr 30 19:03:03 2016 +0200

testsuite/smokey: include errno dependency explicitly

---

 testsuite/smokey/main.c |1 +
 1 file changed, 1 insertion(+)

diff --git a/testsuite/smokey/main.c b/testsuite/smokey/main.c
index 02ccc83..12321df 100644
--- a/testsuite/smokey/main.c
+++ b/testsuite/smokey/main.c
@@ -17,6 +17,7 @@
  */
 #include 
 #include 
+#include 
 #include 
 
 int main(int argc, char *const argv[])


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : boilerplate/init: track automatic bootstrap mode in --dump-config

2016-05-14 Thread git repository hosting
Module: xenomai-3
Branch: next
Commit: 41df44537009a5b3835c5b354fa67bdad30c0ff8
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=41df44537009a5b3835c5b354fa67bdad30c0ff8

Author: Philippe Gerum 
Date:   Mon Apr 25 15:09:17 2016 +0200

boilerplate/init: track automatic bootstrap mode in --dump-config

Automatic bootstrapping (or misusage of manual bootstrap mode) is a
frequent source of issues among C++ applications with non-trivial
static constructors. Have --dump-config display the bootstrap mode for
the executable to make investigation easier.

---

 include/xenomai/init.h   |2 ++
 lib/boilerplate/init/bootstrap.c |2 ++
 lib/boilerplate/setup.c  |3 +++
 3 files changed, 7 insertions(+)

diff --git a/include/xenomai/init.h b/include/xenomai/init.h
index 1ec1d43..9adc90d 100644
--- a/include/xenomai/init.h
+++ b/include/xenomai/init.h
@@ -37,6 +37,8 @@ void application_version(void);
 
 extern const char *xenomai_version_string;
 
+extern const int xenomai_auto_bootstrap;
+  
 #ifdef __cplusplus
 }
 #endif
diff --git a/lib/boilerplate/init/bootstrap.c b/lib/boilerplate/init/bootstrap.c
index cee6843..119b405 100644
--- a/lib/boilerplate/init/bootstrap.c
+++ b/lib/boilerplate/init/bootstrap.c
@@ -26,6 +26,8 @@ static int early_argc;
 
 static char *const *early_argv;
 
+const int xenomai_auto_bootstrap = 1;
+
 int __real_main(int argc, char *const argv[]);
 
 int __wrap_main(int argc, char *const argv[])
diff --git a/lib/boilerplate/setup.c b/lib/boilerplate/setup.c
index 7a9334d..dbeb5e1 100644
--- a/lib/boilerplate/setup.c
+++ b/lib/boilerplate/setup.c
@@ -46,6 +46,8 @@ pid_t __node_id = 0;
 
 int __config_done = 0;
 
+const int __weak xenomai_auto_bootstrap = 0;
+
 static int init_done;
 
 static DEFINE_PRIVATE_LIST(setup_list);
@@ -143,6 +145,7 @@ static inline void dump_configuration(void)
puts(config_strings[n]);
 
printf("PTHREAD_STACK_DEFAULT=%d\n", PTHREAD_STACK_DEFAULT);
+   printf("AUTOMATIC_BOOTSTRAP=%d\n", xenomai_auto_bootstrap);
 }
 
 static int collect_cpu_affinity(const char *cpu_list)


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Jan Kiszka : cobalt/kernel: Trigger missing reschedule after PP deboost

2016-05-14 Thread git repository hosting
Module: xenomai-3
Branch: next
Commit: 73141639fc3902382dfcccdf30dc9023cbc0caa5
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=73141639fc3902382dfcccdf30dc9023cbc0caa5

Author: Jan Kiszka 
Date:   Mon May  9 21:22:23 2016 +0200

cobalt/kernel: Trigger missing reschedule after PP deboost

xnsynch_release also needs to tell the caller about the potential need
for a reschedule after deboosting for prio-protection.

Signed-off-by: Jan Kiszka 

---

 kernel/cobalt/synch.c |4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/kernel/cobalt/synch.c b/kernel/cobalt/synch.c
index d8b83d9..f3b70a2 100644
--- a/kernel/cobalt/synch.c
+++ b/kernel/cobalt/synch.c
@@ -949,8 +949,10 @@ bool xnsynch_release(struct xnsynch *synch, struct 
xnthread *curr)
else if (h != currh)/* FLCEIL set, FLCLAIM clear. */
atomic_set(lockp, XN_NO_HANDLE);
 
-   if (synch->status & XNSYNCH_PP)
+   if (synch->status & XNSYNCH_PP) {
clear_pp_boost(synch, curr);
+   need_resched = true;
+   }
 
xnlock_put_irqrestore(&nklock, s);
 


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : alchemy/queue: allow zero-size message with rt_queue_write()

2016-05-14 Thread git repository hosting
Module: xenomai-3
Branch: next
Commit: 32c7bdc249f48122fc2a15cade98fdfffad04cf4
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=32c7bdc249f48122fc2a15cade98fdfffad04cf4

Author: Philippe Gerum 
Date:   Sat Apr 30 17:41:18 2016 +0200

alchemy/queue: allow zero-size message with rt_queue_write()

---

 lib/alchemy/queue.c |8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/lib/alchemy/queue.c b/lib/alchemy/queue.c
index 34a35f5..eb4bd19 100644
--- a/lib/alchemy/queue.c
+++ b/lib/alchemy/queue.c
@@ -630,10 +630,7 @@ int rt_queue_write(RT_QUEUE *queue,
if (mode & ~(Q_URGENT|Q_BROADCAST))
return -EINVAL;
 
-   if (size == 0)
-   return 0;
-
-   if (buf == NULL)
+   if (buf == NULL && size > 0)
return -EINVAL;
 
CANCEL_DEFER(svc);
@@ -683,7 +680,8 @@ enqueue:
 
msg->size = size;
msg->refcount = 0;
-   memcpy(msg + 1, buf, size);
+   if (size > 0)
+   memcpy(msg + 1, buf, size);
 
ret = 0;  /* # of tasks unblocked. */
if (nwaiters == 0) {


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : alchemy/queue: fix calculation of metadata overhead

2016-05-14 Thread git repository hosting
Module: xenomai-3
Branch: next
Commit: 695e1d2093d1242274fdf2c308a1c82e1ea226a6
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=695e1d2093d1242274fdf2c308a1c82e1ea226a6

Author: Philippe Gerum 
Date:   Sat Apr 30 07:25:23 2016 +0200

alchemy/queue: fix calculation of metadata overhead

---

 lib/alchemy/queue.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/alchemy/queue.c b/lib/alchemy/queue.c
index 410f480..34a35f5 100644
--- a/lib/alchemy/queue.c
+++ b/lib/alchemy/queue.c
@@ -232,7 +232,7 @@ int rt_queue_create(RT_QUEUE *queue, const char *name,
 */
if (qlimit == Q_UNLIMITED)
ret = heapobj_init(&qcb->hobj, qcb->name,
-  poolsize + (poolsize / 5));
+  poolsize + (poolsize * 5 / 100));
else
ret = heapobj_init_array(&qcb->hobj, qcb->name,
 (poolsize / qlimit) *


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : cobalt/rtdm: reinit driver magic after unregistration

2016-05-14 Thread git repository hosting
Module: xenomai-3
Branch: next
Commit: c58299dd82a52d6a144dc3585bfa990a4966
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=c58299dd82a52d6a144dc3585bfa990a4966

Author: Philippe Gerum 
Date:   Tue May  3 10:06:11 2016 +0200

cobalt/rtdm: reinit driver magic after unregistration

Failing to do so would prevent the driver to be properly registered
again.

---

 kernel/cobalt/rtdm/device.c |4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/kernel/cobalt/rtdm/device.c b/kernel/cobalt/rtdm/device.c
index 46b7965..aa62169 100644
--- a/kernel/cobalt/rtdm/device.c
+++ b/kernel/cobalt/rtdm/device.c
@@ -325,7 +325,9 @@ static void unregister_driver(struct rtdm_driver *drv)
XENO_BUG_ON(COBALT, drv->profile_info.magic != RTDM_CLASS_MAGIC);
 
cobalt_remove_state_chain(&drv->nb_statechange);
-   
+
+   drv->profile_info.magic = ~RTDM_CLASS_MAGIC;
+
if (drv->device_flags & RTDM_NAMED_DEVICE) {
cdev_del(&drv->named.cdev);
unregister_chrdev_region(MKDEV(drv->named.major, 0),


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : rtipc/iddp: fix cleanup on binding error

2016-05-14 Thread git repository hosting
Module: xenomai-3
Branch: next
Commit: 3febc57edec5fa87ee8c145455c72b67ea3843ab
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=3febc57edec5fa87ee8c145455c72b67ea3843ab

Author: Philippe Gerum 
Date:   Sat May 14 15:20:34 2016 +0200

rtipc/iddp: fix cleanup on binding error

---

 kernel/drivers/ipc/iddp.c |   30 +++---
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/kernel/drivers/ipc/iddp.c b/kernel/drivers/ipc/iddp.c
index 59508f6..028e40a 100644
--- a/kernel/drivers/ipc/iddp.c
+++ b/kernel/drivers/ipc/iddp.c
@@ -192,24 +192,24 @@ static void iddp_close(struct rtdm_fd *fd)
void *poolmem;
u32 poolsz;
 
-   if (sk->name.sipc_port > -1) {
-   cobalt_atomic_enter(s);
-   xnmap_remove(portmap, sk->name.sipc_port);
-   cobalt_atomic_leave(s);
-   }
-
rtdm_sem_destroy(&sk->insem);
rtdm_waitqueue_destroy(&sk->privwaitq);
 
-   if (sk->handle)
-   xnregistry_remove(sk->handle);
-
-   if (sk->bufpool != &cobalt_heap) {
-   poolmem = xnheap_get_membase(&sk->privpool);
-   poolsz = xnheap_get_size(&sk->privpool);
-   xnheap_destroy(&sk->privpool);
-   xnheap_vfree(poolmem);
-   return;
+   if (test_bit(_IDDP_BOUND, &sk->status)) {
+   if (sk->handle)
+   xnregistry_remove(sk->handle);
+   if (sk->name.sipc_port > -1) {
+   cobalt_atomic_enter(s);
+   xnmap_remove(portmap, sk->name.sipc_port);
+   cobalt_atomic_leave(s);
+   }
+   if (sk->bufpool != &cobalt_heap) {
+   poolmem = xnheap_get_membase(&sk->privpool);
+   poolsz = xnheap_get_size(&sk->privpool);
+   xnheap_destroy(&sk->privpool);
+   xnheap_vfree(poolmem);
+   return;
+   }
}
 
/* Send unread datagrams back to the system heap. */


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Jan Kiszka : cobalt/kernel: Return need_resched flag from xnsynch_release

2016-05-14 Thread git repository hosting
Module: xenomai-3
Branch: next
Commit: 3223ffec97a360ceb967d487a57e9a0a4ae31500
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=3223ffec97a360ceb967d487a57e9a0a4ae31500

Author: Jan Kiszka 
Date:   Mon May  9 21:19:04 2016 +0200

cobalt/kernel: Return need_resched flag from xnsynch_release

We currently return the next owner, but no caller of xnsynch_release
evaluates this beyond != NULL and calls xnsched_run in that case.
Simplify the API by returning a need_resched flag directly. This will
also help with fixing the missing reschedule after PP deboost.

Signed-off-by: Jan Kiszka 

---

 include/cobalt/kernel/synch.h |3 +--
 kernel/cobalt/posix/mutex.c   |2 +-
 kernel/cobalt/rtdm/drvlib.c   |2 +-
 kernel/cobalt/synch.c |   23 +++
 4 files changed, 14 insertions(+), 16 deletions(-)

diff --git a/include/cobalt/kernel/synch.h b/include/cobalt/kernel/synch.h
index 04d7f10..1e99c18 100644
--- a/include/cobalt/kernel/synch.h
+++ b/include/cobalt/kernel/synch.h
@@ -164,8 +164,7 @@ int xnsynch_acquire(struct xnsynch *synch,
 
 int xnsynch_try_acquire(struct xnsynch *synch);
 
-struct xnthread *xnsynch_release(struct xnsynch *synch,
-struct xnthread *thread);
+bool xnsynch_release(struct xnsynch *synch, struct xnthread *thread);
 
 struct xnthread *xnsynch_peek_pendq(struct xnsynch *synch);
 
diff --git a/kernel/cobalt/posix/mutex.c b/kernel/cobalt/posix/mutex.c
index c6020ff..f99874b 100644
--- a/kernel/cobalt/posix/mutex.c
+++ b/kernel/cobalt/posix/mutex.c
@@ -128,7 +128,7 @@ int cobalt_mutex_release(struct xnthread *curr,
cobalt_cond_deferred_signals(cond);
}
}
-   need_resched |= xnsynch_release(&mutex->synchbase, curr) != NULL;
+   need_resched |= xnsynch_release(&mutex->synchbase, curr);
 
return need_resched;
 }
diff --git a/kernel/cobalt/rtdm/drvlib.c b/kernel/cobalt/rtdm/drvlib.c
index ae55a4b..1973c37 100644
--- a/kernel/cobalt/rtdm/drvlib.c
+++ b/kernel/cobalt/rtdm/drvlib.c
@@ -1282,7 +1282,7 @@ void rtdm_mutex_unlock(rtdm_mutex_t *mutex)
trace_cobalt_driver_mutex_release(mutex);
 
if (unlikely(xnsynch_release(&mutex->synch_base,
-xnsched_current_thread()) != NULL))
+xnsched_current_thread(
xnsched_run();
 }
 EXPORT_SYMBOL_GPL(rtdm_mutex_unlock);
diff --git a/kernel/cobalt/synch.c b/kernel/cobalt/synch.c
index 976261d..d8b83d9 100644
--- a/kernel/cobalt/synch.c
+++ b/kernel/cobalt/synch.c
@@ -843,8 +843,8 @@ static inline void clear_pp_boost(struct xnsynch *synch,
drop_booster(synch, owner);
 }
 
-static struct xnthread *transfer_ownership(struct xnsynch *synch,
-  struct xnthread *lastowner)
+static bool transfer_ownership(struct xnsynch *synch,
+  struct xnthread *lastowner)
 {  /* nklock held, irqs off */
struct xnthread *nextowner;
xnhandle_t nextownerh;
@@ -859,7 +859,7 @@ static struct xnthread *transfer_ownership(struct xnsynch 
*synch,
if (list_empty(&synch->pendq)) {
synch->owner = NULL;
atomic_set(lockp, XN_NO_HANDLE);
-   return NULL;
+   return false;
}
 
nextowner = list_first_entry(&synch->pendq, struct xnthread, plink);
@@ -879,11 +879,11 @@ static struct xnthread *transfer_ownership(struct xnsynch 
*synch,
 
atomic_set(lockp, nextownerh);
 
-   return nextowner;
+   return true;
 }
 
 /**
- * @fn struct xnthread *xnsynch_release(struct xnsynch *synch, struct xnthread 
*curr)
+ * @fn bool xnsynch_release(struct xnsynch *synch, struct xnthread *curr)
  * @brief Release a resource and pass it to the next waiting thread.
  *
  * This service releases the ownership of the given synchronization
@@ -900,7 +900,7 @@ static struct xnthread *transfer_ownership(struct xnsynch 
*synch,
  * @param curr The descriptor address of the current thread, which
  * must own the object at the time of calling.
  *
- * @return The descriptor address of the unblocked thread.
+ * @return True if a reschedule is required.
  *
  * @sideeffect
  *
@@ -913,10 +913,9 @@ static struct xnthread *transfer_ownership(struct xnsynch 
*synch,
  *
  * @coretags{primary-only, might-switch}
  */
-struct xnthread *xnsynch_release(struct xnsynch *synch,
-struct xnthread *curr)
+bool xnsynch_release(struct xnsynch *synch, struct xnthread *curr)
 {
-   struct xnthread *nextowner = NULL;
+   bool need_resched = false;
xnhandle_t currh, h;
atomic_t *lockp;
spl_t s;
@@ -926,7 +925,7 @@ struct xnthread *xnsynch_release(struct xnsynch *synch,
trace_cobalt_synch_release(synch);
 
if (xnthread_put_resource(curr))
-   return NULL;
+   return false;
 
lockp = 

[Xenomai-git] Gilles Chanteperdrix : cobalt/timer: replace bheap with rbtree

2016-05-14 Thread git repository hosting
Module: xenomai-gch
Branch: next
Commit: 15a799e1edf1da86ad80b5d19cb6d3c704c6e614
URL:
http://git.xenomai.org/?p=xenomai-gch.git;a=commit;h=15a799e1edf1da86ad80b5d19cb6d3c704c6e614

Author: Gilles Chanteperdrix 
Date:   Sun Apr  3 22:47:55 2016 +0200

cobalt/timer: replace bheap with rbtree

make rbtree the default on x86_64, so that it gets tested.

---

 include/cobalt/kernel/Makefile.am |1 -
 include/cobalt/kernel/bheap.h |  266 -
 include/cobalt/kernel/timer.h |   80 ++-
 kernel/cobalt/Kconfig |   14 +-
 kernel/cobalt/clock.c |2 +-
 kernel/cobalt/timer.c |   34 -
 6 files changed, 87 insertions(+), 310 deletions(-)

diff --git a/include/cobalt/kernel/Makefile.am 
b/include/cobalt/kernel/Makefile.am
index 757675a..4d95702 100644
--- a/include/cobalt/kernel/Makefile.am
+++ b/include/cobalt/kernel/Makefile.am
@@ -4,7 +4,6 @@ noinst_HEADERS =\
apc.h   \
arith.h \
assert.h\
-   bheap.h \
bufd.h  \
clock.h \
compat.h\
diff --git a/include/cobalt/kernel/bheap.h b/include/cobalt/kernel/bheap.h
deleted file mode 100644
index 4c05bb4..000
--- a/include/cobalt/kernel/bheap.h
+++ /dev/null
@@ -1,266 +0,0 @@
-/*
- * Copyright (C) 2006 Gilles Chanteperdrix 
- *
- * Xenomai is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published
- * by the Free Software Foundation; either version 2 of the License,
- * or (at your option) any later version.
- *
- * Xenomai is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Xenomai; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-#ifndef _COBALT_KERNEL_BHEAP_H
-#define _COBALT_KERNEL_BHEAP_H
-
-/* debug support */
-#include 
-
-/* Priority queue implementation, using a binary heap. */
-
-typedef unsigned long long bheap_key_t;
-
-typedef struct bheaph {
-   bheap_key_t key;
-   unsigned prio;
-   unsigned pos;
-} bheaph_t;
-
-#define bheaph_init(holder) do { } while (0)
-#define bheaph_key(holder)  ((holder)->key)
-#define bheaph_prio(holder) ((holder)->prio)
-#define bheaph_pos(holder)  ((holder)->pos)
-#define bheaph_lt(h1, h2)   ((long long) ((h1)->key - (h2)->key) < 0 ||
\
-((h1)->key == (h2)->key && \
- (h1)->prio > (h2)->prio))
-
-typedef struct bheap {
-   unsigned sz;
-   unsigned last;
-   bheaph_t *elems[]; /* only padding, indexing starts at 1 */
-} bheap_t;
-
-#define DECLARE_BHEAP_CONTAINER(name, sz)   \
-   struct {\
-   bheap_t bheap;  \
-   bheaph_t *elems[sz + 1];\
-   } name
-
-/* Check the binary heap invariant. */
-static inline int bheap_ordered(bheap_t *heap)
-{
-   unsigned i;
-   for (i = 2; i < heap->last; i++)
-   if (bheaph_lt(heap->elems[i], heap->elems[i / 2]))
-   return 0;
-   return 1;
-}
-
-#define BHEAP_CHECK(heap)  \
-   XENO_BUG_ON(COBALT, ((heap)->sz == 0) || !bheap_ordered(heap))
-
-#define bheap_gethead(heap)\
-   ({  \
-   bheap_t *_bheap = &(heap)->bheap;   \
-   BHEAP_CHECK(_bheap);\
-   __internal_bheap_gethead(_bheap);   \
-   })
-
-static inline bheaph_t *__internal_bheap_gethead(bheap_t *heap)
-{
-   if (heap->last == 1)
-   return NULL;
-
-   return heap->elems[1];
-}
-
-#define bheap_second(heap) \
-   ({  \
-   bheap_t *_bheap = &(heap)->bheap;   \
-   BHEAP_CHECK(_bheap);\
-   __internal_bheap_second(_bheap);\
-   })
-
-#define bheap_next(heap, holder)   \
-   ({  \
-   bheap_t *_bheap = &(heap)->bheap;   \
-   BHEAP_CHECK(_bheap);\
-   __internal_bheap_next(_bheap, holder);  \
-   })
-
-static inline bheaph_t *__internal_bheap_next(bheap_t *heap, bheaph_t *holder)
-{
-   unsigned pos;
-
-   if (unlikely(bheaph_pos(holder) >= heap->last
-|| heap->elems[bheaph_pos(holder)] != holder))
-   return (bheaph_t *) ERR_PTR(-EINVAL);
-
-   pos = bheaph_pos

[Xenomai-git] Gilles Chanteperdrix : cobalt/timer: replace bheap with rbtree

2016-05-14 Thread git repository hosting
Module: xenomai-gch
Branch: stable-3.0.x
Commit: 04e0d12f17a0f0c41372818d5e2db6ced8dded3b
URL:
http://git.xenomai.org/?p=xenomai-gch.git;a=commit;h=04e0d12f17a0f0c41372818d5e2db6ced8dded3b

Author: Gilles Chanteperdrix 
Date:   Sun Apr  3 22:47:55 2016 +0200

cobalt/timer: replace bheap with rbtree

make rbtree the default on x86_64, so that it gets tested.

---

 include/cobalt/kernel/Makefile.am |1 -
 include/cobalt/kernel/bheap.h |  266 -
 include/cobalt/kernel/timer.h |   80 ++-
 kernel/cobalt/Kconfig |   14 +-
 kernel/cobalt/clock.c |2 +-
 kernel/cobalt/timer.c |   34 -
 6 files changed, 87 insertions(+), 310 deletions(-)

diff --git a/include/cobalt/kernel/Makefile.am 
b/include/cobalt/kernel/Makefile.am
index 757675a..4d95702 100644
--- a/include/cobalt/kernel/Makefile.am
+++ b/include/cobalt/kernel/Makefile.am
@@ -4,7 +4,6 @@ noinst_HEADERS =\
apc.h   \
arith.h \
assert.h\
-   bheap.h \
bufd.h  \
clock.h \
compat.h\
diff --git a/include/cobalt/kernel/bheap.h b/include/cobalt/kernel/bheap.h
deleted file mode 100644
index 4c05bb4..000
--- a/include/cobalt/kernel/bheap.h
+++ /dev/null
@@ -1,266 +0,0 @@
-/*
- * Copyright (C) 2006 Gilles Chanteperdrix 
- *
- * Xenomai is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published
- * by the Free Software Foundation; either version 2 of the License,
- * or (at your option) any later version.
- *
- * Xenomai is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Xenomai; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-#ifndef _COBALT_KERNEL_BHEAP_H
-#define _COBALT_KERNEL_BHEAP_H
-
-/* debug support */
-#include 
-
-/* Priority queue implementation, using a binary heap. */
-
-typedef unsigned long long bheap_key_t;
-
-typedef struct bheaph {
-   bheap_key_t key;
-   unsigned prio;
-   unsigned pos;
-} bheaph_t;
-
-#define bheaph_init(holder) do { } while (0)
-#define bheaph_key(holder)  ((holder)->key)
-#define bheaph_prio(holder) ((holder)->prio)
-#define bheaph_pos(holder)  ((holder)->pos)
-#define bheaph_lt(h1, h2)   ((long long) ((h1)->key - (h2)->key) < 0 ||
\
-((h1)->key == (h2)->key && \
- (h1)->prio > (h2)->prio))
-
-typedef struct bheap {
-   unsigned sz;
-   unsigned last;
-   bheaph_t *elems[]; /* only padding, indexing starts at 1 */
-} bheap_t;
-
-#define DECLARE_BHEAP_CONTAINER(name, sz)   \
-   struct {\
-   bheap_t bheap;  \
-   bheaph_t *elems[sz + 1];\
-   } name
-
-/* Check the binary heap invariant. */
-static inline int bheap_ordered(bheap_t *heap)
-{
-   unsigned i;
-   for (i = 2; i < heap->last; i++)
-   if (bheaph_lt(heap->elems[i], heap->elems[i / 2]))
-   return 0;
-   return 1;
-}
-
-#define BHEAP_CHECK(heap)  \
-   XENO_BUG_ON(COBALT, ((heap)->sz == 0) || !bheap_ordered(heap))
-
-#define bheap_gethead(heap)\
-   ({  \
-   bheap_t *_bheap = &(heap)->bheap;   \
-   BHEAP_CHECK(_bheap);\
-   __internal_bheap_gethead(_bheap);   \
-   })
-
-static inline bheaph_t *__internal_bheap_gethead(bheap_t *heap)
-{
-   if (heap->last == 1)
-   return NULL;
-
-   return heap->elems[1];
-}
-
-#define bheap_second(heap) \
-   ({  \
-   bheap_t *_bheap = &(heap)->bheap;   \
-   BHEAP_CHECK(_bheap);\
-   __internal_bheap_second(_bheap);\
-   })
-
-#define bheap_next(heap, holder)   \
-   ({  \
-   bheap_t *_bheap = &(heap)->bheap;   \
-   BHEAP_CHECK(_bheap);\
-   __internal_bheap_next(_bheap, holder);  \
-   })
-
-static inline bheaph_t *__internal_bheap_next(bheap_t *heap, bheaph_t *holder)
-{
-   unsigned pos;
-
-   if (unlikely(bheaph_pos(holder) >= heap->last
-|| heap->elems[bheaph_pos(holder)] != holder))
-   return (bheaph_t *) ERR_PTR(-EINVAL);
-
-   pos = bh

[Xenomai-git] Gilles Chanteperdrix : cobalt/timer: replace bheap with rbtree

2016-05-15 Thread git repository hosting
Module: xenomai-3
Branch: stable-3.0.x
Commit: 04e0d12f17a0f0c41372818d5e2db6ced8dded3b
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=04e0d12f17a0f0c41372818d5e2db6ced8dded3b

Author: Gilles Chanteperdrix 
Date:   Sun Apr  3 22:47:55 2016 +0200

cobalt/timer: replace bheap with rbtree

make rbtree the default on x86_64, so that it gets tested.

---

 include/cobalt/kernel/Makefile.am |1 -
 include/cobalt/kernel/bheap.h |  266 -
 include/cobalt/kernel/timer.h |   80 ++-
 kernel/cobalt/Kconfig |   14 +-
 kernel/cobalt/clock.c |2 +-
 kernel/cobalt/timer.c |   34 -
 6 files changed, 87 insertions(+), 310 deletions(-)

diff --git a/include/cobalt/kernel/Makefile.am 
b/include/cobalt/kernel/Makefile.am
index 757675a..4d95702 100644
--- a/include/cobalt/kernel/Makefile.am
+++ b/include/cobalt/kernel/Makefile.am
@@ -4,7 +4,6 @@ noinst_HEADERS =\
apc.h   \
arith.h \
assert.h\
-   bheap.h \
bufd.h  \
clock.h \
compat.h\
diff --git a/include/cobalt/kernel/bheap.h b/include/cobalt/kernel/bheap.h
deleted file mode 100644
index 4c05bb4..000
--- a/include/cobalt/kernel/bheap.h
+++ /dev/null
@@ -1,266 +0,0 @@
-/*
- * Copyright (C) 2006 Gilles Chanteperdrix 
- *
- * Xenomai is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published
- * by the Free Software Foundation; either version 2 of the License,
- * or (at your option) any later version.
- *
- * Xenomai is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Xenomai; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-#ifndef _COBALT_KERNEL_BHEAP_H
-#define _COBALT_KERNEL_BHEAP_H
-
-/* debug support */
-#include 
-
-/* Priority queue implementation, using a binary heap. */
-
-typedef unsigned long long bheap_key_t;
-
-typedef struct bheaph {
-   bheap_key_t key;
-   unsigned prio;
-   unsigned pos;
-} bheaph_t;
-
-#define bheaph_init(holder) do { } while (0)
-#define bheaph_key(holder)  ((holder)->key)
-#define bheaph_prio(holder) ((holder)->prio)
-#define bheaph_pos(holder)  ((holder)->pos)
-#define bheaph_lt(h1, h2)   ((long long) ((h1)->key - (h2)->key) < 0 ||
\
-((h1)->key == (h2)->key && \
- (h1)->prio > (h2)->prio))
-
-typedef struct bheap {
-   unsigned sz;
-   unsigned last;
-   bheaph_t *elems[]; /* only padding, indexing starts at 1 */
-} bheap_t;
-
-#define DECLARE_BHEAP_CONTAINER(name, sz)   \
-   struct {\
-   bheap_t bheap;  \
-   bheaph_t *elems[sz + 1];\
-   } name
-
-/* Check the binary heap invariant. */
-static inline int bheap_ordered(bheap_t *heap)
-{
-   unsigned i;
-   for (i = 2; i < heap->last; i++)
-   if (bheaph_lt(heap->elems[i], heap->elems[i / 2]))
-   return 0;
-   return 1;
-}
-
-#define BHEAP_CHECK(heap)  \
-   XENO_BUG_ON(COBALT, ((heap)->sz == 0) || !bheap_ordered(heap))
-
-#define bheap_gethead(heap)\
-   ({  \
-   bheap_t *_bheap = &(heap)->bheap;   \
-   BHEAP_CHECK(_bheap);\
-   __internal_bheap_gethead(_bheap);   \
-   })
-
-static inline bheaph_t *__internal_bheap_gethead(bheap_t *heap)
-{
-   if (heap->last == 1)
-   return NULL;
-
-   return heap->elems[1];
-}
-
-#define bheap_second(heap) \
-   ({  \
-   bheap_t *_bheap = &(heap)->bheap;   \
-   BHEAP_CHECK(_bheap);\
-   __internal_bheap_second(_bheap);\
-   })
-
-#define bheap_next(heap, holder)   \
-   ({  \
-   bheap_t *_bheap = &(heap)->bheap;   \
-   BHEAP_CHECK(_bheap);\
-   __internal_bheap_next(_bheap, holder);  \
-   })
-
-static inline bheaph_t *__internal_bheap_next(bheap_t *heap, bheaph_t *holder)
-{
-   unsigned pos;
-
-   if (unlikely(bheaph_pos(holder) >= heap->last
-|| heap->elems[bheaph_pos(holder)] != holder))
-   return (bheaph_t *) ERR_PTR(-EINVAL);
-
-   pos = bheaph

[Xenomai-git] Gilles Chanteperdrix : cobalt/timer: replace bheap with rbtree

2016-05-15 Thread git repository hosting
Module: xenomai-3
Branch: next
Commit: 15a799e1edf1da86ad80b5d19cb6d3c704c6e614
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=15a799e1edf1da86ad80b5d19cb6d3c704c6e614

Author: Gilles Chanteperdrix 
Date:   Sun Apr  3 22:47:55 2016 +0200

cobalt/timer: replace bheap with rbtree

make rbtree the default on x86_64, so that it gets tested.

---

 include/cobalt/kernel/Makefile.am |1 -
 include/cobalt/kernel/bheap.h |  266 -
 include/cobalt/kernel/timer.h |   80 ++-
 kernel/cobalt/Kconfig |   14 +-
 kernel/cobalt/clock.c |2 +-
 kernel/cobalt/timer.c |   34 -
 6 files changed, 87 insertions(+), 310 deletions(-)

diff --git a/include/cobalt/kernel/Makefile.am 
b/include/cobalt/kernel/Makefile.am
index 757675a..4d95702 100644
--- a/include/cobalt/kernel/Makefile.am
+++ b/include/cobalt/kernel/Makefile.am
@@ -4,7 +4,6 @@ noinst_HEADERS =\
apc.h   \
arith.h \
assert.h\
-   bheap.h \
bufd.h  \
clock.h \
compat.h\
diff --git a/include/cobalt/kernel/bheap.h b/include/cobalt/kernel/bheap.h
deleted file mode 100644
index 4c05bb4..000
--- a/include/cobalt/kernel/bheap.h
+++ /dev/null
@@ -1,266 +0,0 @@
-/*
- * Copyright (C) 2006 Gilles Chanteperdrix 
- *
- * Xenomai is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published
- * by the Free Software Foundation; either version 2 of the License,
- * or (at your option) any later version.
- *
- * Xenomai is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Xenomai; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-#ifndef _COBALT_KERNEL_BHEAP_H
-#define _COBALT_KERNEL_BHEAP_H
-
-/* debug support */
-#include 
-
-/* Priority queue implementation, using a binary heap. */
-
-typedef unsigned long long bheap_key_t;
-
-typedef struct bheaph {
-   bheap_key_t key;
-   unsigned prio;
-   unsigned pos;
-} bheaph_t;
-
-#define bheaph_init(holder) do { } while (0)
-#define bheaph_key(holder)  ((holder)->key)
-#define bheaph_prio(holder) ((holder)->prio)
-#define bheaph_pos(holder)  ((holder)->pos)
-#define bheaph_lt(h1, h2)   ((long long) ((h1)->key - (h2)->key) < 0 ||
\
-((h1)->key == (h2)->key && \
- (h1)->prio > (h2)->prio))
-
-typedef struct bheap {
-   unsigned sz;
-   unsigned last;
-   bheaph_t *elems[]; /* only padding, indexing starts at 1 */
-} bheap_t;
-
-#define DECLARE_BHEAP_CONTAINER(name, sz)   \
-   struct {\
-   bheap_t bheap;  \
-   bheaph_t *elems[sz + 1];\
-   } name
-
-/* Check the binary heap invariant. */
-static inline int bheap_ordered(bheap_t *heap)
-{
-   unsigned i;
-   for (i = 2; i < heap->last; i++)
-   if (bheaph_lt(heap->elems[i], heap->elems[i / 2]))
-   return 0;
-   return 1;
-}
-
-#define BHEAP_CHECK(heap)  \
-   XENO_BUG_ON(COBALT, ((heap)->sz == 0) || !bheap_ordered(heap))
-
-#define bheap_gethead(heap)\
-   ({  \
-   bheap_t *_bheap = &(heap)->bheap;   \
-   BHEAP_CHECK(_bheap);\
-   __internal_bheap_gethead(_bheap);   \
-   })
-
-static inline bheaph_t *__internal_bheap_gethead(bheap_t *heap)
-{
-   if (heap->last == 1)
-   return NULL;
-
-   return heap->elems[1];
-}
-
-#define bheap_second(heap) \
-   ({  \
-   bheap_t *_bheap = &(heap)->bheap;   \
-   BHEAP_CHECK(_bheap);\
-   __internal_bheap_second(_bheap);\
-   })
-
-#define bheap_next(heap, holder)   \
-   ({  \
-   bheap_t *_bheap = &(heap)->bheap;   \
-   BHEAP_CHECK(_bheap);\
-   __internal_bheap_next(_bheap, holder);  \
-   })
-
-static inline bheaph_t *__internal_bheap_next(bheap_t *heap, bheaph_t *holder)
-{
-   unsigned pos;
-
-   if (unlikely(bheaph_pos(holder) >= heap->last
-|| heap->elems[bheaph_pos(holder)] != holder))
-   return (bheaph_t *) ERR_PTR(-EINVAL);
-
-   pos = bheaph_pos(hol

[Xenomai-git] Jan Kiszka : cobalt/kernel: Introduce __SCHED_CURRENT policy to setschedparam_ex

2016-05-17 Thread git repository hosting
Module: xenomai-jki
Branch: for-forge
Commit: 3489d686f7f9b5fa1fc8ddb1559a0e391b28bc9a
URL:
http://git.xenomai.org/?p=xenomai-jki.git;a=commit;h=3489d686f7f9b5fa1fc8ddb1559a0e391b28bc9a

Author: Jan Kiszka 
Date:   Tue Mar  8 14:41:28 2016 +0100

cobalt/kernel: Introduce __SCHED_CURRENT policy to setschedparam_ex

Define the internal scheduling policy "current": it shall refer to the
target thread's current scheduling policy. This will allow to model
pthread_setschedprio on top of pthread_setschedparam_ex with only a
single syscall.

Signed-off-by: Jan Kiszka 

---

 include/cobalt/uapi/sched.h|3 +++
 kernel/cobalt/posix/thread.c   |   10 ++
 kernel/cobalt/trace/cobalt-posix.h |3 ++-
 3 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/include/cobalt/uapi/sched.h b/include/cobalt/uapi/sched.h
index b672095..2a1df44 100644
--- a/include/cobalt/uapi/sched.h
+++ b/include/cobalt/uapi/sched.h
@@ -21,6 +21,9 @@
 #define SCHED_COBALT   42
 #define SCHED_WEAK 43
 
+/* for internal use */
+#define __SCHED_CURRENT44
+
 #ifndef SCHED_SPORADIC
 #define SCHED_SPORADIC 10
 #define sched_ss_low_priority  sched_u.ss.__sched_low_priority
diff --git a/kernel/cobalt/posix/thread.c b/kernel/cobalt/posix/thread.c
index d87edb1..217b81b 100644
--- a/kernel/cobalt/posix/thread.c
+++ b/kernel/cobalt/posix/thread.c
@@ -242,6 +242,7 @@ struct xnthread_personality *cobalt_thread_finalize(struct 
xnthread *zombie)
 int __cobalt_thread_setschedparam_ex(struct cobalt_thread *thread, int policy,
 const struct sched_param_ex *param_ex)
 {
+   struct xnthread *base_thread = &thread->threadbase;
struct xnsched_class *sched_class;
union xnsched_policy_param param;
xnticks_t tslice;
@@ -256,6 +257,15 @@ int __cobalt_thread_setschedparam_ex(struct cobalt_thread 
*thread, int policy,
goto out;
}
 
+   if (policy == __SCHED_CURRENT) {
+   policy = base_thread->base_class->policy;
+   if (xnthread_base_priority(base_thread) == 0)
+   policy = SCHED_NORMAL;
+   else if (base_thread->base_class == &xnsched_class_rt &&
+xnthread_test_state(base_thread, XNRRB))
+   policy = SCHED_RR;
+   }
+
tslice = thread->threadbase.rrperiod;
sched_class = cobalt_sched_policy_param(¶m, policy,
param_ex, &tslice);
diff --git a/kernel/cobalt/trace/cobalt-posix.h 
b/kernel/cobalt/trace/cobalt-posix.h
index 3d0e20c..cc0eb05 100644
--- a/kernel/cobalt/trace/cobalt-posix.h
+++ b/kernel/cobalt/trace/cobalt-posix.h
@@ -90,7 +90,8 @@ DECLARE_EVENT_CLASS(syscall_exit,
 {SCHED_QUOTA, "quota"},\
 {SCHED_SPORADIC, "sporadic"},  \
 {SCHED_COBALT, "cobalt"},  \
-{SCHED_WEAK, "weak"})
+{SCHED_WEAK, "weak"},  \
+{__SCHED_CURRENT, ""})
 
 #define cobalt_print_sched_params(__policy, __p_ex)\
 ({ \


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Jan Kiszka : lib/cobalt: Wrap pthread_setschedprio for proper real-time support

2016-05-17 Thread git repository hosting
Module: xenomai-jki
Branch: for-forge
Commit: aae48a645c6638b297e9d1739ae299ca6a9ae20f
URL:
http://git.xenomai.org/?p=xenomai-jki.git;a=commit;h=aae48a645c6638b297e9d1739ae299ca6a9ae20f

Author: Jan Kiszka 
Date:   Tue Mar  8 14:46:59 2016 +0100

lib/cobalt: Wrap pthread_setschedprio for proper real-time support

Implement pthread_setschedprio on top of pthread_setschedparam_ex with
the help of the new __SCHED_CURRENT policy. This ensures that prio
changes are directly applied to the real-time core, and that with just
a single syscall.

Signed-off-by: Jan Kiszka 

---

 include/cobalt/pthread.h   |2 ++
 lib/cobalt/cobalt.wrappers |1 +
 lib/cobalt/thread.c|9 +
 lib/cobalt/wrappers.c  |6 ++
 4 files changed, 18 insertions(+)

diff --git a/include/cobalt/pthread.h b/include/cobalt/pthread.h
index f1b1c8a..3e9bd47 100644
--- a/include/cobalt/pthread.h
+++ b/include/cobalt/pthread.h
@@ -53,6 +53,8 @@ COBALT_DECL(int, pthread_setschedparam(pthread_t thread,
   int policy,
   const struct sched_param *param));
 
+COBALT_DECL(int, pthread_setschedprio(pthread_t thread, int prio));
+
 COBALT_DECL(int, pthread_mutex_init(pthread_mutex_t *mutex,
const pthread_mutexattr_t *attr));
 
diff --git a/lib/cobalt/cobalt.wrappers b/lib/cobalt/cobalt.wrappers
index 75f29d6..19153ae 100644
--- a/lib/cobalt/cobalt.wrappers
+++ b/lib/cobalt/cobalt.wrappers
@@ -2,6 +2,7 @@
 --wrap pthread_create
 --wrap pthread_setschedparam
 --wrap pthread_getschedparam
+--wrap pthread_setschedprio
 --wrap pthread_yield
 --wrap sched_yield
 --wrap sched_get_priority_min
diff --git a/lib/cobalt/thread.c b/lib/cobalt/thread.c
index 908516f..62ca0a0 100644
--- a/lib/cobalt/thread.c
+++ b/lib/cobalt/thread.c
@@ -650,6 +650,15 @@ int pthread_setschedparam_ex(pthread_t thread,
return ret;
 }
 
+COBALT_IMPL(int, pthread_setschedprio, (pthread_t thread, int prio))
+{
+   struct sched_param_ex param_ex = {
+   .sched_priority = prio,
+   };
+
+   return pthread_setschedparam_ex(thread, __SCHED_CURRENT, ¶m_ex);
+}
+
 /**
  * Get the scheduling policy and parameters of the specified thread.
  *
diff --git a/lib/cobalt/wrappers.c b/lib/cobalt/wrappers.c
index 09c74e5..1f1664e 100644
--- a/lib/cobalt/wrappers.c
+++ b/lib/cobalt/wrappers.c
@@ -60,6 +60,12 @@ int __real_pthread_getschedparam(pthread_t thread,
 }
 
 __weak
+int __real_pthread_setschedprio(pthread_t thread, int prio)
+{
+   return pthread_setschedprio(thread, prio);
+}
+
+__weak
 int __real_sched_yield(void)
 {
return sched_yield();


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Jan Kiszka : testsuite/smokey: Add test case for setschedparam & Co,

2016-05-17 Thread git repository hosting
Module: xenomai-jki
Branch: for-forge
Commit: fd200400b6d1aeb291a6d38a2e4aacbfe823422d
URL:
http://git.xenomai.org/?p=xenomai-jki.git;a=commit;h=fd200400b6d1aeb291a6d38a2e4aacbfe823422d

Author: Jan Kiszka 
Date:   Mon Feb 29 16:54:26 2016 +0100

testsuite/smokey: Add test case for setschedparam & Co,

This performs basic checks on the correct execution of scheduling
parameter changes from primary mode.

Signed-off-by: Jan Kiszka 

---

 configure.ac  |1 +
 testsuite/smokey/Makefile.am  |1 +
 testsuite/smokey/setsched/Makefile.am |9 +++
 testsuite/smokey/setsched/setsched.c  |  137 +
 4 files changed, 148 insertions(+)

diff --git a/configure.ac b/configure.ac
index cd9f047..667931a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -913,6 +913,7 @@ AC_CONFIG_FILES([ \
testsuite/smokey/arith/Makefile \
testsuite/smokey/sched-quota/Makefile \
testsuite/smokey/sched-tp/Makefile \
+   testsuite/smokey/setsched/Makefile \
testsuite/smokey/rtdm/Makefile \
testsuite/smokey/vdso-access/Makefile \
testsuite/smokey/posix-cond/Makefile \
diff --git a/testsuite/smokey/Makefile.am b/testsuite/smokey/Makefile.am
index 51292f1..e253d6f 100644
--- a/testsuite/smokey/Makefile.am
+++ b/testsuite/smokey/Makefile.am
@@ -24,6 +24,7 @@ COBALT_SUBDIRS =  \
rtdm\
sched-quota \
sched-tp\
+   setsched\
sigdebug\
timerfd \
tsc \
diff --git a/testsuite/smokey/setsched/Makefile.am 
b/testsuite/smokey/setsched/Makefile.am
new file mode 100644
index 000..8c0a59b
--- /dev/null
+++ b/testsuite/smokey/setsched/Makefile.am
@@ -0,0 +1,9 @@
+
+noinst_LIBRARIES = libsetsched.a
+
+libsetsched_a_SOURCES = setsched.c
+
+libsetsched_a_CPPFLAGS =   \
+   @XENO_USER_CFLAGS@  \
+   -I$(top_srcdir) \
+   -I$(top_srcdir)/include
diff --git a/testsuite/smokey/setsched/setsched.c 
b/testsuite/smokey/setsched/setsched.c
new file mode 100644
index 000..359f190
--- /dev/null
+++ b/testsuite/smokey/setsched/setsched.c
@@ -0,0 +1,137 @@
+/*
+ * Scheduler live-adjustment test.
+ *
+ * Copyright (c) Siemens AG 2016
+ *
+ * Authors:
+ *  Jan Kiszka 
+ *
+ * Released under the terms of GPLv2.
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+smokey_test_plugin(setsched, SMOKEY_NOARGS,
+   "Validate correct application of scheduling parameters to running threads."
+);
+
+static pid_t thread_pid;
+
+static void __check_linux_schedparams(int expected_policy, int expected_prio,
+ int line)
+{
+   struct sched_param linux_param;
+   int linux_policy;
+
+   linux_policy = syscall(SYS_sched_getscheduler, thread_pid);
+   if (smokey_check_status(syscall(SYS_sched_getparam, thread_pid,
+   &linux_param)))
+   pthread_exit((void *)(long)-EINVAL);
+
+   if (!smokey_assert(linux_policy == expected_policy) ||
+   !smokey_assert(linux_param.sched_priority == expected_prio)) {
+   smokey_warning("called from line %d", line);
+   pthread_exit((void *)(long)-EINVAL);
+   }
+}
+
+#define check_linux_schedparams(pol, prio) \
+   __check_linux_schedparams(pol, prio, __LINE__)
+
+static void __check_rt_schedparams(int expected_policy, int expected_prio,
+  int line)
+{
+   struct sched_param cobalt_param;
+   int cobalt_policy;
+
+   if (smokey_check_status(pthread_getschedparam(pthread_self(),
+ &cobalt_policy,
+ &cobalt_param)))
+   pthread_exit((void *)(long)-EINVAL);
+
+   if (!smokey_assert(cobalt_policy == expected_policy) ||
+   !smokey_assert(cobalt_param.sched_priority == expected_prio)) {
+   smokey_warning("called from line %d", line);
+   pthread_exit((void *)(long)-EINVAL);
+   }
+}
+
+#define check_rt_schedparams(pol, prio)\
+   __check_rt_schedparams(pol, prio, __LINE__)
+
+static void *thread_body(void *arg)
+{
+   struct cobalt_threadstat stats;
+   struct sched_param param;
+   unsigned long long msw;
+
+   thread_pid = syscall(SYS_gettid);
+
+   check_rt_schedparams(SCHED_FIFO, 1);
+   check_linux_schedparams(SCHED_FIFO, 1);
+
+   if (smokey_check_status(cobalt_thread_stat(thread_pid, &stats)))
+   pthread_exit((void *)(long)-EINVAL);
+   msw = stats.msw;
+
+   param.sched_priority = 2;
+   if (smokey_check_status(pthread_setschedparam(pthread_self(),
+ SCHED_FIFO, ¶m)))
+   pthread_exit((void *)(long)-EINVAL);
+
+   check_rt_schedparams(SCHED_FIFO, 2);
+
+ 

[Xenomai-git] Jan Kiszka : cobalt/kernel: Allow to restart clock_nanosleep and select after signal processing

2016-05-17 Thread git repository hosting
Module: xenomai-jki
Branch: for-forge
Commit: 29c69f003f41df94a1fc03c91d383ba728e05abd
URL:
http://git.xenomai.org/?p=xenomai-jki.git;a=commit;h=29c69f003f41df94a1fc03c91d383ba728e05abd

Author: Jan Kiszka 
Date:   Fri May 13 20:35:26 2016 +0200

cobalt/kernel: Allow to restart clock_nanosleep and select after signal 
processing

Only if a signal was actually delivered to a thread that was blocked on
sleep, [clock_]nanosleep or select, those calls should return -EINTR.
Otherwise, they should resume with the timeout, accordingly adjusted in
case of relative timeout. So far we returned -EINTR immediately which
particularly disturbed the debugging of applications (SIGSTOP/CONT
terminated those syscalls).

This approach reuses the Linux restart mechanism to find out if those
syscalls should be restarted or actually terminated after the signal
was handled: Linux sets current->restart_block.fn in case a termination
is required, unconditionally, thus also when the syscall did not return
ERESTART_RESTARTBLOCK. We also use the restart_block.nanosleep.expires
to transfer the remaining timeout to the restarted syscall.

We can't use the original restart mechanism of Linux because it directs
all ERESTART_RESTARTBLOCK through a special, Linux-only syscall. In our
case, we would have to migrate the caller in that context to primary in
order to resume the sleep, but this is not possible under Xenomai (we
need to migration from within the syscall hooks).

Signed-off-by: Jan Kiszka 

---

 include/cobalt/uapi/kernel/thread.h|1 +
 .../cobalt/include/asm-generic/xenomai/wrappers.h  |6 +++
 kernel/cobalt/posix/clock.c|   38 +--
 kernel/cobalt/posix/internal.h |2 +
 kernel/cobalt/posix/io.c   |   39 
 kernel/cobalt/posix/syscall.c  |5 +++
 6 files changed, 81 insertions(+), 10 deletions(-)

diff --git a/include/cobalt/uapi/kernel/thread.h 
b/include/cobalt/uapi/kernel/thread.h
index 8d26f16..1f1dca7 100644
--- a/include/cobalt/uapi/kernel/thread.h
+++ b/include/cobalt/uapi/kernel/thread.h
@@ -77,6 +77,7 @@
 
 #define XNMOVED   0x0001 /**< CPU migration in primary mode occurred */
 #define XNLBALERT 0x0002 /**< Scheduler lock break alert (SIGDEBUG sent) */
+#define XNRESTART 0x0004 /**< Thread awaiting syscall restart after signal 
*/
 
 /** @} */
 
diff --git a/kernel/cobalt/include/asm-generic/xenomai/wrappers.h 
b/kernel/cobalt/include/asm-generic/xenomai/wrappers.h
index 060ce85..0f9ab14 100644
--- a/kernel/cobalt/include/asm-generic/xenomai/wrappers.h
+++ b/kernel/cobalt/include/asm-generic/xenomai/wrappers.h
@@ -133,4 +133,10 @@ devm_hwmon_device_register_with_groups(struct device *dev, 
const char *name,
 #error "Xenomai/cobalt requires Linux kernel 3.10 or above"
 #endif /* < 3.10 */
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4,0,0)
+#define cobalt_get_restart_block(p)(&task_thread_info(p)->restart_block)
+#else
+#define cobalt_get_restart_block(p)(&(p)->restart_block)
+#endif
+
 #endif /* _COBALT_ASM_GENERIC_WRAPPERS_H */
diff --git a/kernel/cobalt/posix/clock.c b/kernel/cobalt/posix/clock.c
index b51cb4c..c977bf8 100644
--- a/kernel/cobalt/posix/clock.c
+++ b/kernel/cobalt/posix/clock.c
@@ -236,8 +236,9 @@ int __cobalt_clock_nanosleep(clockid_t clock_id, int flags,
 const struct timespec *rqt,
 struct timespec *rmt)
 {
+   struct restart_block *restart;
struct xnthread *cur;
-   xnsticks_t rem;
+   xnsticks_t timeout, rem;
int ret = 0;
spl_t s;
 
@@ -261,10 +262,41 @@ int __cobalt_clock_nanosleep(clockid_t clock_id, int 
flags,
 
xnlock_get_irqsave(&nklock, s);
 
-   xnthread_suspend(cur, XNDELAY, ts2ns(rqt) + 1,
+   if (xnthread_test_localinfo(cur, XNLBALERT)) {
+   xnthread_clear_localinfo(cur, XNLBALERT);
+
+   restart = cobalt_get_restart_block(current);
+
+   if (restart->fn != cobalt_restart_syscall_placeholder) {
+   xnlock_put_irqrestore(&nklock, s);
+
+   if (rmt)
+   ns2ts(rmt, rem > 1 ? rem : 0);
+   return -EINTR;
+   }
+
+   timeout = restart->nanosleep.expires;
+   } else
+   timeout = ts2ns(rqt);
+
+   xnthread_suspend(cur, XNDELAY, timeout + 1,
 clock_flag(flags, clock_id), NULL);
 
if (xnthread_test_info(cur, XNBREAK)) {
+   if (signal_pending(current)) {
+   xnthread_set_localinfo(cur, XNLBALERT);
+
+   restart = cobalt_get_restart_block(current);
+   restart->fn = cobalt_restart_syscall_placeholder;
+   restart->nanosleep.expires =
+   (flags & TIMER_ABSTIME) ? timeout :
+   

[Xenomai-git] Jan Kiszka : cobalt/kernel: Fix xntimer_get_timeout_stopped

2016-05-17 Thread git repository hosting
Module: xenomai-jki
Branch: for-forge
Commit: d5c1e0b00ac571a5bfcee48dd2f4bbb5de706e77
URL:
http://git.xenomai.org/?p=xenomai-jki.git;a=commit;h=d5c1e0b00ac571a5bfcee48dd2f4bbb5de706e77

Author: Jan Kiszka 
Date:   Thu May 12 21:02:40 2016 +0200

cobalt/kernel: Fix xntimer_get_timeout_stopped

xntimer_get_timeout_stopped just called into xntimer_get_timeout, but
the latter returned XN_INFINITE for stopped timers. Restore the desired
behavior from Xenomai 2.

Signed-off-by: Jan Kiszka 

---

 include/cobalt/kernel/timer.h |   12 ++--
 kernel/cobalt/timer.c |7 ++-
 2 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/include/cobalt/kernel/timer.h b/include/cobalt/kernel/timer.h
index 9f85985..f45a753 100644
--- a/include/cobalt/kernel/timer.h
+++ b/include/cobalt/kernel/timer.h
@@ -474,7 +474,7 @@ void __xntimer_stop(struct xntimer *timer);
 
 xnticks_t xntimer_get_date(struct xntimer *timer);
 
-xnticks_t xntimer_get_timeout(struct xntimer *timer);
+xnticks_t __xntimer_get_timeout(struct xntimer *timer);
 
 xnticks_t xntimer_get_interval(struct xntimer *timer);
 
@@ -486,9 +486,17 @@ static inline void xntimer_stop(struct xntimer *timer)
__xntimer_stop(timer);
 }
 
+static inline xnticks_t xntimer_get_timeout(struct xntimer *timer)
+{
+   if (!xntimer_running_p(timer))
+   return XN_INFINITE;
+
+   return __xntimer_get_timeout(timer);
+}
+
 static inline xnticks_t xntimer_get_timeout_stopped(struct xntimer *timer)
 {
-   return xntimer_get_timeout(timer);
+   return __xntimer_get_timeout(timer);
 }
 
 static inline void xntimer_enqueue(struct xntimer *timer,
diff --git a/kernel/cobalt/timer.c b/kernel/cobalt/timer.c
index bc5893d..c1a2081 100644
--- a/kernel/cobalt/timer.c
+++ b/kernel/cobalt/timer.c
@@ -266,14 +266,11 @@ EXPORT_SYMBOL_GPL(xntimer_get_date);
  *
  * @coretags{unrestricted, atomic-entry}
  */
-xnticks_t xntimer_get_timeout(struct xntimer *timer)
+xnticks_t __xntimer_get_timeout(struct xntimer *timer)
 {
struct xnclock *clock;
xnticks_t expiry, now;
 
-   if (!xntimer_running_p(timer))
-   return XN_INFINITE;
-
clock = xntimer_clock(timer);
now = xnclock_read_raw(clock);
expiry = xntimer_expiry(timer);
@@ -282,7 +279,7 @@ xnticks_t xntimer_get_timeout(struct xntimer *timer)
 
return xnclock_ticks_to_ns(clock, expiry - now);
 }
-EXPORT_SYMBOL_GPL(xntimer_get_timeout);
+EXPORT_SYMBOL_GPL(__xntimer_get_timeout);
 
 /**
  * @fn void xntimer_init(struct xntimer *timer,struct xnclock *clock,void 
(*handler)(struct xntimer *timer), struct xnsched *sched, int flags)


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Jan Kiszka : cobalt/kernel: Fix xntimer_get_timeout_stopped

2016-05-17 Thread git repository hosting
Module: xenomai-3
Branch: stable-3.0.x
Commit: 3e1ee65647cf24fef7bd66f82b0be9060907f2fe
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=3e1ee65647cf24fef7bd66f82b0be9060907f2fe

Author: Jan Kiszka 
Date:   Thu May 12 21:02:40 2016 +0200

cobalt/kernel: Fix xntimer_get_timeout_stopped

xntimer_get_timeout_stopped just called into xntimer_get_timeout, but
the latter returned XN_INFINITE for stopped timers. Restore the desired
behavior from Xenomai 2.

Signed-off-by: Jan Kiszka 

---

 include/cobalt/kernel/timer.h |   12 ++--
 kernel/cobalt/timer.c |7 ++-
 2 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/include/cobalt/kernel/timer.h b/include/cobalt/kernel/timer.h
index 9f85985..f45a753 100644
--- a/include/cobalt/kernel/timer.h
+++ b/include/cobalt/kernel/timer.h
@@ -474,7 +474,7 @@ void __xntimer_stop(struct xntimer *timer);
 
 xnticks_t xntimer_get_date(struct xntimer *timer);
 
-xnticks_t xntimer_get_timeout(struct xntimer *timer);
+xnticks_t __xntimer_get_timeout(struct xntimer *timer);
 
 xnticks_t xntimer_get_interval(struct xntimer *timer);
 
@@ -486,9 +486,17 @@ static inline void xntimer_stop(struct xntimer *timer)
__xntimer_stop(timer);
 }
 
+static inline xnticks_t xntimer_get_timeout(struct xntimer *timer)
+{
+   if (!xntimer_running_p(timer))
+   return XN_INFINITE;
+
+   return __xntimer_get_timeout(timer);
+}
+
 static inline xnticks_t xntimer_get_timeout_stopped(struct xntimer *timer)
 {
-   return xntimer_get_timeout(timer);
+   return __xntimer_get_timeout(timer);
 }
 
 static inline void xntimer_enqueue(struct xntimer *timer,
diff --git a/kernel/cobalt/timer.c b/kernel/cobalt/timer.c
index bc5893d..c1a2081 100644
--- a/kernel/cobalt/timer.c
+++ b/kernel/cobalt/timer.c
@@ -266,14 +266,11 @@ EXPORT_SYMBOL_GPL(xntimer_get_date);
  *
  * @coretags{unrestricted, atomic-entry}
  */
-xnticks_t xntimer_get_timeout(struct xntimer *timer)
+xnticks_t __xntimer_get_timeout(struct xntimer *timer)
 {
struct xnclock *clock;
xnticks_t expiry, now;
 
-   if (!xntimer_running_p(timer))
-   return XN_INFINITE;
-
clock = xntimer_clock(timer);
now = xnclock_read_raw(clock);
expiry = xntimer_expiry(timer);
@@ -282,7 +279,7 @@ xnticks_t xntimer_get_timeout(struct xntimer *timer)
 
return xnclock_ticks_to_ns(clock, expiry - now);
 }
-EXPORT_SYMBOL_GPL(xntimer_get_timeout);
+EXPORT_SYMBOL_GPL(__xntimer_get_timeout);
 
 /**
  * @fn void xntimer_init(struct xntimer *timer,struct xnclock *clock,void 
(*handler)(struct xntimer *timer), struct xnsched *sched, int flags)


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Jan Kiszka : cobalt/kernel: Fix xntimer_get_timeout_stopped

2016-05-17 Thread git repository hosting
Module: xenomai-3
Branch: next
Commit: 3645c68ea889c255d9873ce1c4c97b35450fd059
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=3645c68ea889c255d9873ce1c4c97b35450fd059

Author: Jan Kiszka 
Date:   Thu May 12 21:02:40 2016 +0200

cobalt/kernel: Fix xntimer_get_timeout_stopped

xntimer_get_timeout_stopped just called into xntimer_get_timeout, but
the latter returned XN_INFINITE for stopped timers. Restore the desired
behavior from Xenomai 2.

Signed-off-by: Jan Kiszka 

---

 include/cobalt/kernel/timer.h |   12 ++--
 kernel/cobalt/timer.c |7 ++-
 2 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/include/cobalt/kernel/timer.h b/include/cobalt/kernel/timer.h
index 9f85985..f45a753 100644
--- a/include/cobalt/kernel/timer.h
+++ b/include/cobalt/kernel/timer.h
@@ -474,7 +474,7 @@ void __xntimer_stop(struct xntimer *timer);
 
 xnticks_t xntimer_get_date(struct xntimer *timer);
 
-xnticks_t xntimer_get_timeout(struct xntimer *timer);
+xnticks_t __xntimer_get_timeout(struct xntimer *timer);
 
 xnticks_t xntimer_get_interval(struct xntimer *timer);
 
@@ -486,9 +486,17 @@ static inline void xntimer_stop(struct xntimer *timer)
__xntimer_stop(timer);
 }
 
+static inline xnticks_t xntimer_get_timeout(struct xntimer *timer)
+{
+   if (!xntimer_running_p(timer))
+   return XN_INFINITE;
+
+   return __xntimer_get_timeout(timer);
+}
+
 static inline xnticks_t xntimer_get_timeout_stopped(struct xntimer *timer)
 {
-   return xntimer_get_timeout(timer);
+   return __xntimer_get_timeout(timer);
 }
 
 static inline void xntimer_enqueue(struct xntimer *timer,
diff --git a/kernel/cobalt/timer.c b/kernel/cobalt/timer.c
index bc5893d..c1a2081 100644
--- a/kernel/cobalt/timer.c
+++ b/kernel/cobalt/timer.c
@@ -266,14 +266,11 @@ EXPORT_SYMBOL_GPL(xntimer_get_date);
  *
  * @coretags{unrestricted, atomic-entry}
  */
-xnticks_t xntimer_get_timeout(struct xntimer *timer)
+xnticks_t __xntimer_get_timeout(struct xntimer *timer)
 {
struct xnclock *clock;
xnticks_t expiry, now;
 
-   if (!xntimer_running_p(timer))
-   return XN_INFINITE;
-
clock = xntimer_clock(timer);
now = xnclock_read_raw(clock);
expiry = xntimer_expiry(timer);
@@ -282,7 +279,7 @@ xnticks_t xntimer_get_timeout(struct xntimer *timer)
 
return xnclock_ticks_to_ns(clock, expiry - now);
 }
-EXPORT_SYMBOL_GPL(xntimer_get_timeout);
+EXPORT_SYMBOL_GPL(__xntimer_get_timeout);
 
 /**
  * @fn void xntimer_init(struct xntimer *timer,struct xnclock *clock,void 
(*handler)(struct xntimer *timer), struct xnsched *sched, int flags)


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : cobalt/rtdm: reinit driver magic after unregistration

2016-05-17 Thread git repository hosting
Module: xenomai-3
Branch: wip/dovetail
Commit: c58299dd82a52d6a144dc3585bfa990a4966
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=c58299dd82a52d6a144dc3585bfa990a4966

Author: Philippe Gerum 
Date:   Tue May  3 10:06:11 2016 +0200

cobalt/rtdm: reinit driver magic after unregistration

Failing to do so would prevent the driver to be properly registered
again.

---

 kernel/cobalt/rtdm/device.c |4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/kernel/cobalt/rtdm/device.c b/kernel/cobalt/rtdm/device.c
index 46b7965..aa62169 100644
--- a/kernel/cobalt/rtdm/device.c
+++ b/kernel/cobalt/rtdm/device.c
@@ -325,7 +325,9 @@ static void unregister_driver(struct rtdm_driver *drv)
XENO_BUG_ON(COBALT, drv->profile_info.magic != RTDM_CLASS_MAGIC);
 
cobalt_remove_state_chain(&drv->nb_statechange);
-   
+
+   drv->profile_info.magic = ~RTDM_CLASS_MAGIC;
+
if (drv->device_flags & RTDM_NAMED_DEVICE) {
cdev_del(&drv->named.cdev);
unregister_chrdev_region(MKDEV(drv->named.major, 0),


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : rtipc/bufp: fix cleanup on binding error

2016-05-17 Thread git repository hosting
Module: xenomai-3
Branch: wip/dovetail
Commit: a783d3db5e420b5174a213da210c7e287de9f500
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=a783d3db5e420b5174a213da210c7e287de9f500

Author: Philippe Gerum 
Date:   Sat May 14 15:20:21 2016 +0200

rtipc/bufp: fix cleanup on binding error

---

 kernel/drivers/ipc/bufp.c |   20 +++-
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/kernel/drivers/ipc/bufp.c b/kernel/drivers/ipc/bufp.c
index 6fc51d4..f129eaa 100644
--- a/kernel/drivers/ipc/bufp.c
+++ b/kernel/drivers/ipc/bufp.c
@@ -138,17 +138,19 @@ static void bufp_close(struct rtdm_fd *fd)
rtdm_event_destroy(&sk->i_event);
rtdm_event_destroy(&sk->o_event);
 
-   if (sk->name.sipc_port > -1) {
-   cobalt_atomic_enter(s);
-   xnmap_remove(portmap, sk->name.sipc_port);
-   cobalt_atomic_leave(s);
-   }
+   if (test_bit(_BUFP_BOUND, &sk->status)) {
+   if (sk->name.sipc_port > -1) {
+   cobalt_atomic_enter(s);
+   xnmap_remove(portmap, sk->name.sipc_port);
+   cobalt_atomic_leave(s);
+   }
 
-   if (sk->handle)
-   xnregistry_remove(sk->handle);
+   if (sk->handle)
+   xnregistry_remove(sk->handle);
 
-   if (sk->bufmem)
-   xnheap_vfree(sk->bufmem);
+   if (sk->bufmem)
+   xnheap_vfree(sk->bufmem);
+   }
 
kfree(sk);
 }


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : testsuite/smokey: include errno dependency explicitly

2016-05-17 Thread git repository hosting
Module: xenomai-3
Branch: wip/dovetail
Commit: 7b61945d8eb022a04bbffcb9527c0c7a4405c92d
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=7b61945d8eb022a04bbffcb9527c0c7a4405c92d

Author: Philippe Gerum 
Date:   Sat Apr 30 19:03:03 2016 +0200

testsuite/smokey: include errno dependency explicitly

---

 testsuite/smokey/main.c |1 +
 1 file changed, 1 insertion(+)

diff --git a/testsuite/smokey/main.c b/testsuite/smokey/main.c
index 02ccc83..12321df 100644
--- a/testsuite/smokey/main.c
+++ b/testsuite/smokey/main.c
@@ -17,6 +17,7 @@
  */
 #include 
 #include 
+#include 
 #include 
 
 int main(int argc, char *const argv[])


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : cobalt/rtdm: zero-init the private context area

2016-05-17 Thread git repository hosting
Module: xenomai-3
Branch: wip/dovetail
Commit: 7cc5c68c085d017183e4d6d91cfa9a59f025b0e6
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=7cc5c68c085d017183e4d6d91cfa9a59f025b0e6

Author: Philippe Gerum 
Date:   Tue May  3 12:16:29 2016 +0200

cobalt/rtdm: zero-init the private context area

---

 include/cobalt/kernel/rtdm/driver.h |9 -
 kernel/cobalt/rtdm/core.c   |2 +-
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/include/cobalt/kernel/rtdm/driver.h 
b/include/cobalt/kernel/rtdm/driver.h
index edd92ee..1354d9a 100644
--- a/include/cobalt/kernel/rtdm/driver.h
+++ b/include/cobalt/kernel/rtdm/driver.h
@@ -258,7 +258,14 @@ struct rtdm_driver {
 * @anchor rtdm_driver_flags
 */
int device_flags;
-   /** Size of driver defined appendix to struct rtdm_dev_context */
+   /**
+* Size of the private memory area the core should
+* automatically allocate for each open file descriptor, which
+* is usable for storing the context data associated to each
+* connection. The allocated memory is zero-initialized. The
+* start of this area can be retrieved by a call to
+* rtdm_fd_to_private().
+*/
size_t context_size;
/** Protocol device identification: protocol family (PF_xxx) */
int protocol_family;
diff --git a/kernel/cobalt/rtdm/core.c b/kernel/cobalt/rtdm/core.c
index 0f68e77..05f273f 100644
--- a/kernel/cobalt/rtdm/core.c
+++ b/kernel/cobalt/rtdm/core.c
@@ -86,7 +86,7 @@ static int create_instance(int ufd, struct rtdm_device *dev,
atomic_read(&dev->refcount) > 1)
return -EBUSY;
 
-   context = kmalloc(sizeof(struct rtdm_dev_context) +
+   context = kzalloc(sizeof(struct rtdm_dev_context) +
  drv->context_size, GFP_KERNEL);
if (unlikely(context == NULL))
return -ENOMEM;


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : alchemy/queue: allow zero-size message with rt_queue_write()

2016-05-17 Thread git repository hosting
Module: xenomai-3
Branch: wip/dovetail
Commit: 32c7bdc249f48122fc2a15cade98fdfffad04cf4
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=32c7bdc249f48122fc2a15cade98fdfffad04cf4

Author: Philippe Gerum 
Date:   Sat Apr 30 17:41:18 2016 +0200

alchemy/queue: allow zero-size message with rt_queue_write()

---

 lib/alchemy/queue.c |8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/lib/alchemy/queue.c b/lib/alchemy/queue.c
index 34a35f5..eb4bd19 100644
--- a/lib/alchemy/queue.c
+++ b/lib/alchemy/queue.c
@@ -630,10 +630,7 @@ int rt_queue_write(RT_QUEUE *queue,
if (mode & ~(Q_URGENT|Q_BROADCAST))
return -EINVAL;
 
-   if (size == 0)
-   return 0;
-
-   if (buf == NULL)
+   if (buf == NULL && size > 0)
return -EINVAL;
 
CANCEL_DEFER(svc);
@@ -683,7 +680,8 @@ enqueue:
 
msg->size = size;
msg->refcount = 0;
-   memcpy(msg + 1, buf, size);
+   if (size > 0)
+   memcpy(msg + 1, buf, size);
 
ret = 0;  /* # of tasks unblocked. */
if (nwaiters == 0) {


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Jan Kiszka : cobalt/kernel: Trigger missing reschedule after PP deboost

2016-05-17 Thread git repository hosting
Module: xenomai-3
Branch: wip/dovetail
Commit: 73141639fc3902382dfcccdf30dc9023cbc0caa5
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=73141639fc3902382dfcccdf30dc9023cbc0caa5

Author: Jan Kiszka 
Date:   Mon May  9 21:22:23 2016 +0200

cobalt/kernel: Trigger missing reschedule after PP deboost

xnsynch_release also needs to tell the caller about the potential need
for a reschedule after deboosting for prio-protection.

Signed-off-by: Jan Kiszka 

---

 kernel/cobalt/synch.c |4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/kernel/cobalt/synch.c b/kernel/cobalt/synch.c
index d8b83d9..f3b70a2 100644
--- a/kernel/cobalt/synch.c
+++ b/kernel/cobalt/synch.c
@@ -949,8 +949,10 @@ bool xnsynch_release(struct xnsynch *synch, struct 
xnthread *curr)
else if (h != currh)/* FLCEIL set, FLCLAIM clear. */
atomic_set(lockp, XN_NO_HANDLE);
 
-   if (synch->status & XNSYNCH_PP)
+   if (synch->status & XNSYNCH_PP) {
clear_pp_boost(synch, curr);
+   need_resched = true;
+   }
 
xnlock_put_irqrestore(&nklock, s);
 


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : cobalt/registry: allow slash in keys without /proc node

2016-05-17 Thread git repository hosting
Module: xenomai-3
Branch: wip/dovetail
Commit: a1cbf0ee6dc5dd08c96c13b79ddc49e85a25dc86
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=a1cbf0ee6dc5dd08c96c13b79ddc49e85a25dc86

Author: Philippe Gerum 
Date:   Sat Apr 30 15:06:02 2016 +0200

cobalt/registry: allow slash in keys without /proc node

---

 kernel/cobalt/registry.c |   12 
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/kernel/cobalt/registry.c b/kernel/cobalt/registry.c
index 9d14863..ed8a37f 100644
--- a/kernel/cobalt/registry.c
+++ b/kernel/cobalt/registry.c
@@ -595,7 +595,8 @@ static inline int registry_wakeup_sleepers(const char *key)
  * that such key is stored into the registered object, it will *not*
  * be copied but only kept by reference in the registry. Pass an empty
  * or NULL string if the object shall only occupy a registry slot for
- * handle-based lookups.
+ * handle-based lookups. The slash character is not accepted in @a key
+ * if @a pnode is non-NULL.
  *
  * @param objaddr An opaque pointer to the object to index by @a
  * key.
@@ -613,8 +614,10 @@ static inline int registry_wakeup_sleepers(const char *key)
  *
  * @return 0 is returned upon success. Otherwise:
  *
- * - -EINVAL is returned if @a objaddr is NULL, or if @a key is
- * non-NULL and contains an invalid '/' character.
+ * - -EINVAL is returned if @a objaddr is NULL.
+ *
+ * - -EINVAL if @a pnode is non-NULL, and @a key points to a valid
+ * string containing a '/' character.
  *
  * - -ENOMEM is returned if the system fails to get enough dynamic
  * memory from the global real-time heap in order to register the
@@ -631,7 +634,8 @@ int xnregistry_enter(const char *key, void *objaddr,
spl_t s;
int ret;
 
-   if (objaddr == NULL || (key != NULL && strchr(key, '/')))
+   if (objaddr == NULL ||
+   (pnode != NULL && key != NULL && strchr(key, '/')))
return -EINVAL;
 
xnlock_get_irqsave(&nklock, s);


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : rtipc/iddp: fix cleanup on binding error

2016-05-17 Thread git repository hosting
Module: xenomai-3
Branch: wip/dovetail
Commit: 3febc57edec5fa87ee8c145455c72b67ea3843ab
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=3febc57edec5fa87ee8c145455c72b67ea3843ab

Author: Philippe Gerum 
Date:   Sat May 14 15:20:34 2016 +0200

rtipc/iddp: fix cleanup on binding error

---

 kernel/drivers/ipc/iddp.c |   30 +++---
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/kernel/drivers/ipc/iddp.c b/kernel/drivers/ipc/iddp.c
index 59508f6..028e40a 100644
--- a/kernel/drivers/ipc/iddp.c
+++ b/kernel/drivers/ipc/iddp.c
@@ -192,24 +192,24 @@ static void iddp_close(struct rtdm_fd *fd)
void *poolmem;
u32 poolsz;
 
-   if (sk->name.sipc_port > -1) {
-   cobalt_atomic_enter(s);
-   xnmap_remove(portmap, sk->name.sipc_port);
-   cobalt_atomic_leave(s);
-   }
-
rtdm_sem_destroy(&sk->insem);
rtdm_waitqueue_destroy(&sk->privwaitq);
 
-   if (sk->handle)
-   xnregistry_remove(sk->handle);
-
-   if (sk->bufpool != &cobalt_heap) {
-   poolmem = xnheap_get_membase(&sk->privpool);
-   poolsz = xnheap_get_size(&sk->privpool);
-   xnheap_destroy(&sk->privpool);
-   xnheap_vfree(poolmem);
-   return;
+   if (test_bit(_IDDP_BOUND, &sk->status)) {
+   if (sk->handle)
+   xnregistry_remove(sk->handle);
+   if (sk->name.sipc_port > -1) {
+   cobalt_atomic_enter(s);
+   xnmap_remove(portmap, sk->name.sipc_port);
+   cobalt_atomic_leave(s);
+   }
+   if (sk->bufpool != &cobalt_heap) {
+   poolmem = xnheap_get_membase(&sk->privpool);
+   poolsz = xnheap_get_size(&sk->privpool);
+   xnheap_destroy(&sk->privpool);
+   xnheap_vfree(poolmem);
+   return;
+   }
}
 
/* Send unread datagrams back to the system heap. */


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Jan Kiszka : cobalt/kernel: Null-terminate cobalt_print_sched_params output

2016-05-17 Thread git repository hosting
Module: xenomai-3
Branch: wip/dovetail
Commit: 7fd91d4d9de6704c4975fcd989faca457f72b9a7
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=7fd91d4d9de6704c4975fcd989faca457f72b9a7

Author: Jan Kiszka 
Date:   Fri May  6 10:42:27 2016 +0200

cobalt/kernel: Null-terminate cobalt_print_sched_params output

Using trace_seq_printf requires to terminate the generated string with
0, or we print additional garbage.

Signed-off-by: Jan Kiszka 

---

 kernel/cobalt/trace/cobalt-posix.h |1 +
 1 file changed, 1 insertion(+)

diff --git a/kernel/cobalt/trace/cobalt-posix.h 
b/kernel/cobalt/trace/cobalt-posix.h
index 92f7245..3d0e20c 100644
--- a/kernel/cobalt/trace/cobalt-posix.h
+++ b/kernel/cobalt/trace/cobalt-posix.h
@@ -129,6 +129,7 @@ DECLARE_EVENT_CLASS(syscall_exit,
 (__p_ex)->sched_priority); \
break;  \
}   \
+   trace_seq_putc(p, '\0');\
__ret;  \
 })
 


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Gilles Chanteperdrix : cobalt/timer: replace bheap with rbtree

2016-05-17 Thread git repository hosting
Module: xenomai-3
Branch: wip/dovetail
Commit: 15a799e1edf1da86ad80b5d19cb6d3c704c6e614
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=15a799e1edf1da86ad80b5d19cb6d3c704c6e614

Author: Gilles Chanteperdrix 
Date:   Sun Apr  3 22:47:55 2016 +0200

cobalt/timer: replace bheap with rbtree

make rbtree the default on x86_64, so that it gets tested.

---

 include/cobalt/kernel/Makefile.am |1 -
 include/cobalt/kernel/bheap.h |  266 -
 include/cobalt/kernel/timer.h |   80 ++-
 kernel/cobalt/Kconfig |   14 +-
 kernel/cobalt/clock.c |2 +-
 kernel/cobalt/timer.c |   34 -
 6 files changed, 87 insertions(+), 310 deletions(-)

diff --git a/include/cobalt/kernel/Makefile.am 
b/include/cobalt/kernel/Makefile.am
index 757675a..4d95702 100644
--- a/include/cobalt/kernel/Makefile.am
+++ b/include/cobalt/kernel/Makefile.am
@@ -4,7 +4,6 @@ noinst_HEADERS =\
apc.h   \
arith.h \
assert.h\
-   bheap.h \
bufd.h  \
clock.h \
compat.h\
diff --git a/include/cobalt/kernel/bheap.h b/include/cobalt/kernel/bheap.h
deleted file mode 100644
index 4c05bb4..000
--- a/include/cobalt/kernel/bheap.h
+++ /dev/null
@@ -1,266 +0,0 @@
-/*
- * Copyright (C) 2006 Gilles Chanteperdrix 
- *
- * Xenomai is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published
- * by the Free Software Foundation; either version 2 of the License,
- * or (at your option) any later version.
- *
- * Xenomai is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Xenomai; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-#ifndef _COBALT_KERNEL_BHEAP_H
-#define _COBALT_KERNEL_BHEAP_H
-
-/* debug support */
-#include 
-
-/* Priority queue implementation, using a binary heap. */
-
-typedef unsigned long long bheap_key_t;
-
-typedef struct bheaph {
-   bheap_key_t key;
-   unsigned prio;
-   unsigned pos;
-} bheaph_t;
-
-#define bheaph_init(holder) do { } while (0)
-#define bheaph_key(holder)  ((holder)->key)
-#define bheaph_prio(holder) ((holder)->prio)
-#define bheaph_pos(holder)  ((holder)->pos)
-#define bheaph_lt(h1, h2)   ((long long) ((h1)->key - (h2)->key) < 0 ||
\
-((h1)->key == (h2)->key && \
- (h1)->prio > (h2)->prio))
-
-typedef struct bheap {
-   unsigned sz;
-   unsigned last;
-   bheaph_t *elems[]; /* only padding, indexing starts at 1 */
-} bheap_t;
-
-#define DECLARE_BHEAP_CONTAINER(name, sz)   \
-   struct {\
-   bheap_t bheap;  \
-   bheaph_t *elems[sz + 1];\
-   } name
-
-/* Check the binary heap invariant. */
-static inline int bheap_ordered(bheap_t *heap)
-{
-   unsigned i;
-   for (i = 2; i < heap->last; i++)
-   if (bheaph_lt(heap->elems[i], heap->elems[i / 2]))
-   return 0;
-   return 1;
-}
-
-#define BHEAP_CHECK(heap)  \
-   XENO_BUG_ON(COBALT, ((heap)->sz == 0) || !bheap_ordered(heap))
-
-#define bheap_gethead(heap)\
-   ({  \
-   bheap_t *_bheap = &(heap)->bheap;   \
-   BHEAP_CHECK(_bheap);\
-   __internal_bheap_gethead(_bheap);   \
-   })
-
-static inline bheaph_t *__internal_bheap_gethead(bheap_t *heap)
-{
-   if (heap->last == 1)
-   return NULL;
-
-   return heap->elems[1];
-}
-
-#define bheap_second(heap) \
-   ({  \
-   bheap_t *_bheap = &(heap)->bheap;   \
-   BHEAP_CHECK(_bheap);\
-   __internal_bheap_second(_bheap);\
-   })
-
-#define bheap_next(heap, holder)   \
-   ({  \
-   bheap_t *_bheap = &(heap)->bheap;   \
-   BHEAP_CHECK(_bheap);\
-   __internal_bheap_next(_bheap, holder);  \
-   })
-
-static inline bheaph_t *__internal_bheap_next(bheap_t *heap, bheaph_t *holder)
-{
-   unsigned pos;
-
-   if (unlikely(bheaph_pos(holder) >= heap->last
-|| heap->elems[bheaph_pos(holder)] != holder))
-   return (bheaph_t *) ERR_PTR(-EINVAL);
-
-   pos = bheaph

[Xenomai-git] Jan Kiszka : cobalt/kernel: Return need_resched flag from xnsynch_release

2016-05-17 Thread git repository hosting
Module: xenomai-3
Branch: wip/dovetail
Commit: 3223ffec97a360ceb967d487a57e9a0a4ae31500
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=3223ffec97a360ceb967d487a57e9a0a4ae31500

Author: Jan Kiszka 
Date:   Mon May  9 21:19:04 2016 +0200

cobalt/kernel: Return need_resched flag from xnsynch_release

We currently return the next owner, but no caller of xnsynch_release
evaluates this beyond != NULL and calls xnsched_run in that case.
Simplify the API by returning a need_resched flag directly. This will
also help with fixing the missing reschedule after PP deboost.

Signed-off-by: Jan Kiszka 

---

 include/cobalt/kernel/synch.h |3 +--
 kernel/cobalt/posix/mutex.c   |2 +-
 kernel/cobalt/rtdm/drvlib.c   |2 +-
 kernel/cobalt/synch.c |   23 +++
 4 files changed, 14 insertions(+), 16 deletions(-)

diff --git a/include/cobalt/kernel/synch.h b/include/cobalt/kernel/synch.h
index 04d7f10..1e99c18 100644
--- a/include/cobalt/kernel/synch.h
+++ b/include/cobalt/kernel/synch.h
@@ -164,8 +164,7 @@ int xnsynch_acquire(struct xnsynch *synch,
 
 int xnsynch_try_acquire(struct xnsynch *synch);
 
-struct xnthread *xnsynch_release(struct xnsynch *synch,
-struct xnthread *thread);
+bool xnsynch_release(struct xnsynch *synch, struct xnthread *thread);
 
 struct xnthread *xnsynch_peek_pendq(struct xnsynch *synch);
 
diff --git a/kernel/cobalt/posix/mutex.c b/kernel/cobalt/posix/mutex.c
index c6020ff..f99874b 100644
--- a/kernel/cobalt/posix/mutex.c
+++ b/kernel/cobalt/posix/mutex.c
@@ -128,7 +128,7 @@ int cobalt_mutex_release(struct xnthread *curr,
cobalt_cond_deferred_signals(cond);
}
}
-   need_resched |= xnsynch_release(&mutex->synchbase, curr) != NULL;
+   need_resched |= xnsynch_release(&mutex->synchbase, curr);
 
return need_resched;
 }
diff --git a/kernel/cobalt/rtdm/drvlib.c b/kernel/cobalt/rtdm/drvlib.c
index ae55a4b..1973c37 100644
--- a/kernel/cobalt/rtdm/drvlib.c
+++ b/kernel/cobalt/rtdm/drvlib.c
@@ -1282,7 +1282,7 @@ void rtdm_mutex_unlock(rtdm_mutex_t *mutex)
trace_cobalt_driver_mutex_release(mutex);
 
if (unlikely(xnsynch_release(&mutex->synch_base,
-xnsched_current_thread()) != NULL))
+xnsched_current_thread(
xnsched_run();
 }
 EXPORT_SYMBOL_GPL(rtdm_mutex_unlock);
diff --git a/kernel/cobalt/synch.c b/kernel/cobalt/synch.c
index 976261d..d8b83d9 100644
--- a/kernel/cobalt/synch.c
+++ b/kernel/cobalt/synch.c
@@ -843,8 +843,8 @@ static inline void clear_pp_boost(struct xnsynch *synch,
drop_booster(synch, owner);
 }
 
-static struct xnthread *transfer_ownership(struct xnsynch *synch,
-  struct xnthread *lastowner)
+static bool transfer_ownership(struct xnsynch *synch,
+  struct xnthread *lastowner)
 {  /* nklock held, irqs off */
struct xnthread *nextowner;
xnhandle_t nextownerh;
@@ -859,7 +859,7 @@ static struct xnthread *transfer_ownership(struct xnsynch 
*synch,
if (list_empty(&synch->pendq)) {
synch->owner = NULL;
atomic_set(lockp, XN_NO_HANDLE);
-   return NULL;
+   return false;
}
 
nextowner = list_first_entry(&synch->pendq, struct xnthread, plink);
@@ -879,11 +879,11 @@ static struct xnthread *transfer_ownership(struct xnsynch 
*synch,
 
atomic_set(lockp, nextownerh);
 
-   return nextowner;
+   return true;
 }
 
 /**
- * @fn struct xnthread *xnsynch_release(struct xnsynch *synch, struct xnthread 
*curr)
+ * @fn bool xnsynch_release(struct xnsynch *synch, struct xnthread *curr)
  * @brief Release a resource and pass it to the next waiting thread.
  *
  * This service releases the ownership of the given synchronization
@@ -900,7 +900,7 @@ static struct xnthread *transfer_ownership(struct xnsynch 
*synch,
  * @param curr The descriptor address of the current thread, which
  * must own the object at the time of calling.
  *
- * @return The descriptor address of the unblocked thread.
+ * @return True if a reschedule is required.
  *
  * @sideeffect
  *
@@ -913,10 +913,9 @@ static struct xnthread *transfer_ownership(struct xnsynch 
*synch,
  *
  * @coretags{primary-only, might-switch}
  */
-struct xnthread *xnsynch_release(struct xnsynch *synch,
-struct xnthread *curr)
+bool xnsynch_release(struct xnsynch *synch, struct xnthread *curr)
 {
-   struct xnthread *nextowner = NULL;
+   bool need_resched = false;
xnhandle_t currh, h;
atomic_t *lockp;
spl_t s;
@@ -926,7 +925,7 @@ struct xnthread *xnsynch_release(struct xnsynch *synch,
trace_cobalt_synch_release(synch);
 
if (xnthread_put_resource(curr))
-   return NULL;
+   return false;
 

[Xenomai-git] Jan Kiszka : cobalt/kernel: Fix xntimer_get_timeout_stopped

2016-05-17 Thread git repository hosting
Module: xenomai-3
Branch: wip/dovetail
Commit: 3645c68ea889c255d9873ce1c4c97b35450fd059
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=3645c68ea889c255d9873ce1c4c97b35450fd059

Author: Jan Kiszka 
Date:   Thu May 12 21:02:40 2016 +0200

cobalt/kernel: Fix xntimer_get_timeout_stopped

xntimer_get_timeout_stopped just called into xntimer_get_timeout, but
the latter returned XN_INFINITE for stopped timers. Restore the desired
behavior from Xenomai 2.

Signed-off-by: Jan Kiszka 

---

 include/cobalt/kernel/timer.h |   12 ++--
 kernel/cobalt/timer.c |7 ++-
 2 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/include/cobalt/kernel/timer.h b/include/cobalt/kernel/timer.h
index 9f85985..f45a753 100644
--- a/include/cobalt/kernel/timer.h
+++ b/include/cobalt/kernel/timer.h
@@ -474,7 +474,7 @@ void __xntimer_stop(struct xntimer *timer);
 
 xnticks_t xntimer_get_date(struct xntimer *timer);
 
-xnticks_t xntimer_get_timeout(struct xntimer *timer);
+xnticks_t __xntimer_get_timeout(struct xntimer *timer);
 
 xnticks_t xntimer_get_interval(struct xntimer *timer);
 
@@ -486,9 +486,17 @@ static inline void xntimer_stop(struct xntimer *timer)
__xntimer_stop(timer);
 }
 
+static inline xnticks_t xntimer_get_timeout(struct xntimer *timer)
+{
+   if (!xntimer_running_p(timer))
+   return XN_INFINITE;
+
+   return __xntimer_get_timeout(timer);
+}
+
 static inline xnticks_t xntimer_get_timeout_stopped(struct xntimer *timer)
 {
-   return xntimer_get_timeout(timer);
+   return __xntimer_get_timeout(timer);
 }
 
 static inline void xntimer_enqueue(struct xntimer *timer,
diff --git a/kernel/cobalt/timer.c b/kernel/cobalt/timer.c
index bc5893d..c1a2081 100644
--- a/kernel/cobalt/timer.c
+++ b/kernel/cobalt/timer.c
@@ -266,14 +266,11 @@ EXPORT_SYMBOL_GPL(xntimer_get_date);
  *
  * @coretags{unrestricted, atomic-entry}
  */
-xnticks_t xntimer_get_timeout(struct xntimer *timer)
+xnticks_t __xntimer_get_timeout(struct xntimer *timer)
 {
struct xnclock *clock;
xnticks_t expiry, now;
 
-   if (!xntimer_running_p(timer))
-   return XN_INFINITE;
-
clock = xntimer_clock(timer);
now = xnclock_read_raw(clock);
expiry = xntimer_expiry(timer);
@@ -282,7 +279,7 @@ xnticks_t xntimer_get_timeout(struct xntimer *timer)
 
return xnclock_ticks_to_ns(clock, expiry - now);
 }
-EXPORT_SYMBOL_GPL(xntimer_get_timeout);
+EXPORT_SYMBOL_GPL(__xntimer_get_timeout);
 
 /**
  * @fn void xntimer_init(struct xntimer *timer,struct xnclock *clock,void 
(*handler)(struct xntimer *timer), struct xnsched *sched, int flags)


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : boilerplate/init: track automatic bootstrap mode in --dump-config

2016-05-17 Thread git repository hosting
Module: xenomai-3
Branch: wip/dovetail
Commit: 41df44537009a5b3835c5b354fa67bdad30c0ff8
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=41df44537009a5b3835c5b354fa67bdad30c0ff8

Author: Philippe Gerum 
Date:   Mon Apr 25 15:09:17 2016 +0200

boilerplate/init: track automatic bootstrap mode in --dump-config

Automatic bootstrapping (or misusage of manual bootstrap mode) is a
frequent source of issues among C++ applications with non-trivial
static constructors. Have --dump-config display the bootstrap mode for
the executable to make investigation easier.

---

 include/xenomai/init.h   |2 ++
 lib/boilerplate/init/bootstrap.c |2 ++
 lib/boilerplate/setup.c  |3 +++
 3 files changed, 7 insertions(+)

diff --git a/include/xenomai/init.h b/include/xenomai/init.h
index 1ec1d43..9adc90d 100644
--- a/include/xenomai/init.h
+++ b/include/xenomai/init.h
@@ -37,6 +37,8 @@ void application_version(void);
 
 extern const char *xenomai_version_string;
 
+extern const int xenomai_auto_bootstrap;
+  
 #ifdef __cplusplus
 }
 #endif
diff --git a/lib/boilerplate/init/bootstrap.c b/lib/boilerplate/init/bootstrap.c
index cee6843..119b405 100644
--- a/lib/boilerplate/init/bootstrap.c
+++ b/lib/boilerplate/init/bootstrap.c
@@ -26,6 +26,8 @@ static int early_argc;
 
 static char *const *early_argv;
 
+const int xenomai_auto_bootstrap = 1;
+
 int __real_main(int argc, char *const argv[]);
 
 int __wrap_main(int argc, char *const argv[])
diff --git a/lib/boilerplate/setup.c b/lib/boilerplate/setup.c
index 7a9334d..dbeb5e1 100644
--- a/lib/boilerplate/setup.c
+++ b/lib/boilerplate/setup.c
@@ -46,6 +46,8 @@ pid_t __node_id = 0;
 
 int __config_done = 0;
 
+const int __weak xenomai_auto_bootstrap = 0;
+
 static int init_done;
 
 static DEFINE_PRIVATE_LIST(setup_list);
@@ -143,6 +145,7 @@ static inline void dump_configuration(void)
puts(config_strings[n]);
 
printf("PTHREAD_STACK_DEFAULT=%d\n", PTHREAD_STACK_DEFAULT);
+   printf("AUTOMATIC_BOOTSTRAP=%d\n", xenomai_auto_bootstrap);
 }
 
 static int collect_cpu_affinity(const char *cpu_list)


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : alchemy/queue: fix calculation of metadata overhead

2016-05-17 Thread git repository hosting
Module: xenomai-3
Branch: wip/dovetail
Commit: 695e1d2093d1242274fdf2c308a1c82e1ea226a6
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=695e1d2093d1242274fdf2c308a1c82e1ea226a6

Author: Philippe Gerum 
Date:   Sat Apr 30 07:25:23 2016 +0200

alchemy/queue: fix calculation of metadata overhead

---

 lib/alchemy/queue.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/alchemy/queue.c b/lib/alchemy/queue.c
index 410f480..34a35f5 100644
--- a/lib/alchemy/queue.c
+++ b/lib/alchemy/queue.c
@@ -232,7 +232,7 @@ int rt_queue_create(RT_QUEUE *queue, const char *name,
 */
if (qlimit == Q_UNLIMITED)
ret = heapobj_init(&qcb->hobj, qcb->name,
-  poolsize + (poolsize / 5));
+  poolsize + (poolsize * 5 / 100));
else
ret = heapobj_init_array(&qcb->hobj, qcb->name,
 (poolsize / qlimit) *


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : cobalt/rtdm: allow device paths with multiple components

2016-05-17 Thread git repository hosting
Module: xenomai-3
Branch: wip/dovetail
Commit: 8f1a3d8707553815c7310220bdf17ed35fec4380
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=8f1a3d8707553815c7310220bdf17ed35fec4380

Author: Philippe Gerum 
Date:   Sat Apr 30 09:40:10 2016 +0200

cobalt/rtdm: allow device paths with multiple components

---

 kernel/cobalt/rtdm/device.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/cobalt/rtdm/device.c b/kernel/cobalt/rtdm/device.c
index c760f31..46b7965 100644
--- a/kernel/cobalt/rtdm/device.c
+++ b/kernel/cobalt/rtdm/device.c
@@ -424,7 +424,7 @@ int rtdm_dev_register(struct rtdm_device *dev)
 
rdev = MKDEV(major, minor);
kdev = device_create(kdev_class, NULL, rdev,
-dev, dev->label, minor);
+dev, kbasename(dev->label), minor);
if (IS_ERR(kdev)) {
xnregistry_remove(dev->named.handle);
ret = PTR_ERR(kdev);


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Jan Kiszka : lib/cobalt: Wrap pthread_setschedprio for proper real-time support

2016-05-20 Thread git repository hosting
Module: xenomai-jki
Branch: for-forge
Commit: 5d2eda526d74cff937241ab7e191485f62708355
URL:
http://git.xenomai.org/?p=xenomai-jki.git;a=commit;h=5d2eda526d74cff937241ab7e191485f62708355

Author: Jan Kiszka 
Date:   Tue Mar  8 14:46:59 2016 +0100

lib/cobalt: Wrap pthread_setschedprio for proper real-time support

Implement pthread_setschedprio on top of pthread_setschedparam_ex with
the help of the new __SCHED_CURRENT policy. This ensures that prio
changes are directly applied to the real-time core, and that with just
a single syscall.

Signed-off-by: Jan Kiszka 

---

 include/cobalt/pthread.h   |2 ++
 lib/cobalt/cobalt.wrappers |1 +
 lib/cobalt/thread.c|9 +
 lib/cobalt/wrappers.c  |6 ++
 4 files changed, 18 insertions(+)

diff --git a/include/cobalt/pthread.h b/include/cobalt/pthread.h
index f1b1c8a..3e9bd47 100644
--- a/include/cobalt/pthread.h
+++ b/include/cobalt/pthread.h
@@ -53,6 +53,8 @@ COBALT_DECL(int, pthread_setschedparam(pthread_t thread,
   int policy,
   const struct sched_param *param));
 
+COBALT_DECL(int, pthread_setschedprio(pthread_t thread, int prio));
+
 COBALT_DECL(int, pthread_mutex_init(pthread_mutex_t *mutex,
const pthread_mutexattr_t *attr));
 
diff --git a/lib/cobalt/cobalt.wrappers b/lib/cobalt/cobalt.wrappers
index 75f29d6..19153ae 100644
--- a/lib/cobalt/cobalt.wrappers
+++ b/lib/cobalt/cobalt.wrappers
@@ -2,6 +2,7 @@
 --wrap pthread_create
 --wrap pthread_setschedparam
 --wrap pthread_getschedparam
+--wrap pthread_setschedprio
 --wrap pthread_yield
 --wrap sched_yield
 --wrap sched_get_priority_min
diff --git a/lib/cobalt/thread.c b/lib/cobalt/thread.c
index 908516f..62ca0a0 100644
--- a/lib/cobalt/thread.c
+++ b/lib/cobalt/thread.c
@@ -650,6 +650,15 @@ int pthread_setschedparam_ex(pthread_t thread,
return ret;
 }
 
+COBALT_IMPL(int, pthread_setschedprio, (pthread_t thread, int prio))
+{
+   struct sched_param_ex param_ex = {
+   .sched_priority = prio,
+   };
+
+   return pthread_setschedparam_ex(thread, __SCHED_CURRENT, ¶m_ex);
+}
+
 /**
  * Get the scheduling policy and parameters of the specified thread.
  *
diff --git a/lib/cobalt/wrappers.c b/lib/cobalt/wrappers.c
index 09c74e5..1f1664e 100644
--- a/lib/cobalt/wrappers.c
+++ b/lib/cobalt/wrappers.c
@@ -60,6 +60,12 @@ int __real_pthread_getschedparam(pthread_t thread,
 }
 
 __weak
+int __real_pthread_setschedprio(pthread_t thread, int prio)
+{
+   return pthread_setschedprio(thread, prio);
+}
+
+__weak
 int __real_sched_yield(void)
 {
return sched_yield();


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Jan Kiszka : testsuite/smokey: Add test case for setschedparam & Co,

2016-05-20 Thread git repository hosting
Module: xenomai-jki
Branch: for-forge
Commit: 09c90181ee7c500ee99d079202bb8674737158fb
URL:
http://git.xenomai.org/?p=xenomai-jki.git;a=commit;h=09c90181ee7c500ee99d079202bb8674737158fb

Author: Jan Kiszka 
Date:   Mon Feb 29 16:54:26 2016 +0100

testsuite/smokey: Add test case for setschedparam & Co,

This performs basic checks on the correct execution of scheduling
parameter changes from primary mode.

Signed-off-by: Jan Kiszka 

---

 configure.ac  |1 +
 testsuite/smokey/Makefile.am  |1 +
 testsuite/smokey/setsched/Makefile.am |9 +++
 testsuite/smokey/setsched/setsched.c  |  137 +
 4 files changed, 148 insertions(+)

diff --git a/configure.ac b/configure.ac
index cd9f047..667931a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -913,6 +913,7 @@ AC_CONFIG_FILES([ \
testsuite/smokey/arith/Makefile \
testsuite/smokey/sched-quota/Makefile \
testsuite/smokey/sched-tp/Makefile \
+   testsuite/smokey/setsched/Makefile \
testsuite/smokey/rtdm/Makefile \
testsuite/smokey/vdso-access/Makefile \
testsuite/smokey/posix-cond/Makefile \
diff --git a/testsuite/smokey/Makefile.am b/testsuite/smokey/Makefile.am
index 51292f1..e253d6f 100644
--- a/testsuite/smokey/Makefile.am
+++ b/testsuite/smokey/Makefile.am
@@ -24,6 +24,7 @@ COBALT_SUBDIRS =  \
rtdm\
sched-quota \
sched-tp\
+   setsched\
sigdebug\
timerfd \
tsc \
diff --git a/testsuite/smokey/setsched/Makefile.am 
b/testsuite/smokey/setsched/Makefile.am
new file mode 100644
index 000..8c0a59b
--- /dev/null
+++ b/testsuite/smokey/setsched/Makefile.am
@@ -0,0 +1,9 @@
+
+noinst_LIBRARIES = libsetsched.a
+
+libsetsched_a_SOURCES = setsched.c
+
+libsetsched_a_CPPFLAGS =   \
+   @XENO_USER_CFLAGS@  \
+   -I$(top_srcdir) \
+   -I$(top_srcdir)/include
diff --git a/testsuite/smokey/setsched/setsched.c 
b/testsuite/smokey/setsched/setsched.c
new file mode 100644
index 000..359f190
--- /dev/null
+++ b/testsuite/smokey/setsched/setsched.c
@@ -0,0 +1,137 @@
+/*
+ * Scheduler live-adjustment test.
+ *
+ * Copyright (c) Siemens AG 2016
+ *
+ * Authors:
+ *  Jan Kiszka 
+ *
+ * Released under the terms of GPLv2.
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+smokey_test_plugin(setsched, SMOKEY_NOARGS,
+   "Validate correct application of scheduling parameters to running threads."
+);
+
+static pid_t thread_pid;
+
+static void __check_linux_schedparams(int expected_policy, int expected_prio,
+ int line)
+{
+   struct sched_param linux_param;
+   int linux_policy;
+
+   linux_policy = syscall(SYS_sched_getscheduler, thread_pid);
+   if (smokey_check_status(syscall(SYS_sched_getparam, thread_pid,
+   &linux_param)))
+   pthread_exit((void *)(long)-EINVAL);
+
+   if (!smokey_assert(linux_policy == expected_policy) ||
+   !smokey_assert(linux_param.sched_priority == expected_prio)) {
+   smokey_warning("called from line %d", line);
+   pthread_exit((void *)(long)-EINVAL);
+   }
+}
+
+#define check_linux_schedparams(pol, prio) \
+   __check_linux_schedparams(pol, prio, __LINE__)
+
+static void __check_rt_schedparams(int expected_policy, int expected_prio,
+  int line)
+{
+   struct sched_param cobalt_param;
+   int cobalt_policy;
+
+   if (smokey_check_status(pthread_getschedparam(pthread_self(),
+ &cobalt_policy,
+ &cobalt_param)))
+   pthread_exit((void *)(long)-EINVAL);
+
+   if (!smokey_assert(cobalt_policy == expected_policy) ||
+   !smokey_assert(cobalt_param.sched_priority == expected_prio)) {
+   smokey_warning("called from line %d", line);
+   pthread_exit((void *)(long)-EINVAL);
+   }
+}
+
+#define check_rt_schedparams(pol, prio)\
+   __check_rt_schedparams(pol, prio, __LINE__)
+
+static void *thread_body(void *arg)
+{
+   struct cobalt_threadstat stats;
+   struct sched_param param;
+   unsigned long long msw;
+
+   thread_pid = syscall(SYS_gettid);
+
+   check_rt_schedparams(SCHED_FIFO, 1);
+   check_linux_schedparams(SCHED_FIFO, 1);
+
+   if (smokey_check_status(cobalt_thread_stat(thread_pid, &stats)))
+   pthread_exit((void *)(long)-EINVAL);
+   msw = stats.msw;
+
+   param.sched_priority = 2;
+   if (smokey_check_status(pthread_setschedparam(pthread_self(),
+ SCHED_FIFO, ¶m)))
+   pthread_exit((void *)(long)-EINVAL);
+
+   check_rt_schedparams(SCHED_FIFO, 2);
+
+ 

[Xenomai-git] Jan Kiszka : cobalt/kernel: Fix infinite loops on thread cleanup

2016-05-20 Thread git repository hosting
Module: xenomai-jki
Branch: for-forge
Commit: 828c3955719ad5a08bbe4f369b1afa8225ffad8e
URL:
http://git.xenomai.org/?p=xenomai-jki.git;a=commit;h=828c3955719ad5a08bbe4f369b1afa8225ffad8e

Author: Jan Kiszka 
Date:   Sat May 21 00:03:24 2016 +0200

cobalt/kernel: Fix infinite loops on thread cleanup

Due to flipped parameters of list_for_each_entry_safe,
cobalt_signal_flush caused eventual infinite loops.

Signed-off-by: Jan Kiszka 

---

 kernel/cobalt/posix/signal.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/cobalt/posix/signal.c b/kernel/cobalt/posix/signal.c
index a3ec756..4822fda 100644
--- a/kernel/cobalt/posix/signal.c
+++ b/kernel/cobalt/posix/signal.c
@@ -194,7 +194,7 @@ void cobalt_signal_flush(struct cobalt_thread *thread)
 * detect this fact when deleting their respective
 * owners.
 */
-   list_for_each_entry_safe(tmp, sigp, sigq, next)
+   list_for_each_entry_safe(sigp, tmp, sigq, next)
list_del_init(&sigp->next);
}
 


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Jan Kiszka : cobalt/kernel: Allow to restart clock_nanosleep and select after signal processing

2016-05-20 Thread git repository hosting
Module: xenomai-jki
Branch: for-forge
Commit: ee1fcc9c19dba0488f2fb5b964e1062438247c81
URL:
http://git.xenomai.org/?p=xenomai-jki.git;a=commit;h=ee1fcc9c19dba0488f2fb5b964e1062438247c81

Author: Jan Kiszka 
Date:   Fri May 13 20:35:26 2016 +0200

cobalt/kernel: Allow to restart clock_nanosleep and select after signal 
processing

Only if a signal was actually delivered to a thread that was blocked on
sleep, [clock_]nanosleep or select, those calls should return -EINTR.
Otherwise, they should resume with the timeout, accordingly adjusted in
case of relative timeout. So far we returned -EINTR immediately which
particularly disturbed the debugging of applications (SIGSTOP/CONT
terminated those syscalls).

This approach reuses the Linux restart mechanism to find out if those
syscalls should be restarted or actually terminated after the signal
was handled: Linux sets current->restart_block.fn in case a termination
is required, unconditionally, thus also when the syscall did not return
ERESTART_RESTARTBLOCK. We also use the restart_block.nanosleep.expires
to transfer the remaining timeout to the restarted syscall.

We can't use the original restart mechanism of Linux because it directs
all ERESTART_RESTARTBLOCK through a special, Linux-only syscall. In our
case, we would have to migrate the caller in that context to primary in
order to resume the sleep, but this is not possible under Xenomai (we
need to migration from within the syscall hooks).

Signed-off-by: Jan Kiszka 

---

 include/cobalt/uapi/kernel/thread.h|1 +
 .../cobalt/include/asm-generic/xenomai/wrappers.h  |6 +++
 kernel/cobalt/posix/clock.c|   38 +--
 kernel/cobalt/posix/internal.h |2 +
 kernel/cobalt/posix/io.c   |   39 
 kernel/cobalt/posix/syscall.c  |5 +++
 6 files changed, 81 insertions(+), 10 deletions(-)

diff --git a/include/cobalt/uapi/kernel/thread.h 
b/include/cobalt/uapi/kernel/thread.h
index 8d26f16..1f1dca7 100644
--- a/include/cobalt/uapi/kernel/thread.h
+++ b/include/cobalt/uapi/kernel/thread.h
@@ -77,6 +77,7 @@
 
 #define XNMOVED   0x0001 /**< CPU migration in primary mode occurred */
 #define XNLBALERT 0x0002 /**< Scheduler lock break alert (SIGDEBUG sent) */
+#define XNRESTART 0x0004 /**< Thread awaiting syscall restart after signal 
*/
 
 /** @} */
 
diff --git a/kernel/cobalt/include/asm-generic/xenomai/wrappers.h 
b/kernel/cobalt/include/asm-generic/xenomai/wrappers.h
index 060ce85..0f9ab14 100644
--- a/kernel/cobalt/include/asm-generic/xenomai/wrappers.h
+++ b/kernel/cobalt/include/asm-generic/xenomai/wrappers.h
@@ -133,4 +133,10 @@ devm_hwmon_device_register_with_groups(struct device *dev, 
const char *name,
 #error "Xenomai/cobalt requires Linux kernel 3.10 or above"
 #endif /* < 3.10 */
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4,0,0)
+#define cobalt_get_restart_block(p)(&task_thread_info(p)->restart_block)
+#else
+#define cobalt_get_restart_block(p)(&(p)->restart_block)
+#endif
+
 #endif /* _COBALT_ASM_GENERIC_WRAPPERS_H */
diff --git a/kernel/cobalt/posix/clock.c b/kernel/cobalt/posix/clock.c
index b51cb4c..c977bf8 100644
--- a/kernel/cobalt/posix/clock.c
+++ b/kernel/cobalt/posix/clock.c
@@ -236,8 +236,9 @@ int __cobalt_clock_nanosleep(clockid_t clock_id, int flags,
 const struct timespec *rqt,
 struct timespec *rmt)
 {
+   struct restart_block *restart;
struct xnthread *cur;
-   xnsticks_t rem;
+   xnsticks_t timeout, rem;
int ret = 0;
spl_t s;
 
@@ -261,10 +262,41 @@ int __cobalt_clock_nanosleep(clockid_t clock_id, int 
flags,
 
xnlock_get_irqsave(&nklock, s);
 
-   xnthread_suspend(cur, XNDELAY, ts2ns(rqt) + 1,
+   if (xnthread_test_localinfo(cur, XNLBALERT)) {
+   xnthread_clear_localinfo(cur, XNLBALERT);
+
+   restart = cobalt_get_restart_block(current);
+
+   if (restart->fn != cobalt_restart_syscall_placeholder) {
+   xnlock_put_irqrestore(&nklock, s);
+
+   if (rmt)
+   ns2ts(rmt, rem > 1 ? rem : 0);
+   return -EINTR;
+   }
+
+   timeout = restart->nanosleep.expires;
+   } else
+   timeout = ts2ns(rqt);
+
+   xnthread_suspend(cur, XNDELAY, timeout + 1,
 clock_flag(flags, clock_id), NULL);
 
if (xnthread_test_info(cur, XNBREAK)) {
+   if (signal_pending(current)) {
+   xnthread_set_localinfo(cur, XNLBALERT);
+
+   restart = cobalt_get_restart_block(current);
+   restart->fn = cobalt_restart_syscall_placeholder;
+   restart->nanosleep.expires =
+   (flags & TIMER_ABSTIME) ? timeout :
+   

[Xenomai-git] Jan Kiszka : cobalt/kernel: Introduce __SCHED_CURRENT policy to setschedparam_ex

2016-05-20 Thread git repository hosting
Module: xenomai-jki
Branch: for-forge
Commit: 188ca70999794b5b97aeffc55721b3c106515996
URL:
http://git.xenomai.org/?p=xenomai-jki.git;a=commit;h=188ca70999794b5b97aeffc55721b3c106515996

Author: Jan Kiszka 
Date:   Tue Mar  8 14:41:28 2016 +0100

cobalt/kernel: Introduce __SCHED_CURRENT policy to setschedparam_ex

Define the internal scheduling policy "current": it shall refer to the
target thread's current scheduling policy. This will allow to model
pthread_setschedprio on top of pthread_setschedparam_ex with only a
single syscall.

Signed-off-by: Jan Kiszka 

---

 include/cobalt/uapi/sched.h|3 +++
 kernel/cobalt/posix/thread.c   |   10 ++
 kernel/cobalt/trace/cobalt-posix.h |3 ++-
 3 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/include/cobalt/uapi/sched.h b/include/cobalt/uapi/sched.h
index b672095..2a1df44 100644
--- a/include/cobalt/uapi/sched.h
+++ b/include/cobalt/uapi/sched.h
@@ -21,6 +21,9 @@
 #define SCHED_COBALT   42
 #define SCHED_WEAK 43
 
+/* for internal use */
+#define __SCHED_CURRENT44
+
 #ifndef SCHED_SPORADIC
 #define SCHED_SPORADIC 10
 #define sched_ss_low_priority  sched_u.ss.__sched_low_priority
diff --git a/kernel/cobalt/posix/thread.c b/kernel/cobalt/posix/thread.c
index d87edb1..217b81b 100644
--- a/kernel/cobalt/posix/thread.c
+++ b/kernel/cobalt/posix/thread.c
@@ -242,6 +242,7 @@ struct xnthread_personality *cobalt_thread_finalize(struct 
xnthread *zombie)
 int __cobalt_thread_setschedparam_ex(struct cobalt_thread *thread, int policy,
 const struct sched_param_ex *param_ex)
 {
+   struct xnthread *base_thread = &thread->threadbase;
struct xnsched_class *sched_class;
union xnsched_policy_param param;
xnticks_t tslice;
@@ -256,6 +257,15 @@ int __cobalt_thread_setschedparam_ex(struct cobalt_thread 
*thread, int policy,
goto out;
}
 
+   if (policy == __SCHED_CURRENT) {
+   policy = base_thread->base_class->policy;
+   if (xnthread_base_priority(base_thread) == 0)
+   policy = SCHED_NORMAL;
+   else if (base_thread->base_class == &xnsched_class_rt &&
+xnthread_test_state(base_thread, XNRRB))
+   policy = SCHED_RR;
+   }
+
tslice = thread->threadbase.rrperiod;
sched_class = cobalt_sched_policy_param(¶m, policy,
param_ex, &tslice);
diff --git a/kernel/cobalt/trace/cobalt-posix.h 
b/kernel/cobalt/trace/cobalt-posix.h
index 3d0e20c..cc0eb05 100644
--- a/kernel/cobalt/trace/cobalt-posix.h
+++ b/kernel/cobalt/trace/cobalt-posix.h
@@ -90,7 +90,8 @@ DECLARE_EVENT_CLASS(syscall_exit,
 {SCHED_QUOTA, "quota"},\
 {SCHED_SPORADIC, "sporadic"},  \
 {SCHED_COBALT, "cobalt"},  \
-{SCHED_WEAK, "weak"})
+{SCHED_WEAK, "weak"},  \
+{__SCHED_CURRENT, ""})
 
 #define cobalt_print_sched_params(__policy, __p_ex)\
 ({ \


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Jan Kiszka : cobalt/kernel: Introduce __SCHED_CURRENT policy to setschedparam_ex

2016-05-23 Thread git repository hosting
Module: xenomai-3
Branch: next
Commit: c821cbaa31c4a816615a82d7cbbd049987da6f1a
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=c821cbaa31c4a816615a82d7cbbd049987da6f1a

Author: Jan Kiszka 
Date:   Tue Mar  8 14:41:28 2016 +0100

cobalt/kernel: Introduce __SCHED_CURRENT policy to setschedparam_ex

Define the internal scheduling policy "current": it shall refer to the
target thread's current scheduling policy. This will allow to model
pthread_setschedprio on top of pthread_setschedparam_ex with only a
single syscall.

Signed-off-by: Jan Kiszka 

---

 include/cobalt/uapi/sched.h|3 +++
 kernel/cobalt/posix/thread.c   |   10 ++
 kernel/cobalt/trace/cobalt-posix.h |3 ++-
 3 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/include/cobalt/uapi/sched.h b/include/cobalt/uapi/sched.h
index b672095..2a1df44 100644
--- a/include/cobalt/uapi/sched.h
+++ b/include/cobalt/uapi/sched.h
@@ -21,6 +21,9 @@
 #define SCHED_COBALT   42
 #define SCHED_WEAK 43
 
+/* for internal use */
+#define __SCHED_CURRENT44
+
 #ifndef SCHED_SPORADIC
 #define SCHED_SPORADIC 10
 #define sched_ss_low_priority  sched_u.ss.__sched_low_priority
diff --git a/kernel/cobalt/posix/thread.c b/kernel/cobalt/posix/thread.c
index d87edb1..217b81b 100644
--- a/kernel/cobalt/posix/thread.c
+++ b/kernel/cobalt/posix/thread.c
@@ -242,6 +242,7 @@ struct xnthread_personality *cobalt_thread_finalize(struct 
xnthread *zombie)
 int __cobalt_thread_setschedparam_ex(struct cobalt_thread *thread, int policy,
 const struct sched_param_ex *param_ex)
 {
+   struct xnthread *base_thread = &thread->threadbase;
struct xnsched_class *sched_class;
union xnsched_policy_param param;
xnticks_t tslice;
@@ -256,6 +257,15 @@ int __cobalt_thread_setschedparam_ex(struct cobalt_thread 
*thread, int policy,
goto out;
}
 
+   if (policy == __SCHED_CURRENT) {
+   policy = base_thread->base_class->policy;
+   if (xnthread_base_priority(base_thread) == 0)
+   policy = SCHED_NORMAL;
+   else if (base_thread->base_class == &xnsched_class_rt &&
+xnthread_test_state(base_thread, XNRRB))
+   policy = SCHED_RR;
+   }
+
tslice = thread->threadbase.rrperiod;
sched_class = cobalt_sched_policy_param(¶m, policy,
param_ex, &tslice);
diff --git a/kernel/cobalt/trace/cobalt-posix.h 
b/kernel/cobalt/trace/cobalt-posix.h
index 3d0e20c..cc0eb05 100644
--- a/kernel/cobalt/trace/cobalt-posix.h
+++ b/kernel/cobalt/trace/cobalt-posix.h
@@ -90,7 +90,8 @@ DECLARE_EVENT_CLASS(syscall_exit,
 {SCHED_QUOTA, "quota"},\
 {SCHED_SPORADIC, "sporadic"},  \
 {SCHED_COBALT, "cobalt"},  \
-{SCHED_WEAK, "weak"})
+{SCHED_WEAK, "weak"},  \
+{__SCHED_CURRENT, ""})
 
 #define cobalt_print_sched_params(__policy, __p_ex)\
 ({ \


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Jan Kiszka : lib/cobalt: Wrap pthread_setschedprio for proper real-time support

2016-05-23 Thread git repository hosting
Module: xenomai-3
Branch: next
Commit: f96f0548cce9b54eac5f60cab543c9598f4f2386
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=f96f0548cce9b54eac5f60cab543c9598f4f2386

Author: Jan Kiszka 
Date:   Tue Mar  8 14:46:59 2016 +0100

lib/cobalt: Wrap pthread_setschedprio for proper real-time support

Implement pthread_setschedprio on top of pthread_setschedparam_ex with
the help of the new __SCHED_CURRENT policy. This ensures that prio
changes are directly applied to the real-time core, and that with just
a single syscall.

Signed-off-by: Jan Kiszka 

---

 include/cobalt/pthread.h   |2 ++
 lib/cobalt/cobalt.wrappers |1 +
 lib/cobalt/thread.c|9 +
 lib/cobalt/wrappers.c  |6 ++
 4 files changed, 18 insertions(+)

diff --git a/include/cobalt/pthread.h b/include/cobalt/pthread.h
index f1b1c8a..3e9bd47 100644
--- a/include/cobalt/pthread.h
+++ b/include/cobalt/pthread.h
@@ -53,6 +53,8 @@ COBALT_DECL(int, pthread_setschedparam(pthread_t thread,
   int policy,
   const struct sched_param *param));
 
+COBALT_DECL(int, pthread_setschedprio(pthread_t thread, int prio));
+
 COBALT_DECL(int, pthread_mutex_init(pthread_mutex_t *mutex,
const pthread_mutexattr_t *attr));
 
diff --git a/lib/cobalt/cobalt.wrappers b/lib/cobalt/cobalt.wrappers
index 75f29d6..19153ae 100644
--- a/lib/cobalt/cobalt.wrappers
+++ b/lib/cobalt/cobalt.wrappers
@@ -2,6 +2,7 @@
 --wrap pthread_create
 --wrap pthread_setschedparam
 --wrap pthread_getschedparam
+--wrap pthread_setschedprio
 --wrap pthread_yield
 --wrap sched_yield
 --wrap sched_get_priority_min
diff --git a/lib/cobalt/thread.c b/lib/cobalt/thread.c
index 908516f..62ca0a0 100644
--- a/lib/cobalt/thread.c
+++ b/lib/cobalt/thread.c
@@ -650,6 +650,15 @@ int pthread_setschedparam_ex(pthread_t thread,
return ret;
 }
 
+COBALT_IMPL(int, pthread_setschedprio, (pthread_t thread, int prio))
+{
+   struct sched_param_ex param_ex = {
+   .sched_priority = prio,
+   };
+
+   return pthread_setschedparam_ex(thread, __SCHED_CURRENT, ¶m_ex);
+}
+
 /**
  * Get the scheduling policy and parameters of the specified thread.
  *
diff --git a/lib/cobalt/wrappers.c b/lib/cobalt/wrappers.c
index 09c74e5..1f1664e 100644
--- a/lib/cobalt/wrappers.c
+++ b/lib/cobalt/wrappers.c
@@ -60,6 +60,12 @@ int __real_pthread_getschedparam(pthread_t thread,
 }
 
 __weak
+int __real_pthread_setschedprio(pthread_t thread, int prio)
+{
+   return pthread_setschedprio(thread, prio);
+}
+
+__weak
 int __real_sched_yield(void)
 {
return sched_yield();


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : boilerplate/libc: add placeholder for pthread_setschedprio()

2016-05-24 Thread git repository hosting
Module: xenomai-3
Branch: next
Commit: bc183bc4e88d69035f4b2b445749f6a9a4de5db2
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=bc183bc4e88d69035f4b2b445749f6a9a4de5db2

Author: Philippe Gerum 
Date:   Tue May 24 09:43:29 2016 +0200

boilerplate/libc: add placeholder for pthread_setschedprio()

For outdated uClibc.

---

 configure.ac   |1 +
 include/boilerplate/libc.h |   19 +++
 2 files changed, 20 insertions(+)

diff --git a/configure.ac b/configure.ac
index cd9f047..42f2f5d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -540,6 +540,7 @@ AC_CHECK_FUNCS([pthread_mutexattr_setprotocol   \
pthread_getattr_np  \
pthread_atfork  \
pthread_setname_np  \
+   pthread_setschedprio\
sched_getcpu\
clock_nanosleep \
shm_open\
diff --git a/include/boilerplate/libc.h b/include/boilerplate/libc.h
index 2f356a9..88b522d 100644
--- a/include/boilerplate/libc.h
+++ b/include/boilerplate/libc.h
@@ -168,6 +168,25 @@ int pthread_setaffinity_np(pthread_t thread, size_t 
cpusetsize,
 
 #endif /* !HAVE_PTHREAD_ATTR_SETAFFINITY_NP */
 
+#ifndef HAVE_PTHREAD_SETSCHEDPRIO
+
+static inline
+int pthread_setschedprio(pthread_t thread, int prio)
+{
+   struct sched_param param;
+   int policy, ret;
+
+   ret = pthread_getschedparam(thread, &policy, ¶m);
+   if (ret)
+   return ret;
+
+   param.sched_priority = prio;
+
+   return pthread_setschedparam(thread, policy, ¶m);
+}
+
+#endif /* !HAVE_PTHREAD_SETSCHEDPRIO */
+
 #if !defined(HAVE_CLOCK_NANOSLEEP) && defined(CONFIG_XENO_MERCURY)
 /*
  * Best effort for a Mercury setup based on an outdated libc lacking


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : ksrc, include: cope with introduction of user_msghdr

2016-05-25 Thread git repository hosting
Module: xenomai-2.6
Branch: wip/4.x-fixups
Commit: 54515995de2143734b16b16ba3419cdf016fc0dd
URL:
http://git.xenomai.org/?p=xenomai-2.6.git;a=commit;h=54515995de2143734b16b16ba3419cdf016fc0dd

Author: Philippe Gerum 
Date:   Wed May 25 14:32:05 2016 +0200

ksrc, include: cope with introduction of user_msghdr

---

 include/rtdm/rtcan.h |2 +-
 include/rtdm/rtdm.h  |   15 +--
 include/rtdm/rtdm_driver.h   |4 ++--
 include/rtdm/rtipc.h |4 ++--
 ksrc/drivers/can/rtcan_raw.c |6 +++---
 ksrc/drivers/ipc/bufp.c  |4 ++--
 ksrc/drivers/ipc/iddp.c  |4 ++--
 ksrc/drivers/ipc/internal.h  |4 ++--
 ksrc/drivers/ipc/rtipc.c |4 ++--
 ksrc/drivers/ipc/xddp.c  |4 ++--
 ksrc/skins/rtdm/core.c   |   12 ++--
 ksrc/skins/rtdm/syscall.c|4 ++--
 12 files changed, 35 insertions(+), 32 deletions(-)

diff --git a/include/rtdm/rtcan.h b/include/rtdm/rtcan.h
index b8bd762..3ff7651 100644
--- a/include/rtdm/rtcan.h
+++ b/include/rtdm/rtcan.h
@@ -146,7 +146,7 @@
  * It is possible to receive a high precision timestamp with every CAN
  * message. The condition is a former instruction to the socket via
  * @ref RTCAN_RTIOC_TAKE_TIMESTAMP. The timestamp will be copied to the
- * @c msg_control buffer of struct msghdr if it points to a valid
+ * @c msg_control buffer of struct user_msghdr if it points to a valid
  * memory location with size of @ref nanosecs_abs_t. If this
  * is a NULL pointer the timestamp will be discarded silently. @n
  * @n
diff --git a/include/rtdm/rtdm.h b/include/rtdm/rtdm.h
index d907f08..64accfc 100644
--- a/include/rtdm/rtdm.h
+++ b/include/rtdm/rtdm.h
@@ -54,6 +54,7 @@
 #include 
 #include 
 #include 
+#include 
 
 typedef u32 socklen_t;
 typedef struct task_struct rtdm_user_info_t;
@@ -247,9 +248,9 @@ ssize_t __rt_dev_read(rtdm_user_info_t *user_info, int fd, 
void *buf,
 ssize_t __rt_dev_write(rtdm_user_info_t *user_info, int fd, const void *buf,
   size_t nbyte);
 ssize_t __rt_dev_recvmsg(rtdm_user_info_t *user_info, int fd,
-struct msghdr *msg, int flags);
+struct user_msghdr *msg, int flags);
 ssize_t __rt_dev_sendmsg(rtdm_user_info_t *user_info, int fd,
-const struct msghdr *msg, int flags);
+const struct user_msghdr *msg, int flags);
 #endif /* __KERNEL__ */
 
 /* Define RTDM_NO_DEFAULT_USER_API to switch off the default rt_dev_xxx
@@ -287,7 +288,7 @@ static inline ssize_t rt_dev_recvfrom(int fd, void *buf, 
size_t len, int flags,
  socklen_t *fromlen)
 {
struct iovec iov;
-   struct msghdr msg;
+   struct user_msghdr msg;
int ret;
 
iov.iov_base = buf;
@@ -308,6 +309,8 @@ static inline ssize_t rt_dev_recvfrom(int fd, void *buf, 
size_t len, int flags,
 
 #else /* !__KERNEL__ */
 
+#define user_msghdr msghdr
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -318,8 +321,8 @@ int rt_dev_close(int fd);
 int rt_dev_ioctl(int fd, int request, ...);
 ssize_t rt_dev_read(int fd, void *buf, size_t nbyte);
 ssize_t rt_dev_write(int fd, const void *buf, size_t nbyte);
-ssize_t rt_dev_recvmsg(int fd, struct msghdr *msg, int flags);
-ssize_t rt_dev_sendmsg(int fd, const struct msghdr *msg, int flags);
+ssize_t rt_dev_recvmsg(int fd, struct user_msghdr *msg, int flags);
+ssize_t rt_dev_sendmsg(int fd, const struct user_msghdr *msg, int flags);
 
 ssize_t rt_dev_recvfrom(int fd, void *buf, size_t len, int flags,
struct sockaddr *from, socklen_t *fromlen);
@@ -344,7 +347,7 @@ static inline ssize_t rt_dev_sendto(int fd, const void 
*buf, size_t len,
socklen_t tolen)
 {
struct iovec iov;
-   struct msghdr msg;
+   struct user_msghdr msg;
 
iov.iov_base = (void *)buf;
iov.iov_len = len;
diff --git a/include/rtdm/rtdm_driver.h b/include/rtdm/rtdm_driver.h
index 15d61d3..f0f82b7 100644
--- a/include/rtdm/rtdm_driver.h
+++ b/include/rtdm/rtdm_driver.h
@@ -305,7 +305,7 @@ typedef ssize_t (*rtdm_write_handler_t)(struct 
rtdm_dev_context *context,
  * http://www.opengroup.org/onlinepubs/009695399 */
 typedef ssize_t (*rtdm_recvmsg_handler_t)(struct rtdm_dev_context *context,
  rtdm_user_info_t *user_info,
- struct msghdr *msg, int flags);
+ struct user_msghdr *msg, int flags);
 
 /**
  * Transmit message handler
@@ -325,7 +325,7 @@ typedef ssize_t (*rtdm_recvmsg_handler_t)(struct 
rtdm_dev_context *context,
  * http://www.opengroup.org/onlinepubs/009695399 */
 typedef ssize_t (*rtdm_sendmsg_handler_t)(struct rtdm_dev_context *context,
  rtdm_user_info_t *user_info,
- const struct msghdr *msg, int flags);
+ const stru

[Xenomai-git] Jan Kiszka : cobalt/kernel: Allow to restart clock_nanosleep and select after signal processing

2016-05-26 Thread git repository hosting
Module: xenomai-jki
Branch: for-forge
Commit: 5254992e6a428c400a111d77348948d314bcb7ca
URL:
http://git.xenomai.org/?p=xenomai-jki.git;a=commit;h=5254992e6a428c400a111d77348948d314bcb7ca

Author: Jan Kiszka 
Date:   Fri May 13 20:35:26 2016 +0200

cobalt/kernel: Allow to restart clock_nanosleep and select after signal 
processing

Only if a signal was actually delivered to a thread that was blocked on
sleep, [clock_]nanosleep or select, those calls should return -EINTR.
Otherwise, they should resume with the timeout, accordingly adjusted in
case of relative timeout. So far we returned -EINTR immediately which
particularly disturbed the debugging of applications (SIGSTOP/CONT
terminated those syscalls).

This approach reuses the Linux restart mechanism to find out if those
syscalls should be restarted or actually terminated after the signal
was handled: Linux sets current->restart_block.fn in case a termination
is required, unconditionally, thus also when the syscall did not return
ERESTART_RESTARTBLOCK. We also use the restart_block.nanosleep.expires
to transfer the remaining timeout to the restarted syscall.

We can't use the original restart mechanism of Linux because it directs
all ERESTART_RESTARTBLOCK through a special, Linux-only syscall. In our
case, we would have to migrate the caller in that context to primary in
order to resume the sleep, but this is not possible under Xenomai (we
need to migration from within the syscall hooks).

Signed-off-by: Jan Kiszka 

---

 include/cobalt/uapi/kernel/thread.h|1 +
 .../cobalt/include/asm-generic/xenomai/wrappers.h  |6 +++
 kernel/cobalt/posix/clock.c|   38 +--
 kernel/cobalt/posix/internal.h |2 +
 kernel/cobalt/posix/io.c   |   39 
 kernel/cobalt/posix/syscall.c  |5 +++
 6 files changed, 81 insertions(+), 10 deletions(-)

diff --git a/include/cobalt/uapi/kernel/thread.h 
b/include/cobalt/uapi/kernel/thread.h
index 8d26f16..1f1dca7 100644
--- a/include/cobalt/uapi/kernel/thread.h
+++ b/include/cobalt/uapi/kernel/thread.h
@@ -77,6 +77,7 @@
 
 #define XNMOVED   0x0001 /**< CPU migration in primary mode occurred */
 #define XNLBALERT 0x0002 /**< Scheduler lock break alert (SIGDEBUG sent) */
+#define XNRESTART 0x0004 /**< Thread awaiting syscall restart after signal 
*/
 
 /** @} */
 
diff --git a/kernel/cobalt/include/asm-generic/xenomai/wrappers.h 
b/kernel/cobalt/include/asm-generic/xenomai/wrappers.h
index 060ce85..0f9ab14 100644
--- a/kernel/cobalt/include/asm-generic/xenomai/wrappers.h
+++ b/kernel/cobalt/include/asm-generic/xenomai/wrappers.h
@@ -133,4 +133,10 @@ devm_hwmon_device_register_with_groups(struct device *dev, 
const char *name,
 #error "Xenomai/cobalt requires Linux kernel 3.10 or above"
 #endif /* < 3.10 */
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4,0,0)
+#define cobalt_get_restart_block(p)(&task_thread_info(p)->restart_block)
+#else
+#define cobalt_get_restart_block(p)(&(p)->restart_block)
+#endif
+
 #endif /* _COBALT_ASM_GENERIC_WRAPPERS_H */
diff --git a/kernel/cobalt/posix/clock.c b/kernel/cobalt/posix/clock.c
index b51cb4c..c977bf8 100644
--- a/kernel/cobalt/posix/clock.c
+++ b/kernel/cobalt/posix/clock.c
@@ -236,8 +236,9 @@ int __cobalt_clock_nanosleep(clockid_t clock_id, int flags,
 const struct timespec *rqt,
 struct timespec *rmt)
 {
+   struct restart_block *restart;
struct xnthread *cur;
-   xnsticks_t rem;
+   xnsticks_t timeout, rem;
int ret = 0;
spl_t s;
 
@@ -261,10 +262,41 @@ int __cobalt_clock_nanosleep(clockid_t clock_id, int 
flags,
 
xnlock_get_irqsave(&nklock, s);
 
-   xnthread_suspend(cur, XNDELAY, ts2ns(rqt) + 1,
+   if (xnthread_test_localinfo(cur, XNLBALERT)) {
+   xnthread_clear_localinfo(cur, XNLBALERT);
+
+   restart = cobalt_get_restart_block(current);
+
+   if (restart->fn != cobalt_restart_syscall_placeholder) {
+   xnlock_put_irqrestore(&nklock, s);
+
+   if (rmt)
+   ns2ts(rmt, rem > 1 ? rem : 0);
+   return -EINTR;
+   }
+
+   timeout = restart->nanosleep.expires;
+   } else
+   timeout = ts2ns(rqt);
+
+   xnthread_suspend(cur, XNDELAY, timeout + 1,
 clock_flag(flags, clock_id), NULL);
 
if (xnthread_test_info(cur, XNBREAK)) {
+   if (signal_pending(current)) {
+   xnthread_set_localinfo(cur, XNLBALERT);
+
+   restart = cobalt_get_restart_block(current);
+   restart->fn = cobalt_restart_syscall_placeholder;
+   restart->nanosleep.expires =
+   (flags & TIMER_ABSTIME) ? timeout :
+   

[Xenomai-git] Jan Kiszka : testsuite/smokey: Add test case for setschedparam & Co,

2016-05-26 Thread git repository hosting
Module: xenomai-jki
Branch: for-forge
Commit: 26212c38dcc8eea5eac4d72015072b0740f89e8e
URL:
http://git.xenomai.org/?p=xenomai-jki.git;a=commit;h=26212c38dcc8eea5eac4d72015072b0740f89e8e

Author: Jan Kiszka 
Date:   Mon Feb 29 16:54:26 2016 +0100

testsuite/smokey: Add test case for setschedparam & Co,

This performs basic checks on the correct execution of scheduling
parameter changes from primary mode.

Signed-off-by: Jan Kiszka 

---

 configure.ac  |1 +
 testsuite/smokey/Makefile.am  |1 +
 testsuite/smokey/setsched/Makefile.am |9 +++
 testsuite/smokey/setsched/setsched.c  |  137 +
 4 files changed, 148 insertions(+)

diff --git a/configure.ac b/configure.ac
index 42f2f5d..9680edb 100644
--- a/configure.ac
+++ b/configure.ac
@@ -914,6 +914,7 @@ AC_CONFIG_FILES([ \
testsuite/smokey/arith/Makefile \
testsuite/smokey/sched-quota/Makefile \
testsuite/smokey/sched-tp/Makefile \
+   testsuite/smokey/setsched/Makefile \
testsuite/smokey/rtdm/Makefile \
testsuite/smokey/vdso-access/Makefile \
testsuite/smokey/posix-cond/Makefile \
diff --git a/testsuite/smokey/Makefile.am b/testsuite/smokey/Makefile.am
index 51292f1..e253d6f 100644
--- a/testsuite/smokey/Makefile.am
+++ b/testsuite/smokey/Makefile.am
@@ -24,6 +24,7 @@ COBALT_SUBDIRS =  \
rtdm\
sched-quota \
sched-tp\
+   setsched\
sigdebug\
timerfd \
tsc \
diff --git a/testsuite/smokey/setsched/Makefile.am 
b/testsuite/smokey/setsched/Makefile.am
new file mode 100644
index 000..8c0a59b
--- /dev/null
+++ b/testsuite/smokey/setsched/Makefile.am
@@ -0,0 +1,9 @@
+
+noinst_LIBRARIES = libsetsched.a
+
+libsetsched_a_SOURCES = setsched.c
+
+libsetsched_a_CPPFLAGS =   \
+   @XENO_USER_CFLAGS@  \
+   -I$(top_srcdir) \
+   -I$(top_srcdir)/include
diff --git a/testsuite/smokey/setsched/setsched.c 
b/testsuite/smokey/setsched/setsched.c
new file mode 100644
index 000..359f190
--- /dev/null
+++ b/testsuite/smokey/setsched/setsched.c
@@ -0,0 +1,137 @@
+/*
+ * Scheduler live-adjustment test.
+ *
+ * Copyright (c) Siemens AG 2016
+ *
+ * Authors:
+ *  Jan Kiszka 
+ *
+ * Released under the terms of GPLv2.
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+smokey_test_plugin(setsched, SMOKEY_NOARGS,
+   "Validate correct application of scheduling parameters to running threads."
+);
+
+static pid_t thread_pid;
+
+static void __check_linux_schedparams(int expected_policy, int expected_prio,
+ int line)
+{
+   struct sched_param linux_param;
+   int linux_policy;
+
+   linux_policy = syscall(SYS_sched_getscheduler, thread_pid);
+   if (smokey_check_status(syscall(SYS_sched_getparam, thread_pid,
+   &linux_param)))
+   pthread_exit((void *)(long)-EINVAL);
+
+   if (!smokey_assert(linux_policy == expected_policy) ||
+   !smokey_assert(linux_param.sched_priority == expected_prio)) {
+   smokey_warning("called from line %d", line);
+   pthread_exit((void *)(long)-EINVAL);
+   }
+}
+
+#define check_linux_schedparams(pol, prio) \
+   __check_linux_schedparams(pol, prio, __LINE__)
+
+static void __check_rt_schedparams(int expected_policy, int expected_prio,
+  int line)
+{
+   struct sched_param cobalt_param;
+   int cobalt_policy;
+
+   if (smokey_check_status(pthread_getschedparam(pthread_self(),
+ &cobalt_policy,
+ &cobalt_param)))
+   pthread_exit((void *)(long)-EINVAL);
+
+   if (!smokey_assert(cobalt_policy == expected_policy) ||
+   !smokey_assert(cobalt_param.sched_priority == expected_prio)) {
+   smokey_warning("called from line %d", line);
+   pthread_exit((void *)(long)-EINVAL);
+   }
+}
+
+#define check_rt_schedparams(pol, prio)\
+   __check_rt_schedparams(pol, prio, __LINE__)
+
+static void *thread_body(void *arg)
+{
+   struct cobalt_threadstat stats;
+   struct sched_param param;
+   unsigned long long msw;
+
+   thread_pid = syscall(SYS_gettid);
+
+   check_rt_schedparams(SCHED_FIFO, 1);
+   check_linux_schedparams(SCHED_FIFO, 1);
+
+   if (smokey_check_status(cobalt_thread_stat(thread_pid, &stats)))
+   pthread_exit((void *)(long)-EINVAL);
+   msw = stats.msw;
+
+   param.sched_priority = 2;
+   if (smokey_check_status(pthread_setschedparam(pthread_self(),
+ SCHED_FIFO, ¶m)))
+   pthread_exit((void *)(long)-EINVAL);
+
+   check_rt_schedparams(SCHED_FIFO, 2);
+
+ 

[Xenomai-git] Jan Kiszka : cobalt/kernel: Fix infinite loops on thread cleanup

2016-05-26 Thread git repository hosting
Module: xenomai-jki
Branch: for-forge
Commit: 279183e45798533736e3427ab3e945f1814710df
URL:
http://git.xenomai.org/?p=xenomai-jki.git;a=commit;h=279183e45798533736e3427ab3e945f1814710df

Author: Jan Kiszka 
Date:   Sat May 21 00:03:24 2016 +0200

cobalt/kernel: Fix infinite loops on thread cleanup

Due to flipped parameters of list_for_each_entry_safe,
cobalt_signal_flush caused eventual infinite loops.

Signed-off-by: Jan Kiszka 

---

 kernel/cobalt/posix/signal.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/cobalt/posix/signal.c b/kernel/cobalt/posix/signal.c
index a3ec756..4822fda 100644
--- a/kernel/cobalt/posix/signal.c
+++ b/kernel/cobalt/posix/signal.c
@@ -194,7 +194,7 @@ void cobalt_signal_flush(struct cobalt_thread *thread)
 * detect this fact when deleting their respective
 * owners.
 */
-   list_for_each_entry_safe(tmp, sigp, sigq, next)
+   list_for_each_entry_safe(sigp, tmp, sigq, next)
list_del_init(&sigp->next);
}
 


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Jan Kiszka : cobalt/rtdm: Fix driver reference counting

2016-05-26 Thread git repository hosting
Module: xenomai-jki
Branch: for-forge
Commit: c9d83776c0ed882c71045dc32b340b57f88c5e00
URL:
http://git.xenomai.org/?p=xenomai-jki.git;a=commit;h=c9d83776c0ed882c71045dc32b340b57f88c5e00

Author: Jan Kiszka 
Date:   Fri May 27 08:32:41 2016 +0200

cobalt/rtdm: Fix driver reference counting

The rtdm smokey test triggered a BUG due to rtdm_dev_unregister not
taking the reference counter of a driver into account. Fix this by
moving the check into unregister_driver directly.

Signed-off-by: Jan Kiszka 

---

 kernel/cobalt/rtdm/device.c |6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/kernel/cobalt/rtdm/device.c b/kernel/cobalt/rtdm/device.c
index aa62169..8c54890 100644
--- a/kernel/cobalt/rtdm/device.c
+++ b/kernel/cobalt/rtdm/device.c
@@ -324,6 +324,9 @@ static void unregister_driver(struct rtdm_driver *drv)
 {
XENO_BUG_ON(COBALT, drv->profile_info.magic != RTDM_CLASS_MAGIC);
 
+   if (!atomic_dec_and_test(&drv->refcount))
+   return;
+
cobalt_remove_state_chain(&drv->nb_statechange);
 
drv->profile_info.magic = ~RTDM_CLASS_MAGIC;
@@ -477,8 +480,7 @@ fail:
if (kdev)
device_destroy(kdev_class, rdev);
 
-   if (atomic_dec_and_test(&drv->refcount))
-   unregister_driver(drv);
+   unregister_driver(drv);
 
mutex_unlock(®ister_lock);
 


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Jan Kiszka : cobalt/rtdm: Also initialized driver refcount for protocol devices

2016-05-27 Thread git repository hosting
Module: xenomai-jki
Branch: for-forge
Commit: 2ece9baad0aecdcfaacc79eaad0240221c930375
URL:
http://git.xenomai.org/?p=xenomai-jki.git;a=commit;h=2ece9baad0aecdcfaacc79eaad0240221c930375

Author: Jan Kiszka 
Date:   Fri May 27 11:35:26 2016 +0200

cobalt/rtdm: Also initialized driver refcount for protocol devices

Was only done for named devices, thus leaving protocol devices in limbo
state after rtdm_dev_unregister.

Signed-off-by: Jan Kiszka 

---

 kernel/cobalt/rtdm/device.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/cobalt/rtdm/device.c b/kernel/cobalt/rtdm/device.c
index 8c54890..3e6a46b 100644
--- a/kernel/cobalt/rtdm/device.c
+++ b/kernel/cobalt/rtdm/device.c
@@ -303,10 +303,10 @@ static int register_driver(struct rtdm_driver *drv)
goto fail_cdev;
 
drv->named.major = MAJOR(rdev);
-   atomic_set(&drv->refcount, 1);
bitmap_zero(drv->minor_map, RTDM_MAX_MINOR);
 
 done:
+   atomic_set(&drv->refcount, 1);
drv->nb_statechange.notifier_call = state_change_notifier;
drv->nb_statechange.priority = 0;
cobalt_add_state_chain(&drv->nb_statechange);


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Jan Kiszka : lib/cobalt: Provide RT-capable usleep

2016-05-30 Thread git repository hosting
Module: xenomai-jki
Branch: for-forge
Commit: ec9a8c81944d4a3e3f50af314fa58ade68dd28c2
URL:
http://git.xenomai.org/?p=xenomai-jki.git;a=commit;h=ec9a8c81944d4a3e3f50af314fa58ade68dd28c2

Author: Jan Kiszka 
Date:   Mon May 30 14:58:07 2016 +0200

lib/cobalt: Provide RT-capable usleep

User may expect this (probably last) sleeping service to be available
under Cobalt just like sleep, nanosleep & Co.

Signed-off-by: Jan Kiszka 

---

 include/cobalt/unistd.h|2 ++
 lib/cobalt/clock.c |   14 ++
 lib/cobalt/cobalt.wrappers |1 +
 lib/cobalt/wrappers.c  |6 ++
 4 files changed, 23 insertions(+)

diff --git a/include/cobalt/unistd.h b/include/cobalt/unistd.h
index 8ad2b40..fe3992a 100644
--- a/include/cobalt/unistd.h
+++ b/include/cobalt/unistd.h
@@ -35,6 +35,8 @@ COBALT_DECL(int, close(int fildes));
 
 COBALT_DECL(unsigned int, sleep(unsigned int seconds));
 
+COBALT_DECL(int, usleep(useconds_t usec));
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/lib/cobalt/clock.c b/lib/cobalt/clock.c
index 0450019..7b4ef54 100644
--- a/lib/cobalt/clock.c
+++ b/lib/cobalt/clock.c
@@ -364,6 +364,20 @@ COBALT_IMPL(unsigned int, sleep, (unsigned int seconds))
return 0;
 }
 
+/* @apitags{thread-unrestricted, switch-primary} */
+
+COBALT_IMPL(int, usleep, (useconds_t usec))
+{
+   struct timespec rqt;
+
+   if (cobalt_get_current_fast() == XN_NO_HANDLE)
+   return __STD(usleep(usec));
+
+   rqt.tv_sec = usec / 100;
+   rqt.tv_nsec = (usec % 100) * 1000;
+   return __WRAP(clock_nanosleep(CLOCK_MONOTONIC, 0, &rqt, NULL));
+}
+
 /* @apitags{unrestricted} */
 
 COBALT_IMPL(int, gettimeofday, (struct timeval *tv, struct timezone *tz))
diff --git a/lib/cobalt/cobalt.wrappers b/lib/cobalt/cobalt.wrappers
index 19153ae..bf7a810 100644
--- a/lib/cobalt/cobalt.wrappers
+++ b/lib/cobalt/cobalt.wrappers
@@ -110,6 +110,7 @@
 --wrap sigqueue
 --wrap kill
 --wrap sleep
+--wrap usleep
 --wrap mmap
 --wrap mmap64
 --wrap time
diff --git a/lib/cobalt/wrappers.c b/lib/cobalt/wrappers.c
index 1f1664e..43ca630 100644
--- a/lib/cobalt/wrappers.c
+++ b/lib/cobalt/wrappers.c
@@ -538,3 +538,9 @@ unsigned int __real_sleep(unsigned int seconds)
 {
return sleep(seconds);
 }
+
+__weak
+int __real_usleep(useconds_t usec)
+{
+   return usleep(usec);
+}


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : testsuite/gpiotest: add GPIO test suite

2016-06-01 Thread git repository hosting
Module: xenomai-3
Branch: wip/gpio
Commit: e29e39f3b5a6a73d6b6ca5dc3e45dbc63c7c9045
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=e29e39f3b5a6a73d6b6ca5dc3e45dbc63c7c9045

Author: Philippe Gerum 
Date:   Wed Jun  1 15:59:27 2016 +0200

testsuite/gpiotest: add GPIO test suite

---

 testsuite/Makefile.am  |2 +
 testsuite/gpiotest/Makefile.am |   19 
 testsuite/gpiotest/gpiotest.c  |  188 
 3 files changed, 209 insertions(+)

diff --git a/testsuite/Makefile.am b/testsuite/Makefile.am
index e83e6cb..c345472 100644
--- a/testsuite/Makefile.am
+++ b/testsuite/Makefile.am
@@ -4,12 +4,14 @@ SUBDIRS = latency smokey
 if XENO_COBALT
 SUBDIRS += \
clocktest   \
+   gpiotest\
switchtest  \
xeno-test
 endif
 
 DIST_SUBDIRS = \
clocktest   \
+   gpiotest\
latency \
smokey  \
switchtest  \
diff --git a/testsuite/gpiotest/Makefile.am b/testsuite/gpiotest/Makefile.am
new file mode 100644
index 000..b01427b
--- /dev/null
+++ b/testsuite/gpiotest/Makefile.am
@@ -0,0 +1,19 @@
+testdir = @XENO_TEST_DIR@
+
+CCLD = $(top_srcdir)/scripts/wrap-link.sh $(CC)
+
+test_PROGRAMS = gpiotest
+
+gpiotest_SOURCES = gpiotest.c
+
+gpiotest_CPPFLAGS =\
+   $(XENO_USER_CFLAGS) \
+   -I$(top_srcdir)/include
+
+gpiotest_LDFLAGS = @XENO_AUTOINIT_LDFLAGS@ $(XENO_POSIX_WRAPPERS)
+
+gpiotest_LDADD =   \
+   ../../lib/smokey/libsmokey.la   \
+   ../../lib/@XENO_CORE_LIB@   \
+@XENO_USER_LDADD@  \
+   -lpthread -lrt
diff --git a/testsuite/gpiotest/gpiotest.c b/testsuite/gpiotest/gpiotest.c
new file mode 100644
index 000..838f498
--- /dev/null
+++ b/testsuite/gpiotest/gpiotest.c
@@ -0,0 +1,188 @@
+/*
+ * Copyright (C) 2016 Philippe Gerum .
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+smokey_test_plugin(interrupt,
+  SMOKEY_ARGLIST(
+  SMOKEY_STRING(device),
+  ),
+   "Wait for interrupts from a GPIO pin.\n"
+   "\tdevice=."
+);
+
+smokey_test_plugin(read_value,
+  SMOKEY_ARGLIST(
+  SMOKEY_STRING(device),
+  ),
+   "Read GPIO value.\n"
+   "\tdevice=."
+);
+
+smokey_test_plugin(write_value,
+  SMOKEY_ARGLIST(
+  SMOKEY_STRING(device),
+  ),
+   "Write GPIO value.\n"
+   "\tdevice=."
+);
+
+static int run_interrupt(struct smokey_test *t, int argc, char *const argv[])
+{
+   const char *device = NULL;
+   int fd, ret;
+   fd_set set;
+   
+   smokey_parse_args(t, argc, argv);
+
+   if (!SMOKEY_ARG_ISSET(interrupt, device)) {
+   warning("missing device= specification");
+   return -EINVAL;
+   }
+
+   device = SMOKEY_ARG_STRING(interrupt, device);
+   fd = open(device, O_RDWR);
+   if (fd < 0) {
+   ret = -errno;
+   warning("cannot open device %s [%s]",
+   device, symerror(ret));
+   return ret;
+   }
+
+   ret = ioctl(fd, GPIO_RTIOC_IRQEN);
+   if (ret) {
+   ret = -errno;
+   warning("GPIO_RTIOC_IRQEN failed on %s [%s]",
+   device, symerror(ret));
+   return ret;
+   }
+
+   FD_ZERO(&set);
+   FD_SET(fd, &set);
+   
+   for (;;) {
+   ret = select(fd + 1, &set, NULL, NULL, NULL);
+   if (ret < 0) {
+   ret = -errno;
+   warning("failed listening to %s [%s]",
+   device, symerror(ret));
+   }
+   printf("kick %d!\n", ret);
+   }
+
+   close(fd);
+
+   return 0;
+}
+
+static int run_read_value(struct smokey_test *t, int argc, char *const argv[])
+{
+   const char *device = NULL;
+   int fd, ret, value = -1;
+
+   smokey_parse_args(t, argc, argv);
+
+   if (!SMOKEY_ARG_ISSET(read_value, device)) {
+   warning("missing device= specification");
+   return -EINVAL;
+   

[Xenomai-git] Philippe Gerum : drivers/ipc/xddp: fix select() support for the real-time endpoint

2016-06-02 Thread git repository hosting
Module: xenomai-3
Branch: stable-3.0.x
Commit: fd828bf38f2c7ba5140cbbf1ae932a5e184f823f
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=fd828bf38f2c7ba5140cbbf1ae932a5e184f823f

Author: Philippe Gerum 
Date:   Thu Jun  2 14:55:25 2016 +0200

drivers/ipc/xddp: fix select() support for the real-time endpoint

---

 kernel/drivers/ipc/xddp.c |   26 --
 1 file changed, 12 insertions(+), 14 deletions(-)

diff --git a/kernel/drivers/ipc/xddp.c b/kernel/drivers/ipc/xddp.c
index a528061..c91aa02 100644
--- a/kernel/drivers/ipc/xddp.c
+++ b/kernel/drivers/ipc/xddp.c
@@ -184,14 +184,18 @@ static int __xddp_input_handler(struct xnpipe_mh *mh, int 
retval, void *skarg) /
 {
struct xddp_socket *sk = skarg;
 
-   if (sk->monitor == NULL)
-   return retval;
+   if (sk->monitor) {
+   if (retval == 0)
+   /* Callee may alter the return value passed to 
userland. */
+   retval = sk->monitor(sk->fd, XDDP_EVTIN, 
xnpipe_m_size(mh));
+   else if (retval == -EPIPE && mh == NULL)
+   sk->monitor(sk->fd, XDDP_EVTDOWN, 0);
+   }
 
-   if (retval == 0)
-   /* Callee may alter the return value passed to userland. */
-   retval = sk->monitor(sk->fd, XDDP_EVTIN, xnpipe_m_size(mh));
-   else if (retval == -EPIPE && mh == NULL)
-   sk->monitor(sk->fd, XDDP_EVTDOWN, 0);
+   if (retval == 0 &&
+   (__xnpipe_pollstate(sk->minor) & POLLIN) != 0 &&
+   xnselect_signal(&sk->priv->recv_block, POLLIN))
+   xnsched_run();
 
return retval;
 }
@@ -577,13 +581,7 @@ nostream:
rtdm_fd_unlock(rfd);
return ret;
}
- done:
-   cobalt_atomic_enter(s);
-   if ((__xnpipe_pollstate(rsk->minor) & POLLIN) != 0 &&
-   xnselect_signal(&rsk->priv->recv_block, POLLIN))
-   xnsched_run();
-   cobalt_atomic_leave(s);
-
+done:
rtdm_fd_unlock(rfd);
 
return len;


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Jan Kiszka : cobalt/kernel: Fix infinite loops on thread cleanup

2016-06-02 Thread git repository hosting
Module: xenomai-3
Branch: stable-3.0.x
Commit: 35c0893e3e91ae33d2e12572638f7f38a21c9542
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=35c0893e3e91ae33d2e12572638f7f38a21c9542

Author: Jan Kiszka 
Date:   Sat May 21 00:03:24 2016 +0200

cobalt/kernel: Fix infinite loops on thread cleanup

Due to flipped parameters of list_for_each_entry_safe,
cobalt_signal_flush caused eventual infinite loops.

Signed-off-by: Jan Kiszka 

---

 kernel/cobalt/posix/signal.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/cobalt/posix/signal.c b/kernel/cobalt/posix/signal.c
index a3ec756..4822fda 100644
--- a/kernel/cobalt/posix/signal.c
+++ b/kernel/cobalt/posix/signal.c
@@ -194,7 +194,7 @@ void cobalt_signal_flush(struct cobalt_thread *thread)
 * detect this fact when deleting their respective
 * owners.
 */
-   list_for_each_entry_safe(tmp, sigp, sigq, next)
+   list_for_each_entry_safe(sigp, tmp, sigq, next)
list_del_init(&sigp->next);
}
 


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Jan Kiszka : cobalt/rtdm: Also initialized driver refcount for protocol devices

2016-06-02 Thread git repository hosting
Module: xenomai-3
Branch: stable-3.0.x
Commit: 7fa3633957cee1a7d1cc8b2704858992e9c49821
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=7fa3633957cee1a7d1cc8b2704858992e9c49821

Author: Jan Kiszka 
Date:   Fri May 27 11:35:26 2016 +0200

cobalt/rtdm: Also initialized driver refcount for protocol devices

Was only done for named devices, thus leaving protocol devices in limbo
state after rtdm_dev_unregister.

Signed-off-by: Jan Kiszka 

---

 kernel/cobalt/rtdm/device.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/cobalt/rtdm/device.c b/kernel/cobalt/rtdm/device.c
index 8c54890..3e6a46b 100644
--- a/kernel/cobalt/rtdm/device.c
+++ b/kernel/cobalt/rtdm/device.c
@@ -303,10 +303,10 @@ static int register_driver(struct rtdm_driver *drv)
goto fail_cdev;
 
drv->named.major = MAJOR(rdev);
-   atomic_set(&drv->refcount, 1);
bitmap_zero(drv->minor_map, RTDM_MAX_MINOR);
 
 done:
+   atomic_set(&drv->refcount, 1);
drv->nb_statechange.notifier_call = state_change_notifier;
drv->nb_statechange.priority = 0;
cobalt_add_state_chain(&drv->nb_statechange);


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Jan Kiszka : cobalt/rtdm: Fix driver reference counting

2016-06-02 Thread git repository hosting
Module: xenomai-3
Branch: stable-3.0.x
Commit: 2af3ab42d7a38f93e56ae714a446ce7c8d66bfc8
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=2af3ab42d7a38f93e56ae714a446ce7c8d66bfc8

Author: Jan Kiszka 
Date:   Fri May 27 08:32:41 2016 +0200

cobalt/rtdm: Fix driver reference counting

The rtdm smokey test triggered a BUG due to rtdm_dev_unregister not
taking the reference counter of a driver into account. Fix this by
moving the check into unregister_driver directly.

Signed-off-by: Jan Kiszka 

---

 kernel/cobalt/rtdm/device.c |6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/kernel/cobalt/rtdm/device.c b/kernel/cobalt/rtdm/device.c
index aa62169..8c54890 100644
--- a/kernel/cobalt/rtdm/device.c
+++ b/kernel/cobalt/rtdm/device.c
@@ -324,6 +324,9 @@ static void unregister_driver(struct rtdm_driver *drv)
 {
XENO_BUG_ON(COBALT, drv->profile_info.magic != RTDM_CLASS_MAGIC);
 
+   if (!atomic_dec_and_test(&drv->refcount))
+   return;
+
cobalt_remove_state_chain(&drv->nb_statechange);
 
drv->profile_info.magic = ~RTDM_CLASS_MAGIC;
@@ -477,8 +480,7 @@ fail:
if (kdev)
device_destroy(kdev_class, rdev);
 
-   if (atomic_dec_and_test(&drv->refcount))
-   unregister_driver(drv);
+   unregister_driver(drv);
 
mutex_unlock(®ister_lock);
 


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Jan Kiszka : cobalt/rtdm: Also initialized driver refcount for protocol devices

2016-06-02 Thread git repository hosting
Module: xenomai-3
Branch: next
Commit: 4cc8fc3d6cc51b920d61473c280364e0e46fdef8
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=4cc8fc3d6cc51b920d61473c280364e0e46fdef8

Author: Jan Kiszka 
Date:   Fri May 27 11:35:26 2016 +0200

cobalt/rtdm: Also initialized driver refcount for protocol devices

Was only done for named devices, thus leaving protocol devices in limbo
state after rtdm_dev_unregister.

Signed-off-by: Jan Kiszka 

---

 kernel/cobalt/rtdm/device.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/cobalt/rtdm/device.c b/kernel/cobalt/rtdm/device.c
index 8c54890..3e6a46b 100644
--- a/kernel/cobalt/rtdm/device.c
+++ b/kernel/cobalt/rtdm/device.c
@@ -303,10 +303,10 @@ static int register_driver(struct rtdm_driver *drv)
goto fail_cdev;
 
drv->named.major = MAJOR(rdev);
-   atomic_set(&drv->refcount, 1);
bitmap_zero(drv->minor_map, RTDM_MAX_MINOR);
 
 done:
+   atomic_set(&drv->refcount, 1);
drv->nb_statechange.notifier_call = state_change_notifier;
drv->nb_statechange.priority = 0;
cobalt_add_state_chain(&drv->nb_statechange);


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : drivers/ipc/xddp: fix select() support for the real-time endpoint

2016-06-02 Thread git repository hosting
Module: xenomai-3
Branch: next
Commit: 539812255e0b552da76be83c9a142e5c3de85999
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=539812255e0b552da76be83c9a142e5c3de85999

Author: Philippe Gerum 
Date:   Thu Jun  2 14:55:25 2016 +0200

drivers/ipc/xddp: fix select() support for the real-time endpoint

---

 kernel/drivers/ipc/xddp.c |   26 --
 1 file changed, 12 insertions(+), 14 deletions(-)

diff --git a/kernel/drivers/ipc/xddp.c b/kernel/drivers/ipc/xddp.c
index a528061..c91aa02 100644
--- a/kernel/drivers/ipc/xddp.c
+++ b/kernel/drivers/ipc/xddp.c
@@ -184,14 +184,18 @@ static int __xddp_input_handler(struct xnpipe_mh *mh, int 
retval, void *skarg) /
 {
struct xddp_socket *sk = skarg;
 
-   if (sk->monitor == NULL)
-   return retval;
+   if (sk->monitor) {
+   if (retval == 0)
+   /* Callee may alter the return value passed to 
userland. */
+   retval = sk->monitor(sk->fd, XDDP_EVTIN, 
xnpipe_m_size(mh));
+   else if (retval == -EPIPE && mh == NULL)
+   sk->monitor(sk->fd, XDDP_EVTDOWN, 0);
+   }
 
-   if (retval == 0)
-   /* Callee may alter the return value passed to userland. */
-   retval = sk->monitor(sk->fd, XDDP_EVTIN, xnpipe_m_size(mh));
-   else if (retval == -EPIPE && mh == NULL)
-   sk->monitor(sk->fd, XDDP_EVTDOWN, 0);
+   if (retval == 0 &&
+   (__xnpipe_pollstate(sk->minor) & POLLIN) != 0 &&
+   xnselect_signal(&sk->priv->recv_block, POLLIN))
+   xnsched_run();
 
return retval;
 }
@@ -577,13 +581,7 @@ nostream:
rtdm_fd_unlock(rfd);
return ret;
}
- done:
-   cobalt_atomic_enter(s);
-   if ((__xnpipe_pollstate(rsk->minor) & POLLIN) != 0 &&
-   xnselect_signal(&rsk->priv->recv_block, POLLIN))
-   xnsched_run();
-   cobalt_atomic_leave(s);
-
+done:
rtdm_fd_unlock(rfd);
 
return len;


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Jan Kiszka : cobalt/rtdm: Fix driver reference counting

2016-06-02 Thread git repository hosting
Module: xenomai-3
Branch: next
Commit: aaff949b9792ab6f80041e39424399d82a83888c
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=aaff949b9792ab6f80041e39424399d82a83888c

Author: Jan Kiszka 
Date:   Fri May 27 08:32:41 2016 +0200

cobalt/rtdm: Fix driver reference counting

The rtdm smokey test triggered a BUG due to rtdm_dev_unregister not
taking the reference counter of a driver into account. Fix this by
moving the check into unregister_driver directly.

Signed-off-by: Jan Kiszka 

---

 kernel/cobalt/rtdm/device.c |6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/kernel/cobalt/rtdm/device.c b/kernel/cobalt/rtdm/device.c
index aa62169..8c54890 100644
--- a/kernel/cobalt/rtdm/device.c
+++ b/kernel/cobalt/rtdm/device.c
@@ -324,6 +324,9 @@ static void unregister_driver(struct rtdm_driver *drv)
 {
XENO_BUG_ON(COBALT, drv->profile_info.magic != RTDM_CLASS_MAGIC);
 
+   if (!atomic_dec_and_test(&drv->refcount))
+   return;
+
cobalt_remove_state_chain(&drv->nb_statechange);
 
drv->profile_info.magic = ~RTDM_CLASS_MAGIC;
@@ -477,8 +480,7 @@ fail:
if (kdev)
device_destroy(kdev_class, rdev);
 
-   if (atomic_dec_and_test(&drv->refcount))
-   unregister_driver(drv);
+   unregister_driver(drv);
 
mutex_unlock(®ister_lock);
 


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Jan Kiszka : cobalt/kernel: Fix infinite loops on thread cleanup

2016-06-02 Thread git repository hosting
Module: xenomai-3
Branch: next
Commit: f1bb28c0f08b631ba65eae70d0fb06f785975831
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=f1bb28c0f08b631ba65eae70d0fb06f785975831

Author: Jan Kiszka 
Date:   Sat May 21 00:03:24 2016 +0200

cobalt/kernel: Fix infinite loops on thread cleanup

Due to flipped parameters of list_for_each_entry_safe,
cobalt_signal_flush caused eventual infinite loops.

Signed-off-by: Jan Kiszka 

---

 kernel/cobalt/posix/signal.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/cobalt/posix/signal.c b/kernel/cobalt/posix/signal.c
index a3ec756..4822fda 100644
--- a/kernel/cobalt/posix/signal.c
+++ b/kernel/cobalt/posix/signal.c
@@ -194,7 +194,7 @@ void cobalt_signal_flush(struct cobalt_thread *thread)
 * detect this fact when deleting their respective
 * owners.
 */
-   list_for_each_entry_safe(tmp, sigp, sigq, next)
+   list_for_each_entry_safe(sigp, tmp, sigq, next)
list_del_init(&sigp->next);
}
 


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : ksrc, include: cope with introduction of user_msghdr

2016-06-02 Thread git repository hosting
Module: xenomai-2.6
Branch: master
Commit: 54515995de2143734b16b16ba3419cdf016fc0dd
URL:
http://git.xenomai.org/?p=xenomai-2.6.git;a=commit;h=54515995de2143734b16b16ba3419cdf016fc0dd

Author: Philippe Gerum 
Date:   Wed May 25 14:32:05 2016 +0200

ksrc, include: cope with introduction of user_msghdr

---

 include/rtdm/rtcan.h |2 +-
 include/rtdm/rtdm.h  |   15 +--
 include/rtdm/rtdm_driver.h   |4 ++--
 include/rtdm/rtipc.h |4 ++--
 ksrc/drivers/can/rtcan_raw.c |6 +++---
 ksrc/drivers/ipc/bufp.c  |4 ++--
 ksrc/drivers/ipc/iddp.c  |4 ++--
 ksrc/drivers/ipc/internal.h  |4 ++--
 ksrc/drivers/ipc/rtipc.c |4 ++--
 ksrc/drivers/ipc/xddp.c  |4 ++--
 ksrc/skins/rtdm/core.c   |   12 ++--
 ksrc/skins/rtdm/syscall.c|4 ++--
 12 files changed, 35 insertions(+), 32 deletions(-)

diff --git a/include/rtdm/rtcan.h b/include/rtdm/rtcan.h
index b8bd762..3ff7651 100644
--- a/include/rtdm/rtcan.h
+++ b/include/rtdm/rtcan.h
@@ -146,7 +146,7 @@
  * It is possible to receive a high precision timestamp with every CAN
  * message. The condition is a former instruction to the socket via
  * @ref RTCAN_RTIOC_TAKE_TIMESTAMP. The timestamp will be copied to the
- * @c msg_control buffer of struct msghdr if it points to a valid
+ * @c msg_control buffer of struct user_msghdr if it points to a valid
  * memory location with size of @ref nanosecs_abs_t. If this
  * is a NULL pointer the timestamp will be discarded silently. @n
  * @n
diff --git a/include/rtdm/rtdm.h b/include/rtdm/rtdm.h
index d907f08..64accfc 100644
--- a/include/rtdm/rtdm.h
+++ b/include/rtdm/rtdm.h
@@ -54,6 +54,7 @@
 #include 
 #include 
 #include 
+#include 
 
 typedef u32 socklen_t;
 typedef struct task_struct rtdm_user_info_t;
@@ -247,9 +248,9 @@ ssize_t __rt_dev_read(rtdm_user_info_t *user_info, int fd, 
void *buf,
 ssize_t __rt_dev_write(rtdm_user_info_t *user_info, int fd, const void *buf,
   size_t nbyte);
 ssize_t __rt_dev_recvmsg(rtdm_user_info_t *user_info, int fd,
-struct msghdr *msg, int flags);
+struct user_msghdr *msg, int flags);
 ssize_t __rt_dev_sendmsg(rtdm_user_info_t *user_info, int fd,
-const struct msghdr *msg, int flags);
+const struct user_msghdr *msg, int flags);
 #endif /* __KERNEL__ */
 
 /* Define RTDM_NO_DEFAULT_USER_API to switch off the default rt_dev_xxx
@@ -287,7 +288,7 @@ static inline ssize_t rt_dev_recvfrom(int fd, void *buf, 
size_t len, int flags,
  socklen_t *fromlen)
 {
struct iovec iov;
-   struct msghdr msg;
+   struct user_msghdr msg;
int ret;
 
iov.iov_base = buf;
@@ -308,6 +309,8 @@ static inline ssize_t rt_dev_recvfrom(int fd, void *buf, 
size_t len, int flags,
 
 #else /* !__KERNEL__ */
 
+#define user_msghdr msghdr
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -318,8 +321,8 @@ int rt_dev_close(int fd);
 int rt_dev_ioctl(int fd, int request, ...);
 ssize_t rt_dev_read(int fd, void *buf, size_t nbyte);
 ssize_t rt_dev_write(int fd, const void *buf, size_t nbyte);
-ssize_t rt_dev_recvmsg(int fd, struct msghdr *msg, int flags);
-ssize_t rt_dev_sendmsg(int fd, const struct msghdr *msg, int flags);
+ssize_t rt_dev_recvmsg(int fd, struct user_msghdr *msg, int flags);
+ssize_t rt_dev_sendmsg(int fd, const struct user_msghdr *msg, int flags);
 
 ssize_t rt_dev_recvfrom(int fd, void *buf, size_t len, int flags,
struct sockaddr *from, socklen_t *fromlen);
@@ -344,7 +347,7 @@ static inline ssize_t rt_dev_sendto(int fd, const void 
*buf, size_t len,
socklen_t tolen)
 {
struct iovec iov;
-   struct msghdr msg;
+   struct user_msghdr msg;
 
iov.iov_base = (void *)buf;
iov.iov_len = len;
diff --git a/include/rtdm/rtdm_driver.h b/include/rtdm/rtdm_driver.h
index 15d61d3..f0f82b7 100644
--- a/include/rtdm/rtdm_driver.h
+++ b/include/rtdm/rtdm_driver.h
@@ -305,7 +305,7 @@ typedef ssize_t (*rtdm_write_handler_t)(struct 
rtdm_dev_context *context,
  * http://www.opengroup.org/onlinepubs/009695399 */
 typedef ssize_t (*rtdm_recvmsg_handler_t)(struct rtdm_dev_context *context,
  rtdm_user_info_t *user_info,
- struct msghdr *msg, int flags);
+ struct user_msghdr *msg, int flags);
 
 /**
  * Transmit message handler
@@ -325,7 +325,7 @@ typedef ssize_t (*rtdm_recvmsg_handler_t)(struct 
rtdm_dev_context *context,
  * http://www.opengroup.org/onlinepubs/009695399 */
 typedef ssize_t (*rtdm_sendmsg_handler_t)(struct rtdm_dev_context *context,
  rtdm_user_info_t *user_info,
- const struct msghdr *msg, int flags);
+ const struct user_

[Xenomai-git] Philippe Gerum : hal/generic: add backward wrappers for legacy cpu mask ops

2016-06-02 Thread git repository hosting
Module: xenomai-2.6
Branch: master
Commit: 16c3ad926fca58f9572e258b58be526028797b46
URL:
http://git.xenomai.org/?p=xenomai-2.6.git;a=commit;h=16c3ad926fca58f9572e258b58be526028797b46

Author: Philippe Gerum 
Date:   Wed May 25 12:38:36 2016 +0200

hal/generic: add backward wrappers for legacy cpu mask ops

---

 include/asm-generic/wrappers.h |   17 +
 1 file changed, 17 insertions(+)

diff --git a/include/asm-generic/wrappers.h b/include/asm-generic/wrappers.h
index 089e45a..b4b4291 100644
--- a/include/asm-generic/wrappers.h
+++ b/include/asm-generic/wrappers.h
@@ -807,4 +807,21 @@ proc_create(const char *name, mode_t mode, struct 
proc_dir_entry *parent,
 #endif /* < 2.6.25 */
 #endif /* < 3.10 */
 
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,0,0)
+#define cpu_set(cpu, mask) cpumask_set_cpu(cpu, &(mask))
+#define cpu_clear(cpu, mask)   cpumask_clear_cpu(cpu, &(mask))
+#define cpus_clear(mask)   cpumask_clear(&(mask))
+#define cpu_isset(cpu, mask)   cpumask_test_cpu(cpu, &(mask))
+#define cpus_and(dst, src1, src2)  cpumask_and(&(dst), &(src1), &(src2))
+#define cpus_equal(mask1, mask2)   cpumask_equal(&(mask1), &(mask2))
+#define cpus_empty(mask)   cpumask_empty(&(mask))
+#define cpu_test_and_set(cpu, mask)cpumask_test_and_set_cpu(cpu, &(mask))
+#define first_cpu(mask)cpumask_first(&(mask))
+#define cpumask_of_cpu(mask)   (*cpumask_of(mask))
+#endif
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(3,19,0)
+#define user_msghdr msghdr
+#endif
+
 #endif /* _XENO_ASM_GENERIC_WRAPPERS_H */


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : scripts/prepare-kernel: allow building over 4.x kernel series

2016-06-02 Thread git repository hosting
Module: xenomai-2.6
Branch: master
Commit: 45be10c19d319d30257b930b8b26e6923616a22a
URL:
http://git.xenomai.org/?p=xenomai-2.6.git;a=commit;h=45be10c19d319d30257b930b8b26e6923616a22a

Author: Philippe Gerum 
Date:   Wed May 25 12:39:14 2016 +0200

scripts/prepare-kernel: allow building over 4.x kernel series

---

 scripts/prepare-kernel.sh |4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/scripts/prepare-kernel.sh b/scripts/prepare-kernel.sh
index 021c650..7e91033 100755
--- a/scripts/prepare-kernel.sh
+++ b/scripts/prepare-kernel.sh
@@ -453,10 +453,10 @@ patch_kernelversion_specific="y"
 case $linux_VERSION.$linux_PATCHLEVEL in
 
 #
-#  Linux v2.6 and 3.x section
+#  Linux v2.6 and above section
 #
 
-2.6|3.*)
+2.6|3.*|4.*)
 
 config_file=Kconfig
 


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : copperplate/heapobj-pshared: introduce allocation bitmap

2016-06-05 Thread git repository hosting
Module: xenomai-3
Branch: wip/heap-bitmap
Commit: 72ea1bdc6a12839c10326daf59564c2a16768e0c
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=72ea1bdc6a12839c10326daf59564c2a16768e0c

Author: Philippe Gerum 
Date:   Fri Jun  3 10:00:38 2016 +0200

copperplate/heapobj-pshared: introduce allocation bitmap

Using a free list leads to pathological execution times when releasing
blocks obtained from huge heaps (i.e. hundreds of megabytes). Rework
the core to use an allocation bitmap instead.

---

 lib/copperplate/heapobj-pshared.c |  389 +
 lib/copperplate/internal.h|   18 +-
 2 files changed, 238 insertions(+), 169 deletions(-)

diff --git a/lib/copperplate/heapobj-pshared.c 
b/lib/copperplate/heapobj-pshared.c
index 8c5dac6..2186d7c 100644
--- a/lib/copperplate/heapobj-pshared.c
+++ b/lib/copperplate/heapobj-pshared.c
@@ -28,6 +28,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -43,15 +44,7 @@
 #include "xenomai/init.h"
 #include "internal.h"
 
-#define HOBJ_PAGE_SHIFT9   /* 2^9 => 512 bytes */
-#define HOBJ_PAGE_SIZE (1U << HOBJ_PAGE_SHIFT)
-#define HOBJ_PAGE_MASK (~(HOBJ_PAGE_SIZE-1))
-#define HOBJ_PAGE_ALIGN(addr)  (((addr)+HOBJ_PAGE_SIZE-1)&HOBJ_PAGE_MASK)
-
-#define HOBJ_MINALIGNSZ (1U << 4) /* i.e. 16 bytes */
-#define HOBJ_MAXEXTSZ   (1U << 31) /* i.e. 2Gb */
-
-enum {
+enum { /* FIXME: page_free redundant with future 
bitmap */
page_free =0,
page_cont =1,
page_list =2
@@ -66,8 +59,9 @@ struct shared_extent {
struct holder link;
memoff_t membase;   /* Base offset of page array */
memoff_t memlim;/* Offset limit of page array */
-   memoff_t freelist;  /* Head of free page list */
-   struct page_entry pagemap[1]; /* Start of page map */
+   memoff_t bitmap;/* Offset of allocation bitmap */
+   int bitwords;   /* 32bit words in bitmap */
+   struct page_entry pagemap[0]; /* Start of page map */
 };
 
 /*
@@ -117,24 +111,38 @@ static inline size_t __align_to(size_t size, size_t al)
return ((size+al-1)&(~(al-1)));
 }
 
-static inline size_t get_pagemap_size(size_t h)
+static inline size_t get_pagemap_size(size_t h,
+ memoff_t *bmapoff, int *bmapwords)
 {
+   int nrpages = h >> HOBJ_PAGE_SHIFT, bitmapw;
+   size_t pagemapsz;
+
/*
 * Return the size of the meta data required to map 'h' bytes
 * of user memory in pages of HOBJ_PAGE_SIZE bytes. The meta
 * data includes the length of the extent descriptor, plus the
-* length of the page mapping array. 'h' must be a multiple of
-* HOBJ_PAGE_SIZE on entry.
+* length of the page mapping array followed by the allocation
+* bitmap. 'h' must be a multiple of HOBJ_PAGE_SIZE on entry.
 */
assert((h & ~HOBJ_PAGE_MASK) == 0);
-   return __align_to((h >> HOBJ_PAGE_SHIFT) * sizeof(struct page_entry)
- + sizeof(struct shared_extent), HOBJ_MINALIGNSZ);
+   pagemapsz = __align_to(nrpages * sizeof(struct page_entry),
+  sizeof(uint32_t));
+   bitmapw =__align_to(nrpages, 32) / 32;
+   if (bmapoff)
+   *bmapoff = offsetof(struct shared_extent, pagemap) + pagemapsz;
+   if (bmapwords)
+   *bmapwords = bitmapw;
+
+   return __align_to(pagemapsz
+ + sizeof(struct shared_extent)
+ + bitmapw * sizeof(uint32_t),
+ HOBJ_MINALIGNSZ);
 }
 
 static void init_extent(void *base, struct shared_extent *extent)
 {
-   caddr_t freepage;
int n, lastpgnum;
+   uint32_t *p;
 
__holder_init_nocheck(base, &extent->link);
 
@@ -147,19 +155,20 @@ static void init_extent(void *base, struct shared_extent 
*extent)
assert(lastpgnum >= 1);
 
/* Mark each page as free in the page map. */
-   for (n = 0, freepage = __shref(base, extent->membase);
-n < lastpgnum; n++, freepage += HOBJ_PAGE_SIZE) {
-   *((memoff_t *)freepage) = __shoff(base, freepage) + 
HOBJ_PAGE_SIZE;
+   for (n = 0; n <= lastpgnum; n++) {
extent->pagemap[n].type = page_free;
extent->pagemap[n].bcount = 0;
}
 
-   *((memoff_t *)freepage) = 0;
-   extent->pagemap[lastpgnum].type = page_free;
-   extent->pagemap[lastpgnum].bcount = 0;
-
-   /* The first page starts the free list of a new extent. */
-   extent->freelist = extent->membase;
+   /* Clear the allocation bitmap. */
+   p = __shref(base, extent->bitmap);
+   memset(p, 0, extent->bitwords * sizeof(uint32_t));
+   /*
+* Mark the unused trailing bits (due to alignment) as busy,
+* we don't want to pick them since they don't map any actual
+* memory from the page pool.
+

  1   2   3   4   5   6   7   8   9   10   >