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 <quic_jinlmao@quicinc.com>
This commit is contained in:
Mao Jinlong 2022-09-06 08:23:43 +08:00 committed by Gerrit - the friendly Code Review server
parent cb5ed64bbf
commit 15c0fa5355

View File

@ -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.