Skip to content

Commit 33726bf

Browse files
committed
Merge branch 'perf-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip
* 'perf-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip: perf: Fix comments in include/linux/perf_event.h perf: Comment /proc/sys/kernel/perf_event_paranoid to be part of user ABI perf python: Fix argument name list of read_on_cpu() perf evlist: Don't die if sample_{id_all|type} is invalid perf python: Use exception to propagate errors perf evlist: Remove dependency on debug routines perf, cgroups: Fix up for new API
2 parents 5b28f6a + d7ebe75 commit 33726bf

File tree

12 files changed

+97
-82
lines changed

12 files changed

+97
-82
lines changed

include/linux/perf_event.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,14 @@ enum perf_event_sample_format {
137137
*
138138
* struct read_format {
139139
* { u64 value;
140-
* { u64 time_enabled; } && PERF_FORMAT_ENABLED
141-
* { u64 time_running; } && PERF_FORMAT_RUNNING
140+
* { u64 time_enabled; } && PERF_FORMAT_TOTAL_TIME_ENABLED
141+
* { u64 time_running; } && PERF_FORMAT_TOTAL_TIME_RUNNING
142142
* { u64 id; } && PERF_FORMAT_ID
143143
* } && !PERF_FORMAT_GROUP
144144
*
145145
* { u64 nr;
146-
* { u64 time_enabled; } && PERF_FORMAT_ENABLED
147-
* { u64 time_running; } && PERF_FORMAT_RUNNING
146+
* { u64 time_enabled; } && PERF_FORMAT_TOTAL_TIME_ENABLED
147+
* { u64 time_running; } && PERF_FORMAT_TOTAL_TIME_RUNNING
148148
* { u64 value;
149149
* { u64 id; } && PERF_FORMAT_ID
150150
* } cntr[nr];

kernel/events/core.c

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7402,26 +7402,12 @@ static int __perf_cgroup_move(void *info)
74027402
return 0;
74037403
}
74047404

7405-
static void perf_cgroup_move(struct task_struct *task)
7405+
static void
7406+
perf_cgroup_attach_task(struct cgroup *cgrp, struct task_struct *task)
74067407
{
74077408
task_function_call(task, __perf_cgroup_move, task);
74087409
}
74097410

7410-
static void perf_cgroup_attach(struct cgroup_subsys *ss, struct cgroup *cgrp,
7411-
struct cgroup *old_cgrp, struct task_struct *task,
7412-
bool threadgroup)
7413-
{
7414-
perf_cgroup_move(task);
7415-
if (threadgroup) {
7416-
struct task_struct *c;
7417-
rcu_read_lock();
7418-
list_for_each_entry_rcu(c, &task->thread_group, thread_group) {
7419-
perf_cgroup_move(c);
7420-
}
7421-
rcu_read_unlock();
7422-
}
7423-
}
7424-
74257411
static void perf_cgroup_exit(struct cgroup_subsys *ss, struct cgroup *cgrp,
74267412
struct cgroup *old_cgrp, struct task_struct *task)
74277413
{
@@ -7433,7 +7419,7 @@ static void perf_cgroup_exit(struct cgroup_subsys *ss, struct cgroup *cgrp,
74337419
if (!(task->flags & PF_EXITING))
74347420
return;
74357421

7436-
perf_cgroup_move(task);
7422+
perf_cgroup_attach_task(cgrp, task);
74377423
}
74387424

74397425
struct cgroup_subsys perf_subsys = {
@@ -7442,6 +7428,6 @@ struct cgroup_subsys perf_subsys = {
74427428
.create = perf_cgroup_create,
74437429
.destroy = perf_cgroup_destroy,
74447430
.exit = perf_cgroup_exit,
7445-
.attach = perf_cgroup_attach,
7431+
.attach_task = perf_cgroup_attach_task,
74467432
};
74477433
#endif /* CONFIG_CGROUP_PERF */

kernel/sysctl.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -938,6 +938,12 @@ static struct ctl_table kern_table[] = {
938938
},
939939
#endif
940940
#ifdef CONFIG_PERF_EVENTS
941+
/*
942+
* User-space scripts rely on the existence of this file
943+
* as a feature check for perf_events being enabled.
944+
*
945+
* So it's an ABI, do not remove!
946+
*/
941947
{
942948
.procname = "perf_event_paranoid",
943949
.data = &sysctl_perf_event_paranoid,

tools/perf/builtin-test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ static int test__basic_mmap(void)
474474
unsigned int nr_events[nsyscalls],
475475
expected_nr_events[nsyscalls], i, j;
476476
struct perf_evsel *evsels[nsyscalls], *evsel;
477-
int sample_size = perf_sample_size(attr.sample_type);
477+
int sample_size = __perf_evsel__sample_size(attr.sample_type);
478478

479479
for (i = 0; i < nsyscalls; ++i) {
480480
char name[64];

tools/perf/util/event.c

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,6 @@ const char *perf_event__name(unsigned int id)
3535
return perf_event__names[id];
3636
}
3737

38-
int perf_sample_size(u64 sample_type)
39-
{
40-
u64 mask = sample_type & PERF_SAMPLE_MASK;
41-
int size = 0;
42-
int i;
43-
44-
for (i = 0; i < 64; i++) {
45-
if (mask & (1ULL << i))
46-
size++;
47-
}
48-
49-
size *= sizeof(u64);
50-
51-
return size;
52-
}
53-
5438
static struct perf_sample synth_sample = {
5539
.pid = -1,
5640
.tid = -1,

tools/perf/util/event.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,6 @@ struct perf_sample {
8282
struct ip_callchain *callchain;
8383
};
8484

85-
int perf_sample_size(u64 sample_type);
86-
8785
#define BUILD_ID_SIZE 20
8886

8987
struct build_id_event {

tools/perf/util/evlist.c

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include "evlist.h"
1313
#include "evsel.h"
1414
#include "util.h"
15-
#include "debug.h"
1615

1716
#include <sys/mman.h>
1817

@@ -257,19 +256,15 @@ int perf_evlist__alloc_mmap(struct perf_evlist *evlist)
257256
return evlist->mmap != NULL ? 0 : -ENOMEM;
258257
}
259258

260-
static int __perf_evlist__mmap(struct perf_evlist *evlist, struct perf_evsel *evsel,
259+
static int __perf_evlist__mmap(struct perf_evlist *evlist,
261260
int idx, int prot, int mask, int fd)
262261
{
263262
evlist->mmap[idx].prev = 0;
264263
evlist->mmap[idx].mask = mask;
265264
evlist->mmap[idx].base = mmap(NULL, evlist->mmap_len, prot,
266265
MAP_SHARED, fd, 0);
267-
if (evlist->mmap[idx].base == MAP_FAILED) {
268-
if (evlist->cpus->map[idx] == -1 && evsel->attr.inherit)
269-
ui__warning("Inherit is not allowed on per-task "
270-
"events using mmap.\n");
266+
if (evlist->mmap[idx].base == MAP_FAILED)
271267
return -1;
272-
}
273268

274269
perf_evlist__add_pollfd(evlist, fd);
275270
return 0;
@@ -289,7 +284,7 @@ static int perf_evlist__mmap_per_cpu(struct perf_evlist *evlist, int prot, int m
289284

290285
if (output == -1) {
291286
output = fd;
292-
if (__perf_evlist__mmap(evlist, evsel, cpu,
287+
if (__perf_evlist__mmap(evlist, cpu,
293288
prot, mask, output) < 0)
294289
goto out_unmap;
295290
} else {
@@ -329,7 +324,7 @@ static int perf_evlist__mmap_per_thread(struct perf_evlist *evlist, int prot, in
329324

330325
if (output == -1) {
331326
output = fd;
332-
if (__perf_evlist__mmap(evlist, evsel, thread,
327+
if (__perf_evlist__mmap(evlist, thread,
333328
prot, mask, output) < 0)
334329
goto out_unmap;
335330
} else {
@@ -460,33 +455,46 @@ int perf_evlist__set_filters(struct perf_evlist *evlist)
460455
return 0;
461456
}
462457

463-
u64 perf_evlist__sample_type(struct perf_evlist *evlist)
458+
bool perf_evlist__valid_sample_type(const struct perf_evlist *evlist)
464459
{
465-
struct perf_evsel *pos;
466-
u64 type = 0;
467-
468-
list_for_each_entry(pos, &evlist->entries, node) {
469-
if (!type)
470-
type = pos->attr.sample_type;
471-
else if (type != pos->attr.sample_type)
472-
die("non matching sample_type");
460+
struct perf_evsel *pos, *first;
461+
462+
pos = first = list_entry(evlist->entries.next, struct perf_evsel, node);
463+
464+
list_for_each_entry_continue(pos, &evlist->entries, node) {
465+
if (first->attr.sample_type != pos->attr.sample_type)
466+
return false;
473467
}
474468

475-
return type;
469+
return true;
476470
}
477471

478-
bool perf_evlist__sample_id_all(const struct perf_evlist *evlist)
472+
u64 perf_evlist__sample_type(const struct perf_evlist *evlist)
473+
{
474+
struct perf_evsel *first;
475+
476+
first = list_entry(evlist->entries.next, struct perf_evsel, node);
477+
return first->attr.sample_type;
478+
}
479+
480+
bool perf_evlist__valid_sample_id_all(const struct perf_evlist *evlist)
479481
{
480-
bool value = false, first = true;
481-
struct perf_evsel *pos;
482-
483-
list_for_each_entry(pos, &evlist->entries, node) {
484-
if (first) {
485-
value = pos->attr.sample_id_all;
486-
first = false;
487-
} else if (value != pos->attr.sample_id_all)
488-
die("non matching sample_id_all");
482+
struct perf_evsel *pos, *first;
483+
484+
pos = first = list_entry(evlist->entries.next, struct perf_evsel, node);
485+
486+
list_for_each_entry_continue(pos, &evlist->entries, node) {
487+
if (first->attr.sample_id_all != pos->attr.sample_id_all)
488+
return false;
489489
}
490490

491-
return value;
491+
return true;
492+
}
493+
494+
bool perf_evlist__sample_id_all(const struct perf_evlist *evlist)
495+
{
496+
struct perf_evsel *first;
497+
498+
first = list_entry(evlist->entries.next, struct perf_evsel, node);
499+
return first->attr.sample_id_all;
492500
}

tools/perf/util/evlist.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ int perf_evlist__create_maps(struct perf_evlist *evlist, pid_t target_pid,
6666
void perf_evlist__delete_maps(struct perf_evlist *evlist);
6767
int perf_evlist__set_filters(struct perf_evlist *evlist);
6868

69-
u64 perf_evlist__sample_type(struct perf_evlist *evlist);
70-
bool perf_evlist__sample_id_all(const struct perf_evlist *evlist);
69+
u64 perf_evlist__sample_type(const struct perf_evlist *evlist);
70+
bool perf_evlist__sample_id_all(const const struct perf_evlist *evlist);
7171

72+
bool perf_evlist__valid_sample_type(const struct perf_evlist *evlist);
73+
bool perf_evlist__valid_sample_id_all(const struct perf_evlist *evlist);
7274
#endif /* __PERF_EVLIST_H */

tools/perf/util/evsel.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,22 @@
1515

1616
#define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y))
1717

18+
int __perf_evsel__sample_size(u64 sample_type)
19+
{
20+
u64 mask = sample_type & PERF_SAMPLE_MASK;
21+
int size = 0;
22+
int i;
23+
24+
for (i = 0; i < 64; i++) {
25+
if (mask & (1ULL << i))
26+
size++;
27+
}
28+
29+
size *= sizeof(u64);
30+
31+
return size;
32+
}
33+
1834
void perf_evsel__init(struct perf_evsel *evsel,
1935
struct perf_event_attr *attr, int idx)
2036
{

tools/perf/util/evsel.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,4 +149,11 @@ static inline int perf_evsel__read_scaled(struct perf_evsel *evsel,
149149
return __perf_evsel__read(evsel, ncpus, nthreads, true);
150150
}
151151

152+
int __perf_evsel__sample_size(u64 sample_type);
153+
154+
static inline int perf_evsel__sample_size(struct perf_evsel *evsel)
155+
{
156+
return __perf_evsel__sample_size(evsel->attr.sample_type);
157+
}
158+
152159
#endif /* __PERF_EVSEL_H */

tools/perf/util/python.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ static PyObject *pyrf_evlist__read_on_cpu(struct pyrf_evlist *pevlist,
674674
struct perf_evlist *evlist = &pevlist->evlist;
675675
union perf_event *event;
676676
int sample_id_all = 1, cpu;
677-
static char *kwlist[] = {"sample_id_all", NULL, NULL};
677+
static char *kwlist[] = {"cpu", "sample_id_all", NULL, NULL};
678678
int err;
679679

680680
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i|i", kwlist,
@@ -692,16 +692,14 @@ static PyObject *pyrf_evlist__read_on_cpu(struct pyrf_evlist *pevlist,
692692

693693
first = list_entry(evlist->entries.next, struct perf_evsel, node);
694694
err = perf_event__parse_sample(event, first->attr.sample_type,
695-
perf_sample_size(first->attr.sample_type),
695+
perf_evsel__sample_size(first),
696696
sample_id_all, &pevent->sample);
697-
if (err) {
698-
pr_err("Can't parse sample, err = %d\n", err);
699-
goto end;
700-
}
701-
697+
if (err)
698+
return PyErr_Format(PyExc_OSError,
699+
"perf: can't parse sample, err=%d", err);
702700
return pyevent;
703701
}
704-
end:
702+
705703
Py_INCREF(Py_None);
706704
return Py_None;
707705
}

tools/perf/util/session.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,16 @@ static int perf_session__open(struct perf_session *self, bool force)
5858
goto out_close;
5959
}
6060

61+
if (!perf_evlist__valid_sample_type(self->evlist)) {
62+
pr_err("non matching sample_type");
63+
goto out_close;
64+
}
65+
66+
if (!perf_evlist__valid_sample_id_all(self->evlist)) {
67+
pr_err("non matching sample_id_all");
68+
goto out_close;
69+
}
70+
6171
self->size = input_stat.st_size;
6272
return 0;
6373

@@ -97,7 +107,7 @@ static void perf_session__id_header_size(struct perf_session *session)
97107
void perf_session__update_sample_type(struct perf_session *self)
98108
{
99109
self->sample_type = perf_evlist__sample_type(self->evlist);
100-
self->sample_size = perf_sample_size(self->sample_type);
110+
self->sample_size = __perf_evsel__sample_size(self->sample_type);
101111
self->sample_id_all = perf_evlist__sample_id_all(self->evlist);
102112
perf_session__id_header_size(self);
103113
}

0 commit comments

Comments
 (0)