Snitch Runtime
Loading...
Searching...
No Matches
perf_cnt.h
1// Copyright 2023 ETH Zurich and University of Bologna.
2// Licensed under the Apache License, Version 2.0, see LICENSE for details.
3// SPDX-License-Identifier: Apache-2.0
4
5#define SNRT_NUM_PERF_CNTS SNITCH_CLUSTER_PERIPHERAL_PARAM_NUM_PERF_COUNTERS
6
11typedef union {
12 uint32_t value __attribute__((aligned(8)));
14
22typedef struct {
23 volatile perf_reg32_t enable[SNRT_NUM_PERF_CNTS];
24 volatile perf_reg32_t select[SNRT_NUM_PERF_CNTS];
25 volatile perf_reg32_t perf_counter[SNRT_NUM_PERF_CNTS];
27
33inline perf_regs_t* snrt_perf_counters() {
34 return (perf_regs_t*)snrt_cluster_perf_counters_addr();
35}
36
44inline void snrt_cfg_perf_counter(uint32_t perf_cnt, uint16_t metric,
45 uint16_t hart) {
46 snrt_perf_counters()->select[perf_cnt].value = (metric << 16) | hart;
47}
48
54inline void snrt_start_perf_counter(uint32_t perf_cnt) {
55 snrt_perf_counters()->enable[perf_cnt].value = 0x1;
56}
57
63inline void snrt_stop_perf_counter(uint32_t perf_cnt) {
64 snrt_perf_counters()->enable[perf_cnt].value = 0x0;
65}
66
72inline void snrt_reset_perf_counter(uint32_t perf_cnt) {
73 snrt_perf_counters()->perf_counter[perf_cnt].value = 0x0;
74}
75
83inline uint32_t snrt_get_perf_counter(uint32_t perf_cnt) {
84 return snrt_perf_counters()->perf_counter[perf_cnt].value;
85}
Structure representing the performance counters.
Definition perf_cnt.h:22
Union representing a 32-bit performance counter register, with 8-byte alignment.
Definition perf_cnt.h:11