[Xenomai-git] Philippe Gerum : testsuite/sched-tp: fix priority level of test thread
Module: xenomai-forge Branch: next Commit: fe84ba357a445e1e50cf67e4124aae426cd0651c URL: http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=fe84ba357a445e1e50cf67e4124aae426cd0651c Author: Philippe Gerum r...@xenomai.org Date: Thu Dec 19 15:35:45 2013 +0100 testsuite/sched-tp: fix priority level of test thread --- testsuite/unit/sched-tp.c |2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testsuite/unit/sched-tp.c b/testsuite/unit/sched-tp.c index 5af1688..d051238 100644 --- a/testsuite/unit/sched-tp.c +++ b/testsuite/unit/sched-tp.c @@ -68,7 +68,7 @@ static void cleanup(int sig) static void __create_thread(pthread_t *tid, const char *name, int seq) { - struct sched_param param; + struct sched_param param = { .sched_priority = 1 }; pthread_attr_t attr; int ret; ___ Xenomai-git mailing list Xenomai-git@xenomai.org http://www.xenomai.org/mailman/listinfo/xenomai-git
[Xenomai-git] Gilles Chanteperdrix : cobalt/mutex: export through registry
Module: xenomai-forge Branch: next Commit: 6d4f960c7f1e065c90129395c6ca47d64f6b6d72 URL: http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=6d4f960c7f1e065c90129395c6ca47d64f6b6d72 Author: Gilles Chanteperdrix gilles.chanteperd...@xenomai.org Date: Thu Dec 5 22:07:48 2013 +0100 cobalt/mutex: export through registry --- include/cobalt/uapi/mutex.h |2 +- kernel/cobalt/posix/mutex.c | 127 +-- kernel/cobalt/posix/mutex.h |1 + 3 files changed, 88 insertions(+), 42 deletions(-) diff --git a/include/cobalt/uapi/mutex.h b/include/cobalt/uapi/mutex.h index dec09e2..88c95e7 100644 --- a/include/cobalt/uapi/mutex.h +++ b/include/cobalt/uapi/mutex.h @@ -32,7 +32,7 @@ union cobalt_mutex_union { struct __shadow_mutex { unsigned int magic; unsigned int lockcnt; - struct cobalt_mutex *mutex; + xnhandle_t handle; union { unsigned int dat_offset; struct mutex_dat *dat; diff --git a/kernel/cobalt/posix/mutex.c b/kernel/cobalt/posix/mutex.c index 2b1c515..c94ed79 100644 --- a/kernel/cobalt/posix/mutex.c +++ b/kernel/cobalt/posix/mutex.c @@ -62,6 +62,7 @@ static int cobalt_mutex_init_inner(struct __shadow_mutex *shadow, struct xnsys_ppd *sys_ppd; struct cobalt_kqueues *kq; spl_t s; + int err; if (!attr) attr = cobalt_default_mutex_attr; @@ -71,9 +72,12 @@ static int cobalt_mutex_init_inner(struct __shadow_mutex *shadow, kq = cobalt_kqueues(attr-pshared); sys_ppd = xnsys_ppd_get(attr-pshared); + err = xnregistry_enter(, mutex, shadow-handle, NULL); + if (err 0) + return err; + mutex-handle = shadow-handle; shadow-magic = COBALT_MUTEX_MAGIC; - shadow-mutex = mutex; shadow-lockcnt = 0; shadow-attr = *attr; @@ -97,12 +101,21 @@ static int cobalt_mutex_init_inner(struct __shadow_mutex *shadow, return 0; } -static void cobalt_mutex_destroy_inner(struct cobalt_mutex *mutex, - struct cobalt_kqueues *q) +static void +cobalt_mutex_destroy_inner(xnhandle_t handle, struct cobalt_kqueues *q) { + struct cobalt_mutex *mutex; spl_t s; xnlock_get_irqsave(nklock, s); + mutex = xnregistry_fetch(handle); + if (!cobalt_obj_active(mutex, COBALT_MUTEX_MAGIC, typeof(*mutex))) { + xnlock_put_irqrestore(nklock, s); + printk(mutex_destroy: invalid mutex %x\n, + mutex ? mutex-magic : ~0); + return; + } + xnregistry_remove(handle); list_del(mutex-link); /* * synchbase wait queue may not be empty only when this @@ -110,6 +123,7 @@ static void cobalt_mutex_destroy_inner(struct cobalt_mutex *mutex, * absence of xnsched_run(). */ xnsynch_destroy(mutex-synchbase); + cobalt_mark_deleted(mutex); xnlock_put_irqrestore(nklock, s); xnheap_free(xnsys_ppd_get(mutex-attr.pshared)-sem_heap, @@ -240,30 +254,23 @@ int cobalt_mutex_timedlock_break(struct cobalt_mutex *mutex, int cobalt_mutex_check_init(struct __shadow_mutex __user *u_mx) { - struct list_head *mutexq, *entry; struct cobalt_mutex *mutex; - int qnr; + xnhandle_t handle; + int err; spl_t s; - __xn_get_user(mutex, u_mx-mutex); + __xn_get_user(handle, u_mx-handle); - for (qnr = 0; qnr 2; qnr++) { - mutexq = cobalt_kqueues(qnr)-mutexq; - xnlock_get_irqsave(nklock, s); - if (!list_empty(mutexq)) { - list_for_each(entry, mutexq) { - if (entry == mutex-link) - goto busy; - } - } - xnlock_put_irqrestore(nklock, s); - } + xnlock_get_irqsave(nklock, s); + mutex = xnregistry_fetch(handle); + if (cobalt_obj_active(mutex, COBALT_MUTEX_MAGIC, typeof(*mutex))) + /* mutex is already in a queue. */ + err = -EBUSY; + else + err = 0; - return 0; -busy: xnlock_put_irqrestore(nklock, s); - /* mutex is already in a queue. */ - return -EBUSY; + return err; } int cobalt_mutex_init(struct __shadow_mutex __user *u_mx, @@ -313,23 +320,39 @@ int cobalt_mutex_destroy(struct __shadow_mutex __user *u_mx) { struct cobalt_mutex *mutex; struct __shadow_mutex mx; + spl_t s; + int err; if (__xn_safe_copy_from_user(mx, u_mx, sizeof(mx))) return -EFAULT; - mutex = mx.mutex; - if (cobalt_kqueues(mutex-attr.pshared) != mutex-owningq) - return -EPERM; + xnlock_get_irqsave(nklock, s); + mutex = xnregistry_fetch(mx.handle); +
[Xenomai-git] Philippe Gerum : cobalt/thread: demote thread upon cancellation request
Module: xenomai-forge Branch: next Commit: 0cc962d5dbdfc5449a54bba8abcd3e11d5b7f3dc URL: http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=0cc962d5dbdfc5449a54bba8abcd3e11d5b7f3dc Author: Philippe Gerum r...@xenomai.org Date: Sat Dec 14 12:17:23 2013 +0100 cobalt/thread: demote thread upon cancellation request A thread which is sent a cancellation request might be held internally by the scheduling policy it undergoes, in a way that would prevent it from waking up for exiting. Typically, a SCHED_QUOTA thread with no runtime budget at the time of the request would be prevented from exiting. To address this issue, we demote threads receiving a cancellation request, which implies switching them out of primary mode, and moving to the weak scheduling class, where it cannot be held. --- kernel/cobalt/thread.c |2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/cobalt/thread.c b/kernel/cobalt/thread.c index d05482f..5bf8f39 100644 --- a/kernel/cobalt/thread.c +++ b/kernel/cobalt/thread.c @@ -1535,7 +1535,7 @@ check_self_cancel: return; } - __xnshadow_kick(thread); + __xnshadow_demote(thread); xnsched_run(); unlock_and_exit: ___ Xenomai-git mailing list Xenomai-git@xenomai.org http://www.xenomai.org/mailman/listinfo/xenomai-git
[Xenomai-git] Philippe Gerum : cobalt/sched-tp: set CPU affinity of the per-sched frame timer
Module: xenomai-forge Branch: next Commit: 1fe0a2f16746b82b9b0fcd163d3273ab33d1bd71 URL: http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=1fe0a2f16746b82b9b0fcd163d3273ab33d1bd71 Author: Philippe Gerum r...@xenomai.org Date: Tue Dec 10 16:21:25 2013 +0100 cobalt/sched-tp: set CPU affinity of the per-sched frame timer --- kernel/cobalt/sched-tp.c |1 + 1 file changed, 1 insertion(+) diff --git a/kernel/cobalt/sched-tp.c b/kernel/cobalt/sched-tp.c index 165ae1d..03c6d67 100644 --- a/kernel/cobalt/sched-tp.c +++ b/kernel/cobalt/sched-tp.c @@ -101,6 +101,7 @@ static void xnsched_tp_init(struct xnsched *sched) tp-gps = NULL; INIT_LIST_HEAD(tp-threads); xntimer_init_noblock(tp-tf_timer, nkclock, tp_tick_handler, NULL); + xntimer_set_sched(tp-tf_timer, sched); xntimer_set_name(tp-tf_timer, tp-tick); } ___ Xenomai-git mailing list Xenomai-git@xenomai.org http://www.xenomai.org/mailman/listinfo/xenomai-git
[Xenomai-git] Philippe Gerum : cobalt/cond: export through registry
Module: xenomai-forge Branch: next Commit: 48718f9697e8e8ceca952dae6249a72f47ea23cf URL: http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=48718f9697e8e8ceca952dae6249a72f47ea23cf Author: Philippe Gerum r...@xenomai.org Date: Fri Dec 20 09:11:16 2013 +0100 cobalt/cond: export through registry --- include/cobalt/uapi/cond.h |2 +- kernel/cobalt/posix/cond.c | 72 +--- kernel/cobalt/posix/cond.h |1 + 3 files changed, 50 insertions(+), 25 deletions(-) diff --git a/include/cobalt/uapi/cond.h b/include/cobalt/uapi/cond.h index de37315..0c6157a 100644 --- a/include/cobalt/uapi/cond.h +++ b/include/cobalt/uapi/cond.h @@ -27,7 +27,7 @@ union cobalt_cond_union { struct __shadow_cond { unsigned int magic; struct cobalt_condattr attr; - struct cobalt_cond *cond; + xnhandle_t handle; union { unsigned int pending_signals_offset; unsigned long *pending_signals; diff --git a/kernel/cobalt/posix/cond.c b/kernel/cobalt/posix/cond.c index 571bdc7..87dd09d 100644 --- a/kernel/cobalt/posix/cond.c +++ b/kernel/cobalt/posix/cond.c @@ -54,16 +54,24 @@ #include clock.h static inline void -cond_destroy_internal(struct cobalt_cond *cond, struct cobalt_kqueues *q) +cond_destroy_internal(xnhandle_t handle, struct cobalt_kqueues *q) { + struct cobalt_cond *cond; spl_t s; xnlock_get_irqsave(nklock, s); + cond = xnregistry_fetch(handle); + if (!cobalt_obj_active(cond, COBALT_COND_MAGIC, typeof(*cond))) { + xnlock_put_irqrestore(nklock, s); + return; + } + xnregistry_remove(handle); list_del(cond-link); /* synchbase wait queue may not be empty only when this function is called from cobalt_cond_pkg_cleanup, hence the absence of xnsched_run(). */ xnsynch_destroy(cond-synchbase); + cobalt_mark_deleted(cond); xnlock_put_irqrestore(nklock, s); xnheap_free(xnsys_ppd_get(cond-attr.pshared)-sem_heap, cond-pending_signals); @@ -99,9 +107,9 @@ static inline int pthread_cond_init(struct __shadow_cond *cnd, const pthread_condattr_t *attr) { int synch_flags = XNSYNCH_PRIO | XNSYNCH_NOPIP, err; - struct list_head *condq, *entry; + struct cobalt_cond *cond, *old_cond; + struct list_head *condq; struct xnsys_ppd *sys_ppd; - struct cobalt_cond *cond; spl_t s; if (attr == NULL) @@ -139,18 +147,23 @@ pthread_cond_init(struct __shadow_cond *cnd, const pthread_condattr_t *attr) if (cnd-magic != COBALT_COND_MAGIC || list_empty(condq)) goto do_init; - list_for_each(entry, condq) { - if (entry == cnd-cond-link) { - if (attr-pshared) { - cond_destroy_internal(cnd-cond, - cobalt_kqueues(1)); - goto do_init; - } - err = -EBUSY; - goto err_free_pending_signals; - } + old_cond = xnregistry_fetch(cnd-handle); + if (!cobalt_obj_active(old_cond, COBALT_COND_MAGIC, typeof(*old_cond))) + goto do_init; + + if (attr-pshared == 0) { + err = -EBUSY; + goto err_free_pending_signals; } + xnlock_put_irqrestore(nklock, s); + cond_destroy_internal(cnd-handle, cobalt_kqueues(1)); + xnlock_get_irqsave(nklock, s); do_init: + err = xnregistry_enter(, cond, cond-handle, NULL); + if (err 0) + goto err_free_pending_signals; + + cnd-handle = cond-handle; cnd-attr = *attr; cnd-pending_signals_offset = xnheap_mapped_offset(sys_ppd-sem_heap, @@ -158,7 +171,6 @@ do_init: cnd-mutex_datp = (struct mutex_dat *)~0UL; cnd-magic = COBALT_COND_MAGIC; - cnd-cond = cond; cond-magic = COBALT_COND_MAGIC; xnsynch_init(cond-synchbase, synch_flags, NULL); @@ -205,11 +217,16 @@ do_init: static inline int pthread_cond_destroy(struct __shadow_cond *cnd) { struct cobalt_cond *cond; + int pshared; spl_t s; xnlock_get_irqsave(nklock, s); - - cond = cnd-cond; + cond = xnregistry_fetch(cnd-handle); + if (cond == NULL) { + xnlock_put_irqrestore(nklock, s); + return -EINVAL; + } + if (!cobalt_obj_active(cnd, COBALT_COND_MAGIC, struct __shadow_cond) || !cobalt_obj_active(cond, COBALT_COND_MAGIC, struct cobalt_cond)) { xnlock_put_irqrestore(nklock, s); @@ -227,11 +244,10 @@ static inline int pthread_cond_destroy(struct __shadow_cond *cnd) } cobalt_mark_deleted(cnd); - cobalt_mark_deleted(cond); -
[Xenomai-git] Philippe Gerum : cobalt/sched: introduce sched_kick() handler for policy modules
Module: xenomai-forge Branch: next Commit: cee27b2945f92857308dcde619a3e64607b5327e URL: http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=cee27b2945f92857308dcde619a3e64607b5327e Author: Philippe Gerum r...@xenomai.org Date: Tue Dec 17 19:07:57 2013 +0100 cobalt/sched: introduce sched_kick() handler for policy modules Scheduling policies may prevent threads from running based on some extra state, by not returning them from the sched_pick() handler, without reflecting such state with any block bit. Those threads remain in the ready state from the scheduler core point of view, although they won't be elected for running. This behavior is typical of policies enforcing a runtime budget for instance. However, we also have to honor the request to move a thread out of primary mode (i.e. shadow kicking). Therefore we need a way to tell the policy module to release such thread temporarily, until it eventually relaxes (e.g. sigwake - kick - relax). To this end, the sched_kick() handler can be defined by policy modules for dealing with this specific case. It is called for kicked threads bearing the XNREADY bit, once all block bits have been lifted. --- include/cobalt/kernel/sched.h | 19 +++ kernel/cobalt/sched-idle.c |1 + kernel/cobalt/sched-rt.c |1 + kernel/cobalt/sched-sporadic.c |1 + kernel/cobalt/sched-tp.c |6 -- kernel/cobalt/sched-weak.c |1 + kernel/cobalt/shadow.c | 34 +- 7 files changed, 48 insertions(+), 15 deletions(-) diff --git a/include/cobalt/kernel/sched.h b/include/cobalt/kernel/sched.h index addfd0c..d32a404 100644 --- a/include/cobalt/kernel/sched.h +++ b/include/cobalt/kernel/sched.h @@ -147,6 +147,7 @@ struct xnsched_class { int (*sched_declare)(struct xnthread *thread, const union xnsched_policy_param *p); void (*sched_forget)(struct xnthread *thread); + void (*sched_kick)(struct xnthread *thread); #ifdef CONFIG_XENO_OPT_VFILE int (*sched_init_vfile)(struct xnsched_class *schedclass, struct xnvfile_directory *vfroot); @@ -581,6 +582,18 @@ static inline void xnsched_forget(struct xnthread *thread) sched_class-sched_forget(thread); } +static inline void xnsched_kick(struct xnthread *thread) +{ + struct xnsched_class *sched_class = thread-base_class; + + xnthread_set_info(thread, XNKICKED); + + if (sched_class-sched_kick) + sched_class-sched_kick(thread); + + xnsched_set_resched(thread-sched); +} + #else /* !CONFIG_XENO_OPT_SCHED_CLASSES */ /* @@ -655,6 +668,12 @@ static inline void xnsched_forget(struct xnthread *thread) __xnsched_rt_forget(thread); } +static inline void xnsched_kick(struct xnthread *thread) +{ + xnthread_set_info(thread, XNKICKED); + xnsched_set_resched(thread-sched); +} + #endif /* !CONFIG_XENO_OPT_SCHED_CLASSES */ /*@}*/ diff --git a/kernel/cobalt/sched-idle.c b/kernel/cobalt/sched-idle.c index 51ce963..5127798 100644 --- a/kernel/cobalt/sched-idle.c +++ b/kernel/cobalt/sched-idle.c @@ -49,6 +49,7 @@ struct xnsched_class xnsched_class_idle = { .sched_tick = NULL, .sched_rotate = NULL, .sched_forget = NULL, + .sched_kick = NULL, .sched_declare = NULL, .sched_pick = xnsched_idle_pick, .sched_setparam = xnsched_idle_setparam, diff --git a/kernel/cobalt/sched-rt.c b/kernel/cobalt/sched-rt.c index c92b0a0..c5001fc 100644 --- a/kernel/cobalt/sched-rt.c +++ b/kernel/cobalt/sched-rt.c @@ -244,6 +244,7 @@ struct xnsched_class xnsched_class_rt = { .sched_tick = xnsched_rt_tick, .sched_rotate = xnsched_rt_rotate, .sched_forget = NULL, + .sched_kick = NULL, .sched_declare = NULL, .sched_setparam = xnsched_rt_setparam, .sched_trackprio= xnsched_rt_trackprio, diff --git a/kernel/cobalt/sched-sporadic.c b/kernel/cobalt/sched-sporadic.c index 8f9d3b1..a523391 100644 --- a/kernel/cobalt/sched-sporadic.c +++ b/kernel/cobalt/sched-sporadic.c @@ -536,6 +536,7 @@ struct xnsched_class xnsched_class_sporadic = { .sched_trackprio= xnsched_sporadic_trackprio, .sched_declare = xnsched_sporadic_declare, .sched_forget = xnsched_sporadic_forget, + .sched_kick = NULL, #ifdef CONFIG_XENO_OPT_VFILE .sched_init_vfile = xnsched_sporadic_init_vfile, .sched_cleanup_vfile= xnsched_sporadic_cleanup_vfile, diff --git a/kernel/cobalt/sched-tp.c b/kernel/cobalt/sched-tp.c index 03c6d67..bf30c7a 100644 --- a/kernel/cobalt/sched-tp.c +++
[Xenomai-git] Philippe Gerum : copperplate/registry: detect SCHED_QUOTA policy for threads
Module: xenomai-forge Branch: next Commit: 50a8cad7e55a68332d5750748aa9c2cad9a6d017 URL: http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=50a8cad7e55a68332d5750748aa9c2cad9a6d017 Author: Philippe Gerum r...@xenomai.org Date: Thu Dec 19 15:56:37 2013 +0100 copperplate/registry: detect SCHED_QUOTA policy for threads --- lib/copperplate/regd/fs-common.c |5 + 1 file changed, 5 insertions(+) diff --git a/lib/copperplate/regd/fs-common.c b/lib/copperplate/regd/fs-common.c index d4e2b78..96a4f87 100644 --- a/lib/copperplate/regd/fs-common.c +++ b/lib/copperplate/regd/fs-common.c @@ -158,6 +158,11 @@ ssize_t read_threads(struct fsobj *fsobj, char *buf, sched_class = tp; break; #endif +#ifdef SCHED_QUOTA + case SCHED_QUOTA: + sched_class = quota; + break; +#endif default: sched_class = other; break; ___ Xenomai-git mailing list Xenomai-git@xenomai.org http://www.xenomai.org/mailman/listinfo/xenomai-git
[Xenomai-git] Gilles Chanteperdrix : cobalt/sem: export through registry
Module: xenomai-forge Branch: next Commit: 07aab6ec30964b23a6a86b6be36360cabe8ec3de URL: http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=07aab6ec30964b23a6a86b6be36360cabe8ec3de Author: Gilles Chanteperdrix gilles.chanteperd...@xenomai.org Date: Sun Dec 15 17:09:32 2013 +0100 cobalt/sem: export through registry --- include/cobalt/uapi/sem.h|4 +- kernel/cobalt/posix/Makefile |1 + kernel/cobalt/posix/init.c |7 + kernel/cobalt/posix/nsem.c | 313 +++ kernel/cobalt/posix/sem.c| 574 +- kernel/cobalt/posix/sem.h| 33 ++- lib/cobalt/semaphore.c | 19 +- 7 files changed, 482 insertions(+), 469 deletions(-) diff --git a/include/cobalt/uapi/sem.h b/include/cobalt/uapi/sem.h index a1a9526..e011141 100644 --- a/include/cobalt/uapi/sem.h +++ b/include/cobalt/uapi/sem.h @@ -18,6 +18,8 @@ #ifndef _COBALT_UAPI_SEM_H #define _COBALT_UAPI_SEM_H +#include cobalt/uapi/kernel/types.h + #define COBALT_SEM_MAGIC (0x86860707) #define COBALT_NAMED_SEM_MAGIC (0x86860D0D) @@ -32,8 +34,8 @@ union cobalt_sem_union { sem_t native_sem; struct __shadow_sem { unsigned int magic; - struct cobalt_sem *sem; int datp_offset; + xnhandle_t handle; } shadow_sem; }; diff --git a/kernel/cobalt/posix/Makefile b/kernel/cobalt/posix/Makefile index d08442d..aad94a6 100644 --- a/kernel/cobalt/posix/Makefile +++ b/kernel/cobalt/posix/Makefile @@ -12,6 +12,7 @@ posix-y :=\ mutex_attr.o\ registry.o \ sem.o \ + nsem.o \ select.o\ signal.o\ syscall.o \ diff --git a/kernel/cobalt/posix/init.c b/kernel/cobalt/posix/init.c index 4676d27..02e0b08 100644 --- a/kernel/cobalt/posix/init.c +++ b/kernel/cobalt/posix/init.c @@ -64,6 +64,7 @@ MODULE_LICENSE(GPL); void cobalt_cleanup(void) { cobalt_syscall_cleanup(); + cobalt_nsem_pkg_cleanup(); cobalt_timer_pkg_cleanup(); cobalt_monitor_pkg_cleanup(); cobalt_event_pkg_cleanup(); @@ -83,6 +84,12 @@ int __init cobalt_init(void) if (ret) return ret; + ret = cobalt_nsem_pkg_init(); + if (ret) { + cobalt_syscall_cleanup(); + return ret; + } + cobalt_reg_pkg_init(64, 128); /* FIXME: replace with compilation constants. */ cobalt_mutex_pkg_init(); cobalt_sem_pkg_init(); diff --git a/kernel/cobalt/posix/nsem.c b/kernel/cobalt/posix/nsem.c new file mode 100644 index 000..c19faaf --- /dev/null +++ b/kernel/cobalt/posix/nsem.c @@ -0,0 +1,313 @@ +/* + * Copyright (C) 2013 Gilles Chanteperdrix gilles.chanteperd...@xenomai.org. + * + * 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 linux/list.h +#include linux/err.h +#include cobalt/kernel/lock.h +#include cobalt/kernel/heap.h +#include internal.h +#include sem.h + +static struct hlist_head *nsem_hash; +DEFINE_XNLOCK(nsem_lock); +static unsigned mm_mult, mm_shift, nsem_hash_size; + +struct nsem { + struct cobalt_sem *sem; + struct mm_struct *mm; + struct __shadow_sem __user *usem; + unsigned refs; + struct hlist_node hlink; /* Link in global hash */ + struct list_head link; /* Link in per-process queue */ +}; + +static unsigned __attribute__((pure)) +nsem_hash_crunch(xnhandle_t handle, struct mm_struct *mm) +{ + unsigned long hash = (unsigned long)mm; + hash = handle + (((unsigned long long)hash * mm_mult) mm_shift); + return hash % nsem_hash_size; +} + +static struct nsem * +nsem_hash_search(xnhandle_t handle, struct mm_struct *mm) +{ + unsigned bucket = nsem_hash_crunch(handle, mm); + struct nsem *u; + + hlist_for_each_entry(u, nsem_hash[bucket], hlink) + if (u-sem-handle == handle u-mm == mm) + return u; + + return NULL; +} + +static void nsem_hash_enter(xnhandle_t handle, struct nsem *nsem) +{ + unsigned bucket = nsem_hash_crunch(handle, current-mm); + + hlist_add_head(nsem-hlink, nsem_hash[bucket]); +} + +static void nsem_hash_remove(struct nsem *u) +{ + hlist_del(u-hlink); +} + +static struct
[Xenomai-git] Philippe Gerum : cobalt/shadow: force runaway thread out of primary mode upon signal
Module: xenomai-forge Branch: next Commit: fdd9004f642299d7351d8d69c4d26281fbf995ee URL: http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=fdd9004f642299d7351d8d69c4d26281fbf995ee Author: Philippe Gerum r...@xenomai.org Date: Wed Dec 18 12:09:14 2013 +0100 cobalt/shadow: force runaway thread out of primary mode upon signal --- kernel/cobalt/shadow.c |2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/cobalt/shadow.c b/kernel/cobalt/shadow.c index 1a9b519..0a40e83 100644 --- a/kernel/cobalt/shadow.c +++ b/kernel/cobalt/shadow.c @@ -2468,7 +2468,7 @@ static int handle_sigwake_event(struct task_struct *p) if (p-state (TASK_INTERRUPTIBLE|TASK_UNINTERRUPTIBLE)) set_task_state(p, p-state | TASK_NOWAKEUP); - force_wakeup(thread); + __xnshadow_kick(thread); xnsched_run(); ___ Xenomai-git mailing list Xenomai-git@xenomai.org http://www.xenomai.org/mailman/listinfo/xenomai-git
[Xenomai-git] Gilles Chanteperdrix : testsuite: various improvements in leaks test
Module: xenomai-forge Branch: next Commit: 7a3c3d156a3fcaab52792dcb0c30d848cf1aadca URL: http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=7a3c3d156a3fcaab52792dcb0c30d848cf1aadca Author: Gilles Chanteperdrix gilles.chanteperd...@xenomai.org Date: Sun Dec 15 19:54:36 2013 +0100 testsuite: various improvements in leaks test Fix timer_create parameters to cope with timer_create API changes (SIGEV_SIGNAL is no longer supported). Add a fork test to verify automatic objects destruction upon process termination. --- testsuite/regression/posix/leaks.c | 42 +++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/testsuite/regression/posix/leaks.c b/testsuite/regression/posix/leaks.c index f368cae..4e8a769 100644 --- a/testsuite/regression/posix/leaks.c +++ b/testsuite/regression/posix/leaks.c @@ -9,6 +9,9 @@ #include semaphore.h #include mqueue.h #include signal.h +#include sys/types.h +#include sys/wait.h +#include linux/unistd.h #include cobalt/uapi/kernel/heap.h #include asm/xenomai/syscall.h @@ -50,6 +53,28 @@ static void *empty(void *cookie) return cookie; } +static void subprocess_leak(void) +{ + struct sigevent sevt; + pthread_mutex_t mutex; + pthread_cond_t cond; + pthread_t thread; + sem_t sem, *psem; + timer_t tm; + int fd; + + check_pthread(pthread_create(thread, NULL, empty, NULL)); + check_pthread(pthread_mutex_init(mutex, NULL)); + check_pthread(pthread_cond_init(cond, NULL)); + check_unix(sem_init(sem, 0, 0)); + check_unix(-!(psem = sem_open(SEM_NAME, O_CREAT, 0644, 1))); + sevt.sigev_notify = SIGEV_THREAD_ID; + sevt.sigev_signo = SIGALRM; + sevt.sigev_notify_thread_id = syscall(__NR_gettid); + check_unix(timer_create(CLOCK_MONOTONIC, sevt, tm)); + check_unix(fd = mq_open(MQ_NAME, O_RDWR | O_CREAT, 0644, NULL)); +} + int main(void) { unsigned long long before; @@ -60,6 +85,7 @@ int main(void) pthread_t thread; sem_t sem, *psem; timer_t tm; + pid_t child; mlockall(MCL_CURRENT|MCL_FUTURE); @@ -93,8 +119,9 @@ int main(void) check_used(named sem, before, failed); before = get_used(); - sevt.sigev_notify = SIGEV_SIGNAL; + sevt.sigev_notify = SIGEV_THREAD_ID; sevt.sigev_signo = SIGALRM; + sevt.sigev_notify_thread_id = syscall(__NR_gettid); check_unix(timer_create(CLOCK_MONOTONIC, sevt, tm)); check_unix(timer_delete(tm)); check_used(timer, before, failed); @@ -105,5 +132,18 @@ int main(void) check_unix(mq_unlink(MQ_NAME)); check_used(mq, before, failed); + before = get_used(); + check_unix(child = fork()); + if (!child) { + subprocess_leak(); + return EXIT_SUCCESS; + } + while (waitpid(child, NULL, 0) == -1 errno == EINTR); + sleep(1); /* Leave some time for xnheap +* deferred free */ + check_unix(sem_unlink(SEM_NAME)); + check_unix(mq_unlink(MQ_NAME)); + check_used(fork, before, failed); + return failed ? EXIT_FAILURE : EXIT_SUCCESS; } ___ Xenomai-git mailing list Xenomai-git@xenomai.org http://www.xenomai.org/mailman/listinfo/xenomai-git
[Xenomai-git] Philippe Gerum : lib/cobalt: enable SCHED_QUOTA policy
Module: xenomai-forge Branch: next Commit: 5cb540dd3454a48b0a7fa877b5a5c04494c17710 URL: http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=5cb540dd3454a48b0a7fa877b5a5c04494c17710 Author: Philippe Gerum r...@xenomai.org Date: Thu Dec 19 15:55:58 2013 +0100 lib/cobalt: enable SCHED_QUOTA policy --- include/cobalt/sched.h |2 ++ lib/cobalt/thread.c|3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/include/cobalt/sched.h b/include/cobalt/sched.h index fd53161..ece501c 100644 --- a/include/cobalt/sched.h +++ b/include/cobalt/sched.h @@ -44,6 +44,8 @@ void __sched_cpufill(size_t __setsize, cpu_set_t *__setp); #define sched_tp_confsz(nr_win) \ (sizeof(struct __sched_config_tp) + nr_win * sizeof(struct sched_tp_window)) +#define sched_quota_confsz() sizeof(struct __sched_config_quota) + #ifdef __cplusplus extern C { #endif diff --git a/lib/cobalt/thread.c b/lib/cobalt/thread.c index 89c1d46..bf3c22b 100644 --- a/lib/cobalt/thread.c +++ b/lib/cobalt/thread.c @@ -30,7 +30,7 @@ #include internal.h #include boilerplate/ancillaries.h -static pthread_attr_ex_t default_attr_ex; +static pthread_attr_ex_t default_attr_ex; /* We want it zeroed at init. */ static int linuxthreads; @@ -59,6 +59,7 @@ static int libc_setschedparam(pthread_t thread, case SCHED_COBALT: case SCHED_TP: case SCHED_SPORADIC: + case SCHED_QUOTA: policy = SCHED_FIFO; /* * Our priority range is larger than the regular ___ Xenomai-git mailing list Xenomai-git@xenomai.org http://www.xenomai.org/mailman/listinfo/xenomai-git
[Xenomai-git] Philippe Gerum : cobalt/assert: introduce XENO_WARNON, XENO_BUG
Module: xenomai-forge Branch: next Commit: ed6f62c36fcbf4657f5e0ba74567e64edf288e9f URL: http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=ed6f62c36fcbf4657f5e0ba74567e64edf288e9f Author: Philippe Gerum r...@xenomai.org Date: Thu Dec 19 15:36:49 2013 +0100 cobalt/assert: introduce XENO_WARNON, XENO_BUG --- include/cobalt/kernel/assert.h |9 + 1 file changed, 9 insertions(+) diff --git a/include/cobalt/kernel/assert.h b/include/cobalt/kernel/assert.h index 158d51f..63886a1 100644 --- a/include/cobalt/kernel/assert.h +++ b/include/cobalt/kernel/assert.h @@ -43,6 +43,15 @@ __FILE__, __LINE__, (#__cond)); \ } while (0) +#define XENO_BUG(__subsys) XENO_BUGON(__subsys, 1) + +#define XENO_WARNON(__subsys, __cond) \ + do {\ + if (unlikely(XENO_DEBUG(__subsys) (__cond))) \ + printk(XENO_WARN assertion failed at %s:%d (%s), \ + __FILE__, __LINE__, (#__cond)); \ + } while (0) + #ifndef CONFIG_XENO_OPT_DEBUG_NUCLEUS #define CONFIG_XENO_OPT_DEBUG_NUCLEUS 0 #endif ___ Xenomai-git mailing list Xenomai-git@xenomai.org http://www.xenomai.org/mailman/listinfo/xenomai-git
[Xenomai-git] Philippe Gerum : cobalt/thread: allow changing thread priority from secondary mode
Module: xenomai-forge Branch: next Commit: 9b6513daf5fae678be8fb347c8c25a490e7210d9 URL: http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=9b6513daf5fae678be8fb347c8c25a490e7210d9 Author: Philippe Gerum r...@xenomai.org Date: Fri Dec 20 09:36:45 2013 +0100 cobalt/thread: allow changing thread priority from secondary mode The former restriction on calling xnthread_set_schedparam() from primary mode only is no more. In addition, we introduce the inner __xnthread_set_schedparam() routine for callers already running in atomic context. --- include/cobalt/kernel/thread.h |4 +++ kernel/cobalt/sched-sporadic.c |4 +-- kernel/cobalt/shadow.c |2 +- kernel/cobalt/thread.c | 69 +--- 4 files changed, 43 insertions(+), 36 deletions(-) diff --git a/include/cobalt/kernel/thread.h b/include/cobalt/kernel/thread.h index aa2fd46..4223ddc 100644 --- a/include/cobalt/kernel/thread.h +++ b/include/cobalt/kernel/thread.h @@ -437,6 +437,10 @@ static inline void xnthread_migrate_passive(struct xnthread *thread, #endif +int __xnthread_set_schedparam(struct xnthread *thread, + struct xnsched_class *sched_class, + const union xnsched_policy_param *sched_param); + int xnthread_set_schedparam(struct xnthread *thread, struct xnsched_class *sched_class, const union xnsched_policy_param *sched_param); diff --git a/kernel/cobalt/sched-sporadic.c b/kernel/cobalt/sched-sporadic.c index 44438ab..8f9d3b1 100644 --- a/kernel/cobalt/sched-sporadic.c +++ b/kernel/cobalt/sched-sporadic.c @@ -86,7 +86,7 @@ static void sporadic_drop_handler(struct xntimer *timer) p.pss.init_budget = 0; p.pss.current_prio = pss-param.low_prio; /* Move sporadic thread to the background. */ - xnthread_set_schedparam(thread, xnsched_class_sporadic, p); + __xnthread_set_schedparam(thread, xnsched_class_sporadic, p); } } } @@ -161,7 +161,7 @@ retry: p.pss.init_budget = 0; p.pss.current_prio = pss-param.normal_prio; /* Move sporadic thread to the foreground. */ - xnthread_set_schedparam(thread, xnsched_class_sporadic, p); + __xnthread_set_schedparam(thread, xnsched_class_sporadic, p); } /* diff --git a/kernel/cobalt/shadow.c b/kernel/cobalt/shadow.c index 148bdc6..6105622 100644 --- a/kernel/cobalt/shadow.c +++ b/kernel/cobalt/shadow.c @@ -818,7 +818,7 @@ void __xnshadow_demote(struct xnthread *thread) /* nklock locked, irqs off */ param.rt.prio = 0; sched_class = xnsched_class_rt; #endif - xnthread_set_schedparam(thread, sched_class, param); + __xnthread_set_schedparam(thread, sched_class, param); } void xnshadow_demote(struct xnthread *thread) diff --git a/kernel/cobalt/thread.c b/kernel/cobalt/thread.c index 00d6c41..d05482f 100644 --- a/kernel/cobalt/thread.c +++ b/kernel/cobalt/thread.c @@ -1780,11 +1780,7 @@ void xnthread_migrate_passive(struct xnthread *thread, struct xnsched *sched) * or ready thread moves it to the end of the runnable queue, thus * causing a manual round-robin. * - * Environments: - * - * This service can be called from: - * - * - Primary mode only. + * Calling context: any. * * Rescheduling: never. * @@ -1797,18 +1793,43 @@ int xnthread_set_schedparam(struct xnthread *thread, struct xnsched_class *sched_class, const union xnsched_policy_param *sched_param) { - int old_wprio, new_wprio, ret; spl_t s; - - primary_mode_only(); + int ret; xnlock_get_irqsave(nklock, s); + ret = __xnthread_set_schedparam(thread, sched_class, sched_param); + xnlock_put_irqrestore(nklock, s); + return ret; +} +EXPORT_SYMBOL_GPL(xnthread_set_schedparam); + +int __xnthread_set_schedparam(struct xnthread *thread, + struct xnsched_class *sched_class, + const union xnsched_policy_param *sched_param) +{ + int old_wprio, new_wprio, ret; + + /* +* NOTE: we do not prevent the caller from altering the +* scheduling parameters of a thread that currently undergoes +* a PIP boost. +* +* Rationale: Calling xnthread_set_schedparam() carelessly +* with no consideration for resource management is a bug in +* essence, and xnthread_set_schedparam() does not have to +* paper over it, especially at the cost of more complexity +* when dealing with multiple scheduling classes. +* +* In short, callers have to make sure that lowering a thread +* priority is safe with respect to what their application +* currently does. +*/
[Xenomai-git] Philippe Gerum : testsuite/unit: introduce SCHED_QUOTA policy test
Module: xenomai-forge Branch: next Commit: 3f0ccecb52b8c46bd824f9cc99b2b49d7173603a URL: http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=3f0ccecb52b8c46bd824f9cc99b2b49d7173603a Author: Philippe Gerum r...@xenomai.org Date: Thu Dec 19 15:57:07 2013 +0100 testsuite/unit: introduce SCHED_QUOTA policy test --- config/libtool.m4| 12 +- configure| 12 +- testsuite/unit/Makefile.am | 15 ++ testsuite/unit/Makefile.in | 50 ++- testsuite/unit/sched-quota.c | 312 ++ 5 files changed, 392 insertions(+), 9 deletions(-) diff --git a/config/libtool.m4 b/config/libtool.m4 index 5f0..126202f 100644 --- a/config/libtool.m4 +++ b/config/libtool.m4 @@ -1312,7 +1312,7 @@ ia64-*-hpux*) rm -rf conftest* ;; -x86_64-*kfreebsd*-gnu|x86_64-*linux*|ppc*-*linux*|powerpc*-*linux*| \ +x86_64-*kfreebsd*-gnu|x86_64-*linux*|powerpc*-*linux*| \ s390*-*linux*|s390*-*tpf*|sparc*-*linux*) # Find out which ABI we are using. echo 'int i;' conftest.$ac_ext @@ -1326,7 +1326,10 @@ s390*-*linux*|s390*-*tpf*|sparc*-*linux*) x86_64-*linux*) LD=${LD-ld} -m elf_i386 ;; - ppc64-*linux*|powerpc64-*linux*) + powerpcle-*linux*) + LD=${LD-ld} -m elf32lppclinux + ;; + powerpc-*linux*) LD=${LD-ld} -m elf32ppclinux ;; s390x-*linux*) @@ -1345,7 +1348,10 @@ s390*-*linux*|s390*-*tpf*|sparc*-*linux*) x86_64-*linux*) LD=${LD-ld} -m elf_x86_64 ;; - ppc*-*linux*|powerpc*-*linux*) + powerpcle-*linux*) + LD=${LD-ld} -m elf64lppc + ;; + powerpc-*linux*) LD=${LD-ld} -m elf64ppc ;; s390*-*linux*|s390*-*tpf*) diff --git a/configure b/configure index 50133f3..304e833 100755 --- a/configure +++ b/configure @@ -7736,7 +7736,7 @@ ia64-*-hpux*) rm -rf conftest* ;; -x86_64-*kfreebsd*-gnu|x86_64-*linux*|ppc*-*linux*|powerpc*-*linux*| \ +x86_64-*kfreebsd*-gnu|x86_64-*linux*|powerpc*-*linux*| \ s390*-*linux*|s390*-*tpf*|sparc*-*linux*) # Find out which ABI we are using. echo 'int i;' conftest.$ac_ext @@ -7754,7 +7754,10 @@ s390*-*linux*|s390*-*tpf*|sparc*-*linux*) x86_64-*linux*) LD=${LD-ld} -m elf_i386 ;; - ppc64-*linux*|powerpc64-*linux*) + powerpcle-*linux*) + LD=${LD-ld} -m elf32lppclinux + ;; + powerpc-*linux*) LD=${LD-ld} -m elf32ppclinux ;; s390x-*linux*) @@ -7773,7 +7776,10 @@ s390*-*linux*|s390*-*tpf*|sparc*-*linux*) x86_64-*linux*) LD=${LD-ld} -m elf_x86_64 ;; - ppc*-*linux*|powerpc*-*linux*) + powerpcle-*linux*) + LD=${LD-ld} -m elf64lppc + ;; + powerpc-*linux*) LD=${LD-ld} -m elf64ppc ;; s390*-*linux*|s390*-*tpf*) diff --git a/testsuite/unit/Makefile.am b/testsuite/unit/Makefile.am index f292d48..a933d99 100644 --- a/testsuite/unit/Makefile.am +++ b/testsuite/unit/Makefile.am @@ -14,6 +14,7 @@ test_PROGRAMS += arith\ mutex-torture \ cond-torture\ sched-tp\ + sched-quota \ check-vdso arith_SOURCES = arith.c arith-noinline.c arith-noinline.h @@ -76,6 +77,20 @@ sched_tp_LDADD = \ @XENO_USER_LDADD@ \ -lpthread -lrt -lm +sched_quota_SOURCES = sched-quota.c + +sched_quota_CPPFLAGS = \ + @XENO_USER_CFLAGS@ \ + -I$(top_srcdir)/include + +sched_quota_LDFLAGS = $(XENO_POSIX_WRAPPERS) + +sched_quota_LDADD =\ + ../../lib/copperplate/libcopperplate.la \ + $(coredep_lib) \ + @XENO_USER_LDADD@ \ + -lpthread -lrt -lm + check_vdso_SOURCES = check-vdso.c check_vdso_CPPFLAGS = \ diff --git a/testsuite/unit/Makefile.in b/testsuite/unit/Makefile.in index 30868d9..80a9bab 100644 --- a/testsuite/unit/Makefile.in +++ b/testsuite/unit/Makefile.in @@ -84,6 +84,7 @@ test_PROGRAMS = wakeup-time$(EXEEXT) rtdm$(EXEEXT) $(am__EXEEXT_1) @XENO_COBALT_TRUE@ mutex-torture \ @XENO_COBALT_TRUE@ cond-torture\ @XENO_COBALT_TRUE@ sched-tp\ +@XENO_COBALT_TRUE@ sched-quota \ @XENO_COBALT_TRUE@ check-vdso subdir = testsuite/unit @@ -106,7 +107,7 @@ CONFIG_CLEAN_FILES = CONFIG_CLEAN_VPATH_FILES = @XENO_COBALT_TRUE@am__EXEEXT_1 = arith$(EXEEXT) mutex-torture$(EXEEXT) \ @XENO_COBALT_TRUE@ cond-torture$(EXEEXT) sched-tp$(EXEEXT) \ -@XENO_COBALT_TRUE@ check-vdso$(EXEEXT) +@XENO_COBALT_TRUE@ sched-quota$(EXEEXT) check-vdso$(EXEEXT) am__installdirs = $(DESTDIR)$(testdir) PROGRAMS = $(test_PROGRAMS) am__arith_SOURCES_DIST = arith.c arith-noinline.c