Received: by 10.223.176.46 with SMTP id f43csp35654wra; Thu, 18 Jan 2018 13:32:36 -0800 (PST) X-Google-Smtp-Source: ACJfBosbBOr2iHDPSwEd8M1Eur5rAXSWvtZpmek+5fldpru62pVdmNoBrtH3XZN6UtterLXs+Qa1 X-Received: by 2002:a17:902:5a41:: with SMTP id f1-v6mr441694plm.201.1516311156409; Thu, 18 Jan 2018 13:32:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516311156; cv=none; d=google.com; s=arc-20160816; b=Bf3p8kJvsxSag5viXgEQsDa+qUFEVrD1056WI7x1dmia9H/DMrrehlGOJVDhU3kaF+ N4zE7Pq+FS1S+nsRHcrpFUqs7IBX8W/AX5n7U50s15Q+tSdYze18+3TMEzTu87nOtObp AikPjkQcUCnQ3HCuzywhXQ8eL5i0wO8bxyDj8VDhCCtNZBfSI28Tz2dmLwIXg6Vj/WLv azUfNCct4B/2Lm8Xvkne9vrq0+JNuhAdAZ0W2cegT3BYxcxoU6VoQ6qT6u8oAJcek69t 1wnnhYgXBmopl+lz5KOf7CHekAIyn4UyCcqOr51tQjiUg9piWeZ4g+btXeUuWUyFPFuV DLaw== 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:arc-authentication-results; bh=aJ4Xl1MCIiZO9KIHmDts6WpOKWTlQgRI5UEFQofvRXo=; b=Dq+XrOAZ61ifNZUamWiEGM9OgQ4qCqw9tP2FRNTGLr5CpU+f8PYyBROPkUsz+zdBpd 33WftJR09jPUykZhQq/TV4qU/lIrVEqldpMZf/hGEpdI/ZoDCZ1QSVpz7DaQBalMrW1/ V6unYt6E+4cHo6oqWpc5o40LL62+MEK9pvbk8EAK8U3VithfdX9fZzKB/WNNRMzIzEC5 32TJZjok9Fvjv26liLsASMM5DXwOBTwXVxUpmIi9XzLBYGrb6zPix67pl7NfzW4r1g0Z FGpzpXTudgxooqdykPFTmwHEAyZAYLJiSPQlrKnySlChXTmqp3nnztDGNbx7ylbow5mz nhgg== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s66si6853697pgb.609.2018.01.18.13.32.22; Thu, 18 Jan 2018 13:32:36 -0800 (PST) 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 S1755245AbeARVbU (ORCPT + 99 others); Thu, 18 Jan 2018 16:31:20 -0500 Received: from mga04.intel.com ([192.55.52.120]:47419 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754162AbeARV1g (ORCPT ); Thu, 18 Jan 2018 16:27:36 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Jan 2018 13:27:34 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,378,1511856000"; d="scan'208";a="11477254" Received: from otc-knm-01.jf.intel.com ([10.54.39.34]) by fmsmga008.fm.intel.com with ESMTP; 18 Jan 2018 13:27:33 -0800 From: kan.liang@intel.com To: acme@kernel.org, peterz@infradead.org, mingo@redhat.com, linux-kernel@vger.kernel.org Cc: wangnan0@huawei.com, jolsa@kernel.org, namhyung@kernel.org, ak@linux.intel.com, yao.jin@linux.intel.com, Kan Liang Subject: [PATCH V5 08/17] perf mmap: introduce perf_mmap__read_event() Date: Thu, 18 Jan 2018 13:26:23 -0800 Message-Id: <1516310792-208685-9-git-send-email-kan.liang@intel.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1516310792-208685-1-git-send-email-kan.liang@intel.com> References: <1516310792-208685-1-git-send-email-kan.liang@intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kan Liang Except perf record, other perf tools read events one by one from ring buffer by perf_mmap__read_forward(). But it only supports non-overwrite mode. Introduce perf_mmap__read_event() to support both non-overwrite and overwrite mode. Usage: perf_mmap__read_init() while(event = perf_mmap__read_event()) { //process the event perf_mmap__consume() } perf_mmap__read_done() It cannot use perf_mmap__read_backward(). Because it always read the stale buffer which is already processed. Furthermore, the forward and backward concepts have been removed. The perf_mmap__read_backward() will be replaced and discarded later. Signed-off-by: Kan Liang --- tools/perf/util/mmap.c | 39 +++++++++++++++++++++++++++++++++++++++ tools/perf/util/mmap.h | 4 ++++ 2 files changed, 43 insertions(+) diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c index 4f59eae..f804926 100644 --- a/tools/perf/util/mmap.c +++ b/tools/perf/util/mmap.c @@ -113,6 +113,45 @@ union perf_event *perf_mmap__read_backward(struct perf_mmap *map) return perf_mmap__read(map, &map->prev, end); } +/* + * Read event from ring buffer one by one. + * Return one event for each call. + * + * Usage: + * perf_mmap__read_init() + * while(event = perf_mmap__read_event()) { + * //process the event + * perf_mmap__consume() + * } + * perf_mmap__read_done() + */ +union perf_event *perf_mmap__read_event(struct perf_mmap *map, + bool overwrite, + u64 *startp, u64 end) +{ + union perf_event *event; + + /* + * Check if event was unmapped due to a POLLHUP/POLLERR. + */ + if (!refcount_read(&map->refcnt)) + return NULL; + + if (startp == NULL) + return NULL; + + /* non-overwirte doesn't pause the ringbuffer */ + if (!overwrite) + end = perf_mmap__read_head(map); + + event = perf_mmap__read(map, startp, end); + + if (!overwrite) + map->prev = *startp; + + return event; +} + void perf_mmap__read_catchup(struct perf_mmap *map) { u64 head; diff --git a/tools/perf/util/mmap.h b/tools/perf/util/mmap.h index 95549d4..2871854 100644 --- a/tools/perf/util/mmap.h +++ b/tools/perf/util/mmap.h @@ -89,6 +89,10 @@ static inline void perf_mmap__write_tail(struct perf_mmap *md, u64 tail) union perf_event *perf_mmap__read_forward(struct perf_mmap *map); union perf_event *perf_mmap__read_backward(struct perf_mmap *map); +union perf_event *perf_mmap__read_event(struct perf_mmap *map, + bool overwrite, + u64 *startp, u64 end); + int perf_mmap__push(struct perf_mmap *md, bool backward, void *to, int push(void *to, void *buf, size_t size)); -- 2.5.5