Skip to content

Commit 40bcea7

Browse files
author
Ingo Molnar
committed
Merge branch 'tip/perf/core' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-2.6-trace into perf/core
2 parents 492f73a + 14a8fd7 commit 40bcea7

26 files changed

Lines changed: 1663 additions & 1003 deletions

‎Documentation/trace/kprobetrace.txt‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,15 @@ current_tracer. Instead of that, add probe points via
2222

2323
Synopsis of kprobe_events
2424
-------------------------
25-
p[:[GRP/]EVENT] SYMBOL[+offs]|MEMADDR [FETCHARGS] : Set a probe
26-
r[:[GRP/]EVENT] SYMBOL[+0] [FETCHARGS] : Set a return probe
25+
p[:[GRP/]EVENT] [MOD:]SYM[+offs]|MEMADDR [FETCHARGS] : Set a probe
26+
r[:[GRP/]EVENT] [MOD:]SYM[+0] [FETCHARGS] : Set a return probe
2727
-:[GRP/]EVENT : Clear a probe
2828

2929
GRP : Group name. If omitted, use "kprobes" for it.
3030
EVENT : Event name. If omitted, the event name is generated
31-
based on SYMBOL+offs or MEMADDR.
32-
SYMBOL[+offs] : Symbol+offset where the probe is inserted.
31+
based on SYM+offs or MEMADDR.
32+
MOD : Module name which has given SYM.
33+
SYM[+offs] : Symbol+offset where the probe is inserted.
3334
MEMADDR : Address where the probe is inserted.
3435

3536
FETCHARGS : Arguments. Each probe can have up to 128 args.

‎arch/x86/include/asm/perf_event_p4.h‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,14 @@
101101
#define P4_CONFIG_HT_SHIFT 63
102102
#define P4_CONFIG_HT (1ULL << P4_CONFIG_HT_SHIFT)
103103

104+
/*
105+
* If an event has alias it should be marked
106+
* with a special bit. (Don't forget to check
107+
* P4_PEBS_CONFIG_MASK and related bits on
108+
* modification.)
109+
*/
110+
#define P4_CONFIG_ALIASABLE (1 << 9)
111+
104112
/*
105113
* The bits we allow to pass for RAW events
106114
*/
@@ -123,6 +131,31 @@
123131
(p4_config_pack_escr(P4_CONFIG_MASK_ESCR)) | \
124132
(p4_config_pack_cccr(P4_CONFIG_MASK_CCCR))
125133

134+
/*
135+
* In case of event aliasing we need to preserve some
136+
* caller bits otherwise the mapping won't be complete.
137+
*/
138+
#define P4_CONFIG_EVENT_ALIAS_MASK \
139+
(p4_config_pack_escr(P4_CONFIG_MASK_ESCR) | \
140+
p4_config_pack_cccr(P4_CCCR_EDGE | \
141+
P4_CCCR_THRESHOLD_MASK | \
142+
P4_CCCR_COMPLEMENT | \
143+
P4_CCCR_COMPARE))
144+
145+
#define P4_CONFIG_EVENT_ALIAS_IMMUTABLE_BITS \
146+
((P4_CONFIG_HT) | \
147+
p4_config_pack_escr(P4_ESCR_T0_OS | \
148+
P4_ESCR_T0_USR | \
149+
P4_ESCR_T1_OS | \
150+
P4_ESCR_T1_USR) | \
151+
p4_config_pack_cccr(P4_CCCR_OVF | \
152+
P4_CCCR_CASCADE | \
153+
P4_CCCR_FORCE_OVF | \
154+
P4_CCCR_THREAD_ANY | \
155+
P4_CCCR_OVF_PMI_T0 | \
156+
P4_CCCR_OVF_PMI_T1 | \
157+
P4_CONFIG_ALIASABLE))
158+
126159
static inline bool p4_is_event_cascaded(u64 config)
127160
{
128161
u32 cccr = p4_config_unpack_cccr(config);

‎arch/x86/kernel/cpu/perf_event.c‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,6 @@ struct x86_pmu {
274274
void (*enable_all)(int added);
275275
void (*enable)(struct perf_event *);
276276
void (*disable)(struct perf_event *);
277-
void (*hw_watchdog_set_attr)(struct perf_event_attr *attr);
278277
int (*hw_config)(struct perf_event *event);
279278
int (*schedule_events)(struct cpu_hw_events *cpuc, int n, int *assign);
280279
unsigned eventsel;
@@ -360,12 +359,6 @@ static u64 __read_mostly hw_cache_extra_regs
360359
[PERF_COUNT_HW_CACHE_OP_MAX]
361360
[PERF_COUNT_HW_CACHE_RESULT_MAX];
362361

363-
void hw_nmi_watchdog_set_attr(struct perf_event_attr *wd_attr)
364-
{
365-
if (x86_pmu.hw_watchdog_set_attr)
366-
x86_pmu.hw_watchdog_set_attr(wd_attr);
367-
}
368-
369362
/*
370363
* Propagate event elapsed time into the generic event.
371364
* Can only be executed on the CPU where the event is active.

‎arch/x86/kernel/cpu/perf_event_p4.c‎

Lines changed: 106 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -570,11 +570,92 @@ static __initconst const u64 p4_hw_cache_event_ids
570570
},
571571
};
572572

573+
/*
574+
* Because of Netburst being quite restricted in now
575+
* many same events can run simultaneously, we use
576+
* event aliases, ie different events which have the
577+
* same functionallity but use non-intersected resources
578+
* (ESCR/CCCR/couter registers). This allow us to run
579+
* two or more semi-same events together. It is done
580+
* transparently to a user space.
581+
*
582+
* Never set any cusom internal bits such as P4_CONFIG_HT,
583+
* P4_CONFIG_ALIASABLE or bits for P4_PEBS_METRIC, they are
584+
* either up-to-dated automatically either not appliable
585+
* at all.
586+
*
587+
* And be really carefull choosing aliases!
588+
*/
589+
struct p4_event_alias {
590+
u64 orig;
591+
u64 alter;
592+
} p4_event_aliases[] = {
593+
{
594+
/*
595+
* Non-halted cycles can be substituted with
596+
* non-sleeping cycles (see Intel SDM Vol3b for
597+
* details).
598+
*/
599+
.orig =
600+
p4_config_pack_escr(P4_ESCR_EVENT(P4_EVENT_GLOBAL_POWER_EVENTS) |
601+
P4_ESCR_EMASK_BIT(P4_EVENT_GLOBAL_POWER_EVENTS, RUNNING)),
602+
.alter =
603+
p4_config_pack_escr(P4_ESCR_EVENT(P4_EVENT_EXECUTION_EVENT) |
604+
P4_ESCR_EMASK_BIT(P4_EVENT_EXECUTION_EVENT, NBOGUS0)|
605+
P4_ESCR_EMASK_BIT(P4_EVENT_EXECUTION_EVENT, NBOGUS1)|
606+
P4_ESCR_EMASK_BIT(P4_EVENT_EXECUTION_EVENT, NBOGUS2)|
607+
P4_ESCR_EMASK_BIT(P4_EVENT_EXECUTION_EVENT, NBOGUS3)|
608+
P4_ESCR_EMASK_BIT(P4_EVENT_EXECUTION_EVENT, BOGUS0) |
609+
P4_ESCR_EMASK_BIT(P4_EVENT_EXECUTION_EVENT, BOGUS1) |
610+
P4_ESCR_EMASK_BIT(P4_EVENT_EXECUTION_EVENT, BOGUS2) |
611+
P4_ESCR_EMASK_BIT(P4_EVENT_EXECUTION_EVENT, BOGUS3))|
612+
p4_config_pack_cccr(P4_CCCR_THRESHOLD(15) | P4_CCCR_COMPLEMENT |
613+
P4_CCCR_COMPARE),
614+
},
615+
};
616+
617+
static u64 p4_get_alias_event(u64 config)
618+
{
619+
u64 config_match;
620+
int i;
621+
622+
/*
623+
* Probably we're lucky and don't have to do
624+
* matching over all config bits.
625+
*/
626+
if (!(config & P4_CONFIG_ALIASABLE))
627+
return 0;
628+
629+
config_match = config & P4_CONFIG_EVENT_ALIAS_MASK;
630+
631+
/*
632+
* If an event was previously swapped to the alter config
633+
* we should swap it back otherwise contnention on registers
634+
* will return back.
635+
*/
636+
for (i = 0; i < ARRAY_SIZE(p4_event_aliases); i++) {
637+
if (config_match == p4_event_aliases[i].orig) {
638+
config_match = p4_event_aliases[i].alter;
639+
break;
640+
} else if (config_match == p4_event_aliases[i].alter) {
641+
config_match = p4_event_aliases[i].orig;
642+
break;
643+
}
644+
}
645+
646+
if (i >= ARRAY_SIZE(p4_event_aliases))
647+
return 0;
648+
649+
return config_match |
650+
(config & P4_CONFIG_EVENT_ALIAS_IMMUTABLE_BITS);
651+
}
652+
573653
static u64 p4_general_events[PERF_COUNT_HW_MAX] = {
574654
/* non-halted CPU clocks */
575655
[PERF_COUNT_HW_CPU_CYCLES] =
576656
p4_config_pack_escr(P4_ESCR_EVENT(P4_EVENT_GLOBAL_POWER_EVENTS) |
577-
P4_ESCR_EMASK_BIT(P4_EVENT_GLOBAL_POWER_EVENTS, RUNNING)),
657+
P4_ESCR_EMASK_BIT(P4_EVENT_GLOBAL_POWER_EVENTS, RUNNING)) |
658+
P4_CONFIG_ALIASABLE,
578659

579660
/*
580661
* retired instructions
@@ -719,31 +800,6 @@ static int p4_validate_raw_event(struct perf_event *event)
719800
return 0;
720801
}
721802

722-
static void p4_hw_watchdog_set_attr(struct perf_event_attr *wd_attr)
723-
{
724-
/*
725-
* Watchdog ticks are special on Netburst, we use
726-
* that named "non-sleeping" ticks as recommended
727-
* by Intel SDM Vol3b.
728-
*/
729-
WARN_ON_ONCE(wd_attr->type != PERF_TYPE_HARDWARE ||
730-
wd_attr->config != PERF_COUNT_HW_CPU_CYCLES);
731-
732-
wd_attr->type = PERF_TYPE_RAW;
733-
wd_attr->config =
734-
p4_config_pack_escr(P4_ESCR_EVENT(P4_EVENT_EXECUTION_EVENT) |
735-
P4_ESCR_EMASK_BIT(P4_EVENT_EXECUTION_EVENT, NBOGUS0) |
736-
P4_ESCR_EMASK_BIT(P4_EVENT_EXECUTION_EVENT, NBOGUS1) |
737-
P4_ESCR_EMASK_BIT(P4_EVENT_EXECUTION_EVENT, NBOGUS2) |
738-
P4_ESCR_EMASK_BIT(P4_EVENT_EXECUTION_EVENT, NBOGUS3) |
739-
P4_ESCR_EMASK_BIT(P4_EVENT_EXECUTION_EVENT, BOGUS0) |
740-
P4_ESCR_EMASK_BIT(P4_EVENT_EXECUTION_EVENT, BOGUS1) |
741-
P4_ESCR_EMASK_BIT(P4_EVENT_EXECUTION_EVENT, BOGUS2) |
742-
P4_ESCR_EMASK_BIT(P4_EVENT_EXECUTION_EVENT, BOGUS3)) |
743-
p4_config_pack_cccr(P4_CCCR_THRESHOLD(15) | P4_CCCR_COMPLEMENT |
744-
P4_CCCR_COMPARE);
745-
}
746-
747803
static int p4_hw_config(struct perf_event *event)
748804
{
749805
int cpu = get_cpu();
@@ -1159,6 +1215,8 @@ static int p4_pmu_schedule_events(struct cpu_hw_events *cpuc, int n, int *assign
11591215
struct p4_event_bind *bind;
11601216
unsigned int i, thread, num;
11611217
int cntr_idx, escr_idx;
1218+
u64 config_alias;
1219+
int pass;
11621220

11631221
bitmap_zero(used_mask, X86_PMC_IDX_MAX);
11641222
bitmap_zero(escr_mask, P4_ESCR_MSR_TABLE_SIZE);
@@ -1167,6 +1225,17 @@ static int p4_pmu_schedule_events(struct cpu_hw_events *cpuc, int n, int *assign
11671225

11681226
hwc = &cpuc->event_list[i]->hw;
11691227
thread = p4_ht_thread(cpu);
1228+
pass = 0;
1229+
1230+
again:
1231+
/*
1232+
* Aliases are swappable so we may hit circular
1233+
* lock if both original config and alias need
1234+
* resources (MSR registers) which already busy.
1235+
*/
1236+
if (pass > 2)
1237+
goto done;
1238+
11701239
bind = p4_config_get_bind(hwc->config);
11711240
escr_idx = p4_get_escr_idx(bind->escr_msr[thread]);
11721241
if (unlikely(escr_idx == -1))
@@ -1180,8 +1249,17 @@ static int p4_pmu_schedule_events(struct cpu_hw_events *cpuc, int n, int *assign
11801249
}
11811250

11821251
cntr_idx = p4_next_cntr(thread, used_mask, bind);
1183-
if (cntr_idx == -1 || test_bit(escr_idx, escr_mask))
1184-
goto done;
1252+
if (cntr_idx == -1 || test_bit(escr_idx, escr_mask)) {
1253+
/*
1254+
* Probably an event alias is still available.
1255+
*/
1256+
config_alias = p4_get_alias_event(hwc->config);
1257+
if (!config_alias)
1258+
goto done;
1259+
hwc->config = config_alias;
1260+
pass++;
1261+
goto again;
1262+
}
11851263

11861264
p4_pmu_swap_config_ts(hwc, cpu);
11871265
if (assign)
@@ -1218,7 +1296,6 @@ static __initconst const struct x86_pmu p4_pmu = {
12181296
.cntval_bits = ARCH_P4_CNTRVAL_BITS,
12191297
.cntval_mask = ARCH_P4_CNTRVAL_MASK,
12201298
.max_period = (1ULL << (ARCH_P4_CNTRVAL_BITS - 1)) - 1,
1221-
.hw_watchdog_set_attr = p4_hw_watchdog_set_attr,
12221299
.hw_config = p4_hw_config,
12231300
.schedule_events = p4_pmu_schedule_events,
12241301
/*

‎include/linux/ftrace_event.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ struct trace_iterator {
7676
struct trace_entry *ent;
7777
unsigned long lost_events;
7878
int leftover;
79+
int ent_size;
7980
int cpu;
8081
u64 ts;
8182

‎kernel/kprobes.c‎

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,19 +1255,29 @@ static int __kprobes in_kprobes_functions(unsigned long addr)
12551255
/*
12561256
* If we have a symbol_name argument, look it up and add the offset field
12571257
* to it. This way, we can specify a relative address to a symbol.
1258+
* This returns encoded errors if it fails to look up symbol or invalid
1259+
* combination of parameters.
12581260
*/
12591261
static kprobe_opcode_t __kprobes *kprobe_addr(struct kprobe *p)
12601262
{
12611263
kprobe_opcode_t *addr = p->addr;
1264+
1265+
if ((p->symbol_name && p->addr) ||
1266+
(!p->symbol_name && !p->addr))
1267+
goto invalid;
1268+
12621269
if (p->symbol_name) {
1263-
if (addr)
1264-
return NULL;
12651270
kprobe_lookup_name(p->symbol_name, addr);
1271+
if (!addr)
1272+
return ERR_PTR(-ENOENT);
12661273
}
12671274

1268-
if (!addr)
1269-
return NULL;
1270-
return (kprobe_opcode_t *)(((char *)addr) + p->offset);
1275+
addr = (kprobe_opcode_t *)(((char *)addr) + p->offset);
1276+
if (addr)
1277+
return addr;
1278+
1279+
invalid:
1280+
return ERR_PTR(-EINVAL);
12711281
}
12721282

12731283
/* Check passed kprobe is valid and return kprobe in kprobe_table. */
@@ -1311,8 +1321,8 @@ int __kprobes register_kprobe(struct kprobe *p)
13111321
kprobe_opcode_t *addr;
13121322

13131323
addr = kprobe_addr(p);
1314-
if (!addr)
1315-
return -EINVAL;
1324+
if (IS_ERR(addr))
1325+
return PTR_ERR(addr);
13161326
p->addr = addr;
13171327

13181328
ret = check_kprobe_rereg(p);
@@ -1335,6 +1345,8 @@ int __kprobes register_kprobe(struct kprobe *p)
13351345
*/
13361346
probed_mod = __module_text_address((unsigned long) p->addr);
13371347
if (probed_mod) {
1348+
/* Return -ENOENT if fail. */
1349+
ret = -ENOENT;
13381350
/*
13391351
* We must hold a refcount of the probed module while updating
13401352
* its code to prohibit unexpected unloading.
@@ -1351,6 +1363,7 @@ int __kprobes register_kprobe(struct kprobe *p)
13511363
module_put(probed_mod);
13521364
goto fail_with_jump_label;
13531365
}
1366+
/* ret will be updated by following code */
13541367
}
13551368
preempt_enable();
13561369
jump_label_unlock();
@@ -1399,7 +1412,7 @@ int __kprobes register_kprobe(struct kprobe *p)
13991412
fail_with_jump_label:
14001413
preempt_enable();
14011414
jump_label_unlock();
1402-
return -EINVAL;
1415+
return ret;
14031416
}
14041417
EXPORT_SYMBOL_GPL(register_kprobe);
14051418

@@ -1686,8 +1699,8 @@ int __kprobes register_kretprobe(struct kretprobe *rp)
16861699

16871700
if (kretprobe_blacklist_size) {
16881701
addr = kprobe_addr(&rp->kp);
1689-
if (!addr)
1690-
return -EINVAL;
1702+
if (IS_ERR(addr))
1703+
return PTR_ERR(addr);
16911704

16921705
for (i = 0; kretprobe_blacklist[i].name != NULL; i++) {
16931706
if (kretprobe_blacklist[i].addr == addr)

0 commit comments

Comments
 (0)