[Xenomai-git] Philippe Gerum : cobalt/posix: introduce tracepoints (WIP)

2014-04-26 Thread git repository hosting
Module: xenomai-forge
Branch: next
Commit: 423e2e4a2c57f5a14a86b5adfc2ad8de1534af96
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=423e2e4a2c57f5a14a86b5adfc2ad8de1534af96

Author: Philippe Gerum r...@xenomai.org
Date:   Sat Apr 26 15:09:17 2014 +0200

cobalt/posix: introduce tracepoints (WIP)

---

 kernel/cobalt/posix/thread.c   |   31 --
 kernel/cobalt/trace/cobalt-posix.h |  193 
 2 files changed, 216 insertions(+), 8 deletions(-)

diff --git a/kernel/cobalt/posix/thread.c b/kernel/cobalt/posix/thread.c
index 83f58d0..262d2ee 100644
--- a/kernel/cobalt/posix/thread.c
+++ b/kernel/cobalt/posix/thread.c
@@ -40,6 +40,8 @@
 #include signal.h
 #include timer.h
 #include clock.h
+#define CREATE_TRACE_POINTS
+#include trace/events/cobalt-posix.h
 
 xnticks_t cobalt_time_slice;
 
@@ -812,18 +814,19 @@ int cobalt_thread_setschedparam_ex(unsigned long pth,
   unsigned long __user *u_window_offset,
   int __user *u_promoted)
 {
+   struct sched_param_ex param_ex;
struct cobalt_local_hkey hkey;
struct cobalt_thread *thread;
-   struct sched_param_ex param;
int ret, promoted = 0;
 
-   if (__xn_safe_copy_from_user(param, u_param, sizeof(param)))
+   if (__xn_safe_copy_from_user(param_ex, u_param, sizeof(param_ex)))
return -EFAULT;
 
hkey.u_pth = pth;
hkey.mm = current-mm;
-   thread = thread_lookup(hkey);
+   trace_cobalt_pthread_setschedparam(pth, policy, param_ex);
 
+   thread = thread_lookup(hkey);
if (thread == NULL  u_window_offset) {
thread = cobalt_thread_shadow(current, hkey, u_window_offset);
if (IS_ERR(thread))
@@ -833,7 +836,7 @@ int cobalt_thread_setschedparam_ex(unsigned long pth,
}
 
if (thread)
-   ret = pthread_setschedparam_ex(thread, policy, param);
+   ret = pthread_setschedparam_ex(thread, policy, param_ex);
else
ret = -EPERM;
 
@@ -853,9 +856,9 @@ int cobalt_thread_getschedparam_ex(unsigned long pth,
   int __user *u_policy,
   struct sched_param_ex __user *u_param)
 {
+   struct sched_param_ex param_ex;
struct cobalt_local_hkey hkey;
struct cobalt_thread *thread;
-   struct sched_param_ex param;
int policy, ret;
 
hkey.u_pth = pth;
@@ -864,14 +867,16 @@ int cobalt_thread_getschedparam_ex(unsigned long pth,
if (thread == NULL)
return -ESRCH;
 
-   ret = pthread_getschedparam_ex(thread, policy, param);
+   ret = pthread_getschedparam_ex(thread, policy, param_ex);
if (ret)
return ret;
 
+   trace_cobalt_pthread_getschedparam(pth, policy, param_ex);
+
if (__xn_safe_copy_to_user(u_policy, policy, sizeof(int)))
return -EFAULT;
 
-   return __xn_safe_copy_to_user(u_param, param, sizeof(param));
+   return __xn_safe_copy_to_user(u_param, param_ex, sizeof(param_ex));
 }
 
 /*
@@ -906,6 +911,9 @@ int cobalt_thread_create(unsigned long pth, int policy,
 
if (__xn_safe_copy_from_user(param_ex, u_param, sizeof(param_ex)))
return -EFAULT;
+
+   trace_cobalt_pthread_create(pth, policy, param_ex);
+
/*
 * We have been passed the pthread_t identifier the user-space
 * Cobalt library has assigned to our caller; we'll index our
@@ -952,6 +960,7 @@ cobalt_thread_shadow(struct task_struct *p,
int ret;
 
param_ex.sched_priority = 0;
+   trace_cobalt_pthread_create(hkey-u_pth, SCHED_NORMAL, param_ex);
ret = pthread_create(thread, SCHED_NORMAL, param_ex, p);
if (ret)
return ERR_PTR(-ret);
@@ -995,18 +1004,24 @@ int cobalt_thread_make_periodic_np(unsigned long pth,
if (__xn_safe_copy_from_user(periodt, u_periodt, sizeof(periodt)))
return -EFAULT;
 
+   trace_cobalt_posix_make_periodic(pth, clk_id, startt, periodt);
+
return pthread_make_periodic_np(thread, clk_id, startt, periodt);
 }
 
 int cobalt_thread_wait_np(unsigned long __user *u_overruns)
 {
-   unsigned long overruns;
+   unsigned long overruns = 0;
int ret;
 
+   trace_cobalt_posix_wait_entry(0);
+
ret = xnthread_wait_period(overruns);
if (u_overruns  (ret == 0 || ret == -ETIMEDOUT))
__xn_put_user(overruns, u_overruns);
 
+   trace_cobalt_posix_wait_exit(ret, overruns);
+
return ret;
 }
 
diff --git a/kernel/cobalt/trace/cobalt-posix.h 
b/kernel/cobalt/trace/cobalt-posix.h
new file mode 100644
index 000..ddcf70e
--- /dev/null
+++ b/kernel/cobalt/trace/cobalt-posix.h
@@ -0,0 +1,193 @@
+#undef TRACE_SYSTEM
+#define TRACE_SYSTEM cobalt-posix
+
+#if !defined(_TRACE_COBALT_POSIX_H) || defined(TRACE_HEADER_MULTI_READ)
+#define _TRACE_COBALT_POSIX_H
+

[Xenomai-git] Philippe Gerum : copperplate/notifier: sanitize and simplify - again

2014-04-26 Thread git repository hosting
Module: xenomai-forge
Branch: next
Commit: 4f3396bf96b9fcb750d68e843c60ec9f5d22f9cd
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=4f3396bf96b9fcb750d68e843c60ec9f5d22f9cd

Author: Philippe Gerum r...@xenomai.org
Date:   Sat Apr 26 15:07:41 2014 +0200

copperplate/notifier: sanitize and simplify - again

Those changes build on the fact that the notification support is there
exclusively for implementing the thread suspend/resume mechanism over
Mercury. Therefore we may drop any code which is not directly aimed at
supporting this feature.

Assuming this, locking may now be handled directly from the call
sites, all located in the threadobj implementation.

As a bonus, this change set also fixes the issue discussed there:
http://www.xenomai.org/pipermail/xenomai/2014-April/030804.html

---

 include/copperplate/notifier.h  |   16 ++--
 include/copperplate/threadobj.h |1 -
 lib/copperplate/notifier.c  |  169 ---
 lib/copperplate/threadobj.c |   69 +++-
 4 files changed, 86 insertions(+), 169 deletions(-)

diff --git a/include/copperplate/notifier.h b/include/copperplate/notifier.h
index 536782d..13bf588 100644
--- a/include/copperplate/notifier.h
+++ b/include/copperplate/notifier.h
@@ -19,16 +19,12 @@
 #ifndef _COPPERPLATE_NOTIFIER_H
 #define _COPPERPLATE_NOTIFIER_H
 
-#include pthread.h
 #include boilerplate/list.h
 
 struct notifier {
-   pthread_mutex_t lock;
-   int notified;
pid_t owner;
int psfd[2];
int pwfd[2];
-   void (*callback)(const struct notifier *nf);
struct pvholder link;
 };
 
@@ -36,17 +32,17 @@ struct notifier {
 extern C {
 #endif
 
-int notifier_init(struct notifier *nf,
- void (*callback)(const struct notifier *nf),
- int owned);
+int notifier_init(struct notifier *nf, pid_t pid);
 
 void notifier_destroy(struct notifier *nf);
 
-int notifier_signal(struct notifier *nf);
+void notifier_signal(struct notifier *nf);
 
-int notifier_wait(const struct notifier *nf);
+void notifier_wait(const struct notifier *nf);
 
-int notifier_release(struct notifier *nf);
+void notifier_disable(struct notifier *nf);
+
+void notifier_release(struct notifier *nf);
 
 void notifier_pkg_init(void);
 
diff --git a/include/copperplate/threadobj.h b/include/copperplate/threadobj.h
index 5438790..bc5be99 100644
--- a/include/copperplate/threadobj.h
+++ b/include/copperplate/threadobj.h
@@ -128,7 +128,6 @@ void threadobj_save_timeout(struct threadobj_corespec 
*corespec,
 #define __THREAD_S_ACTIVE  (1  5)/* Running user code. */
 #define __THREAD_S_SUSPENDED   (1  6)/* Suspended via 
threadobj_suspend(). */
 #define __THREAD_S_SAFE(1  7)/* TCB release 
deferred. */
-#define __THREAD_S_ZOMBIE  (1  8)/* Deletion process ongoing. */
 #define __THREAD_S_DEBUG   (1  31)   /* Debug mode enabled. */
 /*
  * threadobj-run_state, locklessly updated by current, merged
diff --git a/lib/copperplate/notifier.c b/lib/copperplate/notifier.c
index 7fa48f3..4b3988a 100644
--- a/lib/copperplate/notifier.c
+++ b/lib/copperplate/notifier.c
@@ -50,25 +50,20 @@ static void notifier_sighandler(int sig, siginfo_t 
*siginfo, void *uc)
pvlist_for_each_entry(nf, notifier_list, link) {
if (nf-psfd[0] != siginfo-si_fd)
continue;
+
+   matched = 1;
/*
-* Ignore misdirected notifications. We want those to
-* hit the thread owning the notification object, but
-* it may happen that the kernel picks another thread
-* for receiving a subsequent signal while we are
-* blocked in the callback code. In such a case, we
-* just dismiss the notification, and expect the
-* actual owner to detect the pending notification
-* once the callback returns to the read() loop.
+* Paranoid: misdirected notifications should never
+* happen with F_SETOWN_EX invoked for the
+* notification fildes.
 */
-   matched = 1;
-   if (nf-owner  nf-owner != tid)
+   if (nf-owner != tid)
continue;
 
for (;;) {
-   ret = __STD(read(nf-psfd[0], c, 1)); 
+   ret = read(nf-psfd[0], c, 1); 
if (ret  0)
-   /* Callee must run async-safe code only. */
-   nf-callback(nf);
+   notifier_wait(nf);
else if (ret == 0 || errno != EINTR)
break;
}
@@ -77,9 +72,9 @@ static void notifier_sighandler(int sig, siginfo_t *siginfo, 
void *uc)
}
 
/*
-* We may have received a valid notification on the wrong
-