From 15c0fa5355a3e8416fe124a492bdc9caee7a9cea Mon Sep 17 00:00:00 2001 From: Mao Jinlong Date: Tue, 6 Sep 2022 08:23:43 +0800 Subject: [PATCH] coresight: etr: Don't allocate the new buffer when etr is enabled When ETR is enabled, new buffer is not necessary to be allocated even if buffer size is changed. This change can avoid some unnecessary allocation of ETR buffer. Change-Id: Ia39a99bb46c5c3f18ffc19bcc2a5cdf9ca086bbb Signed-off-by: Mao Jinlong --- .../hwtracing/coresight/coresight-tmc-etr.c | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-tmc-etr.c b/drivers/hwtracing/coresight/coresight-tmc-etr.c index 8724bb349944..a544b81dee21 100644 --- a/drivers/hwtracing/coresight/coresight-tmc-etr.c +++ b/drivers/hwtracing/coresight/coresight-tmc-etr.c @@ -1249,6 +1249,22 @@ static int tmc_enable_etr_sink_sysfs(struct coresight_device *csdev) struct tmc_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent); struct etr_buf *sysfs_buf = NULL, *new_buf = NULL, *free_buf = NULL; + spin_lock_irqsave(&drvdata->spinlock, flags); + if (drvdata->reading || drvdata->mode == CS_MODE_PERF) { + ret = -EBUSY; + goto unlock_out; + } + + /* + * In sysFS mode we can have multiple writers per sink. Since this + * sink is already enabled no memory is needed and the HW need not be + * touched, even if the buffer size has changed. + */ + if (drvdata->mode == CS_MODE_SYSFS) { + atomic_inc(csdev->refcnt); + goto unlock_out; + } + /* * If we are enabling the ETR from disabled state, we need to make * sure we have a buffer with the right size. The etr_buf is not reset @@ -1257,7 +1273,6 @@ static int tmc_enable_etr_sink_sysfs(struct coresight_device *csdev) * buffer, provided the size matches. Any allocation has to be done * with the lock released. */ - spin_lock_irqsave(&drvdata->spinlock, flags); if ((drvdata->out_mode == TMC_ETR_OUT_MODE_MEM) || (drvdata->out_mode == TMC_ETR_OUT_MODE_USB && drvdata->usb_data->usb_mode == @@ -1280,21 +1295,6 @@ static int tmc_enable_etr_sink_sysfs(struct coresight_device *csdev) } } - if (drvdata->reading || drvdata->mode == CS_MODE_PERF) { - ret = -EBUSY; - goto unlock_out; - } - - /* - * In sysFS mode we can have multiple writers per sink. Since this - * sink is already enabled no memory is needed and the HW need not be - * touched, even if the buffer size has changed. - */ - if (drvdata->mode == CS_MODE_SYSFS) { - atomic_inc(csdev->refcnt); - goto unlock_out; - } - /* * If we don't have a buffer or it doesn't match the requested size, * use the buffer allocated above. Otherwise reuse the existing buffer.