Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf kmem: Support legacy tracepoints

Commit 11e9734bcb6a7361 ("mm/slab_common: unify NUMA and UMA version of
tracepoints") removed tracepoints 'kmalloc_node' and
'kmem_cache_alloc_node', we need to consider the tool should be backward
compatible.

If it detect the tracepoint "kmem:kmalloc_node", this patch enables the
legacy tracepoints, otherwise, it will ignore them.

Fixes: 11e9734bcb6a7361 ("mm/slab_common: unify NUMA and UMA version of tracepoints")
Reported-by: Ravi Bangoria <ravi.bangoria@amd.com>
Reviewed-by: James Clark <james.clark@arm.com>
Signed-off-by: Leo Yan <leo.yan@linaro.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Hyeonggon Yoo <42.hyeyoo@gmail.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Vlastimil Babka <vbabka@suse.cz>
Link: https://lore.kernel.org/r/20230108062400.250690-1-leo.yan@linaro.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Leo Yan and committed by
Arnaldo Carvalho de Melo
b3719108 d891f2b7

+26 -3
+26 -3
tools/perf/builtin-kmem.c
··· 1824 1824 return 0; 1825 1825 } 1826 1826 1827 + static bool slab_legacy_tp_is_exposed(void) 1828 + { 1829 + /* 1830 + * The tracepoints "kmem:kmalloc_node" and 1831 + * "kmem:kmem_cache_alloc_node" have been removed on the latest 1832 + * kernel, if the tracepoint "kmem:kmalloc_node" is existed it 1833 + * means the tool is running on an old kernel, we need to 1834 + * rollback to support these legacy tracepoints. 1835 + */ 1836 + return IS_ERR(trace_event__tp_format("kmem", "kmalloc_node")) ? 1837 + false : true; 1838 + } 1839 + 1827 1840 static int __cmd_record(int argc, const char **argv) 1828 1841 { 1829 1842 const char * const record_args[] = { ··· 1844 1831 }; 1845 1832 const char * const slab_events[] = { 1846 1833 "-e", "kmem:kmalloc", 1847 - "-e", "kmem:kmalloc_node", 1848 1834 "-e", "kmem:kfree", 1849 1835 "-e", "kmem:kmem_cache_alloc", 1850 - "-e", "kmem:kmem_cache_alloc_node", 1851 1836 "-e", "kmem:kmem_cache_free", 1837 + }; 1838 + const char * const slab_legacy_events[] = { 1839 + "-e", "kmem:kmalloc_node", 1840 + "-e", "kmem:kmem_cache_alloc_node", 1852 1841 }; 1853 1842 const char * const page_events[] = { 1854 1843 "-e", "kmem:mm_page_alloc", ··· 1858 1843 }; 1859 1844 unsigned int rec_argc, i, j; 1860 1845 const char **rec_argv; 1846 + unsigned int slab_legacy_tp_exposed = slab_legacy_tp_is_exposed(); 1861 1847 1862 1848 rec_argc = ARRAY_SIZE(record_args) + argc - 1; 1863 - if (kmem_slab) 1849 + if (kmem_slab) { 1864 1850 rec_argc += ARRAY_SIZE(slab_events); 1851 + if (slab_legacy_tp_exposed) 1852 + rec_argc += ARRAY_SIZE(slab_legacy_events); 1853 + } 1865 1854 if (kmem_page) 1866 1855 rec_argc += ARRAY_SIZE(page_events) + 1; /* for -g */ 1867 1856 ··· 1880 1861 if (kmem_slab) { 1881 1862 for (j = 0; j < ARRAY_SIZE(slab_events); j++, i++) 1882 1863 rec_argv[i] = strdup(slab_events[j]); 1864 + if (slab_legacy_tp_exposed) { 1865 + for (j = 0; j < ARRAY_SIZE(slab_legacy_events); j++, i++) 1866 + rec_argv[i] = strdup(slab_legacy_events[j]); 1867 + } 1883 1868 } 1884 1869 if (kmem_page) { 1885 1870 rec_argv[i++] = strdup("-g");