From patchwork Thu Aug 22 14:44:05 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Richter X-Patchwork-Id: 19423 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qa0-f71.google.com (mail-qa0-f71.google.com [209.85.216.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 665CD248E6 for ; Thu, 22 Aug 2013 14:44:39 +0000 (UTC) Received: by mail-qa0-f71.google.com with SMTP id bq6sf578567qab.2 for ; Thu, 22 Aug 2013 07:44:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:delivered-to:sender:from:to:cc:subject:date:message-id :in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=Y+0KIkO1bT+ZNibwuFyvtXIlSmhQkbKqNTrj+qqfCt8=; b=zYQd2ShvjYcXAynfVcRXiIOBA849EhozaIUNKCN93VzNLxZY1Y+AdDCnu4bKQKzrk6 sd2vucq64e3WZ4d4TuTsGC+9aCT+XwlzTxzKEZB35XYI/n5nG0eJDCr8H3uXXfSd6Vn7 WQG0j553u6Zh3pzdnG4bCVY+llNawR71lDPkg56RrOIBe/NDioSLJEyXBJRnVOWqCE2H vF6kSicispSrKX+f6goJOrIPcn9hvrYJFTtcUW21PFOgF7f4FJV9ZIGaOHvjuV/sT33j 4OnS1daCBmAhxSMNR8v4ZMIcphjTM5WV14XQfMy7eDC7oX+AqF1nV0UDXXRBe20wS+An 1b7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-gm-message-state:delivered-to:sender:from:to:cc :subject:date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=Y+0KIkO1bT+ZNibwuFyvtXIlSmhQkbKqNTrj+qqfCt8=; b=O1WJjt31BvRQi19x77JeJXDo8dtky7FNFN9++G2DGLfyVgrzIktqz9BDaezbQhyg7N xZxYcrl+dD2b8KysquAf+PCfpU/A6VTxmEbIL6nC1NFop0f0cT8L+2M577/4f/hY2Ekv LNMBY+w5IHQPXnXkx9VT0cbf6eDaOLk+JyFRZGY06xwo9e/3bxkOjsK4HLE9uhF48FdN GTnToDJTR06mGHKwAWDuRTyApHim1vyclhLvSvuaQvgK2y5prLuEpH22z79h2OLAoz3g 7ed9NiaZnLgqCLty+AT90lYUD6XPdMRGE6UCBQOJAXhkKOiF3gyU3xdjLKBOO+34AEBL 4XQA== X-Received: by 10.236.207.103 with SMTP id m67mr4623969yho.1.1377182679049; Thu, 22 Aug 2013 07:44:39 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.74.102 with SMTP id s6ls1095593qev.17.gmail; Thu, 22 Aug 2013 07:44:39 -0700 (PDT) X-Received: by 10.52.165.239 with SMTP id zb15mr74963vdb.44.1377182678966; Thu, 22 Aug 2013 07:44:38 -0700 (PDT) Received: from mail-ve0-x235.google.com (mail-ve0-x235.google.com [2607:f8b0:400c:c01::235]) by mx.google.com with ESMTPS id ya5si4066482vec.19.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 22 Aug 2013 07:44:38 -0700 (PDT) Received-SPF: neutral (google.com: 2607:f8b0:400c:c01::235 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=2607:f8b0:400c:c01::235; Received: by mail-ve0-f181.google.com with SMTP id jz10so1555262veb.26 for ; Thu, 22 Aug 2013 07:44:38 -0700 (PDT) X-Gm-Message-State: ALoCoQkd5UGI8QbUUuq0MR3fa7d/HjMmnE3oCdzMpTjYCTHMX5kZhin/8KOY7EjCRW+axHD1SfV1 X-Received: by 10.52.230.102 with SMTP id sx6mr9938483vdc.15.1377182678822; Thu, 22 Aug 2013 07:44:38 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp34807vcz; Thu, 22 Aug 2013 07:44:38 -0700 (PDT) X-Received: by 10.205.26.67 with SMTP id rl3mr443136bkb.41.1377182677649; Thu, 22 Aug 2013 07:44:37 -0700 (PDT) Received: from mail-bk0-x235.google.com (mail-bk0-x235.google.com [2a00:1450:4008:c01::235]) by mx.google.com with ESMTPS id cy5si2343547bkc.45.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 22 Aug 2013 07:44:37 -0700 (PDT) Received-SPF: pass (google.com: domain of rric.net@gmail.com designates 2a00:1450:4008:c01::235 as permitted sender) client-ip=2a00:1450:4008:c01::235; Received: by mail-bk0-f53.google.com with SMTP id d7so732943bkh.12 for ; Thu, 22 Aug 2013 07:44:36 -0700 (PDT) X-Received: by 10.204.225.12 with SMTP id iq12mr10724479bkb.4.1377182676463; Thu, 22 Aug 2013 07:44:36 -0700 (PDT) Received: from rric.localhost (g224195237.adsl.alicedsl.de. [92.224.195.237]) by mx.google.com with ESMTPSA id h5sm3117070bkg.8.1969.12.31.16.00.00 (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 22 Aug 2013 07:44:35 -0700 (PDT) Sender: Robert Richter From: Robert Richter To: Arnaldo Carvalho de Melo Cc: Peter Zijlstra , Ingo Molnar , Borislav Petkov , Jiri Olsa , linux-kernel@vger.kernel.org, Robert Richter , Robert Richter Subject: [PATCH resent 4/4] perf tools: Retry mapping buffers readonly on EACCES Date: Thu, 22 Aug 2013 16:44:05 +0200 Message-Id: <1377182645-12922-5-git-send-email-rric@kernel.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1377182645-12922-1-git-send-email-rric@kernel.org> References: <1377182645-12922-1-git-send-email-rric@kernel.org> X-Original-Sender: rric.net@gmail.com X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 2607:f8b0:400c:c01::235 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org; dkim=pass header.i=@gmail.com Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Robert Richter Persistent event buffers may only be mmapped readonly. Thus, retry mapping it readonly if mmap returns EACCES after trying to mmap writable. [ namhyung: Don't write to readonly mmap'ed buffers. ] Signed-off-by: Robert Richter Signed-off-by: Robert Richter --- tools/perf/builtin-record.c | 11 ++++++++--- tools/perf/builtin-top.c | 8 ++++++-- tools/perf/perf.h | 1 + 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index a41ac415..f3f7483 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -152,8 +152,8 @@ static int perf_record__mmap_read(struct perf_record *rec, } md->prev = old; - perf_mmap__write_tail(md, old); - + if (!rec->opts.mmap_ro) + perf_mmap__write_tail(md, old); out: return rc; } @@ -226,7 +226,12 @@ static int perf_record__open(struct perf_record *rec) goto out; } - if (perf_evlist__mmap(evlist, opts->mmap_pages, false) < 0) { +try_again2: + if (perf_evlist__mmap(evlist, opts->mmap_pages, opts->mmap_ro) < 0) { + if (!opts->mmap_ro && errno == EACCES) { + opts->mmap_ro = true; + goto try_again2; + } if (errno == EPERM) { pr_err("Permission error mapping pages.\n" "Consider increasing " diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index e37521f..bef7b1d 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c @@ -894,8 +894,12 @@ static int perf_top__start_counters(struct perf_top *top) goto out_err; } } - - if (perf_evlist__mmap(evlist, opts->mmap_pages, false) < 0) { +try_again2: + if (perf_evlist__mmap(evlist, opts->mmap_pages, opts->mmap_ro) < 0) { + if (!opts->mmap_ro && errno == EACCES) { + opts->mmap_ro = true; + goto try_again2; + } ui__error("Failed to mmap with %d (%s)\n", errno, strerror(errno)); goto out_err; diff --git a/tools/perf/perf.h b/tools/perf/perf.h index cf20187..dca43c72 100644 --- a/tools/perf/perf.h +++ b/tools/perf/perf.h @@ -224,6 +224,7 @@ struct perf_record_opts { bool sample_weight; bool sample_time; bool period; + bool mmap_ro; unsigned int freq; unsigned int mmap_pages; unsigned int user_freq;