dwarves_fprintf: Move cacheline_size into struct conf_fprintf
Remove the global variable and turn it into a member in struct conf_fprintf, so that it can be used by other parts of the code. Signed-off-by: Douglas Raillard <douglas.raillard@arm.com> Cc: dwarves@vger.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
parent
cdd088c05c
commit
772725a77d
4
codiff.c
4
codiff.c
|
@ -778,11 +778,13 @@ failure:
|
|||
goto out;
|
||||
}
|
||||
|
||||
if (dwarves__init(0)) {
|
||||
if (dwarves__init()) {
|
||||
fputs("codiff: insufficient memory\n", stderr);
|
||||
goto out;
|
||||
}
|
||||
|
||||
dwarves__resolve_cacheline_size(&conf_load, 0);
|
||||
|
||||
if (show_function_diffs == 0 && show_struct_diffs == 0 &&
|
||||
show_terse_type_changes == 0)
|
||||
show_function_diffs = show_struct_diffs = 1;
|
||||
|
|
|
@ -940,10 +940,11 @@ int main(int argc, char *argv[])
|
|||
FILE *fp_functions;
|
||||
int rc = EXIT_FAILURE;
|
||||
|
||||
if (dwarves__init(0)) {
|
||||
if (dwarves__init()) {
|
||||
fputs("ctracer: insufficient memory\n", stderr);
|
||||
goto out;
|
||||
}
|
||||
dwarves__resolve_cacheline_size(NULL, 0);
|
||||
|
||||
if (argp_parse(&ctracer__argp, argc, argv, 0, &remaining, NULL) ||
|
||||
remaining < argc) {
|
||||
|
|
|
@ -34,10 +34,11 @@ int main(int argc __maybe_unused, char *argv[])
|
|||
int err, rc = EXIT_FAILURE;
|
||||
struct cus *cus = cus__new();
|
||||
|
||||
if (dwarves__init(0) || cus == NULL) {
|
||||
if (dwarves__init() || cus == NULL) {
|
||||
fputs("dtagnames: insufficient memory\n", stderr);
|
||||
goto out;
|
||||
}
|
||||
dwarves__resolve_cacheline_size(NULL, 0);
|
||||
|
||||
err = cus__load_files(cus, NULL, argv + 1);
|
||||
if (err != 0) {
|
||||
|
|
|
@ -2458,12 +2458,8 @@ void cus__set_loader_exit(struct cus *cus, void (*loader_exit)(struct cus *cus))
|
|||
cus->loader_exit = loader_exit;
|
||||
}
|
||||
|
||||
void dwarves__fprintf_init(uint16_t user_cacheline_size);
|
||||
|
||||
int dwarves__init(uint16_t user_cacheline_size)
|
||||
int dwarves__init(void)
|
||||
{
|
||||
dwarves__fprintf_init(user_cacheline_size);
|
||||
|
||||
int i = 0;
|
||||
int err = 0;
|
||||
|
||||
|
|
|
@ -100,6 +100,7 @@ struct conf_fprintf {
|
|||
const char *header_type;
|
||||
const char *range;
|
||||
uint32_t skip;
|
||||
uint16_t cacheline_size;
|
||||
uint8_t indent;
|
||||
uint8_t expand_types:1;
|
||||
uint8_t expand_pointers:1;
|
||||
|
@ -573,7 +574,7 @@ void tag__not_found_die(const char *file, int line, const char *func);
|
|||
__LINE__, __func__); } while (0)
|
||||
|
||||
size_t tag__size(const struct tag *tag, const struct cu *cu);
|
||||
size_t tag__nr_cachelines(const struct tag *tag, const struct cu *cu);
|
||||
size_t tag__nr_cachelines(const struct conf_fprintf *conf, const struct tag *tag, const struct cu *cu);
|
||||
struct tag *tag__follow_typedef(const struct tag *tag, const struct cu *cu);
|
||||
struct tag *tag__strip_typedefs_and_modifiers(const struct tag *tag, const struct cu *cu);
|
||||
|
||||
|
@ -1336,8 +1337,9 @@ void enumeration__add(struct type *type, struct enumerator *enumerator);
|
|||
size_t enumeration__fprintf(const struct tag *tag_enum,
|
||||
const struct conf_fprintf *conf, FILE *fp);
|
||||
|
||||
int dwarves__init(uint16_t user_cacheline_size);
|
||||
int dwarves__init(void);
|
||||
void dwarves__exit(void);
|
||||
void dwarves__resolve_cacheline_size(const struct conf_load *conf, uint16_t user_cacheline_size);
|
||||
|
||||
const char *dwarf_tag_name(const uint32_t tag);
|
||||
|
||||
|
|
|
@ -127,7 +127,7 @@ const char *dwarf_tag_name(const uint32_t tag)
|
|||
return "INVALID";
|
||||
}
|
||||
|
||||
static const struct conf_fprintf conf_fprintf__defaults = {
|
||||
static struct conf_fprintf conf_fprintf__defaults = {
|
||||
.name_spacing = 23,
|
||||
.type_spacing = 26,
|
||||
.emit_stats = 1,
|
||||
|
@ -135,11 +135,10 @@ static const struct conf_fprintf conf_fprintf__defaults = {
|
|||
|
||||
const char tabs[] = "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
|
||||
|
||||
static size_t cacheline_size;
|
||||
|
||||
size_t tag__nr_cachelines(const struct tag *tag, const struct cu *cu)
|
||||
size_t tag__nr_cachelines(const struct conf_fprintf *conf, const struct tag *tag, const struct cu *cu)
|
||||
{
|
||||
return (tag__size(tag, cu) + cacheline_size - 1) / cacheline_size;
|
||||
return (tag__size(tag, cu) + conf->cacheline_size - 1) / conf->cacheline_size;
|
||||
}
|
||||
|
||||
static const char *tag__accessibility(const struct tag *tag)
|
||||
|
@ -611,7 +610,7 @@ static size_t type__fprintf_stats(struct type *type, const struct cu *cu,
|
|||
{
|
||||
size_t printed = fprintf(fp, "\n%.*s/* size: %d, cachelines: %zd, members: %u",
|
||||
conf->indent, tabs, type->size,
|
||||
tag__nr_cachelines(type__tag(type), cu), type->nr_members);
|
||||
tag__nr_cachelines(conf, type__tag(type), cu), type->nr_members);
|
||||
|
||||
if (type->nr_static_members != 0)
|
||||
printed += fprintf(fp, ", static members: %u */\n", type->nr_static_members);
|
||||
|
@ -1304,11 +1303,11 @@ static size_t class__fprintf_cacheline_boundary(struct conf_fprintf *conf,
|
|||
FILE *fp)
|
||||
{
|
||||
int indent = conf->indent;
|
||||
uint32_t cacheline = offset / cacheline_size;
|
||||
uint32_t cacheline = offset / conf->cacheline_size;
|
||||
size_t printed = 0;
|
||||
|
||||
if (cacheline > *conf->cachelinep) {
|
||||
const uint32_t cacheline_pos = offset % cacheline_size;
|
||||
const uint32_t cacheline_pos = offset % conf->cacheline_size;
|
||||
const uint32_t cacheline_in_bytes = offset - cacheline_pos;
|
||||
|
||||
if (cacheline_pos == 0)
|
||||
|
@ -1750,7 +1749,7 @@ static size_t __class__fprintf(struct class *class, const struct cu *cu,
|
|||
}
|
||||
printed += fprintf(fp, " */\n");
|
||||
}
|
||||
cacheline = (cconf.base_offset + type->size) % cacheline_size;
|
||||
cacheline = (cconf.base_offset + type->size) % conf->cacheline_size;
|
||||
if (cacheline != 0)
|
||||
printed += fprintf(fp, "%.*s/* last cacheline: %u bytes */\n",
|
||||
cconf.indent, tabs,
|
||||
|
@ -1977,15 +1976,22 @@ static long cacheline__size(void)
|
|||
#endif
|
||||
}
|
||||
|
||||
void dwarves__fprintf_init(uint16_t user_cacheline_size)
|
||||
void dwarves__resolve_cacheline_size(const struct conf_load *conf, uint16_t user_cacheline_size)
|
||||
{
|
||||
uint16_t size;
|
||||
|
||||
if (user_cacheline_size == 0) {
|
||||
long sys_cacheline_size = cacheline__size();
|
||||
|
||||
if (sys_cacheline_size > 0)
|
||||
cacheline_size = sys_cacheline_size;
|
||||
size = sys_cacheline_size;
|
||||
else
|
||||
cacheline_size = 64; /* Fall back to a sane value */
|
||||
size = 64; /* Fall back to a sane value */
|
||||
} else
|
||||
cacheline_size = user_cacheline_size;
|
||||
size = user_cacheline_size;
|
||||
|
||||
if (conf)
|
||||
conf->conf_fprintf->cacheline_size = size;
|
||||
|
||||
conf_fprintf__defaults.cacheline_size = size;
|
||||
}
|
||||
|
|
8
pahole.c
8
pahole.c
|
@ -1692,8 +1692,8 @@ static void do_reorg(struct tag *class, struct cu *cu)
|
|||
tag__fprintf(class__tag(clone), cu, &conf, stdout);
|
||||
if (savings != 0) {
|
||||
const size_t cacheline_savings =
|
||||
(tag__nr_cachelines(class, cu) -
|
||||
tag__nr_cachelines(class__tag(clone), cu));
|
||||
(tag__nr_cachelines(&conf, class, cu) -
|
||||
tag__nr_cachelines(&conf, class__tag(clone), cu));
|
||||
|
||||
printf(" /* saved %d byte%s", savings,
|
||||
savings != 1 ? "s" : "");
|
||||
|
@ -3156,11 +3156,13 @@ int main(int argc, char *argv[])
|
|||
goto out;
|
||||
}
|
||||
|
||||
if (dwarves__init(cacheline_size)) {
|
||||
if (dwarves__init()) {
|
||||
fputs("pahole: insufficient memory\n", stderr);
|
||||
goto out;
|
||||
}
|
||||
|
||||
dwarves__resolve_cacheline_size(&conf_load, cacheline_size);
|
||||
|
||||
if (prettify_input_filename) {
|
||||
if (strcmp(prettify_input_filename, "-") == 0) {
|
||||
prettify_input = stdin;
|
||||
|
|
|
@ -131,11 +131,13 @@ int main(int argc, char *argv[])
|
|||
int remaining, rc = EXIT_FAILURE, err;
|
||||
struct cus *cus = cus__new();
|
||||
|
||||
if (dwarves__init(0) || cus == NULL) {
|
||||
if (dwarves__init() || cus == NULL) {
|
||||
fputs("pwdtags: insufficient memory\n", stderr);
|
||||
goto out;
|
||||
}
|
||||
|
||||
dwarves__resolve_cacheline_size(&pdwtags_conf_load, 0);
|
||||
|
||||
if (argp_parse(&pdwtags__argp, argc, argv, 0, &remaining, NULL) ||
|
||||
remaining == argc) {
|
||||
argp_help(&pdwtags__argp, stderr, ARGP_HELP_SEE, argv[0]);
|
||||
|
|
4
pfunct.c
4
pfunct.c
|
@ -721,11 +721,13 @@ int main(int argc, char *argv[])
|
|||
if (symtab_name != NULL)
|
||||
return elf_symtabs__show(argv + remaining);
|
||||
|
||||
if (dwarves__init(0)) {
|
||||
if (dwarves__init()) {
|
||||
fputs("pfunct: insufficient memory\n", stderr);
|
||||
goto out;
|
||||
}
|
||||
|
||||
dwarves__resolve_cacheline_size(&conf_load, 0);
|
||||
|
||||
struct cus *cus = cus__new();
|
||||
if (cus == NULL) {
|
||||
fputs("pfunct: insufficient memory\n", stderr);
|
||||
|
|
|
@ -303,11 +303,13 @@ int main(int argc, char *argv[])
|
|||
goto out;
|
||||
}
|
||||
|
||||
if (dwarves__init(0)) {
|
||||
if (dwarves__init()) {
|
||||
fputs("pglobal: insufficient memory\n", stderr);
|
||||
goto out;
|
||||
}
|
||||
|
||||
dwarves__resolve_cacheline_size(&conf_load, 0);
|
||||
|
||||
struct cus *cus = cus__new();
|
||||
if (cus == NULL) {
|
||||
fputs("pglobal: insufficient memory\n", stderr);
|
||||
|
|
|
@ -136,11 +136,13 @@ int main(int argc __maybe_unused, char *argv[])
|
|||
int err;
|
||||
struct cus *cus = cus__new();
|
||||
|
||||
if (dwarves__init(0) || cus == NULL) {
|
||||
if (dwarves__init() || cus == NULL) {
|
||||
fputs("prefcnt: insufficient memory\n", stderr);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
dwarves__resolve_cacheline_size(NULL, 0);
|
||||
|
||||
err = cus__load_files(cus, NULL, argv + 1);
|
||||
if (err != 0) {
|
||||
cus__fprintf_load_files_err(cus, "prefcnt", argv + 1, err, stderr);
|
||||
|
|
Loading…
Reference in New Issue