aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/linux/perf_counter.h13
-rw-r--r--kernel/perf_counter.c27
2 files changed, 39 insertions, 1 deletions
diff --git a/include/linux/perf_counter.h b/include/linux/perf_counter.h
index edf5bfb7ff51..43083afffe0f 100644
--- a/include/linux/perf_counter.h
+++ b/include/linux/perf_counter.h
@@ -140,8 +140,9 @@ struct perf_counter_hw_event {
140 include_tid : 1, /* include the tid */ 140 include_tid : 1, /* include the tid */
141 mmap : 1, /* include mmap data */ 141 mmap : 1, /* include mmap data */
142 munmap : 1, /* include munmap data */ 142 munmap : 1, /* include munmap data */
143 callchain : 1, /* add callchain data */
143 144
144 __reserved_1 : 52; 145 __reserved_1 : 51;
145 146
146 __u32 extra_config_len; 147 __u32 extra_config_len;
147 __u32 __reserved_4; 148 __u32 __reserved_4;
@@ -219,6 +220,7 @@ enum perf_event_type {
219 PERF_EVENT_OVERFLOW = 1UL << 31, 220 PERF_EVENT_OVERFLOW = 1UL << 31,
220 __PERF_EVENT_IP = 1UL << 30, 221 __PERF_EVENT_IP = 1UL << 30,
221 __PERF_EVENT_TID = 1UL << 29, 222 __PERF_EVENT_TID = 1UL << 29,
223 __PERF_EVENT_CALLCHAIN = 1UL << 28,
222}; 224};
223 225
224#ifdef __KERNEL__ 226#ifdef __KERNEL__
@@ -504,6 +506,15 @@ extern void perf_counter_mmap(unsigned long addr, unsigned long len,
504extern void perf_counter_munmap(unsigned long addr, unsigned long len, 506extern void perf_counter_munmap(unsigned long addr, unsigned long len,
505 unsigned long pgoff, struct file *file); 507 unsigned long pgoff, struct file *file);
506 508
509#define MAX_STACK_DEPTH 255
510
511struct perf_callchain_entry {
512 u64 nr;
513 u64 ip[MAX_STACK_DEPTH];
514};
515
516extern struct perf_callchain_entry *perf_callchain(struct pt_regs *regs);
517
507#else 518#else
508static inline void 519static inline void
509perf_counter_task_sched_in(struct task_struct *task, int cpu) { } 520perf_counter_task_sched_in(struct task_struct *task, int cpu) { }
diff --git a/kernel/perf_counter.c b/kernel/perf_counter.c
index d93e9ddf7848..860cdc26bd7a 100644
--- a/kernel/perf_counter.c
+++ b/kernel/perf_counter.c
@@ -1654,6 +1654,17 @@ void perf_counter_do_pending(void)
1654} 1654}
1655 1655
1656/* 1656/*
1657 * Callchain support -- arch specific
1658 */
1659
1660struct perf_callchain_entry *
1661__attribute__((weak))
1662perf_callchain(struct pt_regs *regs)
1663{
1664 return NULL;
1665}
1666
1667/*
1657 * Output 1668 * Output
1658 */ 1669 */
1659 1670
@@ -1764,6 +1775,8 @@ static void perf_output_simple(struct perf_counter *counter,
1764 struct { 1775 struct {
1765 u32 pid, tid; 1776 u32 pid, tid;
1766 } tid_entry; 1777 } tid_entry;
1778 struct perf_callchain_entry *callchain = NULL;
1779 int callchain_size = 0;
1767 1780
1768 header.type = PERF_EVENT_OVERFLOW; 1781 header.type = PERF_EVENT_OVERFLOW;
1769 header.size = sizeof(header); 1782 header.size = sizeof(header);
@@ -1781,6 +1794,17 @@ static void perf_output_simple(struct perf_counter *counter,
1781 header.size += sizeof(tid_entry); 1794 header.size += sizeof(tid_entry);
1782 } 1795 }
1783 1796
1797 if (counter->hw_event.callchain) {
1798 callchain = perf_callchain(regs);
1799
1800 if (callchain) {
1801 callchain_size = (1 + callchain->nr) * sizeof(u64);
1802
1803 header.type |= __PERF_EVENT_CALLCHAIN;
1804 header.size += callchain_size;
1805 }
1806 }
1807
1784 ret = perf_output_begin(&handle, counter, header.size, nmi); 1808 ret = perf_output_begin(&handle, counter, header.size, nmi);
1785 if (ret) 1809 if (ret)
1786 return; 1810 return;
@@ -1791,6 +1815,9 @@ static void perf_output_simple(struct perf_counter *counter,
1791 if (counter->hw_event.include_tid) 1815 if (counter->hw_event.include_tid)
1792 perf_output_put(&handle, tid_entry); 1816 perf_output_put(&handle, tid_entry);
1793 1817
1818 if (callchain)
1819 perf_output_copy(&handle, callchain, callchain_size);
1820
1794 perf_output_end(&handle); 1821 perf_output_end(&handle);
1795} 1822}
1796 1823