Skip to content

Commit 3f0a525

Browse files
Xiao GuangrongKAGA-KOKO
authored andcommitted
itimers: Add tracepoints for itimer
Add tracepoints for all itimer variants: ITIMER_REAL, ITIMER_VIRTUAL and ITIMER_PROF. [ tglx: Fixed comments and made the output more readable, parseable and consistent. Replaced pid_vnr by pid_nr because the hrtimer callback can happen in any namespace ] Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca> Cc: Anton Blanchard <anton@samba.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com> Cc: Zhaolei <zhaolei@cn.fujitsu.com> LKML-Reference: <4A7F8B6E.2010109@cn.fujitsu.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
1 parent c6a2a17 commit 3f0a525

3 files changed

Lines changed: 77 additions & 1 deletion

File tree

‎include/trace/events/timer.h‎

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,72 @@ TRACE_EVENT(hrtimer_cancel,
270270
TP_printk("hrtimer %p", __entry->timer)
271271
);
272272

273+
/**
274+
* itimer_state - called when itimer is started or canceled
275+
* @which: name of the interval timer
276+
* @value: the itimers value, itimer is canceled if value->it_value is
277+
* zero, otherwise it is started
278+
* @expires: the itimers expiry time
279+
*/
280+
TRACE_EVENT(itimer_state,
281+
282+
TP_PROTO(int which, const struct itimerval *const value,
283+
cputime_t expires),
284+
285+
TP_ARGS(which, value, expires),
286+
287+
TP_STRUCT__entry(
288+
__field( int, which )
289+
__field( cputime_t, expires )
290+
__field( long, value_sec )
291+
__field( long, value_usec )
292+
__field( long, interval_sec )
293+
__field( long, interval_usec )
294+
),
295+
296+
TP_fast_assign(
297+
__entry->which = which;
298+
__entry->expires = expires;
299+
__entry->value_sec = value->it_value.tv_sec;
300+
__entry->value_usec = value->it_value.tv_usec;
301+
__entry->interval_sec = value->it_interval.tv_sec;
302+
__entry->interval_usec = value->it_interval.tv_usec;
303+
),
304+
305+
TP_printk("which %d, expires %lu, it_value %lu.%lu, it_interval %lu.%lu",
306+
__entry->which, __entry->expires,
307+
__entry->value_sec, __entry->value_usec,
308+
__entry->interval_sec, __entry->interval_usec)
309+
);
310+
311+
/**
312+
* itimer_expire - called when itimer expires
313+
* @which: type of the interval timer
314+
* @pid: pid of the process which owns the timer
315+
* @now: current time, used to calculate the latency of itimer
316+
*/
317+
TRACE_EVENT(itimer_expire,
318+
319+
TP_PROTO(int which, struct pid *pid, cputime_t now),
320+
321+
TP_ARGS(which, pid, now),
322+
323+
TP_STRUCT__entry(
324+
__field( int , which )
325+
__field( pid_t, pid )
326+
__field( cputime_t, now )
327+
),
328+
329+
TP_fast_assign(
330+
__entry->which = which;
331+
__entry->now = now;
332+
__entry->pid = pid_nr(pid);
333+
),
334+
335+
TP_printk("which %d, pid %d, now %lu", __entry->which,
336+
(int) __entry->pid, __entry->now)
337+
);
338+
273339
#endif /* _TRACE_TIMER_H */
274340

275341
/* This part must be outside protection */

‎kernel/itimer.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <linux/time.h>
1313
#include <linux/posix-timers.h>
1414
#include <linux/hrtimer.h>
15+
#include <trace/events/timer.h>
1516

1617
#include <asm/uaccess.h>
1718

@@ -122,6 +123,7 @@ enum hrtimer_restart it_real_fn(struct hrtimer *timer)
122123
struct signal_struct *sig =
123124
container_of(timer, struct signal_struct, real_timer);
124125

126+
trace_itimer_expire(ITIMER_REAL, sig->leader_pid, 0);
125127
kill_pid_info(SIGALRM, SEND_SIG_PRIV, sig->leader_pid);
126128

127129
return HRTIMER_NORESTART;
@@ -166,6 +168,8 @@ static void set_cpu_itimer(struct task_struct *tsk, unsigned int clock_id,
166168
}
167169
it->expires = nval;
168170
it->incr = ninterval;
171+
trace_itimer_state(clock_id == CPUCLOCK_VIRT ?
172+
ITIMER_VIRTUAL : ITIMER_PROF, value, nval);
169173

170174
spin_unlock_irq(&tsk->sighand->siglock);
171175

@@ -217,6 +221,7 @@ int do_setitimer(int which, struct itimerval *value, struct itimerval *ovalue)
217221
} else
218222
tsk->signal->it_real_incr.tv64 = 0;
219223

224+
trace_itimer_state(ITIMER_REAL, value, 0);
220225
spin_unlock_irq(&tsk->sighand->siglock);
221226
break;
222227
case ITIMER_VIRTUAL:

‎kernel/posix-cpu-timers.c‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <linux/math64.h>
99
#include <asm/uaccess.h>
1010
#include <linux/kernel_stat.h>
11+
#include <trace/events/timer.h>
1112

1213
/*
1314
* Called after updating RLIMIT_CPU to set timer expiration if necessary.
@@ -1090,9 +1091,13 @@ static void check_cpu_itimer(struct task_struct *tsk, struct cpu_itimer *it,
10901091
cputime_one_jiffy);
10911092
it->error -= onecputick;
10921093
}
1093-
} else
1094+
} else {
10941095
it->expires = cputime_zero;
1096+
}
10951097

1098+
trace_itimer_expire(signo == SIGPROF ?
1099+
ITIMER_PROF : ITIMER_VIRTUAL,
1100+
tsk->signal->leader_pid, cur_time);
10961101
__group_send_sig_info(signo, SEND_SIG_PRIV, tsk);
10971102
}
10981103

0 commit comments

Comments
 (0)