diff options
| -rw-r--r-- | tools/perf/util/evlist.c | 25 | ||||
| -rw-r--r-- | tools/perf/util/evsel.c | 8 |
2 files changed, 20 insertions, 13 deletions
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index 08cedb643ea6..ed20f4379956 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c | |||
| @@ -230,18 +230,33 @@ void perf_evlist__set_leader(struct perf_evlist *evlist) | |||
| 230 | } | 230 | } |
| 231 | } | 231 | } |
| 232 | 232 | ||
| 233 | void perf_event_attr__set_max_precise_ip(struct perf_event_attr *attr) | 233 | void perf_event_attr__set_max_precise_ip(struct perf_event_attr *pattr) |
| 234 | { | 234 | { |
| 235 | attr->precise_ip = 3; | 235 | struct perf_event_attr attr = { |
| 236 | .type = PERF_TYPE_HARDWARE, | ||
| 237 | .config = PERF_COUNT_HW_CPU_CYCLES, | ||
| 238 | .exclude_kernel = 1, | ||
| 239 | .precise_ip = 3, | ||
| 240 | }; | ||
| 236 | 241 | ||
| 237 | while (attr->precise_ip != 0) { | 242 | event_attr_init(&attr); |
| 238 | int fd = sys_perf_event_open(attr, 0, -1, -1, 0); | 243 | |
| 244 | /* | ||
| 245 | * Unnamed union member, not supported as struct member named | ||
| 246 | * initializer in older compilers such as gcc 4.4.7 | ||
| 247 | */ | ||
| 248 | attr.sample_period = 1; | ||
| 249 | |||
| 250 | while (attr.precise_ip != 0) { | ||
| 251 | int fd = sys_perf_event_open(&attr, 0, -1, -1, 0); | ||
| 239 | if (fd != -1) { | 252 | if (fd != -1) { |
| 240 | close(fd); | 253 | close(fd); |
| 241 | break; | 254 | break; |
| 242 | } | 255 | } |
| 243 | --attr->precise_ip; | 256 | --attr.precise_ip; |
| 244 | } | 257 | } |
| 258 | |||
| 259 | pattr->precise_ip = attr.precise_ip; | ||
| 245 | } | 260 | } |
| 246 | 261 | ||
| 247 | int __perf_evlist__add_default(struct perf_evlist *evlist, bool precise) | 262 | int __perf_evlist__add_default(struct perf_evlist *evlist, bool precise) |
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index dfe2958e6287..3bbf73e979c0 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c | |||
| @@ -294,20 +294,12 @@ struct perf_evsel *perf_evsel__new_cycles(bool precise) | |||
| 294 | 294 | ||
| 295 | if (!precise) | 295 | if (!precise) |
| 296 | goto new_event; | 296 | goto new_event; |
| 297 | /* | ||
| 298 | * Unnamed union member, not supported as struct member named | ||
| 299 | * initializer in older compilers such as gcc 4.4.7 | ||
| 300 | * | ||
| 301 | * Just for probing the precise_ip: | ||
| 302 | */ | ||
| 303 | attr.sample_period = 1; | ||
| 304 | 297 | ||
| 305 | perf_event_attr__set_max_precise_ip(&attr); | 298 | perf_event_attr__set_max_precise_ip(&attr); |
| 306 | /* | 299 | /* |
| 307 | * Now let the usual logic to set up the perf_event_attr defaults | 300 | * Now let the usual logic to set up the perf_event_attr defaults |
| 308 | * to kick in when we return and before perf_evsel__open() is called. | 301 | * to kick in when we return and before perf_evsel__open() is called. |
| 309 | */ | 302 | */ |
| 310 | attr.sample_period = 0; | ||
| 311 | new_event: | 303 | new_event: |
| 312 | evsel = perf_evsel__new(&attr); | 304 | evsel = perf_evsel__new(&attr); |
| 313 | if (evsel == NULL) | 305 | if (evsel == NULL) |
