diff options
62 files changed, 1645 insertions, 805 deletions
diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h index 86f9301903c8..5f2fc4441b11 100644 --- a/arch/x86/include/asm/nmi.h +++ b/arch/x86/include/asm/nmi.h | |||
@@ -1,6 +1,7 @@ | |||
1 | #ifndef _ASM_X86_NMI_H | 1 | #ifndef _ASM_X86_NMI_H |
2 | #define _ASM_X86_NMI_H | 2 | #define _ASM_X86_NMI_H |
3 | 3 | ||
4 | #include <linux/irq_work.h> | ||
4 | #include <linux/pm.h> | 5 | #include <linux/pm.h> |
5 | #include <asm/irq.h> | 6 | #include <asm/irq.h> |
6 | #include <asm/io.h> | 7 | #include <asm/io.h> |
@@ -38,6 +39,8 @@ typedef int (*nmi_handler_t)(unsigned int, struct pt_regs *); | |||
38 | struct nmiaction { | 39 | struct nmiaction { |
39 | struct list_head list; | 40 | struct list_head list; |
40 | nmi_handler_t handler; | 41 | nmi_handler_t handler; |
42 | u64 max_duration; | ||
43 | struct irq_work irq_work; | ||
41 | unsigned long flags; | 44 | unsigned long flags; |
42 | const char *name; | 45 | const char *name; |
43 | }; | 46 | }; |
diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c index c88f7f4b03ee..b262c6124cf3 100644 --- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c +++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c | |||
@@ -66,6 +66,47 @@ DEFINE_UNCORE_FORMAT_ATTR(mask_vnw, mask_vnw, "config2:3-4"); | |||
66 | DEFINE_UNCORE_FORMAT_ATTR(mask0, mask0, "config2:0-31"); | 66 | DEFINE_UNCORE_FORMAT_ATTR(mask0, mask0, "config2:0-31"); |
67 | DEFINE_UNCORE_FORMAT_ATTR(mask1, mask1, "config2:32-63"); | 67 | DEFINE_UNCORE_FORMAT_ATTR(mask1, mask1, "config2:32-63"); |
68 | 68 | ||
69 | static void uncore_pmu_start_hrtimer(struct intel_uncore_box *box); | ||
70 | static void uncore_pmu_cancel_hrtimer(struct intel_uncore_box *box); | ||
71 | static void uncore_perf_event_update(struct intel_uncore_box *box, struct perf_event *event); | ||
72 | static void uncore_pmu_event_read(struct perf_event *event); | ||
73 | |||
74 | static struct intel_uncore_pmu *uncore_event_to_pmu(struct perf_event *event) | ||
75 | { | ||
76 | return container_of(event->pmu, struct intel_uncore_pmu, pmu); | ||
77 | } | ||
78 | |||
79 | static struct intel_uncore_box * | ||
80 | uncore_pmu_to_box(struct intel_uncore_pmu *pmu, int cpu) | ||
81 | { | ||
82 | struct intel_uncore_box *box; | ||
83 | |||
84 | box = *per_cpu_ptr(pmu->box, cpu); | ||
85 | if (box) | ||
86 | return box; | ||
87 | |||
88 | raw_spin_lock(&uncore_box_lock); | ||
89 | list_for_each_entry(box, &pmu->box_list, list) { | ||
90 | if (box->phys_id == topology_physical_package_id(cpu)) { | ||
91 | atomic_inc(&box->refcnt); | ||
92 | *per_cpu_ptr(pmu->box, cpu) = box; | ||
93 | break; | ||
94 | } | ||
95 | } | ||
96 | raw_spin_unlock(&uncore_box_lock); | ||
97 | |||
98 | return *per_cpu_ptr(pmu->box, cpu); | ||
99 | } | ||
100 | |||
101 | static struct intel_uncore_box *uncore_event_to_box(struct perf_event *event) | ||
102 | { | ||
103 | /* | ||
104 | * perf core schedules event on the basis of cpu, uncore events are | ||
105 | * collected by one of the cpus inside a physical package. | ||
106 | */ | ||
107 | return uncore_pmu_to_box(uncore_event_to_pmu(event), smp_processor_id()); | ||
108 | } | ||
109 | |||
69 | static u64 uncore_msr_read_counter(struct intel_uncore_box *box, struct perf_event *event) | 110 | static u64 uncore_msr_read_counter(struct intel_uncore_box *box, struct perf_event *event) |
70 | { | 111 | { |
71 | u64 count; | 112 | u64 count; |
@@ -1639,6 +1680,345 @@ static struct intel_uncore_type *snb_msr_uncores[] = { | |||
1639 | &snb_uncore_cbox, | 1680 | &snb_uncore_cbox, |
1640 | NULL, | 1681 | NULL, |
1641 | }; | 1682 | }; |
1683 | |||
1684 | enum { | ||
1685 | SNB_PCI_UNCORE_IMC, | ||
1686 | }; | ||
1687 | |||
1688 | static struct uncore_event_desc snb_uncore_imc_events[] = { | ||
1689 | INTEL_UNCORE_EVENT_DESC(data_reads, "event=0x01"), | ||
1690 | INTEL_UNCORE_EVENT_DESC(data_reads.scale, "6.103515625e-5"), | ||
1691 | INTEL_UNCORE_EVENT_DESC(data_reads.unit, "MiB"), | ||
1692 | |||
1693 | INTEL_UNCORE_EVENT_DESC(data_writes, "event=0x02"), | ||
1694 | INTEL_UNCORE_EVENT_DESC(data_writes.scale, "6.103515625e-5"), | ||
1695 | INTEL_UNCORE_EVENT_DESC(data_writes.unit, "MiB"), | ||
1696 | |||
1697 | { /* end: all zeroes */ }, | ||
1698 | }; | ||
1699 | |||
1700 | #define SNB_UNCORE_PCI_IMC_EVENT_MASK 0xff | ||
1701 | #define SNB_UNCORE_PCI_IMC_BAR_OFFSET 0x48 | ||
1702 | |||
1703 | /* page size multiple covering all config regs */ | ||
1704 | #define SNB_UNCORE_PCI_IMC_MAP_SIZE 0x6000 | ||
1705 | |||
1706 | #define SNB_UNCORE_PCI_IMC_DATA_READS 0x1 | ||
1707 | #define SNB_UNCORE_PCI_IMC_DATA_READS_BASE 0x5050 | ||
1708 | #define SNB_UNCORE_PCI_IMC_DATA_WRITES 0x2 | ||
1709 | #define SNB_UNCORE_PCI_IMC_DATA_WRITES_BASE 0x5054 | ||
1710 | #define SNB_UNCORE_PCI_IMC_CTR_BASE SNB_UNCORE_PCI_IMC_DATA_READS_BASE | ||
1711 | |||
1712 | static struct attribute *snb_uncore_imc_formats_attr[] = { | ||
1713 | &format_attr_event.attr, | ||
1714 | NULL, | ||
1715 | }; | ||
1716 | |||
1717 | static struct attribute_group snb_uncore_imc_format_group = { | ||
1718 | .name = "format", | ||
1719 | .attrs = snb_uncore_imc_formats_attr, | ||
1720 | }; | ||
1721 | |||
1722 | static void snb_uncore_imc_init_box(struct intel_uncore_box *box) | ||
1723 | { | ||
1724 | struct pci_dev *pdev = box->pci_dev; | ||
1725 | u32 addr_lo, addr_hi; | ||
1726 | resource_size_t addr; | ||
1727 | |||
1728 | pci_read_config_dword(pdev, SNB_UNCORE_PCI_IMC_BAR_OFFSET, &addr_lo); | ||
1729 | addr = addr_lo; | ||
1730 | |||
1731 | #ifdef CONFIG_PHYS_ADDR_T_64BIT | ||
1732 | pci_read_config_dword(pdev, SNB_UNCORE_PCI_IMC_BAR_OFFSET+4, &addr_hi); | ||
1733 | addr = ((resource_size_t)addr_hi << 32) | addr_lo; | ||
1734 | #endif | ||
1735 | |||
1736 | addr &= ~(PAGE_SIZE - 1); | ||
1737 | |||
1738 | box->io_addr = ioremap(addr, SNB_UNCORE_PCI_IMC_MAP_SIZE); | ||
1739 | box->hrtimer_duration = UNCORE_SNB_IMC_HRTIMER_INTERVAL; | ||
1740 | } | ||
1741 | |||
1742 | static void snb_uncore_imc_enable_box(struct intel_uncore_box *box) | ||
1743 | {} | ||
1744 | |||
1745 | static void snb_uncore_imc_disable_box(struct intel_uncore_box *box) | ||
1746 | {} | ||
1747 | |||
1748 | static void snb_uncore_imc_enable_event(struct intel_uncore_box *box, struct perf_event *event) | ||
1749 | {} | ||
1750 | |||
1751 | static void snb_uncore_imc_disable_event(struct intel_uncore_box *box, struct perf_event *event) | ||
1752 | {} | ||
1753 | |||
1754 | static u64 snb_uncore_imc_read_counter(struct intel_uncore_box *box, struct perf_event *event) | ||
1755 | { | ||
1756 | struct hw_perf_event *hwc = &event->hw; | ||
1757 | |||
1758 | return (u64)*(unsigned int *)(box->io_addr + hwc->event_base); | ||
1759 | } | ||
1760 | |||
1761 | /* | ||
1762 | * custom event_init() function because we define our own fixed, free | ||
1763 | * running counters, so we do not want to conflict with generic uncore | ||
1764 | * logic. Also simplifies processing | ||
1765 | */ | ||
1766 | static int snb_uncore_imc_event_init(struct perf_event *event) | ||
1767 | { | ||
1768 | struct intel_uncore_pmu *pmu; | ||
1769 | struct intel_uncore_box *box; | ||
1770 | struct hw_perf_event *hwc = &event->hw; | ||
1771 | u64 cfg = event->attr.config & SNB_UNCORE_PCI_IMC_EVENT_MASK; | ||
1772 | int idx, base; | ||
1773 | |||
1774 | if (event->attr.type != event->pmu->type) | ||
1775 | return -ENOENT; | ||
1776 | |||
1777 | pmu = uncore_event_to_pmu(event); | ||
1778 | /* no device found for this pmu */ | ||
1779 | if (pmu->func_id < 0) | ||
1780 | return -ENOENT; | ||
1781 | |||
1782 | /* Sampling not supported yet */ | ||
1783 | if (hwc->sample_period) | ||
1784 | return -EINVAL; | ||
1785 | |||
1786 | /* unsupported modes and filters */ | ||
1787 | if (event->attr.exclude_user || | ||
1788 | event->attr.exclude_kernel || | ||
1789 | event->attr.exclude_hv || | ||
1790 | event->attr.exclude_idle || | ||
1791 | event->attr.exclude_host || | ||
1792 | event->attr.exclude_guest || | ||
1793 | event->attr.sample_period) /* no sampling */ | ||
1794 | return -EINVAL; | ||
1795 | |||
1796 | /* | ||
1797 | * Place all uncore events for a particular physical package | ||
1798 | * onto a single cpu | ||
1799 | */ | ||
1800 | if (event->cpu < 0) | ||
1801 | return -EINVAL; | ||
1802 | |||
1803 | /* check only supported bits are set */ | ||
1804 | if (event->attr.config & ~SNB_UNCORE_PCI_IMC_EVENT_MASK) | ||
1805 | return -EINVAL; | ||
1806 | |||
1807 | box = uncore_pmu_to_box(pmu, event->cpu); | ||
1808 | if (!box || box->cpu < 0) | ||
1809 | return -EINVAL; | ||
1810 | |||
1811 | event->cpu = box->cpu; | ||
1812 | |||
1813 | event->hw.idx = -1; | ||
1814 | event->hw.last_tag = ~0ULL; | ||
1815 | event->hw.extra_reg.idx = EXTRA_REG_NONE; | ||
1816 | event->hw.branch_reg.idx = EXTRA_REG_NONE; | ||
1817 | /* | ||
1818 | * check event is known (whitelist, determines counter) | ||
1819 | */ | ||
1820 | switch (cfg) { | ||
1821 | case SNB_UNCORE_PCI_IMC_DATA_READS: | ||
1822 | base = SNB_UNCORE_PCI_IMC_DATA_READS_BASE; | ||
1823 | idx = UNCORE_PMC_IDX_FIXED; | ||
1824 | break; | ||
1825 | case SNB_UNCORE_PCI_IMC_DATA_WRITES: | ||
1826 | base = SNB_UNCORE_PCI_IMC_DATA_WRITES_BASE; | ||
1827 | idx = UNCORE_PMC_IDX_FIXED + 1; | ||
1828 | break; | ||
1829 | default: | ||
1830 | return -EINVAL; | ||
1831 | } | ||
1832 | |||
1833 | /* must be done before validate_group */ | ||
1834 | event->hw.event_base = base; | ||
1835 | event->hw.config = cfg; | ||
1836 | event->hw.idx = idx; | ||
1837 | |||
1838 | /* no group validation needed, we have free running counters */ | ||
1839 | |||
1840 | return 0; | ||
1841 | } | ||
1842 | |||
1843 | static int snb_uncore_imc_hw_config(struct intel_uncore_box *box, struct perf_event *event) | ||
1844 | { | ||
1845 | return 0; | ||
1846 | } | ||
1847 | |||
1848 | static void snb_uncore_imc_event_start(struct perf_event *event, int flags) | ||
1849 | { | ||
1850 | struct intel_uncore_box *box = uncore_event_to_box(event); | ||
1851 | u64 count; | ||
1852 | |||
1853 | if (WARN_ON_ONCE(!(event->hw.state & PERF_HES_STOPPED))) | ||
1854 | return; | ||
1855 | |||
1856 | event->hw.state = 0; | ||
1857 | box->n_active++; | ||
1858 | |||
1859 | list_add_tail(&event->active_entry, &box->active_list); | ||
1860 | |||
1861 | count = snb_uncore_imc_read_counter(box, event); | ||
1862 | local64_set(&event->hw.prev_count, count); | ||
1863 | |||
1864 | if (box->n_active == 1) | ||
1865 | uncore_pmu_start_hrtimer(box); | ||
1866 | } | ||
1867 | |||
1868 | static void snb_uncore_imc_event_stop(struct perf_event *event, int flags) | ||
1869 | { | ||
1870 | struct intel_uncore_box *box = uncore_event_to_box(event); | ||
1871 | struct hw_perf_event *hwc = &event->hw; | ||
1872 | |||
1873 | if (!(hwc->state & PERF_HES_STOPPED)) { | ||
1874 | box->n_active--; | ||
1875 | |||
1876 | WARN_ON_ONCE(hwc->state & PERF_HES_STOPPED); | ||
1877 | hwc->state |= PERF_HES_STOPPED; | ||
1878 | |||
1879 | list_del(&event->active_entry); | ||
1880 | |||
1881 | if (box->n_active == 0) | ||
1882 | uncore_pmu_cancel_hrtimer(box); | ||
1883 | } | ||
1884 | |||
1885 | if ((flags & PERF_EF_UPDATE) && !(hwc->state & PERF_HES_UPTODATE)) { | ||
1886 | /* | ||
1887 | * Drain the remaining delta count out of a event | ||
1888 | * that we are disabling: | ||
1889 | */ | ||
1890 | uncore_perf_event_update(box, event); | ||
1891 | hwc->state |= PERF_HES_UPTODATE; | ||
1892 | } | ||
1893 | } | ||
1894 | |||
1895 | static int snb_uncore_imc_event_add(struct perf_event *event, int flags) | ||
1896 | { | ||
1897 | struct intel_uncore_box *box = uncore_event_to_box(event); | ||
1898 | struct hw_perf_event *hwc = &event->hw; | ||
1899 | |||
1900 | if (!box) | ||
1901 | return -ENODEV; | ||
1902 | |||
1903 | hwc->state = PERF_HES_UPTODATE | PERF_HES_STOPPED; | ||
1904 | if (!(flags & PERF_EF_START)) | ||
1905 | hwc->state |= PERF_HES_ARCH; | ||
1906 | |||
1907 | snb_uncore_imc_event_start(event, 0); | ||
1908 | |||
1909 | box->n_events++; | ||
1910 | |||
1911 | return 0; | ||
1912 | } | ||
1913 | |||
1914 | static void snb_uncore_imc_event_del(struct perf_event *event, int flags) | ||
1915 | { | ||
1916 | struct intel_uncore_box *box = uncore_event_to_box(event); | ||
1917 | int i; | ||
1918 | |||
1919 | snb_uncore_imc_event_stop(event, PERF_EF_UPDATE); | ||
1920 | |||
1921 | for (i = 0; i < box->n_events; i++) { | ||
1922 | if (event == box->event_list[i]) { | ||
1923 | --box->n_events; | ||
1924 | break; | ||
1925 | } | ||
1926 | } | ||
1927 | } | ||
1928 | |||
1929 | static int snb_pci2phy_map_init(int devid) | ||
1930 | { | ||
1931 | struct pci_dev *dev = NULL; | ||
1932 | int bus; | ||
1933 | |||
1934 | dev = pci_get_device(PCI_VENDOR_ID_INTEL, devid, dev); | ||
1935 | if (!dev) | ||
1936 | return -ENOTTY; | ||
1937 | |||
1938 | bus = dev->bus->number; | ||
1939 | |||
1940 | pcibus_to_physid[bus] = 0; | ||
1941 | |||
1942 | pci_dev_put(dev); | ||
1943 | |||
1944 | return 0; | ||
1945 | } | ||
1946 | |||
1947 | static struct pmu snb_uncore_imc_pmu = { | ||
1948 | .task_ctx_nr = perf_invalid_context, | ||
1949 | .event_init = snb_uncore_imc_event_init, | ||
1950 | .add = snb_uncore_imc_event_add, | ||
1951 | .del = snb_uncore_imc_event_del, | ||
1952 | .start = snb_uncore_imc_event_start, | ||
1953 | .stop = snb_uncore_imc_event_stop, | ||
1954 | .read = uncore_pmu_event_read, | ||
1955 | }; | ||
1956 | |||
1957 | static struct intel_uncore_ops snb_uncore_imc_ops = { | ||
1958 | .init_box = snb_uncore_imc_init_box, | ||
1959 | .enable_box = snb_uncore_imc_enable_box, | ||
1960 | .disable_box = snb_uncore_imc_disable_box, | ||
1961 | .disable_event = snb_uncore_imc_disable_event, | ||
1962 | .enable_event = snb_uncore_imc_enable_event, | ||
1963 | .hw_config = snb_uncore_imc_hw_config, | ||
1964 | .read_counter = snb_uncore_imc_read_counter, | ||
1965 | }; | ||
1966 | |||
1967 | static struct intel_uncore_type snb_uncore_imc = { | ||
1968 | .name = "imc", | ||
1969 | .num_counters = 2, | ||
1970 | .num_boxes = 1, | ||
1971 | .fixed_ctr_bits = 32, | ||
1972 | .fixed_ctr = SNB_UNCORE_PCI_IMC_CTR_BASE, | ||
1973 | .event_descs = snb_uncore_imc_events, | ||
1974 | .format_group = &snb_uncore_imc_format_group, | ||
1975 | .perf_ctr = SNB_UNCORE_PCI_IMC_DATA_READS_BASE, | ||
1976 | .event_mask = SNB_UNCORE_PCI_IMC_EVENT_MASK, | ||
1977 | .ops = &snb_uncore_imc_ops, | ||
1978 | .pmu = &snb_uncore_imc_pmu, | ||
1979 | }; | ||
1980 | |||
1981 | static struct intel_uncore_type *snb_pci_uncores[] = { | ||
1982 | [SNB_PCI_UNCORE_IMC] = &snb_uncore_imc, | ||
1983 | NULL, | ||
1984 | }; | ||
1985 | |||
1986 | static DEFINE_PCI_DEVICE_TABLE(snb_uncore_pci_ids) = { | ||
1987 | { /* IMC */ | ||
1988 | PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SNB_IMC), | ||
1989 | .driver_data = UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC, 0), | ||
1990 | }, | ||
1991 | }; | ||
1992 | |||
1993 | static DEFINE_PCI_DEVICE_TABLE(ivb_uncore_pci_ids) = { | ||
1994 | { /* IMC */ | ||
1995 | PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IVB_IMC), | ||
1996 | .driver_data = UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC, 0), | ||
1997 | }, | ||
1998 | }; | ||
1999 | |||
2000 | static DEFINE_PCI_DEVICE_TABLE(hsw_uncore_pci_ids) = { | ||
2001 | { /* IMC */ | ||
2002 | PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_HSW_IMC), | ||
2003 | .driver_data = UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC, 0), | ||
2004 | }, | ||
2005 | }; | ||
2006 | |||
2007 | static struct pci_driver snb_uncore_pci_driver = { | ||
2008 | .name = "snb_uncore", | ||
2009 | .id_table = snb_uncore_pci_ids, | ||
2010 | }; | ||
2011 | |||
2012 | static struct pci_driver ivb_uncore_pci_driver = { | ||
2013 | .name = "ivb_uncore", | ||
2014 | .id_table = ivb_uncore_pci_ids, | ||
2015 | }; | ||
2016 | |||
2017 | static struct pci_driver hsw_uncore_pci_driver = { | ||
2018 | .name = "hsw_uncore", | ||
2019 | .id_table = hsw_uncore_pci_ids, | ||
2020 | }; | ||
2021 | |||
1642 | /* end of Sandy Bridge uncore support */ | 2022 | /* end of Sandy Bridge uncore support */ |
1643 | 2023 | ||
1644 | /* Nehalem uncore support */ | 2024 | /* Nehalem uncore support */ |
@@ -2789,6 +3169,7 @@ again: | |||
2789 | static enum hrtimer_restart uncore_pmu_hrtimer(struct hrtimer *hrtimer) | 3169 | static enum hrtimer_restart uncore_pmu_hrtimer(struct hrtimer *hrtimer) |
2790 | { | 3170 | { |
2791 | struct intel_uncore_box *box; | 3171 | struct intel_uncore_box *box; |
3172 | struct perf_event *event; | ||
2792 | unsigned long flags; | 3173 | unsigned long flags; |
2793 | int bit; | 3174 | int bit; |
2794 | 3175 | ||
@@ -2801,19 +3182,27 @@ static enum hrtimer_restart uncore_pmu_hrtimer(struct hrtimer *hrtimer) | |||
2801 | */ | 3182 | */ |
2802 | local_irq_save(flags); | 3183 | local_irq_save(flags); |
2803 | 3184 | ||
3185 | /* | ||
3186 | * handle boxes with an active event list as opposed to active | ||
3187 | * counters | ||
3188 | */ | ||
3189 | list_for_each_entry(event, &box->active_list, active_entry) { | ||
3190 | uncore_perf_event_update(box, event); | ||
3191 | } | ||
3192 | |||
2804 | for_each_set_bit(bit, box->active_mask, UNCORE_PMC_IDX_MAX) | 3193 | for_each_set_bit(bit, box->active_mask, UNCORE_PMC_IDX_MAX) |
2805 | uncore_perf_event_update(box, box->events[bit]); | 3194 | uncore_perf_event_update(box, box->events[bit]); |
2806 | 3195 | ||
2807 | local_irq_restore(flags); | 3196 | local_irq_restore(flags); |
2808 | 3197 | ||
2809 | hrtimer_forward_now(hrtimer, ns_to_ktime(UNCORE_PMU_HRTIMER_INTERVAL)); | 3198 | hrtimer_forward_now(hrtimer, ns_to_ktime(box->hrtimer_duration)); |
2810 | return HRTIMER_RESTART; | 3199 | return HRTIMER_RESTART; |
2811 | } | 3200 | } |
2812 | 3201 | ||
2813 | static void uncore_pmu_start_hrtimer(struct intel_uncore_box *box) | 3202 | static void uncore_pmu_start_hrtimer(struct intel_uncore_box *box) |
2814 | { | 3203 | { |
2815 | __hrtimer_start_range_ns(&box->hrtimer, | 3204 | __hrtimer_start_range_ns(&box->hrtimer, |
2816 | ns_to_ktime(UNCORE_PMU_HRTIMER_INTERVAL), 0, | 3205 | ns_to_ktime(box->hrtimer_duration), 0, |
2817 | HRTIMER_MODE_REL_PINNED, 0); | 3206 | HRTIMER_MODE_REL_PINNED, 0); |
2818 | } | 3207 | } |
2819 | 3208 | ||
@@ -2847,43 +3236,12 @@ static struct intel_uncore_box *uncore_alloc_box(struct intel_uncore_type *type, | |||
2847 | box->cpu = -1; | 3236 | box->cpu = -1; |
2848 | box->phys_id = -1; | 3237 | box->phys_id = -1; |
2849 | 3238 | ||
2850 | return box; | 3239 | /* set default hrtimer timeout */ |
2851 | } | 3240 | box->hrtimer_duration = UNCORE_PMU_HRTIMER_INTERVAL; |
2852 | 3241 | ||
2853 | static struct intel_uncore_box * | 3242 | INIT_LIST_HEAD(&box->active_list); |
2854 | uncore_pmu_to_box(struct intel_uncore_pmu *pmu, int cpu) | ||
2855 | { | ||
2856 | struct intel_uncore_box *box; | ||
2857 | 3243 | ||
2858 | box = *per_cpu_ptr(pmu->box, cpu); | 3244 | return box; |
2859 | if (box) | ||
2860 | return box; | ||
2861 | |||
2862 | raw_spin_lock(&uncore_box_lock); | ||
2863 | list_for_each_entry(box, &pmu->box_list, list) { | ||
2864 | if (box->phys_id == topology_physical_package_id(cpu)) { | ||
2865 | atomic_inc(&box->refcnt); | ||
2866 | *per_cpu_ptr(pmu->box, cpu) = box; | ||
2867 | break; | ||
2868 | } | ||
2869 | } | ||
2870 | raw_spin_unlock(&uncore_box_lock); | ||
2871 | |||
2872 | return *per_cpu_ptr(pmu->box, cpu); | ||
2873 | } | ||
2874 | |||
2875 | static struct intel_uncore_pmu *uncore_event_to_pmu(struct perf_event *event) | ||
2876 | { | ||
2877 | return container_of(event->pmu, struct intel_uncore_pmu, pmu); | ||
2878 | } | ||
2879 | |||
2880 | static struct intel_uncore_box *uncore_event_to_box(struct perf_event *event) | ||
2881 | { | ||
2882 | /* | ||
2883 | * perf core schedules event on the basis of cpu, uncore events are | ||
2884 | * collected by one of the cpus inside a physical package. | ||
2885 | */ | ||
2886 | return uncore_pmu_to_box(uncore_event_to_pmu(event), smp_processor_id()); | ||
2887 | } | 3245 | } |
2888 | 3246 | ||
2889 | static int | 3247 | static int |
@@ -3279,16 +3637,21 @@ static int __init uncore_pmu_register(struct intel_uncore_pmu *pmu) | |||
3279 | { | 3637 | { |
3280 | int ret; | 3638 | int ret; |
3281 | 3639 | ||
3282 | pmu->pmu = (struct pmu) { | 3640 | if (!pmu->type->pmu) { |
3283 | .attr_groups = pmu->type->attr_groups, | 3641 | pmu->pmu = (struct pmu) { |
3284 | .task_ctx_nr = perf_invalid_context, | 3642 | .attr_groups = pmu->type->attr_groups, |
3285 | .event_init = uncore_pmu_event_init, | 3643 | .task_ctx_nr = perf_invalid_context, |
3286 | .add = uncore_pmu_event_add, | 3644 | .event_init = uncore_pmu_event_init, |
3287 | .del = uncore_pmu_event_del, | 3645 | .add = uncore_pmu_event_add, |
3288 | .start = uncore_pmu_event_start, | 3646 | .del = uncore_pmu_event_del, |
3289 | .stop = uncore_pmu_event_stop, | 3647 | .start = uncore_pmu_event_start, |
3290 | .read = uncore_pmu_event_read, | 3648 | .stop = uncore_pmu_event_stop, |
3291 | }; | 3649 | .read = uncore_pmu_event_read, |
3650 | }; | ||
3651 | } else { | ||
3652 | pmu->pmu = *pmu->type->pmu; | ||
3653 | pmu->pmu.attr_groups = pmu->type->attr_groups; | ||
3654 | } | ||
3292 | 3655 | ||
3293 | if (pmu->type->num_boxes == 1) { | 3656 | if (pmu->type->num_boxes == 1) { |
3294 | if (strlen(pmu->type->name) > 0) | 3657 | if (strlen(pmu->type->name) > 0) |
@@ -3501,6 +3864,28 @@ static int __init uncore_pci_init(void) | |||
3501 | pci_uncores = ivt_pci_uncores; | 3864 | pci_uncores = ivt_pci_uncores; |
3502 | uncore_pci_driver = &ivt_uncore_pci_driver; | 3865 | uncore_pci_driver = &ivt_uncore_pci_driver; |
3503 | break; | 3866 | break; |
3867 | case 42: /* Sandy Bridge */ | ||
3868 | ret = snb_pci2phy_map_init(PCI_DEVICE_ID_INTEL_SNB_IMC); | ||
3869 | if (ret) | ||
3870 | return ret; | ||
3871 | pci_uncores = snb_pci_uncores; | ||
3872 | uncore_pci_driver = &snb_uncore_pci_driver; | ||
3873 | break; | ||
3874 | case 58: /* Ivy Bridge */ | ||
3875 | ret = snb_pci2phy_map_init(PCI_DEVICE_ID_INTEL_IVB_IMC); | ||
3876 | if (ret) | ||
3877 | return ret; | ||
3878 | pci_uncores = snb_pci_uncores; | ||
3879 | uncore_pci_driver = &ivb_uncore_pci_driver; | ||
3880 | break; | ||
3881 | case 60: /* Haswell */ | ||
3882 | case 69: /* Haswell Celeron */ | ||
3883 | ret = snb_pci2phy_map_init(PCI_DEVICE_ID_INTEL_HSW_IMC); | ||
3884 | if (ret) | ||
3885 | return ret; | ||
3886 | pci_uncores = snb_pci_uncores; | ||
3887 | uncore_pci_driver = &hsw_uncore_pci_driver; | ||
3888 | break; | ||
3504 | default: | 3889 | default: |
3505 | return 0; | 3890 | return 0; |
3506 | } | 3891 | } |
@@ -3772,7 +4157,7 @@ static void __init uncore_cpu_setup(void *dummy) | |||
3772 | 4157 | ||
3773 | static int __init uncore_cpu_init(void) | 4158 | static int __init uncore_cpu_init(void) |
3774 | { | 4159 | { |
3775 | int ret, cpu, max_cores; | 4160 | int ret, max_cores; |
3776 | 4161 | ||
3777 | max_cores = boot_cpu_data.x86_max_cores; | 4162 | max_cores = boot_cpu_data.x86_max_cores; |
3778 | switch (boot_cpu_data.x86_model) { | 4163 | switch (boot_cpu_data.x86_model) { |
@@ -3816,29 +4201,6 @@ static int __init uncore_cpu_init(void) | |||
3816 | if (ret) | 4201 | if (ret) |
3817 | return ret; | 4202 | return ret; |
3818 | 4203 | ||
3819 | get_online_cpus(); | ||
3820 | |||
3821 | for_each_online_cpu(cpu) { | ||
3822 | int i, phys_id = topology_physical_package_id(cpu); | ||
3823 | |||
3824 | for_each_cpu(i, &uncore_cpu_mask) { | ||
3825 | if (phys_id == topology_physical_package_id(i)) { | ||
3826 | phys_id = -1; | ||
3827 | break; | ||
3828 | } | ||
3829 | } | ||
3830 | if (phys_id < 0) | ||
3831 | continue; | ||
3832 | |||
3833 | uncore_cpu_prepare(cpu, phys_id); | ||
3834 | uncore_event_init_cpu(cpu); | ||
3835 | } | ||
3836 | on_each_cpu(uncore_cpu_setup, NULL, 1); | ||
3837 | |||
3838 | register_cpu_notifier(&uncore_cpu_nb); | ||
3839 | |||
3840 | put_online_cpus(); | ||
3841 | |||
3842 | return 0; | 4204 | return 0; |
3843 | } | 4205 | } |
3844 | 4206 | ||
@@ -3867,6 +4229,41 @@ static int __init uncore_pmus_register(void) | |||
3867 | return 0; | 4229 | return 0; |
3868 | } | 4230 | } |
3869 | 4231 | ||
4232 | static void uncore_cpumask_init(void) | ||
4233 | { | ||
4234 | int cpu; | ||
4235 | |||
4236 | /* | ||
4237 | * ony invoke once from msr or pci init code | ||
4238 | */ | ||
4239 | if (!cpumask_empty(&uncore_cpu_mask)) | ||
4240 | return; | ||
4241 | |||
4242 | get_online_cpus(); | ||
4243 | |||
4244 | for_each_online_cpu(cpu) { | ||
4245 | int i, phys_id = topology_physical_package_id(cpu); | ||
4246 | |||
4247 | for_each_cpu(i, &uncore_cpu_mask) { | ||
4248 | if (phys_id == topology_physical_package_id(i)) { | ||
4249 | phys_id = -1; | ||
4250 | break; | ||
4251 | } | ||
4252 | } | ||
4253 | if (phys_id < 0) | ||
4254 | continue; | ||
4255 | |||
4256 | uncore_cpu_prepare(cpu, phys_id); | ||
4257 | uncore_event_init_cpu(cpu); | ||
4258 | } | ||
4259 | on_each_cpu(uncore_cpu_setup, NULL, 1); | ||
4260 | |||
4261 | register_cpu_notifier(&uncore_cpu_nb); | ||
4262 | |||
4263 | put_online_cpus(); | ||
4264 | } | ||
4265 | |||
4266 | |||
3870 | static int __init intel_uncore_init(void) | 4267 | static int __init intel_uncore_init(void) |
3871 | { | 4268 | { |
3872 | int ret; | 4269 | int ret; |
@@ -3885,6 +4282,7 @@ static int __init intel_uncore_init(void) | |||
3885 | uncore_pci_exit(); | 4282 | uncore_pci_exit(); |
3886 | goto fail; | 4283 | goto fail; |
3887 | } | 4284 | } |
4285 | uncore_cpumask_init(); | ||
3888 | 4286 | ||
3889 | uncore_pmus_register(); | 4287 | uncore_pmus_register(); |
3890 | return 0; | 4288 | return 0; |
diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h index a80ab71a883d..90236f0c94a9 100644 --- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h +++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h | |||
@@ -6,6 +6,7 @@ | |||
6 | 6 | ||
7 | #define UNCORE_PMU_NAME_LEN 32 | 7 | #define UNCORE_PMU_NAME_LEN 32 |
8 | #define UNCORE_PMU_HRTIMER_INTERVAL (60LL * NSEC_PER_SEC) | 8 | #define UNCORE_PMU_HRTIMER_INTERVAL (60LL * NSEC_PER_SEC) |
9 | #define UNCORE_SNB_IMC_HRTIMER_INTERVAL (5ULL * NSEC_PER_SEC) | ||
9 | 10 | ||
10 | #define UNCORE_FIXED_EVENT 0xff | 11 | #define UNCORE_FIXED_EVENT 0xff |
11 | #define UNCORE_PMC_IDX_MAX_GENERIC 8 | 12 | #define UNCORE_PMC_IDX_MAX_GENERIC 8 |
@@ -440,6 +441,7 @@ struct intel_uncore_type { | |||
440 | struct intel_uncore_ops *ops; | 441 | struct intel_uncore_ops *ops; |
441 | struct uncore_event_desc *event_descs; | 442 | struct uncore_event_desc *event_descs; |
442 | const struct attribute_group *attr_groups[4]; | 443 | const struct attribute_group *attr_groups[4]; |
444 | struct pmu *pmu; /* for custom pmu ops */ | ||
443 | }; | 445 | }; |
444 | 446 | ||
445 | #define pmu_group attr_groups[0] | 447 | #define pmu_group attr_groups[0] |
@@ -488,8 +490,11 @@ struct intel_uncore_box { | |||
488 | u64 tags[UNCORE_PMC_IDX_MAX]; | 490 | u64 tags[UNCORE_PMC_IDX_MAX]; |
489 | struct pci_dev *pci_dev; | 491 | struct pci_dev *pci_dev; |
490 | struct intel_uncore_pmu *pmu; | 492 | struct intel_uncore_pmu *pmu; |
493 | u64 hrtimer_duration; /* hrtimer timeout for this box */ | ||
491 | struct hrtimer hrtimer; | 494 | struct hrtimer hrtimer; |
492 | struct list_head list; | 495 | struct list_head list; |
496 | struct list_head active_list; | ||
497 | void *io_addr; | ||
493 | struct intel_uncore_extra_reg shared_regs[0]; | 498 | struct intel_uncore_extra_reg shared_regs[0]; |
494 | }; | 499 | }; |
495 | 500 | ||
diff --git a/arch/x86/kernel/cpu/perf_event_p4.c b/arch/x86/kernel/cpu/perf_event_p4.c index 3486e6660357..5d466b7d8609 100644 --- a/arch/x86/kernel/cpu/perf_event_p4.c +++ b/arch/x86/kernel/cpu/perf_event_p4.c | |||
@@ -1257,7 +1257,24 @@ again: | |||
1257 | pass++; | 1257 | pass++; |
1258 | goto again; | 1258 | goto again; |
1259 | } | 1259 | } |
1260 | 1260 | /* | |
1261 | * Perf does test runs to see if a whole group can be assigned | ||
1262 | * together succesfully. There can be multiple rounds of this. | ||
1263 | * Unfortunately, p4_pmu_swap_config_ts touches the hwc->config | ||
1264 | * bits, such that the next round of group assignments will | ||
1265 | * cause the above p4_should_swap_ts to pass instead of fail. | ||
1266 | * This leads to counters exclusive to thread0 being used by | ||
1267 | * thread1. | ||
1268 | * | ||
1269 | * Solve this with a cheap hack, reset the idx back to -1 to | ||
1270 | * force a new lookup (p4_next_cntr) to get the right counter | ||
1271 | * for the right thread. | ||
1272 | * | ||
1273 | * This probably doesn't comply with the general spirit of how | ||
1274 | * perf wants to work, but P4 is special. :-( | ||
1275 | */ | ||
1276 | if (p4_should_swap_ts(hwc->config, cpu)) | ||
1277 | hwc->idx = -1; | ||
1261 | p4_pmu_swap_config_ts(hwc, cpu); | 1278 | p4_pmu_swap_config_ts(hwc, cpu); |
1262 | if (assign) | 1279 | if (assign) |
1263 | assign[i] = cntr_idx; | 1280 | assign[i] = cntr_idx; |
@@ -1322,6 +1339,7 @@ static __initconst const struct x86_pmu p4_pmu = { | |||
1322 | __init int p4_pmu_init(void) | 1339 | __init int p4_pmu_init(void) |
1323 | { | 1340 | { |
1324 | unsigned int low, high; | 1341 | unsigned int low, high; |
1342 | int i, reg; | ||
1325 | 1343 | ||
1326 | /* If we get stripped -- indexing fails */ | 1344 | /* If we get stripped -- indexing fails */ |
1327 | BUILD_BUG_ON(ARCH_P4_MAX_CCCR > INTEL_PMC_MAX_GENERIC); | 1345 | BUILD_BUG_ON(ARCH_P4_MAX_CCCR > INTEL_PMC_MAX_GENERIC); |
@@ -1340,5 +1358,19 @@ __init int p4_pmu_init(void) | |||
1340 | 1358 | ||
1341 | x86_pmu = p4_pmu; | 1359 | x86_pmu = p4_pmu; |
1342 | 1360 | ||
1361 | /* | ||
1362 | * Even though the counters are configured to interrupt a particular | ||
1363 | * logical processor when an overflow happens, testing has shown that | ||
1364 | * on kdump kernels (which uses a single cpu), thread1's counter | ||
1365 | * continues to run and will report an NMI on thread0. Due to the | ||
1366 | * overflow bug, this leads to a stream of unknown NMIs. | ||
1367 | * | ||
1368 | * Solve this by zero'ing out the registers to mimic a reset. | ||
1369 | */ | ||
1370 | for (i = 0; i < x86_pmu.num_counters; i++) { | ||
1371 | reg = x86_pmu_config_addr(i); | ||
1372 | wrmsrl_safe(reg, 0ULL); | ||
1373 | } | ||
1374 | |||
1343 | return 0; | 1375 | return 0; |
1344 | } | 1376 | } |
diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c index 6fcb49ce50a1..b4872b999a71 100644 --- a/arch/x86/kernel/nmi.c +++ b/arch/x86/kernel/nmi.c | |||
@@ -87,6 +87,7 @@ __setup("unknown_nmi_panic", setup_unknown_nmi_panic); | |||
87 | #define nmi_to_desc(type) (&nmi_desc[type]) | 87 | #define nmi_to_desc(type) (&nmi_desc[type]) |
88 | 88 | ||
89 | static u64 nmi_longest_ns = 1 * NSEC_PER_MSEC; | 89 | static u64 nmi_longest_ns = 1 * NSEC_PER_MSEC; |
90 | |||
90 | static int __init nmi_warning_debugfs(void) | 91 | static int __init nmi_warning_debugfs(void) |
91 | { | 92 | { |
92 | debugfs_create_u64("nmi_longest_ns", 0644, | 93 | debugfs_create_u64("nmi_longest_ns", 0644, |
@@ -95,6 +96,20 @@ static int __init nmi_warning_debugfs(void) | |||
95 | } | 96 | } |
96 | fs_initcall(nmi_warning_debugfs); | 97 | fs_initcall(nmi_warning_debugfs); |
97 | 98 | ||
99 | static void nmi_max_handler(struct irq_work *w) | ||
100 | { | ||
101 | struct nmiaction *a = container_of(w, struct nmiaction, irq_work); | ||
102 | int remainder_ns, decimal_msecs; | ||
103 | u64 whole_msecs = ACCESS_ONCE(a->max_duration); | ||
104 | |||
105 | remainder_ns = do_div(whole_msecs, (1000 * 1000)); | ||
106 | decimal_msecs = remainder_ns / 1000; | ||
107 | |||
108 | printk_ratelimited(KERN_INFO | ||
109 | "INFO: NMI handler (%ps) took too long to run: %lld.%03d msecs\n", | ||
110 | a->handler, whole_msecs, decimal_msecs); | ||
111 | } | ||
112 | |||
98 | static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b) | 113 | static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b) |
99 | { | 114 | { |
100 | struct nmi_desc *desc = nmi_to_desc(type); | 115 | struct nmi_desc *desc = nmi_to_desc(type); |
@@ -110,26 +125,20 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2 | |||
110 | * to handle those situations. | 125 | * to handle those situations. |
111 | */ | 126 | */ |
112 | list_for_each_entry_rcu(a, &desc->head, list) { | 127 | list_for_each_entry_rcu(a, &desc->head, list) { |
113 | u64 before, delta, whole_msecs; | 128 | int thishandled; |
114 | int remainder_ns, decimal_msecs, thishandled; | 129 | u64 delta; |
115 | 130 | ||
116 | before = sched_clock(); | 131 | delta = sched_clock(); |
117 | thishandled = a->handler(type, regs); | 132 | thishandled = a->handler(type, regs); |
118 | handled += thishandled; | 133 | handled += thishandled; |
119 | delta = sched_clock() - before; | 134 | delta = sched_clock() - delta; |
120 | trace_nmi_handler(a->handler, (int)delta, thishandled); | 135 | trace_nmi_handler(a->handler, (int)delta, thishandled); |
121 | 136 | ||
122 | if (delta < nmi_longest_ns) | 137 | if (delta < nmi_longest_ns || delta < a->max_duration) |
123 | continue; | 138 | continue; |
124 | 139 | ||
125 | nmi_longest_ns = delta; | 140 | a->max_duration = delta; |
126 | whole_msecs = delta; | 141 | irq_work_queue(&a->irq_work); |
127 | remainder_ns = do_div(whole_msecs, (1000 * 1000)); | ||
128 | decimal_msecs = remainder_ns / 1000; | ||
129 | printk_ratelimited(KERN_INFO | ||
130 | "INFO: NMI handler (%ps) took too long to run: " | ||
131 | "%lld.%03d msecs\n", a->handler, whole_msecs, | ||
132 | decimal_msecs); | ||
133 | } | 142 | } |
134 | 143 | ||
135 | rcu_read_unlock(); | 144 | rcu_read_unlock(); |
@@ -146,6 +155,8 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action) | |||
146 | if (!action->handler) | 155 | if (!action->handler) |
147 | return -EINVAL; | 156 | return -EINVAL; |
148 | 157 | ||
158 | init_irq_work(&action->irq_work, nmi_max_handler); | ||
159 | |||
149 | spin_lock_irqsave(&desc->lock, flags); | 160 | spin_lock_irqsave(&desc->lock, flags); |
150 | 161 | ||
151 | /* | 162 | /* |
diff --git a/include/linux/irq_work.h b/include/linux/irq_work.h index 66017028dcb3..19ae05d4b8ec 100644 --- a/include/linux/irq_work.h +++ b/include/linux/irq_work.h | |||
@@ -30,7 +30,9 @@ void init_irq_work(struct irq_work *work, void (*func)(struct irq_work *)) | |||
30 | work->func = func; | 30 | work->func = func; |
31 | } | 31 | } |
32 | 32 | ||
33 | void irq_work_queue(struct irq_work *work); | 33 | #define DEFINE_IRQ_WORK(name, _f) struct irq_work name = { .func = (_f), } |
34 | |||
35 | bool irq_work_queue(struct irq_work *work); | ||
34 | void irq_work_run(void); | 36 | void irq_work_run(void); |
35 | void irq_work_sync(struct irq_work *work); | 37 | void irq_work_sync(struct irq_work *work); |
36 | 38 | ||
diff --git a/include/linux/pci_ids.h b/include/linux/pci_ids.h index 97fbecdd7a40..7399e6a3e9a0 100644 --- a/include/linux/pci_ids.h +++ b/include/linux/pci_ids.h | |||
@@ -2531,6 +2531,9 @@ | |||
2531 | 2531 | ||
2532 | #define PCI_VENDOR_ID_INTEL 0x8086 | 2532 | #define PCI_VENDOR_ID_INTEL 0x8086 |
2533 | #define PCI_DEVICE_ID_INTEL_EESSC 0x0008 | 2533 | #define PCI_DEVICE_ID_INTEL_EESSC 0x0008 |
2534 | #define PCI_DEVICE_ID_INTEL_SNB_IMC 0x0100 | ||
2535 | #define PCI_DEVICE_ID_INTEL_IVB_IMC 0x0154 | ||
2536 | #define PCI_DEVICE_ID_INTEL_HSW_IMC 0x0c00 | ||
2534 | #define PCI_DEVICE_ID_INTEL_PXHD_0 0x0320 | 2537 | #define PCI_DEVICE_ID_INTEL_PXHD_0 0x0320 |
2535 | #define PCI_DEVICE_ID_INTEL_PXHD_1 0x0321 | 2538 | #define PCI_DEVICE_ID_INTEL_PXHD_1 0x0321 |
2536 | #define PCI_DEVICE_ID_INTEL_PXH_0 0x0329 | 2539 | #define PCI_DEVICE_ID_INTEL_PXH_0 0x0329 |
diff --git a/kernel/events/core.c b/kernel/events/core.c index fa0b2d4ad83c..fa990061aa6c 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c | |||
@@ -231,11 +231,29 @@ int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write, | |||
231 | #define NR_ACCUMULATED_SAMPLES 128 | 231 | #define NR_ACCUMULATED_SAMPLES 128 |
232 | static DEFINE_PER_CPU(u64, running_sample_length); | 232 | static DEFINE_PER_CPU(u64, running_sample_length); |
233 | 233 | ||
234 | void perf_sample_event_took(u64 sample_len_ns) | 234 | static void perf_duration_warn(struct irq_work *w) |
235 | { | 235 | { |
236 | u64 allowed_ns = ACCESS_ONCE(perf_sample_allowed_ns); | ||
236 | u64 avg_local_sample_len; | 237 | u64 avg_local_sample_len; |
237 | u64 local_samples_len; | 238 | u64 local_samples_len; |
239 | |||
240 | local_samples_len = __get_cpu_var(running_sample_length); | ||
241 | avg_local_sample_len = local_samples_len/NR_ACCUMULATED_SAMPLES; | ||
242 | |||
243 | printk_ratelimited(KERN_WARNING | ||
244 | "perf interrupt took too long (%lld > %lld), lowering " | ||
245 | "kernel.perf_event_max_sample_rate to %d\n", | ||
246 | avg_local_sample_len, allowed_ns >> 1, | ||
247 | sysctl_perf_event_sample_rate); | ||
248 | } | ||
249 | |||
250 | static DEFINE_IRQ_WORK(perf_duration_work, perf_duration_warn); | ||
251 | |||
252 | void perf_sample_event_took(u64 sample_len_ns) | ||
253 | { | ||
238 | u64 allowed_ns = ACCESS_ONCE(perf_sample_allowed_ns); | 254 | u64 allowed_ns = ACCESS_ONCE(perf_sample_allowed_ns); |
255 | u64 avg_local_sample_len; | ||
256 | u64 local_samples_len; | ||
239 | 257 | ||
240 | if (allowed_ns == 0) | 258 | if (allowed_ns == 0) |
241 | return; | 259 | return; |
@@ -263,13 +281,14 @@ void perf_sample_event_took(u64 sample_len_ns) | |||
263 | sysctl_perf_event_sample_rate = max_samples_per_tick * HZ; | 281 | sysctl_perf_event_sample_rate = max_samples_per_tick * HZ; |
264 | perf_sample_period_ns = NSEC_PER_SEC / sysctl_perf_event_sample_rate; | 282 | perf_sample_period_ns = NSEC_PER_SEC / sysctl_perf_event_sample_rate; |
265 | 283 | ||
266 | printk_ratelimited(KERN_WARNING | ||
267 | "perf samples too long (%lld > %lld), lowering " | ||
268 | "kernel.perf_event_max_sample_rate to %d\n", | ||
269 | avg_local_sample_len, allowed_ns, | ||
270 | sysctl_perf_event_sample_rate); | ||
271 | |||
272 | update_perf_cpu_limits(); | 284 | update_perf_cpu_limits(); |
285 | |||
286 | if (!irq_work_queue(&perf_duration_work)) { | ||
287 | early_printk("perf interrupt took too long (%lld > %lld), lowering " | ||
288 | "kernel.perf_event_max_sample_rate to %d\n", | ||
289 | avg_local_sample_len, allowed_ns >> 1, | ||
290 | sysctl_perf_event_sample_rate); | ||
291 | } | ||
273 | } | 292 | } |
274 | 293 | ||
275 | static atomic64_t perf_event_id; | 294 | static atomic64_t perf_event_id; |
diff --git a/kernel/irq_work.c b/kernel/irq_work.c index 55fcce6065cf..a82170e2fa78 100644 --- a/kernel/irq_work.c +++ b/kernel/irq_work.c | |||
@@ -61,11 +61,11 @@ void __weak arch_irq_work_raise(void) | |||
61 | * | 61 | * |
62 | * Can be re-enqueued while the callback is still in progress. | 62 | * Can be re-enqueued while the callback is still in progress. |
63 | */ | 63 | */ |
64 | void irq_work_queue(struct irq_work *work) | 64 | bool irq_work_queue(struct irq_work *work) |
65 | { | 65 | { |
66 | /* Only queue if not already pending */ | 66 | /* Only queue if not already pending */ |
67 | if (!irq_work_claim(work)) | 67 | if (!irq_work_claim(work)) |
68 | return; | 68 | return false; |
69 | 69 | ||
70 | /* Queue the entry and raise the IPI if needed. */ | 70 | /* Queue the entry and raise the IPI if needed. */ |
71 | preempt_disable(); | 71 | preempt_disable(); |
@@ -83,6 +83,8 @@ void irq_work_queue(struct irq_work *work) | |||
83 | } | 83 | } |
84 | 84 | ||
85 | preempt_enable(); | 85 | preempt_enable(); |
86 | |||
87 | return true; | ||
86 | } | 88 | } |
87 | EXPORT_SYMBOL_GPL(irq_work_queue); | 89 | EXPORT_SYMBOL_GPL(irq_work_queue); |
88 | 90 | ||
diff --git a/tools/include/linux/hash.h b/tools/include/linux/hash.h new file mode 100644 index 000000000000..d026c6573018 --- /dev/null +++ b/tools/include/linux/hash.h | |||
@@ -0,0 +1,5 @@ | |||
1 | #include "../../../include/linux/hash.h" | ||
2 | |||
3 | #ifndef _TOOLS_LINUX_HASH_H | ||
4 | #define _TOOLS_LINUX_HASH_H | ||
5 | #endif | ||
diff --git a/tools/lib/api/Makefile b/tools/lib/api/Makefile index ed2f51e11b80..ce00f7ee6455 100644 --- a/tools/lib/api/Makefile +++ b/tools/lib/api/Makefile | |||
@@ -9,8 +9,10 @@ LIB_H= | |||
9 | LIB_OBJS= | 9 | LIB_OBJS= |
10 | 10 | ||
11 | LIB_H += fs/debugfs.h | 11 | LIB_H += fs/debugfs.h |
12 | LIB_H += fs/fs.h | ||
12 | 13 | ||
13 | LIB_OBJS += $(OUTPUT)fs/debugfs.o | 14 | LIB_OBJS += $(OUTPUT)fs/debugfs.o |
15 | LIB_OBJS += $(OUTPUT)fs/fs.o | ||
14 | 16 | ||
15 | LIBFILE = libapikfs.a | 17 | LIBFILE = libapikfs.a |
16 | 18 | ||
diff --git a/tools/perf/util/fs.c b/tools/lib/api/fs/fs.c index f5be1f26e724..5b5eb788996e 100644 --- a/tools/perf/util/fs.c +++ b/tools/lib/api/fs/fs.c | |||
@@ -1,8 +1,13 @@ | |||
1 | /* TODO merge/factor in debugfs.c here */ | ||
1 | 2 | ||
2 | /* TODO merge/factor into tools/lib/lk/debugfs.c */ | 3 | #include <errno.h> |
4 | #include <stdbool.h> | ||
5 | #include <stdio.h> | ||
6 | #include <string.h> | ||
7 | #include <sys/vfs.h> | ||
3 | 8 | ||
4 | #include "util.h" | 9 | #include "debugfs.h" |
5 | #include "util/fs.h" | 10 | #include "fs.h" |
6 | 11 | ||
7 | static const char * const sysfs__fs_known_mountpoints[] = { | 12 | static const char * const sysfs__fs_known_mountpoints[] = { |
8 | "/sys", | 13 | "/sys", |
diff --git a/tools/perf/util/include/linux/magic.h b/tools/lib/api/fs/fs.h index 07d63cf3e0f6..cb7049551f33 100644 --- a/tools/perf/util/include/linux/magic.h +++ b/tools/lib/api/fs/fs.h | |||
@@ -1,9 +1,5 @@ | |||
1 | #ifndef _PERF_LINUX_MAGIC_H_ | 1 | #ifndef __API_FS__ |
2 | #define _PERF_LINUX_MAGIC_H_ | 2 | #define __API_FS__ |
3 | |||
4 | #ifndef DEBUGFS_MAGIC | ||
5 | #define DEBUGFS_MAGIC 0x64626720 | ||
6 | #endif | ||
7 | 3 | ||
8 | #ifndef SYSFS_MAGIC | 4 | #ifndef SYSFS_MAGIC |
9 | #define SYSFS_MAGIC 0x62656572 | 5 | #define SYSFS_MAGIC 0x62656572 |
@@ -13,4 +9,6 @@ | |||
13 | #define PROC_SUPER_MAGIC 0x9fa0 | 9 | #define PROC_SUPER_MAGIC 0x9fa0 |
14 | #endif | 10 | #endif |
15 | 11 | ||
16 | #endif | 12 | const char *sysfs__mountpoint(void); |
13 | const char *procfs__mountpoint(void); | ||
14 | #endif /* __API_FS__ */ | ||
diff --git a/tools/perf/MANIFEST b/tools/perf/MANIFEST index f41572d0dd76..c0c87c87b60f 100644 --- a/tools/perf/MANIFEST +++ b/tools/perf/MANIFEST | |||
@@ -6,6 +6,7 @@ tools/lib/symbol/kallsyms.c | |||
6 | tools/lib/symbol/kallsyms.h | 6 | tools/lib/symbol/kallsyms.h |
7 | tools/include/asm/bug.h | 7 | tools/include/asm/bug.h |
8 | tools/include/linux/compiler.h | 8 | tools/include/linux/compiler.h |
9 | tools/include/linux/hash.h | ||
9 | include/linux/const.h | 10 | include/linux/const.h |
10 | include/linux/perf_event.h | 11 | include/linux/perf_event.h |
11 | include/linux/rbtree.h | 12 | include/linux/rbtree.h |
diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf index 7257e7e9e38a..77b153fa23a5 100644 --- a/tools/perf/Makefile.perf +++ b/tools/perf/Makefile.perf | |||
@@ -208,7 +208,7 @@ LIB_H += ../../include/uapi/linux/perf_event.h | |||
208 | LIB_H += ../../include/linux/rbtree.h | 208 | LIB_H += ../../include/linux/rbtree.h |
209 | LIB_H += ../../include/linux/list.h | 209 | LIB_H += ../../include/linux/list.h |
210 | LIB_H += ../../include/uapi/linux/const.h | 210 | LIB_H += ../../include/uapi/linux/const.h |
211 | LIB_H += ../../include/linux/hash.h | 211 | LIB_H += ../include/linux/hash.h |
212 | LIB_H += ../../include/linux/stringify.h | 212 | LIB_H += ../../include/linux/stringify.h |
213 | LIB_H += util/include/linux/bitmap.h | 213 | LIB_H += util/include/linux/bitmap.h |
214 | LIB_H += util/include/linux/bitops.h | 214 | LIB_H += util/include/linux/bitops.h |
@@ -218,9 +218,7 @@ LIB_H += util/include/linux/ctype.h | |||
218 | LIB_H += util/include/linux/kernel.h | 218 | LIB_H += util/include/linux/kernel.h |
219 | LIB_H += util/include/linux/list.h | 219 | LIB_H += util/include/linux/list.h |
220 | LIB_H += util/include/linux/export.h | 220 | LIB_H += util/include/linux/export.h |
221 | LIB_H += util/include/linux/magic.h | ||
222 | LIB_H += util/include/linux/poison.h | 221 | LIB_H += util/include/linux/poison.h |
223 | LIB_H += util/include/linux/prefetch.h | ||
224 | LIB_H += util/include/linux/rbtree.h | 222 | LIB_H += util/include/linux/rbtree.h |
225 | LIB_H += util/include/linux/rbtree_augmented.h | 223 | LIB_H += util/include/linux/rbtree_augmented.h |
226 | LIB_H += util/include/linux/string.h | 224 | LIB_H += util/include/linux/string.h |
@@ -244,7 +242,6 @@ LIB_H += util/cache.h | |||
244 | LIB_H += util/callchain.h | 242 | LIB_H += util/callchain.h |
245 | LIB_H += util/build-id.h | 243 | LIB_H += util/build-id.h |
246 | LIB_H += util/debug.h | 244 | LIB_H += util/debug.h |
247 | LIB_H += util/fs.h | ||
248 | LIB_H += util/pmu.h | 245 | LIB_H += util/pmu.h |
249 | LIB_H += util/event.h | 246 | LIB_H += util/event.h |
250 | LIB_H += util/evsel.h | 247 | LIB_H += util/evsel.h |
@@ -306,7 +303,6 @@ LIB_OBJS += $(OUTPUT)util/annotate.o | |||
306 | LIB_OBJS += $(OUTPUT)util/build-id.o | 303 | LIB_OBJS += $(OUTPUT)util/build-id.o |
307 | LIB_OBJS += $(OUTPUT)util/config.o | 304 | LIB_OBJS += $(OUTPUT)util/config.o |
308 | LIB_OBJS += $(OUTPUT)util/ctype.o | 305 | LIB_OBJS += $(OUTPUT)util/ctype.o |
309 | LIB_OBJS += $(OUTPUT)util/fs.o | ||
310 | LIB_OBJS += $(OUTPUT)util/pmu.o | 306 | LIB_OBJS += $(OUTPUT)util/pmu.o |
311 | LIB_OBJS += $(OUTPUT)util/environment.o | 307 | LIB_OBJS += $(OUTPUT)util/environment.o |
312 | LIB_OBJS += $(OUTPUT)util/event.o | 308 | LIB_OBJS += $(OUTPUT)util/event.o |
@@ -408,6 +404,11 @@ endif | |||
408 | LIB_OBJS += $(OUTPUT)tests/code-reading.o | 404 | LIB_OBJS += $(OUTPUT)tests/code-reading.o |
409 | LIB_OBJS += $(OUTPUT)tests/sample-parsing.o | 405 | LIB_OBJS += $(OUTPUT)tests/sample-parsing.o |
410 | LIB_OBJS += $(OUTPUT)tests/parse-no-sample-id-all.o | 406 | LIB_OBJS += $(OUTPUT)tests/parse-no-sample-id-all.o |
407 | ifndef NO_LIBUNWIND | ||
408 | ifeq ($(ARCH),x86) | ||
409 | LIB_OBJS += $(OUTPUT)tests/dwarf-unwind.o | ||
410 | endif | ||
411 | endif | ||
411 | 412 | ||
412 | BUILTIN_OBJS += $(OUTPUT)builtin-annotate.o | 413 | BUILTIN_OBJS += $(OUTPUT)builtin-annotate.o |
413 | BUILTIN_OBJS += $(OUTPUT)builtin-bench.o | 414 | BUILTIN_OBJS += $(OUTPUT)builtin-bench.o |
@@ -476,7 +477,7 @@ endif # NO_DWARF | |||
476 | endif # NO_LIBELF | 477 | endif # NO_LIBELF |
477 | 478 | ||
478 | ifndef NO_LIBUNWIND | 479 | ifndef NO_LIBUNWIND |
479 | LIB_OBJS += $(OUTPUT)util/unwind.o | 480 | LIB_OBJS += $(OUTPUT)util/unwind-libunwind.o |
480 | endif | 481 | endif |
481 | LIB_OBJS += $(OUTPUT)tests/keep-tracking.o | 482 | LIB_OBJS += $(OUTPUT)tests/keep-tracking.o |
482 | 483 | ||
@@ -533,6 +534,7 @@ ifeq ($(NO_PERF_REGS),0) | |||
533 | ifeq ($(ARCH),x86) | 534 | ifeq ($(ARCH),x86) |
534 | LIB_H += arch/x86/include/perf_regs.h | 535 | LIB_H += arch/x86/include/perf_regs.h |
535 | endif | 536 | endif |
537 | LIB_OBJS += $(OUTPUT)util/perf_regs.o | ||
536 | endif | 538 | endif |
537 | 539 | ||
538 | ifndef NO_LIBNUMA | 540 | ifndef NO_LIBNUMA |
@@ -655,6 +657,9 @@ $(OUTPUT)tests/python-use.o: tests/python-use.c $(OUTPUT)PERF-CFLAGS | |||
655 | -DPYTHON='"$(PYTHON_WORD)"' \ | 657 | -DPYTHON='"$(PYTHON_WORD)"' \ |
656 | $< | 658 | $< |
657 | 659 | ||
660 | $(OUTPUT)tests/dwarf-unwind.o: tests/dwarf-unwind.c | ||
661 | $(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) -fno-optimize-sibling-calls $< | ||
662 | |||
658 | $(OUTPUT)util/config.o: util/config.c $(OUTPUT)PERF-CFLAGS | 663 | $(OUTPUT)util/config.o: util/config.c $(OUTPUT)PERF-CFLAGS |
659 | $(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $< | 664 | $(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $< |
660 | 665 | ||
diff --git a/tools/perf/arch/arm/Makefile b/tools/perf/arch/arm/Makefile index fe9b61e322a5..67e9b3d38e89 100644 --- a/tools/perf/arch/arm/Makefile +++ b/tools/perf/arch/arm/Makefile | |||
@@ -3,5 +3,5 @@ PERF_HAVE_DWARF_REGS := 1 | |||
3 | LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/dwarf-regs.o | 3 | LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/dwarf-regs.o |
4 | endif | 4 | endif |
5 | ifndef NO_LIBUNWIND | 5 | ifndef NO_LIBUNWIND |
6 | LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/unwind.o | 6 | LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/unwind-libunwind.o |
7 | endif | 7 | endif |
diff --git a/tools/perf/arch/arm/util/unwind.c b/tools/perf/arch/arm/util/unwind-libunwind.c index da3dc950550c..729ed69a6664 100644 --- a/tools/perf/arch/arm/util/unwind.c +++ b/tools/perf/arch/arm/util/unwind-libunwind.c | |||
@@ -4,7 +4,7 @@ | |||
4 | #include "perf_regs.h" | 4 | #include "perf_regs.h" |
5 | #include "../../util/unwind.h" | 5 | #include "../../util/unwind.h" |
6 | 6 | ||
7 | int unwind__arch_reg_id(int regnum) | 7 | int libunwind__arch_reg_id(int regnum) |
8 | { | 8 | { |
9 | switch (regnum) { | 9 | switch (regnum) { |
10 | case UNW_ARM_R0: | 10 | case UNW_ARM_R0: |
diff --git a/tools/perf/arch/x86/Makefile b/tools/perf/arch/x86/Makefile index 8801fe02f206..4fa9be983ad1 100644 --- a/tools/perf/arch/x86/Makefile +++ b/tools/perf/arch/x86/Makefile | |||
@@ -3,7 +3,9 @@ PERF_HAVE_DWARF_REGS := 1 | |||
3 | LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/dwarf-regs.o | 3 | LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/dwarf-regs.o |
4 | endif | 4 | endif |
5 | ifndef NO_LIBUNWIND | 5 | ifndef NO_LIBUNWIND |
6 | LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/unwind.o | 6 | LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/unwind-libunwind.o |
7 | LIB_OBJS += $(OUTPUT)arch/$(ARCH)/tests/regs_load.o | ||
8 | LIB_OBJS += $(OUTPUT)arch/$(ARCH)/tests/dwarf-unwind.o | ||
7 | endif | 9 | endif |
8 | LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/header.o | 10 | LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/header.o |
9 | LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/tsc.o | 11 | LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/tsc.o |
diff --git a/tools/perf/arch/x86/include/perf_regs.h b/tools/perf/arch/x86/include/perf_regs.h index e84ca76aae77..fc819ca34a7e 100644 --- a/tools/perf/arch/x86/include/perf_regs.h +++ b/tools/perf/arch/x86/include/perf_regs.h | |||
@@ -5,14 +5,20 @@ | |||
5 | #include "../../util/types.h" | 5 | #include "../../util/types.h" |
6 | #include <asm/perf_regs.h> | 6 | #include <asm/perf_regs.h> |
7 | 7 | ||
8 | void perf_regs_load(u64 *regs); | ||
9 | |||
8 | #ifndef HAVE_ARCH_X86_64_SUPPORT | 10 | #ifndef HAVE_ARCH_X86_64_SUPPORT |
9 | #define PERF_REGS_MASK ((1ULL << PERF_REG_X86_32_MAX) - 1) | 11 | #define PERF_REGS_MASK ((1ULL << PERF_REG_X86_32_MAX) - 1) |
12 | #define PERF_REGS_MAX PERF_REG_X86_32_MAX | ||
13 | #define PERF_SAMPLE_REGS_ABI PERF_SAMPLE_REGS_ABI_32 | ||
10 | #else | 14 | #else |
11 | #define REG_NOSUPPORT ((1ULL << PERF_REG_X86_DS) | \ | 15 | #define REG_NOSUPPORT ((1ULL << PERF_REG_X86_DS) | \ |
12 | (1ULL << PERF_REG_X86_ES) | \ | 16 | (1ULL << PERF_REG_X86_ES) | \ |
13 | (1ULL << PERF_REG_X86_FS) | \ | 17 | (1ULL << PERF_REG_X86_FS) | \ |
14 | (1ULL << PERF_REG_X86_GS)) | 18 | (1ULL << PERF_REG_X86_GS)) |
15 | #define PERF_REGS_MASK (((1ULL << PERF_REG_X86_64_MAX) - 1) & ~REG_NOSUPPORT) | 19 | #define PERF_REGS_MASK (((1ULL << PERF_REG_X86_64_MAX) - 1) & ~REG_NOSUPPORT) |
20 | #define PERF_REGS_MAX PERF_REG_X86_64_MAX | ||
21 | #define PERF_SAMPLE_REGS_ABI PERF_SAMPLE_REGS_ABI_64 | ||
16 | #endif | 22 | #endif |
17 | #define PERF_REG_IP PERF_REG_X86_IP | 23 | #define PERF_REG_IP PERF_REG_X86_IP |
18 | #define PERF_REG_SP PERF_REG_X86_SP | 24 | #define PERF_REG_SP PERF_REG_X86_SP |
diff --git a/tools/perf/arch/x86/tests/dwarf-unwind.c b/tools/perf/arch/x86/tests/dwarf-unwind.c new file mode 100644 index 000000000000..b602ad93ce63 --- /dev/null +++ b/tools/perf/arch/x86/tests/dwarf-unwind.c | |||
@@ -0,0 +1,59 @@ | |||
1 | #include <string.h> | ||
2 | #include "perf_regs.h" | ||
3 | #include "thread.h" | ||
4 | #include "map.h" | ||
5 | #include "event.h" | ||
6 | #include "tests/tests.h" | ||
7 | |||
8 | #define STACK_SIZE 8192 | ||
9 | |||
10 | static int sample_ustack(struct perf_sample *sample, | ||
11 | struct thread *thread, u64 *regs) | ||
12 | { | ||
13 | struct stack_dump *stack = &sample->user_stack; | ||
14 | struct map *map; | ||
15 | unsigned long sp; | ||
16 | u64 stack_size, *buf; | ||
17 | |||
18 | buf = malloc(STACK_SIZE); | ||
19 | if (!buf) { | ||
20 | pr_debug("failed to allocate sample uregs data\n"); | ||
21 | return -1; | ||
22 | } | ||
23 | |||
24 | sp = (unsigned long) regs[PERF_REG_X86_SP]; | ||
25 | |||
26 | map = map_groups__find(&thread->mg, MAP__FUNCTION, (u64) sp); | ||
27 | if (!map) { | ||
28 | pr_debug("failed to get stack map\n"); | ||
29 | return -1; | ||
30 | } | ||
31 | |||
32 | stack_size = map->end - sp; | ||
33 | stack_size = stack_size > STACK_SIZE ? STACK_SIZE : stack_size; | ||
34 | |||
35 | memcpy(buf, (void *) sp, stack_size); | ||
36 | stack->data = (char *) buf; | ||
37 | stack->size = stack_size; | ||
38 | return 0; | ||
39 | } | ||
40 | |||
41 | int test__arch_unwind_sample(struct perf_sample *sample, | ||
42 | struct thread *thread) | ||
43 | { | ||
44 | struct regs_dump *regs = &sample->user_regs; | ||
45 | u64 *buf; | ||
46 | |||
47 | buf = malloc(sizeof(u64) * PERF_REGS_MAX); | ||
48 | if (!buf) { | ||
49 | pr_debug("failed to allocate sample uregs data\n"); | ||
50 | return -1; | ||
51 | } | ||
52 | |||
53 | perf_regs_load(buf); | ||
54 | regs->abi = PERF_SAMPLE_REGS_ABI; | ||
55 | regs->regs = buf; | ||
56 | regs->mask = PERF_REGS_MASK; | ||
57 | |||
58 | return sample_ustack(sample, thread, buf); | ||
59 | } | ||
diff --git a/tools/perf/arch/x86/tests/regs_load.S b/tools/perf/arch/x86/tests/regs_load.S new file mode 100644 index 000000000000..99167bf644ea --- /dev/null +++ b/tools/perf/arch/x86/tests/regs_load.S | |||
@@ -0,0 +1,92 @@ | |||
1 | |||
2 | #include <linux/linkage.h> | ||
3 | |||
4 | #define AX 0 | ||
5 | #define BX 1 * 8 | ||
6 | #define CX 2 * 8 | ||
7 | #define DX 3 * 8 | ||
8 | #define SI 4 * 8 | ||
9 | #define DI 5 * 8 | ||
10 | #define BP 6 * 8 | ||
11 | #define SP 7 * 8 | ||
12 | #define IP 8 * 8 | ||
13 | #define FLAGS 9 * 8 | ||
14 | #define CS 10 * 8 | ||
15 | #define SS 11 * 8 | ||
16 | #define DS 12 * 8 | ||
17 | #define ES 13 * 8 | ||
18 | #define FS 14 * 8 | ||
19 | #define GS 15 * 8 | ||
20 | #define R8 16 * 8 | ||
21 | #define R9 17 * 8 | ||
22 | #define R10 18 * 8 | ||
23 | #define R11 19 * 8 | ||
24 | #define R12 20 * 8 | ||
25 | #define R13 21 * 8 | ||
26 | #define R14 22 * 8 | ||
27 | #define R15 23 * 8 | ||
28 | |||
29 | .text | ||
30 | #ifdef HAVE_ARCH_X86_64_SUPPORT | ||
31 | ENTRY(perf_regs_load) | ||
32 | movq %rax, AX(%rdi) | ||
33 | movq %rbx, BX(%rdi) | ||
34 | movq %rcx, CX(%rdi) | ||
35 | movq %rdx, DX(%rdi) | ||
36 | movq %rsi, SI(%rdi) | ||
37 | movq %rdi, DI(%rdi) | ||
38 | movq %rbp, BP(%rdi) | ||
39 | |||
40 | leaq 8(%rsp), %rax /* exclude this call. */ | ||
41 | movq %rax, SP(%rdi) | ||
42 | |||
43 | movq 0(%rsp), %rax | ||
44 | movq %rax, IP(%rdi) | ||
45 | |||
46 | movq $0, FLAGS(%rdi) | ||
47 | movq $0, CS(%rdi) | ||
48 | movq $0, SS(%rdi) | ||
49 | movq $0, DS(%rdi) | ||
50 | movq $0, ES(%rdi) | ||
51 | movq $0, FS(%rdi) | ||
52 | movq $0, GS(%rdi) | ||
53 | |||
54 | movq %r8, R8(%rdi) | ||
55 | movq %r9, R9(%rdi) | ||
56 | movq %r10, R10(%rdi) | ||
57 | movq %r11, R11(%rdi) | ||
58 | movq %r12, R12(%rdi) | ||
59 | movq %r13, R13(%rdi) | ||
60 | movq %r14, R14(%rdi) | ||
61 | movq %r15, R15(%rdi) | ||
62 | ret | ||
63 | ENDPROC(perf_regs_load) | ||
64 | #else | ||
65 | ENTRY(perf_regs_load) | ||
66 | push %edi | ||
67 | movl 8(%esp), %edi | ||
68 | movl %eax, AX(%edi) | ||
69 | movl %ebx, BX(%edi) | ||
70 | movl %ecx, CX(%edi) | ||
71 | movl %edx, DX(%edi) | ||
72 | movl %esi, SI(%edi) | ||
73 | pop %eax | ||
74 | movl %eax, DI(%edi) | ||
75 | movl %ebp, BP(%edi) | ||
76 | |||
77 | leal 4(%esp), %eax /* exclude this call. */ | ||
78 | movl %eax, SP(%edi) | ||
79 | |||
80 | movl 0(%esp), %eax | ||
81 | movl %eax, IP(%edi) | ||
82 | |||
83 | movl $0, FLAGS(%edi) | ||
84 | movl $0, CS(%edi) | ||
85 | movl $0, SS(%edi) | ||
86 | movl $0, DS(%edi) | ||
87 | movl $0, ES(%edi) | ||
88 | movl $0, FS(%edi) | ||
89 | movl $0, GS(%edi) | ||
90 | ret | ||
91 | ENDPROC(perf_regs_load) | ||
92 | #endif | ||
diff --git a/tools/perf/arch/x86/util/unwind.c b/tools/perf/arch/x86/util/unwind-libunwind.c index 456a88cf5b37..3261f68c6a7c 100644 --- a/tools/perf/arch/x86/util/unwind.c +++ b/tools/perf/arch/x86/util/unwind-libunwind.c | |||
@@ -5,7 +5,7 @@ | |||
5 | #include "../../util/unwind.h" | 5 | #include "../../util/unwind.h" |
6 | 6 | ||
7 | #ifdef HAVE_ARCH_X86_64_SUPPORT | 7 | #ifdef HAVE_ARCH_X86_64_SUPPORT |
8 | int unwind__arch_reg_id(int regnum) | 8 | int libunwind__arch_reg_id(int regnum) |
9 | { | 9 | { |
10 | int id; | 10 | int id; |
11 | 11 | ||
@@ -69,7 +69,7 @@ int unwind__arch_reg_id(int regnum) | |||
69 | return id; | 69 | return id; |
70 | } | 70 | } |
71 | #else | 71 | #else |
72 | int unwind__arch_reg_id(int regnum) | 72 | int libunwind__arch_reg_id(int regnum) |
73 | { | 73 | { |
74 | int id; | 74 | int id; |
75 | 75 | ||
diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index b3466018bbd7..3a7387551369 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c | |||
@@ -312,7 +312,6 @@ found: | |||
312 | sample_sw.period = sample->period; | 312 | sample_sw.period = sample->period; |
313 | sample_sw.time = sample->time; | 313 | sample_sw.time = sample->time; |
314 | perf_event__synthesize_sample(event_sw, evsel->attr.sample_type, | 314 | perf_event__synthesize_sample(event_sw, evsel->attr.sample_type, |
315 | evsel->attr.sample_regs_user, | ||
316 | evsel->attr.read_format, &sample_sw, | 315 | evsel->attr.read_format, &sample_sw, |
317 | false); | 316 | false); |
318 | build_id__mark_dso_hit(tool, event_sw, &sample_sw, evsel, machine); | 317 | build_id__mark_dso_hit(tool, event_sw, &sample_sw, evsel, machine); |
diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c index 78948882e3de..cdcd4eb3a57d 100644 --- a/tools/perf/builtin-probe.c +++ b/tools/perf/builtin-probe.c | |||
@@ -268,9 +268,9 @@ static int opt_set_filter(const struct option *opt __maybe_unused, | |||
268 | return 0; | 268 | return 0; |
269 | } | 269 | } |
270 | 270 | ||
271 | static void init_params(void) | 271 | static int init_params(void) |
272 | { | 272 | { |
273 | line_range__init(¶ms.line_range); | 273 | return line_range__init(¶ms.line_range); |
274 | } | 274 | } |
275 | 275 | ||
276 | static void cleanup_params(void) | 276 | static void cleanup_params(void) |
@@ -515,9 +515,11 @@ int cmd_probe(int argc, const char **argv, const char *prefix) | |||
515 | { | 515 | { |
516 | int ret; | 516 | int ret; |
517 | 517 | ||
518 | init_params(); | 518 | ret = init_params(); |
519 | ret = __cmd_probe(argc, argv, prefix); | 519 | if (!ret) { |
520 | cleanup_params(); | 520 | ret = __cmd_probe(argc, argv, prefix); |
521 | cleanup_params(); | ||
522 | } | ||
521 | 523 | ||
522 | return ret; | 524 | return ret; |
523 | } | 525 | } |
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index af47531b82ec..eb524f91bffe 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c | |||
@@ -649,7 +649,7 @@ error: | |||
649 | return ret; | 649 | return ret; |
650 | } | 650 | } |
651 | 651 | ||
652 | #ifdef HAVE_LIBUNWIND_SUPPORT | 652 | #ifdef HAVE_DWARF_UNWIND_SUPPORT |
653 | static int get_stack_size(char *str, unsigned long *_size) | 653 | static int get_stack_size(char *str, unsigned long *_size) |
654 | { | 654 | { |
655 | char *endptr; | 655 | char *endptr; |
@@ -675,7 +675,7 @@ static int get_stack_size(char *str, unsigned long *_size) | |||
675 | max_size, str); | 675 | max_size, str); |
676 | return -1; | 676 | return -1; |
677 | } | 677 | } |
678 | #endif /* HAVE_LIBUNWIND_SUPPORT */ | 678 | #endif /* HAVE_DWARF_UNWIND_SUPPORT */ |
679 | 679 | ||
680 | int record_parse_callchain(const char *arg, struct record_opts *opts) | 680 | int record_parse_callchain(const char *arg, struct record_opts *opts) |
681 | { | 681 | { |
@@ -704,7 +704,7 @@ int record_parse_callchain(const char *arg, struct record_opts *opts) | |||
704 | "needed for -g fp\n"); | 704 | "needed for -g fp\n"); |
705 | break; | 705 | break; |
706 | 706 | ||
707 | #ifdef HAVE_LIBUNWIND_SUPPORT | 707 | #ifdef HAVE_DWARF_UNWIND_SUPPORT |
708 | /* Dwarf style */ | 708 | /* Dwarf style */ |
709 | } else if (!strncmp(name, "dwarf", sizeof("dwarf"))) { | 709 | } else if (!strncmp(name, "dwarf", sizeof("dwarf"))) { |
710 | const unsigned long default_stack_dump_size = 8192; | 710 | const unsigned long default_stack_dump_size = 8192; |
@@ -720,7 +720,7 @@ int record_parse_callchain(const char *arg, struct record_opts *opts) | |||
720 | ret = get_stack_size(tok, &size); | 720 | ret = get_stack_size(tok, &size); |
721 | opts->stack_dump_size = size; | 721 | opts->stack_dump_size = size; |
722 | } | 722 | } |
723 | #endif /* HAVE_LIBUNWIND_SUPPORT */ | 723 | #endif /* HAVE_DWARF_UNWIND_SUPPORT */ |
724 | } else { | 724 | } else { |
725 | pr_err("callchain: Unknown --call-graph option " | 725 | pr_err("callchain: Unknown --call-graph option " |
726 | "value: %s\n", arg); | 726 | "value: %s\n", arg); |
@@ -735,7 +735,9 @@ int record_parse_callchain(const char *arg, struct record_opts *opts) | |||
735 | 735 | ||
736 | static void callchain_debug(struct record_opts *opts) | 736 | static void callchain_debug(struct record_opts *opts) |
737 | { | 737 | { |
738 | pr_debug("callchain: type %d\n", opts->call_graph); | 738 | static const char *str[CALLCHAIN_MAX] = { "NONE", "FP", "DWARF" }; |
739 | |||
740 | pr_debug("callchain: type %s\n", str[opts->call_graph]); | ||
739 | 741 | ||
740 | if (opts->call_graph == CALLCHAIN_DWARF) | 742 | if (opts->call_graph == CALLCHAIN_DWARF) |
741 | pr_debug("callchain: stack dump size %d\n", | 743 | pr_debug("callchain: stack dump size %d\n", |
@@ -749,6 +751,8 @@ int record_parse_callchain_opt(const struct option *opt, | |||
749 | struct record_opts *opts = opt->value; | 751 | struct record_opts *opts = opt->value; |
750 | int ret; | 752 | int ret; |
751 | 753 | ||
754 | opts->call_graph_enabled = !unset; | ||
755 | |||
752 | /* --no-call-graph */ | 756 | /* --no-call-graph */ |
753 | if (unset) { | 757 | if (unset) { |
754 | opts->call_graph = CALLCHAIN_NONE; | 758 | opts->call_graph = CALLCHAIN_NONE; |
@@ -769,6 +773,8 @@ int record_callchain_opt(const struct option *opt, | |||
769 | { | 773 | { |
770 | struct record_opts *opts = opt->value; | 774 | struct record_opts *opts = opt->value; |
771 | 775 | ||
776 | opts->call_graph_enabled = !unset; | ||
777 | |||
772 | if (opts->call_graph == CALLCHAIN_NONE) | 778 | if (opts->call_graph == CALLCHAIN_NONE) |
773 | opts->call_graph = CALLCHAIN_FP; | 779 | opts->call_graph = CALLCHAIN_FP; |
774 | 780 | ||
@@ -776,6 +782,16 @@ int record_callchain_opt(const struct option *opt, | |||
776 | return 0; | 782 | return 0; |
777 | } | 783 | } |
778 | 784 | ||
785 | static int perf_record_config(const char *var, const char *value, void *cb) | ||
786 | { | ||
787 | struct record *rec = cb; | ||
788 | |||
789 | if (!strcmp(var, "record.call-graph")) | ||
790 | return record_parse_callchain(value, &rec->opts); | ||
791 | |||
792 | return perf_default_config(var, value, cb); | ||
793 | } | ||
794 | |||
779 | static const char * const record_usage[] = { | 795 | static const char * const record_usage[] = { |
780 | "perf record [<options>] [<command>]", | 796 | "perf record [<options>] [<command>]", |
781 | "perf record [<options>] -- <command> [<options>]", | 797 | "perf record [<options>] -- <command> [<options>]", |
@@ -807,7 +823,7 @@ static struct record record = { | |||
807 | 823 | ||
808 | #define CALLCHAIN_HELP "setup and enables call-graph (stack chain/backtrace) recording: " | 824 | #define CALLCHAIN_HELP "setup and enables call-graph (stack chain/backtrace) recording: " |
809 | 825 | ||
810 | #ifdef HAVE_LIBUNWIND_SUPPORT | 826 | #ifdef HAVE_DWARF_UNWIND_SUPPORT |
811 | const char record_callchain_help[] = CALLCHAIN_HELP "fp dwarf"; | 827 | const char record_callchain_help[] = CALLCHAIN_HELP "fp dwarf"; |
812 | #else | 828 | #else |
813 | const char record_callchain_help[] = CALLCHAIN_HELP "fp"; | 829 | const char record_callchain_help[] = CALLCHAIN_HELP "fp"; |
@@ -907,6 +923,8 @@ int cmd_record(int argc, const char **argv, const char *prefix __maybe_unused) | |||
907 | if (rec->evlist == NULL) | 923 | if (rec->evlist == NULL) |
908 | return -ENOMEM; | 924 | return -ENOMEM; |
909 | 925 | ||
926 | perf_config(perf_record_config, rec); | ||
927 | |||
910 | argc = parse_options(argc, argv, record_options, record_usage, | 928 | argc = parse_options(argc, argv, record_options, record_usage, |
911 | PARSE_OPT_STOP_AT_NON_OPTION); | 929 | PARSE_OPT_STOP_AT_NON_OPTION); |
912 | if (!argc && target__none(&rec->opts.target)) | 930 | if (!argc && target__none(&rec->opts.target)) |
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index 3c53ec268fbc..d882b6f96411 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c | |||
@@ -75,13 +75,10 @@ static int report__config(const char *var, const char *value, void *cb) | |||
75 | return perf_default_config(var, value, cb); | 75 | return perf_default_config(var, value, cb); |
76 | } | 76 | } |
77 | 77 | ||
78 | static int report__add_mem_hist_entry(struct perf_tool *tool, struct addr_location *al, | 78 | static int report__add_mem_hist_entry(struct report *rep, struct addr_location *al, |
79 | struct perf_sample *sample, struct perf_evsel *evsel, | 79 | struct perf_sample *sample, struct perf_evsel *evsel) |
80 | union perf_event *event) | ||
81 | { | 80 | { |
82 | struct report *rep = container_of(tool, struct report, tool); | ||
83 | struct symbol *parent = NULL; | 81 | struct symbol *parent = NULL; |
84 | u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK; | ||
85 | struct hist_entry *he; | 82 | struct hist_entry *he; |
86 | struct mem_info *mi, *mx; | 83 | struct mem_info *mi, *mx; |
87 | uint64_t cost; | 84 | uint64_t cost; |
@@ -90,7 +87,7 @@ static int report__add_mem_hist_entry(struct perf_tool *tool, struct addr_locati | |||
90 | if (err) | 87 | if (err) |
91 | return err; | 88 | return err; |
92 | 89 | ||
93 | mi = machine__resolve_mem(al->machine, al->thread, sample, cpumode); | 90 | mi = sample__resolve_mem(sample, al); |
94 | if (!mi) | 91 | if (!mi) |
95 | return -ENOMEM; | 92 | return -ENOMEM; |
96 | 93 | ||
@@ -129,10 +126,9 @@ out: | |||
129 | return err; | 126 | return err; |
130 | } | 127 | } |
131 | 128 | ||
132 | static int report__add_branch_hist_entry(struct perf_tool *tool, struct addr_location *al, | 129 | static int report__add_branch_hist_entry(struct report *rep, struct addr_location *al, |
133 | struct perf_sample *sample, struct perf_evsel *evsel) | 130 | struct perf_sample *sample, struct perf_evsel *evsel) |
134 | { | 131 | { |
135 | struct report *rep = container_of(tool, struct report, tool); | ||
136 | struct symbol *parent = NULL; | 132 | struct symbol *parent = NULL; |
137 | unsigned i; | 133 | unsigned i; |
138 | struct hist_entry *he; | 134 | struct hist_entry *he; |
@@ -142,8 +138,7 @@ static int report__add_branch_hist_entry(struct perf_tool *tool, struct addr_loc | |||
142 | if (err) | 138 | if (err) |
143 | return err; | 139 | return err; |
144 | 140 | ||
145 | bi = machine__resolve_bstack(al->machine, al->thread, | 141 | bi = sample__resolve_bstack(sample, al); |
146 | sample->branch_stack); | ||
147 | if (!bi) | 142 | if (!bi) |
148 | return -ENOMEM; | 143 | return -ENOMEM; |
149 | 144 | ||
@@ -184,10 +179,9 @@ out: | |||
184 | return err; | 179 | return err; |
185 | } | 180 | } |
186 | 181 | ||
187 | static int report__add_hist_entry(struct perf_tool *tool, struct perf_evsel *evsel, | 182 | static int report__add_hist_entry(struct report *rep, struct perf_evsel *evsel, |
188 | struct addr_location *al, struct perf_sample *sample) | 183 | struct addr_location *al, struct perf_sample *sample) |
189 | { | 184 | { |
190 | struct report *rep = container_of(tool, struct report, tool); | ||
191 | struct symbol *parent = NULL; | 185 | struct symbol *parent = NULL; |
192 | struct hist_entry *he; | 186 | struct hist_entry *he; |
193 | int err = sample__resolve_callchain(sample, &parent, evsel, al, rep->max_stack); | 187 | int err = sample__resolve_callchain(sample, &parent, evsel, al, rep->max_stack); |
@@ -236,18 +230,18 @@ static int process_sample_event(struct perf_tool *tool, | |||
236 | return 0; | 230 | return 0; |
237 | 231 | ||
238 | if (sort__mode == SORT_MODE__BRANCH) { | 232 | if (sort__mode == SORT_MODE__BRANCH) { |
239 | ret = report__add_branch_hist_entry(tool, &al, sample, evsel); | 233 | ret = report__add_branch_hist_entry(rep, &al, sample, evsel); |
240 | if (ret < 0) | 234 | if (ret < 0) |
241 | pr_debug("problem adding lbr entry, skipping event\n"); | 235 | pr_debug("problem adding lbr entry, skipping event\n"); |
242 | } else if (rep->mem_mode == 1) { | 236 | } else if (rep->mem_mode == 1) { |
243 | ret = report__add_mem_hist_entry(tool, &al, sample, evsel, event); | 237 | ret = report__add_mem_hist_entry(rep, &al, sample, evsel); |
244 | if (ret < 0) | 238 | if (ret < 0) |
245 | pr_debug("problem adding mem entry, skipping event\n"); | 239 | pr_debug("problem adding mem entry, skipping event\n"); |
246 | } else { | 240 | } else { |
247 | if (al.map != NULL) | 241 | if (al.map != NULL) |
248 | al.map->dso->hit = 1; | 242 | al.map->dso->hit = 1; |
249 | 243 | ||
250 | ret = report__add_hist_entry(tool, evsel, &al, sample); | 244 | ret = report__add_hist_entry(rep, evsel, &al, sample); |
251 | if (ret < 0) | 245 | if (ret < 0) |
252 | pr_debug("problem incrementing symbol period, skipping event\n"); | 246 | pr_debug("problem incrementing symbol period, skipping event\n"); |
253 | } | 247 | } |
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index 76cd510d34d0..ed99ec4a309f 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c | |||
@@ -991,6 +991,16 @@ parse_callchain_opt(const struct option *opt, const char *arg, int unset) | |||
991 | return record_parse_callchain_opt(opt, arg, unset); | 991 | return record_parse_callchain_opt(opt, arg, unset); |
992 | } | 992 | } |
993 | 993 | ||
994 | static int perf_top_config(const char *var, const char *value, void *cb) | ||
995 | { | ||
996 | struct perf_top *top = cb; | ||
997 | |||
998 | if (!strcmp(var, "top.call-graph")) | ||
999 | return record_parse_callchain(value, &top->record_opts); | ||
1000 | |||
1001 | return perf_default_config(var, value, cb); | ||
1002 | } | ||
1003 | |||
994 | static int | 1004 | static int |
995 | parse_percent_limit(const struct option *opt, const char *arg, | 1005 | parse_percent_limit(const struct option *opt, const char *arg, |
996 | int unset __maybe_unused) | 1006 | int unset __maybe_unused) |
@@ -1115,6 +1125,8 @@ int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused) | |||
1115 | if (top.evlist == NULL) | 1125 | if (top.evlist == NULL) |
1116 | return -ENOMEM; | 1126 | return -ENOMEM; |
1117 | 1127 | ||
1128 | perf_config(perf_top_config, &top); | ||
1129 | |||
1118 | argc = parse_options(argc, argv, options, top_usage, 0); | 1130 | argc = parse_options(argc, argv, options, top_usage, 0); |
1119 | if (argc) | 1131 | if (argc) |
1120 | usage_with_options(top_usage, options); | 1132 | usage_with_options(top_usage, options); |
diff --git a/tools/perf/config/Makefile b/tools/perf/config/Makefile index c48d44958172..1686583ff7fc 100644 --- a/tools/perf/config/Makefile +++ b/tools/perf/config/Makefile | |||
@@ -338,7 +338,7 @@ ifndef NO_LIBUNWIND | |||
338 | CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME | 338 | CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME |
339 | endif | 339 | endif |
340 | 340 | ||
341 | CFLAGS += -DHAVE_LIBUNWIND_SUPPORT | 341 | CFLAGS += -DHAVE_DWARF_UNWIND_SUPPORT -DHAVE_LIBUNWIND_SUPPORT |
342 | EXTLIBS += $(LIBUNWIND_LIBS) | 342 | EXTLIBS += $(LIBUNWIND_LIBS) |
343 | CFLAGS += $(LIBUNWIND_CFLAGS) | 343 | CFLAGS += $(LIBUNWIND_CFLAGS) |
344 | LDFLAGS += $(LIBUNWIND_LDFLAGS) | 344 | LDFLAGS += $(LIBUNWIND_LDFLAGS) |
diff --git a/tools/perf/perf.h b/tools/perf/perf.h index e84fa26bc1be..6898ad0e199f 100644 --- a/tools/perf/perf.h +++ b/tools/perf/perf.h | |||
@@ -251,12 +251,14 @@ void pthread__unblock_sigwinch(void); | |||
251 | enum perf_call_graph_mode { | 251 | enum perf_call_graph_mode { |
252 | CALLCHAIN_NONE, | 252 | CALLCHAIN_NONE, |
253 | CALLCHAIN_FP, | 253 | CALLCHAIN_FP, |
254 | CALLCHAIN_DWARF | 254 | CALLCHAIN_DWARF, |
255 | CALLCHAIN_MAX | ||
255 | }; | 256 | }; |
256 | 257 | ||
257 | struct record_opts { | 258 | struct record_opts { |
258 | struct target target; | 259 | struct target target; |
259 | int call_graph; | 260 | int call_graph; |
261 | bool call_graph_enabled; | ||
260 | bool group; | 262 | bool group; |
261 | bool inherit_stat; | 263 | bool inherit_stat; |
262 | bool no_buffering; | 264 | bool no_buffering; |
diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c index 1e67437fb4ca..b11bf8a08430 100644 --- a/tools/perf/tests/builtin-test.c +++ b/tools/perf/tests/builtin-test.c | |||
@@ -115,6 +115,14 @@ static struct test { | |||
115 | .desc = "Test parsing with no sample_id_all bit set", | 115 | .desc = "Test parsing with no sample_id_all bit set", |
116 | .func = test__parse_no_sample_id_all, | 116 | .func = test__parse_no_sample_id_all, |
117 | }, | 117 | }, |
118 | #if defined(__x86_64__) || defined(__i386__) | ||
119 | #ifdef HAVE_DWARF_UNWIND_SUPPORT | ||
120 | { | ||
121 | .desc = "Test dwarf unwind", | ||
122 | .func = test__dwarf_unwind, | ||
123 | }, | ||
124 | #endif | ||
125 | #endif | ||
118 | { | 126 | { |
119 | .func = NULL, | 127 | .func = NULL, |
120 | }, | 128 | }, |
diff --git a/tools/perf/tests/dwarf-unwind.c b/tools/perf/tests/dwarf-unwind.c new file mode 100644 index 000000000000..f16ea2808a75 --- /dev/null +++ b/tools/perf/tests/dwarf-unwind.c | |||
@@ -0,0 +1,144 @@ | |||
1 | #include <linux/compiler.h> | ||
2 | #include <sys/types.h> | ||
3 | #include <unistd.h> | ||
4 | #include "tests.h" | ||
5 | #include "debug.h" | ||
6 | #include "machine.h" | ||
7 | #include "event.h" | ||
8 | #include "unwind.h" | ||
9 | #include "perf_regs.h" | ||
10 | #include "map.h" | ||
11 | #include "thread.h" | ||
12 | |||
13 | static int mmap_handler(struct perf_tool *tool __maybe_unused, | ||
14 | union perf_event *event, | ||
15 | struct perf_sample *sample __maybe_unused, | ||
16 | struct machine *machine) | ||
17 | { | ||
18 | return machine__process_mmap_event(machine, event, NULL); | ||
19 | } | ||
20 | |||
21 | static int init_live_machine(struct machine *machine) | ||
22 | { | ||
23 | union perf_event event; | ||
24 | pid_t pid = getpid(); | ||
25 | |||
26 | return perf_event__synthesize_mmap_events(NULL, &event, pid, pid, | ||
27 | mmap_handler, machine, true); | ||
28 | } | ||
29 | |||
30 | #define MAX_STACK 6 | ||
31 | |||
32 | static int unwind_entry(struct unwind_entry *entry, void *arg) | ||
33 | { | ||
34 | unsigned long *cnt = (unsigned long *) arg; | ||
35 | char *symbol = entry->sym ? entry->sym->name : NULL; | ||
36 | static const char *funcs[MAX_STACK] = { | ||
37 | "test__arch_unwind_sample", | ||
38 | "unwind_thread", | ||
39 | "krava_3", | ||
40 | "krava_2", | ||
41 | "krava_1", | ||
42 | "test__dwarf_unwind" | ||
43 | }; | ||
44 | |||
45 | if (*cnt >= MAX_STACK) { | ||
46 | pr_debug("failed: crossed the max stack value %d\n", MAX_STACK); | ||
47 | return -1; | ||
48 | } | ||
49 | |||
50 | if (!symbol) { | ||
51 | pr_debug("failed: got unresolved address 0x%" PRIx64 "\n", | ||
52 | entry->ip); | ||
53 | return -1; | ||
54 | } | ||
55 | |||
56 | pr_debug("got: %s 0x%" PRIx64 "\n", symbol, entry->ip); | ||
57 | return strcmp((const char *) symbol, funcs[(*cnt)++]); | ||
58 | } | ||
59 | |||
60 | __attribute__ ((noinline)) | ||
61 | static int unwind_thread(struct thread *thread, struct machine *machine) | ||
62 | { | ||
63 | struct perf_sample sample; | ||
64 | unsigned long cnt = 0; | ||
65 | int err = -1; | ||
66 | |||
67 | memset(&sample, 0, sizeof(sample)); | ||
68 | |||
69 | if (test__arch_unwind_sample(&sample, thread)) { | ||
70 | pr_debug("failed to get unwind sample\n"); | ||
71 | goto out; | ||
72 | } | ||
73 | |||
74 | err = unwind__get_entries(unwind_entry, &cnt, machine, thread, | ||
75 | &sample, MAX_STACK); | ||
76 | if (err) | ||
77 | pr_debug("unwind failed\n"); | ||
78 | else if (cnt != MAX_STACK) { | ||
79 | pr_debug("got wrong number of stack entries %lu != %d\n", | ||
80 | cnt, MAX_STACK); | ||
81 | err = -1; | ||
82 | } | ||
83 | |||
84 | out: | ||
85 | free(sample.user_stack.data); | ||
86 | free(sample.user_regs.regs); | ||
87 | return err; | ||
88 | } | ||
89 | |||
90 | __attribute__ ((noinline)) | ||
91 | static int krava_3(struct thread *thread, struct machine *machine) | ||
92 | { | ||
93 | return unwind_thread(thread, machine); | ||
94 | } | ||
95 | |||
96 | __attribute__ ((noinline)) | ||
97 | static int krava_2(struct thread *thread, struct machine *machine) | ||
98 | { | ||
99 | return krava_3(thread, machine); | ||
100 | } | ||
101 | |||
102 | __attribute__ ((noinline)) | ||
103 | static int krava_1(struct thread *thread, struct machine *machine) | ||
104 | { | ||
105 | return krava_2(thread, machine); | ||
106 | } | ||
107 | |||
108 | int test__dwarf_unwind(void) | ||
109 | { | ||
110 | struct machines machines; | ||
111 | struct machine *machine; | ||
112 | struct thread *thread; | ||
113 | int err = -1; | ||
114 | |||
115 | machines__init(&machines); | ||
116 | |||
117 | machine = machines__find(&machines, HOST_KERNEL_ID); | ||
118 | if (!machine) { | ||
119 | pr_err("Could not get machine\n"); | ||
120 | return -1; | ||
121 | } | ||
122 | |||
123 | if (init_live_machine(machine)) { | ||
124 | pr_err("Could not init machine\n"); | ||
125 | goto out; | ||
126 | } | ||
127 | |||
128 | if (verbose > 1) | ||
129 | machine__fprintf(machine, stderr); | ||
130 | |||
131 | thread = machine__find_thread(machine, getpid()); | ||
132 | if (!thread) { | ||
133 | pr_err("Could not get thread\n"); | ||
134 | goto out; | ||
135 | } | ||
136 | |||
137 | err = krava_1(thread, machine); | ||
138 | |||
139 | out: | ||
140 | machine__delete_threads(machine); | ||
141 | machine__exit(machine); | ||
142 | machines__exit(&machines); | ||
143 | return err; | ||
144 | } | ||
diff --git a/tools/perf/tests/parse-events.c b/tools/perf/tests/parse-events.c index 4db0ae617d70..8605ff5572ae 100644 --- a/tools/perf/tests/parse-events.c +++ b/tools/perf/tests/parse-events.c | |||
@@ -2,7 +2,7 @@ | |||
2 | #include "parse-events.h" | 2 | #include "parse-events.h" |
3 | #include "evsel.h" | 3 | #include "evsel.h" |
4 | #include "evlist.h" | 4 | #include "evlist.h" |
5 | #include "fs.h" | 5 | #include <api/fs/fs.h> |
6 | #include <api/fs/debugfs.h> | 6 | #include <api/fs/debugfs.h> |
7 | #include "tests.h" | 7 | #include "tests.h" |
8 | #include <linux/hw_breakpoint.h> | 8 | #include <linux/hw_breakpoint.h> |
diff --git a/tools/perf/tests/sample-parsing.c b/tools/perf/tests/sample-parsing.c index 1b677202638d..0014d3c8c21c 100644 --- a/tools/perf/tests/sample-parsing.c +++ b/tools/perf/tests/sample-parsing.c | |||
@@ -22,8 +22,8 @@ | |||
22 | } while (0) | 22 | } while (0) |
23 | 23 | ||
24 | static bool samples_same(const struct perf_sample *s1, | 24 | static bool samples_same(const struct perf_sample *s1, |
25 | const struct perf_sample *s2, u64 type, u64 regs_user, | 25 | const struct perf_sample *s2, |
26 | u64 read_format) | 26 | u64 type, u64 read_format) |
27 | { | 27 | { |
28 | size_t i; | 28 | size_t i; |
29 | 29 | ||
@@ -95,8 +95,9 @@ static bool samples_same(const struct perf_sample *s1, | |||
95 | } | 95 | } |
96 | 96 | ||
97 | if (type & PERF_SAMPLE_REGS_USER) { | 97 | if (type & PERF_SAMPLE_REGS_USER) { |
98 | size_t sz = hweight_long(regs_user) * sizeof(u64); | 98 | size_t sz = hweight_long(s1->user_regs.mask) * sizeof(u64); |
99 | 99 | ||
100 | COMP(user_regs.mask); | ||
100 | COMP(user_regs.abi); | 101 | COMP(user_regs.abi); |
101 | if (s1->user_regs.abi && | 102 | if (s1->user_regs.abi && |
102 | (!s1->user_regs.regs || !s2->user_regs.regs || | 103 | (!s1->user_regs.regs || !s2->user_regs.regs || |
@@ -174,6 +175,7 @@ static int do_test(u64 sample_type, u64 sample_regs_user, u64 read_format) | |||
174 | .branch_stack = &branch_stack.branch_stack, | 175 | .branch_stack = &branch_stack.branch_stack, |
175 | .user_regs = { | 176 | .user_regs = { |
176 | .abi = PERF_SAMPLE_REGS_ABI_64, | 177 | .abi = PERF_SAMPLE_REGS_ABI_64, |
178 | .mask = sample_regs_user, | ||
177 | .regs = user_regs, | 179 | .regs = user_regs, |
178 | }, | 180 | }, |
179 | .user_stack = { | 181 | .user_stack = { |
@@ -201,8 +203,7 @@ static int do_test(u64 sample_type, u64 sample_regs_user, u64 read_format) | |||
201 | sample.read.one.id = 99; | 203 | sample.read.one.id = 99; |
202 | } | 204 | } |
203 | 205 | ||
204 | sz = perf_event__sample_event_size(&sample, sample_type, | 206 | sz = perf_event__sample_event_size(&sample, sample_type, read_format); |
205 | sample_regs_user, read_format); | ||
206 | bufsz = sz + 4096; /* Add a bit for overrun checking */ | 207 | bufsz = sz + 4096; /* Add a bit for overrun checking */ |
207 | event = malloc(bufsz); | 208 | event = malloc(bufsz); |
208 | if (!event) { | 209 | if (!event) { |
@@ -215,8 +216,7 @@ static int do_test(u64 sample_type, u64 sample_regs_user, u64 read_format) | |||
215 | event->header.misc = 0; | 216 | event->header.misc = 0; |
216 | event->header.size = sz; | 217 | event->header.size = sz; |
217 | 218 | ||
218 | err = perf_event__synthesize_sample(event, sample_type, | 219 | err = perf_event__synthesize_sample(event, sample_type, read_format, |
219 | sample_regs_user, read_format, | ||
220 | &sample, false); | 220 | &sample, false); |
221 | if (err) { | 221 | if (err) { |
222 | pr_debug("%s failed for sample_type %#"PRIx64", error %d\n", | 222 | pr_debug("%s failed for sample_type %#"PRIx64", error %d\n", |
@@ -244,8 +244,7 @@ static int do_test(u64 sample_type, u64 sample_regs_user, u64 read_format) | |||
244 | goto out_free; | 244 | goto out_free; |
245 | } | 245 | } |
246 | 246 | ||
247 | if (!samples_same(&sample, &sample_out, sample_type, | 247 | if (!samples_same(&sample, &sample_out, sample_type, read_format)) { |
248 | sample_regs_user, read_format)) { | ||
249 | pr_debug("parsing failed for sample_type %#"PRIx64"\n", | 248 | pr_debug("parsing failed for sample_type %#"PRIx64"\n", |
250 | sample_type); | 249 | sample_type); |
251 | goto out_free; | 250 | goto out_free; |
diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h index e0ac713857ba..a24795ca002d 100644 --- a/tools/perf/tests/tests.h +++ b/tools/perf/tests/tests.h | |||
@@ -40,5 +40,14 @@ int test__code_reading(void); | |||
40 | int test__sample_parsing(void); | 40 | int test__sample_parsing(void); |
41 | int test__keep_tracking(void); | 41 | int test__keep_tracking(void); |
42 | int test__parse_no_sample_id_all(void); | 42 | int test__parse_no_sample_id_all(void); |
43 | int test__dwarf_unwind(void); | ||
43 | 44 | ||
45 | #if defined(__x86_64__) || defined(__i386__) | ||
46 | #ifdef HAVE_DWARF_UNWIND_SUPPORT | ||
47 | struct thread; | ||
48 | struct perf_sample; | ||
49 | int test__arch_unwind_sample(struct perf_sample *sample, | ||
50 | struct thread *thread); | ||
51 | #endif | ||
52 | #endif | ||
44 | #endif /* TESTS_H */ | 53 | #endif /* TESTS_H */ |
diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c index a9b48c42e81e..7fe4994eeb63 100644 --- a/tools/perf/util/cpumap.c +++ b/tools/perf/util/cpumap.c | |||
@@ -1,5 +1,5 @@ | |||
1 | #include "util.h" | 1 | #include "util.h" |
2 | #include "fs.h" | 2 | #include <api/fs/fs.h> |
3 | #include "../perf.h" | 3 | #include "../perf.h" |
4 | #include "cpumap.h" | 4 | #include "cpumap.h" |
5 | #include <assert.h> | 5 | #include <assert.h> |
diff --git a/tools/perf/util/dso.h b/tools/perf/util/dso.h index cd7d6f078cdd..ab06f1c03655 100644 --- a/tools/perf/util/dso.h +++ b/tools/perf/util/dso.h | |||
@@ -102,6 +102,16 @@ struct dso { | |||
102 | char name[0]; | 102 | char name[0]; |
103 | }; | 103 | }; |
104 | 104 | ||
105 | /* dso__for_each_symbol - iterate over the symbols of given type | ||
106 | * | ||
107 | * @dso: the 'struct dso *' in which symbols itereated | ||
108 | * @pos: the 'struct symbol *' to use as a loop cursor | ||
109 | * @n: the 'struct rb_node *' to use as a temporary storage | ||
110 | * @type: the 'enum map_type' type of symbols | ||
111 | */ | ||
112 | #define dso__for_each_symbol(dso, pos, n, type) \ | ||
113 | symbols__for_each_entry(&(dso)->symbols[(type)], pos, n) | ||
114 | |||
105 | static inline void dso__set_loaded(struct dso *dso, enum map_type type) | 115 | static inline void dso__set_loaded(struct dso *dso, enum map_type type) |
106 | { | 116 | { |
107 | dso->loaded |= (1 << type); | 117 | dso->loaded |= (1 << type); |
diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h index 851fa06f4a42..38457d447a13 100644 --- a/tools/perf/util/event.h +++ b/tools/perf/util/event.h | |||
@@ -85,6 +85,7 @@ struct sample_event { | |||
85 | 85 | ||
86 | struct regs_dump { | 86 | struct regs_dump { |
87 | u64 abi; | 87 | u64 abi; |
88 | u64 mask; | ||
88 | u64 *regs; | 89 | u64 *regs; |
89 | }; | 90 | }; |
90 | 91 | ||
@@ -259,9 +260,9 @@ int perf_event__preprocess_sample(const union perf_event *event, | |||
259 | const char *perf_event__name(unsigned int id); | 260 | const char *perf_event__name(unsigned int id); |
260 | 261 | ||
261 | size_t perf_event__sample_event_size(const struct perf_sample *sample, u64 type, | 262 | size_t perf_event__sample_event_size(const struct perf_sample *sample, u64 type, |
262 | u64 sample_regs_user, u64 read_format); | 263 | u64 read_format); |
263 | int perf_event__synthesize_sample(union perf_event *event, u64 type, | 264 | int perf_event__synthesize_sample(union perf_event *event, u64 type, |
264 | u64 sample_regs_user, u64 read_format, | 265 | u64 read_format, |
265 | const struct perf_sample *sample, | 266 | const struct perf_sample *sample, |
266 | bool swapped); | 267 | bool swapped); |
267 | 268 | ||
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 55407c594b87..adc94dd1794d 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c | |||
@@ -595,7 +595,7 @@ void perf_evsel__config(struct perf_evsel *evsel, struct record_opts *opts) | |||
595 | attr->mmap_data = track; | 595 | attr->mmap_data = track; |
596 | } | 596 | } |
597 | 597 | ||
598 | if (opts->call_graph) { | 598 | if (opts->call_graph_enabled) { |
599 | perf_evsel__set_sample_bit(evsel, CALLCHAIN); | 599 | perf_evsel__set_sample_bit(evsel, CALLCHAIN); |
600 | 600 | ||
601 | if (opts->call_graph == CALLCHAIN_DWARF) { | 601 | if (opts->call_graph == CALLCHAIN_DWARF) { |
@@ -1220,7 +1220,7 @@ int perf_evsel__parse_sample(struct perf_evsel *evsel, union perf_event *event, | |||
1220 | memset(data, 0, sizeof(*data)); | 1220 | memset(data, 0, sizeof(*data)); |
1221 | data->cpu = data->pid = data->tid = -1; | 1221 | data->cpu = data->pid = data->tid = -1; |
1222 | data->stream_id = data->id = data->time = -1ULL; | 1222 | data->stream_id = data->id = data->time = -1ULL; |
1223 | data->period = 1; | 1223 | data->period = evsel->attr.sample_period; |
1224 | data->weight = 0; | 1224 | data->weight = 0; |
1225 | 1225 | ||
1226 | if (event->header.type != PERF_RECORD_SAMPLE) { | 1226 | if (event->header.type != PERF_RECORD_SAMPLE) { |
@@ -1396,10 +1396,11 @@ int perf_evsel__parse_sample(struct perf_evsel *evsel, union perf_event *event, | |||
1396 | array++; | 1396 | array++; |
1397 | 1397 | ||
1398 | if (data->user_regs.abi) { | 1398 | if (data->user_regs.abi) { |
1399 | u64 regs_user = evsel->attr.sample_regs_user; | 1399 | u64 mask = evsel->attr.sample_regs_user; |
1400 | 1400 | ||
1401 | sz = hweight_long(regs_user) * sizeof(u64); | 1401 | sz = hweight_long(mask) * sizeof(u64); |
1402 | OVERFLOW_CHECK(array, sz, max_size); | 1402 | OVERFLOW_CHECK(array, sz, max_size); |
1403 | data->user_regs.mask = mask; | ||
1403 | data->user_regs.regs = (u64 *)array; | 1404 | data->user_regs.regs = (u64 *)array; |
1404 | array = (void *)array + sz; | 1405 | array = (void *)array + sz; |
1405 | } | 1406 | } |
@@ -1451,7 +1452,7 @@ int perf_evsel__parse_sample(struct perf_evsel *evsel, union perf_event *event, | |||
1451 | } | 1452 | } |
1452 | 1453 | ||
1453 | size_t perf_event__sample_event_size(const struct perf_sample *sample, u64 type, | 1454 | size_t perf_event__sample_event_size(const struct perf_sample *sample, u64 type, |
1454 | u64 sample_regs_user, u64 read_format) | 1455 | u64 read_format) |
1455 | { | 1456 | { |
1456 | size_t sz, result = sizeof(struct sample_event); | 1457 | size_t sz, result = sizeof(struct sample_event); |
1457 | 1458 | ||
@@ -1517,7 +1518,7 @@ size_t perf_event__sample_event_size(const struct perf_sample *sample, u64 type, | |||
1517 | if (type & PERF_SAMPLE_REGS_USER) { | 1518 | if (type & PERF_SAMPLE_REGS_USER) { |
1518 | if (sample->user_regs.abi) { | 1519 | if (sample->user_regs.abi) { |
1519 | result += sizeof(u64); | 1520 | result += sizeof(u64); |
1520 | sz = hweight_long(sample_regs_user) * sizeof(u64); | 1521 | sz = hweight_long(sample->user_regs.mask) * sizeof(u64); |
1521 | result += sz; | 1522 | result += sz; |
1522 | } else { | 1523 | } else { |
1523 | result += sizeof(u64); | 1524 | result += sizeof(u64); |
@@ -1546,7 +1547,7 @@ size_t perf_event__sample_event_size(const struct perf_sample *sample, u64 type, | |||
1546 | } | 1547 | } |
1547 | 1548 | ||
1548 | int perf_event__synthesize_sample(union perf_event *event, u64 type, | 1549 | int perf_event__synthesize_sample(union perf_event *event, u64 type, |
1549 | u64 sample_regs_user, u64 read_format, | 1550 | u64 read_format, |
1550 | const struct perf_sample *sample, | 1551 | const struct perf_sample *sample, |
1551 | bool swapped) | 1552 | bool swapped) |
1552 | { | 1553 | { |
@@ -1687,7 +1688,7 @@ int perf_event__synthesize_sample(union perf_event *event, u64 type, | |||
1687 | if (type & PERF_SAMPLE_REGS_USER) { | 1688 | if (type & PERF_SAMPLE_REGS_USER) { |
1688 | if (sample->user_regs.abi) { | 1689 | if (sample->user_regs.abi) { |
1689 | *array++ = sample->user_regs.abi; | 1690 | *array++ = sample->user_regs.abi; |
1690 | sz = hweight_long(sample_regs_user) * sizeof(u64); | 1691 | sz = hweight_long(sample->user_regs.mask) * sizeof(u64); |
1691 | memcpy(array, sample->user_regs.regs, sz); | 1692 | memcpy(array, sample->user_regs.regs, sz); |
1692 | array = (void *)array + sz; | 1693 | array = (void *)array + sz; |
1693 | } else { | 1694 | } else { |
diff --git a/tools/perf/util/fs.h b/tools/perf/util/fs.h deleted file mode 100644 index 5e09ce1bab0e..000000000000 --- a/tools/perf/util/fs.h +++ /dev/null | |||
@@ -1,7 +0,0 @@ | |||
1 | #ifndef __PERF_FS | ||
2 | #define __PERF_FS | ||
3 | |||
4 | const char *sysfs__mountpoint(void); | ||
5 | const char *procfs__mountpoint(void); | ||
6 | |||
7 | #endif /* __PERF_FS */ | ||
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c index e4e6249b87d4..0466efa71140 100644 --- a/tools/perf/util/hist.c +++ b/tools/perf/util/hist.c | |||
@@ -290,7 +290,7 @@ static struct hist_entry *hist_entry__new(struct hist_entry *template) | |||
290 | if (he->branch_info) { | 290 | if (he->branch_info) { |
291 | /* | 291 | /* |
292 | * This branch info is (a part of) allocated from | 292 | * This branch info is (a part of) allocated from |
293 | * machine__resolve_bstack() and will be freed after | 293 | * sample__resolve_bstack() and will be freed after |
294 | * adding new entries. So we need to save a copy. | 294 | * adding new entries. So we need to save a copy. |
295 | */ | 295 | */ |
296 | he->branch_info = malloc(sizeof(*he->branch_info)); | 296 | he->branch_info = malloc(sizeof(*he->branch_info)); |
@@ -369,7 +369,7 @@ static struct hist_entry *add_hist_entry(struct hists *hists, | |||
369 | he_stat__add_period(&he->stat, period, weight); | 369 | he_stat__add_period(&he->stat, period, weight); |
370 | 370 | ||
371 | /* | 371 | /* |
372 | * This mem info was allocated from machine__resolve_mem | 372 | * This mem info was allocated from sample__resolve_mem |
373 | * and will not be used anymore. | 373 | * and will not be used anymore. |
374 | */ | 374 | */ |
375 | zfree(&entry->mem_info); | 375 | zfree(&entry->mem_info); |
diff --git a/tools/perf/util/include/linux/hash.h b/tools/perf/util/include/linux/hash.h deleted file mode 100644 index 201f57397997..000000000000 --- a/tools/perf/util/include/linux/hash.h +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | #include "../../../../include/linux/hash.h" | ||
2 | |||
3 | #ifndef PERF_HASH_H | ||
4 | #define PERF_HASH_H | ||
5 | #endif | ||
diff --git a/tools/perf/util/include/linux/list.h b/tools/perf/util/include/linux/list.h index 1d928a0ce997..bfe0a2afd0d2 100644 --- a/tools/perf/util/include/linux/list.h +++ b/tools/perf/util/include/linux/list.h | |||
@@ -1,5 +1,4 @@ | |||
1 | #include <linux/kernel.h> | 1 | #include <linux/kernel.h> |
2 | #include <linux/prefetch.h> | ||
3 | 2 | ||
4 | #include "../../../../include/linux/list.h" | 3 | #include "../../../../include/linux/list.h" |
5 | 4 | ||
diff --git a/tools/perf/util/include/linux/prefetch.h b/tools/perf/util/include/linux/prefetch.h deleted file mode 100644 index 7841e485d8c3..000000000000 --- a/tools/perf/util/include/linux/prefetch.h +++ /dev/null | |||
@@ -1,6 +0,0 @@ | |||
1 | #ifndef PERF_LINUX_PREFETCH_H | ||
2 | #define PERF_LINUX_PREFETCH_H | ||
3 | |||
4 | static inline void prefetch(void *a __attribute__((unused))) { } | ||
5 | |||
6 | #endif | ||
diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c index c872991e0f65..ac37d788b5cb 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c | |||
@@ -1238,37 +1238,35 @@ static void ip__resolve_data(struct machine *machine, struct thread *thread, | |||
1238 | ams->map = al.map; | 1238 | ams->map = al.map; |
1239 | } | 1239 | } |
1240 | 1240 | ||
1241 | struct mem_info *machine__resolve_mem(struct machine *machine, | 1241 | struct mem_info *sample__resolve_mem(struct perf_sample *sample, |
1242 | struct thread *thr, | 1242 | struct addr_location *al) |
1243 | struct perf_sample *sample, | ||
1244 | u8 cpumode) | ||
1245 | { | 1243 | { |
1246 | struct mem_info *mi = zalloc(sizeof(*mi)); | 1244 | struct mem_info *mi = zalloc(sizeof(*mi)); |
1247 | 1245 | ||
1248 | if (!mi) | 1246 | if (!mi) |
1249 | return NULL; | 1247 | return NULL; |
1250 | 1248 | ||
1251 | ip__resolve_ams(machine, thr, &mi->iaddr, sample->ip); | 1249 | ip__resolve_ams(al->machine, al->thread, &mi->iaddr, sample->ip); |
1252 | ip__resolve_data(machine, thr, cpumode, &mi->daddr, sample->addr); | 1250 | ip__resolve_data(al->machine, al->thread, al->cpumode, |
1251 | &mi->daddr, sample->addr); | ||
1253 | mi->data_src.val = sample->data_src; | 1252 | mi->data_src.val = sample->data_src; |
1254 | 1253 | ||
1255 | return mi; | 1254 | return mi; |
1256 | } | 1255 | } |
1257 | 1256 | ||
1258 | struct branch_info *machine__resolve_bstack(struct machine *machine, | 1257 | struct branch_info *sample__resolve_bstack(struct perf_sample *sample, |
1259 | struct thread *thr, | 1258 | struct addr_location *al) |
1260 | struct branch_stack *bs) | ||
1261 | { | 1259 | { |
1262 | struct branch_info *bi; | ||
1263 | unsigned int i; | 1260 | unsigned int i; |
1261 | const struct branch_stack *bs = sample->branch_stack; | ||
1262 | struct branch_info *bi = calloc(bs->nr, sizeof(struct branch_info)); | ||
1264 | 1263 | ||
1265 | bi = calloc(bs->nr, sizeof(struct branch_info)); | ||
1266 | if (!bi) | 1264 | if (!bi) |
1267 | return NULL; | 1265 | return NULL; |
1268 | 1266 | ||
1269 | for (i = 0; i < bs->nr; i++) { | 1267 | for (i = 0; i < bs->nr; i++) { |
1270 | ip__resolve_ams(machine, thr, &bi[i].to, bs->entries[i].to); | 1268 | ip__resolve_ams(al->machine, al->thread, &bi[i].to, bs->entries[i].to); |
1271 | ip__resolve_ams(machine, thr, &bi[i].from, bs->entries[i].from); | 1269 | ip__resolve_ams(al->machine, al->thread, &bi[i].from, bs->entries[i].from); |
1272 | bi[i].flags = bs->entries[i].flags; | 1270 | bi[i].flags = bs->entries[i].flags; |
1273 | } | 1271 | } |
1274 | return bi; | 1272 | return bi; |
@@ -1385,8 +1383,7 @@ int machine__resolve_callchain(struct machine *machine, | |||
1385 | return 0; | 1383 | return 0; |
1386 | 1384 | ||
1387 | return unwind__get_entries(unwind_entry, &callchain_cursor, machine, | 1385 | return unwind__get_entries(unwind_entry, &callchain_cursor, machine, |
1388 | thread, evsel->attr.sample_regs_user, | 1386 | thread, sample, max_stack); |
1389 | sample, max_stack); | ||
1390 | 1387 | ||
1391 | } | 1388 | } |
1392 | 1389 | ||
diff --git a/tools/perf/util/machine.h b/tools/perf/util/machine.h index f77e91e483dc..2e6c248c870f 100644 --- a/tools/perf/util/machine.h +++ b/tools/perf/util/machine.h | |||
@@ -91,12 +91,10 @@ void machine__delete_dead_threads(struct machine *machine); | |||
91 | void machine__delete_threads(struct machine *machine); | 91 | void machine__delete_threads(struct machine *machine); |
92 | void machine__delete(struct machine *machine); | 92 | void machine__delete(struct machine *machine); |
93 | 93 | ||
94 | struct branch_info *machine__resolve_bstack(struct machine *machine, | 94 | struct branch_info *sample__resolve_bstack(struct perf_sample *sample, |
95 | struct thread *thread, | 95 | struct addr_location *al); |
96 | struct branch_stack *bs); | 96 | struct mem_info *sample__resolve_mem(struct perf_sample *sample, |
97 | struct mem_info *machine__resolve_mem(struct machine *machine, | 97 | struct addr_location *al); |
98 | struct thread *thread, | ||
99 | struct perf_sample *sample, u8 cpumode); | ||
100 | int machine__resolve_callchain(struct machine *machine, | 98 | int machine__resolve_callchain(struct machine *machine, |
101 | struct perf_evsel *evsel, | 99 | struct perf_evsel *evsel, |
102 | struct thread *thread, | 100 | struct thread *thread, |
diff --git a/tools/perf/util/map.h b/tools/perf/util/map.h index 257e513205ce..f00f058afb3b 100644 --- a/tools/perf/util/map.h +++ b/tools/perf/util/map.h | |||
@@ -90,6 +90,16 @@ u64 map__objdump_2mem(struct map *map, u64 ip); | |||
90 | 90 | ||
91 | struct symbol; | 91 | struct symbol; |
92 | 92 | ||
93 | /* map__for_each_symbol - iterate over the symbols in the given map | ||
94 | * | ||
95 | * @map: the 'struct map *' in which symbols itereated | ||
96 | * @pos: the 'struct symbol *' to use as a loop cursor | ||
97 | * @n: the 'struct rb_node *' to use as a temporary storage | ||
98 | * Note: caller must ensure map->dso is not NULL (map is loaded). | ||
99 | */ | ||
100 | #define map__for_each_symbol(map, pos, n) \ | ||
101 | dso__for_each_symbol(map->dso, pos, n, map->type) | ||
102 | |||
93 | typedef int (*symbol_filter_t)(struct map *map, struct symbol *sym); | 103 | typedef int (*symbol_filter_t)(struct map *map, struct symbol *sym); |
94 | 104 | ||
95 | void map__init(struct map *map, enum map_type type, | 105 | void map__init(struct map *map, enum map_type type, |
diff --git a/tools/perf/util/perf_regs.c b/tools/perf/util/perf_regs.c new file mode 100644 index 000000000000..a3539ef30b15 --- /dev/null +++ b/tools/perf/util/perf_regs.c | |||
@@ -0,0 +1,19 @@ | |||
1 | #include <errno.h> | ||
2 | #include "perf_regs.h" | ||
3 | |||
4 | int perf_reg_value(u64 *valp, struct regs_dump *regs, int id) | ||
5 | { | ||
6 | int i, idx = 0; | ||
7 | u64 mask = regs->mask; | ||
8 | |||
9 | if (!(mask & (1 << id))) | ||
10 | return -EINVAL; | ||
11 | |||
12 | for (i = 0; i < id; i++) { | ||
13 | if (mask & (1 << i)) | ||
14 | idx++; | ||
15 | } | ||
16 | |||
17 | *valp = regs->regs[idx]; | ||
18 | return 0; | ||
19 | } | ||
diff --git a/tools/perf/util/perf_regs.h b/tools/perf/util/perf_regs.h index a3d42cd74919..d6e8b6a8d7f3 100644 --- a/tools/perf/util/perf_regs.h +++ b/tools/perf/util/perf_regs.h | |||
@@ -1,8 +1,14 @@ | |||
1 | #ifndef __PERF_REGS_H | 1 | #ifndef __PERF_REGS_H |
2 | #define __PERF_REGS_H | 2 | #define __PERF_REGS_H |
3 | 3 | ||
4 | #include "types.h" | ||
5 | #include "event.h" | ||
6 | |||
4 | #ifdef HAVE_PERF_REGS_SUPPORT | 7 | #ifdef HAVE_PERF_REGS_SUPPORT |
5 | #include <perf_regs.h> | 8 | #include <perf_regs.h> |
9 | |||
10 | int perf_reg_value(u64 *valp, struct regs_dump *regs, int id); | ||
11 | |||
6 | #else | 12 | #else |
7 | #define PERF_REGS_MASK 0 | 13 | #define PERF_REGS_MASK 0 |
8 | 14 | ||
@@ -10,5 +16,12 @@ static inline const char *perf_reg_name(int id __maybe_unused) | |||
10 | { | 16 | { |
11 | return NULL; | 17 | return NULL; |
12 | } | 18 | } |
19 | |||
20 | static inline int perf_reg_value(u64 *valp __maybe_unused, | ||
21 | struct regs_dump *regs __maybe_unused, | ||
22 | int id __maybe_unused) | ||
23 | { | ||
24 | return 0; | ||
25 | } | ||
13 | #endif /* HAVE_PERF_REGS_SUPPORT */ | 26 | #endif /* HAVE_PERF_REGS_SUPPORT */ |
14 | #endif /* __PERF_REGS_H */ | 27 | #endif /* __PERF_REGS_H */ |
diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index b752ecb40d86..00a7dcb2f55c 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c | |||
@@ -3,7 +3,7 @@ | |||
3 | #include <unistd.h> | 3 | #include <unistd.h> |
4 | #include <stdio.h> | 4 | #include <stdio.h> |
5 | #include <dirent.h> | 5 | #include <dirent.h> |
6 | #include "fs.h" | 6 | #include <api/fs/fs.h> |
7 | #include <locale.h> | 7 | #include <locale.h> |
8 | #include "util.h" | 8 | #include "util.h" |
9 | #include "pmu.h" | 9 | #include "pmu.h" |
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c index d8b048c20cde..0d1542f33d87 100644 --- a/tools/perf/util/probe-event.c +++ b/tools/perf/util/probe-event.c | |||
@@ -70,34 +70,32 @@ static int e_snprintf(char *str, size_t size, const char *format, ...) | |||
70 | } | 70 | } |
71 | 71 | ||
72 | static char *synthesize_perf_probe_point(struct perf_probe_point *pp); | 72 | static char *synthesize_perf_probe_point(struct perf_probe_point *pp); |
73 | static int convert_name_to_addr(struct perf_probe_event *pev, | ||
74 | const char *exec); | ||
75 | static void clear_probe_trace_event(struct probe_trace_event *tev); | 73 | static void clear_probe_trace_event(struct probe_trace_event *tev); |
76 | static struct machine machine; | 74 | static struct machine *host_machine; |
77 | 75 | ||
78 | /* Initialize symbol maps and path of vmlinux/modules */ | 76 | /* Initialize symbol maps and path of vmlinux/modules */ |
79 | static int init_vmlinux(void) | 77 | static int init_symbol_maps(bool user_only) |
80 | { | 78 | { |
81 | int ret; | 79 | int ret; |
82 | 80 | ||
83 | symbol_conf.sort_by_name = true; | 81 | symbol_conf.sort_by_name = true; |
84 | if (symbol_conf.vmlinux_name == NULL) | ||
85 | symbol_conf.try_vmlinux_path = true; | ||
86 | else | ||
87 | pr_debug("Use vmlinux: %s\n", symbol_conf.vmlinux_name); | ||
88 | ret = symbol__init(); | 82 | ret = symbol__init(); |
89 | if (ret < 0) { | 83 | if (ret < 0) { |
90 | pr_debug("Failed to init symbol map.\n"); | 84 | pr_debug("Failed to init symbol map.\n"); |
91 | goto out; | 85 | goto out; |
92 | } | 86 | } |
93 | 87 | ||
94 | ret = machine__init(&machine, "", HOST_KERNEL_ID); | 88 | if (host_machine || user_only) /* already initialized */ |
95 | if (ret < 0) | 89 | return 0; |
96 | goto out; | ||
97 | 90 | ||
98 | if (machine__create_kernel_maps(&machine) < 0) { | 91 | if (symbol_conf.vmlinux_name) |
99 | pr_debug("machine__create_kernel_maps() failed.\n"); | 92 | pr_debug("Use vmlinux: %s\n", symbol_conf.vmlinux_name); |
100 | goto out; | 93 | |
94 | host_machine = machine__new_host(); | ||
95 | if (!host_machine) { | ||
96 | pr_debug("machine__new_host() failed.\n"); | ||
97 | symbol__exit(); | ||
98 | ret = -1; | ||
101 | } | 99 | } |
102 | out: | 100 | out: |
103 | if (ret < 0) | 101 | if (ret < 0) |
@@ -105,21 +103,66 @@ out: | |||
105 | return ret; | 103 | return ret; |
106 | } | 104 | } |
107 | 105 | ||
106 | static void exit_symbol_maps(void) | ||
107 | { | ||
108 | if (host_machine) { | ||
109 | machine__delete(host_machine); | ||
110 | host_machine = NULL; | ||
111 | } | ||
112 | symbol__exit(); | ||
113 | } | ||
114 | |||
108 | static struct symbol *__find_kernel_function_by_name(const char *name, | 115 | static struct symbol *__find_kernel_function_by_name(const char *name, |
109 | struct map **mapp) | 116 | struct map **mapp) |
110 | { | 117 | { |
111 | return machine__find_kernel_function_by_name(&machine, name, mapp, | 118 | return machine__find_kernel_function_by_name(host_machine, name, mapp, |
112 | NULL); | 119 | NULL); |
113 | } | 120 | } |
114 | 121 | ||
122 | static struct symbol *__find_kernel_function(u64 addr, struct map **mapp) | ||
123 | { | ||
124 | return machine__find_kernel_function(host_machine, addr, mapp, NULL); | ||
125 | } | ||
126 | |||
127 | static struct ref_reloc_sym *kernel_get_ref_reloc_sym(void) | ||
128 | { | ||
129 | /* kmap->ref_reloc_sym should be set if host_machine is initialized */ | ||
130 | struct kmap *kmap; | ||
131 | |||
132 | if (map__load(host_machine->vmlinux_maps[MAP__FUNCTION], NULL) < 0) | ||
133 | return NULL; | ||
134 | |||
135 | kmap = map__kmap(host_machine->vmlinux_maps[MAP__FUNCTION]); | ||
136 | return kmap->ref_reloc_sym; | ||
137 | } | ||
138 | |||
139 | static u64 kernel_get_symbol_address_by_name(const char *name, bool reloc) | ||
140 | { | ||
141 | struct ref_reloc_sym *reloc_sym; | ||
142 | struct symbol *sym; | ||
143 | struct map *map; | ||
144 | |||
145 | /* ref_reloc_sym is just a label. Need a special fix*/ | ||
146 | reloc_sym = kernel_get_ref_reloc_sym(); | ||
147 | if (reloc_sym && strcmp(name, reloc_sym->name) == 0) | ||
148 | return (reloc) ? reloc_sym->addr : reloc_sym->unrelocated_addr; | ||
149 | else { | ||
150 | sym = __find_kernel_function_by_name(name, &map); | ||
151 | if (sym) | ||
152 | return map->unmap_ip(map, sym->start) - | ||
153 | (reloc) ? 0 : map->reloc; | ||
154 | } | ||
155 | return 0; | ||
156 | } | ||
157 | |||
115 | static struct map *kernel_get_module_map(const char *module) | 158 | static struct map *kernel_get_module_map(const char *module) |
116 | { | 159 | { |
117 | struct rb_node *nd; | 160 | struct rb_node *nd; |
118 | struct map_groups *grp = &machine.kmaps; | 161 | struct map_groups *grp = &host_machine->kmaps; |
119 | 162 | ||
120 | /* A file path -- this is an offline module */ | 163 | /* A file path -- this is an offline module */ |
121 | if (module && strchr(module, '/')) | 164 | if (module && strchr(module, '/')) |
122 | return machine__new_module(&machine, 0, module); | 165 | return machine__new_module(host_machine, 0, module); |
123 | 166 | ||
124 | if (!module) | 167 | if (!module) |
125 | module = "kernel"; | 168 | module = "kernel"; |
@@ -141,7 +184,7 @@ static struct dso *kernel_get_module_dso(const char *module) | |||
141 | const char *vmlinux_name; | 184 | const char *vmlinux_name; |
142 | 185 | ||
143 | if (module) { | 186 | if (module) { |
144 | list_for_each_entry(dso, &machine.kernel_dsos, node) { | 187 | list_for_each_entry(dso, &host_machine->kernel_dsos, node) { |
145 | if (strncmp(dso->short_name + 1, module, | 188 | if (strncmp(dso->short_name + 1, module, |
146 | dso->short_name_len - 2) == 0) | 189 | dso->short_name_len - 2) == 0) |
147 | goto found; | 190 | goto found; |
@@ -150,7 +193,7 @@ static struct dso *kernel_get_module_dso(const char *module) | |||
150 | return NULL; | 193 | return NULL; |
151 | } | 194 | } |
152 | 195 | ||
153 | map = machine.vmlinux_maps[MAP__FUNCTION]; | 196 | map = host_machine->vmlinux_maps[MAP__FUNCTION]; |
154 | dso = map->dso; | 197 | dso = map->dso; |
155 | 198 | ||
156 | vmlinux_name = symbol_conf.vmlinux_name; | 199 | vmlinux_name = symbol_conf.vmlinux_name; |
@@ -173,20 +216,6 @@ const char *kernel_get_module_path(const char *module) | |||
173 | return (dso) ? dso->long_name : NULL; | 216 | return (dso) ? dso->long_name : NULL; |
174 | } | 217 | } |
175 | 218 | ||
176 | static int init_user_exec(void) | ||
177 | { | ||
178 | int ret = 0; | ||
179 | |||
180 | symbol_conf.try_vmlinux_path = false; | ||
181 | symbol_conf.sort_by_name = true; | ||
182 | ret = symbol__init(); | ||
183 | |||
184 | if (ret < 0) | ||
185 | pr_debug("Failed to init symbol map.\n"); | ||
186 | |||
187 | return ret; | ||
188 | } | ||
189 | |||
190 | static int convert_exec_to_group(const char *exec, char **result) | 219 | static int convert_exec_to_group(const char *exec, char **result) |
191 | { | 220 | { |
192 | char *ptr1, *ptr2, *exec_copy; | 221 | char *ptr1, *ptr2, *exec_copy; |
@@ -218,32 +247,23 @@ out: | |||
218 | return ret; | 247 | return ret; |
219 | } | 248 | } |
220 | 249 | ||
221 | static int convert_to_perf_probe_point(struct probe_trace_point *tp, | 250 | static void clear_probe_trace_events(struct probe_trace_event *tevs, int ntevs) |
222 | struct perf_probe_point *pp) | ||
223 | { | 251 | { |
224 | pp->function = strdup(tp->symbol); | 252 | int i; |
225 | |||
226 | if (pp->function == NULL) | ||
227 | return -ENOMEM; | ||
228 | |||
229 | pp->offset = tp->offset; | ||
230 | pp->retprobe = tp->retprobe; | ||
231 | 253 | ||
232 | return 0; | 254 | for (i = 0; i < ntevs; i++) |
255 | clear_probe_trace_event(tevs + i); | ||
233 | } | 256 | } |
234 | 257 | ||
235 | #ifdef HAVE_DWARF_SUPPORT | 258 | #ifdef HAVE_DWARF_SUPPORT |
259 | |||
236 | /* Open new debuginfo of given module */ | 260 | /* Open new debuginfo of given module */ |
237 | static struct debuginfo *open_debuginfo(const char *module) | 261 | static struct debuginfo *open_debuginfo(const char *module) |
238 | { | 262 | { |
239 | const char *path; | 263 | const char *path = module; |
240 | 264 | ||
241 | /* A file path -- this is an offline module */ | 265 | if (!module || !strchr(module, '/')) { |
242 | if (module && strchr(module, '/')) | ||
243 | path = module; | ||
244 | else { | ||
245 | path = kernel_get_module_path(module); | 266 | path = kernel_get_module_path(module); |
246 | |||
247 | if (!path) { | 267 | if (!path) { |
248 | pr_err("Failed to find path of %s module.\n", | 268 | pr_err("Failed to find path of %s module.\n", |
249 | module ?: "kernel"); | 269 | module ?: "kernel"); |
@@ -253,46 +273,6 @@ static struct debuginfo *open_debuginfo(const char *module) | |||
253 | return debuginfo__new(path); | 273 | return debuginfo__new(path); |
254 | } | 274 | } |
255 | 275 | ||
256 | /* | ||
257 | * Convert trace point to probe point with debuginfo | ||
258 | * Currently only handles kprobes. | ||
259 | */ | ||
260 | static int kprobe_convert_to_perf_probe(struct probe_trace_point *tp, | ||
261 | struct perf_probe_point *pp) | ||
262 | { | ||
263 | struct symbol *sym; | ||
264 | struct map *map; | ||
265 | u64 addr; | ||
266 | int ret = -ENOENT; | ||
267 | struct debuginfo *dinfo; | ||
268 | |||
269 | sym = __find_kernel_function_by_name(tp->symbol, &map); | ||
270 | if (sym) { | ||
271 | addr = map->unmap_ip(map, sym->start + tp->offset); | ||
272 | pr_debug("try to find %s+%ld@%" PRIx64 "\n", tp->symbol, | ||
273 | tp->offset, addr); | ||
274 | |||
275 | dinfo = debuginfo__new_online_kernel(addr); | ||
276 | if (dinfo) { | ||
277 | ret = debuginfo__find_probe_point(dinfo, | ||
278 | (unsigned long)addr, pp); | ||
279 | debuginfo__delete(dinfo); | ||
280 | } else { | ||
281 | pr_debug("Failed to open debuginfo at 0x%" PRIx64 "\n", | ||
282 | addr); | ||
283 | ret = -ENOENT; | ||
284 | } | ||
285 | } | ||
286 | if (ret <= 0) { | ||
287 | pr_debug("Failed to find corresponding probes from " | ||
288 | "debuginfo. Use kprobe event information.\n"); | ||
289 | return convert_to_perf_probe_point(tp, pp); | ||
290 | } | ||
291 | pp->retprobe = tp->retprobe; | ||
292 | |||
293 | return 0; | ||
294 | } | ||
295 | |||
296 | static int get_text_start_address(const char *exec, unsigned long *address) | 276 | static int get_text_start_address(const char *exec, unsigned long *address) |
297 | { | 277 | { |
298 | Elf *elf; | 278 | Elf *elf; |
@@ -321,12 +301,62 @@ out: | |||
321 | return ret; | 301 | return ret; |
322 | } | 302 | } |
323 | 303 | ||
304 | /* | ||
305 | * Convert trace point to probe point with debuginfo | ||
306 | */ | ||
307 | static int find_perf_probe_point_from_dwarf(struct probe_trace_point *tp, | ||
308 | struct perf_probe_point *pp, | ||
309 | bool is_kprobe) | ||
310 | { | ||
311 | struct debuginfo *dinfo = NULL; | ||
312 | unsigned long stext = 0; | ||
313 | u64 addr = tp->address; | ||
314 | int ret = -ENOENT; | ||
315 | |||
316 | /* convert the address to dwarf address */ | ||
317 | if (!is_kprobe) { | ||
318 | if (!addr) { | ||
319 | ret = -EINVAL; | ||
320 | goto error; | ||
321 | } | ||
322 | ret = get_text_start_address(tp->module, &stext); | ||
323 | if (ret < 0) | ||
324 | goto error; | ||
325 | addr += stext; | ||
326 | } else { | ||
327 | addr = kernel_get_symbol_address_by_name(tp->symbol, false); | ||
328 | if (addr == 0) | ||
329 | goto error; | ||
330 | addr += tp->offset; | ||
331 | } | ||
332 | |||
333 | pr_debug("try to find information at %" PRIx64 " in %s\n", addr, | ||
334 | tp->module ? : "kernel"); | ||
335 | |||
336 | dinfo = open_debuginfo(tp->module); | ||
337 | if (dinfo) { | ||
338 | ret = debuginfo__find_probe_point(dinfo, | ||
339 | (unsigned long)addr, pp); | ||
340 | debuginfo__delete(dinfo); | ||
341 | } else { | ||
342 | pr_debug("Failed to open debuginfo at 0x%" PRIx64 "\n", addr); | ||
343 | ret = -ENOENT; | ||
344 | } | ||
345 | |||
346 | if (ret > 0) { | ||
347 | pp->retprobe = tp->retprobe; | ||
348 | return 0; | ||
349 | } | ||
350 | error: | ||
351 | pr_debug("Failed to find corresponding probes from debuginfo.\n"); | ||
352 | return ret ? : -ENOENT; | ||
353 | } | ||
354 | |||
324 | static int add_exec_to_probe_trace_events(struct probe_trace_event *tevs, | 355 | static int add_exec_to_probe_trace_events(struct probe_trace_event *tevs, |
325 | int ntevs, const char *exec) | 356 | int ntevs, const char *exec) |
326 | { | 357 | { |
327 | int i, ret = 0; | 358 | int i, ret = 0; |
328 | unsigned long offset, stext = 0; | 359 | unsigned long stext = 0; |
329 | char buf[32]; | ||
330 | 360 | ||
331 | if (!exec) | 361 | if (!exec) |
332 | return 0; | 362 | return 0; |
@@ -337,15 +367,9 @@ static int add_exec_to_probe_trace_events(struct probe_trace_event *tevs, | |||
337 | 367 | ||
338 | for (i = 0; i < ntevs && ret >= 0; i++) { | 368 | for (i = 0; i < ntevs && ret >= 0; i++) { |
339 | /* point.address is the addres of point.symbol + point.offset */ | 369 | /* point.address is the addres of point.symbol + point.offset */ |
340 | offset = tevs[i].point.address - stext; | 370 | tevs[i].point.address -= stext; |
341 | tevs[i].point.offset = 0; | ||
342 | zfree(&tevs[i].point.symbol); | ||
343 | ret = e_snprintf(buf, 32, "0x%lx", offset); | ||
344 | if (ret < 0) | ||
345 | break; | ||
346 | tevs[i].point.module = strdup(exec); | 371 | tevs[i].point.module = strdup(exec); |
347 | tevs[i].point.symbol = strdup(buf); | 372 | if (!tevs[i].point.module) { |
348 | if (!tevs[i].point.symbol || !tevs[i].point.module) { | ||
349 | ret = -ENOMEM; | 373 | ret = -ENOMEM; |
350 | break; | 374 | break; |
351 | } | 375 | } |
@@ -388,12 +412,40 @@ static int add_module_to_probe_trace_events(struct probe_trace_event *tevs, | |||
388 | return ret; | 412 | return ret; |
389 | } | 413 | } |
390 | 414 | ||
391 | static void clear_probe_trace_events(struct probe_trace_event *tevs, int ntevs) | 415 | /* Post processing the probe events */ |
416 | static int post_process_probe_trace_events(struct probe_trace_event *tevs, | ||
417 | int ntevs, const char *module, | ||
418 | bool uprobe) | ||
392 | { | 419 | { |
420 | struct ref_reloc_sym *reloc_sym; | ||
421 | char *tmp; | ||
393 | int i; | 422 | int i; |
394 | 423 | ||
395 | for (i = 0; i < ntevs; i++) | 424 | if (uprobe) |
396 | clear_probe_trace_event(tevs + i); | 425 | return add_exec_to_probe_trace_events(tevs, ntevs, module); |
426 | |||
427 | /* Note that currently ref_reloc_sym based probe is not for drivers */ | ||
428 | if (module) | ||
429 | return add_module_to_probe_trace_events(tevs, ntevs, module); | ||
430 | |||
431 | reloc_sym = kernel_get_ref_reloc_sym(); | ||
432 | if (!reloc_sym) { | ||
433 | pr_warning("Relocated base symbol is not found!\n"); | ||
434 | return -EINVAL; | ||
435 | } | ||
436 | |||
437 | for (i = 0; i < ntevs; i++) { | ||
438 | if (tevs[i].point.address) { | ||
439 | tmp = strdup(reloc_sym->name); | ||
440 | if (!tmp) | ||
441 | return -ENOMEM; | ||
442 | free(tevs[i].point.symbol); | ||
443 | tevs[i].point.symbol = tmp; | ||
444 | tevs[i].point.offset = tevs[i].point.address - | ||
445 | reloc_sym->unrelocated_addr; | ||
446 | } | ||
447 | } | ||
448 | return 0; | ||
397 | } | 449 | } |
398 | 450 | ||
399 | /* Try to find perf_probe_event with debuginfo */ | 451 | /* Try to find perf_probe_event with debuginfo */ |
@@ -416,21 +468,16 @@ static int try_to_find_probe_trace_events(struct perf_probe_event *pev, | |||
416 | return 0; | 468 | return 0; |
417 | } | 469 | } |
418 | 470 | ||
471 | pr_debug("Try to find probe point from debuginfo.\n"); | ||
419 | /* Searching trace events corresponding to a probe event */ | 472 | /* Searching trace events corresponding to a probe event */ |
420 | ntevs = debuginfo__find_trace_events(dinfo, pev, tevs, max_tevs); | 473 | ntevs = debuginfo__find_trace_events(dinfo, pev, tevs, max_tevs); |
421 | 474 | ||
422 | debuginfo__delete(dinfo); | 475 | debuginfo__delete(dinfo); |
423 | 476 | ||
424 | if (ntevs > 0) { /* Succeeded to find trace events */ | 477 | if (ntevs > 0) { /* Succeeded to find trace events */ |
425 | pr_debug("find %d probe_trace_events.\n", ntevs); | 478 | pr_debug("Found %d probe_trace_events.\n", ntevs); |
426 | if (target) { | 479 | ret = post_process_probe_trace_events(*tevs, ntevs, |
427 | if (pev->uprobes) | 480 | target, pev->uprobes); |
428 | ret = add_exec_to_probe_trace_events(*tevs, | ||
429 | ntevs, target); | ||
430 | else | ||
431 | ret = add_module_to_probe_trace_events(*tevs, | ||
432 | ntevs, target); | ||
433 | } | ||
434 | if (ret < 0) { | 481 | if (ret < 0) { |
435 | clear_probe_trace_events(*tevs, ntevs); | 482 | clear_probe_trace_events(*tevs, ntevs); |
436 | zfree(tevs); | 483 | zfree(tevs); |
@@ -563,20 +610,16 @@ static int _show_one_line(FILE *fp, int l, bool skip, bool show_num) | |||
563 | * Show line-range always requires debuginfo to find source file and | 610 | * Show line-range always requires debuginfo to find source file and |
564 | * line number. | 611 | * line number. |
565 | */ | 612 | */ |
566 | int show_line_range(struct line_range *lr, const char *module) | 613 | static int __show_line_range(struct line_range *lr, const char *module) |
567 | { | 614 | { |
568 | int l = 1; | 615 | int l = 1; |
569 | struct line_node *ln; | 616 | struct int_node *ln; |
570 | struct debuginfo *dinfo; | 617 | struct debuginfo *dinfo; |
571 | FILE *fp; | 618 | FILE *fp; |
572 | int ret; | 619 | int ret; |
573 | char *tmp; | 620 | char *tmp; |
574 | 621 | ||
575 | /* Search a line range */ | 622 | /* Search a line range */ |
576 | ret = init_vmlinux(); | ||
577 | if (ret < 0) | ||
578 | return ret; | ||
579 | |||
580 | dinfo = open_debuginfo(module); | 623 | dinfo = open_debuginfo(module); |
581 | if (!dinfo) { | 624 | if (!dinfo) { |
582 | pr_warning("Failed to open debuginfo file.\n"); | 625 | pr_warning("Failed to open debuginfo file.\n"); |
@@ -623,8 +666,8 @@ int show_line_range(struct line_range *lr, const char *module) | |||
623 | goto end; | 666 | goto end; |
624 | } | 667 | } |
625 | 668 | ||
626 | list_for_each_entry(ln, &lr->line_list, list) { | 669 | intlist__for_each(ln, lr->line_list) { |
627 | for (; ln->line > l; l++) { | 670 | for (; ln->i > l; l++) { |
628 | ret = show_one_line(fp, l - lr->offset); | 671 | ret = show_one_line(fp, l - lr->offset); |
629 | if (ret < 0) | 672 | if (ret < 0) |
630 | goto end; | 673 | goto end; |
@@ -646,6 +689,19 @@ end: | |||
646 | return ret; | 689 | return ret; |
647 | } | 690 | } |
648 | 691 | ||
692 | int show_line_range(struct line_range *lr, const char *module) | ||
693 | { | ||
694 | int ret; | ||
695 | |||
696 | ret = init_symbol_maps(false); | ||
697 | if (ret < 0) | ||
698 | return ret; | ||
699 | ret = __show_line_range(lr, module); | ||
700 | exit_symbol_maps(); | ||
701 | |||
702 | return ret; | ||
703 | } | ||
704 | |||
649 | static int show_available_vars_at(struct debuginfo *dinfo, | 705 | static int show_available_vars_at(struct debuginfo *dinfo, |
650 | struct perf_probe_event *pev, | 706 | struct perf_probe_event *pev, |
651 | int max_vls, struct strfilter *_filter, | 707 | int max_vls, struct strfilter *_filter, |
@@ -707,14 +763,15 @@ int show_available_vars(struct perf_probe_event *pevs, int npevs, | |||
707 | int i, ret = 0; | 763 | int i, ret = 0; |
708 | struct debuginfo *dinfo; | 764 | struct debuginfo *dinfo; |
709 | 765 | ||
710 | ret = init_vmlinux(); | 766 | ret = init_symbol_maps(false); |
711 | if (ret < 0) | 767 | if (ret < 0) |
712 | return ret; | 768 | return ret; |
713 | 769 | ||
714 | dinfo = open_debuginfo(module); | 770 | dinfo = open_debuginfo(module); |
715 | if (!dinfo) { | 771 | if (!dinfo) { |
716 | pr_warning("Failed to open debuginfo file.\n"); | 772 | pr_warning("Failed to open debuginfo file.\n"); |
717 | return -ENOENT; | 773 | ret = -ENOENT; |
774 | goto out; | ||
718 | } | 775 | } |
719 | 776 | ||
720 | setup_pager(); | 777 | setup_pager(); |
@@ -724,23 +781,19 @@ int show_available_vars(struct perf_probe_event *pevs, int npevs, | |||
724 | externs); | 781 | externs); |
725 | 782 | ||
726 | debuginfo__delete(dinfo); | 783 | debuginfo__delete(dinfo); |
784 | out: | ||
785 | exit_symbol_maps(); | ||
727 | return ret; | 786 | return ret; |
728 | } | 787 | } |
729 | 788 | ||
730 | #else /* !HAVE_DWARF_SUPPORT */ | 789 | #else /* !HAVE_DWARF_SUPPORT */ |
731 | 790 | ||
732 | static int kprobe_convert_to_perf_probe(struct probe_trace_point *tp, | 791 | static int |
733 | struct perf_probe_point *pp) | 792 | find_perf_probe_point_from_dwarf(struct probe_trace_point *tp __maybe_unused, |
793 | struct perf_probe_point *pp __maybe_unused, | ||
794 | bool is_kprobe __maybe_unused) | ||
734 | { | 795 | { |
735 | struct symbol *sym; | 796 | return -ENOSYS; |
736 | |||
737 | sym = __find_kernel_function_by_name(tp->symbol, NULL); | ||
738 | if (!sym) { | ||
739 | pr_err("Failed to find symbol %s in kernel.\n", tp->symbol); | ||
740 | return -ENOENT; | ||
741 | } | ||
742 | |||
743 | return convert_to_perf_probe_point(tp, pp); | ||
744 | } | 797 | } |
745 | 798 | ||
746 | static int try_to_find_probe_trace_events(struct perf_probe_event *pev, | 799 | static int try_to_find_probe_trace_events(struct perf_probe_event *pev, |
@@ -776,24 +829,22 @@ int show_available_vars(struct perf_probe_event *pevs __maybe_unused, | |||
776 | 829 | ||
777 | void line_range__clear(struct line_range *lr) | 830 | void line_range__clear(struct line_range *lr) |
778 | { | 831 | { |
779 | struct line_node *ln; | ||
780 | |||
781 | free(lr->function); | 832 | free(lr->function); |
782 | free(lr->file); | 833 | free(lr->file); |
783 | free(lr->path); | 834 | free(lr->path); |
784 | free(lr->comp_dir); | 835 | free(lr->comp_dir); |
785 | while (!list_empty(&lr->line_list)) { | 836 | intlist__delete(lr->line_list); |
786 | ln = list_first_entry(&lr->line_list, struct line_node, list); | ||
787 | list_del(&ln->list); | ||
788 | free(ln); | ||
789 | } | ||
790 | memset(lr, 0, sizeof(*lr)); | 837 | memset(lr, 0, sizeof(*lr)); |
791 | } | 838 | } |
792 | 839 | ||
793 | void line_range__init(struct line_range *lr) | 840 | int line_range__init(struct line_range *lr) |
794 | { | 841 | { |
795 | memset(lr, 0, sizeof(*lr)); | 842 | memset(lr, 0, sizeof(*lr)); |
796 | INIT_LIST_HEAD(&lr->line_list); | 843 | lr->line_list = intlist__new(NULL); |
844 | if (!lr->line_list) | ||
845 | return -ENOMEM; | ||
846 | else | ||
847 | return 0; | ||
797 | } | 848 | } |
798 | 849 | ||
799 | static int parse_line_num(char **ptr, int *val, const char *what) | 850 | static int parse_line_num(char **ptr, int *val, const char *what) |
@@ -1267,16 +1318,21 @@ static int parse_probe_trace_command(const char *cmd, | |||
1267 | } else | 1318 | } else |
1268 | p = argv[1]; | 1319 | p = argv[1]; |
1269 | fmt1_str = strtok_r(p, "+", &fmt); | 1320 | fmt1_str = strtok_r(p, "+", &fmt); |
1270 | tp->symbol = strdup(fmt1_str); | 1321 | if (fmt1_str[0] == '0') /* only the address started with 0x */ |
1271 | if (tp->symbol == NULL) { | 1322 | tp->address = strtoul(fmt1_str, NULL, 0); |
1272 | ret = -ENOMEM; | 1323 | else { |
1273 | goto out; | 1324 | /* Only the symbol-based probe has offset */ |
1325 | tp->symbol = strdup(fmt1_str); | ||
1326 | if (tp->symbol == NULL) { | ||
1327 | ret = -ENOMEM; | ||
1328 | goto out; | ||
1329 | } | ||
1330 | fmt2_str = strtok_r(NULL, "", &fmt); | ||
1331 | if (fmt2_str == NULL) | ||
1332 | tp->offset = 0; | ||
1333 | else | ||
1334 | tp->offset = strtoul(fmt2_str, NULL, 10); | ||
1274 | } | 1335 | } |
1275 | fmt2_str = strtok_r(NULL, "", &fmt); | ||
1276 | if (fmt2_str == NULL) | ||
1277 | tp->offset = 0; | ||
1278 | else | ||
1279 | tp->offset = strtoul(fmt2_str, NULL, 10); | ||
1280 | 1336 | ||
1281 | tev->nargs = argc - 2; | 1337 | tev->nargs = argc - 2; |
1282 | tev->args = zalloc(sizeof(struct probe_trace_arg) * tev->nargs); | 1338 | tev->args = zalloc(sizeof(struct probe_trace_arg) * tev->nargs); |
@@ -1518,20 +1574,27 @@ char *synthesize_probe_trace_command(struct probe_trace_event *tev) | |||
1518 | if (buf == NULL) | 1574 | if (buf == NULL) |
1519 | return NULL; | 1575 | return NULL; |
1520 | 1576 | ||
1577 | len = e_snprintf(buf, MAX_CMDLEN, "%c:%s/%s ", tp->retprobe ? 'r' : 'p', | ||
1578 | tev->group, tev->event); | ||
1579 | if (len <= 0) | ||
1580 | goto error; | ||
1581 | |||
1582 | /* Uprobes must have tp->address and tp->module */ | ||
1583 | if (tev->uprobes && (!tp->address || !tp->module)) | ||
1584 | goto error; | ||
1585 | |||
1586 | /* Use the tp->address for uprobes */ | ||
1521 | if (tev->uprobes) | 1587 | if (tev->uprobes) |
1522 | len = e_snprintf(buf, MAX_CMDLEN, "%c:%s/%s %s:%s", | 1588 | ret = e_snprintf(buf + len, MAX_CMDLEN - len, "%s:0x%lx", |
1523 | tp->retprobe ? 'r' : 'p', | 1589 | tp->module, tp->address); |
1524 | tev->group, tev->event, | ||
1525 | tp->module, tp->symbol); | ||
1526 | else | 1590 | else |
1527 | len = e_snprintf(buf, MAX_CMDLEN, "%c:%s/%s %s%s%s+%lu", | 1591 | ret = e_snprintf(buf + len, MAX_CMDLEN - len, "%s%s%s+%lu", |
1528 | tp->retprobe ? 'r' : 'p', | ||
1529 | tev->group, tev->event, | ||
1530 | tp->module ?: "", tp->module ? ":" : "", | 1592 | tp->module ?: "", tp->module ? ":" : "", |
1531 | tp->symbol, tp->offset); | 1593 | tp->symbol, tp->offset); |
1532 | 1594 | ||
1533 | if (len <= 0) | 1595 | if (ret <= 0) |
1534 | goto error; | 1596 | goto error; |
1597 | len += ret; | ||
1535 | 1598 | ||
1536 | for (i = 0; i < tev->nargs; i++) { | 1599 | for (i = 0; i < tev->nargs; i++) { |
1537 | ret = synthesize_probe_trace_arg(&tev->args[i], buf + len, | 1600 | ret = synthesize_probe_trace_arg(&tev->args[i], buf + len, |
@@ -1547,6 +1610,79 @@ error: | |||
1547 | return NULL; | 1610 | return NULL; |
1548 | } | 1611 | } |
1549 | 1612 | ||
1613 | static int find_perf_probe_point_from_map(struct probe_trace_point *tp, | ||
1614 | struct perf_probe_point *pp, | ||
1615 | bool is_kprobe) | ||
1616 | { | ||
1617 | struct symbol *sym = NULL; | ||
1618 | struct map *map; | ||
1619 | u64 addr; | ||
1620 | int ret = -ENOENT; | ||
1621 | |||
1622 | if (!is_kprobe) { | ||
1623 | map = dso__new_map(tp->module); | ||
1624 | if (!map) | ||
1625 | goto out; | ||
1626 | addr = tp->address; | ||
1627 | sym = map__find_symbol(map, addr, NULL); | ||
1628 | } else { | ||
1629 | addr = kernel_get_symbol_address_by_name(tp->symbol, true); | ||
1630 | if (addr) { | ||
1631 | addr += tp->offset; | ||
1632 | sym = __find_kernel_function(addr, &map); | ||
1633 | } | ||
1634 | } | ||
1635 | if (!sym) | ||
1636 | goto out; | ||
1637 | |||
1638 | pp->retprobe = tp->retprobe; | ||
1639 | pp->offset = addr - map->unmap_ip(map, sym->start); | ||
1640 | pp->function = strdup(sym->name); | ||
1641 | ret = pp->function ? 0 : -ENOMEM; | ||
1642 | |||
1643 | out: | ||
1644 | if (map && !is_kprobe) { | ||
1645 | dso__delete(map->dso); | ||
1646 | map__delete(map); | ||
1647 | } | ||
1648 | |||
1649 | return ret; | ||
1650 | } | ||
1651 | |||
1652 | static int convert_to_perf_probe_point(struct probe_trace_point *tp, | ||
1653 | struct perf_probe_point *pp, | ||
1654 | bool is_kprobe) | ||
1655 | { | ||
1656 | char buf[128]; | ||
1657 | int ret; | ||
1658 | |||
1659 | ret = find_perf_probe_point_from_dwarf(tp, pp, is_kprobe); | ||
1660 | if (!ret) | ||
1661 | return 0; | ||
1662 | ret = find_perf_probe_point_from_map(tp, pp, is_kprobe); | ||
1663 | if (!ret) | ||
1664 | return 0; | ||
1665 | |||
1666 | pr_debug("Failed to find probe point from both of dwarf and map.\n"); | ||
1667 | |||
1668 | if (tp->symbol) { | ||
1669 | pp->function = strdup(tp->symbol); | ||
1670 | pp->offset = tp->offset; | ||
1671 | } else if (!tp->module && !is_kprobe) { | ||
1672 | ret = e_snprintf(buf, 128, "0x%" PRIx64, (u64)tp->address); | ||
1673 | if (ret < 0) | ||
1674 | return ret; | ||
1675 | pp->function = strdup(buf); | ||
1676 | pp->offset = 0; | ||
1677 | } | ||
1678 | if (pp->function == NULL) | ||
1679 | return -ENOMEM; | ||
1680 | |||
1681 | pp->retprobe = tp->retprobe; | ||
1682 | |||
1683 | return 0; | ||
1684 | } | ||
1685 | |||
1550 | static int convert_to_perf_probe_event(struct probe_trace_event *tev, | 1686 | static int convert_to_perf_probe_event(struct probe_trace_event *tev, |
1551 | struct perf_probe_event *pev, bool is_kprobe) | 1687 | struct perf_probe_event *pev, bool is_kprobe) |
1552 | { | 1688 | { |
@@ -1560,11 +1696,7 @@ static int convert_to_perf_probe_event(struct probe_trace_event *tev, | |||
1560 | return -ENOMEM; | 1696 | return -ENOMEM; |
1561 | 1697 | ||
1562 | /* Convert trace_point to probe_point */ | 1698 | /* Convert trace_point to probe_point */ |
1563 | if (is_kprobe) | 1699 | ret = convert_to_perf_probe_point(&tev->point, &pev->point, is_kprobe); |
1564 | ret = kprobe_convert_to_perf_probe(&tev->point, &pev->point); | ||
1565 | else | ||
1566 | ret = convert_to_perf_probe_point(&tev->point, &pev->point); | ||
1567 | |||
1568 | if (ret < 0) | 1700 | if (ret < 0) |
1569 | return ret; | 1701 | return ret; |
1570 | 1702 | ||
@@ -1731,7 +1863,8 @@ static struct strlist *get_probe_trace_command_rawlist(int fd) | |||
1731 | } | 1863 | } |
1732 | 1864 | ||
1733 | /* Show an event */ | 1865 | /* Show an event */ |
1734 | static int show_perf_probe_event(struct perf_probe_event *pev) | 1866 | static int show_perf_probe_event(struct perf_probe_event *pev, |
1867 | const char *module) | ||
1735 | { | 1868 | { |
1736 | int i, ret; | 1869 | int i, ret; |
1737 | char buf[128]; | 1870 | char buf[128]; |
@@ -1747,6 +1880,8 @@ static int show_perf_probe_event(struct perf_probe_event *pev) | |||
1747 | return ret; | 1880 | return ret; |
1748 | 1881 | ||
1749 | printf(" %-20s (on %s", buf, place); | 1882 | printf(" %-20s (on %s", buf, place); |
1883 | if (module) | ||
1884 | printf(" in %s", module); | ||
1750 | 1885 | ||
1751 | if (pev->nargs > 0) { | 1886 | if (pev->nargs > 0) { |
1752 | printf(" with"); | 1887 | printf(" with"); |
@@ -1784,7 +1919,8 @@ static int __show_perf_probe_events(int fd, bool is_kprobe) | |||
1784 | ret = convert_to_perf_probe_event(&tev, &pev, | 1919 | ret = convert_to_perf_probe_event(&tev, &pev, |
1785 | is_kprobe); | 1920 | is_kprobe); |
1786 | if (ret >= 0) | 1921 | if (ret >= 0) |
1787 | ret = show_perf_probe_event(&pev); | 1922 | ret = show_perf_probe_event(&pev, |
1923 | tev.point.module); | ||
1788 | } | 1924 | } |
1789 | clear_perf_probe_event(&pev); | 1925 | clear_perf_probe_event(&pev); |
1790 | clear_probe_trace_event(&tev); | 1926 | clear_probe_trace_event(&tev); |
@@ -1807,7 +1943,7 @@ int show_perf_probe_events(void) | |||
1807 | if (fd < 0) | 1943 | if (fd < 0) |
1808 | return fd; | 1944 | return fd; |
1809 | 1945 | ||
1810 | ret = init_vmlinux(); | 1946 | ret = init_symbol_maps(false); |
1811 | if (ret < 0) | 1947 | if (ret < 0) |
1812 | return ret; | 1948 | return ret; |
1813 | 1949 | ||
@@ -1820,6 +1956,7 @@ int show_perf_probe_events(void) | |||
1820 | close(fd); | 1956 | close(fd); |
1821 | } | 1957 | } |
1822 | 1958 | ||
1959 | exit_symbol_maps(); | ||
1823 | return ret; | 1960 | return ret; |
1824 | } | 1961 | } |
1825 | 1962 | ||
@@ -1982,7 +2119,7 @@ static int __add_probe_trace_events(struct perf_probe_event *pev, | |||
1982 | group = pev->group; | 2119 | group = pev->group; |
1983 | pev->event = tev->event; | 2120 | pev->event = tev->event; |
1984 | pev->group = tev->group; | 2121 | pev->group = tev->group; |
1985 | show_perf_probe_event(pev); | 2122 | show_perf_probe_event(pev, tev->point.module); |
1986 | /* Trick here - restore current event/group */ | 2123 | /* Trick here - restore current event/group */ |
1987 | pev->event = (char *)event; | 2124 | pev->event = (char *)event; |
1988 | pev->group = (char *)group; | 2125 | pev->group = (char *)group; |
@@ -2008,113 +2145,175 @@ static int __add_probe_trace_events(struct perf_probe_event *pev, | |||
2008 | return ret; | 2145 | return ret; |
2009 | } | 2146 | } |
2010 | 2147 | ||
2011 | static int convert_to_probe_trace_events(struct perf_probe_event *pev, | 2148 | static char *looking_function_name; |
2012 | struct probe_trace_event **tevs, | 2149 | static int num_matched_functions; |
2013 | int max_tevs, const char *target) | 2150 | |
2151 | static int probe_function_filter(struct map *map __maybe_unused, | ||
2152 | struct symbol *sym) | ||
2014 | { | 2153 | { |
2154 | if ((sym->binding == STB_GLOBAL || sym->binding == STB_LOCAL) && | ||
2155 | strcmp(looking_function_name, sym->name) == 0) { | ||
2156 | num_matched_functions++; | ||
2157 | return 0; | ||
2158 | } | ||
2159 | return 1; | ||
2160 | } | ||
2161 | |||
2162 | #define strdup_or_goto(str, label) \ | ||
2163 | ({ char *__p = strdup(str); if (!__p) goto label; __p; }) | ||
2164 | |||
2165 | /* | ||
2166 | * Find probe function addresses from map. | ||
2167 | * Return an error or the number of found probe_trace_event | ||
2168 | */ | ||
2169 | static int find_probe_trace_events_from_map(struct perf_probe_event *pev, | ||
2170 | struct probe_trace_event **tevs, | ||
2171 | int max_tevs, const char *target) | ||
2172 | { | ||
2173 | struct map *map = NULL; | ||
2174 | struct kmap *kmap = NULL; | ||
2175 | struct ref_reloc_sym *reloc_sym = NULL; | ||
2015 | struct symbol *sym; | 2176 | struct symbol *sym; |
2016 | int ret, i; | 2177 | struct rb_node *nd; |
2017 | struct probe_trace_event *tev; | 2178 | struct probe_trace_event *tev; |
2179 | struct perf_probe_point *pp = &pev->point; | ||
2180 | struct probe_trace_point *tp; | ||
2181 | int ret, i; | ||
2018 | 2182 | ||
2019 | if (pev->uprobes && !pev->group) { | 2183 | /* Init maps of given executable or kernel */ |
2020 | /* Replace group name if not given */ | 2184 | if (pev->uprobes) |
2021 | ret = convert_exec_to_group(target, &pev->group); | 2185 | map = dso__new_map(target); |
2022 | if (ret != 0) { | 2186 | else |
2023 | pr_warning("Failed to make a group name.\n"); | 2187 | map = kernel_get_module_map(target); |
2024 | return ret; | 2188 | if (!map) { |
2025 | } | 2189 | ret = -EINVAL; |
2190 | goto out; | ||
2026 | } | 2191 | } |
2027 | 2192 | ||
2028 | /* Convert perf_probe_event with debuginfo */ | 2193 | /* |
2029 | ret = try_to_find_probe_trace_events(pev, tevs, max_tevs, target); | 2194 | * Load matched symbols: Since the different local symbols may have |
2030 | if (ret != 0) | 2195 | * same name but different addresses, this lists all the symbols. |
2031 | return ret; /* Found in debuginfo or got an error */ | 2196 | */ |
2032 | 2197 | num_matched_functions = 0; | |
2033 | if (pev->uprobes) { | 2198 | looking_function_name = pp->function; |
2034 | ret = convert_name_to_addr(pev, target); | 2199 | ret = map__load(map, probe_function_filter); |
2035 | if (ret < 0) | 2200 | if (ret || num_matched_functions == 0) { |
2036 | return ret; | 2201 | pr_err("Failed to find symbol %s in %s\n", pp->function, |
2202 | target ? : "kernel"); | ||
2203 | ret = -ENOENT; | ||
2204 | goto out; | ||
2205 | } else if (num_matched_functions > max_tevs) { | ||
2206 | pr_err("Too many functions matched in %s\n", | ||
2207 | target ? : "kernel"); | ||
2208 | ret = -E2BIG; | ||
2209 | goto out; | ||
2037 | } | 2210 | } |
2038 | 2211 | ||
2039 | /* Allocate trace event buffer */ | 2212 | if (!pev->uprobes) { |
2040 | tev = *tevs = zalloc(sizeof(struct probe_trace_event)); | 2213 | kmap = map__kmap(map); |
2041 | if (tev == NULL) | 2214 | reloc_sym = kmap->ref_reloc_sym; |
2042 | return -ENOMEM; | 2215 | if (!reloc_sym) { |
2216 | pr_warning("Relocated base symbol is not found!\n"); | ||
2217 | ret = -EINVAL; | ||
2218 | goto out; | ||
2219 | } | ||
2220 | } | ||
2043 | 2221 | ||
2044 | /* Copy parameters */ | 2222 | /* Setup result trace-probe-events */ |
2045 | tev->point.symbol = strdup(pev->point.function); | 2223 | *tevs = zalloc(sizeof(*tev) * num_matched_functions); |
2046 | if (tev->point.symbol == NULL) { | 2224 | if (!*tevs) { |
2047 | ret = -ENOMEM; | 2225 | ret = -ENOMEM; |
2048 | goto error; | 2226 | goto out; |
2049 | } | 2227 | } |
2050 | 2228 | ||
2051 | if (target) { | 2229 | ret = 0; |
2052 | tev->point.module = strdup(target); | 2230 | map__for_each_symbol(map, sym, nd) { |
2053 | if (tev->point.module == NULL) { | 2231 | tev = (*tevs) + ret; |
2054 | ret = -ENOMEM; | 2232 | tp = &tev->point; |
2055 | goto error; | 2233 | if (ret == num_matched_functions) { |
2234 | pr_warning("Too many symbols are listed. Skip it.\n"); | ||
2235 | break; | ||
2056 | } | 2236 | } |
2057 | } | 2237 | ret++; |
2058 | |||
2059 | tev->point.offset = pev->point.offset; | ||
2060 | tev->point.retprobe = pev->point.retprobe; | ||
2061 | tev->nargs = pev->nargs; | ||
2062 | tev->uprobes = pev->uprobes; | ||
2063 | 2238 | ||
2064 | if (tev->nargs) { | 2239 | if (pp->offset > sym->end - sym->start) { |
2065 | tev->args = zalloc(sizeof(struct probe_trace_arg) | 2240 | pr_warning("Offset %ld is bigger than the size of %s\n", |
2066 | * tev->nargs); | 2241 | pp->offset, sym->name); |
2067 | if (tev->args == NULL) { | 2242 | ret = -ENOENT; |
2068 | ret = -ENOMEM; | 2243 | goto err_out; |
2069 | goto error; | 2244 | } |
2245 | /* Add one probe point */ | ||
2246 | tp->address = map->unmap_ip(map, sym->start) + pp->offset; | ||
2247 | if (reloc_sym) { | ||
2248 | tp->symbol = strdup_or_goto(reloc_sym->name, nomem_out); | ||
2249 | tp->offset = tp->address - reloc_sym->addr; | ||
2250 | } else { | ||
2251 | tp->symbol = strdup_or_goto(sym->name, nomem_out); | ||
2252 | tp->offset = pp->offset; | ||
2253 | } | ||
2254 | tp->retprobe = pp->retprobe; | ||
2255 | if (target) | ||
2256 | tev->point.module = strdup_or_goto(target, nomem_out); | ||
2257 | tev->uprobes = pev->uprobes; | ||
2258 | tev->nargs = pev->nargs; | ||
2259 | if (tev->nargs) { | ||
2260 | tev->args = zalloc(sizeof(struct probe_trace_arg) * | ||
2261 | tev->nargs); | ||
2262 | if (tev->args == NULL) | ||
2263 | goto nomem_out; | ||
2070 | } | 2264 | } |
2071 | for (i = 0; i < tev->nargs; i++) { | 2265 | for (i = 0; i < tev->nargs; i++) { |
2072 | if (pev->args[i].name) { | 2266 | if (pev->args[i].name) |
2073 | tev->args[i].name = strdup(pev->args[i].name); | 2267 | tev->args[i].name = |
2074 | if (tev->args[i].name == NULL) { | 2268 | strdup_or_goto(pev->args[i].name, |
2075 | ret = -ENOMEM; | 2269 | nomem_out); |
2076 | goto error; | 2270 | |
2077 | } | 2271 | tev->args[i].value = strdup_or_goto(pev->args[i].var, |
2078 | } | 2272 | nomem_out); |
2079 | tev->args[i].value = strdup(pev->args[i].var); | 2273 | if (pev->args[i].type) |
2080 | if (tev->args[i].value == NULL) { | 2274 | tev->args[i].type = |
2081 | ret = -ENOMEM; | 2275 | strdup_or_goto(pev->args[i].type, |
2082 | goto error; | 2276 | nomem_out); |
2083 | } | ||
2084 | if (pev->args[i].type) { | ||
2085 | tev->args[i].type = strdup(pev->args[i].type); | ||
2086 | if (tev->args[i].type == NULL) { | ||
2087 | ret = -ENOMEM; | ||
2088 | goto error; | ||
2089 | } | ||
2090 | } | ||
2091 | } | 2277 | } |
2092 | } | 2278 | } |
2093 | 2279 | ||
2094 | if (pev->uprobes) | 2280 | out: |
2095 | return 1; | 2281 | if (map && pev->uprobes) { |
2282 | /* Only when using uprobe(exec) map needs to be released */ | ||
2283 | dso__delete(map->dso); | ||
2284 | map__delete(map); | ||
2285 | } | ||
2286 | return ret; | ||
2096 | 2287 | ||
2097 | /* Currently just checking function name from symbol map */ | 2288 | nomem_out: |
2098 | sym = __find_kernel_function_by_name(tev->point.symbol, NULL); | 2289 | ret = -ENOMEM; |
2099 | if (!sym) { | 2290 | err_out: |
2100 | pr_warning("Kernel symbol \'%s\' not found.\n", | 2291 | clear_probe_trace_events(*tevs, num_matched_functions); |
2101 | tev->point.symbol); | 2292 | zfree(tevs); |
2102 | ret = -ENOENT; | 2293 | goto out; |
2103 | goto error; | 2294 | } |
2104 | } else if (tev->point.offset > sym->end - sym->start) { | 2295 | |
2105 | pr_warning("Offset specified is greater than size of %s\n", | 2296 | static int convert_to_probe_trace_events(struct perf_probe_event *pev, |
2106 | tev->point.symbol); | 2297 | struct probe_trace_event **tevs, |
2107 | ret = -ENOENT; | 2298 | int max_tevs, const char *target) |
2108 | goto error; | 2299 | { |
2300 | int ret; | ||
2109 | 2301 | ||
2302 | if (pev->uprobes && !pev->group) { | ||
2303 | /* Replace group name if not given */ | ||
2304 | ret = convert_exec_to_group(target, &pev->group); | ||
2305 | if (ret != 0) { | ||
2306 | pr_warning("Failed to make a group name.\n"); | ||
2307 | return ret; | ||
2308 | } | ||
2110 | } | 2309 | } |
2111 | 2310 | ||
2112 | return 1; | 2311 | /* Convert perf_probe_event with debuginfo */ |
2113 | error: | 2312 | ret = try_to_find_probe_trace_events(pev, tevs, max_tevs, target); |
2114 | clear_probe_trace_event(tev); | 2313 | if (ret != 0) |
2115 | free(tev); | 2314 | return ret; /* Found in debuginfo or got an error */ |
2116 | *tevs = NULL; | 2315 | |
2117 | return ret; | 2316 | return find_probe_trace_events_from_map(pev, tevs, max_tevs, target); |
2118 | } | 2317 | } |
2119 | 2318 | ||
2120 | struct __event_package { | 2319 | struct __event_package { |
@@ -2135,12 +2334,7 @@ int add_perf_probe_events(struct perf_probe_event *pevs, int npevs, | |||
2135 | if (pkgs == NULL) | 2334 | if (pkgs == NULL) |
2136 | return -ENOMEM; | 2335 | return -ENOMEM; |
2137 | 2336 | ||
2138 | if (!pevs->uprobes) | 2337 | ret = init_symbol_maps(pevs->uprobes); |
2139 | /* Init vmlinux path */ | ||
2140 | ret = init_vmlinux(); | ||
2141 | else | ||
2142 | ret = init_user_exec(); | ||
2143 | |||
2144 | if (ret < 0) { | 2338 | if (ret < 0) { |
2145 | free(pkgs); | 2339 | free(pkgs); |
2146 | return ret; | 2340 | return ret; |
@@ -2174,6 +2368,7 @@ end: | |||
2174 | zfree(&pkgs[i].tevs); | 2368 | zfree(&pkgs[i].tevs); |
2175 | } | 2369 | } |
2176 | free(pkgs); | 2370 | free(pkgs); |
2371 | exit_symbol_maps(); | ||
2177 | 2372 | ||
2178 | return ret; | 2373 | return ret; |
2179 | } | 2374 | } |
@@ -2323,159 +2518,51 @@ static struct strfilter *available_func_filter; | |||
2323 | static int filter_available_functions(struct map *map __maybe_unused, | 2518 | static int filter_available_functions(struct map *map __maybe_unused, |
2324 | struct symbol *sym) | 2519 | struct symbol *sym) |
2325 | { | 2520 | { |
2326 | if (sym->binding == STB_GLOBAL && | 2521 | if ((sym->binding == STB_GLOBAL || sym->binding == STB_LOCAL) && |
2327 | strfilter__compare(available_func_filter, sym->name)) | 2522 | strfilter__compare(available_func_filter, sym->name)) |
2328 | return 0; | 2523 | return 0; |
2329 | return 1; | 2524 | return 1; |
2330 | } | 2525 | } |
2331 | 2526 | ||
2332 | static int __show_available_funcs(struct map *map) | 2527 | int show_available_funcs(const char *target, struct strfilter *_filter, |
2333 | { | 2528 | bool user) |
2334 | if (map__load(map, filter_available_functions)) { | ||
2335 | pr_err("Failed to load map.\n"); | ||
2336 | return -EINVAL; | ||
2337 | } | ||
2338 | if (!dso__sorted_by_name(map->dso, map->type)) | ||
2339 | dso__sort_by_name(map->dso, map->type); | ||
2340 | |||
2341 | dso__fprintf_symbols_by_name(map->dso, map->type, stdout); | ||
2342 | return 0; | ||
2343 | } | ||
2344 | |||
2345 | static int available_kernel_funcs(const char *module) | ||
2346 | { | 2529 | { |
2347 | struct map *map; | 2530 | struct map *map; |
2348 | int ret; | 2531 | int ret; |
2349 | 2532 | ||
2350 | ret = init_vmlinux(); | 2533 | ret = init_symbol_maps(user); |
2351 | if (ret < 0) | 2534 | if (ret < 0) |
2352 | return ret; | 2535 | return ret; |
2353 | 2536 | ||
2354 | map = kernel_get_module_map(module); | 2537 | /* Get a symbol map */ |
2538 | if (user) | ||
2539 | map = dso__new_map(target); | ||
2540 | else | ||
2541 | map = kernel_get_module_map(target); | ||
2355 | if (!map) { | 2542 | if (!map) { |
2356 | pr_err("Failed to find %s map.\n", (module) ? : "kernel"); | 2543 | pr_err("Failed to get a map for %s\n", (target) ? : "kernel"); |
2357 | return -EINVAL; | 2544 | return -EINVAL; |
2358 | } | 2545 | } |
2359 | return __show_available_funcs(map); | ||
2360 | } | ||
2361 | |||
2362 | static int available_user_funcs(const char *target) | ||
2363 | { | ||
2364 | struct map *map; | ||
2365 | int ret; | ||
2366 | |||
2367 | ret = init_user_exec(); | ||
2368 | if (ret < 0) | ||
2369 | return ret; | ||
2370 | |||
2371 | map = dso__new_map(target); | ||
2372 | ret = __show_available_funcs(map); | ||
2373 | dso__delete(map->dso); | ||
2374 | map__delete(map); | ||
2375 | return ret; | ||
2376 | } | ||
2377 | 2546 | ||
2378 | int show_available_funcs(const char *target, struct strfilter *_filter, | 2547 | /* Load symbols with given filter */ |
2379 | bool user) | ||
2380 | { | ||
2381 | setup_pager(); | ||
2382 | available_func_filter = _filter; | 2548 | available_func_filter = _filter; |
2383 | |||
2384 | if (!user) | ||
2385 | return available_kernel_funcs(target); | ||
2386 | |||
2387 | return available_user_funcs(target); | ||
2388 | } | ||
2389 | |||
2390 | /* | ||
2391 | * uprobe_events only accepts address: | ||
2392 | * Convert function and any offset to address | ||
2393 | */ | ||
2394 | static int convert_name_to_addr(struct perf_probe_event *pev, const char *exec) | ||
2395 | { | ||
2396 | struct perf_probe_point *pp = &pev->point; | ||
2397 | struct symbol *sym; | ||
2398 | struct map *map = NULL; | ||
2399 | char *function = NULL; | ||
2400 | int ret = -EINVAL; | ||
2401 | unsigned long long vaddr = 0; | ||
2402 | |||
2403 | if (!pp->function) { | ||
2404 | pr_warning("No function specified for uprobes"); | ||
2405 | goto out; | ||
2406 | } | ||
2407 | |||
2408 | function = strdup(pp->function); | ||
2409 | if (!function) { | ||
2410 | pr_warning("Failed to allocate memory by strdup.\n"); | ||
2411 | ret = -ENOMEM; | ||
2412 | goto out; | ||
2413 | } | ||
2414 | |||
2415 | map = dso__new_map(exec); | ||
2416 | if (!map) { | ||
2417 | pr_warning("Cannot find appropriate DSO for %s.\n", exec); | ||
2418 | goto out; | ||
2419 | } | ||
2420 | available_func_filter = strfilter__new(function, NULL); | ||
2421 | if (map__load(map, filter_available_functions)) { | 2549 | if (map__load(map, filter_available_functions)) { |
2422 | pr_err("Failed to load map.\n"); | 2550 | pr_err("Failed to load symbols in %s\n", (target) ? : "kernel"); |
2423 | goto out; | 2551 | goto end; |
2424 | } | ||
2425 | |||
2426 | sym = map__find_symbol_by_name(map, function, NULL); | ||
2427 | if (!sym) { | ||
2428 | pr_warning("Cannot find %s in DSO %s\n", function, exec); | ||
2429 | goto out; | ||
2430 | } | ||
2431 | |||
2432 | if (map->start > sym->start) | ||
2433 | vaddr = map->start; | ||
2434 | vaddr += sym->start + pp->offset + map->pgoff; | ||
2435 | pp->offset = 0; | ||
2436 | |||
2437 | if (!pev->event) { | ||
2438 | pev->event = function; | ||
2439 | function = NULL; | ||
2440 | } | ||
2441 | if (!pev->group) { | ||
2442 | char *ptr1, *ptr2, *exec_copy; | ||
2443 | |||
2444 | pev->group = zalloc(sizeof(char *) * 64); | ||
2445 | exec_copy = strdup(exec); | ||
2446 | if (!exec_copy) { | ||
2447 | ret = -ENOMEM; | ||
2448 | pr_warning("Failed to copy exec string.\n"); | ||
2449 | goto out; | ||
2450 | } | ||
2451 | |||
2452 | ptr1 = strdup(basename(exec_copy)); | ||
2453 | if (ptr1) { | ||
2454 | ptr2 = strpbrk(ptr1, "-._"); | ||
2455 | if (ptr2) | ||
2456 | *ptr2 = '\0'; | ||
2457 | e_snprintf(pev->group, 64, "%s_%s", PERFPROBE_GROUP, | ||
2458 | ptr1); | ||
2459 | free(ptr1); | ||
2460 | } | ||
2461 | free(exec_copy); | ||
2462 | } | ||
2463 | free(pp->function); | ||
2464 | pp->function = zalloc(sizeof(char *) * MAX_PROBE_ARGS); | ||
2465 | if (!pp->function) { | ||
2466 | ret = -ENOMEM; | ||
2467 | pr_warning("Failed to allocate memory by zalloc.\n"); | ||
2468 | goto out; | ||
2469 | } | 2552 | } |
2470 | e_snprintf(pp->function, MAX_PROBE_ARGS, "0x%llx", vaddr); | 2553 | if (!dso__sorted_by_name(map->dso, map->type)) |
2471 | ret = 0; | 2554 | dso__sort_by_name(map->dso, map->type); |
2472 | 2555 | ||
2473 | out: | 2556 | /* Show all (filtered) symbols */ |
2474 | if (map) { | 2557 | setup_pager(); |
2558 | dso__fprintf_symbols_by_name(map->dso, map->type, stdout); | ||
2559 | end: | ||
2560 | if (user) { | ||
2475 | dso__delete(map->dso); | 2561 | dso__delete(map->dso); |
2476 | map__delete(map); | 2562 | map__delete(map); |
2477 | } | 2563 | } |
2478 | if (function) | 2564 | exit_symbol_maps(); |
2479 | free(function); | 2565 | |
2480 | return ret; | 2566 | return ret; |
2481 | } | 2567 | } |
2568 | |||
diff --git a/tools/perf/util/probe-event.h b/tools/perf/util/probe-event.h index fcaf7273e85a..776c9347a3b6 100644 --- a/tools/perf/util/probe-event.h +++ b/tools/perf/util/probe-event.h | |||
@@ -2,6 +2,7 @@ | |||
2 | #define _PROBE_EVENT_H | 2 | #define _PROBE_EVENT_H |
3 | 3 | ||
4 | #include <stdbool.h> | 4 | #include <stdbool.h> |
5 | #include "intlist.h" | ||
5 | #include "strlist.h" | 6 | #include "strlist.h" |
6 | #include "strfilter.h" | 7 | #include "strfilter.h" |
7 | 8 | ||
@@ -76,13 +77,6 @@ struct perf_probe_event { | |||
76 | struct perf_probe_arg *args; /* Arguments */ | 77 | struct perf_probe_arg *args; /* Arguments */ |
77 | }; | 78 | }; |
78 | 79 | ||
79 | |||
80 | /* Line number container */ | ||
81 | struct line_node { | ||
82 | struct list_head list; | ||
83 | int line; | ||
84 | }; | ||
85 | |||
86 | /* Line range */ | 80 | /* Line range */ |
87 | struct line_range { | 81 | struct line_range { |
88 | char *file; /* File name */ | 82 | char *file; /* File name */ |
@@ -92,7 +86,7 @@ struct line_range { | |||
92 | int offset; /* Start line offset */ | 86 | int offset; /* Start line offset */ |
93 | char *path; /* Real path name */ | 87 | char *path; /* Real path name */ |
94 | char *comp_dir; /* Compile directory */ | 88 | char *comp_dir; /* Compile directory */ |
95 | struct list_head line_list; /* Visible lines */ | 89 | struct intlist *line_list; /* Visible lines */ |
96 | }; | 90 | }; |
97 | 91 | ||
98 | /* List of variables */ | 92 | /* List of variables */ |
@@ -124,7 +118,7 @@ extern int parse_line_range_desc(const char *cmd, struct line_range *lr); | |||
124 | extern void line_range__clear(struct line_range *lr); | 118 | extern void line_range__clear(struct line_range *lr); |
125 | 119 | ||
126 | /* Initialize line range */ | 120 | /* Initialize line range */ |
127 | extern void line_range__init(struct line_range *lr); | 121 | extern int line_range__init(struct line_range *lr); |
128 | 122 | ||
129 | /* Internal use: Return kernel/module path */ | 123 | /* Internal use: Return kernel/module path */ |
130 | extern const char *kernel_get_module_path(const char *module); | 124 | extern const char *kernel_get_module_path(const char *module); |
diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c index 061edb162b5b..df0238654698 100644 --- a/tools/perf/util/probe-finder.c +++ b/tools/perf/util/probe-finder.c | |||
@@ -34,7 +34,9 @@ | |||
34 | 34 | ||
35 | #include <linux/bitops.h> | 35 | #include <linux/bitops.h> |
36 | #include "event.h" | 36 | #include "event.h" |
37 | #include "dso.h" | ||
37 | #include "debug.h" | 38 | #include "debug.h" |
39 | #include "intlist.h" | ||
38 | #include "util.h" | 40 | #include "util.h" |
39 | #include "symbol.h" | 41 | #include "symbol.h" |
40 | #include "probe-finder.h" | 42 | #include "probe-finder.h" |
@@ -42,65 +44,6 @@ | |||
42 | /* Kprobe tracer basic type is up to u64 */ | 44 | /* Kprobe tracer basic type is up to u64 */ |
43 | #define MAX_BASIC_TYPE_BITS 64 | 45 | #define MAX_BASIC_TYPE_BITS 64 |
44 | 46 | ||
45 | /* Line number list operations */ | ||
46 | |||
47 | /* Add a line to line number list */ | ||
48 | static int line_list__add_line(struct list_head *head, int line) | ||
49 | { | ||
50 | struct line_node *ln; | ||
51 | struct list_head *p; | ||
52 | |||
53 | /* Reverse search, because new line will be the last one */ | ||
54 | list_for_each_entry_reverse(ln, head, list) { | ||
55 | if (ln->line < line) { | ||
56 | p = &ln->list; | ||
57 | goto found; | ||
58 | } else if (ln->line == line) /* Already exist */ | ||
59 | return 1; | ||
60 | } | ||
61 | /* List is empty, or the smallest entry */ | ||
62 | p = head; | ||
63 | found: | ||
64 | pr_debug("line list: add a line %u\n", line); | ||
65 | ln = zalloc(sizeof(struct line_node)); | ||
66 | if (ln == NULL) | ||
67 | return -ENOMEM; | ||
68 | ln->line = line; | ||
69 | INIT_LIST_HEAD(&ln->list); | ||
70 | list_add(&ln->list, p); | ||
71 | return 0; | ||
72 | } | ||
73 | |||
74 | /* Check if the line in line number list */ | ||
75 | static int line_list__has_line(struct list_head *head, int line) | ||
76 | { | ||
77 | struct line_node *ln; | ||
78 | |||
79 | /* Reverse search, because new line will be the last one */ | ||
80 | list_for_each_entry(ln, head, list) | ||
81 | if (ln->line == line) | ||
82 | return 1; | ||
83 | |||
84 | return 0; | ||
85 | } | ||
86 | |||
87 | /* Init line number list */ | ||
88 | static void line_list__init(struct list_head *head) | ||
89 | { | ||
90 | INIT_LIST_HEAD(head); | ||
91 | } | ||
92 | |||
93 | /* Free line number list */ | ||
94 | static void line_list__free(struct list_head *head) | ||
95 | { | ||
96 | struct line_node *ln; | ||
97 | while (!list_empty(head)) { | ||
98 | ln = list_first_entry(head, struct line_node, list); | ||
99 | list_del(&ln->list); | ||
100 | free(ln); | ||
101 | } | ||
102 | } | ||
103 | |||
104 | /* Dwarf FL wrappers */ | 47 | /* Dwarf FL wrappers */ |
105 | static char *debuginfo_path; /* Currently dummy */ | 48 | static char *debuginfo_path; /* Currently dummy */ |
106 | 49 | ||
@@ -147,80 +90,7 @@ error: | |||
147 | return -ENOENT; | 90 | return -ENOENT; |
148 | } | 91 | } |
149 | 92 | ||
150 | #if _ELFUTILS_PREREQ(0, 148) | 93 | static struct debuginfo *__debuginfo__new(const char *path) |
151 | /* This method is buggy if elfutils is older than 0.148 */ | ||
152 | static int __linux_kernel_find_elf(Dwfl_Module *mod, | ||
153 | void **userdata, | ||
154 | const char *module_name, | ||
155 | Dwarf_Addr base, | ||
156 | char **file_name, Elf **elfp) | ||
157 | { | ||
158 | int fd; | ||
159 | const char *path = kernel_get_module_path(module_name); | ||
160 | |||
161 | pr_debug2("Use file %s for %s\n", path, module_name); | ||
162 | if (path) { | ||
163 | fd = open(path, O_RDONLY); | ||
164 | if (fd >= 0) { | ||
165 | *file_name = strdup(path); | ||
166 | return fd; | ||
167 | } | ||
168 | } | ||
169 | /* If failed, try to call standard method */ | ||
170 | return dwfl_linux_kernel_find_elf(mod, userdata, module_name, base, | ||
171 | file_name, elfp); | ||
172 | } | ||
173 | |||
174 | static const Dwfl_Callbacks kernel_callbacks = { | ||
175 | .find_debuginfo = dwfl_standard_find_debuginfo, | ||
176 | .debuginfo_path = &debuginfo_path, | ||
177 | |||
178 | .find_elf = __linux_kernel_find_elf, | ||
179 | .section_address = dwfl_linux_kernel_module_section_address, | ||
180 | }; | ||
181 | |||
182 | /* Get a Dwarf from live kernel image */ | ||
183 | static int debuginfo__init_online_kernel_dwarf(struct debuginfo *dbg, | ||
184 | Dwarf_Addr addr) | ||
185 | { | ||
186 | dbg->dwfl = dwfl_begin(&kernel_callbacks); | ||
187 | if (!dbg->dwfl) | ||
188 | return -EINVAL; | ||
189 | |||
190 | /* Load the kernel dwarves: Don't care the result here */ | ||
191 | dwfl_linux_kernel_report_kernel(dbg->dwfl); | ||
192 | dwfl_linux_kernel_report_modules(dbg->dwfl); | ||
193 | |||
194 | dbg->dbg = dwfl_addrdwarf(dbg->dwfl, addr, &dbg->bias); | ||
195 | /* Here, check whether we could get a real dwarf */ | ||
196 | if (!dbg->dbg) { | ||
197 | pr_debug("Failed to find kernel dwarf at %lx\n", | ||
198 | (unsigned long)addr); | ||
199 | dwfl_end(dbg->dwfl); | ||
200 | memset(dbg, 0, sizeof(*dbg)); | ||
201 | return -ENOENT; | ||
202 | } | ||
203 | |||
204 | return 0; | ||
205 | } | ||
206 | #else | ||
207 | /* With older elfutils, this just support kernel module... */ | ||
208 | static int debuginfo__init_online_kernel_dwarf(struct debuginfo *dbg, | ||
209 | Dwarf_Addr addr __maybe_unused) | ||
210 | { | ||
211 | const char *path = kernel_get_module_path("kernel"); | ||
212 | |||
213 | if (!path) { | ||
214 | pr_err("Failed to find vmlinux path\n"); | ||
215 | return -ENOENT; | ||
216 | } | ||
217 | |||
218 | pr_debug2("Use file %s for debuginfo\n", path); | ||
219 | return debuginfo__init_offline_dwarf(dbg, path); | ||
220 | } | ||
221 | #endif | ||
222 | |||
223 | struct debuginfo *debuginfo__new(const char *path) | ||
224 | { | 94 | { |
225 | struct debuginfo *dbg = zalloc(sizeof(*dbg)); | 95 | struct debuginfo *dbg = zalloc(sizeof(*dbg)); |
226 | if (!dbg) | 96 | if (!dbg) |
@@ -228,21 +98,44 @@ struct debuginfo *debuginfo__new(const char *path) | |||
228 | 98 | ||
229 | if (debuginfo__init_offline_dwarf(dbg, path) < 0) | 99 | if (debuginfo__init_offline_dwarf(dbg, path) < 0) |
230 | zfree(&dbg); | 100 | zfree(&dbg); |
231 | 101 | if (dbg) | |
102 | pr_debug("Open Debuginfo file: %s\n", path); | ||
232 | return dbg; | 103 | return dbg; |
233 | } | 104 | } |
234 | 105 | ||
235 | struct debuginfo *debuginfo__new_online_kernel(unsigned long addr) | 106 | enum dso_binary_type distro_dwarf_types[] = { |
236 | { | 107 | DSO_BINARY_TYPE__FEDORA_DEBUGINFO, |
237 | struct debuginfo *dbg = zalloc(sizeof(*dbg)); | 108 | DSO_BINARY_TYPE__UBUNTU_DEBUGINFO, |
109 | DSO_BINARY_TYPE__OPENEMBEDDED_DEBUGINFO, | ||
110 | DSO_BINARY_TYPE__BUILDID_DEBUGINFO, | ||
111 | DSO_BINARY_TYPE__NOT_FOUND, | ||
112 | }; | ||
238 | 113 | ||
239 | if (!dbg) | 114 | struct debuginfo *debuginfo__new(const char *path) |
240 | return NULL; | 115 | { |
116 | enum dso_binary_type *type; | ||
117 | char buf[PATH_MAX], nil = '\0'; | ||
118 | struct dso *dso; | ||
119 | struct debuginfo *dinfo = NULL; | ||
120 | |||
121 | /* Try to open distro debuginfo files */ | ||
122 | dso = dso__new(path); | ||
123 | if (!dso) | ||
124 | goto out; | ||
241 | 125 | ||
242 | if (debuginfo__init_online_kernel_dwarf(dbg, (Dwarf_Addr)addr) < 0) | 126 | for (type = distro_dwarf_types; |
243 | zfree(&dbg); | 127 | !dinfo && *type != DSO_BINARY_TYPE__NOT_FOUND; |
128 | type++) { | ||
129 | if (dso__read_binary_type_filename(dso, *type, &nil, | ||
130 | buf, PATH_MAX) < 0) | ||
131 | continue; | ||
132 | dinfo = __debuginfo__new(buf); | ||
133 | } | ||
134 | dso__delete(dso); | ||
244 | 135 | ||
245 | return dbg; | 136 | out: |
137 | /* if failed to open all distro debuginfo, open given binary */ | ||
138 | return dinfo ? : __debuginfo__new(path); | ||
246 | } | 139 | } |
247 | 140 | ||
248 | void debuginfo__delete(struct debuginfo *dbg) | 141 | void debuginfo__delete(struct debuginfo *dbg) |
@@ -880,7 +773,7 @@ static int find_probe_point_by_line(struct probe_finder *pf) | |||
880 | } | 773 | } |
881 | 774 | ||
882 | /* Find lines which match lazy pattern */ | 775 | /* Find lines which match lazy pattern */ |
883 | static int find_lazy_match_lines(struct list_head *head, | 776 | static int find_lazy_match_lines(struct intlist *list, |
884 | const char *fname, const char *pat) | 777 | const char *fname, const char *pat) |
885 | { | 778 | { |
886 | FILE *fp; | 779 | FILE *fp; |
@@ -901,7 +794,7 @@ static int find_lazy_match_lines(struct list_head *head, | |||
901 | line[len - 1] = '\0'; | 794 | line[len - 1] = '\0'; |
902 | 795 | ||
903 | if (strlazymatch(line, pat)) { | 796 | if (strlazymatch(line, pat)) { |
904 | line_list__add_line(head, linenum); | 797 | intlist__add(list, linenum); |
905 | count++; | 798 | count++; |
906 | } | 799 | } |
907 | linenum++; | 800 | linenum++; |
@@ -924,7 +817,7 @@ static int probe_point_lazy_walker(const char *fname, int lineno, | |||
924 | Dwarf_Die *sc_die, die_mem; | 817 | Dwarf_Die *sc_die, die_mem; |
925 | int ret; | 818 | int ret; |
926 | 819 | ||
927 | if (!line_list__has_line(&pf->lcache, lineno) || | 820 | if (!intlist__has_entry(pf->lcache, lineno) || |
928 | strtailcmp(fname, pf->fname) != 0) | 821 | strtailcmp(fname, pf->fname) != 0) |
929 | return 0; | 822 | return 0; |
930 | 823 | ||
@@ -952,9 +845,9 @@ static int find_probe_point_lazy(Dwarf_Die *sp_die, struct probe_finder *pf) | |||
952 | { | 845 | { |
953 | int ret = 0; | 846 | int ret = 0; |
954 | 847 | ||
955 | if (list_empty(&pf->lcache)) { | 848 | if (intlist__empty(pf->lcache)) { |
956 | /* Matching lazy line pattern */ | 849 | /* Matching lazy line pattern */ |
957 | ret = find_lazy_match_lines(&pf->lcache, pf->fname, | 850 | ret = find_lazy_match_lines(pf->lcache, pf->fname, |
958 | pf->pev->point.lazy_line); | 851 | pf->pev->point.lazy_line); |
959 | if (ret <= 0) | 852 | if (ret <= 0) |
960 | return ret; | 853 | return ret; |
@@ -1096,7 +989,9 @@ static int debuginfo__find_probes(struct debuginfo *dbg, | |||
1096 | #endif | 989 | #endif |
1097 | 990 | ||
1098 | off = 0; | 991 | off = 0; |
1099 | line_list__init(&pf->lcache); | 992 | pf->lcache = intlist__new(NULL); |
993 | if (!pf->lcache) | ||
994 | return -ENOMEM; | ||
1100 | 995 | ||
1101 | /* Fastpath: lookup by function name from .debug_pubnames section */ | 996 | /* Fastpath: lookup by function name from .debug_pubnames section */ |
1102 | if (pp->function) { | 997 | if (pp->function) { |
@@ -1149,7 +1044,8 @@ static int debuginfo__find_probes(struct debuginfo *dbg, | |||
1149 | } | 1044 | } |
1150 | 1045 | ||
1151 | found: | 1046 | found: |
1152 | line_list__free(&pf->lcache); | 1047 | intlist__delete(pf->lcache); |
1048 | pf->lcache = NULL; | ||
1153 | 1049 | ||
1154 | return ret; | 1050 | return ret; |
1155 | } | 1051 | } |
@@ -1537,7 +1433,7 @@ static int line_range_add_line(const char *src, unsigned int lineno, | |||
1537 | if (lr->path == NULL) | 1433 | if (lr->path == NULL) |
1538 | return -ENOMEM; | 1434 | return -ENOMEM; |
1539 | } | 1435 | } |
1540 | return line_list__add_line(&lr->line_list, lineno); | 1436 | return intlist__add(lr->line_list, lineno); |
1541 | } | 1437 | } |
1542 | 1438 | ||
1543 | static int line_range_walk_cb(const char *fname, int lineno, | 1439 | static int line_range_walk_cb(const char *fname, int lineno, |
@@ -1565,7 +1461,7 @@ static int find_line_range_by_line(Dwarf_Die *sp_die, struct line_finder *lf) | |||
1565 | 1461 | ||
1566 | /* Update status */ | 1462 | /* Update status */ |
1567 | if (ret >= 0) | 1463 | if (ret >= 0) |
1568 | if (!list_empty(&lf->lr->line_list)) | 1464 | if (!intlist__empty(lf->lr->line_list)) |
1569 | ret = lf->found = 1; | 1465 | ret = lf->found = 1; |
1570 | else | 1466 | else |
1571 | ret = 0; /* Lines are not found */ | 1467 | ret = 0; /* Lines are not found */ |
diff --git a/tools/perf/util/probe-finder.h b/tools/perf/util/probe-finder.h index ffc33cdd25cc..92590b2c7e1c 100644 --- a/tools/perf/util/probe-finder.h +++ b/tools/perf/util/probe-finder.h | |||
@@ -3,6 +3,7 @@ | |||
3 | 3 | ||
4 | #include <stdbool.h> | 4 | #include <stdbool.h> |
5 | #include "util.h" | 5 | #include "util.h" |
6 | #include "intlist.h" | ||
6 | #include "probe-event.h" | 7 | #include "probe-event.h" |
7 | 8 | ||
8 | #define MAX_PROBE_BUFFER 1024 | 9 | #define MAX_PROBE_BUFFER 1024 |
@@ -29,8 +30,8 @@ struct debuginfo { | |||
29 | Dwarf_Addr bias; | 30 | Dwarf_Addr bias; |
30 | }; | 31 | }; |
31 | 32 | ||
33 | /* This also tries to open distro debuginfo */ | ||
32 | extern struct debuginfo *debuginfo__new(const char *path); | 34 | extern struct debuginfo *debuginfo__new(const char *path); |
33 | extern struct debuginfo *debuginfo__new_online_kernel(unsigned long addr); | ||
34 | extern void debuginfo__delete(struct debuginfo *dbg); | 35 | extern void debuginfo__delete(struct debuginfo *dbg); |
35 | 36 | ||
36 | /* Find probe_trace_events specified by perf_probe_event from debuginfo */ | 37 | /* Find probe_trace_events specified by perf_probe_event from debuginfo */ |
@@ -66,7 +67,7 @@ struct probe_finder { | |||
66 | const char *fname; /* Real file name */ | 67 | const char *fname; /* Real file name */ |
67 | Dwarf_Die cu_die; /* Current CU */ | 68 | Dwarf_Die cu_die; /* Current CU */ |
68 | Dwarf_Die sp_die; | 69 | Dwarf_Die sp_die; |
69 | struct list_head lcache; /* Line cache for lazy match */ | 70 | struct intlist *lcache; /* Line cache for lazy match */ |
70 | 71 | ||
71 | /* For variable searching */ | 72 | /* For variable searching */ |
72 | #if _ELFUTILS_PREREQ(0, 142) | 73 | #if _ELFUTILS_PREREQ(0, 142) |
diff --git a/tools/perf/util/python-ext-sources b/tools/perf/util/python-ext-sources index 595bfc73d2ed..16a475a7d492 100644 --- a/tools/perf/util/python-ext-sources +++ b/tools/perf/util/python-ext-sources | |||
@@ -17,6 +17,6 @@ util/xyarray.c | |||
17 | util/cgroup.c | 17 | util/cgroup.c |
18 | util/rblist.c | 18 | util/rblist.c |
19 | util/strlist.c | 19 | util/strlist.c |
20 | util/fs.c | 20 | ../lib/api/fs/fs.c |
21 | util/trace-event.c | 21 | util/trace-event.c |
22 | ../../lib/rbtree.c | 22 | ../../lib/rbtree.c |
diff --git a/tools/perf/util/record.c b/tools/perf/util/record.c index 373762501dad..049e0a09ccd3 100644 --- a/tools/perf/util/record.c +++ b/tools/perf/util/record.c | |||
@@ -2,7 +2,7 @@ | |||
2 | #include "evsel.h" | 2 | #include "evsel.h" |
3 | #include "cpumap.h" | 3 | #include "cpumap.h" |
4 | #include "parse-events.h" | 4 | #include "parse-events.h" |
5 | #include "fs.h" | 5 | #include <api/fs/fs.h> |
6 | #include "util.h" | 6 | #include "util.h" |
7 | 7 | ||
8 | typedef void (*setup_probe_fn_t)(struct perf_evsel *evsel); | 8 | typedef void (*setup_probe_fn_t)(struct perf_evsel *evsel); |
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 5da6ce74c676..1d555d652f58 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c | |||
@@ -702,11 +702,12 @@ static void regs_dump__printf(u64 mask, u64 *regs) | |||
702 | } | 702 | } |
703 | } | 703 | } |
704 | 704 | ||
705 | static void regs_user__printf(struct perf_sample *sample, u64 mask) | 705 | static void regs_user__printf(struct perf_sample *sample) |
706 | { | 706 | { |
707 | struct regs_dump *user_regs = &sample->user_regs; | 707 | struct regs_dump *user_regs = &sample->user_regs; |
708 | 708 | ||
709 | if (user_regs->regs) { | 709 | if (user_regs->regs) { |
710 | u64 mask = user_regs->mask; | ||
710 | printf("... user regs: mask 0x%" PRIx64 "\n", mask); | 711 | printf("... user regs: mask 0x%" PRIx64 "\n", mask); |
711 | regs_dump__printf(mask, user_regs->regs); | 712 | regs_dump__printf(mask, user_regs->regs); |
712 | } | 713 | } |
@@ -806,7 +807,7 @@ static void dump_sample(struct perf_evsel *evsel, union perf_event *event, | |||
806 | branch_stack__printf(sample); | 807 | branch_stack__printf(sample); |
807 | 808 | ||
808 | if (sample_type & PERF_SAMPLE_REGS_USER) | 809 | if (sample_type & PERF_SAMPLE_REGS_USER) |
809 | regs_user__printf(sample, evsel->attr.sample_regs_user); | 810 | regs_user__printf(sample); |
810 | 811 | ||
811 | if (sample_type & PERF_SAMPLE_STACK_USER) | 812 | if (sample_type & PERF_SAMPLE_STACK_USER) |
812 | stack_user__printf(&sample->user_stack); | 813 | stack_user__printf(&sample->user_stack); |
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c index a9d758a3b371..46e2ede12c51 100644 --- a/tools/perf/util/symbol.c +++ b/tools/perf/util/symbol.c | |||
@@ -410,7 +410,7 @@ struct symbol *dso__find_symbol(struct dso *dso, | |||
410 | return symbols__find(&dso->symbols[type], addr); | 410 | return symbols__find(&dso->symbols[type], addr); |
411 | } | 411 | } |
412 | 412 | ||
413 | struct symbol *dso__first_symbol(struct dso *dso, enum map_type type) | 413 | static struct symbol *dso__first_symbol(struct dso *dso, enum map_type type) |
414 | { | 414 | { |
415 | return symbols__first(&dso->symbols[type]); | 415 | return symbols__first(&dso->symbols[type]); |
416 | } | 416 | } |
diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h index fffe2888a1c7..2553ae04b788 100644 --- a/tools/perf/util/symbol.h +++ b/tools/perf/util/symbol.h | |||
@@ -79,6 +79,17 @@ struct symbol { | |||
79 | void symbol__delete(struct symbol *sym); | 79 | void symbol__delete(struct symbol *sym); |
80 | void symbols__delete(struct rb_root *symbols); | 80 | void symbols__delete(struct rb_root *symbols); |
81 | 81 | ||
82 | /* symbols__for_each_entry - iterate over symbols (rb_root) | ||
83 | * | ||
84 | * @symbols: the rb_root of symbols | ||
85 | * @pos: the 'struct symbol *' to use as a loop cursor | ||
86 | * @nd: the 'struct rb_node *' to use as a temporary storage | ||
87 | */ | ||
88 | #define symbols__for_each_entry(symbols, pos, nd) \ | ||
89 | for (nd = rb_first(symbols); \ | ||
90 | nd && (pos = rb_entry(nd, struct symbol, rb_node)); \ | ||
91 | nd = rb_next(nd)) | ||
92 | |||
82 | static inline size_t symbol__size(const struct symbol *sym) | 93 | static inline size_t symbol__size(const struct symbol *sym) |
83 | { | 94 | { |
84 | return sym->end - sym->start + 1; | 95 | return sym->end - sym->start + 1; |
@@ -223,7 +234,6 @@ struct symbol *dso__find_symbol(struct dso *dso, enum map_type type, | |||
223 | u64 addr); | 234 | u64 addr); |
224 | struct symbol *dso__find_symbol_by_name(struct dso *dso, enum map_type type, | 235 | struct symbol *dso__find_symbol_by_name(struct dso *dso, enum map_type type, |
225 | const char *name); | 236 | const char *name); |
226 | struct symbol *dso__first_symbol(struct dso *dso, enum map_type type); | ||
227 | 237 | ||
228 | int filename__read_build_id(const char *filename, void *bf, size_t size); | 238 | int filename__read_build_id(const char *filename, void *bf, size_t size); |
229 | int sysfs__read_build_id(const char *filename, void *bf, size_t size); | 239 | int sysfs__read_build_id(const char *filename, void *bf, size_t size); |
diff --git a/tools/perf/util/trace-event-parse.c b/tools/perf/util/trace-event-parse.c index e0d6d07f6848..c36636fd825b 100644 --- a/tools/perf/util/trace-event-parse.c +++ b/tools/perf/util/trace-event-parse.c | |||
@@ -126,6 +126,7 @@ void event_format__print(struct event_format *event, | |||
126 | trace_seq_init(&s); | 126 | trace_seq_init(&s); |
127 | pevent_event_info(&s, event, &record); | 127 | pevent_event_info(&s, event, &record); |
128 | trace_seq_do_printf(&s); | 128 | trace_seq_do_printf(&s); |
129 | trace_seq_destroy(&s); | ||
129 | } | 130 | } |
130 | 131 | ||
131 | void parse_proc_kallsyms(struct pevent *pevent, | 132 | void parse_proc_kallsyms(struct pevent *pevent, |
diff --git a/tools/perf/util/unwind.c b/tools/perf/util/unwind-libunwind.c index 742f23bf35ff..bd5768d74f01 100644 --- a/tools/perf/util/unwind.c +++ b/tools/perf/util/unwind-libunwind.c | |||
@@ -86,7 +86,6 @@ struct unwind_info { | |||
86 | struct perf_sample *sample; | 86 | struct perf_sample *sample; |
87 | struct machine *machine; | 87 | struct machine *machine; |
88 | struct thread *thread; | 88 | struct thread *thread; |
89 | u64 sample_uregs; | ||
90 | }; | 89 | }; |
91 | 90 | ||
92 | #define dw_read(ptr, type, end) ({ \ | 91 | #define dw_read(ptr, type, end) ({ \ |
@@ -391,30 +390,13 @@ static int access_dso_mem(struct unwind_info *ui, unw_word_t addr, | |||
391 | return !(size == sizeof(*data)); | 390 | return !(size == sizeof(*data)); |
392 | } | 391 | } |
393 | 392 | ||
394 | static int reg_value(unw_word_t *valp, struct regs_dump *regs, int id, | ||
395 | u64 sample_regs) | ||
396 | { | ||
397 | int i, idx = 0; | ||
398 | |||
399 | if (!(sample_regs & (1 << id))) | ||
400 | return -EINVAL; | ||
401 | |||
402 | for (i = 0; i < id; i++) { | ||
403 | if (sample_regs & (1 << i)) | ||
404 | idx++; | ||
405 | } | ||
406 | |||
407 | *valp = regs->regs[idx]; | ||
408 | return 0; | ||
409 | } | ||
410 | |||
411 | static int access_mem(unw_addr_space_t __maybe_unused as, | 393 | static int access_mem(unw_addr_space_t __maybe_unused as, |
412 | unw_word_t addr, unw_word_t *valp, | 394 | unw_word_t addr, unw_word_t *valp, |
413 | int __write, void *arg) | 395 | int __write, void *arg) |
414 | { | 396 | { |
415 | struct unwind_info *ui = arg; | 397 | struct unwind_info *ui = arg; |
416 | struct stack_dump *stack = &ui->sample->user_stack; | 398 | struct stack_dump *stack = &ui->sample->user_stack; |
417 | unw_word_t start, end; | 399 | u64 start, end; |
418 | int offset; | 400 | int offset; |
419 | int ret; | 401 | int ret; |
420 | 402 | ||
@@ -424,8 +406,7 @@ static int access_mem(unw_addr_space_t __maybe_unused as, | |||
424 | return 0; | 406 | return 0; |
425 | } | 407 | } |
426 | 408 | ||
427 | ret = reg_value(&start, &ui->sample->user_regs, PERF_REG_SP, | 409 | ret = perf_reg_value(&start, &ui->sample->user_regs, PERF_REG_SP); |
428 | ui->sample_uregs); | ||
429 | if (ret) | 410 | if (ret) |
430 | return ret; | 411 | return ret; |
431 | 412 | ||
@@ -438,8 +419,9 @@ static int access_mem(unw_addr_space_t __maybe_unused as, | |||
438 | if (addr < start || addr + sizeof(unw_word_t) >= end) { | 419 | if (addr < start || addr + sizeof(unw_word_t) >= end) { |
439 | ret = access_dso_mem(ui, addr, valp); | 420 | ret = access_dso_mem(ui, addr, valp); |
440 | if (ret) { | 421 | if (ret) { |
441 | pr_debug("unwind: access_mem %p not inside range %p-%p\n", | 422 | pr_debug("unwind: access_mem %p not inside range" |
442 | (void *)addr, (void *)start, (void *)end); | 423 | " 0x%" PRIx64 "-0x%" PRIx64 "\n", |
424 | (void *) addr, start, end); | ||
443 | *valp = 0; | 425 | *valp = 0; |
444 | return ret; | 426 | return ret; |
445 | } | 427 | } |
@@ -448,8 +430,8 @@ static int access_mem(unw_addr_space_t __maybe_unused as, | |||
448 | 430 | ||
449 | offset = addr - start; | 431 | offset = addr - start; |
450 | *valp = *(unw_word_t *)&stack->data[offset]; | 432 | *valp = *(unw_word_t *)&stack->data[offset]; |
451 | pr_debug("unwind: access_mem addr %p, val %lx, offset %d\n", | 433 | pr_debug("unwind: access_mem addr %p val %lx, offset %d\n", |
452 | (void *)addr, (unsigned long)*valp, offset); | 434 | (void *) addr, (unsigned long)*valp, offset); |
453 | return 0; | 435 | return 0; |
454 | } | 436 | } |
455 | 437 | ||
@@ -459,6 +441,7 @@ static int access_reg(unw_addr_space_t __maybe_unused as, | |||
459 | { | 441 | { |
460 | struct unwind_info *ui = arg; | 442 | struct unwind_info *ui = arg; |
461 | int id, ret; | 443 | int id, ret; |
444 | u64 val; | ||
462 | 445 | ||
463 | /* Don't support write, I suspect we don't need it. */ | 446 | /* Don't support write, I suspect we don't need it. */ |
464 | if (__write) { | 447 | if (__write) { |
@@ -471,16 +454,17 @@ static int access_reg(unw_addr_space_t __maybe_unused as, | |||
471 | return 0; | 454 | return 0; |
472 | } | 455 | } |
473 | 456 | ||
474 | id = unwind__arch_reg_id(regnum); | 457 | id = libunwind__arch_reg_id(regnum); |
475 | if (id < 0) | 458 | if (id < 0) |
476 | return -EINVAL; | 459 | return -EINVAL; |
477 | 460 | ||
478 | ret = reg_value(valp, &ui->sample->user_regs, id, ui->sample_uregs); | 461 | ret = perf_reg_value(&val, &ui->sample->user_regs, id); |
479 | if (ret) { | 462 | if (ret) { |
480 | pr_err("unwind: can't read reg %d\n", regnum); | 463 | pr_err("unwind: can't read reg %d\n", regnum); |
481 | return ret; | 464 | return ret; |
482 | } | 465 | } |
483 | 466 | ||
467 | *valp = (unw_word_t) val; | ||
484 | pr_debug("unwind: reg %d, val %lx\n", regnum, (unsigned long)*valp); | 468 | pr_debug("unwind: reg %d, val %lx\n", regnum, (unsigned long)*valp); |
485 | return 0; | 469 | return 0; |
486 | } | 470 | } |
@@ -563,7 +547,7 @@ static int get_entries(struct unwind_info *ui, unwind_entry_cb_t cb, | |||
563 | unw_word_t ip; | 547 | unw_word_t ip; |
564 | 548 | ||
565 | unw_get_reg(&c, UNW_REG_IP, &ip); | 549 | unw_get_reg(&c, UNW_REG_IP, &ip); |
566 | ret = entry(ip, ui->thread, ui->machine, cb, arg); | 550 | ret = ip ? entry(ip, ui->thread, ui->machine, cb, arg) : 0; |
567 | } | 551 | } |
568 | 552 | ||
569 | unw_destroy_addr_space(addr_space); | 553 | unw_destroy_addr_space(addr_space); |
@@ -572,13 +556,11 @@ static int get_entries(struct unwind_info *ui, unwind_entry_cb_t cb, | |||
572 | 556 | ||
573 | int unwind__get_entries(unwind_entry_cb_t cb, void *arg, | 557 | int unwind__get_entries(unwind_entry_cb_t cb, void *arg, |
574 | struct machine *machine, struct thread *thread, | 558 | struct machine *machine, struct thread *thread, |
575 | u64 sample_uregs, struct perf_sample *data, | 559 | struct perf_sample *data, int max_stack) |
576 | int max_stack) | ||
577 | { | 560 | { |
578 | unw_word_t ip; | 561 | u64 ip; |
579 | struct unwind_info ui = { | 562 | struct unwind_info ui = { |
580 | .sample = data, | 563 | .sample = data, |
581 | .sample_uregs = sample_uregs, | ||
582 | .thread = thread, | 564 | .thread = thread, |
583 | .machine = machine, | 565 | .machine = machine, |
584 | }; | 566 | }; |
@@ -587,7 +569,7 @@ int unwind__get_entries(unwind_entry_cb_t cb, void *arg, | |||
587 | if (!data->user_regs.regs) | 569 | if (!data->user_regs.regs) |
588 | return -EINVAL; | 570 | return -EINVAL; |
589 | 571 | ||
590 | ret = reg_value(&ip, &data->user_regs, PERF_REG_IP, sample_uregs); | 572 | ret = perf_reg_value(&ip, &data->user_regs, PERF_REG_IP); |
591 | if (ret) | 573 | if (ret) |
592 | return ret; | 574 | return ret; |
593 | 575 | ||
@@ -595,5 +577,5 @@ int unwind__get_entries(unwind_entry_cb_t cb, void *arg, | |||
595 | if (ret) | 577 | if (ret) |
596 | return -ENOMEM; | 578 | return -ENOMEM; |
597 | 579 | ||
598 | return get_entries(&ui, cb, arg, max_stack); | 580 | return --max_stack > 0 ? get_entries(&ui, cb, arg, max_stack) : 0; |
599 | } | 581 | } |
diff --git a/tools/perf/util/unwind.h b/tools/perf/util/unwind.h index d5966f49e22c..b031316f221a 100644 --- a/tools/perf/util/unwind.h +++ b/tools/perf/util/unwind.h | |||
@@ -13,24 +13,25 @@ struct unwind_entry { | |||
13 | 13 | ||
14 | typedef int (*unwind_entry_cb_t)(struct unwind_entry *entry, void *arg); | 14 | typedef int (*unwind_entry_cb_t)(struct unwind_entry *entry, void *arg); |
15 | 15 | ||
16 | #ifdef HAVE_LIBUNWIND_SUPPORT | 16 | #ifdef HAVE_DWARF_UNWIND_SUPPORT |
17 | int unwind__get_entries(unwind_entry_cb_t cb, void *arg, | 17 | int unwind__get_entries(unwind_entry_cb_t cb, void *arg, |
18 | struct machine *machine, | 18 | struct machine *machine, |
19 | struct thread *thread, | 19 | struct thread *thread, |
20 | u64 sample_uregs, | ||
21 | struct perf_sample *data, int max_stack); | 20 | struct perf_sample *data, int max_stack); |
22 | int unwind__arch_reg_id(int regnum); | 21 | /* libunwind specific */ |
22 | #ifdef HAVE_LIBUNWIND_SUPPORT | ||
23 | int libunwind__arch_reg_id(int regnum); | ||
24 | #endif | ||
23 | #else | 25 | #else |
24 | static inline int | 26 | static inline int |
25 | unwind__get_entries(unwind_entry_cb_t cb __maybe_unused, | 27 | unwind__get_entries(unwind_entry_cb_t cb __maybe_unused, |
26 | void *arg __maybe_unused, | 28 | void *arg __maybe_unused, |
27 | struct machine *machine __maybe_unused, | 29 | struct machine *machine __maybe_unused, |
28 | struct thread *thread __maybe_unused, | 30 | struct thread *thread __maybe_unused, |
29 | u64 sample_uregs __maybe_unused, | ||
30 | struct perf_sample *data __maybe_unused, | 31 | struct perf_sample *data __maybe_unused, |
31 | int max_stack __maybe_unused) | 32 | int max_stack __maybe_unused) |
32 | { | 33 | { |
33 | return 0; | 34 | return 0; |
34 | } | 35 | } |
35 | #endif /* HAVE_LIBUNWIND_SUPPORT */ | 36 | #endif /* HAVE_DWARF_UNWIND_SUPPORT */ |
36 | #endif /* __UNWIND_H */ | 37 | #endif /* __UNWIND_H */ |
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c index 42ad667bb317..9f66549562bd 100644 --- a/tools/perf/util/util.c +++ b/tools/perf/util/util.c | |||
@@ -1,6 +1,6 @@ | |||
1 | #include "../perf.h" | 1 | #include "../perf.h" |
2 | #include "util.h" | 2 | #include "util.h" |
3 | #include "fs.h" | 3 | #include <api/fs/fs.h> |
4 | #include <sys/mman.h> | 4 | #include <sys/mman.h> |
5 | #ifdef HAVE_BACKTRACE_SUPPORT | 5 | #ifdef HAVE_BACKTRACE_SUPPORT |
6 | #include <execinfo.h> | 6 | #include <execinfo.h> |