|
Packit |
577717 |
/* $Id: perfctr.h,v 1.1.2.3 2009/06/11 12:33:51 mikpe Exp $
|
|
Packit |
577717 |
* PPC32 Performance-Monitoring Counters driver
|
|
Packit |
577717 |
*
|
|
Packit |
577717 |
* Copyright (C) 2004-2007, 2009 Mikael Pettersson
|
|
Packit |
577717 |
*/
|
|
Packit |
577717 |
#ifndef _ASM_PPC_PERFCTR_H
|
|
Packit |
577717 |
#define _ASM_PPC_PERFCTR_H
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* perfctr_info.cpu_type values */
|
|
Packit |
577717 |
#define PERFCTR_PPC_GENERIC 0
|
|
Packit |
577717 |
#define PERFCTR_PPC_604 1
|
|
Packit |
577717 |
#define PERFCTR_PPC_604e 2
|
|
Packit |
577717 |
#define PERFCTR_PPC_750 3
|
|
Packit |
577717 |
#define PERFCTR_PPC_7400 4
|
|
Packit |
577717 |
#define PERFCTR_PPC_7450 5
|
|
Packit |
577717 |
|
|
Packit |
577717 |
struct perfctr_sum_ctrs {
|
|
Packit |
577717 |
unsigned long long tsc;
|
|
Packit |
577717 |
unsigned long long pmc[6];
|
|
Packit |
577717 |
};
|
|
Packit |
577717 |
|
|
Packit |
577717 |
struct perfctr_cpu_control {
|
|
Packit |
577717 |
unsigned int tsc_on;
|
|
Packit |
577717 |
unsigned int nractrs; /* # of a-mode counters */
|
|
Packit |
577717 |
unsigned int nrictrs; /* # of i-mode counters */
|
|
Packit |
577717 |
unsigned int pmc_map[6];
|
|
Packit |
577717 |
unsigned int evntsel[6]; /* one per counter, even on P5 */
|
|
Packit |
577717 |
int ireset[6]; /* [0,0x7fffffff], for i-mode counters */
|
|
Packit |
577717 |
struct {
|
|
Packit |
577717 |
unsigned int mmcr0; /* sans PMC{1,2}SEL */
|
|
Packit |
577717 |
unsigned int mmcr2; /* only THRESHMULT */
|
|
Packit |
577717 |
/* IABR/DABR/BAMR not supported */
|
|
Packit |
577717 |
} ppc;
|
|
Packit |
577717 |
unsigned int _reserved1;
|
|
Packit |
577717 |
unsigned int _reserved2;
|
|
Packit |
577717 |
unsigned int _reserved3;
|
|
Packit |
577717 |
unsigned int _reserved4;
|
|
Packit |
577717 |
};
|
|
Packit |
577717 |
|
|
Packit |
577717 |
struct perfctr_cpu_state {
|
|
Packit |
577717 |
unsigned int cstatus;
|
|
Packit |
577717 |
struct { /* k1 is opaque in the user ABI */
|
|
Packit |
577717 |
unsigned int id;
|
|
Packit |
577717 |
int isuspend_cpu;
|
|
Packit |
577717 |
} k1;
|
|
Packit |
577717 |
/* The two tsc fields must be inlined. Placing them in a
|
|
Packit |
577717 |
sub-struct causes unwanted internal padding on x86-64. */
|
|
Packit |
577717 |
unsigned int tsc_start;
|
|
Packit |
577717 |
unsigned long long tsc_sum;
|
|
Packit |
577717 |
struct {
|
|
Packit |
577717 |
unsigned int map;
|
|
Packit |
577717 |
unsigned int start;
|
|
Packit |
577717 |
unsigned long long sum;
|
|
Packit |
577717 |
} pmc[6]; /* the size is not part of the user ABI */
|
|
Packit |
577717 |
#ifdef __KERNEL__
|
|
Packit |
577717 |
unsigned int ppc_mmcr[3];
|
|
Packit |
577717 |
struct perfctr_cpu_control control;
|
|
Packit |
577717 |
#endif
|
|
Packit |
577717 |
};
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* cstatus is a re-encoding of control.tsc_on/nractrs/nrictrs
|
|
Packit |
577717 |
which should have less overhead in most cases */
|
|
Packit |
577717 |
/* XXX: ppc driver internally also uses cstatus&(1<<30) */
|
|
Packit |
577717 |
|
|
Packit |
577717 |
static inline
|
|
Packit |
577717 |
unsigned int perfctr_mk_cstatus(unsigned int tsc_on, unsigned int nractrs,
|
|
Packit |
577717 |
unsigned int nrictrs)
|
|
Packit |
577717 |
{
|
|
Packit |
577717 |
return (tsc_on<<31) | (nrictrs<<16) | ((nractrs+nrictrs)<<8) | nractrs;
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
static inline unsigned int perfctr_cstatus_enabled(unsigned int cstatus)
|
|
Packit |
577717 |
{
|
|
Packit |
577717 |
return cstatus;
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
static inline int perfctr_cstatus_has_tsc(unsigned int cstatus)
|
|
Packit |
577717 |
{
|
|
Packit |
577717 |
return (int)cstatus < 0; /* test and jump on sign */
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
static inline unsigned int perfctr_cstatus_nractrs(unsigned int cstatus)
|
|
Packit |
577717 |
{
|
|
Packit |
577717 |
return cstatus & 0x7F; /* and with imm8 */
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
static inline unsigned int perfctr_cstatus_nrctrs(unsigned int cstatus)
|
|
Packit |
577717 |
{
|
|
Packit |
577717 |
return (cstatus >> 8) & 0x7F;
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
static inline unsigned int perfctr_cstatus_has_ictrs(unsigned int cstatus)
|
|
Packit |
577717 |
{
|
|
Packit |
577717 |
return cstatus & (0x7F << 16);
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/*
|
|
Packit |
577717 |
* 'struct siginfo' support for perfctr overflow signals.
|
|
Packit |
577717 |
* In unbuffered mode, si_code is set to SI_PMC_OVF and a bitmask
|
|
Packit |
577717 |
* describing which perfctrs overflowed is put in si_pmc_ovf_mask.
|
|
Packit |
577717 |
* A bitmask is used since more than one perfctr can have overflowed
|
|
Packit |
577717 |
* by the time the interrupt handler runs.
|
|
Packit |
577717 |
*
|
|
Packit |
577717 |
* glibc's <signal.h> doesn't seem to define __SI_FAULT or __SI_CODE(),
|
|
Packit |
577717 |
* and including <asm/siginfo.h> as well may cause redefinition errors,
|
|
Packit |
577717 |
* so the user and kernel values are different #defines here.
|
|
Packit |
577717 |
*/
|
|
Packit |
577717 |
#ifdef __KERNEL__
|
|
Packit |
577717 |
#define SI_PMC_OVF (__SI_FAULT|'P')
|
|
Packit |
577717 |
#else
|
|
Packit |
577717 |
#define SI_PMC_OVF ('P')
|
|
Packit |
577717 |
#endif
|
|
Packit |
577717 |
#define si_pmc_ovf_mask _sifields._pad[0] /* XXX: use an unsigned field later */
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* version number for user-visible CPU-specific data */
|
|
Packit |
577717 |
#define PERFCTR_CPU_VERSION 0 /* XXX: not yet cast in stone */
|
|
Packit |
577717 |
|
|
Packit |
577717 |
#ifdef __KERNEL__
|
|
Packit |
577717 |
|
|
Packit |
577717 |
#if defined(CONFIG_PERFCTR) || defined(CONFIG_PERFCTR_MODULE)
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* Driver init/exit. */
|
|
Packit |
577717 |
extern int perfctr_cpu_init(void);
|
|
Packit |
577717 |
extern void perfctr_cpu_exit(void);
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* CPU type name. */
|
|
Packit |
577717 |
extern char *perfctr_cpu_name;
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* Hardware reservation. */
|
|
Packit |
577717 |
extern const char *perfctr_cpu_reserve(const char *service);
|
|
Packit |
577717 |
extern void perfctr_cpu_release(const char *service);
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* PRE: state has no running interrupt-mode counters.
|
|
Packit |
577717 |
Check that the new control data is valid.
|
|
Packit |
577717 |
Update the driver's private control data.
|
|
Packit |
577717 |
Returns a negative error code if the control data is invalid. */
|
|
Packit |
577717 |
extern int perfctr_cpu_update_control(struct perfctr_cpu_state *state, cpumask_t *cpumask);
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* Read a-mode counters. Subtract from start and accumulate into sums.
|
|
Packit |
577717 |
Must be called with preemption disabled. */
|
|
Packit |
577717 |
extern void perfctr_cpu_suspend(struct perfctr_cpu_state *state);
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* Write control registers. Read a-mode counters into start.
|
|
Packit |
577717 |
Must be called with preemption disabled. */
|
|
Packit |
577717 |
extern void perfctr_cpu_resume(struct perfctr_cpu_state *state);
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* Perform an efficient combined suspend/resume operation.
|
|
Packit |
577717 |
Must be called with preemption disabled. */
|
|
Packit |
577717 |
extern void perfctr_cpu_sample(struct perfctr_cpu_state *state);
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* The type of a perfctr overflow interrupt handler.
|
|
Packit |
577717 |
It will be called in IRQ context, with preemption disabled. */
|
|
Packit |
577717 |
typedef void (*perfctr_ihandler_t)(unsigned long pc);
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* Operations related to overflow interrupt handling. */
|
|
Packit |
577717 |
#ifdef CONFIG_PERFCTR_INTERRUPT_SUPPORT
|
|
Packit |
577717 |
extern void perfctr_cpu_set_ihandler(perfctr_ihandler_t);
|
|
Packit |
577717 |
extern void perfctr_cpu_ireload(struct perfctr_cpu_state*);
|
|
Packit |
577717 |
extern unsigned int perfctr_cpu_identify_overflow(struct perfctr_cpu_state*);
|
|
Packit |
577717 |
#else
|
|
Packit |
577717 |
static inline void perfctr_cpu_set_ihandler(perfctr_ihandler_t x) { }
|
|
Packit |
577717 |
#endif
|
|
Packit |
577717 |
static inline int perfctr_cpu_has_pending_interrupt(const struct perfctr_cpu_state *state)
|
|
Packit |
577717 |
{
|
|
Packit |
577717 |
return 0;
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
#endif /* CONFIG_PERFCTR */
|
|
Packit |
577717 |
|
|
Packit |
577717 |
#endif /* __KERNEL__ */
|
|
Packit |
577717 |
|
|
Packit |
577717 |
#endif /* _ASM_PPC_PERFCTR_H */
|