Blame src/perfctr-2.6.x/usr.lib/libperfctr.h

Packit Service a1973e
/* $Id: libperfctr.h,v 1.35.2.3 2009/01/23 20:25:42 mikpe Exp $
Packit Service a1973e
 * Library interface to Linux x86 Performance-Monitoring Counters.
Packit Service a1973e
 *
Packit Service a1973e
 * Copyright (C) 1999-2009  Mikael Pettersson
Packit Service a1973e
 */
Packit Service a1973e
Packit Service a1973e
#ifndef __LIB_PERFCTR_H
Packit Service a1973e
#define __LIB_PERFCTR_H
Packit Service a1973e
Packit Service a1973e
#define CONFIG_KPERFCTR 1
Packit Service a1973e
#include <linux/perfctr.h>
Packit Service a1973e
Packit Service a1973e
struct perfctr_cpus_info {	/* malloc():d, use free() */
Packit Service a1973e
    struct perfctr_cpu_mask *cpus;
Packit Service a1973e
    struct perfctr_cpu_mask *cpus_forbidden;
Packit Service a1973e
};
Packit Service a1973e
Packit Service a1973e
/*
Packit Service a1973e
 * Operations on the process' own virtual-mode perfctrs.
Packit Service a1973e
 */
Packit Service a1973e
Packit Service a1973e
int _vperfctr_open(int creat);
Packit Service a1973e
int _vperfctr_control(int fd, const struct vperfctr_control*);
Packit Service a1973e
int _vperfctr_read_control(int fd, struct vperfctr_control*);
Packit Service a1973e
int _vperfctr_read_sum(int fd, struct perfctr_sum_ctrs*);
Packit Service a1973e
Packit Service a1973e
struct vperfctr;	/* opaque */
Packit Service a1973e
Packit Service a1973e
struct vperfctr *vperfctr_open_mode(unsigned int mode);
Packit Service a1973e
#define VPERFCTR_OPEN_CREAT_EXCL	3
Packit Service a1973e
Packit Service a1973e
struct vperfctr *vperfctr_open(void);
Packit Service a1973e
int vperfctr_info(const struct vperfctr*, struct perfctr_info*);
Packit Service a1973e
struct perfctr_cpus_info *vperfctr_cpus_info(const struct vperfctr*);
Packit Service a1973e
unsigned long long vperfctr_read_tsc(const struct vperfctr*);
Packit Service a1973e
unsigned long long vperfctr_read_pmc(const struct vperfctr*, unsigned);
Packit Service a1973e
int vperfctr_read_ctrs(const struct vperfctr*, struct perfctr_sum_ctrs*);
Packit Service a1973e
int vperfctr_read_state(const struct vperfctr*, struct perfctr_sum_ctrs*,
Packit Service a1973e
			struct vperfctr_control*);
Packit Service a1973e
int vperfctr_control(const struct vperfctr*, struct vperfctr_control*);
Packit Service a1973e
int vperfctr_stop(const struct vperfctr*);
Packit Service a1973e
int vperfctr_is_running(const struct vperfctr*);
Packit Service a1973e
int vperfctr_iresume(const struct vperfctr*);
Packit Service a1973e
int vperfctr_unlink(const struct vperfctr*);
Packit Service a1973e
void vperfctr_close(struct vperfctr*);
Packit Service a1973e
Packit Service a1973e
/*
Packit Service a1973e
 * Operations on other processes' virtual-mode perfctrs.
Packit Service a1973e
 * (Preliminary, subject to change.)
Packit Service a1973e
 */
Packit Service a1973e
Packit Service a1973e
struct rvperfctr;	/* opaque */
Packit Service a1973e
Packit Service a1973e
struct rvperfctr *rvperfctr_open(int pid);
Packit Service a1973e
int rvperfctr_pid(const struct rvperfctr*);
Packit Service a1973e
int rvperfctr_info(const struct rvperfctr*, struct perfctr_info*);
Packit Service a1973e
int rvperfctr_read_ctrs(const struct rvperfctr*, struct perfctr_sum_ctrs*);
Packit Service a1973e
int rvperfctr_read_state(const struct rvperfctr*, struct perfctr_sum_ctrs*,
Packit Service a1973e
			 struct vperfctr_control*);
Packit Service a1973e
int rvperfctr_control(const struct rvperfctr*, struct vperfctr_control*);
Packit Service a1973e
int rvperfctr_stop(const struct rvperfctr*);
Packit Service a1973e
int rvperfctr_iresume(const struct rvperfctr*);
Packit Service a1973e
int rvperfctr_unlink(const struct rvperfctr*);
Packit Service a1973e
void rvperfctr_close(struct rvperfctr*);
Packit Service a1973e
Packit Service a1973e
/*
Packit Service a1973e
 * Operations on global-mode perfctrs.
Packit Service a1973e
 */
Packit Service a1973e
Packit Service a1973e
struct gperfctr;	/* opaque */
Packit Service a1973e
Packit Service a1973e
struct gperfctr *gperfctr_open(void);
Packit Service a1973e
void gperfctr_close(struct gperfctr*);
Packit Service a1973e
int gperfctr_control(const struct gperfctr*, struct gperfctr_cpu_control*);
Packit Service a1973e
int gperfctr_read(const struct gperfctr*, struct gperfctr_cpu_state*);
Packit Service a1973e
int gperfctr_stop(const struct gperfctr*);
Packit Service a1973e
int gperfctr_start(const struct gperfctr*, unsigned int interval_usec);
Packit Service a1973e
int gperfctr_info(const struct gperfctr*, struct perfctr_info*);
Packit Service a1973e
struct perfctr_cpus_info *gperfctr_cpus_info(const struct gperfctr*);
Packit Service a1973e
Packit Service a1973e
/*
Packit Service a1973e
 * Descriptions of the events available for different processor types.
Packit Service a1973e
 */
Packit Service a1973e
Packit Service a1973e
enum perfctr_unit_mask_type {
Packit Service a1973e
    perfctr_um_type_fixed,	/* one fixed (required) value */
Packit Service a1973e
    perfctr_um_type_exclusive,	/* exactly one of N values */
Packit Service a1973e
    perfctr_um_type_bitmask,	/* bitwise 'or' of N power-of-2 values */
Packit Service a1973e
};
Packit Service a1973e
Packit Service a1973e
struct perfctr_unit_mask_value {
Packit Service a1973e
    unsigned int value;
Packit Service a1973e
    const char *description;	/* [NAME:]text */
Packit Service a1973e
};
Packit Service a1973e
Packit Service a1973e
struct perfctr_unit_mask {
Packit Service a1973e
    unsigned short default_value;
Packit Service a1973e
    enum perfctr_unit_mask_type type:8;
Packit Service a1973e
    unsigned char nvalues;
Packit Service a1973e
    struct perfctr_unit_mask_value values[1/*nvalues*/];
Packit Service a1973e
};
Packit Service a1973e
Packit Service a1973e
struct perfctr_event {
Packit Service a1973e
    unsigned short evntsel;
Packit Service a1973e
    unsigned short counters_set; /* P4 force this to be CPU-specific */
Packit Service a1973e
    const struct perfctr_unit_mask *unit_mask;
Packit Service a1973e
    const char *name;
Packit Service a1973e
    const char *description;
Packit Service a1973e
};
Packit Service a1973e
Packit Service a1973e
struct perfctr_event_set {
Packit Service a1973e
    unsigned int cpu_type;
Packit Service a1973e
    const char *event_prefix;
Packit Service a1973e
    const struct perfctr_event_set *include;
Packit Service a1973e
    unsigned int nevents;
Packit Service a1973e
    const struct perfctr_event *events;
Packit Service a1973e
};
Packit Service a1973e
Packit Service a1973e
const struct perfctr_event_set *perfctr_cpu_event_set(unsigned int cpu_type);
Packit Service a1973e
Packit Service a1973e
/*
Packit Service a1973e
 * Miscellaneous operations.
Packit Service a1973e
 */
Packit Service a1973e
Packit Service a1973e
/* this checks the ABI between library and kernel -- it can also
Packit Service a1973e
   be used by applications operating on raw file descriptors */
Packit Service a1973e
int _perfctr_abi_check_fd(int fd, unsigned int user_abi_version);
Packit Service a1973e
static __inline__ int perfctr_abi_check_fd(int fd)
Packit Service a1973e
{
Packit Service a1973e
    return _perfctr_abi_check_fd(fd, PERFCTR_ABI_VERSION);
Packit Service a1973e
}
Packit Service a1973e
Packit Service a1973e
int perfctr_info(int fd, struct perfctr_info *info);
Packit Service a1973e
int perfctr_get_info(struct perfctr_info *info);
Packit Service a1973e
struct perfctr_cpus_info *perfctr_cpus_info(int fd);
Packit Service a1973e
unsigned int perfctr_info_nrctrs(const struct perfctr_info*);
Packit Service a1973e
const char *perfctr_info_cpu_name(const struct perfctr_info*);
Packit Service a1973e
void perfctr_info_print(const struct perfctr_info*);
Packit Service a1973e
void perfctr_cpus_info_print(const struct perfctr_cpus_info*);
Packit Service a1973e
void perfctr_cpu_control_print(const struct perfctr_cpu_control*);
Packit Service a1973e
Packit Service a1973e
#endif /* __LIB_PERFCTR_H */