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

Author: Philippe Gerum <r...@xenomai.org>
Date:   Sun Dec 22 17:07:06 2013 +0100

lib/cobalt: introduce sched_getconfig_np()

---

 include/cobalt/sched.h        |   11 +++++------
 include/cobalt/uapi/sched.h   |   13 ++++++++++++-
 include/cobalt/uapi/syscall.h |    1 +
 lib/cobalt/thread.c           |   18 +++++++++++++++++-
 testsuite/unit/sched-tp.c     |   19 ++++++++++++++++++-
 5 files changed, 53 insertions(+), 9 deletions(-)

diff --git a/include/cobalt/sched.h b/include/cobalt/sched.h
index ece501c..bfdff69 100644
--- a/include/cobalt/sched.h
+++ b/include/cobalt/sched.h
@@ -20,6 +20,7 @@
 
 #pragma GCC system_header
 #include_next <sched.h>
+#include <sys/types.h>
 #include <cobalt/wrappers.h>
 #include <cobalt/uapi/sched.h>
 
@@ -41,17 +42,15 @@ int __sched_cpucount(size_t __setsize, const cpu_set_t 
*__setp);
 void __sched_cpufill(size_t __setsize, cpu_set_t *__setp);
 #endif /* !CPU_COUNT */
 
-#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
 
 int sched_setconfig_np(int cpu, int policy,
-                      union sched_config *config, size_t len);
+                      const union sched_config *config, size_t len);
+
+ssize_t sched_getconfig_np(int cpu, int policy,
+                          union sched_config *config, size_t *len_r);
 
 #ifdef __cplusplus
 }
diff --git a/include/cobalt/uapi/sched.h b/include/cobalt/uapi/sched.h
index d458376..11bbc1a 100644
--- a/include/cobalt/uapi/sched.h
+++ b/include/cobalt/uapi/sched.h
@@ -62,6 +62,9 @@ struct __sched_config_tp {
        struct sched_tp_window windows[0];
 };
 
+#define sched_tp_confsz(nr_win) \
+  (sizeof(struct __sched_config_tp) + nr_win * sizeof(struct sched_tp_window))
+
 #ifndef SCHED_QUOTA
 #define SCHED_QUOTA            12
 #define sched_quota_group      sched_u.quota.__sched_group
@@ -74,7 +77,8 @@ struct __sched_quota_param {
 enum {
        sched_quota_add,
        sched_quota_remove,
-       sched_quota_set
+       sched_quota_set,
+       sched_quota_get,
 };
 
 struct __sched_config_quota {
@@ -90,8 +94,15 @@ struct __sched_config_quota {
                int quota;
                int quota_peak;
        } set;
+       struct {
+               int tgid;
+               int *quota_r;
+               int *quota_peak_r;
+       } get;
 };
 
+#define sched_quota_confsz()  sizeof(struct __sched_config_quota)
+
 struct sched_param_ex {
        int sched_priority;
        union {
diff --git a/include/cobalt/uapi/syscall.h b/include/cobalt/uapi/syscall.h
index ed60c35..f8d1511 100644
--- a/include/cobalt/uapi/syscall.h
+++ b/include/cobalt/uapi/syscall.h
@@ -112,5 +112,6 @@
 #define sc_cobalt_event_sync            91
 #define sc_cobalt_event_destroy         92
 #define sc_cobalt_sched_setconfig_np   93
+#define sc_cobalt_sched_getconfig_np   94
 
 #endif /* !_COBALT_UAPI_SYSCALL_H */
diff --git a/lib/cobalt/thread.c b/lib/cobalt/thread.c
index bf3c22b..5fabf9a 100644
--- a/lib/cobalt/thread.c
+++ b/lib/cobalt/thread.c
@@ -438,13 +438,29 @@ int pthread_probe_np(pid_t tid)
 }
 
 int sched_setconfig_np(int cpu, int policy,
-                      union sched_config *config, size_t len)
+                      const union sched_config *config, size_t len)
 {
        return -XENOMAI_SKINCALL4(__cobalt_muxid,
                                  sc_cobalt_sched_setconfig_np,
                                  cpu, policy, config, len);
 }
 
+ssize_t sched_getconfig_np(int cpu, int policy,
+                          union sched_config *config, size_t *len_r)
+{
+       ssize_t ret;
+
+       ret = XENOMAI_SKINCALL4(__cobalt_muxid,
+                               sc_cobalt_sched_getconfig_np,
+                               cpu, policy, config, *len_r);
+       if (ret < 0)
+               return -ret;
+
+       *len_r = ret;
+
+       return 0;
+}
+
 COBALT_IMPL(int, pthread_kill, (pthread_t thread, int sig))
 {
        int ret;
diff --git a/testsuite/unit/sched-tp.c b/testsuite/unit/sched-tp.c
index d051238..271a7ff 100644
--- a/testsuite/unit/sched-tp.c
+++ b/testsuite/unit/sched-tp.c
@@ -10,6 +10,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <limits.h>
+#include <memory.h>
 #include <malloc.h>
 #include <unistd.h>
 #include <signal.h>
@@ -94,7 +95,7 @@ int main(int argc, char **argv)
        sigset_t mask, oldmask;
        union sched_config *p;
        size_t len;
-       int ret;
+       int ret, n;
 
        mlockall(MCL_CURRENT | MCL_FUTURE);
 
@@ -150,6 +151,22 @@ int main(int argc, char **argv)
        if (ret)
                error(1, ret, "sched_setconfig_np");
 
+       memset(p, 0xa5, len);
+
+       ret = sched_getconfig_np(0, SCHED_TP, p, &len);
+       if (ret)
+               error(1, ret, "sched_getconfig_np");
+
+       printf("check: %d windows\n", p->tp.nr_windows);
+       for (n = 0; n < 4; n++)
+               printf("[%d] offset = { %ld s, %ld ns }, duration = { %ld s, 
%ld ns }, ptid = %d\n",
+                      n,
+                      p->tp.windows[n].offset.tv_sec,
+                      p->tp.windows[n].offset.tv_nsec,
+                      p->tp.windows[n].duration.tv_sec,
+                      p->tp.windows[n].duration.tv_nsec,
+                      p->tp.windows[n].ptid);
+
        sigemptyset(&mask);
        sigaddset(&mask, SIGINT);
        signal(SIGINT, cleanup);


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

Reply via email to