summaryrefslogtreecommitdiff
path: root/src/core/load-fragment.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2014-04-25 13:27:25 +0200
committerLennart Poettering <lennart@poettering.net>2014-04-25 13:27:25 +0200
commitb2f8b02ec27dfec9cbd23573f47aba494f2e9b5f (patch)
tree56ca4d6015fa5bd06f473d7836ef3fc797f35f64 /src/core/load-fragment.c
parent3051f1871ea2d9a36b423207221e461cc27e577c (diff)
core: expose CFS CPU time quota as high-level unit properties
Diffstat (limited to 'src/core/load-fragment.c')
-rw-r--r--src/core/load-fragment.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c
index 6c92935d0a..3b36d1568c 100644
--- a/src/core/load-fragment.c
+++ b/src/core/load-fragment.c
@@ -2455,6 +2455,54 @@ int config_parse_cpu_shares(
return 0;
}
+int config_parse_cpu_quota(
+ const char *unit,
+ const char *filename,
+ unsigned line,
+ const char *section,
+ unsigned section_line,
+ const char *lvalue,
+ int ltype,
+ const char *rvalue,
+ void *data,
+ void *userdata) {
+
+ CGroupContext *c = data;
+ int r;
+
+ assert(filename);
+ assert(lvalue);
+ assert(rvalue);
+
+ if (isempty(rvalue)) {
+ c->cpu_quota_per_sec_usec = (usec_t) -1;
+ c->cpu_quota_usec = (usec_t) -1;
+ return 0;
+ }
+
+ if (endswith(rvalue, "%")) {
+ double percent;
+
+ if (sscanf(rvalue, "%lf%%", &percent) != 1 || percent <= 0) {
+ log_syntax(unit, LOG_ERR, filename, line, EINVAL, "CPU quota '%s' invalid. Ignoring.", rvalue);
+ return 0;
+ }
+
+ c->cpu_quota_per_sec_usec = (usec_t) (percent * USEC_PER_SEC / 100);
+ c->cpu_quota_usec = (usec_t) -1;
+ } else {
+ r = parse_sec(rvalue, &c->cpu_quota_usec);
+ if (r < 0) {
+ log_syntax(unit, LOG_ERR, filename, line, EINVAL, "CPU quota '%s' invalid. Ignoring.", rvalue);
+ return 0;
+ }
+
+ c->cpu_quota_per_sec_usec = (usec_t) -1;
+ }
+
+ return 0;
+}
+
int config_parse_memory_limit(
const char *unit,
const char *filename,