[Sound-open-firmware] [RFC PATCH v2 20/29] Change macro definition and trace calling for volume.

yan.wang at linux.intel.com yan.wang at linux.intel.com
Fri May 11 08:36:02 CEST 2018


From: Yan Wang <yan.wang at linux.intel.com>

It will use VOLUME trace class and component DMA trace API.
For trace calling of volume_new(), NULL will be passed into trace
API because comp_dev hasn't been initialized.

Signed-off-by: Yan Wang <yan.wang at linux.intel.com>
---
Test with:
CNL nocodec
SOF master: c1f2682c210201bbbc96fce7b382b25b90d19775
SOF-Tool master: 86fe688a2b4f68a1ce87e0951686be12a00f1a3c
https://github.com/plbossart/sound/tree/topic/sof-v4.14:
d09db67c5a9d6dfc85f700669fa2e43c678c8d51
---
 src/audio/volume.c | 121 +++++++++++++++++++++++++++++------------------------
 1 file changed, 66 insertions(+), 55 deletions(-)

diff --git a/src/audio/volume.c b/src/audio/volume.c
index d0b690b..8d8eb70 100644
--- a/src/audio/volume.c
+++ b/src/audio/volume.c
@@ -43,9 +43,18 @@
 #include <sof/audio/pipeline.h>
 #include <sof/audio/format.h>
 
-#define trace_volume(__e)	trace_event(TRACE_CLASS_VOLUME, __e)
-#define tracev_volume(__e)	tracev_event(TRACE_CLASS_VOLUME, __e)
-#define trace_volume_error(__e)	trace_error(TRACE_CLASS_VOLUME, __e)
+#define trace_volume(cd, __e) \
+	trace_comp_event(cd, NORMAL_LEVEL, TRACE_CLASS_VOLUME, __e)
+#define tracev_volume(cd, __e) \
+	trace_comp_event(cd, VERBOSE_LEVEL, TRACE_CLASS_VOLUME, __e)
+#define trace_volume_error(cd, __e) \
+	trace_comp_event_atomic(cd, ERROR_LEVEL, TRACE_CLASS_VOLUME, __e)
+#define trace_volume_value(cd, x) \
+	trace_comp_value(cd, NORMAL_LEVEL, x)
+#define tracev_volume_value(cd, x) \
+	trace_comp_value(cd, VERBOSE_LEVEL, x)
+#define trace_volume_error_value(cd, x) \
+	trace_comp_value_atomic(cd, ERROR_LEVEL, x)
 
 /* this should ramp from 0dB to mute in 64ms.
  * i.e 2^16 -> 0 in 32 * 2048 steps each lasting 2ms
@@ -538,7 +547,8 @@ static const struct comp_func_map func_map[] = {
 };
 
 /* synchronise host mmap() volume with real value */
-static void vol_sync_host(struct comp_data *cd, uint32_t chan)
+static void vol_sync_host(struct comp_dev *dev, struct comp_data *cd,
+			  uint32_t chan)
 {
 	if (cd->hvol == NULL)
 		return;
@@ -546,15 +556,16 @@ static void vol_sync_host(struct comp_data *cd, uint32_t chan)
 	if (chan < SOF_IPC_MAX_CHANNELS)
 		cd->hvol[chan].value = cd->volume[chan];
 	else {
-		trace_volume_error("veh");
-		tracev_value(chan);
+		trace_volume_error(dev, "veh");
+		tracev_volume_value(dev, chan);
 	}
 }
 
-static void vol_update(struct comp_data *cd, uint32_t chan)
+static void vol_update(struct comp_dev *dev, struct comp_data *cd,
+		       uint32_t chan)
 {
 	cd->volume[chan] = cd->tvolume[chan];
-	vol_sync_host(cd, chan);
+	vol_sync_host(dev, cd, chan);
 }
 
 /* this ramps volume changes over time */
@@ -582,7 +593,7 @@ static uint64_t vol_work(void *data, uint64_t delay)
 
 			/* ramp completed ? */
 			if (vol >= cd->tvolume[i] || vol >= VOL_MAX)
-				vol_update(cd, i);
+				vol_update(dev, cd, i);
 			else {
 				cd->volume[i] = vol;
 				again = 1;
@@ -592,12 +603,12 @@ static uint64_t vol_work(void *data, uint64_t delay)
 			new_vol = vol - VOL_RAMP_STEP;
 			if (new_vol <= 0) {
 				/* cannot ramp down below 0 */
-				vol_update(cd, i);
+				vol_update(dev, cd, i);
 			} else {
 				/* ramp completed ? */
 				if (new_vol <= cd->tvolume[i] ||
 					new_vol <= VOL_MIN) {
-					vol_update(cd, i);
+					vol_update(dev, cd, i);
 				} else {
 					cd->volume[i] = new_vol;
 					again = 1;
@@ -606,7 +617,7 @@ static uint64_t vol_work(void *data, uint64_t delay)
 		}
 
 		/* sync host with new value */
-		vol_sync_host(cd, i);
+		vol_sync_host(dev, cd, i);
 	}
 
 	/* do we need to continue ramping */
@@ -624,7 +635,7 @@ static struct comp_dev *volume_new(struct sof_ipc_comp *comp)
 	struct comp_data *cd;
 	int i;
 
-	trace_volume("new");
+	trace_volume(NULL, "new");
 
 	dev = rzalloc(RZONE_RUNTIME, SOF_MEM_CAPS_RAM,
 		COMP_SIZE(struct sof_ipc_comp_volume));
@@ -657,7 +668,7 @@ static void volume_free(struct comp_dev *dev)
 {
 	struct comp_data *cd = comp_get_drvdata(dev);
 
-	trace_volume("fre");
+	trace_volume(dev, "fre");
 
 	rfree(cd);
 	rfree(dev);
@@ -671,7 +682,7 @@ static int volume_params(struct comp_dev *dev)
 {
 	struct comp_data *cd = comp_get_drvdata(dev);
 
-	trace_volume("par");
+	trace_volume(dev, "par");
 
 	/* rewrite params format for all downstream */
 	dev->params.frame_fmt = cd->sink_format;
@@ -725,34 +736,34 @@ static int volume_ctrl_set_cmd(struct comp_dev *dev, struct sof_ipc_ctrl_data *c
 
 	/* validate */
 	if (cdata->num_elems == 0 || cdata->num_elems >= SOF_IPC_MAX_CHANNELS) {
-		trace_volume_error("gs0");
+		trace_volume_error(dev, "gs0");
 		return -EINVAL;
 	}
 
 	switch (cdata->cmd) {
 	case SOF_CTRL_CMD_VOLUME:
-		trace_volume("vst");
-		trace_value(cdata->comp_id);
+		trace_volume(dev, "vst");
+		trace_volume_value(dev, cdata->comp_id);
 		for (j = 0; j < cdata->num_elems; j++) {
-			trace_value(cdata->chanv[j].channel);
-			trace_value(cdata->chanv[j].value);
+			trace_volume_value(dev, cdata->chanv[j].channel);
+			trace_volume_value(dev, cdata->chanv[j].value);
 			i = cdata->chanv[j].channel;
 			if ((i >= 0) && (i < SOF_IPC_MAX_CHANNELS))
 				volume_set_chan(dev, i, cdata->chanv[j].value);
 			else {
-				trace_volume_error("gs2");
-				tracev_value(i);
+				trace_volume_error(dev, "gs2");
+				tracev_volume_value(dev, i);
 			}
 		}
 		work_schedule_default(&cd->volwork, VOL_RAMP_US);
 		break;
 
 	case SOF_CTRL_CMD_SWITCH:
-		trace_volume("mst");
-		trace_value(cdata->comp_id);
+		trace_volume(dev, "mst");
+		trace_volume_value(dev, cdata->comp_id);
 		for (j = 0; j < cdata->num_elems; j++) {
-			trace_value(cdata->chanv[j].channel);
-			trace_value(cdata->chanv[j].value);
+			trace_volume_value(dev, cdata->chanv[j].channel);
+			trace_volume_value(dev, cdata->chanv[j].value);
 			i = cdata->chanv[j].channel;
 			if ((i >= 0) && (i < SOF_IPC_MAX_CHANNELS)) {
 				if (cdata->chanv[j].value)
@@ -760,15 +771,15 @@ static int volume_ctrl_set_cmd(struct comp_dev *dev, struct sof_ipc_ctrl_data *c
 				else
 					volume_set_chan_mute(dev, i);
 			} else {
-				trace_volume_error("gs3");
-				tracev_value(i);
+				trace_volume_error(dev, "gs3");
+				tracev_volume_value(dev, i);
 			}
 		}
 		work_schedule_default(&cd->volwork, VOL_RAMP_US);
 		break;
 
 	default:
-		trace_volume_error("gs1");
+		trace_volume_error(dev, "gs1");
 		return -EINVAL;
 	}
 
@@ -782,23 +793,23 @@ static int volume_ctrl_get_cmd(struct comp_dev *dev, struct sof_ipc_ctrl_data *c
 
 	/* validate */
 	if (cdata->num_elems == 0 || cdata->num_elems >= SOF_IPC_MAX_CHANNELS) {
-		trace_volume_error("gc0");
-		tracev_value(cdata->num_elems);
+		trace_volume_error(dev, "gc0");
+		tracev_volume_value(dev, cdata->num_elems);
 		return -EINVAL;
 	}
 
 	if (cdata->cmd == SOF_CTRL_CMD_VOLUME ||
 	    cdata->cmd ==  SOF_CTRL_CMD_SWITCH) {
-		trace_volume("vgt");
-		trace_value(cdata->comp_id);
+		trace_volume(dev, "vgt");
+		trace_volume_value(dev, cdata->comp_id);
 		for (j = 0; j < cdata->num_elems; j++) {
 			cdata->chanv[j].channel = j;
 			cdata->chanv[j].value = cd->tvolume[j];
-			trace_value(cdata->chanv[j].channel);
-			trace_value(cdata->chanv[j].value);
+			trace_volume_value(dev, cdata->chanv[j].channel);
+			trace_volume_value(dev, cdata->chanv[j].value);
 		}
 	} else {
-		trace_volume_error("ec2");
+		trace_volume_error(dev, "ec2");
 		return -EINVAL;
 	}
 
@@ -810,7 +821,7 @@ static int volume_cmd(struct comp_dev *dev, int cmd, void *data)
 {
 	struct sof_ipc_ctrl_data *cdata = data;
 
-	trace_volume("cmd");
+	trace_volume(dev, "cmd");
 
 	switch (cmd) {
 	case COMP_CMD_SET_VALUE:
@@ -824,7 +835,7 @@ static int volume_cmd(struct comp_dev *dev, int cmd, void *data)
 
 static int volume_trigger(struct comp_dev *dev, int cmd)
 {
-	trace_volume("trg");
+	trace_volume(dev, "trg");
 
 	return comp_set_state(dev, cmd);
 }
@@ -836,7 +847,7 @@ static int volume_copy(struct comp_dev *dev)
 	struct comp_buffer *sink;
 	struct comp_buffer *source;
 
-	tracev_volume("cpy");
+	tracev_volume(dev, "cpy");
 
 	/* volume components will only ever have 1 source and 1 sink buffer */
 	source = list_first_item(&dev->bsource_list, struct comp_buffer, sink_list);
@@ -846,12 +857,12 @@ static int volume_copy(struct comp_dev *dev)
 	 * the sink component buffer has enough free bytes for copy. Also
 	 * check for XRUNs */
 	if (source->avail < cd->source_period_bytes) {
-		trace_volume_error("xru");
+		trace_volume_error(dev, "xru");
 		comp_underrun(dev, source, cd->source_period_bytes, 0);
 		return -EIO;	/* xrun */
 	}
 	if (sink->free < cd->sink_period_bytes) {
-		trace_volume_error("xro");
+		trace_volume_error(dev, "xro");
 		comp_overrun(dev, sink, cd->sink_period_bytes, 0);
 		return -EIO;	/* xrun */
 	}
@@ -880,7 +891,7 @@ static int volume_prepare(struct comp_dev *dev)
 	int i;
 	int ret;
 
-	trace_volume("pre");
+	trace_volume(dev, "pre");
 
 	ret = comp_set_state(dev, COMP_TRIGGER_PREPARE);
 	if (ret < 0)
@@ -938,22 +949,22 @@ static int volume_prepare(struct comp_dev *dev)
 	ret = buffer_set_size(sinkb, cd->sink_period_bytes *
 		config->periods_sink);
 	if (ret < 0) {
-		trace_volume_error("vp0");
+		trace_volume_error(dev, "vp0");
 		goto err;
 	}
 
 	/* validate */
 	if (cd->sink_period_bytes == 0) {
-		trace_volume_error("vp1");
-		trace_error_value(dev->frames);
-		trace_error_value(sinkb->sink->frame_bytes);
+		trace_volume_error(dev, "vp1");
+		trace_volume_error_value(dev, dev->frames);
+		trace_volume_error_value(dev, sinkb->sink->frame_bytes);
 		ret = -EINVAL;
 		goto err;
 	}
 	if (cd->source_period_bytes == 0) {
-		trace_volume_error("vp2");
-		trace_error_value(dev->frames);
-		trace_error_value(sourceb->source->frame_bytes);
+		trace_volume_error(dev, "vp2");
+		trace_volume_error_value(dev, dev->frames);
+		trace_volume_error_value(dev, sourceb->source->frame_bytes);
 		ret = -EINVAL;
 		goto err;
 	}
@@ -971,10 +982,10 @@ static int volume_prepare(struct comp_dev *dev)
 		cd->scale_vol = func_map[i].func;
 		goto found;
 	}
-	trace_volume_error("vp3");
-	trace_error_value(cd->source_format);
-	trace_error_value(cd->sink_format);
-	trace_error_value(dev->params.channels);
+	trace_volume_error(dev, "vp3");
+	trace_volume_error_value(dev, cd->source_format);
+	trace_volume_error_value(dev, cd->sink_format);
+	trace_volume_error_value(dev, dev->params.channels);
 
 err:
 	comp_set_state(dev, COMP_TRIGGER_RESET);
@@ -982,14 +993,14 @@ err:
 
 found:
 	for (i = 0; i < PLATFORM_MAX_CHANNELS; i++)
-		vol_sync_host(cd, i);
+		vol_sync_host(dev, cd, i);
 
 	return 0;
 }
 
 static int volume_reset(struct comp_dev *dev)
 {
-	trace_volume("res");
+	trace_volume(dev, "res");
 
 	comp_set_state(dev, COMP_TRIGGER_RESET);
 	return 0;
-- 
2.14.3



More information about the Sound-open-firmware mailing list