diff --git a/inc/ocf.h b/inc/ocf.h index 416d743..888b9c5 100644 --- a/inc/ocf.h +++ b/inc/ocf.h @@ -31,6 +31,5 @@ #include "ocf_mngt.h" #include "ocf_ctx.h" #include "ocf_err.h" -#include "ocf_trace.h" #endif /* __OCF_H__ */ diff --git a/inc/ocf_trace.h b/inc/ocf_trace.h deleted file mode 100644 index 44cf419..0000000 --- a/inc/ocf_trace.h +++ /dev/null @@ -1,185 +0,0 @@ -/* - * Copyright(c) 2012-2021 Intel Corporation - * SPDX-License-Identifier: BSD-3-Clause-Clear - */ - -#ifndef __OCF_TRACE_H__ -#define __OCF_TRACE_H__ - -#include "ocf_def.h" -#include "ocf_types.h" - -typedef uint64_t log_sid_t; - -#define OCF_EVENT_VERSION 1 -#define OCF_TRACING_STOP 1 - -/** - * @brief OCF trace (event) type - */ -typedef enum { - /** IO trace description, this event is pushed first to indicate version - * of traces, number of cores and provides details about cache */ - ocf_event_type_cache_desc, - - /** Event describing ocf core */ - ocf_event_type_core_desc, - - /** IO */ - ocf_event_type_io, - - /** IO completion */ - ocf_event_type_io_cmpl, - - /** IO in file domain */ - ocf_event_type_io_file, -} ocf_event_type; - -/** - * @brief Generic OCF trace event - */ -struct ocf_event_hdr { - /** Event sequence ID */ - log_sid_t sid; - - /** Time stamp */ - uint64_t timestamp; - - /** Trace event type */ - ocf_event_type type; - - /** Size of this event */ - uint32_t size; -}; - -/** - * @brief Cache trace description -*/ -struct ocf_event_cache_desc { - /** Event header */ - struct ocf_event_hdr hdr; - - /** Cache name */ - const char *name; - - /** Cache line size */ - ocf_cache_line_size_t cache_line_size; - - /** Cache mode */ - ocf_cache_mode_t cache_mode; - - /** Cache size in bytes*/ - uint64_t cache_size; - - /** Number of cores */ - uint32_t cores_no; - - /** Trace version */ - uint32_t version; -}; - -/** - * @brief Core trace description -*/ -struct ocf_event_core_desc { - /** Event header */ - struct ocf_event_hdr hdr; - - /** Core name */ - const char *name; - - /** Core size in bytes */ - uint64_t core_size; -}; - -/** @brief IO operation */ -typedef enum { - /** Read */ - ocf_event_operation_rd = 'R', - - /** Write */ - ocf_event_operation_wr = 'W', - - /** Flush */ - ocf_event_operation_flush = 'F', - - /** Discard */ - ocf_event_operation_discard = 'D', -} ocf_event_operation_t; - -/** - * @brief IO trace event - */ -struct ocf_event_io { - /** Trace event header */ - struct ocf_event_hdr hdr; - - /** Address of IO in bytes */ - uint64_t addr; - - /** Size of IO in bytes */ - uint32_t len; - - /** IO class of IO */ - uint32_t io_class; - - /** Core name */ - const char *core_name; - - /** Operation type: read, write, trim or flush **/ - ocf_event_operation_t operation; -}; - -/** - * @brief IO completion event - */ -struct ocf_event_io_cmpl { - /** Trace event header */ - struct ocf_event_hdr hdr; - - /** Reference event sequence ID */ - log_sid_t rsid; - - /** Was IO a cache hit or miss */ - bool is_hit; -}; - - -/** @brief Push log callback. - * - * @param[in] cache OCF cache - * @param[in] trace_ctx Tracing context - * @param[in] queue Queue handle - * @param[out] trace Event log - * @param[out] size Size of event log - * - * @return 0 If pushing trace succeeded - * @return Non-zero error - */ -typedef void (*ocf_trace_callback_t)(ocf_cache_t cache, void *trace_ctx, - ocf_queue_t queue, const void* trace, const uint32_t size); - -/** - * @brief Start tracing - * - * @param[in] cache OCF cache - * @param[in] trace_ctx Tracing context - * @param[in] trace_callback Callback used for pushing logs - * - * @retval 0 Tracing started successfully - * @retval Non-zero Error - */ -int ocf_mngt_start_trace(ocf_cache_t cache, void *trace_ctx, - ocf_trace_callback_t trace_callback); - -/** - * @brief Stop tracing - * - * @param[in] cache OCF cache - * - * @retval 0 Tracing stopped successfully - * @retval Non-zero Error - */ -int ocf_mngt_stop_trace(ocf_cache_t cache); - -#endif /* __OCF_TRACE_H__ */ diff --git a/src/ocf_cache_priv.h b/src/ocf_cache_priv.h index b0a6f77..12b2cc2 100644 --- a/src/ocf_cache_priv.h +++ b/src/ocf_cache_priv.h @@ -19,25 +19,11 @@ #include "ocf_stats_priv.h" #include "cleaning/cleaning.h" #include "ocf_logger_priv.h" -#include "ocf/ocf_trace.h" #include "promotion/promotion.h" #define DIRTY_FLUSHED 1 #define DIRTY_NOT_FLUSHED 0 -/** - * @brief Structure used for aggregating trace-related ocf_cache fields - */ -struct ocf_trace { - /* Placeholder for push_event callback */ - ocf_trace_callback_t trace_callback; - - /* Telemetry context */ - void *trace_ctx; - - env_atomic64 trace_seq_ref; -}; - /* Cache device */ struct ocf_cache_device { struct ocf_volume volume; @@ -133,8 +119,6 @@ struct ocf_cache { bool use_submit_io_fast; struct { - struct ocf_trace trace; - struct ocf_async_lock lock; } __attribute__((aligned(64))); // This should be on it's own cacheline ideally diff --git a/src/ocf_core.c b/src/ocf_core.c index 38a3884..13804cd 100644 --- a/src/ocf_core.c +++ b/src/ocf_core.c @@ -11,7 +11,6 @@ #include "engine/cache_engine.h" #include "utils/utils_user_part.h" #include "ocf_request.h" -#include "ocf_trace_priv.h" struct ocf_core_volume { ocf_core_t core; @@ -209,9 +208,6 @@ static inline int ocf_core_validate_io(struct ocf_io *io) static void ocf_req_complete(struct ocf_request *req, int error) { - /* Log trace */ - ocf_trace_io_cmpl(req); - /* Complete IO */ ocf_io_end(&req->ioi.io, error); @@ -224,7 +220,6 @@ static void ocf_req_complete(struct ocf_request *req, int error) static int ocf_core_submit_io_fast(struct ocf_io *io, struct ocf_request *req, ocf_core_t core, ocf_cache_t cache) { - struct ocf_event_io trace_event; ocf_req_cache_mode_t original_cache_mode; int fast; @@ -251,18 +246,9 @@ static int ocf_core_submit_io_fast(struct ocf_io *io, struct ocf_request *req, req->cache_mode = ocf_req_cache_mode_fast; } - if (cache->trace.trace_callback) { - if (io->dir == OCF_WRITE) - ocf_trace_prep_io_event(&trace_event, req, ocf_event_operation_wr); - else if (io->dir == OCF_READ) - ocf_trace_prep_io_event(&trace_event, req, ocf_event_operation_rd); - } - fast = ocf_engine_hndl_fast_req(req); - if (fast != OCF_FAST_PATH_NO) { - ocf_trace_push(io->io_queue, &trace_event, sizeof(trace_event)); + if (fast != OCF_FAST_PATH_NO) return 0; - } req->cache_mode = original_cache_mode; return -OCF_ERR_IO; @@ -287,8 +273,6 @@ void ocf_core_volume_submit_io(struct ocf_io *io) core = ocf_volume_to_core(ocf_io_get_volume(io)); cache = ocf_core_get_cache(core); - ocf_trace_init_io(req); - if (unlikely(!env_bit_test(ocf_cache_state_running, &cache->cache_state))) { ocf_io_end(io, -OCF_ERR_CACHE_NOT_AVAIL); @@ -319,11 +303,6 @@ void ocf_core_volume_submit_io(struct ocf_io *io) ocf_req_clear_map(req); ocf_core_seq_cutoff_update(core, req); - if (io->dir == OCF_WRITE) - ocf_trace_io(req, ocf_event_operation_wr); - else if (io->dir == OCF_READ) - ocf_trace_io(req, ocf_event_operation_rd); - ret = ocf_engine_hndl_req(req); if (ret) { dec_counter_if_req_was_dirty(req); @@ -360,7 +339,6 @@ static void ocf_core_volume_submit_flush(struct ocf_io *io) req->core = core; req->complete = ocf_req_complete; - ocf_trace_io(req, ocf_event_operation_flush); ocf_io_get(io); ocf_engine_hndl_ops_req(req); @@ -405,7 +383,6 @@ static void ocf_core_volume_submit_discard(struct ocf_io *io) req->core = core; req->complete = ocf_req_complete; - ocf_trace_io(req, ocf_event_operation_discard); ocf_io_get(io); ocf_engine_hndl_discard_req(req); diff --git a/src/ocf_request.h b/src/ocf_request.h index a624487..a704d54 100644 --- a/src/ocf_request.h +++ b/src/ocf_request.h @@ -199,9 +199,6 @@ struct ocf_request { ocf_req_cache_mode_t cache_mode; - log_sid_t sid; - /*!< Tracing sequence ID */ - uint64_t timestamp; /*!< Tracing timestamp */ diff --git a/src/ocf_trace.c b/src/ocf_trace.c deleted file mode 100644 index 5c60973..0000000 --- a/src/ocf_trace.c +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Copyright(c) 2012-2021 Intel Corporation - * SPDX-License-Identifier: BSD-3-Clause-Clear - */ - -#include "ocf_env.h" -#include "ocf_priv.h" -#include "ocf/ocf.h" -#include "ocf/ocf_trace.h" -#include "ocf_core_priv.h" -#include "ocf_cache_priv.h" -#include "ocf_trace_priv.h" - -struct core_trace_visitor_ctx { - ocf_cache_t cache; - ocf_queue_t io_queue; -}; - -static int _ocf_core_desc(ocf_core_t core, void *ctx) -{ - struct ocf_event_core_desc core_desc; - struct core_trace_visitor_ctx *visitor_ctx = - (struct core_trace_visitor_ctx *) ctx; - ocf_cache_t cache = visitor_ctx->cache; - - ocf_event_init_hdr(&core_desc.hdr, ocf_event_type_core_desc, - ocf_trace_seq_id(cache), - env_ticks_to_nsecs(env_get_tick_count()), - sizeof(core_desc)); - core_desc.name = ocf_core_get_name(core); - core_desc.core_size = ocf_volume_get_length( - ocf_core_get_volume(core)); - - ocf_trace_push(visitor_ctx->io_queue, - &core_desc, sizeof(core_desc)); - - return 0; -} - -static int _ocf_trace_cache_info(ocf_cache_t cache, ocf_queue_t io_queue) -{ - struct ocf_event_cache_desc cache_desc; - int retval; - struct core_trace_visitor_ctx visitor_ctx; - - ocf_event_init_hdr(&cache_desc.hdr, ocf_event_type_cache_desc, - ocf_trace_seq_id(cache), - env_ticks_to_nsecs(env_get_tick_count()), - sizeof(cache_desc)); - - cache_desc.name = ocf_cache_get_name(cache); - cache_desc.cache_line_size = ocf_cache_get_line_size(cache); - cache_desc.cache_mode = ocf_cache_get_mode(cache); - - if (ocf_cache_is_device_attached(cache)) { - /* Attached cache */ - cache_desc.cache_size = ocf_volume_get_length( - ocf_cache_get_volume(cache)); - } else { - cache_desc.cache_size = 0; - } - - cache_desc.cores_no = ocf_cache_get_core_count(cache); - cache_desc.version = OCF_EVENT_VERSION; - - ocf_trace_push(io_queue, &cache_desc, sizeof(cache_desc)); - - visitor_ctx.cache = cache; - visitor_ctx.io_queue = io_queue; - - retval = ocf_core_visit(cache, _ocf_core_desc, &visitor_ctx, true); - - return retval; -} - -int ocf_mngt_start_trace(ocf_cache_t cache, void *trace_ctx, - ocf_trace_callback_t trace_callback) -{ - ocf_queue_t queue; - int result = 0; - - OCF_CHECK_NULL(cache); - - if (!trace_callback) - return -EINVAL; - - if (cache->trace.trace_callback) { - ocf_cache_log(cache, log_err, "Tracing already started\n"); - return -EINVAL; - } - - cache->trace.trace_callback = trace_callback; - cache->trace.trace_ctx = trace_ctx; - - // Reset trace stop flag - list_for_each_entry(queue, &cache->io_queues, list) { - env_atomic_set(&queue->trace_stop, 0); - } - - list_for_each_entry(queue, &cache->io_queues, list) { - result = _ocf_trace_cache_info(cache, queue); - if (result) { - cache->trace.trace_callback = NULL; - return result; - } - } - - ocf_cache_log(cache, log_info, "Tracing started\n"); - - return result; -} - -int ocf_mngt_stop_trace(ocf_cache_t cache) -{ - ocf_queue_t queue; - - OCF_CHECK_NULL(cache); - - if (!cache->trace.trace_callback) { - ocf_cache_log(cache, log_err, "Tracing not started\n"); - return -EINVAL; - } - - // Set trace stop flag - list_for_each_entry(queue, &cache->io_queues, list) { - env_atomic_set(&queue->trace_stop, OCF_TRACING_STOP); - } - - cache->trace.trace_callback = NULL; - cache->trace.trace_ctx = NULL; - - // Poll for all ongoing traces completion - while (ocf_is_trace_ongoing(cache)) - env_msleep(20); - - return 0; -} diff --git a/src/ocf_trace_priv.h b/src/ocf_trace_priv.h deleted file mode 100644 index 3a189c8..0000000 --- a/src/ocf_trace_priv.h +++ /dev/null @@ -1,134 +0,0 @@ -/* - * Copyright(c) 2012-2021 Intel Corporation - * SPDX-License-Identifier: BSD-3-Clause-Clear - */ - -#ifndef __OCF_TRACE_PRIV_H__ -#define __OCF_TRACE_PRIV_H__ - -#include "ocf/ocf.h" -#include "ocf_env.h" -#include "ocf/ocf_trace.h" -#include "engine/engine_common.h" -#include "ocf_request.h" -#include "ocf_core_priv.h" -#include "ocf_queue_priv.h" - -static inline bool ocf_is_trace_ongoing(ocf_cache_t cache) -{ - ocf_queue_t q; - - list_for_each_entry(q, &cache->io_queues, list) { - if (env_atomic64_read(&q->trace_ref_cntr)) - return true; - } - - return false; -} -static inline void ocf_event_init_hdr(struct ocf_event_hdr *hdr, - ocf_event_type type, uint64_t sid, uint64_t timestamp, - uint32_t size) -{ - hdr->sid = sid; - hdr->timestamp = timestamp; - hdr->type = type; - hdr->size = size; -} - -static inline uint64_t ocf_trace_seq_id(ocf_cache_t cache) -{ - return env_atomic64_inc_return(&cache->trace.trace_seq_ref); -} - -static inline void ocf_trace_init_io(struct ocf_request *req) -{ - req->timestamp = env_ticks_to_nsecs(env_get_tick_count()); - req->sid = ocf_trace_seq_id(req->cache); -} - -static inline void ocf_trace_prep_io_event(struct ocf_event_io *ev, - struct ocf_request *req, ocf_event_operation_t op) -{ - ocf_event_init_hdr(&ev->hdr, ocf_event_type_io, req->sid, - req->timestamp, sizeof(*ev)); - - ev->addr = req->byte_position; - if (op == ocf_event_operation_discard) - ev->len = req->discard.nr_sects << ENV_SECTOR_SHIFT; - else - ev->len = req->byte_length; - - ev->operation = op; - ev->core_name = ocf_core_get_name(req->core); - - ev->io_class = req->ioi.io.io_class; -} - -static inline void ocf_trace_push(ocf_queue_t queue, void *trace, uint32_t size) -{ - ocf_cache_t cache; - ocf_trace_callback_t trace_callback; - void *trace_ctx; - - OCF_CHECK_NULL(queue); - - cache = ocf_queue_get_cache(queue); - - if (cache->trace.trace_callback == NULL) - return; - - env_atomic64_inc(&queue->trace_ref_cntr); - - if (env_atomic_read(&queue->trace_stop)) { - // Tracing stop was requested - env_atomic64_dec(&queue->trace_ref_cntr); - return; - } - - /* - * Remember callback and context pointers. - * These will be valid even when later on original pointers - * will be set to NULL as cleanup will wait till trace - * reference counter is zero - */ - trace_callback = cache->trace.trace_callback; - trace_ctx = cache->trace.trace_ctx; - - if (trace_callback && trace_ctx) { - trace_callback(cache, trace_ctx, queue, trace, size); - } - - env_atomic64_dec(&queue->trace_ref_cntr); -} - -static inline void ocf_trace_io(struct ocf_request *req, - ocf_event_operation_t dir) -{ - struct ocf_event_io ev; - - if (!req->cache->trace.trace_callback) - return; - - ocf_trace_prep_io_event(&ev, req, dir); - - ocf_trace_push(req->io_queue, &ev, sizeof(ev)); -} - -static inline void ocf_trace_io_cmpl(struct ocf_request *req) -{ - struct ocf_event_io_cmpl ev; - - if (!req->cache->trace.trace_callback) - return; - - ocf_event_init_hdr(&ev.hdr, ocf_event_type_io_cmpl, - ocf_trace_seq_id(req->cache), - env_ticks_to_nsecs(env_get_tick_count()), - sizeof(ev)); - ev.rsid = req->sid; - ev.is_hit = ocf_engine_is_hit(req); - - ocf_trace_push(req->io_queue, &ev, sizeof(ev)); -} - -#endif /* __OCF_TRACE_PRIV_H__ */