Bursty timers aren't good for anybody, very much including latency for other programs when we trigger lots of timers in interrupt context. So set a random limit, after which we'll handle the rest on the next timer tick. Noted by Oleg Nesterov <oleg@tv-sign.ru>
Unified · Split
| @@ -961,14 +961,16 @@ void posix_cpu_timer_get(struct k_itimer *timer, struct itimerspec *itp) · 960 unmodified lines | ||
| 961 | 961 | static void check_thread_timers(struct task_struct *tsk, |
| 962 | 962 | struct list_head *firing) |
| 963 | 963 | { |
| 964 | + int maxfire; | |
| 964 | 965 | struct list_head *timers = tsk->cpu_timers; |
| 965 | 966 | |
| 967 | + maxfire = 20; | |
| 966 | 968 | tsk->it_prof_expires = cputime_zero; |
| 967 | 969 | while (!list_empty(timers)) { |
| 968 | 970 | struct cpu_timer_list *t = list_entry(timers->next, |
| 969 | 971 | struct cpu_timer_list, |
| 970 | 972 | entry); |
| 971 | − if (cputime_lt(prof_ticks(tsk), t->expires.cpu)) { | |
| 973 | + if (!--maxfire || cputime_lt(prof_ticks(tsk), t->expires.cpu)) { | |
| 972 | 974 | tsk->it_prof_expires = t->expires.cpu; |
| 973 | 975 | break; |
| 974 | 976 | } |
| @@ -977,12 +979,13 @@ static void check_thread_timers(struct task_struct *tsk, · 2 unmodified lines | ||
| 977 | 979 | } |
| 978 | 980 | |
| 979 | 981 | ++timers; |
| 982 | + maxfire = 20; | |
| 980 | 983 | tsk->it_virt_expires = cputime_zero; |
| 981 | 984 | while (!list_empty(timers)) { |
| 982 | 985 | struct cpu_timer_list *t = list_entry(timers->next, |
| 983 | 986 | struct cpu_timer_list, |
| 984 | 987 | entry); |
| 985 | − if (cputime_lt(virt_ticks(tsk), t->expires.cpu)) { | |
| 988 | + if (!--maxfire || cputime_lt(virt_ticks(tsk), t->expires.cpu)) { | |
| 986 | 989 | tsk->it_virt_expires = t->expires.cpu; |
| 987 | 990 | break; |
| 988 | 991 | } |
| @@ -991,12 +994,13 @@ static void check_thread_timers(struct task_struct *tsk, · 2 unmodified lines | ||
| 991 | 994 | } |
| 992 | 995 | |
| 993 | 996 | ++timers; |
| 997 | + maxfire = 20; | |
| 994 | 998 | tsk->it_sched_expires = 0; |
| 995 | 999 | while (!list_empty(timers)) { |
| 996 | 1000 | struct cpu_timer_list *t = list_entry(timers->next, |
| 997 | 1001 | struct cpu_timer_list, |
| 998 | 1002 | entry); |
| 999 | − if (tsk->sched_time < t->expires.sched) { | |
| 1003 | + if (!--maxfire || tsk->sched_time < t->expires.sched) { | |
| 1000 | 1004 | tsk->it_sched_expires = t->expires.sched; |
| 1001 | 1005 | break; |
| 1002 | 1006 | } |
| @@ -1013,6 +1017,7 @@ static void check_thread_timers(struct task_struct *tsk, · 10 unmodified lines | ||
| 1013 | 1017 | static void check_process_timers(struct task_struct *tsk, |
| 1014 | 1018 | struct list_head *firing) |
| 1015 | 1019 | { |
| 1020 | + int maxfire; | |
| 1016 | 1021 | struct signal_struct *const sig = tsk->signal; |
| 1017 | 1022 | cputime_t utime, stime, ptime, virt_expires, prof_expires; |
| 1018 | 1023 | unsigned long long sched_time, sched_expires; |
| @@ -1045,12 +1050,13 @@ static void check_process_timers(struct task_struct *tsk, · 26 unmodified lines | ||
| 1045 | 1050 | } while (t != tsk); |
| 1046 | 1051 | ptime = cputime_add(utime, stime); |
| 1047 | 1052 | |
| 1053 | + maxfire = 20; | |
| 1048 | 1054 | prof_expires = cputime_zero; |
| 1049 | 1055 | while (!list_empty(timers)) { |
| 1050 | 1056 | struct cpu_timer_list *t = list_entry(timers->next, |
| 1051 | 1057 | struct cpu_timer_list, |
| 1052 | 1058 | entry); |
| 1053 | − if (cputime_lt(ptime, t->expires.cpu)) { | |
| 1059 | + if (!--maxfire || cputime_lt(ptime, t->expires.cpu)) { | |
| 1054 | 1060 | prof_expires = t->expires.cpu; |
| 1055 | 1061 | break; |
| 1056 | 1062 | } |
| @@ -1059,12 +1065,13 @@ static void check_process_timers(struct task_struct *tsk, · 2 unmodified lines | ||
| 1059 | 1065 | } |
| 1060 | 1066 | |
| 1061 | 1067 | ++timers; |
| 1068 | + maxfire = 20; | |
| 1062 | 1069 | virt_expires = cputime_zero; |
| 1063 | 1070 | while (!list_empty(timers)) { |
| 1064 | 1071 | struct cpu_timer_list *t = list_entry(timers->next, |
| 1065 | 1072 | struct cpu_timer_list, |
| 1066 | 1073 | entry); |
| 1067 | − if (cputime_lt(utime, t->expires.cpu)) { | |
| 1074 | + if (!--maxfire || cputime_lt(utime, t->expires.cpu)) { | |
| 1068 | 1075 | virt_expires = t->expires.cpu; |
| 1069 | 1076 | break; |
| 1070 | 1077 | } |
| @@ -1073,12 +1080,13 @@ static void check_process_timers(struct task_struct *tsk, · 2 unmodified lines | ||
| 1073 | 1080 | } |
| 1074 | 1081 | |
| 1075 | 1082 | ++timers; |
| 1083 | + maxfire = 20; | |
| 1076 | 1084 | sched_expires = 0; |
| 1077 | 1085 | while (!list_empty(timers)) { |
| 1078 | 1086 | struct cpu_timer_list *t = list_entry(timers->next, |
| 1079 | 1087 | struct cpu_timer_list, |
| 1080 | 1088 | entry); |
| 1081 | − if (sched_time < t->expires.sched) { | |
| 1089 | + if (!--maxfire || sched_time < t->expires.sched) { | |
| 1082 | 1090 | sched_expires = t->expires.sched; |
| 1083 | 1091 | break; |
| 1084 | 1092 | } |