Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp3388216yba; Tue, 16 Apr 2019 10:18:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqzyJHaukkAMqC5FuutYLpwyfJH66vsxfDmE2qi69qRjapgrAHb+gNBemuGhsblWJbtIdWyf X-Received: by 2002:a17:902:e01:: with SMTP id 1mr84318535plw.128.1555435111270; Tue, 16 Apr 2019 10:18:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555435111; cv=none; d=google.com; s=arc-20160816; b=kSpuBzMANUM61yj/mxN0y7a/UEgLbXDCn+O2zfiCGrzbofLFEtxThYyDpcXMmPh73i G+ON6EbI2qo7I2XdIWbUt0oq9eT/4SApYqRVbBTrpmPiZozm0Fvu/QP3khd1Oh/qATMe 1WW3G8vEIh2/XLcq7MBD0o+kPYXL+i1QvFrSq2MbSo6adNSiFbDnxiVgyxKZyUfBCOgK Cc7rgMN04G45nZuCtMO48tBzqO0N0Y2QUDI3oV82b6TbPVGUNr4L3cLQPPhglcnASdwG KqXBuXSslwYrjzYnX0G7ejwrHJVpkvFtkRMfo/NasShx8JjTWE6IHh7b3iSZ/O19xxGI 0zfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=r4if/nt2tHvb7ZR/GcjznTNmFZDClzCvbOGHsqoQ9dc=; b=p4oqWL3793++xDPrvBwCf1RnWNbVvshSTYo5CC5bai5kTfEmSy/gLHsSBMMTNkyGjc WiKpHIffiAnZ8s/ma8U9KX0DmHoAiLTzKHdPEb/0EpTcESP3s86M+N1op1VYc5TGUSU6 mcMzSOO04bjSWHSrlSUxK3Qq1AJ8hsxewBKA3OjonlvAtQHu7bQIb1hDtYZYLakgDrPR 6SA9WsVl8VPUEEr8BTRlWNZrHVt9cJKqgPg6zvWx7jJ6YfkIxi9SvB8XHLVP0KZxkuXL 07fTqnqG8ev/ReeJDj67VnxjTYsnZTTRcc9zG9BuZaa9t4TdA/078MxJK4S9p2DPdS0F 8JUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fomichev-me.20150623.gappssmtp.com header.s=20150623 header.b=Equ2u3qP; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g31si34140791plg.154.2019.04.16.10.18.15; Tue, 16 Apr 2019 10:18:31 -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=@fomichev-me.20150623.gappssmtp.com header.s=20150623 header.b=Equ2u3qP; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730070AbfDPRRQ (ORCPT + 99 others); Tue, 16 Apr 2019 13:17:16 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:37603 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726860AbfDPRRP (ORCPT ); Tue, 16 Apr 2019 13:17:15 -0400 Received: by mail-pg1-f195.google.com with SMTP id e6so10655004pgc.4 for ; Tue, 16 Apr 2019 10:17:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fomichev-me.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=r4if/nt2tHvb7ZR/GcjznTNmFZDClzCvbOGHsqoQ9dc=; b=Equ2u3qPiyp5D8arG6HBn4QW3xL53iKpstvaviriRvp2By7IBElsf5H+MWfM4Ogn8v oiNyKOoDemldMpwg1gVWJf2adPElUdbiH1j229rRTdm2b6WYfDrqwcL91ejfcm6ciKMI GIm31g/fkfOvtv7QjvCrJVkSjPgplPiTjGWKb38AQb2EyMGf6l8jSugDBep9ZJY2ypJ9 ppNVYF0I9dHummLpiAfBqOeSIiXr5XM+hMnpVjjpkRxM+QBZoxpaVa+lu+NhFavx8NSn Fuogcnf7BN3LYLcGSMLccUF85+ISm4jfMctKZIbn4C+Pt2/+jPt7d4qe5OAhRezq1g/V pZtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=r4if/nt2tHvb7ZR/GcjznTNmFZDClzCvbOGHsqoQ9dc=; b=Ih3u2YbDDHfEzK5GsxyqiGrhGfoOakAEI3CIFERfItzMqNc6XA/Iel9rU1Os/fHSDp LK7/VjNlbLvFiC/rXN7KpLZinbLd7+8l+RgZZoK5c3x2XgS1W9tyP6wfZos5GvA4q7yL w3FUq5O0o9br+Ypdz0BReSNfI4mwjEMV2y26IkLmrLwS/1oJTfhKdV9fdJGAOcG3Qxl3 /GOhvdrPSlT5nx52Yf4qWUe6uHBv2lbMlmRt+BBesiiloHoAQ7wjBNDkWk+ioylunkXZ hp5pzFEWqH11ugmDpjgJAQLaW+tK5EPWSg+bIALzRljo0xuSnhIYIqzEUdGXXDQUV/zM GEWA== X-Gm-Message-State: APjAAAW02Bpy4rq6Kt5zwFYOrF8UWHrBBKRzImly3gP1bnuIo24d1Xv3 c3EMTa1t6tHQ5SuMu9CcQVrwBJMPAK0= X-Received: by 2002:a65:4247:: with SMTP id d7mr73181537pgq.114.1555435034699; Tue, 16 Apr 2019 10:17:14 -0700 (PDT) Received: from localhost ([2601:646:8f00:18d9:d0fa:7a4b:764f:de48]) by smtp.gmail.com with ESMTPSA id z21sm74225602pfn.139.2019.04.16.10.17.13 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 16 Apr 2019 10:17:13 -0700 (PDT) Date: Tue, 16 Apr 2019 10:17:13 -0700 From: Stanislav Fomichev To: Jiri Olsa Cc: Arnaldo Carvalho de Melo , lkml , Ingo Molnar , Namhyung Kim , Alexander Shishkin , Peter Zijlstra , Andi Kleen , Adrian Hunter , Song Liu , Alexei Starovoitov , Daniel Borkmann Subject: Re: [PATCH 02/12] perf tools: Separate generic code in dso_cache__read Message-ID: <20190416171712.GB8631@mini-arch.hsd1.ca.comcast.net> References: <20190416160127.30203-1-jolsa@kernel.org> <20190416160127.30203-3-jolsa@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190416160127.30203-3-jolsa@kernel.org> User-Agent: Mutt/1.11.3 (2019-02-01) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 04/16, Jiri Olsa wrote: > 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; pthread_mutex_unlock(&dso__data_open_lock) here? > + 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 >