|
| 1 | +/* |
| 2 | + * SPDX-License-Identifier: BSD-3-Clause |
| 3 | + * Copyright (c) 2024-2026 The XTC Project Authors |
| 4 | + */ |
| 5 | +#include "host_structures.h" |
| 6 | +#include "mppa_management_host.h" |
| 7 | + |
| 8 | +#include <mppa_offload_host.h> |
| 9 | + |
| 10 | +#include <stdlib.h> |
| 11 | +#include <assert.h> |
| 12 | +#include <stddef.h> |
| 13 | +#include <stdint.h> |
| 14 | + |
| 15 | +#define MAX_NB_PM_COUNTERS 8 /* value of _COS_PM_NB for Coolidge V2 */ |
| 16 | + |
| 17 | +typedef struct { |
| 18 | + const char *name; |
| 19 | + int id; |
| 20 | + const char *description; |
| 21 | +} kvx_pm_counter_t; |
| 22 | + |
| 23 | +#define NB_COUNTERS_AVAILABLE 55 |
| 24 | +static const kvx_pm_counter_t kvx_pm_counters[NB_COUNTERS_AVAILABLE] = { |
| 25 | + { "PCC" , 0 /* _COS_PM_PCC */, "Processor Clock CycleSAT" }, |
| 26 | + { "ICC" , 1 /* _COS_PM_ICC */, "Idle Clock Cycle" }, |
| 27 | + { "EBE" , 2 /* _COS_PM_EBE */, "Executed Bundle Event" }, |
| 28 | + { "ENIE" , 3 /* _COS_PM_ENIE */, "Executed N Instructions Event" }, |
| 29 | + { "ENSE" , 4 /* _COS_PM_ENSE */, "Executed N Syllables Event" }, |
| 30 | + { "ICHE" , 5 /* _COS_PM_ICHE */, "I$ Hit Event" }, |
| 31 | + { "ICME" , 6 /* _COS_PM_ICME */, "I$ Miss Event" }, |
| 32 | + { "ICMABE" , 7 /* _COS_PM_ICMABE */, "I$ Memory Accesses Burst Event" }, |
| 33 | + { "MNGIC" , 8 /* _COS_PM_MNGIC */, "Memory Not Granting Instruction cache access Cycle" }, |
| 34 | + { "MIMHE" , 9 /* _COS_PM_MIMHE */, "MMU Instruction Micro-tlb Hit Event" }, |
| 35 | + { "MIMME" , 10 /* _COS_PM_MIMME */, "MMU Instruction Micro-tlb Miss Event" }, |
| 36 | + { "IATSC" , 11 /* _COS_PM_IATSC */, "Instruction Address Translation Stall Cycle" }, |
| 37 | + { "FE" , 12 /* _COS_PM_FE */, "Fetch Event" }, |
| 38 | + { "PBSC" , 13 /* _COS_PM_PBSC */, "Prefetch Buffer Starvation Cycle" }, |
| 39 | + { "PNVC" , 14 /* _COS_PM_PNVC */, "Pipeline No Valid Cycle" }, |
| 40 | + { "PSC" , 15 /* _COS_PM_PSC */, "Pipeline Starvation Cycle" }, |
| 41 | + { "TADBE" , 16 /* _COS_PM_TADBE */, "Taken Applicative Direct Branch Event" }, |
| 42 | + { "TABE" , 17 /* _COS_PM_TABE */, "Taken Applicative Branch Event" }, |
| 43 | + { "TBE" , 18 /* _COS_PM_TBE */, "Taken Branch Event" }, |
| 44 | + { "MDMHE" , 19 /* _COS_PM_MDMHE */, "MMU Data Micro-tlb Hit Event" }, |
| 45 | + { "MDMME" , 20 /* _COS_PM_MDMME */, "MMU Data Micro-tlb Miss Event" }, |
| 46 | + { "DATSC" , 21 /* _COS_PM_DATSC */, "Data Address Translation Stall Cycle" }, |
| 47 | + { "DCLHE" , 22 /* _COS_PM_DCLHE */, "D$ Load Hit Event" }, |
| 48 | + { "DCHE" , 23 /* _COS_PM_DCHE */, "D$ Hit Event" }, |
| 49 | + { "DCLME" , 24 /* _COS_PM_DCLME */, "D$ Load Miss Event" }, |
| 50 | + { "DCME" , 25 /* _COS_PM_DCME */, "D$ Miss Event" }, |
| 51 | + { "DARSC" , 26 /* _COS_PM_DARSC */, "Data Access Related Stall Cycle" }, |
| 52 | + { "LDSC" , 27 /* _COS_PM_LDSC */, "Load Dependency Stall Cycle" }, |
| 53 | + { "DCNGC" , 28 /* _COS_PM_DCNGC */, "Data Cache Not Granting Cycle" }, |
| 54 | + { "DMAE" , 29 /* _COS_PM_DMAE */, "Data Misaligned Access Event" }, |
| 55 | + { "LCFSC" , 30 /* _COS_PM_LCFSC */, "Load Cam Full Stall Cycle" }, |
| 56 | + { "MNGDC" , 31 /* _COS_PM_MNGDC */, "Memory Not Granting Data cache access Cycle" }, |
| 57 | + { "MACC" , 32 /* _COS_PM_MACC */, "Memory Accesses Conflict Cycle" }, |
| 58 | + { "TACC" , 33 /* _COS_PM_TACC */, "TLB Accesses Conflict Cycle" }, |
| 59 | + { "IWC" , 34 /* _COS_PM_IWC */, "Idle Wait Cycle" }, |
| 60 | + { "WISC" , 35 /* _COS_PM_WISC */, "Wait Instruction Stall Cycle" }, |
| 61 | + { "SISC" , 36 /* _COS_PM_SISC */, "Synchronization Instruction Stall Cycle" }, |
| 62 | + { "DDSC" , 37 /* _COS_PM_DDSC */, "Data Dependency Stall Cycle" }, |
| 63 | + { "SC" , 38 /* _COS_PM_SC */, "Stall Cycle" }, |
| 64 | + { "ELE" , 39 /* _COS_PM_ELE */, "Executed Load Event" }, |
| 65 | + { "ELNBE" , 40 /* _COS_PM_ELNBE */, "Executed Load N Bytes Event" }, |
| 66 | + { "ELUE" , 41 /* _COS_PM_ELUE */, "Executed Load Uncached Event" }, |
| 67 | + { "ELUNBE" , 42 /* _COS_PM_ELUNBE */, "Executed Load Uncached N Bytes Event" }, |
| 68 | + { "ESE" , 43 /* _COS_PM_ESE */, "Executed Store Event" }, |
| 69 | + { "ESNBE" , 44 /* _COS_PM_ESNBE */, "Executed Store N Bytes Event" }, |
| 70 | + { "EAE" , 45 /* _COS_PM_EAE */, "Executed Atomics Event" }, |
| 71 | + { "CIRE" , 46 /* _COS_PM_CIRE */, "Coherency Invalidation Request Event" }, |
| 72 | + { "CIE" , 47 /* _COS_PM_CIE */, "Coherency Invalidation Event" }, |
| 73 | + { "SE" , 48 /* _COS_PM_SE */, "Stop Event" }, |
| 74 | + { "RE" , 49 /* _COS_PM_RE */, "Reset Event" }, |
| 75 | + { "FSC" , 50 /* _COS_PM_FSC */, "Fetch Stall Cycle" }, |
| 76 | + /* PMC available only on Coolidge V2 */ |
| 77 | + { "CPIRE" , 51 /* _COS_PM_CPIRE */, "Coherency Precise Invalidation Request Event" }, |
| 78 | + { "CPIE" , 52 /* _COS_PM_CPIE */, "Coherency Precise Invalidation Event" }, |
| 79 | + { "HUPEVICT" , 53 /* _COS_PM_HUPEVICT */, "Hit-Under-Prefetch Line Eviction Event" }, |
| 80 | + { "HUPHIT" , 54 /* _COS_PM_HUPHIT */, "Hit-Under-Prefetch Hit Event" }, |
| 81 | +}; |
| 82 | + |
| 83 | +void mppa_setup_perf_events(char* event_names[], int n_events) { |
| 84 | + assert(n_events <= MAX_NB_PM_COUNTERS); |
| 85 | + int counter_ids[MAX_NB_PM_COUNTERS] = {0}; |
| 86 | + for (int i = 0; i < n_events; i++) { |
| 87 | + const char *event_name = event_names[i]; |
| 88 | + int j = 0; |
| 89 | + for (j = 0; j < NB_COUNTERS_AVAILABLE; j++) { |
| 90 | + if (strcmp(event_name, kvx_pm_counters[j].name) == 0) { |
| 91 | + counter_ids[i] = kvx_pm_counters[j].id; |
| 92 | + break; |
| 93 | + } |
| 94 | + } |
| 95 | + if (j == NB_COUNTERS_AVAILABLE) { |
| 96 | + printf("Event %s not found in the list of available events\n", event_name); |
| 97 | + assert(false); |
| 98 | + } |
| 99 | + } |
| 100 | + // Call runtime function |
| 101 | + mppa_setup_pm_counters(counter_ids, n_events); |
| 102 | +} |
| 103 | + |
| 104 | +void mppa_read_perf_events_results(void* dst_handle) { |
| 105 | + mppa_copy_out_pm_counters_buffer(dst_handle); |
| 106 | +} |
| 107 | + |
| 108 | +void mppa_reset_perf_events() { |
| 109 | + mppa_reset_pm_counters_buffer(); |
| 110 | +} |
| 111 | + |
| 112 | +// uint64_t mppa_get_frequency() already exists in the runtime, just need to call it |
0 commit comments