Skip to content

Commit 53fa8ea

Browse files
committed
perf tools: Add data_fd into dso object
Adding data_fd into dso object so we could handle caching of opened dso file data descriptors coming int next patches. Adding dso__data_close interface to keep the data_fd updated when the descriptor is closed. Acked-by: Namhyung Kim <namhyung@kernel.org> Cc: Arnaldo Carvalho de Melo <acme@kernel.org> Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com> Cc: David Ahern <dsahern@gmail.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Ingo Molnar <mingo@kernel.org> Cc: Jean Pihet <jean.pihet@linaro.org> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Link: http://lkml.kernel.org/r/1401892622-30848-4-git-send-email-jolsa@kernel.org Signed-off-by: Jiri Olsa <jolsa@kernel.org>
1 parent ca40e2a commit 53fa8ea

3 files changed

Lines changed: 24 additions & 6 deletions

File tree

‎tools/perf/util/dso.c‎

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,14 @@ static int open_dso(struct dso *dso, struct machine *machine)
159159
return fd;
160160
}
161161

162+
void dso__data_close(struct dso *dso)
163+
{
164+
if (dso->data.fd >= 0) {
165+
close(dso->data.fd);
166+
dso->data.fd = -1;
167+
}
168+
}
169+
162170
int dso__data_fd(struct dso *dso, struct machine *machine)
163171
{
164172
enum dso_binary_type binary_type_data[] = {
@@ -168,8 +176,13 @@ int dso__data_fd(struct dso *dso, struct machine *machine)
168176
};
169177
int i = 0;
170178

171-
if (dso->binary_type != DSO_BINARY_TYPE__NOT_FOUND)
172-
return open_dso(dso, machine);
179+
if (dso->data.fd >= 0)
180+
return dso->data.fd;
181+
182+
if (dso->binary_type != DSO_BINARY_TYPE__NOT_FOUND) {
183+
dso->data.fd = open_dso(dso, machine);
184+
return dso->data.fd;
185+
}
173186

174187
do {
175188
int fd;
@@ -178,7 +191,7 @@ int dso__data_fd(struct dso *dso, struct machine *machine)
178191

179192
fd = open_dso(dso, machine);
180193
if (fd >= 0)
181-
return fd;
194+
return dso->data.fd = fd;
182195

183196
} while (dso->binary_type != DSO_BINARY_TYPE__NOT_FOUND);
184197

@@ -301,7 +314,7 @@ dso_cache__read(struct dso *dso, struct machine *machine,
301314
if (ret <= 0)
302315
free(cache);
303316

304-
close(fd);
317+
dso__data_close(dso);
305318
return ret;
306319
}
307320

@@ -474,6 +487,7 @@ struct dso *dso__new(const char *name)
474487
for (i = 0; i < MAP__NR_TYPES; ++i)
475488
dso->symbols[i] = dso->symbol_names[i] = RB_ROOT;
476489
dso->data.cache = RB_ROOT;
490+
dso->data.fd = -1;
477491
dso->symtab_type = DSO_BINARY_TYPE__NOT_FOUND;
478492
dso->binary_type = DSO_BINARY_TYPE__NOT_FOUND;
479493
dso->loaded = 0;
@@ -506,6 +520,7 @@ void dso__delete(struct dso *dso)
506520
dso->long_name_allocated = false;
507521
}
508522

523+
dso__data_close(dso);
509524
dso_cache__free(&dso->data.cache);
510525
dso__free_a2l(dso);
511526
zfree(&dso->symsrc_filename);

‎tools/perf/util/dso.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ struct dso {
102102
/* dso data file */
103103
struct {
104104
struct rb_root cache;
105+
int fd;
105106
} data;
106107

107108
char name[0];
@@ -147,6 +148,8 @@ int dso__read_binary_type_filename(const struct dso *dso, enum dso_binary_type t
147148
char *root_dir, char *filename, size_t size);
148149

149150
int dso__data_fd(struct dso *dso, struct machine *machine);
151+
void dso__data_close(struct dso *dso);
152+
150153
ssize_t dso__data_read_offset(struct dso *dso, struct machine *machine,
151154
u64 offset, u8 *data, ssize_t size);
152155
ssize_t dso__data_read_addr(struct dso *dso, struct map *map,

‎tools/perf/util/unwind-libunwind.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ static int read_unwind_spec_eh_frame(struct dso *dso, struct machine *machine,
250250

251251
/* Check the .eh_frame section for unwinding info */
252252
offset = elf_section_offset(fd, ".eh_frame_hdr");
253-
close(fd);
253+
dso__data_close(dso);
254254

255255
if (offset)
256256
ret = unwind_spec_ehframe(dso, machine, offset,
@@ -271,7 +271,7 @@ static int read_unwind_spec_debug_frame(struct dso *dso,
271271

272272
/* Check the .debug_frame section for unwinding info */
273273
*offset = elf_section_offset(fd, ".debug_frame");
274-
close(fd);
274+
dso__data_close(dso);
275275

276276
if (*offset)
277277
return 0;

0 commit comments

Comments
 (0)