Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/audio/copier/host_copier.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
#include <sof/lib/notifier.h>
#include "copier.h"

#ifdef CONFIG_SOF_TELEMETRY_IO_PERFORMANCE_MEASUREMENTS
struct io_perf_data_item;
#endif

typedef void (*copy_callback_t)(struct comp_dev *dev, size_t bytes);

struct host_data;
Expand Down Expand Up @@ -112,6 +116,9 @@ struct host_data {
uint64_t next_sync;
uint64_t period_in_cycles;
#endif
#ifdef CONFIG_SOF_TELEMETRY_IO_PERFORMANCE_MEASUREMENTS
struct io_perf_data_item *io_perf_host_byte_count;
#endif
};

int host_common_new(struct host_data *hd, struct comp_dev *dev,
Expand Down
8 changes: 4 additions & 4 deletions src/audio/dai-zephyr.c
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ dai_dma_cb(struct dai_data *dd, struct comp_dev *dev, uint32_t bytes,
}
#ifdef CONFIG_SOF_TELEMETRY_IO_PERFORMANCE_MEASUREMENTS
/* Increment performance counters */
io_perf_monitor_update_data(dd->io_perf_bytes_count, bytes);
io_perf_monitor_update_data(dd->io_perf_dai_byte_count, bytes);
#endif

return dma_status;
Expand Down Expand Up @@ -558,12 +558,12 @@ __cold int dai_common_new(struct dai_data *dd, struct comp_dev *dev,
/* ignore perf meas init on case of other dai types */
if (perf_type != IO_PERF_INVALID_ID) {
struct io_perf_data_item init_data = {perf_type,
cpu_get_id(),
dai_cfg->dai_index,
perf_dir,
IO_PERF_POWERED_UP_ENABLED,
IO_PERF_D0IX_POWER_MODE,
0, 0, 0 };
io_perf_monitor_init_data(&dd->io_perf_bytes_count, &init_data);
io_perf_monitor_init_data(&dd->io_perf_dai_byte_count, &init_data);
}
#endif

Expand Down Expand Up @@ -617,7 +617,7 @@ __cold void dai_common_free(struct dai_data *dd)
assert_can_be_cold();

#ifdef CONFIG_SOF_TELEMETRY_IO_PERFORMANCE_MEASUREMENTS
io_perf_monitor_release_slot(dd->io_perf_bytes_count);
io_perf_monitor_release_slot(dd->io_perf_dai_byte_count);
#endif

if (dd->group)
Expand Down
32 changes: 32 additions & 0 deletions src/audio/host-legacy.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <rtos/string.h>
#include <sof/ut.h>
#include <sof/trace/trace.h>
#include <sof/debug/telemetry/performance_monitor.h>
#include <ipc/stream.h>
#include <ipc/topology.h>
#include <user/trace.h>
Expand Down Expand Up @@ -250,6 +251,10 @@ void host_common_update(struct host_data *hd, struct comp_dev *dev, uint32_t byt
if (ret < 0)
return;

#ifdef CONFIG_SOF_TELEMETRY_IO_PERFORMANCE_MEASUREMENTS
io_perf_monitor_update_data(hd->io_perf_host_byte_count, bytes);
#endif

hd->total_data_processed += bytes;

/* new local period, update host buffer position blks
Expand Down Expand Up @@ -599,6 +604,14 @@ static struct comp_dev *host_new(const struct comp_driver *drv,

void host_common_free(struct host_data *hd)
{
#ifdef CONFIG_SOF_TELEMETRY_IO_PERFORMANCE_MEASUREMENTS
/* Check for NULL just in case the params() step is omitted */
if (hd->io_perf_host_byte_count) {
io_perf_monitor_release_slot(hd->io_perf_host_byte_count);
hd->io_perf_host_byte_count = NULL;
}
#endif

dma_put(hd->dma);

ipc_msg_free(hd->msg);
Expand Down Expand Up @@ -829,6 +842,25 @@ int host_common_params(struct host_data *hd, struct comp_dev *dev,
pcm_get_conversion_function(audio_stream_get_frm_fmt(&hd->local_buffer->stream),
audio_stream_get_frm_fmt(&hd->local_buffer->stream));

#ifdef CONFIG_SOF_TELEMETRY_IO_PERFORMANCE_MEASUREMENTS
if (!hd->io_perf_host_byte_count) {
/* On the Host side, unlike the DAI side, the port direction values (INPUT/OUTPUT)
* match the stream direction enum values (CAPTURE/PLAYBACK), so we can directly
* use params->direction here.
*/
struct io_perf_data_item init_data = {
IO_PERF_HDA_ID,
hd->chan->index,
params->direction,
IO_PERF_POWERED_UP_ENABLED,
IO_PERF_D0IX_POWER_MODE,
0, 0, 0
};

io_perf_monitor_init_data(&hd->io_perf_host_byte_count, &init_data);
}
#endif

out:

hd->cb_dev = dev;
Expand Down
31 changes: 31 additions & 0 deletions src/audio/host-zephyr.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <rtos/string.h>
#include <sof/ut.h>
#include <sof/trace/trace.h>
#include <sof/debug/telemetry/performance_monitor.h>
#include <ipc/stream.h>
#include <ipc/topology.h>
#include <user/trace.h>
Expand Down Expand Up @@ -262,6 +263,10 @@ void host_common_update(struct host_data *hd, struct comp_dev *dev, uint32_t byt
return;
}

#ifdef CONFIG_SOF_TELEMETRY_IO_PERFORMANCE_MEASUREMENTS
io_perf_monitor_update_data(hd->io_perf_host_byte_count, bytes);
#endif

hd->total_data_processed += bytes;

/* new local period, update host buffer position blks
Expand Down Expand Up @@ -771,6 +776,14 @@ __cold void host_common_free(struct host_data *hd)
{
assert_can_be_cold();

#ifdef CONFIG_SOF_TELEMETRY_IO_PERFORMANCE_MEASUREMENTS
/* Check for NULL just in case the params() step is omitted */
if (hd->io_perf_host_byte_count) {
io_perf_monitor_release_slot(hd->io_perf_host_byte_count);
hd->io_perf_host_byte_count = NULL;
}
#endif

sof_dma_put(hd->dma);

ipc_msg_free(hd->msg);
Expand Down Expand Up @@ -1074,6 +1087,24 @@ int host_common_params(struct host_data *hd, struct comp_dev *dev,
hd->copy = hd->copy_type == COMP_COPY_ONE_SHOT ? host_copy_one_shot :
host_copy_normal;

#ifdef CONFIG_SOF_TELEMETRY_IO_PERFORMANCE_MEASUREMENTS
if (!hd->io_perf_host_byte_count) {
/* On the Host side, unlike the DAI side, the port direction values (INPUT/OUTPUT)
* match the stream direction enum values (CAPTURE/PLAYBACK), so we can directly
* use params->direction here.
*/
struct io_perf_data_item init_data = {
IO_PERF_HDA_ID,
hd->chan->index,
params->direction,
IO_PERF_POWERED_UP_ENABLED,
IO_PERF_D0IX_POWER_MODE,
0, 0, 0
};
io_perf_monitor_init_data(&hd->io_perf_host_byte_count, &init_data);
}
#endif

return 0;

err_free_block_cfg:
Expand Down
20 changes: 14 additions & 6 deletions src/debug/telemetry/performance_monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ static bool perf_bitmap_is_bit_clear(struct perf_bitmap * const bitmap, size_t b

struct perf_data_item_comp *perf_data_getnext(void)
{
int idx;
size_t idx;
int ret = perf_bitmap_alloc(&performance_data_bitmap, &idx);

if (ret < 0)
Expand All @@ -138,8 +138,10 @@ struct perf_data_item_comp *perf_data_getnext(void)
* ,and always set bit on bitmap alloc.
*/
ret = perf_bitmap_setbit(&performance_data_bitmap, idx);
if (ret < 0)
if (ret < 0) {
perf_bitmap_free(&performance_data_bitmap, idx);
return NULL;
}
return &perf_data[idx];
}

Expand Down Expand Up @@ -445,24 +447,30 @@ int io_perf_monitor_init(void)

static struct io_perf_data_item *io_perf_monitor_get_next_slot(struct io_perf_monitor_ctx *self)
{
int idx;
size_t idx;
int ret;
k_spinlock_key_t key = k_spin_lock(&self->lock);

ret = perf_bitmap_alloc(&self->io_performance_data_bitmap, &idx);
if (ret < 0)
return NULL;
goto out_unlock;
/* ref. FW did not set the bits, but here we do it to not have to use
* isFree() check that the bitarray does not provide yet. Instead we will use isClear
* ,and always set bit on bitmap alloc.
*/

ret = perf_bitmap_setbit(&self->io_performance_data_bitmap, idx);
if (ret < 0)
return NULL;
if (ret < 0) {
perf_bitmap_free(&self->io_performance_data_bitmap, idx);
goto out_unlock;
}

k_spin_unlock(&self->lock, key);
return &self->io_perf_data[idx];

out_unlock:
k_spin_unlock(&self->lock, key);
return NULL;
}

int io_perf_monitor_release_slot(struct io_perf_data_item *item)
Expand Down
2 changes: 1 addition & 1 deletion src/include/sof/lib/dai-zephyr.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ struct dai_data {
#endif
#ifdef CONFIG_SOF_TELEMETRY_IO_PERFORMANCE_MEASUREMENTS
/* io performance measurement */
struct io_perf_data_item *io_perf_bytes_count;
struct io_perf_data_item *io_perf_dai_byte_count;
#endif
/* Copier gain params */
struct copier_gain_params *gain_data;
Expand Down
Loading