Module: xenomai-forge
Branch: next
Commit: 06a131ccbbcecbb3523ed12c71576596d7780abb
URL:    
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=06a131ccbbcecbb3523ed12c71576596d7780abb

Author: Philippe Gerum <r...@xenomai.org>
Date:   Thu Jul  3 14:35:46 2014 +0200

cobalt/kernel/thread: add cobalt_thread_getpid service

This service returns the per-task kernel pid of a local pthread.

---

 include/cobalt/uapi/syscall.h      |    2 +-
 kernel/cobalt/posix/syscall.c      |    1 +
 kernel/cobalt/posix/thread.c       |   24 ++++++++++++++++++++++++
 kernel/cobalt/posix/thread.h       |   14 +++++++-------
 kernel/cobalt/trace/cobalt-posix.h |   17 ++++++++++++-----
 5 files changed, 45 insertions(+), 13 deletions(-)

diff --git a/include/cobalt/uapi/syscall.h b/include/cobalt/uapi/syscall.h
index 29756b7..f9e56c8 100644
--- a/include/cobalt/uapi/syscall.h
+++ b/include/cobalt/uapi/syscall.h
@@ -23,7 +23,7 @@
 #define COBALT_BINDING_MAGIC            0x50534531
 
 #define sc_cobalt_thread_create         0
-/* 1 unimplemented */
+#define sc_cobalt_thread_getpid         1
 #define sc_cobalt_sched_weightprio      2
 #define sc_cobalt_sched_yield           3
 /* 4-5 unimplemented */
diff --git a/kernel/cobalt/posix/syscall.c b/kernel/cobalt/posix/syscall.c
index 04be66d..d921d81 100644
--- a/kernel/cobalt/posix/syscall.c
+++ b/kernel/cobalt/posix/syscall.c
@@ -88,6 +88,7 @@ static int cobalt_syscall_ni(void)
 static struct xnsyscall cobalt_syscalls[] = {
        [0 ... __NR_COBALT_SYSCALLS-1] = SKINCALL_NI,
        SKINCALL_DEF(sc_cobalt_thread_create, cobalt_thread_create, init),
+       SKINCALL_DEF(sc_cobalt_thread_getpid, cobalt_thread_pid, current),
        SKINCALL_DEF(sc_cobalt_thread_setschedparam_ex, 
cobalt_thread_setschedparam_ex, conforming),
        SKINCALL_DEF(sc_cobalt_thread_getschedparam_ex, 
cobalt_thread_getschedparam_ex, current),
        SKINCALL_DEF(sc_cobalt_sched_weightprio, cobalt_sched_weighted_prio, 
current),
diff --git a/kernel/cobalt/posix/thread.c b/kernel/cobalt/posix/thread.c
index e3cf3cc..267ae67 100644
--- a/kernel/cobalt/posix/thread.c
+++ b/kernel/cobalt/posix/thread.c
@@ -705,6 +705,30 @@ int cobalt_thread_join(unsigned long pth)
        return xnthread_join(&thread->threadbase, false);
 }
 
+pid_t cobalt_thread_pid(unsigned long pth)
+{
+       struct cobalt_local_hkey hkey;
+       struct cobalt_thread *thread;
+       pid_t pid;
+       spl_t s;
+
+       trace_cobalt_pthread_pid(pth);
+
+       xnlock_get_irqsave(&nklock, s);
+
+       hkey.u_pth = pth;
+       hkey.mm = current->mm;
+       thread = thread_lookup(&hkey);
+       if (thread == NULL)
+               pid = -ESRCH;
+       else
+               pid = xnthread_host_pid(&thread->threadbase);
+
+       xnlock_put_irqrestore(&nklock, s);
+
+       return pid;
+}
+
 int cobalt_thread_stat(pid_t pid,
                       struct cobalt_threadstat __user *u_stat)
 {
diff --git a/kernel/cobalt/posix/thread.h b/kernel/cobalt/posix/thread.h
index 426231c..5097b2d 100644
--- a/kernel/cobalt/posix/thread.h
+++ b/kernel/cobalt/posix/thread.h
@@ -128,7 +128,7 @@ struct cobalt_thread *cobalt_thread_find_local(pid_t pid);
 
 struct cobalt_thread *cobalt_thread_lookup(unsigned long pth);
 
-int cobalt_thread_create(unsigned long tid, int policy,
+int cobalt_thread_create(unsigned long pth, int policy,
                         struct sched_param_ex __user *u_param,
                         int shifted_muxid,
                         unsigned long __user *u_window_offset);
@@ -140,24 +140,24 @@ cobalt_thread_shadow(struct task_struct *p,
 
 int cobalt_thread_setmode_np(int clrmask, int setmask, int __user *u_mode_r);
 
-int cobalt_thread_setname_np(unsigned long tid, const char __user *u_name);
+int cobalt_thread_setname_np(unsigned long pth, const char __user *u_name);
 
-int cobalt_thread_probe_np(pid_t h_tid);
+int cobalt_thread_kill(unsigned long pth, int sig);
 
-int cobalt_thread_kill(unsigned long tid, int sig);
+int cobalt_thread_join(unsigned long pth);
 
-int cobalt_thread_join(unsigned long tid);
+pid_t cobalt_thread_pid(unsigned long pth);
 
 int cobalt_thread_stat(pid_t pid,
                       struct cobalt_threadstat __user *u_stat);
 
-int cobalt_thread_setschedparam_ex(unsigned long tid,
+int cobalt_thread_setschedparam_ex(unsigned long pth,
                                   int policy,
                                   const struct sched_param_ex __user *u_param,
                                   unsigned long __user *u_window_offset,
                                   int __user *u_promoted);
 
-int cobalt_thread_getschedparam_ex(unsigned long tid,
+int cobalt_thread_getschedparam_ex(unsigned long pth,
                                   int __user *u_policy,
                                   struct sched_param_ex __user *u_param);
 
diff --git a/kernel/cobalt/trace/cobalt-posix.h 
b/kernel/cobalt/trace/cobalt-posix.h
index e731dc6..39f5789 100644
--- a/kernel/cobalt/trace/cobalt-posix.h
+++ b/kernel/cobalt/trace/cobalt-posix.h
@@ -177,11 +177,6 @@ DECLARE_EVENT_CLASS(cobalt_posix_pid,
        TP_printk("pid=%d", __entry->pid)
 );
 
-DEFINE_EVENT(cobalt_posix_pid, cobalt_pthread_probe,
-       TP_PROTO(pid_t pid),
-       TP_ARGS(pid)
-);
-
 DEFINE_EVENT(cobalt_posix_pid, cobalt_pthread_stat,
        TP_PROTO(pid_t pid),
        TP_ARGS(pid)
@@ -213,6 +208,18 @@ TRACE_EVENT(cobalt_pthread_join,
        TP_printk("pth=%p", (void *)__entry->pth)
 );
 
+TRACE_EVENT(cobalt_pthread_pid,
+       TP_PROTO(unsigned long pth),
+       TP_ARGS(pth),
+       TP_STRUCT__entry(
+               __field(unsigned long, pth)
+       ),
+       TP_fast_assign(
+               __entry->pth = pth;
+       ),
+       TP_printk("pth=%p", (void *)__entry->pth)
+);
+
 TRACE_EVENT(cobalt_pthread_extend,
        TP_PROTO(unsigned long pth, const char *name),
        TP_ARGS(pth, name),


_______________________________________________
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://www.xenomai.org/mailman/listinfo/xenomai-git

Reply via email to