diff --git a/include/spdk/accel.h b/include/spdk/accel.h index 0b6c7476a..4862b7010 100644 --- a/include/spdk/accel.h +++ b/include/spdk/accel.h @@ -691,6 +691,26 @@ int spdk_accel_set_opts(const struct spdk_accel_opts *opts); */ void spdk_accel_get_opts(struct spdk_accel_opts *opts); +struct spdk_accel_opcode_stats { + /** Number of executed operations */ + uint64_t executed; + /** Number of failed operations */ + uint64_t failed; + /** Number of processed bytes */ + uint64_t num_bytes; +} __attribute__((packed)); + +/** + * Retrieve opcode statistics for a given IO channel. + * + * \param ch I/O channel. + * \param opcode Operation to retrieve statistics. + * \param stats Per-channel statistics. + * \param size Size of the `stats` structure. + */ +void spdk_accel_get_opcode_stats(struct spdk_io_channel *ch, enum accel_opcode opcode, + struct spdk_accel_opcode_stats *stats, size_t size); + #ifdef __cplusplus } #endif diff --git a/lib/accel/accel.c b/lib/accel/accel.c index 063a46dcc..c57bc84c9 100644 --- a/lib/accel/accel.c +++ b/lib/accel/accel.c @@ -2715,4 +2715,26 @@ accel_get_stats(accel_get_stats_cb cb_fn, void *cb_arg) return 0; } +void +spdk_accel_get_opcode_stats(struct spdk_io_channel *ch, enum accel_opcode opcode, + struct spdk_accel_opcode_stats *stats, size_t size) +{ + struct accel_io_channel *accel_ch = spdk_io_channel_get_ctx(ch); + +#define FIELD_OK(field) \ + offsetof(struct spdk_accel_opcode_stats, field) + sizeof(stats->field) <= size + +#define SET_FIELD(field, value) \ + if (FIELD_OK(field)) { \ + stats->field = value; \ + } + + SET_FIELD(executed, accel_ch->stats.operations[opcode].executed); + SET_FIELD(failed, accel_ch->stats.operations[opcode].failed); + SET_FIELD(num_bytes, accel_ch->stats.operations[opcode].num_bytes); + +#undef FIELD_OK +#undef SET_FIELD +} + SPDK_LOG_REGISTER_COMPONENT(accel) diff --git a/lib/accel/spdk_accel.map b/lib/accel/spdk_accel.map index 042af3eb9..7b8210fa4 100644 --- a/lib/accel/spdk_accel.map +++ b/lib/accel/spdk_accel.map @@ -39,6 +39,7 @@ spdk_accel_get_memory_domain; spdk_accel_set_opts; spdk_accel_get_opts; + spdk_accel_get_opcode_stats; # functions needed by modules spdk_accel_module_list_add;