tools/perf/util/cs-etm-decoder/cs-etm-decoder.c
Source file repositories/reference/linux-study-clean/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/util/cs-etm-decoder/cs-etm-decoder.c- Extension
.c- Size
- 23420 bytes
- Lines
- 799
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
asm/bug.hlinux/coresight-pmu.hlinux/err.hlinux/list.hlinux/zalloc.hstdlib.hopencsd/c_api/opencsd_c_api.hcs-etm.hcs-etm-decoder.hdebug.hintlist.h
Detected Declarations
struct cs_etm_decoderfunction cs_etm_decoder__mem_accessfunction cs_etm_decoder__add_mem_access_cbfunction cs_etm_decoder__resetfunction cs_etm_decoder__get_packetfunction cs_etm_decoder__dec_instr_count_to_nsfunction cs_etm_decoder__gen_etmv3_configfunction cs_etm_decoder__get_etmv4_arch_verfunction cs_etm_decoder__gen_etmv4_configfunction cs_etm_decoder__gen_ete_configfunction cs_etm_decoder__print_str_cbfunction cs_etm_decoder__init_def_logger_printingfunction cs_etm_decoder__do_soft_timestampfunction cs_etm_decoder__do_hard_timestampfunction do_soft_timestampfunction cs_etm_decoder__reset_timestampfunction cs_etm_decoder__buffer_packetfunction cs_etm_decoder__buffer_rangefunction cs_etm_decoder__buffer_discontinuityfunction cs_etm_decoder__buffer_exceptionfunction cs_etm_decoder__buffer_exception_retfunction cs_etm_decoder__set_tidfunction cs_etm_decoder__gen_trace_elem_printerfunction cs_etm_decoder__create_etm_decoderfunction cs_etm_decoder__newfunction cs_etm_decoder__process_data_blockfunction cs_etm_decoder__free
Annotated Snippet
struct cs_etm_decoder {
void *data;
void (*packet_printer)(const char *msg, void *data);
bool suppress_printing;
dcd_tree_handle_t dcd_tree;
cs_etm_mem_cb_type mem_access;
ocsd_datapath_resp_t prev_return;
const char *decoder_name;
};
static u32
cs_etm_decoder__mem_access(const void *context,
const ocsd_vaddr_t address,
const ocsd_mem_space_acc_t mem_space,
const u8 trace_chan_id,
const u32 req_size,
u8 *buffer)
{
struct cs_etm_decoder *decoder = (struct cs_etm_decoder *) context;
return decoder->mem_access(decoder->data, trace_chan_id, address,
req_size, buffer, mem_space);
}
int cs_etm_decoder__add_mem_access_cb(struct cs_etm_decoder *decoder,
u64 start, u64 end,
cs_etm_mem_cb_type cb_func)
{
decoder->mem_access = cb_func;
if (ocsd_dt_add_callback_trcid_mem_acc(decoder->dcd_tree, start, end,
OCSD_MEM_SPACE_ANY,
cs_etm_decoder__mem_access,
decoder))
return -1;
return 0;
}
int cs_etm_decoder__reset(struct cs_etm_decoder *decoder)
{
ocsd_datapath_resp_t dp_ret;
decoder->prev_return = OCSD_RESP_CONT;
decoder->suppress_printing = true;
dp_ret = ocsd_dt_process_data(decoder->dcd_tree, OCSD_OP_RESET,
0, 0, NULL, NULL);
decoder->suppress_printing = false;
if (OCSD_DATA_RESP_IS_FATAL(dp_ret))
return -1;
return 0;
}
int cs_etm_decoder__get_packet(struct cs_etm_packet_queue *packet_queue,
struct cs_etm_packet *packet)
{
if (!packet_queue || !packet)
return -EINVAL;
/* Nothing to do, might as well just return */
if (packet_queue->packet_count == 0)
return 0;
/*
* The queueing process in function cs_etm_decoder__buffer_packet()
* increments the tail *before* using it. This is somewhat counter
* intuitive but it has the advantage of centralizing tail management
* at a single location. Because of that we need to follow the same
* heuristic with the head, i.e we increment it before using its
* value. Otherwise the first element of the packet queue is not
* used.
*/
packet_queue->head = (packet_queue->head + 1) &
(CS_ETM_PACKET_MAX_BUFFER - 1);
*packet = packet_queue->packet_buffer[packet_queue->head];
packet_queue->packet_count--;
return 1;
}
/*
* Calculate the number of nanoseconds elapsed.
*
* instr_count is updated in place with the remainder of the instructions
* which didn't make up a whole nanosecond.
*/
static u32 cs_etm_decoder__dec_instr_count_to_ns(u32 *instr_count)
{
Annotation
- Immediate include surface: `asm/bug.h`, `linux/coresight-pmu.h`, `linux/err.h`, `linux/list.h`, `linux/zalloc.h`, `stdlib.h`, `opencsd/c_api/opencsd_c_api.h`, `cs-etm.h`.
- Detected declarations: `struct cs_etm_decoder`, `function cs_etm_decoder__mem_access`, `function cs_etm_decoder__add_mem_access_cb`, `function cs_etm_decoder__reset`, `function cs_etm_decoder__get_packet`, `function cs_etm_decoder__dec_instr_count_to_ns`, `function cs_etm_decoder__gen_etmv3_config`, `function cs_etm_decoder__get_etmv4_arch_ver`, `function cs_etm_decoder__gen_etmv4_config`, `function cs_etm_decoder__gen_ete_config`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.