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

perf config: Call perf_config__init() lazily

We check what perf_config__init() does at each perf_config() call,
namely if the static perf_config instance was created, so instead of
bailing out in that case, try to allocate it, bailing if it fails.

Now to get the perf_config() call out of the start of perf's main()
function, doing it also lazily.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Taeung Song <treeze.taeung@gmail.com>
Cc: Wang Nan <wangnan0@huawei.com>
Link: https://lkml.kernel.org/n/tip-4bo45k6ivsmbxpfpdte4orsg@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

+9 -9
-1
tools/perf/perf.c
··· 458 458 459 459 srandom(time(NULL)); 460 460 461 - perf_config__init(); 462 461 err = perf_config(perf_default_config, NULL); 463 462 if (err) 464 463 return err;
+9 -7
tools/perf/util/config.c
··· 707 707 return set; 708 708 } 709 709 710 + static int perf_config__init(void) 711 + { 712 + if (config_set == NULL) 713 + config_set = perf_config_set__new(); 714 + 715 + return config_set == NULL; 716 + } 717 + 710 718 int perf_config(config_fn_t fn, void *data) 711 719 { 712 720 int ret = 0; ··· 722 714 struct perf_config_section *section; 723 715 struct perf_config_item *item; 724 716 725 - if (config_set == NULL) 717 + if (config_set == NULL && perf_config__init()) 726 718 return -1; 727 719 728 720 perf_config_set__for_each_entry(config_set, section, item) { ··· 741 733 } 742 734 743 735 return ret; 744 - } 745 - 746 - void perf_config__init(void) 747 - { 748 - if (config_set == NULL) 749 - config_set = perf_config_set__new(); 750 736 } 751 737 752 738 void perf_config__exit(void)
-1
tools/perf/util/config.h
··· 38 38 void perf_config_set__delete(struct perf_config_set *set); 39 39 int perf_config_set__collect(struct perf_config_set *set, const char *file_name, 40 40 const char *var, const char *value); 41 - void perf_config__init(void); 42 41 void perf_config__exit(void); 43 42 void perf_config__refresh(void); 44 43