Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf probe: Replace line_list with intlist

Replace line_list (struct line_node) with intlist for reducing similar
codes.

Signed-off-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: "David A. Long" <dave.long@linaro.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: yrl.pp-manager.tt@hitachi.com
Link: http://lkml.kernel.org/r/20140206053209.29635.81043.stgit@kbuild-fedora.yrl.intra.hitachi.co.jp
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Masami Hiramatsu and committed by
Arnaldo Carvalho de Melo
5a62257a f49540b1

+35 -95
+7 -5
tools/perf/builtin-probe.c
··· 268 268 return 0; 269 269 } 270 270 271 - static void init_params(void) 271 + static int init_params(void) 272 272 { 273 - line_range__init(&params.line_range); 273 + return line_range__init(&params.line_range); 274 274 } 275 275 276 276 static void cleanup_params(void) ··· 515 515 { 516 516 int ret; 517 517 518 - init_params(); 519 - ret = __cmd_probe(argc, argv, prefix); 520 - cleanup_params(); 518 + ret = init_params(); 519 + if (!ret) { 520 + ret = __cmd_probe(argc, argv, prefix); 521 + cleanup_params(); 522 + } 521 523 522 524 return ret; 523 525 }
+10 -12
tools/perf/util/probe-event.c
··· 561 561 static int __show_line_range(struct line_range *lr, const char *module) 562 562 { 563 563 int l = 1; 564 - struct line_node *ln; 564 + struct int_node *ln; 565 565 struct debuginfo *dinfo; 566 566 FILE *fp; 567 567 int ret; ··· 614 614 goto end; 615 615 } 616 616 617 - list_for_each_entry(ln, &lr->line_list, list) { 618 - for (; ln->line > l; l++) { 617 + intlist__for_each(ln, lr->line_list) { 618 + for (; ln->i > l; l++) { 619 619 ret = show_one_line(fp, l - lr->offset); 620 620 if (ret < 0) 621 621 goto end; ··· 775 775 776 776 void line_range__clear(struct line_range *lr) 777 777 { 778 - struct line_node *ln; 779 - 780 778 free(lr->function); 781 779 free(lr->file); 782 780 free(lr->path); 783 781 free(lr->comp_dir); 784 - while (!list_empty(&lr->line_list)) { 785 - ln = list_first_entry(&lr->line_list, struct line_node, list); 786 - list_del(&ln->list); 787 - free(ln); 788 - } 782 + intlist__delete(lr->line_list); 789 783 memset(lr, 0, sizeof(*lr)); 790 784 } 791 785 792 - void line_range__init(struct line_range *lr) 786 + int line_range__init(struct line_range *lr) 793 787 { 794 788 memset(lr, 0, sizeof(*lr)); 795 - INIT_LIST_HEAD(&lr->line_list); 789 + lr->line_list = intlist__new(NULL); 790 + if (!lr->line_list) 791 + return -ENOMEM; 792 + else 793 + return 0; 796 794 } 797 795 798 796 static int parse_line_num(char **ptr, int *val, const char *what)
+3 -9
tools/perf/util/probe-event.h
··· 2 2 #define _PROBE_EVENT_H 3 3 4 4 #include <stdbool.h> 5 + #include "intlist.h" 5 6 #include "strlist.h" 6 7 #include "strfilter.h" 7 8 ··· 77 76 struct perf_probe_arg *args; /* Arguments */ 78 77 }; 79 78 80 - 81 - /* Line number container */ 82 - struct line_node { 83 - struct list_head list; 84 - int line; 85 - }; 86 - 87 79 /* Line range */ 88 80 struct line_range { 89 81 char *file; /* File name */ ··· 86 92 int offset; /* Start line offset */ 87 93 char *path; /* Real path name */ 88 94 char *comp_dir; /* Compile directory */ 89 - struct list_head line_list; /* Visible lines */ 95 + struct intlist *line_list; /* Visible lines */ 90 96 }; 91 97 92 98 /* List of variables */ ··· 118 124 extern void line_range__clear(struct line_range *lr); 119 125 120 126 /* Initialize line range */ 121 - extern void line_range__init(struct line_range *lr); 127 + extern int line_range__init(struct line_range *lr); 122 128 123 129 /* Internal use: Return kernel/module path */ 124 130 extern const char *kernel_get_module_path(const char *module);
+13 -68
tools/perf/util/probe-finder.c
··· 35 35 #include <linux/bitops.h> 36 36 #include "event.h" 37 37 #include "debug.h" 38 + #include "intlist.h" 38 39 #include "util.h" 39 40 #include "symbol.h" 40 41 #include "probe-finder.h" 41 42 42 43 /* Kprobe tracer basic type is up to u64 */ 43 44 #define MAX_BASIC_TYPE_BITS 64 44 - 45 - /* Line number list operations */ 46 - 47 - /* Add a line to line number list */ 48 - static int line_list__add_line(struct list_head *head, int line) 49 - { 50 - struct line_node *ln; 51 - struct list_head *p; 52 - 53 - /* Reverse search, because new line will be the last one */ 54 - list_for_each_entry_reverse(ln, head, list) { 55 - if (ln->line < line) { 56 - p = &ln->list; 57 - goto found; 58 - } else if (ln->line == line) /* Already exist */ 59 - return 1; 60 - } 61 - /* List is empty, or the smallest entry */ 62 - p = head; 63 - found: 64 - pr_debug("line list: add a line %u\n", line); 65 - ln = zalloc(sizeof(struct line_node)); 66 - if (ln == NULL) 67 - return -ENOMEM; 68 - ln->line = line; 69 - INIT_LIST_HEAD(&ln->list); 70 - list_add(&ln->list, p); 71 - return 0; 72 - } 73 - 74 - /* Check if the line in line number list */ 75 - static int line_list__has_line(struct list_head *head, int line) 76 - { 77 - struct line_node *ln; 78 - 79 - /* Reverse search, because new line will be the last one */ 80 - list_for_each_entry(ln, head, list) 81 - if (ln->line == line) 82 - return 1; 83 - 84 - return 0; 85 - } 86 - 87 - /* Init line number list */ 88 - static void line_list__init(struct list_head *head) 89 - { 90 - INIT_LIST_HEAD(head); 91 - } 92 - 93 - /* Free line number list */ 94 - static void line_list__free(struct list_head *head) 95 - { 96 - struct line_node *ln; 97 - while (!list_empty(head)) { 98 - ln = list_first_entry(head, struct line_node, list); 99 - list_del(&ln->list); 100 - free(ln); 101 - } 102 - } 103 45 104 46 /* Dwarf FL wrappers */ 105 47 static char *debuginfo_path; /* Currently dummy */ ··· 822 880 } 823 881 824 882 /* Find lines which match lazy pattern */ 825 - static int find_lazy_match_lines(struct list_head *head, 883 + static int find_lazy_match_lines(struct intlist *list, 826 884 const char *fname, const char *pat) 827 885 { 828 886 FILE *fp; ··· 843 901 line[len - 1] = '\0'; 844 902 845 903 if (strlazymatch(line, pat)) { 846 - line_list__add_line(head, linenum); 904 + intlist__add(list, linenum); 847 905 count++; 848 906 } 849 907 linenum++; ··· 866 924 Dwarf_Die *sc_die, die_mem; 867 925 int ret; 868 926 869 - if (!line_list__has_line(&pf->lcache, lineno) || 927 + if (!intlist__has_entry(pf->lcache, lineno) || 870 928 strtailcmp(fname, pf->fname) != 0) 871 929 return 0; 872 930 ··· 894 952 { 895 953 int ret = 0; 896 954 897 - if (list_empty(&pf->lcache)) { 955 + if (intlist__empty(pf->lcache)) { 898 956 /* Matching lazy line pattern */ 899 - ret = find_lazy_match_lines(&pf->lcache, pf->fname, 957 + ret = find_lazy_match_lines(pf->lcache, pf->fname, 900 958 pf->pev->point.lazy_line); 901 959 if (ret <= 0) 902 960 return ret; ··· 1038 1096 #endif 1039 1097 1040 1098 off = 0; 1041 - line_list__init(&pf->lcache); 1099 + pf->lcache = intlist__new(NULL); 1100 + if (!pf->lcache) 1101 + return -ENOMEM; 1042 1102 1043 1103 /* Fastpath: lookup by function name from .debug_pubnames section */ 1044 1104 if (pp->function) { ··· 1093 1149 } 1094 1150 1095 1151 found: 1096 - line_list__free(&pf->lcache); 1152 + intlist__delete(pf->lcache); 1153 + pf->lcache = NULL; 1097 1154 1098 1155 return ret; 1099 1156 } ··· 1482 1537 if (lr->path == NULL) 1483 1538 return -ENOMEM; 1484 1539 } 1485 - return line_list__add_line(&lr->line_list, lineno); 1540 + return intlist__add(lr->line_list, lineno); 1486 1541 } 1487 1542 1488 1543 static int line_range_walk_cb(const char *fname, int lineno, ··· 1510 1565 1511 1566 /* Update status */ 1512 1567 if (ret >= 0) 1513 - if (!list_empty(&lf->lr->line_list)) 1568 + if (!intlist__empty(lf->lr->line_list)) 1514 1569 ret = lf->found = 1; 1515 1570 else 1516 1571 ret = 0; /* Lines are not found */
+2 -1
tools/perf/util/probe-finder.h
··· 3 3 4 4 #include <stdbool.h> 5 5 #include "util.h" 6 + #include "intlist.h" 6 7 #include "probe-event.h" 7 8 8 9 #define MAX_PROBE_BUFFER 1024 ··· 67 66 const char *fname; /* Real file name */ 68 67 Dwarf_Die cu_die; /* Current CU */ 69 68 Dwarf_Die sp_die; 70 - struct list_head lcache; /* Line cache for lazy match */ 69 + struct intlist *lcache; /* Line cache for lazy match */ 71 70 72 71 /* For variable searching */ 73 72 #if _ELFUTILS_PREREQ(0, 142)