Skip to content

Commit 58f6d42

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 Thomas Gleixner: "A pile of perf updates: - Fix broken sanity check in the /proc/sys/kernel/perf_cpu_time_max_percent write handler - Cure a perf script crash which caused by an unitinialized data structure - Highlight the hottest instruction in perf top and not a random one - Cure yet another clang issue when building perf python - Handle topology entries with no CPU correctly in the tools - Handle perf data which contains both tracepoints and performance counter entries correctly. - Add a missing NULL pointer check in perf ordered_events_free()" * 'perf-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: perf script: Fix crash when processing recorded stat data perf top: Fix wrong hottest instruction highlighted perf tools: Handle TOPOLOGY headers with no CPU perf python: Remove -fstack-clash-protection when building with some clang versions perf core: Fix perf_proc_update_handler() bug perf script: Fix crash with printing mixed trace point and other events perf ordered_events: Fix crash in ordered_events__free
2 parents 89401be + d3c8c0a commit 58f6d42

File tree

6 files changed

+35
-23
lines changed

6 files changed

+35
-23
lines changed

kernel/events/core.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -436,18 +436,18 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
436436
void __user *buffer, size_t *lenp,
437437
loff_t *ppos)
438438
{
439-
int ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
440-
441-
if (ret || !write)
442-
return ret;
443-
439+
int ret;
440+
int perf_cpu = sysctl_perf_cpu_time_max_percent;
444441
/*
445442
* If throttling is disabled don't allow the write:
446443
*/
447-
if (sysctl_perf_cpu_time_max_percent == 100 ||
448-
sysctl_perf_cpu_time_max_percent == 0)
444+
if (write && (perf_cpu == 100 || perf_cpu == 0))
449445
return -EINVAL;
450446

447+
ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
448+
if (ret || !write)
449+
return ret;
450+
451451
max_samples_per_tick = DIV_ROUND_UP(sysctl_perf_event_sample_rate, HZ);
452452
perf_sample_period_ns = NSEC_PER_SEC / sysctl_perf_event_sample_rate;
453453
update_perf_cpu_limits();

tools/perf/builtin-script.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1681,13 +1681,8 @@ static void perf_sample__fprint_metric(struct perf_script *script,
16811681
.force_header = false,
16821682
};
16831683
struct perf_evsel *ev2;
1684-
static bool init;
16851684
u64 val;
16861685

1687-
if (!init) {
1688-
perf_stat__init_shadow_stats();
1689-
init = true;
1690-
}
16911686
if (!evsel->stats)
16921687
perf_evlist__alloc_stats(script->session->evlist, false);
16931688
if (evsel_script(evsel->leader)->gnum++ == 0)
@@ -1794,7 +1789,7 @@ static void process_event(struct perf_script *script,
17941789
return;
17951790
}
17961791

1797-
if (PRINT_FIELD(TRACE)) {
1792+
if (PRINT_FIELD(TRACE) && sample->raw_data) {
17981793
event_format__fprintf(evsel->tp_format, sample->cpu,
17991794
sample->raw_data, sample->raw_size, fp);
18001795
}
@@ -2359,6 +2354,8 @@ static int __cmd_script(struct perf_script *script)
23592354

23602355
signal(SIGINT, sig_handler);
23612356

2357+
perf_stat__init_shadow_stats();
2358+
23622359
/* override event processing functions */
23632360
if (script->show_task_events) {
23642361
script->tool.comm = process_comm_event;

tools/perf/ui/browsers/annotate.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -224,20 +224,24 @@ static unsigned int annotate_browser__refresh(struct ui_browser *browser)
224224
return ret;
225225
}
226226

227-
static int disasm__cmp(struct annotation_line *a, struct annotation_line *b)
227+
static double disasm__cmp(struct annotation_line *a, struct annotation_line *b,
228+
int percent_type)
228229
{
229230
int i;
230231

231232
for (i = 0; i < a->data_nr; i++) {
232-
if (a->data[i].percent == b->data[i].percent)
233+
if (a->data[i].percent[percent_type] == b->data[i].percent[percent_type])
233234
continue;
234-
return a->data[i].percent < b->data[i].percent;
235+
return a->data[i].percent[percent_type] -
236+
b->data[i].percent[percent_type];
235237
}
236238
return 0;
237239
}
238240

239-
static void disasm_rb_tree__insert(struct rb_root *root, struct annotation_line *al)
241+
static void disasm_rb_tree__insert(struct annotate_browser *browser,
242+
struct annotation_line *al)
240243
{
244+
struct rb_root *root = &browser->entries;
241245
struct rb_node **p = &root->rb_node;
242246
struct rb_node *parent = NULL;
243247
struct annotation_line *l;
@@ -246,7 +250,7 @@ static void disasm_rb_tree__insert(struct rb_root *root, struct annotation_line
246250
parent = *p;
247251
l = rb_entry(parent, struct annotation_line, rb_node);
248252

249-
if (disasm__cmp(al, l))
253+
if (disasm__cmp(al, l, browser->opts->percent_type) < 0)
250254
p = &(*p)->rb_left;
251255
else
252256
p = &(*p)->rb_right;
@@ -329,7 +333,7 @@ static void annotate_browser__calc_percent(struct annotate_browser *browser,
329333
RB_CLEAR_NODE(&pos->al.rb_node);
330334
continue;
331335
}
332-
disasm_rb_tree__insert(&browser->entries, &pos->al);
336+
disasm_rb_tree__insert(browser, &pos->al);
333337
}
334338
pthread_mutex_unlock(&notes->lock);
335339

tools/perf/util/cpumap.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,12 @@ struct cpu_map *cpu_map__new(const char *cpu_list)
134134
if (!cpu_list)
135135
return cpu_map__read_all_cpu_map();
136136

137-
if (!isdigit(*cpu_list))
137+
/*
138+
* must handle the case of empty cpumap to cover
139+
* TOPOLOGY header for NUMA nodes with no CPU
140+
* ( e.g., because of CPU hotplug)
141+
*/
142+
if (!isdigit(*cpu_list) && *cpu_list != '\0')
138143
goto out;
139144

140145
while (isdigit(*cpu_list)) {
@@ -181,8 +186,10 @@ struct cpu_map *cpu_map__new(const char *cpu_list)
181186

182187
if (nr_cpus > 0)
183188
cpus = cpu_map__trim_new(nr_cpus, tmp_cpus);
184-
else
189+
else if (*cpu_list != '\0')
185190
cpus = cpu_map__default_new();
191+
else
192+
cpus = cpu_map__dummy_new();
186193
invalid:
187194
free(tmp_cpus);
188195
out:

tools/perf/util/ordered-events.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,8 +391,10 @@ void ordered_events__free(struct ordered_events *oe)
391391
* Current buffer might not have all the events allocated
392392
* yet, we need to free only allocated ones ...
393393
*/
394-
list_del(&oe->buffer->list);
395-
ordered_events_buffer__free(oe->buffer, oe->buffer_idx, oe);
394+
if (oe->buffer) {
395+
list_del(&oe->buffer->list);
396+
ordered_events_buffer__free(oe->buffer, oe->buffer_idx, oe);
397+
}
396398

397399
/* ... and continue with the rest */
398400
list_for_each_entry_safe(buffer, tmp, &oe->to_free, list) {

tools/perf/util/setup.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ def clang_has_option(option):
1717
vars[var] = sub("-mcet", "", vars[var])
1818
if not clang_has_option("-fcf-protection"):
1919
vars[var] = sub("-fcf-protection", "", vars[var])
20+
if not clang_has_option("-fstack-clash-protection"):
21+
vars[var] = sub("-fstack-clash-protection", "", vars[var])
2022

2123
from distutils.core import setup, Extension
2224

0 commit comments

Comments
 (0)