Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp459748ybi; Thu, 30 May 2019 01:11:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqwWc+j3J0L1UDwvtsilrQLA+3/q8UWG6VPwdpQRCDcwsU1DQj5MI6mtUwghLP+IsXFkMu7J X-Received: by 2002:a65:6648:: with SMTP id z8mr2547160pgv.303.1559203900484; Thu, 30 May 2019 01:11:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559203900; cv=none; d=google.com; s=arc-20160816; b=sliy/+0zOLVXi+Pxj4+TmE0TW5V4BqqBMKd6W3gjdglAuJDd6BFt5IuVF1nF3qa1qd 1oaPJVOBgjNcTgiqVNwLxqr8HhCkrdBRz17zSLVxVXwXkZNPa/L+u/EWOh+bycmo+WCj pA8/nnXj3Y4Uv2ZN/j5JhyhW7Q2U4iWGN22/hifOJJqVhnpmuWqnT56GJqBzSkoC65s5 zXapSXWXkycU6ETkuqb0F0HjffjaciUxV/RqpC/EQnjTjbTbACzNlBpUUGpL1KWRIpT7 xIlNhgN9CYeQV37XyNGHIhvL4/+n3qBZyCrRd281JKDtn+tV5WdJlq4RTay5FHDYYVk5 PbnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date:dkim-signature:dkim-filter; bh=Alf6jg6h+dfedKR7HcB98amyAjzZPc7CUtF0++zjjws=; b=quHM6ctjQem55jNLhWNrgo2BX1jwuGmq/aOTCq+TooStDAF1Vjbsa9wuOu4hyuSDC9 NaIcE73pC65LzHw1WMzJLjBlfGOLxSgZSU8pvYmry71L4/8eoVU6QMprZKHq8/FviR7X AJ5ncAq8PO4hCNJKOND0Vvg31zz34CECsup/bLLFbaTJ92h168PclouRsu8IoaCarvAd Aa0BzkYNHkCRMEKYIR/vkf099RuPzzUM0yoV5+4rKfd9wkG3slJYBGLLtWU5GgbKuNnP /tFpFWK1CgEAFsuOUup/19mu6/sUirOW2r1P8Xa7crXRn0gwSWsWFievSKiFACac4NB8 uPfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zytor.com header.s=2019051801 header.b=LB7XEjAV; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zytor.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z7si2370549plo.274.2019.05.30.01.11.23; Thu, 30 May 2019 01:11:40 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@zytor.com header.s=2019051801 header.b=LB7XEjAV; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zytor.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728012AbfE3IJZ (ORCPT + 99 others); Thu, 30 May 2019 04:09:25 -0400 Received: from terminus.zytor.com ([198.137.202.136]:36775 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727403AbfE3IJY (ORCPT ); Thu, 30 May 2019 04:09:24 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id x4U897Nq2904031 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Thu, 30 May 2019 01:09:07 -0700 DKIM-Filter: OpenDKIM Filter v2.11.0 terminus.zytor.com x4U897Nq2904031 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zytor.com; s=2019051801; t=1559203748; bh=Alf6jg6h+dfedKR7HcB98amyAjzZPc7CUtF0++zjjws=; h=Date:From:Cc:Reply-To:In-Reply-To:References:To:Subject:From; b=LB7XEjAVdz/DqIDbqWnlYE4hYygLF/G5Tx9x3jj9q28DgV6F8ZUDlsuv+l+8nbgQX YqPDhgPlwDFVcmQKWwvRCT2b5T9xBXRleuVv04mBmT03KLrkST0Z0CDi9EwBUiuXfH 6F8X2wjxm9uLyCbsGbCZnpU+p5q61B6XIp4Un5XqC76z7p2cxVeypwm52o3pP3QrSN kcXe4lTyJBe3BkZN0aU6ELT9LFbgBBUPMmKLNDyDDG1JTKwfKEIxTXus1wkx/CuPcd PB2D/IUF276NrEfj0JtUzc4FpN1a8dEZGftbLAHrsEDOLSirpubp9m3U8jHTuDt2hW lMqv/fAZXwZEg== Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id x4U897AB2904028; Thu, 30 May 2019 01:09:07 -0700 Date: Thu, 30 May 2019 01:09:07 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Jiri Olsa Message-ID: Cc: mingo@kernel.org, hpa@zytor.com, tglx@linutronix.de, jolsa@kernel.org, alexander.shishkin@linux.intel.com, adrian.hunter@intel.com, acme@redhat.com, songliubraving@fb.com, ak@linux.intel.com, sdf@google.com, peterz@infradead.org, linux-kernel@vger.kernel.org, namhyung@kernel.org Reply-To: linux-kernel@vger.kernel.org, namhyung@kernel.org, peterz@infradead.org, sdf@google.com, adrian.hunter@intel.com, alexander.shishkin@linux.intel.com, acme@redhat.com, songliubraving@fb.com, ak@linux.intel.com, jolsa@kernel.org, tglx@linutronix.de, mingo@kernel.org, hpa@zytor.com In-Reply-To: <20190508132010.14512-3-jolsa@kernel.org> References: <20190508132010.14512-3-jolsa@kernel.org> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] perf dso: Separate generic code in dso_cache__read Git-Commit-ID: ea5db1bd5a04b865bc86bb8e3267c27939dfb5ee X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DATE_IN_FUTURE_96_Q,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF autolearn=no autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: ea5db1bd5a04b865bc86bb8e3267c27939dfb5ee Gitweb: https://git.kernel.org/tip/ea5db1bd5a04b865bc86bb8e3267c27939dfb5ee Author: Jiri Olsa AuthorDate: Wed, 8 May 2019 15:20:00 +0200 Committer: Arnaldo Carvalho de Melo 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 Acked-by: Song Liu Cc: Adrian Hunter Cc: Alexander Shishkin Cc: Andi Kleen Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Stanislav Fomichev Link: http://lkml.kernel.org/r/20190508132010.14512-3-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- 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);