Commit d4bb5274 authored by Jiri Slaby's avatar Jiri Slaby Committed by Linus Torvalds

posix-cpu-timers: cleanup rlimits usage

Fetch rlimit (both hard and soft) values only once and work on them.  It
removes many accesses through sig structure and makes the code cleaner.

Mostly a preparation for writable resource limits support.
Signed-off-by: default avatarJiri Slaby <jslaby@suse.cz>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: john stultz <johnstul@us.ibm.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent f3abd4f9
...@@ -982,6 +982,7 @@ static void check_thread_timers(struct task_struct *tsk, ...@@ -982,6 +982,7 @@ static void check_thread_timers(struct task_struct *tsk,
int maxfire; int maxfire;
struct list_head *timers = tsk->cpu_timers; struct list_head *timers = tsk->cpu_timers;
struct signal_struct *const sig = tsk->signal; struct signal_struct *const sig = tsk->signal;
unsigned long soft;
maxfire = 20; maxfire = 20;
tsk->cputime_expires.prof_exp = cputime_zero; tsk->cputime_expires.prof_exp = cputime_zero;
...@@ -1030,9 +1031,9 @@ static void check_thread_timers(struct task_struct *tsk, ...@@ -1030,9 +1031,9 @@ static void check_thread_timers(struct task_struct *tsk,
/* /*
* Check for the special case thread timers. * Check for the special case thread timers.
*/ */
if (sig->rlim[RLIMIT_RTTIME].rlim_cur != RLIM_INFINITY) { soft = sig->rlim[RLIMIT_RTTIME].rlim_cur;
if (soft != RLIM_INFINITY) {
unsigned long hard = sig->rlim[RLIMIT_RTTIME].rlim_max; unsigned long hard = sig->rlim[RLIMIT_RTTIME].rlim_max;
unsigned long *soft = &sig->rlim[RLIMIT_RTTIME].rlim_cur;
if (hard != RLIM_INFINITY && if (hard != RLIM_INFINITY &&
tsk->rt.timeout > DIV_ROUND_UP(hard, USEC_PER_SEC/HZ)) { tsk->rt.timeout > DIV_ROUND_UP(hard, USEC_PER_SEC/HZ)) {
...@@ -1043,14 +1044,13 @@ static void check_thread_timers(struct task_struct *tsk, ...@@ -1043,14 +1044,13 @@ static void check_thread_timers(struct task_struct *tsk,
__group_send_sig_info(SIGKILL, SEND_SIG_PRIV, tsk); __group_send_sig_info(SIGKILL, SEND_SIG_PRIV, tsk);
return; return;
} }
if (tsk->rt.timeout > DIV_ROUND_UP(*soft, USEC_PER_SEC/HZ)) { if (tsk->rt.timeout > DIV_ROUND_UP(soft, USEC_PER_SEC/HZ)) {
/* /*
* At the soft limit, send a SIGXCPU every second. * At the soft limit, send a SIGXCPU every second.
*/ */
if (sig->rlim[RLIMIT_RTTIME].rlim_cur if (soft < hard) {
< sig->rlim[RLIMIT_RTTIME].rlim_max) { soft += USEC_PER_SEC;
sig->rlim[RLIMIT_RTTIME].rlim_cur += sig->rlim[RLIMIT_RTTIME].rlim_cur = soft;
USEC_PER_SEC;
} }
printk(KERN_INFO printk(KERN_INFO
"RT Watchdog Timeout: %s[%d]\n", "RT Watchdog Timeout: %s[%d]\n",
...@@ -1121,6 +1121,7 @@ static void check_process_timers(struct task_struct *tsk, ...@@ -1121,6 +1121,7 @@ static void check_process_timers(struct task_struct *tsk,
unsigned long long sum_sched_runtime, sched_expires; unsigned long long sum_sched_runtime, sched_expires;
struct list_head *timers = sig->cpu_timers; struct list_head *timers = sig->cpu_timers;
struct task_cputime cputime; struct task_cputime cputime;
unsigned long soft;
/* /*
* Don't sample the current process CPU clocks if there are no timers. * Don't sample the current process CPU clocks if there are no timers.
...@@ -1193,11 +1194,12 @@ static void check_process_timers(struct task_struct *tsk, ...@@ -1193,11 +1194,12 @@ static void check_process_timers(struct task_struct *tsk,
SIGPROF); SIGPROF);
check_cpu_itimer(tsk, &sig->it[CPUCLOCK_VIRT], &virt_expires, utime, check_cpu_itimer(tsk, &sig->it[CPUCLOCK_VIRT], &virt_expires, utime,
SIGVTALRM); SIGVTALRM);
soft = sig->rlim[RLIMIT_CPU].rlim_cur;
if (sig->rlim[RLIMIT_CPU].rlim_cur != RLIM_INFINITY) { if (soft != RLIM_INFINITY) {
unsigned long psecs = cputime_to_secs(ptime); unsigned long psecs = cputime_to_secs(ptime);
unsigned long hard = sig->rlim[RLIMIT_CPU].rlim_max;
cputime_t x; cputime_t x;
if (psecs >= sig->rlim[RLIMIT_CPU].rlim_max) { if (psecs >= hard) {
/* /*
* At the hard limit, we just die. * At the hard limit, we just die.
* No need to calculate anything else now. * No need to calculate anything else now.
...@@ -1205,17 +1207,17 @@ static void check_process_timers(struct task_struct *tsk, ...@@ -1205,17 +1207,17 @@ static void check_process_timers(struct task_struct *tsk,
__group_send_sig_info(SIGKILL, SEND_SIG_PRIV, tsk); __group_send_sig_info(SIGKILL, SEND_SIG_PRIV, tsk);
return; return;
} }
if (psecs >= sig->rlim[RLIMIT_CPU].rlim_cur) { if (psecs >= soft) {
/* /*
* At the soft limit, send a SIGXCPU every second. * At the soft limit, send a SIGXCPU every second.
*/ */
__group_send_sig_info(SIGXCPU, SEND_SIG_PRIV, tsk); __group_send_sig_info(SIGXCPU, SEND_SIG_PRIV, tsk);
if (sig->rlim[RLIMIT_CPU].rlim_cur if (soft < hard) {
< sig->rlim[RLIMIT_CPU].rlim_max) { soft++;
sig->rlim[RLIMIT_CPU].rlim_cur++; sig->rlim[RLIMIT_CPU].rlim_cur = soft;
} }
} }
x = secs_to_cputime(sig->rlim[RLIMIT_CPU].rlim_cur); x = secs_to_cputime(soft);
if (cputime_eq(prof_expires, cputime_zero) || if (cputime_eq(prof_expires, cputime_zero) ||
cputime_lt(x, prof_expires)) { cputime_lt(x, prof_expires)) {
prof_expires = x; prof_expires = x;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment