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

posix-timers: Convert timer list to hlist

No requirement for a real list. Spare a few bytes.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Frederic Weisbecker <frederic@kernel.org>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>

authored by

Thomas Gleixner and committed by
Frederic Weisbecker
52dea0a1 aca1dc0c

+15 -18
+3 -3
fs/proc/base.c
··· 2456 2456 if (!tp->sighand) 2457 2457 return ERR_PTR(-ESRCH); 2458 2458 2459 - return seq_list_start(&tp->task->signal->posix_timers, *pos); 2459 + return seq_hlist_start(&tp->task->signal->posix_timers, *pos); 2460 2460 } 2461 2461 2462 2462 static void *timers_next(struct seq_file *m, void *v, loff_t *pos) 2463 2463 { 2464 2464 struct timers_private *tp = m->private; 2465 - return seq_list_next(v, &tp->task->signal->posix_timers, pos); 2465 + return seq_hlist_next(v, &tp->task->signal->posix_timers, pos); 2466 2466 } 2467 2467 2468 2468 static void timers_stop(struct seq_file *m, void *v) ··· 2491 2491 [SIGEV_THREAD] = "thread", 2492 2492 }; 2493 2493 2494 - timer = list_entry((struct list_head *)v, struct k_itimer, list); 2494 + timer = hlist_entry((struct hlist_node *)v, struct k_itimer, list); 2495 2495 notify = timer->it_sigev_notify; 2496 2496 2497 2497 seq_printf(m, "ID: %d\n", timer->it_id);
+1 -1
include/linux/posix-timers.h
··· 158 158 * @rcu: RCU head for freeing the timer. 159 159 */ 160 160 struct k_itimer { 161 - struct list_head list; 161 + struct hlist_node list; 162 162 struct hlist_node t_hash; 163 163 spinlock_t it_lock; 164 164 const struct k_clock *kclock;
+1 -1
include/linux/sched/signal.h
··· 137 137 138 138 /* POSIX.1b Interval Timers */ 139 139 unsigned int next_posix_timer_id; 140 - struct list_head posix_timers; 140 + struct hlist_head posix_timers; 141 141 142 142 /* ITIMER_REAL timer for the process */ 143 143 struct hrtimer real_timer;
+1 -1
init/init_task.c
··· 29 29 .cred_guard_mutex = __MUTEX_INITIALIZER(init_signals.cred_guard_mutex), 30 30 .exec_update_lock = __RWSEM_INITIALIZER(init_signals.exec_update_lock), 31 31 #ifdef CONFIG_POSIX_TIMERS 32 - .posix_timers = LIST_HEAD_INIT(init_signals.posix_timers), 32 + .posix_timers = HLIST_HEAD_INIT, 33 33 .cputimer = { 34 34 .cputime_atomic = INIT_CPUTIME_ATOMIC, 35 35 },
+1 -1
kernel/fork.c
··· 1861 1861 prev_cputime_init(&sig->prev_cputime); 1862 1862 1863 1863 #ifdef CONFIG_POSIX_TIMERS 1864 - INIT_LIST_HEAD(&sig->posix_timers); 1864 + INIT_HLIST_HEAD(&sig->posix_timers); 1865 1865 hrtimer_init(&sig->real_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); 1866 1866 sig->real_timer.function = it_real_fn; 1867 1867 #endif
+8 -11
kernel/time/posix-timers.c
··· 515 515 spin_lock_irq(&current->sighand->siglock); 516 516 /* This makes the timer valid in the hash table */ 517 517 WRITE_ONCE(new_timer->it_signal, current->signal); 518 - list_add(&new_timer->list, &current->signal->posix_timers); 518 + hlist_add_head(&new_timer->list, &current->signal->posix_timers); 519 519 spin_unlock_irq(&current->sighand->siglock); 520 520 /* 521 521 * After unlocking sighand::siglock @new_timer is subject to ··· 1025 1025 } 1026 1026 1027 1027 spin_lock(&current->sighand->siglock); 1028 - list_del(&timer->list); 1028 + hlist_del(&timer->list); 1029 1029 spin_unlock(&current->sighand->siglock); 1030 1030 /* 1031 1031 * A concurrent lookup could check timer::it_signal lockless. It ··· 1075 1075 1076 1076 goto retry_delete; 1077 1077 } 1078 - list_del(&timer->list); 1078 + hlist_del(&timer->list); 1079 1079 1080 1080 /* 1081 1081 * Setting timer::it_signal to NULL is technically not required ··· 1096 1096 */ 1097 1097 void exit_itimers(struct task_struct *tsk) 1098 1098 { 1099 - struct list_head timers; 1100 - struct k_itimer *tmr; 1099 + struct hlist_head timers; 1101 1100 1102 - if (list_empty(&tsk->signal->posix_timers)) 1101 + if (hlist_empty(&tsk->signal->posix_timers)) 1103 1102 return; 1104 1103 1105 1104 /* Protect against concurrent read via /proc/$PID/timers */ 1106 1105 spin_lock_irq(&tsk->sighand->siglock); 1107 - list_replace_init(&tsk->signal->posix_timers, &timers); 1106 + hlist_move_list(&tsk->signal->posix_timers, &timers); 1108 1107 spin_unlock_irq(&tsk->sighand->siglock); 1109 1108 1110 1109 /* The timers are not longer accessible via tsk::signal */ 1111 - while (!list_empty(&timers)) { 1112 - tmr = list_first_entry(&timers, struct k_itimer, list); 1113 - itimer_delete(tmr); 1114 - } 1110 + while (!hlist_empty(&timers)) 1111 + itimer_delete(hlist_entry(timers.first, struct k_itimer, list)); 1115 1112 } 1116 1113 1117 1114 SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,