akaros/kern/arch/x86/perfmon.h
<<
>>
Prefs
   1/* Copyright (c) 2015 Google Inc
   2 * Davide Libenzi <dlibenzi@google.com>
   3 * See LICENSE for details.
   4 */
   5
   6#pragma once
   7
   8#include <sys/types.h>
   9#include <ros/common.h>
  10#include <ros/arch/perfmon.h>
  11#include <arch/x86.h>
  12#include <atomic.h>
  13#include <core_set.h>
  14#include <stdint.h>
  15#include <kthread.h>
  16
  17#define MAX_VAR_COUNTERS 32
  18#define MAX_FIX_COUNTERS 16
  19#define MAX_PERFMON_COUNTERS (MAX_VAR_COUNTERS + MAX_FIX_COUNTERS)
  20#define INVALID_COUNTER INT32_MIN
  21
  22struct hw_trapframe;
  23
  24typedef int32_t counter_t;
  25
  26struct perfmon_cpu_caps {
  27        uint32_t perfmon_version;
  28        uint32_t proc_arch_events;
  29        uint32_t bits_x_counter;
  30        uint32_t counters_x_proc;
  31        uint32_t bits_x_fix_counter;
  32        uint32_t fix_counters_x_proc;
  33};
  34
  35struct perfmon_alloc {
  36        struct perfmon_event ev;
  37        counter_t cores_counters[0];
  38};
  39
  40struct perfmon_session {
  41        qlock_t qlock;
  42        struct perfmon_alloc *allocs[MAX_PERFMON_COUNTERS];
  43};
  44
  45struct perfmon_status {
  46        struct perfmon_event ev;
  47        uint64_t cores_values[0];
  48};
  49
  50bool perfmon_supported(void);
  51void perfmon_global_init(void);
  52void perfmon_pcpu_init(void);
  53void perfmon_snapshot_hwtf(struct hw_trapframe *hw_tf);
  54void perfmon_snapshot_vmtf(struct vm_trapframe *vm_tf);
  55void perfmon_interrupt(struct hw_trapframe *hw_tf, void *data);
  56void perfmon_get_cpu_caps(struct perfmon_cpu_caps *pcc);
  57int perfmon_open_event(const struct core_set *cset, struct perfmon_session *ps,
  58                       const struct perfmon_event *pev);
  59void perfmon_close_event(struct perfmon_session *ps, int ped);
  60struct perfmon_status *perfmon_get_event_status(struct perfmon_session *ps,
  61                                                int ped);
  62void perfmon_free_event_status(struct perfmon_status *pef);
  63struct perfmon_session *perfmon_create_session(void);
  64void perfmon_close_session(struct perfmon_session *ps);
  65
  66static inline uint64_t read_pmc(uint32_t index)
  67{
  68        uint32_t edx, eax;
  69
  70        asm volatile("rdpmc" : "=d"(edx), "=a"(eax) : "c"(index));
  71        return ((uint64_t) edx << 32) | eax;
  72}
  73