Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

posix_cpu_timers: consolidate expired timers check

Consolidate the common code amongst per thread and per process timers list
on tick time.

List traversal, expiry check and subsequent updates can be shared in a
common helper.

Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Stanislaw Gruszka <sgruszka@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@gmail.com>
Cc: Olivier Langlois <olivier@trillion01.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

+33 -85
+33 -85
kernel/posix-cpu-timers.c
··· 862 862 } 863 863 } 864 864 865 + static unsigned long long 866 + check_timers_list(struct list_head *timers, 867 + struct list_head *firing, 868 + unsigned long long curr) 869 + { 870 + int maxfire = 20; 871 + 872 + while (!list_empty(timers)) { 873 + struct cpu_timer_list *t; 874 + 875 + t = list_first_entry(timers, struct cpu_timer_list, entry); 876 + 877 + if (!--maxfire || curr < t->expires) 878 + return t->expires; 879 + 880 + t->firing = 1; 881 + list_move_tail(&t->entry, firing); 882 + } 883 + 884 + return 0; 885 + } 886 + 865 887 /* 866 888 * Check for any per-thread CPU timers that have fired and move them off 867 889 * the tsk->cpu_timers[N] list onto the firing list. Here we update the ··· 892 870 static void check_thread_timers(struct task_struct *tsk, 893 871 struct list_head *firing) 894 872 { 895 - int maxfire; 896 873 struct list_head *timers = tsk->cpu_timers; 897 874 struct signal_struct *const sig = tsk->signal; 875 + struct task_cputime *tsk_expires = &tsk->cputime_expires; 876 + unsigned long long expires; 898 877 unsigned long soft; 899 878 900 - maxfire = 20; 901 - tsk->cputime_expires.prof_exp = 0; 902 - while (!list_empty(timers)) { 903 - struct cpu_timer_list *t = list_first_entry(timers, 904 - struct cpu_timer_list, 905 - entry); 906 - if (!--maxfire || prof_ticks(tsk) < t->expires) { 907 - tsk->cputime_expires.prof_exp = expires_to_cputime(t->expires); 908 - break; 909 - } 910 - t->firing = 1; 911 - list_move_tail(&t->entry, firing); 912 - } 879 + expires = check_timers_list(timers, firing, prof_ticks(tsk)); 880 + tsk_expires->prof_exp = expires_to_cputime(expires); 913 881 914 - ++timers; 915 - maxfire = 20; 916 - tsk->cputime_expires.virt_exp = 0; 917 - while (!list_empty(timers)) { 918 - struct cpu_timer_list *t = list_first_entry(timers, 919 - struct cpu_timer_list, 920 - entry); 921 - if (!--maxfire || virt_ticks(tsk) < t->expires) { 922 - tsk->cputime_expires.virt_exp = expires_to_cputime(t->expires); 923 - break; 924 - } 925 - t->firing = 1; 926 - list_move_tail(&t->entry, firing); 927 - } 882 + expires = check_timers_list(++timers, firing, virt_ticks(tsk)); 883 + tsk_expires->virt_exp = expires_to_cputime(expires); 928 884 929 - ++timers; 930 - maxfire = 20; 931 - tsk->cputime_expires.sched_exp = 0; 932 - while (!list_empty(timers)) { 933 - struct cpu_timer_list *t = list_first_entry(timers, 934 - struct cpu_timer_list, 935 - entry); 936 - if (!--maxfire || tsk->se.sum_exec_runtime < t->expires) { 937 - tsk->cputime_expires.sched_exp = t->expires; 938 - break; 939 - } 940 - t->firing = 1; 941 - list_move_tail(&t->entry, firing); 942 - } 885 + tsk_expires->sched_exp = check_timers_list(++timers, firing, 886 + tsk->se.sum_exec_runtime); 943 887 944 888 /* 945 889 * Check for the special case thread timers. ··· 990 1002 static void check_process_timers(struct task_struct *tsk, 991 1003 struct list_head *firing) 992 1004 { 993 - int maxfire; 994 1005 struct signal_struct *const sig = tsk->signal; 995 1006 unsigned long long utime, ptime, virt_expires, prof_expires; 996 1007 unsigned long long sum_sched_runtime, sched_expires; ··· 1004 1017 utime = cputime_to_expires(cputime.utime); 1005 1018 ptime = utime + cputime_to_expires(cputime.stime); 1006 1019 sum_sched_runtime = cputime.sum_exec_runtime; 1007 - maxfire = 20; 1008 - prof_expires = 0; 1009 - while (!list_empty(timers)) { 1010 - struct cpu_timer_list *tl = list_first_entry(timers, 1011 - struct cpu_timer_list, 1012 - entry); 1013 - if (!--maxfire || ptime < tl->expires) { 1014 - prof_expires = tl->expires; 1015 - break; 1016 - } 1017 - tl->firing = 1; 1018 - list_move_tail(&tl->entry, firing); 1019 - } 1020 1020 1021 - ++timers; 1022 - maxfire = 20; 1023 - virt_expires = 0; 1024 - while (!list_empty(timers)) { 1025 - struct cpu_timer_list *tl = list_first_entry(timers, 1026 - struct cpu_timer_list, 1027 - entry); 1028 - if (!--maxfire || utime < tl->expires) { 1029 - virt_expires = tl->expires; 1030 - break; 1031 - } 1032 - tl->firing = 1; 1033 - list_move_tail(&tl->entry, firing); 1034 - } 1035 - 1036 - ++timers; 1037 - maxfire = 20; 1038 - sched_expires = 0; 1039 - while (!list_empty(timers)) { 1040 - struct cpu_timer_list *tl = list_first_entry(timers, 1041 - struct cpu_timer_list, 1042 - entry); 1043 - if (!--maxfire || sum_sched_runtime < tl->expires) { 1044 - sched_expires = tl->expires; 1045 - break; 1046 - } 1047 - tl->firing = 1; 1048 - list_move_tail(&tl->entry, firing); 1049 - } 1021 + prof_expires = check_timers_list(timers, firing, ptime); 1022 + virt_expires = check_timers_list(++timers, firing, utime); 1023 + sched_expires = check_timers_list(++timers, firing, sum_sched_runtime); 1050 1024 1051 1025 /* 1052 1026 * Check for the special case process timers.