From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932907AbcGGFAb (ORCPT ); Thu, 7 Jul 2016 01:00:31 -0400 Received: from szxga01-in.huawei.com ([58.251.152.64]:38682 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750765AbcGGFAa (ORCPT ); Thu, 7 Jul 2016 01:00:30 -0400 Subject: Re: [PATCH v13 5/8] perf record: Read from overwritable ring buffer To: Jiri Olsa References: <1467613209-191781-1-git-send-email-wangnan0@huawei.com> <1467613209-191781-6-git-send-email-wangnan0@huawei.com> <20160706113857.GD26517@krava> <577CF390.2090700@huawei.com> <20160706123411.GF26517@krava> CC: , , , , He Kuang , Arnaldo Carvalho de Melo , Jiri Olsa , Masami Hiramatsu , Namhyung Kim , Nilay Vaish From: "Wangnan (F)" Message-ID: <577DE1BD.5020905@huawei.com> Date: Thu, 7 Jul 2016 12:59:41 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.5.0 MIME-Version: 1.0 In-Reply-To: <20160706123411.GF26517@krava> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [10.111.66.109] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A090204.577DE1E7.0084,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: 6e0b8a9f55f696656fbe4a91084550ec Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2016/7/6 20:34, Jiri Olsa wrote: > On Wed, Jul 06, 2016 at 08:03:28PM +0800, Wangnan (F) wrote: >> >> On 2016/7/6 19:38, Jiri Olsa wrote: >>> On Mon, Jul 04, 2016 at 06:20:06AM +0000, Wang Nan wrote: >>> >>> SNIP >>> >>>> +static void >>>> +record__toggle_overwrite_evsels(struct record *rec, >>>> + enum overwrite_evt_state state) >>>> +{ >>>> + struct perf_evlist *evlist = rec->overwrite_evlist; >>>> + enum overwrite_evt_state old_state = rec->overwrite_evt_state; >>>> + enum action { >>>> + NONE, >>>> + PAUSE, >>>> + RESUME, >>>> + } action = NONE; >>>> + >>>> + switch (old_state) { >>>> + case OVERWRITE_EVT_RUNNING: { >>>> + switch (state) { >>>> + case OVERWRITE_EVT_DATA_PENDING: >>>> + action = PAUSE; >>>> + break; >>>> + case OVERWRITE_EVT_RUNNING: >>>> + case OVERWRITE_EVT_EMPTY: >>>> + default: >>>> + goto state_err; >>>> + } >>>> + break; >>>> + } >>>> + case OVERWRITE_EVT_DATA_PENDING: { >>>> + switch (state) { >>>> + case OVERWRITE_EVT_EMPTY: >>>> + break; >>>> + case OVERWRITE_EVT_RUNNING: >>>> + case OVERWRITE_EVT_DATA_PENDING: >>>> + default: >>>> + goto state_err; >>>> + } >>>> + break; >>>> + } >>>> + case OVERWRITE_EVT_EMPTY: { >>>> + switch (state) { >>>> + case OVERWRITE_EVT_RUNNING: >>>> + action = RESUME; >>>> + break; >>>> + case OVERWRITE_EVT_EMPTY: >>>> + case OVERWRITE_EVT_DATA_PENDING: >>>> + default: >>>> + goto state_err; >>>> + } >>>> + break; >>>> + } >>>> + default: >>>> + WARN_ONCE(1, "Shouldn't get there\n"); >>>> + } >>>> + >>>> + rec->overwrite_evt_state = state; >>>> + >>>> + if (!evlist) >>>> + return; >>> I'd expect this check at the begining >> I think even evlist is NULL the state changing is still required. >> Actually, the state machine is independent with aux evlist. Even >> we without overwritable evsels the state machine is still valid. >> So let the state machine runs unconditionally. > hum, can't see that.. it's state machine to govern overwrite evlist, right? > if there's no overwrite evlist we should keep the current processing Not as easy as I thought. Look at following code: >@@ -1006,8 +1122,27 @@ 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 overwrite_evt_state should be set to >+ * OVERWRITE_EVT_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->overwrite_evt_state == OVERWRITE_EVT_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. >+ */ >+ record__toggle_overwrite_evsels(rec, OVERWRITE_EVT_RUNNING); >+ > if (!quiet) > fprintf(stderr, "[ perf record: dump data: Woken up %ld times ]\n", > waking); Here perf tests whether reading from overwritable ring buffer is required. If SIGUSR2 is received just before the above trigger_is_hit, we should read from overwrite ring buffer again. The OVERWRITE_EVT_RUNNING checker is for this reason. Now if we stop the state machine, the state is stopped at OVERWRITE_EVT_RUNNING, causes perf loops forever. We can check rec->overwrite_evlist first, but it is ugly, since I believe the overwritable state is independent to overwrite evlist. So I decide to introduce a new state indicate the overwrite evlist is not ready. Thank you. > if it's meant to govern the mmap reading in general > we should at least rename it > jirka