From 7d80855aa8f2b4d38d3e6c3bdf9b3b90c88978d1 Mon Sep 17 00:00:00 2001 From: Mao Jinlong Date: Fri, 29 Oct 2021 15:12:42 +0800 Subject: [PATCH 1/4] byte-cntr: Enable qdss clock before getting the rwp offset QDSS clock need to be enabled before reading the etr rwp offset otherwise there will be register access issue. Change-Id: Ie9ba3f3ae742d3f319bece47508fd6e636f608c7 Signed-off-by: Mao Jinlong --- .../hwtracing/coresight/coresight-byte-cntr.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/drivers/hwtracing/coresight/coresight-byte-cntr.c b/drivers/hwtracing/coresight/coresight-byte-cntr.c index 80f2a3f6322c..3487f7c90ec8 100644 --- a/drivers/hwtracing/coresight/coresight-byte-cntr.c +++ b/drivers/hwtracing/coresight/coresight-byte-cntr.c @@ -58,9 +58,24 @@ static long tmc_etr_flush_remaining_bytes(struct tmc_drvdata *tmcdrvdata, loff_t char **bufpp) { long rwp_offset, req_size, actual = 0; - struct etr_buf *etr_buf = tmcdrvdata->sysfs_buf; + struct etr_buf *etr_buf; + struct device *dev; + int rc = 0; + + if (!tmcdrvdata) + return -EINVAL; + + etr_buf = tmcdrvdata->sysfs_buf; + dev = &tmcdrvdata->csdev->dev; + + rc = pm_runtime_get_sync(dev->parent); + if (rc < 0) { + pm_runtime_put_noidle(dev->parent); + return rc; + } rwp_offset = tmc_get_rwp_offset(tmcdrvdata); + pm_runtime_put(dev->parent); req_size = ((rwp_offset < *ppos) ? tmcdrvdata->size : 0) + rwp_offset - *ppos; From 7e1ac1f82370b10fab23ad52810e79c64dd1232a Mon Sep 17 00:00:00 2001 From: Tao Zhang Date: Fri, 14 Jan 2022 11:21:19 +0800 Subject: [PATCH 2/4] coresight: add debug log to coresight-tmc Add debug log for byte-cntr and sw usb to count the data sent by coresight-tmc. Change-Id: I2491c1c79930cecb0e0e680eb357211f6c8aa38c Signed-off-by: Yuanfang Zhang Signed-off-by: Tao Zhang Signed-off-by: Mao Jinlong --- .../hwtracing/coresight/coresight-byte-cntr.c | 24 ++++++++++++++++++- .../hwtracing/coresight/coresight-byte-cntr.h | 6 ++++- .../hwtracing/coresight/coresight-tmc-usb.c | 10 ++++++-- 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-byte-cntr.c b/drivers/hwtracing/coresight/coresight-byte-cntr.c index 3487f7c90ec8..6f0d4494595f 100644 --- a/drivers/hwtracing/coresight/coresight-byte-cntr.c +++ b/drivers/hwtracing/coresight/coresight-byte-cntr.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-only /* - * Copyright (c) 2021 Qualcomm Innovation Center, Inc. All rights reserved. + * Copyright (c) 2021-2022 Qualcomm Innovation Center, Inc. All rights reserved. */ #include @@ -50,6 +50,8 @@ static irqreturn_t etr_handler(int irq, void *data) wake_up(&byte_cntr_data->wq); } + byte_cntr_data->total_irq++; + return IRQ_HANDLED; } @@ -152,6 +154,8 @@ static ssize_t tmc_etr_byte_cntr_read(struct file *fp, char __user *data, return -EFAULT; } + byte_cntr_data->total_size += len; + if (*ppos + len >= tmcdrvdata->size) *ppos = 0; else @@ -207,6 +211,8 @@ EXPORT_SYMBOL(tmc_etr_byte_cntr_stop); static int tmc_etr_byte_cntr_release(struct inode *in, struct file *fp) { struct byte_cntr *byte_cntr_data = fp->private_data; + struct device *dev = &byte_cntr_data->tmcdrvdata->csdev->dev; + int rc; mutex_lock(&byte_cntr_data->byte_cntr_lock); byte_cntr_data->read_active = false; @@ -218,6 +224,21 @@ static int tmc_etr_byte_cntr_release(struct inode *in, struct file *fp) byte_cntr_data->irqctrl_offset, 0); disable_irq_wake(byte_cntr_data->byte_cntr_irq); + + rc = pm_runtime_get_sync(dev->parent); + if (rc < 0) { + pm_runtime_put_noidle(dev->parent); + } else { + byte_cntr_data->rwp_offset = + tmc_get_rwp_offset(byte_cntr_data->tmcdrvdata); + + pm_runtime_put(dev->parent); + } + + dev_dbg(dev, "send data total size: %lld bytes, irq_cnt: %lld, offset: %lld rwp_offset: %lld\n", + byte_cntr_data->total_size, byte_cntr_data->total_irq, + byte_cntr_data->offset, byte_cntr_data->rwp_offset); + byte_cntr_data->total_irq = 0; mutex_unlock(&byte_cntr_data->byte_cntr_lock); return 0; @@ -254,6 +275,7 @@ static int tmc_etr_byte_cntr_open(struct inode *in, struct file *fp) nonseekable_open(in, fp); byte_cntr_data->enable = true; byte_cntr_data->read_active = true; + byte_cntr_data->total_size = 0; mutex_unlock(&byte_cntr_data->byte_cntr_lock); return 0; } diff --git a/drivers/hwtracing/coresight/coresight-byte-cntr.h b/drivers/hwtracing/coresight/coresight-byte-cntr.h index 3380fda029f8..634e8724bdd9 100644 --- a/drivers/hwtracing/coresight/coresight-byte-cntr.h +++ b/drivers/hwtracing/coresight/coresight-byte-cntr.h @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0-only */ /* - * Copyright (c) 2021 Qualcomm Innovation Center, Inc. All rights reserved. + * Copyright (c) 2021-2022 Qualcomm Innovation Center, Inc. All rights reserved. */ #ifndef _CORESIGHT_BYTE_CNTR_H @@ -34,6 +34,10 @@ struct byte_cntr { const char *class_name; int irqctrl_offset; unsigned long offset; + unsigned long rwp_offset; + uint64_t total_size; + uint64_t total_irq; + }; extern void tmc_etr_byte_cntr_start(struct byte_cntr *byte_cntr_data); diff --git a/drivers/hwtracing/coresight/coresight-tmc-usb.c b/drivers/hwtracing/coresight/coresight-tmc-usb.c index 5269ac139ce8..e322558b250b 100644 --- a/drivers/hwtracing/coresight/coresight-tmc-usb.c +++ b/drivers/hwtracing/coresight/coresight-tmc-usb.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-only /* - * Copyright (c) 2021 Qualcomm Innovation Center, Inc. All rights reserved. + * Copyright (c) 2021-2022 Qualcomm Innovation Center, Inc. All rights reserved. * * Description: CoreSight TMC USB driver */ @@ -82,6 +82,7 @@ static int usb_bypass_start(struct byte_cntr *byte_cntr_data) USB_BLK_SIZE / 8); atomic_set(&byte_cntr_data->irq_cnt, 0); + byte_cntr_data->total_size = 0; mutex_unlock(&byte_cntr_data->usb_bypass_lock); return 0; @@ -102,6 +103,10 @@ static void usb_bypass_stop(struct byte_cntr *byte_cntr_data) wake_up(&byte_cntr_data->usb_wait_wq); pr_info("coresight: stop usb bypass\n"); coresight_csr_set_byte_cntr(byte_cntr_data->csr, byte_cntr_data->irqctrl_offset, 0); + dev_dbg(&byte_cntr_data->tmcdrvdata->csdev->dev, + "write to usb data total size: %lld bytes, irq_cnt: %lld, offset: %ld\n", + byte_cntr_data->total_size, byte_cntr_data->total_irq, byte_cntr_data->offset); + byte_cntr_data->total_irq = 0; mutex_unlock(&byte_cntr_data->usb_bypass_lock); } @@ -172,7 +177,7 @@ static int usb_transfer_small_packet(struct byte_cntr *drvdata, size_t *small_si "Write data failed:%d\n", ret); goto out; } - + drvdata->total_size += actual; atomic_dec(&drvdata->usb_free_buf); } else { dev_dbg(&tmcdrvdata->csdev->dev, @@ -289,6 +294,7 @@ static void usb_read_work_fn(struct work_struct *work) continue; return; } + drvdata->total_size += actual_total; atomic_dec(&drvdata->usb_free_buf); } else { From fa43ed19f78860f43d1fcbb0c5f0d1c7c83674d6 Mon Sep 17 00:00:00 2001 From: Mao Jinlong Date: Wed, 6 Apr 2022 18:28:04 +0800 Subject: [PATCH 3/4] coresight: byte-cntr: Read data from current rwp offset When enable byte-cntr, read data from current rwp offset instead of the begainning of the ETR buffer. Change-Id: I485aeea97de774055179ccb4c8eb9fe7fb6b0ab1 Signed-off-by: Mao Jinlong --- .../hwtracing/coresight/coresight-byte-cntr.c | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-byte-cntr.c b/drivers/hwtracing/coresight/coresight-byte-cntr.c index 6f0d4494595f..3aaa600589b2 100644 --- a/drivers/hwtracing/coresight/coresight-byte-cntr.c +++ b/drivers/hwtracing/coresight/coresight-byte-cntr.c @@ -18,7 +18,7 @@ #define CSR_BYTECNTVAL (0x06C) -static void tmc_etr_read_bytes(struct byte_cntr *byte_cntr_data, loff_t *ppos, +static void tmc_etr_read_bytes(struct byte_cntr *byte_cntr_data, long offset, size_t bytes, size_t *len, char **bufp) { struct tmc_drvdata *tmcdrvdata = byte_cntr_data->tmcdrvdata; @@ -27,12 +27,12 @@ static void tmc_etr_read_bytes(struct byte_cntr *byte_cntr_data, loff_t *ppos, if (*len >= bytes) *len = bytes; - else if (((uint32_t)*ppos % bytes) + *len > bytes) - *len = bytes - ((uint32_t)*ppos % bytes); + else if (((uint32_t)offset % bytes) + *len > bytes) + *len = bytes - ((uint32_t)offset % bytes); - actual = tmc_etr_buf_get_data(etr_buf, *ppos, *len, bufp); + actual = tmc_etr_buf_get_data(etr_buf, offset, *len, bufp); *len = actual; - if (actual == bytes || (actual + (uint32_t)*ppos) % bytes == 0) + if (actual == bytes || (actual + (uint32_t)offset) % bytes == 0) atomic_dec(&byte_cntr_data->irq_cnt); } @@ -56,7 +56,7 @@ static irqreturn_t etr_handler(int irq, void *data) } -static long tmc_etr_flush_remaining_bytes(struct tmc_drvdata *tmcdrvdata, loff_t *ppos, +static long tmc_etr_flush_remaining_bytes(struct tmc_drvdata *tmcdrvdata, long offset, char **bufpp) { long rwp_offset, req_size, actual = 0; @@ -78,11 +78,11 @@ static long tmc_etr_flush_remaining_bytes(struct tmc_drvdata *tmcdrvdata, loff_t rwp_offset = tmc_get_rwp_offset(tmcdrvdata); pm_runtime_put(dev->parent); - req_size = ((rwp_offset < *ppos) ? tmcdrvdata->size : 0) + - rwp_offset - *ppos; + req_size = ((rwp_offset < offset) ? tmcdrvdata->size : 0) + + rwp_offset - offset; if (req_size > 0) - actual = tmc_etr_buf_get_data(etr_buf, *ppos, req_size, bufpp); + actual = tmc_etr_buf_get_data(etr_buf, offset, req_size, bufpp); return actual; } @@ -102,7 +102,8 @@ static ssize_t tmc_etr_byte_cntr_read(struct file *fp, char __user *data, mutex_lock(&byte_cntr_data->byte_cntr_lock); if (!byte_cntr_data->read_active) { - actual = tmc_etr_flush_remaining_bytes(tmcdrvdata, ppos, &bufp); + actual = tmc_etr_flush_remaining_bytes(tmcdrvdata, + byte_cntr_data->offset, &bufp); if (actual > 0) { len = actual; goto copy; @@ -121,7 +122,8 @@ static ssize_t tmc_etr_byte_cntr_read(struct file *fp, char __user *data, return -ERESTARTSYS; mutex_lock(&byte_cntr_data->byte_cntr_lock); if (!byte_cntr_data->read_active) { - actual = tmc_etr_flush_remaining_bytes(tmcdrvdata, ppos, &bufp); + actual = tmc_etr_flush_remaining_bytes(tmcdrvdata, + byte_cntr_data->offset, &bufp); if (actual > 0) { len = actual; goto copy; @@ -132,11 +134,12 @@ static ssize_t tmc_etr_byte_cntr_read(struct file *fp, char __user *data, } } - tmc_etr_read_bytes(byte_cntr_data, ppos, + tmc_etr_read_bytes(byte_cntr_data, byte_cntr_data->offset, byte_cntr_data->block_size, &len, &bufp); } else { - actual = tmc_etr_flush_remaining_bytes(tmcdrvdata, ppos, &bufp); + actual = tmc_etr_flush_remaining_bytes(tmcdrvdata, + byte_cntr_data->offset, &bufp); if (actual > 0) { len = actual; goto copy; @@ -156,10 +159,10 @@ static ssize_t tmc_etr_byte_cntr_read(struct file *fp, char __user *data, byte_cntr_data->total_size += len; - if (*ppos + len >= tmcdrvdata->size) - *ppos = 0; + if (byte_cntr_data->offset + len >= tmcdrvdata->size) + byte_cntr_data->offset = 0; else - *ppos += len; + byte_cntr_data->offset += len; goto out; @@ -276,6 +279,7 @@ static int tmc_etr_byte_cntr_open(struct inode *in, struct file *fp) byte_cntr_data->enable = true; byte_cntr_data->read_active = true; byte_cntr_data->total_size = 0; + byte_cntr_data->offset = tmc_get_rwp_offset(tmcdrvdata); mutex_unlock(&byte_cntr_data->byte_cntr_lock); return 0; } From 2ee721536f4fdd4d9881020a7c541c104224a6b1 Mon Sep 17 00:00:00 2001 From: Tao Zhang Date: Fri, 12 Aug 2022 19:57:14 +0800 Subject: [PATCH 4/4] coresight: byte-cntr: Add the length check in reading data Add the length check in the reading method to avoid data overwirtten. Change-Id: I79a467fe39d491dfdee267d8e6209c34a3b04269 Signed-off-by: Tao Zhang Signed-off-by: Mao Jinlong --- drivers/hwtracing/coresight/coresight-byte-cntr.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-byte-cntr.c b/drivers/hwtracing/coresight/coresight-byte-cntr.c index 3aaa600589b2..e30d2d8127a5 100644 --- a/drivers/hwtracing/coresight/coresight-byte-cntr.c +++ b/drivers/hwtracing/coresight/coresight-byte-cntr.c @@ -57,7 +57,7 @@ static irqreturn_t etr_handler(int irq, void *data) static long tmc_etr_flush_remaining_bytes(struct tmc_drvdata *tmcdrvdata, long offset, - char **bufpp) + size_t len, char **bufpp) { long rwp_offset, req_size, actual = 0; struct etr_buf *etr_buf; @@ -81,6 +81,9 @@ static long tmc_etr_flush_remaining_bytes(struct tmc_drvdata *tmcdrvdata, long o req_size = ((rwp_offset < offset) ? tmcdrvdata->size : 0) + rwp_offset - offset; + if (req_size > len) + req_size = len; + if (req_size > 0) actual = tmc_etr_buf_get_data(etr_buf, offset, req_size, bufpp); @@ -103,7 +106,7 @@ static ssize_t tmc_etr_byte_cntr_read(struct file *fp, char __user *data, mutex_lock(&byte_cntr_data->byte_cntr_lock); if (!byte_cntr_data->read_active) { actual = tmc_etr_flush_remaining_bytes(tmcdrvdata, - byte_cntr_data->offset, &bufp); + byte_cntr_data->offset, len, &bufp); if (actual > 0) { len = actual; goto copy; @@ -123,7 +126,7 @@ static ssize_t tmc_etr_byte_cntr_read(struct file *fp, char __user *data, mutex_lock(&byte_cntr_data->byte_cntr_lock); if (!byte_cntr_data->read_active) { actual = tmc_etr_flush_remaining_bytes(tmcdrvdata, - byte_cntr_data->offset, &bufp); + byte_cntr_data->offset, len, &bufp); if (actual > 0) { len = actual; goto copy; @@ -139,7 +142,7 @@ static ssize_t tmc_etr_byte_cntr_read(struct file *fp, char __user *data, } else { actual = tmc_etr_flush_remaining_bytes(tmcdrvdata, - byte_cntr_data->offset, &bufp); + byte_cntr_data->offset, len, &bufp); if (actual > 0) { len = actual; goto copy;