diff options
author | Namhyung Kim <namhyung@kernel.org> | 2015-05-20 12:03:39 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2015-05-27 11:21:44 -0400 |
commit | 71ff824a60a7b0d9d0746e6e237fe4735077e5b4 (patch) | |
tree | 573fd8686995d141c6f62105264cbce8c848de3a /tools/perf | |
parent | 8e160b2e1e3efdd84ddef726f9b5136dd192a682 (diff) |
perf tools: Fix dso__data_read_offset() file opening
When dso__data_read_offset/addr() is called without prior dso__data_fd()
(or other functions which call it internally), it failed to open dso in
data_file_size() since its binary type was not identified.
However calling dso__data_fd() in dso__data_read_offset() will hurt
performance as it grabs a global lock everytime. So factor out the loop
on the binary type in dso__data_fd(), and call it from both.
Reported-by: Adrian Hunter <adrian.hunter@intel.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Acked-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1432137821-10853-1-git-send-email-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf')
-rw-r--r-- | tools/perf/util/dso.c | 59 |
1 files changed, 32 insertions, 27 deletions
diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c index 1b96c8d18435..516e0c25ea16 100644 --- a/tools/perf/util/dso.c +++ b/tools/perf/util/dso.c | |||
@@ -440,15 +440,7 @@ void dso__data_close(struct dso *dso) | |||
440 | pthread_mutex_unlock(&dso__data_open_lock); | 440 | pthread_mutex_unlock(&dso__data_open_lock); |
441 | } | 441 | } |
442 | 442 | ||
443 | /** | 443 | static void try_to_open_dso(struct dso *dso, struct machine *machine) |
444 | * dso__data_fd - Get dso's data file descriptor | ||
445 | * @dso: dso object | ||
446 | * @machine: machine object | ||
447 | * | ||
448 | * External interface to find dso's file, open it and | ||
449 | * returns file descriptor. | ||
450 | */ | ||
451 | int dso__data_fd(struct dso *dso, struct machine *machine) | ||
452 | { | 444 | { |
453 | enum dso_binary_type binary_type_data[] = { | 445 | enum dso_binary_type binary_type_data[] = { |
454 | DSO_BINARY_TYPE__BUILD_ID_CACHE, | 446 | DSO_BINARY_TYPE__BUILD_ID_CACHE, |
@@ -457,13 +449,8 @@ int dso__data_fd(struct dso *dso, struct machine *machine) | |||
457 | }; | 449 | }; |
458 | int i = 0; | 450 | int i = 0; |
459 | 451 | ||
460 | if (dso->data.status == DSO_DATA_STATUS_ERROR) | ||
461 | return -1; | ||
462 | |||
463 | pthread_mutex_lock(&dso__data_open_lock); | ||
464 | |||
465 | if (dso->data.fd >= 0) | 452 | if (dso->data.fd >= 0) |
466 | goto out; | 453 | return; |
467 | 454 | ||
468 | if (dso->binary_type != DSO_BINARY_TYPE__NOT_FOUND) { | 455 | if (dso->binary_type != DSO_BINARY_TYPE__NOT_FOUND) { |
469 | dso->data.fd = open_dso(dso, machine); | 456 | dso->data.fd = open_dso(dso, machine); |
@@ -483,8 +470,25 @@ out: | |||
483 | dso->data.status = DSO_DATA_STATUS_OK; | 470 | dso->data.status = DSO_DATA_STATUS_OK; |
484 | else | 471 | else |
485 | dso->data.status = DSO_DATA_STATUS_ERROR; | 472 | dso->data.status = DSO_DATA_STATUS_ERROR; |
473 | } | ||
474 | |||
475 | /** | ||
476 | * dso__data_fd - Get dso's data file descriptor | ||
477 | * @dso: dso object | ||
478 | * @machine: machine object | ||
479 | * | ||
480 | * External interface to find dso's file, open it and | ||
481 | * returns file descriptor. | ||
482 | */ | ||
483 | int dso__data_fd(struct dso *dso, struct machine *machine) | ||
484 | { | ||
485 | if (dso->data.status == DSO_DATA_STATUS_ERROR) | ||
486 | return -1; | ||
486 | 487 | ||
488 | pthread_mutex_lock(&dso__data_open_lock); | ||
489 | try_to_open_dso(dso, machine); | ||
487 | pthread_mutex_unlock(&dso__data_open_lock); | 490 | pthread_mutex_unlock(&dso__data_open_lock); |
491 | |||
488 | return dso->data.fd; | 492 | return dso->data.fd; |
489 | } | 493 | } |
490 | 494 | ||
@@ -609,13 +613,12 @@ dso_cache__read(struct dso *dso, struct machine *machine, | |||
609 | * dso->data.fd might be closed if other thread opened another | 613 | * dso->data.fd might be closed if other thread opened another |
610 | * file (dso) due to open file limit (RLIMIT_NOFILE). | 614 | * file (dso) due to open file limit (RLIMIT_NOFILE). |
611 | */ | 615 | */ |
616 | try_to_open_dso(dso, machine); | ||
617 | |||
612 | if (dso->data.fd < 0) { | 618 | if (dso->data.fd < 0) { |
613 | dso->data.fd = open_dso(dso, machine); | 619 | ret = -errno; |
614 | if (dso->data.fd < 0) { | 620 | dso->data.status = DSO_DATA_STATUS_ERROR; |
615 | ret = -errno; | 621 | break; |
616 | dso->data.status = DSO_DATA_STATUS_ERROR; | ||
617 | break; | ||
618 | } | ||
619 | } | 622 | } |
620 | 623 | ||
621 | cache_offset = offset & DSO__DATA_CACHE_MASK; | 624 | cache_offset = offset & DSO__DATA_CACHE_MASK; |
@@ -702,19 +705,21 @@ static int data_file_size(struct dso *dso, struct machine *machine) | |||
702 | if (dso->data.file_size) | 705 | if (dso->data.file_size) |
703 | return 0; | 706 | return 0; |
704 | 707 | ||
708 | if (dso->data.status == DSO_DATA_STATUS_ERROR) | ||
709 | return -1; | ||
710 | |||
705 | pthread_mutex_lock(&dso__data_open_lock); | 711 | pthread_mutex_lock(&dso__data_open_lock); |
706 | 712 | ||
707 | /* | 713 | /* |
708 | * dso->data.fd might be closed if other thread opened another | 714 | * dso->data.fd might be closed if other thread opened another |
709 | * file (dso) due to open file limit (RLIMIT_NOFILE). | 715 | * file (dso) due to open file limit (RLIMIT_NOFILE). |
710 | */ | 716 | */ |
717 | try_to_open_dso(dso, machine); | ||
718 | |||
711 | if (dso->data.fd < 0) { | 719 | if (dso->data.fd < 0) { |
712 | dso->data.fd = open_dso(dso, machine); | 720 | ret = -errno; |
713 | if (dso->data.fd < 0) { | 721 | dso->data.status = DSO_DATA_STATUS_ERROR; |
714 | ret = -errno; | 722 | goto out; |
715 | dso->data.status = DSO_DATA_STATUS_ERROR; | ||
716 | goto out; | ||
717 | } | ||
718 | } | 723 | } |
719 | 724 | ||
720 | if (fstat(dso->data.fd, &st) < 0) { | 725 | if (fstat(dso->data.fd, &st) < 0) { |