#ifndef _LIBCPC_IMPL_H
#define _LIBCPC_IMPL_H
#include <libcpc.h>
#include <inttypes.h>
#include <thread.h>
#include <synch.h>
#include <sys/types.h>
#include <sys/cpc_impl.h>
#ifdef __cplusplus
extern "C" {
#endif
#define CPC_VER_1 1
#define CPC1_BUFSIZE (2 * sizeof (uint64_t))
struct _cpc_attr {
char ca_name[CPC_MAX_ATTR_LEN];
uint64_t ca_val;
};
typedef struct __cpc_request cpc_request_t;
struct __cpc_request {
char cr_event[CPC_MAX_EVENT_LEN];
uint64_t cr_preset;
uint16_t cr_index;
uint_t cr_flags;
uint_t cr_nattrs;
kcpc_attr_t *cr_attr;
cpc_request_t *cr_next;
};
struct __cpc_buf {
uint64_t *cb_data;
hrtime_t cb_hrtime;
uint64_t cb_tick;
size_t cb_size;
cpc_buf_t *cb_next;
};
typedef enum {
CS_UNBOUND,
CS_BOUND_CURLWP,
CS_BOUND_PCTX,
CS_BOUND_CPU
} __cpc_state_t;
struct __cpc_set {
cpc_request_t *cs_request;
__cpc_state_t cs_state;
int cs_nreqs;
int cs_fd;
processorid_t cs_obind;
pctx_t *cs_pctx;
id_t cs_id;
thread_t cs_thr;
cpc_set_t *cs_next;
};
struct __cpc {
cpc_set_t *cpc_sets;
cpc_buf_t *cpc_bufs;
cpc_errhndlr_t *cpc_errfn;
mutex_t cpc_lock;
char *cpc_attrlist;
char **cpc_evlist;
char cpc_cpuref[CPC_MAX_CPUREF];
char cpc_cciname[CPC_MAX_IMPL_NAME];
uint_t cpc_caps;
uint_t cpc_npic;
};
extern cpc_t *__cpc;
extern void __cpc_error(const char *fn, const char *fmt, ...);
extern const char *__cpc_reg_to_name(int cpuver, int regno, uint8_t bits);
extern int __cpc_name_to_reg(int cpuver, int regno,
const char *name, uint8_t *bits);
extern uint_t __cpc_workver;
extern int __cpc_v1_cpuver;
#ifdef __sparc
extern uint64_t __cpc_v1_pcr;
#else
extern uint32_t __cpc_v1_pes[2];
#endif
extern char *__cpc_pack_set(cpc_set_t *set, uint_t flags, size_t *buflen);
typedef struct __cpc_strhash cpc_strhash_t;
struct __cpc_strhash {
char *str;
struct __cpc_strhash *cur;
struct __cpc_strhash *next;
};
extern cpc_strhash_t *__cpc_strhash_alloc(void);
extern void __cpc_strhash_free(cpc_strhash_t *hash);
extern int __cpc_strhash_add(cpc_strhash_t *hash, char *key);
extern char *__cpc_strhash_next(cpc_strhash_t *hash);
struct __cpc;
extern int __pctx_cpc(pctx_t *pctx, struct __cpc *cpc, int cmd, id_t lwpid,
void *data1, void *data2, void *data3, int bufsize);
#define CPUDRV "/devices/pseudo/cpc@0"
#define CPUDRV_SHARED CPUDRV":shared"
#if defined(__sparc) || defined(__i386)
extern int __cpc_init(void);
extern cpc_set_t *__cpc_eventtoset(cpc_t *cpc, cpc_event_t *event, int flags);
#define CPC_ULTRA1 1000
#define CPC_ULTRA2 1001
#define CPC_ULTRA3 1002
#define CPC_ULTRA3_PLUS 1003
#define CPC_ULTRA3_I 1004
#define CPC_ULTRA4_PLUS 1005
#define CPC_PENTIUM 2000
#define CPC_PENTIUM_MMX 2001
#define CPC_PENTIUM_PRO 2002
#define CPC_PENTIUM_PRO_MMX 2003
#define CPC_SPARC64_III 3000
#define CPC_SPARC64_V 3002
#endif
#if defined(__i386) || defined(__amd64)
#define CPC_TICKREG_NAME "tsc"
#endif
#if defined(__sparc)
struct _cpc_event {
int ce_cpuver;
hrtime_t ce_hrt;
uint64_t ce_tick;
uint64_t ce_pic[2];
uint64_t ce_pcr;
};
#define CPC_TICKREG(ev) ((ev)->ce_tick)
#define CPC_TICKREG_NAME "%tick"
#define CPC_ULTRA_PCR_USR 2
#define CPC_ULTRA_PCR_SYS 1
#define CPC_ULTRA_PCR_PRIVPIC 0
#define CPC_ULTRA_PCR_PIC0_SHIFT 4
#define CPC_ULTRA2_PCR_PIC0_MASK UINT64_C(0xf)
#define CPC_ULTRA3_PCR_PIC0_MASK UINT64_C(0x3f)
#define CPC_ULTRA_PCR_PIC1_SHIFT 11
#define CPC_ULTRA2_PCR_PIC1_MASK UINT64_C(0xf)
#define CPC_ULTRA3_PCR_PIC1_MASK UINT64_C(0x3f)
#elif defined(__i386)
struct _cpc_event {
int ce_cpuver;
hrtime_t ce_hrt;
uint64_t ce_tsc;
uint64_t ce_pic[2];
uint32_t ce_pes[2];
#define ce_cesr ce_pes[0]
};
#define CPC_TICKREG(ev) ((ev)->ce_tsc)
#define CPC_P5_CESR_ES0_SHIFT 0
#define CPC_P5_CESR_ES0_MASK 0x3f
#define CPC_P5_CESR_ES1_SHIFT 16
#define CPC_P5_CESR_ES1_MASK 0x3f
#define CPC_P5_CESR_OS0 6
#define CPC_P5_CESR_USR0 7
#define CPC_P5_CESR_CLK0 8
#define CPC_P5_CESR_PC0 9
#define CPC_P5_CESR_OS1 (CPC_P5_CESR_OS0 + 16)
#define CPC_P5_CESR_USR1 (CPC_P5_CESR_USR0 + 16)
#define CPC_P5_CESR_CLK1 (CPC_P5_CESR_CLK0 + 16)
#define CPC_P5_CESR_PC1 (CPC_P5_CESR_PC0 + 16)
#define CPC_P6_PES_INV 23
#define CPC_P6_PES_EN 22
#define CPC_P6_PES_INT 20
#define CPC_P6_PES_PC 19
#define CPC_P6_PES_E 18
#define CPC_P6_PES_OS 17
#define CPC_P6_PES_USR 16
#define CPC_P6_PES_UMASK_SHIFT 8
#define CPC_P6_PES_UMASK_MASK (0xffu)
#define CPC_P6_PES_CMASK_SHIFT 24
#define CPC_P6_PES_CMASK_MASK (0xffu)
#define CPC_P6_PES_PIC0_MASK (0xffu)
#define CPC_P6_PES_PIC1_MASK (0xffu)
#endif
#ifdef __cplusplus
}
#endif
#endif