Module: xenomai-3
Branch: master
Commit: 6baf0c769a41a5ff65686c51f2341ab09db24e9e
URL:    
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=6baf0c769a41a5ff65686c51f2341ab09db24e9e

Author: Philippe Gerum <r...@xenomai.org>
Date:   Thu Oct 16 14:38:18 2014 +0200

cobalt/posix/thread: prepare for 32bit syscall emulation

---

 kernel/cobalt/posix/thread.c |   74 ++++++++++++++++++++++++++++--------------
 kernel/cobalt/posix/thread.h |   10 ++++++
 lib/cobalt/thread.c          |   51 +++++++++++++++++++----------
 3 files changed, 92 insertions(+), 43 deletions(-)

diff --git a/kernel/cobalt/posix/thread.c b/kernel/cobalt/posix/thread.c
index 8271afd..a74d024 100644
--- a/kernel/cobalt/posix/thread.c
+++ b/kernel/cobalt/posix/thread.c
@@ -439,29 +439,19 @@ static inline int pthread_setmode_np(int clrmask, int 
setmask, int *mode_r)
        return 0;
 }
 
-/*
- * NOTE: there is no cobalt_thread_setschedparam syscall defined by
- * the Cobalt ABI. Useland changes scheduling parameters only via the
- * extended cobalt_thread_setschedparam_ex syscall.
- */
-COBALT_SYSCALL(thread_setschedparam_ex, conforming,
-              int, (unsigned long pth,
-                    int policy,
-                    const struct sched_param_ex __user *u_param,
-                    __u32 __user *u_winoff,
-                    int __user *u_promoted))
+int __cobalt_thread_setschedparam_ex(unsigned long pth,
+                                    int policy,
+                                    const struct sched_param_ex *param_ex,
+                                    __u32 __user *u_winoff,
+                                    int __user *u_promoted)
 {
-       struct sched_param_ex param_ex;
        struct cobalt_local_hkey hkey;
        struct cobalt_thread *thread;
        int ret, promoted = 0;
 
-       if (__xn_safe_copy_from_user(&param_ex, u_param, sizeof(param_ex)))
-               return -EFAULT;
-
        hkey.u_pth = pth;
        hkey.mm = current->mm;
-       trace_cobalt_pthread_setschedparam(pth, policy, &param_ex);
+       trace_cobalt_pthread_setschedparam(pth, policy, param_ex);
 
        thread = thread_lookup(&hkey);
        if (thread == NULL && u_winoff) {
@@ -473,7 +463,7 @@ COBALT_SYSCALL(thread_setschedparam_ex, conforming,
        }
 
        if (thread)
-               ret = pthread_setschedparam_ex(thread, policy, &param_ex);
+               ret = pthread_setschedparam_ex(thread, policy, param_ex);
        else
                ret = -EPERM;
 
@@ -485,16 +475,30 @@ COBALT_SYSCALL(thread_setschedparam_ex, conforming,
 }
 
 /*
- * NOTE: there is no cobalt_thread_getschedparam syscall defined by
- * the Cobalt ABI. Useland retrieves scheduling parameters only via
- * the extended cobalt_thread_getschedparam_ex syscall.
+ * NOTE: there is no cobalt_thread_setschedparam syscall defined by
+ * the Cobalt ABI. Useland changes scheduling parameters only via the
+ * extended cobalt_thread_setschedparam_ex syscall.
  */
-COBALT_SYSCALL(thread_getschedparam_ex, current,
+COBALT_SYSCALL(thread_setschedparam_ex, conforming,
               int, (unsigned long pth,
-                    int __user *u_policy,
-                    struct sched_param_ex __user *u_param))
+                    int policy,
+                    const struct sched_param_ex __user *u_param,
+                    __u32 __user *u_winoff,
+                    int __user *u_promoted))
 {
        struct sched_param_ex param_ex;
+
+       if (__xn_safe_copy_from_user(&param_ex, u_param, sizeof(param_ex)))
+               return -EFAULT;
+
+       return __cobalt_thread_setschedparam_ex(pth, policy, &param_ex,
+                                               u_winoff, u_promoted);
+}
+
+int __cobalt_thread_getschedparam_ex(unsigned long pth,
+                                    int __user *u_policy,
+                                    struct sched_param_ex *param_ex)
+{
        struct cobalt_local_hkey hkey;
        struct cobalt_thread *thread;
        int policy, ret;
@@ -505,15 +509,35 @@ COBALT_SYSCALL(thread_getschedparam_ex, current,
        if (thread == NULL)
                return -ESRCH;
 
-       ret = pthread_getschedparam_ex(thread, &policy, &param_ex);
+       ret = pthread_getschedparam_ex(thread, &policy, param_ex);
        if (ret)
                return ret;
 
-       trace_cobalt_pthread_getschedparam(pth, policy, &param_ex);
+       trace_cobalt_pthread_getschedparam(pth, policy, param_ex);
 
        if (__xn_safe_copy_to_user(u_policy, &policy, sizeof(int)))
                return -EFAULT;
 
+       return policy;
+}
+
+/*
+ * NOTE: there is no cobalt_thread_getschedparam syscall defined by
+ * the Cobalt ABI. Useland retrieves scheduling parameters only via
+ * the extended cobalt_thread_getschedparam_ex syscall.
+ */
+COBALT_SYSCALL(thread_getschedparam_ex, current,
+              int, (unsigned long pth,
+                    int __user *u_policy,
+                    struct sched_param_ex __user *u_param))
+{
+       struct sched_param_ex param_ex;
+       int policy;
+
+       policy = __cobalt_thread_getschedparam_ex(pth, u_policy, &param_ex);
+       if (policy < 0)
+               return policy;
+
        return __xn_safe_copy_to_user(u_param, &param_ex, sizeof(param_ex));
 }
 
diff --git a/kernel/cobalt/posix/thread.h b/kernel/cobalt/posix/thread.h
index e5deadd..1322993 100644
--- a/kernel/cobalt/posix/thread.h
+++ b/kernel/cobalt/posix/thread.h
@@ -156,6 +156,12 @@ COBALT_SYSCALL_DECL(thread_getstat,
                    int, (pid_t pid,
                          struct cobalt_threadstat __user *u_stat));
 
+int __cobalt_thread_setschedparam_ex(unsigned long pth,
+                                    int policy,
+                                    const struct sched_param_ex *param_ex,
+                                    __u32 __user *u_winoff,
+                                    int __user *u_promoted);
+
 COBALT_SYSCALL_DECL(thread_setschedparam_ex,
                    int, (unsigned long pth,
                          int policy,
@@ -163,6 +169,10 @@ COBALT_SYSCALL_DECL(thread_setschedparam_ex,
                          __u32 __user *u_winoff,
                          int __user *u_promoted));
 
+int __cobalt_thread_getschedparam_ex(unsigned long pth,
+                                    int __user *u_policy,
+                                    struct sched_param_ex *param_ex);
+
 COBALT_SYSCALL_DECL(thread_getschedparam_ex,
                    int, (unsigned long pth,
                          int __user *u_policy,
diff --git a/lib/cobalt/thread.c b/lib/cobalt/thread.c
index 8eb732a..fa6845a 100644
--- a/lib/cobalt/thread.c
+++ b/lib/cobalt/thread.c
@@ -972,6 +972,8 @@ COBALT_IMPL(int, pthread_yield, (void))
  * - config.tp.nr_windows should define the number of elements present
  * in the config.tp.windows[] array.
  *
+ * @a info is ignored for this request.
+ *
  * @par Settings applicable to SCHED_QUOTA
  *
  * This call manages thread groups running on @a cpu.
@@ -980,10 +982,9 @@ COBALT_IMPL(int, pthread_yield, (void))
  * out. Valid operations are:
  *
  *    - sched_quota_add for creating a new thread group on @a cpu.
- *      The new group identifier will be written back to
- *      config.quota.add.tgid_r upon success. A new group is given no
- *      initial runtime budget when created. sched_quota_set should be
- *      issued to enable it.
+ *      The new group identifier will be written back to info.tgid
+ *      upon success. A new group is given no initial runtime budget
+ *      when created. sched_quota_set should be issued to enable it.
  *
  *    - sched_quota_remove for deleting a thread group on @a cpu. The
  *      group identifier should be passed in config.quota.remove.tgid.
@@ -994,13 +995,10 @@ COBALT_IMPL(int, pthread_yield, (void))
  *      percentage of the quota interval (config.quota.set.quota), and
  *      the peak percentage allowed (config.quota.set.quota_peak).
  *
- *    - sched_quota_get for retrieving the scheduling parameters of a
- *      thread group defined on @a cpu. The group identifier should be
- *      passed in config.quota.get.tgid. The allotted percentage of
- *      the quota interval (config.quota.get.quota_r), and the peak
- *      percentage (config.quota.get.quota_peak_r) will be written to
- *      the given output variables. The result of this operation is
- *      identical to calling sched_getconfig_np().
+ * All three operations fill in the @a config.info structure with the
+ * information reflecting the state of the scheduler on @a cpu with
+ * respect to @a policy, after the requested changes have been
+ * applied.
  *
  * @param len overall length of the configuration data (in bytes).
  *
@@ -1035,14 +1033,30 @@ int sched_setconfig_np(int cpu, int policy,
  * @param cpu processor to retrieve the configuration of.
  *
  * @param policy scheduling policy to which the configuration data
- * applies. Currently, SCHED_TP and SCHED_QUOTA are valid.
+ * applies. Currently, only SCHED_TP and SCHED_QUOTA are valid input.
+ *
+ * @param[in, out] info a pointer to a memory area for receiving the
+ * configuration data. This area must be at least @a *len_r bytes
+ * long.
+ *
+ * @par SCHED_TP specifics
  *
- * @param config a pointer to a memory area where the configuration
- * data will be copied back. This area must be at least @a *len_r
- * bytes long.
+ * On successful return, config->quota.tp contains the TP schedule
+ * active on @a cpu.
  *
- * @param len_r overall length of the configuration data returned (in
- * bytes).
+ * @par SCHED_QUOTA specifics
+ *
+ * On entry, config->quota.get.tgid must contain the thread group
+ * identifier to inquire about.
+ *
+ * On successful exit, config->quota.info contains the information
+ * related to the thread group referenced to by
+ * config->quota.get.tgid.
+ *
+ * @param[in, out] len_r a pointer to a variable for collecting the
+ * overall length of the configuration data returned (in bytes). This
+ * variable must contain the amount of space available in @a config
+ * when the request is issued.
  *
  * @return the number of bytes copied to @a config on success;
  * @return a negative error number if:
@@ -1052,7 +1066,8 @@ int sched_setconfig_np(int cpu, int policy,
  * configuration data.
  *
  * - ESRCH, with @a policy equal to SCHED_QUOTA, if the group
- *   identifier required to perform the operation is not valid.
+ *   identifier required to perform the operation is not valid
+ *   (i.e. config->quota.get.tgid is invalid).
  *
  * - ENOMEM, lack of memory to perform the operation.
  *


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

Reply via email to