akaros/kern/arch/x86/ros/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/memops.h>
  11#include <ros/bitfield.h>
  12#include <stdint.h>
  13
  14/* The request format for the #arch/perf device is as follow (all the integers
  15 * listed here are little endian):
  16 *
  17 * U8 CMD;
  18 * [CMD dependent payload]
  19 *
  20 * The following command are supported, with their own structure:
  21 *
  22 * PERFMON_CMD_COUNTER_OPEN request
  23 *   U8 CMD; (= PERFMON_CMD_COUNTER_OPEN)
  24 *   U64 EVENT_DESCRIPTOR;
  25 *   U64 EVENT_FLAGS;
  26 *   U64 EVENT_TRIGGER_COUNT;
  27 *   U64 EVENT_USER_DATA;
  28 *   U32 NUM_CPUMASK_BYTES;
  29 *   U8 CPUMASK_BYTES[NUM_CPUMASK_BYTES];
  30 * PERFMON_CMD_COUNTER_OPEN response
  31 *   U32 EVENT_DESCRIPTOR;
  32 *
  33 * PERFMON_CMD_COUNTER_STATUS request
  34 *   U8 CMD; (= PERFMON_CMD_COUNTER_STATUS)
  35 *   U32 EVENT_DESCRIPTOR;
  36 * PERFMON_CMD_COUNTER_STATUS response
  37 *   U32 NUM_VALUES; (always num_cores)
  38 *   U64 VALUES[NUM_VALUES]; (one value per core - zero if the counter was not
  39 *                            active in that core)
  40 *
  41 * PERFMON_CMD_COUNTER_CLOSE request
  42 *   U8 CMD; (= PERFMON_CMD_COUNTER_CLOSE)
  43 *   U32 EVENT_DESCRIPTOR;
  44 * PERFMON_CMD_COUNTER_CLOSE response
  45 *   NONE
  46 *
  47 * PERFMON_CMD_CPU_CAPS request
  48 *   U8 CMD; (= PERFMON_CMD_CPU_CAPS)
  49 * PERFMON_CMD_CPU_CAPS response
  50 *   U32 PERFMON_VERSION;
  51 *   U32 ARCH_EVENTS;
  52 *   U32 BITS_X_COUNTER;
  53 *   U32 COUNTERS_X_PROC;
  54 *   U32 BITS_X_FIX_COUNTER;
  55 *   U32 FIX_COUNTERS_X_PROC;
  56 */
  57
  58#define PERFMON_CMD_COUNTER_OPEN 1
  59#define PERFMON_CMD_COUNTER_STATUS 2
  60#define PERFMON_CMD_COUNTER_CLOSE 3
  61#define PERFMON_CMD_CPU_CAPS 4
  62
  63#define PERFMON_FIXED_EVENT (1 << 0)
  64
  65#define PMEV_EVENT MKBITFIELD(0, 8)
  66#define PMEV_MASK MKBITFIELD(8, 8)
  67#define PMEV_USR MKBITFIELD(16, 1)
  68#define PMEV_OS MKBITFIELD(17, 1)
  69#define PMEV_EDGE MKBITFIELD(18, 1)
  70#define PMEV_PC MKBITFIELD(19, 1)
  71#define PMEV_INTEN MKBITFIELD(20, 1)
  72#define PMEV_ANYTH MKBITFIELD(21, 1)
  73#define PMEV_EN MKBITFIELD(22, 1)
  74#define PMEV_INVCMSK MKBITFIELD(23, 1)
  75#define PMEV_CMASK MKBITFIELD(24, 8)
  76
  77#define PMEV_GET_EVENT(v) BF_GETFIELD(v, PMEV_EVENT)
  78#define PMEV_SET_EVENT(v, x) BF_SETFIELD(v, x, PMEV_EVENT)
  79#define PMEV_GET_MASK(v) BF_GETFIELD(v, PMEV_MASK)
  80#define PMEV_SET_MASK(v, x) BF_SETFIELD(v, x, PMEV_MASK)
  81#define PMEV_GET_USR(v) BF_GETFIELD(v, PMEV_USR)
  82#define PMEV_SET_USR(v, x) BF_SETFIELD(v, x, PMEV_USR)
  83#define PMEV_GET_OS(v) BF_GETFIELD(v, PMEV_OS)
  84#define PMEV_SET_OS(v, x) BF_SETFIELD(v, x, PMEV_OS)
  85#define PMEV_GET_EDGE(v) BF_GETFIELD(v, PMEV_EDGE)
  86#define PMEV_SET_EDGE(v, x) BF_SETFIELD(v, x, PMEV_EDGE)
  87#define PMEV_GET_PC(v) BF_GETFIELD(v, PMEV_PC)
  88#define PMEV_SET_PC(v, x) BF_SETFIELD(v, x, PMEV_PC)
  89#define PMEV_GET_INTEN(v) BF_GETFIELD(v, PMEV_INTEN)
  90#define PMEV_SET_INTEN(v, x) BF_SETFIELD(v, x, PMEV_INTEN)
  91#define PMEV_GET_ANYTH(v) BF_GETFIELD(v, PMEV_ANYTH)
  92#define PMEV_SET_ANYTH(v, x) BF_SETFIELD(v, x, PMEV_ANYTH)
  93#define PMEV_GET_EN(v) BF_GETFIELD(v, PMEV_EN)
  94#define PMEV_SET_EN(v, x) BF_SETFIELD(v, x, PMEV_EN)
  95#define PMEV_GET_INVCMSK(v) BF_GETFIELD(v, PMEV_INVCMSK)
  96#define PMEV_SET_INVCMSK(v, x) BF_SETFIELD(v, x, PMEV_INVCMSK)
  97#define PMEV_GET_CMASK(v) BF_GETFIELD(v, PMEV_CMASK)
  98#define PMEV_SET_CMASK(v, x) BF_SETFIELD(v, x, PMEV_CMASK)
  99
 100struct perfmon_event {
 101        uint64_t event;
 102        uint64_t flags;
 103        uint64_t trigger_count;
 104        uint64_t user_data;
 105};
 106
 107static inline void perfmon_init_event(struct perfmon_event *pev)
 108{
 109        ZERO_DATA(*pev);
 110}
 111
 112static inline bool perfmon_is_fixed_event(const struct perfmon_event *pev)
 113{
 114        return (pev->flags & PERFMON_FIXED_EVENT) != 0;
 115}
 116