Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp3965697ybh; Tue, 6 Aug 2019 04:17:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqxUb3nGiMC8aej4/fNG2Wc0SuIMRERzowjpQs/JiqYrE47s9rBpYNvUewkyHVArkltjW+JX X-Received: by 2002:a63:e20a:: with SMTP id q10mr2572558pgh.24.1565090278891; Tue, 06 Aug 2019 04:17:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565090278; cv=none; d=google.com; s=arc-20160816; b=VPi2OFnw5KkWyVJLx38aJuMk9nfLc5S/5j7BeRzVkR6LwzFPTe/GowMUpONAuYHXBa AQW/+iCKcgmUqJPEqdBL/5hIxhtA/k76OdcIM+INSb1flVF/9aXZB4y8OPlEFO+bQUkF vjlb/+psTo53b+az8EOkTxfcjXCqxyPnSy7Wj3Zr0YAOCfDwfZaMdDE6WuLNMvJtVLvX Wr1wDAvI+GWKJir7eI3qFebtxJ7h/H7OWTOm7jlu3XmLpulAOY7aXzLSoy6Ye04O2ygF ilDf0phJ/RGXcJ1H0Zg6M566zmfPvzYCdggHy5I2a8TF40ECA6zWw6Zq3hE3ahQvH9ie CTKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=Pz8LgdIcYr/48rf40Gc401zLF5qxmePKIw2YZaJ5EDA=; b=sHqKvq+78Pyqg7JGfETNbLyfiFlnrGksVuzQoOsOGEq5T898vVqfpGrtCRB80Euf0R bRtz/4D8O3ytTDvURsHnasM39mnGw3XAhTCpkS3TBZtsbupvVkMYBlqHKUY33DcyQrNm w+F4q+erjJGZf/4qUCuHnMbQ2YnbDbphCg9CskO9iswmKXX5jfaJhJgkKnqEUTX38x04 NvGnN/K9WmbDDP6+8imcAp+u1P6lKjDoLJTktPRVdt5l0gCivHu+COt3aavcusLf3aFW RsM1isS2gLAeJgXizwVKAN6vCCy40Mu4yRfgnfy4bU18cgtE3BZihnfl8y/tLFmQLIr0 Vp8Q== 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 d21si42067783pls.25.2019.08.06.04.17.42; Tue, 06 Aug 2019 04:17:58 -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 S1732765AbfHFLPY (ORCPT + 99 others); Tue, 6 Aug 2019 07:15:24 -0400 Received: from foss.arm.com ([217.140.110.172]:60344 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728845AbfHFLPX (ORCPT ); Tue, 6 Aug 2019 07:15:23 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 1BC0B337; Tue, 6 Aug 2019 04:15:23 -0700 (PDT) Received: from dawn-kernel.cambridge.arm.com (unknown [10.1.197.116]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 690503F694; Tue, 6 Aug 2019 04:15:22 -0700 (PDT) Subject: Re: [PATCH] coresight: tmc-etr: Fix updating buffer in not-snapshot mode. To: yabinc@google.com, mathieu.poirier@linaro.org, alexander.shishkin@linux.intel.com Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org References: <20190805233738.136357-1-yabinc@google.com> From: Suzuki K Poulose Message-ID: Date: Tue, 6 Aug 2019 12:15:21 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <20190805233738.136357-1-yabinc@google.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Yabin On 06/08/2019 00:37, Yabin Cui wrote: > TMC etr always copies all available data to perf aux buffer, which > may exceed the available space in perf aux buffer. It isn't suitable > for not-snapshot mode, because: > 1) It may overwrite previously written data. > 2) It may make the perf_event_mmap_page->aux_head report having more > or less data than the reality. Thanks for debugging and the fix. > Signed-off-by: Yabin Cui > --- > drivers/hwtracing/coresight/coresight-tmc-etr.c | 12 ++++++++---- > 1 file changed, 8 insertions(+), 4 deletions(-) > > diff --git a/drivers/hwtracing/coresight/coresight-tmc-etr.c b/drivers/hwtracing/coresight/coresight-tmc-etr.c > index 17006705287a..697e68d492af 100644 > --- a/drivers/hwtracing/coresight/coresight-tmc-etr.c > +++ b/drivers/hwtracing/coresight/coresight-tmc-etr.c > @@ -1410,9 +1410,10 @@ static void tmc_free_etr_buffer(void *config) > * tmc_etr_sync_perf_buffer: Copy the actual trace data from the hardware > * buffer to the perf ring buffer. > */ > -static void tmc_etr_sync_perf_buffer(struct etr_perf_buffer *etr_perf) > +static void tmc_etr_sync_perf_buffer(struct etr_perf_buffer *etr_perf, > + unsigned long to_copy) > { > - long bytes, to_copy; > + long bytes; > long pg_idx, pg_offset, src_offset; > unsigned long head = etr_perf->head; > char **dst_pages, *src_buf; > @@ -1423,7 +1424,6 @@ static void tmc_etr_sync_perf_buffer(struct etr_perf_buffer *etr_perf) > pg_offset = head & (PAGE_SIZE - 1); > dst_pages = (char **)etr_perf->pages; > src_offset = etr_buf->offset; > - to_copy = etr_buf->len; > > while (to_copy > 0) { > /* > @@ -1501,7 +1501,11 @@ tmc_update_etr_buffer(struct coresight_device *csdev, > spin_unlock_irqrestore(&drvdata->spinlock, flags); > > size = etr_buf->len; > - tmc_etr_sync_perf_buffer(etr_perf); > + if (!etr_perf->snapshot && size > handle->size) { > + size = handle->size; > + lost = true; > + } > + tmc_etr_sync_perf_buffer(etr_perf, size); The patch as such looks good to me. I was thinking if we should limit the ETR buffer to the perf ring buffer, in case the perf buffer is smaller than the ETR configured size. Irrespective of snapshot mode or not, we can't save more than what the ring buffer offers us with. Even though for the cpu-wide trace, we could have "n" such ring buffers, we end up using only one ring buffer(the last one scheduled out). May be we could explore if we could improve the handling of large buffer into multiple ring buffers (which may require perf core changes). Anyways, for this patch: Reviewed-by: Suzuki K Poulose