Pull perf/urgent fixes and improvements from Arnaldo Carvalho de Melo: perf python: Arnaldo Carvalho de Melo: - Fix clang detection to strip out options passed in $CC. build: He Zhe: - Normalize gcc parameter when generating arch errno table, fixing the build by removing options from $(CC). Sam Lunt: - Support Python 3.8+ in Makefile. perf report/top: Arnaldo Carvalho de Melo: - Fix title line formatting. perf script: Andreas Gerstmayr: - Fix SEGFAULT when using DWARF mode. - Fix invalid read of directory entry after closedir(), found with valgrind. Hagen Paul Pfeifer: - Introduce --deltatime option. Stephane Eranian: - Allow --symbol to accept hexadecimal addresses. Ian Rogers: - Add -S/--symbols documentation Namhyung Kim: - Add --show-cgroup-events option. perf python: Arnaldo Carvalho de Melo: - Include rwsem.c in the python binding, needed by the cgroups improvements. build-test: Arnaldo Carvalho de Melo: - Honour JOBS to override detection of number of cores perf top: Jin Yao: - Support --group-sort-idx to change the sort order - perf top: Support hotkey to change sort order perf pmu-events x86: Jin Yao: - Use CPU_CLK_UNHALTED.THREAD in Kernel_Utilization metric perf symbols arm64: Kemeng Shi: - Fix arm64 gap between kernel start and module end kernel perf subsystem: Namhyung Kim: - Add PERF_RECORD_CGROUP event and Add PERF_SAMPLE_CGROUP feature, to allow cgroup tracking, saving a link between cgroup path and its id number. perf cgroup: Namhyung Kim: - Maintain cgroup hierarchy. perf report: Namhyung Kim: - Add 'cgroup' sort key. perf record: Namhyung Kim: - Support synthesizing cgroup events for pre-existing cgroups. - Add --all-cgroups option Documentation: Tony Jones: - Update docs regarding kernel/user space unwinding.
Showing the changes to kernel (1 of 100 files). Show all
Unified · Split
| @@ -387,6 +387,7 @@ static atomic_t nr_freq_events __read_mostly; · 386 unmodified lines | ||
| 387 | 387 | static atomic_t nr_switch_events __read_mostly; |
| 388 | 388 | static atomic_t nr_ksymbol_events __read_mostly; |
| 389 | 389 | static atomic_t nr_bpf_events __read_mostly; |
| 390 | +static atomic_t nr_cgroup_events __read_mostly; | |
| 390 | 391 | |
| 391 | 392 | static LIST_HEAD(pmus); |
| 392 | 393 | static DEFINE_MUTEX(pmus_lock); |
| @@ -1861,6 +1862,9 @@ static void __perf_event_header_size(struct perf_event *event, u64 sample_type) · 1468 unmodified lines | ||
| 1861 | 1862 | if (sample_type & PERF_SAMPLE_PHYS_ADDR) |
| 1862 | 1863 | size += sizeof(data->phys_addr); |
| 1863 | 1864 | |
| 1865 | + if (sample_type & PERF_SAMPLE_CGROUP) | |
| 1866 | + size += sizeof(data->cgroup); | |
| 1867 | + | |
| 1864 | 1868 | event->header_size = size; |
| 1865 | 1869 | } |
| 1866 | 1870 | |
| @@ -4608,6 +4612,8 @@ static void unaccount_event(struct perf_event *event) · 2741 unmodified lines | ||
| 4608 | 4612 | atomic_dec(&nr_comm_events); |
| 4609 | 4613 | if (event->attr.namespaces) |
| 4610 | 4614 | atomic_dec(&nr_namespaces_events); |
| 4615 | + if (event->attr.cgroup) | |
| 4616 | + atomic_dec(&nr_cgroup_events); | |
| 4611 | 4617 | if (event->attr.task) |
| 4612 | 4618 | atomic_dec(&nr_task_events); |
| 4613 | 4619 | if (event->attr.freq) |
| @@ -6864,6 +6870,9 @@ void perf_output_sample(struct perf_output_handle *handle, · 2250 unmodified lines | ||
| 6864 | 6870 | if (sample_type & PERF_SAMPLE_PHYS_ADDR) |
| 6865 | 6871 | perf_output_put(handle, data->phys_addr); |
| 6866 | 6872 | |
| 6873 | + if (sample_type & PERF_SAMPLE_CGROUP) | |
| 6874 | + perf_output_put(handle, data->cgroup); | |
| 6875 | + | |
| 6867 | 6876 | if (sample_type & PERF_SAMPLE_AUX) { |
| 6868 | 6877 | perf_output_put(handle, data->aux_size); |
| 6869 | 6878 | |
| @@ -7063,6 +7072,16 @@ void perf_prepare_sample(struct perf_event_header *header, · 193 unmodified lines | ||
| 7063 | 7072 | if (sample_type & PERF_SAMPLE_PHYS_ADDR) |
| 7064 | 7073 | data->phys_addr = perf_virt_to_phys(data->addr); |
| 7065 | 7074 | |
| 7075 | +#ifdef CONFIG_CGROUP_PERF | |
| 7076 | + if (sample_type & PERF_SAMPLE_CGROUP) { | |
| 7077 | + struct cgroup *cgrp; | |
| 7078 | + | |
| 7079 | + /* protected by RCU */ | |
| 7080 | + cgrp = task_css_check(current, perf_event_cgrp_id, 1)->cgroup; | |
| 7081 | + data->cgroup = cgroup_id(cgrp); | |
| 7082 | + } | |
| 7083 | +#endif | |
| 7084 | + | |
| 7066 | 7085 | if (sample_type & PERF_SAMPLE_AUX) { |
| 7067 | 7086 | u64 size; |
| 7068 | 7087 | |
| @@ -7735,6 +7754,105 @@ void perf_event_namespaces(struct task_struct *task) · 666 unmodified lines | ||
| 7735 | 7754 | NULL); |
| 7736 | 7755 | } |
| 7737 | 7756 | |
| 7757 | +/* | |
| 7758 | + * cgroup tracking | |
| 7759 | + */ | |
| 7760 | +#ifdef CONFIG_CGROUP_PERF | |
| 7761 | + | |
| 7762 | +struct perf_cgroup_event { | |
| 7763 | + char *path; | |
| 7764 | + int path_size; | |
| 7765 | + struct { | |
| 7766 | + struct perf_event_header header; | |
| 7767 | + u64 id; | |
| 7768 | + char path[]; | |
| 7769 | + } event_id; | |
| 7770 | +}; | |
| 7771 | + | |
| 7772 | +static int perf_event_cgroup_match(struct perf_event *event) | |
| 7773 | +{ | |
| 7774 | + return event->attr.cgroup; | |
| 7775 | +} | |
| 7776 | + | |
| 7777 | +static void perf_event_cgroup_output(struct perf_event *event, void *data) | |
| 7778 | +{ | |
| 7779 | + struct perf_cgroup_event *cgroup_event = data; | |
| 7780 | + struct perf_output_handle handle; | |
| 7781 | + struct perf_sample_data sample; | |
| 7782 | + u16 header_size = cgroup_event->event_id.header.size; | |
| 7783 | + int ret; | |
| 7784 | + | |
| 7785 | + if (!perf_event_cgroup_match(event)) | |
| 7786 | + return; | |
| 7787 | + | |
| 7788 | + perf_event_header__init_id(&cgroup_event->event_id.header, | |
| 7789 | + &sample, event); | |
| 7790 | + ret = perf_output_begin(&handle, event, | |
| 7791 | + cgroup_event->event_id.header.size); | |
| 7792 | + if (ret) | |
| 7793 | + goto out; | |
| 7794 | + | |
| 7795 | + perf_output_put(&handle, cgroup_event->event_id); | |
| 7796 | + __output_copy(&handle, cgroup_event->path, cgroup_event->path_size); | |
| 7797 | + | |
| 7798 | + perf_event__output_id_sample(event, &handle, &sample); | |
| 7799 | + | |
| 7800 | + perf_output_end(&handle); | |
| 7801 | +out: | |
| 7802 | + cgroup_event->event_id.header.size = header_size; | |
| 7803 | +} | |
| 7804 | + | |
| 7805 | +static void perf_event_cgroup(struct cgroup *cgrp) | |
| 7806 | +{ | |
| 7807 | + struct perf_cgroup_event cgroup_event; | |
| 7808 | + char path_enomem[16] = "//enomem"; | |
| 7809 | + char *pathname; | |
| 7810 | + size_t size; | |
| 7811 | + | |
| 7812 | + if (!atomic_read(&nr_cgroup_events)) | |
| 7813 | + return; | |
| 7814 | + | |
| 7815 | + cgroup_event = (struct perf_cgroup_event){ | |
| 7816 | + .event_id = { | |
| 7817 | + .header = { | |
| 7818 | + .type = PERF_RECORD_CGROUP, | |
| 7819 | + .misc = 0, | |
| 7820 | + .size = sizeof(cgroup_event.event_id), | |
| 7821 | + }, | |
| 7822 | + .id = cgroup_id(cgrp), | |
| 7823 | + }, | |
| 7824 | + }; | |
| 7825 | + | |
| 7826 | + pathname = kmalloc(PATH_MAX, GFP_KERNEL); | |
| 7827 | + if (pathname == NULL) { | |
| 7828 | + cgroup_event.path = path_enomem; | |
| 7829 | + } else { | |
| 7830 | + /* just to be sure to have enough space for alignment */ | |
| 7831 | + cgroup_path(cgrp, pathname, PATH_MAX - sizeof(u64)); | |
| 7832 | + cgroup_event.path = pathname; | |
| 7833 | + } | |
| 7834 | + | |
| 7835 | + /* | |
| 7836 | + * Since our buffer works in 8 byte units we need to align our string | |
| 7837 | + * size to a multiple of 8. However, we must guarantee the tail end is | |
| 7838 | + * zero'd out to avoid leaking random bits to userspace. | |
| 7839 | + */ | |
| 7840 | + size = strlen(cgroup_event.path) + 1; | |
| 7841 | + while (!IS_ALIGNED(size, sizeof(u64))) | |
| 7842 | + cgroup_event.path[size++] = '\0'; | |
| 7843 | + | |
| 7844 | + cgroup_event.event_id.header.size += size; | |
| 7845 | + cgroup_event.path_size = size; | |
| 7846 | + | |
| 7847 | + perf_iterate_sb(perf_event_cgroup_output, | |
| 7848 | + &cgroup_event, | |
| 7849 | + NULL); | |
| 7850 | + | |
| 7851 | + kfree(pathname); | |
| 7852 | +} | |
| 7853 | + | |
| 7854 | +#endif | |
| 7855 | + | |
| 7738 | 7856 | /* |
| 7739 | 7857 | * mmap tracking |
| 7740 | 7858 | */ |
| @@ -10781,6 +10899,8 @@ static void account_event(struct perf_event *event) · 3040 unmodified lines | ||
| 10781 | 10899 | atomic_inc(&nr_comm_events); |
| 10782 | 10900 | if (event->attr.namespaces) |
| 10783 | 10901 | atomic_inc(&nr_namespaces_events); |
| 10902 | + if (event->attr.cgroup) | |
| 10903 | + atomic_inc(&nr_cgroup_events); | |
| 10784 | 10904 | if (event->attr.task) |
| 10785 | 10905 | atomic_inc(&nr_task_events); |
| 10786 | 10906 | if (event->attr.freq) |
| @@ -11160,6 +11280,12 @@ static int perf_copy_attr(struct perf_event_attr __user *uattr, · 373 unmodified lines | ||
| 11160 | 11280 | |
| 11161 | 11281 | if (attr->sample_type & PERF_SAMPLE_REGS_INTR) |
| 11162 | 11282 | ret = perf_reg_validate(attr->sample_regs_intr); |
| 11283 | + | |
| 11284 | +#ifndef CONFIG_CGROUP_PERF | |
| 11285 | + if (attr->sample_type & PERF_SAMPLE_CGROUP) | |
| 11286 | + return -EINVAL; | |
| 11287 | +#endif | |
| 11288 | + | |
| 11163 | 11289 | out: |
| 11164 | 11290 | return ret; |
| 11165 | 11291 | |
| @@ -12757,6 +12883,12 @@ static void perf_cgroup_css_free(struct cgroup_subsys_state *css) · 1591 unmodified lines | ||
| 12757 | 12883 | kfree(jc); |
| 12758 | 12884 | } |
| 12759 | 12885 | |
| 12886 | +static int perf_cgroup_css_online(struct cgroup_subsys_state *css) | |
| 12887 | +{ | |
| 12888 | + perf_event_cgroup(css->cgroup); | |
| 12889 | + return 0; | |
| 12890 | +} | |
| 12891 | + | |
| 12760 | 12892 | static int __perf_cgroup_move(void *info) |
| 12761 | 12893 | { |
| 12762 | 12894 | struct task_struct *task = info; |
| @@ -12778,6 +12910,7 @@ static void perf_cgroup_attach(struct cgroup_taskset *tset) · 15 unmodified lines | ||
| 12778 | 12910 | struct cgroup_subsys perf_event_cgrp_subsys = { |
| 12779 | 12911 | .css_alloc = perf_cgroup_css_alloc, |
| 12780 | 12912 | .css_free = perf_cgroup_css_free, |
| 12913 | + .css_online = perf_cgroup_css_online, | |
| 12781 | 12914 | .attach = perf_cgroup_attach, |
| 12782 | 12915 | /* |
| 12783 | 12916 | * Implicitly enable on dfl hierarchy so that perf events can |