Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp122717ybl; Mon, 12 Aug 2019 12:55:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqyPBnDRHY6335fn4IoafBjo1MT9Bf6a1e3L/6UuY3ZjgwWiYOpDJCMGiNfdMVV42Qwn4mel X-Received: by 2002:a65:6850:: with SMTP id q16mr32416748pgt.423.1565639745889; Mon, 12 Aug 2019 12:55:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565639745; cv=none; d=google.com; s=arc-20160816; b=LU1Ml2jwNN0FarJCU/kIcih6QnmUygMtUnpocnHYQkRorx3NgbofIVpzdeAzgZBkw3 RzZRYdXf96eXoTp0nkOZ6Rwc8z+DERjgSdss2I/qCPJ3Pj2X3iDzUAVmppDdju9jTz/z 2id6uGOMkDgZQQHB14H1DVaACfPaarITORIkzjJ3RS/wTRSSB448pgzOHnUDjL+1p6u6 3Ia0HBesktTMoIZinBuOeJEi2yVbIiK60I911I98+z6NUiUjdovopKUL6gQjtXGYenvy 3lmMz/Fqag9n2SZZ17ki+0CBpQasvxhLQ0/A8BJVA57OEZqV4mFGZFYhuz+WAKJGT7f4 tH0Q== 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=xdTaSZFMc5c0WlaR2P3h3aNLmfWS7MtBN6nvtQBsHM0=; b=aecNOVi2A5KFc9eTR0m2TyY0llKEOjaZzNhOQvCNFcofaPxRPmvUR+RhCEhOfNguum IKhYvhG2SagUsS+EDND20DSNeKLVD6b61b1dg0nCXGgm9JAwFB3Kepa6+D0uU/jx0Emq cQiVvE+4K2HeJviXnMGitte4snROIq8MCD2oGj1ufqNDLpF+dvgVGV0KLIUZkcEG0gOF qZjZfvrcdsdzf5lJVNiUv2mgr6wdc5iZFoXkobdH+GX3/nbbUhO7bWXOXxEo6ZDiaVYH tf+4wsvbN9vfu03ztzdC4QBRJQuKdHPz2j/8wj0f0Su2vNq9qpkrQVoR+7x7RWN5Zfw1 ytUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wOXQsMpK; 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 y16si66413117pgj.169.2019.08.12.12.55.30; Mon, 12 Aug 2019 12:55:45 -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=wOXQsMpK; 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 S1727087AbfHLTwZ (ORCPT + 99 others); Mon, 12 Aug 2019 15:52:25 -0400 Received: from mail-ot1-f65.google.com ([209.85.210.65]:38717 "EHLO mail-ot1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726679AbfHLTwZ (ORCPT ); Mon, 12 Aug 2019 15:52:25 -0400 Received: by mail-ot1-f65.google.com with SMTP id r20so13708784ota.5 for ; Mon, 12 Aug 2019 12:52:24 -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=xdTaSZFMc5c0WlaR2P3h3aNLmfWS7MtBN6nvtQBsHM0=; b=wOXQsMpKls2n2TWvbygbodoRbilCT7zxfywZx8W9fg1DsdaPvB+TWjAJKecI0MwLma HPkyKCzyphSBstyhyr2OoGDSiqolOIW4UYiEmDOYnlvbZs/T+IHfNmqjCEm0mUnV0zDN K66Rav+9mPw4nRCZh8YzfrZzyTewjwRc/YQatITPJNKwAlkwb2IbNsGNKetKp9nyyQ6L bu8DgM2Uccyr/Y0L/CuazZBwuIWOvb8pp/lrMVDZgK1+WuKSciTIRyvm4uO67nE5iCVA YYUjAE1TiFd1125P2QenAH5Wti81+Pj5qr9pBmKXoSiE6s0tWuBYW1+jD2R8nYKNvHzg rjOQ== 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=xdTaSZFMc5c0WlaR2P3h3aNLmfWS7MtBN6nvtQBsHM0=; b=geZUVx4LFGvdh7B9xBTO6K96aggQVG2sEM3dLjvA4tnphMOnUhNLBwPn4muu5tcUGI xcrocP/EHw7oRzDfJ/Ac2gmO0Gx7pgT8v19A3QKw60zcGyYezbZoJ36Iz4NqEQLVsAHQ RBX024p96qz39sDj+t3iFf0KC1LF/4RhCVYMqcS7vucexD/nr4jyJb8PT1aBF8y9Mkye /+30d3roNngJ/7w7I3LXmvsQ/5nNBktpbmQE2qS8bXRO/pADjdlUcgu2ulULy/LZvb8I SNQhn8kSQYDGF4GkkBYlaGUAe718vygM4iUHA5EYB7hx8HSBDw3+4L68i80q1NE5ff2y qLig== X-Gm-Message-State: APjAAAX1Dp+NbX5mIZO2xziOrO+XfUoDXtFlrzlbyKZMSgezPC4wGnCr wKMuB059NOyrv3C5mZWhmrrOX19jBEtfCvN5q9Jd4w== X-Received: by 2002:a02:8663:: with SMTP id e90mr40014405jai.98.1565639543943; Mon, 12 Aug 2019 12:52:23 -0700 (PDT) MIME-Version: 1.0 References: <20190805233738.136357-1-yabinc@google.com> In-Reply-To: <20190805233738.136357-1-yabinc@google.com> From: Mathieu Poirier Date: Mon, 12 Aug 2019 13:52:12 -0600 Message-ID: Subject: Re: [PATCH] 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 Good day Yabin, With this patch you are addressing a long time itch I had - please read on. On Mon, 5 Aug 2019 at 17: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. > > 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; > + } Perfect - this is in line with what is done for ETB and ETF. > + tmc_etr_sync_perf_buffer(etr_perf, size); Here tmc_etr_sync_perf_buffer() will copy data to the perf ring buffer starting at @etr_perf->offset for @size, clipping the _end_ of the trace data accumulated in the trace buffer. This is contrary to what is done for ETB and ETF where the equivalent of @etr_perf->offset is moved forward (clipping the _beginning_ of the trace data) in order to keep as much of the end as possible. I would rather enact the same heuristic here. Thanks, Mathieu > > /* > * In snapshot mode we simply increment the head by the number of byte > -- > 2.22.0.770.g0f2c4a37fd-goog >