[Xenomai-git] Gilles Chanteperdrix : cobalt/timer: make timer_id per-process instead of global

2014-02-15 Thread git repository hosting
Module: xenomai-forge
Branch: master
Commit: c0574d09b0614cb383ec2a9657c3933de5cb89a3
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=c0574d09b0614cb383ec2a9657c3933de5cb89a3

Author: Gilles Chanteperdrix gilles.chanteperd...@xenomai.org
Date:   Sun Dec 29 00:28:47 2013 +0100

cobalt/timer: make timer_id per-process instead of global

---

 kernel/cobalt/posix/init.c|2 -
 kernel/cobalt/posix/process.h |7 +-
 kernel/cobalt/posix/syscall.c |9 +-
 kernel/cobalt/posix/timer.c   |  209 ++---
 kernel/cobalt/posix/timer.h   |   19 +---
 5 files changed, 127 insertions(+), 119 deletions(-)

diff --git a/kernel/cobalt/posix/init.c b/kernel/cobalt/posix/init.c
index 02e0b08..e5395d9 100644
--- a/kernel/cobalt/posix/init.c
+++ b/kernel/cobalt/posix/init.c
@@ -65,7 +65,6 @@ void cobalt_cleanup(void)
 {
cobalt_syscall_cleanup();
cobalt_nsem_pkg_cleanup();
-   cobalt_timer_pkg_cleanup();
cobalt_monitor_pkg_cleanup();
cobalt_event_pkg_cleanup();
cobalt_signal_pkg_cleanup();
@@ -98,7 +97,6 @@ int __init cobalt_init(void)
cobalt_mq_pkg_init();
cobalt_event_pkg_init();
cobalt_monitor_pkg_init();
-   cobalt_timer_pkg_init();
 
INIT_LIST_HEAD(cobalt_global_kqueues.threadq);
cobalt_time_slice = CONFIG_XENO_OPT_RR_QUANTUM * 1000;
diff --git a/kernel/cobalt/posix/process.h b/kernel/cobalt/posix/process.h
index 42f3afd..0a4e722 100644
--- a/kernel/cobalt/posix/process.h
+++ b/kernel/cobalt/posix/process.h
@@ -19,6 +19,7 @@
 #define _COBALT_POSIX_PROCESS_H
 
 #include linux/list.h
+#include linux/bitmap.h
 #include cobalt/kernel/ppd.h
 
 struct cobalt_kqueues {
@@ -26,17 +27,21 @@ struct cobalt_kqueues {
struct list_head mutexq;
struct list_head semq;
struct list_head threadq;
-   struct list_head timerq;
struct list_head monitorq;
struct list_head eventq;
 };
 
+struct cobalt_timer;
 struct cobalt_process {
struct cobalt_kqueues kqueues;
struct list_head uqds;
struct list_head usems;
struct xnshadow_ppd ppd;
struct list_head sigwaiters;
+
+   /* timers */
+   DECLARE_BITMAP(timers_map, CONFIG_XENO_OPT_NRTIMERS);
+   struct cobalt_timer *timers[CONFIG_XENO_OPT_NRTIMERS];
 };
 
 extern struct cobalt_kqueues cobalt_global_kqueues;
diff --git a/kernel/cobalt/posix/syscall.c b/kernel/cobalt/posix/syscall.c
index 3848b9a..b89c331 100644
--- a/kernel/cobalt/posix/syscall.c
+++ b/kernel/cobalt/posix/syscall.c
@@ -53,13 +53,14 @@ static struct xnshadow_ppd *cobalt_process_attach(void)
INIT_LIST_HEAD(cc-kqueues.mutexq);
INIT_LIST_HEAD(cc-kqueues.semq);
INIT_LIST_HEAD(cc-kqueues.threadq);
-   INIT_LIST_HEAD(cc-kqueues.timerq);
INIT_LIST_HEAD(cc-kqueues.monitorq);
INIT_LIST_HEAD(cc-kqueues.eventq);
INIT_LIST_HEAD(cc-uqds);
INIT_LIST_HEAD(cc-usems);
INIT_LIST_HEAD(cc-sigwaiters);
 
+   bitmap_fill(cc-timers_map, CONFIG_XENO_OPT_NRTIMERS);
+
return cc-ppd;
 }
 
@@ -71,8 +72,8 @@ static void cobalt_process_detach(struct xnshadow_ppd *ppd)
 
cobalt_sem_usems_cleanup(cc);
cobalt_mq_uqds_cleanup(cc);
+   cobalt_timers_cleanup(cc);
cobalt_monitorq_cleanup(cc-kqueues);
-   cobalt_timerq_cleanup(cc-kqueues);
cobalt_semq_cleanup(cc-kqueues);
cobalt_mutexq_cleanup(cc-kqueues);
cobalt_condq_cleanup(cc-kqueues);
@@ -136,8 +137,8 @@ static struct xnsyscall cobalt_syscalls[] = {
SKINCALL_DEF(sc_cobalt_sigtimedwait, cobalt_sigtimedwait, primary),
SKINCALL_DEF(sc_cobalt_sigpending, cobalt_sigpending, primary),
SKINCALL_DEF(sc_cobalt_kill, cobalt_kill, conforming),
-   SKINCALL_DEF(sc_cobalt_timer_create, cobalt_timer_create, any),
-   SKINCALL_DEF(sc_cobalt_timer_delete, cobalt_timer_delete, any),
+   SKINCALL_DEF(sc_cobalt_timer_create, cobalt_timer_create, lostage),
+   SKINCALL_DEF(sc_cobalt_timer_delete, cobalt_timer_delete, lostage),
SKINCALL_DEF(sc_cobalt_timer_settime, cobalt_timer_settime, primary),
SKINCALL_DEF(sc_cobalt_timer_gettime, cobalt_timer_gettime, any),
SKINCALL_DEF(sc_cobalt_timer_getoverrun, cobalt_timer_getoverrun, any),
diff --git a/kernel/cobalt/posix/timer.c b/kernel/cobalt/posix/timer.c
index 17d7063..6c5994f 100644
--- a/kernel/cobalt/posix/timer.c
+++ b/kernel/cobalt/posix/timer.c
@@ -30,10 +30,6 @@
 #include timer.h
 #include clock.h
 
-struct cobalt_timer *cobalt_timer_pool;
-
-static struct list_head timer_freeq;
-
 void cobalt_timer_handler(struct xntimer *xntimer)
 {
struct cobalt_timer *timer;
@@ -100,6 +96,32 @@ timer_init(struct cobalt_timer *timer,
return target;
 }
 
+static inline int timer_alloc_id(struct cobalt_process *cc)
+{
+   unsigned id;
+
+   id = find_first_bit(cc-timers_map, CONFIG_XENO_OPT_NRTIMERS);
+   if (id == 

[Xenomai-git] Gilles Chanteperdrix : cobalt/timer: make timer_id per-process instead of global

2014-01-19 Thread git repository hosting
Module: xenomai-gch
Branch: for-forge
Commit: c0574d09b0614cb383ec2a9657c3933de5cb89a3
URL:
http://git.xenomai.org/?p=xenomai-gch.git;a=commit;h=c0574d09b0614cb383ec2a9657c3933de5cb89a3

Author: Gilles Chanteperdrix gilles.chanteperd...@xenomai.org
Date:   Sun Dec 29 00:28:47 2013 +0100

cobalt/timer: make timer_id per-process instead of global

---

 kernel/cobalt/posix/init.c|2 -
 kernel/cobalt/posix/process.h |7 +-
 kernel/cobalt/posix/syscall.c |9 +-
 kernel/cobalt/posix/timer.c   |  209 ++---
 kernel/cobalt/posix/timer.h   |   19 +---
 5 files changed, 127 insertions(+), 119 deletions(-)

diff --git a/kernel/cobalt/posix/init.c b/kernel/cobalt/posix/init.c
index 02e0b08..e5395d9 100644
--- a/kernel/cobalt/posix/init.c
+++ b/kernel/cobalt/posix/init.c
@@ -65,7 +65,6 @@ void cobalt_cleanup(void)
 {
cobalt_syscall_cleanup();
cobalt_nsem_pkg_cleanup();
-   cobalt_timer_pkg_cleanup();
cobalt_monitor_pkg_cleanup();
cobalt_event_pkg_cleanup();
cobalt_signal_pkg_cleanup();
@@ -98,7 +97,6 @@ int __init cobalt_init(void)
cobalt_mq_pkg_init();
cobalt_event_pkg_init();
cobalt_monitor_pkg_init();
-   cobalt_timer_pkg_init();
 
INIT_LIST_HEAD(cobalt_global_kqueues.threadq);
cobalt_time_slice = CONFIG_XENO_OPT_RR_QUANTUM * 1000;
diff --git a/kernel/cobalt/posix/process.h b/kernel/cobalt/posix/process.h
index 42f3afd..0a4e722 100644
--- a/kernel/cobalt/posix/process.h
+++ b/kernel/cobalt/posix/process.h
@@ -19,6 +19,7 @@
 #define _COBALT_POSIX_PROCESS_H
 
 #include linux/list.h
+#include linux/bitmap.h
 #include cobalt/kernel/ppd.h
 
 struct cobalt_kqueues {
@@ -26,17 +27,21 @@ struct cobalt_kqueues {
struct list_head mutexq;
struct list_head semq;
struct list_head threadq;
-   struct list_head timerq;
struct list_head monitorq;
struct list_head eventq;
 };
 
+struct cobalt_timer;
 struct cobalt_process {
struct cobalt_kqueues kqueues;
struct list_head uqds;
struct list_head usems;
struct xnshadow_ppd ppd;
struct list_head sigwaiters;
+
+   /* timers */
+   DECLARE_BITMAP(timers_map, CONFIG_XENO_OPT_NRTIMERS);
+   struct cobalt_timer *timers[CONFIG_XENO_OPT_NRTIMERS];
 };
 
 extern struct cobalt_kqueues cobalt_global_kqueues;
diff --git a/kernel/cobalt/posix/syscall.c b/kernel/cobalt/posix/syscall.c
index 3848b9a..b89c331 100644
--- a/kernel/cobalt/posix/syscall.c
+++ b/kernel/cobalt/posix/syscall.c
@@ -53,13 +53,14 @@ static struct xnshadow_ppd *cobalt_process_attach(void)
INIT_LIST_HEAD(cc-kqueues.mutexq);
INIT_LIST_HEAD(cc-kqueues.semq);
INIT_LIST_HEAD(cc-kqueues.threadq);
-   INIT_LIST_HEAD(cc-kqueues.timerq);
INIT_LIST_HEAD(cc-kqueues.monitorq);
INIT_LIST_HEAD(cc-kqueues.eventq);
INIT_LIST_HEAD(cc-uqds);
INIT_LIST_HEAD(cc-usems);
INIT_LIST_HEAD(cc-sigwaiters);
 
+   bitmap_fill(cc-timers_map, CONFIG_XENO_OPT_NRTIMERS);
+
return cc-ppd;
 }
 
@@ -71,8 +72,8 @@ static void cobalt_process_detach(struct xnshadow_ppd *ppd)
 
cobalt_sem_usems_cleanup(cc);
cobalt_mq_uqds_cleanup(cc);
+   cobalt_timers_cleanup(cc);
cobalt_monitorq_cleanup(cc-kqueues);
-   cobalt_timerq_cleanup(cc-kqueues);
cobalt_semq_cleanup(cc-kqueues);
cobalt_mutexq_cleanup(cc-kqueues);
cobalt_condq_cleanup(cc-kqueues);
@@ -136,8 +137,8 @@ static struct xnsyscall cobalt_syscalls[] = {
SKINCALL_DEF(sc_cobalt_sigtimedwait, cobalt_sigtimedwait, primary),
SKINCALL_DEF(sc_cobalt_sigpending, cobalt_sigpending, primary),
SKINCALL_DEF(sc_cobalt_kill, cobalt_kill, conforming),
-   SKINCALL_DEF(sc_cobalt_timer_create, cobalt_timer_create, any),
-   SKINCALL_DEF(sc_cobalt_timer_delete, cobalt_timer_delete, any),
+   SKINCALL_DEF(sc_cobalt_timer_create, cobalt_timer_create, lostage),
+   SKINCALL_DEF(sc_cobalt_timer_delete, cobalt_timer_delete, lostage),
SKINCALL_DEF(sc_cobalt_timer_settime, cobalt_timer_settime, primary),
SKINCALL_DEF(sc_cobalt_timer_gettime, cobalt_timer_gettime, any),
SKINCALL_DEF(sc_cobalt_timer_getoverrun, cobalt_timer_getoverrun, any),
diff --git a/kernel/cobalt/posix/timer.c b/kernel/cobalt/posix/timer.c
index 17d7063..6c5994f 100644
--- a/kernel/cobalt/posix/timer.c
+++ b/kernel/cobalt/posix/timer.c
@@ -30,10 +30,6 @@
 #include timer.h
 #include clock.h
 
-struct cobalt_timer *cobalt_timer_pool;
-
-static struct list_head timer_freeq;
-
 void cobalt_timer_handler(struct xntimer *xntimer)
 {
struct cobalt_timer *timer;
@@ -100,6 +96,32 @@ timer_init(struct cobalt_timer *timer,
return target;
 }
 
+static inline int timer_alloc_id(struct cobalt_process *cc)
+{
+   unsigned id;
+
+   id = find_first_bit(cc-timers_map, CONFIG_XENO_OPT_NRTIMERS);
+   if (id == 

[Xenomai-git] Gilles Chanteperdrix : cobalt/timer: make timer_id per-process instead of global

2013-12-28 Thread git repository hosting
Module: xenomai-gch
Branch: for-forge
Commit: 80fee42db6a174edc3d1368d59d393ee8256e9e3
URL:
http://git.xenomai.org/?p=xenomai-gch.git;a=commit;h=80fee42db6a174edc3d1368d59d393ee8256e9e3

Author: Gilles Chanteperdrix gilles.chanteperd...@xenomai.org
Date:   Sun Dec 29 00:28:47 2013 +0100

cobalt/timer: make timer_id per-process instead of global

---

 kernel/cobalt/posix/process.h |7 +-
 kernel/cobalt/posix/syscall.c |   11 ++-
 kernel/cobalt/posix/timer.c   |  204 +++--
 kernel/cobalt/posix/timer.h   |   14 +--
 4 files changed, 134 insertions(+), 102 deletions(-)

diff --git a/kernel/cobalt/posix/process.h b/kernel/cobalt/posix/process.h
index c19920d..6239b1d 100644
--- a/kernel/cobalt/posix/process.h
+++ b/kernel/cobalt/posix/process.h
@@ -20,13 +20,13 @@
 
 #include linux/list.h
 #include cobalt/kernel/ppd.h
+#include asm/bitsperlong.h
 
 struct cobalt_kqueues {
struct list_head condq;
struct list_head mutexq;
struct list_head semq;
struct list_head threadq;
-   struct list_head timerq;
struct list_head monitorq;
struct list_head eventq;
 };
@@ -36,6 +36,11 @@ struct cobalt_process {
struct list_head usems;
struct xnshadow_ppd ppd;
struct list_head sigwaiters;
+
+   /* timers */
+   unsigned long timers_himap;
+   unsigned long timers_lomap[BITS_PER_LONG];
+   struct list_head timerq;
 };
 
 extern struct cobalt_kqueues cobalt_global_kqueues;
diff --git a/kernel/cobalt/posix/syscall.c b/kernel/cobalt/posix/syscall.c
index 6603d94..82c8ae0 100644
--- a/kernel/cobalt/posix/syscall.c
+++ b/kernel/cobalt/posix/syscall.c
@@ -55,12 +55,15 @@ static struct xnshadow_ppd *cobalt_process_attach(void)
INIT_LIST_HEAD(cc-kqueues.mutexq);
INIT_LIST_HEAD(cc-kqueues.semq);
INIT_LIST_HEAD(cc-kqueues.threadq);
-   INIT_LIST_HEAD(cc-kqueues.timerq);
INIT_LIST_HEAD(cc-kqueues.monitorq);
INIT_LIST_HEAD(cc-kqueues.eventq);
+   INIT_LIST_HEAD(cc-timerq);
INIT_LIST_HEAD(cc-usems);
INIT_LIST_HEAD(cc-sigwaiters);
 
+   cc-timers_himap = ~0UL;
+   memset(cc-timers_lomap, 0xff, sizeof(cc-timers_lomap));
+
return cc-ppd;
 }
 
@@ -71,8 +74,8 @@ static void cobalt_process_detach(struct xnshadow_ppd *ppd)
cc = container_of(ppd, struct cobalt_process, ppd);
 
cobalt_sem_usems_cleanup(cc);
+   cobalt_timerq_cleanup(cc);
cobalt_monitorq_cleanup(cc-kqueues);
-   cobalt_timerq_cleanup(cc-kqueues);
cobalt_semq_cleanup(cc-kqueues);
cobalt_mutexq_cleanup(cc-kqueues);
cobalt_condq_cleanup(cc-kqueues);
@@ -134,8 +137,8 @@ static struct xnsyscall cobalt_syscalls[] = {
SKINCALL_DEF(sc_cobalt_sigtimedwait, cobalt_sigtimedwait, primary),
SKINCALL_DEF(sc_cobalt_sigpending, cobalt_sigpending, primary),
SKINCALL_DEF(sc_cobalt_kill, cobalt_kill, conforming),
-   SKINCALL_DEF(sc_cobalt_timer_create, cobalt_timer_create, any),
-   SKINCALL_DEF(sc_cobalt_timer_delete, cobalt_timer_delete, any),
+   SKINCALL_DEF(sc_cobalt_timer_create, cobalt_timer_create, lostage),
+   SKINCALL_DEF(sc_cobalt_timer_delete, cobalt_timer_delete, lostage),
SKINCALL_DEF(sc_cobalt_timer_settime, cobalt_timer_settime, primary),
SKINCALL_DEF(sc_cobalt_timer_gettime, cobalt_timer_gettime, any),
SKINCALL_DEF(sc_cobalt_timer_getoverrun, cobalt_timer_getoverrun, any),
diff --git a/kernel/cobalt/posix/timer.c b/kernel/cobalt/posix/timer.c
index 18dcb29..1628bba 100644
--- a/kernel/cobalt/posix/timer.c
+++ b/kernel/cobalt/posix/timer.c
@@ -24,14 +24,13 @@
 #include linux/module.h
 #include linux/cred.h
 #include linux/err.h
+#include cobalt/kernel/id_table.h
 #include internal.h
 #include thread.h
 #include timer.h
 #include clock.h
 
-struct cobalt_timer *cobalt_timer_pool;
-
-static struct list_head timer_freeq;
+static struct xnid_table timer_table;
 
 void cobalt_timer_handler(struct xntimer *xntimer)
 {
@@ -99,6 +98,44 @@ timer_init(struct cobalt_timer *timer,
return target;
 }
 
+static inline int timer_alloc_id(struct cobalt_process *proc)
+{
+   unsigned tl, th;
+   
+   th = ffs(proc-timers_himap);
+   if (th == 0)
+   return -EAGAIN;
+   th--;
+   tl = ffs(proc-timers_lomap[th]);
+   tl--;
+   proc-timers_lomap[th] = ~(1  tl);
+   if (proc-timers_lomap[th] == 0)
+   proc-timers_himap = ~(1  th);
+
+   return th * BITS_PER_LONG + tl;
+}
+
+static inline void timer_free_id(struct cobalt_process *proc, int id)
+{
+   unsigned tl, th;
+   
+   tl = id % BITS_PER_LONG;
+   th = id / BITS_PER_LONG;
+   
+   if (proc-timers_lomap[th] == 0)
+   proc-timers_himap |= (1  th);
+   proc-timers_lomap[th] |= (1  tl);
+}
+
+struct cobalt_timer *cobalt_timer_by_id(struct mm_struct *mm, timer_t timer_id)
+{
+   struct xnid *i =