Received: by 10.192.165.148 with SMTP id m20csp2239764imm; Thu, 3 May 2018 12:50:48 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrQH1EKyHi1PU1fmxnibiEUynRkMa+VKpKnp0J4bXegUCRmDgWohBkm7judkeC36UmR8XEf X-Received: by 10.98.24.214 with SMTP id 205mr24279276pfy.242.1525377048530; Thu, 03 May 2018 12:50:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525377048; cv=none; d=google.com; s=arc-20160816; b=vo4CA/LG8Drsk4wsWwbP9DAIPODFU7DXUingVcIot0Ke7NvPdp9HDjmMHuaOVw5lNa 3cVmZwTu+M8kYqz9pVoZ9iJHq0p13bHM1DFB+3xOM1/m27HPU1Z7V9c11wED/wK4RVrE krdYWqs1GinxyHutBGmltEHNdwgjpKrEBGp8oZO6cztbjlZR6PZHQXSwyY87lYp8mYnV LxhrzdZlY/PDQYS3zyAAtEc1tHe1XEuk3pFBYycUanhJdpaBlhiDib6tNj9bWkMImg5L fGP6/119Oeoc0bBggcdyCaSxgG2oT48jkAggeBV1ETqQ0TdSuGhxHmYoMFPlnXhHNrOi Gvzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=8TVsF7+/zqK/NzOQAXDpNG1wvHRVslrWEF1g/eghxRY=; b=zZ1enOOO3FLcIm2KNZp1Ngjr/erPLedgP0CSs46uLNmDsgv68kf1Hyx9T5hJ6XwEcz Y1mGGv4vCl0uHNL6n4JcmAmixFxeTrORwbOwaXZBRxJF5CdE5j/lMW6uqLohWKyo++EV W2+f+60SY9IxhCvm4P6lOi+aZ6/lscTD3ShqGxufzgcH2/Zi5y7lthyWcoc0+IVDE/pp +Nl0yIvAkwltUfYEP0v/4Dw7ZPXQhGJkDIGRoDTjUHLZmrbp3GV6IynxQeoxJ/ryvyYD jk6raLfPCbbc2IK3UYnOx9JK6NjG4YhvbujR/uYF2JfQ2aJTBT0QX4GfEckevfhe2duG 0emQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=FDoUmV6z; 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 l7-v6si14419171plg.82.2018.05.03.12.50.34; Thu, 03 May 2018 12:50:48 -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=FDoUmV6z; 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 S1751343AbeECTuS (ORCPT + 99 others); Thu, 3 May 2018 15:50:18 -0400 Received: from mail-pg0-f66.google.com ([74.125.83.66]:41568 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751115AbeECTuR (ORCPT ); Thu, 3 May 2018 15:50:17 -0400 Received: by mail-pg0-f66.google.com with SMTP id m21-v6so13854827pgv.8 for ; Thu, 03 May 2018 12:50:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=8TVsF7+/zqK/NzOQAXDpNG1wvHRVslrWEF1g/eghxRY=; b=FDoUmV6z7/eZnwelrOuNaX8g05e83AoIlNOhePuPC3mcWeWpyoTwnUKT6KoXMyBpbJ 87RiuTXLuC9yBuP3SbfOMOO5zgX/pXtKAz7WWpOMGr9zliAo1AIGJm50rfuQEE8SNoGq o+81rsXNQDoqUtbFPqT60HQM/7M3jV5KsCmtI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=8TVsF7+/zqK/NzOQAXDpNG1wvHRVslrWEF1g/eghxRY=; b=r8E46qLUSV5pIR5A/0vzVCo7Yeqiz/tpN4aYl8pJDZqlOO4V/4c8HyVQCIpIWKq41Q Dcm2yKzv7V6B4a06i4RVMhfUgujpMI80bnLd0IOP58BRKFZWEk7ER893emPD1VwCPuFq OrLELagolDhk+GAKrdp6nH7keV+dtrMsH2Z99Qc4K08CZ/SXMlInxLXX/TuuBzyrlluQ cQVSwAHOWJO/bDSH/Po26+VETAV74xbzdarVWYvNOgLGQfKlEgxp9esH6LpaMO5zyc8N Zo8Gu4rQolA/BQiwfGTGXlCVGnUfYIam8PhTGtiWm5p/r+Od+viwEL+CCQ3Y2NnSJeW5 PkAQ== X-Gm-Message-State: ALQs6tB3bFSZJ4rMS8I/IjAAO82jCllqrUEk196gkefrZ0m1TDwElaO0 kDA0dcAB2NEkamQfZsUvDaUe0A== X-Received: by 2002:a63:7341:: with SMTP id d1-v6mr19859267pgn.404.1525377016371; Thu, 03 May 2018 12:50:16 -0700 (PDT) Received: from xps15 (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id j1-v6sm24250332pgn.69.2018.05.03.12.50.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 03 May 2018 12:50:15 -0700 (PDT) Date: Thu, 3 May 2018 13:50:13 -0600 From: Mathieu Poirier To: Suzuki K Poulose Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, mike.leach@linaro.org, robert.walker@arm.com, mark.rutland@arm.com, will.deacon@arm.com, robin.murphy@arm.com, sudeep.holla@arm.com, frowand.list@gmail.com, robh@kernel.org, john.horley@arm.com Subject: Re: [PATCH v2 07/27] coresight: tmc: Hide trace buffer handling for file read Message-ID: <20180503195013.GC11425@xps15> References: <1525165857-11096-1-git-send-email-suzuki.poulose@arm.com> <1525165857-11096-8-git-send-email-suzuki.poulose@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1525165857-11096-8-git-send-email-suzuki.poulose@arm.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, May 01, 2018 at 10:10:37AM +0100, Suzuki K Poulose wrote: > At the moment we adjust the buffer pointers for reading the trace > data via misc device in the common code for ETF/ETB and ETR. Since > we are going to change how we manage the buffer for ETR, let us > move the buffer manipulation to the respective driver files, hiding > it from the common code. We do so by adding type specific helpers > for finding the length of data and the pointer to the buffer, > for a given length at a file position. > > Cc: Mathieu Poirier > Signed-off-by: Suzuki K Poulose > --- > drivers/hwtracing/coresight/coresight-tmc-etf.c | 18 +++++++++++ > drivers/hwtracing/coresight/coresight-tmc-etr.c | 34 ++++++++++++++++++++ > drivers/hwtracing/coresight/coresight-tmc.c | 41 ++++++++++++++----------- > drivers/hwtracing/coresight/coresight-tmc.h | 4 +++ > 4 files changed, 79 insertions(+), 18 deletions(-) > > diff --git a/drivers/hwtracing/coresight/coresight-tmc-etf.c b/drivers/hwtracing/coresight/coresight-tmc-etf.c > index e2513b7..2113e93 100644 > --- a/drivers/hwtracing/coresight/coresight-tmc-etf.c > +++ b/drivers/hwtracing/coresight/coresight-tmc-etf.c > @@ -120,6 +120,24 @@ static void tmc_etf_disable_hw(struct tmc_drvdata *drvdata) > CS_LOCK(drvdata->base); > } > > +/* > + * Return the available trace data in the buffer from @pos, with > + * a maximum limit of @len, updating the @bufpp on where to > + * find it. > + */ > +ssize_t tmc_etb_get_sysfs_trace(struct tmc_drvdata *drvdata, > + loff_t pos, size_t len, char **bufpp) > +{ > + ssize_t actual = len; > + > + /* Adjust the len to available size @pos */ > + if (pos + actual > drvdata->len) > + actual = drvdata->len - pos; > + if (actual > 0) > + *bufpp = drvdata->buf + pos; > + return actual; > +} > + > static int tmc_enable_etf_sink_sysfs(struct coresight_device *csdev) > { > int ret = 0; > diff --git a/drivers/hwtracing/coresight/coresight-tmc-etr.c b/drivers/hwtracing/coresight/coresight-tmc-etr.c > index bff46f2..53a17a8 100644 > --- a/drivers/hwtracing/coresight/coresight-tmc-etr.c > +++ b/drivers/hwtracing/coresight/coresight-tmc-etr.c > @@ -92,6 +92,40 @@ static void tmc_etr_enable_hw(struct tmc_drvdata *drvdata) > CS_LOCK(drvdata->base); > } > > +/* > + * Return the available trace data in the buffer @pos, with a maximum > + * limit of @len, also updating the @bufpp on where to find it. > + */ > +ssize_t tmc_etr_get_sysfs_trace(struct tmc_drvdata *drvdata, > + loff_t pos, size_t len, char **bufpp) > +{ > + ssize_t actual = len; > + char *bufp = drvdata->buf + pos; > + char *bufend = (char *)(drvdata->vaddr + drvdata->size); > + > + /* Adjust the len to available size @pos */ > + if (pos + actual > drvdata->len) > + actual = drvdata->len - pos; > + > + if (actual <= 0) > + return actual; > + > + /* > + * Since we use a circular buffer, with trace data starting > + * @drvdata->buf, possibly anywhere in the buffer @drvdata->vaddr, > + * wrap the current @pos to within the buffer. > + */ > + if (bufp >= bufend) > + bufp -= drvdata->size; > + /* > + * For simplicity, avoid copying over a wrapped around buffer. > + */ > + if ((bufp + actual) > bufend) > + actual = bufend - bufp; > + *bufpp = bufp; > + return actual; > +} > + > static void tmc_etr_dump_hw(struct tmc_drvdata *drvdata) > { > const u32 *barrier; > diff --git a/drivers/hwtracing/coresight/coresight-tmc.c b/drivers/hwtracing/coresight/coresight-tmc.c > index 0ea04f5..7a4e84f 100644 > --- a/drivers/hwtracing/coresight/coresight-tmc.c > +++ b/drivers/hwtracing/coresight/coresight-tmc.c > @@ -131,35 +131,40 @@ static int tmc_open(struct inode *inode, struct file *file) > return 0; > } > > +static inline ssize_t tmc_get_sysfs_trace(struct tmc_drvdata *drvdata, > + loff_t pos, size_t len, char **bufpp) > +{ > + switch (drvdata->config_type) { > + case TMC_CONFIG_TYPE_ETB: > + case TMC_CONFIG_TYPE_ETF: > + return tmc_etb_get_sysfs_trace(drvdata, pos, len, bufpp); > + case TMC_CONFIG_TYPE_ETR: > + return tmc_etr_get_sysfs_trace(drvdata, pos, len, bufpp); > + } > + > + return -EINVAL; Extra space betwen return and -EINVAL. > +} > + > static ssize_t tmc_read(struct file *file, char __user *data, size_t len, > loff_t *ppos) > { > + char *bufp; > + ssize_t actual; > struct tmc_drvdata *drvdata = container_of(file->private_data, > struct tmc_drvdata, miscdev); > - char *bufp = drvdata->buf + *ppos; > + actual = tmc_get_sysfs_trace(drvdata, *ppos, len, &bufp); > + if (actual <= 0) > + return 0; > > - if (*ppos + len > drvdata->len) > - len = drvdata->len - *ppos; > - > - if (drvdata->config_type == TMC_CONFIG_TYPE_ETR) { > - if (bufp == (char *)(drvdata->vaddr + drvdata->size)) > - bufp = drvdata->vaddr; > - else if (bufp > (char *)(drvdata->vaddr + drvdata->size)) > - bufp -= drvdata->size; > - if ((bufp + len) > (char *)(drvdata->vaddr + drvdata->size)) > - len = (char *)(drvdata->vaddr + drvdata->size) - bufp; > - } > - > - if (copy_to_user(data, bufp, len)) { > + if (copy_to_user(data, bufp, actual)) { > dev_dbg(drvdata->dev, "%s: copy_to_user failed\n", __func__); > return -EFAULT; > } > > - *ppos += len; > + *ppos += actual; > + dev_dbg(drvdata->dev, "%zu bytes copied\n", actual); > > - dev_dbg(drvdata->dev, "%s: %zu bytes copied, %d bytes left\n", > - __func__, len, (int)(drvdata->len - *ppos)); > - return len; > + return actual; > } > > static int tmc_release(struct inode *inode, struct file *file) > diff --git a/drivers/hwtracing/coresight/coresight-tmc.h b/drivers/hwtracing/coresight/coresight-tmc.h > index cdff853..9cbc4d5 100644 > --- a/drivers/hwtracing/coresight/coresight-tmc.h > +++ b/drivers/hwtracing/coresight/coresight-tmc.h > @@ -184,10 +184,14 @@ int tmc_read_unprepare_etb(struct tmc_drvdata *drvdata); > extern const struct coresight_ops tmc_etb_cs_ops; > extern const struct coresight_ops tmc_etf_cs_ops; > > +ssize_t tmc_etb_get_sysfs_trace(struct tmc_drvdata *drvdata, > + loff_t pos, size_t len, char **bufpp); > /* ETR functions */ > int tmc_read_prepare_etr(struct tmc_drvdata *drvdata); > int tmc_read_unprepare_etr(struct tmc_drvdata *drvdata); > extern const struct coresight_ops tmc_etr_cs_ops; > +ssize_t tmc_etr_get_sysfs_trace(struct tmc_drvdata *drvdata, > + loff_t pos, size_t len, char **bufpp); > > > #define TMC_REG_PAIR(name, lo_off, hi_off) \ > -- > 2.7.4 >