Skip to content

Commit 46c1e79

Browse files
committed
Merge branch 'perf-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull perf fixes from Ingo Molnar: "A handful of tooling fixes" * 'perf-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: perf stat: Wait for the correct child perf tools: Support running perf binaries with a dash in their name perf config: Check not only section->from_system_config but also item's perf ui progress: Fix progress update perf ui progress: Make sure we always define step value perf tools: Open perf.data with O_CLOEXEC flag tools lib api: Fix make DEBUG=1 build perf tests: Fix compile when libunwind's unwind.h is available tools include linux: Guard against redefinition of some macros
2 parents ec846ec + b130a69 commit 46c1e79

File tree

8 files changed

+45
-14
lines changed

8 files changed

+45
-14
lines changed

tools/include/linux/compiler-gcc.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,14 @@
2121
#define __must_be_array(a) BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0]))
2222

2323
#define noinline __attribute__((noinline))
24-
24+
#ifndef __packed
2525
#define __packed __attribute__((packed))
26-
26+
#endif
27+
#ifndef __noreturn
2728
#define __noreturn __attribute__((noreturn))
28-
29+
#endif
30+
#ifndef __aligned
2931
#define __aligned(x) __attribute__((aligned(x)))
32+
#endif
3033
#define __printf(a, b) __attribute__((format(printf, a, b)))
3134
#define __scanf(a, b) __attribute__((format(scanf, a, b)))

tools/lib/api/Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,19 @@ MAKEFLAGS += --no-print-directory
1717
LIBFILE = $(OUTPUT)libapi.a
1818

1919
CFLAGS := $(EXTRA_WARNINGS) $(EXTRA_CFLAGS)
20-
CFLAGS += -ggdb3 -Wall -Wextra -std=gnu99 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fPIC
20+
CFLAGS += -ggdb3 -Wall -Wextra -std=gnu99 -U_FORTIFY_SOURCE -fPIC
2121

22+
ifeq ($(DEBUG),0)
2223
ifeq ($(CC_NO_CLANG), 0)
2324
CFLAGS += -O3
2425
else
2526
CFLAGS += -O6
2627
endif
28+
endif
29+
30+
ifeq ($(DEBUG),0)
31+
CFLAGS += -D_FORTIFY_SOURCE
32+
endif
2733

2834
# Treat warnings as errors unless directed not to
2935
ifneq ($(WERROR),0)

tools/perf/builtin-config.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ static int set_config(struct perf_config_set *set, const char *file_name,
5959
fprintf(fp, "[%s]\n", section->name);
6060

6161
perf_config_items__for_each_entry(&section->items, item) {
62-
if (!use_system_config && section->from_system_config)
62+
if (!use_system_config && item->from_system_config)
6363
continue;
6464
if (item->value)
6565
fprintf(fp, "\t%s = %s\n",

tools/perf/builtin-stat.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ static int __run_perf_stat(int argc, const char **argv)
707707
process_interval();
708708
}
709709
}
710-
wait(&status);
710+
waitpid(child_pid, &status, 0);
711711

712712
if (workload_exec_errno) {
713713
const char *emsg = str_error_r(workload_exec_errno, msg, sizeof(msg));

tools/perf/perf.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -467,15 +467,21 @@ int main(int argc, const char **argv)
467467
* - cannot execute it externally (since it would just do
468468
* the same thing over again)
469469
*
470-
* So we just directly call the internal command handler, and
471-
* die if that one cannot handle it.
470+
* So we just directly call the internal command handler. If that one
471+
* fails to handle this, then maybe we just run a renamed perf binary
472+
* that contains a dash in its name. To handle this scenario, we just
473+
* fall through and ignore the "xxxx" part of the command string.
472474
*/
473475
if (strstarts(cmd, "perf-")) {
474476
cmd += 5;
475477
argv[0] = cmd;
476478
handle_internal_command(argc, argv);
477-
fprintf(stderr, "cannot handle %s internally", cmd);
478-
goto out;
479+
/*
480+
* If the command is handled, the above function does not
481+
* return undo changes and fall through in such a case.
482+
*/
483+
cmd -= 5;
484+
argv[0] = cmd;
479485
}
480486
if (strstarts(cmd, "trace")) {
481487
#ifdef HAVE_LIBAUDIT_SUPPORT

tools/perf/tests/dwarf-unwind.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include "debug.h"
77
#include "machine.h"
88
#include "event.h"
9-
#include "unwind.h"
9+
#include "../util/unwind.h"
1010
#include "perf_regs.h"
1111
#include "map.h"
1212
#include "thread.h"

tools/perf/ui/progress.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include <linux/kernel.h>
12
#include "../cache.h"
23
#include "progress.h"
34

@@ -14,18 +15,22 @@ struct ui_progress_ops *ui_progress__ops = &null_progress__ops;
1415

1516
void ui_progress__update(struct ui_progress *p, u64 adv)
1617
{
18+
u64 last = p->curr;
19+
1720
p->curr += adv;
1821

1922
if (p->curr >= p->next) {
20-
p->next += p->step;
23+
u64 nr = DIV_ROUND_UP(p->curr - last, p->step);
24+
25+
p->next += nr * p->step;
2126
ui_progress__ops->update(p);
2227
}
2328
}
2429

2530
void ui_progress__init(struct ui_progress *p, u64 total, const char *title)
2631
{
2732
p->curr = 0;
28-
p->next = p->step = total / 16;
33+
p->next = p->step = total / 16 ?: 1;
2934
p->total = total;
3035
p->title = title;
3136

tools/perf/util/data.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@
1010
#include "util.h"
1111
#include "debug.h"
1212

13+
#ifndef O_CLOEXEC
14+
#ifdef __sparc__
15+
#define O_CLOEXEC 0x400000
16+
#elif defined(__alpha__) || defined(__hppa__)
17+
#define O_CLOEXEC 010000000
18+
#else
19+
#define O_CLOEXEC 02000000
20+
#endif
21+
#endif
22+
1323
static bool check_pipe(struct perf_data_file *file)
1424
{
1525
struct stat st;
@@ -96,7 +106,8 @@ static int open_file_write(struct perf_data_file *file)
96106
if (check_backup(file))
97107
return -1;
98108

99-
fd = open(file->path, O_CREAT|O_RDWR|O_TRUNC, S_IRUSR|S_IWUSR);
109+
fd = open(file->path, O_CREAT|O_RDWR|O_TRUNC|O_CLOEXEC,
110+
S_IRUSR|S_IWUSR);
100111

101112
if (fd < 0)
102113
pr_err("failed to open %s : %s\n", file->path,

0 commit comments

Comments
 (0)