Skip to content

Commit 05cfb61

Browse files
Roman ZippelLinus Torvalds
authored andcommitted
[PATCH] hrtimers: remove data field
The nanosleep cleanup allows to remove the data field of hrtimer. The callback function can use container_of() to get it's own data. Since the hrtimer structure is anyway embedded in other structures, this adds no overhead. Signed-off-by: Roman Zippel <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent df869b6 commit 05cfb61

File tree

8 files changed

+22
-27
lines changed

8 files changed

+22
-27
lines changed

fs/exec.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ static int de_thread(struct task_struct *tsk)
632632
* synchronize with any firing (by calling del_timer_sync)
633633
* before we can safely let the old group leader die.
634634
*/
635-
sig->real_timer.data = current;
635+
sig->tsk = current;
636636
spin_unlock_irq(lock);
637637
if (hrtimer_cancel(&sig->real_timer))
638638
hrtimer_restart(&sig->real_timer);

include/linux/hrtimer.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,15 @@ struct hrtimer_base;
4545
* @expires: the absolute expiry time in the hrtimers internal
4646
* representation. The time is related to the clock on
4747
* which the timer is based.
48-
* @state: state of the timer
4948
* @function: timer expiry callback function
50-
* @data: argument for the callback function
5149
* @base: pointer to the timer base (per cpu and per clock)
5250
*
5351
* The hrtimer structure must be initialized by init_hrtimer_#CLOCKTYPE()
5452
*/
5553
struct hrtimer {
5654
struct rb_node node;
5755
ktime_t expires;
58-
int (*function)(void *);
59-
void *data;
56+
int (*function)(struct hrtimer *);
6057
struct hrtimer_base *base;
6158
};
6259

include/linux/sched.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,7 @@ struct signal_struct {
402402

403403
/* ITIMER_REAL timer for the process */
404404
struct hrtimer real_timer;
405+
struct task_struct *tsk;
405406
ktime_t it_real_incr;
406407

407408
/* ITIMER_PROF and ITIMER_VIRTUAL timers for the process */

include/linux/timer.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ static inline void add_timer(struct timer_list *timer)
9696

9797
extern void init_timers(void);
9898
extern void run_local_timers(void);
99-
extern int it_real_fn(void *);
99+
struct hrtimer;
100+
extern int it_real_fn(struct hrtimer *);
100101

101102
#endif

kernel/fork.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,7 @@ static inline int copy_signal(unsigned long clone_flags, struct task_struct * ts
848848
hrtimer_init(&sig->real_timer, CLOCK_MONOTONIC, HRTIMER_REL);
849849
sig->it_real_incr.tv64 = 0;
850850
sig->real_timer.function = it_real_fn;
851-
sig->real_timer.data = tsk;
851+
sig->tsk = tsk;
852852

853853
sig->it_virt_expires = cputime_zero;
854854
sig->it_virt_incr = cputime_zero;

kernel/hrtimer.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -613,21 +613,19 @@ static inline void run_hrtimer_queue(struct hrtimer_base *base)
613613

614614
while ((node = base->first)) {
615615
struct hrtimer *timer;
616-
int (*fn)(void *);
616+
int (*fn)(struct hrtimer *);
617617
int restart;
618-
void *data;
619618

620619
timer = rb_entry(node, struct hrtimer, node);
621620
if (base->softirq_time.tv64 <= timer->expires.tv64)
622621
break;
623622

624623
fn = timer->function;
625-
data = timer->data;
626624
set_curr_timer(base, timer);
627625
__remove_hrtimer(timer, base);
628626
spin_unlock_irq(&base->lock);
629627

630-
restart = fn(data);
628+
restart = fn(timer);
631629

632630
spin_lock_irq(&base->lock);
633631

@@ -664,9 +662,10 @@ struct sleep_hrtimer {
664662
int expired;
665663
};
666664

667-
static int nanosleep_wakeup(void *data)
665+
static int nanosleep_wakeup(struct hrtimer *timer)
668666
{
669-
struct sleep_hrtimer *t = data;
667+
struct sleep_hrtimer *t =
668+
container_of(timer, struct sleep_hrtimer, timer);
670669

671670
t->expired = 1;
672671
wake_up_process(t->task);
@@ -677,7 +676,6 @@ static int nanosleep_wakeup(void *data)
677676
static int __sched do_nanosleep(struct sleep_hrtimer *t, enum hrtimer_mode mode)
678677
{
679678
t->timer.function = nanosleep_wakeup;
680-
t->timer.data = t;
681679
t->task = current;
682680
t->expired = 0;
683681

kernel/itimer.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,17 +128,16 @@ asmlinkage long sys_getitimer(int which, struct itimerval __user *value)
128128
/*
129129
* The timer is automagically restarted, when interval != 0
130130
*/
131-
int it_real_fn(void *data)
131+
int it_real_fn(struct hrtimer *timer)
132132
{
133-
struct task_struct *tsk = (struct task_struct *) data;
133+
struct signal_struct *sig =
134+
container_of(timer, struct signal_struct, real_timer);
134135

135-
send_group_sig_info(SIGALRM, SEND_SIG_PRIV, tsk);
136-
137-
if (tsk->signal->it_real_incr.tv64 != 0) {
138-
hrtimer_forward(&tsk->signal->real_timer,
139-
tsk->signal->real_timer.base->softirq_time,
140-
tsk->signal->it_real_incr);
136+
send_group_sig_info(SIGALRM, SEND_SIG_PRIV, sig->tsk);
141137

138+
if (sig->it_real_incr.tv64 != 0) {
139+
hrtimer_forward(timer, timer->base->softirq_time,
140+
sig->it_real_incr);
142141
return HRTIMER_RESTART;
143142
}
144143
return HRTIMER_NORESTART;

kernel/posix-timers.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ static int common_timer_set(struct k_itimer *, int,
145145
struct itimerspec *, struct itimerspec *);
146146
static int common_timer_del(struct k_itimer *timer);
147147

148-
static int posix_timer_fn(void *data);
148+
static int posix_timer_fn(struct hrtimer *data);
149149

150150
static struct k_itimer *lock_timer(timer_t timer_id, unsigned long *flags);
151151

@@ -334,14 +334,14 @@ EXPORT_SYMBOL_GPL(posix_timer_event);
334334
335335
* This code is for CLOCK_REALTIME* and CLOCK_MONOTONIC* timers.
336336
*/
337-
static int posix_timer_fn(void *data)
337+
static int posix_timer_fn(struct hrtimer *timer)
338338
{
339-
struct k_itimer *timr = data;
340-
struct hrtimer *timer = &timr->it.real.timer;
339+
struct k_itimer *timr;
341340
unsigned long flags;
342341
int si_private = 0;
343342
int ret = HRTIMER_NORESTART;
344343

344+
timr = container_of(timer, struct k_itimer, it.real.timer);
345345
spin_lock_irqsave(&timr->it_lock, flags);
346346

347347
if (timr->it.real.interval.tv64 != 0)
@@ -725,7 +725,6 @@ common_timer_set(struct k_itimer *timr, int flags,
725725

726726
mode = flags & TIMER_ABSTIME ? HRTIMER_ABS : HRTIMER_REL;
727727
hrtimer_init(&timr->it.real.timer, timr->it_clock, mode);
728-
timr->it.real.timer.data = timr;
729728
timr->it.real.timer.function = posix_timer_fn;
730729

731730
timer->expires = timespec_to_ktime(new_setting->it_value);

0 commit comments

Comments
 (0)