[tip:perf/core] perf dso: Separate generic code in dso_cache__read
From: tip-bot for Jiri Olsa
Date: Thu May 30 2019 - 04:12:59 EST
Commit-ID: ea5db1bd5a04b865bc86bb8e3267c27939dfb5ee
Gitweb: https://git.kernel.org/tip/ea5db1bd5a04b865bc86bb8e3267c27939dfb5ee
Author: Jiri Olsa <jolsa@xxxxxxxxxx>
AuthorDate: Wed, 8 May 2019 15:20:00 +0200
Committer: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
CommitDate: Tue, 28 May 2019 18:37:44 -0300
perf dso: Separate generic code in dso_cache__read
Move the file specific code in the dso_cache__read function to a
separate file_read function. I'll add BPF specific code in the following
patches.
Signed-off-by: Jiri Olsa <jolsa@xxxxxxxxxx>
Acked-by: Song Liu <songliubraving@xxxxxx>
Cc: Adrian Hunter <adrian.hunter@xxxxxxxxx>
Cc: Alexander Shishkin <alexander.shishkin@xxxxxxxxxxxxxxx>
Cc: Andi Kleen <ak@xxxxxxxxxxxxxxx>
Cc: Namhyung Kim <namhyung@xxxxxxxxxx>
Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
Cc: Stanislav Fomichev <sdf@xxxxxxxxxx>
Link: http://lkml.kernel.org/r/20190508132010.14512-3-jolsa@xxxxxxxxxx
Signed-off-by: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
---
tools/perf/util/dso.c | 48 +++++++++++++++++++++++++++---------------------
1 file changed, 27 insertions(+), 21 deletions(-)
diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c
index cb6199c1390a..7734f50a6912 100644
--- a/tools/perf/util/dso.c
+++ b/tools/perf/util/dso.c
@@ -794,6 +794,31 @@ dso_cache__memcpy(struct dso_cache *cache, u64 offset,
return cache_size;
}
+static ssize_t file_read(struct dso *dso, struct machine *machine,
+ u64 offset, char *data)
+{
+ ssize_t ret;
+
+ pthread_mutex_lock(&dso__data_open_lock);
+
+ /*
+ * dso->data.fd might be closed if other thread opened another
+ * file (dso) due to open file limit (RLIMIT_NOFILE).
+ */
+ try_to_open_dso(dso, machine);
+
+ if (dso->data.fd < 0) {
+ dso->data.status = DSO_DATA_STATUS_ERROR;
+ ret = -errno;
+ goto out;
+ }
+
+ ret = pread(dso->data.fd, data, DSO__DATA_CACHE_SIZE, offset);
+out:
+ pthread_mutex_unlock(&dso__data_open_lock);
+ return ret;
+}
+
static ssize_t
dso_cache__read(struct dso *dso, struct machine *machine,
u64 offset, u8 *data, ssize_t size)
@@ -803,37 +828,18 @@ dso_cache__read(struct dso *dso, struct machine *machine,
ssize_t ret;
do {
- u64 cache_offset;
+ u64 cache_offset = offset & DSO__DATA_CACHE_MASK;
cache = zalloc(sizeof(*cache) + DSO__DATA_CACHE_SIZE);
if (!cache)
return -ENOMEM;
- pthread_mutex_lock(&dso__data_open_lock);
-
- /*
- * dso->data.fd might be closed if other thread opened another
- * file (dso) due to open file limit (RLIMIT_NOFILE).
- */
- try_to_open_dso(dso, machine);
-
- if (dso->data.fd < 0) {
- ret = -errno;
- dso->data.status = DSO_DATA_STATUS_ERROR;
- break;
- }
-
- cache_offset = offset & DSO__DATA_CACHE_MASK;
-
- ret = pread(dso->data.fd, cache->data, DSO__DATA_CACHE_SIZE, cache_offset);
- if (ret <= 0)
- break;
+ ret = file_read(dso, machine, cache_offset, cache->data);
cache->offset = cache_offset;
cache->size = ret;
} while (0);
- pthread_mutex_unlock(&dso__data_open_lock);
if (ret > 0) {
old = dso_cache__insert(dso, cache);