Skip to content

Commit a116371

Browse files
committed
Merge branch 'perf-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull perf updates from Ingo Molnar. * 'perf-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: ftrace: Make all inline tags also include notrace perf: Use css_tryget() to avoid propping up css refcount perf tools: Fix synthesizing tracepoint names from the perf.data headers perf stat: Fix default output file perf tools: Fix endianity swapping for adds_features bitmask
2 parents 636040b + 6921a57 commit a116371

File tree

7 files changed

+71
-14
lines changed

7 files changed

+71
-14
lines changed

include/linux/compiler-gcc.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@
4747
*/
4848
#if !defined(CONFIG_ARCH_SUPPORTS_OPTIMIZED_INLINING) || \
4949
!defined(CONFIG_OPTIMIZE_INLINING) || (__GNUC__ < 4)
50-
# define inline inline __attribute__((always_inline))
51-
# define __inline__ __inline__ __attribute__((always_inline))
52-
# define __inline __inline __attribute__((always_inline))
50+
# define inline inline __attribute__((always_inline)) notrace
51+
# define __inline__ __inline__ __attribute__((always_inline)) notrace
52+
# define __inline __inline __attribute__((always_inline)) notrace
5353
#else
5454
/* A lot of inline functions can cause havoc with function tracing */
5555
# define inline inline notrace

kernel/events/core.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,9 @@ perf_cgroup_match(struct perf_event *event)
253253
return !event->cgrp || event->cgrp == cpuctx->cgrp;
254254
}
255255

256-
static inline void perf_get_cgroup(struct perf_event *event)
256+
static inline bool perf_tryget_cgroup(struct perf_event *event)
257257
{
258-
css_get(&event->cgrp->css);
258+
return css_tryget(&event->cgrp->css);
259259
}
260260

261261
static inline void perf_put_cgroup(struct perf_event *event)
@@ -484,7 +484,11 @@ static inline int perf_cgroup_connect(int fd, struct perf_event *event,
484484
event->cgrp = cgrp;
485485

486486
/* must be done before we fput() the file */
487-
perf_get_cgroup(event);
487+
if (!perf_tryget_cgroup(event)) {
488+
event->cgrp = NULL;
489+
ret = -ENOENT;
490+
goto out;
491+
}
488492

489493
/*
490494
* all events in a group must monitor

tools/perf/builtin-stat.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1179,6 +1179,12 @@ int cmd_stat(int argc, const char **argv, const char *prefix __used)
11791179
fprintf(stderr, "cannot use both --output and --log-fd\n");
11801180
usage_with_options(stat_usage, options);
11811181
}
1182+
1183+
if (output_fd < 0) {
1184+
fprintf(stderr, "argument to --log-fd must be a > 0\n");
1185+
usage_with_options(stat_usage, options);
1186+
}
1187+
11821188
if (!output) {
11831189
struct timespec tm;
11841190
mode = append_file ? "a" : "w";
@@ -1190,7 +1196,7 @@ int cmd_stat(int argc, const char **argv, const char *prefix __used)
11901196
}
11911197
clock_gettime(CLOCK_REALTIME, &tm);
11921198
fprintf(output, "# started on %s\n", ctime(&tm.tv_sec));
1193-
} else if (output_fd != 2) {
1199+
} else if (output_fd > 0) {
11941200
mode = append_file ? "a" : "w";
11951201
output = fdopen(output_fd, mode);
11961202
if (!output) {

tools/perf/util/header.c

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1942,7 +1942,6 @@ int perf_file_header__read(struct perf_file_header *header,
19421942
else
19431943
return -1;
19441944
} else if (ph->needs_swap) {
1945-
unsigned int i;
19461945
/*
19471946
* feature bitmap is declared as an array of unsigned longs --
19481947
* not good since its size can differ between the host that
@@ -1958,14 +1957,17 @@ int perf_file_header__read(struct perf_file_header *header,
19581957
* file), punt and fallback to the original behavior --
19591958
* clearing all feature bits and setting buildid.
19601959
*/
1961-
for (i = 0; i < BITS_TO_LONGS(HEADER_FEAT_BITS); ++i)
1962-
header->adds_features[i] = bswap_64(header->adds_features[i]);
1960+
mem_bswap_64(&header->adds_features,
1961+
BITS_TO_U64(HEADER_FEAT_BITS));
19631962

19641963
if (!test_bit(HEADER_HOSTNAME, header->adds_features)) {
1965-
for (i = 0; i < BITS_TO_LONGS(HEADER_FEAT_BITS); ++i) {
1966-
header->adds_features[i] = bswap_64(header->adds_features[i]);
1967-
header->adds_features[i] = bswap_32(header->adds_features[i]);
1968-
}
1964+
/* unswap as u64 */
1965+
mem_bswap_64(&header->adds_features,
1966+
BITS_TO_U64(HEADER_FEAT_BITS));
1967+
1968+
/* unswap as u32 */
1969+
mem_bswap_32(&header->adds_features,
1970+
BITS_TO_U32(HEADER_FEAT_BITS));
19691971
}
19701972

19711973
if (!test_bit(HEADER_HOSTNAME, header->adds_features)) {
@@ -2091,6 +2093,35 @@ static int read_attr(int fd, struct perf_header *ph,
20912093
return ret <= 0 ? -1 : 0;
20922094
}
20932095

2096+
static int perf_evsel__set_tracepoint_name(struct perf_evsel *evsel)
2097+
{
2098+
struct event_format *event = trace_find_event(evsel->attr.config);
2099+
char bf[128];
2100+
2101+
if (event == NULL)
2102+
return -1;
2103+
2104+
snprintf(bf, sizeof(bf), "%s:%s", event->system, event->name);
2105+
evsel->name = strdup(bf);
2106+
if (event->name == NULL)
2107+
return -1;
2108+
2109+
return 0;
2110+
}
2111+
2112+
static int perf_evlist__set_tracepoint_names(struct perf_evlist *evlist)
2113+
{
2114+
struct perf_evsel *pos;
2115+
2116+
list_for_each_entry(pos, &evlist->entries, node) {
2117+
if (pos->attr.type == PERF_TYPE_TRACEPOINT &&
2118+
perf_evsel__set_tracepoint_name(pos))
2119+
return -1;
2120+
}
2121+
2122+
return 0;
2123+
}
2124+
20942125
int perf_session__read_header(struct perf_session *session, int fd)
20952126
{
20962127
struct perf_header *header = &session->header;
@@ -2172,6 +2203,9 @@ int perf_session__read_header(struct perf_session *session, int fd)
21722203

21732204
lseek(fd, header->data_offset, SEEK_SET);
21742205

2206+
if (perf_evlist__set_tracepoint_names(session->evlist))
2207+
goto out_delete_evlist;
2208+
21752209
header->frozen = 1;
21762210
return 0;
21772211
out_errno:

tools/perf/util/include/linux/bitops.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#define BITS_PER_LONG __WORDSIZE
99
#define BITS_PER_BYTE 8
1010
#define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))
11+
#define BITS_TO_U64(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(u64))
12+
#define BITS_TO_U32(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(u32))
1113

1214
#define for_each_set_bit(bit, addr, size) \
1315
for ((bit) = find_first_bit((addr), (size)); \

tools/perf/util/session.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,16 @@ static void perf_tool__fill_defaults(struct perf_tool *tool)
442442
tool->finished_round = process_finished_round_stub;
443443
}
444444
}
445+
446+
void mem_bswap_32(void *src, int byte_size)
447+
{
448+
u32 *m = src;
449+
while (byte_size > 0) {
450+
*m = bswap_32(*m);
451+
byte_size -= sizeof(u32);
452+
++m;
453+
}
454+
}
445455

446456
void mem_bswap_64(void *src, int byte_size)
447457
{

tools/perf/util/session.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ struct branch_info *machine__resolve_bstack(struct machine *self,
8080
bool perf_session__has_traces(struct perf_session *self, const char *msg);
8181

8282
void mem_bswap_64(void *src, int byte_size);
83+
void mem_bswap_32(void *src, int byte_size);
8384
void perf_event__attr_swap(struct perf_event_attr *attr);
8485

8586
int perf_session__create_kernel_maps(struct perf_session *self);

0 commit comments

Comments
 (0)