Skip to content

Commit 52dea0a

Browse files
KAGA-KOKOFrederic Weisbecker
authored andcommitted
posix-timers: Convert timer list to hlist
No requirement for a real list. Spare a few bytes. Signed-off-by: Thomas Gleixner <[email protected]> Signed-off-by: Frederic Weisbecker <[email protected]> Acked-by: Peter Zijlstra (Intel) <[email protected]>
1 parent aca1dc0 commit 52dea0a

File tree

6 files changed

+15
-18
lines changed

6 files changed

+15
-18
lines changed

fs/proc/base.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2456,13 +2456,13 @@ static void *timers_start(struct seq_file *m, loff_t *pos)
24562456
if (!tp->sighand)
24572457
return ERR_PTR(-ESRCH);
24582458

2459-
return seq_list_start(&tp->task->signal->posix_timers, *pos);
2459+
return seq_hlist_start(&tp->task->signal->posix_timers, *pos);
24602460
}
24612461

24622462
static void *timers_next(struct seq_file *m, void *v, loff_t *pos)
24632463
{
24642464
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);
24662466
}
24672467

24682468
static void timers_stop(struct seq_file *m, void *v)
@@ -2491,7 +2491,7 @@ static int show_timer(struct seq_file *m, void *v)
24912491
[SIGEV_THREAD] = "thread",
24922492
};
24932493

2494-
timer = list_entry((struct list_head *)v, struct k_itimer, list);
2494+
timer = hlist_entry((struct hlist_node *)v, struct k_itimer, list);
24952495
notify = timer->it_sigev_notify;
24962496

24972497
seq_printf(m, "ID: %d\n", timer->it_id);

include/linux/posix-timers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ static inline void posix_cputimers_init_work(void) { }
158158
* @rcu: RCU head for freeing the timer.
159159
*/
160160
struct k_itimer {
161-
struct list_head list;
161+
struct hlist_node list;
162162
struct hlist_node t_hash;
163163
spinlock_t it_lock;
164164
const struct k_clock *kclock;

include/linux/sched/signal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ struct signal_struct {
137137

138138
/* POSIX.1b Interval Timers */
139139
unsigned int next_posix_timer_id;
140-
struct list_head posix_timers;
140+
struct hlist_head posix_timers;
141141

142142
/* ITIMER_REAL timer for the process */
143143
struct hrtimer real_timer;

init/init_task.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ static struct signal_struct init_signals = {
2929
.cred_guard_mutex = __MUTEX_INITIALIZER(init_signals.cred_guard_mutex),
3030
.exec_update_lock = __RWSEM_INITIALIZER(init_signals.exec_update_lock),
3131
#ifdef CONFIG_POSIX_TIMERS
32-
.posix_timers = LIST_HEAD_INIT(init_signals.posix_timers),
32+
.posix_timers = HLIST_HEAD_INIT,
3333
.cputimer = {
3434
.cputime_atomic = INIT_CPUTIME_ATOMIC,
3535
},

kernel/fork.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1861,7 +1861,7 @@ static int copy_signal(unsigned long clone_flags, struct task_struct *tsk)
18611861
prev_cputime_init(&sig->prev_cputime);
18621862

18631863
#ifdef CONFIG_POSIX_TIMERS
1864-
INIT_LIST_HEAD(&sig->posix_timers);
1864+
INIT_HLIST_HEAD(&sig->posix_timers);
18651865
hrtimer_init(&sig->real_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
18661866
sig->real_timer.function = it_real_fn;
18671867
#endif

kernel/time/posix-timers.c

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ static int do_timer_create(clockid_t which_clock, struct sigevent *event,
515515
spin_lock_irq(&current->sighand->siglock);
516516
/* This makes the timer valid in the hash table */
517517
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);
519519
spin_unlock_irq(&current->sighand->siglock);
520520
/*
521521
* After unlocking sighand::siglock @new_timer is subject to
@@ -1025,7 +1025,7 @@ SYSCALL_DEFINE1(timer_delete, timer_t, timer_id)
10251025
}
10261026

10271027
spin_lock(&current->sighand->siglock);
1028-
list_del(&timer->list);
1028+
hlist_del(&timer->list);
10291029
spin_unlock(&current->sighand->siglock);
10301030
/*
10311031
* A concurrent lookup could check timer::it_signal lockless. It
@@ -1075,7 +1075,7 @@ static void itimer_delete(struct k_itimer *timer)
10751075

10761076
goto retry_delete;
10771077
}
1078-
list_del(&timer->list);
1078+
hlist_del(&timer->list);
10791079

10801080
/*
10811081
* Setting timer::it_signal to NULL is technically not required
@@ -1096,22 +1096,19 @@ static void itimer_delete(struct k_itimer *timer)
10961096
*/
10971097
void exit_itimers(struct task_struct *tsk)
10981098
{
1099-
struct list_head timers;
1100-
struct k_itimer *tmr;
1099+
struct hlist_head timers;
11011100

1102-
if (list_empty(&tsk->signal->posix_timers))
1101+
if (hlist_empty(&tsk->signal->posix_timers))
11031102
return;
11041103

11051104
/* Protect against concurrent read via /proc/$PID/timers */
11061105
spin_lock_irq(&tsk->sighand->siglock);
1107-
list_replace_init(&tsk->signal->posix_timers, &timers);
1106+
hlist_move_list(&tsk->signal->posix_timers, &timers);
11081107
spin_unlock_irq(&tsk->sighand->siglock);
11091108

11101109
/* 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));
11151112
}
11161113

11171114
SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,

0 commit comments

Comments
 (0)