Skip to content

Commit 26c923a

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: "Some tooling fixes plus three kernel fixes: a memory leak fix, a statistics fix and a crash fix" * 'perf-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: perf/x86/intel/uncore: Fix memory leaks on allocation failures perf/core: Fix cgroup time when scheduling descendants perf/core: Avoid freeing static PMU contexts when PMU is unregistered tools include uapi bpf.h: Sync kernel ABI header with tooling header perf pmu: Unbreak perf record for arm/arm64 with events with explicit PMU perf script: Add missing separator for "-F ip,brstack" (and brstackoff) perf callchain: Compare dsos (as well) for CCKEY_FUNCTION
2 parents 60a6ca6 + 47a74bd commit 26c923a

File tree

8 files changed

+74
-26
lines changed

8 files changed

+74
-26
lines changed

arch/x86/events/intel/uncore.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,7 @@ static int __init uncore_type_init(struct intel_uncore_type *type, bool setid)
822822
pmus[i].type = type;
823823
pmus[i].boxes = kzalloc(size, GFP_KERNEL);
824824
if (!pmus[i].boxes)
825-
return -ENOMEM;
825+
goto err;
826826
}
827827

828828
type->pmus = pmus;
@@ -836,7 +836,7 @@ static int __init uncore_type_init(struct intel_uncore_type *type, bool setid)
836836
attr_group = kzalloc(sizeof(struct attribute *) * (i + 1) +
837837
sizeof(*attr_group), GFP_KERNEL);
838838
if (!attr_group)
839-
return -ENOMEM;
839+
goto err;
840840

841841
attrs = (struct attribute **)(attr_group + 1);
842842
attr_group->name = "events";
@@ -849,7 +849,15 @@ static int __init uncore_type_init(struct intel_uncore_type *type, bool setid)
849849
}
850850

851851
type->pmu_group = &uncore_pmu_attr_group;
852+
852853
return 0;
854+
855+
err:
856+
for (i = 0; i < type->num_boxes; i++)
857+
kfree(pmus[i].boxes);
858+
kfree(pmus);
859+
860+
return -ENOMEM;
853861
}
854862

855863
static int __init

kernel/events/core.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ static inline void update_cgrp_time_from_event(struct perf_event *event)
662662
/*
663663
* Do not update time when cgroup is not active
664664
*/
665-
if (cgrp == event->cgrp)
665+
if (cgroup_is_descendant(cgrp->css.cgroup, event->cgrp->css.cgroup))
666666
__update_cgrp_time(event->cgrp);
667667
}
668668

@@ -8955,6 +8955,14 @@ static struct perf_cpu_context __percpu *find_pmu_context(int ctxn)
89558955

89568956
static void free_pmu_context(struct pmu *pmu)
89578957
{
8958+
/*
8959+
* Static contexts such as perf_sw_context have a global lifetime
8960+
* and may be shared between different PMUs. Avoid freeing them
8961+
* when a single PMU is going away.
8962+
*/
8963+
if (pmu->task_ctx_nr > perf_invalid_context)
8964+
return;
8965+
89588966
mutex_lock(&pmus_lock);
89598967
free_percpu(pmu->pmu_cpu_context);
89608968
mutex_unlock(&pmus_lock);

tools/include/uapi/linux/bpf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ union bpf_attr {
312312
* jump into another BPF program
313313
* @ctx: context pointer passed to next program
314314
* @prog_array_map: pointer to map which type is BPF_MAP_TYPE_PROG_ARRAY
315-
* @index: index inside array that selects specific program to run
315+
* @index: 32-bit index inside array that selects specific program to run
316316
* Return: 0 on success or negative error
317317
*
318318
* int bpf_clone_redirect(skb, ifindex, flags)

tools/perf/builtin-script.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ static void print_sample_brstack(struct perf_sample *sample,
586586
thread__find_addr_map(thread, sample->cpumode, MAP__FUNCTION, to, &alt);
587587
}
588588

589-
printf("0x%"PRIx64, from);
589+
printf(" 0x%"PRIx64, from);
590590
if (PRINT_FIELD(DSO)) {
591591
printf("(");
592592
map__fprintf_dsoname(alf.map, stdout);
@@ -681,7 +681,7 @@ static void print_sample_brstackoff(struct perf_sample *sample,
681681
if (alt.map && !alt.map->dso->adjust_symbols)
682682
to = map__map_ip(alt.map, to);
683683

684-
printf("0x%"PRIx64, from);
684+
printf(" 0x%"PRIx64, from);
685685
if (PRINT_FIELD(DSO)) {
686686
printf("(");
687687
map__fprintf_dsoname(alf.map, stdout);

tools/perf/util/callchain.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,8 @@ static enum match_result match_chain(struct callchain_cursor_node *node,
685685
{
686686
struct symbol *sym = node->sym;
687687
u64 left, right;
688+
struct dso *left_dso = NULL;
689+
struct dso *right_dso = NULL;
688690

689691
if (callchain_param.key == CCKEY_SRCLINE) {
690692
enum match_result match = match_chain_srcline(node, cnode);
@@ -696,12 +698,14 @@ static enum match_result match_chain(struct callchain_cursor_node *node,
696698
if (cnode->ms.sym && sym && callchain_param.key == CCKEY_FUNCTION) {
697699
left = cnode->ms.sym->start;
698700
right = sym->start;
701+
left_dso = cnode->ms.map->dso;
702+
right_dso = node->map->dso;
699703
} else {
700704
left = cnode->ip;
701705
right = node->ip;
702706
}
703707

704-
if (left == right) {
708+
if (left == right && left_dso == right_dso) {
705709
if (node->branch) {
706710
cnode->branch_count++;
707711

tools/perf/util/parse-events.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,10 +309,11 @@ static char *get_config_name(struct list_head *head_terms)
309309
static struct perf_evsel *
310310
__add_event(struct list_head *list, int *idx,
311311
struct perf_event_attr *attr,
312-
char *name, struct cpu_map *cpus,
312+
char *name, struct perf_pmu *pmu,
313313
struct list_head *config_terms, bool auto_merge_stats)
314314
{
315315
struct perf_evsel *evsel;
316+
struct cpu_map *cpus = pmu ? pmu->cpus : NULL;
316317

317318
event_attr_init(attr);
318319

@@ -323,7 +324,7 @@ __add_event(struct list_head *list, int *idx,
323324
(*idx)++;
324325
evsel->cpus = cpu_map__get(cpus);
325326
evsel->own_cpus = cpu_map__get(cpus);
326-
evsel->system_wide = !!cpus;
327+
evsel->system_wide = pmu ? pmu->is_uncore : false;
327328
evsel->auto_merge_stats = auto_merge_stats;
328329

329330
if (name)
@@ -1233,7 +1234,7 @@ static int __parse_events_add_pmu(struct parse_events_state *parse_state,
12331234

12341235
if (!head_config) {
12351236
attr.type = pmu->type;
1236-
evsel = __add_event(list, &parse_state->idx, &attr, NULL, pmu->cpus, NULL, auto_merge_stats);
1237+
evsel = __add_event(list, &parse_state->idx, &attr, NULL, pmu, NULL, auto_merge_stats);
12371238
return evsel ? 0 : -ENOMEM;
12381239
}
12391240

@@ -1254,7 +1255,7 @@ static int __parse_events_add_pmu(struct parse_events_state *parse_state,
12541255
return -EINVAL;
12551256

12561257
evsel = __add_event(list, &parse_state->idx, &attr,
1257-
get_config_name(head_config), pmu->cpus,
1258+
get_config_name(head_config), pmu,
12581259
&config_terms, auto_merge_stats);
12591260
if (evsel) {
12601261
evsel->unit = info.unit;

tools/perf/util/pmu.c

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -470,17 +470,36 @@ static void pmu_read_sysfs(void)
470470
closedir(dir);
471471
}
472472

473+
static struct cpu_map *__pmu_cpumask(const char *path)
474+
{
475+
FILE *file;
476+
struct cpu_map *cpus;
477+
478+
file = fopen(path, "r");
479+
if (!file)
480+
return NULL;
481+
482+
cpus = cpu_map__read(file);
483+
fclose(file);
484+
return cpus;
485+
}
486+
487+
/*
488+
* Uncore PMUs have a "cpumask" file under sysfs. CPU PMUs (e.g. on arm/arm64)
489+
* may have a "cpus" file.
490+
*/
491+
#define CPUS_TEMPLATE_UNCORE "%s/bus/event_source/devices/%s/cpumask"
492+
#define CPUS_TEMPLATE_CPU "%s/bus/event_source/devices/%s/cpus"
493+
473494
static struct cpu_map *pmu_cpumask(const char *name)
474495
{
475-
struct stat st;
476496
char path[PATH_MAX];
477-
FILE *file;
478497
struct cpu_map *cpus;
479498
const char *sysfs = sysfs__mountpoint();
480499
const char *templates[] = {
481-
"%s/bus/event_source/devices/%s/cpumask",
482-
"%s/bus/event_source/devices/%s/cpus",
483-
NULL
500+
CPUS_TEMPLATE_UNCORE,
501+
CPUS_TEMPLATE_CPU,
502+
NULL
484503
};
485504
const char **template;
486505

@@ -489,20 +508,25 @@ static struct cpu_map *pmu_cpumask(const char *name)
489508

490509
for (template = templates; *template; template++) {
491510
snprintf(path, PATH_MAX, *template, sysfs, name);
492-
if (stat(path, &st) == 0)
493-
break;
511+
cpus = __pmu_cpumask(path);
512+
if (cpus)
513+
return cpus;
494514
}
495515

496-
if (!*template)
497-
return NULL;
516+
return NULL;
517+
}
498518

499-
file = fopen(path, "r");
500-
if (!file)
501-
return NULL;
519+
static bool pmu_is_uncore(const char *name)
520+
{
521+
char path[PATH_MAX];
522+
struct cpu_map *cpus;
523+
const char *sysfs = sysfs__mountpoint();
502524

503-
cpus = cpu_map__read(file);
504-
fclose(file);
505-
return cpus;
525+
snprintf(path, PATH_MAX, CPUS_TEMPLATE_UNCORE, sysfs, name);
526+
cpus = __pmu_cpumask(path);
527+
cpu_map__put(cpus);
528+
529+
return !!cpus;
506530
}
507531

508532
/*
@@ -617,6 +641,8 @@ static struct perf_pmu *pmu_lookup(const char *name)
617641

618642
pmu->cpus = pmu_cpumask(name);
619643

644+
pmu->is_uncore = pmu_is_uncore(name);
645+
620646
INIT_LIST_HEAD(&pmu->format);
621647
INIT_LIST_HEAD(&pmu->aliases);
622648
list_splice(&format, &pmu->format);

tools/perf/util/pmu.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ struct perf_pmu {
2222
char *name;
2323
__u32 type;
2424
bool selectable;
25+
bool is_uncore;
2526
struct perf_event_attr *default_config;
2627
struct cpu_map *cpus;
2728
struct list_head format; /* HEAD struct perf_pmu_format -> list */

0 commit comments

Comments
 (0)