History

Merge tag 'perf-urgent-for-mingo-5.7-20200403' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/urgent

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.

Ingo Molnar committed 6 years ago

Commit 7dc41b92 parents 42595ce 9ff76ce100 files · +3182 −622Browse files

Showing the changes to kernel (1 of 100 files). Show all

Unified · Split

kernel/events/core.c+133−0
@@ -387,6 +387,7 @@ static atomic_t nr_freq_events __read_mostly; · 386 unmodified lines
387387 static atomic_t nr_switch_events __read_mostly;
388388 static atomic_t nr_ksymbol_events __read_mostly;
389389 static atomic_t nr_bpf_events __read_mostly;
390+static atomic_t nr_cgroup_events __read_mostly;
390391
391392 static LIST_HEAD(pmus);
392393 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
18611862 if (sample_type & PERF_SAMPLE_PHYS_ADDR)
18621863 size += sizeof(data->phys_addr);
18631864
1865+ if (sample_type & PERF_SAMPLE_CGROUP)
1866+ size += sizeof(data->cgroup);
1867+
18641868 event->header_size = size;
18651869 }
18661870
@@ -4608,6 +4612,8 @@ static void unaccount_event(struct perf_event *event) · 2741 unmodified lines
46084612 atomic_dec(&nr_comm_events);
46094613 if (event->attr.namespaces)
46104614 atomic_dec(&nr_namespaces_events);
4615+ if (event->attr.cgroup)
4616+ atomic_dec(&nr_cgroup_events);
46114617 if (event->attr.task)
46124618 atomic_dec(&nr_task_events);
46134619 if (event->attr.freq)
@@ -6864,6 +6870,9 @@ void perf_output_sample(struct perf_output_handle *handle, · 2250 unmodified lines
68646870 if (sample_type & PERF_SAMPLE_PHYS_ADDR)
68656871 perf_output_put(handle, data->phys_addr);
68666872
6873+ if (sample_type & PERF_SAMPLE_CGROUP)
6874+ perf_output_put(handle, data->cgroup);
6875+
68676876 if (sample_type & PERF_SAMPLE_AUX) {
68686877 perf_output_put(handle, data->aux_size);
68696878
@@ -7063,6 +7072,16 @@ void perf_prepare_sample(struct perf_event_header *header, · 193 unmodified lines
70637072 if (sample_type & PERF_SAMPLE_PHYS_ADDR)
70647073 data->phys_addr = perf_virt_to_phys(data->addr);
70657074
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+
70667085 if (sample_type & PERF_SAMPLE_AUX) {
70677086 u64 size;
70687087
@@ -7735,6 +7754,105 @@ void perf_event_namespaces(struct task_struct *task) · 666 unmodified lines
77357754 NULL);
77367755 }
77377756
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+
77387856 /*
77397857 * mmap tracking
77407858 */
@@ -10781,6 +10899,8 @@ static void account_event(struct perf_event *event) · 3040 unmodified lines
1078110899 atomic_inc(&nr_comm_events);
1078210900 if (event->attr.namespaces)
1078310901 atomic_inc(&nr_namespaces_events);
10902+ if (event->attr.cgroup)
10903+ atomic_inc(&nr_cgroup_events);
1078410904 if (event->attr.task)
1078510905 atomic_inc(&nr_task_events);
1078610906 if (event->attr.freq)
@@ -11160,6 +11280,12 @@ static int perf_copy_attr(struct perf_event_attr __user *uattr, · 373 unmodified lines
1116011280
1116111281 if (attr->sample_type & PERF_SAMPLE_REGS_INTR)
1116211282 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+
1116311289 out:
1116411290 return ret;
1116511291
@@ -12757,6 +12883,12 @@ static void perf_cgroup_css_free(struct cgroup_subsys_state *css) · 1591 unmodified lines
1275712883 kfree(jc);
1275812884 }
1275912885
12886+static int perf_cgroup_css_online(struct cgroup_subsys_state *css)
12887+{
12888+ perf_event_cgroup(css->cgroup);
12889+ return 0;
12890+}
12891+
1276012892 static int __perf_cgroup_move(void *info)
1276112893 {
1276212894 struct task_struct *task = info;
@@ -12778,6 +12910,7 @@ static void perf_cgroup_attach(struct cgroup_taskset *tset) · 15 unmodified lines
1277812910 struct cgroup_subsys perf_event_cgrp_subsys = {
1277912911 .css_alloc = perf_cgroup_css_alloc,
1278012912 .css_free = perf_cgroup_css_free,
12913+ .css_online = perf_cgroup_css_online,
1278112914 .attach = perf_cgroup_attach,
1278212915 /*
1278312916 * Implicitly enable on dfl hierarchy so that perf events can

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t