Message ID | 20140513115749.ebf3eebc64e44aac6f183410@gmail.com |
---|---|
State | New |
Headers | show |
On Tue, May 13, 2014 at 11:57:49AM +0200, Juri Lelli wrote: > static bool > __checkparam_dl(const struct sched_attr *attr) > { > return attr && attr->sched_deadline != 0 && > (attr->sched_period == 0 || > - (s64)(attr->sched_period - attr->sched_deadline) >= 0) && > - (s64)(attr->sched_deadline - attr->sched_runtime ) >= 0 && > - attr->sched_runtime >= (2 << (DL_SCALE - 1)); > + (attr->sched_period >= attr->sched_deadline)) && > + (attr->sched_deadline >= attr->sched_runtime) && > + attr->sched_runtime >= (1ULL << DL_SCALE) && > + (attr->sched_deadline < (1ULL << 63) && > + attr->sched_period < (1ULL << 63)); > } Could we maybe rewrite that function to look less like a ioccc.org submission? static bool __checkparam_dl(const struct sched_attr *attr) { if (!attr) /* possible at all? */ return false; /* runtime <= deadline <= period */ if (attr->sched_period < attr->sched_deadline || attr->sched_deadline < attr->sched_runtime) return false; /* * Since we truncate DL_SCALE bits make sure we're at least that big, * if runtime > (1 << DL_SCALE), so must the others be per the above */ if (attr->sched_runtime <= (1ULL << DL_SCALE)) return false; /* * Since we use the MSB for wrap-around and sign issues, make * sure its not set, if period < 2^63, so must the others be. */ if (attr->sched_period & (1ULL << 63)) return false; return true; } Did I miss anything?
diff --git a/kernel/sched/core.c b/kernel/sched/core.c index d9d8ece..96ba59d 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -3188,17 +3188,21 @@ __getparam_dl(struct task_struct *p, struct sched_attr *attr) * We ask for the deadline not being zero, and greater or equal * than the runtime, as well as the period of being zero or * greater than deadline. Furthermore, we have to be sure that - * user parameters are above the internal resolution (1us); we - * check sched_runtime only since it is always the smaller one. + * user parameters are above the internal resolution of 1us (we + * check sched_runtime only since it is always the smaller one) and + * below 2^63 ns (we have to check both sched_deadline and + * sched_period, as the latter can be zero). */ static bool __checkparam_dl(const struct sched_attr *attr) { return attr && attr->sched_deadline != 0 && (attr->sched_period == 0 || - (s64)(attr->sched_period - attr->sched_deadline) >= 0) && - (s64)(attr->sched_deadline - attr->sched_runtime ) >= 0 && - attr->sched_runtime >= (2 << (DL_SCALE - 1)); + (attr->sched_period >= attr->sched_deadline)) && + (attr->sched_deadline >= attr->sched_runtime) && + attr->sched_runtime >= (1ULL << DL_SCALE) && + (attr->sched_deadline < (1ULL << 63) && + attr->sched_period < (1ULL << 63)); } /*