From patchwork Fri Jul 15 20:50:52 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaldo Carvalho de Melo X-Patchwork-Id: 72134 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp820190qga; Fri, 15 Jul 2016 13:52:21 -0700 (PDT) X-Received: by 10.66.155.129 with SMTP id vw1mr34383054pab.148.1468615930507; Fri, 15 Jul 2016 13:52:10 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z4si1118874pfi.24.2016.07.15.13.52.07; Fri, 15 Jul 2016 13:52: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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752264AbcGOUwE (ORCPT + 29 others); Fri, 15 Jul 2016 16:52:04 -0400 Received: from bombadil.infradead.org ([198.137.202.9]:44269 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751823AbcGOUvW (ORCPT ); Fri, 15 Jul 2016 16:51:22 -0400 Received: from [179.235.155.208] (helo=jouet.infradead.org) by bombadil.infradead.org with esmtpsa (Exim 4.85_2 #1 (Red Hat Linux)) id 1bOA4t-0008VQ-Nt; Fri, 15 Jul 2016 20:51:19 +0000 Received: by jouet.infradead.org (Postfix, from userid 1000) id 27BAB143C80; Fri, 15 Jul 2016 17:51:12 -0300 (BRT) From: Arnaldo Carvalho de Melo To: Ingo Molnar Cc: linux-kernel@vger.kernel.org, Wang Nan , Masami Hiramatsu , Namhyung Kim , Nilay Vaish , Zefan Li , pi3orama@163.com, He Kuang , Arnaldo Carvalho de Melo Subject: [PATCH 18/24] perf record: Read from overwritable ring buffer Date: Fri, 15 Jul 2016 17:50:52 -0300 Message-Id: <1468615858-24936-19-git-send-email-acme@kernel.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1468615858-24936-1-git-send-email-acme@kernel.org> References: <1468615858-24936-1-git-send-email-acme@kernel.org> X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Wang Nan Drive the evlist->bkw_mmap_state state machine during draining and when SIGUSR2 is received. Read the backward ring buffer in record__mmap_read_all. Signed-off-by: Wang Nan Acked-by: Jiri Olsa Cc: Masami Hiramatsu Cc: Namhyung Kim Cc: Nilay Vaish Cc: Zefan Li Cc: pi3orama@163.com Link: http://lkml.kernel.org/r/1468485287-33422-12-git-send-email-wangnan0@huawei.com Signed-off-by: He Kuang Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-record.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) -- 2.7.4 diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index d4f15e76c98a..b87070b1f492 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -555,7 +555,7 @@ static int record__mmap_read_all(struct record *rec) if (err) return err; - return err; + return record__mmap_read_evlist(rec, rec->evlist, true); } static void record__init_features(struct record *rec) @@ -953,6 +953,17 @@ static int __cmd_record(struct record *rec, int argc, const char **argv) for (;;) { unsigned long long hits = rec->samples; + /* + * rec->evlist->bkw_mmap_state is possible to be + * BKW_MMAP_EMPTY here: when done == true and + * hits != rec->samples in previous round. + * + * perf_evlist__toggle_bkw_mmap ensure we never + * convert BKW_MMAP_EMPTY to BKW_MMAP_DATA_PENDING. + */ + if (trigger_is_hit(&switch_output_trigger) || done || draining) + perf_evlist__toggle_bkw_mmap(rec->evlist, BKW_MMAP_DATA_PENDING); + if (record__mmap_read_all(rec) < 0) { trigger_error(&auxtrace_snapshot_trigger); trigger_error(&switch_output_trigger); @@ -972,8 +983,26 @@ static int __cmd_record(struct record *rec, int argc, const char **argv) } if (trigger_is_hit(&switch_output_trigger)) { + /* + * If switch_output_trigger is hit, the data in + * overwritable ring buffer should have been collected, + * so bkw_mmap_state should be set to BKW_MMAP_EMPTY. + * + * If SIGUSR2 raise after or during record__mmap_read_all(), + * record__mmap_read_all() didn't collect data from + * overwritable ring buffer. Read again. + */ + if (rec->evlist->bkw_mmap_state == BKW_MMAP_RUNNING) + continue; trigger_ready(&switch_output_trigger); + /* + * Reenable events in overwrite ring buffer after + * record__mmap_read_all(): we should have collected + * data from it. + */ + perf_evlist__toggle_bkw_mmap(rec->evlist, BKW_MMAP_RUNNING); + if (!quiet) fprintf(stderr, "[ perf record: dump data: Woken up %ld times ]\n", waking);