Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp3323679yba; Tue, 16 Apr 2019 09:04:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqyw/9WFkEn4PAQuAzq/COlu5k/RY+v0aZM9SmefCjH/TKS90ZVTQG44vtF2kM6k8woF0zl2 X-Received: by 2002:a62:aa01:: with SMTP id e1mr83358461pff.43.1555430650085; Tue, 16 Apr 2019 09:04:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555430650; cv=none; d=google.com; s=arc-20160816; b=FuW3OIPFCgzrz1sZjnyQTSFEkaoeuarfQeDNNIADLkX8TEgpVvE+V+izh4lSZLHfga lt/nShZz+YfOqSqToQWK/H/pRntI7dDarL8rcjh019plJBlUeqjlGPQ/XaRew6GQpUSm xesCzmA0/hKT5fWG8J73SX8W67SqH+U/SZieF3pNxFGpHpEXjEWDXwqfkZAAQRNKJqaq 7/5twbHL3eJ3K/qE02dtspxmqHoAI5IA7NJvHtqIrpQLAUWU7W7EAwucYSLLA2Gksg58 yQg5oB15M3G+d7+7Js7Q077N8Ls+wjPJtAuV5mtlbnD+lBZE6tcaVqAjWW6ooBznNUKR TM2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=WxTfafEHd+OJ3/YGPGOXRgZFR7pzVdB29XTWXz3FYDU=; b=hJhv+WZvcAaUfgP7Wt/7efD61VEEwYLfkPDc/fAyl1iLKKyMUCX0eIXFFyvAB3MfSe yQfqtEUfY+jSRJyFqL4dTYkIV6kJd83M6tnJzBUdlk/lbBFTaw590IB/bP8m/4rVlRuj p/u0iqjq6QEzYhuGy/N/cRQ6qODVkvePqlfxRVZWNl7Omyr5hxmgQCP6kSI3cwol2Iqx GQtNkf/t1KaEqmsVg+Yu7wVbmMDLFW0NeJ8sTKx+TEsXZzmVMwtwcOdNFvGIMzQwnWBD faBa3JJnsfsLBwvA8jCC21U4BHgIM/ovYCLTUB1IrLFt8poB76+3gbOs+hZ3QO9wkC+b JocA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 61si17268396plb.256.2019.04.16.09.03.53; Tue, 16 Apr 2019 09:04:10 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729905AbfDPQBo (ORCPT + 99 others); Tue, 16 Apr 2019 12:01:44 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46322 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727691AbfDPQBm (ORCPT ); Tue, 16 Apr 2019 12:01:42 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1B6C581106; Tue, 16 Apr 2019 16:01:42 +0000 (UTC) Received: from krava.brq.redhat.com (unknown [10.43.17.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id C50905D71A; Tue, 16 Apr 2019 16:01:39 +0000 (UTC) From: Jiri Olsa To: Arnaldo Carvalho de Melo Cc: lkml , Ingo Molnar , Namhyung Kim , Alexander Shishkin , Peter Zijlstra , Andi Kleen , Adrian Hunter , Song Liu , Alexei Starovoitov , Daniel Borkmann Subject: [PATCH 02/12] perf tools: Separate generic code in dso_cache__read Date: Tue, 16 Apr 2019 18:01:17 +0200 Message-Id: <20190416160127.30203-3-jolsa@kernel.org> In-Reply-To: <20190416160127.30203-1-jolsa@kernel.org> References: <20190416160127.30203-1-jolsa@kernel.org> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 16 Apr 2019 16:01:42 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Moving file specific code in dso_cache__read function into separate file_read function. I'll add bpf specific code in following patches. Link: http://lkml.kernel.org/n/tip-7f7d717uzrqt5ka2xp29ige3@git.kernel.org Signed-off-by: Jiri Olsa --- tools/perf/util/dso.c | 47 ++++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c index cb6199c1390a..6baad22ec8a9 100644 --- a/tools/perf/util/dso.c +++ b/tools/perf/util/dso.c @@ -794,6 +794,30 @@ 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; + return -errno; + } + + ret = pread(dso->data.fd, data, DSO__DATA_CACHE_SIZE, offset); + 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 +827,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); -- 2.17.2