Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1306724ybl; Wed, 14 Aug 2019 14:33:03 -0700 (PDT) X-Google-Smtp-Source: APXvYqxMFqMo09MnLxzNc71D/KGxEfZygIBXvj4gp/bPrxXTjRSEla/q0OXaeQrlIm/4HnH4/OKg X-Received: by 2002:a17:90a:a78b:: with SMTP id f11mr3060pjq.16.1565818383448; Wed, 14 Aug 2019 14:33:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565818383; cv=none; d=google.com; s=arc-20160816; b=U1aJBO8POuUDdITF34dyHcB2O7zhjDrUDPSBNLI9Kgn1/O7aFvudzrdWRQ7xsy8JSw FHPCgzbTMO54CEJSxUvreRadHEPm4wGEQEqG//se9d8nu4og/Rn7lh/SoZyosBoaTp1m lneV8tr7AmsFkx4LX2eK5RWT2xBTIKXTBWOpJRXf9HvaDIatY3GYTIkYc1z5fryil+Bz 9sN9DsS8ucAZuQXVkNL9XKEpkeGsD7oYcbTp8MOn0XKWmE+L3RA2oBlkQB+CeL0ekFVY sRzb/qOpfkBPB0Od+4qnb5mVIkds5ZY5glnbfawcYgPX6PUZQNPpaAGR6ftbPTEXzfzM lzlQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=8/VpPJuBcEAlBq5ppU9bWHqxCKnz3CDU+X2UU9Ge/5A=; b=E9CBLuYd56wzrsBeiRChqaxozKDPmiIhz6W595h4PTFFG/qkt0cH4X7pFB5TVGQ89R EBuE+8PYE8DbXcbp2lrBkGDrSOTIaCzv3/7ABOiu8uS52rcWjmaHNRNG/DDe5tZzbHPX YIi3e4qpANiK3j/qAb9BRVv+n+rLFVnCiEImHVVP71/9VGalE0bAocLHOChbH3KSjLPe GAufQK3onfhkXy4S4NvwHVtNFZJHXaesXFgoqtiwz+ZX4vdNb5iUaR5G52E2XUyhTSTS MaZIG7If8L1njLRUSz5VKHD6H6kwCtD80QctxIEN2oB2RjjeZ85lKDchj5YIKEP2lKCF r+sA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=iFtJZARB; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m20si560001pjn.41.2019.08.14.14.32.47; Wed, 14 Aug 2019 14:33:03 -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; dkim=pass header.i=@linaro.org header.s=google header.b=iFtJZARB; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729090AbfHNUia (ORCPT + 99 others); Wed, 14 Aug 2019 16:38:30 -0400 Received: from mail-oi1-f193.google.com ([209.85.167.193]:44005 "EHLO mail-oi1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727273AbfHNUia (ORCPT ); Wed, 14 Aug 2019 16:38:30 -0400 Received: by mail-oi1-f193.google.com with SMTP id y8so5688924oih.10 for ; Wed, 14 Aug 2019 13:38:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=8/VpPJuBcEAlBq5ppU9bWHqxCKnz3CDU+X2UU9Ge/5A=; b=iFtJZARBLqCuehUIIZ6AX53e0HLaQLvnEVXGI7Gaw53CJuIbJqqJ2/Gw91zRiWBiOr B+AT8Mwb7GgwRNuev7TOp6GfTfnZPTTilFQpSwTpcyVKzFk4xYK2i0026P902uwkbqRe AmebT2nh3FEJohKc7/43Er3nVTZ5QP3OxmuJFOuHgr+cceWB05yqa9nsj0G/KWRzXV8w dA5GGKSMGhAOc9EJP8uv33aO9C6SMwAhBje5dmq5hPod5JjNxJNvIcFy9C489z/Lm+gQ tJPg8UH9nm9pQnfmpw9ZrJPiaOBKfqLMLDLTmit1mVc3vpLGfCBoP+7SQvVheo7TjyXA MV+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=8/VpPJuBcEAlBq5ppU9bWHqxCKnz3CDU+X2UU9Ge/5A=; b=YB8h2ZrE1xKDd0jiDc1Gjlfe6eY19h6DwiOtUckYh0cI4NRPGzOI2FtAkxfoePtxNz JYxK/1su/w8/5bDGYjuL3SwNrPH12XhCZLURmGCBxRwe5eY/L4mkkHoKsbINGSA5ISbc 1waAaMRCog3zLdWNV64UE5NKvqCAtQO5y1Shf9zqVhAL32qrG8n6A7PD7USDphdQcqOA J+couJc/XUjtShxBfWZYYh2G9Dk7UtLtqywO8B/y2XsDV7MbcO8StSyhcxxZq+JigL0I WHzyfgAIUaLhLRaxprXZyuOp//vsyyWCQ9rZWfHKsWIwcLra0/nZ94e01ZkgXFAd+hwl jUbA== X-Gm-Message-State: APjAAAWHGKLWETkCEHBLZs/qzT/QSJldockn+16ua/d8JmC4jkrQFwnq LaGkazZOI5AaenYZ2E5PYprzfCwe29lcTq2miSXbkg== X-Received: by 2002:a02:b609:: with SMTP id h9mr1322561jam.36.1565815109337; Wed, 14 Aug 2019 13:38:29 -0700 (PDT) MIME-Version: 1.0 References: <20190812221154.46875-1-yabinc@google.com> In-Reply-To: <20190812221154.46875-1-yabinc@google.com> From: Mathieu Poirier Date: Wed, 14 Aug 2019 14:38:18 -0600 Message-ID: Subject: Re: [PATCH v2] coresight: tmc-etr: Fix updating buffer in not-snapshot mode. To: Yabin Cui Cc: Suzuki K Poulose , Alexander Shishkin , linux-arm-kernel , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 12 Aug 2019 at 16:11, 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. > > So change to only copy the latest data fitting the available space in > perf aux buffer. > > Signed-off-by: Yabin Cui > --- > > v1 -> v2: copy the latest data instead of the earliest data. > > --- > .../hwtracing/coresight/coresight-tmc-etr.c | 18 +++++++++++------- > 1 file changed, 11 insertions(+), 7 deletions(-) > > diff --git a/drivers/hwtracing/coresight/coresight-tmc-etr.c b/drivers/hwtracing/coresight/coresight-tmc-etr.c > index 17006705287a..676dcb4cf0e2 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; > @@ -1422,8 +1423,7 @@ static void tmc_etr_sync_perf_buffer(struct etr_perf_buffer *etr_perf) > pg_idx = head >> PAGE_SHIFT; > pg_offset = head & (PAGE_SIZE - 1); > dst_pages = (char **)etr_perf->pages; > - src_offset = etr_buf->offset; > - to_copy = etr_buf->len; > + src_offset = etr_buf->offset + etr_buf->len - to_copy; > > while (to_copy > 0) { > /* > @@ -1434,6 +1434,8 @@ static void tmc_etr_sync_perf_buffer(struct etr_perf_buffer *etr_perf) > * 3) what is available in the destination page. > * in one iteration. > */ > + if (src_offset >= etr_buf->size) > + src_offset -= etr_buf->size; > bytes = tmc_etr_buf_get_data(etr_buf, src_offset, to_copy, > &src_buf); > if (WARN_ON_ONCE(bytes <= 0)) > @@ -1454,8 +1456,6 @@ static void tmc_etr_sync_perf_buffer(struct etr_perf_buffer *etr_perf) > > /* Move source pointers */ > src_offset += bytes; > - if (src_offset >= etr_buf->size) > - src_offset -= etr_buf->size; > } > } Yes, much better now. I have applied your work. Thanks, Mathieu > > @@ -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); > > /* > * In snapshot mode we simply increment the head by the number of byte > -- > 2.23.0.rc1.153.gdeed80330f-goog >