From patchwork Mon Jun 20 10:47:18 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Nan X-Patchwork-Id: 70427 Delivered-To: patch@linaro.org Received: by 10.140.28.4 with SMTP id 4csp1444749qgy; Mon, 20 Jun 2016 03:49:27 -0700 (PDT) X-Received: by 10.98.63.199 with SMTP id z68mr21535804pfj.41.1466419767316; Mon, 20 Jun 2016 03:49:27 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id xq1si10601425pab.11.2016.06.20.03.49.27; Mon, 20 Jun 2016 03:49:27 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754064AbcFTKtZ (ORCPT + 30 others); Mon, 20 Jun 2016 06:49:25 -0400 Received: from szxga02-in.huawei.com ([119.145.14.65]:55733 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752358AbcFTKtO (ORCPT ); Mon, 20 Jun 2016 06:49:14 -0400 Received: from 172.24.1.60 (EHLO szxeml434-hub.china.huawei.com) ([172.24.1.60]) by szxrg02-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id DJB40561; Mon, 20 Jun 2016 18:48:06 +0800 (CST) Received: from linux-4hy3.site (10.107.193.248) by szxeml434-hub.china.huawei.com (10.82.67.225) with Microsoft SMTP Server id 14.3.235.1; Mon, 20 Jun 2016 18:47:54 +0800 From: Wang Nan To: CC: , , Wang Nan , He Kuang , Jiri Olsa , Masami Hiramatsu , Namhyung Kim , Zefan Li Subject: [PATCH v8 1/8] perf tools: Fix write_backwards fallback Date: Mon, 20 Jun 2016 10:47:18 +0000 Message-ID: <1466419645-75551-2-git-send-email-wangnan0@huawei.com> X-Mailer: git-send-email 1.8.3.4 In-Reply-To: <1466419645-75551-1-git-send-email-wangnan0@huawei.com> References: <1466419645-75551-1-git-send-email-wangnan0@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.107.193.248] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020202.5767C9E9.01AE, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2013-06-18 04:22:30, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 0d2bf5dcbb4ec999c3d03dbe4952a9bf Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit b90dc17a5d14 "perf evsel: Add overwrite attribute and check write_backward" misunderstood the 'order' should be obeyed in __perf_evsel__open. Arnaldo in [1]: "But the way this was done for attr.write_backwards was buggy, as we need to check features in the inverse order of their introduction to the kernel, so that a newer tool checks first the newest perf_event_attr fields, detecting that the older kernel doesn't have support for them." Also, we can avoid calling sys_perf_event_open() if we have already detected the missing of write_backward. [1] http://lkml.kernel.org/r/20160616214724.GI13337@kernel.org Signed-off-by: Wang Nan Signed-off-by: Arnaldo Carvalho de Melo Cc: He Kuang Cc: Jiri Olsa Cc: Masami Hiramatsu Cc: Namhyung Kim Cc: Zefan Li Cc: pi3orama@163.com --- tools/perf/util/evsel.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) -- 1.8.3.4 diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 9b2e3e6..1d8f2bb 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -1389,8 +1389,11 @@ fallback_missing_features: if (perf_missing_features.lbr_flags) evsel->attr.branch_sample_type &= ~(PERF_SAMPLE_BRANCH_NO_FLAGS | PERF_SAMPLE_BRANCH_NO_CYCLES); - if (perf_missing_features.write_backward) + if (perf_missing_features.write_backward) { + if (evsel->overwrite) + return -EINVAL; evsel->attr.write_backward = false; + } retry_sample_id: if (perf_missing_features.sample_id_all) evsel->attr.sample_id_all = 0; @@ -1453,12 +1456,6 @@ retry_open: err = -EINVAL; goto out_close; } - - if (evsel->overwrite && - perf_missing_features.write_backward) { - err = -EINVAL; - goto out_close; - } } } @@ -1496,7 +1493,10 @@ try_fallback: * Must probe features in the order they were added to the * perf_event_attr interface. */ - if (!perf_missing_features.clockid_wrong && evsel->attr.use_clockid) { + if (!perf_missing_features.write_backward && evsel->attr.write_backward) { + perf_missing_features.write_backward = true; + goto fallback_missing_features; + } else if (!perf_missing_features.clockid_wrong && evsel->attr.use_clockid) { perf_missing_features.clockid_wrong = true; goto fallback_missing_features; } else if (!perf_missing_features.clockid && evsel->attr.use_clockid) { @@ -1521,12 +1521,7 @@ try_fallback: PERF_SAMPLE_BRANCH_NO_FLAGS))) { perf_missing_features.lbr_flags = true; goto fallback_missing_features; - } else if (!perf_missing_features.write_backward && - evsel->attr.write_backward) { - perf_missing_features.write_backward = true; - goto fallback_missing_features; } - out_close: do { while (--thread >= 0) { @@ -2409,6 +2404,8 @@ int perf_evsel__open_strerror(struct perf_evsel *evsel, struct target *target, "We found oprofile daemon running, please stop it and try again."); break; case EINVAL: + if (evsel->overwrite && perf_missing_features.write_backward) + return scnprintf(msg, size, "Reading from overwrite event is not supported by this kernel."); if (perf_missing_features.clockid) return scnprintf(msg, size, "clockid feature not supported."); if (perf_missing_features.clockid_wrong)