Module: xenomai-forge Branch: next Commit: e5eb08193efe682a7a569678658648eca7e53aab URL: http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=e5eb08193efe682a7a569678658648eca7e53aab
Author: Philippe Gerum <r...@xenomai.org> Date: Thu May 29 11:38:54 2014 +0200 cobalt/posix/sched: allow for private/shared quota groups --- include/cobalt/uapi/sched.h | 1 + kernel/cobalt/posix/sched.c | 47 +++++++++++++++++++++++++++--------------- kernel/cobalt/posix/sched.h | 4 ++++ testsuite/unit/sched-quota.c | 1 + 4 files changed, 36 insertions(+), 17 deletions(-) diff --git a/include/cobalt/uapi/sched.h b/include/cobalt/uapi/sched.h index 99f0f98..2b588a8 100644 --- a/include/cobalt/uapi/sched.h +++ b/include/cobalt/uapi/sched.h @@ -85,6 +85,7 @@ struct __sched_config_quota { int op; int *sum_r; struct { + int pshared; int *tgid_r; } add; struct { diff --git a/kernel/cobalt/posix/sched.c b/kernel/cobalt/posix/sched.c index 7d36390..a8588a1 100644 --- a/kernel/cobalt/posix/sched.c +++ b/kernel/cobalt/posix/sched.c @@ -372,7 +372,6 @@ int do_quota_config(int cpu, const union sched_config *config, size_t len) const struct __sched_config_quota *p = &config->quota; struct cobalt_sched_group *group; struct xnsched_quota_group *tg; - struct cobalt_kqueues *kq; struct xnsched *sched; spl_t s; @@ -384,7 +383,8 @@ int do_quota_config(int cpu, const union sched_config *config, size_t len) if (group == NULL) return -ENOMEM; tg = &group->quota; - kq = cobalt_kqueues(0); + group->pshared = p->add.pshared != 0; + group->kq = cobalt_kqueues(group->pshared); xnlock_get_irqsave(&nklock, s); sched = xnsched_struct(cpu); ret = xnsched_quota_create_group(tg, sched, "a_sum); @@ -392,7 +392,7 @@ int do_quota_config(int cpu, const union sched_config *config, size_t len) xnlock_put_irqrestore(&nklock, s); xnfree(group); } else { - list_add(&group->next, &kq->schedq); + list_add(&group->next, &group->kq->schedq); xnlock_put_irqrestore(&nklock, s); ret = __xn_safe_copy_to_user(p->add.tgid_r, &tg->tgid, sizeof(tg->tgid)); @@ -412,6 +412,10 @@ int do_quota_config(int cpu, const union sched_config *config, size_t len) return ret; } group = container_of(tg, struct cobalt_sched_group, quota); + if (group->kq != cobalt_kqueues(group->pshared)) { + xnlock_put_irqrestore(&nklock, s); + return ret; + } ret = xnsched_quota_destroy_group(tg, "a_sum); if (ret) { xnlock_put_irqrestore(&nklock, s); @@ -430,15 +434,20 @@ int do_quota_config(int cpu, const union sched_config *config, size_t len) xnlock_get_irqsave(&nklock, s); sched = xnsched_struct(cpu); tg = xnsched_quota_find_group(sched, p->set.tgid); - if (tg) { - xnsched_quota_set_limit(tg, - p->set.quota, - p->set.quota_peak, - "a_sum); - ret = 0; + if (tg == NULL) { + xnlock_put_irqrestore(&nklock, s); + return ret; } + group = container_of(tg, struct cobalt_sched_group, quota); + if (group->kq != cobalt_kqueues(group->pshared)) { + xnlock_put_irqrestore(&nklock, s); + return ret; + } + xnsched_quota_set_limit(tg, p->set.quota, p->set.quota_peak, + "a_sum); xnlock_put_irqrestore(&nklock, s); - if (ret == 0 && p->sum_r) + ret = 0; + if (p->sum_r) ret = __xn_safe_copy_to_user(p->sum_r, "a_sum, sizeof(quota_sum)); return ret; @@ -448,15 +457,19 @@ int do_quota_config(int cpu, const union sched_config *config, size_t len) xnlock_get_irqsave(&nklock, s); sched = xnsched_struct(cpu); tg = xnsched_quota_find_group(sched, p->get.tgid); - if (tg) { - quota_percent = tg->quota_percent; - quota_peak_percent = tg->quota_peak_percent; - quota_sum = xnsched_quota_sum_all(sched); - ret = 0; + if (tg == NULL) { + xnlock_put_irqrestore(&nklock, s); + return ret; } - xnlock_put_irqrestore(&nklock, s); - if (ret) + group = container_of(tg, struct cobalt_sched_group, quota); + if (group->kq != cobalt_kqueues(group->pshared)) { + xnlock_put_irqrestore(&nklock, s); return ret; + } + quota_percent = tg->quota_percent; + quota_peak_percent = tg->quota_peak_percent; + quota_sum = xnsched_quota_sum_all(sched); + xnlock_put_irqrestore(&nklock, s); ret = __xn_safe_copy_to_user(p->get.quota_r, "a_percent, sizeof(quota_percent)); if (ret) diff --git a/kernel/cobalt/posix/sched.h b/kernel/cobalt/posix/sched.h index 2cf2325..f8288b4 100644 --- a/kernel/cobalt/posix/sched.h +++ b/kernel/cobalt/posix/sched.h @@ -21,8 +21,12 @@ #include <linux/list.h> #include <cobalt/kernel/sched.h> +struct cobalt_kqueues; + struct cobalt_sched_group { struct xnsched_quota_group quota; + struct cobalt_kqueues *kq; + int pshared; struct list_head next; }; diff --git a/testsuite/unit/sched-quota.c b/testsuite/unit/sched-quota.c index cea6aa0..abfebab 100644 --- a/testsuite/unit/sched-quota.c +++ b/testsuite/unit/sched-quota.c @@ -164,6 +164,7 @@ static double run_quota(int quota) cf.quota.sum_r = "a_sum; cf.quota.op = sched_quota_add; + cf.quota.add.pshared = 0; cf.quota.add.tgid_r = &tgid; ret = sched_setconfig_np(0, SCHED_QUOTA, &cf, len); if (ret) _______________________________________________ Xenomai-git mailing list Xenomai-git@xenomai.org http://www.xenomai.org/mailman/listinfo/xenomai-git