diff options
author | Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> | 2012-08-13 15:39:10 -0400 |
---|---|---|
committer | Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> | 2012-08-13 15:39:10 -0400 |
commit | 0980bd9cd32de2fef7eaa2858345c49d14498625 (patch) | |
tree | 41f5f823d0569a81b22037e79c22d823933a63f1 /tools | |
parent | 78821b2c0299ab807d483802f09897728b93bce0 (diff) | |
parent | 0d7614f09c1ebdbaa1599a5aba7593f147bf96ee (diff) |
Merge commit 'v3.6-rc1' into linux-next
* commit 'v3.6-rc1': (9532 commits)
Linux 3.6-rc1
mm: remove node_start_pfn checking in new WARN_ON for now
ARM: mmp: add missing irqs.h
arm: mvebu: fix typo in .dtsi comment for Armada XP SoCs
ARM: PRIMA2: delete redundant codes to restore LATCHED when timer resumes
libceph: fix crypto key null deref, memory leak
ceph: simplify+fix atomic_open
sh: explicitly include sh_dma.h in setup-sh7722.c
um: Add arch/x86/um to MAINTAINERS
um: pass siginfo to guest process
um: fix ubd_file_size for read-only files
md/dm-raid: DM_RAID should select MD_RAID10
md/raid1: submit IO from originating thread instead of md thread.
raid5: raid5d handle stripe in batch way
raid5: make_request use batch stripe release
um: pull interrupt_end() into userspace()
um: split syscall_trace(), pass pt_regs to it
um: switch UPT_SET_RETURN_VALUE and regs_return_value to pt_regs
MIPS: Loongson 2: Sort out clock managment.
locks: remove unused lm_release_private
...
Diffstat (limited to 'tools')
85 files changed, 5305 insertions, 1775 deletions
diff --git a/tools/hv/hv_kvp_daemon.c b/tools/hv/hv_kvp_daemon.c index 146fd6147e84..d9834b362943 100644 --- a/tools/hv/hv_kvp_daemon.c +++ b/tools/hv/hv_kvp_daemon.c | |||
@@ -701,14 +701,18 @@ int main(void) | |||
701 | pfd.fd = fd; | 701 | pfd.fd = fd; |
702 | 702 | ||
703 | while (1) { | 703 | while (1) { |
704 | struct sockaddr *addr_p = (struct sockaddr *) &addr; | ||
705 | socklen_t addr_l = sizeof(addr); | ||
704 | pfd.events = POLLIN; | 706 | pfd.events = POLLIN; |
705 | pfd.revents = 0; | 707 | pfd.revents = 0; |
706 | poll(&pfd, 1, -1); | 708 | poll(&pfd, 1, -1); |
707 | 709 | ||
708 | len = recv(fd, kvp_recv_buffer, sizeof(kvp_recv_buffer), 0); | 710 | len = recvfrom(fd, kvp_recv_buffer, sizeof(kvp_recv_buffer), 0, |
711 | addr_p, &addr_l); | ||
709 | 712 | ||
710 | if (len < 0) { | 713 | if (len < 0 || addr.nl_pid) { |
711 | syslog(LOG_ERR, "recv failed; error:%d", len); | 714 | syslog(LOG_ERR, "recvfrom failed; pid:%u error:%d %s", |
715 | addr.nl_pid, errno, strerror(errno)); | ||
712 | close(fd); | 716 | close(fd); |
713 | return -1; | 717 | return -1; |
714 | } | 718 | } |
diff --git a/tools/lib/traceevent/.gitignore b/tools/lib/traceevent/.gitignore new file mode 100644 index 000000000000..35f56be5a4cd --- /dev/null +++ b/tools/lib/traceevent/.gitignore | |||
@@ -0,0 +1 @@ | |||
TRACEEVENT-CFLAGS | |||
diff --git a/tools/lib/traceevent/Makefile b/tools/lib/traceevent/Makefile index 3d69aa9ff51e..14131cb0522d 100644 --- a/tools/lib/traceevent/Makefile +++ b/tools/lib/traceevent/Makefile | |||
@@ -207,7 +207,7 @@ libtraceevent.so: $(PEVENT_LIB_OBJS) | |||
207 | libtraceevent.a: $(PEVENT_LIB_OBJS) | 207 | libtraceevent.a: $(PEVENT_LIB_OBJS) |
208 | $(Q)$(do_build_static_lib) | 208 | $(Q)$(do_build_static_lib) |
209 | 209 | ||
210 | $(PEVENT_LIB_OBJS): %.o: $(src)/%.c | 210 | $(PEVENT_LIB_OBJS): %.o: $(src)/%.c TRACEEVENT-CFLAGS |
211 | $(Q)$(do_fpic_compile) | 211 | $(Q)$(do_fpic_compile) |
212 | 212 | ||
213 | define make_version.h | 213 | define make_version.h |
@@ -250,8 +250,12 @@ endef | |||
250 | all_objs := $(sort $(ALL_OBJS)) | 250 | all_objs := $(sort $(ALL_OBJS)) |
251 | all_deps := $(all_objs:%.o=.%.d) | 251 | all_deps := $(all_objs:%.o=.%.d) |
252 | 252 | ||
253 | # let .d file also depends on the source and header files | ||
253 | define check_deps | 254 | define check_deps |
254 | $(CC) -M $(CFLAGS) $< > $@; | 255 | @set -e; $(RM) $@; \ |
256 | $(CC) -M $(CFLAGS) $< > $@.$$$$; \ | ||
257 | sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \ | ||
258 | $(RM) $@.$$$$ | ||
255 | endef | 259 | endef |
256 | 260 | ||
257 | $(gui_deps): ks_version.h | 261 | $(gui_deps): ks_version.h |
@@ -268,13 +272,25 @@ ifneq ($(dep_includes),) | |||
268 | include $(dep_includes) | 272 | include $(dep_includes) |
269 | endif | 273 | endif |
270 | 274 | ||
275 | ### Detect environment changes | ||
276 | TRACK_CFLAGS = $(subst ','\'',$(CFLAGS)):$(ARCH):$(CROSS_COMPILE) | ||
277 | |||
278 | TRACEEVENT-CFLAGS: force | ||
279 | @FLAGS='$(TRACK_CFLAGS)'; \ | ||
280 | if test x"$$FLAGS" != x"`cat TRACEEVENT-CFLAGS 2>/dev/null`" ; then \ | ||
281 | echo 1>&2 " * new build flags or cross compiler"; \ | ||
282 | echo "$$FLAGS" >TRACEEVENT-CFLAGS; \ | ||
283 | fi | ||
284 | |||
271 | tags: force | 285 | tags: force |
272 | $(RM) tags | 286 | $(RM) tags |
273 | find . -name '*.[ch]' | xargs ctags --extra=+f --c-kinds=+px | 287 | find . -name '*.[ch]' | xargs ctags --extra=+f --c-kinds=+px \ |
288 | --regex-c++='/_PE\(([^,)]*).*/PEVENT_ERRNO__\1/' | ||
274 | 289 | ||
275 | TAGS: force | 290 | TAGS: force |
276 | $(RM) TAGS | 291 | $(RM) TAGS |
277 | find . -name '*.[ch]' | xargs etags | 292 | find . -name '*.[ch]' | xargs etags \ |
293 | --regex='/_PE(\([^,)]*\).*/PEVENT_ERRNO__\1/' | ||
278 | 294 | ||
279 | define do_install | 295 | define do_install |
280 | $(print_install) \ | 296 | $(print_install) \ |
@@ -290,8 +306,8 @@ install_lib: all_cmd install_plugins install_python | |||
290 | install: install_lib | 306 | install: install_lib |
291 | 307 | ||
292 | clean: | 308 | clean: |
293 | $(RM) *.o *~ $(TARGETS) *.a *.so $(VERSION_FILES).*.d | 309 | $(RM) *.o *~ $(TARGETS) *.a *.so $(VERSION_FILES) .*.d |
294 | $(RM) tags TAGS | 310 | $(RM) TRACEEVENT-CFLAGS tags TAGS |
295 | 311 | ||
296 | endif # skip-makefile | 312 | endif # skip-makefile |
297 | 313 | ||
diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c index 554828219c33..5f34aa371b56 100644 --- a/tools/lib/traceevent/event-parse.c +++ b/tools/lib/traceevent/event-parse.c | |||
@@ -467,8 +467,10 @@ int pevent_register_function(struct pevent *pevent, char *func, | |||
467 | item->mod = NULL; | 467 | item->mod = NULL; |
468 | item->addr = addr; | 468 | item->addr = addr; |
469 | 469 | ||
470 | pevent->funclist = item; | 470 | if (!item->func || (mod && !item->mod)) |
471 | die("malloc func"); | ||
471 | 472 | ||
473 | pevent->funclist = item; | ||
472 | pevent->func_count++; | 474 | pevent->func_count++; |
473 | 475 | ||
474 | return 0; | 476 | return 0; |
@@ -511,12 +513,12 @@ struct printk_list { | |||
511 | 513 | ||
512 | static int printk_cmp(const void *a, const void *b) | 514 | static int printk_cmp(const void *a, const void *b) |
513 | { | 515 | { |
514 | const struct func_map *fa = a; | 516 | const struct printk_map *pa = a; |
515 | const struct func_map *fb = b; | 517 | const struct printk_map *pb = b; |
516 | 518 | ||
517 | if (fa->addr < fb->addr) | 519 | if (pa->addr < pb->addr) |
518 | return -1; | 520 | return -1; |
519 | if (fa->addr > fb->addr) | 521 | if (pa->addr > pb->addr) |
520 | return 1; | 522 | return 1; |
521 | 523 | ||
522 | return 0; | 524 | return 0; |
@@ -583,10 +585,13 @@ int pevent_register_print_string(struct pevent *pevent, char *fmt, | |||
583 | item = malloc_or_die(sizeof(*item)); | 585 | item = malloc_or_die(sizeof(*item)); |
584 | 586 | ||
585 | item->next = pevent->printklist; | 587 | item->next = pevent->printklist; |
586 | pevent->printklist = item; | ||
587 | item->printk = strdup(fmt); | 588 | item->printk = strdup(fmt); |
588 | item->addr = addr; | 589 | item->addr = addr; |
589 | 590 | ||
591 | if (!item->printk) | ||
592 | die("malloc fmt"); | ||
593 | |||
594 | pevent->printklist = item; | ||
590 | pevent->printk_count++; | 595 | pevent->printk_count++; |
591 | 596 | ||
592 | return 0; | 597 | return 0; |
@@ -616,7 +621,9 @@ static struct event_format *alloc_event(void) | |||
616 | { | 621 | { |
617 | struct event_format *event; | 622 | struct event_format *event; |
618 | 623 | ||
619 | event = malloc_or_die(sizeof(*event)); | 624 | event = malloc(sizeof(*event)); |
625 | if (!event) | ||
626 | return NULL; | ||
620 | memset(event, 0, sizeof(*event)); | 627 | memset(event, 0, sizeof(*event)); |
621 | 628 | ||
622 | return event; | 629 | return event; |
@@ -626,12 +633,8 @@ static void add_event(struct pevent *pevent, struct event_format *event) | |||
626 | { | 633 | { |
627 | int i; | 634 | int i; |
628 | 635 | ||
629 | if (!pevent->events) | 636 | pevent->events = realloc(pevent->events, sizeof(event) * |
630 | pevent->events = malloc_or_die(sizeof(event)); | 637 | (pevent->nr_events + 1)); |
631 | else | ||
632 | pevent->events = | ||
633 | realloc(pevent->events, sizeof(event) * | ||
634 | (pevent->nr_events + 1)); | ||
635 | if (!pevent->events) | 638 | if (!pevent->events) |
636 | die("Can not allocate events"); | 639 | die("Can not allocate events"); |
637 | 640 | ||
@@ -697,6 +700,10 @@ static void free_arg(struct print_arg *arg) | |||
697 | free_arg(arg->symbol.field); | 700 | free_arg(arg->symbol.field); |
698 | free_flag_sym(arg->symbol.symbols); | 701 | free_flag_sym(arg->symbol.symbols); |
699 | break; | 702 | break; |
703 | case PRINT_HEX: | ||
704 | free_arg(arg->hex.field); | ||
705 | free_arg(arg->hex.size); | ||
706 | break; | ||
700 | case PRINT_TYPE: | 707 | case PRINT_TYPE: |
701 | free(arg->typecast.type); | 708 | free(arg->typecast.type); |
702 | free_arg(arg->typecast.item); | 709 | free_arg(arg->typecast.item); |
@@ -775,6 +782,25 @@ int pevent_peek_char(void) | |||
775 | return __peek_char(); | 782 | return __peek_char(); |
776 | } | 783 | } |
777 | 784 | ||
785 | static int extend_token(char **tok, char *buf, int size) | ||
786 | { | ||
787 | char *newtok = realloc(*tok, size); | ||
788 | |||
789 | if (!newtok) { | ||
790 | free(*tok); | ||
791 | *tok = NULL; | ||
792 | return -1; | ||
793 | } | ||
794 | |||
795 | if (!*tok) | ||
796 | strcpy(newtok, buf); | ||
797 | else | ||
798 | strcat(newtok, buf); | ||
799 | *tok = newtok; | ||
800 | |||
801 | return 0; | ||
802 | } | ||
803 | |||
778 | static enum event_type force_token(const char *str, char **tok); | 804 | static enum event_type force_token(const char *str, char **tok); |
779 | 805 | ||
780 | static enum event_type __read_token(char **tok) | 806 | static enum event_type __read_token(char **tok) |
@@ -859,17 +885,10 @@ static enum event_type __read_token(char **tok) | |||
859 | do { | 885 | do { |
860 | if (i == (BUFSIZ - 1)) { | 886 | if (i == (BUFSIZ - 1)) { |
861 | buf[i] = 0; | 887 | buf[i] = 0; |
862 | if (*tok) { | 888 | tok_size += BUFSIZ; |
863 | *tok = realloc(*tok, tok_size + BUFSIZ); | ||
864 | if (!*tok) | ||
865 | return EVENT_NONE; | ||
866 | strcat(*tok, buf); | ||
867 | } else | ||
868 | *tok = strdup(buf); | ||
869 | 889 | ||
870 | if (!*tok) | 890 | if (extend_token(tok, buf, tok_size) < 0) |
871 | return EVENT_NONE; | 891 | return EVENT_NONE; |
872 | tok_size += BUFSIZ; | ||
873 | i = 0; | 892 | i = 0; |
874 | } | 893 | } |
875 | last_ch = ch; | 894 | last_ch = ch; |
@@ -908,17 +927,10 @@ static enum event_type __read_token(char **tok) | |||
908 | while (get_type(__peek_char()) == type) { | 927 | while (get_type(__peek_char()) == type) { |
909 | if (i == (BUFSIZ - 1)) { | 928 | if (i == (BUFSIZ - 1)) { |
910 | buf[i] = 0; | 929 | buf[i] = 0; |
911 | if (*tok) { | 930 | tok_size += BUFSIZ; |
912 | *tok = realloc(*tok, tok_size + BUFSIZ); | ||
913 | if (!*tok) | ||
914 | return EVENT_NONE; | ||
915 | strcat(*tok, buf); | ||
916 | } else | ||
917 | *tok = strdup(buf); | ||
918 | 931 | ||
919 | if (!*tok) | 932 | if (extend_token(tok, buf, tok_size) < 0) |
920 | return EVENT_NONE; | 933 | return EVENT_NONE; |
921 | tok_size += BUFSIZ; | ||
922 | i = 0; | 934 | i = 0; |
923 | } | 935 | } |
924 | ch = __read_char(); | 936 | ch = __read_char(); |
@@ -927,14 +939,7 @@ static enum event_type __read_token(char **tok) | |||
927 | 939 | ||
928 | out: | 940 | out: |
929 | buf[i] = 0; | 941 | buf[i] = 0; |
930 | if (*tok) { | 942 | if (extend_token(tok, buf, tok_size + i + 1) < 0) |
931 | *tok = realloc(*tok, tok_size + i); | ||
932 | if (!*tok) | ||
933 | return EVENT_NONE; | ||
934 | strcat(*tok, buf); | ||
935 | } else | ||
936 | *tok = strdup(buf); | ||
937 | if (!*tok) | ||
938 | return EVENT_NONE; | 943 | return EVENT_NONE; |
939 | 944 | ||
940 | if (type == EVENT_ITEM) { | 945 | if (type == EVENT_ITEM) { |
@@ -1255,9 +1260,15 @@ static int event_read_fields(struct event_format *event, struct format_field **f | |||
1255 | field->flags |= FIELD_IS_POINTER; | 1260 | field->flags |= FIELD_IS_POINTER; |
1256 | 1261 | ||
1257 | if (field->type) { | 1262 | if (field->type) { |
1258 | field->type = realloc(field->type, | 1263 | char *new_type; |
1259 | strlen(field->type) + | 1264 | new_type = realloc(field->type, |
1260 | strlen(last_token) + 2); | 1265 | strlen(field->type) + |
1266 | strlen(last_token) + 2); | ||
1267 | if (!new_type) { | ||
1268 | free(last_token); | ||
1269 | goto fail; | ||
1270 | } | ||
1271 | field->type = new_type; | ||
1261 | strcat(field->type, " "); | 1272 | strcat(field->type, " "); |
1262 | strcat(field->type, last_token); | 1273 | strcat(field->type, last_token); |
1263 | free(last_token); | 1274 | free(last_token); |
@@ -1282,6 +1293,7 @@ static int event_read_fields(struct event_format *event, struct format_field **f | |||
1282 | if (strcmp(token, "[") == 0) { | 1293 | if (strcmp(token, "[") == 0) { |
1283 | enum event_type last_type = type; | 1294 | enum event_type last_type = type; |
1284 | char *brackets = token; | 1295 | char *brackets = token; |
1296 | char *new_brackets; | ||
1285 | int len; | 1297 | int len; |
1286 | 1298 | ||
1287 | field->flags |= FIELD_IS_ARRAY; | 1299 | field->flags |= FIELD_IS_ARRAY; |
@@ -1301,9 +1313,14 @@ static int event_read_fields(struct event_format *event, struct format_field **f | |||
1301 | len = 1; | 1313 | len = 1; |
1302 | last_type = type; | 1314 | last_type = type; |
1303 | 1315 | ||
1304 | brackets = realloc(brackets, | 1316 | new_brackets = realloc(brackets, |
1305 | strlen(brackets) + | 1317 | strlen(brackets) + |
1306 | strlen(token) + len); | 1318 | strlen(token) + len); |
1319 | if (!new_brackets) { | ||
1320 | free(brackets); | ||
1321 | goto fail; | ||
1322 | } | ||
1323 | brackets = new_brackets; | ||
1307 | if (len == 2) | 1324 | if (len == 2) |
1308 | strcat(brackets, " "); | 1325 | strcat(brackets, " "); |
1309 | strcat(brackets, token); | 1326 | strcat(brackets, token); |
@@ -1319,7 +1336,12 @@ static int event_read_fields(struct event_format *event, struct format_field **f | |||
1319 | 1336 | ||
1320 | free_token(token); | 1337 | free_token(token); |
1321 | 1338 | ||
1322 | brackets = realloc(brackets, strlen(brackets) + 2); | 1339 | new_brackets = realloc(brackets, strlen(brackets) + 2); |
1340 | if (!new_brackets) { | ||
1341 | free(brackets); | ||
1342 | goto fail; | ||
1343 | } | ||
1344 | brackets = new_brackets; | ||
1323 | strcat(brackets, "]"); | 1345 | strcat(brackets, "]"); |
1324 | 1346 | ||
1325 | /* add brackets to type */ | 1347 | /* add brackets to type */ |
@@ -1330,10 +1352,16 @@ static int event_read_fields(struct event_format *event, struct format_field **f | |||
1330 | * the format: type [] item; | 1352 | * the format: type [] item; |
1331 | */ | 1353 | */ |
1332 | if (type == EVENT_ITEM) { | 1354 | if (type == EVENT_ITEM) { |
1333 | field->type = realloc(field->type, | 1355 | char *new_type; |
1334 | strlen(field->type) + | 1356 | new_type = realloc(field->type, |
1335 | strlen(field->name) + | 1357 | strlen(field->type) + |
1336 | strlen(brackets) + 2); | 1358 | strlen(field->name) + |
1359 | strlen(brackets) + 2); | ||
1360 | if (!new_type) { | ||
1361 | free(brackets); | ||
1362 | goto fail; | ||
1363 | } | ||
1364 | field->type = new_type; | ||
1337 | strcat(field->type, " "); | 1365 | strcat(field->type, " "); |
1338 | strcat(field->type, field->name); | 1366 | strcat(field->type, field->name); |
1339 | free_token(field->name); | 1367 | free_token(field->name); |
@@ -1341,9 +1369,15 @@ static int event_read_fields(struct event_format *event, struct format_field **f | |||
1341 | field->name = token; | 1369 | field->name = token; |
1342 | type = read_token(&token); | 1370 | type = read_token(&token); |
1343 | } else { | 1371 | } else { |
1344 | field->type = realloc(field->type, | 1372 | char *new_type; |
1345 | strlen(field->type) + | 1373 | new_type = realloc(field->type, |
1346 | strlen(brackets) + 1); | 1374 | strlen(field->type) + |
1375 | strlen(brackets) + 1); | ||
1376 | if (!new_type) { | ||
1377 | free(brackets); | ||
1378 | goto fail; | ||
1379 | } | ||
1380 | field->type = new_type; | ||
1347 | strcat(field->type, brackets); | 1381 | strcat(field->type, brackets); |
1348 | } | 1382 | } |
1349 | free(brackets); | 1383 | free(brackets); |
@@ -1726,10 +1760,16 @@ process_op(struct event_format *event, struct print_arg *arg, char **tok) | |||
1726 | /* could just be a type pointer */ | 1760 | /* could just be a type pointer */ |
1727 | if ((strcmp(arg->op.op, "*") == 0) && | 1761 | if ((strcmp(arg->op.op, "*") == 0) && |
1728 | type == EVENT_DELIM && (strcmp(token, ")") == 0)) { | 1762 | type == EVENT_DELIM && (strcmp(token, ")") == 0)) { |
1763 | char *new_atom; | ||
1764 | |||
1729 | if (left->type != PRINT_ATOM) | 1765 | if (left->type != PRINT_ATOM) |
1730 | die("bad pointer type"); | 1766 | die("bad pointer type"); |
1731 | left->atom.atom = realloc(left->atom.atom, | 1767 | new_atom = realloc(left->atom.atom, |
1732 | strlen(left->atom.atom) + 3); | 1768 | strlen(left->atom.atom) + 3); |
1769 | if (!new_atom) | ||
1770 | goto out_free; | ||
1771 | |||
1772 | left->atom.atom = new_atom; | ||
1733 | strcat(left->atom.atom, " *"); | 1773 | strcat(left->atom.atom, " *"); |
1734 | free(arg->op.op); | 1774 | free(arg->op.op); |
1735 | *arg = *left; | 1775 | *arg = *left; |
@@ -2146,6 +2186,8 @@ process_fields(struct event_format *event, struct print_flag_sym **list, char ** | |||
2146 | if (value == NULL) | 2186 | if (value == NULL) |
2147 | goto out_free; | 2187 | goto out_free; |
2148 | field->value = strdup(value); | 2188 | field->value = strdup(value); |
2189 | if (field->value == NULL) | ||
2190 | goto out_free; | ||
2149 | 2191 | ||
2150 | free_arg(arg); | 2192 | free_arg(arg); |
2151 | arg = alloc_arg(); | 2193 | arg = alloc_arg(); |
@@ -2159,6 +2201,8 @@ process_fields(struct event_format *event, struct print_flag_sym **list, char ** | |||
2159 | if (value == NULL) | 2201 | if (value == NULL) |
2160 | goto out_free; | 2202 | goto out_free; |
2161 | field->str = strdup(value); | 2203 | field->str = strdup(value); |
2204 | if (field->str == NULL) | ||
2205 | goto out_free; | ||
2162 | free_arg(arg); | 2206 | free_arg(arg); |
2163 | arg = NULL; | 2207 | arg = NULL; |
2164 | 2208 | ||
@@ -2260,6 +2304,45 @@ process_symbols(struct event_format *event, struct print_arg *arg, char **tok) | |||
2260 | } | 2304 | } |
2261 | 2305 | ||
2262 | static enum event_type | 2306 | static enum event_type |
2307 | process_hex(struct event_format *event, struct print_arg *arg, char **tok) | ||
2308 | { | ||
2309 | struct print_arg *field; | ||
2310 | enum event_type type; | ||
2311 | char *token; | ||
2312 | |||
2313 | memset(arg, 0, sizeof(*arg)); | ||
2314 | arg->type = PRINT_HEX; | ||
2315 | |||
2316 | field = alloc_arg(); | ||
2317 | type = process_arg(event, field, &token); | ||
2318 | |||
2319 | if (test_type_token(type, token, EVENT_DELIM, ",")) | ||
2320 | goto out_free; | ||
2321 | |||
2322 | arg->hex.field = field; | ||
2323 | |||
2324 | free_token(token); | ||
2325 | |||
2326 | field = alloc_arg(); | ||
2327 | type = process_arg(event, field, &token); | ||
2328 | |||
2329 | if (test_type_token(type, token, EVENT_DELIM, ")")) | ||
2330 | goto out_free; | ||
2331 | |||
2332 | arg->hex.size = field; | ||
2333 | |||
2334 | free_token(token); | ||
2335 | type = read_token_item(tok); | ||
2336 | return type; | ||
2337 | |||
2338 | out_free: | ||
2339 | free_arg(field); | ||
2340 | free_token(token); | ||
2341 | *tok = NULL; | ||
2342 | return EVENT_ERROR; | ||
2343 | } | ||
2344 | |||
2345 | static enum event_type | ||
2263 | process_dynamic_array(struct event_format *event, struct print_arg *arg, char **tok) | 2346 | process_dynamic_array(struct event_format *event, struct print_arg *arg, char **tok) |
2264 | { | 2347 | { |
2265 | struct format_field *field; | 2348 | struct format_field *field; |
@@ -2488,6 +2571,10 @@ process_function(struct event_format *event, struct print_arg *arg, | |||
2488 | is_symbolic_field = 1; | 2571 | is_symbolic_field = 1; |
2489 | return process_symbols(event, arg, tok); | 2572 | return process_symbols(event, arg, tok); |
2490 | } | 2573 | } |
2574 | if (strcmp(token, "__print_hex") == 0) { | ||
2575 | free_token(token); | ||
2576 | return process_hex(event, arg, tok); | ||
2577 | } | ||
2491 | if (strcmp(token, "__get_str") == 0) { | 2578 | if (strcmp(token, "__get_str") == 0) { |
2492 | free_token(token); | 2579 | free_token(token); |
2493 | return process_str(event, arg, tok); | 2580 | return process_str(event, arg, tok); |
@@ -2541,7 +2628,16 @@ process_arg_token(struct event_format *event, struct print_arg *arg, | |||
2541 | } | 2628 | } |
2542 | /* atoms can be more than one token long */ | 2629 | /* atoms can be more than one token long */ |
2543 | while (type == EVENT_ITEM) { | 2630 | while (type == EVENT_ITEM) { |
2544 | atom = realloc(atom, strlen(atom) + strlen(token) + 2); | 2631 | char *new_atom; |
2632 | new_atom = realloc(atom, | ||
2633 | strlen(atom) + strlen(token) + 2); | ||
2634 | if (!new_atom) { | ||
2635 | free(atom); | ||
2636 | *tok = NULL; | ||
2637 | free_token(token); | ||
2638 | return EVENT_ERROR; | ||
2639 | } | ||
2640 | atom = new_atom; | ||
2545 | strcat(atom, " "); | 2641 | strcat(atom, " "); |
2546 | strcat(atom, token); | 2642 | strcat(atom, token); |
2547 | free_token(token); | 2643 | free_token(token); |
@@ -2835,7 +2931,7 @@ static int get_common_info(struct pevent *pevent, | |||
2835 | event = pevent->events[0]; | 2931 | event = pevent->events[0]; |
2836 | field = pevent_find_common_field(event, type); | 2932 | field = pevent_find_common_field(event, type); |
2837 | if (!field) | 2933 | if (!field) |
2838 | die("field '%s' not found", type); | 2934 | return -1; |
2839 | 2935 | ||
2840 | *offset = field->offset; | 2936 | *offset = field->offset; |
2841 | *size = field->size; | 2937 | *size = field->size; |
@@ -2886,15 +2982,16 @@ static int parse_common_flags(struct pevent *pevent, void *data) | |||
2886 | 2982 | ||
2887 | static int parse_common_lock_depth(struct pevent *pevent, void *data) | 2983 | static int parse_common_lock_depth(struct pevent *pevent, void *data) |
2888 | { | 2984 | { |
2889 | int ret; | 2985 | return __parse_common(pevent, data, |
2890 | 2986 | &pevent->ld_size, &pevent->ld_offset, | |
2891 | ret = __parse_common(pevent, data, | 2987 | "common_lock_depth"); |
2892 | &pevent->ld_size, &pevent->ld_offset, | 2988 | } |
2893 | "common_lock_depth"); | ||
2894 | if (ret < 0) | ||
2895 | return -1; | ||
2896 | 2989 | ||
2897 | return ret; | 2990 | static int parse_common_migrate_disable(struct pevent *pevent, void *data) |
2991 | { | ||
2992 | return __parse_common(pevent, data, | ||
2993 | &pevent->ld_size, &pevent->ld_offset, | ||
2994 | "common_migrate_disable"); | ||
2898 | } | 2995 | } |
2899 | 2996 | ||
2900 | static int events_id_cmp(const void *a, const void *b); | 2997 | static int events_id_cmp(const void *a, const void *b); |
@@ -2995,6 +3092,7 @@ eval_num_arg(void *data, int size, struct event_format *event, struct print_arg | |||
2995 | break; | 3092 | break; |
2996 | case PRINT_FLAGS: | 3093 | case PRINT_FLAGS: |
2997 | case PRINT_SYMBOL: | 3094 | case PRINT_SYMBOL: |
3095 | case PRINT_HEX: | ||
2998 | break; | 3096 | break; |
2999 | case PRINT_TYPE: | 3097 | case PRINT_TYPE: |
3000 | val = eval_num_arg(data, size, event, arg->typecast.item); | 3098 | val = eval_num_arg(data, size, event, arg->typecast.item); |
@@ -3214,11 +3312,13 @@ static void print_str_arg(struct trace_seq *s, void *data, int size, | |||
3214 | { | 3312 | { |
3215 | struct pevent *pevent = event->pevent; | 3313 | struct pevent *pevent = event->pevent; |
3216 | struct print_flag_sym *flag; | 3314 | struct print_flag_sym *flag; |
3315 | struct format_field *field; | ||
3217 | unsigned long long val, fval; | 3316 | unsigned long long val, fval; |
3218 | unsigned long addr; | 3317 | unsigned long addr; |
3219 | char *str; | 3318 | char *str; |
3319 | unsigned char *hex; | ||
3220 | int print; | 3320 | int print; |
3221 | int len; | 3321 | int i, len; |
3222 | 3322 | ||
3223 | switch (arg->type) { | 3323 | switch (arg->type) { |
3224 | case PRINT_NULL: | 3324 | case PRINT_NULL: |
@@ -3228,27 +3328,29 @@ static void print_str_arg(struct trace_seq *s, void *data, int size, | |||
3228 | print_str_to_seq(s, format, len_arg, arg->atom.atom); | 3328 | print_str_to_seq(s, format, len_arg, arg->atom.atom); |
3229 | return; | 3329 | return; |
3230 | case PRINT_FIELD: | 3330 | case PRINT_FIELD: |
3231 | if (!arg->field.field) { | 3331 | field = arg->field.field; |
3232 | arg->field.field = pevent_find_any_field(event, arg->field.name); | 3332 | if (!field) { |
3233 | if (!arg->field.field) | 3333 | field = pevent_find_any_field(event, arg->field.name); |
3334 | if (!field) | ||
3234 | die("field %s not found", arg->field.name); | 3335 | die("field %s not found", arg->field.name); |
3336 | arg->field.field = field; | ||
3235 | } | 3337 | } |
3236 | /* Zero sized fields, mean the rest of the data */ | 3338 | /* Zero sized fields, mean the rest of the data */ |
3237 | len = arg->field.field->size ? : size - arg->field.field->offset; | 3339 | len = field->size ? : size - field->offset; |
3238 | 3340 | ||
3239 | /* | 3341 | /* |
3240 | * Some events pass in pointers. If this is not an array | 3342 | * Some events pass in pointers. If this is not an array |
3241 | * and the size is the same as long_size, assume that it | 3343 | * and the size is the same as long_size, assume that it |
3242 | * is a pointer. | 3344 | * is a pointer. |
3243 | */ | 3345 | */ |
3244 | if (!(arg->field.field->flags & FIELD_IS_ARRAY) && | 3346 | if (!(field->flags & FIELD_IS_ARRAY) && |
3245 | arg->field.field->size == pevent->long_size) { | 3347 | field->size == pevent->long_size) { |
3246 | addr = *(unsigned long *)(data + arg->field.field->offset); | 3348 | addr = *(unsigned long *)(data + field->offset); |
3247 | trace_seq_printf(s, "%lx", addr); | 3349 | trace_seq_printf(s, "%lx", addr); |
3248 | break; | 3350 | break; |
3249 | } | 3351 | } |
3250 | str = malloc_or_die(len + 1); | 3352 | str = malloc_or_die(len + 1); |
3251 | memcpy(str, data + arg->field.field->offset, len); | 3353 | memcpy(str, data + field->offset, len); |
3252 | str[len] = 0; | 3354 | str[len] = 0; |
3253 | print_str_to_seq(s, format, len_arg, str); | 3355 | print_str_to_seq(s, format, len_arg, str); |
3254 | free(str); | 3356 | free(str); |
@@ -3281,6 +3383,23 @@ static void print_str_arg(struct trace_seq *s, void *data, int size, | |||
3281 | } | 3383 | } |
3282 | } | 3384 | } |
3283 | break; | 3385 | break; |
3386 | case PRINT_HEX: | ||
3387 | field = arg->hex.field->field.field; | ||
3388 | if (!field) { | ||
3389 | str = arg->hex.field->field.name; | ||
3390 | field = pevent_find_any_field(event, str); | ||
3391 | if (!field) | ||
3392 | die("field %s not found", str); | ||
3393 | arg->hex.field->field.field = field; | ||
3394 | } | ||
3395 | hex = data + field->offset; | ||
3396 | len = eval_num_arg(data, size, event, arg->hex.size); | ||
3397 | for (i = 0; i < len; i++) { | ||
3398 | if (i) | ||
3399 | trace_seq_putc(s, ' '); | ||
3400 | trace_seq_printf(s, "%02x", hex[i]); | ||
3401 | } | ||
3402 | break; | ||
3284 | 3403 | ||
3285 | case PRINT_TYPE: | 3404 | case PRINT_TYPE: |
3286 | break; | 3405 | break; |
@@ -3299,7 +3418,7 @@ static void print_str_arg(struct trace_seq *s, void *data, int size, | |||
3299 | break; | 3418 | break; |
3300 | } | 3419 | } |
3301 | case PRINT_BSTRING: | 3420 | case PRINT_BSTRING: |
3302 | trace_seq_printf(s, format, arg->string.string); | 3421 | print_str_to_seq(s, format, len_arg, arg->string.string); |
3303 | break; | 3422 | break; |
3304 | case PRINT_OP: | 3423 | case PRINT_OP: |
3305 | /* | 3424 | /* |
@@ -3363,6 +3482,10 @@ process_defined_func(struct trace_seq *s, void *data, int size, | |||
3363 | string = malloc_or_die(sizeof(*string)); | 3482 | string = malloc_or_die(sizeof(*string)); |
3364 | string->next = strings; | 3483 | string->next = strings; |
3365 | string->str = strdup(str.buffer); | 3484 | string->str = strdup(str.buffer); |
3485 | if (!string->str) | ||
3486 | die("malloc str"); | ||
3487 | |||
3488 | args[i] = (unsigned long long)string->str; | ||
3366 | strings = string; | 3489 | strings = string; |
3367 | trace_seq_destroy(&str); | 3490 | trace_seq_destroy(&str); |
3368 | break; | 3491 | break; |
@@ -3400,6 +3523,7 @@ static struct print_arg *make_bprint_args(char *fmt, void *data, int size, struc | |||
3400 | unsigned long long ip, val; | 3523 | unsigned long long ip, val; |
3401 | char *ptr; | 3524 | char *ptr; |
3402 | void *bptr; | 3525 | void *bptr; |
3526 | int vsize; | ||
3403 | 3527 | ||
3404 | field = pevent->bprint_buf_field; | 3528 | field = pevent->bprint_buf_field; |
3405 | ip_field = pevent->bprint_ip_field; | 3529 | ip_field = pevent->bprint_ip_field; |
@@ -3448,6 +3572,8 @@ static struct print_arg *make_bprint_args(char *fmt, void *data, int size, struc | |||
3448 | goto process_again; | 3572 | goto process_again; |
3449 | case '0' ... '9': | 3573 | case '0' ... '9': |
3450 | goto process_again; | 3574 | goto process_again; |
3575 | case '.': | ||
3576 | goto process_again; | ||
3451 | case 'p': | 3577 | case 'p': |
3452 | ls = 1; | 3578 | ls = 1; |
3453 | /* fall through */ | 3579 | /* fall through */ |
@@ -3455,23 +3581,30 @@ static struct print_arg *make_bprint_args(char *fmt, void *data, int size, struc | |||
3455 | case 'u': | 3581 | case 'u': |
3456 | case 'x': | 3582 | case 'x': |
3457 | case 'i': | 3583 | case 'i': |
3458 | /* the pointers are always 4 bytes aligned */ | ||
3459 | bptr = (void *)(((unsigned long)bptr + 3) & | ||
3460 | ~3); | ||
3461 | switch (ls) { | 3584 | switch (ls) { |
3462 | case 0: | 3585 | case 0: |
3463 | ls = 4; | 3586 | vsize = 4; |
3464 | break; | 3587 | break; |
3465 | case 1: | 3588 | case 1: |
3466 | ls = pevent->long_size; | 3589 | vsize = pevent->long_size; |
3467 | break; | 3590 | break; |
3468 | case 2: | 3591 | case 2: |
3469 | ls = 8; | 3592 | vsize = 8; |
3593 | break; | ||
3470 | default: | 3594 | default: |
3595 | vsize = ls; /* ? */ | ||
3471 | break; | 3596 | break; |
3472 | } | 3597 | } |
3473 | val = pevent_read_number(pevent, bptr, ls); | 3598 | /* fall through */ |
3474 | bptr += ls; | 3599 | case '*': |
3600 | if (*ptr == '*') | ||
3601 | vsize = 4; | ||
3602 | |||
3603 | /* the pointers are always 4 bytes aligned */ | ||
3604 | bptr = (void *)(((unsigned long)bptr + 3) & | ||
3605 | ~3); | ||
3606 | val = pevent_read_number(pevent, bptr, vsize); | ||
3607 | bptr += vsize; | ||
3475 | arg = alloc_arg(); | 3608 | arg = alloc_arg(); |
3476 | arg->next = NULL; | 3609 | arg->next = NULL; |
3477 | arg->type = PRINT_ATOM; | 3610 | arg->type = PRINT_ATOM; |
@@ -3479,12 +3612,21 @@ static struct print_arg *make_bprint_args(char *fmt, void *data, int size, struc | |||
3479 | sprintf(arg->atom.atom, "%lld", val); | 3612 | sprintf(arg->atom.atom, "%lld", val); |
3480 | *next = arg; | 3613 | *next = arg; |
3481 | next = &arg->next; | 3614 | next = &arg->next; |
3615 | /* | ||
3616 | * The '*' case means that an arg is used as the length. | ||
3617 | * We need to continue to figure out for what. | ||
3618 | */ | ||
3619 | if (*ptr == '*') | ||
3620 | goto process_again; | ||
3621 | |||
3482 | break; | 3622 | break; |
3483 | case 's': | 3623 | case 's': |
3484 | arg = alloc_arg(); | 3624 | arg = alloc_arg(); |
3485 | arg->next = NULL; | 3625 | arg->next = NULL; |
3486 | arg->type = PRINT_BSTRING; | 3626 | arg->type = PRINT_BSTRING; |
3487 | arg->string.string = strdup(bptr); | 3627 | arg->string.string = strdup(bptr); |
3628 | if (!arg->string.string) | ||
3629 | break; | ||
3488 | bptr += strlen(bptr) + 1; | 3630 | bptr += strlen(bptr) + 1; |
3489 | *next = arg; | 3631 | *next = arg; |
3490 | next = &arg->next; | 3632 | next = &arg->next; |
@@ -3589,6 +3731,16 @@ static void print_mac_arg(struct trace_seq *s, int mac, void *data, int size, | |||
3589 | trace_seq_printf(s, fmt, buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]); | 3731 | trace_seq_printf(s, fmt, buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]); |
3590 | } | 3732 | } |
3591 | 3733 | ||
3734 | static int is_printable_array(char *p, unsigned int len) | ||
3735 | { | ||
3736 | unsigned int i; | ||
3737 | |||
3738 | for (i = 0; i < len && p[i]; i++) | ||
3739 | if (!isprint(p[i])) | ||
3740 | return 0; | ||
3741 | return 1; | ||
3742 | } | ||
3743 | |||
3592 | static void print_event_fields(struct trace_seq *s, void *data, int size, | 3744 | static void print_event_fields(struct trace_seq *s, void *data, int size, |
3593 | struct event_format *event) | 3745 | struct event_format *event) |
3594 | { | 3746 | { |
@@ -3608,7 +3760,8 @@ static void print_event_fields(struct trace_seq *s, void *data, int size, | |||
3608 | len = offset >> 16; | 3760 | len = offset >> 16; |
3609 | offset &= 0xffff; | 3761 | offset &= 0xffff; |
3610 | } | 3762 | } |
3611 | if (field->flags & FIELD_IS_STRING) { | 3763 | if (field->flags & FIELD_IS_STRING && |
3764 | is_printable_array(data + offset, len)) { | ||
3612 | trace_seq_printf(s, "%s", (char *)data + offset); | 3765 | trace_seq_printf(s, "%s", (char *)data + offset); |
3613 | } else { | 3766 | } else { |
3614 | trace_seq_puts(s, "ARRAY["); | 3767 | trace_seq_puts(s, "ARRAY["); |
@@ -3619,6 +3772,7 @@ static void print_event_fields(struct trace_seq *s, void *data, int size, | |||
3619 | *((unsigned char *)data + offset + i)); | 3772 | *((unsigned char *)data + offset + i)); |
3620 | } | 3773 | } |
3621 | trace_seq_putc(s, ']'); | 3774 | trace_seq_putc(s, ']'); |
3775 | field->flags &= ~FIELD_IS_STRING; | ||
3622 | } | 3776 | } |
3623 | } else { | 3777 | } else { |
3624 | val = pevent_read_number(event->pevent, data + field->offset, | 3778 | val = pevent_read_number(event->pevent, data + field->offset, |
@@ -3758,6 +3912,7 @@ static void pretty_print(struct trace_seq *s, void *data, int size, struct event | |||
3758 | } else if (*(ptr+1) == 'M' || *(ptr+1) == 'm') { | 3912 | } else if (*(ptr+1) == 'M' || *(ptr+1) == 'm') { |
3759 | print_mac_arg(s, *(ptr+1), data, size, event, arg); | 3913 | print_mac_arg(s, *(ptr+1), data, size, event, arg); |
3760 | ptr++; | 3914 | ptr++; |
3915 | arg = arg->next; | ||
3761 | break; | 3916 | break; |
3762 | } | 3917 | } |
3763 | 3918 | ||
@@ -3794,14 +3949,15 @@ static void pretty_print(struct trace_seq *s, void *data, int size, struct event | |||
3794 | break; | 3949 | break; |
3795 | } | 3950 | } |
3796 | } | 3951 | } |
3797 | if (pevent->long_size == 8 && ls) { | 3952 | if (pevent->long_size == 8 && ls && |
3953 | sizeof(long) != 8) { | ||
3798 | char *p; | 3954 | char *p; |
3799 | 3955 | ||
3800 | ls = 2; | 3956 | ls = 2; |
3801 | /* make %l into %ll */ | 3957 | /* make %l into %ll */ |
3802 | p = strchr(format, 'l'); | 3958 | p = strchr(format, 'l'); |
3803 | if (p) | 3959 | if (p) |
3804 | memmove(p, p+1, strlen(p)+1); | 3960 | memmove(p+1, p, strlen(p)+1); |
3805 | else if (strcmp(format, "%p") == 0) | 3961 | else if (strcmp(format, "%p") == 0) |
3806 | strcpy(format, "0x%llx"); | 3962 | strcpy(format, "0x%llx"); |
3807 | } | 3963 | } |
@@ -3878,8 +4034,7 @@ static void pretty_print(struct trace_seq *s, void *data, int size, struct event | |||
3878 | * pevent_data_lat_fmt - parse the data for the latency format | 4034 | * pevent_data_lat_fmt - parse the data for the latency format |
3879 | * @pevent: a handle to the pevent | 4035 | * @pevent: a handle to the pevent |
3880 | * @s: the trace_seq to write to | 4036 | * @s: the trace_seq to write to |
3881 | * @data: the raw data to read from | 4037 | * @record: the record to read from |
3882 | * @size: currently unused. | ||
3883 | * | 4038 | * |
3884 | * This parses out the Latency format (interrupts disabled, | 4039 | * This parses out the Latency format (interrupts disabled, |
3885 | * need rescheduling, in hard/soft interrupt, preempt count | 4040 | * need rescheduling, in hard/soft interrupt, preempt count |
@@ -3889,10 +4044,13 @@ void pevent_data_lat_fmt(struct pevent *pevent, | |||
3889 | struct trace_seq *s, struct pevent_record *record) | 4044 | struct trace_seq *s, struct pevent_record *record) |
3890 | { | 4045 | { |
3891 | static int check_lock_depth = 1; | 4046 | static int check_lock_depth = 1; |
4047 | static int check_migrate_disable = 1; | ||
3892 | static int lock_depth_exists; | 4048 | static int lock_depth_exists; |
4049 | static int migrate_disable_exists; | ||
3893 | unsigned int lat_flags; | 4050 | unsigned int lat_flags; |
3894 | unsigned int pc; | 4051 | unsigned int pc; |
3895 | int lock_depth; | 4052 | int lock_depth; |
4053 | int migrate_disable; | ||
3896 | int hardirq; | 4054 | int hardirq; |
3897 | int softirq; | 4055 | int softirq; |
3898 | void *data = record->data; | 4056 | void *data = record->data; |
@@ -3900,18 +4058,26 @@ void pevent_data_lat_fmt(struct pevent *pevent, | |||
3900 | lat_flags = parse_common_flags(pevent, data); | 4058 | lat_flags = parse_common_flags(pevent, data); |
3901 | pc = parse_common_pc(pevent, data); | 4059 | pc = parse_common_pc(pevent, data); |
3902 | /* lock_depth may not always exist */ | 4060 | /* lock_depth may not always exist */ |
3903 | if (check_lock_depth) { | ||
3904 | struct format_field *field; | ||
3905 | struct event_format *event; | ||
3906 | |||
3907 | check_lock_depth = 0; | ||
3908 | event = pevent->events[0]; | ||
3909 | field = pevent_find_common_field(event, "common_lock_depth"); | ||
3910 | if (field) | ||
3911 | lock_depth_exists = 1; | ||
3912 | } | ||
3913 | if (lock_depth_exists) | 4061 | if (lock_depth_exists) |
3914 | lock_depth = parse_common_lock_depth(pevent, data); | 4062 | lock_depth = parse_common_lock_depth(pevent, data); |
4063 | else if (check_lock_depth) { | ||
4064 | lock_depth = parse_common_lock_depth(pevent, data); | ||
4065 | if (lock_depth < 0) | ||
4066 | check_lock_depth = 0; | ||
4067 | else | ||
4068 | lock_depth_exists = 1; | ||
4069 | } | ||
4070 | |||
4071 | /* migrate_disable may not always exist */ | ||
4072 | if (migrate_disable_exists) | ||
4073 | migrate_disable = parse_common_migrate_disable(pevent, data); | ||
4074 | else if (check_migrate_disable) { | ||
4075 | migrate_disable = parse_common_migrate_disable(pevent, data); | ||
4076 | if (migrate_disable < 0) | ||
4077 | check_migrate_disable = 0; | ||
4078 | else | ||
4079 | migrate_disable_exists = 1; | ||
4080 | } | ||
3915 | 4081 | ||
3916 | hardirq = lat_flags & TRACE_FLAG_HARDIRQ; | 4082 | hardirq = lat_flags & TRACE_FLAG_HARDIRQ; |
3917 | softirq = lat_flags & TRACE_FLAG_SOFTIRQ; | 4083 | softirq = lat_flags & TRACE_FLAG_SOFTIRQ; |
@@ -3930,6 +4096,13 @@ void pevent_data_lat_fmt(struct pevent *pevent, | |||
3930 | else | 4096 | else |
3931 | trace_seq_putc(s, '.'); | 4097 | trace_seq_putc(s, '.'); |
3932 | 4098 | ||
4099 | if (migrate_disable_exists) { | ||
4100 | if (migrate_disable < 0) | ||
4101 | trace_seq_putc(s, '.'); | ||
4102 | else | ||
4103 | trace_seq_printf(s, "%d", migrate_disable); | ||
4104 | } | ||
4105 | |||
3933 | if (lock_depth_exists) { | 4106 | if (lock_depth_exists) { |
3934 | if (lock_depth < 0) | 4107 | if (lock_depth < 0) |
3935 | trace_seq_putc(s, '.'); | 4108 | trace_seq_putc(s, '.'); |
@@ -3996,10 +4169,7 @@ const char *pevent_data_comm_from_pid(struct pevent *pevent, int pid) | |||
3996 | * pevent_data_comm_from_pid - parse the data into the print format | 4169 | * pevent_data_comm_from_pid - parse the data into the print format |
3997 | * @s: the trace_seq to write to | 4170 | * @s: the trace_seq to write to |
3998 | * @event: the handle to the event | 4171 | * @event: the handle to the event |
3999 | * @cpu: the cpu the event was recorded on | 4172 | * @record: the record to read from |
4000 | * @data: the raw data | ||
4001 | * @size: the size of the raw data | ||
4002 | * @nsecs: the timestamp of the event | ||
4003 | * | 4173 | * |
4004 | * This parses the raw @data using the given @event information and | 4174 | * This parses the raw @data using the given @event information and |
4005 | * writes the print format into the trace_seq. | 4175 | * writes the print format into the trace_seq. |
@@ -4279,6 +4449,13 @@ static void print_args(struct print_arg *args) | |||
4279 | trace_seq_destroy(&s); | 4449 | trace_seq_destroy(&s); |
4280 | printf(")"); | 4450 | printf(")"); |
4281 | break; | 4451 | break; |
4452 | case PRINT_HEX: | ||
4453 | printf("__print_hex("); | ||
4454 | print_args(args->hex.field); | ||
4455 | printf(", "); | ||
4456 | print_args(args->hex.size); | ||
4457 | printf(")"); | ||
4458 | break; | ||
4282 | case PRINT_STRING: | 4459 | case PRINT_STRING: |
4283 | case PRINT_BSTRING: | 4460 | case PRINT_BSTRING: |
4284 | printf("__get_str(%s)", args->string.string); | 4461 | printf("__get_str(%s)", args->string.string); |
@@ -4541,6 +4718,8 @@ int pevent_parse_event(struct pevent *pevent, | |||
4541 | die("failed to read event id"); | 4718 | die("failed to read event id"); |
4542 | 4719 | ||
4543 | event->system = strdup(sys); | 4720 | event->system = strdup(sys); |
4721 | if (!event->system) | ||
4722 | die("failed to allocate system"); | ||
4544 | 4723 | ||
4545 | /* Add pevent to event so that it can be referenced */ | 4724 | /* Add pevent to event so that it can be referenced */ |
4546 | event->pevent = pevent; | 4725 | event->pevent = pevent; |
@@ -4582,6 +4761,11 @@ int pevent_parse_event(struct pevent *pevent, | |||
4582 | list = &arg->next; | 4761 | list = &arg->next; |
4583 | arg->type = PRINT_FIELD; | 4762 | arg->type = PRINT_FIELD; |
4584 | arg->field.name = strdup(field->name); | 4763 | arg->field.name = strdup(field->name); |
4764 | if (!arg->field.name) { | ||
4765 | do_warning("failed to allocate field name"); | ||
4766 | event->flags |= EVENT_FL_FAILED; | ||
4767 | return -1; | ||
4768 | } | ||
4585 | arg->field.field = field; | 4769 | arg->field.field = field; |
4586 | } | 4770 | } |
4587 | return 0; | 4771 | return 0; |
@@ -4753,7 +4937,7 @@ int pevent_get_any_field_val(struct trace_seq *s, struct event_format *event, | |||
4753 | * @record: The record with the field name. | 4937 | * @record: The record with the field name. |
4754 | * @err: print default error if failed. | 4938 | * @err: print default error if failed. |
4755 | * | 4939 | * |
4756 | * Returns: 0 on success, -1 field not fould, or 1 if buffer is full. | 4940 | * Returns: 0 on success, -1 field not found, or 1 if buffer is full. |
4757 | */ | 4941 | */ |
4758 | int pevent_print_num_field(struct trace_seq *s, const char *fmt, | 4942 | int pevent_print_num_field(struct trace_seq *s, const char *fmt, |
4759 | struct event_format *event, const char *name, | 4943 | struct event_format *event, const char *name, |
@@ -4795,11 +4979,12 @@ static void free_func_handle(struct pevent_function_handler *func) | |||
4795 | * pevent_register_print_function - register a helper function | 4979 | * pevent_register_print_function - register a helper function |
4796 | * @pevent: the handle to the pevent | 4980 | * @pevent: the handle to the pevent |
4797 | * @func: the function to process the helper function | 4981 | * @func: the function to process the helper function |
4982 | * @ret_type: the return type of the helper function | ||
4798 | * @name: the name of the helper function | 4983 | * @name: the name of the helper function |
4799 | * @parameters: A list of enum pevent_func_arg_type | 4984 | * @parameters: A list of enum pevent_func_arg_type |
4800 | * | 4985 | * |
4801 | * Some events may have helper functions in the print format arguments. | 4986 | * Some events may have helper functions in the print format arguments. |
4802 | * This allows a plugin to dynmically create a way to process one | 4987 | * This allows a plugin to dynamically create a way to process one |
4803 | * of these functions. | 4988 | * of these functions. |
4804 | * | 4989 | * |
4805 | * The @parameters is a variable list of pevent_func_arg_type enums that | 4990 | * The @parameters is a variable list of pevent_func_arg_type enums that |
@@ -4870,12 +5055,13 @@ int pevent_register_print_function(struct pevent *pevent, | |||
4870 | } | 5055 | } |
4871 | 5056 | ||
4872 | /** | 5057 | /** |
4873 | * pevent_register_event_handle - register a way to parse an event | 5058 | * pevent_register_event_handler - register a way to parse an event |
4874 | * @pevent: the handle to the pevent | 5059 | * @pevent: the handle to the pevent |
4875 | * @id: the id of the event to register | 5060 | * @id: the id of the event to register |
4876 | * @sys_name: the system name the event belongs to | 5061 | * @sys_name: the system name the event belongs to |
4877 | * @event_name: the name of the event | 5062 | * @event_name: the name of the event |
4878 | * @func: the function to call to parse the event information | 5063 | * @func: the function to call to parse the event information |
5064 | * @context: the data to be passed to @func | ||
4879 | * | 5065 | * |
4880 | * This function allows a developer to override the parsing of | 5066 | * This function allows a developer to override the parsing of |
4881 | * a given event. If for some reason the default print format | 5067 | * a given event. If for some reason the default print format |
@@ -4925,6 +5111,11 @@ int pevent_register_event_handler(struct pevent *pevent, | |||
4925 | if (sys_name) | 5111 | if (sys_name) |
4926 | handle->sys_name = strdup(sys_name); | 5112 | handle->sys_name = strdup(sys_name); |
4927 | 5113 | ||
5114 | if ((event_name && !handle->event_name) || | ||
5115 | (sys_name && !handle->sys_name)) { | ||
5116 | die("Failed to allocate event/sys name"); | ||
5117 | } | ||
5118 | |||
4928 | handle->func = func; | 5119 | handle->func = func; |
4929 | handle->next = pevent->handlers; | 5120 | handle->next = pevent->handlers; |
4930 | pevent->handlers = handle; | 5121 | pevent->handlers = handle; |
diff --git a/tools/lib/traceevent/event-parse.h b/tools/lib/traceevent/event-parse.h index ac997bc7b592..5772ad8cb386 100644 --- a/tools/lib/traceevent/event-parse.h +++ b/tools/lib/traceevent/event-parse.h | |||
@@ -226,6 +226,11 @@ struct print_arg_symbol { | |||
226 | struct print_flag_sym *symbols; | 226 | struct print_flag_sym *symbols; |
227 | }; | 227 | }; |
228 | 228 | ||
229 | struct print_arg_hex { | ||
230 | struct print_arg *field; | ||
231 | struct print_arg *size; | ||
232 | }; | ||
233 | |||
229 | struct print_arg_dynarray { | 234 | struct print_arg_dynarray { |
230 | struct format_field *field; | 235 | struct format_field *field; |
231 | struct print_arg *index; | 236 | struct print_arg *index; |
@@ -253,6 +258,7 @@ enum print_arg_type { | |||
253 | PRINT_FIELD, | 258 | PRINT_FIELD, |
254 | PRINT_FLAGS, | 259 | PRINT_FLAGS, |
255 | PRINT_SYMBOL, | 260 | PRINT_SYMBOL, |
261 | PRINT_HEX, | ||
256 | PRINT_TYPE, | 262 | PRINT_TYPE, |
257 | PRINT_STRING, | 263 | PRINT_STRING, |
258 | PRINT_BSTRING, | 264 | PRINT_BSTRING, |
@@ -270,6 +276,7 @@ struct print_arg { | |||
270 | struct print_arg_typecast typecast; | 276 | struct print_arg_typecast typecast; |
271 | struct print_arg_flags flags; | 277 | struct print_arg_flags flags; |
272 | struct print_arg_symbol symbol; | 278 | struct print_arg_symbol symbol; |
279 | struct print_arg_hex hex; | ||
273 | struct print_arg_func func; | 280 | struct print_arg_func func; |
274 | struct print_arg_string string; | 281 | struct print_arg_string string; |
275 | struct print_arg_op op; | 282 | struct print_arg_op op; |
diff --git a/tools/lib/traceevent/parse-filter.c b/tools/lib/traceevent/parse-filter.c index dfcfe2c131de..ad17855528f9 100644 --- a/tools/lib/traceevent/parse-filter.c +++ b/tools/lib/traceevent/parse-filter.c | |||
@@ -96,7 +96,7 @@ static enum event_type read_token(char **tok) | |||
96 | (strcmp(token, "=") == 0 || strcmp(token, "!") == 0) && | 96 | (strcmp(token, "=") == 0 || strcmp(token, "!") == 0) && |
97 | pevent_peek_char() == '~') { | 97 | pevent_peek_char() == '~') { |
98 | /* append it */ | 98 | /* append it */ |
99 | *tok = malloc(3); | 99 | *tok = malloc_or_die(3); |
100 | sprintf(*tok, "%c%c", *token, '~'); | 100 | sprintf(*tok, "%c%c", *token, '~'); |
101 | free_token(token); | 101 | free_token(token); |
102 | /* Now remove the '~' from the buffer */ | 102 | /* Now remove the '~' from the buffer */ |
@@ -148,17 +148,11 @@ add_filter_type(struct event_filter *filter, int id) | |||
148 | if (filter_type) | 148 | if (filter_type) |
149 | return filter_type; | 149 | return filter_type; |
150 | 150 | ||
151 | if (!filter->filters) | 151 | filter->event_filters = realloc(filter->event_filters, |
152 | filter->event_filters = | 152 | sizeof(*filter->event_filters) * |
153 | malloc_or_die(sizeof(*filter->event_filters)); | 153 | (filter->filters + 1)); |
154 | else { | 154 | if (!filter->event_filters) |
155 | filter->event_filters = | 155 | die("Could not allocate filter"); |
156 | realloc(filter->event_filters, | ||
157 | sizeof(*filter->event_filters) * | ||
158 | (filter->filters + 1)); | ||
159 | if (!filter->event_filters) | ||
160 | die("Could not allocate filter"); | ||
161 | } | ||
162 | 156 | ||
163 | for (i = 0; i < filter->filters; i++) { | 157 | for (i = 0; i < filter->filters; i++) { |
164 | if (filter->event_filters[i].event_id > id) | 158 | if (filter->event_filters[i].event_id > id) |
@@ -1480,7 +1474,7 @@ void pevent_filter_clear_trivial(struct event_filter *filter, | |||
1480 | { | 1474 | { |
1481 | struct filter_type *filter_type; | 1475 | struct filter_type *filter_type; |
1482 | int count = 0; | 1476 | int count = 0; |
1483 | int *ids; | 1477 | int *ids = NULL; |
1484 | int i; | 1478 | int i; |
1485 | 1479 | ||
1486 | if (!filter->filters) | 1480 | if (!filter->filters) |
@@ -1504,10 +1498,8 @@ void pevent_filter_clear_trivial(struct event_filter *filter, | |||
1504 | default: | 1498 | default: |
1505 | break; | 1499 | break; |
1506 | } | 1500 | } |
1507 | if (count) | 1501 | |
1508 | ids = realloc(ids, sizeof(*ids) * (count + 1)); | 1502 | ids = realloc(ids, sizeof(*ids) * (count + 1)); |
1509 | else | ||
1510 | ids = malloc(sizeof(*ids)); | ||
1511 | if (!ids) | 1503 | if (!ids) |
1512 | die("Can't allocate ids"); | 1504 | die("Can't allocate ids"); |
1513 | ids[count++] = filter_type->event_id; | 1505 | ids[count++] = filter_type->event_id; |
@@ -1710,18 +1702,43 @@ static int test_num(struct event_format *event, | |||
1710 | 1702 | ||
1711 | static const char *get_field_str(struct filter_arg *arg, struct pevent_record *record) | 1703 | static const char *get_field_str(struct filter_arg *arg, struct pevent_record *record) |
1712 | { | 1704 | { |
1713 | const char *val = record->data + arg->str.field->offset; | 1705 | struct event_format *event; |
1706 | struct pevent *pevent; | ||
1707 | unsigned long long addr; | ||
1708 | const char *val = NULL; | ||
1709 | char hex[64]; | ||
1714 | 1710 | ||
1715 | /* | 1711 | /* If the field is not a string convert it */ |
1716 | * We need to copy the data since we can't be sure the field | 1712 | if (arg->str.field->flags & FIELD_IS_STRING) { |
1717 | * is null terminated. | 1713 | val = record->data + arg->str.field->offset; |
1718 | */ | 1714 | |
1719 | if (*(val + arg->str.field->size - 1)) { | 1715 | /* |
1720 | /* copy it */ | 1716 | * We need to copy the data since we can't be sure the field |
1721 | memcpy(arg->str.buffer, val, arg->str.field->size); | 1717 | * is null terminated. |
1722 | /* the buffer is already NULL terminated */ | 1718 | */ |
1723 | val = arg->str.buffer; | 1719 | if (*(val + arg->str.field->size - 1)) { |
1720 | /* copy it */ | ||
1721 | memcpy(arg->str.buffer, val, arg->str.field->size); | ||
1722 | /* the buffer is already NULL terminated */ | ||
1723 | val = arg->str.buffer; | ||
1724 | } | ||
1725 | |||
1726 | } else { | ||
1727 | event = arg->str.field->event; | ||
1728 | pevent = event->pevent; | ||
1729 | addr = get_value(event, arg->str.field, record); | ||
1730 | |||
1731 | if (arg->str.field->flags & (FIELD_IS_POINTER | FIELD_IS_LONG)) | ||
1732 | /* convert to a kernel symbol */ | ||
1733 | val = pevent_find_function(pevent, addr); | ||
1734 | |||
1735 | if (val == NULL) { | ||
1736 | /* just use the hex of the string name */ | ||
1737 | snprintf(hex, 64, "0x%llx", addr); | ||
1738 | val = hex; | ||
1739 | } | ||
1724 | } | 1740 | } |
1741 | |||
1725 | return val; | 1742 | return val; |
1726 | } | 1743 | } |
1727 | 1744 | ||
@@ -2001,11 +2018,13 @@ static char *exp_to_str(struct event_filter *filter, struct filter_arg *arg) | |||
2001 | char *lstr; | 2018 | char *lstr; |
2002 | char *rstr; | 2019 | char *rstr; |
2003 | char *op; | 2020 | char *op; |
2004 | char *str; | 2021 | char *str = NULL; |
2005 | int len; | 2022 | int len; |
2006 | 2023 | ||
2007 | lstr = arg_to_str(filter, arg->exp.left); | 2024 | lstr = arg_to_str(filter, arg->exp.left); |
2008 | rstr = arg_to_str(filter, arg->exp.right); | 2025 | rstr = arg_to_str(filter, arg->exp.right); |
2026 | if (!lstr || !rstr) | ||
2027 | goto out; | ||
2009 | 2028 | ||
2010 | switch (arg->exp.type) { | 2029 | switch (arg->exp.type) { |
2011 | case FILTER_EXP_ADD: | 2030 | case FILTER_EXP_ADD: |
@@ -2045,6 +2064,7 @@ static char *exp_to_str(struct event_filter *filter, struct filter_arg *arg) | |||
2045 | len = strlen(op) + strlen(lstr) + strlen(rstr) + 4; | 2064 | len = strlen(op) + strlen(lstr) + strlen(rstr) + 4; |
2046 | str = malloc_or_die(len); | 2065 | str = malloc_or_die(len); |
2047 | snprintf(str, len, "%s %s %s", lstr, op, rstr); | 2066 | snprintf(str, len, "%s %s %s", lstr, op, rstr); |
2067 | out: | ||
2048 | free(lstr); | 2068 | free(lstr); |
2049 | free(rstr); | 2069 | free(rstr); |
2050 | 2070 | ||
@@ -2061,6 +2081,8 @@ static char *num_to_str(struct event_filter *filter, struct filter_arg *arg) | |||
2061 | 2081 | ||
2062 | lstr = arg_to_str(filter, arg->num.left); | 2082 | lstr = arg_to_str(filter, arg->num.left); |
2063 | rstr = arg_to_str(filter, arg->num.right); | 2083 | rstr = arg_to_str(filter, arg->num.right); |
2084 | if (!lstr || !rstr) | ||
2085 | goto out; | ||
2064 | 2086 | ||
2065 | switch (arg->num.type) { | 2087 | switch (arg->num.type) { |
2066 | case FILTER_CMP_EQ: | 2088 | case FILTER_CMP_EQ: |
@@ -2097,6 +2119,7 @@ static char *num_to_str(struct event_filter *filter, struct filter_arg *arg) | |||
2097 | break; | 2119 | break; |
2098 | } | 2120 | } |
2099 | 2121 | ||
2122 | out: | ||
2100 | free(lstr); | 2123 | free(lstr); |
2101 | free(rstr); | 2124 | free(rstr); |
2102 | return str; | 2125 | return str; |
@@ -2247,7 +2270,12 @@ int pevent_filter_compare(struct event_filter *filter1, struct event_filter *fil | |||
2247 | /* The best way to compare complex filters is with strings */ | 2270 | /* The best way to compare complex filters is with strings */ |
2248 | str1 = arg_to_str(filter1, filter_type1->filter); | 2271 | str1 = arg_to_str(filter1, filter_type1->filter); |
2249 | str2 = arg_to_str(filter2, filter_type2->filter); | 2272 | str2 = arg_to_str(filter2, filter_type2->filter); |
2250 | result = strcmp(str1, str2) != 0; | 2273 | if (str1 && str2) |
2274 | result = strcmp(str1, str2) != 0; | ||
2275 | else | ||
2276 | /* bail out if allocation fails */ | ||
2277 | result = 1; | ||
2278 | |||
2251 | free(str1); | 2279 | free(str1); |
2252 | free(str2); | 2280 | free(str2); |
2253 | if (result) | 2281 | if (result) |
diff --git a/tools/perf/Documentation/perf-bench.txt b/tools/perf/Documentation/perf-bench.txt index a3dbadb26ef5..7065cd6fbdfc 100644 --- a/tools/perf/Documentation/perf-bench.txt +++ b/tools/perf/Documentation/perf-bench.txt | |||
@@ -12,7 +12,7 @@ SYNOPSIS | |||
12 | 12 | ||
13 | DESCRIPTION | 13 | DESCRIPTION |
14 | ----------- | 14 | ----------- |
15 | This 'perf bench' command is general framework for benchmark suites. | 15 | This 'perf bench' command is a general framework for benchmark suites. |
16 | 16 | ||
17 | COMMON OPTIONS | 17 | COMMON OPTIONS |
18 | -------------- | 18 | -------------- |
@@ -45,14 +45,20 @@ SUBSYSTEM | |||
45 | 'sched':: | 45 | 'sched':: |
46 | Scheduler and IPC mechanisms. | 46 | Scheduler and IPC mechanisms. |
47 | 47 | ||
48 | 'mem':: | ||
49 | Memory access performance. | ||
50 | |||
51 | 'all':: | ||
52 | All benchmark subsystems. | ||
53 | |||
48 | SUITES FOR 'sched' | 54 | SUITES FOR 'sched' |
49 | ~~~~~~~~~~~~~~~~~~ | 55 | ~~~~~~~~~~~~~~~~~~ |
50 | *messaging*:: | 56 | *messaging*:: |
51 | Suite for evaluating performance of scheduler and IPC mechanisms. | 57 | Suite for evaluating performance of scheduler and IPC mechanisms. |
52 | Based on hackbench by Rusty Russell. | 58 | Based on hackbench by Rusty Russell. |
53 | 59 | ||
54 | Options of *pipe* | 60 | Options of *messaging* |
55 | ^^^^^^^^^^^^^^^^^ | 61 | ^^^^^^^^^^^^^^^^^^^^^^ |
56 | -p:: | 62 | -p:: |
57 | --pipe:: | 63 | --pipe:: |
58 | Use pipe() instead of socketpair() | 64 | Use pipe() instead of socketpair() |
@@ -115,6 +121,72 @@ Example of *pipe* | |||
115 | 59004 ops/sec | 121 | 59004 ops/sec |
116 | --------------------- | 122 | --------------------- |
117 | 123 | ||
124 | SUITES FOR 'mem' | ||
125 | ~~~~~~~~~~~~~~~~ | ||
126 | *memcpy*:: | ||
127 | Suite for evaluating performance of simple memory copy in various ways. | ||
128 | |||
129 | Options of *memcpy* | ||
130 | ^^^^^^^^^^^^^^^^^^^ | ||
131 | -l:: | ||
132 | --length:: | ||
133 | Specify length of memory to copy (default: 1MB). | ||
134 | Available units are B, KB, MB, GB and TB (case insensitive). | ||
135 | |||
136 | -r:: | ||
137 | --routine:: | ||
138 | Specify routine to copy (default: default). | ||
139 | Available routines are depend on the architecture. | ||
140 | On x86-64, x86-64-unrolled, x86-64-movsq and x86-64-movsb are supported. | ||
141 | |||
142 | -i:: | ||
143 | --iterations:: | ||
144 | Repeat memcpy invocation this number of times. | ||
145 | |||
146 | -c:: | ||
147 | --cycle:: | ||
148 | Use perf's cpu-cycles event instead of gettimeofday syscall. | ||
149 | |||
150 | -o:: | ||
151 | --only-prefault:: | ||
152 | Show only the result with page faults before memcpy. | ||
153 | |||
154 | -n:: | ||
155 | --no-prefault:: | ||
156 | Show only the result without page faults before memcpy. | ||
157 | |||
158 | *memset*:: | ||
159 | Suite for evaluating performance of simple memory set in various ways. | ||
160 | |||
161 | Options of *memset* | ||
162 | ^^^^^^^^^^^^^^^^^^^ | ||
163 | -l:: | ||
164 | --length:: | ||
165 | Specify length of memory to set (default: 1MB). | ||
166 | Available units are B, KB, MB, GB and TB (case insensitive). | ||
167 | |||
168 | -r:: | ||
169 | --routine:: | ||
170 | Specify routine to set (default: default). | ||
171 | Available routines are depend on the architecture. | ||
172 | On x86-64, x86-64-unrolled, x86-64-stosq and x86-64-stosb are supported. | ||
173 | |||
174 | -i:: | ||
175 | --iterations:: | ||
176 | Repeat memset invocation this number of times. | ||
177 | |||
178 | -c:: | ||
179 | --cycle:: | ||
180 | Use perf's cpu-cycles event instead of gettimeofday syscall. | ||
181 | |||
182 | -o:: | ||
183 | --only-prefault:: | ||
184 | Show only the result with page faults before memset. | ||
185 | |||
186 | -n:: | ||
187 | --no-prefault:: | ||
188 | Show only the result without page faults before memset. | ||
189 | |||
118 | SEE ALSO | 190 | SEE ALSO |
119 | -------- | 191 | -------- |
120 | linkperf:perf[1] | 192 | linkperf:perf[1] |
diff --git a/tools/perf/Documentation/perf-report.txt b/tools/perf/Documentation/perf-report.txt index 2d89f02719b5..495210a612c4 100644 --- a/tools/perf/Documentation/perf-report.txt +++ b/tools/perf/Documentation/perf-report.txt | |||
@@ -57,7 +57,7 @@ OPTIONS | |||
57 | 57 | ||
58 | -s:: | 58 | -s:: |
59 | --sort=:: | 59 | --sort=:: |
60 | Sort by key(s): pid, comm, dso, symbol, parent. | 60 | Sort by key(s): pid, comm, dso, symbol, parent, srcline. |
61 | 61 | ||
62 | -p:: | 62 | -p:: |
63 | --parent=<regex>:: | 63 | --parent=<regex>:: |
diff --git a/tools/perf/Documentation/perf-top.txt b/tools/perf/Documentation/perf-top.txt index 4a5680cb242e..5b80d84d6b4a 100644 --- a/tools/perf/Documentation/perf-top.txt +++ b/tools/perf/Documentation/perf-top.txt | |||
@@ -112,7 +112,7 @@ Default is to monitor all CPUS. | |||
112 | 112 | ||
113 | -s:: | 113 | -s:: |
114 | --sort:: | 114 | --sort:: |
115 | Sort by key(s): pid, comm, dso, symbol, parent | 115 | Sort by key(s): pid, comm, dso, symbol, parent, srcline. |
116 | 116 | ||
117 | -n:: | 117 | -n:: |
118 | --show-nr-samples:: | 118 | --show-nr-samples:: |
diff --git a/tools/perf/Makefile b/tools/perf/Makefile index 0eee64cfe9a0..77f124fe57ad 100644 --- a/tools/perf/Makefile +++ b/tools/perf/Makefile | |||
@@ -155,7 +155,7 @@ endif | |||
155 | 155 | ||
156 | ### --- END CONFIGURATION SECTION --- | 156 | ### --- END CONFIGURATION SECTION --- |
157 | 157 | ||
158 | BASIC_CFLAGS = -Iutil/include -Iarch/$(ARCH)/include -I$(OUTPUT)/util -I$(TRACE_EVENT_DIR) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE | 158 | BASIC_CFLAGS = -Iutil/include -Iarch/$(ARCH)/include -I$(OUTPUT)util -I$(TRACE_EVENT_DIR) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE |
159 | BASIC_LDFLAGS = | 159 | BASIC_LDFLAGS = |
160 | 160 | ||
161 | # Guard against environment variables | 161 | # Guard against environment variables |
@@ -354,6 +354,7 @@ LIB_OBJS += $(OUTPUT)util/usage.o | |||
354 | LIB_OBJS += $(OUTPUT)util/wrapper.o | 354 | LIB_OBJS += $(OUTPUT)util/wrapper.o |
355 | LIB_OBJS += $(OUTPUT)util/sigchain.o | 355 | LIB_OBJS += $(OUTPUT)util/sigchain.o |
356 | LIB_OBJS += $(OUTPUT)util/symbol.o | 356 | LIB_OBJS += $(OUTPUT)util/symbol.o |
357 | LIB_OBJS += $(OUTPUT)util/dso-test-data.o | ||
357 | LIB_OBJS += $(OUTPUT)util/color.o | 358 | LIB_OBJS += $(OUTPUT)util/color.o |
358 | LIB_OBJS += $(OUTPUT)util/pager.o | 359 | LIB_OBJS += $(OUTPUT)util/pager.o |
359 | LIB_OBJS += $(OUTPUT)util/header.o | 360 | LIB_OBJS += $(OUTPUT)util/header.o |
@@ -503,6 +504,7 @@ else | |||
503 | LIB_OBJS += $(OUTPUT)ui/progress.o | 504 | LIB_OBJS += $(OUTPUT)ui/progress.o |
504 | LIB_OBJS += $(OUTPUT)ui/util.o | 505 | LIB_OBJS += $(OUTPUT)ui/util.o |
505 | LIB_OBJS += $(OUTPUT)ui/tui/setup.o | 506 | LIB_OBJS += $(OUTPUT)ui/tui/setup.o |
507 | LIB_OBJS += $(OUTPUT)ui/tui/util.o | ||
506 | LIB_H += ui/browser.h | 508 | LIB_H += ui/browser.h |
507 | LIB_H += ui/browsers/map.h | 509 | LIB_H += ui/browsers/map.h |
508 | LIB_H += ui/helpline.h | 510 | LIB_H += ui/helpline.h |
@@ -522,13 +524,18 @@ else | |||
522 | msg := $(warning GTK2 not found, disables GTK2 support. Please install gtk2-devel or libgtk2.0-dev); | 524 | msg := $(warning GTK2 not found, disables GTK2 support. Please install gtk2-devel or libgtk2.0-dev); |
523 | BASIC_CFLAGS += -DNO_GTK2_SUPPORT | 525 | BASIC_CFLAGS += -DNO_GTK2_SUPPORT |
524 | else | 526 | else |
527 | ifeq ($(call try-cc,$(SOURCE_GTK2_INFOBAR),$(FLAGS_GTK2)),y) | ||
528 | BASIC_CFLAGS += -DHAVE_GTK_INFO_BAR | ||
529 | endif | ||
525 | BASIC_CFLAGS += $(shell pkg-config --cflags gtk+-2.0) | 530 | BASIC_CFLAGS += $(shell pkg-config --cflags gtk+-2.0) |
526 | EXTLIBS += $(shell pkg-config --libs gtk+-2.0) | 531 | EXTLIBS += $(shell pkg-config --libs gtk+-2.0) |
527 | LIB_OBJS += $(OUTPUT)ui/gtk/browser.o | 532 | LIB_OBJS += $(OUTPUT)ui/gtk/browser.o |
528 | LIB_OBJS += $(OUTPUT)ui/gtk/setup.o | 533 | LIB_OBJS += $(OUTPUT)ui/gtk/setup.o |
534 | LIB_OBJS += $(OUTPUT)ui/gtk/util.o | ||
529 | # Make sure that it'd be included only once. | 535 | # Make sure that it'd be included only once. |
530 | ifneq ($(findstring -DNO_NEWT_SUPPORT,$(BASIC_CFLAGS)),) | 536 | ifneq ($(findstring -DNO_NEWT_SUPPORT,$(BASIC_CFLAGS)),) |
531 | LIB_OBJS += $(OUTPUT)ui/setup.o | 537 | LIB_OBJS += $(OUTPUT)ui/setup.o |
538 | LIB_OBJS += $(OUTPUT)ui/util.o | ||
532 | endif | 539 | endif |
533 | endif | 540 | endif |
534 | endif | 541 | endif |
@@ -797,6 +804,9 @@ $(OUTPUT)ui/browsers/map.o: ui/browsers/map.c $(OUTPUT)PERF-CFLAGS | |||
797 | $(OUTPUT)util/rbtree.o: ../../lib/rbtree.c $(OUTPUT)PERF-CFLAGS | 804 | $(OUTPUT)util/rbtree.o: ../../lib/rbtree.c $(OUTPUT)PERF-CFLAGS |
798 | $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $< | 805 | $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $< |
799 | 806 | ||
807 | $(OUTPUT)util/parse-events.o: util/parse-events.c $(OUTPUT)PERF-CFLAGS | ||
808 | $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -Wno-redundant-decls $< | ||
809 | |||
800 | $(OUTPUT)util/scripting-engines/trace-event-perl.o: util/scripting-engines/trace-event-perl.c $(OUTPUT)PERF-CFLAGS | 810 | $(OUTPUT)util/scripting-engines/trace-event-perl.o: util/scripting-engines/trace-event-perl.c $(OUTPUT)PERF-CFLAGS |
801 | $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $(PERL_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-shadow $< | 811 | $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $(PERL_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-shadow $< |
802 | 812 | ||
diff --git a/tools/perf/bench/mem-memcpy.c b/tools/perf/bench/mem-memcpy.c index 71557225bf92..02dad5d3359b 100644 --- a/tools/perf/bench/mem-memcpy.c +++ b/tools/perf/bench/mem-memcpy.c | |||
@@ -24,21 +24,21 @@ | |||
24 | static const char *length_str = "1MB"; | 24 | static const char *length_str = "1MB"; |
25 | static const char *routine = "default"; | 25 | static const char *routine = "default"; |
26 | static int iterations = 1; | 26 | static int iterations = 1; |
27 | static bool use_clock; | 27 | static bool use_cycle; |
28 | static int clock_fd; | 28 | static int cycle_fd; |
29 | static bool only_prefault; | 29 | static bool only_prefault; |
30 | static bool no_prefault; | 30 | static bool no_prefault; |
31 | 31 | ||
32 | static const struct option options[] = { | 32 | static const struct option options[] = { |
33 | OPT_STRING('l', "length", &length_str, "1MB", | 33 | OPT_STRING('l', "length", &length_str, "1MB", |
34 | "Specify length of memory to copy. " | 34 | "Specify length of memory to copy. " |
35 | "available unit: B, MB, GB (upper and lower)"), | 35 | "Available units: B, KB, MB, GB and TB (upper and lower)"), |
36 | OPT_STRING('r', "routine", &routine, "default", | 36 | OPT_STRING('r', "routine", &routine, "default", |
37 | "Specify routine to copy"), | 37 | "Specify routine to copy"), |
38 | OPT_INTEGER('i', "iterations", &iterations, | 38 | OPT_INTEGER('i', "iterations", &iterations, |
39 | "repeat memcpy() invocation this number of times"), | 39 | "repeat memcpy() invocation this number of times"), |
40 | OPT_BOOLEAN('c', "clock", &use_clock, | 40 | OPT_BOOLEAN('c', "cycle", &use_cycle, |
41 | "Use CPU clock for measuring"), | 41 | "Use cycles event instead of gettimeofday() for measuring"), |
42 | OPT_BOOLEAN('o', "only-prefault", &only_prefault, | 42 | OPT_BOOLEAN('o', "only-prefault", &only_prefault, |
43 | "Show only the result with page faults before memcpy()"), | 43 | "Show only the result with page faults before memcpy()"), |
44 | OPT_BOOLEAN('n', "no-prefault", &no_prefault, | 44 | OPT_BOOLEAN('n', "no-prefault", &no_prefault, |
@@ -76,27 +76,27 @@ static const char * const bench_mem_memcpy_usage[] = { | |||
76 | NULL | 76 | NULL |
77 | }; | 77 | }; |
78 | 78 | ||
79 | static struct perf_event_attr clock_attr = { | 79 | static struct perf_event_attr cycle_attr = { |
80 | .type = PERF_TYPE_HARDWARE, | 80 | .type = PERF_TYPE_HARDWARE, |
81 | .config = PERF_COUNT_HW_CPU_CYCLES | 81 | .config = PERF_COUNT_HW_CPU_CYCLES |
82 | }; | 82 | }; |
83 | 83 | ||
84 | static void init_clock(void) | 84 | static void init_cycle(void) |
85 | { | 85 | { |
86 | clock_fd = sys_perf_event_open(&clock_attr, getpid(), -1, -1, 0); | 86 | cycle_fd = sys_perf_event_open(&cycle_attr, getpid(), -1, -1, 0); |
87 | 87 | ||
88 | if (clock_fd < 0 && errno == ENOSYS) | 88 | if (cycle_fd < 0 && errno == ENOSYS) |
89 | die("No CONFIG_PERF_EVENTS=y kernel support configured?\n"); | 89 | die("No CONFIG_PERF_EVENTS=y kernel support configured?\n"); |
90 | else | 90 | else |
91 | BUG_ON(clock_fd < 0); | 91 | BUG_ON(cycle_fd < 0); |
92 | } | 92 | } |
93 | 93 | ||
94 | static u64 get_clock(void) | 94 | static u64 get_cycle(void) |
95 | { | 95 | { |
96 | int ret; | 96 | int ret; |
97 | u64 clk; | 97 | u64 clk; |
98 | 98 | ||
99 | ret = read(clock_fd, &clk, sizeof(u64)); | 99 | ret = read(cycle_fd, &clk, sizeof(u64)); |
100 | BUG_ON(ret != sizeof(u64)); | 100 | BUG_ON(ret != sizeof(u64)); |
101 | 101 | ||
102 | return clk; | 102 | return clk; |
@@ -119,9 +119,9 @@ static void alloc_mem(void **dst, void **src, size_t length) | |||
119 | die("memory allocation failed - maybe length is too large?\n"); | 119 | die("memory allocation failed - maybe length is too large?\n"); |
120 | } | 120 | } |
121 | 121 | ||
122 | static u64 do_memcpy_clock(memcpy_t fn, size_t len, bool prefault) | 122 | static u64 do_memcpy_cycle(memcpy_t fn, size_t len, bool prefault) |
123 | { | 123 | { |
124 | u64 clock_start = 0ULL, clock_end = 0ULL; | 124 | u64 cycle_start = 0ULL, cycle_end = 0ULL; |
125 | void *src = NULL, *dst = NULL; | 125 | void *src = NULL, *dst = NULL; |
126 | int i; | 126 | int i; |
127 | 127 | ||
@@ -130,14 +130,14 @@ static u64 do_memcpy_clock(memcpy_t fn, size_t len, bool prefault) | |||
130 | if (prefault) | 130 | if (prefault) |
131 | fn(dst, src, len); | 131 | fn(dst, src, len); |
132 | 132 | ||
133 | clock_start = get_clock(); | 133 | cycle_start = get_cycle(); |
134 | for (i = 0; i < iterations; ++i) | 134 | for (i = 0; i < iterations; ++i) |
135 | fn(dst, src, len); | 135 | fn(dst, src, len); |
136 | clock_end = get_clock(); | 136 | cycle_end = get_cycle(); |
137 | 137 | ||
138 | free(src); | 138 | free(src); |
139 | free(dst); | 139 | free(dst); |
140 | return clock_end - clock_start; | 140 | return cycle_end - cycle_start; |
141 | } | 141 | } |
142 | 142 | ||
143 | static double do_memcpy_gettimeofday(memcpy_t fn, size_t len, bool prefault) | 143 | static double do_memcpy_gettimeofday(memcpy_t fn, size_t len, bool prefault) |
@@ -182,17 +182,17 @@ int bench_mem_memcpy(int argc, const char **argv, | |||
182 | int i; | 182 | int i; |
183 | size_t len; | 183 | size_t len; |
184 | double result_bps[2]; | 184 | double result_bps[2]; |
185 | u64 result_clock[2]; | 185 | u64 result_cycle[2]; |
186 | 186 | ||
187 | argc = parse_options(argc, argv, options, | 187 | argc = parse_options(argc, argv, options, |
188 | bench_mem_memcpy_usage, 0); | 188 | bench_mem_memcpy_usage, 0); |
189 | 189 | ||
190 | if (use_clock) | 190 | if (use_cycle) |
191 | init_clock(); | 191 | init_cycle(); |
192 | 192 | ||
193 | len = (size_t)perf_atoll((char *)length_str); | 193 | len = (size_t)perf_atoll((char *)length_str); |
194 | 194 | ||
195 | result_clock[0] = result_clock[1] = 0ULL; | 195 | result_cycle[0] = result_cycle[1] = 0ULL; |
196 | result_bps[0] = result_bps[1] = 0.0; | 196 | result_bps[0] = result_bps[1] = 0.0; |
197 | 197 | ||
198 | if ((s64)len <= 0) { | 198 | if ((s64)len <= 0) { |
@@ -223,11 +223,11 @@ int bench_mem_memcpy(int argc, const char **argv, | |||
223 | 223 | ||
224 | if (!only_prefault && !no_prefault) { | 224 | if (!only_prefault && !no_prefault) { |
225 | /* show both of results */ | 225 | /* show both of results */ |
226 | if (use_clock) { | 226 | if (use_cycle) { |
227 | result_clock[0] = | 227 | result_cycle[0] = |
228 | do_memcpy_clock(routines[i].fn, len, false); | 228 | do_memcpy_cycle(routines[i].fn, len, false); |
229 | result_clock[1] = | 229 | result_cycle[1] = |
230 | do_memcpy_clock(routines[i].fn, len, true); | 230 | do_memcpy_cycle(routines[i].fn, len, true); |
231 | } else { | 231 | } else { |
232 | result_bps[0] = | 232 | result_bps[0] = |
233 | do_memcpy_gettimeofday(routines[i].fn, | 233 | do_memcpy_gettimeofday(routines[i].fn, |
@@ -237,9 +237,9 @@ int bench_mem_memcpy(int argc, const char **argv, | |||
237 | len, true); | 237 | len, true); |
238 | } | 238 | } |
239 | } else { | 239 | } else { |
240 | if (use_clock) { | 240 | if (use_cycle) { |
241 | result_clock[pf] = | 241 | result_cycle[pf] = |
242 | do_memcpy_clock(routines[i].fn, | 242 | do_memcpy_cycle(routines[i].fn, |
243 | len, only_prefault); | 243 | len, only_prefault); |
244 | } else { | 244 | } else { |
245 | result_bps[pf] = | 245 | result_bps[pf] = |
@@ -251,12 +251,12 @@ int bench_mem_memcpy(int argc, const char **argv, | |||
251 | switch (bench_format) { | 251 | switch (bench_format) { |
252 | case BENCH_FORMAT_DEFAULT: | 252 | case BENCH_FORMAT_DEFAULT: |
253 | if (!only_prefault && !no_prefault) { | 253 | if (!only_prefault && !no_prefault) { |
254 | if (use_clock) { | 254 | if (use_cycle) { |
255 | printf(" %14lf Clock/Byte\n", | 255 | printf(" %14lf Cycle/Byte\n", |
256 | (double)result_clock[0] | 256 | (double)result_cycle[0] |
257 | / (double)len); | 257 | / (double)len); |
258 | printf(" %14lf Clock/Byte (with prefault)\n", | 258 | printf(" %14lf Cycle/Byte (with prefault)\n", |
259 | (double)result_clock[1] | 259 | (double)result_cycle[1] |
260 | / (double)len); | 260 | / (double)len); |
261 | } else { | 261 | } else { |
262 | print_bps(result_bps[0]); | 262 | print_bps(result_bps[0]); |
@@ -265,9 +265,9 @@ int bench_mem_memcpy(int argc, const char **argv, | |||
265 | printf(" (with prefault)\n"); | 265 | printf(" (with prefault)\n"); |
266 | } | 266 | } |
267 | } else { | 267 | } else { |
268 | if (use_clock) { | 268 | if (use_cycle) { |
269 | printf(" %14lf Clock/Byte", | 269 | printf(" %14lf Cycle/Byte", |
270 | (double)result_clock[pf] | 270 | (double)result_cycle[pf] |
271 | / (double)len); | 271 | / (double)len); |
272 | } else | 272 | } else |
273 | print_bps(result_bps[pf]); | 273 | print_bps(result_bps[pf]); |
@@ -277,17 +277,17 @@ int bench_mem_memcpy(int argc, const char **argv, | |||
277 | break; | 277 | break; |
278 | case BENCH_FORMAT_SIMPLE: | 278 | case BENCH_FORMAT_SIMPLE: |
279 | if (!only_prefault && !no_prefault) { | 279 | if (!only_prefault && !no_prefault) { |
280 | if (use_clock) { | 280 | if (use_cycle) { |
281 | printf("%lf %lf\n", | 281 | printf("%lf %lf\n", |
282 | (double)result_clock[0] / (double)len, | 282 | (double)result_cycle[0] / (double)len, |
283 | (double)result_clock[1] / (double)len); | 283 | (double)result_cycle[1] / (double)len); |
284 | } else { | 284 | } else { |
285 | printf("%lf %lf\n", | 285 | printf("%lf %lf\n", |
286 | result_bps[0], result_bps[1]); | 286 | result_bps[0], result_bps[1]); |
287 | } | 287 | } |
288 | } else { | 288 | } else { |
289 | if (use_clock) { | 289 | if (use_cycle) { |
290 | printf("%lf\n", (double)result_clock[pf] | 290 | printf("%lf\n", (double)result_cycle[pf] |
291 | / (double)len); | 291 | / (double)len); |
292 | } else | 292 | } else |
293 | printf("%lf\n", result_bps[pf]); | 293 | printf("%lf\n", result_bps[pf]); |
diff --git a/tools/perf/bench/mem-memset.c b/tools/perf/bench/mem-memset.c index e9079185bd72..350cc9557265 100644 --- a/tools/perf/bench/mem-memset.c +++ b/tools/perf/bench/mem-memset.c | |||
@@ -24,21 +24,21 @@ | |||
24 | static const char *length_str = "1MB"; | 24 | static const char *length_str = "1MB"; |
25 | static const char *routine = "default"; | 25 | static const char *routine = "default"; |
26 | static int iterations = 1; | 26 | static int iterations = 1; |
27 | static bool use_clock; | 27 | static bool use_cycle; |
28 | static int clock_fd; | 28 | static int cycle_fd; |
29 | static bool only_prefault; | 29 | static bool only_prefault; |
30 | static bool no_prefault; | 30 | static bool no_prefault; |
31 | 31 | ||
32 | static const struct option options[] = { | 32 | static const struct option options[] = { |
33 | OPT_STRING('l', "length", &length_str, "1MB", | 33 | OPT_STRING('l', "length", &length_str, "1MB", |
34 | "Specify length of memory to copy. " | 34 | "Specify length of memory to set. " |
35 | "available unit: B, MB, GB (upper and lower)"), | 35 | "Available units: B, KB, MB, GB and TB (upper and lower)"), |
36 | OPT_STRING('r', "routine", &routine, "default", | 36 | OPT_STRING('r', "routine", &routine, "default", |
37 | "Specify routine to copy"), | 37 | "Specify routine to set"), |
38 | OPT_INTEGER('i', "iterations", &iterations, | 38 | OPT_INTEGER('i', "iterations", &iterations, |
39 | "repeat memset() invocation this number of times"), | 39 | "repeat memset() invocation this number of times"), |
40 | OPT_BOOLEAN('c', "clock", &use_clock, | 40 | OPT_BOOLEAN('c', "cycle", &use_cycle, |
41 | "Use CPU clock for measuring"), | 41 | "Use cycles event instead of gettimeofday() for measuring"), |
42 | OPT_BOOLEAN('o', "only-prefault", &only_prefault, | 42 | OPT_BOOLEAN('o', "only-prefault", &only_prefault, |
43 | "Show only the result with page faults before memset()"), | 43 | "Show only the result with page faults before memset()"), |
44 | OPT_BOOLEAN('n', "no-prefault", &no_prefault, | 44 | OPT_BOOLEAN('n', "no-prefault", &no_prefault, |
@@ -76,27 +76,27 @@ static const char * const bench_mem_memset_usage[] = { | |||
76 | NULL | 76 | NULL |
77 | }; | 77 | }; |
78 | 78 | ||
79 | static struct perf_event_attr clock_attr = { | 79 | static struct perf_event_attr cycle_attr = { |
80 | .type = PERF_TYPE_HARDWARE, | 80 | .type = PERF_TYPE_HARDWARE, |
81 | .config = PERF_COUNT_HW_CPU_CYCLES | 81 | .config = PERF_COUNT_HW_CPU_CYCLES |
82 | }; | 82 | }; |
83 | 83 | ||
84 | static void init_clock(void) | 84 | static void init_cycle(void) |
85 | { | 85 | { |
86 | clock_fd = sys_perf_event_open(&clock_attr, getpid(), -1, -1, 0); | 86 | cycle_fd = sys_perf_event_open(&cycle_attr, getpid(), -1, -1, 0); |
87 | 87 | ||
88 | if (clock_fd < 0 && errno == ENOSYS) | 88 | if (cycle_fd < 0 && errno == ENOSYS) |
89 | die("No CONFIG_PERF_EVENTS=y kernel support configured?\n"); | 89 | die("No CONFIG_PERF_EVENTS=y kernel support configured?\n"); |
90 | else | 90 | else |
91 | BUG_ON(clock_fd < 0); | 91 | BUG_ON(cycle_fd < 0); |
92 | } | 92 | } |
93 | 93 | ||
94 | static u64 get_clock(void) | 94 | static u64 get_cycle(void) |
95 | { | 95 | { |
96 | int ret; | 96 | int ret; |
97 | u64 clk; | 97 | u64 clk; |
98 | 98 | ||
99 | ret = read(clock_fd, &clk, sizeof(u64)); | 99 | ret = read(cycle_fd, &clk, sizeof(u64)); |
100 | BUG_ON(ret != sizeof(u64)); | 100 | BUG_ON(ret != sizeof(u64)); |
101 | 101 | ||
102 | return clk; | 102 | return clk; |
@@ -115,9 +115,9 @@ static void alloc_mem(void **dst, size_t length) | |||
115 | die("memory allocation failed - maybe length is too large?\n"); | 115 | die("memory allocation failed - maybe length is too large?\n"); |
116 | } | 116 | } |
117 | 117 | ||
118 | static u64 do_memset_clock(memset_t fn, size_t len, bool prefault) | 118 | static u64 do_memset_cycle(memset_t fn, size_t len, bool prefault) |
119 | { | 119 | { |
120 | u64 clock_start = 0ULL, clock_end = 0ULL; | 120 | u64 cycle_start = 0ULL, cycle_end = 0ULL; |
121 | void *dst = NULL; | 121 | void *dst = NULL; |
122 | int i; | 122 | int i; |
123 | 123 | ||
@@ -126,13 +126,13 @@ static u64 do_memset_clock(memset_t fn, size_t len, bool prefault) | |||
126 | if (prefault) | 126 | if (prefault) |
127 | fn(dst, -1, len); | 127 | fn(dst, -1, len); |
128 | 128 | ||
129 | clock_start = get_clock(); | 129 | cycle_start = get_cycle(); |
130 | for (i = 0; i < iterations; ++i) | 130 | for (i = 0; i < iterations; ++i) |
131 | fn(dst, i, len); | 131 | fn(dst, i, len); |
132 | clock_end = get_clock(); | 132 | cycle_end = get_cycle(); |
133 | 133 | ||
134 | free(dst); | 134 | free(dst); |
135 | return clock_end - clock_start; | 135 | return cycle_end - cycle_start; |
136 | } | 136 | } |
137 | 137 | ||
138 | static double do_memset_gettimeofday(memset_t fn, size_t len, bool prefault) | 138 | static double do_memset_gettimeofday(memset_t fn, size_t len, bool prefault) |
@@ -176,17 +176,17 @@ int bench_mem_memset(int argc, const char **argv, | |||
176 | int i; | 176 | int i; |
177 | size_t len; | 177 | size_t len; |
178 | double result_bps[2]; | 178 | double result_bps[2]; |
179 | u64 result_clock[2]; | 179 | u64 result_cycle[2]; |
180 | 180 | ||
181 | argc = parse_options(argc, argv, options, | 181 | argc = parse_options(argc, argv, options, |
182 | bench_mem_memset_usage, 0); | 182 | bench_mem_memset_usage, 0); |
183 | 183 | ||
184 | if (use_clock) | 184 | if (use_cycle) |
185 | init_clock(); | 185 | init_cycle(); |
186 | 186 | ||
187 | len = (size_t)perf_atoll((char *)length_str); | 187 | len = (size_t)perf_atoll((char *)length_str); |
188 | 188 | ||
189 | result_clock[0] = result_clock[1] = 0ULL; | 189 | result_cycle[0] = result_cycle[1] = 0ULL; |
190 | result_bps[0] = result_bps[1] = 0.0; | 190 | result_bps[0] = result_bps[1] = 0.0; |
191 | 191 | ||
192 | if ((s64)len <= 0) { | 192 | if ((s64)len <= 0) { |
@@ -217,11 +217,11 @@ int bench_mem_memset(int argc, const char **argv, | |||
217 | 217 | ||
218 | if (!only_prefault && !no_prefault) { | 218 | if (!only_prefault && !no_prefault) { |
219 | /* show both of results */ | 219 | /* show both of results */ |
220 | if (use_clock) { | 220 | if (use_cycle) { |
221 | result_clock[0] = | 221 | result_cycle[0] = |
222 | do_memset_clock(routines[i].fn, len, false); | 222 | do_memset_cycle(routines[i].fn, len, false); |
223 | result_clock[1] = | 223 | result_cycle[1] = |
224 | do_memset_clock(routines[i].fn, len, true); | 224 | do_memset_cycle(routines[i].fn, len, true); |
225 | } else { | 225 | } else { |
226 | result_bps[0] = | 226 | result_bps[0] = |
227 | do_memset_gettimeofday(routines[i].fn, | 227 | do_memset_gettimeofday(routines[i].fn, |
@@ -231,9 +231,9 @@ int bench_mem_memset(int argc, const char **argv, | |||
231 | len, true); | 231 | len, true); |
232 | } | 232 | } |
233 | } else { | 233 | } else { |
234 | if (use_clock) { | 234 | if (use_cycle) { |
235 | result_clock[pf] = | 235 | result_cycle[pf] = |
236 | do_memset_clock(routines[i].fn, | 236 | do_memset_cycle(routines[i].fn, |
237 | len, only_prefault); | 237 | len, only_prefault); |
238 | } else { | 238 | } else { |
239 | result_bps[pf] = | 239 | result_bps[pf] = |
@@ -245,12 +245,12 @@ int bench_mem_memset(int argc, const char **argv, | |||
245 | switch (bench_format) { | 245 | switch (bench_format) { |
246 | case BENCH_FORMAT_DEFAULT: | 246 | case BENCH_FORMAT_DEFAULT: |
247 | if (!only_prefault && !no_prefault) { | 247 | if (!only_prefault && !no_prefault) { |
248 | if (use_clock) { | 248 | if (use_cycle) { |
249 | printf(" %14lf Clock/Byte\n", | 249 | printf(" %14lf Cycle/Byte\n", |
250 | (double)result_clock[0] | 250 | (double)result_cycle[0] |
251 | / (double)len); | 251 | / (double)len); |
252 | printf(" %14lf Clock/Byte (with prefault)\n ", | 252 | printf(" %14lf Cycle/Byte (with prefault)\n ", |
253 | (double)result_clock[1] | 253 | (double)result_cycle[1] |
254 | / (double)len); | 254 | / (double)len); |
255 | } else { | 255 | } else { |
256 | print_bps(result_bps[0]); | 256 | print_bps(result_bps[0]); |
@@ -259,9 +259,9 @@ int bench_mem_memset(int argc, const char **argv, | |||
259 | printf(" (with prefault)\n"); | 259 | printf(" (with prefault)\n"); |
260 | } | 260 | } |
261 | } else { | 261 | } else { |
262 | if (use_clock) { | 262 | if (use_cycle) { |
263 | printf(" %14lf Clock/Byte", | 263 | printf(" %14lf Cycle/Byte", |
264 | (double)result_clock[pf] | 264 | (double)result_cycle[pf] |
265 | / (double)len); | 265 | / (double)len); |
266 | } else | 266 | } else |
267 | print_bps(result_bps[pf]); | 267 | print_bps(result_bps[pf]); |
@@ -271,17 +271,17 @@ int bench_mem_memset(int argc, const char **argv, | |||
271 | break; | 271 | break; |
272 | case BENCH_FORMAT_SIMPLE: | 272 | case BENCH_FORMAT_SIMPLE: |
273 | if (!only_prefault && !no_prefault) { | 273 | if (!only_prefault && !no_prefault) { |
274 | if (use_clock) { | 274 | if (use_cycle) { |
275 | printf("%lf %lf\n", | 275 | printf("%lf %lf\n", |
276 | (double)result_clock[0] / (double)len, | 276 | (double)result_cycle[0] / (double)len, |
277 | (double)result_clock[1] / (double)len); | 277 | (double)result_cycle[1] / (double)len); |
278 | } else { | 278 | } else { |
279 | printf("%lf %lf\n", | 279 | printf("%lf %lf\n", |
280 | result_bps[0], result_bps[1]); | 280 | result_bps[0], result_bps[1]); |
281 | } | 281 | } |
282 | } else { | 282 | } else { |
283 | if (use_clock) { | 283 | if (use_cycle) { |
284 | printf("%lf\n", (double)result_clock[pf] | 284 | printf("%lf\n", (double)result_cycle[pf] |
285 | / (double)len); | 285 | / (double)len); |
286 | } else | 286 | } else |
287 | printf("%lf\n", result_bps[pf]); | 287 | printf("%lf\n", result_bps[pf]); |
diff --git a/tools/perf/builtin-bench.c b/tools/perf/builtin-bench.c index b0e74ab2d7a2..1f3100216448 100644 --- a/tools/perf/builtin-bench.c +++ b/tools/perf/builtin-bench.c | |||
@@ -33,7 +33,7 @@ struct bench_suite { | |||
33 | }; | 33 | }; |
34 | \ | 34 | \ |
35 | /* sentinel: easy for help */ | 35 | /* sentinel: easy for help */ |
36 | #define suite_all { "all", "test all suite (pseudo suite)", NULL } | 36 | #define suite_all { "all", "Test all benchmark suites", NULL } |
37 | 37 | ||
38 | static struct bench_suite sched_suites[] = { | 38 | static struct bench_suite sched_suites[] = { |
39 | { "messaging", | 39 | { "messaging", |
@@ -75,7 +75,7 @@ static struct bench_subsys subsystems[] = { | |||
75 | "memory access performance", | 75 | "memory access performance", |
76 | mem_suites }, | 76 | mem_suites }, |
77 | { "all", /* sentinel: easy for help */ | 77 | { "all", /* sentinel: easy for help */ |
78 | "test all subsystem (pseudo subsystem)", | 78 | "all benchmark subsystem", |
79 | NULL }, | 79 | NULL }, |
80 | { NULL, | 80 | { NULL, |
81 | NULL, | 81 | NULL, |
diff --git a/tools/perf/builtin-evlist.c b/tools/perf/builtin-evlist.c index acd78dc28341..0dd5a058f766 100644 --- a/tools/perf/builtin-evlist.c +++ b/tools/perf/builtin-evlist.c | |||
@@ -60,7 +60,7 @@ static int __cmd_evlist(const char *input_name, struct perf_attr_details *detail | |||
60 | list_for_each_entry(pos, &session->evlist->entries, node) { | 60 | list_for_each_entry(pos, &session->evlist->entries, node) { |
61 | bool first = true; | 61 | bool first = true; |
62 | 62 | ||
63 | printf("%s", event_name(pos)); | 63 | printf("%s", perf_evsel__name(pos)); |
64 | 64 | ||
65 | if (details->verbose || details->freq) { | 65 | if (details->verbose || details->freq) { |
66 | comma_printf(&first, " sample_freq=%" PRIu64, | 66 | comma_printf(&first, " sample_freq=%" PRIu64, |
diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c index 547af48deb4f..ce35015f2dc6 100644 --- a/tools/perf/builtin-kmem.c +++ b/tools/perf/builtin-kmem.c | |||
@@ -57,6 +57,11 @@ static unsigned long nr_allocs, nr_cross_allocs; | |||
57 | 57 | ||
58 | #define PATH_SYS_NODE "/sys/devices/system/node" | 58 | #define PATH_SYS_NODE "/sys/devices/system/node" |
59 | 59 | ||
60 | struct perf_kmem { | ||
61 | struct perf_tool tool; | ||
62 | struct perf_session *session; | ||
63 | }; | ||
64 | |||
60 | static void init_cpunode_map(void) | 65 | static void init_cpunode_map(void) |
61 | { | 66 | { |
62 | FILE *fp; | 67 | FILE *fp; |
@@ -278,14 +283,16 @@ static void process_free_event(void *data, | |||
278 | s_alloc->alloc_cpu = -1; | 283 | s_alloc->alloc_cpu = -1; |
279 | } | 284 | } |
280 | 285 | ||
281 | static void process_raw_event(union perf_event *raw_event __used, void *data, | 286 | static void process_raw_event(struct perf_tool *tool, |
287 | union perf_event *raw_event __used, void *data, | ||
282 | int cpu, u64 timestamp, struct thread *thread) | 288 | int cpu, u64 timestamp, struct thread *thread) |
283 | { | 289 | { |
290 | struct perf_kmem *kmem = container_of(tool, struct perf_kmem, tool); | ||
284 | struct event_format *event; | 291 | struct event_format *event; |
285 | int type; | 292 | int type; |
286 | 293 | ||
287 | type = trace_parse_common_type(data); | 294 | type = trace_parse_common_type(kmem->session->pevent, data); |
288 | event = trace_find_event(type); | 295 | event = pevent_find_event(kmem->session->pevent, type); |
289 | 296 | ||
290 | if (!strcmp(event->name, "kmalloc") || | 297 | if (!strcmp(event->name, "kmalloc") || |
291 | !strcmp(event->name, "kmem_cache_alloc")) { | 298 | !strcmp(event->name, "kmem_cache_alloc")) { |
@@ -306,7 +313,7 @@ static void process_raw_event(union perf_event *raw_event __used, void *data, | |||
306 | } | 313 | } |
307 | } | 314 | } |
308 | 315 | ||
309 | static int process_sample_event(struct perf_tool *tool __used, | 316 | static int process_sample_event(struct perf_tool *tool, |
310 | union perf_event *event, | 317 | union perf_event *event, |
311 | struct perf_sample *sample, | 318 | struct perf_sample *sample, |
312 | struct perf_evsel *evsel __used, | 319 | struct perf_evsel *evsel __used, |
@@ -322,16 +329,18 @@ static int process_sample_event(struct perf_tool *tool __used, | |||
322 | 329 | ||
323 | dump_printf(" ... thread: %s:%d\n", thread->comm, thread->pid); | 330 | dump_printf(" ... thread: %s:%d\n", thread->comm, thread->pid); |
324 | 331 | ||
325 | process_raw_event(event, sample->raw_data, sample->cpu, | 332 | process_raw_event(tool, event, sample->raw_data, sample->cpu, |
326 | sample->time, thread); | 333 | sample->time, thread); |
327 | 334 | ||
328 | return 0; | 335 | return 0; |
329 | } | 336 | } |
330 | 337 | ||
331 | static struct perf_tool perf_kmem = { | 338 | static struct perf_kmem perf_kmem = { |
332 | .sample = process_sample_event, | 339 | .tool = { |
333 | .comm = perf_event__process_comm, | 340 | .sample = process_sample_event, |
334 | .ordered_samples = true, | 341 | .comm = perf_event__process_comm, |
342 | .ordered_samples = true, | ||
343 | }, | ||
335 | }; | 344 | }; |
336 | 345 | ||
337 | static double fragmentation(unsigned long n_req, unsigned long n_alloc) | 346 | static double fragmentation(unsigned long n_req, unsigned long n_alloc) |
@@ -486,11 +495,15 @@ static void sort_result(void) | |||
486 | static int __cmd_kmem(void) | 495 | static int __cmd_kmem(void) |
487 | { | 496 | { |
488 | int err = -EINVAL; | 497 | int err = -EINVAL; |
489 | struct perf_session *session = perf_session__new(input_name, O_RDONLY, | 498 | struct perf_session *session; |
490 | 0, false, &perf_kmem); | 499 | |
500 | session = perf_session__new(input_name, O_RDONLY, 0, false, | ||
501 | &perf_kmem.tool); | ||
491 | if (session == NULL) | 502 | if (session == NULL) |
492 | return -ENOMEM; | 503 | return -ENOMEM; |
493 | 504 | ||
505 | perf_kmem.session = session; | ||
506 | |||
494 | if (perf_session__create_kernel_maps(session) < 0) | 507 | if (perf_session__create_kernel_maps(session) < 0) |
495 | goto out_delete; | 508 | goto out_delete; |
496 | 509 | ||
@@ -498,7 +511,7 @@ static int __cmd_kmem(void) | |||
498 | goto out_delete; | 511 | goto out_delete; |
499 | 512 | ||
500 | setup_pager(); | 513 | setup_pager(); |
501 | err = perf_session__process_events(session, &perf_kmem); | 514 | err = perf_session__process_events(session, &perf_kmem.tool); |
502 | if (err != 0) | 515 | if (err != 0) |
503 | goto out_delete; | 516 | goto out_delete; |
504 | sort_result(); | 517 | sort_result(); |
diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c index fd53319de20d..b3c428548868 100644 --- a/tools/perf/builtin-lock.c +++ b/tools/perf/builtin-lock.c | |||
@@ -724,8 +724,8 @@ process_raw_event(void *data, int cpu, u64 timestamp, struct thread *thread) | |||
724 | struct event_format *event; | 724 | struct event_format *event; |
725 | int type; | 725 | int type; |
726 | 726 | ||
727 | type = trace_parse_common_type(data); | 727 | type = trace_parse_common_type(session->pevent, data); |
728 | event = trace_find_event(type); | 728 | event = pevent_find_event(session->pevent, type); |
729 | 729 | ||
730 | if (!strcmp(event->name, "lock_acquire")) | 730 | if (!strcmp(event->name, "lock_acquire")) |
731 | process_lock_acquire_event(data, event, cpu, timestamp, thread); | 731 | process_lock_acquire_event(data, event, cpu, timestamp, thread); |
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index f95840d04e4c..f5a6452931e6 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c | |||
@@ -265,7 +265,7 @@ try_again: | |||
265 | 265 | ||
266 | if (err == ENOENT) { | 266 | if (err == ENOENT) { |
267 | ui__error("The %s event is not supported.\n", | 267 | ui__error("The %s event is not supported.\n", |
268 | event_name(pos)); | 268 | perf_evsel__name(pos)); |
269 | exit(EXIT_FAILURE); | 269 | exit(EXIT_FAILURE); |
270 | } | 270 | } |
271 | 271 | ||
@@ -916,7 +916,7 @@ int cmd_record(int argc, const char **argv, const char *prefix __used) | |||
916 | usage_with_options(record_usage, record_options); | 916 | usage_with_options(record_usage, record_options); |
917 | 917 | ||
918 | list_for_each_entry(pos, &evsel_list->entries, node) { | 918 | list_for_each_entry(pos, &evsel_list->entries, node) { |
919 | if (perf_header__push_event(pos->attr.config, event_name(pos))) | 919 | if (perf_header__push_event(pos->attr.config, perf_evsel__name(pos))) |
920 | goto out_free_fd; | 920 | goto out_free_fd; |
921 | } | 921 | } |
922 | 922 | ||
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index 25249f76329d..69b1c1185159 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c | |||
@@ -69,7 +69,7 @@ static int perf_report__add_branch_hist_entry(struct perf_tool *tool, | |||
69 | 69 | ||
70 | if ((sort__has_parent || symbol_conf.use_callchain) | 70 | if ((sort__has_parent || symbol_conf.use_callchain) |
71 | && sample->callchain) { | 71 | && sample->callchain) { |
72 | err = machine__resolve_callchain(machine, evsel, al->thread, | 72 | err = machine__resolve_callchain(machine, al->thread, |
73 | sample->callchain, &parent); | 73 | sample->callchain, &parent); |
74 | if (err) | 74 | if (err) |
75 | return err; | 75 | return err; |
@@ -140,7 +140,7 @@ static int perf_evsel__add_hist_entry(struct perf_evsel *evsel, | |||
140 | struct hist_entry *he; | 140 | struct hist_entry *he; |
141 | 141 | ||
142 | if ((sort__has_parent || symbol_conf.use_callchain) && sample->callchain) { | 142 | if ((sort__has_parent || symbol_conf.use_callchain) && sample->callchain) { |
143 | err = machine__resolve_callchain(machine, evsel, al->thread, | 143 | err = machine__resolve_callchain(machine, al->thread, |
144 | sample->callchain, &parent); | 144 | sample->callchain, &parent); |
145 | if (err) | 145 | if (err) |
146 | return err; | 146 | return err; |
@@ -230,7 +230,7 @@ static int process_read_event(struct perf_tool *tool, | |||
230 | struct perf_report *rep = container_of(tool, struct perf_report, tool); | 230 | struct perf_report *rep = container_of(tool, struct perf_report, tool); |
231 | 231 | ||
232 | if (rep->show_threads) { | 232 | if (rep->show_threads) { |
233 | const char *name = evsel ? event_name(evsel) : "unknown"; | 233 | const char *name = evsel ? perf_evsel__name(evsel) : "unknown"; |
234 | perf_read_values_add_value(&rep->show_threads_values, | 234 | perf_read_values_add_value(&rep->show_threads_values, |
235 | event->read.pid, event->read.tid, | 235 | event->read.pid, event->read.tid, |
236 | event->read.id, | 236 | event->read.id, |
@@ -239,17 +239,18 @@ static int process_read_event(struct perf_tool *tool, | |||
239 | } | 239 | } |
240 | 240 | ||
241 | dump_printf(": %d %d %s %" PRIu64 "\n", event->read.pid, event->read.tid, | 241 | dump_printf(": %d %d %s %" PRIu64 "\n", event->read.pid, event->read.tid, |
242 | evsel ? event_name(evsel) : "FAIL", | 242 | evsel ? perf_evsel__name(evsel) : "FAIL", |
243 | event->read.value); | 243 | event->read.value); |
244 | 244 | ||
245 | return 0; | 245 | return 0; |
246 | } | 246 | } |
247 | 247 | ||
248 | /* For pipe mode, sample_type is not currently set */ | ||
248 | static int perf_report__setup_sample_type(struct perf_report *rep) | 249 | static int perf_report__setup_sample_type(struct perf_report *rep) |
249 | { | 250 | { |
250 | struct perf_session *self = rep->session; | 251 | struct perf_session *self = rep->session; |
251 | 252 | ||
252 | if (!(self->sample_type & PERF_SAMPLE_CALLCHAIN)) { | 253 | if (!self->fd_pipe && !(self->sample_type & PERF_SAMPLE_CALLCHAIN)) { |
253 | if (sort__has_parent) { | 254 | if (sort__has_parent) { |
254 | ui__error("Selected --sort parent, but no " | 255 | ui__error("Selected --sort parent, but no " |
255 | "callchain data. Did you call " | 256 | "callchain data. Did you call " |
@@ -272,7 +273,8 @@ static int perf_report__setup_sample_type(struct perf_report *rep) | |||
272 | } | 273 | } |
273 | 274 | ||
274 | if (sort__branch_mode == 1) { | 275 | if (sort__branch_mode == 1) { |
275 | if (!(self->sample_type & PERF_SAMPLE_BRANCH_STACK)) { | 276 | if (!self->fd_pipe && |
277 | !(self->sample_type & PERF_SAMPLE_BRANCH_STACK)) { | ||
276 | ui__error("Selected -b but no branch data. " | 278 | ui__error("Selected -b but no branch data. " |
277 | "Did you call perf record without -b?\n"); | 279 | "Did you call perf record without -b?\n"); |
278 | return -1; | 280 | return -1; |
@@ -314,7 +316,7 @@ static int perf_evlist__tty_browse_hists(struct perf_evlist *evlist, | |||
314 | 316 | ||
315 | list_for_each_entry(pos, &evlist->entries, node) { | 317 | list_for_each_entry(pos, &evlist->entries, node) { |
316 | struct hists *hists = &pos->hists; | 318 | struct hists *hists = &pos->hists; |
317 | const char *evname = event_name(pos); | 319 | const char *evname = perf_evsel__name(pos); |
318 | 320 | ||
319 | hists__fprintf_nr_sample_events(hists, evname, stdout); | 321 | hists__fprintf_nr_sample_events(hists, evname, stdout); |
320 | hists__fprintf(hists, NULL, false, true, 0, 0, stdout); | 322 | hists__fprintf(hists, NULL, false, true, 0, 0, stdout); |
diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c index b125e07eb399..7a9ad2b1ee76 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c | |||
@@ -43,6 +43,11 @@ static u64 sleep_measurement_overhead; | |||
43 | 43 | ||
44 | static unsigned long nr_tasks; | 44 | static unsigned long nr_tasks; |
45 | 45 | ||
46 | struct perf_sched { | ||
47 | struct perf_tool tool; | ||
48 | struct perf_session *session; | ||
49 | }; | ||
50 | |||
46 | struct sched_atom; | 51 | struct sched_atom; |
47 | 52 | ||
48 | struct task_desc { | 53 | struct task_desc { |
@@ -1597,11 +1602,13 @@ static int perf_sched__process_tracepoint_sample(struct perf_tool *tool, | |||
1597 | struct perf_evsel *evsel, | 1602 | struct perf_evsel *evsel, |
1598 | struct machine *machine) | 1603 | struct machine *machine) |
1599 | { | 1604 | { |
1605 | struct perf_sched *sched = container_of(tool, struct perf_sched, tool); | ||
1606 | struct pevent *pevent = sched->session->pevent; | ||
1600 | struct thread *thread = machine__findnew_thread(machine, sample->pid); | 1607 | struct thread *thread = machine__findnew_thread(machine, sample->pid); |
1601 | 1608 | ||
1602 | if (thread == NULL) { | 1609 | if (thread == NULL) { |
1603 | pr_debug("problem processing %s event, skipping it.\n", | 1610 | pr_debug("problem processing %s event, skipping it.\n", |
1604 | evsel->name); | 1611 | perf_evsel__name(evsel)); |
1605 | return -1; | 1612 | return -1; |
1606 | } | 1613 | } |
1607 | 1614 | ||
@@ -1612,7 +1619,8 @@ static int perf_sched__process_tracepoint_sample(struct perf_tool *tool, | |||
1612 | tracepoint_handler f = evsel->handler.func; | 1619 | tracepoint_handler f = evsel->handler.func; |
1613 | 1620 | ||
1614 | if (evsel->handler.data == NULL) | 1621 | if (evsel->handler.data == NULL) |
1615 | evsel->handler.data = trace_find_event(evsel->attr.config); | 1622 | evsel->handler.data = pevent_find_event(pevent, |
1623 | evsel->attr.config); | ||
1616 | 1624 | ||
1617 | f(tool, evsel->handler.data, sample, machine, thread); | 1625 | f(tool, evsel->handler.data, sample, machine, thread); |
1618 | } | 1626 | } |
@@ -1620,12 +1628,14 @@ static int perf_sched__process_tracepoint_sample(struct perf_tool *tool, | |||
1620 | return 0; | 1628 | return 0; |
1621 | } | 1629 | } |
1622 | 1630 | ||
1623 | static struct perf_tool perf_sched = { | 1631 | static struct perf_sched perf_sched = { |
1624 | .sample = perf_sched__process_tracepoint_sample, | 1632 | .tool = { |
1625 | .comm = perf_event__process_comm, | 1633 | .sample = perf_sched__process_tracepoint_sample, |
1626 | .lost = perf_event__process_lost, | 1634 | .comm = perf_event__process_comm, |
1627 | .fork = perf_event__process_task, | 1635 | .lost = perf_event__process_lost, |
1628 | .ordered_samples = true, | 1636 | .fork = perf_event__process_task, |
1637 | .ordered_samples = true, | ||
1638 | }, | ||
1629 | }; | 1639 | }; |
1630 | 1640 | ||
1631 | static void read_events(bool destroy, struct perf_session **psession) | 1641 | static void read_events(bool destroy, struct perf_session **psession) |
@@ -1640,16 +1650,20 @@ static void read_events(bool destroy, struct perf_session **psession) | |||
1640 | { "sched:sched_process_exit", process_sched_exit_event, }, | 1650 | { "sched:sched_process_exit", process_sched_exit_event, }, |
1641 | { "sched:sched_migrate_task", process_sched_migrate_task_event, }, | 1651 | { "sched:sched_migrate_task", process_sched_migrate_task_event, }, |
1642 | }; | 1652 | }; |
1643 | struct perf_session *session = perf_session__new(input_name, O_RDONLY, | 1653 | struct perf_session *session; |
1644 | 0, false, &perf_sched); | 1654 | |
1655 | session = perf_session__new(input_name, O_RDONLY, 0, false, | ||
1656 | &perf_sched.tool); | ||
1645 | if (session == NULL) | 1657 | if (session == NULL) |
1646 | die("No Memory"); | 1658 | die("No Memory"); |
1647 | 1659 | ||
1648 | err = perf_evlist__set_tracepoints_handlers_array(session->evlist, handlers); | 1660 | perf_sched.session = session; |
1661 | |||
1662 | err = perf_session__set_tracepoints_handlers(session, handlers); | ||
1649 | assert(err == 0); | 1663 | assert(err == 0); |
1650 | 1664 | ||
1651 | if (perf_session__has_traces(session, "record -R")) { | 1665 | if (perf_session__has_traces(session, "record -R")) { |
1652 | err = perf_session__process_events(session, &perf_sched); | 1666 | err = perf_session__process_events(session, &perf_sched.tool); |
1653 | if (err) | 1667 | if (err) |
1654 | die("Failed to process events, error %d", err); | 1668 | die("Failed to process events, error %d", err); |
1655 | 1669 | ||
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 8e395a538eb9..1e60ab70b2b1 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c | |||
@@ -28,6 +28,11 @@ static bool system_wide; | |||
28 | static const char *cpu_list; | 28 | static const char *cpu_list; |
29 | static DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS); | 29 | static DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS); |
30 | 30 | ||
31 | struct perf_script { | ||
32 | struct perf_tool tool; | ||
33 | struct perf_session *session; | ||
34 | }; | ||
35 | |||
31 | enum perf_output_field { | 36 | enum perf_output_field { |
32 | PERF_OUTPUT_COMM = 1U << 0, | 37 | PERF_OUTPUT_COMM = 1U << 0, |
33 | PERF_OUTPUT_TID = 1U << 1, | 38 | PERF_OUTPUT_TID = 1U << 1, |
@@ -137,10 +142,11 @@ static const char *output_field2str(enum perf_output_field field) | |||
137 | 142 | ||
138 | #define PRINT_FIELD(x) (output[attr->type].fields & PERF_OUTPUT_##x) | 143 | #define PRINT_FIELD(x) (output[attr->type].fields & PERF_OUTPUT_##x) |
139 | 144 | ||
140 | static int perf_event_attr__check_stype(struct perf_event_attr *attr, | 145 | static int perf_evsel__check_stype(struct perf_evsel *evsel, |
141 | u64 sample_type, const char *sample_msg, | 146 | u64 sample_type, const char *sample_msg, |
142 | enum perf_output_field field) | 147 | enum perf_output_field field) |
143 | { | 148 | { |
149 | struct perf_event_attr *attr = &evsel->attr; | ||
144 | int type = attr->type; | 150 | int type = attr->type; |
145 | const char *evname; | 151 | const char *evname; |
146 | 152 | ||
@@ -148,7 +154,7 @@ static int perf_event_attr__check_stype(struct perf_event_attr *attr, | |||
148 | return 0; | 154 | return 0; |
149 | 155 | ||
150 | if (output[type].user_set) { | 156 | if (output[type].user_set) { |
151 | evname = __event_name(attr->type, attr->config); | 157 | evname = perf_evsel__name(evsel); |
152 | pr_err("Samples for '%s' event do not have %s attribute set. " | 158 | pr_err("Samples for '%s' event do not have %s attribute set. " |
153 | "Cannot print '%s' field.\n", | 159 | "Cannot print '%s' field.\n", |
154 | evname, sample_msg, output_field2str(field)); | 160 | evname, sample_msg, output_field2str(field)); |
@@ -157,7 +163,7 @@ static int perf_event_attr__check_stype(struct perf_event_attr *attr, | |||
157 | 163 | ||
158 | /* user did not ask for it explicitly so remove from the default list */ | 164 | /* user did not ask for it explicitly so remove from the default list */ |
159 | output[type].fields &= ~field; | 165 | output[type].fields &= ~field; |
160 | evname = __event_name(attr->type, attr->config); | 166 | evname = perf_evsel__name(evsel); |
161 | pr_debug("Samples for '%s' event do not have %s attribute set. " | 167 | pr_debug("Samples for '%s' event do not have %s attribute set. " |
162 | "Skipping '%s' field.\n", | 168 | "Skipping '%s' field.\n", |
163 | evname, sample_msg, output_field2str(field)); | 169 | evname, sample_msg, output_field2str(field)); |
@@ -175,8 +181,8 @@ static int perf_evsel__check_attr(struct perf_evsel *evsel, | |||
175 | return -EINVAL; | 181 | return -EINVAL; |
176 | 182 | ||
177 | if (PRINT_FIELD(IP)) { | 183 | if (PRINT_FIELD(IP)) { |
178 | if (perf_event_attr__check_stype(attr, PERF_SAMPLE_IP, "IP", | 184 | if (perf_evsel__check_stype(evsel, PERF_SAMPLE_IP, "IP", |
179 | PERF_OUTPUT_IP)) | 185 | PERF_OUTPUT_IP)) |
180 | return -EINVAL; | 186 | return -EINVAL; |
181 | 187 | ||
182 | if (!no_callchain && | 188 | if (!no_callchain && |
@@ -185,8 +191,8 @@ static int perf_evsel__check_attr(struct perf_evsel *evsel, | |||
185 | } | 191 | } |
186 | 192 | ||
187 | if (PRINT_FIELD(ADDR) && | 193 | if (PRINT_FIELD(ADDR) && |
188 | perf_event_attr__check_stype(attr, PERF_SAMPLE_ADDR, "ADDR", | 194 | perf_evsel__check_stype(evsel, PERF_SAMPLE_ADDR, "ADDR", |
189 | PERF_OUTPUT_ADDR)) | 195 | PERF_OUTPUT_ADDR)) |
190 | return -EINVAL; | 196 | return -EINVAL; |
191 | 197 | ||
192 | if (PRINT_FIELD(SYM) && !PRINT_FIELD(IP) && !PRINT_FIELD(ADDR)) { | 198 | if (PRINT_FIELD(SYM) && !PRINT_FIELD(IP) && !PRINT_FIELD(ADDR)) { |
@@ -208,18 +214,18 @@ static int perf_evsel__check_attr(struct perf_evsel *evsel, | |||
208 | } | 214 | } |
209 | 215 | ||
210 | if ((PRINT_FIELD(PID) || PRINT_FIELD(TID)) && | 216 | if ((PRINT_FIELD(PID) || PRINT_FIELD(TID)) && |
211 | perf_event_attr__check_stype(attr, PERF_SAMPLE_TID, "TID", | 217 | perf_evsel__check_stype(evsel, PERF_SAMPLE_TID, "TID", |
212 | PERF_OUTPUT_TID|PERF_OUTPUT_PID)) | 218 | PERF_OUTPUT_TID|PERF_OUTPUT_PID)) |
213 | return -EINVAL; | 219 | return -EINVAL; |
214 | 220 | ||
215 | if (PRINT_FIELD(TIME) && | 221 | if (PRINT_FIELD(TIME) && |
216 | perf_event_attr__check_stype(attr, PERF_SAMPLE_TIME, "TIME", | 222 | perf_evsel__check_stype(evsel, PERF_SAMPLE_TIME, "TIME", |
217 | PERF_OUTPUT_TIME)) | 223 | PERF_OUTPUT_TIME)) |
218 | return -EINVAL; | 224 | return -EINVAL; |
219 | 225 | ||
220 | if (PRINT_FIELD(CPU) && | 226 | if (PRINT_FIELD(CPU) && |
221 | perf_event_attr__check_stype(attr, PERF_SAMPLE_CPU, "CPU", | 227 | perf_evsel__check_stype(evsel, PERF_SAMPLE_CPU, "CPU", |
222 | PERF_OUTPUT_CPU)) | 228 | PERF_OUTPUT_CPU)) |
223 | return -EINVAL; | 229 | return -EINVAL; |
224 | 230 | ||
225 | return 0; | 231 | return 0; |
@@ -256,11 +262,13 @@ static int perf_session__check_output_opt(struct perf_session *session) | |||
256 | return 0; | 262 | return 0; |
257 | } | 263 | } |
258 | 264 | ||
259 | static void print_sample_start(struct perf_sample *sample, | 265 | static void print_sample_start(struct pevent *pevent, |
266 | struct perf_sample *sample, | ||
260 | struct thread *thread, | 267 | struct thread *thread, |
261 | struct perf_event_attr *attr) | 268 | struct perf_evsel *evsel) |
262 | { | 269 | { |
263 | int type; | 270 | int type; |
271 | struct perf_event_attr *attr = &evsel->attr; | ||
264 | struct event_format *event; | 272 | struct event_format *event; |
265 | const char *evname = NULL; | 273 | const char *evname = NULL; |
266 | unsigned long secs; | 274 | unsigned long secs; |
@@ -300,12 +308,18 @@ static void print_sample_start(struct perf_sample *sample, | |||
300 | 308 | ||
301 | if (PRINT_FIELD(EVNAME)) { | 309 | if (PRINT_FIELD(EVNAME)) { |
302 | if (attr->type == PERF_TYPE_TRACEPOINT) { | 310 | if (attr->type == PERF_TYPE_TRACEPOINT) { |
303 | type = trace_parse_common_type(sample->raw_data); | 311 | /* |
304 | event = trace_find_event(type); | 312 | * XXX Do we really need this here? |
313 | * perf_evlist__set_tracepoint_names should have done | ||
314 | * this already | ||
315 | */ | ||
316 | type = trace_parse_common_type(pevent, | ||
317 | sample->raw_data); | ||
318 | event = pevent_find_event(pevent, type); | ||
305 | if (event) | 319 | if (event) |
306 | evname = event->name; | 320 | evname = event->name; |
307 | } else | 321 | } else |
308 | evname = __event_name(attr->type, attr->config); | 322 | evname = perf_evsel__name(evsel); |
309 | 323 | ||
310 | printf("%s: ", evname ? evname : "[unknown]"); | 324 | printf("%s: ", evname ? evname : "[unknown]"); |
311 | } | 325 | } |
@@ -387,7 +401,7 @@ static void print_sample_bts(union perf_event *event, | |||
387 | printf(" "); | 401 | printf(" "); |
388 | else | 402 | else |
389 | printf("\n"); | 403 | printf("\n"); |
390 | perf_event__print_ip(event, sample, machine, evsel, | 404 | perf_event__print_ip(event, sample, machine, |
391 | PRINT_FIELD(SYM), PRINT_FIELD(DSO), | 405 | PRINT_FIELD(SYM), PRINT_FIELD(DSO), |
392 | PRINT_FIELD(SYMOFFSET)); | 406 | PRINT_FIELD(SYMOFFSET)); |
393 | } | 407 | } |
@@ -402,6 +416,7 @@ static void print_sample_bts(union perf_event *event, | |||
402 | } | 416 | } |
403 | 417 | ||
404 | static void process_event(union perf_event *event __unused, | 418 | static void process_event(union perf_event *event __unused, |
419 | struct pevent *pevent, | ||
405 | struct perf_sample *sample, | 420 | struct perf_sample *sample, |
406 | struct perf_evsel *evsel, | 421 | struct perf_evsel *evsel, |
407 | struct machine *machine, | 422 | struct machine *machine, |
@@ -412,7 +427,7 @@ static void process_event(union perf_event *event __unused, | |||
412 | if (output[attr->type].fields == 0) | 427 | if (output[attr->type].fields == 0) |
413 | return; | 428 | return; |
414 | 429 | ||
415 | print_sample_start(sample, thread, attr); | 430 | print_sample_start(pevent, sample, thread, evsel); |
416 | 431 | ||
417 | if (is_bts_event(attr)) { | 432 | if (is_bts_event(attr)) { |
418 | print_sample_bts(event, sample, evsel, machine, thread); | 433 | print_sample_bts(event, sample, evsel, machine, thread); |
@@ -420,7 +435,7 @@ static void process_event(union perf_event *event __unused, | |||
420 | } | 435 | } |
421 | 436 | ||
422 | if (PRINT_FIELD(TRACE)) | 437 | if (PRINT_FIELD(TRACE)) |
423 | print_trace_event(sample->cpu, sample->raw_data, | 438 | print_trace_event(pevent, sample->cpu, sample->raw_data, |
424 | sample->raw_size); | 439 | sample->raw_size); |
425 | 440 | ||
426 | if (PRINT_FIELD(ADDR)) | 441 | if (PRINT_FIELD(ADDR)) |
@@ -431,7 +446,7 @@ static void process_event(union perf_event *event __unused, | |||
431 | printf(" "); | 446 | printf(" "); |
432 | else | 447 | else |
433 | printf("\n"); | 448 | printf("\n"); |
434 | perf_event__print_ip(event, sample, machine, evsel, | 449 | perf_event__print_ip(event, sample, machine, |
435 | PRINT_FIELD(SYM), PRINT_FIELD(DSO), | 450 | PRINT_FIELD(SYM), PRINT_FIELD(DSO), |
436 | PRINT_FIELD(SYMOFFSET)); | 451 | PRINT_FIELD(SYMOFFSET)); |
437 | } | 452 | } |
@@ -451,7 +466,8 @@ static int default_stop_script(void) | |||
451 | return 0; | 466 | return 0; |
452 | } | 467 | } |
453 | 468 | ||
454 | static int default_generate_script(const char *outfile __unused) | 469 | static int default_generate_script(struct pevent *pevent __unused, |
470 | const char *outfile __unused) | ||
455 | { | 471 | { |
456 | return 0; | 472 | return 0; |
457 | } | 473 | } |
@@ -489,6 +505,7 @@ static int process_sample_event(struct perf_tool *tool __used, | |||
489 | struct machine *machine) | 505 | struct machine *machine) |
490 | { | 506 | { |
491 | struct addr_location al; | 507 | struct addr_location al; |
508 | struct perf_script *scr = container_of(tool, struct perf_script, tool); | ||
492 | struct thread *thread = machine__findnew_thread(machine, event->ip.tid); | 509 | struct thread *thread = machine__findnew_thread(machine, event->ip.tid); |
493 | 510 | ||
494 | if (thread == NULL) { | 511 | if (thread == NULL) { |
@@ -520,24 +537,27 @@ static int process_sample_event(struct perf_tool *tool __used, | |||
520 | if (cpu_list && !test_bit(sample->cpu, cpu_bitmap)) | 537 | if (cpu_list && !test_bit(sample->cpu, cpu_bitmap)) |
521 | return 0; | 538 | return 0; |
522 | 539 | ||
523 | scripting_ops->process_event(event, sample, evsel, machine, thread); | 540 | scripting_ops->process_event(event, scr->session->pevent, |
541 | sample, evsel, machine, thread); | ||
524 | 542 | ||
525 | evsel->hists.stats.total_period += sample->period; | 543 | evsel->hists.stats.total_period += sample->period; |
526 | return 0; | 544 | return 0; |
527 | } | 545 | } |
528 | 546 | ||
529 | static struct perf_tool perf_script = { | 547 | static struct perf_script perf_script = { |
530 | .sample = process_sample_event, | 548 | .tool = { |
531 | .mmap = perf_event__process_mmap, | 549 | .sample = process_sample_event, |
532 | .comm = perf_event__process_comm, | 550 | .mmap = perf_event__process_mmap, |
533 | .exit = perf_event__process_task, | 551 | .comm = perf_event__process_comm, |
534 | .fork = perf_event__process_task, | 552 | .exit = perf_event__process_task, |
535 | .attr = perf_event__process_attr, | 553 | .fork = perf_event__process_task, |
536 | .event_type = perf_event__process_event_type, | 554 | .attr = perf_event__process_attr, |
537 | .tracing_data = perf_event__process_tracing_data, | 555 | .event_type = perf_event__process_event_type, |
538 | .build_id = perf_event__process_build_id, | 556 | .tracing_data = perf_event__process_tracing_data, |
539 | .ordered_samples = true, | 557 | .build_id = perf_event__process_build_id, |
540 | .ordering_requires_timestamps = true, | 558 | .ordered_samples = true, |
559 | .ordering_requires_timestamps = true, | ||
560 | }, | ||
541 | }; | 561 | }; |
542 | 562 | ||
543 | extern volatile int session_done; | 563 | extern volatile int session_done; |
@@ -553,7 +573,7 @@ static int __cmd_script(struct perf_session *session) | |||
553 | 573 | ||
554 | signal(SIGINT, sig_handler); | 574 | signal(SIGINT, sig_handler); |
555 | 575 | ||
556 | ret = perf_session__process_events(session, &perf_script); | 576 | ret = perf_session__process_events(session, &perf_script.tool); |
557 | 577 | ||
558 | if (debug_mode) | 578 | if (debug_mode) |
559 | pr_err("Misordered timestamps: %" PRIu64 "\n", nr_unordered); | 579 | pr_err("Misordered timestamps: %" PRIu64 "\n", nr_unordered); |
@@ -1335,10 +1355,13 @@ int cmd_script(int argc, const char **argv, const char *prefix __used) | |||
1335 | if (!script_name) | 1355 | if (!script_name) |
1336 | setup_pager(); | 1356 | setup_pager(); |
1337 | 1357 | ||
1338 | session = perf_session__new(input_name, O_RDONLY, 0, false, &perf_script); | 1358 | session = perf_session__new(input_name, O_RDONLY, 0, false, |
1359 | &perf_script.tool); | ||
1339 | if (session == NULL) | 1360 | if (session == NULL) |
1340 | return -ENOMEM; | 1361 | return -ENOMEM; |
1341 | 1362 | ||
1363 | perf_script.session = session; | ||
1364 | |||
1342 | if (cpu_list) { | 1365 | if (cpu_list) { |
1343 | if (perf_session__cpu_bitmap(session, cpu_list, cpu_bitmap)) | 1366 | if (perf_session__cpu_bitmap(session, cpu_list, cpu_bitmap)) |
1344 | return -1; | 1367 | return -1; |
@@ -1384,7 +1407,8 @@ int cmd_script(int argc, const char **argv, const char *prefix __used) | |||
1384 | return -1; | 1407 | return -1; |
1385 | } | 1408 | } |
1386 | 1409 | ||
1387 | err = scripting_ops->generate_script("perf-script"); | 1410 | err = scripting_ops->generate_script(session->pevent, |
1411 | "perf-script"); | ||
1388 | goto out; | 1412 | goto out; |
1389 | } | 1413 | } |
1390 | 1414 | ||
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 262589991ea4..861f0aec77ae 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c | |||
@@ -391,7 +391,7 @@ static int read_counter_aggr(struct perf_evsel *counter) | |||
391 | 391 | ||
392 | if (verbose) { | 392 | if (verbose) { |
393 | fprintf(output, "%s: %" PRIu64 " %" PRIu64 " %" PRIu64 "\n", | 393 | fprintf(output, "%s: %" PRIu64 " %" PRIu64 " %" PRIu64 "\n", |
394 | event_name(counter), count[0], count[1], count[2]); | 394 | perf_evsel__name(counter), count[0], count[1], count[2]); |
395 | } | 395 | } |
396 | 396 | ||
397 | /* | 397 | /* |
@@ -496,7 +496,7 @@ static int run_perf_stat(int argc __used, const char **argv) | |||
496 | errno == ENXIO) { | 496 | errno == ENXIO) { |
497 | if (verbose) | 497 | if (verbose) |
498 | ui__warning("%s event is not supported by the kernel.\n", | 498 | ui__warning("%s event is not supported by the kernel.\n", |
499 | event_name(counter)); | 499 | perf_evsel__name(counter)); |
500 | counter->supported = false; | 500 | counter->supported = false; |
501 | continue; | 501 | continue; |
502 | } | 502 | } |
@@ -594,7 +594,7 @@ static void nsec_printout(int cpu, struct perf_evsel *evsel, double avg) | |||
594 | csv_output ? 0 : -4, | 594 | csv_output ? 0 : -4, |
595 | evsel_list->cpus->map[cpu], csv_sep); | 595 | evsel_list->cpus->map[cpu], csv_sep); |
596 | 596 | ||
597 | fprintf(output, fmt, cpustr, msecs, csv_sep, event_name(evsel)); | 597 | fprintf(output, fmt, cpustr, msecs, csv_sep, perf_evsel__name(evsel)); |
598 | 598 | ||
599 | if (evsel->cgrp) | 599 | if (evsel->cgrp) |
600 | fprintf(output, "%s%s", csv_sep, evsel->cgrp->name); | 600 | fprintf(output, "%s%s", csv_sep, evsel->cgrp->name); |
@@ -792,7 +792,7 @@ static void abs_printout(int cpu, struct perf_evsel *evsel, double avg) | |||
792 | else | 792 | else |
793 | cpu = 0; | 793 | cpu = 0; |
794 | 794 | ||
795 | fprintf(output, fmt, cpustr, avg, csv_sep, event_name(evsel)); | 795 | fprintf(output, fmt, cpustr, avg, csv_sep, perf_evsel__name(evsel)); |
796 | 796 | ||
797 | if (evsel->cgrp) | 797 | if (evsel->cgrp) |
798 | fprintf(output, "%s%s", csv_sep, evsel->cgrp->name); | 798 | fprintf(output, "%s%s", csv_sep, evsel->cgrp->name); |
@@ -908,7 +908,7 @@ static void print_counter_aggr(struct perf_evsel *counter) | |||
908 | counter->supported ? CNTR_NOT_COUNTED : CNTR_NOT_SUPPORTED, | 908 | counter->supported ? CNTR_NOT_COUNTED : CNTR_NOT_SUPPORTED, |
909 | csv_sep, | 909 | csv_sep, |
910 | csv_output ? 0 : -24, | 910 | csv_output ? 0 : -24, |
911 | event_name(counter)); | 911 | perf_evsel__name(counter)); |
912 | 912 | ||
913 | if (counter->cgrp) | 913 | if (counter->cgrp) |
914 | fprintf(output, "%s%s", csv_sep, counter->cgrp->name); | 914 | fprintf(output, "%s%s", csv_sep, counter->cgrp->name); |
@@ -961,7 +961,7 @@ static void print_counter(struct perf_evsel *counter) | |||
961 | counter->supported ? CNTR_NOT_COUNTED : CNTR_NOT_SUPPORTED, | 961 | counter->supported ? CNTR_NOT_COUNTED : CNTR_NOT_SUPPORTED, |
962 | csv_sep, | 962 | csv_sep, |
963 | csv_output ? 0 : -24, | 963 | csv_output ? 0 : -24, |
964 | event_name(counter)); | 964 | perf_evsel__name(counter)); |
965 | 965 | ||
966 | if (counter->cgrp) | 966 | if (counter->cgrp) |
967 | fprintf(output, "%s%s", | 967 | fprintf(output, "%s%s", |
@@ -1179,6 +1179,12 @@ int cmd_stat(int argc, const char **argv, const char *prefix __used) | |||
1179 | fprintf(stderr, "cannot use both --output and --log-fd\n"); | 1179 | fprintf(stderr, "cannot use both --output and --log-fd\n"); |
1180 | usage_with_options(stat_usage, options); | 1180 | usage_with_options(stat_usage, options); |
1181 | } | 1181 | } |
1182 | |||
1183 | if (output_fd < 0) { | ||
1184 | fprintf(stderr, "argument to --log-fd must be a > 0\n"); | ||
1185 | usage_with_options(stat_usage, options); | ||
1186 | } | ||
1187 | |||
1182 | if (!output) { | 1188 | if (!output) { |
1183 | struct timespec tm; | 1189 | struct timespec tm; |
1184 | mode = append_file ? "a" : "w"; | 1190 | mode = append_file ? "a" : "w"; |
@@ -1190,7 +1196,7 @@ int cmd_stat(int argc, const char **argv, const char *prefix __used) | |||
1190 | } | 1196 | } |
1191 | clock_gettime(CLOCK_REALTIME, &tm); | 1197 | clock_gettime(CLOCK_REALTIME, &tm); |
1192 | fprintf(output, "# started on %s\n", ctime(&tm.tv_sec)); | 1198 | fprintf(output, "# started on %s\n", ctime(&tm.tv_sec)); |
1193 | } else if (output_fd != 2) { | 1199 | } else if (output_fd > 0) { |
1194 | mode = append_file ? "a" : "w"; | 1200 | mode = append_file ? "a" : "w"; |
1195 | output = fdopen(output_fd, mode); | 1201 | output = fdopen(output_fd, mode); |
1196 | if (!output) { | 1202 | if (!output) { |
diff --git a/tools/perf/builtin-test.c b/tools/perf/builtin-test.c index 5a8727c08757..d909eb74a0eb 100644 --- a/tools/perf/builtin-test.c +++ b/tools/perf/builtin-test.c | |||
@@ -583,7 +583,7 @@ static int test__basic_mmap(void) | |||
583 | if (nr_events[evsel->idx] != expected_nr_events[evsel->idx]) { | 583 | if (nr_events[evsel->idx] != expected_nr_events[evsel->idx]) { |
584 | pr_debug("expected %d %s events, got %d\n", | 584 | pr_debug("expected %d %s events, got %d\n", |
585 | expected_nr_events[evsel->idx], | 585 | expected_nr_events[evsel->idx], |
586 | event_name(evsel), nr_events[evsel->idx]); | 586 | perf_evsel__name(evsel), nr_events[evsel->idx]); |
587 | goto out_munmap; | 587 | goto out_munmap; |
588 | } | 588 | } |
589 | } | 589 | } |
@@ -1142,6 +1142,10 @@ static struct test { | |||
1142 | .func = test__perf_pmu, | 1142 | .func = test__perf_pmu, |
1143 | }, | 1143 | }, |
1144 | { | 1144 | { |
1145 | .desc = "Test dso data interface", | ||
1146 | .func = dso__test_data, | ||
1147 | }, | ||
1148 | { | ||
1145 | .func = NULL, | 1149 | .func = NULL, |
1146 | }, | 1150 | }, |
1147 | }; | 1151 | }; |
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index 6bb0277b7dfe..35e86c6df713 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c | |||
@@ -125,7 +125,7 @@ static int perf_top__parse_source(struct perf_top *top, struct hist_entry *he) | |||
125 | /* | 125 | /* |
126 | * We can't annotate with just /proc/kallsyms | 126 | * We can't annotate with just /proc/kallsyms |
127 | */ | 127 | */ |
128 | if (map->dso->symtab_type == SYMTAB__KALLSYMS) { | 128 | if (map->dso->symtab_type == DSO_BINARY_TYPE__KALLSYMS) { |
129 | pr_err("Can't annotate %s: No vmlinux file was found in the " | 129 | pr_err("Can't annotate %s: No vmlinux file was found in the " |
130 | "path\n", sym->name); | 130 | "path\n", sym->name); |
131 | sleep(1); | 131 | sleep(1); |
@@ -245,7 +245,7 @@ static void perf_top__show_details(struct perf_top *top) | |||
245 | if (notes->src == NULL) | 245 | if (notes->src == NULL) |
246 | goto out_unlock; | 246 | goto out_unlock; |
247 | 247 | ||
248 | printf("Showing %s for %s\n", event_name(top->sym_evsel), symbol->name); | 248 | printf("Showing %s for %s\n", perf_evsel__name(top->sym_evsel), symbol->name); |
249 | printf(" Events Pcnt (>=%d%%)\n", top->sym_pcnt_filter); | 249 | printf(" Events Pcnt (>=%d%%)\n", top->sym_pcnt_filter); |
250 | 250 | ||
251 | more = symbol__annotate_printf(symbol, he->ms.map, top->sym_evsel->idx, | 251 | more = symbol__annotate_printf(symbol, he->ms.map, top->sym_evsel->idx, |
@@ -408,7 +408,7 @@ static void perf_top__print_mapped_keys(struct perf_top *top) | |||
408 | fprintf(stdout, "\t[e] display entries (lines). \t(%d)\n", top->print_entries); | 408 | fprintf(stdout, "\t[e] display entries (lines). \t(%d)\n", top->print_entries); |
409 | 409 | ||
410 | if (top->evlist->nr_entries > 1) | 410 | if (top->evlist->nr_entries > 1) |
411 | fprintf(stdout, "\t[E] active event counter. \t(%s)\n", event_name(top->sym_evsel)); | 411 | fprintf(stdout, "\t[E] active event counter. \t(%s)\n", perf_evsel__name(top->sym_evsel)); |
412 | 412 | ||
413 | fprintf(stdout, "\t[f] profile display filter (count). \t(%d)\n", top->count_filter); | 413 | fprintf(stdout, "\t[f] profile display filter (count). \t(%d)\n", top->count_filter); |
414 | 414 | ||
@@ -503,13 +503,13 @@ static void perf_top__handle_keypress(struct perf_top *top, int c) | |||
503 | fprintf(stderr, "\nAvailable events:"); | 503 | fprintf(stderr, "\nAvailable events:"); |
504 | 504 | ||
505 | list_for_each_entry(top->sym_evsel, &top->evlist->entries, node) | 505 | list_for_each_entry(top->sym_evsel, &top->evlist->entries, node) |
506 | fprintf(stderr, "\n\t%d %s", top->sym_evsel->idx, event_name(top->sym_evsel)); | 506 | fprintf(stderr, "\n\t%d %s", top->sym_evsel->idx, perf_evsel__name(top->sym_evsel)); |
507 | 507 | ||
508 | prompt_integer(&counter, "Enter details event counter"); | 508 | prompt_integer(&counter, "Enter details event counter"); |
509 | 509 | ||
510 | if (counter >= top->evlist->nr_entries) { | 510 | if (counter >= top->evlist->nr_entries) { |
511 | top->sym_evsel = list_entry(top->evlist->entries.next, struct perf_evsel, node); | 511 | top->sym_evsel = list_entry(top->evlist->entries.next, struct perf_evsel, node); |
512 | fprintf(stderr, "Sorry, no such event, using %s.\n", event_name(top->sym_evsel)); | 512 | fprintf(stderr, "Sorry, no such event, using %s.\n", perf_evsel__name(top->sym_evsel)); |
513 | sleep(1); | 513 | sleep(1); |
514 | break; | 514 | break; |
515 | } | 515 | } |
@@ -774,7 +774,7 @@ static void perf_event__process_sample(struct perf_tool *tool, | |||
774 | 774 | ||
775 | if ((sort__has_parent || symbol_conf.use_callchain) && | 775 | if ((sort__has_parent || symbol_conf.use_callchain) && |
776 | sample->callchain) { | 776 | sample->callchain) { |
777 | err = machine__resolve_callchain(machine, evsel, al.thread, | 777 | err = machine__resolve_callchain(machine, al.thread, |
778 | sample->callchain, &parent); | 778 | sample->callchain, &parent); |
779 | if (err) | 779 | if (err) |
780 | return; | 780 | return; |
@@ -960,7 +960,7 @@ try_again: | |||
960 | 960 | ||
961 | if (err == ENOENT) { | 961 | if (err == ENOENT) { |
962 | ui__error("The %s event is not supported.\n", | 962 | ui__error("The %s event is not supported.\n", |
963 | event_name(counter)); | 963 | perf_evsel__name(counter)); |
964 | goto out_err; | 964 | goto out_err; |
965 | } else if (err == EMFILE) { | 965 | } else if (err == EMFILE) { |
966 | ui__error("Too many events are opened.\n" | 966 | ui__error("Too many events are opened.\n" |
diff --git a/tools/perf/config/feature-tests.mak b/tools/perf/config/feature-tests.mak index d9084e03ce56..6c18785a6417 100644 --- a/tools/perf/config/feature-tests.mak +++ b/tools/perf/config/feature-tests.mak | |||
@@ -78,6 +78,19 @@ int main(int argc, char *argv[]) | |||
78 | return 0; | 78 | return 0; |
79 | } | 79 | } |
80 | endef | 80 | endef |
81 | |||
82 | define SOURCE_GTK2_INFOBAR | ||
83 | #pragma GCC diagnostic ignored \"-Wstrict-prototypes\" | ||
84 | #include <gtk/gtk.h> | ||
85 | #pragma GCC diagnostic error \"-Wstrict-prototypes\" | ||
86 | |||
87 | int main(void) | ||
88 | { | ||
89 | gtk_info_bar_new(); | ||
90 | |||
91 | return 0; | ||
92 | } | ||
93 | endef | ||
81 | endif | 94 | endif |
82 | 95 | ||
83 | ifndef NO_LIBPERL | 96 | ifndef NO_LIBPERL |
diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/annotate.c index 34b1c46eaf42..67a2703e666a 100644 --- a/tools/perf/ui/browsers/annotate.c +++ b/tools/perf/ui/browsers/annotate.c | |||
@@ -814,7 +814,7 @@ int symbol__tui_annotate(struct symbol *sym, struct map *map, int evidx, | |||
814 | { | 814 | { |
815 | struct disasm_line *pos, *n; | 815 | struct disasm_line *pos, *n; |
816 | struct annotation *notes; | 816 | struct annotation *notes; |
817 | const size_t size = symbol__size(sym); | 817 | size_t size; |
818 | struct map_symbol ms = { | 818 | struct map_symbol ms = { |
819 | .map = map, | 819 | .map = map, |
820 | .sym = sym, | 820 | .sym = sym, |
@@ -834,6 +834,8 @@ int symbol__tui_annotate(struct symbol *sym, struct map *map, int evidx, | |||
834 | if (sym == NULL) | 834 | if (sym == NULL) |
835 | return -1; | 835 | return -1; |
836 | 836 | ||
837 | size = symbol__size(sym); | ||
838 | |||
837 | if (map->dso->annotate_warned) | 839 | if (map->dso->annotate_warned) |
838 | return -1; | 840 | return -1; |
839 | 841 | ||
diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c index 53f6697d014e..413bd62eedb1 100644 --- a/tools/perf/ui/browsers/hists.c +++ b/tools/perf/ui/browsers/hists.c | |||
@@ -23,6 +23,7 @@ struct hist_browser { | |||
23 | struct hists *hists; | 23 | struct hists *hists; |
24 | struct hist_entry *he_selection; | 24 | struct hist_entry *he_selection; |
25 | struct map_symbol *selection; | 25 | struct map_symbol *selection; |
26 | int print_seq; | ||
26 | bool has_symbols; | 27 | bool has_symbols; |
27 | }; | 28 | }; |
28 | 29 | ||
@@ -800,6 +801,196 @@ do_offset: | |||
800 | } | 801 | } |
801 | } | 802 | } |
802 | 803 | ||
804 | static int hist_browser__fprintf_callchain_node_rb_tree(struct hist_browser *browser, | ||
805 | struct callchain_node *chain_node, | ||
806 | u64 total, int level, | ||
807 | FILE *fp) | ||
808 | { | ||
809 | struct rb_node *node; | ||
810 | int offset = level * LEVEL_OFFSET_STEP; | ||
811 | u64 new_total, remaining; | ||
812 | int printed = 0; | ||
813 | |||
814 | if (callchain_param.mode == CHAIN_GRAPH_REL) | ||
815 | new_total = chain_node->children_hit; | ||
816 | else | ||
817 | new_total = total; | ||
818 | |||
819 | remaining = new_total; | ||
820 | node = rb_first(&chain_node->rb_root); | ||
821 | while (node) { | ||
822 | struct callchain_node *child = rb_entry(node, struct callchain_node, rb_node); | ||
823 | struct rb_node *next = rb_next(node); | ||
824 | u64 cumul = callchain_cumul_hits(child); | ||
825 | struct callchain_list *chain; | ||
826 | char folded_sign = ' '; | ||
827 | int first = true; | ||
828 | int extra_offset = 0; | ||
829 | |||
830 | remaining -= cumul; | ||
831 | |||
832 | list_for_each_entry(chain, &child->val, list) { | ||
833 | char ipstr[BITS_PER_LONG / 4 + 1], *alloc_str; | ||
834 | const char *str; | ||
835 | bool was_first = first; | ||
836 | |||
837 | if (first) | ||
838 | first = false; | ||
839 | else | ||
840 | extra_offset = LEVEL_OFFSET_STEP; | ||
841 | |||
842 | folded_sign = callchain_list__folded(chain); | ||
843 | |||
844 | alloc_str = NULL; | ||
845 | str = callchain_list__sym_name(chain, ipstr, sizeof(ipstr)); | ||
846 | if (was_first) { | ||
847 | double percent = cumul * 100.0 / new_total; | ||
848 | |||
849 | if (asprintf(&alloc_str, "%2.2f%% %s", percent, str) < 0) | ||
850 | str = "Not enough memory!"; | ||
851 | else | ||
852 | str = alloc_str; | ||
853 | } | ||
854 | |||
855 | printed += fprintf(fp, "%*s%c %s\n", offset + extra_offset, " ", folded_sign, str); | ||
856 | free(alloc_str); | ||
857 | if (folded_sign == '+') | ||
858 | break; | ||
859 | } | ||
860 | |||
861 | if (folded_sign == '-') { | ||
862 | const int new_level = level + (extra_offset ? 2 : 1); | ||
863 | printed += hist_browser__fprintf_callchain_node_rb_tree(browser, child, new_total, | ||
864 | new_level, fp); | ||
865 | } | ||
866 | |||
867 | node = next; | ||
868 | } | ||
869 | |||
870 | return printed; | ||
871 | } | ||
872 | |||
873 | static int hist_browser__fprintf_callchain_node(struct hist_browser *browser, | ||
874 | struct callchain_node *node, | ||
875 | int level, FILE *fp) | ||
876 | { | ||
877 | struct callchain_list *chain; | ||
878 | int offset = level * LEVEL_OFFSET_STEP; | ||
879 | char folded_sign = ' '; | ||
880 | int printed = 0; | ||
881 | |||
882 | list_for_each_entry(chain, &node->val, list) { | ||
883 | char ipstr[BITS_PER_LONG / 4 + 1], *s; | ||
884 | |||
885 | folded_sign = callchain_list__folded(chain); | ||
886 | s = callchain_list__sym_name(chain, ipstr, sizeof(ipstr)); | ||
887 | printed += fprintf(fp, "%*s%c %s\n", offset, " ", folded_sign, s); | ||
888 | } | ||
889 | |||
890 | if (folded_sign == '-') | ||
891 | printed += hist_browser__fprintf_callchain_node_rb_tree(browser, node, | ||
892 | browser->hists->stats.total_period, | ||
893 | level + 1, fp); | ||
894 | return printed; | ||
895 | } | ||
896 | |||
897 | static int hist_browser__fprintf_callchain(struct hist_browser *browser, | ||
898 | struct rb_root *chain, int level, FILE *fp) | ||
899 | { | ||
900 | struct rb_node *nd; | ||
901 | int printed = 0; | ||
902 | |||
903 | for (nd = rb_first(chain); nd; nd = rb_next(nd)) { | ||
904 | struct callchain_node *node = rb_entry(nd, struct callchain_node, rb_node); | ||
905 | |||
906 | printed += hist_browser__fprintf_callchain_node(browser, node, level, fp); | ||
907 | } | ||
908 | |||
909 | return printed; | ||
910 | } | ||
911 | |||
912 | static int hist_browser__fprintf_entry(struct hist_browser *browser, | ||
913 | struct hist_entry *he, FILE *fp) | ||
914 | { | ||
915 | char s[8192]; | ||
916 | double percent; | ||
917 | int printed = 0; | ||
918 | char folded_sign = ' '; | ||
919 | |||
920 | if (symbol_conf.use_callchain) | ||
921 | folded_sign = hist_entry__folded(he); | ||
922 | |||
923 | hist_entry__snprintf(he, s, sizeof(s), browser->hists); | ||
924 | percent = (he->period * 100.0) / browser->hists->stats.total_period; | ||
925 | |||
926 | if (symbol_conf.use_callchain) | ||
927 | printed += fprintf(fp, "%c ", folded_sign); | ||
928 | |||
929 | printed += fprintf(fp, " %5.2f%%", percent); | ||
930 | |||
931 | if (symbol_conf.show_nr_samples) | ||
932 | printed += fprintf(fp, " %11u", he->nr_events); | ||
933 | |||
934 | if (symbol_conf.show_total_period) | ||
935 | printed += fprintf(fp, " %12" PRIu64, he->period); | ||
936 | |||
937 | printed += fprintf(fp, "%s\n", rtrim(s)); | ||
938 | |||
939 | if (folded_sign == '-') | ||
940 | printed += hist_browser__fprintf_callchain(browser, &he->sorted_chain, 1, fp); | ||
941 | |||
942 | return printed; | ||
943 | } | ||
944 | |||
945 | static int hist_browser__fprintf(struct hist_browser *browser, FILE *fp) | ||
946 | { | ||
947 | struct rb_node *nd = hists__filter_entries(rb_first(browser->b.entries)); | ||
948 | int printed = 0; | ||
949 | |||
950 | while (nd) { | ||
951 | struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); | ||
952 | |||
953 | printed += hist_browser__fprintf_entry(browser, h, fp); | ||
954 | nd = hists__filter_entries(rb_next(nd)); | ||
955 | } | ||
956 | |||
957 | return printed; | ||
958 | } | ||
959 | |||
960 | static int hist_browser__dump(struct hist_browser *browser) | ||
961 | { | ||
962 | char filename[64]; | ||
963 | FILE *fp; | ||
964 | |||
965 | while (1) { | ||
966 | scnprintf(filename, sizeof(filename), "perf.hist.%d", browser->print_seq); | ||
967 | if (access(filename, F_OK)) | ||
968 | break; | ||
969 | /* | ||
970 | * XXX: Just an arbitrary lazy upper limit | ||
971 | */ | ||
972 | if (++browser->print_seq == 8192) { | ||
973 | ui_helpline__fpush("Too many perf.hist.N files, nothing written!"); | ||
974 | return -1; | ||
975 | } | ||
976 | } | ||
977 | |||
978 | fp = fopen(filename, "w"); | ||
979 | if (fp == NULL) { | ||
980 | char bf[64]; | ||
981 | const char *err = strerror_r(errno, bf, sizeof(bf)); | ||
982 | ui_helpline__fpush("Couldn't write to %s: %s", filename, err); | ||
983 | return -1; | ||
984 | } | ||
985 | |||
986 | ++browser->print_seq; | ||
987 | hist_browser__fprintf(browser, fp); | ||
988 | fclose(fp); | ||
989 | ui_helpline__fpush("%s written!", filename); | ||
990 | |||
991 | return 0; | ||
992 | } | ||
993 | |||
803 | static struct hist_browser *hist_browser__new(struct hists *hists) | 994 | static struct hist_browser *hist_browser__new(struct hists *hists) |
804 | { | 995 | { |
805 | struct hist_browser *browser = zalloc(sizeof(*browser)); | 996 | struct hist_browser *browser = zalloc(sizeof(*browser)); |
@@ -937,6 +1128,9 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events, | |||
937 | browser->selection->map->dso->annotate_warned) | 1128 | browser->selection->map->dso->annotate_warned) |
938 | continue; | 1129 | continue; |
939 | goto do_annotate; | 1130 | goto do_annotate; |
1131 | case 'P': | ||
1132 | hist_browser__dump(browser); | ||
1133 | continue; | ||
940 | case 'd': | 1134 | case 'd': |
941 | goto zoom_dso; | 1135 | goto zoom_dso; |
942 | case 't': | 1136 | case 't': |
@@ -969,6 +1163,7 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events, | |||
969 | "E Expand all callchains\n" | 1163 | "E Expand all callchains\n" |
970 | "d Zoom into current DSO\n" | 1164 | "d Zoom into current DSO\n" |
971 | "t Zoom into current Thread\n" | 1165 | "t Zoom into current Thread\n" |
1166 | "P Print histograms to perf.hist.N\n" | ||
972 | "/ Filter symbol by name"); | 1167 | "/ Filter symbol by name"); |
973 | continue; | 1168 | continue; |
974 | case K_ENTER: | 1169 | case K_ENTER: |
@@ -1172,7 +1367,7 @@ static void perf_evsel_menu__write(struct ui_browser *browser, | |||
1172 | struct perf_evsel *evsel = list_entry(entry, struct perf_evsel, node); | 1367 | struct perf_evsel *evsel = list_entry(entry, struct perf_evsel, node); |
1173 | bool current_entry = ui_browser__is_current_entry(browser, row); | 1368 | bool current_entry = ui_browser__is_current_entry(browser, row); |
1174 | unsigned long nr_events = evsel->hists.stats.nr_events[PERF_RECORD_SAMPLE]; | 1369 | unsigned long nr_events = evsel->hists.stats.nr_events[PERF_RECORD_SAMPLE]; |
1175 | const char *ev_name = event_name(evsel); | 1370 | const char *ev_name = perf_evsel__name(evsel); |
1176 | char bf[256], unit; | 1371 | char bf[256], unit; |
1177 | const char *warn = " "; | 1372 | const char *warn = " "; |
1178 | size_t printed; | 1373 | size_t printed; |
@@ -1240,7 +1435,7 @@ browse_hists: | |||
1240 | */ | 1435 | */ |
1241 | if (timer) | 1436 | if (timer) |
1242 | timer(arg); | 1437 | timer(arg); |
1243 | ev_name = event_name(pos); | 1438 | ev_name = perf_evsel__name(pos); |
1244 | key = perf_evsel__hists_browse(pos, nr_events, help, | 1439 | key = perf_evsel__hists_browse(pos, nr_events, help, |
1245 | ev_name, true, timer, | 1440 | ev_name, true, timer, |
1246 | arg, delay_secs); | 1441 | arg, delay_secs); |
@@ -1309,17 +1504,11 @@ static int __perf_evlist__tui_browse_hists(struct perf_evlist *evlist, | |||
1309 | ui_helpline__push("Press ESC to exit"); | 1504 | ui_helpline__push("Press ESC to exit"); |
1310 | 1505 | ||
1311 | list_for_each_entry(pos, &evlist->entries, node) { | 1506 | list_for_each_entry(pos, &evlist->entries, node) { |
1312 | const char *ev_name = event_name(pos); | 1507 | const char *ev_name = perf_evsel__name(pos); |
1313 | size_t line_len = strlen(ev_name) + 7; | 1508 | size_t line_len = strlen(ev_name) + 7; |
1314 | 1509 | ||
1315 | if (menu.b.width < line_len) | 1510 | if (menu.b.width < line_len) |
1316 | menu.b.width = line_len; | 1511 | menu.b.width = line_len; |
1317 | /* | ||
1318 | * Cache the evsel name, tracepoints have a _high_ cost per | ||
1319 | * event_name() call. | ||
1320 | */ | ||
1321 | if (pos->name == NULL) | ||
1322 | pos->name = strdup(ev_name); | ||
1323 | } | 1512 | } |
1324 | 1513 | ||
1325 | return perf_evsel_menu__run(&menu, evlist->nr_entries, help, timer, | 1514 | return perf_evsel_menu__run(&menu, evlist->nr_entries, help, timer, |
@@ -1330,11 +1519,10 @@ int perf_evlist__tui_browse_hists(struct perf_evlist *evlist, const char *help, | |||
1330 | void(*timer)(void *arg), void *arg, | 1519 | void(*timer)(void *arg), void *arg, |
1331 | int delay_secs) | 1520 | int delay_secs) |
1332 | { | 1521 | { |
1333 | |||
1334 | if (evlist->nr_entries == 1) { | 1522 | if (evlist->nr_entries == 1) { |
1335 | struct perf_evsel *first = list_entry(evlist->entries.next, | 1523 | struct perf_evsel *first = list_entry(evlist->entries.next, |
1336 | struct perf_evsel, node); | 1524 | struct perf_evsel, node); |
1337 | const char *ev_name = event_name(first); | 1525 | const char *ev_name = perf_evsel__name(first); |
1338 | return perf_evsel__hists_browse(first, evlist->nr_entries, help, | 1526 | return perf_evsel__hists_browse(first, evlist->nr_entries, help, |
1339 | ev_name, false, timer, arg, | 1527 | ev_name, false, timer, arg, |
1340 | delay_secs); | 1528 | delay_secs); |
diff --git a/tools/perf/ui/gtk/browser.c b/tools/perf/ui/gtk/browser.c index 0656c381a89c..ec12e0b4ded6 100644 --- a/tools/perf/ui/gtk/browser.c +++ b/tools/perf/ui/gtk/browser.c | |||
@@ -11,8 +11,8 @@ | |||
11 | 11 | ||
12 | static void perf_gtk__signal(int sig) | 12 | static void perf_gtk__signal(int sig) |
13 | { | 13 | { |
14 | perf_gtk__exit(false); | ||
14 | psignal(sig, "perf"); | 15 | psignal(sig, "perf"); |
15 | gtk_main_quit(); | ||
16 | } | 16 | } |
17 | 17 | ||
18 | static void perf_gtk__resize_window(GtkWidget *window) | 18 | static void perf_gtk__resize_window(GtkWidget *window) |
@@ -122,13 +122,59 @@ static void perf_gtk__show_hists(GtkWidget *window, struct hists *hists) | |||
122 | gtk_container_add(GTK_CONTAINER(window), view); | 122 | gtk_container_add(GTK_CONTAINER(window), view); |
123 | } | 123 | } |
124 | 124 | ||
125 | #ifdef HAVE_GTK_INFO_BAR | ||
126 | static GtkWidget *perf_gtk__setup_info_bar(void) | ||
127 | { | ||
128 | GtkWidget *info_bar; | ||
129 | GtkWidget *label; | ||
130 | GtkWidget *content_area; | ||
131 | |||
132 | info_bar = gtk_info_bar_new(); | ||
133 | gtk_widget_set_no_show_all(info_bar, TRUE); | ||
134 | |||
135 | label = gtk_label_new(""); | ||
136 | gtk_widget_show(label); | ||
137 | |||
138 | content_area = gtk_info_bar_get_content_area(GTK_INFO_BAR(info_bar)); | ||
139 | gtk_container_add(GTK_CONTAINER(content_area), label); | ||
140 | |||
141 | gtk_info_bar_add_button(GTK_INFO_BAR(info_bar), GTK_STOCK_OK, | ||
142 | GTK_RESPONSE_OK); | ||
143 | g_signal_connect(info_bar, "response", | ||
144 | G_CALLBACK(gtk_widget_hide), NULL); | ||
145 | |||
146 | pgctx->info_bar = info_bar; | ||
147 | pgctx->message_label = label; | ||
148 | |||
149 | return info_bar; | ||
150 | } | ||
151 | #endif | ||
152 | |||
153 | static GtkWidget *perf_gtk__setup_statusbar(void) | ||
154 | { | ||
155 | GtkWidget *stbar; | ||
156 | unsigned ctxid; | ||
157 | |||
158 | stbar = gtk_statusbar_new(); | ||
159 | |||
160 | ctxid = gtk_statusbar_get_context_id(GTK_STATUSBAR(stbar), | ||
161 | "perf report"); | ||
162 | pgctx->statbar = stbar; | ||
163 | pgctx->statbar_ctx_id = ctxid; | ||
164 | |||
165 | return stbar; | ||
166 | } | ||
167 | |||
125 | int perf_evlist__gtk_browse_hists(struct perf_evlist *evlist, | 168 | int perf_evlist__gtk_browse_hists(struct perf_evlist *evlist, |
126 | const char *help __used, | 169 | const char *help __used, |
127 | void (*timer) (void *arg)__used, | 170 | void (*timer) (void *arg)__used, |
128 | void *arg __used, int delay_secs __used) | 171 | void *arg __used, int delay_secs __used) |
129 | { | 172 | { |
130 | struct perf_evsel *pos; | 173 | struct perf_evsel *pos; |
174 | GtkWidget *vbox; | ||
131 | GtkWidget *notebook; | 175 | GtkWidget *notebook; |
176 | GtkWidget *info_bar; | ||
177 | GtkWidget *statbar; | ||
132 | GtkWidget *window; | 178 | GtkWidget *window; |
133 | 179 | ||
134 | signal(SIGSEGV, perf_gtk__signal); | 180 | signal(SIGSEGV, perf_gtk__signal); |
@@ -143,11 +189,17 @@ int perf_evlist__gtk_browse_hists(struct perf_evlist *evlist, | |||
143 | 189 | ||
144 | g_signal_connect(window, "delete_event", gtk_main_quit, NULL); | 190 | g_signal_connect(window, "delete_event", gtk_main_quit, NULL); |
145 | 191 | ||
192 | pgctx = perf_gtk__activate_context(window); | ||
193 | if (!pgctx) | ||
194 | return -1; | ||
195 | |||
196 | vbox = gtk_vbox_new(FALSE, 0); | ||
197 | |||
146 | notebook = gtk_notebook_new(); | 198 | notebook = gtk_notebook_new(); |
147 | 199 | ||
148 | list_for_each_entry(pos, &evlist->entries, node) { | 200 | list_for_each_entry(pos, &evlist->entries, node) { |
149 | struct hists *hists = &pos->hists; | 201 | struct hists *hists = &pos->hists; |
150 | const char *evname = event_name(pos); | 202 | const char *evname = perf_evsel__name(pos); |
151 | GtkWidget *scrolled_window; | 203 | GtkWidget *scrolled_window; |
152 | GtkWidget *tab_label; | 204 | GtkWidget *tab_label; |
153 | 205 | ||
@@ -164,7 +216,16 @@ int perf_evlist__gtk_browse_hists(struct perf_evlist *evlist, | |||
164 | gtk_notebook_append_page(GTK_NOTEBOOK(notebook), scrolled_window, tab_label); | 216 | gtk_notebook_append_page(GTK_NOTEBOOK(notebook), scrolled_window, tab_label); |
165 | } | 217 | } |
166 | 218 | ||
167 | gtk_container_add(GTK_CONTAINER(window), notebook); | 219 | gtk_box_pack_start(GTK_BOX(vbox), notebook, TRUE, TRUE, 0); |
220 | |||
221 | info_bar = perf_gtk__setup_info_bar(); | ||
222 | if (info_bar) | ||
223 | gtk_box_pack_start(GTK_BOX(vbox), info_bar, FALSE, FALSE, 0); | ||
224 | |||
225 | statbar = perf_gtk__setup_statusbar(); | ||
226 | gtk_box_pack_start(GTK_BOX(vbox), statbar, FALSE, FALSE, 0); | ||
227 | |||
228 | gtk_container_add(GTK_CONTAINER(window), vbox); | ||
168 | 229 | ||
169 | gtk_widget_show_all(window); | 230 | gtk_widget_show_all(window); |
170 | 231 | ||
@@ -174,5 +235,7 @@ int perf_evlist__gtk_browse_hists(struct perf_evlist *evlist, | |||
174 | 235 | ||
175 | gtk_main(); | 236 | gtk_main(); |
176 | 237 | ||
238 | perf_gtk__deactivate_context(&pgctx); | ||
239 | |||
177 | return 0; | 240 | return 0; |
178 | } | 241 | } |
diff --git a/tools/perf/ui/gtk/gtk.h b/tools/perf/ui/gtk/gtk.h index 75177ee04032..a4d0f2b4a2dc 100644 --- a/tools/perf/ui/gtk/gtk.h +++ b/tools/perf/ui/gtk/gtk.h | |||
@@ -1,8 +1,39 @@ | |||
1 | #ifndef _PERF_GTK_H_ | 1 | #ifndef _PERF_GTK_H_ |
2 | #define _PERF_GTK_H_ 1 | 2 | #define _PERF_GTK_H_ 1 |
3 | 3 | ||
4 | #include <stdbool.h> | ||
5 | |||
4 | #pragma GCC diagnostic ignored "-Wstrict-prototypes" | 6 | #pragma GCC diagnostic ignored "-Wstrict-prototypes" |
5 | #include <gtk/gtk.h> | 7 | #include <gtk/gtk.h> |
6 | #pragma GCC diagnostic error "-Wstrict-prototypes" | 8 | #pragma GCC diagnostic error "-Wstrict-prototypes" |
7 | 9 | ||
10 | |||
11 | struct perf_gtk_context { | ||
12 | GtkWidget *main_window; | ||
13 | |||
14 | #ifdef HAVE_GTK_INFO_BAR | ||
15 | GtkWidget *info_bar; | ||
16 | GtkWidget *message_label; | ||
17 | #endif | ||
18 | GtkWidget *statbar; | ||
19 | guint statbar_ctx_id; | ||
20 | }; | ||
21 | |||
22 | extern struct perf_gtk_context *pgctx; | ||
23 | |||
24 | static inline bool perf_gtk__is_active_context(struct perf_gtk_context *ctx) | ||
25 | { | ||
26 | return ctx && ctx->main_window; | ||
27 | } | ||
28 | |||
29 | struct perf_gtk_context *perf_gtk__activate_context(GtkWidget *window); | ||
30 | int perf_gtk__deactivate_context(struct perf_gtk_context **ctx); | ||
31 | |||
32 | #ifndef HAVE_GTK_INFO_BAR | ||
33 | static inline GtkWidget *perf_gtk__setup_info_bar(void) | ||
34 | { | ||
35 | return NULL; | ||
36 | } | ||
37 | #endif | ||
38 | |||
8 | #endif /* _PERF_GTK_H_ */ | 39 | #endif /* _PERF_GTK_H_ */ |
diff --git a/tools/perf/ui/gtk/setup.c b/tools/perf/ui/gtk/setup.c index 829529957766..92879ce61e2f 100644 --- a/tools/perf/ui/gtk/setup.c +++ b/tools/perf/ui/gtk/setup.c | |||
@@ -1,12 +1,17 @@ | |||
1 | #include "gtk.h" | 1 | #include "gtk.h" |
2 | #include "../../util/cache.h" | 2 | #include "../../util/cache.h" |
3 | #include "../../util/debug.h" | ||
4 | |||
5 | extern struct perf_error_ops perf_gtk_eops; | ||
3 | 6 | ||
4 | int perf_gtk__init(void) | 7 | int perf_gtk__init(void) |
5 | { | 8 | { |
9 | perf_error__register(&perf_gtk_eops); | ||
6 | return gtk_init_check(NULL, NULL) ? 0 : -1; | 10 | return gtk_init_check(NULL, NULL) ? 0 : -1; |
7 | } | 11 | } |
8 | 12 | ||
9 | void perf_gtk__exit(bool wait_for_ok __used) | 13 | void perf_gtk__exit(bool wait_for_ok __used) |
10 | { | 14 | { |
15 | perf_error__unregister(&perf_gtk_eops); | ||
11 | gtk_main_quit(); | 16 | gtk_main_quit(); |
12 | } | 17 | } |
diff --git a/tools/perf/ui/gtk/util.c b/tools/perf/ui/gtk/util.c new file mode 100644 index 000000000000..0ead373c0dfb --- /dev/null +++ b/tools/perf/ui/gtk/util.c | |||
@@ -0,0 +1,129 @@ | |||
1 | #include "../util.h" | ||
2 | #include "../../util/debug.h" | ||
3 | #include "gtk.h" | ||
4 | |||
5 | #include <string.h> | ||
6 | |||
7 | |||
8 | struct perf_gtk_context *pgctx; | ||
9 | |||
10 | struct perf_gtk_context *perf_gtk__activate_context(GtkWidget *window) | ||
11 | { | ||
12 | struct perf_gtk_context *ctx; | ||
13 | |||
14 | ctx = malloc(sizeof(*pgctx)); | ||
15 | if (ctx) | ||
16 | ctx->main_window = window; | ||
17 | |||
18 | return ctx; | ||
19 | } | ||
20 | |||
21 | int perf_gtk__deactivate_context(struct perf_gtk_context **ctx) | ||
22 | { | ||
23 | if (!perf_gtk__is_active_context(*ctx)) | ||
24 | return -1; | ||
25 | |||
26 | free(*ctx); | ||
27 | *ctx = NULL; | ||
28 | return 0; | ||
29 | } | ||
30 | |||
31 | static int perf_gtk__error(const char *format, va_list args) | ||
32 | { | ||
33 | char *msg; | ||
34 | GtkWidget *dialog; | ||
35 | |||
36 | if (!perf_gtk__is_active_context(pgctx) || | ||
37 | vasprintf(&msg, format, args) < 0) { | ||
38 | fprintf(stderr, "Error:\n"); | ||
39 | vfprintf(stderr, format, args); | ||
40 | fprintf(stderr, "\n"); | ||
41 | return -1; | ||
42 | } | ||
43 | |||
44 | dialog = gtk_message_dialog_new_with_markup(GTK_WINDOW(pgctx->main_window), | ||
45 | GTK_DIALOG_DESTROY_WITH_PARENT, | ||
46 | GTK_MESSAGE_ERROR, | ||
47 | GTK_BUTTONS_CLOSE, | ||
48 | "<b>Error</b>\n\n%s", msg); | ||
49 | gtk_dialog_run(GTK_DIALOG(dialog)); | ||
50 | |||
51 | gtk_widget_destroy(dialog); | ||
52 | free(msg); | ||
53 | return 0; | ||
54 | } | ||
55 | |||
56 | #ifdef HAVE_GTK_INFO_BAR | ||
57 | static int perf_gtk__warning_info_bar(const char *format, va_list args) | ||
58 | { | ||
59 | char *msg; | ||
60 | |||
61 | if (!perf_gtk__is_active_context(pgctx) || | ||
62 | vasprintf(&msg, format, args) < 0) { | ||
63 | fprintf(stderr, "Warning:\n"); | ||
64 | vfprintf(stderr, format, args); | ||
65 | fprintf(stderr, "\n"); | ||
66 | return -1; | ||
67 | } | ||
68 | |||
69 | gtk_label_set_text(GTK_LABEL(pgctx->message_label), msg); | ||
70 | gtk_info_bar_set_message_type(GTK_INFO_BAR(pgctx->info_bar), | ||
71 | GTK_MESSAGE_WARNING); | ||
72 | gtk_widget_show(pgctx->info_bar); | ||
73 | |||
74 | free(msg); | ||
75 | return 0; | ||
76 | } | ||
77 | #else | ||
78 | static int perf_gtk__warning_statusbar(const char *format, va_list args) | ||
79 | { | ||
80 | char *msg, *p; | ||
81 | |||
82 | if (!perf_gtk__is_active_context(pgctx) || | ||
83 | vasprintf(&msg, format, args) < 0) { | ||
84 | fprintf(stderr, "Warning:\n"); | ||
85 | vfprintf(stderr, format, args); | ||
86 | fprintf(stderr, "\n"); | ||
87 | return -1; | ||
88 | } | ||
89 | |||
90 | gtk_statusbar_pop(GTK_STATUSBAR(pgctx->statbar), | ||
91 | pgctx->statbar_ctx_id); | ||
92 | |||
93 | /* Only first line can be displayed */ | ||
94 | p = strchr(msg, '\n'); | ||
95 | if (p) | ||
96 | *p = '\0'; | ||
97 | |||
98 | gtk_statusbar_push(GTK_STATUSBAR(pgctx->statbar), | ||
99 | pgctx->statbar_ctx_id, msg); | ||
100 | |||
101 | free(msg); | ||
102 | return 0; | ||
103 | } | ||
104 | #endif | ||
105 | |||
106 | struct perf_error_ops perf_gtk_eops = { | ||
107 | .error = perf_gtk__error, | ||
108 | #ifdef HAVE_GTK_INFO_BAR | ||
109 | .warning = perf_gtk__warning_info_bar, | ||
110 | #else | ||
111 | .warning = perf_gtk__warning_statusbar, | ||
112 | #endif | ||
113 | }; | ||
114 | |||
115 | /* | ||
116 | * FIXME: Functions below should be implemented properly. | ||
117 | * For now, just add stubs for NO_NEWT=1 build. | ||
118 | */ | ||
119 | #ifdef NO_NEWT_SUPPORT | ||
120 | int ui_helpline__show_help(const char *format __used, va_list ap __used) | ||
121 | { | ||
122 | return 0; | ||
123 | } | ||
124 | |||
125 | void ui_progress__update(u64 curr __used, u64 total __used, | ||
126 | const char *title __used) | ||
127 | { | ||
128 | } | ||
129 | #endif | ||
diff --git a/tools/perf/ui/tui/setup.c b/tools/perf/ui/tui/setup.c index d33e943ac434..e813c1d17346 100644 --- a/tools/perf/ui/tui/setup.c +++ b/tools/perf/ui/tui/setup.c | |||
@@ -15,6 +15,8 @@ pthread_mutex_t ui__lock = PTHREAD_MUTEX_INITIALIZER; | |||
15 | 15 | ||
16 | static volatile int ui__need_resize; | 16 | static volatile int ui__need_resize; |
17 | 17 | ||
18 | extern struct perf_error_ops perf_tui_eops; | ||
19 | |||
18 | void ui__refresh_dimensions(bool force) | 20 | void ui__refresh_dimensions(bool force) |
19 | { | 21 | { |
20 | if (force || ui__need_resize) { | 22 | if (force || ui__need_resize) { |
@@ -122,6 +124,8 @@ int ui__init(void) | |||
122 | signal(SIGINT, ui__signal); | 124 | signal(SIGINT, ui__signal); |
123 | signal(SIGQUIT, ui__signal); | 125 | signal(SIGQUIT, ui__signal); |
124 | signal(SIGTERM, ui__signal); | 126 | signal(SIGTERM, ui__signal); |
127 | |||
128 | perf_error__register(&perf_tui_eops); | ||
125 | out: | 129 | out: |
126 | return err; | 130 | return err; |
127 | } | 131 | } |
@@ -137,4 +141,6 @@ void ui__exit(bool wait_for_ok) | |||
137 | SLsmg_refresh(); | 141 | SLsmg_refresh(); |
138 | SLsmg_reset_smg(); | 142 | SLsmg_reset_smg(); |
139 | SLang_reset_tty(); | 143 | SLang_reset_tty(); |
144 | |||
145 | perf_error__unregister(&perf_tui_eops); | ||
140 | } | 146 | } |
diff --git a/tools/perf/ui/tui/util.c b/tools/perf/ui/tui/util.c new file mode 100644 index 000000000000..092902e30cee --- /dev/null +++ b/tools/perf/ui/tui/util.c | |||
@@ -0,0 +1,243 @@ | |||
1 | #include "../../util/util.h" | ||
2 | #include <signal.h> | ||
3 | #include <stdbool.h> | ||
4 | #include <string.h> | ||
5 | #include <sys/ttydefaults.h> | ||
6 | |||
7 | #include "../../util/cache.h" | ||
8 | #include "../../util/debug.h" | ||
9 | #include "../browser.h" | ||
10 | #include "../keysyms.h" | ||
11 | #include "../helpline.h" | ||
12 | #include "../ui.h" | ||
13 | #include "../util.h" | ||
14 | #include "../libslang.h" | ||
15 | |||
16 | static void ui_browser__argv_write(struct ui_browser *browser, | ||
17 | void *entry, int row) | ||
18 | { | ||
19 | char **arg = entry; | ||
20 | bool current_entry = ui_browser__is_current_entry(browser, row); | ||
21 | |||
22 | ui_browser__set_color(browser, current_entry ? HE_COLORSET_SELECTED : | ||
23 | HE_COLORSET_NORMAL); | ||
24 | slsmg_write_nstring(*arg, browser->width); | ||
25 | } | ||
26 | |||
27 | static int popup_menu__run(struct ui_browser *menu) | ||
28 | { | ||
29 | int key; | ||
30 | |||
31 | if (ui_browser__show(menu, " ", "ESC: exit, ENTER|->: Select option") < 0) | ||
32 | return -1; | ||
33 | |||
34 | while (1) { | ||
35 | key = ui_browser__run(menu, 0); | ||
36 | |||
37 | switch (key) { | ||
38 | case K_RIGHT: | ||
39 | case K_ENTER: | ||
40 | key = menu->index; | ||
41 | break; | ||
42 | case K_LEFT: | ||
43 | case K_ESC: | ||
44 | case 'q': | ||
45 | case CTRL('c'): | ||
46 | key = -1; | ||
47 | break; | ||
48 | default: | ||
49 | continue; | ||
50 | } | ||
51 | |||
52 | break; | ||
53 | } | ||
54 | |||
55 | ui_browser__hide(menu); | ||
56 | return key; | ||
57 | } | ||
58 | |||
59 | int ui__popup_menu(int argc, char * const argv[]) | ||
60 | { | ||
61 | struct ui_browser menu = { | ||
62 | .entries = (void *)argv, | ||
63 | .refresh = ui_browser__argv_refresh, | ||
64 | .seek = ui_browser__argv_seek, | ||
65 | .write = ui_browser__argv_write, | ||
66 | .nr_entries = argc, | ||
67 | }; | ||
68 | |||
69 | return popup_menu__run(&menu); | ||
70 | } | ||
71 | |||
72 | int ui_browser__input_window(const char *title, const char *text, char *input, | ||
73 | const char *exit_msg, int delay_secs) | ||
74 | { | ||
75 | int x, y, len, key; | ||
76 | int max_len = 60, nr_lines = 0; | ||
77 | static char buf[50]; | ||
78 | const char *t; | ||
79 | |||
80 | t = text; | ||
81 | while (1) { | ||
82 | const char *sep = strchr(t, '\n'); | ||
83 | |||
84 | if (sep == NULL) | ||
85 | sep = strchr(t, '\0'); | ||
86 | len = sep - t; | ||
87 | if (max_len < len) | ||
88 | max_len = len; | ||
89 | ++nr_lines; | ||
90 | if (*sep == '\0') | ||
91 | break; | ||
92 | t = sep + 1; | ||
93 | } | ||
94 | |||
95 | max_len += 2; | ||
96 | nr_lines += 8; | ||
97 | y = SLtt_Screen_Rows / 2 - nr_lines / 2; | ||
98 | x = SLtt_Screen_Cols / 2 - max_len / 2; | ||
99 | |||
100 | SLsmg_set_color(0); | ||
101 | SLsmg_draw_box(y, x++, nr_lines, max_len); | ||
102 | if (title) { | ||
103 | SLsmg_gotorc(y, x + 1); | ||
104 | SLsmg_write_string((char *)title); | ||
105 | } | ||
106 | SLsmg_gotorc(++y, x); | ||
107 | nr_lines -= 7; | ||
108 | max_len -= 2; | ||
109 | SLsmg_write_wrapped_string((unsigned char *)text, y, x, | ||
110 | nr_lines, max_len, 1); | ||
111 | y += nr_lines; | ||
112 | len = 5; | ||
113 | while (len--) { | ||
114 | SLsmg_gotorc(y + len - 1, x); | ||
115 | SLsmg_write_nstring((char *)" ", max_len); | ||
116 | } | ||
117 | SLsmg_draw_box(y++, x + 1, 3, max_len - 2); | ||
118 | |||
119 | SLsmg_gotorc(y + 3, x); | ||
120 | SLsmg_write_nstring((char *)exit_msg, max_len); | ||
121 | SLsmg_refresh(); | ||
122 | |||
123 | x += 2; | ||
124 | len = 0; | ||
125 | key = ui__getch(delay_secs); | ||
126 | while (key != K_TIMER && key != K_ENTER && key != K_ESC) { | ||
127 | if (key == K_BKSPC) { | ||
128 | if (len == 0) | ||
129 | goto next_key; | ||
130 | SLsmg_gotorc(y, x + --len); | ||
131 | SLsmg_write_char(' '); | ||
132 | } else { | ||
133 | buf[len] = key; | ||
134 | SLsmg_gotorc(y, x + len++); | ||
135 | SLsmg_write_char(key); | ||
136 | } | ||
137 | SLsmg_refresh(); | ||
138 | |||
139 | /* XXX more graceful overflow handling needed */ | ||
140 | if (len == sizeof(buf) - 1) { | ||
141 | ui_helpline__push("maximum size of symbol name reached!"); | ||
142 | key = K_ENTER; | ||
143 | break; | ||
144 | } | ||
145 | next_key: | ||
146 | key = ui__getch(delay_secs); | ||
147 | } | ||
148 | |||
149 | buf[len] = '\0'; | ||
150 | strncpy(input, buf, len+1); | ||
151 | return key; | ||
152 | } | ||
153 | |||
154 | int ui__question_window(const char *title, const char *text, | ||
155 | const char *exit_msg, int delay_secs) | ||
156 | { | ||
157 | int x, y; | ||
158 | int max_len = 0, nr_lines = 0; | ||
159 | const char *t; | ||
160 | |||
161 | t = text; | ||
162 | while (1) { | ||
163 | const char *sep = strchr(t, '\n'); | ||
164 | int len; | ||
165 | |||
166 | if (sep == NULL) | ||
167 | sep = strchr(t, '\0'); | ||
168 | len = sep - t; | ||
169 | if (max_len < len) | ||
170 | max_len = len; | ||
171 | ++nr_lines; | ||
172 | if (*sep == '\0') | ||
173 | break; | ||
174 | t = sep + 1; | ||
175 | } | ||
176 | |||
177 | max_len += 2; | ||
178 | nr_lines += 4; | ||
179 | y = SLtt_Screen_Rows / 2 - nr_lines / 2, | ||
180 | x = SLtt_Screen_Cols / 2 - max_len / 2; | ||
181 | |||
182 | SLsmg_set_color(0); | ||
183 | SLsmg_draw_box(y, x++, nr_lines, max_len); | ||
184 | if (title) { | ||
185 | SLsmg_gotorc(y, x + 1); | ||
186 | SLsmg_write_string((char *)title); | ||
187 | } | ||
188 | SLsmg_gotorc(++y, x); | ||
189 | nr_lines -= 2; | ||
190 | max_len -= 2; | ||
191 | SLsmg_write_wrapped_string((unsigned char *)text, y, x, | ||
192 | nr_lines, max_len, 1); | ||
193 | SLsmg_gotorc(y + nr_lines - 2, x); | ||
194 | SLsmg_write_nstring((char *)" ", max_len); | ||
195 | SLsmg_gotorc(y + nr_lines - 1, x); | ||
196 | SLsmg_write_nstring((char *)exit_msg, max_len); | ||
197 | SLsmg_refresh(); | ||
198 | return ui__getch(delay_secs); | ||
199 | } | ||
200 | |||
201 | int ui__help_window(const char *text) | ||
202 | { | ||
203 | return ui__question_window("Help", text, "Press any key...", 0); | ||
204 | } | ||
205 | |||
206 | int ui__dialog_yesno(const char *msg) | ||
207 | { | ||
208 | return ui__question_window(NULL, msg, "Enter: Yes, ESC: No", 0); | ||
209 | } | ||
210 | |||
211 | static int __ui__warning(const char *title, const char *format, va_list args) | ||
212 | { | ||
213 | char *s; | ||
214 | |||
215 | if (vasprintf(&s, format, args) > 0) { | ||
216 | int key; | ||
217 | |||
218 | pthread_mutex_lock(&ui__lock); | ||
219 | key = ui__question_window(title, s, "Press any key...", 0); | ||
220 | pthread_mutex_unlock(&ui__lock); | ||
221 | free(s); | ||
222 | return key; | ||
223 | } | ||
224 | |||
225 | fprintf(stderr, "%s\n", title); | ||
226 | vfprintf(stderr, format, args); | ||
227 | return K_ESC; | ||
228 | } | ||
229 | |||
230 | static int perf_tui__error(const char *format, va_list args) | ||
231 | { | ||
232 | return __ui__warning("Error:", format, args); | ||
233 | } | ||
234 | |||
235 | static int perf_tui__warning(const char *format, va_list args) | ||
236 | { | ||
237 | return __ui__warning("Warning:", format, args); | ||
238 | } | ||
239 | |||
240 | struct perf_error_ops perf_tui_eops = { | ||
241 | .error = perf_tui__error, | ||
242 | .warning = perf_tui__warning, | ||
243 | }; | ||
diff --git a/tools/perf/ui/util.c b/tools/perf/ui/util.c index ad4374a16bb0..4f989774c8c6 100644 --- a/tools/perf/ui/util.c +++ b/tools/perf/ui/util.c | |||
@@ -1,250 +1,85 @@ | |||
1 | #include "../util.h" | ||
2 | #include <signal.h> | ||
3 | #include <stdbool.h> | ||
4 | #include <string.h> | ||
5 | #include <sys/ttydefaults.h> | ||
6 | |||
7 | #include "../cache.h" | ||
8 | #include "../debug.h" | ||
9 | #include "browser.h" | ||
10 | #include "keysyms.h" | ||
11 | #include "helpline.h" | ||
12 | #include "ui.h" | ||
13 | #include "util.h" | 1 | #include "util.h" |
14 | #include "libslang.h" | 2 | #include "../debug.h" |
15 | |||
16 | static void ui_browser__argv_write(struct ui_browser *browser, | ||
17 | void *entry, int row) | ||
18 | { | ||
19 | char **arg = entry; | ||
20 | bool current_entry = ui_browser__is_current_entry(browser, row); | ||
21 | |||
22 | ui_browser__set_color(browser, current_entry ? HE_COLORSET_SELECTED : | ||
23 | HE_COLORSET_NORMAL); | ||
24 | slsmg_write_nstring(*arg, browser->width); | ||
25 | } | ||
26 | |||
27 | static int popup_menu__run(struct ui_browser *menu) | ||
28 | { | ||
29 | int key; | ||
30 | |||
31 | if (ui_browser__show(menu, " ", "ESC: exit, ENTER|->: Select option") < 0) | ||
32 | return -1; | ||
33 | 3 | ||
34 | while (1) { | ||
35 | key = ui_browser__run(menu, 0); | ||
36 | |||
37 | switch (key) { | ||
38 | case K_RIGHT: | ||
39 | case K_ENTER: | ||
40 | key = menu->index; | ||
41 | break; | ||
42 | case K_LEFT: | ||
43 | case K_ESC: | ||
44 | case 'q': | ||
45 | case CTRL('c'): | ||
46 | key = -1; | ||
47 | break; | ||
48 | default: | ||
49 | continue; | ||
50 | } | ||
51 | |||
52 | break; | ||
53 | } | ||
54 | |||
55 | ui_browser__hide(menu); | ||
56 | return key; | ||
57 | } | ||
58 | 4 | ||
59 | int ui__popup_menu(int argc, char * const argv[]) | 5 | /* |
6 | * Default error logging functions | ||
7 | */ | ||
8 | static int perf_stdio__error(const char *format, va_list args) | ||
60 | { | 9 | { |
61 | struct ui_browser menu = { | 10 | fprintf(stderr, "Error:\n"); |
62 | .entries = (void *)argv, | 11 | vfprintf(stderr, format, args); |
63 | .refresh = ui_browser__argv_refresh, | 12 | return 0; |
64 | .seek = ui_browser__argv_seek, | ||
65 | .write = ui_browser__argv_write, | ||
66 | .nr_entries = argc, | ||
67 | }; | ||
68 | |||
69 | return popup_menu__run(&menu); | ||
70 | } | 13 | } |
71 | 14 | ||
72 | int ui_browser__input_window(const char *title, const char *text, char *input, | 15 | static int perf_stdio__warning(const char *format, va_list args) |
73 | const char *exit_msg, int delay_secs) | ||
74 | { | 16 | { |
75 | int x, y, len, key; | 17 | fprintf(stderr, "Warning:\n"); |
76 | int max_len = 60, nr_lines = 0; | 18 | vfprintf(stderr, format, args); |
77 | static char buf[50]; | 19 | return 0; |
78 | const char *t; | ||
79 | |||
80 | t = text; | ||
81 | while (1) { | ||
82 | const char *sep = strchr(t, '\n'); | ||
83 | |||
84 | if (sep == NULL) | ||
85 | sep = strchr(t, '\0'); | ||
86 | len = sep - t; | ||
87 | if (max_len < len) | ||
88 | max_len = len; | ||
89 | ++nr_lines; | ||
90 | if (*sep == '\0') | ||
91 | break; | ||
92 | t = sep + 1; | ||
93 | } | ||
94 | |||
95 | max_len += 2; | ||
96 | nr_lines += 8; | ||
97 | y = SLtt_Screen_Rows / 2 - nr_lines / 2; | ||
98 | x = SLtt_Screen_Cols / 2 - max_len / 2; | ||
99 | |||
100 | SLsmg_set_color(0); | ||
101 | SLsmg_draw_box(y, x++, nr_lines, max_len); | ||
102 | if (title) { | ||
103 | SLsmg_gotorc(y, x + 1); | ||
104 | SLsmg_write_string((char *)title); | ||
105 | } | ||
106 | SLsmg_gotorc(++y, x); | ||
107 | nr_lines -= 7; | ||
108 | max_len -= 2; | ||
109 | SLsmg_write_wrapped_string((unsigned char *)text, y, x, | ||
110 | nr_lines, max_len, 1); | ||
111 | y += nr_lines; | ||
112 | len = 5; | ||
113 | while (len--) { | ||
114 | SLsmg_gotorc(y + len - 1, x); | ||
115 | SLsmg_write_nstring((char *)" ", max_len); | ||
116 | } | ||
117 | SLsmg_draw_box(y++, x + 1, 3, max_len - 2); | ||
118 | |||
119 | SLsmg_gotorc(y + 3, x); | ||
120 | SLsmg_write_nstring((char *)exit_msg, max_len); | ||
121 | SLsmg_refresh(); | ||
122 | |||
123 | x += 2; | ||
124 | len = 0; | ||
125 | key = ui__getch(delay_secs); | ||
126 | while (key != K_TIMER && key != K_ENTER && key != K_ESC) { | ||
127 | if (key == K_BKSPC) { | ||
128 | if (len == 0) | ||
129 | goto next_key; | ||
130 | SLsmg_gotorc(y, x + --len); | ||
131 | SLsmg_write_char(' '); | ||
132 | } else { | ||
133 | buf[len] = key; | ||
134 | SLsmg_gotorc(y, x + len++); | ||
135 | SLsmg_write_char(key); | ||
136 | } | ||
137 | SLsmg_refresh(); | ||
138 | |||
139 | /* XXX more graceful overflow handling needed */ | ||
140 | if (len == sizeof(buf) - 1) { | ||
141 | ui_helpline__push("maximum size of symbol name reached!"); | ||
142 | key = K_ENTER; | ||
143 | break; | ||
144 | } | ||
145 | next_key: | ||
146 | key = ui__getch(delay_secs); | ||
147 | } | ||
148 | |||
149 | buf[len] = '\0'; | ||
150 | strncpy(input, buf, len+1); | ||
151 | return key; | ||
152 | } | 20 | } |
153 | 21 | ||
154 | int ui__question_window(const char *title, const char *text, | 22 | static struct perf_error_ops default_eops = |
155 | const char *exit_msg, int delay_secs) | ||
156 | { | 23 | { |
157 | int x, y; | 24 | .error = perf_stdio__error, |
158 | int max_len = 0, nr_lines = 0; | 25 | .warning = perf_stdio__warning, |
159 | const char *t; | 26 | }; |
160 | |||
161 | t = text; | ||
162 | while (1) { | ||
163 | const char *sep = strchr(t, '\n'); | ||
164 | int len; | ||
165 | |||
166 | if (sep == NULL) | ||
167 | sep = strchr(t, '\0'); | ||
168 | len = sep - t; | ||
169 | if (max_len < len) | ||
170 | max_len = len; | ||
171 | ++nr_lines; | ||
172 | if (*sep == '\0') | ||
173 | break; | ||
174 | t = sep + 1; | ||
175 | } | ||
176 | |||
177 | max_len += 2; | ||
178 | nr_lines += 4; | ||
179 | y = SLtt_Screen_Rows / 2 - nr_lines / 2, | ||
180 | x = SLtt_Screen_Cols / 2 - max_len / 2; | ||
181 | |||
182 | SLsmg_set_color(0); | ||
183 | SLsmg_draw_box(y, x++, nr_lines, max_len); | ||
184 | if (title) { | ||
185 | SLsmg_gotorc(y, x + 1); | ||
186 | SLsmg_write_string((char *)title); | ||
187 | } | ||
188 | SLsmg_gotorc(++y, x); | ||
189 | nr_lines -= 2; | ||
190 | max_len -= 2; | ||
191 | SLsmg_write_wrapped_string((unsigned char *)text, y, x, | ||
192 | nr_lines, max_len, 1); | ||
193 | SLsmg_gotorc(y + nr_lines - 2, x); | ||
194 | SLsmg_write_nstring((char *)" ", max_len); | ||
195 | SLsmg_gotorc(y + nr_lines - 1, x); | ||
196 | SLsmg_write_nstring((char *)exit_msg, max_len); | ||
197 | SLsmg_refresh(); | ||
198 | return ui__getch(delay_secs); | ||
199 | } | ||
200 | 27 | ||
201 | int ui__help_window(const char *text) | 28 | static struct perf_error_ops *perf_eops = &default_eops; |
202 | { | ||
203 | return ui__question_window("Help", text, "Press any key...", 0); | ||
204 | } | ||
205 | 29 | ||
206 | int ui__dialog_yesno(const char *msg) | ||
207 | { | ||
208 | return ui__question_window(NULL, msg, "Enter: Yes, ESC: No", 0); | ||
209 | } | ||
210 | 30 | ||
211 | int __ui__warning(const char *title, const char *format, va_list args) | 31 | int ui__error(const char *format, ...) |
212 | { | 32 | { |
213 | char *s; | 33 | int ret; |
214 | 34 | va_list args; | |
215 | if (use_browser > 0 && vasprintf(&s, format, args) > 0) { | ||
216 | int key; | ||
217 | 35 | ||
218 | pthread_mutex_lock(&ui__lock); | 36 | va_start(args, format); |
219 | key = ui__question_window(title, s, "Press any key...", 0); | 37 | ret = perf_eops->error(format, args); |
220 | pthread_mutex_unlock(&ui__lock); | 38 | va_end(args); |
221 | free(s); | ||
222 | return key; | ||
223 | } | ||
224 | 39 | ||
225 | fprintf(stderr, "%s:\n", title); | 40 | return ret; |
226 | vfprintf(stderr, format, args); | ||
227 | return K_ESC; | ||
228 | } | 41 | } |
229 | 42 | ||
230 | int ui__warning(const char *format, ...) | 43 | int ui__warning(const char *format, ...) |
231 | { | 44 | { |
232 | int key; | 45 | int ret; |
233 | va_list args; | 46 | va_list args; |
234 | 47 | ||
235 | va_start(args, format); | 48 | va_start(args, format); |
236 | key = __ui__warning("Warning", format, args); | 49 | ret = perf_eops->warning(format, args); |
237 | va_end(args); | 50 | va_end(args); |
238 | return key; | 51 | |
52 | return ret; | ||
239 | } | 53 | } |
240 | 54 | ||
241 | int ui__error(const char *format, ...) | 55 | |
56 | /** | ||
57 | * perf_error__register - Register error logging functions | ||
58 | * @eops: The pointer to error logging function struct | ||
59 | * | ||
60 | * Register UI-specific error logging functions. Before calling this, | ||
61 | * other logging functions should be unregistered, if any. | ||
62 | */ | ||
63 | int perf_error__register(struct perf_error_ops *eops) | ||
242 | { | 64 | { |
243 | int key; | 65 | if (perf_eops != &default_eops) |
244 | va_list args; | 66 | return -1; |
245 | 67 | ||
246 | va_start(args, format); | 68 | perf_eops = eops; |
247 | key = __ui__warning("Error", format, args); | 69 | return 0; |
248 | va_end(args); | 70 | } |
249 | return key; | 71 | |
72 | /** | ||
73 | * perf_error__unregister - Unregister error logging functions | ||
74 | * @eops: The pointer to error logging function struct | ||
75 | * | ||
76 | * Unregister already registered error logging functions. | ||
77 | */ | ||
78 | int perf_error__unregister(struct perf_error_ops *eops) | ||
79 | { | ||
80 | if (perf_eops != eops) | ||
81 | return -1; | ||
82 | |||
83 | perf_eops = &default_eops; | ||
84 | return 0; | ||
250 | } | 85 | } |
diff --git a/tools/perf/ui/util.h b/tools/perf/ui/util.h index 2d1738bd71c8..361f08c52d37 100644 --- a/tools/perf/ui/util.h +++ b/tools/perf/ui/util.h | |||
@@ -9,6 +9,13 @@ int ui__help_window(const char *text); | |||
9 | int ui__dialog_yesno(const char *msg); | 9 | int ui__dialog_yesno(const char *msg); |
10 | int ui__question_window(const char *title, const char *text, | 10 | int ui__question_window(const char *title, const char *text, |
11 | const char *exit_msg, int delay_secs); | 11 | const char *exit_msg, int delay_secs); |
12 | int __ui__warning(const char *title, const char *format, va_list args); | 12 | |
13 | struct perf_error_ops { | ||
14 | int (*error)(const char *format, va_list args); | ||
15 | int (*warning)(const char *format, va_list args); | ||
16 | }; | ||
17 | |||
18 | int perf_error__register(struct perf_error_ops *eops); | ||
19 | int perf_error__unregister(struct perf_error_ops *eops); | ||
13 | 20 | ||
14 | #endif /* _PERF_UI_UTIL_H_ */ | 21 | #endif /* _PERF_UI_UTIL_H_ */ |
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index 8069dfb5ba77..3a282c0057d2 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c | |||
@@ -426,7 +426,18 @@ int symbol__alloc_hist(struct symbol *sym) | |||
426 | { | 426 | { |
427 | struct annotation *notes = symbol__annotation(sym); | 427 | struct annotation *notes = symbol__annotation(sym); |
428 | const size_t size = symbol__size(sym); | 428 | const size_t size = symbol__size(sym); |
429 | size_t sizeof_sym_hist = (sizeof(struct sym_hist) + size * sizeof(u64)); | 429 | size_t sizeof_sym_hist; |
430 | |||
431 | /* Check for overflow when calculating sizeof_sym_hist */ | ||
432 | if (size > (SIZE_MAX - sizeof(struct sym_hist)) / sizeof(u64)) | ||
433 | return -1; | ||
434 | |||
435 | sizeof_sym_hist = (sizeof(struct sym_hist) + size * sizeof(u64)); | ||
436 | |||
437 | /* Check for overflow in zalloc argument */ | ||
438 | if (sizeof_sym_hist > (SIZE_MAX - sizeof(*notes->src)) | ||
439 | / symbol_conf.nr_events) | ||
440 | return -1; | ||
430 | 441 | ||
431 | notes->src = zalloc(sizeof(*notes->src) + symbol_conf.nr_events * sizeof_sym_hist); | 442 | notes->src = zalloc(sizeof(*notes->src) + symbol_conf.nr_events * sizeof_sym_hist); |
432 | if (notes->src == NULL) | 443 | if (notes->src == NULL) |
@@ -777,7 +788,7 @@ fallback: | |||
777 | free_filename = false; | 788 | free_filename = false; |
778 | } | 789 | } |
779 | 790 | ||
780 | if (dso->symtab_type == SYMTAB__KALLSYMS) { | 791 | if (dso->symtab_type == DSO_BINARY_TYPE__KALLSYMS) { |
781 | char bf[BUILD_ID_SIZE * 2 + 16] = " with build id "; | 792 | char bf[BUILD_ID_SIZE * 2 + 16] = " with build id "; |
782 | char *build_id_msg = NULL; | 793 | char *build_id_msg = NULL; |
783 | 794 | ||
diff --git a/tools/perf/util/debug.c b/tools/perf/util/debug.c index efb1fce259a4..4dfe0bb3c322 100644 --- a/tools/perf/util/debug.c +++ b/tools/perf/util/debug.c | |||
@@ -47,7 +47,7 @@ int dump_printf(const char *fmt, ...) | |||
47 | return ret; | 47 | return ret; |
48 | } | 48 | } |
49 | 49 | ||
50 | #ifdef NO_NEWT_SUPPORT | 50 | #if defined(NO_NEWT_SUPPORT) && defined(NO_GTK2_SUPPORT) |
51 | int ui__warning(const char *format, ...) | 51 | int ui__warning(const char *format, ...) |
52 | { | 52 | { |
53 | va_list args; | 53 | va_list args; |
diff --git a/tools/perf/util/debug.h b/tools/perf/util/debug.h index 6bebe7f0a20c..015c91dbc096 100644 --- a/tools/perf/util/debug.h +++ b/tools/perf/util/debug.h | |||
@@ -12,8 +12,9 @@ int dump_printf(const char *fmt, ...) __attribute__((format(printf, 1, 2))); | |||
12 | void trace_event(union perf_event *event); | 12 | void trace_event(union perf_event *event); |
13 | 13 | ||
14 | struct ui_progress; | 14 | struct ui_progress; |
15 | struct perf_error_ops; | ||
15 | 16 | ||
16 | #ifdef NO_NEWT_SUPPORT | 17 | #if defined(NO_NEWT_SUPPORT) && defined(NO_GTK2_SUPPORT) |
17 | static inline int ui_helpline__show_help(const char *format __used, va_list ap __used) | 18 | static inline int ui_helpline__show_help(const char *format __used, va_list ap __used) |
18 | { | 19 | { |
19 | return 0; | 20 | return 0; |
@@ -23,12 +24,28 @@ static inline void ui_progress__update(u64 curr __used, u64 total __used, | |||
23 | const char *title __used) {} | 24 | const char *title __used) {} |
24 | 25 | ||
25 | #define ui__error(format, arg...) ui__warning(format, ##arg) | 26 | #define ui__error(format, arg...) ui__warning(format, ##arg) |
26 | #else | 27 | |
28 | static inline int | ||
29 | perf_error__register(struct perf_error_ops *eops __used) | ||
30 | { | ||
31 | return 0; | ||
32 | } | ||
33 | |||
34 | static inline int | ||
35 | perf_error__unregister(struct perf_error_ops *eops __used) | ||
36 | { | ||
37 | return 0; | ||
38 | } | ||
39 | |||
40 | #else /* NO_NEWT_SUPPORT && NO_GTK2_SUPPORT */ | ||
41 | |||
27 | extern char ui_helpline__last_msg[]; | 42 | extern char ui_helpline__last_msg[]; |
28 | int ui_helpline__show_help(const char *format, va_list ap); | 43 | int ui_helpline__show_help(const char *format, va_list ap); |
29 | #include "../ui/progress.h" | 44 | #include "../ui/progress.h" |
30 | int ui__error(const char *format, ...) __attribute__((format(printf, 1, 2))); | 45 | int ui__error(const char *format, ...) __attribute__((format(printf, 1, 2))); |
31 | #endif | 46 | #include "../ui/util.h" |
47 | |||
48 | #endif /* NO_NEWT_SUPPORT && NO_GTK2_SUPPORT */ | ||
32 | 49 | ||
33 | int ui__warning(const char *format, ...) __attribute__((format(printf, 1, 2))); | 50 | int ui__warning(const char *format, ...) __attribute__((format(printf, 1, 2))); |
34 | int ui__error_paranoid(void); | 51 | int ui__error_paranoid(void); |
diff --git a/tools/perf/util/dso-test-data.c b/tools/perf/util/dso-test-data.c new file mode 100644 index 000000000000..541cdc72c7df --- /dev/null +++ b/tools/perf/util/dso-test-data.c | |||
@@ -0,0 +1,153 @@ | |||
1 | #include "util.h" | ||
2 | |||
3 | #include <stdlib.h> | ||
4 | #include <sys/types.h> | ||
5 | #include <sys/stat.h> | ||
6 | #include <fcntl.h> | ||
7 | #include <string.h> | ||
8 | |||
9 | #include "symbol.h" | ||
10 | |||
11 | #define TEST_ASSERT_VAL(text, cond) \ | ||
12 | do { \ | ||
13 | if (!(cond)) { \ | ||
14 | pr_debug("FAILED %s:%d %s\n", __FILE__, __LINE__, text); \ | ||
15 | return -1; \ | ||
16 | } \ | ||
17 | } while (0) | ||
18 | |||
19 | static char *test_file(int size) | ||
20 | { | ||
21 | static char buf_templ[] = "/tmp/test-XXXXXX"; | ||
22 | char *templ = buf_templ; | ||
23 | int fd, i; | ||
24 | unsigned char *buf; | ||
25 | |||
26 | fd = mkostemp(templ, O_CREAT|O_WRONLY|O_TRUNC); | ||
27 | |||
28 | buf = malloc(size); | ||
29 | if (!buf) { | ||
30 | close(fd); | ||
31 | return NULL; | ||
32 | } | ||
33 | |||
34 | for (i = 0; i < size; i++) | ||
35 | buf[i] = (unsigned char) ((int) i % 10); | ||
36 | |||
37 | if (size != write(fd, buf, size)) | ||
38 | templ = NULL; | ||
39 | |||
40 | close(fd); | ||
41 | return templ; | ||
42 | } | ||
43 | |||
44 | #define TEST_FILE_SIZE (DSO__DATA_CACHE_SIZE * 20) | ||
45 | |||
46 | struct test_data_offset { | ||
47 | off_t offset; | ||
48 | u8 data[10]; | ||
49 | int size; | ||
50 | }; | ||
51 | |||
52 | struct test_data_offset offsets[] = { | ||
53 | /* Fill first cache page. */ | ||
54 | { | ||
55 | .offset = 10, | ||
56 | .data = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, | ||
57 | .size = 10, | ||
58 | }, | ||
59 | /* Read first cache page. */ | ||
60 | { | ||
61 | .offset = 10, | ||
62 | .data = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, | ||
63 | .size = 10, | ||
64 | }, | ||
65 | /* Fill cache boundary pages. */ | ||
66 | { | ||
67 | .offset = DSO__DATA_CACHE_SIZE - DSO__DATA_CACHE_SIZE % 10, | ||
68 | .data = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, | ||
69 | .size = 10, | ||
70 | }, | ||
71 | /* Read cache boundary pages. */ | ||
72 | { | ||
73 | .offset = DSO__DATA_CACHE_SIZE - DSO__DATA_CACHE_SIZE % 10, | ||
74 | .data = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, | ||
75 | .size = 10, | ||
76 | }, | ||
77 | /* Fill final cache page. */ | ||
78 | { | ||
79 | .offset = TEST_FILE_SIZE - 10, | ||
80 | .data = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, | ||
81 | .size = 10, | ||
82 | }, | ||
83 | /* Read final cache page. */ | ||
84 | { | ||
85 | .offset = TEST_FILE_SIZE - 10, | ||
86 | .data = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, | ||
87 | .size = 10, | ||
88 | }, | ||
89 | /* Read final cache page. */ | ||
90 | { | ||
91 | .offset = TEST_FILE_SIZE - 3, | ||
92 | .data = { 7, 8, 9, 0, 0, 0, 0, 0, 0, 0 }, | ||
93 | .size = 3, | ||
94 | }, | ||
95 | }; | ||
96 | |||
97 | int dso__test_data(void) | ||
98 | { | ||
99 | struct machine machine; | ||
100 | struct dso *dso; | ||
101 | char *file = test_file(TEST_FILE_SIZE); | ||
102 | size_t i; | ||
103 | |||
104 | TEST_ASSERT_VAL("No test file", file); | ||
105 | |||
106 | memset(&machine, 0, sizeof(machine)); | ||
107 | |||
108 | dso = dso__new((const char *)file); | ||
109 | |||
110 | /* Basic 10 bytes tests. */ | ||
111 | for (i = 0; i < ARRAY_SIZE(offsets); i++) { | ||
112 | struct test_data_offset *data = &offsets[i]; | ||
113 | ssize_t size; | ||
114 | u8 buf[10]; | ||
115 | |||
116 | memset(buf, 0, 10); | ||
117 | size = dso__data_read_offset(dso, &machine, data->offset, | ||
118 | buf, 10); | ||
119 | |||
120 | TEST_ASSERT_VAL("Wrong size", size == data->size); | ||
121 | TEST_ASSERT_VAL("Wrong data", !memcmp(buf, data->data, 10)); | ||
122 | } | ||
123 | |||
124 | /* Read cross multiple cache pages. */ | ||
125 | { | ||
126 | ssize_t size; | ||
127 | int c; | ||
128 | u8 *buf; | ||
129 | |||
130 | buf = malloc(TEST_FILE_SIZE); | ||
131 | TEST_ASSERT_VAL("ENOMEM\n", buf); | ||
132 | |||
133 | /* First iteration to fill caches, second one to read them. */ | ||
134 | for (c = 0; c < 2; c++) { | ||
135 | memset(buf, 0, TEST_FILE_SIZE); | ||
136 | size = dso__data_read_offset(dso, &machine, 10, | ||
137 | buf, TEST_FILE_SIZE); | ||
138 | |||
139 | TEST_ASSERT_VAL("Wrong size", | ||
140 | size == (TEST_FILE_SIZE - 10)); | ||
141 | |||
142 | for (i = 0; i < (size_t)size; i++) | ||
143 | TEST_ASSERT_VAL("Wrong data", | ||
144 | buf[i] == (i % 10)); | ||
145 | } | ||
146 | |||
147 | free(buf); | ||
148 | } | ||
149 | |||
150 | dso__delete(dso); | ||
151 | unlink(file); | ||
152 | return 0; | ||
153 | } | ||
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index 7400fb3fc50c..3edfd3483816 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c | |||
@@ -214,7 +214,7 @@ int perf_evlist__add_tracepoints(struct perf_evlist *evlist, | |||
214 | attrs[i].type = PERF_TYPE_TRACEPOINT; | 214 | attrs[i].type = PERF_TYPE_TRACEPOINT; |
215 | attrs[i].config = err; | 215 | attrs[i].config = err; |
216 | attrs[i].sample_type = (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME | | 216 | attrs[i].sample_type = (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME | |
217 | PERF_SAMPLE_CPU); | 217 | PERF_SAMPLE_CPU | PERF_SAMPLE_PERIOD); |
218 | attrs[i].sample_period = 1; | 218 | attrs[i].sample_period = 1; |
219 | } | 219 | } |
220 | 220 | ||
@@ -224,8 +224,8 @@ out_free_attrs: | |||
224 | return err; | 224 | return err; |
225 | } | 225 | } |
226 | 226 | ||
227 | static struct perf_evsel * | 227 | struct perf_evsel * |
228 | perf_evlist__find_tracepoint_by_id(struct perf_evlist *evlist, int id) | 228 | perf_evlist__find_tracepoint_by_id(struct perf_evlist *evlist, int id) |
229 | { | 229 | { |
230 | struct perf_evsel *evsel; | 230 | struct perf_evsel *evsel; |
231 | 231 | ||
diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h index 989bee9624c2..40d4d3cdced0 100644 --- a/tools/perf/util/evlist.h +++ b/tools/perf/util/evlist.h | |||
@@ -73,6 +73,9 @@ int perf_evlist__set_tracepoints_handlers(struct perf_evlist *evlist, | |||
73 | #define perf_evlist__set_tracepoints_handlers_array(evlist, array) \ | 73 | #define perf_evlist__set_tracepoints_handlers_array(evlist, array) \ |
74 | perf_evlist__set_tracepoints_handlers(evlist, array, ARRAY_SIZE(array)) | 74 | perf_evlist__set_tracepoints_handlers(evlist, array, ARRAY_SIZE(array)) |
75 | 75 | ||
76 | struct perf_evsel * | ||
77 | perf_evlist__find_tracepoint_by_id(struct perf_evlist *evlist, int id); | ||
78 | |||
76 | void perf_evlist__id_add(struct perf_evlist *evlist, struct perf_evsel *evsel, | 79 | void perf_evlist__id_add(struct perf_evlist *evlist, struct perf_evsel *evsel, |
77 | int cpu, int thread, u64 id); | 80 | int cpu, int thread, u64 id); |
78 | 81 | ||
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 9f6cebd798ee..e81771364867 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c | |||
@@ -15,7 +15,7 @@ | |||
15 | #include "cpumap.h" | 15 | #include "cpumap.h" |
16 | #include "thread_map.h" | 16 | #include "thread_map.h" |
17 | #include "target.h" | 17 | #include "target.h" |
18 | #include "../../include/linux/perf_event.h" | 18 | #include "../../../include/linux/hw_breakpoint.h" |
19 | 19 | ||
20 | #define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y)) | 20 | #define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y)) |
21 | #define GROUP_FD(group_fd, cpu) (*(int *)xyarray__entry(group_fd, cpu, 0)) | 21 | #define GROUP_FD(group_fd, cpu) (*(int *)xyarray__entry(group_fd, cpu, 0)) |
@@ -78,7 +78,7 @@ static const char *perf_evsel__hw_names[PERF_COUNT_HW_MAX] = { | |||
78 | "ref-cycles", | 78 | "ref-cycles", |
79 | }; | 79 | }; |
80 | 80 | ||
81 | const char *__perf_evsel__hw_name(u64 config) | 81 | static const char *__perf_evsel__hw_name(u64 config) |
82 | { | 82 | { |
83 | if (config < PERF_COUNT_HW_MAX && perf_evsel__hw_names[config]) | 83 | if (config < PERF_COUNT_HW_MAX && perf_evsel__hw_names[config]) |
84 | return perf_evsel__hw_names[config]; | 84 | return perf_evsel__hw_names[config]; |
@@ -86,16 +86,15 @@ const char *__perf_evsel__hw_name(u64 config) | |||
86 | return "unknown-hardware"; | 86 | return "unknown-hardware"; |
87 | } | 87 | } |
88 | 88 | ||
89 | static int perf_evsel__hw_name(struct perf_evsel *evsel, char *bf, size_t size) | 89 | static int perf_evsel__add_modifiers(struct perf_evsel *evsel, char *bf, size_t size) |
90 | { | 90 | { |
91 | int colon = 0; | 91 | int colon = 0, r = 0; |
92 | struct perf_event_attr *attr = &evsel->attr; | 92 | struct perf_event_attr *attr = &evsel->attr; |
93 | int r = scnprintf(bf, size, "%s", __perf_evsel__hw_name(attr->config)); | ||
94 | bool exclude_guest_default = false; | 93 | bool exclude_guest_default = false; |
95 | 94 | ||
96 | #define MOD_PRINT(context, mod) do { \ | 95 | #define MOD_PRINT(context, mod) do { \ |
97 | if (!attr->exclude_##context) { \ | 96 | if (!attr->exclude_##context) { \ |
98 | if (!colon) colon = r++; \ | 97 | if (!colon) colon = ++r; \ |
99 | r += scnprintf(bf + r, size - r, "%c", mod); \ | 98 | r += scnprintf(bf + r, size - r, "%c", mod); \ |
100 | } } while(0) | 99 | } } while(0) |
101 | 100 | ||
@@ -108,7 +107,7 @@ static int perf_evsel__hw_name(struct perf_evsel *evsel, char *bf, size_t size) | |||
108 | 107 | ||
109 | if (attr->precise_ip) { | 108 | if (attr->precise_ip) { |
110 | if (!colon) | 109 | if (!colon) |
111 | colon = r++; | 110 | colon = ++r; |
112 | r += scnprintf(bf + r, size - r, "%.*s", attr->precise_ip, "ppp"); | 111 | r += scnprintf(bf + r, size - r, "%.*s", attr->precise_ip, "ppp"); |
113 | exclude_guest_default = true; | 112 | exclude_guest_default = true; |
114 | } | 113 | } |
@@ -119,39 +118,211 @@ static int perf_evsel__hw_name(struct perf_evsel *evsel, char *bf, size_t size) | |||
119 | } | 118 | } |
120 | #undef MOD_PRINT | 119 | #undef MOD_PRINT |
121 | if (colon) | 120 | if (colon) |
122 | bf[colon] = ':'; | 121 | bf[colon - 1] = ':'; |
123 | return r; | 122 | return r; |
124 | } | 123 | } |
125 | 124 | ||
126 | int perf_evsel__name(struct perf_evsel *evsel, char *bf, size_t size) | 125 | static int perf_evsel__hw_name(struct perf_evsel *evsel, char *bf, size_t size) |
126 | { | ||
127 | int r = scnprintf(bf, size, "%s", __perf_evsel__hw_name(evsel->attr.config)); | ||
128 | return r + perf_evsel__add_modifiers(evsel, bf + r, size - r); | ||
129 | } | ||
130 | |||
131 | static const char *perf_evsel__sw_names[PERF_COUNT_SW_MAX] = { | ||
132 | "cpu-clock", | ||
133 | "task-clock", | ||
134 | "page-faults", | ||
135 | "context-switches", | ||
136 | "CPU-migrations", | ||
137 | "minor-faults", | ||
138 | "major-faults", | ||
139 | "alignment-faults", | ||
140 | "emulation-faults", | ||
141 | }; | ||
142 | |||
143 | static const char *__perf_evsel__sw_name(u64 config) | ||
127 | { | 144 | { |
128 | int ret; | 145 | if (config < PERF_COUNT_SW_MAX && perf_evsel__sw_names[config]) |
146 | return perf_evsel__sw_names[config]; | ||
147 | return "unknown-software"; | ||
148 | } | ||
149 | |||
150 | static int perf_evsel__sw_name(struct perf_evsel *evsel, char *bf, size_t size) | ||
151 | { | ||
152 | int r = scnprintf(bf, size, "%s", __perf_evsel__sw_name(evsel->attr.config)); | ||
153 | return r + perf_evsel__add_modifiers(evsel, bf + r, size - r); | ||
154 | } | ||
155 | |||
156 | static int __perf_evsel__bp_name(char *bf, size_t size, u64 addr, u64 type) | ||
157 | { | ||
158 | int r; | ||
159 | |||
160 | r = scnprintf(bf, size, "mem:0x%" PRIx64 ":", addr); | ||
161 | |||
162 | if (type & HW_BREAKPOINT_R) | ||
163 | r += scnprintf(bf + r, size - r, "r"); | ||
164 | |||
165 | if (type & HW_BREAKPOINT_W) | ||
166 | r += scnprintf(bf + r, size - r, "w"); | ||
167 | |||
168 | if (type & HW_BREAKPOINT_X) | ||
169 | r += scnprintf(bf + r, size - r, "x"); | ||
170 | |||
171 | return r; | ||
172 | } | ||
173 | |||
174 | static int perf_evsel__bp_name(struct perf_evsel *evsel, char *bf, size_t size) | ||
175 | { | ||
176 | struct perf_event_attr *attr = &evsel->attr; | ||
177 | int r = __perf_evsel__bp_name(bf, size, attr->bp_addr, attr->bp_type); | ||
178 | return r + perf_evsel__add_modifiers(evsel, bf + r, size - r); | ||
179 | } | ||
180 | |||
181 | const char *perf_evsel__hw_cache[PERF_COUNT_HW_CACHE_MAX] | ||
182 | [PERF_EVSEL__MAX_ALIASES] = { | ||
183 | { "L1-dcache", "l1-d", "l1d", "L1-data", }, | ||
184 | { "L1-icache", "l1-i", "l1i", "L1-instruction", }, | ||
185 | { "LLC", "L2", }, | ||
186 | { "dTLB", "d-tlb", "Data-TLB", }, | ||
187 | { "iTLB", "i-tlb", "Instruction-TLB", }, | ||
188 | { "branch", "branches", "bpu", "btb", "bpc", }, | ||
189 | { "node", }, | ||
190 | }; | ||
191 | |||
192 | const char *perf_evsel__hw_cache_op[PERF_COUNT_HW_CACHE_OP_MAX] | ||
193 | [PERF_EVSEL__MAX_ALIASES] = { | ||
194 | { "load", "loads", "read", }, | ||
195 | { "store", "stores", "write", }, | ||
196 | { "prefetch", "prefetches", "speculative-read", "speculative-load", }, | ||
197 | }; | ||
198 | |||
199 | const char *perf_evsel__hw_cache_result[PERF_COUNT_HW_CACHE_RESULT_MAX] | ||
200 | [PERF_EVSEL__MAX_ALIASES] = { | ||
201 | { "refs", "Reference", "ops", "access", }, | ||
202 | { "misses", "miss", }, | ||
203 | }; | ||
204 | |||
205 | #define C(x) PERF_COUNT_HW_CACHE_##x | ||
206 | #define CACHE_READ (1 << C(OP_READ)) | ||
207 | #define CACHE_WRITE (1 << C(OP_WRITE)) | ||
208 | #define CACHE_PREFETCH (1 << C(OP_PREFETCH)) | ||
209 | #define COP(x) (1 << x) | ||
210 | |||
211 | /* | ||
212 | * cache operartion stat | ||
213 | * L1I : Read and prefetch only | ||
214 | * ITLB and BPU : Read-only | ||
215 | */ | ||
216 | static unsigned long perf_evsel__hw_cache_stat[C(MAX)] = { | ||
217 | [C(L1D)] = (CACHE_READ | CACHE_WRITE | CACHE_PREFETCH), | ||
218 | [C(L1I)] = (CACHE_READ | CACHE_PREFETCH), | ||
219 | [C(LL)] = (CACHE_READ | CACHE_WRITE | CACHE_PREFETCH), | ||
220 | [C(DTLB)] = (CACHE_READ | CACHE_WRITE | CACHE_PREFETCH), | ||
221 | [C(ITLB)] = (CACHE_READ), | ||
222 | [C(BPU)] = (CACHE_READ), | ||
223 | [C(NODE)] = (CACHE_READ | CACHE_WRITE | CACHE_PREFETCH), | ||
224 | }; | ||
225 | |||
226 | bool perf_evsel__is_cache_op_valid(u8 type, u8 op) | ||
227 | { | ||
228 | if (perf_evsel__hw_cache_stat[type] & COP(op)) | ||
229 | return true; /* valid */ | ||
230 | else | ||
231 | return false; /* invalid */ | ||
232 | } | ||
233 | |||
234 | int __perf_evsel__hw_cache_type_op_res_name(u8 type, u8 op, u8 result, | ||
235 | char *bf, size_t size) | ||
236 | { | ||
237 | if (result) { | ||
238 | return scnprintf(bf, size, "%s-%s-%s", perf_evsel__hw_cache[type][0], | ||
239 | perf_evsel__hw_cache_op[op][0], | ||
240 | perf_evsel__hw_cache_result[result][0]); | ||
241 | } | ||
242 | |||
243 | return scnprintf(bf, size, "%s-%s", perf_evsel__hw_cache[type][0], | ||
244 | perf_evsel__hw_cache_op[op][1]); | ||
245 | } | ||
246 | |||
247 | static int __perf_evsel__hw_cache_name(u64 config, char *bf, size_t size) | ||
248 | { | ||
249 | u8 op, result, type = (config >> 0) & 0xff; | ||
250 | const char *err = "unknown-ext-hardware-cache-type"; | ||
251 | |||
252 | if (type > PERF_COUNT_HW_CACHE_MAX) | ||
253 | goto out_err; | ||
254 | |||
255 | op = (config >> 8) & 0xff; | ||
256 | err = "unknown-ext-hardware-cache-op"; | ||
257 | if (op > PERF_COUNT_HW_CACHE_OP_MAX) | ||
258 | goto out_err; | ||
259 | |||
260 | result = (config >> 16) & 0xff; | ||
261 | err = "unknown-ext-hardware-cache-result"; | ||
262 | if (result > PERF_COUNT_HW_CACHE_RESULT_MAX) | ||
263 | goto out_err; | ||
264 | |||
265 | err = "invalid-cache"; | ||
266 | if (!perf_evsel__is_cache_op_valid(type, op)) | ||
267 | goto out_err; | ||
268 | |||
269 | return __perf_evsel__hw_cache_type_op_res_name(type, op, result, bf, size); | ||
270 | out_err: | ||
271 | return scnprintf(bf, size, "%s", err); | ||
272 | } | ||
273 | |||
274 | static int perf_evsel__hw_cache_name(struct perf_evsel *evsel, char *bf, size_t size) | ||
275 | { | ||
276 | int ret = __perf_evsel__hw_cache_name(evsel->attr.config, bf, size); | ||
277 | return ret + perf_evsel__add_modifiers(evsel, bf + ret, size - ret); | ||
278 | } | ||
279 | |||
280 | static int perf_evsel__raw_name(struct perf_evsel *evsel, char *bf, size_t size) | ||
281 | { | ||
282 | int ret = scnprintf(bf, size, "raw 0x%" PRIx64, evsel->attr.config); | ||
283 | return ret + perf_evsel__add_modifiers(evsel, bf + ret, size - ret); | ||
284 | } | ||
285 | |||
286 | const char *perf_evsel__name(struct perf_evsel *evsel) | ||
287 | { | ||
288 | char bf[128]; | ||
289 | |||
290 | if (evsel->name) | ||
291 | return evsel->name; | ||
129 | 292 | ||
130 | switch (evsel->attr.type) { | 293 | switch (evsel->attr.type) { |
131 | case PERF_TYPE_RAW: | 294 | case PERF_TYPE_RAW: |
132 | ret = scnprintf(bf, size, "raw 0x%" PRIx64, evsel->attr.config); | 295 | perf_evsel__raw_name(evsel, bf, sizeof(bf)); |
133 | break; | 296 | break; |
134 | 297 | ||
135 | case PERF_TYPE_HARDWARE: | 298 | case PERF_TYPE_HARDWARE: |
136 | ret = perf_evsel__hw_name(evsel, bf, size); | 299 | perf_evsel__hw_name(evsel, bf, sizeof(bf)); |
300 | break; | ||
301 | |||
302 | case PERF_TYPE_HW_CACHE: | ||
303 | perf_evsel__hw_cache_name(evsel, bf, sizeof(bf)); | ||
304 | break; | ||
305 | |||
306 | case PERF_TYPE_SOFTWARE: | ||
307 | perf_evsel__sw_name(evsel, bf, sizeof(bf)); | ||
137 | break; | 308 | break; |
309 | |||
310 | case PERF_TYPE_TRACEPOINT: | ||
311 | scnprintf(bf, sizeof(bf), "%s", "unknown tracepoint"); | ||
312 | break; | ||
313 | |||
314 | case PERF_TYPE_BREAKPOINT: | ||
315 | perf_evsel__bp_name(evsel, bf, sizeof(bf)); | ||
316 | break; | ||
317 | |||
138 | default: | 318 | default: |
139 | /* | 319 | scnprintf(bf, sizeof(bf), "%s", "unknown attr type"); |
140 | * FIXME | 320 | break; |
141 | * | 321 | } |
142 | * This is the minimal perf_evsel__name so that we can | 322 | |
143 | * reconstruct event names taking into account event modifiers. | 323 | evsel->name = strdup(bf); |
144 | * | 324 | |
145 | * The old event_name uses it now for raw anr hw events, so that | 325 | return evsel->name ?: "unknown"; |
146 | * we don't drag all the parsing stuff into the python binding. | ||
147 | * | ||
148 | * On the next devel cycle the rest of the event naming will be | ||
149 | * brought here. | ||
150 | */ | ||
151 | return 0; | ||
152 | } | ||
153 | |||
154 | return ret; | ||
155 | } | 326 | } |
156 | 327 | ||
157 | void perf_evsel__config(struct perf_evsel *evsel, struct perf_record_opts *opts, | 328 | void perf_evsel__config(struct perf_evsel *evsel, struct perf_record_opts *opts, |
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index 4ba8b564e6f4..67cc5033d192 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h | |||
@@ -83,8 +83,19 @@ void perf_evsel__config(struct perf_evsel *evsel, | |||
83 | struct perf_record_opts *opts, | 83 | struct perf_record_opts *opts, |
84 | struct perf_evsel *first); | 84 | struct perf_evsel *first); |
85 | 85 | ||
86 | const char* __perf_evsel__hw_name(u64 config); | 86 | bool perf_evsel__is_cache_op_valid(u8 type, u8 op); |
87 | int perf_evsel__name(struct perf_evsel *evsel, char *bf, size_t size); | 87 | |
88 | #define PERF_EVSEL__MAX_ALIASES 8 | ||
89 | |||
90 | extern const char *perf_evsel__hw_cache[PERF_COUNT_HW_CACHE_MAX] | ||
91 | [PERF_EVSEL__MAX_ALIASES]; | ||
92 | extern const char *perf_evsel__hw_cache_op[PERF_COUNT_HW_CACHE_OP_MAX] | ||
93 | [PERF_EVSEL__MAX_ALIASES]; | ||
94 | const char *perf_evsel__hw_cache_result[PERF_COUNT_HW_CACHE_RESULT_MAX] | ||
95 | [PERF_EVSEL__MAX_ALIASES]; | ||
96 | int __perf_evsel__hw_cache_type_op_res_name(u8 type, u8 op, u8 result, | ||
97 | char *bf, size_t size); | ||
98 | const char *perf_evsel__name(struct perf_evsel *evsel); | ||
88 | 99 | ||
89 | int perf_evsel__alloc_fd(struct perf_evsel *evsel, int ncpus, int nthreads); | 100 | int perf_evsel__alloc_fd(struct perf_evsel *evsel, int ncpus, int nthreads); |
90 | int perf_evsel__alloc_id(struct perf_evsel *evsel, int ncpus, int nthreads); | 101 | int perf_evsel__alloc_id(struct perf_evsel *evsel, int ncpus, int nthreads); |
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index 2dd5edf161b7..3a6d20443330 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c | |||
@@ -641,7 +641,7 @@ static int write_event_desc(int fd, struct perf_header *h __used, | |||
641 | /* | 641 | /* |
642 | * write event string as passed on cmdline | 642 | * write event string as passed on cmdline |
643 | */ | 643 | */ |
644 | ret = do_write_string(fd, event_name(attr)); | 644 | ret = do_write_string(fd, perf_evsel__name(attr)); |
645 | if (ret < 0) | 645 | if (ret < 0) |
646 | return ret; | 646 | return ret; |
647 | /* | 647 | /* |
@@ -1212,6 +1212,12 @@ static void print_event_desc(struct perf_header *ph, int fd, FILE *fp) | |||
1212 | attr.exclude_user, | 1212 | attr.exclude_user, |
1213 | attr.exclude_kernel); | 1213 | attr.exclude_kernel); |
1214 | 1214 | ||
1215 | fprintf(fp, ", excl_host = %d, excl_guest = %d", | ||
1216 | attr.exclude_host, | ||
1217 | attr.exclude_guest); | ||
1218 | |||
1219 | fprintf(fp, ", precise_ip = %d", attr.precise_ip); | ||
1220 | |||
1215 | if (nr) | 1221 | if (nr) |
1216 | fprintf(fp, ", id = {"); | 1222 | fprintf(fp, ", id = {"); |
1217 | 1223 | ||
@@ -1474,15 +1480,15 @@ out: | |||
1474 | 1480 | ||
1475 | static int process_tracing_data(struct perf_file_section *section __unused, | 1481 | static int process_tracing_data(struct perf_file_section *section __unused, |
1476 | struct perf_header *ph __unused, | 1482 | struct perf_header *ph __unused, |
1477 | int feat __unused, int fd) | 1483 | int feat __unused, int fd, void *data) |
1478 | { | 1484 | { |
1479 | trace_report(fd, false); | 1485 | trace_report(fd, data, false); |
1480 | return 0; | 1486 | return 0; |
1481 | } | 1487 | } |
1482 | 1488 | ||
1483 | static int process_build_id(struct perf_file_section *section, | 1489 | static int process_build_id(struct perf_file_section *section, |
1484 | struct perf_header *ph, | 1490 | struct perf_header *ph, |
1485 | int feat __unused, int fd) | 1491 | int feat __unused, int fd, void *data __used) |
1486 | { | 1492 | { |
1487 | if (perf_header__read_build_ids(ph, fd, section->offset, section->size)) | 1493 | if (perf_header__read_build_ids(ph, fd, section->offset, section->size)) |
1488 | pr_debug("Failed to read buildids, continuing...\n"); | 1494 | pr_debug("Failed to read buildids, continuing...\n"); |
@@ -1493,7 +1499,7 @@ struct feature_ops { | |||
1493 | int (*write)(int fd, struct perf_header *h, struct perf_evlist *evlist); | 1499 | int (*write)(int fd, struct perf_header *h, struct perf_evlist *evlist); |
1494 | void (*print)(struct perf_header *h, int fd, FILE *fp); | 1500 | void (*print)(struct perf_header *h, int fd, FILE *fp); |
1495 | int (*process)(struct perf_file_section *section, | 1501 | int (*process)(struct perf_file_section *section, |
1496 | struct perf_header *h, int feat, int fd); | 1502 | struct perf_header *h, int feat, int fd, void *data); |
1497 | const char *name; | 1503 | const char *name; |
1498 | bool full_only; | 1504 | bool full_only; |
1499 | }; | 1505 | }; |
@@ -1942,7 +1948,6 @@ int perf_file_header__read(struct perf_file_header *header, | |||
1942 | else | 1948 | else |
1943 | return -1; | 1949 | return -1; |
1944 | } else if (ph->needs_swap) { | 1950 | } else if (ph->needs_swap) { |
1945 | unsigned int i; | ||
1946 | /* | 1951 | /* |
1947 | * feature bitmap is declared as an array of unsigned longs -- | 1952 | * feature bitmap is declared as an array of unsigned longs -- |
1948 | * not good since its size can differ between the host that | 1953 | * not good since its size can differ between the host that |
@@ -1958,14 +1963,17 @@ int perf_file_header__read(struct perf_file_header *header, | |||
1958 | * file), punt and fallback to the original behavior -- | 1963 | * file), punt and fallback to the original behavior -- |
1959 | * clearing all feature bits and setting buildid. | 1964 | * clearing all feature bits and setting buildid. |
1960 | */ | 1965 | */ |
1961 | for (i = 0; i < BITS_TO_LONGS(HEADER_FEAT_BITS); ++i) | 1966 | mem_bswap_64(&header->adds_features, |
1962 | header->adds_features[i] = bswap_64(header->adds_features[i]); | 1967 | BITS_TO_U64(HEADER_FEAT_BITS)); |
1963 | 1968 | ||
1964 | if (!test_bit(HEADER_HOSTNAME, header->adds_features)) { | 1969 | if (!test_bit(HEADER_HOSTNAME, header->adds_features)) { |
1965 | for (i = 0; i < BITS_TO_LONGS(HEADER_FEAT_BITS); ++i) { | 1970 | /* unswap as u64 */ |
1966 | header->adds_features[i] = bswap_64(header->adds_features[i]); | 1971 | mem_bswap_64(&header->adds_features, |
1967 | header->adds_features[i] = bswap_32(header->adds_features[i]); | 1972 | BITS_TO_U64(HEADER_FEAT_BITS)); |
1968 | } | 1973 | |
1974 | /* unswap as u32 */ | ||
1975 | mem_bswap_32(&header->adds_features, | ||
1976 | BITS_TO_U32(HEADER_FEAT_BITS)); | ||
1969 | } | 1977 | } |
1970 | 1978 | ||
1971 | if (!test_bit(HEADER_HOSTNAME, header->adds_features)) { | 1979 | if (!test_bit(HEADER_HOSTNAME, header->adds_features)) { |
@@ -1986,7 +1994,7 @@ int perf_file_header__read(struct perf_file_header *header, | |||
1986 | 1994 | ||
1987 | static int perf_file_section__process(struct perf_file_section *section, | 1995 | static int perf_file_section__process(struct perf_file_section *section, |
1988 | struct perf_header *ph, | 1996 | struct perf_header *ph, |
1989 | int feat, int fd, void *data __used) | 1997 | int feat, int fd, void *data) |
1990 | { | 1998 | { |
1991 | if (lseek(fd, section->offset, SEEK_SET) == (off_t)-1) { | 1999 | if (lseek(fd, section->offset, SEEK_SET) == (off_t)-1) { |
1992 | pr_debug("Failed to lseek to %" PRIu64 " offset for feature " | 2000 | pr_debug("Failed to lseek to %" PRIu64 " offset for feature " |
@@ -2002,7 +2010,7 @@ static int perf_file_section__process(struct perf_file_section *section, | |||
2002 | if (!feat_ops[feat].process) | 2010 | if (!feat_ops[feat].process) |
2003 | return 0; | 2011 | return 0; |
2004 | 2012 | ||
2005 | return feat_ops[feat].process(section, ph, feat, fd); | 2013 | return feat_ops[feat].process(section, ph, feat, fd, data); |
2006 | } | 2014 | } |
2007 | 2015 | ||
2008 | static int perf_file_header__read_pipe(struct perf_pipe_file_header *header, | 2016 | static int perf_file_header__read_pipe(struct perf_pipe_file_header *header, |
@@ -2091,6 +2099,38 @@ static int read_attr(int fd, struct perf_header *ph, | |||
2091 | return ret <= 0 ? -1 : 0; | 2099 | return ret <= 0 ? -1 : 0; |
2092 | } | 2100 | } |
2093 | 2101 | ||
2102 | static int perf_evsel__set_tracepoint_name(struct perf_evsel *evsel, | ||
2103 | struct pevent *pevent) | ||
2104 | { | ||
2105 | struct event_format *event = pevent_find_event(pevent, | ||
2106 | evsel->attr.config); | ||
2107 | char bf[128]; | ||
2108 | |||
2109 | if (event == NULL) | ||
2110 | return -1; | ||
2111 | |||
2112 | snprintf(bf, sizeof(bf), "%s:%s", event->system, event->name); | ||
2113 | evsel->name = strdup(bf); | ||
2114 | if (event->name == NULL) | ||
2115 | return -1; | ||
2116 | |||
2117 | return 0; | ||
2118 | } | ||
2119 | |||
2120 | static int perf_evlist__set_tracepoint_names(struct perf_evlist *evlist, | ||
2121 | struct pevent *pevent) | ||
2122 | { | ||
2123 | struct perf_evsel *pos; | ||
2124 | |||
2125 | list_for_each_entry(pos, &evlist->entries, node) { | ||
2126 | if (pos->attr.type == PERF_TYPE_TRACEPOINT && | ||
2127 | perf_evsel__set_tracepoint_name(pos, pevent)) | ||
2128 | return -1; | ||
2129 | } | ||
2130 | |||
2131 | return 0; | ||
2132 | } | ||
2133 | |||
2094 | int perf_session__read_header(struct perf_session *session, int fd) | 2134 | int perf_session__read_header(struct perf_session *session, int fd) |
2095 | { | 2135 | { |
2096 | struct perf_header *header = &session->header; | 2136 | struct perf_header *header = &session->header; |
@@ -2167,11 +2207,14 @@ int perf_session__read_header(struct perf_session *session, int fd) | |||
2167 | event_count = f_header.event_types.size / sizeof(struct perf_trace_event_type); | 2207 | event_count = f_header.event_types.size / sizeof(struct perf_trace_event_type); |
2168 | } | 2208 | } |
2169 | 2209 | ||
2170 | perf_header__process_sections(header, fd, NULL, | 2210 | perf_header__process_sections(header, fd, &session->pevent, |
2171 | perf_file_section__process); | 2211 | perf_file_section__process); |
2172 | 2212 | ||
2173 | lseek(fd, header->data_offset, SEEK_SET); | 2213 | lseek(fd, header->data_offset, SEEK_SET); |
2174 | 2214 | ||
2215 | if (perf_evlist__set_tracepoint_names(session->evlist, session->pevent)) | ||
2216 | goto out_delete_evlist; | ||
2217 | |||
2175 | header->frozen = 1; | 2218 | header->frozen = 1; |
2176 | return 0; | 2219 | return 0; |
2177 | out_errno: | 2220 | out_errno: |
@@ -2385,8 +2428,8 @@ int perf_event__process_tracing_data(union perf_event *event, | |||
2385 | lseek(session->fd, offset + sizeof(struct tracing_data_event), | 2428 | lseek(session->fd, offset + sizeof(struct tracing_data_event), |
2386 | SEEK_SET); | 2429 | SEEK_SET); |
2387 | 2430 | ||
2388 | size_read = trace_report(session->fd, session->repipe); | 2431 | size_read = trace_report(session->fd, &session->pevent, |
2389 | 2432 | session->repipe); | |
2390 | padding = ALIGN(size_read, sizeof(u64)) - size_read; | 2433 | padding = ALIGN(size_read, sizeof(u64)) - size_read; |
2391 | 2434 | ||
2392 | if (read(session->fd, buf, padding) < 0) | 2435 | if (read(session->fd, buf, padding) < 0) |
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c index 514e2a4b367d..f247ef2789a4 100644 --- a/tools/perf/util/hist.c +++ b/tools/perf/util/hist.c | |||
@@ -708,7 +708,7 @@ static size_t callchain__fprintf_graph(FILE *fp, struct rb_root *root, | |||
708 | bool printed = false; | 708 | bool printed = false; |
709 | struct rb_node *node; | 709 | struct rb_node *node; |
710 | int i = 0; | 710 | int i = 0; |
711 | int ret; | 711 | int ret = 0; |
712 | 712 | ||
713 | /* | 713 | /* |
714 | * If have one single callchain root, don't bother printing | 714 | * If have one single callchain root, don't bother printing |
@@ -747,8 +747,11 @@ static size_t callchain__fprintf_graph(FILE *fp, struct rb_root *root, | |||
747 | root = &cnode->rb_root; | 747 | root = &cnode->rb_root; |
748 | } | 748 | } |
749 | 749 | ||
750 | return __callchain__fprintf_graph(fp, root, total_samples, | 750 | ret += __callchain__fprintf_graph(fp, root, total_samples, |
751 | 1, 1, left_margin); | 751 | 1, 1, left_margin); |
752 | ret += fprintf(fp, "\n"); | ||
753 | |||
754 | return ret; | ||
752 | } | 755 | } |
753 | 756 | ||
754 | static size_t __callchain__fprintf_flat(FILE *fp, | 757 | static size_t __callchain__fprintf_flat(FILE *fp, |
diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h index 34bb556d6219..0b096c27a419 100644 --- a/tools/perf/util/hist.h +++ b/tools/perf/util/hist.h | |||
@@ -47,6 +47,7 @@ enum hist_column { | |||
47 | HISTC_SYMBOL_TO, | 47 | HISTC_SYMBOL_TO, |
48 | HISTC_DSO_FROM, | 48 | HISTC_DSO_FROM, |
49 | HISTC_DSO_TO, | 49 | HISTC_DSO_TO, |
50 | HISTC_SRCLINE, | ||
50 | HISTC_NR_COLS, /* Last entry */ | 51 | HISTC_NR_COLS, /* Last entry */ |
51 | }; | 52 | }; |
52 | 53 | ||
diff --git a/tools/perf/util/include/linux/bitops.h b/tools/perf/util/include/linux/bitops.h index f1584833bd22..587a230d2075 100644 --- a/tools/perf/util/include/linux/bitops.h +++ b/tools/perf/util/include/linux/bitops.h | |||
@@ -8,6 +8,8 @@ | |||
8 | #define BITS_PER_LONG __WORDSIZE | 8 | #define BITS_PER_LONG __WORDSIZE |
9 | #define BITS_PER_BYTE 8 | 9 | #define BITS_PER_BYTE 8 |
10 | #define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long)) | 10 | #define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long)) |
11 | #define BITS_TO_U64(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(u64)) | ||
12 | #define BITS_TO_U32(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(u32)) | ||
11 | 13 | ||
12 | #define for_each_set_bit(bit, addr, size) \ | 14 | #define for_each_set_bit(bit, addr, size) \ |
13 | for ((bit) = find_first_bit((addr), (size)); \ | 15 | for ((bit) = find_first_bit((addr), (size)); \ |
diff --git a/tools/perf/util/include/linux/kernel.h b/tools/perf/util/include/linux/kernel.h index 1eb804fd3fbf..b6842c1d02a8 100644 --- a/tools/perf/util/include/linux/kernel.h +++ b/tools/perf/util/include/linux/kernel.h | |||
@@ -108,4 +108,14 @@ int eprintf(int level, | |||
108 | #define pr_debug3(fmt, ...) pr_debugN(3, pr_fmt(fmt), ##__VA_ARGS__) | 108 | #define pr_debug3(fmt, ...) pr_debugN(3, pr_fmt(fmt), ##__VA_ARGS__) |
109 | #define pr_debug4(fmt, ...) pr_debugN(4, pr_fmt(fmt), ##__VA_ARGS__) | 109 | #define pr_debug4(fmt, ...) pr_debugN(4, pr_fmt(fmt), ##__VA_ARGS__) |
110 | 110 | ||
111 | /* | ||
112 | * This looks more complex than it should be. But we need to | ||
113 | * get the type for the ~ right in round_down (it needs to be | ||
114 | * as wide as the result!), and we want to evaluate the macro | ||
115 | * arguments just once each. | ||
116 | */ | ||
117 | #define __round_mask(x, y) ((__typeof__(x))((y)-1)) | ||
118 | #define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1) | ||
119 | #define round_down(x, y) ((x) & ~__round_mask(x, y)) | ||
120 | |||
111 | #endif | 121 | #endif |
diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c index 35ae56864e4f..cc33486ad9e2 100644 --- a/tools/perf/util/map.c +++ b/tools/perf/util/map.c | |||
@@ -7,6 +7,8 @@ | |||
7 | #include <stdio.h> | 7 | #include <stdio.h> |
8 | #include <unistd.h> | 8 | #include <unistd.h> |
9 | #include "map.h" | 9 | #include "map.h" |
10 | #include "thread.h" | ||
11 | #include "strlist.h" | ||
10 | 12 | ||
11 | const char *map_type__name[MAP__NR_TYPES] = { | 13 | const char *map_type__name[MAP__NR_TYPES] = { |
12 | [MAP__FUNCTION] = "Functions", | 14 | [MAP__FUNCTION] = "Functions", |
@@ -585,7 +587,21 @@ int machine__init(struct machine *self, const char *root_dir, pid_t pid) | |||
585 | self->kmaps.machine = self; | 587 | self->kmaps.machine = self; |
586 | self->pid = pid; | 588 | self->pid = pid; |
587 | self->root_dir = strdup(root_dir); | 589 | self->root_dir = strdup(root_dir); |
588 | return self->root_dir == NULL ? -ENOMEM : 0; | 590 | if (self->root_dir == NULL) |
591 | return -ENOMEM; | ||
592 | |||
593 | if (pid != HOST_KERNEL_ID) { | ||
594 | struct thread *thread = machine__findnew_thread(self, pid); | ||
595 | char comm[64]; | ||
596 | |||
597 | if (thread == NULL) | ||
598 | return -ENOMEM; | ||
599 | |||
600 | snprintf(comm, sizeof(comm), "[guest/%d]", pid); | ||
601 | thread__set_comm(thread, comm); | ||
602 | } | ||
603 | |||
604 | return 0; | ||
589 | } | 605 | } |
590 | 606 | ||
591 | static void dsos__delete(struct list_head *self) | 607 | static void dsos__delete(struct list_head *self) |
@@ -669,25 +685,34 @@ struct machine *machines__find(struct rb_root *self, pid_t pid) | |||
669 | struct machine *machines__findnew(struct rb_root *self, pid_t pid) | 685 | struct machine *machines__findnew(struct rb_root *self, pid_t pid) |
670 | { | 686 | { |
671 | char path[PATH_MAX]; | 687 | char path[PATH_MAX]; |
672 | const char *root_dir; | 688 | const char *root_dir = ""; |
673 | struct machine *machine = machines__find(self, pid); | 689 | struct machine *machine = machines__find(self, pid); |
674 | 690 | ||
675 | if (!machine || machine->pid != pid) { | 691 | if (machine && (machine->pid == pid)) |
676 | if (pid == HOST_KERNEL_ID || pid == DEFAULT_GUEST_KERNEL_ID) | 692 | goto out; |
677 | root_dir = ""; | 693 | |
678 | else { | 694 | if ((pid != HOST_KERNEL_ID) && |
679 | if (!symbol_conf.guestmount) | 695 | (pid != DEFAULT_GUEST_KERNEL_ID) && |
680 | goto out; | 696 | (symbol_conf.guestmount)) { |
681 | sprintf(path, "%s/%d", symbol_conf.guestmount, pid); | 697 | sprintf(path, "%s/%d", symbol_conf.guestmount, pid); |
682 | if (access(path, R_OK)) { | 698 | if (access(path, R_OK)) { |
699 | static struct strlist *seen; | ||
700 | |||
701 | if (!seen) | ||
702 | seen = strlist__new(true, NULL); | ||
703 | |||
704 | if (!strlist__has_entry(seen, path)) { | ||
683 | pr_err("Can't access file %s\n", path); | 705 | pr_err("Can't access file %s\n", path); |
684 | goto out; | 706 | strlist__add(seen, path); |
685 | } | 707 | } |
686 | root_dir = path; | 708 | machine = NULL; |
709 | goto out; | ||
687 | } | 710 | } |
688 | machine = machines__add(self, pid, root_dir); | 711 | root_dir = path; |
689 | } | 712 | } |
690 | 713 | ||
714 | machine = machines__add(self, pid, root_dir); | ||
715 | |||
691 | out: | 716 | out: |
692 | return machine; | 717 | return machine; |
693 | } | 718 | } |
@@ -713,3 +738,16 @@ char *machine__mmap_name(struct machine *self, char *bf, size_t size) | |||
713 | 738 | ||
714 | return bf; | 739 | return bf; |
715 | } | 740 | } |
741 | |||
742 | void machines__set_id_hdr_size(struct rb_root *machines, u16 id_hdr_size) | ||
743 | { | ||
744 | struct rb_node *node; | ||
745 | struct machine *machine; | ||
746 | |||
747 | for (node = rb_first(machines); node; node = rb_next(node)) { | ||
748 | machine = rb_entry(node, struct machine, rb_node); | ||
749 | machine->id_hdr_size = id_hdr_size; | ||
750 | } | ||
751 | |||
752 | return; | ||
753 | } | ||
diff --git a/tools/perf/util/map.h b/tools/perf/util/map.h index 81371bad4ef0..03a1e9b08b21 100644 --- a/tools/perf/util/map.h +++ b/tools/perf/util/map.h | |||
@@ -151,13 +151,14 @@ struct machine *machines__add(struct rb_root *self, pid_t pid, | |||
151 | struct machine *machines__find_host(struct rb_root *self); | 151 | struct machine *machines__find_host(struct rb_root *self); |
152 | struct machine *machines__find(struct rb_root *self, pid_t pid); | 152 | struct machine *machines__find(struct rb_root *self, pid_t pid); |
153 | struct machine *machines__findnew(struct rb_root *self, pid_t pid); | 153 | struct machine *machines__findnew(struct rb_root *self, pid_t pid); |
154 | void machines__set_id_hdr_size(struct rb_root *self, u16 id_hdr_size); | ||
154 | char *machine__mmap_name(struct machine *self, char *bf, size_t size); | 155 | char *machine__mmap_name(struct machine *self, char *bf, size_t size); |
155 | int machine__init(struct machine *self, const char *root_dir, pid_t pid); | 156 | int machine__init(struct machine *self, const char *root_dir, pid_t pid); |
156 | void machine__exit(struct machine *self); | 157 | void machine__exit(struct machine *self); |
157 | void machine__delete(struct machine *self); | 158 | void machine__delete(struct machine *self); |
158 | 159 | ||
159 | int machine__resolve_callchain(struct machine *machine, | 160 | int machine__resolve_callchain(struct machine *machine, |
160 | struct perf_evsel *evsel, struct thread *thread, | 161 | struct thread *thread, |
161 | struct ip_callchain *chain, | 162 | struct ip_callchain *chain, |
162 | struct symbol **parent); | 163 | struct symbol **parent); |
163 | int maps__set_kallsyms_ref_reloc_sym(struct map **maps, const char *symbol_name, | 164 | int maps__set_kallsyms_ref_reloc_sym(struct map **maps, const char *symbol_name, |
diff --git a/tools/perf/util/parse-events-test.c b/tools/perf/util/parse-events-test.c index 76b98e2a587d..1b997d2b89ce 100644 --- a/tools/perf/util/parse-events-test.c +++ b/tools/perf/util/parse-events-test.c | |||
@@ -181,6 +181,22 @@ static int test__checkevent_breakpoint_w(struct perf_evlist *evlist) | |||
181 | return 0; | 181 | return 0; |
182 | } | 182 | } |
183 | 183 | ||
184 | static int test__checkevent_breakpoint_rw(struct perf_evlist *evlist) | ||
185 | { | ||
186 | struct perf_evsel *evsel = list_entry(evlist->entries.next, | ||
187 | struct perf_evsel, node); | ||
188 | |||
189 | TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries); | ||
190 | TEST_ASSERT_VAL("wrong type", | ||
191 | PERF_TYPE_BREAKPOINT == evsel->attr.type); | ||
192 | TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config); | ||
193 | TEST_ASSERT_VAL("wrong bp_type", | ||
194 | (HW_BREAKPOINT_R|HW_BREAKPOINT_W) == evsel->attr.bp_type); | ||
195 | TEST_ASSERT_VAL("wrong bp_len", | ||
196 | HW_BREAKPOINT_LEN_4 == evsel->attr.bp_len); | ||
197 | return 0; | ||
198 | } | ||
199 | |||
184 | static int test__checkevent_tracepoint_modifier(struct perf_evlist *evlist) | 200 | static int test__checkevent_tracepoint_modifier(struct perf_evlist *evlist) |
185 | { | 201 | { |
186 | struct perf_evsel *evsel = list_entry(evlist->entries.next, | 202 | struct perf_evsel *evsel = list_entry(evlist->entries.next, |
@@ -309,6 +325,8 @@ static int test__checkevent_breakpoint_modifier(struct perf_evlist *evlist) | |||
309 | TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel); | 325 | TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel); |
310 | TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); | 326 | TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); |
311 | TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); | 327 | TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); |
328 | TEST_ASSERT_VAL("wrong name", | ||
329 | !strcmp(perf_evsel__name(evsel), "mem:0x0:rw:u")); | ||
312 | 330 | ||
313 | return test__checkevent_breakpoint(evlist); | 331 | return test__checkevent_breakpoint(evlist); |
314 | } | 332 | } |
@@ -322,6 +340,8 @@ static int test__checkevent_breakpoint_x_modifier(struct perf_evlist *evlist) | |||
322 | TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel); | 340 | TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel); |
323 | TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); | 341 | TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); |
324 | TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); | 342 | TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); |
343 | TEST_ASSERT_VAL("wrong name", | ||
344 | !strcmp(perf_evsel__name(evsel), "mem:0x0:x:k")); | ||
325 | 345 | ||
326 | return test__checkevent_breakpoint_x(evlist); | 346 | return test__checkevent_breakpoint_x(evlist); |
327 | } | 347 | } |
@@ -335,6 +355,8 @@ static int test__checkevent_breakpoint_r_modifier(struct perf_evlist *evlist) | |||
335 | TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel); | 355 | TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel); |
336 | TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv); | 356 | TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv); |
337 | TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip); | 357 | TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip); |
358 | TEST_ASSERT_VAL("wrong name", | ||
359 | !strcmp(perf_evsel__name(evsel), "mem:0x0:r:hp")); | ||
338 | 360 | ||
339 | return test__checkevent_breakpoint_r(evlist); | 361 | return test__checkevent_breakpoint_r(evlist); |
340 | } | 362 | } |
@@ -348,10 +370,27 @@ static int test__checkevent_breakpoint_w_modifier(struct perf_evlist *evlist) | |||
348 | TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel); | 370 | TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel); |
349 | TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); | 371 | TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); |
350 | TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip); | 372 | TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip); |
373 | TEST_ASSERT_VAL("wrong name", | ||
374 | !strcmp(perf_evsel__name(evsel), "mem:0x0:w:up")); | ||
351 | 375 | ||
352 | return test__checkevent_breakpoint_w(evlist); | 376 | return test__checkevent_breakpoint_w(evlist); |
353 | } | 377 | } |
354 | 378 | ||
379 | static int test__checkevent_breakpoint_rw_modifier(struct perf_evlist *evlist) | ||
380 | { | ||
381 | struct perf_evsel *evsel = list_entry(evlist->entries.next, | ||
382 | struct perf_evsel, node); | ||
383 | |||
384 | TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user); | ||
385 | TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel); | ||
386 | TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); | ||
387 | TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip); | ||
388 | TEST_ASSERT_VAL("wrong name", | ||
389 | !strcmp(perf_evsel__name(evsel), "mem:0x0:rw:kp")); | ||
390 | |||
391 | return test__checkevent_breakpoint_rw(evlist); | ||
392 | } | ||
393 | |||
355 | static int test__checkevent_pmu(struct perf_evlist *evlist) | 394 | static int test__checkevent_pmu(struct perf_evlist *evlist) |
356 | { | 395 | { |
357 | 396 | ||
@@ -413,19 +452,63 @@ static int test__checkevent_pmu_name(struct perf_evlist *evlist) | |||
413 | { | 452 | { |
414 | struct perf_evsel *evsel; | 453 | struct perf_evsel *evsel; |
415 | 454 | ||
416 | /* cpu/config=1,name=krava1/u */ | 455 | /* cpu/config=1,name=krava/u */ |
417 | evsel = list_entry(evlist->entries.next, struct perf_evsel, node); | 456 | evsel = list_entry(evlist->entries.next, struct perf_evsel, node); |
418 | TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries); | 457 | TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries); |
419 | TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type); | 458 | TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type); |
420 | TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config); | 459 | TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config); |
421 | TEST_ASSERT_VAL("wrong name", !strcmp(evsel->name, "krava")); | 460 | TEST_ASSERT_VAL("wrong name", !strcmp(perf_evsel__name(evsel), "krava")); |
422 | 461 | ||
423 | /* cpu/config=2/" */ | 462 | /* cpu/config=2/u" */ |
424 | evsel = list_entry(evsel->node.next, struct perf_evsel, node); | 463 | evsel = list_entry(evsel->node.next, struct perf_evsel, node); |
425 | TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries); | 464 | TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries); |
426 | TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type); | 465 | TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type); |
427 | TEST_ASSERT_VAL("wrong config", 2 == evsel->attr.config); | 466 | TEST_ASSERT_VAL("wrong config", 2 == evsel->attr.config); |
428 | TEST_ASSERT_VAL("wrong name", !strcmp(evsel->name, "raw 0x2")); | 467 | TEST_ASSERT_VAL("wrong name", |
468 | !strcmp(perf_evsel__name(evsel), "raw 0x2:u")); | ||
469 | |||
470 | return 0; | ||
471 | } | ||
472 | |||
473 | static int test__checkterms_simple(struct list_head *terms) | ||
474 | { | ||
475 | struct parse_events__term *term; | ||
476 | |||
477 | /* config=10 */ | ||
478 | term = list_entry(terms->next, struct parse_events__term, list); | ||
479 | TEST_ASSERT_VAL("wrong type term", | ||
480 | term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG); | ||
481 | TEST_ASSERT_VAL("wrong type val", | ||
482 | term->type_val == PARSE_EVENTS__TERM_TYPE_NUM); | ||
483 | TEST_ASSERT_VAL("wrong val", term->val.num == 10); | ||
484 | TEST_ASSERT_VAL("wrong config", !term->config); | ||
485 | |||
486 | /* config1 */ | ||
487 | term = list_entry(term->list.next, struct parse_events__term, list); | ||
488 | TEST_ASSERT_VAL("wrong type term", | ||
489 | term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG1); | ||
490 | TEST_ASSERT_VAL("wrong type val", | ||
491 | term->type_val == PARSE_EVENTS__TERM_TYPE_NUM); | ||
492 | TEST_ASSERT_VAL("wrong val", term->val.num == 1); | ||
493 | TEST_ASSERT_VAL("wrong config", !term->config); | ||
494 | |||
495 | /* config2=3 */ | ||
496 | term = list_entry(term->list.next, struct parse_events__term, list); | ||
497 | TEST_ASSERT_VAL("wrong type term", | ||
498 | term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG2); | ||
499 | TEST_ASSERT_VAL("wrong type val", | ||
500 | term->type_val == PARSE_EVENTS__TERM_TYPE_NUM); | ||
501 | TEST_ASSERT_VAL("wrong val", term->val.num == 3); | ||
502 | TEST_ASSERT_VAL("wrong config", !term->config); | ||
503 | |||
504 | /* umask=1*/ | ||
505 | term = list_entry(term->list.next, struct parse_events__term, list); | ||
506 | TEST_ASSERT_VAL("wrong type term", | ||
507 | term->type_term == PARSE_EVENTS__TERM_TYPE_USER); | ||
508 | TEST_ASSERT_VAL("wrong type val", | ||
509 | term->type_val == PARSE_EVENTS__TERM_TYPE_NUM); | ||
510 | TEST_ASSERT_VAL("wrong val", term->val.num == 1); | ||
511 | TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "umask")); | ||
429 | 512 | ||
430 | return 0; | 513 | return 0; |
431 | } | 514 | } |
@@ -541,10 +624,16 @@ static struct test__event_st test__events[] = { | |||
541 | .name = "instructions:H", | 624 | .name = "instructions:H", |
542 | .check = test__checkevent_exclude_guest_modifier, | 625 | .check = test__checkevent_exclude_guest_modifier, |
543 | }, | 626 | }, |
627 | [26] = { | ||
628 | .name = "mem:0:rw", | ||
629 | .check = test__checkevent_breakpoint_rw, | ||
630 | }, | ||
631 | [27] = { | ||
632 | .name = "mem:0:rw:kp", | ||
633 | .check = test__checkevent_breakpoint_rw_modifier, | ||
634 | }, | ||
544 | }; | 635 | }; |
545 | 636 | ||
546 | #define TEST__EVENTS_CNT (sizeof(test__events) / sizeof(struct test__event_st)) | ||
547 | |||
548 | static struct test__event_st test__events_pmu[] = { | 637 | static struct test__event_st test__events_pmu[] = { |
549 | [0] = { | 638 | [0] = { |
550 | .name = "cpu/config=10,config1,config2=3,period=1000/u", | 639 | .name = "cpu/config=10,config1,config2=3,period=1000/u", |
@@ -556,10 +645,23 @@ static struct test__event_st test__events_pmu[] = { | |||
556 | }, | 645 | }, |
557 | }; | 646 | }; |
558 | 647 | ||
559 | #define TEST__EVENTS_PMU_CNT (sizeof(test__events_pmu) / \ | 648 | struct test__term { |
560 | sizeof(struct test__event_st)) | 649 | const char *str; |
650 | __u32 type; | ||
651 | int (*check)(struct list_head *terms); | ||
652 | }; | ||
653 | |||
654 | static struct test__term test__terms[] = { | ||
655 | [0] = { | ||
656 | .str = "config=10,config1,config2=3,umask=1", | ||
657 | .check = test__checkterms_simple, | ||
658 | }, | ||
659 | }; | ||
660 | |||
661 | #define TEST__TERMS_CNT (sizeof(test__terms) / \ | ||
662 | sizeof(struct test__term)) | ||
561 | 663 | ||
562 | static int test(struct test__event_st *e) | 664 | static int test_event(struct test__event_st *e) |
563 | { | 665 | { |
564 | struct perf_evlist *evlist; | 666 | struct perf_evlist *evlist; |
565 | int ret; | 667 | int ret; |
@@ -590,7 +692,48 @@ static int test_events(struct test__event_st *events, unsigned cnt) | |||
590 | struct test__event_st *e = &events[i]; | 692 | struct test__event_st *e = &events[i]; |
591 | 693 | ||
592 | pr_debug("running test %d '%s'\n", i, e->name); | 694 | pr_debug("running test %d '%s'\n", i, e->name); |
593 | ret = test(e); | 695 | ret = test_event(e); |
696 | if (ret) | ||
697 | break; | ||
698 | } | ||
699 | |||
700 | return ret; | ||
701 | } | ||
702 | |||
703 | static int test_term(struct test__term *t) | ||
704 | { | ||
705 | struct list_head *terms; | ||
706 | int ret; | ||
707 | |||
708 | terms = malloc(sizeof(*terms)); | ||
709 | if (!terms) | ||
710 | return -ENOMEM; | ||
711 | |||
712 | INIT_LIST_HEAD(terms); | ||
713 | |||
714 | ret = parse_events_terms(terms, t->str); | ||
715 | if (ret) { | ||
716 | pr_debug("failed to parse terms '%s', err %d\n", | ||
717 | t->str , ret); | ||
718 | return ret; | ||
719 | } | ||
720 | |||
721 | ret = t->check(terms); | ||
722 | parse_events__free_terms(terms); | ||
723 | |||
724 | return ret; | ||
725 | } | ||
726 | |||
727 | static int test_terms(struct test__term *terms, unsigned cnt) | ||
728 | { | ||
729 | int ret = 0; | ||
730 | unsigned i; | ||
731 | |||
732 | for (i = 0; i < cnt; i++) { | ||
733 | struct test__term *t = &terms[i]; | ||
734 | |||
735 | pr_debug("running test %d '%s'\n", i, t->str); | ||
736 | ret = test_term(t); | ||
594 | if (ret) | 737 | if (ret) |
595 | break; | 738 | break; |
596 | } | 739 | } |
@@ -617,9 +760,17 @@ int parse_events__test(void) | |||
617 | { | 760 | { |
618 | int ret; | 761 | int ret; |
619 | 762 | ||
620 | ret = test_events(test__events, TEST__EVENTS_CNT); | 763 | #define TEST_EVENTS(tests) \ |
621 | if (!ret && test_pmu()) | 764 | do { \ |
622 | ret = test_events(test__events_pmu, TEST__EVENTS_PMU_CNT); | 765 | ret = test_events(tests, ARRAY_SIZE(tests)); \ |
766 | if (ret) \ | ||
767 | return ret; \ | ||
768 | } while (0) | ||
623 | 769 | ||
624 | return ret; | 770 | TEST_EVENTS(test__events); |
771 | |||
772 | if (test_pmu()) | ||
773 | TEST_EVENTS(test__events_pmu); | ||
774 | |||
775 | return test_terms(test__terms, ARRAY_SIZE(test__terms)); | ||
625 | } | 776 | } |
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 05dbc8b3c767..74a5af4d33ec 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c | |||
@@ -11,14 +11,14 @@ | |||
11 | #include "cache.h" | 11 | #include "cache.h" |
12 | #include "header.h" | 12 | #include "header.h" |
13 | #include "debugfs.h" | 13 | #include "debugfs.h" |
14 | #include "parse-events-bison.h" | ||
15 | #define YY_EXTRA_TYPE int | ||
14 | #include "parse-events-flex.h" | 16 | #include "parse-events-flex.h" |
15 | #include "pmu.h" | 17 | #include "pmu.h" |
16 | 18 | ||
17 | #define MAX_NAME_LEN 100 | 19 | #define MAX_NAME_LEN 100 |
18 | 20 | ||
19 | struct event_symbol { | 21 | struct event_symbol { |
20 | u8 type; | ||
21 | u64 config; | ||
22 | const char *symbol; | 22 | const char *symbol; |
23 | const char *alias; | 23 | const char *alias; |
24 | }; | 24 | }; |
@@ -26,32 +26,88 @@ struct event_symbol { | |||
26 | #ifdef PARSER_DEBUG | 26 | #ifdef PARSER_DEBUG |
27 | extern int parse_events_debug; | 27 | extern int parse_events_debug; |
28 | #endif | 28 | #endif |
29 | int parse_events_parse(struct list_head *list, int *idx); | 29 | int parse_events_parse(void *data, void *scanner); |
30 | 30 | ||
31 | #define CHW(x) .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_##x | 31 | static struct event_symbol event_symbols_hw[PERF_COUNT_HW_MAX] = { |
32 | #define CSW(x) .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_##x | 32 | [PERF_COUNT_HW_CPU_CYCLES] = { |
33 | 33 | .symbol = "cpu-cycles", | |
34 | static struct event_symbol event_symbols[] = { | 34 | .alias = "cycles", |
35 | { CHW(CPU_CYCLES), "cpu-cycles", "cycles" }, | 35 | }, |
36 | { CHW(STALLED_CYCLES_FRONTEND), "stalled-cycles-frontend", "idle-cycles-frontend" }, | 36 | [PERF_COUNT_HW_INSTRUCTIONS] = { |
37 | { CHW(STALLED_CYCLES_BACKEND), "stalled-cycles-backend", "idle-cycles-backend" }, | 37 | .symbol = "instructions", |
38 | { CHW(INSTRUCTIONS), "instructions", "" }, | 38 | .alias = "", |
39 | { CHW(CACHE_REFERENCES), "cache-references", "" }, | 39 | }, |
40 | { CHW(CACHE_MISSES), "cache-misses", "" }, | 40 | [PERF_COUNT_HW_CACHE_REFERENCES] = { |
41 | { CHW(BRANCH_INSTRUCTIONS), "branch-instructions", "branches" }, | 41 | .symbol = "cache-references", |
42 | { CHW(BRANCH_MISSES), "branch-misses", "" }, | 42 | .alias = "", |
43 | { CHW(BUS_CYCLES), "bus-cycles", "" }, | 43 | }, |
44 | { CHW(REF_CPU_CYCLES), "ref-cycles", "" }, | 44 | [PERF_COUNT_HW_CACHE_MISSES] = { |
45 | 45 | .symbol = "cache-misses", | |
46 | { CSW(CPU_CLOCK), "cpu-clock", "" }, | 46 | .alias = "", |
47 | { CSW(TASK_CLOCK), "task-clock", "" }, | 47 | }, |
48 | { CSW(PAGE_FAULTS), "page-faults", "faults" }, | 48 | [PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = { |
49 | { CSW(PAGE_FAULTS_MIN), "minor-faults", "" }, | 49 | .symbol = "branch-instructions", |
50 | { CSW(PAGE_FAULTS_MAJ), "major-faults", "" }, | 50 | .alias = "branches", |
51 | { CSW(CONTEXT_SWITCHES), "context-switches", "cs" }, | 51 | }, |
52 | { CSW(CPU_MIGRATIONS), "cpu-migrations", "migrations" }, | 52 | [PERF_COUNT_HW_BRANCH_MISSES] = { |
53 | { CSW(ALIGNMENT_FAULTS), "alignment-faults", "" }, | 53 | .symbol = "branch-misses", |
54 | { CSW(EMULATION_FAULTS), "emulation-faults", "" }, | 54 | .alias = "", |
55 | }, | ||
56 | [PERF_COUNT_HW_BUS_CYCLES] = { | ||
57 | .symbol = "bus-cycles", | ||
58 | .alias = "", | ||
59 | }, | ||
60 | [PERF_COUNT_HW_STALLED_CYCLES_FRONTEND] = { | ||
61 | .symbol = "stalled-cycles-frontend", | ||
62 | .alias = "idle-cycles-frontend", | ||
63 | }, | ||
64 | [PERF_COUNT_HW_STALLED_CYCLES_BACKEND] = { | ||
65 | .symbol = "stalled-cycles-backend", | ||
66 | .alias = "idle-cycles-backend", | ||
67 | }, | ||
68 | [PERF_COUNT_HW_REF_CPU_CYCLES] = { | ||
69 | .symbol = "ref-cycles", | ||
70 | .alias = "", | ||
71 | }, | ||
72 | }; | ||
73 | |||
74 | static struct event_symbol event_symbols_sw[PERF_COUNT_SW_MAX] = { | ||
75 | [PERF_COUNT_SW_CPU_CLOCK] = { | ||
76 | .symbol = "cpu-clock", | ||
77 | .alias = "", | ||
78 | }, | ||
79 | [PERF_COUNT_SW_TASK_CLOCK] = { | ||
80 | .symbol = "task-clock", | ||
81 | .alias = "", | ||
82 | }, | ||
83 | [PERF_COUNT_SW_PAGE_FAULTS] = { | ||
84 | .symbol = "page-faults", | ||
85 | .alias = "faults", | ||
86 | }, | ||
87 | [PERF_COUNT_SW_CONTEXT_SWITCHES] = { | ||
88 | .symbol = "context-switches", | ||
89 | .alias = "cs", | ||
90 | }, | ||
91 | [PERF_COUNT_SW_CPU_MIGRATIONS] = { | ||
92 | .symbol = "cpu-migrations", | ||
93 | .alias = "migrations", | ||
94 | }, | ||
95 | [PERF_COUNT_SW_PAGE_FAULTS_MIN] = { | ||
96 | .symbol = "minor-faults", | ||
97 | .alias = "", | ||
98 | }, | ||
99 | [PERF_COUNT_SW_PAGE_FAULTS_MAJ] = { | ||
100 | .symbol = "major-faults", | ||
101 | .alias = "", | ||
102 | }, | ||
103 | [PERF_COUNT_SW_ALIGNMENT_FAULTS] = { | ||
104 | .symbol = "alignment-faults", | ||
105 | .alias = "", | ||
106 | }, | ||
107 | [PERF_COUNT_SW_EMULATION_FAULTS] = { | ||
108 | .symbol = "emulation-faults", | ||
109 | .alias = "", | ||
110 | }, | ||
55 | }; | 111 | }; |
56 | 112 | ||
57 | #define __PERF_EVENT_FIELD(config, name) \ | 113 | #define __PERF_EVENT_FIELD(config, name) \ |
@@ -62,63 +118,6 @@ static struct event_symbol event_symbols[] = { | |||
62 | #define PERF_EVENT_TYPE(config) __PERF_EVENT_FIELD(config, TYPE) | 118 | #define PERF_EVENT_TYPE(config) __PERF_EVENT_FIELD(config, TYPE) |
63 | #define PERF_EVENT_ID(config) __PERF_EVENT_FIELD(config, EVENT) | 119 | #define PERF_EVENT_ID(config) __PERF_EVENT_FIELD(config, EVENT) |
64 | 120 | ||
65 | static const char *sw_event_names[PERF_COUNT_SW_MAX] = { | ||
66 | "cpu-clock", | ||
67 | "task-clock", | ||
68 | "page-faults", | ||
69 | "context-switches", | ||
70 | "CPU-migrations", | ||
71 | "minor-faults", | ||
72 | "major-faults", | ||
73 | "alignment-faults", | ||
74 | "emulation-faults", | ||
75 | }; | ||
76 | |||
77 | #define MAX_ALIASES 8 | ||
78 | |||
79 | static const char *hw_cache[PERF_COUNT_HW_CACHE_MAX][MAX_ALIASES] = { | ||
80 | { "L1-dcache", "l1-d", "l1d", "L1-data", }, | ||
81 | { "L1-icache", "l1-i", "l1i", "L1-instruction", }, | ||
82 | { "LLC", "L2", }, | ||
83 | { "dTLB", "d-tlb", "Data-TLB", }, | ||
84 | { "iTLB", "i-tlb", "Instruction-TLB", }, | ||
85 | { "branch", "branches", "bpu", "btb", "bpc", }, | ||
86 | { "node", }, | ||
87 | }; | ||
88 | |||
89 | static const char *hw_cache_op[PERF_COUNT_HW_CACHE_OP_MAX][MAX_ALIASES] = { | ||
90 | { "load", "loads", "read", }, | ||
91 | { "store", "stores", "write", }, | ||
92 | { "prefetch", "prefetches", "speculative-read", "speculative-load", }, | ||
93 | }; | ||
94 | |||
95 | static const char *hw_cache_result[PERF_COUNT_HW_CACHE_RESULT_MAX] | ||
96 | [MAX_ALIASES] = { | ||
97 | { "refs", "Reference", "ops", "access", }, | ||
98 | { "misses", "miss", }, | ||
99 | }; | ||
100 | |||
101 | #define C(x) PERF_COUNT_HW_CACHE_##x | ||
102 | #define CACHE_READ (1 << C(OP_READ)) | ||
103 | #define CACHE_WRITE (1 << C(OP_WRITE)) | ||
104 | #define CACHE_PREFETCH (1 << C(OP_PREFETCH)) | ||
105 | #define COP(x) (1 << x) | ||
106 | |||
107 | /* | ||
108 | * cache operartion stat | ||
109 | * L1I : Read and prefetch only | ||
110 | * ITLB and BPU : Read-only | ||
111 | */ | ||
112 | static unsigned long hw_cache_stat[C(MAX)] = { | ||
113 | [C(L1D)] = (CACHE_READ | CACHE_WRITE | CACHE_PREFETCH), | ||
114 | [C(L1I)] = (CACHE_READ | CACHE_PREFETCH), | ||
115 | [C(LL)] = (CACHE_READ | CACHE_WRITE | CACHE_PREFETCH), | ||
116 | [C(DTLB)] = (CACHE_READ | CACHE_WRITE | CACHE_PREFETCH), | ||
117 | [C(ITLB)] = (CACHE_READ), | ||
118 | [C(BPU)] = (CACHE_READ), | ||
119 | [C(NODE)] = (CACHE_READ | CACHE_WRITE | CACHE_PREFETCH), | ||
120 | }; | ||
121 | |||
122 | #define for_each_subsystem(sys_dir, sys_dirent, sys_next) \ | 121 | #define for_each_subsystem(sys_dir, sys_dirent, sys_next) \ |
123 | while (!readdir_r(sys_dir, &sys_dirent, &sys_next) && sys_next) \ | 122 | while (!readdir_r(sys_dir, &sys_dirent, &sys_next) && sys_next) \ |
124 | if (sys_dirent.d_type == DT_DIR && \ | 123 | if (sys_dirent.d_type == DT_DIR && \ |
@@ -218,48 +217,6 @@ struct tracepoint_path *tracepoint_id_to_path(u64 config) | |||
218 | return NULL; | 217 | return NULL; |
219 | } | 218 | } |
220 | 219 | ||
221 | #define TP_PATH_LEN (MAX_EVENT_LENGTH * 2 + 1) | ||
222 | static const char *tracepoint_id_to_name(u64 config) | ||
223 | { | ||
224 | static char buf[TP_PATH_LEN]; | ||
225 | struct tracepoint_path *path; | ||
226 | |||
227 | path = tracepoint_id_to_path(config); | ||
228 | if (path) { | ||
229 | snprintf(buf, TP_PATH_LEN, "%s:%s", path->system, path->name); | ||
230 | free(path->name); | ||
231 | free(path->system); | ||
232 | free(path); | ||
233 | } else | ||
234 | snprintf(buf, TP_PATH_LEN, "%s:%s", "unknown", "unknown"); | ||
235 | |||
236 | return buf; | ||
237 | } | ||
238 | |||
239 | static int is_cache_op_valid(u8 cache_type, u8 cache_op) | ||
240 | { | ||
241 | if (hw_cache_stat[cache_type] & COP(cache_op)) | ||
242 | return 1; /* valid */ | ||
243 | else | ||
244 | return 0; /* invalid */ | ||
245 | } | ||
246 | |||
247 | static char *event_cache_name(u8 cache_type, u8 cache_op, u8 cache_result) | ||
248 | { | ||
249 | static char name[50]; | ||
250 | |||
251 | if (cache_result) { | ||
252 | sprintf(name, "%s-%s-%s", hw_cache[cache_type][0], | ||
253 | hw_cache_op[cache_op][0], | ||
254 | hw_cache_result[cache_result][0]); | ||
255 | } else { | ||
256 | sprintf(name, "%s-%s", hw_cache[cache_type][0], | ||
257 | hw_cache_op[cache_op][1]); | ||
258 | } | ||
259 | |||
260 | return name; | ||
261 | } | ||
262 | |||
263 | const char *event_type(int type) | 220 | const char *event_type(int type) |
264 | { | 221 | { |
265 | switch (type) { | 222 | switch (type) { |
@@ -282,76 +239,6 @@ const char *event_type(int type) | |||
282 | return "unknown"; | 239 | return "unknown"; |
283 | } | 240 | } |
284 | 241 | ||
285 | const char *event_name(struct perf_evsel *evsel) | ||
286 | { | ||
287 | u64 config = evsel->attr.config; | ||
288 | int type = evsel->attr.type; | ||
289 | |||
290 | if (type == PERF_TYPE_RAW || type == PERF_TYPE_HARDWARE) { | ||
291 | /* | ||
292 | * XXX minimal fix, see comment on perf_evsen__name, this static buffer | ||
293 | * will go away together with event_name in the next devel cycle. | ||
294 | */ | ||
295 | static char bf[128]; | ||
296 | perf_evsel__name(evsel, bf, sizeof(bf)); | ||
297 | return bf; | ||
298 | } | ||
299 | |||
300 | if (evsel->name) | ||
301 | return evsel->name; | ||
302 | |||
303 | return __event_name(type, config); | ||
304 | } | ||
305 | |||
306 | const char *__event_name(int type, u64 config) | ||
307 | { | ||
308 | static char buf[32]; | ||
309 | |||
310 | if (type == PERF_TYPE_RAW) { | ||
311 | sprintf(buf, "raw 0x%" PRIx64, config); | ||
312 | return buf; | ||
313 | } | ||
314 | |||
315 | switch (type) { | ||
316 | case PERF_TYPE_HARDWARE: | ||
317 | return __perf_evsel__hw_name(config); | ||
318 | |||
319 | case PERF_TYPE_HW_CACHE: { | ||
320 | u8 cache_type, cache_op, cache_result; | ||
321 | |||
322 | cache_type = (config >> 0) & 0xff; | ||
323 | if (cache_type > PERF_COUNT_HW_CACHE_MAX) | ||
324 | return "unknown-ext-hardware-cache-type"; | ||
325 | |||
326 | cache_op = (config >> 8) & 0xff; | ||
327 | if (cache_op > PERF_COUNT_HW_CACHE_OP_MAX) | ||
328 | return "unknown-ext-hardware-cache-op"; | ||
329 | |||
330 | cache_result = (config >> 16) & 0xff; | ||
331 | if (cache_result > PERF_COUNT_HW_CACHE_RESULT_MAX) | ||
332 | return "unknown-ext-hardware-cache-result"; | ||
333 | |||
334 | if (!is_cache_op_valid(cache_type, cache_op)) | ||
335 | return "invalid-cache"; | ||
336 | |||
337 | return event_cache_name(cache_type, cache_op, cache_result); | ||
338 | } | ||
339 | |||
340 | case PERF_TYPE_SOFTWARE: | ||
341 | if (config < PERF_COUNT_SW_MAX && sw_event_names[config]) | ||
342 | return sw_event_names[config]; | ||
343 | return "unknown-software"; | ||
344 | |||
345 | case PERF_TYPE_TRACEPOINT: | ||
346 | return tracepoint_id_to_name(config); | ||
347 | |||
348 | default: | ||
349 | break; | ||
350 | } | ||
351 | |||
352 | return "unknown"; | ||
353 | } | ||
354 | |||
355 | static int add_event(struct list_head **_list, int *idx, | 242 | static int add_event(struct list_head **_list, int *idx, |
356 | struct perf_event_attr *attr, char *name) | 243 | struct perf_event_attr *attr, char *name) |
357 | { | 244 | { |
@@ -373,19 +260,20 @@ static int add_event(struct list_head **_list, int *idx, | |||
373 | return -ENOMEM; | 260 | return -ENOMEM; |
374 | } | 261 | } |
375 | 262 | ||
376 | evsel->name = strdup(name); | 263 | if (name) |
264 | evsel->name = strdup(name); | ||
377 | list_add_tail(&evsel->node, list); | 265 | list_add_tail(&evsel->node, list); |
378 | *_list = list; | 266 | *_list = list; |
379 | return 0; | 267 | return 0; |
380 | } | 268 | } |
381 | 269 | ||
382 | static int parse_aliases(char *str, const char *names[][MAX_ALIASES], int size) | 270 | static int parse_aliases(char *str, const char *names[][PERF_EVSEL__MAX_ALIASES], int size) |
383 | { | 271 | { |
384 | int i, j; | 272 | int i, j; |
385 | int n, longest = -1; | 273 | int n, longest = -1; |
386 | 274 | ||
387 | for (i = 0; i < size; i++) { | 275 | for (i = 0; i < size; i++) { |
388 | for (j = 0; j < MAX_ALIASES && names[i][j]; j++) { | 276 | for (j = 0; j < PERF_EVSEL__MAX_ALIASES && names[i][j]; j++) { |
389 | n = strlen(names[i][j]); | 277 | n = strlen(names[i][j]); |
390 | if (n > longest && !strncasecmp(str, names[i][j], n)) | 278 | if (n > longest && !strncasecmp(str, names[i][j], n)) |
391 | longest = n; | 279 | longest = n; |
@@ -410,7 +298,7 @@ int parse_events_add_cache(struct list_head **list, int *idx, | |||
410 | * No fallback - if we cannot get a clear cache type | 298 | * No fallback - if we cannot get a clear cache type |
411 | * then bail out: | 299 | * then bail out: |
412 | */ | 300 | */ |
413 | cache_type = parse_aliases(type, hw_cache, | 301 | cache_type = parse_aliases(type, perf_evsel__hw_cache, |
414 | PERF_COUNT_HW_CACHE_MAX); | 302 | PERF_COUNT_HW_CACHE_MAX); |
415 | if (cache_type == -1) | 303 | if (cache_type == -1) |
416 | return -EINVAL; | 304 | return -EINVAL; |
@@ -423,18 +311,18 @@ int parse_events_add_cache(struct list_head **list, int *idx, | |||
423 | snprintf(name + n, MAX_NAME_LEN - n, "-%s\n", str); | 311 | snprintf(name + n, MAX_NAME_LEN - n, "-%s\n", str); |
424 | 312 | ||
425 | if (cache_op == -1) { | 313 | if (cache_op == -1) { |
426 | cache_op = parse_aliases(str, hw_cache_op, | 314 | cache_op = parse_aliases(str, perf_evsel__hw_cache_op, |
427 | PERF_COUNT_HW_CACHE_OP_MAX); | 315 | PERF_COUNT_HW_CACHE_OP_MAX); |
428 | if (cache_op >= 0) { | 316 | if (cache_op >= 0) { |
429 | if (!is_cache_op_valid(cache_type, cache_op)) | 317 | if (!perf_evsel__is_cache_op_valid(cache_type, cache_op)) |
430 | return -EINVAL; | 318 | return -EINVAL; |
431 | continue; | 319 | continue; |
432 | } | 320 | } |
433 | } | 321 | } |
434 | 322 | ||
435 | if (cache_result == -1) { | 323 | if (cache_result == -1) { |
436 | cache_result = parse_aliases(str, hw_cache_result, | 324 | cache_result = parse_aliases(str, perf_evsel__hw_cache_result, |
437 | PERF_COUNT_HW_CACHE_RESULT_MAX); | 325 | PERF_COUNT_HW_CACHE_RESULT_MAX); |
438 | if (cache_result >= 0) | 326 | if (cache_result >= 0) |
439 | continue; | 327 | continue; |
440 | } | 328 | } |
@@ -489,6 +377,7 @@ static int add_tracepoint(struct list_head **list, int *idx, | |||
489 | attr.sample_type |= PERF_SAMPLE_RAW; | 377 | attr.sample_type |= PERF_SAMPLE_RAW; |
490 | attr.sample_type |= PERF_SAMPLE_TIME; | 378 | attr.sample_type |= PERF_SAMPLE_TIME; |
491 | attr.sample_type |= PERF_SAMPLE_CPU; | 379 | attr.sample_type |= PERF_SAMPLE_CPU; |
380 | attr.sample_type |= PERF_SAMPLE_PERIOD; | ||
492 | attr.sample_period = 1; | 381 | attr.sample_period = 1; |
493 | 382 | ||
494 | snprintf(name, MAX_NAME_LEN, "%s:%s", sys_name, evt_name); | 383 | snprintf(name, MAX_NAME_LEN, "%s:%s", sys_name, evt_name); |
@@ -549,21 +438,31 @@ parse_breakpoint_type(const char *type, struct perf_event_attr *attr) | |||
549 | if (!type || !type[i]) | 438 | if (!type || !type[i]) |
550 | break; | 439 | break; |
551 | 440 | ||
441 | #define CHECK_SET_TYPE(bit) \ | ||
442 | do { \ | ||
443 | if (attr->bp_type & bit) \ | ||
444 | return -EINVAL; \ | ||
445 | else \ | ||
446 | attr->bp_type |= bit; \ | ||
447 | } while (0) | ||
448 | |||
552 | switch (type[i]) { | 449 | switch (type[i]) { |
553 | case 'r': | 450 | case 'r': |
554 | attr->bp_type |= HW_BREAKPOINT_R; | 451 | CHECK_SET_TYPE(HW_BREAKPOINT_R); |
555 | break; | 452 | break; |
556 | case 'w': | 453 | case 'w': |
557 | attr->bp_type |= HW_BREAKPOINT_W; | 454 | CHECK_SET_TYPE(HW_BREAKPOINT_W); |
558 | break; | 455 | break; |
559 | case 'x': | 456 | case 'x': |
560 | attr->bp_type |= HW_BREAKPOINT_X; | 457 | CHECK_SET_TYPE(HW_BREAKPOINT_X); |
561 | break; | 458 | break; |
562 | default: | 459 | default: |
563 | return -EINVAL; | 460 | return -EINVAL; |
564 | } | 461 | } |
565 | } | 462 | } |
566 | 463 | ||
464 | #undef CHECK_SET_TYPE | ||
465 | |||
567 | if (!attr->bp_type) /* Default */ | 466 | if (!attr->bp_type) /* Default */ |
568 | attr->bp_type = HW_BREAKPOINT_R | HW_BREAKPOINT_W; | 467 | attr->bp_type = HW_BREAKPOINT_R | HW_BREAKPOINT_W; |
569 | 468 | ||
@@ -574,7 +473,6 @@ int parse_events_add_breakpoint(struct list_head **list, int *idx, | |||
574 | void *ptr, char *type) | 473 | void *ptr, char *type) |
575 | { | 474 | { |
576 | struct perf_event_attr attr; | 475 | struct perf_event_attr attr; |
577 | char name[MAX_NAME_LEN]; | ||
578 | 476 | ||
579 | memset(&attr, 0, sizeof(attr)); | 477 | memset(&attr, 0, sizeof(attr)); |
580 | attr.bp_addr = (unsigned long) ptr; | 478 | attr.bp_addr = (unsigned long) ptr; |
@@ -592,9 +490,9 @@ int parse_events_add_breakpoint(struct list_head **list, int *idx, | |||
592 | attr.bp_len = HW_BREAKPOINT_LEN_4; | 490 | attr.bp_len = HW_BREAKPOINT_LEN_4; |
593 | 491 | ||
594 | attr.type = PERF_TYPE_BREAKPOINT; | 492 | attr.type = PERF_TYPE_BREAKPOINT; |
493 | attr.sample_period = 1; | ||
595 | 494 | ||
596 | snprintf(name, MAX_NAME_LEN, "mem:%p:%s", ptr, type ? type : "rw"); | 495 | return add_event(list, idx, &attr, NULL); |
597 | return add_event(list, idx, &attr, name); | ||
598 | } | 496 | } |
599 | 497 | ||
600 | static int config_term(struct perf_event_attr *attr, | 498 | static int config_term(struct perf_event_attr *attr, |
@@ -666,8 +564,7 @@ int parse_events_add_numeric(struct list_head **list, int *idx, | |||
666 | config_attr(&attr, head_config, 1)) | 564 | config_attr(&attr, head_config, 1)) |
667 | return -EINVAL; | 565 | return -EINVAL; |
668 | 566 | ||
669 | return add_event(list, idx, &attr, | 567 | return add_event(list, idx, &attr, NULL); |
670 | (char *) __event_name(type, config)); | ||
671 | } | 568 | } |
672 | 569 | ||
673 | static int parse_events__is_name_term(struct parse_events__term *term) | 570 | static int parse_events__is_name_term(struct parse_events__term *term) |
@@ -675,8 +572,7 @@ static int parse_events__is_name_term(struct parse_events__term *term) | |||
675 | return term->type_term == PARSE_EVENTS__TERM_TYPE_NAME; | 572 | return term->type_term == PARSE_EVENTS__TERM_TYPE_NAME; |
676 | } | 573 | } |
677 | 574 | ||
678 | static char *pmu_event_name(struct perf_event_attr *attr, | 575 | static char *pmu_event_name(struct list_head *head_terms) |
679 | struct list_head *head_terms) | ||
680 | { | 576 | { |
681 | struct parse_events__term *term; | 577 | struct parse_events__term *term; |
682 | 578 | ||
@@ -684,7 +580,7 @@ static char *pmu_event_name(struct perf_event_attr *attr, | |||
684 | if (parse_events__is_name_term(term)) | 580 | if (parse_events__is_name_term(term)) |
685 | return term->val.str; | 581 | return term->val.str; |
686 | 582 | ||
687 | return (char *) __event_name(PERF_TYPE_RAW, attr->config); | 583 | return NULL; |
688 | } | 584 | } |
689 | 585 | ||
690 | int parse_events_add_pmu(struct list_head **list, int *idx, | 586 | int parse_events_add_pmu(struct list_head **list, int *idx, |
@@ -699,6 +595,9 @@ int parse_events_add_pmu(struct list_head **list, int *idx, | |||
699 | 595 | ||
700 | memset(&attr, 0, sizeof(attr)); | 596 | memset(&attr, 0, sizeof(attr)); |
701 | 597 | ||
598 | if (perf_pmu__check_alias(pmu, head_config)) | ||
599 | return -EINVAL; | ||
600 | |||
702 | /* | 601 | /* |
703 | * Configure hardcoded terms first, no need to check | 602 | * Configure hardcoded terms first, no need to check |
704 | * return value when called with fail == 0 ;) | 603 | * return value when called with fail == 0 ;) |
@@ -709,7 +608,7 @@ int parse_events_add_pmu(struct list_head **list, int *idx, | |||
709 | return -EINVAL; | 608 | return -EINVAL; |
710 | 609 | ||
711 | return add_event(list, idx, &attr, | 610 | return add_event(list, idx, &attr, |
712 | pmu_event_name(&attr, head_config)); | 611 | pmu_event_name(head_config)); |
713 | } | 612 | } |
714 | 613 | ||
715 | void parse_events_update_lists(struct list_head *list_event, | 614 | void parse_events_update_lists(struct list_head *list_event, |
@@ -787,27 +686,62 @@ int parse_events_modifier(struct list_head *list, char *str) | |||
787 | return 0; | 686 | return 0; |
788 | } | 687 | } |
789 | 688 | ||
790 | int parse_events(struct perf_evlist *evlist, const char *str, int unset __used) | 689 | static int parse_events__scanner(const char *str, void *data, int start_token) |
791 | { | 690 | { |
792 | LIST_HEAD(list); | ||
793 | LIST_HEAD(list_tmp); | ||
794 | YY_BUFFER_STATE buffer; | 691 | YY_BUFFER_STATE buffer; |
795 | int ret, idx = evlist->nr_entries; | 692 | void *scanner; |
693 | int ret; | ||
694 | |||
695 | ret = parse_events_lex_init_extra(start_token, &scanner); | ||
696 | if (ret) | ||
697 | return ret; | ||
796 | 698 | ||
797 | buffer = parse_events__scan_string(str); | 699 | buffer = parse_events__scan_string(str, scanner); |
798 | 700 | ||
799 | #ifdef PARSER_DEBUG | 701 | #ifdef PARSER_DEBUG |
800 | parse_events_debug = 1; | 702 | parse_events_debug = 1; |
801 | #endif | 703 | #endif |
802 | ret = parse_events_parse(&list, &idx); | 704 | ret = parse_events_parse(data, scanner); |
803 | 705 | ||
804 | parse_events__flush_buffer(buffer); | 706 | parse_events__flush_buffer(buffer, scanner); |
805 | parse_events__delete_buffer(buffer); | 707 | parse_events__delete_buffer(buffer, scanner); |
806 | parse_events_lex_destroy(); | 708 | parse_events_lex_destroy(scanner); |
709 | return ret; | ||
710 | } | ||
711 | |||
712 | /* | ||
713 | * parse event config string, return a list of event terms. | ||
714 | */ | ||
715 | int parse_events_terms(struct list_head *terms, const char *str) | ||
716 | { | ||
717 | struct parse_events_data__terms data = { | ||
718 | .terms = NULL, | ||
719 | }; | ||
720 | int ret; | ||
807 | 721 | ||
722 | ret = parse_events__scanner(str, &data, PE_START_TERMS); | ||
808 | if (!ret) { | 723 | if (!ret) { |
809 | int entries = idx - evlist->nr_entries; | 724 | list_splice(data.terms, terms); |
810 | perf_evlist__splice_list_tail(evlist, &list, entries); | 725 | free(data.terms); |
726 | return 0; | ||
727 | } | ||
728 | |||
729 | parse_events__free_terms(data.terms); | ||
730 | return ret; | ||
731 | } | ||
732 | |||
733 | int parse_events(struct perf_evlist *evlist, const char *str, int unset __used) | ||
734 | { | ||
735 | struct parse_events_data__events data = { | ||
736 | .list = LIST_HEAD_INIT(data.list), | ||
737 | .idx = evlist->nr_entries, | ||
738 | }; | ||
739 | int ret; | ||
740 | |||
741 | ret = parse_events__scanner(str, &data, PE_START_EVENTS); | ||
742 | if (!ret) { | ||
743 | int entries = data.idx - evlist->nr_entries; | ||
744 | perf_evlist__splice_list_tail(evlist, &data.list, entries); | ||
811 | return 0; | 745 | return 0; |
812 | } | 746 | } |
813 | 747 | ||
@@ -946,16 +880,13 @@ int is_valid_tracepoint(const char *event_string) | |||
946 | return 0; | 880 | return 0; |
947 | } | 881 | } |
948 | 882 | ||
949 | void print_events_type(u8 type) | 883 | static void __print_events_type(u8 type, struct event_symbol *syms, |
884 | unsigned max) | ||
950 | { | 885 | { |
951 | struct event_symbol *syms = event_symbols; | ||
952 | unsigned int i; | ||
953 | char name[64]; | 886 | char name[64]; |
887 | unsigned i; | ||
954 | 888 | ||
955 | for (i = 0; i < ARRAY_SIZE(event_symbols); i++, syms++) { | 889 | for (i = 0; i < max ; i++, syms++) { |
956 | if (type != syms->type) | ||
957 | continue; | ||
958 | |||
959 | if (strlen(syms->alias)) | 890 | if (strlen(syms->alias)) |
960 | snprintf(name, sizeof(name), "%s OR %s", | 891 | snprintf(name, sizeof(name), "%s OR %s", |
961 | syms->symbol, syms->alias); | 892 | syms->symbol, syms->alias); |
@@ -967,19 +898,28 @@ void print_events_type(u8 type) | |||
967 | } | 898 | } |
968 | } | 899 | } |
969 | 900 | ||
901 | void print_events_type(u8 type) | ||
902 | { | ||
903 | if (type == PERF_TYPE_SOFTWARE) | ||
904 | __print_events_type(type, event_symbols_sw, PERF_COUNT_SW_MAX); | ||
905 | else | ||
906 | __print_events_type(type, event_symbols_hw, PERF_COUNT_HW_MAX); | ||
907 | } | ||
908 | |||
970 | int print_hwcache_events(const char *event_glob) | 909 | int print_hwcache_events(const char *event_glob) |
971 | { | 910 | { |
972 | unsigned int type, op, i, printed = 0; | 911 | unsigned int type, op, i, printed = 0; |
912 | char name[64]; | ||
973 | 913 | ||
974 | for (type = 0; type < PERF_COUNT_HW_CACHE_MAX; type++) { | 914 | for (type = 0; type < PERF_COUNT_HW_CACHE_MAX; type++) { |
975 | for (op = 0; op < PERF_COUNT_HW_CACHE_OP_MAX; op++) { | 915 | for (op = 0; op < PERF_COUNT_HW_CACHE_OP_MAX; op++) { |
976 | /* skip invalid cache type */ | 916 | /* skip invalid cache type */ |
977 | if (!is_cache_op_valid(type, op)) | 917 | if (!perf_evsel__is_cache_op_valid(type, op)) |
978 | continue; | 918 | continue; |
979 | 919 | ||
980 | for (i = 0; i < PERF_COUNT_HW_CACHE_RESULT_MAX; i++) { | 920 | for (i = 0; i < PERF_COUNT_HW_CACHE_RESULT_MAX; i++) { |
981 | char *name = event_cache_name(type, op, i); | 921 | __perf_evsel__hw_cache_type_op_res_name(type, op, i, |
982 | 922 | name, sizeof(name)); | |
983 | if (event_glob != NULL && !strglobmatch(name, event_glob)) | 923 | if (event_glob != NULL && !strglobmatch(name, event_glob)) |
984 | continue; | 924 | continue; |
985 | 925 | ||
@@ -993,26 +933,13 @@ int print_hwcache_events(const char *event_glob) | |||
993 | return printed; | 933 | return printed; |
994 | } | 934 | } |
995 | 935 | ||
996 | /* | 936 | static void print_symbol_events(const char *event_glob, unsigned type, |
997 | * Print the help text for the event symbols: | 937 | struct event_symbol *syms, unsigned max) |
998 | */ | ||
999 | void print_events(const char *event_glob) | ||
1000 | { | 938 | { |
1001 | unsigned int i, type, prev_type = -1, printed = 0, ntypes_printed = 0; | 939 | unsigned i, printed = 0; |
1002 | struct event_symbol *syms = event_symbols; | ||
1003 | char name[MAX_NAME_LEN]; | 940 | char name[MAX_NAME_LEN]; |
1004 | 941 | ||
1005 | printf("\n"); | 942 | for (i = 0; i < max; i++, syms++) { |
1006 | printf("List of pre-defined events (to be used in -e):\n"); | ||
1007 | |||
1008 | for (i = 0; i < ARRAY_SIZE(event_symbols); i++, syms++) { | ||
1009 | type = syms->type; | ||
1010 | |||
1011 | if (type != prev_type && printed) { | ||
1012 | printf("\n"); | ||
1013 | printed = 0; | ||
1014 | ntypes_printed++; | ||
1015 | } | ||
1016 | 943 | ||
1017 | if (event_glob != NULL && | 944 | if (event_glob != NULL && |
1018 | !(strglobmatch(syms->symbol, event_glob) || | 945 | !(strglobmatch(syms->symbol, event_glob) || |
@@ -1023,17 +950,31 @@ void print_events(const char *event_glob) | |||
1023 | snprintf(name, MAX_NAME_LEN, "%s OR %s", syms->symbol, syms->alias); | 950 | snprintf(name, MAX_NAME_LEN, "%s OR %s", syms->symbol, syms->alias); |
1024 | else | 951 | else |
1025 | strncpy(name, syms->symbol, MAX_NAME_LEN); | 952 | strncpy(name, syms->symbol, MAX_NAME_LEN); |
1026 | printf(" %-50s [%s]\n", name, | ||
1027 | event_type_descriptors[type]); | ||
1028 | 953 | ||
1029 | prev_type = type; | 954 | printf(" %-50s [%s]\n", name, event_type_descriptors[type]); |
1030 | ++printed; | 955 | |
956 | printed++; | ||
1031 | } | 957 | } |
1032 | 958 | ||
1033 | if (ntypes_printed) { | 959 | if (printed) |
1034 | printed = 0; | ||
1035 | printf("\n"); | 960 | printf("\n"); |
1036 | } | 961 | } |
962 | |||
963 | /* | ||
964 | * Print the help text for the event symbols: | ||
965 | */ | ||
966 | void print_events(const char *event_glob) | ||
967 | { | ||
968 | |||
969 | printf("\n"); | ||
970 | printf("List of pre-defined events (to be used in -e):\n"); | ||
971 | |||
972 | print_symbol_events(event_glob, PERF_TYPE_HARDWARE, | ||
973 | event_symbols_hw, PERF_COUNT_HW_MAX); | ||
974 | |||
975 | print_symbol_events(event_glob, PERF_TYPE_SOFTWARE, | ||
976 | event_symbols_sw, PERF_COUNT_SW_MAX); | ||
977 | |||
1037 | print_hwcache_events(event_glob); | 978 | print_hwcache_events(event_glob); |
1038 | 979 | ||
1039 | if (event_glob != NULL) | 980 | if (event_glob != NULL) |
@@ -1106,6 +1047,13 @@ int parse_events__term_str(struct parse_events__term **term, | |||
1106 | config, str, 0); | 1047 | config, str, 0); |
1107 | } | 1048 | } |
1108 | 1049 | ||
1050 | int parse_events__term_clone(struct parse_events__term **new, | ||
1051 | struct parse_events__term *term) | ||
1052 | { | ||
1053 | return new_term(new, term->type_val, term->type_term, term->config, | ||
1054 | term->val.str, term->val.num); | ||
1055 | } | ||
1056 | |||
1109 | void parse_events__free_terms(struct list_head *terms) | 1057 | void parse_events__free_terms(struct list_head *terms) |
1110 | { | 1058 | { |
1111 | struct parse_events__term *term, *h; | 1059 | struct parse_events__term *term, *h; |
diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h index 8cac57ab4ee6..ee9c218a193c 100644 --- a/tools/perf/util/parse-events.h +++ b/tools/perf/util/parse-events.h | |||
@@ -26,13 +26,12 @@ extern struct tracepoint_path *tracepoint_id_to_path(u64 config); | |||
26 | extern bool have_tracepoints(struct list_head *evlist); | 26 | extern bool have_tracepoints(struct list_head *evlist); |
27 | 27 | ||
28 | const char *event_type(int type); | 28 | const char *event_type(int type); |
29 | const char *event_name(struct perf_evsel *event); | ||
30 | extern const char *__event_name(int type, u64 config); | ||
31 | 29 | ||
32 | extern int parse_events_option(const struct option *opt, const char *str, | 30 | extern int parse_events_option(const struct option *opt, const char *str, |
33 | int unset); | 31 | int unset); |
34 | extern int parse_events(struct perf_evlist *evlist, const char *str, | 32 | extern int parse_events(struct perf_evlist *evlist, const char *str, |
35 | int unset); | 33 | int unset); |
34 | extern int parse_events_terms(struct list_head *terms, const char *str); | ||
36 | extern int parse_filter(const struct option *opt, const char *str, int unset); | 35 | extern int parse_filter(const struct option *opt, const char *str, int unset); |
37 | 36 | ||
38 | #define EVENTS_HELP_MAX (128*1024) | 37 | #define EVENTS_HELP_MAX (128*1024) |
@@ -63,11 +62,22 @@ struct parse_events__term { | |||
63 | struct list_head list; | 62 | struct list_head list; |
64 | }; | 63 | }; |
65 | 64 | ||
65 | struct parse_events_data__events { | ||
66 | struct list_head list; | ||
67 | int idx; | ||
68 | }; | ||
69 | |||
70 | struct parse_events_data__terms { | ||
71 | struct list_head *terms; | ||
72 | }; | ||
73 | |||
66 | int parse_events__is_hardcoded_term(struct parse_events__term *term); | 74 | int parse_events__is_hardcoded_term(struct parse_events__term *term); |
67 | int parse_events__term_num(struct parse_events__term **_term, | 75 | int parse_events__term_num(struct parse_events__term **_term, |
68 | int type_term, char *config, long num); | 76 | int type_term, char *config, long num); |
69 | int parse_events__term_str(struct parse_events__term **_term, | 77 | int parse_events__term_str(struct parse_events__term **_term, |
70 | int type_term, char *config, char *str); | 78 | int type_term, char *config, char *str); |
79 | int parse_events__term_clone(struct parse_events__term **new, | ||
80 | struct parse_events__term *term); | ||
71 | void parse_events__free_terms(struct list_head *terms); | 81 | void parse_events__free_terms(struct list_head *terms); |
72 | int parse_events_modifier(struct list_head *list, char *str); | 82 | int parse_events_modifier(struct list_head *list, char *str); |
73 | int parse_events_add_tracepoint(struct list_head **list, int *idx, | 83 | int parse_events_add_tracepoint(struct list_head **list, int *idx, |
@@ -83,8 +93,7 @@ int parse_events_add_pmu(struct list_head **list, int *idx, | |||
83 | char *pmu , struct list_head *head_config); | 93 | char *pmu , struct list_head *head_config); |
84 | void parse_events_update_lists(struct list_head *list_event, | 94 | void parse_events_update_lists(struct list_head *list_event, |
85 | struct list_head *list_all); | 95 | struct list_head *list_all); |
86 | void parse_events_error(struct list_head *list_all, | 96 | void parse_events_error(void *data, void *scanner, char const *msg); |
87 | int *idx, char const *msg); | ||
88 | int parse_events__test(void); | 97 | int parse_events__test(void); |
89 | 98 | ||
90 | void print_events(const char *event_glob); | 99 | void print_events(const char *event_glob); |
diff --git a/tools/perf/util/parse-events.l b/tools/perf/util/parse-events.l index 618a8e788399..384ca74c6b22 100644 --- a/tools/perf/util/parse-events.l +++ b/tools/perf/util/parse-events.l | |||
@@ -1,4 +1,6 @@ | |||
1 | 1 | ||
2 | %option reentrant | ||
3 | %option bison-bridge | ||
2 | %option prefix="parse_events_" | 4 | %option prefix="parse_events_" |
3 | %option stack | 5 | %option stack |
4 | 6 | ||
@@ -8,7 +10,10 @@ | |||
8 | #include "parse-events-bison.h" | 10 | #include "parse-events-bison.h" |
9 | #include "parse-events.h" | 11 | #include "parse-events.h" |
10 | 12 | ||
11 | static int __value(char *str, int base, int token) | 13 | char *parse_events_get_text(yyscan_t yyscanner); |
14 | YYSTYPE *parse_events_get_lval(yyscan_t yyscanner); | ||
15 | |||
16 | static int __value(YYSTYPE *yylval, char *str, int base, int token) | ||
12 | { | 17 | { |
13 | long num; | 18 | long num; |
14 | 19 | ||
@@ -17,35 +22,48 @@ static int __value(char *str, int base, int token) | |||
17 | if (errno) | 22 | if (errno) |
18 | return PE_ERROR; | 23 | return PE_ERROR; |
19 | 24 | ||
20 | parse_events_lval.num = num; | 25 | yylval->num = num; |
21 | return token; | 26 | return token; |
22 | } | 27 | } |
23 | 28 | ||
24 | static int value(int base) | 29 | static int value(yyscan_t scanner, int base) |
25 | { | 30 | { |
26 | return __value(parse_events_text, base, PE_VALUE); | 31 | YYSTYPE *yylval = parse_events_get_lval(scanner); |
32 | char *text = parse_events_get_text(scanner); | ||
33 | |||
34 | return __value(yylval, text, base, PE_VALUE); | ||
27 | } | 35 | } |
28 | 36 | ||
29 | static int raw(void) | 37 | static int raw(yyscan_t scanner) |
30 | { | 38 | { |
31 | return __value(parse_events_text + 1, 16, PE_RAW); | 39 | YYSTYPE *yylval = parse_events_get_lval(scanner); |
40 | char *text = parse_events_get_text(scanner); | ||
41 | |||
42 | return __value(yylval, text + 1, 16, PE_RAW); | ||
32 | } | 43 | } |
33 | 44 | ||
34 | static int str(int token) | 45 | static int str(yyscan_t scanner, int token) |
35 | { | 46 | { |
36 | parse_events_lval.str = strdup(parse_events_text); | 47 | YYSTYPE *yylval = parse_events_get_lval(scanner); |
48 | char *text = parse_events_get_text(scanner); | ||
49 | |||
50 | yylval->str = strdup(text); | ||
37 | return token; | 51 | return token; |
38 | } | 52 | } |
39 | 53 | ||
40 | static int sym(int type, int config) | 54 | static int sym(yyscan_t scanner, int type, int config) |
41 | { | 55 | { |
42 | parse_events_lval.num = (type << 16) + config; | 56 | YYSTYPE *yylval = parse_events_get_lval(scanner); |
43 | return PE_VALUE_SYM; | 57 | |
58 | yylval->num = (type << 16) + config; | ||
59 | return type == PERF_TYPE_HARDWARE ? PE_VALUE_SYM_HW : PE_VALUE_SYM_SW; | ||
44 | } | 60 | } |
45 | 61 | ||
46 | static int term(int type) | 62 | static int term(yyscan_t scanner, int type) |
47 | { | 63 | { |
48 | parse_events_lval.num = type; | 64 | YYSTYPE *yylval = parse_events_get_lval(scanner); |
65 | |||
66 | yylval->num = type; | ||
49 | return PE_TERM; | 67 | return PE_TERM; |
50 | } | 68 | } |
51 | 69 | ||
@@ -58,28 +76,41 @@ num_hex 0x[a-fA-F0-9]+ | |||
58 | num_raw_hex [a-fA-F0-9]+ | 76 | num_raw_hex [a-fA-F0-9]+ |
59 | name [a-zA-Z_*?][a-zA-Z0-9_*?]* | 77 | name [a-zA-Z_*?][a-zA-Z0-9_*?]* |
60 | modifier_event [ukhpGH]{1,8} | 78 | modifier_event [ukhpGH]{1,8} |
61 | modifier_bp [rwx] | 79 | modifier_bp [rwx]{1,3} |
62 | 80 | ||
63 | %% | 81 | %% |
64 | cpu-cycles|cycles { return sym(PERF_TYPE_HARDWARE, PERF_COUNT_HW_CPU_CYCLES); } | 82 | |
65 | stalled-cycles-frontend|idle-cycles-frontend { return sym(PERF_TYPE_HARDWARE, PERF_COUNT_HW_STALLED_CYCLES_FRONTEND); } | 83 | %{ |
66 | stalled-cycles-backend|idle-cycles-backend { return sym(PERF_TYPE_HARDWARE, PERF_COUNT_HW_STALLED_CYCLES_BACKEND); } | 84 | { |
67 | instructions { return sym(PERF_TYPE_HARDWARE, PERF_COUNT_HW_INSTRUCTIONS); } | 85 | int start_token; |
68 | cache-references { return sym(PERF_TYPE_HARDWARE, PERF_COUNT_HW_CACHE_REFERENCES); } | 86 | |
69 | cache-misses { return sym(PERF_TYPE_HARDWARE, PERF_COUNT_HW_CACHE_MISSES); } | 87 | start_token = (int) parse_events_get_extra(yyscanner); |
70 | branch-instructions|branches { return sym(PERF_TYPE_HARDWARE, PERF_COUNT_HW_BRANCH_INSTRUCTIONS); } | 88 | if (start_token) { |
71 | branch-misses { return sym(PERF_TYPE_HARDWARE, PERF_COUNT_HW_BRANCH_MISSES); } | 89 | parse_events_set_extra(NULL, yyscanner); |
72 | bus-cycles { return sym(PERF_TYPE_HARDWARE, PERF_COUNT_HW_BUS_CYCLES); } | 90 | return start_token; |
73 | ref-cycles { return sym(PERF_TYPE_HARDWARE, PERF_COUNT_HW_REF_CPU_CYCLES); } | 91 | } |
74 | cpu-clock { return sym(PERF_TYPE_SOFTWARE, PERF_COUNT_SW_CPU_CLOCK); } | 92 | } |
75 | task-clock { return sym(PERF_TYPE_SOFTWARE, PERF_COUNT_SW_TASK_CLOCK); } | 93 | %} |
76 | page-faults|faults { return sym(PERF_TYPE_SOFTWARE, PERF_COUNT_SW_PAGE_FAULTS); } | 94 | |
77 | minor-faults { return sym(PERF_TYPE_SOFTWARE, PERF_COUNT_SW_PAGE_FAULTS_MIN); } | 95 | cpu-cycles|cycles { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_CPU_CYCLES); } |
78 | major-faults { return sym(PERF_TYPE_SOFTWARE, PERF_COUNT_SW_PAGE_FAULTS_MAJ); } | 96 | stalled-cycles-frontend|idle-cycles-frontend { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_STALLED_CYCLES_FRONTEND); } |
79 | context-switches|cs { return sym(PERF_TYPE_SOFTWARE, PERF_COUNT_SW_CONTEXT_SWITCHES); } | 97 | stalled-cycles-backend|idle-cycles-backend { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_STALLED_CYCLES_BACKEND); } |
80 | cpu-migrations|migrations { return sym(PERF_TYPE_SOFTWARE, PERF_COUNT_SW_CPU_MIGRATIONS); } | 98 | instructions { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_INSTRUCTIONS); } |
81 | alignment-faults { return sym(PERF_TYPE_SOFTWARE, PERF_COUNT_SW_ALIGNMENT_FAULTS); } | 99 | cache-references { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_CACHE_REFERENCES); } |
82 | emulation-faults { return sym(PERF_TYPE_SOFTWARE, PERF_COUNT_SW_EMULATION_FAULTS); } | 100 | cache-misses { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_CACHE_MISSES); } |
101 | branch-instructions|branches { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_BRANCH_INSTRUCTIONS); } | ||
102 | branch-misses { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_BRANCH_MISSES); } | ||
103 | bus-cycles { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_BUS_CYCLES); } | ||
104 | ref-cycles { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_REF_CPU_CYCLES); } | ||
105 | cpu-clock { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_CPU_CLOCK); } | ||
106 | task-clock { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_TASK_CLOCK); } | ||
107 | page-faults|faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_PAGE_FAULTS); } | ||
108 | minor-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_PAGE_FAULTS_MIN); } | ||
109 | major-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_PAGE_FAULTS_MAJ); } | ||
110 | context-switches|cs { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_CONTEXT_SWITCHES); } | ||
111 | cpu-migrations|migrations { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_CPU_MIGRATIONS); } | ||
112 | alignment-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_ALIGNMENT_FAULTS); } | ||
113 | emulation-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_EMULATION_FAULTS); } | ||
83 | 114 | ||
84 | L1-dcache|l1-d|l1d|L1-data | | 115 | L1-dcache|l1-d|l1d|L1-data | |
85 | L1-icache|l1-i|l1i|L1-instruction | | 116 | L1-icache|l1-i|l1i|L1-instruction | |
@@ -87,14 +118,14 @@ LLC|L2 | | |||
87 | dTLB|d-tlb|Data-TLB | | 118 | dTLB|d-tlb|Data-TLB | |
88 | iTLB|i-tlb|Instruction-TLB | | 119 | iTLB|i-tlb|Instruction-TLB | |
89 | branch|branches|bpu|btb|bpc | | 120 | branch|branches|bpu|btb|bpc | |
90 | node { return str(PE_NAME_CACHE_TYPE); } | 121 | node { return str(yyscanner, PE_NAME_CACHE_TYPE); } |
91 | 122 | ||
92 | load|loads|read | | 123 | load|loads|read | |
93 | store|stores|write | | 124 | store|stores|write | |
94 | prefetch|prefetches | | 125 | prefetch|prefetches | |
95 | speculative-read|speculative-load | | 126 | speculative-read|speculative-load | |
96 | refs|Reference|ops|access | | 127 | refs|Reference|ops|access | |
97 | misses|miss { return str(PE_NAME_CACHE_OP_RESULT); } | 128 | misses|miss { return str(yyscanner, PE_NAME_CACHE_OP_RESULT); } |
98 | 129 | ||
99 | /* | 130 | /* |
100 | * These are event config hardcoded term names to be specified | 131 | * These are event config hardcoded term names to be specified |
@@ -102,38 +133,39 @@ misses|miss { return str(PE_NAME_CACHE_OP_RESULT); } | |||
102 | * so we can put them here directly. In case the we have a conflict | 133 | * so we can put them here directly. In case the we have a conflict |
103 | * in future, this needs to go into '//' condition block. | 134 | * in future, this needs to go into '//' condition block. |
104 | */ | 135 | */ |
105 | config { return term(PARSE_EVENTS__TERM_TYPE_CONFIG); } | 136 | config { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_CONFIG); } |
106 | config1 { return term(PARSE_EVENTS__TERM_TYPE_CONFIG1); } | 137 | config1 { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_CONFIG1); } |
107 | config2 { return term(PARSE_EVENTS__TERM_TYPE_CONFIG2); } | 138 | config2 { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_CONFIG2); } |
108 | name { return term(PARSE_EVENTS__TERM_TYPE_NAME); } | 139 | name { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_NAME); } |
109 | period { return term(PARSE_EVENTS__TERM_TYPE_SAMPLE_PERIOD); } | 140 | period { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_SAMPLE_PERIOD); } |
110 | branch_type { return term(PARSE_EVENTS__TERM_TYPE_BRANCH_SAMPLE_TYPE); } | 141 | branch_type { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_BRANCH_SAMPLE_TYPE); } |
111 | 142 | ||
112 | mem: { BEGIN(mem); return PE_PREFIX_MEM; } | 143 | mem: { BEGIN(mem); return PE_PREFIX_MEM; } |
113 | r{num_raw_hex} { return raw(); } | 144 | r{num_raw_hex} { return raw(yyscanner); } |
114 | {num_dec} { return value(10); } | 145 | {num_dec} { return value(yyscanner, 10); } |
115 | {num_hex} { return value(16); } | 146 | {num_hex} { return value(yyscanner, 16); } |
116 | 147 | ||
117 | {modifier_event} { return str(PE_MODIFIER_EVENT); } | 148 | {modifier_event} { return str(yyscanner, PE_MODIFIER_EVENT); } |
118 | {name} { return str(PE_NAME); } | 149 | {name} { return str(yyscanner, PE_NAME); } |
119 | "/" { return '/'; } | 150 | "/" { return '/'; } |
120 | - { return '-'; } | 151 | - { return '-'; } |
121 | , { return ','; } | 152 | , { return ','; } |
122 | : { return ':'; } | 153 | : { return ':'; } |
123 | = { return '='; } | 154 | = { return '='; } |
155 | \n { } | ||
124 | 156 | ||
125 | <mem>{ | 157 | <mem>{ |
126 | {modifier_bp} { return str(PE_MODIFIER_BP); } | 158 | {modifier_bp} { return str(yyscanner, PE_MODIFIER_BP); } |
127 | : { return ':'; } | 159 | : { return ':'; } |
128 | {num_dec} { return value(10); } | 160 | {num_dec} { return value(yyscanner, 10); } |
129 | {num_hex} { return value(16); } | 161 | {num_hex} { return value(yyscanner, 16); } |
130 | /* | 162 | /* |
131 | * We need to separate 'mem:' scanner part, in order to get specific | 163 | * We need to separate 'mem:' scanner part, in order to get specific |
132 | * modifier bits parsed out. Otherwise we would need to handle PE_NAME | 164 | * modifier bits parsed out. Otherwise we would need to handle PE_NAME |
133 | * and we'd need to parse it manually. During the escape from <mem> | 165 | * and we'd need to parse it manually. During the escape from <mem> |
134 | * state we need to put the escaping char back, so we dont miss it. | 166 | * state we need to put the escaping char back, so we dont miss it. |
135 | */ | 167 | */ |
136 | . { unput(*parse_events_text); BEGIN(INITIAL); } | 168 | . { unput(*yytext); BEGIN(INITIAL); } |
137 | /* | 169 | /* |
138 | * We destroy the scanner after reaching EOF, | 170 | * We destroy the scanner after reaching EOF, |
139 | * but anyway just to be sure get back to INIT state. | 171 | * but anyway just to be sure get back to INIT state. |
@@ -143,7 +175,7 @@ r{num_raw_hex} { return raw(); } | |||
143 | 175 | ||
144 | %% | 176 | %% |
145 | 177 | ||
146 | int parse_events_wrap(void) | 178 | int parse_events_wrap(void *scanner __used) |
147 | { | 179 | { |
148 | return 1; | 180 | return 1; |
149 | } | 181 | } |
diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y index 362cc59332ae..2bc5fbff2b5d 100644 --- a/tools/perf/util/parse-events.y +++ b/tools/perf/util/parse-events.y | |||
@@ -1,7 +1,8 @@ | |||
1 | 1 | %pure-parser | |
2 | %name-prefix "parse_events_" | 2 | %name-prefix "parse_events_" |
3 | %parse-param {struct list_head *list_all} | 3 | %parse-param {void *_data} |
4 | %parse-param {int *idx} | 4 | %parse-param {void *scanner} |
5 | %lex-param {void* scanner} | ||
5 | 6 | ||
6 | %{ | 7 | %{ |
7 | 8 | ||
@@ -12,8 +13,9 @@ | |||
12 | #include "types.h" | 13 | #include "types.h" |
13 | #include "util.h" | 14 | #include "util.h" |
14 | #include "parse-events.h" | 15 | #include "parse-events.h" |
16 | #include "parse-events-bison.h" | ||
15 | 17 | ||
16 | extern int parse_events_lex (void); | 18 | extern int parse_events_lex (YYSTYPE* lvalp, void* scanner); |
17 | 19 | ||
18 | #define ABORT_ON(val) \ | 20 | #define ABORT_ON(val) \ |
19 | do { \ | 21 | do { \ |
@@ -23,14 +25,16 @@ do { \ | |||
23 | 25 | ||
24 | %} | 26 | %} |
25 | 27 | ||
26 | %token PE_VALUE PE_VALUE_SYM PE_RAW PE_TERM | 28 | %token PE_START_EVENTS PE_START_TERMS |
29 | %token PE_VALUE PE_VALUE_SYM_HW PE_VALUE_SYM_SW PE_RAW PE_TERM | ||
27 | %token PE_NAME | 30 | %token PE_NAME |
28 | %token PE_MODIFIER_EVENT PE_MODIFIER_BP | 31 | %token PE_MODIFIER_EVENT PE_MODIFIER_BP |
29 | %token PE_NAME_CACHE_TYPE PE_NAME_CACHE_OP_RESULT | 32 | %token PE_NAME_CACHE_TYPE PE_NAME_CACHE_OP_RESULT |
30 | %token PE_PREFIX_MEM PE_PREFIX_RAW | 33 | %token PE_PREFIX_MEM PE_PREFIX_RAW |
31 | %token PE_ERROR | 34 | %token PE_ERROR |
32 | %type <num> PE_VALUE | 35 | %type <num> PE_VALUE |
33 | %type <num> PE_VALUE_SYM | 36 | %type <num> PE_VALUE_SYM_HW |
37 | %type <num> PE_VALUE_SYM_SW | ||
34 | %type <num> PE_RAW | 38 | %type <num> PE_RAW |
35 | %type <num> PE_TERM | 39 | %type <num> PE_TERM |
36 | %type <str> PE_NAME | 40 | %type <str> PE_NAME |
@@ -38,6 +42,7 @@ do { \ | |||
38 | %type <str> PE_NAME_CACHE_OP_RESULT | 42 | %type <str> PE_NAME_CACHE_OP_RESULT |
39 | %type <str> PE_MODIFIER_EVENT | 43 | %type <str> PE_MODIFIER_EVENT |
40 | %type <str> PE_MODIFIER_BP | 44 | %type <str> PE_MODIFIER_BP |
45 | %type <num> value_sym | ||
41 | %type <head> event_config | 46 | %type <head> event_config |
42 | %type <term> event_term | 47 | %type <term> event_term |
43 | %type <head> event_pmu | 48 | %type <head> event_pmu |
@@ -58,24 +63,33 @@ do { \ | |||
58 | } | 63 | } |
59 | %% | 64 | %% |
60 | 65 | ||
66 | start: | ||
67 | PE_START_EVENTS events | ||
68 | | | ||
69 | PE_START_TERMS terms | ||
70 | |||
61 | events: | 71 | events: |
62 | events ',' event | event | 72 | events ',' event | event |
63 | 73 | ||
64 | event: | 74 | event: |
65 | event_def PE_MODIFIER_EVENT | 75 | event_def PE_MODIFIER_EVENT |
66 | { | 76 | { |
77 | struct parse_events_data__events *data = _data; | ||
78 | |||
67 | /* | 79 | /* |
68 | * Apply modifier on all events added by single event definition | 80 | * Apply modifier on all events added by single event definition |
69 | * (there could be more events added for multiple tracepoint | 81 | * (there could be more events added for multiple tracepoint |
70 | * definitions via '*?'. | 82 | * definitions via '*?'. |
71 | */ | 83 | */ |
72 | ABORT_ON(parse_events_modifier($1, $2)); | 84 | ABORT_ON(parse_events_modifier($1, $2)); |
73 | parse_events_update_lists($1, list_all); | 85 | parse_events_update_lists($1, &data->list); |
74 | } | 86 | } |
75 | | | 87 | | |
76 | event_def | 88 | event_def |
77 | { | 89 | { |
78 | parse_events_update_lists($1, list_all); | 90 | struct parse_events_data__events *data = _data; |
91 | |||
92 | parse_events_update_lists($1, &data->list); | ||
79 | } | 93 | } |
80 | 94 | ||
81 | event_def: event_pmu | | 95 | event_def: event_pmu | |
@@ -89,104 +103,131 @@ event_def: event_pmu | | |||
89 | event_pmu: | 103 | event_pmu: |
90 | PE_NAME '/' event_config '/' | 104 | PE_NAME '/' event_config '/' |
91 | { | 105 | { |
106 | struct parse_events_data__events *data = _data; | ||
92 | struct list_head *list = NULL; | 107 | struct list_head *list = NULL; |
93 | 108 | ||
94 | ABORT_ON(parse_events_add_pmu(&list, idx, $1, $3)); | 109 | ABORT_ON(parse_events_add_pmu(&list, &data->idx, $1, $3)); |
95 | parse_events__free_terms($3); | 110 | parse_events__free_terms($3); |
96 | $$ = list; | 111 | $$ = list; |
97 | } | 112 | } |
98 | 113 | ||
114 | value_sym: | ||
115 | PE_VALUE_SYM_HW | ||
116 | | | ||
117 | PE_VALUE_SYM_SW | ||
118 | |||
99 | event_legacy_symbol: | 119 | event_legacy_symbol: |
100 | PE_VALUE_SYM '/' event_config '/' | 120 | value_sym '/' event_config '/' |
101 | { | 121 | { |
122 | struct parse_events_data__events *data = _data; | ||
102 | struct list_head *list = NULL; | 123 | struct list_head *list = NULL; |
103 | int type = $1 >> 16; | 124 | int type = $1 >> 16; |
104 | int config = $1 & 255; | 125 | int config = $1 & 255; |
105 | 126 | ||
106 | ABORT_ON(parse_events_add_numeric(&list, idx, type, config, $3)); | 127 | ABORT_ON(parse_events_add_numeric(&list, &data->idx, |
128 | type, config, $3)); | ||
107 | parse_events__free_terms($3); | 129 | parse_events__free_terms($3); |
108 | $$ = list; | 130 | $$ = list; |
109 | } | 131 | } |
110 | | | 132 | | |
111 | PE_VALUE_SYM sep_slash_dc | 133 | value_sym sep_slash_dc |
112 | { | 134 | { |
135 | struct parse_events_data__events *data = _data; | ||
113 | struct list_head *list = NULL; | 136 | struct list_head *list = NULL; |
114 | int type = $1 >> 16; | 137 | int type = $1 >> 16; |
115 | int config = $1 & 255; | 138 | int config = $1 & 255; |
116 | 139 | ||
117 | ABORT_ON(parse_events_add_numeric(&list, idx, type, config, NULL)); | 140 | ABORT_ON(parse_events_add_numeric(&list, &data->idx, |
141 | type, config, NULL)); | ||
118 | $$ = list; | 142 | $$ = list; |
119 | } | 143 | } |
120 | 144 | ||
121 | event_legacy_cache: | 145 | event_legacy_cache: |
122 | PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT '-' PE_NAME_CACHE_OP_RESULT | 146 | PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT '-' PE_NAME_CACHE_OP_RESULT |
123 | { | 147 | { |
148 | struct parse_events_data__events *data = _data; | ||
124 | struct list_head *list = NULL; | 149 | struct list_head *list = NULL; |
125 | 150 | ||
126 | ABORT_ON(parse_events_add_cache(&list, idx, $1, $3, $5)); | 151 | ABORT_ON(parse_events_add_cache(&list, &data->idx, $1, $3, $5)); |
127 | $$ = list; | 152 | $$ = list; |
128 | } | 153 | } |
129 | | | 154 | | |
130 | PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT | 155 | PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT |
131 | { | 156 | { |
157 | struct parse_events_data__events *data = _data; | ||
132 | struct list_head *list = NULL; | 158 | struct list_head *list = NULL; |
133 | 159 | ||
134 | ABORT_ON(parse_events_add_cache(&list, idx, $1, $3, NULL)); | 160 | ABORT_ON(parse_events_add_cache(&list, &data->idx, $1, $3, NULL)); |
135 | $$ = list; | 161 | $$ = list; |
136 | } | 162 | } |
137 | | | 163 | | |
138 | PE_NAME_CACHE_TYPE | 164 | PE_NAME_CACHE_TYPE |
139 | { | 165 | { |
166 | struct parse_events_data__events *data = _data; | ||
140 | struct list_head *list = NULL; | 167 | struct list_head *list = NULL; |
141 | 168 | ||
142 | ABORT_ON(parse_events_add_cache(&list, idx, $1, NULL, NULL)); | 169 | ABORT_ON(parse_events_add_cache(&list, &data->idx, $1, NULL, NULL)); |
143 | $$ = list; | 170 | $$ = list; |
144 | } | 171 | } |
145 | 172 | ||
146 | event_legacy_mem: | 173 | event_legacy_mem: |
147 | PE_PREFIX_MEM PE_VALUE ':' PE_MODIFIER_BP sep_dc | 174 | PE_PREFIX_MEM PE_VALUE ':' PE_MODIFIER_BP sep_dc |
148 | { | 175 | { |
176 | struct parse_events_data__events *data = _data; | ||
149 | struct list_head *list = NULL; | 177 | struct list_head *list = NULL; |
150 | 178 | ||
151 | ABORT_ON(parse_events_add_breakpoint(&list, idx, (void *) $2, $4)); | 179 | ABORT_ON(parse_events_add_breakpoint(&list, &data->idx, |
180 | (void *) $2, $4)); | ||
152 | $$ = list; | 181 | $$ = list; |
153 | } | 182 | } |
154 | | | 183 | | |
155 | PE_PREFIX_MEM PE_VALUE sep_dc | 184 | PE_PREFIX_MEM PE_VALUE sep_dc |
156 | { | 185 | { |
186 | struct parse_events_data__events *data = _data; | ||
157 | struct list_head *list = NULL; | 187 | struct list_head *list = NULL; |
158 | 188 | ||
159 | ABORT_ON(parse_events_add_breakpoint(&list, idx, (void *) $2, NULL)); | 189 | ABORT_ON(parse_events_add_breakpoint(&list, &data->idx, |
190 | (void *) $2, NULL)); | ||
160 | $$ = list; | 191 | $$ = list; |
161 | } | 192 | } |
162 | 193 | ||
163 | event_legacy_tracepoint: | 194 | event_legacy_tracepoint: |
164 | PE_NAME ':' PE_NAME | 195 | PE_NAME ':' PE_NAME |
165 | { | 196 | { |
197 | struct parse_events_data__events *data = _data; | ||
166 | struct list_head *list = NULL; | 198 | struct list_head *list = NULL; |
167 | 199 | ||
168 | ABORT_ON(parse_events_add_tracepoint(&list, idx, $1, $3)); | 200 | ABORT_ON(parse_events_add_tracepoint(&list, &data->idx, $1, $3)); |
169 | $$ = list; | 201 | $$ = list; |
170 | } | 202 | } |
171 | 203 | ||
172 | event_legacy_numeric: | 204 | event_legacy_numeric: |
173 | PE_VALUE ':' PE_VALUE | 205 | PE_VALUE ':' PE_VALUE |
174 | { | 206 | { |
207 | struct parse_events_data__events *data = _data; | ||
175 | struct list_head *list = NULL; | 208 | struct list_head *list = NULL; |
176 | 209 | ||
177 | ABORT_ON(parse_events_add_numeric(&list, idx, $1, $3, NULL)); | 210 | ABORT_ON(parse_events_add_numeric(&list, &data->idx, $1, $3, NULL)); |
178 | $$ = list; | 211 | $$ = list; |
179 | } | 212 | } |
180 | 213 | ||
181 | event_legacy_raw: | 214 | event_legacy_raw: |
182 | PE_RAW | 215 | PE_RAW |
183 | { | 216 | { |
217 | struct parse_events_data__events *data = _data; | ||
184 | struct list_head *list = NULL; | 218 | struct list_head *list = NULL; |
185 | 219 | ||
186 | ABORT_ON(parse_events_add_numeric(&list, idx, PERF_TYPE_RAW, $1, NULL)); | 220 | ABORT_ON(parse_events_add_numeric(&list, &data->idx, |
221 | PERF_TYPE_RAW, $1, NULL)); | ||
187 | $$ = list; | 222 | $$ = list; |
188 | } | 223 | } |
189 | 224 | ||
225 | terms: event_config | ||
226 | { | ||
227 | struct parse_events_data__terms *data = _data; | ||
228 | data->terms = $1; | ||
229 | } | ||
230 | |||
190 | event_config: | 231 | event_config: |
191 | event_config ',' event_term | 232 | event_config ',' event_term |
192 | { | 233 | { |
@@ -267,8 +308,7 @@ sep_slash_dc: '/' | ':' | | |||
267 | 308 | ||
268 | %% | 309 | %% |
269 | 310 | ||
270 | void parse_events_error(struct list_head *list_all __used, | 311 | void parse_events_error(void *data __used, void *scanner __used, |
271 | int *idx __used, | ||
272 | char const *msg __used) | 312 | char const *msg __used) |
273 | { | 313 | { |
274 | } | 314 | } |
diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index a119a5371699..67715a42cd6d 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c | |||
@@ -72,7 +72,7 @@ static int pmu_format(char *name, struct list_head *format) | |||
72 | "%s/bus/event_source/devices/%s/format", sysfs, name); | 72 | "%s/bus/event_source/devices/%s/format", sysfs, name); |
73 | 73 | ||
74 | if (stat(path, &st) < 0) | 74 | if (stat(path, &st) < 0) |
75 | return -1; | 75 | return 0; /* no error if format does not exist */ |
76 | 76 | ||
77 | if (pmu_format_parse(path, format)) | 77 | if (pmu_format_parse(path, format)) |
78 | return -1; | 78 | return -1; |
@@ -80,6 +80,114 @@ static int pmu_format(char *name, struct list_head *format) | |||
80 | return 0; | 80 | return 0; |
81 | } | 81 | } |
82 | 82 | ||
83 | static int perf_pmu__new_alias(struct list_head *list, char *name, FILE *file) | ||
84 | { | ||
85 | struct perf_pmu__alias *alias; | ||
86 | char buf[256]; | ||
87 | int ret; | ||
88 | |||
89 | ret = fread(buf, 1, sizeof(buf), file); | ||
90 | if (ret == 0) | ||
91 | return -EINVAL; | ||
92 | buf[ret] = 0; | ||
93 | |||
94 | alias = malloc(sizeof(*alias)); | ||
95 | if (!alias) | ||
96 | return -ENOMEM; | ||
97 | |||
98 | INIT_LIST_HEAD(&alias->terms); | ||
99 | ret = parse_events_terms(&alias->terms, buf); | ||
100 | if (ret) { | ||
101 | free(alias); | ||
102 | return ret; | ||
103 | } | ||
104 | |||
105 | alias->name = strdup(name); | ||
106 | list_add_tail(&alias->list, list); | ||
107 | return 0; | ||
108 | } | ||
109 | |||
110 | /* | ||
111 | * Process all the sysfs attributes located under the directory | ||
112 | * specified in 'dir' parameter. | ||
113 | */ | ||
114 | static int pmu_aliases_parse(char *dir, struct list_head *head) | ||
115 | { | ||
116 | struct dirent *evt_ent; | ||
117 | DIR *event_dir; | ||
118 | int ret = 0; | ||
119 | |||
120 | event_dir = opendir(dir); | ||
121 | if (!event_dir) | ||
122 | return -EINVAL; | ||
123 | |||
124 | while (!ret && (evt_ent = readdir(event_dir))) { | ||
125 | char path[PATH_MAX]; | ||
126 | char *name = evt_ent->d_name; | ||
127 | FILE *file; | ||
128 | |||
129 | if (!strcmp(name, ".") || !strcmp(name, "..")) | ||
130 | continue; | ||
131 | |||
132 | snprintf(path, PATH_MAX, "%s/%s", dir, name); | ||
133 | |||
134 | ret = -EINVAL; | ||
135 | file = fopen(path, "r"); | ||
136 | if (!file) | ||
137 | break; | ||
138 | ret = perf_pmu__new_alias(head, name, file); | ||
139 | fclose(file); | ||
140 | } | ||
141 | |||
142 | closedir(event_dir); | ||
143 | return ret; | ||
144 | } | ||
145 | |||
146 | /* | ||
147 | * Reading the pmu event aliases definition, which should be located at: | ||
148 | * /sys/bus/event_source/devices/<dev>/events as sysfs group attributes. | ||
149 | */ | ||
150 | static int pmu_aliases(char *name, struct list_head *head) | ||
151 | { | ||
152 | struct stat st; | ||
153 | char path[PATH_MAX]; | ||
154 | const char *sysfs; | ||
155 | |||
156 | sysfs = sysfs_find_mountpoint(); | ||
157 | if (!sysfs) | ||
158 | return -1; | ||
159 | |||
160 | snprintf(path, PATH_MAX, | ||
161 | "%s/bus/event_source/devices/%s/events", sysfs, name); | ||
162 | |||
163 | if (stat(path, &st) < 0) | ||
164 | return -1; | ||
165 | |||
166 | if (pmu_aliases_parse(path, head)) | ||
167 | return -1; | ||
168 | |||
169 | return 0; | ||
170 | } | ||
171 | |||
172 | static int pmu_alias_terms(struct perf_pmu__alias *alias, | ||
173 | struct list_head *terms) | ||
174 | { | ||
175 | struct parse_events__term *term, *clone; | ||
176 | LIST_HEAD(list); | ||
177 | int ret; | ||
178 | |||
179 | list_for_each_entry(term, &alias->terms, list) { | ||
180 | ret = parse_events__term_clone(&clone, term); | ||
181 | if (ret) { | ||
182 | parse_events__free_terms(&list); | ||
183 | return ret; | ||
184 | } | ||
185 | list_add_tail(&clone->list, &list); | ||
186 | } | ||
187 | list_splice(&list, terms); | ||
188 | return 0; | ||
189 | } | ||
190 | |||
83 | /* | 191 | /* |
84 | * Reading/parsing the default pmu type value, which should be | 192 | * Reading/parsing the default pmu type value, which should be |
85 | * located at: | 193 | * located at: |
@@ -118,6 +226,7 @@ static struct perf_pmu *pmu_lookup(char *name) | |||
118 | { | 226 | { |
119 | struct perf_pmu *pmu; | 227 | struct perf_pmu *pmu; |
120 | LIST_HEAD(format); | 228 | LIST_HEAD(format); |
229 | LIST_HEAD(aliases); | ||
121 | __u32 type; | 230 | __u32 type; |
122 | 231 | ||
123 | /* | 232 | /* |
@@ -135,10 +244,15 @@ static struct perf_pmu *pmu_lookup(char *name) | |||
135 | if (!pmu) | 244 | if (!pmu) |
136 | return NULL; | 245 | return NULL; |
137 | 246 | ||
247 | pmu_aliases(name, &aliases); | ||
248 | |||
138 | INIT_LIST_HEAD(&pmu->format); | 249 | INIT_LIST_HEAD(&pmu->format); |
250 | INIT_LIST_HEAD(&pmu->aliases); | ||
139 | list_splice(&format, &pmu->format); | 251 | list_splice(&format, &pmu->format); |
252 | list_splice(&aliases, &pmu->aliases); | ||
140 | pmu->name = strdup(name); | 253 | pmu->name = strdup(name); |
141 | pmu->type = type; | 254 | pmu->type = type; |
255 | list_add_tail(&pmu->list, &pmus); | ||
142 | return pmu; | 256 | return pmu; |
143 | } | 257 | } |
144 | 258 | ||
@@ -279,6 +393,59 @@ int perf_pmu__config(struct perf_pmu *pmu, struct perf_event_attr *attr, | |||
279 | return pmu_config(&pmu->format, attr, head_terms); | 393 | return pmu_config(&pmu->format, attr, head_terms); |
280 | } | 394 | } |
281 | 395 | ||
396 | static struct perf_pmu__alias *pmu_find_alias(struct perf_pmu *pmu, | ||
397 | struct parse_events__term *term) | ||
398 | { | ||
399 | struct perf_pmu__alias *alias; | ||
400 | char *name; | ||
401 | |||
402 | if (parse_events__is_hardcoded_term(term)) | ||
403 | return NULL; | ||
404 | |||
405 | if (term->type_val == PARSE_EVENTS__TERM_TYPE_NUM) { | ||
406 | if (term->val.num != 1) | ||
407 | return NULL; | ||
408 | if (pmu_find_format(&pmu->format, term->config)) | ||
409 | return NULL; | ||
410 | name = term->config; | ||
411 | } else if (term->type_val == PARSE_EVENTS__TERM_TYPE_STR) { | ||
412 | if (strcasecmp(term->config, "event")) | ||
413 | return NULL; | ||
414 | name = term->val.str; | ||
415 | } else { | ||
416 | return NULL; | ||
417 | } | ||
418 | |||
419 | list_for_each_entry(alias, &pmu->aliases, list) { | ||
420 | if (!strcasecmp(alias->name, name)) | ||
421 | return alias; | ||
422 | } | ||
423 | return NULL; | ||
424 | } | ||
425 | |||
426 | /* | ||
427 | * Find alias in the terms list and replace it with the terms | ||
428 | * defined for the alias | ||
429 | */ | ||
430 | int perf_pmu__check_alias(struct perf_pmu *pmu, struct list_head *head_terms) | ||
431 | { | ||
432 | struct parse_events__term *term, *h; | ||
433 | struct perf_pmu__alias *alias; | ||
434 | int ret; | ||
435 | |||
436 | list_for_each_entry_safe(term, h, head_terms, list) { | ||
437 | alias = pmu_find_alias(pmu, term); | ||
438 | if (!alias) | ||
439 | continue; | ||
440 | ret = pmu_alias_terms(alias, &term->list); | ||
441 | if (ret) | ||
442 | return ret; | ||
443 | list_del(&term->list); | ||
444 | free(term); | ||
445 | } | ||
446 | return 0; | ||
447 | } | ||
448 | |||
282 | int perf_pmu__new_format(struct list_head *list, char *name, | 449 | int perf_pmu__new_format(struct list_head *list, char *name, |
283 | int config, unsigned long *bits) | 450 | int config, unsigned long *bits) |
284 | { | 451 | { |
diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h index 68c0db965e1f..535f2c5258ab 100644 --- a/tools/perf/util/pmu.h +++ b/tools/perf/util/pmu.h | |||
@@ -19,17 +19,26 @@ struct perf_pmu__format { | |||
19 | struct list_head list; | 19 | struct list_head list; |
20 | }; | 20 | }; |
21 | 21 | ||
22 | struct perf_pmu__alias { | ||
23 | char *name; | ||
24 | struct list_head terms; | ||
25 | struct list_head list; | ||
26 | }; | ||
27 | |||
22 | struct perf_pmu { | 28 | struct perf_pmu { |
23 | char *name; | 29 | char *name; |
24 | __u32 type; | 30 | __u32 type; |
25 | struct list_head format; | 31 | struct list_head format; |
32 | struct list_head aliases; | ||
26 | struct list_head list; | 33 | struct list_head list; |
27 | }; | 34 | }; |
28 | 35 | ||
29 | struct perf_pmu *perf_pmu__find(char *name); | 36 | struct perf_pmu *perf_pmu__find(char *name); |
30 | int perf_pmu__config(struct perf_pmu *pmu, struct perf_event_attr *attr, | 37 | int perf_pmu__config(struct perf_pmu *pmu, struct perf_event_attr *attr, |
31 | struct list_head *head_terms); | 38 | struct list_head *head_terms); |
32 | 39 | int perf_pmu__check_alias(struct perf_pmu *pmu, struct list_head *head_terms); | |
40 | struct list_head *perf_pmu__alias(struct perf_pmu *pmu, | ||
41 | struct list_head *head_terms); | ||
33 | int perf_pmu_wrap(void); | 42 | int perf_pmu_wrap(void); |
34 | void perf_pmu_error(struct list_head *list, char *name, char const *msg); | 43 | void perf_pmu_error(struct list_head *list, char *name, char const *msg); |
35 | 44 | ||
diff --git a/tools/perf/util/scripting-engines/trace-event-perl.c b/tools/perf/util/scripting-engines/trace-event-perl.c index 4c1b3d72a1d2..02dfa19a467f 100644 --- a/tools/perf/util/scripting-engines/trace-event-perl.c +++ b/tools/perf/util/scripting-engines/trace-event-perl.c | |||
@@ -209,6 +209,10 @@ static void define_event_symbols(struct event_format *event, | |||
209 | define_symbolic_values(args->symbol.symbols, ev_name, | 209 | define_symbolic_values(args->symbol.symbols, ev_name, |
210 | cur_field_name); | 210 | cur_field_name); |
211 | break; | 211 | break; |
212 | case PRINT_HEX: | ||
213 | define_event_symbols(event, ev_name, args->hex.field); | ||
214 | define_event_symbols(event, ev_name, args->hex.size); | ||
215 | break; | ||
212 | case PRINT_BSTRING: | 216 | case PRINT_BSTRING: |
213 | case PRINT_DYNAMIC_ARRAY: | 217 | case PRINT_DYNAMIC_ARRAY: |
214 | case PRINT_STRING: | 218 | case PRINT_STRING: |
@@ -233,7 +237,8 @@ static void define_event_symbols(struct event_format *event, | |||
233 | define_event_symbols(event, ev_name, args->next); | 237 | define_event_symbols(event, ev_name, args->next); |
234 | } | 238 | } |
235 | 239 | ||
236 | static inline struct event_format *find_cache_event(int type) | 240 | static inline |
241 | struct event_format *find_cache_event(struct pevent *pevent, int type) | ||
237 | { | 242 | { |
238 | static char ev_name[256]; | 243 | static char ev_name[256]; |
239 | struct event_format *event; | 244 | struct event_format *event; |
@@ -241,7 +246,7 @@ static inline struct event_format *find_cache_event(int type) | |||
241 | if (events[type]) | 246 | if (events[type]) |
242 | return events[type]; | 247 | return events[type]; |
243 | 248 | ||
244 | events[type] = event = trace_find_event(type); | 249 | events[type] = event = pevent_find_event(pevent, type); |
245 | if (!event) | 250 | if (!event) |
246 | return NULL; | 251 | return NULL; |
247 | 252 | ||
@@ -252,7 +257,8 @@ static inline struct event_format *find_cache_event(int type) | |||
252 | return event; | 257 | return event; |
253 | } | 258 | } |
254 | 259 | ||
255 | static void perl_process_tracepoint(union perf_event *pevent __unused, | 260 | static void perl_process_tracepoint(union perf_event *perf_event __unused, |
261 | struct pevent *pevent, | ||
256 | struct perf_sample *sample, | 262 | struct perf_sample *sample, |
257 | struct perf_evsel *evsel, | 263 | struct perf_evsel *evsel, |
258 | struct machine *machine __unused, | 264 | struct machine *machine __unused, |
@@ -275,13 +281,13 @@ static void perl_process_tracepoint(union perf_event *pevent __unused, | |||
275 | if (evsel->attr.type != PERF_TYPE_TRACEPOINT) | 281 | if (evsel->attr.type != PERF_TYPE_TRACEPOINT) |
276 | return; | 282 | return; |
277 | 283 | ||
278 | type = trace_parse_common_type(data); | 284 | type = trace_parse_common_type(pevent, data); |
279 | 285 | ||
280 | event = find_cache_event(type); | 286 | event = find_cache_event(pevent, type); |
281 | if (!event) | 287 | if (!event) |
282 | die("ug! no event found for type %d", type); | 288 | die("ug! no event found for type %d", type); |
283 | 289 | ||
284 | pid = trace_parse_common_pid(data); | 290 | pid = trace_parse_common_pid(pevent, data); |
285 | 291 | ||
286 | sprintf(handler, "%s::%s", event->system, event->name); | 292 | sprintf(handler, "%s::%s", event->system, event->name); |
287 | 293 | ||
@@ -314,7 +320,8 @@ static void perl_process_tracepoint(union perf_event *pevent __unused, | |||
314 | offset = field->offset; | 320 | offset = field->offset; |
315 | XPUSHs(sv_2mortal(newSVpv((char *)data + offset, 0))); | 321 | XPUSHs(sv_2mortal(newSVpv((char *)data + offset, 0))); |
316 | } else { /* FIELD_IS_NUMERIC */ | 322 | } else { /* FIELD_IS_NUMERIC */ |
317 | val = read_size(data + field->offset, field->size); | 323 | val = read_size(pevent, data + field->offset, |
324 | field->size); | ||
318 | if (field->flags & FIELD_IS_SIGNED) { | 325 | if (field->flags & FIELD_IS_SIGNED) { |
319 | XPUSHs(sv_2mortal(newSViv(val))); | 326 | XPUSHs(sv_2mortal(newSViv(val))); |
320 | } else { | 327 | } else { |
@@ -368,14 +375,15 @@ static void perl_process_event_generic(union perf_event *pevent __unused, | |||
368 | LEAVE; | 375 | LEAVE; |
369 | } | 376 | } |
370 | 377 | ||
371 | static void perl_process_event(union perf_event *pevent, | 378 | static void perl_process_event(union perf_event *event, |
379 | struct pevent *pevent, | ||
372 | struct perf_sample *sample, | 380 | struct perf_sample *sample, |
373 | struct perf_evsel *evsel, | 381 | struct perf_evsel *evsel, |
374 | struct machine *machine, | 382 | struct machine *machine, |
375 | struct thread *thread) | 383 | struct thread *thread) |
376 | { | 384 | { |
377 | perl_process_tracepoint(pevent, sample, evsel, machine, thread); | 385 | perl_process_tracepoint(event, pevent, sample, evsel, machine, thread); |
378 | perl_process_event_generic(pevent, sample, evsel, machine, thread); | 386 | perl_process_event_generic(event, sample, evsel, machine, thread); |
379 | } | 387 | } |
380 | 388 | ||
381 | static void run_start_sub(void) | 389 | static void run_start_sub(void) |
@@ -448,7 +456,7 @@ static int perl_stop_script(void) | |||
448 | return 0; | 456 | return 0; |
449 | } | 457 | } |
450 | 458 | ||
451 | static int perl_generate_script(const char *outfile) | 459 | static int perl_generate_script(struct pevent *pevent, const char *outfile) |
452 | { | 460 | { |
453 | struct event_format *event = NULL; | 461 | struct event_format *event = NULL; |
454 | struct format_field *f; | 462 | struct format_field *f; |
@@ -495,7 +503,7 @@ static int perl_generate_script(const char *outfile) | |||
495 | fprintf(ofp, "sub trace_begin\n{\n\t# optional\n}\n\n"); | 503 | fprintf(ofp, "sub trace_begin\n{\n\t# optional\n}\n\n"); |
496 | fprintf(ofp, "sub trace_end\n{\n\t# optional\n}\n\n"); | 504 | fprintf(ofp, "sub trace_end\n{\n\t# optional\n}\n\n"); |
497 | 505 | ||
498 | while ((event = trace_find_next_event(event))) { | 506 | while ((event = trace_find_next_event(pevent, event))) { |
499 | fprintf(ofp, "sub %s::%s\n{\n", event->system, event->name); | 507 | fprintf(ofp, "sub %s::%s\n{\n", event->system, event->name); |
500 | fprintf(ofp, "\tmy ("); | 508 | fprintf(ofp, "\tmy ("); |
501 | 509 | ||
diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c index acb9795286c4..ce4d1b0c3862 100644 --- a/tools/perf/util/scripting-engines/trace-event-python.c +++ b/tools/perf/util/scripting-engines/trace-event-python.c | |||
@@ -166,6 +166,10 @@ static void define_event_symbols(struct event_format *event, | |||
166 | define_values(PRINT_SYMBOL, args->symbol.symbols, ev_name, | 166 | define_values(PRINT_SYMBOL, args->symbol.symbols, ev_name, |
167 | cur_field_name); | 167 | cur_field_name); |
168 | break; | 168 | break; |
169 | case PRINT_HEX: | ||
170 | define_event_symbols(event, ev_name, args->hex.field); | ||
171 | define_event_symbols(event, ev_name, args->hex.size); | ||
172 | break; | ||
169 | case PRINT_STRING: | 173 | case PRINT_STRING: |
170 | break; | 174 | break; |
171 | case PRINT_TYPE: | 175 | case PRINT_TYPE: |
@@ -190,7 +194,8 @@ static void define_event_symbols(struct event_format *event, | |||
190 | define_event_symbols(event, ev_name, args->next); | 194 | define_event_symbols(event, ev_name, args->next); |
191 | } | 195 | } |
192 | 196 | ||
193 | static inline struct event_format *find_cache_event(int type) | 197 | static inline |
198 | struct event_format *find_cache_event(struct pevent *pevent, int type) | ||
194 | { | 199 | { |
195 | static char ev_name[256]; | 200 | static char ev_name[256]; |
196 | struct event_format *event; | 201 | struct event_format *event; |
@@ -198,7 +203,7 @@ static inline struct event_format *find_cache_event(int type) | |||
198 | if (events[type]) | 203 | if (events[type]) |
199 | return events[type]; | 204 | return events[type]; |
200 | 205 | ||
201 | events[type] = event = trace_find_event(type); | 206 | events[type] = event = pevent_find_event(pevent, type); |
202 | if (!event) | 207 | if (!event) |
203 | return NULL; | 208 | return NULL; |
204 | 209 | ||
@@ -209,7 +214,8 @@ static inline struct event_format *find_cache_event(int type) | |||
209 | return event; | 214 | return event; |
210 | } | 215 | } |
211 | 216 | ||
212 | static void python_process_event(union perf_event *pevent __unused, | 217 | static void python_process_event(union perf_event *perf_event __unused, |
218 | struct pevent *pevent, | ||
213 | struct perf_sample *sample, | 219 | struct perf_sample *sample, |
214 | struct perf_evsel *evsel __unused, | 220 | struct perf_evsel *evsel __unused, |
215 | struct machine *machine __unused, | 221 | struct machine *machine __unused, |
@@ -233,13 +239,13 @@ static void python_process_event(union perf_event *pevent __unused, | |||
233 | if (!t) | 239 | if (!t) |
234 | Py_FatalError("couldn't create Python tuple"); | 240 | Py_FatalError("couldn't create Python tuple"); |
235 | 241 | ||
236 | type = trace_parse_common_type(data); | 242 | type = trace_parse_common_type(pevent, data); |
237 | 243 | ||
238 | event = find_cache_event(type); | 244 | event = find_cache_event(pevent, type); |
239 | if (!event) | 245 | if (!event) |
240 | die("ug! no event found for type %d", type); | 246 | die("ug! no event found for type %d", type); |
241 | 247 | ||
242 | pid = trace_parse_common_pid(data); | 248 | pid = trace_parse_common_pid(pevent, data); |
243 | 249 | ||
244 | sprintf(handler_name, "%s__%s", event->system, event->name); | 250 | sprintf(handler_name, "%s__%s", event->system, event->name); |
245 | 251 | ||
@@ -284,7 +290,8 @@ static void python_process_event(union perf_event *pevent __unused, | |||
284 | offset = field->offset; | 290 | offset = field->offset; |
285 | obj = PyString_FromString((char *)data + offset); | 291 | obj = PyString_FromString((char *)data + offset); |
286 | } else { /* FIELD_IS_NUMERIC */ | 292 | } else { /* FIELD_IS_NUMERIC */ |
287 | val = read_size(data + field->offset, field->size); | 293 | val = read_size(pevent, data + field->offset, |
294 | field->size); | ||
288 | if (field->flags & FIELD_IS_SIGNED) { | 295 | if (field->flags & FIELD_IS_SIGNED) { |
289 | if ((long long)val >= LONG_MIN && | 296 | if ((long long)val >= LONG_MIN && |
290 | (long long)val <= LONG_MAX) | 297 | (long long)val <= LONG_MAX) |
@@ -438,7 +445,7 @@ out: | |||
438 | return err; | 445 | return err; |
439 | } | 446 | } |
440 | 447 | ||
441 | static int python_generate_script(const char *outfile) | 448 | static int python_generate_script(struct pevent *pevent, const char *outfile) |
442 | { | 449 | { |
443 | struct event_format *event = NULL; | 450 | struct event_format *event = NULL; |
444 | struct format_field *f; | 451 | struct format_field *f; |
@@ -487,7 +494,7 @@ static int python_generate_script(const char *outfile) | |||
487 | fprintf(ofp, "def trace_end():\n"); | 494 | fprintf(ofp, "def trace_end():\n"); |
488 | fprintf(ofp, "\tprint \"in trace_end\"\n\n"); | 495 | fprintf(ofp, "\tprint \"in trace_end\"\n\n"); |
489 | 496 | ||
490 | while ((event = trace_find_next_event(event))) { | 497 | while ((event = trace_find_next_event(pevent, event))) { |
491 | fprintf(ofp, "def %s__%s(", event->system, event->name); | 498 | fprintf(ofp, "def %s__%s(", event->system, event->name); |
492 | fprintf(ofp, "event_name, "); | 499 | fprintf(ofp, "event_name, "); |
493 | fprintf(ofp, "context, "); | 500 | fprintf(ofp, "context, "); |
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 2600916efa83..8e4f0755d2aa 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c | |||
@@ -14,6 +14,7 @@ | |||
14 | #include "sort.h" | 14 | #include "sort.h" |
15 | #include "util.h" | 15 | #include "util.h" |
16 | #include "cpumap.h" | 16 | #include "cpumap.h" |
17 | #include "event-parse.h" | ||
17 | 18 | ||
18 | static int perf_session__open(struct perf_session *self, bool force) | 19 | static int perf_session__open(struct perf_session *self, bool force) |
19 | { | 20 | { |
@@ -86,6 +87,7 @@ void perf_session__update_sample_type(struct perf_session *self) | |||
86 | self->sample_id_all = perf_evlist__sample_id_all(self->evlist); | 87 | self->sample_id_all = perf_evlist__sample_id_all(self->evlist); |
87 | self->id_hdr_size = perf_evlist__id_hdr_size(self->evlist); | 88 | self->id_hdr_size = perf_evlist__id_hdr_size(self->evlist); |
88 | self->host_machine.id_hdr_size = self->id_hdr_size; | 89 | self->host_machine.id_hdr_size = self->id_hdr_size; |
90 | machines__set_id_hdr_size(&self->machines, self->id_hdr_size); | ||
89 | } | 91 | } |
90 | 92 | ||
91 | int perf_session__create_kernel_maps(struct perf_session *self) | 93 | int perf_session__create_kernel_maps(struct perf_session *self) |
@@ -289,7 +291,6 @@ struct branch_info *machine__resolve_bstack(struct machine *self, | |||
289 | } | 291 | } |
290 | 292 | ||
291 | int machine__resolve_callchain(struct machine *self, | 293 | int machine__resolve_callchain(struct machine *self, |
292 | struct perf_evsel *evsel __used, | ||
293 | struct thread *thread, | 294 | struct thread *thread, |
294 | struct ip_callchain *chain, | 295 | struct ip_callchain *chain, |
295 | struct symbol **parent) | 296 | struct symbol **parent) |
@@ -442,6 +443,16 @@ static void perf_tool__fill_defaults(struct perf_tool *tool) | |||
442 | tool->finished_round = process_finished_round_stub; | 443 | tool->finished_round = process_finished_round_stub; |
443 | } | 444 | } |
444 | } | 445 | } |
446 | |||
447 | void mem_bswap_32(void *src, int byte_size) | ||
448 | { | ||
449 | u32 *m = src; | ||
450 | while (byte_size > 0) { | ||
451 | *m = bswap_32(*m); | ||
452 | byte_size -= sizeof(u32); | ||
453 | ++m; | ||
454 | } | ||
455 | } | ||
445 | 456 | ||
446 | void mem_bswap_64(void *src, int byte_size) | 457 | void mem_bswap_64(void *src, int byte_size) |
447 | { | 458 | { |
@@ -908,7 +919,9 @@ static struct machine * | |||
908 | { | 919 | { |
909 | const u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK; | 920 | const u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK; |
910 | 921 | ||
911 | if (cpumode == PERF_RECORD_MISC_GUEST_KERNEL && perf_guest) { | 922 | if (perf_guest && |
923 | ((cpumode == PERF_RECORD_MISC_GUEST_KERNEL) || | ||
924 | (cpumode == PERF_RECORD_MISC_GUEST_USER))) { | ||
912 | u32 pid; | 925 | u32 pid; |
913 | 926 | ||
914 | if (event->header.type == PERF_RECORD_MMAP) | 927 | if (event->header.type == PERF_RECORD_MMAP) |
@@ -916,7 +929,7 @@ static struct machine * | |||
916 | else | 929 | else |
917 | pid = event->ip.pid; | 930 | pid = event->ip.pid; |
918 | 931 | ||
919 | return perf_session__find_machine(session, pid); | 932 | return perf_session__findnew_machine(session, pid); |
920 | } | 933 | } |
921 | 934 | ||
922 | return perf_session__find_host_machine(session); | 935 | return perf_session__find_host_machine(session); |
@@ -1439,7 +1452,7 @@ size_t perf_session__fprintf_nr_events(struct perf_session *session, FILE *fp) | |||
1439 | ret += hists__fprintf_nr_events(&session->hists, fp); | 1452 | ret += hists__fprintf_nr_events(&session->hists, fp); |
1440 | 1453 | ||
1441 | list_for_each_entry(pos, &session->evlist->entries, node) { | 1454 | list_for_each_entry(pos, &session->evlist->entries, node) { |
1442 | ret += fprintf(fp, "%s stats:\n", event_name(pos)); | 1455 | ret += fprintf(fp, "%s stats:\n", perf_evsel__name(pos)); |
1443 | ret += hists__fprintf_nr_events(&pos->hists, fp); | 1456 | ret += hists__fprintf_nr_events(&pos->hists, fp); |
1444 | } | 1457 | } |
1445 | 1458 | ||
@@ -1480,8 +1493,8 @@ struct perf_evsel *perf_session__find_first_evtype(struct perf_session *session, | |||
1480 | } | 1493 | } |
1481 | 1494 | ||
1482 | void perf_event__print_ip(union perf_event *event, struct perf_sample *sample, | 1495 | void perf_event__print_ip(union perf_event *event, struct perf_sample *sample, |
1483 | struct machine *machine, struct perf_evsel *evsel, | 1496 | struct machine *machine, int print_sym, |
1484 | int print_sym, int print_dso, int print_symoffset) | 1497 | int print_dso, int print_symoffset) |
1485 | { | 1498 | { |
1486 | struct addr_location al; | 1499 | struct addr_location al; |
1487 | struct callchain_cursor_node *node; | 1500 | struct callchain_cursor_node *node; |
@@ -1495,7 +1508,7 @@ void perf_event__print_ip(union perf_event *event, struct perf_sample *sample, | |||
1495 | 1508 | ||
1496 | if (symbol_conf.use_callchain && sample->callchain) { | 1509 | if (symbol_conf.use_callchain && sample->callchain) { |
1497 | 1510 | ||
1498 | if (machine__resolve_callchain(machine, evsel, al.thread, | 1511 | if (machine__resolve_callchain(machine, al.thread, |
1499 | sample->callchain, NULL) != 0) { | 1512 | sample->callchain, NULL) != 0) { |
1500 | if (verbose) | 1513 | if (verbose) |
1501 | error("Failed to resolve callchain. Skipping\n"); | 1514 | error("Failed to resolve callchain. Skipping\n"); |
@@ -1601,3 +1614,58 @@ void perf_session__fprintf_info(struct perf_session *session, FILE *fp, | |||
1601 | perf_header__fprintf_info(session, fp, full); | 1614 | perf_header__fprintf_info(session, fp, full); |
1602 | fprintf(fp, "# ========\n#\n"); | 1615 | fprintf(fp, "# ========\n#\n"); |
1603 | } | 1616 | } |
1617 | |||
1618 | |||
1619 | int __perf_session__set_tracepoints_handlers(struct perf_session *session, | ||
1620 | const struct perf_evsel_str_handler *assocs, | ||
1621 | size_t nr_assocs) | ||
1622 | { | ||
1623 | struct perf_evlist *evlist = session->evlist; | ||
1624 | struct event_format *format; | ||
1625 | struct perf_evsel *evsel; | ||
1626 | char *tracepoint, *name; | ||
1627 | size_t i; | ||
1628 | int err; | ||
1629 | |||
1630 | for (i = 0; i < nr_assocs; i++) { | ||
1631 | err = -ENOMEM; | ||
1632 | tracepoint = strdup(assocs[i].name); | ||
1633 | if (tracepoint == NULL) | ||
1634 | goto out; | ||
1635 | |||
1636 | err = -ENOENT; | ||
1637 | name = strchr(tracepoint, ':'); | ||
1638 | if (name == NULL) | ||
1639 | goto out_free; | ||
1640 | |||
1641 | *name++ = '\0'; | ||
1642 | format = pevent_find_event_by_name(session->pevent, | ||
1643 | tracepoint, name); | ||
1644 | if (format == NULL) { | ||
1645 | /* | ||
1646 | * Adding a handler for an event not in the session, | ||
1647 | * just ignore it. | ||
1648 | */ | ||
1649 | goto next; | ||
1650 | } | ||
1651 | |||
1652 | evsel = perf_evlist__find_tracepoint_by_id(evlist, format->id); | ||
1653 | if (evsel == NULL) | ||
1654 | goto next; | ||
1655 | |||
1656 | err = -EEXIST; | ||
1657 | if (evsel->handler.func != NULL) | ||
1658 | goto out_free; | ||
1659 | evsel->handler.func = assocs[i].handler; | ||
1660 | next: | ||
1661 | free(tracepoint); | ||
1662 | } | ||
1663 | |||
1664 | err = 0; | ||
1665 | out: | ||
1666 | return err; | ||
1667 | |||
1668 | out_free: | ||
1669 | free(tracepoint); | ||
1670 | goto out; | ||
1671 | } | ||
diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h index 7a5434c00565..7c435bde6eb0 100644 --- a/tools/perf/util/session.h +++ b/tools/perf/util/session.h | |||
@@ -33,6 +33,7 @@ struct perf_session { | |||
33 | struct machine host_machine; | 33 | struct machine host_machine; |
34 | struct rb_root machines; | 34 | struct rb_root machines; |
35 | struct perf_evlist *evlist; | 35 | struct perf_evlist *evlist; |
36 | struct pevent *pevent; | ||
36 | /* | 37 | /* |
37 | * FIXME: Need to split this up further, we need global | 38 | * FIXME: Need to split this up further, we need global |
38 | * stats + per event stats. 'perf diff' also needs | 39 | * stats + per event stats. 'perf diff' also needs |
@@ -80,6 +81,7 @@ struct branch_info *machine__resolve_bstack(struct machine *self, | |||
80 | bool perf_session__has_traces(struct perf_session *self, const char *msg); | 81 | bool perf_session__has_traces(struct perf_session *self, const char *msg); |
81 | 82 | ||
82 | void mem_bswap_64(void *src, int byte_size); | 83 | void mem_bswap_64(void *src, int byte_size); |
84 | void mem_bswap_32(void *src, int byte_size); | ||
83 | void perf_event__attr_swap(struct perf_event_attr *attr); | 85 | void perf_event__attr_swap(struct perf_event_attr *attr); |
84 | 86 | ||
85 | int perf_session__create_kernel_maps(struct perf_session *self); | 87 | int perf_session__create_kernel_maps(struct perf_session *self); |
@@ -150,11 +152,20 @@ struct perf_evsel *perf_session__find_first_evtype(struct perf_session *session, | |||
150 | unsigned int type); | 152 | unsigned int type); |
151 | 153 | ||
152 | void perf_event__print_ip(union perf_event *event, struct perf_sample *sample, | 154 | void perf_event__print_ip(union perf_event *event, struct perf_sample *sample, |
153 | struct machine *machine, struct perf_evsel *evsel, | 155 | struct machine *machine, int print_sym, |
154 | int print_sym, int print_dso, int print_symoffset); | 156 | int print_dso, int print_symoffset); |
155 | 157 | ||
156 | int perf_session__cpu_bitmap(struct perf_session *session, | 158 | int perf_session__cpu_bitmap(struct perf_session *session, |
157 | const char *cpu_list, unsigned long *cpu_bitmap); | 159 | const char *cpu_list, unsigned long *cpu_bitmap); |
158 | 160 | ||
159 | void perf_session__fprintf_info(struct perf_session *s, FILE *fp, bool full); | 161 | void perf_session__fprintf_info(struct perf_session *s, FILE *fp, bool full); |
162 | |||
163 | struct perf_evsel_str_handler; | ||
164 | |||
165 | int __perf_session__set_tracepoints_handlers(struct perf_session *session, | ||
166 | const struct perf_evsel_str_handler *assocs, | ||
167 | size_t nr_assocs); | ||
168 | |||
169 | #define perf_session__set_tracepoints_handlers(session, array) \ | ||
170 | __perf_session__set_tracepoints_handlers(session, array, ARRAY_SIZE(array)) | ||
160 | #endif /* __PERF_SESSION_H */ | 171 | #endif /* __PERF_SESSION_H */ |
diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c index a27237430c5f..0f5a0a496bc4 100644 --- a/tools/perf/util/sort.c +++ b/tools/perf/util/sort.c | |||
@@ -241,6 +241,54 @@ struct sort_entry sort_sym = { | |||
241 | .se_width_idx = HISTC_SYMBOL, | 241 | .se_width_idx = HISTC_SYMBOL, |
242 | }; | 242 | }; |
243 | 243 | ||
244 | /* --sort srcline */ | ||
245 | |||
246 | static int64_t | ||
247 | sort__srcline_cmp(struct hist_entry *left, struct hist_entry *right) | ||
248 | { | ||
249 | return (int64_t)(right->ip - left->ip); | ||
250 | } | ||
251 | |||
252 | static int hist_entry__srcline_snprintf(struct hist_entry *self, char *bf, | ||
253 | size_t size, unsigned int width __used) | ||
254 | { | ||
255 | FILE *fp; | ||
256 | char cmd[PATH_MAX + 2], *path = self->srcline, *nl; | ||
257 | size_t line_len; | ||
258 | |||
259 | if (path != NULL) | ||
260 | goto out_path; | ||
261 | |||
262 | snprintf(cmd, sizeof(cmd), "addr2line -e %s %016" PRIx64, | ||
263 | self->ms.map->dso->long_name, self->ip); | ||
264 | fp = popen(cmd, "r"); | ||
265 | if (!fp) | ||
266 | goto out_ip; | ||
267 | |||
268 | if (getline(&path, &line_len, fp) < 0 || !line_len) | ||
269 | goto out_ip; | ||
270 | fclose(fp); | ||
271 | self->srcline = strdup(path); | ||
272 | if (self->srcline == NULL) | ||
273 | goto out_ip; | ||
274 | |||
275 | nl = strchr(self->srcline, '\n'); | ||
276 | if (nl != NULL) | ||
277 | *nl = '\0'; | ||
278 | path = self->srcline; | ||
279 | out_path: | ||
280 | return repsep_snprintf(bf, size, "%s", path); | ||
281 | out_ip: | ||
282 | return repsep_snprintf(bf, size, "%-#*llx", BITS_PER_LONG / 4, self->ip); | ||
283 | } | ||
284 | |||
285 | struct sort_entry sort_srcline = { | ||
286 | .se_header = "Source:Line", | ||
287 | .se_cmp = sort__srcline_cmp, | ||
288 | .se_snprintf = hist_entry__srcline_snprintf, | ||
289 | .se_width_idx = HISTC_SRCLINE, | ||
290 | }; | ||
291 | |||
244 | /* --sort parent */ | 292 | /* --sort parent */ |
245 | 293 | ||
246 | static int64_t | 294 | static int64_t |
@@ -439,6 +487,7 @@ static struct sort_dimension sort_dimensions[] = { | |||
439 | DIM(SORT_PARENT, "parent", sort_parent), | 487 | DIM(SORT_PARENT, "parent", sort_parent), |
440 | DIM(SORT_CPU, "cpu", sort_cpu), | 488 | DIM(SORT_CPU, "cpu", sort_cpu), |
441 | DIM(SORT_MISPREDICT, "mispredict", sort_mispredict), | 489 | DIM(SORT_MISPREDICT, "mispredict", sort_mispredict), |
490 | DIM(SORT_SRCLINE, "srcline", sort_srcline), | ||
442 | }; | 491 | }; |
443 | 492 | ||
444 | int sort_dimension__add(const char *tok) | 493 | int sort_dimension__add(const char *tok) |
diff --git a/tools/perf/util/sort.h b/tools/perf/util/sort.h index 472aa5a63a58..e724b26acd51 100644 --- a/tools/perf/util/sort.h +++ b/tools/perf/util/sort.h | |||
@@ -71,6 +71,7 @@ struct hist_entry { | |||
71 | char level; | 71 | char level; |
72 | bool used; | 72 | bool used; |
73 | u8 filtered; | 73 | u8 filtered; |
74 | char *srcline; | ||
74 | struct symbol *parent; | 75 | struct symbol *parent; |
75 | union { | 76 | union { |
76 | unsigned long position; | 77 | unsigned long position; |
@@ -93,6 +94,7 @@ enum sort_type { | |||
93 | SORT_SYM_FROM, | 94 | SORT_SYM_FROM, |
94 | SORT_SYM_TO, | 95 | SORT_SYM_TO, |
95 | SORT_MISPREDICT, | 96 | SORT_MISPREDICT, |
97 | SORT_SRCLINE, | ||
96 | }; | 98 | }; |
97 | 99 | ||
98 | /* | 100 | /* |
diff --git a/tools/perf/util/string.c b/tools/perf/util/string.c index d5836382ff2c..199bc4d8905d 100644 --- a/tools/perf/util/string.c +++ b/tools/perf/util/string.c | |||
@@ -313,3 +313,25 @@ int strtailcmp(const char *s1, const char *s2) | |||
313 | return 0; | 313 | return 0; |
314 | } | 314 | } |
315 | 315 | ||
316 | /** | ||
317 | * rtrim - Removes trailing whitespace from @s. | ||
318 | * @s: The string to be stripped. | ||
319 | * | ||
320 | * Note that the first trailing whitespace is replaced with a %NUL-terminator | ||
321 | * in the given string @s. Returns @s. | ||
322 | */ | ||
323 | char *rtrim(char *s) | ||
324 | { | ||
325 | size_t size = strlen(s); | ||
326 | char *end; | ||
327 | |||
328 | if (!size) | ||
329 | return s; | ||
330 | |||
331 | end = s + size - 1; | ||
332 | while (end >= s && isspace(*end)) | ||
333 | end--; | ||
334 | *(end + 1) = '\0'; | ||
335 | |||
336 | return s; | ||
337 | } | ||
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c index 3e2e5ea0f03f..fdad4eeeb429 100644 --- a/tools/perf/util/symbol.c +++ b/tools/perf/util/symbol.c | |||
@@ -29,6 +29,7 @@ | |||
29 | #define NT_GNU_BUILD_ID 3 | 29 | #define NT_GNU_BUILD_ID 3 |
30 | #endif | 30 | #endif |
31 | 31 | ||
32 | static void dso_cache__free(struct rb_root *root); | ||
32 | static bool dso__build_id_equal(const struct dso *dso, u8 *build_id); | 33 | static bool dso__build_id_equal(const struct dso *dso, u8 *build_id); |
33 | static int elf_read_build_id(Elf *elf, void *bf, size_t size); | 34 | static int elf_read_build_id(Elf *elf, void *bf, size_t size); |
34 | static void dsos__add(struct list_head *head, struct dso *dso); | 35 | static void dsos__add(struct list_head *head, struct dso *dso); |
@@ -48,6 +49,31 @@ struct symbol_conf symbol_conf = { | |||
48 | .symfs = "", | 49 | .symfs = "", |
49 | }; | 50 | }; |
50 | 51 | ||
52 | static enum dso_binary_type binary_type_symtab[] = { | ||
53 | DSO_BINARY_TYPE__KALLSYMS, | ||
54 | DSO_BINARY_TYPE__GUEST_KALLSYMS, | ||
55 | DSO_BINARY_TYPE__JAVA_JIT, | ||
56 | DSO_BINARY_TYPE__DEBUGLINK, | ||
57 | DSO_BINARY_TYPE__BUILD_ID_CACHE, | ||
58 | DSO_BINARY_TYPE__FEDORA_DEBUGINFO, | ||
59 | DSO_BINARY_TYPE__UBUNTU_DEBUGINFO, | ||
60 | DSO_BINARY_TYPE__BUILDID_DEBUGINFO, | ||
61 | DSO_BINARY_TYPE__SYSTEM_PATH_DSO, | ||
62 | DSO_BINARY_TYPE__GUEST_KMODULE, | ||
63 | DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE, | ||
64 | DSO_BINARY_TYPE__NOT_FOUND, | ||
65 | }; | ||
66 | |||
67 | #define DSO_BINARY_TYPE__SYMTAB_CNT sizeof(binary_type_symtab) | ||
68 | |||
69 | static enum dso_binary_type binary_type_data[] = { | ||
70 | DSO_BINARY_TYPE__BUILD_ID_CACHE, | ||
71 | DSO_BINARY_TYPE__SYSTEM_PATH_DSO, | ||
72 | DSO_BINARY_TYPE__NOT_FOUND, | ||
73 | }; | ||
74 | |||
75 | #define DSO_BINARY_TYPE__DATA_CNT sizeof(binary_type_data) | ||
76 | |||
51 | int dso__name_len(const struct dso *dso) | 77 | int dso__name_len(const struct dso *dso) |
52 | { | 78 | { |
53 | if (!dso) | 79 | if (!dso) |
@@ -318,7 +344,9 @@ struct dso *dso__new(const char *name) | |||
318 | dso__set_short_name(dso, dso->name); | 344 | dso__set_short_name(dso, dso->name); |
319 | for (i = 0; i < MAP__NR_TYPES; ++i) | 345 | for (i = 0; i < MAP__NR_TYPES; ++i) |
320 | dso->symbols[i] = dso->symbol_names[i] = RB_ROOT; | 346 | dso->symbols[i] = dso->symbol_names[i] = RB_ROOT; |
321 | dso->symtab_type = SYMTAB__NOT_FOUND; | 347 | dso->cache = RB_ROOT; |
348 | dso->symtab_type = DSO_BINARY_TYPE__NOT_FOUND; | ||
349 | dso->data_type = DSO_BINARY_TYPE__NOT_FOUND; | ||
322 | dso->loaded = 0; | 350 | dso->loaded = 0; |
323 | dso->sorted_by_name = 0; | 351 | dso->sorted_by_name = 0; |
324 | dso->has_build_id = 0; | 352 | dso->has_build_id = 0; |
@@ -352,6 +380,7 @@ void dso__delete(struct dso *dso) | |||
352 | free((char *)dso->short_name); | 380 | free((char *)dso->short_name); |
353 | if (dso->lname_alloc) | 381 | if (dso->lname_alloc) |
354 | free(dso->long_name); | 382 | free(dso->long_name); |
383 | dso_cache__free(&dso->cache); | ||
355 | free(dso); | 384 | free(dso); |
356 | } | 385 | } |
357 | 386 | ||
@@ -806,9 +835,9 @@ int dso__load_kallsyms(struct dso *dso, const char *filename, | |||
806 | symbols__fixup_end(&dso->symbols[map->type]); | 835 | symbols__fixup_end(&dso->symbols[map->type]); |
807 | 836 | ||
808 | if (dso->kernel == DSO_TYPE_GUEST_KERNEL) | 837 | if (dso->kernel == DSO_TYPE_GUEST_KERNEL) |
809 | dso->symtab_type = SYMTAB__GUEST_KALLSYMS; | 838 | dso->symtab_type = DSO_BINARY_TYPE__GUEST_KALLSYMS; |
810 | else | 839 | else |
811 | dso->symtab_type = SYMTAB__KALLSYMS; | 840 | dso->symtab_type = DSO_BINARY_TYPE__KALLSYMS; |
812 | 841 | ||
813 | return dso__split_kallsyms(dso, map, filter); | 842 | return dso__split_kallsyms(dso, map, filter); |
814 | } | 843 | } |
@@ -1478,14 +1507,31 @@ static int elf_read_build_id(Elf *elf, void *bf, size_t size) | |||
1478 | goto out; | 1507 | goto out; |
1479 | } | 1508 | } |
1480 | 1509 | ||
1481 | sec = elf_section_by_name(elf, &ehdr, &shdr, | 1510 | /* |
1482 | ".note.gnu.build-id", NULL); | 1511 | * Check following sections for notes: |
1483 | if (sec == NULL) { | 1512 | * '.note.gnu.build-id' |
1513 | * '.notes' | ||
1514 | * '.note' (VDSO specific) | ||
1515 | */ | ||
1516 | do { | ||
1517 | sec = elf_section_by_name(elf, &ehdr, &shdr, | ||
1518 | ".note.gnu.build-id", NULL); | ||
1519 | if (sec) | ||
1520 | break; | ||
1521 | |||
1484 | sec = elf_section_by_name(elf, &ehdr, &shdr, | 1522 | sec = elf_section_by_name(elf, &ehdr, &shdr, |
1485 | ".notes", NULL); | 1523 | ".notes", NULL); |
1486 | if (sec == NULL) | 1524 | if (sec) |
1487 | goto out; | 1525 | break; |
1488 | } | 1526 | |
1527 | sec = elf_section_by_name(elf, &ehdr, &shdr, | ||
1528 | ".note", NULL); | ||
1529 | if (sec) | ||
1530 | break; | ||
1531 | |||
1532 | return err; | ||
1533 | |||
1534 | } while (0); | ||
1489 | 1535 | ||
1490 | data = elf_getdata(sec, NULL); | 1536 | data = elf_getdata(sec, NULL); |
1491 | if (data == NULL) | 1537 | if (data == NULL) |
@@ -1590,34 +1636,163 @@ out: | |||
1590 | return err; | 1636 | return err; |
1591 | } | 1637 | } |
1592 | 1638 | ||
1639 | static int filename__read_debuglink(const char *filename, | ||
1640 | char *debuglink, size_t size) | ||
1641 | { | ||
1642 | int fd, err = -1; | ||
1643 | Elf *elf; | ||
1644 | GElf_Ehdr ehdr; | ||
1645 | GElf_Shdr shdr; | ||
1646 | Elf_Data *data; | ||
1647 | Elf_Scn *sec; | ||
1648 | Elf_Kind ek; | ||
1649 | |||
1650 | fd = open(filename, O_RDONLY); | ||
1651 | if (fd < 0) | ||
1652 | goto out; | ||
1653 | |||
1654 | elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL); | ||
1655 | if (elf == NULL) { | ||
1656 | pr_debug2("%s: cannot read %s ELF file.\n", __func__, filename); | ||
1657 | goto out_close; | ||
1658 | } | ||
1659 | |||
1660 | ek = elf_kind(elf); | ||
1661 | if (ek != ELF_K_ELF) | ||
1662 | goto out_close; | ||
1663 | |||
1664 | if (gelf_getehdr(elf, &ehdr) == NULL) { | ||
1665 | pr_err("%s: cannot get elf header.\n", __func__); | ||
1666 | goto out_close; | ||
1667 | } | ||
1668 | |||
1669 | sec = elf_section_by_name(elf, &ehdr, &shdr, | ||
1670 | ".gnu_debuglink", NULL); | ||
1671 | if (sec == NULL) | ||
1672 | goto out_close; | ||
1673 | |||
1674 | data = elf_getdata(sec, NULL); | ||
1675 | if (data == NULL) | ||
1676 | goto out_close; | ||
1677 | |||
1678 | /* the start of this section is a zero-terminated string */ | ||
1679 | strncpy(debuglink, data->d_buf, size); | ||
1680 | |||
1681 | elf_end(elf); | ||
1682 | |||
1683 | out_close: | ||
1684 | close(fd); | ||
1685 | out: | ||
1686 | return err; | ||
1687 | } | ||
1688 | |||
1593 | char dso__symtab_origin(const struct dso *dso) | 1689 | char dso__symtab_origin(const struct dso *dso) |
1594 | { | 1690 | { |
1595 | static const char origin[] = { | 1691 | static const char origin[] = { |
1596 | [SYMTAB__KALLSYMS] = 'k', | 1692 | [DSO_BINARY_TYPE__KALLSYMS] = 'k', |
1597 | [SYMTAB__JAVA_JIT] = 'j', | 1693 | [DSO_BINARY_TYPE__JAVA_JIT] = 'j', |
1598 | [SYMTAB__BUILD_ID_CACHE] = 'B', | 1694 | [DSO_BINARY_TYPE__DEBUGLINK] = 'l', |
1599 | [SYMTAB__FEDORA_DEBUGINFO] = 'f', | 1695 | [DSO_BINARY_TYPE__BUILD_ID_CACHE] = 'B', |
1600 | [SYMTAB__UBUNTU_DEBUGINFO] = 'u', | 1696 | [DSO_BINARY_TYPE__FEDORA_DEBUGINFO] = 'f', |
1601 | [SYMTAB__BUILDID_DEBUGINFO] = 'b', | 1697 | [DSO_BINARY_TYPE__UBUNTU_DEBUGINFO] = 'u', |
1602 | [SYMTAB__SYSTEM_PATH_DSO] = 'd', | 1698 | [DSO_BINARY_TYPE__BUILDID_DEBUGINFO] = 'b', |
1603 | [SYMTAB__SYSTEM_PATH_KMODULE] = 'K', | 1699 | [DSO_BINARY_TYPE__SYSTEM_PATH_DSO] = 'd', |
1604 | [SYMTAB__GUEST_KALLSYMS] = 'g', | 1700 | [DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE] = 'K', |
1605 | [SYMTAB__GUEST_KMODULE] = 'G', | 1701 | [DSO_BINARY_TYPE__GUEST_KALLSYMS] = 'g', |
1702 | [DSO_BINARY_TYPE__GUEST_KMODULE] = 'G', | ||
1606 | }; | 1703 | }; |
1607 | 1704 | ||
1608 | if (dso == NULL || dso->symtab_type == SYMTAB__NOT_FOUND) | 1705 | if (dso == NULL || dso->symtab_type == DSO_BINARY_TYPE__NOT_FOUND) |
1609 | return '!'; | 1706 | return '!'; |
1610 | return origin[dso->symtab_type]; | 1707 | return origin[dso->symtab_type]; |
1611 | } | 1708 | } |
1612 | 1709 | ||
1710 | int dso__binary_type_file(struct dso *dso, enum dso_binary_type type, | ||
1711 | char *root_dir, char *file, size_t size) | ||
1712 | { | ||
1713 | char build_id_hex[BUILD_ID_SIZE * 2 + 1]; | ||
1714 | int ret = 0; | ||
1715 | |||
1716 | switch (type) { | ||
1717 | case DSO_BINARY_TYPE__DEBUGLINK: { | ||
1718 | char *debuglink; | ||
1719 | |||
1720 | strncpy(file, dso->long_name, size); | ||
1721 | debuglink = file + dso->long_name_len; | ||
1722 | while (debuglink != file && *debuglink != '/') | ||
1723 | debuglink--; | ||
1724 | if (*debuglink == '/') | ||
1725 | debuglink++; | ||
1726 | filename__read_debuglink(dso->long_name, debuglink, | ||
1727 | size - (debuglink - file)); | ||
1728 | } | ||
1729 | break; | ||
1730 | case DSO_BINARY_TYPE__BUILD_ID_CACHE: | ||
1731 | /* skip the locally configured cache if a symfs is given */ | ||
1732 | if (symbol_conf.symfs[0] || | ||
1733 | (dso__build_id_filename(dso, file, size) == NULL)) | ||
1734 | ret = -1; | ||
1735 | break; | ||
1736 | |||
1737 | case DSO_BINARY_TYPE__FEDORA_DEBUGINFO: | ||
1738 | snprintf(file, size, "%s/usr/lib/debug%s.debug", | ||
1739 | symbol_conf.symfs, dso->long_name); | ||
1740 | break; | ||
1741 | |||
1742 | case DSO_BINARY_TYPE__UBUNTU_DEBUGINFO: | ||
1743 | snprintf(file, size, "%s/usr/lib/debug%s", | ||
1744 | symbol_conf.symfs, dso->long_name); | ||
1745 | break; | ||
1746 | |||
1747 | case DSO_BINARY_TYPE__BUILDID_DEBUGINFO: | ||
1748 | if (!dso->has_build_id) { | ||
1749 | ret = -1; | ||
1750 | break; | ||
1751 | } | ||
1752 | |||
1753 | build_id__sprintf(dso->build_id, | ||
1754 | sizeof(dso->build_id), | ||
1755 | build_id_hex); | ||
1756 | snprintf(file, size, | ||
1757 | "%s/usr/lib/debug/.build-id/%.2s/%s.debug", | ||
1758 | symbol_conf.symfs, build_id_hex, build_id_hex + 2); | ||
1759 | break; | ||
1760 | |||
1761 | case DSO_BINARY_TYPE__SYSTEM_PATH_DSO: | ||
1762 | snprintf(file, size, "%s%s", | ||
1763 | symbol_conf.symfs, dso->long_name); | ||
1764 | break; | ||
1765 | |||
1766 | case DSO_BINARY_TYPE__GUEST_KMODULE: | ||
1767 | snprintf(file, size, "%s%s%s", symbol_conf.symfs, | ||
1768 | root_dir, dso->long_name); | ||
1769 | break; | ||
1770 | |||
1771 | case DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE: | ||
1772 | snprintf(file, size, "%s%s", symbol_conf.symfs, | ||
1773 | dso->long_name); | ||
1774 | break; | ||
1775 | |||
1776 | default: | ||
1777 | case DSO_BINARY_TYPE__KALLSYMS: | ||
1778 | case DSO_BINARY_TYPE__GUEST_KALLSYMS: | ||
1779 | case DSO_BINARY_TYPE__JAVA_JIT: | ||
1780 | case DSO_BINARY_TYPE__NOT_FOUND: | ||
1781 | ret = -1; | ||
1782 | break; | ||
1783 | } | ||
1784 | |||
1785 | return ret; | ||
1786 | } | ||
1787 | |||
1613 | int dso__load(struct dso *dso, struct map *map, symbol_filter_t filter) | 1788 | int dso__load(struct dso *dso, struct map *map, symbol_filter_t filter) |
1614 | { | 1789 | { |
1615 | int size = PATH_MAX; | ||
1616 | char *name; | 1790 | char *name; |
1617 | int ret = -1; | 1791 | int ret = -1; |
1618 | int fd; | 1792 | int fd; |
1793 | u_int i; | ||
1619 | struct machine *machine; | 1794 | struct machine *machine; |
1620 | const char *root_dir; | 1795 | char *root_dir = (char *) ""; |
1621 | int want_symtab; | 1796 | int want_symtab; |
1622 | 1797 | ||
1623 | dso__set_loaded(dso, map->type); | 1798 | dso__set_loaded(dso, map->type); |
@@ -1632,7 +1807,7 @@ int dso__load(struct dso *dso, struct map *map, symbol_filter_t filter) | |||
1632 | else | 1807 | else |
1633 | machine = NULL; | 1808 | machine = NULL; |
1634 | 1809 | ||
1635 | name = malloc(size); | 1810 | name = malloc(PATH_MAX); |
1636 | if (!name) | 1811 | if (!name) |
1637 | return -1; | 1812 | return -1; |
1638 | 1813 | ||
@@ -1651,69 +1826,27 @@ int dso__load(struct dso *dso, struct map *map, symbol_filter_t filter) | |||
1651 | } | 1826 | } |
1652 | 1827 | ||
1653 | ret = dso__load_perf_map(dso, map, filter); | 1828 | ret = dso__load_perf_map(dso, map, filter); |
1654 | dso->symtab_type = ret > 0 ? SYMTAB__JAVA_JIT : | 1829 | dso->symtab_type = ret > 0 ? DSO_BINARY_TYPE__JAVA_JIT : |
1655 | SYMTAB__NOT_FOUND; | 1830 | DSO_BINARY_TYPE__NOT_FOUND; |
1656 | return ret; | 1831 | return ret; |
1657 | } | 1832 | } |
1658 | 1833 | ||
1834 | if (machine) | ||
1835 | root_dir = machine->root_dir; | ||
1836 | |||
1659 | /* Iterate over candidate debug images. | 1837 | /* Iterate over candidate debug images. |
1660 | * On the first pass, only load images if they have a full symtab. | 1838 | * On the first pass, only load images if they have a full symtab. |
1661 | * Failing that, do a second pass where we accept .dynsym also | 1839 | * Failing that, do a second pass where we accept .dynsym also |
1662 | */ | 1840 | */ |
1663 | want_symtab = 1; | 1841 | want_symtab = 1; |
1664 | restart: | 1842 | restart: |
1665 | for (dso->symtab_type = SYMTAB__BUILD_ID_CACHE; | 1843 | for (i = 0; i < DSO_BINARY_TYPE__SYMTAB_CNT; i++) { |
1666 | dso->symtab_type != SYMTAB__NOT_FOUND; | ||
1667 | dso->symtab_type++) { | ||
1668 | switch (dso->symtab_type) { | ||
1669 | case SYMTAB__BUILD_ID_CACHE: | ||
1670 | /* skip the locally configured cache if a symfs is given */ | ||
1671 | if (symbol_conf.symfs[0] || | ||
1672 | (dso__build_id_filename(dso, name, size) == NULL)) { | ||
1673 | continue; | ||
1674 | } | ||
1675 | break; | ||
1676 | case SYMTAB__FEDORA_DEBUGINFO: | ||
1677 | snprintf(name, size, "%s/usr/lib/debug%s.debug", | ||
1678 | symbol_conf.symfs, dso->long_name); | ||
1679 | break; | ||
1680 | case SYMTAB__UBUNTU_DEBUGINFO: | ||
1681 | snprintf(name, size, "%s/usr/lib/debug%s", | ||
1682 | symbol_conf.symfs, dso->long_name); | ||
1683 | break; | ||
1684 | case SYMTAB__BUILDID_DEBUGINFO: { | ||
1685 | char build_id_hex[BUILD_ID_SIZE * 2 + 1]; | ||
1686 | |||
1687 | if (!dso->has_build_id) | ||
1688 | continue; | ||
1689 | 1844 | ||
1690 | build_id__sprintf(dso->build_id, | 1845 | dso->symtab_type = binary_type_symtab[i]; |
1691 | sizeof(dso->build_id), | ||
1692 | build_id_hex); | ||
1693 | snprintf(name, size, | ||
1694 | "%s/usr/lib/debug/.build-id/%.2s/%s.debug", | ||
1695 | symbol_conf.symfs, build_id_hex, build_id_hex + 2); | ||
1696 | } | ||
1697 | break; | ||
1698 | case SYMTAB__SYSTEM_PATH_DSO: | ||
1699 | snprintf(name, size, "%s%s", | ||
1700 | symbol_conf.symfs, dso->long_name); | ||
1701 | break; | ||
1702 | case SYMTAB__GUEST_KMODULE: | ||
1703 | if (map->groups && machine) | ||
1704 | root_dir = machine->root_dir; | ||
1705 | else | ||
1706 | root_dir = ""; | ||
1707 | snprintf(name, size, "%s%s%s", symbol_conf.symfs, | ||
1708 | root_dir, dso->long_name); | ||
1709 | break; | ||
1710 | 1846 | ||
1711 | case SYMTAB__SYSTEM_PATH_KMODULE: | 1847 | if (dso__binary_type_file(dso, dso->symtab_type, |
1712 | snprintf(name, size, "%s%s", symbol_conf.symfs, | 1848 | root_dir, name, PATH_MAX)) |
1713 | dso->long_name); | 1849 | continue; |
1714 | break; | ||
1715 | default:; | ||
1716 | } | ||
1717 | 1850 | ||
1718 | /* Name is now the name of the next image to try */ | 1851 | /* Name is now the name of the next image to try */ |
1719 | fd = open(name, O_RDONLY); | 1852 | fd = open(name, O_RDONLY); |
@@ -1930,9 +2063,9 @@ struct map *machine__new_module(struct machine *machine, u64 start, | |||
1930 | return NULL; | 2063 | return NULL; |
1931 | 2064 | ||
1932 | if (machine__is_host(machine)) | 2065 | if (machine__is_host(machine)) |
1933 | dso->symtab_type = SYMTAB__SYSTEM_PATH_KMODULE; | 2066 | dso->symtab_type = DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE; |
1934 | else | 2067 | else |
1935 | dso->symtab_type = SYMTAB__GUEST_KMODULE; | 2068 | dso->symtab_type = DSO_BINARY_TYPE__GUEST_KMODULE; |
1936 | map_groups__insert(&machine->kmaps, map); | 2069 | map_groups__insert(&machine->kmaps, map); |
1937 | return map; | 2070 | return map; |
1938 | } | 2071 | } |
@@ -2484,8 +2617,15 @@ int machine__create_kernel_maps(struct machine *machine) | |||
2484 | __machine__create_kernel_maps(machine, kernel) < 0) | 2617 | __machine__create_kernel_maps(machine, kernel) < 0) |
2485 | return -1; | 2618 | return -1; |
2486 | 2619 | ||
2487 | if (symbol_conf.use_modules && machine__create_modules(machine) < 0) | 2620 | if (symbol_conf.use_modules && machine__create_modules(machine) < 0) { |
2488 | pr_debug("Problems creating module maps, continuing anyway...\n"); | 2621 | if (machine__is_host(machine)) |
2622 | pr_debug("Problems creating module maps, " | ||
2623 | "continuing anyway...\n"); | ||
2624 | else | ||
2625 | pr_debug("Problems creating module maps for guest %d, " | ||
2626 | "continuing anyway...\n", machine->pid); | ||
2627 | } | ||
2628 | |||
2489 | /* | 2629 | /* |
2490 | * Now that we have all the maps created, just set the ->end of them: | 2630 | * Now that we have all the maps created, just set the ->end of them: |
2491 | */ | 2631 | */ |
@@ -2825,3 +2965,218 @@ struct map *dso__new_map(const char *name) | |||
2825 | 2965 | ||
2826 | return map; | 2966 | return map; |
2827 | } | 2967 | } |
2968 | |||
2969 | static int open_dso(struct dso *dso, struct machine *machine) | ||
2970 | { | ||
2971 | char *root_dir = (char *) ""; | ||
2972 | char *name; | ||
2973 | int fd; | ||
2974 | |||
2975 | name = malloc(PATH_MAX); | ||
2976 | if (!name) | ||
2977 | return -ENOMEM; | ||
2978 | |||
2979 | if (machine) | ||
2980 | root_dir = machine->root_dir; | ||
2981 | |||
2982 | if (dso__binary_type_file(dso, dso->data_type, | ||
2983 | root_dir, name, PATH_MAX)) { | ||
2984 | free(name); | ||
2985 | return -EINVAL; | ||
2986 | } | ||
2987 | |||
2988 | fd = open(name, O_RDONLY); | ||
2989 | free(name); | ||
2990 | return fd; | ||
2991 | } | ||
2992 | |||
2993 | int dso__data_fd(struct dso *dso, struct machine *machine) | ||
2994 | { | ||
2995 | int i = 0; | ||
2996 | |||
2997 | if (dso->data_type != DSO_BINARY_TYPE__NOT_FOUND) | ||
2998 | return open_dso(dso, machine); | ||
2999 | |||
3000 | do { | ||
3001 | int fd; | ||
3002 | |||
3003 | dso->data_type = binary_type_data[i++]; | ||
3004 | |||
3005 | fd = open_dso(dso, machine); | ||
3006 | if (fd >= 0) | ||
3007 | return fd; | ||
3008 | |||
3009 | } while (dso->data_type != DSO_BINARY_TYPE__NOT_FOUND); | ||
3010 | |||
3011 | return -EINVAL; | ||
3012 | } | ||
3013 | |||
3014 | static void | ||
3015 | dso_cache__free(struct rb_root *root) | ||
3016 | { | ||
3017 | struct rb_node *next = rb_first(root); | ||
3018 | |||
3019 | while (next) { | ||
3020 | struct dso_cache *cache; | ||
3021 | |||
3022 | cache = rb_entry(next, struct dso_cache, rb_node); | ||
3023 | next = rb_next(&cache->rb_node); | ||
3024 | rb_erase(&cache->rb_node, root); | ||
3025 | free(cache); | ||
3026 | } | ||
3027 | } | ||
3028 | |||
3029 | static struct dso_cache* | ||
3030 | dso_cache__find(struct rb_root *root, u64 offset) | ||
3031 | { | ||
3032 | struct rb_node **p = &root->rb_node; | ||
3033 | struct rb_node *parent = NULL; | ||
3034 | struct dso_cache *cache; | ||
3035 | |||
3036 | while (*p != NULL) { | ||
3037 | u64 end; | ||
3038 | |||
3039 | parent = *p; | ||
3040 | cache = rb_entry(parent, struct dso_cache, rb_node); | ||
3041 | end = cache->offset + DSO__DATA_CACHE_SIZE; | ||
3042 | |||
3043 | if (offset < cache->offset) | ||
3044 | p = &(*p)->rb_left; | ||
3045 | else if (offset >= end) | ||
3046 | p = &(*p)->rb_right; | ||
3047 | else | ||
3048 | return cache; | ||
3049 | } | ||
3050 | return NULL; | ||
3051 | } | ||
3052 | |||
3053 | static void | ||
3054 | dso_cache__insert(struct rb_root *root, struct dso_cache *new) | ||
3055 | { | ||
3056 | struct rb_node **p = &root->rb_node; | ||
3057 | struct rb_node *parent = NULL; | ||
3058 | struct dso_cache *cache; | ||
3059 | u64 offset = new->offset; | ||
3060 | |||
3061 | while (*p != NULL) { | ||
3062 | u64 end; | ||
3063 | |||
3064 | parent = *p; | ||
3065 | cache = rb_entry(parent, struct dso_cache, rb_node); | ||
3066 | end = cache->offset + DSO__DATA_CACHE_SIZE; | ||
3067 | |||
3068 | if (offset < cache->offset) | ||
3069 | p = &(*p)->rb_left; | ||
3070 | else if (offset >= end) | ||
3071 | p = &(*p)->rb_right; | ||
3072 | } | ||
3073 | |||
3074 | rb_link_node(&new->rb_node, parent, p); | ||
3075 | rb_insert_color(&new->rb_node, root); | ||
3076 | } | ||
3077 | |||
3078 | static ssize_t | ||
3079 | dso_cache__memcpy(struct dso_cache *cache, u64 offset, | ||
3080 | u8 *data, u64 size) | ||
3081 | { | ||
3082 | u64 cache_offset = offset - cache->offset; | ||
3083 | u64 cache_size = min(cache->size - cache_offset, size); | ||
3084 | |||
3085 | memcpy(data, cache->data + cache_offset, cache_size); | ||
3086 | return cache_size; | ||
3087 | } | ||
3088 | |||
3089 | static ssize_t | ||
3090 | dso_cache__read(struct dso *dso, struct machine *machine, | ||
3091 | u64 offset, u8 *data, ssize_t size) | ||
3092 | { | ||
3093 | struct dso_cache *cache; | ||
3094 | ssize_t ret; | ||
3095 | int fd; | ||
3096 | |||
3097 | fd = dso__data_fd(dso, machine); | ||
3098 | if (fd < 0) | ||
3099 | return -1; | ||
3100 | |||
3101 | do { | ||
3102 | u64 cache_offset; | ||
3103 | |||
3104 | ret = -ENOMEM; | ||
3105 | |||
3106 | cache = zalloc(sizeof(*cache) + DSO__DATA_CACHE_SIZE); | ||
3107 | if (!cache) | ||
3108 | break; | ||
3109 | |||
3110 | cache_offset = offset & DSO__DATA_CACHE_MASK; | ||
3111 | ret = -EINVAL; | ||
3112 | |||
3113 | if (-1 == lseek(fd, cache_offset, SEEK_SET)) | ||
3114 | break; | ||
3115 | |||
3116 | ret = read(fd, cache->data, DSO__DATA_CACHE_SIZE); | ||
3117 | if (ret <= 0) | ||
3118 | break; | ||
3119 | |||
3120 | cache->offset = cache_offset; | ||
3121 | cache->size = ret; | ||
3122 | dso_cache__insert(&dso->cache, cache); | ||
3123 | |||
3124 | ret = dso_cache__memcpy(cache, offset, data, size); | ||
3125 | |||
3126 | } while (0); | ||
3127 | |||
3128 | if (ret <= 0) | ||
3129 | free(cache); | ||
3130 | |||
3131 | close(fd); | ||
3132 | return ret; | ||
3133 | } | ||
3134 | |||
3135 | static ssize_t dso_cache_read(struct dso *dso, struct machine *machine, | ||
3136 | u64 offset, u8 *data, ssize_t size) | ||
3137 | { | ||
3138 | struct dso_cache *cache; | ||
3139 | |||
3140 | cache = dso_cache__find(&dso->cache, offset); | ||
3141 | if (cache) | ||
3142 | return dso_cache__memcpy(cache, offset, data, size); | ||
3143 | else | ||
3144 | return dso_cache__read(dso, machine, offset, data, size); | ||
3145 | } | ||
3146 | |||
3147 | ssize_t dso__data_read_offset(struct dso *dso, struct machine *machine, | ||
3148 | u64 offset, u8 *data, ssize_t size) | ||
3149 | { | ||
3150 | ssize_t r = 0; | ||
3151 | u8 *p = data; | ||
3152 | |||
3153 | do { | ||
3154 | ssize_t ret; | ||
3155 | |||
3156 | ret = dso_cache_read(dso, machine, offset, p, size); | ||
3157 | if (ret < 0) | ||
3158 | return ret; | ||
3159 | |||
3160 | /* Reached EOF, return what we have. */ | ||
3161 | if (!ret) | ||
3162 | break; | ||
3163 | |||
3164 | BUG_ON(ret > size); | ||
3165 | |||
3166 | r += ret; | ||
3167 | p += ret; | ||
3168 | offset += ret; | ||
3169 | size -= ret; | ||
3170 | |||
3171 | } while (size); | ||
3172 | |||
3173 | return r; | ||
3174 | } | ||
3175 | |||
3176 | ssize_t dso__data_read_addr(struct dso *dso, struct map *map, | ||
3177 | struct machine *machine, u64 addr, | ||
3178 | u8 *data, ssize_t size) | ||
3179 | { | ||
3180 | u64 offset = map->map_ip(map, addr); | ||
3181 | return dso__data_read_offset(dso, machine, offset, data, size); | ||
3182 | } | ||
diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h index af0752b1aca1..1fe733a1e21f 100644 --- a/tools/perf/util/symbol.h +++ b/tools/perf/util/symbol.h | |||
@@ -155,6 +155,21 @@ struct addr_location { | |||
155 | s32 cpu; | 155 | s32 cpu; |
156 | }; | 156 | }; |
157 | 157 | ||
158 | enum dso_binary_type { | ||
159 | DSO_BINARY_TYPE__KALLSYMS = 0, | ||
160 | DSO_BINARY_TYPE__GUEST_KALLSYMS, | ||
161 | DSO_BINARY_TYPE__JAVA_JIT, | ||
162 | DSO_BINARY_TYPE__DEBUGLINK, | ||
163 | DSO_BINARY_TYPE__BUILD_ID_CACHE, | ||
164 | DSO_BINARY_TYPE__FEDORA_DEBUGINFO, | ||
165 | DSO_BINARY_TYPE__UBUNTU_DEBUGINFO, | ||
166 | DSO_BINARY_TYPE__BUILDID_DEBUGINFO, | ||
167 | DSO_BINARY_TYPE__SYSTEM_PATH_DSO, | ||
168 | DSO_BINARY_TYPE__GUEST_KMODULE, | ||
169 | DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE, | ||
170 | DSO_BINARY_TYPE__NOT_FOUND, | ||
171 | }; | ||
172 | |||
158 | enum dso_kernel_type { | 173 | enum dso_kernel_type { |
159 | DSO_TYPE_USER = 0, | 174 | DSO_TYPE_USER = 0, |
160 | DSO_TYPE_KERNEL, | 175 | DSO_TYPE_KERNEL, |
@@ -167,19 +182,31 @@ enum dso_swap_type { | |||
167 | DSO_SWAP__YES, | 182 | DSO_SWAP__YES, |
168 | }; | 183 | }; |
169 | 184 | ||
185 | #define DSO__DATA_CACHE_SIZE 4096 | ||
186 | #define DSO__DATA_CACHE_MASK ~(DSO__DATA_CACHE_SIZE - 1) | ||
187 | |||
188 | struct dso_cache { | ||
189 | struct rb_node rb_node; | ||
190 | u64 offset; | ||
191 | u64 size; | ||
192 | char data[0]; | ||
193 | }; | ||
194 | |||
170 | struct dso { | 195 | struct dso { |
171 | struct list_head node; | 196 | struct list_head node; |
172 | struct rb_root symbols[MAP__NR_TYPES]; | 197 | struct rb_root symbols[MAP__NR_TYPES]; |
173 | struct rb_root symbol_names[MAP__NR_TYPES]; | 198 | struct rb_root symbol_names[MAP__NR_TYPES]; |
199 | struct rb_root cache; | ||
174 | enum dso_kernel_type kernel; | 200 | enum dso_kernel_type kernel; |
175 | enum dso_swap_type needs_swap; | 201 | enum dso_swap_type needs_swap; |
202 | enum dso_binary_type symtab_type; | ||
203 | enum dso_binary_type data_type; | ||
176 | u8 adjust_symbols:1; | 204 | u8 adjust_symbols:1; |
177 | u8 has_build_id:1; | 205 | u8 has_build_id:1; |
178 | u8 hit:1; | 206 | u8 hit:1; |
179 | u8 annotate_warned:1; | 207 | u8 annotate_warned:1; |
180 | u8 sname_alloc:1; | 208 | u8 sname_alloc:1; |
181 | u8 lname_alloc:1; | 209 | u8 lname_alloc:1; |
182 | unsigned char symtab_type; | ||
183 | u8 sorted_by_name; | 210 | u8 sorted_by_name; |
184 | u8 loaded; | 211 | u8 loaded; |
185 | u8 build_id[BUILD_ID_SIZE]; | 212 | u8 build_id[BUILD_ID_SIZE]; |
@@ -253,20 +280,6 @@ size_t dso__fprintf_symbols_by_name(struct dso *dso, | |||
253 | enum map_type type, FILE *fp); | 280 | enum map_type type, FILE *fp); |
254 | size_t dso__fprintf(struct dso *dso, enum map_type type, FILE *fp); | 281 | size_t dso__fprintf(struct dso *dso, enum map_type type, FILE *fp); |
255 | 282 | ||
256 | enum symtab_type { | ||
257 | SYMTAB__KALLSYMS = 0, | ||
258 | SYMTAB__GUEST_KALLSYMS, | ||
259 | SYMTAB__JAVA_JIT, | ||
260 | SYMTAB__BUILD_ID_CACHE, | ||
261 | SYMTAB__FEDORA_DEBUGINFO, | ||
262 | SYMTAB__UBUNTU_DEBUGINFO, | ||
263 | SYMTAB__BUILDID_DEBUGINFO, | ||
264 | SYMTAB__SYSTEM_PATH_DSO, | ||
265 | SYMTAB__GUEST_KMODULE, | ||
266 | SYMTAB__SYSTEM_PATH_KMODULE, | ||
267 | SYMTAB__NOT_FOUND, | ||
268 | }; | ||
269 | |||
270 | char dso__symtab_origin(const struct dso *dso); | 283 | char dso__symtab_origin(const struct dso *dso); |
271 | void dso__set_long_name(struct dso *dso, char *name); | 284 | void dso__set_long_name(struct dso *dso, char *name); |
272 | void dso__set_build_id(struct dso *dso, void *build_id); | 285 | void dso__set_build_id(struct dso *dso, void *build_id); |
@@ -303,4 +316,14 @@ bool symbol_type__is_a(char symbol_type, enum map_type map_type); | |||
303 | 316 | ||
304 | size_t machine__fprintf_vmlinux_path(struct machine *machine, FILE *fp); | 317 | size_t machine__fprintf_vmlinux_path(struct machine *machine, FILE *fp); |
305 | 318 | ||
319 | int dso__binary_type_file(struct dso *dso, enum dso_binary_type type, | ||
320 | char *root_dir, char *file, size_t size); | ||
321 | |||
322 | int dso__data_fd(struct dso *dso, struct machine *machine); | ||
323 | ssize_t dso__data_read_offset(struct dso *dso, struct machine *machine, | ||
324 | u64 offset, u8 *data, ssize_t size); | ||
325 | ssize_t dso__data_read_addr(struct dso *dso, struct map *map, | ||
326 | struct machine *machine, u64 addr, | ||
327 | u8 *data, ssize_t size); | ||
328 | int dso__test_data(void); | ||
306 | #endif /* __PERF_SYMBOL */ | 329 | #endif /* __PERF_SYMBOL */ |
diff --git a/tools/perf/util/target.c b/tools/perf/util/target.c index 1064d5b148ad..3f59c496e64c 100644 --- a/tools/perf/util/target.c +++ b/tools/perf/util/target.c | |||
@@ -110,8 +110,17 @@ int perf_target__strerror(struct perf_target *target, int errnum, | |||
110 | int idx; | 110 | int idx; |
111 | const char *msg; | 111 | const char *msg; |
112 | 112 | ||
113 | BUG_ON(buflen > 0); | ||
114 | |||
113 | if (errnum >= 0) { | 115 | if (errnum >= 0) { |
114 | strerror_r(errnum, buf, buflen); | 116 | const char *err = strerror_r(errnum, buf, buflen); |
117 | |||
118 | if (err != buf) { | ||
119 | size_t len = strlen(err); | ||
120 | char *c = mempcpy(buf, err, min(buflen - 1, len)); | ||
121 | *c = '\0'; | ||
122 | } | ||
123 | |||
115 | return 0; | 124 | return 0; |
116 | } | 125 | } |
117 | 126 | ||
diff --git a/tools/perf/util/top.c b/tools/perf/util/top.c index abe0e8e95068..7eeebcee291c 100644 --- a/tools/perf/util/top.c +++ b/tools/perf/util/top.c | |||
@@ -65,7 +65,7 @@ size_t perf_top__header_snprintf(struct perf_top *top, char *bf, size_t size) | |||
65 | top->freq ? "Hz" : ""); | 65 | top->freq ? "Hz" : ""); |
66 | } | 66 | } |
67 | 67 | ||
68 | ret += SNPRINTF(bf + ret, size - ret, "%s", event_name(top->sym_evsel)); | 68 | ret += SNPRINTF(bf + ret, size - ret, "%s", perf_evsel__name(top->sym_evsel)); |
69 | 69 | ||
70 | ret += SNPRINTF(bf + ret, size - ret, "], "); | 70 | ret += SNPRINTF(bf + ret, size - ret, "], "); |
71 | 71 | ||
diff --git a/tools/perf/util/trace-event-parse.c b/tools/perf/util/trace-event-parse.c index df2fddbf0cd2..0715c843c2e7 100644 --- a/tools/perf/util/trace-event-parse.c +++ b/tools/perf/util/trace-event-parse.c | |||
@@ -32,29 +32,25 @@ int header_page_size_size; | |||
32 | int header_page_ts_size; | 32 | int header_page_ts_size; |
33 | int header_page_data_offset; | 33 | int header_page_data_offset; |
34 | 34 | ||
35 | struct pevent *perf_pevent; | ||
36 | static struct pevent *pevent; | ||
37 | |||
38 | bool latency_format; | 35 | bool latency_format; |
39 | 36 | ||
40 | int read_trace_init(int file_bigendian, int host_bigendian) | 37 | struct pevent *read_trace_init(int file_bigendian, int host_bigendian) |
41 | { | 38 | { |
42 | if (pevent) | 39 | struct pevent *pevent = pevent_alloc(); |
43 | return 0; | ||
44 | |||
45 | perf_pevent = pevent_alloc(); | ||
46 | pevent = perf_pevent; | ||
47 | 40 | ||
48 | pevent_set_flag(pevent, PEVENT_NSEC_OUTPUT); | 41 | if (pevent != NULL) { |
49 | pevent_set_file_bigendian(pevent, file_bigendian); | 42 | pevent_set_flag(pevent, PEVENT_NSEC_OUTPUT); |
50 | pevent_set_host_bigendian(pevent, host_bigendian); | 43 | pevent_set_file_bigendian(pevent, file_bigendian); |
44 | pevent_set_host_bigendian(pevent, host_bigendian); | ||
45 | } | ||
51 | 46 | ||
52 | return 0; | 47 | return pevent; |
53 | } | 48 | } |
54 | 49 | ||
55 | static int get_common_field(struct scripting_context *context, | 50 | static int get_common_field(struct scripting_context *context, |
56 | int *offset, int *size, const char *type) | 51 | int *offset, int *size, const char *type) |
57 | { | 52 | { |
53 | struct pevent *pevent = context->pevent; | ||
58 | struct event_format *event; | 54 | struct event_format *event; |
59 | struct format_field *field; | 55 | struct format_field *field; |
60 | 56 | ||
@@ -150,7 +146,7 @@ void *raw_field_ptr(struct event_format *event, const char *name, void *data) | |||
150 | return data + field->offset; | 146 | return data + field->offset; |
151 | } | 147 | } |
152 | 148 | ||
153 | int trace_parse_common_type(void *data) | 149 | int trace_parse_common_type(struct pevent *pevent, void *data) |
154 | { | 150 | { |
155 | struct pevent_record record; | 151 | struct pevent_record record; |
156 | 152 | ||
@@ -158,7 +154,7 @@ int trace_parse_common_type(void *data) | |||
158 | return pevent_data_type(pevent, &record); | 154 | return pevent_data_type(pevent, &record); |
159 | } | 155 | } |
160 | 156 | ||
161 | int trace_parse_common_pid(void *data) | 157 | int trace_parse_common_pid(struct pevent *pevent, void *data) |
162 | { | 158 | { |
163 | struct pevent_record record; | 159 | struct pevent_record record; |
164 | 160 | ||
@@ -166,27 +162,21 @@ int trace_parse_common_pid(void *data) | |||
166 | return pevent_data_pid(pevent, &record); | 162 | return pevent_data_pid(pevent, &record); |
167 | } | 163 | } |
168 | 164 | ||
169 | unsigned long long read_size(void *ptr, int size) | 165 | unsigned long long read_size(struct pevent *pevent, void *ptr, int size) |
170 | { | 166 | { |
171 | return pevent_read_number(pevent, ptr, size); | 167 | return pevent_read_number(pevent, ptr, size); |
172 | } | 168 | } |
173 | 169 | ||
174 | struct event_format *trace_find_event(int type) | 170 | void print_trace_event(struct pevent *pevent, int cpu, void *data, int size) |
175 | { | ||
176 | return pevent_find_event(pevent, type); | ||
177 | } | ||
178 | |||
179 | |||
180 | void print_trace_event(int cpu, void *data, int size) | ||
181 | { | 171 | { |
182 | struct event_format *event; | 172 | struct event_format *event; |
183 | struct pevent_record record; | 173 | struct pevent_record record; |
184 | struct trace_seq s; | 174 | struct trace_seq s; |
185 | int type; | 175 | int type; |
186 | 176 | ||
187 | type = trace_parse_common_type(data); | 177 | type = trace_parse_common_type(pevent, data); |
188 | 178 | ||
189 | event = trace_find_event(type); | 179 | event = pevent_find_event(pevent, type); |
190 | if (!event) { | 180 | if (!event) { |
191 | warning("ug! no event found for type %d", type); | 181 | warning("ug! no event found for type %d", type); |
192 | return; | 182 | return; |
@@ -198,13 +188,12 @@ void print_trace_event(int cpu, void *data, int size) | |||
198 | record.data = data; | 188 | record.data = data; |
199 | 189 | ||
200 | trace_seq_init(&s); | 190 | trace_seq_init(&s); |
201 | pevent_print_event(pevent, &s, &record); | 191 | pevent_event_info(&s, event, &record); |
202 | trace_seq_do_printf(&s); | 192 | trace_seq_do_printf(&s); |
203 | printf("\n"); | ||
204 | } | 193 | } |
205 | 194 | ||
206 | void print_event(int cpu, void *data, int size, unsigned long long nsecs, | 195 | void print_event(struct pevent *pevent, int cpu, void *data, int size, |
207 | char *comm) | 196 | unsigned long long nsecs, char *comm) |
208 | { | 197 | { |
209 | struct pevent_record record; | 198 | struct pevent_record record; |
210 | struct trace_seq s; | 199 | struct trace_seq s; |
@@ -227,7 +216,8 @@ void print_event(int cpu, void *data, int size, unsigned long long nsecs, | |||
227 | printf("\n"); | 216 | printf("\n"); |
228 | } | 217 | } |
229 | 218 | ||
230 | void parse_proc_kallsyms(char *file, unsigned int size __unused) | 219 | void parse_proc_kallsyms(struct pevent *pevent, |
220 | char *file, unsigned int size __unused) | ||
231 | { | 221 | { |
232 | unsigned long long addr; | 222 | unsigned long long addr; |
233 | char *func; | 223 | char *func; |
@@ -258,7 +248,8 @@ void parse_proc_kallsyms(char *file, unsigned int size __unused) | |||
258 | } | 248 | } |
259 | } | 249 | } |
260 | 250 | ||
261 | void parse_ftrace_printk(char *file, unsigned int size __unused) | 251 | void parse_ftrace_printk(struct pevent *pevent, |
252 | char *file, unsigned int size __unused) | ||
262 | { | 253 | { |
263 | unsigned long long addr; | 254 | unsigned long long addr; |
264 | char *printk; | 255 | char *printk; |
@@ -282,17 +273,19 @@ void parse_ftrace_printk(char *file, unsigned int size __unused) | |||
282 | } | 273 | } |
283 | } | 274 | } |
284 | 275 | ||
285 | int parse_ftrace_file(char *buf, unsigned long size) | 276 | int parse_ftrace_file(struct pevent *pevent, char *buf, unsigned long size) |
286 | { | 277 | { |
287 | return pevent_parse_event(pevent, buf, size, "ftrace"); | 278 | return pevent_parse_event(pevent, buf, size, "ftrace"); |
288 | } | 279 | } |
289 | 280 | ||
290 | int parse_event_file(char *buf, unsigned long size, char *sys) | 281 | int parse_event_file(struct pevent *pevent, |
282 | char *buf, unsigned long size, char *sys) | ||
291 | { | 283 | { |
292 | return pevent_parse_event(pevent, buf, size, sys); | 284 | return pevent_parse_event(pevent, buf, size, sys); |
293 | } | 285 | } |
294 | 286 | ||
295 | struct event_format *trace_find_next_event(struct event_format *event) | 287 | struct event_format *trace_find_next_event(struct pevent *pevent, |
288 | struct event_format *event) | ||
296 | { | 289 | { |
297 | static int idx; | 290 | static int idx; |
298 | 291 | ||
diff --git a/tools/perf/util/trace-event-read.c b/tools/perf/util/trace-event-read.c index f097e0dd6c5c..719ed74a8565 100644 --- a/tools/perf/util/trace-event-read.c +++ b/tools/perf/util/trace-event-read.c | |||
@@ -114,20 +114,20 @@ static void skip(int size) | |||
114 | }; | 114 | }; |
115 | } | 115 | } |
116 | 116 | ||
117 | static unsigned int read4(void) | 117 | static unsigned int read4(struct pevent *pevent) |
118 | { | 118 | { |
119 | unsigned int data; | 119 | unsigned int data; |
120 | 120 | ||
121 | read_or_die(&data, 4); | 121 | read_or_die(&data, 4); |
122 | return __data2host4(perf_pevent, data); | 122 | return __data2host4(pevent, data); |
123 | } | 123 | } |
124 | 124 | ||
125 | static unsigned long long read8(void) | 125 | static unsigned long long read8(struct pevent *pevent) |
126 | { | 126 | { |
127 | unsigned long long data; | 127 | unsigned long long data; |
128 | 128 | ||
129 | read_or_die(&data, 8); | 129 | read_or_die(&data, 8); |
130 | return __data2host8(perf_pevent, data); | 130 | return __data2host8(pevent, data); |
131 | } | 131 | } |
132 | 132 | ||
133 | static char *read_string(void) | 133 | static char *read_string(void) |
@@ -168,12 +168,12 @@ static char *read_string(void) | |||
168 | return str; | 168 | return str; |
169 | } | 169 | } |
170 | 170 | ||
171 | static void read_proc_kallsyms(void) | 171 | static void read_proc_kallsyms(struct pevent *pevent) |
172 | { | 172 | { |
173 | unsigned int size; | 173 | unsigned int size; |
174 | char *buf; | 174 | char *buf; |
175 | 175 | ||
176 | size = read4(); | 176 | size = read4(pevent); |
177 | if (!size) | 177 | if (!size) |
178 | return; | 178 | return; |
179 | 179 | ||
@@ -181,29 +181,29 @@ static void read_proc_kallsyms(void) | |||
181 | read_or_die(buf, size); | 181 | read_or_die(buf, size); |
182 | buf[size] = '\0'; | 182 | buf[size] = '\0'; |
183 | 183 | ||
184 | parse_proc_kallsyms(buf, size); | 184 | parse_proc_kallsyms(pevent, buf, size); |
185 | 185 | ||
186 | free(buf); | 186 | free(buf); |
187 | } | 187 | } |
188 | 188 | ||
189 | static void read_ftrace_printk(void) | 189 | static void read_ftrace_printk(struct pevent *pevent) |
190 | { | 190 | { |
191 | unsigned int size; | 191 | unsigned int size; |
192 | char *buf; | 192 | char *buf; |
193 | 193 | ||
194 | size = read4(); | 194 | size = read4(pevent); |
195 | if (!size) | 195 | if (!size) |
196 | return; | 196 | return; |
197 | 197 | ||
198 | buf = malloc_or_die(size); | 198 | buf = malloc_or_die(size); |
199 | read_or_die(buf, size); | 199 | read_or_die(buf, size); |
200 | 200 | ||
201 | parse_ftrace_printk(buf, size); | 201 | parse_ftrace_printk(pevent, buf, size); |
202 | 202 | ||
203 | free(buf); | 203 | free(buf); |
204 | } | 204 | } |
205 | 205 | ||
206 | static void read_header_files(void) | 206 | static void read_header_files(struct pevent *pevent) |
207 | { | 207 | { |
208 | unsigned long long size; | 208 | unsigned long long size; |
209 | char *header_event; | 209 | char *header_event; |
@@ -214,7 +214,7 @@ static void read_header_files(void) | |||
214 | if (memcmp(buf, "header_page", 12) != 0) | 214 | if (memcmp(buf, "header_page", 12) != 0) |
215 | die("did not read header page"); | 215 | die("did not read header page"); |
216 | 216 | ||
217 | size = read8(); | 217 | size = read8(pevent); |
218 | skip(size); | 218 | skip(size); |
219 | 219 | ||
220 | /* | 220 | /* |
@@ -227,47 +227,48 @@ static void read_header_files(void) | |||
227 | if (memcmp(buf, "header_event", 13) != 0) | 227 | if (memcmp(buf, "header_event", 13) != 0) |
228 | die("did not read header event"); | 228 | die("did not read header event"); |
229 | 229 | ||
230 | size = read8(); | 230 | size = read8(pevent); |
231 | header_event = malloc_or_die(size); | 231 | header_event = malloc_or_die(size); |
232 | read_or_die(header_event, size); | 232 | read_or_die(header_event, size); |
233 | free(header_event); | 233 | free(header_event); |
234 | } | 234 | } |
235 | 235 | ||
236 | static void read_ftrace_file(unsigned long long size) | 236 | static void read_ftrace_file(struct pevent *pevent, unsigned long long size) |
237 | { | 237 | { |
238 | char *buf; | 238 | char *buf; |
239 | 239 | ||
240 | buf = malloc_or_die(size); | 240 | buf = malloc_or_die(size); |
241 | read_or_die(buf, size); | 241 | read_or_die(buf, size); |
242 | parse_ftrace_file(buf, size); | 242 | parse_ftrace_file(pevent, buf, size); |
243 | free(buf); | 243 | free(buf); |
244 | } | 244 | } |
245 | 245 | ||
246 | static void read_event_file(char *sys, unsigned long long size) | 246 | static void read_event_file(struct pevent *pevent, char *sys, |
247 | unsigned long long size) | ||
247 | { | 248 | { |
248 | char *buf; | 249 | char *buf; |
249 | 250 | ||
250 | buf = malloc_or_die(size); | 251 | buf = malloc_or_die(size); |
251 | read_or_die(buf, size); | 252 | read_or_die(buf, size); |
252 | parse_event_file(buf, size, sys); | 253 | parse_event_file(pevent, buf, size, sys); |
253 | free(buf); | 254 | free(buf); |
254 | } | 255 | } |
255 | 256 | ||
256 | static void read_ftrace_files(void) | 257 | static void read_ftrace_files(struct pevent *pevent) |
257 | { | 258 | { |
258 | unsigned long long size; | 259 | unsigned long long size; |
259 | int count; | 260 | int count; |
260 | int i; | 261 | int i; |
261 | 262 | ||
262 | count = read4(); | 263 | count = read4(pevent); |
263 | 264 | ||
264 | for (i = 0; i < count; i++) { | 265 | for (i = 0; i < count; i++) { |
265 | size = read8(); | 266 | size = read8(pevent); |
266 | read_ftrace_file(size); | 267 | read_ftrace_file(pevent, size); |
267 | } | 268 | } |
268 | } | 269 | } |
269 | 270 | ||
270 | static void read_event_files(void) | 271 | static void read_event_files(struct pevent *pevent) |
271 | { | 272 | { |
272 | unsigned long long size; | 273 | unsigned long long size; |
273 | char *sys; | 274 | char *sys; |
@@ -275,15 +276,15 @@ static void read_event_files(void) | |||
275 | int count; | 276 | int count; |
276 | int i,x; | 277 | int i,x; |
277 | 278 | ||
278 | systems = read4(); | 279 | systems = read4(pevent); |
279 | 280 | ||
280 | for (i = 0; i < systems; i++) { | 281 | for (i = 0; i < systems; i++) { |
281 | sys = read_string(); | 282 | sys = read_string(); |
282 | 283 | ||
283 | count = read4(); | 284 | count = read4(pevent); |
284 | for (x=0; x < count; x++) { | 285 | for (x=0; x < count; x++) { |
285 | size = read8(); | 286 | size = read8(pevent); |
286 | read_event_file(sys, size); | 287 | read_event_file(pevent, sys, size); |
287 | } | 288 | } |
288 | } | 289 | } |
289 | } | 290 | } |
@@ -377,7 +378,7 @@ static int calc_index(void *ptr, int cpu) | |||
377 | return (unsigned long)ptr - (unsigned long)cpu_data[cpu].page; | 378 | return (unsigned long)ptr - (unsigned long)cpu_data[cpu].page; |
378 | } | 379 | } |
379 | 380 | ||
380 | struct pevent_record *trace_peek_data(int cpu) | 381 | struct pevent_record *trace_peek_data(struct pevent *pevent, int cpu) |
381 | { | 382 | { |
382 | struct pevent_record *data; | 383 | struct pevent_record *data; |
383 | void *page = cpu_data[cpu].page; | 384 | void *page = cpu_data[cpu].page; |
@@ -399,15 +400,15 @@ struct pevent_record *trace_peek_data(int cpu) | |||
399 | /* FIXME: handle header page */ | 400 | /* FIXME: handle header page */ |
400 | if (header_page_ts_size != 8) | 401 | if (header_page_ts_size != 8) |
401 | die("expected a long long type for timestamp"); | 402 | die("expected a long long type for timestamp"); |
402 | cpu_data[cpu].timestamp = data2host8(perf_pevent, ptr); | 403 | cpu_data[cpu].timestamp = data2host8(pevent, ptr); |
403 | ptr += 8; | 404 | ptr += 8; |
404 | switch (header_page_size_size) { | 405 | switch (header_page_size_size) { |
405 | case 4: | 406 | case 4: |
406 | cpu_data[cpu].page_size = data2host4(perf_pevent, ptr); | 407 | cpu_data[cpu].page_size = data2host4(pevent, ptr); |
407 | ptr += 4; | 408 | ptr += 4; |
408 | break; | 409 | break; |
409 | case 8: | 410 | case 8: |
410 | cpu_data[cpu].page_size = data2host8(perf_pevent, ptr); | 411 | cpu_data[cpu].page_size = data2host8(pevent, ptr); |
411 | ptr += 8; | 412 | ptr += 8; |
412 | break; | 413 | break; |
413 | default: | 414 | default: |
@@ -421,10 +422,10 @@ read_again: | |||
421 | 422 | ||
422 | if (idx >= cpu_data[cpu].page_size) { | 423 | if (idx >= cpu_data[cpu].page_size) { |
423 | get_next_page(cpu); | 424 | get_next_page(cpu); |
424 | return trace_peek_data(cpu); | 425 | return trace_peek_data(pevent, cpu); |
425 | } | 426 | } |
426 | 427 | ||
427 | type_len_ts = data2host4(perf_pevent, ptr); | 428 | type_len_ts = data2host4(pevent, ptr); |
428 | ptr += 4; | 429 | ptr += 4; |
429 | 430 | ||
430 | type_len = type_len4host(type_len_ts); | 431 | type_len = type_len4host(type_len_ts); |
@@ -434,14 +435,14 @@ read_again: | |||
434 | case RINGBUF_TYPE_PADDING: | 435 | case RINGBUF_TYPE_PADDING: |
435 | if (!delta) | 436 | if (!delta) |
436 | die("error, hit unexpected end of page"); | 437 | die("error, hit unexpected end of page"); |
437 | length = data2host4(perf_pevent, ptr); | 438 | length = data2host4(pevent, ptr); |
438 | ptr += 4; | 439 | ptr += 4; |
439 | length *= 4; | 440 | length *= 4; |
440 | ptr += length; | 441 | ptr += length; |
441 | goto read_again; | 442 | goto read_again; |
442 | 443 | ||
443 | case RINGBUF_TYPE_TIME_EXTEND: | 444 | case RINGBUF_TYPE_TIME_EXTEND: |
444 | extend = data2host4(perf_pevent, ptr); | 445 | extend = data2host4(pevent, ptr); |
445 | ptr += 4; | 446 | ptr += 4; |
446 | extend <<= TS_SHIFT; | 447 | extend <<= TS_SHIFT; |
447 | extend += delta; | 448 | extend += delta; |
@@ -452,7 +453,7 @@ read_again: | |||
452 | ptr += 12; | 453 | ptr += 12; |
453 | break; | 454 | break; |
454 | case 0: | 455 | case 0: |
455 | length = data2host4(perf_pevent, ptr); | 456 | length = data2host4(pevent, ptr); |
456 | ptr += 4; | 457 | ptr += 4; |
457 | die("here! length=%d", length); | 458 | die("here! length=%d", length); |
458 | break; | 459 | break; |
@@ -477,17 +478,17 @@ read_again: | |||
477 | return data; | 478 | return data; |
478 | } | 479 | } |
479 | 480 | ||
480 | struct pevent_record *trace_read_data(int cpu) | 481 | struct pevent_record *trace_read_data(struct pevent *pevent, int cpu) |
481 | { | 482 | { |
482 | struct pevent_record *data; | 483 | struct pevent_record *data; |
483 | 484 | ||
484 | data = trace_peek_data(cpu); | 485 | data = trace_peek_data(pevent, cpu); |
485 | cpu_data[cpu].next = NULL; | 486 | cpu_data[cpu].next = NULL; |
486 | 487 | ||
487 | return data; | 488 | return data; |
488 | } | 489 | } |
489 | 490 | ||
490 | ssize_t trace_report(int fd, bool __repipe) | 491 | ssize_t trace_report(int fd, struct pevent **ppevent, bool __repipe) |
491 | { | 492 | { |
492 | char buf[BUFSIZ]; | 493 | char buf[BUFSIZ]; |
493 | char test[] = { 23, 8, 68 }; | 494 | char test[] = { 23, 8, 68 }; |
@@ -519,30 +520,32 @@ ssize_t trace_report(int fd, bool __repipe) | |||
519 | file_bigendian = buf[0]; | 520 | file_bigendian = buf[0]; |
520 | host_bigendian = bigendian(); | 521 | host_bigendian = bigendian(); |
521 | 522 | ||
522 | read_trace_init(file_bigendian, host_bigendian); | 523 | *ppevent = read_trace_init(file_bigendian, host_bigendian); |
524 | if (*ppevent == NULL) | ||
525 | die("read_trace_init failed"); | ||
523 | 526 | ||
524 | read_or_die(buf, 1); | 527 | read_or_die(buf, 1); |
525 | long_size = buf[0]; | 528 | long_size = buf[0]; |
526 | 529 | ||
527 | page_size = read4(); | 530 | page_size = read4(*ppevent); |
528 | 531 | ||
529 | read_header_files(); | 532 | read_header_files(*ppevent); |
530 | 533 | ||
531 | read_ftrace_files(); | 534 | read_ftrace_files(*ppevent); |
532 | read_event_files(); | 535 | read_event_files(*ppevent); |
533 | read_proc_kallsyms(); | 536 | read_proc_kallsyms(*ppevent); |
534 | read_ftrace_printk(); | 537 | read_ftrace_printk(*ppevent); |
535 | 538 | ||
536 | size = calc_data_size - 1; | 539 | size = calc_data_size - 1; |
537 | calc_data_size = 0; | 540 | calc_data_size = 0; |
538 | repipe = false; | 541 | repipe = false; |
539 | 542 | ||
540 | if (show_funcs) { | 543 | if (show_funcs) { |
541 | pevent_print_funcs(perf_pevent); | 544 | pevent_print_funcs(*ppevent); |
542 | return size; | 545 | return size; |
543 | } | 546 | } |
544 | if (show_printk) { | 547 | if (show_printk) { |
545 | pevent_print_printk(perf_pevent); | 548 | pevent_print_printk(*ppevent); |
546 | return size; | 549 | return size; |
547 | } | 550 | } |
548 | 551 | ||
diff --git a/tools/perf/util/trace-event-scripting.c b/tools/perf/util/trace-event-scripting.c index 18ae6c1831d3..474aa7a7df43 100644 --- a/tools/perf/util/trace-event-scripting.c +++ b/tools/perf/util/trace-event-scripting.c | |||
@@ -36,6 +36,7 @@ static int stop_script_unsupported(void) | |||
36 | } | 36 | } |
37 | 37 | ||
38 | static void process_event_unsupported(union perf_event *event __unused, | 38 | static void process_event_unsupported(union perf_event *event __unused, |
39 | struct pevent *pevent __unused, | ||
39 | struct perf_sample *sample __unused, | 40 | struct perf_sample *sample __unused, |
40 | struct perf_evsel *evsel __unused, | 41 | struct perf_evsel *evsel __unused, |
41 | struct machine *machine __unused, | 42 | struct machine *machine __unused, |
@@ -61,7 +62,8 @@ static int python_start_script_unsupported(const char *script __unused, | |||
61 | return -1; | 62 | return -1; |
62 | } | 63 | } |
63 | 64 | ||
64 | static int python_generate_script_unsupported(const char *outfile __unused) | 65 | static int python_generate_script_unsupported(struct pevent *pevent __unused, |
66 | const char *outfile __unused) | ||
65 | { | 67 | { |
66 | print_python_unsupported_msg(); | 68 | print_python_unsupported_msg(); |
67 | 69 | ||
@@ -122,7 +124,8 @@ static int perl_start_script_unsupported(const char *script __unused, | |||
122 | return -1; | 124 | return -1; |
123 | } | 125 | } |
124 | 126 | ||
125 | static int perl_generate_script_unsupported(const char *outfile __unused) | 127 | static int perl_generate_script_unsupported(struct pevent *pevent __unused, |
128 | const char *outfile __unused) | ||
126 | { | 129 | { |
127 | print_perl_unsupported_msg(); | 130 | print_perl_unsupported_msg(); |
128 | 131 | ||
diff --git a/tools/perf/util/trace-event.h b/tools/perf/util/trace-event.h index 639852ac1117..8fef1d6687b7 100644 --- a/tools/perf/util/trace-event.h +++ b/tools/perf/util/trace-event.h | |||
@@ -8,6 +8,7 @@ | |||
8 | struct machine; | 8 | struct machine; |
9 | struct perf_sample; | 9 | struct perf_sample; |
10 | union perf_event; | 10 | union perf_event; |
11 | struct perf_tool; | ||
11 | struct thread; | 12 | struct thread; |
12 | 13 | ||
13 | extern int header_page_size_size; | 14 | extern int header_page_size_size; |
@@ -29,35 +30,36 @@ enum { | |||
29 | 30 | ||
30 | int bigendian(void); | 31 | int bigendian(void); |
31 | 32 | ||
32 | int read_trace_init(int file_bigendian, int host_bigendian); | 33 | struct pevent *read_trace_init(int file_bigendian, int host_bigendian); |
33 | void print_trace_event(int cpu, void *data, int size); | 34 | void print_trace_event(struct pevent *pevent, int cpu, void *data, int size); |
34 | 35 | ||
35 | void print_event(int cpu, void *data, int size, unsigned long long nsecs, | 36 | void print_event(struct pevent *pevent, int cpu, void *data, int size, |
36 | char *comm); | 37 | unsigned long long nsecs, char *comm); |
37 | 38 | ||
38 | int parse_ftrace_file(char *buf, unsigned long size); | 39 | int parse_ftrace_file(struct pevent *pevent, char *buf, unsigned long size); |
39 | int parse_event_file(char *buf, unsigned long size, char *sys); | 40 | int parse_event_file(struct pevent *pevent, |
41 | char *buf, unsigned long size, char *sys); | ||
40 | 42 | ||
41 | struct pevent_record *trace_peek_data(int cpu); | 43 | struct pevent_record *trace_peek_data(struct pevent *pevent, int cpu); |
42 | struct event_format *trace_find_event(int type); | ||
43 | 44 | ||
44 | unsigned long long | 45 | unsigned long long |
45 | raw_field_value(struct event_format *event, const char *name, void *data); | 46 | raw_field_value(struct event_format *event, const char *name, void *data); |
46 | void *raw_field_ptr(struct event_format *event, const char *name, void *data); | 47 | void *raw_field_ptr(struct event_format *event, const char *name, void *data); |
47 | 48 | ||
48 | void parse_proc_kallsyms(char *file, unsigned int size __unused); | 49 | void parse_proc_kallsyms(struct pevent *pevent, char *file, unsigned int size); |
49 | void parse_ftrace_printk(char *file, unsigned int size __unused); | 50 | void parse_ftrace_printk(struct pevent *pevent, char *file, unsigned int size); |
50 | 51 | ||
51 | ssize_t trace_report(int fd, bool repipe); | 52 | ssize_t trace_report(int fd, struct pevent **pevent, bool repipe); |
52 | 53 | ||
53 | int trace_parse_common_type(void *data); | 54 | int trace_parse_common_type(struct pevent *pevent, void *data); |
54 | int trace_parse_common_pid(void *data); | 55 | int trace_parse_common_pid(struct pevent *pevent, void *data); |
55 | 56 | ||
56 | struct event_format *trace_find_next_event(struct event_format *event); | 57 | struct event_format *trace_find_next_event(struct pevent *pevent, |
57 | unsigned long long read_size(void *ptr, int size); | 58 | struct event_format *event); |
59 | unsigned long long read_size(struct pevent *pevent, void *ptr, int size); | ||
58 | unsigned long long eval_flag(const char *flag); | 60 | unsigned long long eval_flag(const char *flag); |
59 | 61 | ||
60 | struct pevent_record *trace_read_data(int cpu); | 62 | struct pevent_record *trace_read_data(struct pevent *pevent, int cpu); |
61 | int read_tracing_data(int fd, struct list_head *pattrs); | 63 | int read_tracing_data(int fd, struct list_head *pattrs); |
62 | 64 | ||
63 | struct tracing_data { | 65 | struct tracing_data { |
@@ -77,11 +79,12 @@ struct scripting_ops { | |||
77 | int (*start_script) (const char *script, int argc, const char **argv); | 79 | int (*start_script) (const char *script, int argc, const char **argv); |
78 | int (*stop_script) (void); | 80 | int (*stop_script) (void); |
79 | void (*process_event) (union perf_event *event, | 81 | void (*process_event) (union perf_event *event, |
82 | struct pevent *pevent, | ||
80 | struct perf_sample *sample, | 83 | struct perf_sample *sample, |
81 | struct perf_evsel *evsel, | 84 | struct perf_evsel *evsel, |
82 | struct machine *machine, | 85 | struct machine *machine, |
83 | struct thread *thread); | 86 | struct thread *thread); |
84 | int (*generate_script) (const char *outfile); | 87 | int (*generate_script) (struct pevent *pevent, const char *outfile); |
85 | }; | 88 | }; |
86 | 89 | ||
87 | int script_spec_register(const char *spec, struct scripting_ops *ops); | 90 | int script_spec_register(const char *spec, struct scripting_ops *ops); |
@@ -90,6 +93,7 @@ void setup_perl_scripting(void); | |||
90 | void setup_python_scripting(void); | 93 | void setup_python_scripting(void); |
91 | 94 | ||
92 | struct scripting_context { | 95 | struct scripting_context { |
96 | struct pevent *pevent; | ||
93 | void *event_data; | 97 | void *event_data; |
94 | }; | 98 | }; |
95 | 99 | ||
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h index 2daaedb83d84..b13c7331eaf8 100644 --- a/tools/perf/util/util.h +++ b/tools/perf/util/util.h | |||
@@ -264,4 +264,6 @@ bool is_power_of_2(unsigned long n) | |||
264 | 264 | ||
265 | size_t hex_width(u64 v); | 265 | size_t hex_width(u64 v); |
266 | 266 | ||
267 | char *rtrim(char *s); | ||
268 | |||
267 | #endif | 269 | #endif |
diff --git a/tools/power/x86/turbostat/Makefile b/tools/power/x86/turbostat/Makefile index fd8e1f1297aa..f85649554191 100644 --- a/tools/power/x86/turbostat/Makefile +++ b/tools/power/x86/turbostat/Makefile | |||
@@ -1,4 +1,5 @@ | |||
1 | turbostat : turbostat.c | 1 | turbostat : turbostat.c |
2 | CFLAGS += -Wall | ||
2 | 3 | ||
3 | clean : | 4 | clean : |
4 | rm -f turbostat | 5 | rm -f turbostat |
diff --git a/tools/power/x86/turbostat/turbostat.8 b/tools/power/x86/turbostat/turbostat.8 index adf175f61496..74e44507dfe9 100644 --- a/tools/power/x86/turbostat/turbostat.8 +++ b/tools/power/x86/turbostat/turbostat.8 | |||
@@ -27,7 +27,11 @@ supports an "invariant" TSC, plus the APERF and MPERF MSRs. | |||
27 | on processors that additionally support C-state residency counters. | 27 | on processors that additionally support C-state residency counters. |
28 | 28 | ||
29 | .SS Options | 29 | .SS Options |
30 | The \fB-s\fP option prints only a 1-line summary for each sample interval. | 30 | The \fB-s\fP option limits output to a 1-line system summary for each interval. |
31 | .PP | ||
32 | The \fB-c\fP option limits output to the 1st thread in each core. | ||
33 | .PP | ||
34 | The \fB-p\fP option limits output to the 1st thread in each package. | ||
31 | .PP | 35 | .PP |
32 | The \fB-v\fP option increases verbosity. | 36 | The \fB-v\fP option increases verbosity. |
33 | .PP | 37 | .PP |
@@ -65,19 +69,19 @@ Subsequent rows show per-CPU statistics. | |||
65 | .nf | 69 | .nf |
66 | [root@x980]# ./turbostat | 70 | [root@x980]# ./turbostat |
67 | cor CPU %c0 GHz TSC %c1 %c3 %c6 %pc3 %pc6 | 71 | cor CPU %c0 GHz TSC %c1 %c3 %c6 %pc3 %pc6 |
68 | 0.60 1.63 3.38 2.91 0.00 96.49 0.00 76.64 | 72 | 0.09 1.62 3.38 1.83 0.32 97.76 1.26 83.61 |
69 | 0 0 0.59 1.62 3.38 4.51 0.00 94.90 0.00 76.64 | 73 | 0 0 0.15 1.62 3.38 10.23 0.05 89.56 1.26 83.61 |
70 | 0 6 1.13 1.64 3.38 3.97 0.00 94.90 0.00 76.64 | 74 | 0 6 0.05 1.62 3.38 10.34 |
71 | 1 2 0.08 1.62 3.38 0.07 0.00 99.85 0.00 76.64 | 75 | 1 2 0.03 1.62 3.38 0.07 0.05 99.86 |
72 | 1 8 0.03 1.62 3.38 0.12 0.00 99.85 0.00 76.64 | 76 | 1 8 0.03 1.62 3.38 0.06 |
73 | 2 4 0.01 1.62 3.38 0.06 0.00 99.93 0.00 76.64 | 77 | 2 4 0.21 1.62 3.38 0.10 1.49 98.21 |
74 | 2 10 0.04 1.62 3.38 0.02 0.00 99.93 0.00 76.64 | 78 | 2 10 0.02 1.62 3.38 0.29 |
75 | 8 1 2.85 1.62 3.38 11.71 0.00 85.44 0.00 76.64 | 79 | 8 1 0.04 1.62 3.38 0.04 0.08 99.84 |
76 | 8 7 1.98 1.62 3.38 12.58 0.00 85.44 0.00 76.64 | 80 | 8 7 0.01 1.62 3.38 0.06 |
77 | 9 3 0.36 1.62 3.38 0.71 0.00 98.93 0.00 76.64 | 81 | 9 3 0.53 1.62 3.38 0.10 0.20 99.17 |
78 | 9 9 0.09 1.62 3.38 0.98 0.00 98.93 0.00 76.64 | 82 | 9 9 0.02 1.62 3.38 0.60 |
79 | 10 5 0.03 1.62 3.38 0.09 0.00 99.87 0.00 76.64 | 83 | 10 5 0.01 1.62 3.38 0.02 0.04 99.92 |
80 | 10 11 0.07 1.62 3.38 0.06 0.00 99.87 0.00 76.64 | 84 | 10 11 0.02 1.62 3.38 0.02 |
81 | .fi | 85 | .fi |
82 | .SH SUMMARY EXAMPLE | 86 | .SH SUMMARY EXAMPLE |
83 | The "-s" option prints the column headers just once, | 87 | The "-s" option prints the column headers just once, |
@@ -86,9 +90,10 @@ and then the one line system summary for each sample interval. | |||
86 | .nf | 90 | .nf |
87 | [root@x980]# ./turbostat -s | 91 | [root@x980]# ./turbostat -s |
88 | %c0 GHz TSC %c1 %c3 %c6 %pc3 %pc6 | 92 | %c0 GHz TSC %c1 %c3 %c6 %pc3 %pc6 |
89 | 0.61 1.89 3.38 5.95 0.00 93.44 0.00 66.33 | 93 | 0.23 1.67 3.38 2.00 0.30 97.47 1.07 82.12 |
90 | 0.52 1.62 3.38 6.83 0.00 92.65 0.00 61.11 | 94 | 0.10 1.62 3.38 1.87 2.25 95.77 12.02 72.60 |
91 | 0.62 1.92 3.38 5.47 0.00 93.91 0.00 67.31 | 95 | 0.20 1.64 3.38 1.98 0.11 97.72 0.30 83.36 |
96 | 0.11 1.70 3.38 1.86 1.81 96.22 9.71 74.90 | ||
92 | .fi | 97 | .fi |
93 | .SH VERBOSE EXAMPLE | 98 | .SH VERBOSE EXAMPLE |
94 | The "-v" option adds verbosity to the output: | 99 | The "-v" option adds verbosity to the output: |
@@ -120,30 +125,28 @@ until ^C while the other CPUs are mostly idle: | |||
120 | [root@x980 lenb]# ./turbostat cat /dev/zero > /dev/null | 125 | [root@x980 lenb]# ./turbostat cat /dev/zero > /dev/null |
121 | ^C | 126 | ^C |
122 | cor CPU %c0 GHz TSC %c1 %c3 %c6 %pc3 %pc6 | 127 | cor CPU %c0 GHz TSC %c1 %c3 %c6 %pc3 %pc6 |
123 | 8.63 3.64 3.38 14.46 0.49 76.42 0.00 0.00 | 128 | 8.86 3.61 3.38 15.06 31.19 44.89 0.00 0.00 |
124 | 0 0 0.34 3.36 3.38 99.66 0.00 0.00 0.00 0.00 | 129 | 0 0 1.46 3.22 3.38 16.84 29.48 52.22 0.00 0.00 |
125 | 0 6 99.96 3.64 3.38 0.04 0.00 0.00 0.00 0.00 | 130 | 0 6 0.21 3.06 3.38 18.09 |
126 | 1 2 0.14 3.50 3.38 1.75 2.04 96.07 0.00 0.00 | 131 | 1 2 0.53 3.33 3.38 2.80 46.40 50.27 |
127 | 1 8 0.38 3.57 3.38 1.51 2.04 96.07 0.00 0.00 | 132 | 1 8 0.89 3.47 3.38 2.44 |
128 | 2 4 0.01 2.65 3.38 0.06 0.00 99.93 0.00 0.00 | 133 | 2 4 1.36 3.43 3.38 9.04 23.71 65.89 |
129 | 2 10 0.03 2.12 3.38 0.04 0.00 99.93 0.00 0.00 | 134 | 2 10 0.18 2.86 3.38 10.22 |
130 | 8 1 0.91 3.59 3.38 35.27 0.92 62.90 0.00 0.00 | 135 | 8 1 0.04 2.87 3.38 99.96 0.01 0.00 |
131 | 8 7 1.61 3.63 3.38 34.57 0.92 62.90 0.00 0.00 | 136 | 8 7 99.72 3.63 3.38 0.27 |
132 | 9 3 0.04 3.38 3.38 0.20 0.00 99.76 0.00 0.00 | 137 | 9 3 0.31 3.21 3.38 7.64 56.55 35.50 |
133 | 9 9 0.04 3.29 3.38 0.20 0.00 99.76 0.00 0.00 | 138 | 9 9 0.08 2.95 3.38 7.88 |
134 | 10 5 0.03 3.08 3.38 0.12 0.00 99.85 0.00 0.00 | 139 | 10 5 1.42 3.43 3.38 2.14 30.99 65.44 |
135 | 10 11 0.05 3.07 3.38 0.10 0.00 99.85 0.00 0.00 | 140 | 10 11 0.16 2.88 3.38 3.40 |
136 | 4.907015 sec | ||
137 | |||
138 | .fi | 141 | .fi |
139 | Above the cycle soaker drives cpu6 up 3.6 Ghz turbo limit | 142 | Above the cycle soaker drives cpu7 up its 3.6 Ghz turbo limit |
140 | while the other processors are generally in various states of idle. | 143 | while the other processors are generally in various states of idle. |
141 | 144 | ||
142 | Note that cpu0 is an HT sibling sharing core0 | 145 | Note that cpu1 and cpu7 are HT siblings within core8. |
143 | with cpu6, and thus it is unable to get to an idle state | 146 | As cpu7 is very busy, it prevents its sibling, cpu1, |
144 | deeper than c1 while cpu6 is busy. | 147 | from entering a c-state deeper than c1. |
145 | 148 | ||
146 | Note that turbostat reports average GHz of 3.64, while | 149 | Note that turbostat reports average GHz of 3.63, while |
147 | the arithmetic average of the GHz column above is lower. | 150 | the arithmetic average of the GHz column above is lower. |
148 | This is a weighted average, where the weight is %c0. ie. it is the total number of | 151 | This is a weighted average, where the weight is %c0. ie. it is the total number of |
149 | un-halted cycles elapsed per time divided by the number of CPUs. | 152 | un-halted cycles elapsed per time divided by the number of CPUs. |
diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c index 16de7ad4850f..861d77190206 100644 --- a/tools/power/x86/turbostat/turbostat.c +++ b/tools/power/x86/turbostat/turbostat.c | |||
@@ -67,92 +67,119 @@ double bclk; | |||
67 | unsigned int show_pkg; | 67 | unsigned int show_pkg; |
68 | unsigned int show_core; | 68 | unsigned int show_core; |
69 | unsigned int show_cpu; | 69 | unsigned int show_cpu; |
70 | unsigned int show_pkg_only; | ||
71 | unsigned int show_core_only; | ||
72 | char *output_buffer, *outp; | ||
70 | 73 | ||
71 | int aperf_mperf_unstable; | 74 | int aperf_mperf_unstable; |
72 | int backwards_count; | 75 | int backwards_count; |
73 | char *progname; | 76 | char *progname; |
74 | 77 | ||
75 | int num_cpus; | 78 | cpu_set_t *cpu_present_set, *cpu_affinity_set; |
76 | cpu_set_t *cpu_present_set, *cpu_mask; | 79 | size_t cpu_present_setsize, cpu_affinity_setsize; |
77 | size_t cpu_present_setsize, cpu_mask_size; | 80 | |
78 | 81 | struct thread_data { | |
79 | struct counters { | 82 | unsigned long long tsc; |
80 | unsigned long long tsc; /* per thread */ | 83 | unsigned long long aperf; |
81 | unsigned long long aperf; /* per thread */ | 84 | unsigned long long mperf; |
82 | unsigned long long mperf; /* per thread */ | 85 | unsigned long long c1; /* derived */ |
83 | unsigned long long c1; /* per thread (calculated) */ | 86 | unsigned long long extra_msr; |
84 | unsigned long long c3; /* per core */ | 87 | unsigned int cpu_id; |
85 | unsigned long long c6; /* per core */ | 88 | unsigned int flags; |
86 | unsigned long long c7; /* per core */ | 89 | #define CPU_IS_FIRST_THREAD_IN_CORE 0x2 |
87 | unsigned long long pc2; /* per package */ | 90 | #define CPU_IS_FIRST_CORE_IN_PACKAGE 0x4 |
88 | unsigned long long pc3; /* per package */ | 91 | } *thread_even, *thread_odd; |
89 | unsigned long long pc6; /* per package */ | 92 | |
90 | unsigned long long pc7; /* per package */ | 93 | struct core_data { |
91 | unsigned long long extra_msr; /* per thread */ | 94 | unsigned long long c3; |
92 | int pkg; | 95 | unsigned long long c6; |
93 | int core; | 96 | unsigned long long c7; |
94 | int cpu; | 97 | unsigned int core_id; |
95 | struct counters *next; | 98 | } *core_even, *core_odd; |
96 | }; | 99 | |
97 | 100 | struct pkg_data { | |
98 | struct counters *cnt_even; | 101 | unsigned long long pc2; |
99 | struct counters *cnt_odd; | 102 | unsigned long long pc3; |
100 | struct counters *cnt_delta; | 103 | unsigned long long pc6; |
101 | struct counters *cnt_average; | 104 | unsigned long long pc7; |
102 | struct timeval tv_even; | 105 | unsigned int package_id; |
103 | struct timeval tv_odd; | 106 | } *package_even, *package_odd; |
104 | struct timeval tv_delta; | 107 | |
105 | 108 | #define ODD_COUNTERS thread_odd, core_odd, package_odd | |
106 | int mark_cpu_present(int pkg, int core, int cpu) | 109 | #define EVEN_COUNTERS thread_even, core_even, package_even |
110 | |||
111 | #define GET_THREAD(thread_base, thread_no, core_no, pkg_no) \ | ||
112 | (thread_base + (pkg_no) * topo.num_cores_per_pkg * \ | ||
113 | topo.num_threads_per_core + \ | ||
114 | (core_no) * topo.num_threads_per_core + (thread_no)) | ||
115 | #define GET_CORE(core_base, core_no, pkg_no) \ | ||
116 | (core_base + (pkg_no) * topo.num_cores_per_pkg + (core_no)) | ||
117 | #define GET_PKG(pkg_base, pkg_no) (pkg_base + pkg_no) | ||
118 | |||
119 | struct system_summary { | ||
120 | struct thread_data threads; | ||
121 | struct core_data cores; | ||
122 | struct pkg_data packages; | ||
123 | } sum, average; | ||
124 | |||
125 | |||
126 | struct topo_params { | ||
127 | int num_packages; | ||
128 | int num_cpus; | ||
129 | int num_cores; | ||
130 | int max_cpu_num; | ||
131 | int num_cores_per_pkg; | ||
132 | int num_threads_per_core; | ||
133 | } topo; | ||
134 | |||
135 | struct timeval tv_even, tv_odd, tv_delta; | ||
136 | |||
137 | void setup_all_buffers(void); | ||
138 | |||
139 | int cpu_is_not_present(int cpu) | ||
107 | { | 140 | { |
108 | CPU_SET_S(cpu, cpu_present_setsize, cpu_present_set); | 141 | return !CPU_ISSET_S(cpu, cpu_present_setsize, cpu_present_set); |
109 | return 0; | ||
110 | } | 142 | } |
111 | |||
112 | /* | 143 | /* |
113 | * cpu_mask_init(ncpus) | 144 | * run func(thread, core, package) in topology order |
114 | * | 145 | * skip non-present cpus |
115 | * allocate and clear cpu_mask | ||
116 | * set cpu_mask_size | ||
117 | */ | 146 | */ |
118 | void cpu_mask_init(int ncpus) | 147 | |
148 | int for_all_cpus(int (func)(struct thread_data *, struct core_data *, struct pkg_data *), | ||
149 | struct thread_data *thread_base, struct core_data *core_base, struct pkg_data *pkg_base) | ||
119 | { | 150 | { |
120 | cpu_mask = CPU_ALLOC(ncpus); | 151 | int retval, pkg_no, core_no, thread_no; |
121 | if (cpu_mask == NULL) { | ||
122 | perror("CPU_ALLOC"); | ||
123 | exit(3); | ||
124 | } | ||
125 | cpu_mask_size = CPU_ALLOC_SIZE(ncpus); | ||
126 | CPU_ZERO_S(cpu_mask_size, cpu_mask); | ||
127 | 152 | ||
128 | /* | 153 | for (pkg_no = 0; pkg_no < topo.num_packages; ++pkg_no) { |
129 | * Allocate and initialize cpu_present_set | 154 | for (core_no = 0; core_no < topo.num_cores_per_pkg; ++core_no) { |
130 | */ | 155 | for (thread_no = 0; thread_no < |
131 | cpu_present_set = CPU_ALLOC(ncpus); | 156 | topo.num_threads_per_core; ++thread_no) { |
132 | if (cpu_present_set == NULL) { | 157 | struct thread_data *t; |
133 | perror("CPU_ALLOC"); | 158 | struct core_data *c; |
134 | exit(3); | 159 | struct pkg_data *p; |
135 | } | ||
136 | cpu_present_setsize = CPU_ALLOC_SIZE(ncpus); | ||
137 | CPU_ZERO_S(cpu_present_setsize, cpu_present_set); | ||
138 | for_all_cpus(mark_cpu_present); | ||
139 | } | ||
140 | 160 | ||
141 | void cpu_mask_uninit() | 161 | t = GET_THREAD(thread_base, thread_no, core_no, pkg_no); |
142 | { | 162 | |
143 | CPU_FREE(cpu_mask); | 163 | if (cpu_is_not_present(t->cpu_id)) |
144 | cpu_mask = NULL; | 164 | continue; |
145 | cpu_mask_size = 0; | 165 | |
146 | CPU_FREE(cpu_present_set); | 166 | c = GET_CORE(core_base, core_no, pkg_no); |
147 | cpu_present_set = NULL; | 167 | p = GET_PKG(pkg_base, pkg_no); |
148 | cpu_present_setsize = 0; | 168 | |
169 | retval = func(t, c, p); | ||
170 | if (retval) | ||
171 | return retval; | ||
172 | } | ||
173 | } | ||
174 | } | ||
175 | return 0; | ||
149 | } | 176 | } |
150 | 177 | ||
151 | int cpu_migrate(int cpu) | 178 | int cpu_migrate(int cpu) |
152 | { | 179 | { |
153 | CPU_ZERO_S(cpu_mask_size, cpu_mask); | 180 | CPU_ZERO_S(cpu_affinity_setsize, cpu_affinity_set); |
154 | CPU_SET_S(cpu, cpu_mask_size, cpu_mask); | 181 | CPU_SET_S(cpu, cpu_affinity_setsize, cpu_affinity_set); |
155 | if (sched_setaffinity(0, cpu_mask_size, cpu_mask) == -1) | 182 | if (sched_setaffinity(0, cpu_affinity_setsize, cpu_affinity_set) == -1) |
156 | return -1; | 183 | return -1; |
157 | else | 184 | else |
158 | return 0; | 185 | return 0; |
@@ -181,67 +208,72 @@ int get_msr(int cpu, off_t offset, unsigned long long *msr) | |||
181 | void print_header(void) | 208 | void print_header(void) |
182 | { | 209 | { |
183 | if (show_pkg) | 210 | if (show_pkg) |
184 | fprintf(stderr, "pk"); | 211 | outp += sprintf(outp, "pk"); |
185 | if (show_pkg) | 212 | if (show_pkg) |
186 | fprintf(stderr, " "); | 213 | outp += sprintf(outp, " "); |
187 | if (show_core) | 214 | if (show_core) |
188 | fprintf(stderr, "cor"); | 215 | outp += sprintf(outp, "cor"); |
189 | if (show_cpu) | 216 | if (show_cpu) |
190 | fprintf(stderr, " CPU"); | 217 | outp += sprintf(outp, " CPU"); |
191 | if (show_pkg || show_core || show_cpu) | 218 | if (show_pkg || show_core || show_cpu) |
192 | fprintf(stderr, " "); | 219 | outp += sprintf(outp, " "); |
193 | if (do_nhm_cstates) | 220 | if (do_nhm_cstates) |
194 | fprintf(stderr, " %%c0"); | 221 | outp += sprintf(outp, " %%c0"); |
195 | if (has_aperf) | 222 | if (has_aperf) |
196 | fprintf(stderr, " GHz"); | 223 | outp += sprintf(outp, " GHz"); |
197 | fprintf(stderr, " TSC"); | 224 | outp += sprintf(outp, " TSC"); |
198 | if (do_nhm_cstates) | 225 | if (do_nhm_cstates) |
199 | fprintf(stderr, " %%c1"); | 226 | outp += sprintf(outp, " %%c1"); |
200 | if (do_nhm_cstates) | 227 | if (do_nhm_cstates) |
201 | fprintf(stderr, " %%c3"); | 228 | outp += sprintf(outp, " %%c3"); |
202 | if (do_nhm_cstates) | 229 | if (do_nhm_cstates) |
203 | fprintf(stderr, " %%c6"); | 230 | outp += sprintf(outp, " %%c6"); |
204 | if (do_snb_cstates) | 231 | if (do_snb_cstates) |
205 | fprintf(stderr, " %%c7"); | 232 | outp += sprintf(outp, " %%c7"); |
206 | if (do_snb_cstates) | 233 | if (do_snb_cstates) |
207 | fprintf(stderr, " %%pc2"); | 234 | outp += sprintf(outp, " %%pc2"); |
208 | if (do_nhm_cstates) | 235 | if (do_nhm_cstates) |
209 | fprintf(stderr, " %%pc3"); | 236 | outp += sprintf(outp, " %%pc3"); |
210 | if (do_nhm_cstates) | 237 | if (do_nhm_cstates) |
211 | fprintf(stderr, " %%pc6"); | 238 | outp += sprintf(outp, " %%pc6"); |
212 | if (do_snb_cstates) | 239 | if (do_snb_cstates) |
213 | fprintf(stderr, " %%pc7"); | 240 | outp += sprintf(outp, " %%pc7"); |
214 | if (extra_msr_offset) | 241 | if (extra_msr_offset) |
215 | fprintf(stderr, " MSR 0x%x ", extra_msr_offset); | 242 | outp += sprintf(outp, " MSR 0x%x ", extra_msr_offset); |
216 | 243 | ||
217 | putc('\n', stderr); | 244 | outp += sprintf(outp, "\n"); |
218 | } | 245 | } |
219 | 246 | ||
220 | void dump_cnt(struct counters *cnt) | 247 | int dump_counters(struct thread_data *t, struct core_data *c, |
248 | struct pkg_data *p) | ||
221 | { | 249 | { |
222 | if (!cnt) | 250 | fprintf(stderr, "t %p, c %p, p %p\n", t, c, p); |
223 | return; | 251 | |
224 | if (cnt->pkg) fprintf(stderr, "package: %d ", cnt->pkg); | 252 | if (t) { |
225 | if (cnt->core) fprintf(stderr, "core:: %d ", cnt->core); | 253 | fprintf(stderr, "CPU: %d flags 0x%x\n", t->cpu_id, t->flags); |
226 | if (cnt->cpu) fprintf(stderr, "CPU: %d ", cnt->cpu); | 254 | fprintf(stderr, "TSC: %016llX\n", t->tsc); |
227 | if (cnt->tsc) fprintf(stderr, "TSC: %016llX\n", cnt->tsc); | 255 | fprintf(stderr, "aperf: %016llX\n", t->aperf); |
228 | if (cnt->c3) fprintf(stderr, "c3: %016llX\n", cnt->c3); | 256 | fprintf(stderr, "mperf: %016llX\n", t->mperf); |
229 | if (cnt->c6) fprintf(stderr, "c6: %016llX\n", cnt->c6); | 257 | fprintf(stderr, "c1: %016llX\n", t->c1); |
230 | if (cnt->c7) fprintf(stderr, "c7: %016llX\n", cnt->c7); | 258 | fprintf(stderr, "msr0x%x: %016llX\n", |
231 | if (cnt->aperf) fprintf(stderr, "aperf: %016llX\n", cnt->aperf); | 259 | extra_msr_offset, t->extra_msr); |
232 | if (cnt->pc2) fprintf(stderr, "pc2: %016llX\n", cnt->pc2); | 260 | } |
233 | if (cnt->pc3) fprintf(stderr, "pc3: %016llX\n", cnt->pc3); | ||
234 | if (cnt->pc6) fprintf(stderr, "pc6: %016llX\n", cnt->pc6); | ||
235 | if (cnt->pc7) fprintf(stderr, "pc7: %016llX\n", cnt->pc7); | ||
236 | if (cnt->extra_msr) fprintf(stderr, "msr0x%x: %016llX\n", extra_msr_offset, cnt->extra_msr); | ||
237 | } | ||
238 | 261 | ||
239 | void dump_list(struct counters *cnt) | 262 | if (c) { |
240 | { | 263 | fprintf(stderr, "core: %d\n", c->core_id); |
241 | printf("dump_list 0x%p\n", cnt); | 264 | fprintf(stderr, "c3: %016llX\n", c->c3); |
265 | fprintf(stderr, "c6: %016llX\n", c->c6); | ||
266 | fprintf(stderr, "c7: %016llX\n", c->c7); | ||
267 | } | ||
242 | 268 | ||
243 | for (; cnt; cnt = cnt->next) | 269 | if (p) { |
244 | dump_cnt(cnt); | 270 | fprintf(stderr, "package: %d\n", p->package_id); |
271 | fprintf(stderr, "pc2: %016llX\n", p->pc2); | ||
272 | fprintf(stderr, "pc3: %016llX\n", p->pc3); | ||
273 | fprintf(stderr, "pc6: %016llX\n", p->pc6); | ||
274 | fprintf(stderr, "pc7: %016llX\n", p->pc7); | ||
275 | } | ||
276 | return 0; | ||
245 | } | 277 | } |
246 | 278 | ||
247 | /* | 279 | /* |
@@ -253,321 +285,389 @@ void dump_list(struct counters *cnt) | |||
253 | * TSC: "TSC" 3 columns %3.2 | 285 | * TSC: "TSC" 3 columns %3.2 |
254 | * percentage " %pc3" %6.2 | 286 | * percentage " %pc3" %6.2 |
255 | */ | 287 | */ |
256 | void print_cnt(struct counters *p) | 288 | int format_counters(struct thread_data *t, struct core_data *c, |
289 | struct pkg_data *p) | ||
257 | { | 290 | { |
258 | double interval_float; | 291 | double interval_float; |
259 | 292 | ||
293 | /* if showing only 1st thread in core and this isn't one, bail out */ | ||
294 | if (show_core_only && !(t->flags & CPU_IS_FIRST_THREAD_IN_CORE)) | ||
295 | return 0; | ||
296 | |||
297 | /* if showing only 1st thread in pkg and this isn't one, bail out */ | ||
298 | if (show_pkg_only && !(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) | ||
299 | return 0; | ||
300 | |||
260 | interval_float = tv_delta.tv_sec + tv_delta.tv_usec/1000000.0; | 301 | interval_float = tv_delta.tv_sec + tv_delta.tv_usec/1000000.0; |
261 | 302 | ||
262 | /* topology columns, print blanks on 1st (average) line */ | 303 | /* topo columns, print blanks on 1st (average) line */ |
263 | if (p == cnt_average) { | 304 | if (t == &average.threads) { |
264 | if (show_pkg) | 305 | if (show_pkg) |
265 | fprintf(stderr, " "); | 306 | outp += sprintf(outp, " "); |
266 | if (show_pkg && show_core) | 307 | if (show_pkg && show_core) |
267 | fprintf(stderr, " "); | 308 | outp += sprintf(outp, " "); |
268 | if (show_core) | 309 | if (show_core) |
269 | fprintf(stderr, " "); | 310 | outp += sprintf(outp, " "); |
270 | if (show_cpu) | 311 | if (show_cpu) |
271 | fprintf(stderr, " " " "); | 312 | outp += sprintf(outp, " " " "); |
272 | } else { | 313 | } else { |
273 | if (show_pkg) | 314 | if (show_pkg) { |
274 | fprintf(stderr, "%2d", p->pkg); | 315 | if (p) |
316 | outp += sprintf(outp, "%2d", p->package_id); | ||
317 | else | ||
318 | outp += sprintf(outp, " "); | ||
319 | } | ||
275 | if (show_pkg && show_core) | 320 | if (show_pkg && show_core) |
276 | fprintf(stderr, " "); | 321 | outp += sprintf(outp, " "); |
277 | if (show_core) | 322 | if (show_core) { |
278 | fprintf(stderr, "%3d", p->core); | 323 | if (c) |
324 | outp += sprintf(outp, "%3d", c->core_id); | ||
325 | else | ||
326 | outp += sprintf(outp, " "); | ||
327 | } | ||
279 | if (show_cpu) | 328 | if (show_cpu) |
280 | fprintf(stderr, " %3d", p->cpu); | 329 | outp += sprintf(outp, " %3d", t->cpu_id); |
281 | } | 330 | } |
282 | 331 | ||
283 | /* %c0 */ | 332 | /* %c0 */ |
284 | if (do_nhm_cstates) { | 333 | if (do_nhm_cstates) { |
285 | if (show_pkg || show_core || show_cpu) | 334 | if (show_pkg || show_core || show_cpu) |
286 | fprintf(stderr, " "); | 335 | outp += sprintf(outp, " "); |
287 | if (!skip_c0) | 336 | if (!skip_c0) |
288 | fprintf(stderr, "%6.2f", 100.0 * p->mperf/p->tsc); | 337 | outp += sprintf(outp, "%6.2f", 100.0 * t->mperf/t->tsc); |
289 | else | 338 | else |
290 | fprintf(stderr, " ****"); | 339 | outp += sprintf(outp, " ****"); |
291 | } | 340 | } |
292 | 341 | ||
293 | /* GHz */ | 342 | /* GHz */ |
294 | if (has_aperf) { | 343 | if (has_aperf) { |
295 | if (!aperf_mperf_unstable) { | 344 | if (!aperf_mperf_unstable) { |
296 | fprintf(stderr, " %3.2f", | 345 | outp += sprintf(outp, " %3.2f", |
297 | 1.0 * p->tsc / units * p->aperf / | 346 | 1.0 * t->tsc / units * t->aperf / |
298 | p->mperf / interval_float); | 347 | t->mperf / interval_float); |
299 | } else { | 348 | } else { |
300 | if (p->aperf > p->tsc || p->mperf > p->tsc) { | 349 | if (t->aperf > t->tsc || t->mperf > t->tsc) { |
301 | fprintf(stderr, " ***"); | 350 | outp += sprintf(outp, " ***"); |
302 | } else { | 351 | } else { |
303 | fprintf(stderr, "%3.1f*", | 352 | outp += sprintf(outp, "%3.1f*", |
304 | 1.0 * p->tsc / | 353 | 1.0 * t->tsc / |
305 | units * p->aperf / | 354 | units * t->aperf / |
306 | p->mperf / interval_float); | 355 | t->mperf / interval_float); |
307 | } | 356 | } |
308 | } | 357 | } |
309 | } | 358 | } |
310 | 359 | ||
311 | /* TSC */ | 360 | /* TSC */ |
312 | fprintf(stderr, "%5.2f", 1.0 * p->tsc/units/interval_float); | 361 | outp += sprintf(outp, "%5.2f", 1.0 * t->tsc/units/interval_float); |
313 | 362 | ||
314 | if (do_nhm_cstates) { | 363 | if (do_nhm_cstates) { |
315 | if (!skip_c1) | 364 | if (!skip_c1) |
316 | fprintf(stderr, " %6.2f", 100.0 * p->c1/p->tsc); | 365 | outp += sprintf(outp, " %6.2f", 100.0 * t->c1/t->tsc); |
317 | else | 366 | else |
318 | fprintf(stderr, " ****"); | 367 | outp += sprintf(outp, " ****"); |
319 | } | 368 | } |
369 | |||
370 | /* print per-core data only for 1st thread in core */ | ||
371 | if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE)) | ||
372 | goto done; | ||
373 | |||
320 | if (do_nhm_cstates) | 374 | if (do_nhm_cstates) |
321 | fprintf(stderr, " %6.2f", 100.0 * p->c3/p->tsc); | 375 | outp += sprintf(outp, " %6.2f", 100.0 * c->c3/t->tsc); |
322 | if (do_nhm_cstates) | 376 | if (do_nhm_cstates) |
323 | fprintf(stderr, " %6.2f", 100.0 * p->c6/p->tsc); | 377 | outp += sprintf(outp, " %6.2f", 100.0 * c->c6/t->tsc); |
324 | if (do_snb_cstates) | 378 | if (do_snb_cstates) |
325 | fprintf(stderr, " %6.2f", 100.0 * p->c7/p->tsc); | 379 | outp += sprintf(outp, " %6.2f", 100.0 * c->c7/t->tsc); |
380 | |||
381 | /* print per-package data only for 1st core in package */ | ||
382 | if (!(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) | ||
383 | goto done; | ||
384 | |||
326 | if (do_snb_cstates) | 385 | if (do_snb_cstates) |
327 | fprintf(stderr, " %6.2f", 100.0 * p->pc2/p->tsc); | 386 | outp += sprintf(outp, " %6.2f", 100.0 * p->pc2/t->tsc); |
328 | if (do_nhm_cstates) | 387 | if (do_nhm_cstates) |
329 | fprintf(stderr, " %6.2f", 100.0 * p->pc3/p->tsc); | 388 | outp += sprintf(outp, " %6.2f", 100.0 * p->pc3/t->tsc); |
330 | if (do_nhm_cstates) | 389 | if (do_nhm_cstates) |
331 | fprintf(stderr, " %6.2f", 100.0 * p->pc6/p->tsc); | 390 | outp += sprintf(outp, " %6.2f", 100.0 * p->pc6/t->tsc); |
332 | if (do_snb_cstates) | 391 | if (do_snb_cstates) |
333 | fprintf(stderr, " %6.2f", 100.0 * p->pc7/p->tsc); | 392 | outp += sprintf(outp, " %6.2f", 100.0 * p->pc7/t->tsc); |
393 | done: | ||
334 | if (extra_msr_offset) | 394 | if (extra_msr_offset) |
335 | fprintf(stderr, " 0x%016llx", p->extra_msr); | 395 | outp += sprintf(outp, " 0x%016llx", t->extra_msr); |
336 | putc('\n', stderr); | 396 | outp += sprintf(outp, "\n"); |
397 | |||
398 | return 0; | ||
337 | } | 399 | } |
338 | 400 | ||
339 | void print_counters(struct counters *counters) | 401 | void flush_stdout() |
402 | { | ||
403 | fputs(output_buffer, stdout); | ||
404 | outp = output_buffer; | ||
405 | } | ||
406 | void flush_stderr() | ||
407 | { | ||
408 | fputs(output_buffer, stderr); | ||
409 | outp = output_buffer; | ||
410 | } | ||
411 | void format_all_counters(struct thread_data *t, struct core_data *c, struct pkg_data *p) | ||
340 | { | 412 | { |
341 | struct counters *cnt; | ||
342 | static int printed; | 413 | static int printed; |
343 | 414 | ||
344 | |||
345 | if (!printed || !summary_only) | 415 | if (!printed || !summary_only) |
346 | print_header(); | 416 | print_header(); |
347 | 417 | ||
348 | if (num_cpus > 1) | 418 | if (topo.num_cpus > 1) |
349 | print_cnt(cnt_average); | 419 | format_counters(&average.threads, &average.cores, |
420 | &average.packages); | ||
350 | 421 | ||
351 | printed = 1; | 422 | printed = 1; |
352 | 423 | ||
353 | if (summary_only) | 424 | if (summary_only) |
354 | return; | 425 | return; |
355 | 426 | ||
356 | for (cnt = counters; cnt != NULL; cnt = cnt->next) | 427 | for_all_cpus(format_counters, t, c, p); |
357 | print_cnt(cnt); | ||
358 | |||
359 | } | 428 | } |
360 | 429 | ||
361 | #define SUBTRACT_COUNTER(after, before, delta) (delta = (after - before), (before > after)) | 430 | void |
431 | delta_package(struct pkg_data *new, struct pkg_data *old) | ||
432 | { | ||
433 | old->pc2 = new->pc2 - old->pc2; | ||
434 | old->pc3 = new->pc3 - old->pc3; | ||
435 | old->pc6 = new->pc6 - old->pc6; | ||
436 | old->pc7 = new->pc7 - old->pc7; | ||
437 | } | ||
362 | 438 | ||
363 | int compute_delta(struct counters *after, | 439 | void |
364 | struct counters *before, struct counters *delta) | 440 | delta_core(struct core_data *new, struct core_data *old) |
365 | { | 441 | { |
366 | int errors = 0; | 442 | old->c3 = new->c3 - old->c3; |
367 | int perf_err = 0; | 443 | old->c6 = new->c6 - old->c6; |
444 | old->c7 = new->c7 - old->c7; | ||
445 | } | ||
368 | 446 | ||
369 | skip_c0 = skip_c1 = 0; | 447 | /* |
448 | * old = new - old | ||
449 | */ | ||
450 | void | ||
451 | delta_thread(struct thread_data *new, struct thread_data *old, | ||
452 | struct core_data *core_delta) | ||
453 | { | ||
454 | old->tsc = new->tsc - old->tsc; | ||
455 | |||
456 | /* check for TSC < 1 Mcycles over interval */ | ||
457 | if (old->tsc < (1000 * 1000)) { | ||
458 | fprintf(stderr, "Insanely slow TSC rate, TSC stops in idle?\n"); | ||
459 | fprintf(stderr, "You can disable all c-states by booting with \"idle=poll\"\n"); | ||
460 | fprintf(stderr, "or just the deep ones with \"processor.max_cstate=1\"\n"); | ||
461 | exit(-3); | ||
462 | } | ||
370 | 463 | ||
371 | for ( ; after && before && delta; | 464 | old->c1 = new->c1 - old->c1; |
372 | after = after->next, before = before->next, delta = delta->next) { | ||
373 | if (before->cpu != after->cpu) { | ||
374 | printf("cpu configuration changed: %d != %d\n", | ||
375 | before->cpu, after->cpu); | ||
376 | return -1; | ||
377 | } | ||
378 | 465 | ||
379 | if (SUBTRACT_COUNTER(after->tsc, before->tsc, delta->tsc)) { | 466 | if ((new->aperf > old->aperf) && (new->mperf > old->mperf)) { |
380 | fprintf(stderr, "cpu%d TSC went backwards %llX to %llX\n", | 467 | old->aperf = new->aperf - old->aperf; |
381 | before->cpu, before->tsc, after->tsc); | 468 | old->mperf = new->mperf - old->mperf; |
382 | errors++; | 469 | } else { |
383 | } | ||
384 | /* check for TSC < 1 Mcycles over interval */ | ||
385 | if (delta->tsc < (1000 * 1000)) { | ||
386 | fprintf(stderr, "Insanely slow TSC rate," | ||
387 | " TSC stops in idle?\n"); | ||
388 | fprintf(stderr, "You can disable all c-states" | ||
389 | " by booting with \"idle=poll\"\n"); | ||
390 | fprintf(stderr, "or just the deep ones with" | ||
391 | " \"processor.max_cstate=1\"\n"); | ||
392 | exit(-3); | ||
393 | } | ||
394 | if (SUBTRACT_COUNTER(after->c3, before->c3, delta->c3)) { | ||
395 | fprintf(stderr, "cpu%d c3 counter went backwards %llX to %llX\n", | ||
396 | before->cpu, before->c3, after->c3); | ||
397 | errors++; | ||
398 | } | ||
399 | if (SUBTRACT_COUNTER(after->c6, before->c6, delta->c6)) { | ||
400 | fprintf(stderr, "cpu%d c6 counter went backwards %llX to %llX\n", | ||
401 | before->cpu, before->c6, after->c6); | ||
402 | errors++; | ||
403 | } | ||
404 | if (SUBTRACT_COUNTER(after->c7, before->c7, delta->c7)) { | ||
405 | fprintf(stderr, "cpu%d c7 counter went backwards %llX to %llX\n", | ||
406 | before->cpu, before->c7, after->c7); | ||
407 | errors++; | ||
408 | } | ||
409 | if (SUBTRACT_COUNTER(after->pc2, before->pc2, delta->pc2)) { | ||
410 | fprintf(stderr, "cpu%d pc2 counter went backwards %llX to %llX\n", | ||
411 | before->cpu, before->pc2, after->pc2); | ||
412 | errors++; | ||
413 | } | ||
414 | if (SUBTRACT_COUNTER(after->pc3, before->pc3, delta->pc3)) { | ||
415 | fprintf(stderr, "cpu%d pc3 counter went backwards %llX to %llX\n", | ||
416 | before->cpu, before->pc3, after->pc3); | ||
417 | errors++; | ||
418 | } | ||
419 | if (SUBTRACT_COUNTER(after->pc6, before->pc6, delta->pc6)) { | ||
420 | fprintf(stderr, "cpu%d pc6 counter went backwards %llX to %llX\n", | ||
421 | before->cpu, before->pc6, after->pc6); | ||
422 | errors++; | ||
423 | } | ||
424 | if (SUBTRACT_COUNTER(after->pc7, before->pc7, delta->pc7)) { | ||
425 | fprintf(stderr, "cpu%d pc7 counter went backwards %llX to %llX\n", | ||
426 | before->cpu, before->pc7, after->pc7); | ||
427 | errors++; | ||
428 | } | ||
429 | 470 | ||
430 | perf_err = SUBTRACT_COUNTER(after->aperf, before->aperf, delta->aperf); | 471 | if (!aperf_mperf_unstable) { |
431 | if (perf_err) { | 472 | fprintf(stderr, "%s: APERF or MPERF went backwards *\n", progname); |
432 | fprintf(stderr, "cpu%d aperf counter went backwards %llX to %llX\n", | 473 | fprintf(stderr, "* Frequency results do not cover entire interval *\n"); |
433 | before->cpu, before->aperf, after->aperf); | 474 | fprintf(stderr, "* fix this by running Linux-2.6.30 or later *\n"); |
434 | } | ||
435 | perf_err |= SUBTRACT_COUNTER(after->mperf, before->mperf, delta->mperf); | ||
436 | if (perf_err) { | ||
437 | fprintf(stderr, "cpu%d mperf counter went backwards %llX to %llX\n", | ||
438 | before->cpu, before->mperf, after->mperf); | ||
439 | } | ||
440 | if (perf_err) { | ||
441 | if (!aperf_mperf_unstable) { | ||
442 | fprintf(stderr, "%s: APERF or MPERF went backwards *\n", progname); | ||
443 | fprintf(stderr, "* Frequency results do not cover entire interval *\n"); | ||
444 | fprintf(stderr, "* fix this by running Linux-2.6.30 or later *\n"); | ||
445 | 475 | ||
446 | aperf_mperf_unstable = 1; | 476 | aperf_mperf_unstable = 1; |
447 | } | ||
448 | /* | ||
449 | * mperf delta is likely a huge "positive" number | ||
450 | * can not use it for calculating c0 time | ||
451 | */ | ||
452 | skip_c0 = 1; | ||
453 | skip_c1 = 1; | ||
454 | } | 477 | } |
455 | |||
456 | /* | 478 | /* |
457 | * As mperf and tsc collection are not atomic, | 479 | * mperf delta is likely a huge "positive" number |
458 | * it is possible for mperf's non-halted cycles | 480 | * can not use it for calculating c0 time |
459 | * to exceed TSC's all cycles: show c1 = 0% in that case. | ||
460 | */ | 481 | */ |
461 | if (delta->mperf > delta->tsc) | 482 | skip_c0 = 1; |
462 | delta->c1 = 0; | 483 | skip_c1 = 1; |
463 | else /* normal case, derive c1 */ | 484 | } |
464 | delta->c1 = delta->tsc - delta->mperf | ||
465 | - delta->c3 - delta->c6 - delta->c7; | ||
466 | 485 | ||
467 | if (delta->mperf == 0) | ||
468 | delta->mperf = 1; /* divide by 0 protection */ | ||
469 | 486 | ||
470 | /* | 487 | /* |
471 | * for "extra msr", just copy the latest w/o subtracting | 488 | * As counter collection is not atomic, |
472 | */ | 489 | * it is possible for mperf's non-halted cycles + idle states |
473 | delta->extra_msr = after->extra_msr; | 490 | * to exceed TSC's all cycles: show c1 = 0% in that case. |
474 | if (errors) { | 491 | */ |
475 | fprintf(stderr, "ERROR cpu%d before:\n", before->cpu); | 492 | if ((old->mperf + core_delta->c3 + core_delta->c6 + core_delta->c7) > old->tsc) |
476 | dump_cnt(before); | 493 | old->c1 = 0; |
477 | fprintf(stderr, "ERROR cpu%d after:\n", before->cpu); | 494 | else { |
478 | dump_cnt(after); | 495 | /* normal case, derive c1 */ |
479 | errors = 0; | 496 | old->c1 = old->tsc - old->mperf - core_delta->c3 |
480 | } | 497 | - core_delta->c6 - core_delta->c7; |
481 | } | 498 | } |
499 | |||
500 | if (old->mperf == 0) { | ||
501 | if (verbose > 1) fprintf(stderr, "cpu%d MPERF 0!\n", old->cpu_id); | ||
502 | old->mperf = 1; /* divide by 0 protection */ | ||
503 | } | ||
504 | |||
505 | /* | ||
506 | * for "extra msr", just copy the latest w/o subtracting | ||
507 | */ | ||
508 | old->extra_msr = new->extra_msr; | ||
509 | } | ||
510 | |||
511 | int delta_cpu(struct thread_data *t, struct core_data *c, | ||
512 | struct pkg_data *p, struct thread_data *t2, | ||
513 | struct core_data *c2, struct pkg_data *p2) | ||
514 | { | ||
515 | /* calculate core delta only for 1st thread in core */ | ||
516 | if (t->flags & CPU_IS_FIRST_THREAD_IN_CORE) | ||
517 | delta_core(c, c2); | ||
518 | |||
519 | /* always calculate thread delta */ | ||
520 | delta_thread(t, t2, c2); /* c2 is core delta */ | ||
521 | |||
522 | /* calculate package delta only for 1st core in package */ | ||
523 | if (t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE) | ||
524 | delta_package(p, p2); | ||
525 | |||
482 | return 0; | 526 | return 0; |
483 | } | 527 | } |
484 | 528 | ||
485 | void compute_average(struct counters *delta, struct counters *avg) | 529 | void clear_counters(struct thread_data *t, struct core_data *c, struct pkg_data *p) |
530 | { | ||
531 | t->tsc = 0; | ||
532 | t->aperf = 0; | ||
533 | t->mperf = 0; | ||
534 | t->c1 = 0; | ||
535 | |||
536 | /* tells format_counters to dump all fields from this set */ | ||
537 | t->flags = CPU_IS_FIRST_THREAD_IN_CORE | CPU_IS_FIRST_CORE_IN_PACKAGE; | ||
538 | |||
539 | c->c3 = 0; | ||
540 | c->c6 = 0; | ||
541 | c->c7 = 0; | ||
542 | |||
543 | p->pc2 = 0; | ||
544 | p->pc3 = 0; | ||
545 | p->pc6 = 0; | ||
546 | p->pc7 = 0; | ||
547 | } | ||
548 | int sum_counters(struct thread_data *t, struct core_data *c, | ||
549 | struct pkg_data *p) | ||
486 | { | 550 | { |
487 | struct counters *sum; | 551 | average.threads.tsc += t->tsc; |
552 | average.threads.aperf += t->aperf; | ||
553 | average.threads.mperf += t->mperf; | ||
554 | average.threads.c1 += t->c1; | ||
488 | 555 | ||
489 | sum = calloc(1, sizeof(struct counters)); | 556 | /* sum per-core values only for 1st thread in core */ |
490 | if (sum == NULL) { | 557 | if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE)) |
491 | perror("calloc sum"); | 558 | return 0; |
492 | exit(1); | ||
493 | } | ||
494 | 559 | ||
495 | for (; delta; delta = delta->next) { | 560 | average.cores.c3 += c->c3; |
496 | sum->tsc += delta->tsc; | 561 | average.cores.c6 += c->c6; |
497 | sum->c1 += delta->c1; | 562 | average.cores.c7 += c->c7; |
498 | sum->c3 += delta->c3; | 563 | |
499 | sum->c6 += delta->c6; | 564 | /* sum per-pkg values only for 1st core in pkg */ |
500 | sum->c7 += delta->c7; | 565 | if (!(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) |
501 | sum->aperf += delta->aperf; | 566 | return 0; |
502 | sum->mperf += delta->mperf; | 567 | |
503 | sum->pc2 += delta->pc2; | 568 | average.packages.pc2 += p->pc2; |
504 | sum->pc3 += delta->pc3; | 569 | average.packages.pc3 += p->pc3; |
505 | sum->pc6 += delta->pc6; | 570 | average.packages.pc6 += p->pc6; |
506 | sum->pc7 += delta->pc7; | 571 | average.packages.pc7 += p->pc7; |
507 | } | 572 | |
508 | avg->tsc = sum->tsc/num_cpus; | 573 | return 0; |
509 | avg->c1 = sum->c1/num_cpus; | 574 | } |
510 | avg->c3 = sum->c3/num_cpus; | 575 | /* |
511 | avg->c6 = sum->c6/num_cpus; | 576 | * sum the counters for all cpus in the system |
512 | avg->c7 = sum->c7/num_cpus; | 577 | * compute the weighted average |
513 | avg->aperf = sum->aperf/num_cpus; | 578 | */ |
514 | avg->mperf = sum->mperf/num_cpus; | 579 | void compute_average(struct thread_data *t, struct core_data *c, |
515 | avg->pc2 = sum->pc2/num_cpus; | 580 | struct pkg_data *p) |
516 | avg->pc3 = sum->pc3/num_cpus; | 581 | { |
517 | avg->pc6 = sum->pc6/num_cpus; | 582 | clear_counters(&average.threads, &average.cores, &average.packages); |
518 | avg->pc7 = sum->pc7/num_cpus; | 583 | |
519 | 584 | for_all_cpus(sum_counters, t, c, p); | |
520 | free(sum); | 585 | |
586 | average.threads.tsc /= topo.num_cpus; | ||
587 | average.threads.aperf /= topo.num_cpus; | ||
588 | average.threads.mperf /= topo.num_cpus; | ||
589 | average.threads.c1 /= topo.num_cpus; | ||
590 | |||
591 | average.cores.c3 /= topo.num_cores; | ||
592 | average.cores.c6 /= topo.num_cores; | ||
593 | average.cores.c7 /= topo.num_cores; | ||
594 | |||
595 | average.packages.pc2 /= topo.num_packages; | ||
596 | average.packages.pc3 /= topo.num_packages; | ||
597 | average.packages.pc6 /= topo.num_packages; | ||
598 | average.packages.pc7 /= topo.num_packages; | ||
521 | } | 599 | } |
522 | 600 | ||
523 | int get_counters(struct counters *cnt) | 601 | static unsigned long long rdtsc(void) |
524 | { | 602 | { |
525 | for ( ; cnt; cnt = cnt->next) { | 603 | unsigned int low, high; |
526 | 604 | ||
527 | if (cpu_migrate(cnt->cpu)) | 605 | asm volatile("rdtsc" : "=a" (low), "=d" (high)); |
528 | return -1; | ||
529 | 606 | ||
530 | if (get_msr(cnt->cpu, MSR_TSC, &cnt->tsc)) | 607 | return low | ((unsigned long long)high) << 32; |
531 | return -1; | 608 | } |
532 | 609 | ||
533 | if (has_aperf) { | ||
534 | if (get_msr(cnt->cpu, MSR_APERF, &cnt->aperf)) | ||
535 | return -1; | ||
536 | if (get_msr(cnt->cpu, MSR_MPERF, &cnt->mperf)) | ||
537 | return -1; | ||
538 | } | ||
539 | 610 | ||
540 | if (do_nhm_cstates) { | 611 | /* |
541 | if (get_msr(cnt->cpu, MSR_CORE_C3_RESIDENCY, &cnt->c3)) | 612 | * get_counters(...) |
542 | return -1; | 613 | * migrate to cpu |
543 | if (get_msr(cnt->cpu, MSR_CORE_C6_RESIDENCY, &cnt->c6)) | 614 | * acquire and record local counters for that cpu |
544 | return -1; | 615 | */ |
545 | } | 616 | int get_counters(struct thread_data *t, struct core_data *c, struct pkg_data *p) |
617 | { | ||
618 | int cpu = t->cpu_id; | ||
546 | 619 | ||
547 | if (do_snb_cstates) | 620 | if (cpu_migrate(cpu)) |
548 | if (get_msr(cnt->cpu, MSR_CORE_C7_RESIDENCY, &cnt->c7)) | 621 | return -1; |
549 | return -1; | ||
550 | 622 | ||
551 | if (do_nhm_cstates) { | 623 | t->tsc = rdtsc(); /* we are running on local CPU of interest */ |
552 | if (get_msr(cnt->cpu, MSR_PKG_C3_RESIDENCY, &cnt->pc3)) | 624 | |
553 | return -1; | 625 | if (has_aperf) { |
554 | if (get_msr(cnt->cpu, MSR_PKG_C6_RESIDENCY, &cnt->pc6)) | 626 | if (get_msr(cpu, MSR_APERF, &t->aperf)) |
555 | return -1; | 627 | return -3; |
556 | } | 628 | if (get_msr(cpu, MSR_MPERF, &t->mperf)) |
557 | if (do_snb_cstates) { | 629 | return -4; |
558 | if (get_msr(cnt->cpu, MSR_PKG_C2_RESIDENCY, &cnt->pc2)) | 630 | } |
559 | return -1; | 631 | |
560 | if (get_msr(cnt->cpu, MSR_PKG_C7_RESIDENCY, &cnt->pc7)) | 632 | if (extra_msr_offset) |
561 | return -1; | 633 | if (get_msr(cpu, extra_msr_offset, &t->extra_msr)) |
562 | } | 634 | return -5; |
563 | if (extra_msr_offset) | 635 | |
564 | if (get_msr(cnt->cpu, extra_msr_offset, &cnt->extra_msr)) | 636 | /* collect core counters only for 1st thread in core */ |
565 | return -1; | 637 | if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE)) |
638 | return 0; | ||
639 | |||
640 | if (do_nhm_cstates) { | ||
641 | if (get_msr(cpu, MSR_CORE_C3_RESIDENCY, &c->c3)) | ||
642 | return -6; | ||
643 | if (get_msr(cpu, MSR_CORE_C6_RESIDENCY, &c->c6)) | ||
644 | return -7; | ||
645 | } | ||
646 | |||
647 | if (do_snb_cstates) | ||
648 | if (get_msr(cpu, MSR_CORE_C7_RESIDENCY, &c->c7)) | ||
649 | return -8; | ||
650 | |||
651 | /* collect package counters only for 1st core in package */ | ||
652 | if (!(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) | ||
653 | return 0; | ||
654 | |||
655 | if (do_nhm_cstates) { | ||
656 | if (get_msr(cpu, MSR_PKG_C3_RESIDENCY, &p->pc3)) | ||
657 | return -9; | ||
658 | if (get_msr(cpu, MSR_PKG_C6_RESIDENCY, &p->pc6)) | ||
659 | return -10; | ||
660 | } | ||
661 | if (do_snb_cstates) { | ||
662 | if (get_msr(cpu, MSR_PKG_C2_RESIDENCY, &p->pc2)) | ||
663 | return -11; | ||
664 | if (get_msr(cpu, MSR_PKG_C7_RESIDENCY, &p->pc7)) | ||
665 | return -12; | ||
566 | } | 666 | } |
567 | return 0; | 667 | return 0; |
568 | } | 668 | } |
569 | 669 | ||
570 | void print_nehalem_info(void) | 670 | void print_verbose_header(void) |
571 | { | 671 | { |
572 | unsigned long long msr; | 672 | unsigned long long msr; |
573 | unsigned int ratio; | 673 | unsigned int ratio; |
@@ -615,143 +715,82 @@ void print_nehalem_info(void) | |||
615 | 715 | ||
616 | } | 716 | } |
617 | 717 | ||
618 | void free_counter_list(struct counters *list) | 718 | void free_all_buffers(void) |
619 | { | 719 | { |
620 | struct counters *p; | 720 | CPU_FREE(cpu_present_set); |
721 | cpu_present_set = NULL; | ||
722 | cpu_present_set = 0; | ||
621 | 723 | ||
622 | for (p = list; p; ) { | 724 | CPU_FREE(cpu_affinity_set); |
623 | struct counters *free_me; | 725 | cpu_affinity_set = NULL; |
726 | cpu_affinity_setsize = 0; | ||
624 | 727 | ||
625 | free_me = p; | 728 | free(thread_even); |
626 | p = p->next; | 729 | free(core_even); |
627 | free(free_me); | 730 | free(package_even); |
628 | } | ||
629 | } | ||
630 | 731 | ||
631 | void free_all_counters(void) | 732 | thread_even = NULL; |
632 | { | 733 | core_even = NULL; |
633 | free_counter_list(cnt_even); | 734 | package_even = NULL; |
634 | cnt_even = NULL; | ||
635 | 735 | ||
636 | free_counter_list(cnt_odd); | 736 | free(thread_odd); |
637 | cnt_odd = NULL; | 737 | free(core_odd); |
738 | free(package_odd); | ||
638 | 739 | ||
639 | free_counter_list(cnt_delta); | 740 | thread_odd = NULL; |
640 | cnt_delta = NULL; | 741 | core_odd = NULL; |
742 | package_odd = NULL; | ||
641 | 743 | ||
642 | free_counter_list(cnt_average); | 744 | free(output_buffer); |
643 | cnt_average = NULL; | 745 | output_buffer = NULL; |
746 | outp = NULL; | ||
644 | } | 747 | } |
645 | 748 | ||
646 | void insert_counters(struct counters **list, | 749 | /* |
647 | struct counters *new) | 750 | * cpu_is_first_sibling_in_core(cpu) |
751 | * return 1 if given CPU is 1st HT sibling in the core | ||
752 | */ | ||
753 | int cpu_is_first_sibling_in_core(int cpu) | ||
648 | { | 754 | { |
649 | struct counters *prev; | 755 | char path[64]; |
650 | 756 | FILE *filep; | |
651 | /* | 757 | int first_cpu; |
652 | * list was empty | ||
653 | */ | ||
654 | if (*list == NULL) { | ||
655 | new->next = *list; | ||
656 | *list = new; | ||
657 | return; | ||
658 | } | ||
659 | |||
660 | if (!summary_only) | ||
661 | show_cpu = 1; /* there is more than one CPU */ | ||
662 | |||
663 | /* | ||
664 | * insert on front of list. | ||
665 | * It is sorted by ascending package#, core#, cpu# | ||
666 | */ | ||
667 | if (((*list)->pkg > new->pkg) || | ||
668 | (((*list)->pkg == new->pkg) && ((*list)->core > new->core)) || | ||
669 | (((*list)->pkg == new->pkg) && ((*list)->core == new->core) && ((*list)->cpu > new->cpu))) { | ||
670 | new->next = *list; | ||
671 | *list = new; | ||
672 | return; | ||
673 | } | ||
674 | |||
675 | prev = *list; | ||
676 | |||
677 | while (prev->next && (prev->next->pkg < new->pkg)) { | ||
678 | prev = prev->next; | ||
679 | if (!summary_only) | ||
680 | show_pkg = 1; /* there is more than 1 package */ | ||
681 | } | ||
682 | |||
683 | while (prev->next && (prev->next->pkg == new->pkg) | ||
684 | && (prev->next->core < new->core)) { | ||
685 | prev = prev->next; | ||
686 | if (!summary_only) | ||
687 | show_core = 1; /* there is more than 1 core */ | ||
688 | } | ||
689 | 758 | ||
690 | while (prev->next && (prev->next->pkg == new->pkg) | 759 | sprintf(path, "/sys/devices/system/cpu/cpu%d/topology/thread_siblings_list", cpu); |
691 | && (prev->next->core == new->core) | 760 | filep = fopen(path, "r"); |
692 | && (prev->next->cpu < new->cpu)) { | 761 | if (filep == NULL) { |
693 | prev = prev->next; | 762 | perror(path); |
763 | exit(1); | ||
694 | } | 764 | } |
695 | 765 | fscanf(filep, "%d", &first_cpu); | |
696 | /* | 766 | fclose(filep); |
697 | * insert after "prev" | 767 | return (cpu == first_cpu); |
698 | */ | ||
699 | new->next = prev->next; | ||
700 | prev->next = new; | ||
701 | } | 768 | } |
702 | 769 | ||
703 | void alloc_new_counters(int pkg, int core, int cpu) | 770 | /* |
771 | * cpu_is_first_core_in_package(cpu) | ||
772 | * return 1 if given CPU is 1st core in package | ||
773 | */ | ||
774 | int cpu_is_first_core_in_package(int cpu) | ||
704 | { | 775 | { |
705 | struct counters *new; | 776 | char path[64]; |
706 | 777 | FILE *filep; | |
707 | if (verbose > 1) | 778 | int first_cpu; |
708 | printf("pkg%d core%d, cpu%d\n", pkg, core, cpu); | ||
709 | |||
710 | new = (struct counters *)calloc(1, sizeof(struct counters)); | ||
711 | if (new == NULL) { | ||
712 | perror("calloc"); | ||
713 | exit(1); | ||
714 | } | ||
715 | new->pkg = pkg; | ||
716 | new->core = core; | ||
717 | new->cpu = cpu; | ||
718 | insert_counters(&cnt_odd, new); | ||
719 | |||
720 | new = (struct counters *)calloc(1, | ||
721 | sizeof(struct counters)); | ||
722 | if (new == NULL) { | ||
723 | perror("calloc"); | ||
724 | exit(1); | ||
725 | } | ||
726 | new->pkg = pkg; | ||
727 | new->core = core; | ||
728 | new->cpu = cpu; | ||
729 | insert_counters(&cnt_even, new); | ||
730 | |||
731 | new = (struct counters *)calloc(1, sizeof(struct counters)); | ||
732 | if (new == NULL) { | ||
733 | perror("calloc"); | ||
734 | exit(1); | ||
735 | } | ||
736 | new->pkg = pkg; | ||
737 | new->core = core; | ||
738 | new->cpu = cpu; | ||
739 | insert_counters(&cnt_delta, new); | ||
740 | 779 | ||
741 | new = (struct counters *)calloc(1, sizeof(struct counters)); | 780 | sprintf(path, "/sys/devices/system/cpu/cpu%d/topology/core_siblings_list", cpu); |
742 | if (new == NULL) { | 781 | filep = fopen(path, "r"); |
743 | perror("calloc"); | 782 | if (filep == NULL) { |
783 | perror(path); | ||
744 | exit(1); | 784 | exit(1); |
745 | } | 785 | } |
746 | new->pkg = pkg; | 786 | fscanf(filep, "%d", &first_cpu); |
747 | new->core = core; | 787 | fclose(filep); |
748 | new->cpu = cpu; | 788 | return (cpu == first_cpu); |
749 | cnt_average = new; | ||
750 | } | 789 | } |
751 | 790 | ||
752 | int get_physical_package_id(int cpu) | 791 | int get_physical_package_id(int cpu) |
753 | { | 792 | { |
754 | char path[64]; | 793 | char path[80]; |
755 | FILE *filep; | 794 | FILE *filep; |
756 | int pkg; | 795 | int pkg; |
757 | 796 | ||
@@ -768,7 +807,7 @@ int get_physical_package_id(int cpu) | |||
768 | 807 | ||
769 | int get_core_id(int cpu) | 808 | int get_core_id(int cpu) |
770 | { | 809 | { |
771 | char path[64]; | 810 | char path[80]; |
772 | FILE *filep; | 811 | FILE *filep; |
773 | int core; | 812 | int core; |
774 | 813 | ||
@@ -783,14 +822,87 @@ int get_core_id(int cpu) | |||
783 | return core; | 822 | return core; |
784 | } | 823 | } |
785 | 824 | ||
825 | int get_num_ht_siblings(int cpu) | ||
826 | { | ||
827 | char path[80]; | ||
828 | FILE *filep; | ||
829 | int sib1, sib2; | ||
830 | int matches; | ||
831 | char character; | ||
832 | |||
833 | sprintf(path, "/sys/devices/system/cpu/cpu%d/topology/thread_siblings_list", cpu); | ||
834 | filep = fopen(path, "r"); | ||
835 | if (filep == NULL) { | ||
836 | perror(path); | ||
837 | exit(1); | ||
838 | } | ||
839 | /* | ||
840 | * file format: | ||
841 | * if a pair of number with a character between: 2 siblings (eg. 1-2, or 1,4) | ||
842 | * otherwinse 1 sibling (self). | ||
843 | */ | ||
844 | matches = fscanf(filep, "%d%c%d\n", &sib1, &character, &sib2); | ||
845 | |||
846 | fclose(filep); | ||
847 | |||
848 | if (matches == 3) | ||
849 | return 2; | ||
850 | else | ||
851 | return 1; | ||
852 | } | ||
853 | |||
786 | /* | 854 | /* |
787 | * run func(pkg, core, cpu) on every cpu in /proc/stat | 855 | * run func(thread, core, package) in topology order |
856 | * skip non-present cpus | ||
788 | */ | 857 | */ |
789 | 858 | ||
790 | int for_all_cpus(void (func)(int, int, int)) | 859 | int for_all_cpus_2(int (func)(struct thread_data *, struct core_data *, |
860 | struct pkg_data *, struct thread_data *, struct core_data *, | ||
861 | struct pkg_data *), struct thread_data *thread_base, | ||
862 | struct core_data *core_base, struct pkg_data *pkg_base, | ||
863 | struct thread_data *thread_base2, struct core_data *core_base2, | ||
864 | struct pkg_data *pkg_base2) | ||
865 | { | ||
866 | int retval, pkg_no, core_no, thread_no; | ||
867 | |||
868 | for (pkg_no = 0; pkg_no < topo.num_packages; ++pkg_no) { | ||
869 | for (core_no = 0; core_no < topo.num_cores_per_pkg; ++core_no) { | ||
870 | for (thread_no = 0; thread_no < | ||
871 | topo.num_threads_per_core; ++thread_no) { | ||
872 | struct thread_data *t, *t2; | ||
873 | struct core_data *c, *c2; | ||
874 | struct pkg_data *p, *p2; | ||
875 | |||
876 | t = GET_THREAD(thread_base, thread_no, core_no, pkg_no); | ||
877 | |||
878 | if (cpu_is_not_present(t->cpu_id)) | ||
879 | continue; | ||
880 | |||
881 | t2 = GET_THREAD(thread_base2, thread_no, core_no, pkg_no); | ||
882 | |||
883 | c = GET_CORE(core_base, core_no, pkg_no); | ||
884 | c2 = GET_CORE(core_base2, core_no, pkg_no); | ||
885 | |||
886 | p = GET_PKG(pkg_base, pkg_no); | ||
887 | p2 = GET_PKG(pkg_base2, pkg_no); | ||
888 | |||
889 | retval = func(t, c, p, t2, c2, p2); | ||
890 | if (retval) | ||
891 | return retval; | ||
892 | } | ||
893 | } | ||
894 | } | ||
895 | return 0; | ||
896 | } | ||
897 | |||
898 | /* | ||
899 | * run func(cpu) on every cpu in /proc/stat | ||
900 | * return max_cpu number | ||
901 | */ | ||
902 | int for_all_proc_cpus(int (func)(int)) | ||
791 | { | 903 | { |
792 | FILE *fp; | 904 | FILE *fp; |
793 | int cpu_count; | 905 | int cpu_num; |
794 | int retval; | 906 | int retval; |
795 | 907 | ||
796 | fp = fopen(proc_stat, "r"); | 908 | fp = fopen(proc_stat, "r"); |
@@ -805,78 +917,88 @@ int for_all_cpus(void (func)(int, int, int)) | |||
805 | exit(1); | 917 | exit(1); |
806 | } | 918 | } |
807 | 919 | ||
808 | for (cpu_count = 0; ; cpu_count++) { | 920 | while (1) { |
809 | int cpu; | 921 | retval = fscanf(fp, "cpu%u %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d\n", &cpu_num); |
810 | |||
811 | retval = fscanf(fp, "cpu%u %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d\n", &cpu); | ||
812 | if (retval != 1) | 922 | if (retval != 1) |
813 | break; | 923 | break; |
814 | 924 | ||
815 | func(get_physical_package_id(cpu), get_core_id(cpu), cpu); | 925 | retval = func(cpu_num); |
926 | if (retval) { | ||
927 | fclose(fp); | ||
928 | return(retval); | ||
929 | } | ||
816 | } | 930 | } |
817 | fclose(fp); | 931 | fclose(fp); |
818 | return cpu_count; | 932 | return 0; |
819 | } | 933 | } |
820 | 934 | ||
821 | void re_initialize(void) | 935 | void re_initialize(void) |
822 | { | 936 | { |
823 | free_all_counters(); | 937 | free_all_buffers(); |
824 | num_cpus = for_all_cpus(alloc_new_counters); | 938 | setup_all_buffers(); |
825 | cpu_mask_uninit(); | 939 | printf("turbostat: re-initialized with num_cpus %d\n", topo.num_cpus); |
826 | cpu_mask_init(num_cpus); | ||
827 | printf("turbostat: re-initialized with num_cpus %d\n", num_cpus); | ||
828 | } | 940 | } |
829 | 941 | ||
830 | void dummy(int pkg, int core, int cpu) { return; } | 942 | |
831 | /* | 943 | /* |
832 | * check to see if a cpu came on-line | 944 | * count_cpus() |
945 | * remember the last one seen, it will be the max | ||
833 | */ | 946 | */ |
834 | int verify_num_cpus(void) | 947 | int count_cpus(int cpu) |
835 | { | 948 | { |
836 | int new_num_cpus; | 949 | if (topo.max_cpu_num < cpu) |
837 | 950 | topo.max_cpu_num = cpu; | |
838 | new_num_cpus = for_all_cpus(dummy); | ||
839 | 951 | ||
840 | if (new_num_cpus != num_cpus) { | 952 | topo.num_cpus += 1; |
841 | if (verbose) | 953 | return 0; |
842 | printf("num_cpus was %d, is now %d\n", | 954 | } |
843 | num_cpus, new_num_cpus); | 955 | int mark_cpu_present(int cpu) |
844 | return -1; | 956 | { |
845 | } | 957 | CPU_SET_S(cpu, cpu_present_setsize, cpu_present_set); |
846 | return 0; | 958 | return 0; |
847 | } | 959 | } |
848 | 960 | ||
849 | void turbostat_loop() | 961 | void turbostat_loop() |
850 | { | 962 | { |
963 | int retval; | ||
964 | |||
851 | restart: | 965 | restart: |
852 | get_counters(cnt_even); | 966 | retval = for_all_cpus(get_counters, EVEN_COUNTERS); |
967 | if (retval) { | ||
968 | re_initialize(); | ||
969 | goto restart; | ||
970 | } | ||
853 | gettimeofday(&tv_even, (struct timezone *)NULL); | 971 | gettimeofday(&tv_even, (struct timezone *)NULL); |
854 | 972 | ||
855 | while (1) { | 973 | while (1) { |
856 | if (verify_num_cpus()) { | 974 | if (for_all_proc_cpus(cpu_is_not_present)) { |
857 | re_initialize(); | 975 | re_initialize(); |
858 | goto restart; | 976 | goto restart; |
859 | } | 977 | } |
860 | sleep(interval_sec); | 978 | sleep(interval_sec); |
861 | if (get_counters(cnt_odd)) { | 979 | retval = for_all_cpus(get_counters, ODD_COUNTERS); |
980 | if (retval) { | ||
862 | re_initialize(); | 981 | re_initialize(); |
863 | goto restart; | 982 | goto restart; |
864 | } | 983 | } |
865 | gettimeofday(&tv_odd, (struct timezone *)NULL); | 984 | gettimeofday(&tv_odd, (struct timezone *)NULL); |
866 | compute_delta(cnt_odd, cnt_even, cnt_delta); | ||
867 | timersub(&tv_odd, &tv_even, &tv_delta); | 985 | timersub(&tv_odd, &tv_even, &tv_delta); |
868 | compute_average(cnt_delta, cnt_average); | 986 | for_all_cpus_2(delta_cpu, ODD_COUNTERS, EVEN_COUNTERS); |
869 | print_counters(cnt_delta); | 987 | compute_average(EVEN_COUNTERS); |
988 | format_all_counters(EVEN_COUNTERS); | ||
989 | flush_stdout(); | ||
870 | sleep(interval_sec); | 990 | sleep(interval_sec); |
871 | if (get_counters(cnt_even)) { | 991 | retval = for_all_cpus(get_counters, EVEN_COUNTERS); |
992 | if (retval) { | ||
872 | re_initialize(); | 993 | re_initialize(); |
873 | goto restart; | 994 | goto restart; |
874 | } | 995 | } |
875 | gettimeofday(&tv_even, (struct timezone *)NULL); | 996 | gettimeofday(&tv_even, (struct timezone *)NULL); |
876 | compute_delta(cnt_even, cnt_odd, cnt_delta); | ||
877 | timersub(&tv_even, &tv_odd, &tv_delta); | 997 | timersub(&tv_even, &tv_odd, &tv_delta); |
878 | compute_average(cnt_delta, cnt_average); | 998 | for_all_cpus_2(delta_cpu, EVEN_COUNTERS, ODD_COUNTERS); |
879 | print_counters(cnt_delta); | 999 | compute_average(ODD_COUNTERS); |
1000 | format_all_counters(ODD_COUNTERS); | ||
1001 | flush_stdout(); | ||
880 | } | 1002 | } |
881 | } | 1003 | } |
882 | 1004 | ||
@@ -1051,6 +1173,208 @@ int open_dev_cpu_msr(int dummy1) | |||
1051 | return 0; | 1173 | return 0; |
1052 | } | 1174 | } |
1053 | 1175 | ||
1176 | void topology_probe() | ||
1177 | { | ||
1178 | int i; | ||
1179 | int max_core_id = 0; | ||
1180 | int max_package_id = 0; | ||
1181 | int max_siblings = 0; | ||
1182 | struct cpu_topology { | ||
1183 | int core_id; | ||
1184 | int physical_package_id; | ||
1185 | } *cpus; | ||
1186 | |||
1187 | /* Initialize num_cpus, max_cpu_num */ | ||
1188 | topo.num_cpus = 0; | ||
1189 | topo.max_cpu_num = 0; | ||
1190 | for_all_proc_cpus(count_cpus); | ||
1191 | if (!summary_only && topo.num_cpus > 1) | ||
1192 | show_cpu = 1; | ||
1193 | |||
1194 | if (verbose > 1) | ||
1195 | fprintf(stderr, "num_cpus %d max_cpu_num %d\n", topo.num_cpus, topo.max_cpu_num); | ||
1196 | |||
1197 | cpus = calloc(1, (topo.max_cpu_num + 1) * sizeof(struct cpu_topology)); | ||
1198 | if (cpus == NULL) { | ||
1199 | perror("calloc cpus"); | ||
1200 | exit(1); | ||
1201 | } | ||
1202 | |||
1203 | /* | ||
1204 | * Allocate and initialize cpu_present_set | ||
1205 | */ | ||
1206 | cpu_present_set = CPU_ALLOC((topo.max_cpu_num + 1)); | ||
1207 | if (cpu_present_set == NULL) { | ||
1208 | perror("CPU_ALLOC"); | ||
1209 | exit(3); | ||
1210 | } | ||
1211 | cpu_present_setsize = CPU_ALLOC_SIZE((topo.max_cpu_num + 1)); | ||
1212 | CPU_ZERO_S(cpu_present_setsize, cpu_present_set); | ||
1213 | for_all_proc_cpus(mark_cpu_present); | ||
1214 | |||
1215 | /* | ||
1216 | * Allocate and initialize cpu_affinity_set | ||
1217 | */ | ||
1218 | cpu_affinity_set = CPU_ALLOC((topo.max_cpu_num + 1)); | ||
1219 | if (cpu_affinity_set == NULL) { | ||
1220 | perror("CPU_ALLOC"); | ||
1221 | exit(3); | ||
1222 | } | ||
1223 | cpu_affinity_setsize = CPU_ALLOC_SIZE((topo.max_cpu_num + 1)); | ||
1224 | CPU_ZERO_S(cpu_affinity_setsize, cpu_affinity_set); | ||
1225 | |||
1226 | |||
1227 | /* | ||
1228 | * For online cpus | ||
1229 | * find max_core_id, max_package_id | ||
1230 | */ | ||
1231 | for (i = 0; i <= topo.max_cpu_num; ++i) { | ||
1232 | int siblings; | ||
1233 | |||
1234 | if (cpu_is_not_present(i)) { | ||
1235 | if (verbose > 1) | ||
1236 | fprintf(stderr, "cpu%d NOT PRESENT\n", i); | ||
1237 | continue; | ||
1238 | } | ||
1239 | cpus[i].core_id = get_core_id(i); | ||
1240 | if (cpus[i].core_id > max_core_id) | ||
1241 | max_core_id = cpus[i].core_id; | ||
1242 | |||
1243 | cpus[i].physical_package_id = get_physical_package_id(i); | ||
1244 | if (cpus[i].physical_package_id > max_package_id) | ||
1245 | max_package_id = cpus[i].physical_package_id; | ||
1246 | |||
1247 | siblings = get_num_ht_siblings(i); | ||
1248 | if (siblings > max_siblings) | ||
1249 | max_siblings = siblings; | ||
1250 | if (verbose > 1) | ||
1251 | fprintf(stderr, "cpu %d pkg %d core %d\n", | ||
1252 | i, cpus[i].physical_package_id, cpus[i].core_id); | ||
1253 | } | ||
1254 | topo.num_cores_per_pkg = max_core_id + 1; | ||
1255 | if (verbose > 1) | ||
1256 | fprintf(stderr, "max_core_id %d, sizing for %d cores per package\n", | ||
1257 | max_core_id, topo.num_cores_per_pkg); | ||
1258 | if (!summary_only && topo.num_cores_per_pkg > 1) | ||
1259 | show_core = 1; | ||
1260 | |||
1261 | topo.num_packages = max_package_id + 1; | ||
1262 | if (verbose > 1) | ||
1263 | fprintf(stderr, "max_package_id %d, sizing for %d packages\n", | ||
1264 | max_package_id, topo.num_packages); | ||
1265 | if (!summary_only && topo.num_packages > 1) | ||
1266 | show_pkg = 1; | ||
1267 | |||
1268 | topo.num_threads_per_core = max_siblings; | ||
1269 | if (verbose > 1) | ||
1270 | fprintf(stderr, "max_siblings %d\n", max_siblings); | ||
1271 | |||
1272 | free(cpus); | ||
1273 | } | ||
1274 | |||
1275 | void | ||
1276 | allocate_counters(struct thread_data **t, struct core_data **c, struct pkg_data **p) | ||
1277 | { | ||
1278 | int i; | ||
1279 | |||
1280 | *t = calloc(topo.num_threads_per_core * topo.num_cores_per_pkg * | ||
1281 | topo.num_packages, sizeof(struct thread_data)); | ||
1282 | if (*t == NULL) | ||
1283 | goto error; | ||
1284 | |||
1285 | for (i = 0; i < topo.num_threads_per_core * | ||
1286 | topo.num_cores_per_pkg * topo.num_packages; i++) | ||
1287 | (*t)[i].cpu_id = -1; | ||
1288 | |||
1289 | *c = calloc(topo.num_cores_per_pkg * topo.num_packages, | ||
1290 | sizeof(struct core_data)); | ||
1291 | if (*c == NULL) | ||
1292 | goto error; | ||
1293 | |||
1294 | for (i = 0; i < topo.num_cores_per_pkg * topo.num_packages; i++) | ||
1295 | (*c)[i].core_id = -1; | ||
1296 | |||
1297 | *p = calloc(topo.num_packages, sizeof(struct pkg_data)); | ||
1298 | if (*p == NULL) | ||
1299 | goto error; | ||
1300 | |||
1301 | for (i = 0; i < topo.num_packages; i++) | ||
1302 | (*p)[i].package_id = i; | ||
1303 | |||
1304 | return; | ||
1305 | error: | ||
1306 | perror("calloc counters"); | ||
1307 | exit(1); | ||
1308 | } | ||
1309 | /* | ||
1310 | * init_counter() | ||
1311 | * | ||
1312 | * set cpu_id, core_num, pkg_num | ||
1313 | * set FIRST_THREAD_IN_CORE and FIRST_CORE_IN_PACKAGE | ||
1314 | * | ||
1315 | * increment topo.num_cores when 1st core in pkg seen | ||
1316 | */ | ||
1317 | void init_counter(struct thread_data *thread_base, struct core_data *core_base, | ||
1318 | struct pkg_data *pkg_base, int thread_num, int core_num, | ||
1319 | int pkg_num, int cpu_id) | ||
1320 | { | ||
1321 | struct thread_data *t; | ||
1322 | struct core_data *c; | ||
1323 | struct pkg_data *p; | ||
1324 | |||
1325 | t = GET_THREAD(thread_base, thread_num, core_num, pkg_num); | ||
1326 | c = GET_CORE(core_base, core_num, pkg_num); | ||
1327 | p = GET_PKG(pkg_base, pkg_num); | ||
1328 | |||
1329 | t->cpu_id = cpu_id; | ||
1330 | if (thread_num == 0) { | ||
1331 | t->flags |= CPU_IS_FIRST_THREAD_IN_CORE; | ||
1332 | if (cpu_is_first_core_in_package(cpu_id)) | ||
1333 | t->flags |= CPU_IS_FIRST_CORE_IN_PACKAGE; | ||
1334 | } | ||
1335 | |||
1336 | c->core_id = core_num; | ||
1337 | p->package_id = pkg_num; | ||
1338 | } | ||
1339 | |||
1340 | |||
1341 | int initialize_counters(int cpu_id) | ||
1342 | { | ||
1343 | int my_thread_id, my_core_id, my_package_id; | ||
1344 | |||
1345 | my_package_id = get_physical_package_id(cpu_id); | ||
1346 | my_core_id = get_core_id(cpu_id); | ||
1347 | |||
1348 | if (cpu_is_first_sibling_in_core(cpu_id)) { | ||
1349 | my_thread_id = 0; | ||
1350 | topo.num_cores++; | ||
1351 | } else { | ||
1352 | my_thread_id = 1; | ||
1353 | } | ||
1354 | |||
1355 | init_counter(EVEN_COUNTERS, my_thread_id, my_core_id, my_package_id, cpu_id); | ||
1356 | init_counter(ODD_COUNTERS, my_thread_id, my_core_id, my_package_id, cpu_id); | ||
1357 | return 0; | ||
1358 | } | ||
1359 | |||
1360 | void allocate_output_buffer() | ||
1361 | { | ||
1362 | output_buffer = calloc(1, (1 + topo.num_cpus) * 128); | ||
1363 | outp = output_buffer; | ||
1364 | if (outp == NULL) { | ||
1365 | perror("calloc"); | ||
1366 | exit(-1); | ||
1367 | } | ||
1368 | } | ||
1369 | |||
1370 | void setup_all_buffers(void) | ||
1371 | { | ||
1372 | topology_probe(); | ||
1373 | allocate_counters(&thread_even, &core_even, &package_even); | ||
1374 | allocate_counters(&thread_odd, &core_odd, &package_odd); | ||
1375 | allocate_output_buffer(); | ||
1376 | for_all_proc_cpus(initialize_counters); | ||
1377 | } | ||
1054 | void turbostat_init() | 1378 | void turbostat_init() |
1055 | { | 1379 | { |
1056 | check_cpuid(); | 1380 | check_cpuid(); |
@@ -1058,21 +1382,19 @@ void turbostat_init() | |||
1058 | check_dev_msr(); | 1382 | check_dev_msr(); |
1059 | check_super_user(); | 1383 | check_super_user(); |
1060 | 1384 | ||
1061 | num_cpus = for_all_cpus(alloc_new_counters); | 1385 | setup_all_buffers(); |
1062 | cpu_mask_init(num_cpus); | ||
1063 | 1386 | ||
1064 | if (verbose) | 1387 | if (verbose) |
1065 | print_nehalem_info(); | 1388 | print_verbose_header(); |
1066 | } | 1389 | } |
1067 | 1390 | ||
1068 | int fork_it(char **argv) | 1391 | int fork_it(char **argv) |
1069 | { | 1392 | { |
1070 | int retval; | ||
1071 | pid_t child_pid; | 1393 | pid_t child_pid; |
1072 | get_counters(cnt_even); | ||
1073 | 1394 | ||
1074 | /* clear affinity side-effect of get_counters() */ | 1395 | for_all_cpus(get_counters, EVEN_COUNTERS); |
1075 | sched_setaffinity(0, cpu_present_setsize, cpu_present_set); | 1396 | /* clear affinity side-effect of get_counters() */ |
1397 | sched_setaffinity(0, cpu_present_setsize, cpu_present_set); | ||
1076 | gettimeofday(&tv_even, (struct timezone *)NULL); | 1398 | gettimeofday(&tv_even, (struct timezone *)NULL); |
1077 | 1399 | ||
1078 | child_pid = fork(); | 1400 | child_pid = fork(); |
@@ -1095,14 +1417,17 @@ int fork_it(char **argv) | |||
1095 | exit(1); | 1417 | exit(1); |
1096 | } | 1418 | } |
1097 | } | 1419 | } |
1098 | get_counters(cnt_odd); | 1420 | /* |
1421 | * n.b. fork_it() does not check for errors from for_all_cpus() | ||
1422 | * because re-starting is problematic when forking | ||
1423 | */ | ||
1424 | for_all_cpus(get_counters, ODD_COUNTERS); | ||
1099 | gettimeofday(&tv_odd, (struct timezone *)NULL); | 1425 | gettimeofday(&tv_odd, (struct timezone *)NULL); |
1100 | retval = compute_delta(cnt_odd, cnt_even, cnt_delta); | ||
1101 | |||
1102 | timersub(&tv_odd, &tv_even, &tv_delta); | 1426 | timersub(&tv_odd, &tv_even, &tv_delta); |
1103 | compute_average(cnt_delta, cnt_average); | 1427 | for_all_cpus_2(delta_cpu, ODD_COUNTERS, EVEN_COUNTERS); |
1104 | if (!retval) | 1428 | compute_average(EVEN_COUNTERS); |
1105 | print_counters(cnt_delta); | 1429 | format_all_counters(EVEN_COUNTERS); |
1430 | flush_stderr(); | ||
1106 | 1431 | ||
1107 | fprintf(stderr, "%.6f sec\n", tv_delta.tv_sec + tv_delta.tv_usec/1000000.0); | 1432 | fprintf(stderr, "%.6f sec\n", tv_delta.tv_sec + tv_delta.tv_usec/1000000.0); |
1108 | 1433 | ||
@@ -1115,8 +1440,14 @@ void cmdline(int argc, char **argv) | |||
1115 | 1440 | ||
1116 | progname = argv[0]; | 1441 | progname = argv[0]; |
1117 | 1442 | ||
1118 | while ((opt = getopt(argc, argv, "+svi:M:")) != -1) { | 1443 | while ((opt = getopt(argc, argv, "+cpsvi:M:")) != -1) { |
1119 | switch (opt) { | 1444 | switch (opt) { |
1445 | case 'c': | ||
1446 | show_core_only++; | ||
1447 | break; | ||
1448 | case 'p': | ||
1449 | show_pkg_only++; | ||
1450 | break; | ||
1120 | case 's': | 1451 | case 's': |
1121 | summary_only++; | 1452 | summary_only++; |
1122 | break; | 1453 | break; |
@@ -1142,10 +1473,8 @@ int main(int argc, char **argv) | |||
1142 | cmdline(argc, argv); | 1473 | cmdline(argc, argv); |
1143 | 1474 | ||
1144 | if (verbose > 1) | 1475 | if (verbose > 1) |
1145 | fprintf(stderr, "turbostat Dec 6, 2010" | 1476 | fprintf(stderr, "turbostat v2.0 May 16, 2012" |
1146 | " - Len Brown <lenb@kernel.org>\n"); | 1477 | " - Len Brown <lenb@kernel.org>\n"); |
1147 | if (verbose > 1) | ||
1148 | fprintf(stderr, "http://userweb.kernel.org/~lenb/acpi/utils/pmtools/turbostat/\n"); | ||
1149 | 1478 | ||
1150 | turbostat_init(); | 1479 | turbostat_init(); |
1151 | 1480 | ||
diff --git a/tools/testing/fault-injection/failcmd.sh b/tools/testing/fault-injection/failcmd.sh new file mode 100644 index 000000000000..78a9ed7fecdb --- /dev/null +++ b/tools/testing/fault-injection/failcmd.sh | |||
@@ -0,0 +1,219 @@ | |||
1 | #!/bin/bash | ||
2 | # | ||
3 | # NAME | ||
4 | # failcmd.sh - run a command with injecting slab/page allocation failures | ||
5 | # | ||
6 | # SYNOPSIS | ||
7 | # failcmd.sh --help | ||
8 | # failcmd.sh [<options>] command [arguments] | ||
9 | # | ||
10 | # DESCRIPTION | ||
11 | # Run command with injecting slab/page allocation failures by fault | ||
12 | # injection. | ||
13 | # | ||
14 | # NOTE: you need to run this script as root. | ||
15 | # | ||
16 | |||
17 | usage() | ||
18 | { | ||
19 | cat >&2 <<EOF | ||
20 | Usage: $0 [options] command [arguments] | ||
21 | |||
22 | OPTIONS | ||
23 | -p percent | ||
24 | --probability=percent | ||
25 | likelihood of failure injection, in percent. | ||
26 | Default value is 1 | ||
27 | |||
28 | -t value | ||
29 | --times=value | ||
30 | specifies how many times failures may happen at most. | ||
31 | Default value is 1 | ||
32 | |||
33 | --oom-kill-allocating-task=value | ||
34 | set /proc/sys/vm/oom_kill_allocating_task to specified value | ||
35 | before running the command. | ||
36 | Default value is 1 | ||
37 | |||
38 | -h, --help | ||
39 | Display a usage message and exit | ||
40 | |||
41 | --interval=value, --space=value, --verbose=value, --task-filter=value, | ||
42 | --stacktrace-depth=value, --require-start=value, --require-end=value, | ||
43 | --reject-start=value, --reject-end=value, --ignore-gfp-wait=value | ||
44 | See Documentation/fault-injection/fault-injection.txt for more | ||
45 | information | ||
46 | |||
47 | failslab options: | ||
48 | --cache-filter=value | ||
49 | |||
50 | fail_page_alloc options: | ||
51 | --ignore-gfp-highmem=value, --min-order=value | ||
52 | |||
53 | ENVIRONMENT | ||
54 | FAILCMD_TYPE | ||
55 | The following values for FAILCMD_TYPE are recognized: | ||
56 | |||
57 | failslab | ||
58 | inject slab allocation failures | ||
59 | fail_page_alloc | ||
60 | inject page allocation failures | ||
61 | |||
62 | If FAILCMD_TYPE is not defined, then failslab is used. | ||
63 | EOF | ||
64 | } | ||
65 | |||
66 | if [ $UID != 0 ]; then | ||
67 | echo must be run as root >&2 | ||
68 | exit 1 | ||
69 | fi | ||
70 | |||
71 | DEBUGFS=`mount -t debugfs | head -1 | awk '{ print $3}'` | ||
72 | |||
73 | if [ ! -d "$DEBUGFS" ]; then | ||
74 | echo debugfs is not mounted >&2 | ||
75 | exit 1 | ||
76 | fi | ||
77 | |||
78 | FAILCMD_TYPE=${FAILCMD_TYPE:-failslab} | ||
79 | FAULTATTR=$DEBUGFS/$FAILCMD_TYPE | ||
80 | |||
81 | if [ ! -d $FAULTATTR ]; then | ||
82 | echo $FAILCMD_TYPE is not available >&2 | ||
83 | exit 1 | ||
84 | fi | ||
85 | |||
86 | LONGOPTS=probability:,interval:,times:,space:,verbose:,task-filter: | ||
87 | LONGOPTS=$LONGOPTS,stacktrace-depth:,require-start:,require-end: | ||
88 | LONGOPTS=$LONGOPTS,reject-start:,reject-end:,oom-kill-allocating-task:,help | ||
89 | |||
90 | if [ $FAILCMD_TYPE = failslab ]; then | ||
91 | LONGOPTS=$LONGOPTS,ignore-gfp-wait:,cache-filter: | ||
92 | elif [ $FAILCMD_TYPE = fail_page_alloc ]; then | ||
93 | LONGOPTS=$LONGOPTS,ignore-gfp-wait:,ignore-gfp-highmem:,min-order: | ||
94 | fi | ||
95 | |||
96 | TEMP=`getopt -o p:i:t:s:v:h --long $LONGOPTS -n 'failcmd.sh' -- "$@"` | ||
97 | |||
98 | if [ $? != 0 ]; then | ||
99 | usage | ||
100 | exit 1 | ||
101 | fi | ||
102 | |||
103 | eval set -- "$TEMP" | ||
104 | |||
105 | fault_attr_default() | ||
106 | { | ||
107 | echo N > $FAULTATTR/task-filter | ||
108 | echo 0 > $FAULTATTR/probability | ||
109 | echo 1 > $FAULTATTR/times | ||
110 | } | ||
111 | |||
112 | fault_attr_default | ||
113 | |||
114 | oom_kill_allocating_task_saved=`cat /proc/sys/vm/oom_kill_allocating_task` | ||
115 | |||
116 | restore_values() | ||
117 | { | ||
118 | fault_attr_default | ||
119 | echo $oom_kill_allocating_task_saved \ | ||
120 | > /proc/sys/vm/oom_kill_allocating_task | ||
121 | } | ||
122 | |||
123 | # | ||
124 | # Default options | ||
125 | # | ||
126 | declare -i oom_kill_allocating_task=1 | ||
127 | declare task_filter=Y | ||
128 | declare -i probability=1 | ||
129 | declare -i times=1 | ||
130 | |||
131 | while true; do | ||
132 | case "$1" in | ||
133 | -p|--probability) | ||
134 | probability=$2 | ||
135 | shift 2 | ||
136 | ;; | ||
137 | -i|--interval) | ||
138 | echo $2 > $FAULTATTR/interval | ||
139 | shift 2 | ||
140 | ;; | ||
141 | -t|--times) | ||
142 | times=$2 | ||
143 | shift 2 | ||
144 | ;; | ||
145 | -s|--space) | ||
146 | echo $2 > $FAULTATTR/space | ||
147 | shift 2 | ||
148 | ;; | ||
149 | -v|--verbose) | ||
150 | echo $2 > $FAULTATTR/verbose | ||
151 | shift 2 | ||
152 | ;; | ||
153 | --task-filter) | ||
154 | task_filter=$2 | ||
155 | shift 2 | ||
156 | ;; | ||
157 | --stacktrace-depth) | ||
158 | echo $2 > $FAULTATTR/stacktrace-depth | ||
159 | shift 2 | ||
160 | ;; | ||
161 | --require-start) | ||
162 | echo $2 > $FAULTATTR/require-start | ||
163 | shift 2 | ||
164 | ;; | ||
165 | --require-end) | ||
166 | echo $2 > $FAULTATTR/require-end | ||
167 | shift 2 | ||
168 | ;; | ||
169 | --reject-start) | ||
170 | echo $2 > $FAULTATTR/reject-start | ||
171 | shift 2 | ||
172 | ;; | ||
173 | --reject-end) | ||
174 | echo $2 > $FAULTATTR/reject-end | ||
175 | shift 2 | ||
176 | ;; | ||
177 | --oom-kill-allocating-task) | ||
178 | oom_kill_allocating_task=$2 | ||
179 | shift 2 | ||
180 | ;; | ||
181 | --ignore-gfp-wait) | ||
182 | echo $2 > $FAULTATTR/ignore-gfp-wait | ||
183 | shift 2 | ||
184 | ;; | ||
185 | --cache-filter) | ||
186 | echo $2 > $FAULTATTR/cache_filter | ||
187 | shift 2 | ||
188 | ;; | ||
189 | --ignore-gfp-highmem) | ||
190 | echo $2 > $FAULTATTR/ignore-gfp-highmem | ||
191 | shift 2 | ||
192 | ;; | ||
193 | --min-order) | ||
194 | echo $2 > $FAULTATTR/min-order | ||
195 | shift 2 | ||
196 | ;; | ||
197 | -h|--help) | ||
198 | usage | ||
199 | exit 0 | ||
200 | shift | ||
201 | ;; | ||
202 | --) | ||
203 | shift | ||
204 | break | ||
205 | ;; | ||
206 | esac | ||
207 | done | ||
208 | |||
209 | [ -z "$1" ] && exit 0 | ||
210 | |||
211 | echo $oom_kill_allocating_task > /proc/sys/vm/oom_kill_allocating_task | ||
212 | echo $task_filter > $FAULTATTR/task-filter | ||
213 | echo $probability > $FAULTATTR/probability | ||
214 | echo $times > $FAULTATTR/times | ||
215 | |||
216 | trap "restore_values" SIGINT SIGTERM EXIT | ||
217 | |||
218 | cmd="echo 1 > /proc/self/make-it-fail && exec $@" | ||
219 | bash -c "$cmd" | ||
diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl index 292b13ad03f5..52b7959cd513 100755 --- a/tools/testing/ktest/ktest.pl +++ b/tools/testing/ktest/ktest.pl | |||
@@ -52,6 +52,7 @@ my %default = ( | |||
52 | "STOP_AFTER_SUCCESS" => 10, | 52 | "STOP_AFTER_SUCCESS" => 10, |
53 | "STOP_AFTER_FAILURE" => 60, | 53 | "STOP_AFTER_FAILURE" => 60, |
54 | "STOP_TEST_AFTER" => 600, | 54 | "STOP_TEST_AFTER" => 600, |
55 | "MAX_MONITOR_WAIT" => 1800, | ||
55 | 56 | ||
56 | # required, and we will ask users if they don't have them but we keep the default | 57 | # required, and we will ask users if they don't have them but we keep the default |
57 | # value something that is common. | 58 | # value something that is common. |
@@ -77,6 +78,11 @@ my $output_config; | |||
77 | my $test_type; | 78 | my $test_type; |
78 | my $build_type; | 79 | my $build_type; |
79 | my $build_options; | 80 | my $build_options; |
81 | my $final_post_ktest; | ||
82 | my $pre_ktest; | ||
83 | my $post_ktest; | ||
84 | my $pre_test; | ||
85 | my $post_test; | ||
80 | my $pre_build; | 86 | my $pre_build; |
81 | my $post_build; | 87 | my $post_build; |
82 | my $pre_build_die; | 88 | my $pre_build_die; |
@@ -93,6 +99,7 @@ my $reboot_on_success; | |||
93 | my $die_on_failure; | 99 | my $die_on_failure; |
94 | my $powercycle_after_reboot; | 100 | my $powercycle_after_reboot; |
95 | my $poweroff_after_halt; | 101 | my $poweroff_after_halt; |
102 | my $max_monitor_wait; | ||
96 | my $ssh_exec; | 103 | my $ssh_exec; |
97 | my $scp_to_target; | 104 | my $scp_to_target; |
98 | my $scp_to_target_install; | 105 | my $scp_to_target_install; |
@@ -101,6 +108,7 @@ my $grub_menu; | |||
101 | my $grub_number; | 108 | my $grub_number; |
102 | my $target; | 109 | my $target; |
103 | my $make; | 110 | my $make; |
111 | my $pre_install; | ||
104 | my $post_install; | 112 | my $post_install; |
105 | my $no_install; | 113 | my $no_install; |
106 | my $noclean; | 114 | my $noclean; |
@@ -167,6 +175,7 @@ my $bisect_check; | |||
167 | 175 | ||
168 | my $config_bisect; | 176 | my $config_bisect; |
169 | my $config_bisect_type; | 177 | my $config_bisect_type; |
178 | my $config_bisect_check; | ||
170 | 179 | ||
171 | my $patchcheck_type; | 180 | my $patchcheck_type; |
172 | my $patchcheck_start; | 181 | my $patchcheck_start; |
@@ -182,6 +191,9 @@ my $newconfig = 0; | |||
182 | my %entered_configs; | 191 | my %entered_configs; |
183 | my %config_help; | 192 | my %config_help; |
184 | my %variable; | 193 | my %variable; |
194 | |||
195 | # force_config is the list of configs that we force enabled (or disabled) | ||
196 | # in a .config file. The MIN_CONFIG and ADD_CONFIG configs. | ||
185 | my %force_config; | 197 | my %force_config; |
186 | 198 | ||
187 | # do not force reboots on config problems | 199 | # do not force reboots on config problems |
@@ -197,6 +209,10 @@ my %option_map = ( | |||
197 | "OUTPUT_DIR" => \$outputdir, | 209 | "OUTPUT_DIR" => \$outputdir, |
198 | "BUILD_DIR" => \$builddir, | 210 | "BUILD_DIR" => \$builddir, |
199 | "TEST_TYPE" => \$test_type, | 211 | "TEST_TYPE" => \$test_type, |
212 | "PRE_KTEST" => \$pre_ktest, | ||
213 | "POST_KTEST" => \$post_ktest, | ||
214 | "PRE_TEST" => \$pre_test, | ||
215 | "POST_TEST" => \$post_test, | ||
200 | "BUILD_TYPE" => \$build_type, | 216 | "BUILD_TYPE" => \$build_type, |
201 | "BUILD_OPTIONS" => \$build_options, | 217 | "BUILD_OPTIONS" => \$build_options, |
202 | "PRE_BUILD" => \$pre_build, | 218 | "PRE_BUILD" => \$pre_build, |
@@ -216,6 +232,7 @@ my %option_map = ( | |||
216 | "ADD_CONFIG" => \$addconfig, | 232 | "ADD_CONFIG" => \$addconfig, |
217 | "REBOOT_TYPE" => \$reboot_type, | 233 | "REBOOT_TYPE" => \$reboot_type, |
218 | "GRUB_MENU" => \$grub_menu, | 234 | "GRUB_MENU" => \$grub_menu, |
235 | "PRE_INSTALL" => \$pre_install, | ||
219 | "POST_INSTALL" => \$post_install, | 236 | "POST_INSTALL" => \$post_install, |
220 | "NO_INSTALL" => \$no_install, | 237 | "NO_INSTALL" => \$no_install, |
221 | "REBOOT_SCRIPT" => \$reboot_script, | 238 | "REBOOT_SCRIPT" => \$reboot_script, |
@@ -228,6 +245,7 @@ my %option_map = ( | |||
228 | "POWER_OFF" => \$power_off, | 245 | "POWER_OFF" => \$power_off, |
229 | "POWERCYCLE_AFTER_REBOOT" => \$powercycle_after_reboot, | 246 | "POWERCYCLE_AFTER_REBOOT" => \$powercycle_after_reboot, |
230 | "POWEROFF_AFTER_HALT" => \$poweroff_after_halt, | 247 | "POWEROFF_AFTER_HALT" => \$poweroff_after_halt, |
248 | "MAX_MONITOR_WAIT" => \$max_monitor_wait, | ||
231 | "SLEEP_TIME" => \$sleep_time, | 249 | "SLEEP_TIME" => \$sleep_time, |
232 | "BISECT_SLEEP_TIME" => \$bisect_sleep_time, | 250 | "BISECT_SLEEP_TIME" => \$bisect_sleep_time, |
233 | "PATCHCHECK_SLEEP_TIME" => \$patchcheck_sleep_time, | 251 | "PATCHCHECK_SLEEP_TIME" => \$patchcheck_sleep_time, |
@@ -272,6 +290,7 @@ my %option_map = ( | |||
272 | 290 | ||
273 | "CONFIG_BISECT" => \$config_bisect, | 291 | "CONFIG_BISECT" => \$config_bisect, |
274 | "CONFIG_BISECT_TYPE" => \$config_bisect_type, | 292 | "CONFIG_BISECT_TYPE" => \$config_bisect_type, |
293 | "CONFIG_BISECT_CHECK" => \$config_bisect_check, | ||
275 | 294 | ||
276 | "PATCHCHECK_TYPE" => \$patchcheck_type, | 295 | "PATCHCHECK_TYPE" => \$patchcheck_type, |
277 | "PATCHCHECK_START" => \$patchcheck_start, | 296 | "PATCHCHECK_START" => \$patchcheck_start, |
@@ -604,6 +623,10 @@ sub process_compare { | |||
604 | return $lval eq $rval; | 623 | return $lval eq $rval; |
605 | } elsif ($cmp eq "!=") { | 624 | } elsif ($cmp eq "!=") { |
606 | return $lval ne $rval; | 625 | return $lval ne $rval; |
626 | } elsif ($cmp eq "=~") { | ||
627 | return $lval =~ m/$rval/; | ||
628 | } elsif ($cmp eq "!~") { | ||
629 | return $lval !~ m/$rval/; | ||
607 | } | 630 | } |
608 | 631 | ||
609 | my $statement = "$lval $cmp $rval"; | 632 | my $statement = "$lval $cmp $rval"; |
@@ -659,7 +682,7 @@ sub process_expression { | |||
659 | } | 682 | } |
660 | } | 683 | } |
661 | 684 | ||
662 | if ($val =~ /(.*)(==|\!=|>=|<=|>|<)(.*)/) { | 685 | if ($val =~ /(.*)(==|\!=|>=|<=|>|<|=~|\!~)(.*)/) { |
663 | my $ret = process_compare($1, $2, $3); | 686 | my $ret = process_compare($1, $2, $3); |
664 | if ($ret < 0) { | 687 | if ($ret < 0) { |
665 | die "$name: $.: Unable to process comparison\n"; | 688 | die "$name: $.: Unable to process comparison\n"; |
@@ -1117,7 +1140,11 @@ sub reboot { | |||
1117 | } | 1140 | } |
1118 | 1141 | ||
1119 | if (defined($time)) { | 1142 | if (defined($time)) { |
1120 | wait_for_monitor($time, $reboot_success_line); | 1143 | if (wait_for_monitor($time, $reboot_success_line)) { |
1144 | # reboot got stuck? | ||
1145 | doprint "Reboot did not finish. Forcing power cycle\n"; | ||
1146 | run_command "$power_cycle"; | ||
1147 | } | ||
1121 | end_monitor; | 1148 | end_monitor; |
1122 | } | 1149 | } |
1123 | } | 1150 | } |
@@ -1212,6 +1239,11 @@ sub wait_for_monitor { | |||
1212 | my $full_line = ""; | 1239 | my $full_line = ""; |
1213 | my $line; | 1240 | my $line; |
1214 | my $booted = 0; | 1241 | my $booted = 0; |
1242 | my $start_time = time; | ||
1243 | my $skip_call_trace = 0; | ||
1244 | my $bug = 0; | ||
1245 | my $bug_ignored = 0; | ||
1246 | my $now; | ||
1215 | 1247 | ||
1216 | doprint "** Wait for monitor to settle down **\n"; | 1248 | doprint "** Wait for monitor to settle down **\n"; |
1217 | 1249 | ||
@@ -1227,11 +1259,39 @@ sub wait_for_monitor { | |||
1227 | $booted = 1; | 1259 | $booted = 1; |
1228 | } | 1260 | } |
1229 | 1261 | ||
1262 | if ($full_line =~ /\[ backtrace testing \]/) { | ||
1263 | $skip_call_trace = 1; | ||
1264 | } | ||
1265 | |||
1266 | if ($full_line =~ /call trace:/i) { | ||
1267 | if (!$bug && !$skip_call_trace) { | ||
1268 | if ($ignore_errors) { | ||
1269 | $bug_ignored = 1; | ||
1270 | } else { | ||
1271 | $bug = 1; | ||
1272 | } | ||
1273 | } | ||
1274 | } | ||
1275 | |||
1276 | if ($full_line =~ /\[ end of backtrace testing \]/) { | ||
1277 | $skip_call_trace = 0; | ||
1278 | } | ||
1279 | |||
1280 | if ($full_line =~ /Kernel panic -/) { | ||
1281 | $bug = 1; | ||
1282 | } | ||
1283 | |||
1230 | if ($line =~ /\n/) { | 1284 | if ($line =~ /\n/) { |
1231 | $full_line = ""; | 1285 | $full_line = ""; |
1232 | } | 1286 | } |
1287 | $now = time; | ||
1288 | if ($now - $start_time >= $max_monitor_wait) { | ||
1289 | doprint "Exiting monitor flush due to hitting MAX_MONITOR_WAIT\n"; | ||
1290 | return 1; | ||
1291 | } | ||
1233 | } | 1292 | } |
1234 | print "** Monitor flushed **\n"; | 1293 | print "** Monitor flushed **\n"; |
1294 | return $bug; | ||
1235 | } | 1295 | } |
1236 | 1296 | ||
1237 | sub save_logs { | 1297 | sub save_logs { |
@@ -1273,6 +1333,10 @@ sub save_logs { | |||
1273 | 1333 | ||
1274 | sub fail { | 1334 | sub fail { |
1275 | 1335 | ||
1336 | if (defined($post_test)) { | ||
1337 | run_command $post_test; | ||
1338 | } | ||
1339 | |||
1276 | if ($die_on_failure) { | 1340 | if ($die_on_failure) { |
1277 | dodie @_; | 1341 | dodie @_; |
1278 | } | 1342 | } |
@@ -1656,6 +1720,12 @@ sub install { | |||
1656 | 1720 | ||
1657 | return if ($no_install); | 1721 | return if ($no_install); |
1658 | 1722 | ||
1723 | if (defined($pre_install)) { | ||
1724 | my $cp_pre_install = eval_kernel_version $pre_install; | ||
1725 | run_command "$cp_pre_install" or | ||
1726 | dodie "Failed to run pre install"; | ||
1727 | } | ||
1728 | |||
1659 | my $cp_target = eval_kernel_version $target_image; | 1729 | my $cp_target = eval_kernel_version $target_image; |
1660 | 1730 | ||
1661 | run_scp_install "$outputdir/$build_target", "$cp_target" or | 1731 | run_scp_install "$outputdir/$build_target", "$cp_target" or |
@@ -1814,6 +1884,7 @@ sub make_oldconfig { | |||
1814 | sub load_force_config { | 1884 | sub load_force_config { |
1815 | my ($config) = @_; | 1885 | my ($config) = @_; |
1816 | 1886 | ||
1887 | doprint "Loading force configs from $config\n"; | ||
1817 | open(IN, $config) or | 1888 | open(IN, $config) or |
1818 | dodie "failed to read $config"; | 1889 | dodie "failed to read $config"; |
1819 | while (<IN>) { | 1890 | while (<IN>) { |
@@ -1937,6 +2008,10 @@ sub halt { | |||
1937 | sub success { | 2008 | sub success { |
1938 | my ($i) = @_; | 2009 | my ($i) = @_; |
1939 | 2010 | ||
2011 | if (defined($post_test)) { | ||
2012 | run_command $post_test; | ||
2013 | } | ||
2014 | |||
1940 | $successes++; | 2015 | $successes++; |
1941 | 2016 | ||
1942 | my $name = ""; | 2017 | my $name = ""; |
@@ -2003,6 +2078,7 @@ sub do_run_test { | |||
2003 | my $line; | 2078 | my $line; |
2004 | my $full_line; | 2079 | my $full_line; |
2005 | my $bug = 0; | 2080 | my $bug = 0; |
2081 | my $bug_ignored = 0; | ||
2006 | 2082 | ||
2007 | wait_for_monitor 1; | 2083 | wait_for_monitor 1; |
2008 | 2084 | ||
@@ -2027,7 +2103,11 @@ sub do_run_test { | |||
2027 | doprint $line; | 2103 | doprint $line; |
2028 | 2104 | ||
2029 | if ($full_line =~ /call trace:/i) { | 2105 | if ($full_line =~ /call trace:/i) { |
2030 | $bug = 1; | 2106 | if ($ignore_errors) { |
2107 | $bug_ignored = 1; | ||
2108 | } else { | ||
2109 | $bug = 1; | ||
2110 | } | ||
2031 | } | 2111 | } |
2032 | 2112 | ||
2033 | if ($full_line =~ /Kernel panic -/) { | 2113 | if ($full_line =~ /Kernel panic -/) { |
@@ -2040,6 +2120,10 @@ sub do_run_test { | |||
2040 | } | 2120 | } |
2041 | } while (!$child_done && !$bug); | 2121 | } while (!$child_done && !$bug); |
2042 | 2122 | ||
2123 | if (!$bug && $bug_ignored) { | ||
2124 | doprint "WARNING: Call Trace detected but ignored due to IGNORE_ERRORS=1\n"; | ||
2125 | } | ||
2126 | |||
2043 | if ($bug) { | 2127 | if ($bug) { |
2044 | my $failure_start = time; | 2128 | my $failure_start = time; |
2045 | my $now; | 2129 | my $now; |
@@ -2362,9 +2446,24 @@ sub bisect { | |||
2362 | success $i; | 2446 | success $i; |
2363 | } | 2447 | } |
2364 | 2448 | ||
2449 | # config_ignore holds the configs that were set (or unset) for | ||
2450 | # a good config and we will ignore these configs for the rest | ||
2451 | # of a config bisect. These configs stay as they were. | ||
2365 | my %config_ignore; | 2452 | my %config_ignore; |
2453 | |||
2454 | # config_set holds what all configs were set as. | ||
2366 | my %config_set; | 2455 | my %config_set; |
2367 | 2456 | ||
2457 | # config_off holds the set of configs that the bad config had disabled. | ||
2458 | # We need to record them and set them in the .config when running | ||
2459 | # oldnoconfig, because oldnoconfig does not turn off new symbols, but | ||
2460 | # instead just keeps the defaults. | ||
2461 | my %config_off; | ||
2462 | |||
2463 | # config_off_tmp holds a set of configs to turn off for now | ||
2464 | my @config_off_tmp; | ||
2465 | |||
2466 | # config_list is the set of configs that are being tested | ||
2368 | my %config_list; | 2467 | my %config_list; |
2369 | my %null_config; | 2468 | my %null_config; |
2370 | 2469 | ||
@@ -2443,12 +2542,21 @@ sub create_config { | |||
2443 | } | 2542 | } |
2444 | } | 2543 | } |
2445 | 2544 | ||
2545 | # turn off configs to keep off | ||
2546 | foreach my $config (keys %config_off) { | ||
2547 | print OUT "# $config is not set\n"; | ||
2548 | } | ||
2549 | |||
2550 | # turn off configs that should be off for now | ||
2551 | foreach my $config (@config_off_tmp) { | ||
2552 | print OUT "# $config is not set\n"; | ||
2553 | } | ||
2554 | |||
2446 | foreach my $config (keys %config_ignore) { | 2555 | foreach my $config (keys %config_ignore) { |
2447 | print OUT "$config_ignore{$config}\n"; | 2556 | print OUT "$config_ignore{$config}\n"; |
2448 | } | 2557 | } |
2449 | close(OUT); | 2558 | close(OUT); |
2450 | 2559 | ||
2451 | # exit; | ||
2452 | make_oldconfig; | 2560 | make_oldconfig; |
2453 | } | 2561 | } |
2454 | 2562 | ||
@@ -2525,6 +2633,13 @@ sub run_config_bisect { | |||
2525 | do { | 2633 | do { |
2526 | my @tophalf = @start_list[0 .. $half]; | 2634 | my @tophalf = @start_list[0 .. $half]; |
2527 | 2635 | ||
2636 | # keep the bottom half off | ||
2637 | if ($half < $#start_list) { | ||
2638 | @config_off_tmp = @start_list[$half + 1 .. $#start_list]; | ||
2639 | } else { | ||
2640 | @config_off_tmp = (); | ||
2641 | } | ||
2642 | |||
2528 | create_config @tophalf; | 2643 | create_config @tophalf; |
2529 | read_current_config \%current_config; | 2644 | read_current_config \%current_config; |
2530 | 2645 | ||
@@ -2541,7 +2656,11 @@ sub run_config_bisect { | |||
2541 | if (!$found) { | 2656 | if (!$found) { |
2542 | # try the other half | 2657 | # try the other half |
2543 | doprint "Top half produced no set configs, trying bottom half\n"; | 2658 | doprint "Top half produced no set configs, trying bottom half\n"; |
2659 | |||
2660 | # keep the top half off | ||
2661 | @config_off_tmp = @tophalf; | ||
2544 | @tophalf = @start_list[$half + 1 .. $#start_list]; | 2662 | @tophalf = @start_list[$half + 1 .. $#start_list]; |
2663 | |||
2545 | create_config @tophalf; | 2664 | create_config @tophalf; |
2546 | read_current_config \%current_config; | 2665 | read_current_config \%current_config; |
2547 | foreach my $config (@tophalf) { | 2666 | foreach my $config (@tophalf) { |
@@ -2679,6 +2798,10 @@ sub config_bisect { | |||
2679 | $added_configs{$2} = $1; | 2798 | $added_configs{$2} = $1; |
2680 | $config_list{$2} = $1; | 2799 | $config_list{$2} = $1; |
2681 | } | 2800 | } |
2801 | } elsif (/^# ((CONFIG\S*).*)/) { | ||
2802 | # Keep these configs disabled | ||
2803 | $config_set{$2} = $1; | ||
2804 | $config_off{$2} = $1; | ||
2682 | } | 2805 | } |
2683 | } | 2806 | } |
2684 | close(IN); | 2807 | close(IN); |
@@ -2701,6 +2824,8 @@ sub config_bisect { | |||
2701 | my %config_test; | 2824 | my %config_test; |
2702 | my $once = 0; | 2825 | my $once = 0; |
2703 | 2826 | ||
2827 | @config_off_tmp = (); | ||
2828 | |||
2704 | # Sometimes kconfig does weird things. We must make sure | 2829 | # Sometimes kconfig does weird things. We must make sure |
2705 | # that the config we autocreate has everything we need | 2830 | # that the config we autocreate has everything we need |
2706 | # to test, otherwise we may miss testing configs, or | 2831 | # to test, otherwise we may miss testing configs, or |
@@ -2719,6 +2844,18 @@ sub config_bisect { | |||
2719 | } | 2844 | } |
2720 | } | 2845 | } |
2721 | my $ret; | 2846 | my $ret; |
2847 | |||
2848 | if (defined($config_bisect_check) && $config_bisect_check) { | ||
2849 | doprint " Checking to make sure bad config with min config fails\n"; | ||
2850 | create_config keys %config_list; | ||
2851 | $ret = run_config_bisect_test $config_bisect_type; | ||
2852 | if ($ret) { | ||
2853 | doprint " FAILED! Bad config with min config boots fine\n"; | ||
2854 | return -1; | ||
2855 | } | ||
2856 | doprint " Bad config with min config fails as expected\n"; | ||
2857 | } | ||
2858 | |||
2722 | do { | 2859 | do { |
2723 | $ret = run_config_bisect; | 2860 | $ret = run_config_bisect; |
2724 | } while (!$ret); | 2861 | } while (!$ret); |
@@ -3510,6 +3647,8 @@ for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) { | |||
3510 | 3647 | ||
3511 | $iteration = $i; | 3648 | $iteration = $i; |
3512 | 3649 | ||
3650 | undef %force_config; | ||
3651 | |||
3513 | my $makecmd = set_test_option("MAKE_CMD", $i); | 3652 | my $makecmd = set_test_option("MAKE_CMD", $i); |
3514 | 3653 | ||
3515 | # Load all the options into their mapped variable names | 3654 | # Load all the options into their mapped variable names |
@@ -3519,6 +3658,18 @@ for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) { | |||
3519 | 3658 | ||
3520 | $start_minconfig_defined = 1; | 3659 | $start_minconfig_defined = 1; |
3521 | 3660 | ||
3661 | # The first test may override the PRE_KTEST option | ||
3662 | if (defined($pre_ktest) && $i == 1) { | ||
3663 | doprint "\n"; | ||
3664 | run_command $pre_ktest; | ||
3665 | } | ||
3666 | |||
3667 | # Any test can override the POST_KTEST option | ||
3668 | # The last test takes precedence. | ||
3669 | if (defined($post_ktest)) { | ||
3670 | $final_post_ktest = $post_ktest; | ||
3671 | } | ||
3672 | |||
3522 | if (!defined($start_minconfig)) { | 3673 | if (!defined($start_minconfig)) { |
3523 | $start_minconfig_defined = 0; | 3674 | $start_minconfig_defined = 0; |
3524 | $start_minconfig = $minconfig; | 3675 | $start_minconfig = $minconfig; |
@@ -3573,6 +3724,10 @@ for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) { | |||
3573 | doprint "\n\n"; | 3724 | doprint "\n\n"; |
3574 | doprint "RUNNING TEST $i of $opt{NUM_TESTS} with option $test_type $run_type$installme\n\n"; | 3725 | doprint "RUNNING TEST $i of $opt{NUM_TESTS} with option $test_type $run_type$installme\n\n"; |
3575 | 3726 | ||
3727 | if (defined($pre_test)) { | ||
3728 | run_command $pre_test; | ||
3729 | } | ||
3730 | |||
3576 | unlink $dmesg; | 3731 | unlink $dmesg; |
3577 | unlink $buildlog; | 3732 | unlink $buildlog; |
3578 | unlink $testlog; | 3733 | unlink $testlog; |
@@ -3638,6 +3793,10 @@ for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) { | |||
3638 | success $i; | 3793 | success $i; |
3639 | } | 3794 | } |
3640 | 3795 | ||
3796 | if (defined($final_post_ktest)) { | ||
3797 | run_command $final_post_ktest; | ||
3798 | } | ||
3799 | |||
3641 | if ($opt{"POWEROFF_ON_SUCCESS"}) { | 3800 | if ($opt{"POWEROFF_ON_SUCCESS"}) { |
3642 | halt; | 3801 | halt; |
3643 | } elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot && $reboot_success) { | 3802 | } elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot && $reboot_success) { |
diff --git a/tools/testing/ktest/sample.conf b/tools/testing/ktest/sample.conf index cf362b3d1ec9..de28a0a3b8fc 100644 --- a/tools/testing/ktest/sample.conf +++ b/tools/testing/ktest/sample.conf | |||
@@ -376,6 +376,24 @@ | |||
376 | # DEFAULTS | 376 | # DEFAULTS |
377 | # DEFAULTS SKIP | 377 | # DEFAULTS SKIP |
378 | 378 | ||
379 | # If you want to execute some command before the first test runs | ||
380 | # you can set this option. Note, it can be set as a default option | ||
381 | # or an option in the first test case. All other test cases will | ||
382 | # ignore it. If both the default and first test have this option | ||
383 | # set, then the first test will take precedence. | ||
384 | # | ||
385 | # default (undefined) | ||
386 | #PRE_KTEST = ${SSH} ~/set_up_test | ||
387 | |||
388 | # If you want to execute some command after all the tests have | ||
389 | # completed, you can set this option. Note, it can be set as a | ||
390 | # default or any test case can override it. If multiple test cases | ||
391 | # set this option, then the last test case that set it will take | ||
392 | # precedence | ||
393 | # | ||
394 | # default (undefined) | ||
395 | #POST_KTEST = ${SSH} ~/dismantle_test | ||
396 | |||
379 | # The default test type (default test) | 397 | # The default test type (default test) |
380 | # The test types may be: | 398 | # The test types may be: |
381 | # build - only build the kernel, do nothing else | 399 | # build - only build the kernel, do nothing else |
@@ -408,6 +426,14 @@ | |||
408 | # (default "") | 426 | # (default "") |
409 | #BUILD_OPTIONS = -j20 | 427 | #BUILD_OPTIONS = -j20 |
410 | 428 | ||
429 | # If you need to do some special handling before installing | ||
430 | # you can add a script with this option. | ||
431 | # The environment variable KERNEL_VERSION will be set to the | ||
432 | # kernel version that is used. | ||
433 | # | ||
434 | # default (undefined) | ||
435 | #PRE_INSTALL = ssh user@target rm -rf '/lib/modules/*-test*' | ||
436 | |||
411 | # If you need an initrd, you can add a script or code here to install | 437 | # If you need an initrd, you can add a script or code here to install |
412 | # it. The environment variable KERNEL_VERSION will be set to the | 438 | # it. The environment variable KERNEL_VERSION will be set to the |
413 | # kernel version that is used. Remember to add the initrd line | 439 | # kernel version that is used. Remember to add the initrd line |
@@ -426,6 +452,18 @@ | |||
426 | # (default 0) | 452 | # (default 0) |
427 | #NO_INSTALL = 1 | 453 | #NO_INSTALL = 1 |
428 | 454 | ||
455 | # If there is a command that you want to run before the individual test | ||
456 | # case executes, then you can set this option | ||
457 | # | ||
458 | # default (undefined) | ||
459 | #PRE_TEST = ${SSH} reboot_to_special_kernel | ||
460 | |||
461 | # If there is a command you want to run after the individual test case | ||
462 | # completes, then you can set this option. | ||
463 | # | ||
464 | # default (undefined) | ||
465 | #POST_TEST = cd ${BUILD_DIR}; git reset --hard | ||
466 | |||
429 | # If there is a script that you require to run before the build is done | 467 | # If there is a script that you require to run before the build is done |
430 | # you can specify it with PRE_BUILD. | 468 | # you can specify it with PRE_BUILD. |
431 | # | 469 | # |
@@ -657,6 +695,14 @@ | |||
657 | # (default 60) | 695 | # (default 60) |
658 | #BISECT_SLEEP_TIME = 60 | 696 | #BISECT_SLEEP_TIME = 60 |
659 | 697 | ||
698 | # The max wait time (in seconds) for waiting for the console to finish. | ||
699 | # If for some reason, the console is outputting content without | ||
700 | # ever finishing, this will cause ktest to get stuck. This | ||
701 | # option is the max time ktest will wait for the monitor (console) | ||
702 | # to settle down before continuing. | ||
703 | # (default 1800) | ||
704 | #MAX_MONITOR_WAIT | ||
705 | |||
660 | # The time in between patch checks to sleep (in seconds) | 706 | # The time in between patch checks to sleep (in seconds) |
661 | # (default 60) | 707 | # (default 60) |
662 | #PATCHCHECK_SLEEP_TIME = 60 | 708 | #PATCHCHECK_SLEEP_TIME = 60 |
@@ -1039,6 +1085,12 @@ | |||
1039 | # can specify it with CONFIG_BISECT_GOOD. Otherwise | 1085 | # can specify it with CONFIG_BISECT_GOOD. Otherwise |
1040 | # the MIN_CONFIG is the base. | 1086 | # the MIN_CONFIG is the base. |
1041 | # | 1087 | # |
1088 | # CONFIG_BISECT_CHECK (optional) | ||
1089 | # Set this to 1 if you want to confirm that the config ktest | ||
1090 | # generates (the bad config with the min config) is still bad. | ||
1091 | # It may be that the min config fixes what broke the bad config | ||
1092 | # and the test will not return a result. | ||
1093 | # | ||
1042 | # Example: | 1094 | # Example: |
1043 | # TEST_START | 1095 | # TEST_START |
1044 | # TEST_TYPE = config_bisect | 1096 | # TEST_TYPE = config_bisect |
diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile index a4162e15c25f..85baf11e2acd 100644 --- a/tools/testing/selftests/Makefile +++ b/tools/testing/selftests/Makefile | |||
@@ -1,4 +1,4 @@ | |||
1 | TARGETS = breakpoints kcmp mqueue vm | 1 | TARGETS = breakpoints kcmp mqueue vm cpu-hotplug memory-hotplug |
2 | 2 | ||
3 | all: | 3 | all: |
4 | for TARGET in $(TARGETS); do \ | 4 | for TARGET in $(TARGETS); do \ |
diff --git a/tools/testing/selftests/cpu-hotplug/Makefile b/tools/testing/selftests/cpu-hotplug/Makefile new file mode 100644 index 000000000000..7c9c20ff578a --- /dev/null +++ b/tools/testing/selftests/cpu-hotplug/Makefile | |||
@@ -0,0 +1,6 @@ | |||
1 | all: | ||
2 | |||
3 | run_tests: | ||
4 | ./on-off-test.sh | ||
5 | |||
6 | clean: | ||
diff --git a/tools/testing/selftests/cpu-hotplug/on-off-test.sh b/tools/testing/selftests/cpu-hotplug/on-off-test.sh new file mode 100644 index 000000000000..bdde7cf428bb --- /dev/null +++ b/tools/testing/selftests/cpu-hotplug/on-off-test.sh | |||
@@ -0,0 +1,221 @@ | |||
1 | #!/bin/bash | ||
2 | |||
3 | SYSFS= | ||
4 | |||
5 | prerequisite() | ||
6 | { | ||
7 | msg="skip all tests:" | ||
8 | |||
9 | if [ $UID != 0 ]; then | ||
10 | echo $msg must be run as root >&2 | ||
11 | exit 0 | ||
12 | fi | ||
13 | |||
14 | SYSFS=`mount -t sysfs | head -1 | awk '{ print $3 }'` | ||
15 | |||
16 | if [ ! -d "$SYSFS" ]; then | ||
17 | echo $msg sysfs is not mounted >&2 | ||
18 | exit 0 | ||
19 | fi | ||
20 | |||
21 | if ! ls $SYSFS/devices/system/cpu/cpu* > /dev/null 2>&1; then | ||
22 | echo $msg cpu hotplug is not supported >&2 | ||
23 | exit 0 | ||
24 | fi | ||
25 | } | ||
26 | |||
27 | # | ||
28 | # list all hot-pluggable CPUs | ||
29 | # | ||
30 | hotpluggable_cpus() | ||
31 | { | ||
32 | local state=${1:-.\*} | ||
33 | |||
34 | for cpu in $SYSFS/devices/system/cpu/cpu*; do | ||
35 | if [ -f $cpu/online ] && grep -q $state $cpu/online; then | ||
36 | echo ${cpu##/*/cpu} | ||
37 | fi | ||
38 | done | ||
39 | } | ||
40 | |||
41 | hotplaggable_offline_cpus() | ||
42 | { | ||
43 | hotpluggable_cpus 0 | ||
44 | } | ||
45 | |||
46 | hotpluggable_online_cpus() | ||
47 | { | ||
48 | hotpluggable_cpus 1 | ||
49 | } | ||
50 | |||
51 | cpu_is_online() | ||
52 | { | ||
53 | grep -q 1 $SYSFS/devices/system/cpu/cpu$1/online | ||
54 | } | ||
55 | |||
56 | cpu_is_offline() | ||
57 | { | ||
58 | grep -q 0 $SYSFS/devices/system/cpu/cpu$1/online | ||
59 | } | ||
60 | |||
61 | online_cpu() | ||
62 | { | ||
63 | echo 1 > $SYSFS/devices/system/cpu/cpu$1/online | ||
64 | } | ||
65 | |||
66 | offline_cpu() | ||
67 | { | ||
68 | echo 0 > $SYSFS/devices/system/cpu/cpu$1/online | ||
69 | } | ||
70 | |||
71 | online_cpu_expect_success() | ||
72 | { | ||
73 | local cpu=$1 | ||
74 | |||
75 | if ! online_cpu $cpu; then | ||
76 | echo $FUNCNAME $cpu: unexpected fail >&2 | ||
77 | elif ! cpu_is_online $cpu; then | ||
78 | echo $FUNCNAME $cpu: unexpected offline >&2 | ||
79 | fi | ||
80 | } | ||
81 | |||
82 | online_cpu_expect_fail() | ||
83 | { | ||
84 | local cpu=$1 | ||
85 | |||
86 | if online_cpu $cpu 2> /dev/null; then | ||
87 | echo $FUNCNAME $cpu: unexpected success >&2 | ||
88 | elif ! cpu_is_offline $cpu; then | ||
89 | echo $FUNCNAME $cpu: unexpected online >&2 | ||
90 | fi | ||
91 | } | ||
92 | |||
93 | offline_cpu_expect_success() | ||
94 | { | ||
95 | local cpu=$1 | ||
96 | |||
97 | if ! offline_cpu $cpu; then | ||
98 | echo $FUNCNAME $cpu: unexpected fail >&2 | ||
99 | elif ! cpu_is_offline $cpu; then | ||
100 | echo $FUNCNAME $cpu: unexpected offline >&2 | ||
101 | fi | ||
102 | } | ||
103 | |||
104 | offline_cpu_expect_fail() | ||
105 | { | ||
106 | local cpu=$1 | ||
107 | |||
108 | if offline_cpu $cpu 2> /dev/null; then | ||
109 | echo $FUNCNAME $cpu: unexpected success >&2 | ||
110 | elif ! cpu_is_online $cpu; then | ||
111 | echo $FUNCNAME $cpu: unexpected offline >&2 | ||
112 | fi | ||
113 | } | ||
114 | |||
115 | error=-12 | ||
116 | priority=0 | ||
117 | |||
118 | while getopts e:hp: opt; do | ||
119 | case $opt in | ||
120 | e) | ||
121 | error=$OPTARG | ||
122 | ;; | ||
123 | h) | ||
124 | echo "Usage $0 [ -e errno ] [ -p notifier-priority ]" | ||
125 | exit | ||
126 | ;; | ||
127 | p) | ||
128 | priority=$OPTARG | ||
129 | ;; | ||
130 | esac | ||
131 | done | ||
132 | |||
133 | if ! [ "$error" -ge -4095 -a "$error" -lt 0 ]; then | ||
134 | echo "error code must be -4095 <= errno < 0" >&2 | ||
135 | exit 1 | ||
136 | fi | ||
137 | |||
138 | prerequisite | ||
139 | |||
140 | # | ||
141 | # Online all hot-pluggable CPUs | ||
142 | # | ||
143 | for cpu in `hotplaggable_offline_cpus`; do | ||
144 | online_cpu_expect_success $cpu | ||
145 | done | ||
146 | |||
147 | # | ||
148 | # Offline all hot-pluggable CPUs | ||
149 | # | ||
150 | for cpu in `hotpluggable_online_cpus`; do | ||
151 | offline_cpu_expect_success $cpu | ||
152 | done | ||
153 | |||
154 | # | ||
155 | # Online all hot-pluggable CPUs again | ||
156 | # | ||
157 | for cpu in `hotplaggable_offline_cpus`; do | ||
158 | online_cpu_expect_success $cpu | ||
159 | done | ||
160 | |||
161 | # | ||
162 | # Test with cpu notifier error injection | ||
163 | # | ||
164 | |||
165 | DEBUGFS=`mount -t debugfs | head -1 | awk '{ print $3 }'` | ||
166 | NOTIFIER_ERR_INJECT_DIR=$DEBUGFS/notifier-error-inject/cpu | ||
167 | |||
168 | prerequisite_extra() | ||
169 | { | ||
170 | msg="skip extra tests:" | ||
171 | |||
172 | /sbin/modprobe -q -r cpu-notifier-error-inject | ||
173 | /sbin/modprobe -q cpu-notifier-error-inject priority=$priority | ||
174 | |||
175 | if [ ! -d "$DEBUGFS" ]; then | ||
176 | echo $msg debugfs is not mounted >&2 | ||
177 | exit 0 | ||
178 | fi | ||
179 | |||
180 | if [ ! -d $NOTIFIER_ERR_INJECT_DIR ]; then | ||
181 | echo $msg cpu-notifier-error-inject module is not available >&2 | ||
182 | exit 0 | ||
183 | fi | ||
184 | } | ||
185 | |||
186 | prerequisite_extra | ||
187 | |||
188 | # | ||
189 | # Offline all hot-pluggable CPUs | ||
190 | # | ||
191 | echo 0 > $NOTIFIER_ERR_INJECT_DIR/actions/CPU_DOWN_PREPARE/error | ||
192 | for cpu in `hotpluggable_online_cpus`; do | ||
193 | offline_cpu_expect_success $cpu | ||
194 | done | ||
195 | |||
196 | # | ||
197 | # Test CPU hot-add error handling (offline => online) | ||
198 | # | ||
199 | echo $error > $NOTIFIER_ERR_INJECT_DIR/actions/CPU_UP_PREPARE/error | ||
200 | for cpu in `hotplaggable_offline_cpus`; do | ||
201 | online_cpu_expect_fail $cpu | ||
202 | done | ||
203 | |||
204 | # | ||
205 | # Online all hot-pluggable CPUs | ||
206 | # | ||
207 | echo 0 > $NOTIFIER_ERR_INJECT_DIR/actions/CPU_UP_PREPARE/error | ||
208 | for cpu in `hotplaggable_offline_cpus`; do | ||
209 | online_cpu_expect_success $cpu | ||
210 | done | ||
211 | |||
212 | # | ||
213 | # Test CPU hot-remove error handling (online => offline) | ||
214 | # | ||
215 | echo $error > $NOTIFIER_ERR_INJECT_DIR/actions/CPU_DOWN_PREPARE/error | ||
216 | for cpu in `hotpluggable_online_cpus`; do | ||
217 | offline_cpu_expect_fail $cpu | ||
218 | done | ||
219 | |||
220 | echo 0 > $NOTIFIER_ERR_INJECT_DIR/actions/CPU_DOWN_PREPARE/error | ||
221 | /sbin/modprobe -q -r cpu-notifier-error-inject | ||
diff --git a/tools/testing/selftests/memory-hotplug/Makefile b/tools/testing/selftests/memory-hotplug/Makefile new file mode 100644 index 000000000000..7c9c20ff578a --- /dev/null +++ b/tools/testing/selftests/memory-hotplug/Makefile | |||
@@ -0,0 +1,6 @@ | |||
1 | all: | ||
2 | |||
3 | run_tests: | ||
4 | ./on-off-test.sh | ||
5 | |||
6 | clean: | ||
diff --git a/tools/testing/selftests/memory-hotplug/on-off-test.sh b/tools/testing/selftests/memory-hotplug/on-off-test.sh new file mode 100644 index 000000000000..a2816f631542 --- /dev/null +++ b/tools/testing/selftests/memory-hotplug/on-off-test.sh | |||
@@ -0,0 +1,230 @@ | |||
1 | #!/bin/bash | ||
2 | |||
3 | SYSFS= | ||
4 | |||
5 | prerequisite() | ||
6 | { | ||
7 | msg="skip all tests:" | ||
8 | |||
9 | if [ $UID != 0 ]; then | ||
10 | echo $msg must be run as root >&2 | ||
11 | exit 0 | ||
12 | fi | ||
13 | |||
14 | SYSFS=`mount -t sysfs | head -1 | awk '{ print $3 }'` | ||
15 | |||
16 | if [ ! -d "$SYSFS" ]; then | ||
17 | echo $msg sysfs is not mounted >&2 | ||
18 | exit 0 | ||
19 | fi | ||
20 | |||
21 | if ! ls $SYSFS/devices/system/memory/memory* > /dev/null 2>&1; then | ||
22 | echo $msg memory hotplug is not supported >&2 | ||
23 | exit 0 | ||
24 | fi | ||
25 | } | ||
26 | |||
27 | # | ||
28 | # list all hot-pluggable memory | ||
29 | # | ||
30 | hotpluggable_memory() | ||
31 | { | ||
32 | local state=${1:-.\*} | ||
33 | |||
34 | for memory in $SYSFS/devices/system/memory/memory*; do | ||
35 | if grep -q 1 $memory/removable && | ||
36 | grep -q $state $memory/state; then | ||
37 | echo ${memory##/*/memory} | ||
38 | fi | ||
39 | done | ||
40 | } | ||
41 | |||
42 | hotplaggable_offline_memory() | ||
43 | { | ||
44 | hotpluggable_memory offline | ||
45 | } | ||
46 | |||
47 | hotpluggable_online_memory() | ||
48 | { | ||
49 | hotpluggable_memory online | ||
50 | } | ||
51 | |||
52 | memory_is_online() | ||
53 | { | ||
54 | grep -q online $SYSFS/devices/system/memory/memory$1/state | ||
55 | } | ||
56 | |||
57 | memory_is_offline() | ||
58 | { | ||
59 | grep -q offline $SYSFS/devices/system/memory/memory$1/state | ||
60 | } | ||
61 | |||
62 | online_memory() | ||
63 | { | ||
64 | echo online > $SYSFS/devices/system/memory/memory$1/state | ||
65 | } | ||
66 | |||
67 | offline_memory() | ||
68 | { | ||
69 | echo offline > $SYSFS/devices/system/memory/memory$1/state | ||
70 | } | ||
71 | |||
72 | online_memory_expect_success() | ||
73 | { | ||
74 | local memory=$1 | ||
75 | |||
76 | if ! online_memory $memory; then | ||
77 | echo $FUNCNAME $memory: unexpected fail >&2 | ||
78 | elif ! memory_is_online $memory; then | ||
79 | echo $FUNCNAME $memory: unexpected offline >&2 | ||
80 | fi | ||
81 | } | ||
82 | |||
83 | online_memory_expect_fail() | ||
84 | { | ||
85 | local memory=$1 | ||
86 | |||
87 | if online_memory $memory 2> /dev/null; then | ||
88 | echo $FUNCNAME $memory: unexpected success >&2 | ||
89 | elif ! memory_is_offline $memory; then | ||
90 | echo $FUNCNAME $memory: unexpected online >&2 | ||
91 | fi | ||
92 | } | ||
93 | |||
94 | offline_memory_expect_success() | ||
95 | { | ||
96 | local memory=$1 | ||
97 | |||
98 | if ! offline_memory $memory; then | ||
99 | echo $FUNCNAME $memory: unexpected fail >&2 | ||
100 | elif ! memory_is_offline $memory; then | ||
101 | echo $FUNCNAME $memory: unexpected offline >&2 | ||
102 | fi | ||
103 | } | ||
104 | |||
105 | offline_memory_expect_fail() | ||
106 | { | ||
107 | local memory=$1 | ||
108 | |||
109 | if offline_memory $memory 2> /dev/null; then | ||
110 | echo $FUNCNAME $memory: unexpected success >&2 | ||
111 | elif ! memory_is_online $memory; then | ||
112 | echo $FUNCNAME $memory: unexpected offline >&2 | ||
113 | fi | ||
114 | } | ||
115 | |||
116 | error=-12 | ||
117 | priority=0 | ||
118 | ratio=10 | ||
119 | |||
120 | while getopts e:hp:r: opt; do | ||
121 | case $opt in | ||
122 | e) | ||
123 | error=$OPTARG | ||
124 | ;; | ||
125 | h) | ||
126 | echo "Usage $0 [ -e errno ] [ -p notifier-priority ] [ -r percent-of-memory-to-offline ]" | ||
127 | exit | ||
128 | ;; | ||
129 | p) | ||
130 | priority=$OPTARG | ||
131 | ;; | ||
132 | r) | ||
133 | ratio=$OPTARG | ||
134 | ;; | ||
135 | esac | ||
136 | done | ||
137 | |||
138 | if ! [ "$error" -ge -4095 -a "$error" -lt 0 ]; then | ||
139 | echo "error code must be -4095 <= errno < 0" >&2 | ||
140 | exit 1 | ||
141 | fi | ||
142 | |||
143 | prerequisite | ||
144 | |||
145 | # | ||
146 | # Online all hot-pluggable memory | ||
147 | # | ||
148 | for memory in `hotplaggable_offline_memory`; do | ||
149 | online_memory_expect_success $memory | ||
150 | done | ||
151 | |||
152 | # | ||
153 | # Offline $ratio percent of hot-pluggable memory | ||
154 | # | ||
155 | for memory in `hotpluggable_online_memory`; do | ||
156 | if [ $((RANDOM % 100)) -lt $ratio ]; then | ||
157 | offline_memory_expect_success $memory | ||
158 | fi | ||
159 | done | ||
160 | |||
161 | # | ||
162 | # Online all hot-pluggable memory again | ||
163 | # | ||
164 | for memory in `hotplaggable_offline_memory`; do | ||
165 | online_memory_expect_success $memory | ||
166 | done | ||
167 | |||
168 | # | ||
169 | # Test with memory notifier error injection | ||
170 | # | ||
171 | |||
172 | DEBUGFS=`mount -t debugfs | head -1 | awk '{ print $3 }'` | ||
173 | NOTIFIER_ERR_INJECT_DIR=$DEBUGFS/notifier-error-inject/memory | ||
174 | |||
175 | prerequisite_extra() | ||
176 | { | ||
177 | msg="skip extra tests:" | ||
178 | |||
179 | /sbin/modprobe -q -r memory-notifier-error-inject | ||
180 | /sbin/modprobe -q memory-notifier-error-inject priority=$priority | ||
181 | |||
182 | if [ ! -d "$DEBUGFS" ]; then | ||
183 | echo $msg debugfs is not mounted >&2 | ||
184 | exit 0 | ||
185 | fi | ||
186 | |||
187 | if [ ! -d $NOTIFIER_ERR_INJECT_DIR ]; then | ||
188 | echo $msg memory-notifier-error-inject module is not available >&2 | ||
189 | exit 0 | ||
190 | fi | ||
191 | } | ||
192 | |||
193 | prerequisite_extra | ||
194 | |||
195 | # | ||
196 | # Offline $ratio percent of hot-pluggable memory | ||
197 | # | ||
198 | echo 0 > $NOTIFIER_ERR_INJECT_DIR/actions/MEM_GOING_OFFLINE/error | ||
199 | for memory in `hotpluggable_online_memory`; do | ||
200 | if [ $((RANDOM % 100)) -lt $ratio ]; then | ||
201 | offline_memory_expect_success $memory | ||
202 | fi | ||
203 | done | ||
204 | |||
205 | # | ||
206 | # Test memory hot-add error handling (offline => online) | ||
207 | # | ||
208 | echo $error > $NOTIFIER_ERR_INJECT_DIR/actions/MEM_GOING_ONLINE/error | ||
209 | for memory in `hotplaggable_offline_memory`; do | ||
210 | online_memory_expect_fail $memory | ||
211 | done | ||
212 | |||
213 | # | ||
214 | # Online all hot-pluggable memory | ||
215 | # | ||
216 | echo 0 > $NOTIFIER_ERR_INJECT_DIR/actions/MEM_GOING_ONLINE/error | ||
217 | for memory in `hotplaggable_offline_memory`; do | ||
218 | online_memory_expect_success $memory | ||
219 | done | ||
220 | |||
221 | # | ||
222 | # Test memory hot-remove error handling (online => offline) | ||
223 | # | ||
224 | echo $error > $NOTIFIER_ERR_INJECT_DIR/actions/MEM_GOING_OFFLINE/error | ||
225 | for memory in `hotpluggable_online_memory`; do | ||
226 | offline_memory_expect_fail $memory | ||
227 | done | ||
228 | |||
229 | echo 0 > $NOTIFIER_ERR_INJECT_DIR/actions/MEM_GOING_OFFLINE/error | ||
230 | /sbin/modprobe -q -r memory-notifier-error-inject | ||
diff --git a/tools/usb/testusb.c b/tools/usb/testusb.c index 82d7c590c026..b0adb2710c02 100644 --- a/tools/usb/testusb.c +++ b/tools/usb/testusb.c | |||
@@ -425,7 +425,7 @@ int main (int argc, char **argv) | |||
425 | /* for easy use when hotplugging */ | 425 | /* for easy use when hotplugging */ |
426 | device = getenv ("DEVICE"); | 426 | device = getenv ("DEVICE"); |
427 | 427 | ||
428 | while ((c = getopt (argc, argv, "D:aA:c:g:hns:t:v:")) != EOF) | 428 | while ((c = getopt (argc, argv, "D:aA:c:g:hlns:t:v:")) != EOF) |
429 | switch (c) { | 429 | switch (c) { |
430 | case 'D': /* device, if only one */ | 430 | case 'D': /* device, if only one */ |
431 | device = optarg; | 431 | device = optarg; |
@@ -468,10 +468,21 @@ int main (int argc, char **argv) | |||
468 | case 'h': | 468 | case 'h': |
469 | default: | 469 | default: |
470 | usage: | 470 | usage: |
471 | fprintf (stderr, "usage: %s [-n] [-D dev | -a | -A usbfs-dir]\n" | 471 | fprintf (stderr, |
472 | "\t[-c iterations] [-t testnum]\n" | 472 | "usage: %s [options]\n" |
473 | "\t[-s packetsize] [-g sglen] [-v vary]\n", | 473 | "Options:\n" |
474 | argv [0]); | 474 | "\t-D dev only test specific device\n" |
475 | "\t-A usbfs-dir\n" | ||
476 | "\t-a test all recognized devices\n" | ||
477 | "\t-l loop forever(for stress test)\n" | ||
478 | "\t-t testnum only run specified case\n" | ||
479 | "\t-n no test running, show devices to be tested\n" | ||
480 | "Case arguments:\n" | ||
481 | "\t-c iterations default 1000\n" | ||
482 | "\t-s packetsize default 512\n" | ||
483 | "\t-g sglen default 32\n" | ||
484 | "\t-v vary default 512\n", | ||
485 | argv[0]); | ||
475 | return 1; | 486 | return 1; |
476 | } | 487 | } |
477 | if (optind != argc) | 488 | if (optind != argc) |
diff --git a/tools/vm/slabinfo.c b/tools/vm/slabinfo.c index 164cbcf61106..808d5a9d5dcf 100644 --- a/tools/vm/slabinfo.c +++ b/tools/vm/slabinfo.c | |||
@@ -437,34 +437,34 @@ static void slab_stats(struct slabinfo *s) | |||
437 | printf("Fastpath %8lu %8lu %3lu %3lu\n", | 437 | printf("Fastpath %8lu %8lu %3lu %3lu\n", |
438 | s->alloc_fastpath, s->free_fastpath, | 438 | s->alloc_fastpath, s->free_fastpath, |
439 | s->alloc_fastpath * 100 / total_alloc, | 439 | s->alloc_fastpath * 100 / total_alloc, |
440 | s->free_fastpath * 100 / total_free); | 440 | total_free ? s->free_fastpath * 100 / total_free : 0); |
441 | printf("Slowpath %8lu %8lu %3lu %3lu\n", | 441 | printf("Slowpath %8lu %8lu %3lu %3lu\n", |
442 | total_alloc - s->alloc_fastpath, s->free_slowpath, | 442 | total_alloc - s->alloc_fastpath, s->free_slowpath, |
443 | (total_alloc - s->alloc_fastpath) * 100 / total_alloc, | 443 | (total_alloc - s->alloc_fastpath) * 100 / total_alloc, |
444 | s->free_slowpath * 100 / total_free); | 444 | total_free ? s->free_slowpath * 100 / total_free : 0); |
445 | printf("Page Alloc %8lu %8lu %3lu %3lu\n", | 445 | printf("Page Alloc %8lu %8lu %3lu %3lu\n", |
446 | s->alloc_slab, s->free_slab, | 446 | s->alloc_slab, s->free_slab, |
447 | s->alloc_slab * 100 / total_alloc, | 447 | s->alloc_slab * 100 / total_alloc, |
448 | s->free_slab * 100 / total_free); | 448 | total_free ? s->free_slab * 100 / total_free : 0); |
449 | printf("Add partial %8lu %8lu %3lu %3lu\n", | 449 | printf("Add partial %8lu %8lu %3lu %3lu\n", |
450 | s->deactivate_to_head + s->deactivate_to_tail, | 450 | s->deactivate_to_head + s->deactivate_to_tail, |
451 | s->free_add_partial, | 451 | s->free_add_partial, |
452 | (s->deactivate_to_head + s->deactivate_to_tail) * 100 / total_alloc, | 452 | (s->deactivate_to_head + s->deactivate_to_tail) * 100 / total_alloc, |
453 | s->free_add_partial * 100 / total_free); | 453 | total_free ? s->free_add_partial * 100 / total_free : 0); |
454 | printf("Remove partial %8lu %8lu %3lu %3lu\n", | 454 | printf("Remove partial %8lu %8lu %3lu %3lu\n", |
455 | s->alloc_from_partial, s->free_remove_partial, | 455 | s->alloc_from_partial, s->free_remove_partial, |
456 | s->alloc_from_partial * 100 / total_alloc, | 456 | s->alloc_from_partial * 100 / total_alloc, |
457 | s->free_remove_partial * 100 / total_free); | 457 | total_free ? s->free_remove_partial * 100 / total_free : 0); |
458 | 458 | ||
459 | printf("Cpu partial list %8lu %8lu %3lu %3lu\n", | 459 | printf("Cpu partial list %8lu %8lu %3lu %3lu\n", |
460 | s->cpu_partial_alloc, s->cpu_partial_free, | 460 | s->cpu_partial_alloc, s->cpu_partial_free, |
461 | s->cpu_partial_alloc * 100 / total_alloc, | 461 | s->cpu_partial_alloc * 100 / total_alloc, |
462 | s->cpu_partial_free * 100 / total_free); | 462 | total_free ? s->cpu_partial_free * 100 / total_free : 0); |
463 | 463 | ||
464 | printf("RemoteObj/SlabFrozen %8lu %8lu %3lu %3lu\n", | 464 | printf("RemoteObj/SlabFrozen %8lu %8lu %3lu %3lu\n", |
465 | s->deactivate_remote_frees, s->free_frozen, | 465 | s->deactivate_remote_frees, s->free_frozen, |
466 | s->deactivate_remote_frees * 100 / total_alloc, | 466 | s->deactivate_remote_frees * 100 / total_alloc, |
467 | s->free_frozen * 100 / total_free); | 467 | total_free ? s->free_frozen * 100 / total_free : 0); |
468 | 468 | ||
469 | printf("Total %8lu %8lu\n\n", total_alloc, total_free); | 469 | printf("Total %8lu %8lu\n\n", total_alloc, total_free); |
470 | 470 | ||