sys/dev/hwpmc/hwpmc_{amd,piv,ppro}.c:

- Update driver interrupt statistics correctly.

sys/sys/pmc.h, sys/dev/hwpmc/hwpmc_mod.c:
- Fix a bug affecting debug printfs.
- Move the 'stalled' flag from being in a bit in the
  'pm_flags' field of a 'struct pmc' to a field of its own in the
  same structure.  This flag is updated from the NMI handler and
  keeping it separate makes it easier to avoid races with other
  parts of the code.

sys/dev/hwpmc/hwpmc_logging.c:
- Do arithmetic with 'uintptr_t' types rather that casting
  to and from 'char *'.

Approved by:	re (scottl)
This commit is contained in:
Joseph Koshy 2005-07-09 17:29:36 +00:00
parent 9d77f80ae9
commit fbf1556d46
6 changed files with 46 additions and 36 deletions

View File

@ -679,7 +679,8 @@ amd_intr(int cpu, uintptr_t eip, int usermode)
KASSERT(cpu >= 0 && cpu < mp_ncpus,
("[amd,%d] out of range CPU %d", __LINE__, cpu));
PMCDBG(MDP,INT,1, "cpu=%d eip=%p", cpu, (void *) eip);
PMCDBG(MDP,INT,1, "cpu=%d eip=%p um=%d", cpu, (void *) eip,
usermode);
retval = 0;
@ -733,8 +734,9 @@ amd_intr(int cpu, uintptr_t eip, int usermode)
retval = 1; /* found an interrupting PMC */
}
if (retval == 0)
atomic_add_int(&pmc_stats.pm_intr_ignored, 1);
atomic_add_int(retval ? &pmc_stats.pm_intr_processed :
&pmc_stats.pm_intr_ignored, 1);
return retval;
}

View File

@ -97,6 +97,11 @@ static struct mtx pmc_kthread_mtx; /* sleep lock */
* Log file record constructors.
*/
#define _PMCLOG_TO_HEADER(T,L) \
((PMCLOG_HEADER_MAGIC << 24) | \
(PMCLOG_TYPE_ ## T << 16) | \
((L) & 0xFFFF))
/* reserve LEN bytes of space and initialize the entry header */
#define _PMCLOG_RESERVE(PO,TYPE,LEN,ACTION) do { \
uint32_t *_le; \
@ -104,9 +109,7 @@ static struct mtx pmc_kthread_mtx; /* sleep lock */
if ((_le = pmclog_reserve((PO), _len)) == NULL) { \
ACTION; \
} \
*_le = (PMCLOG_HEADER_MAGIC << 24) | \
(PMCLOG_TYPE_ ## TYPE << 16) | \
(_len & 0xFFFF); \
*_le = _PMCLOG_TO_HEADER(TYPE,_len); \
_le += 3 /* skip over timestamp */
#define PMCLOG_RESERVE(P,T,L) _PMCLOG_RESERVE(P,T,L,return)
@ -397,7 +400,7 @@ pmclog_release(struct pmc_owner *po)
static uint32_t *
pmclog_reserve(struct pmc_owner *po, int length)
{
char *newptr, *oldptr;
uintptr_t newptr, oldptr;
uint32_t *lh;
struct timespec ts;
@ -423,22 +426,25 @@ pmclog_reserve(struct pmc_owner *po, int length)
__LINE__, po, po->po_curbuf->plb_ptr, po->po_curbuf->plb_base,
po->po_curbuf->plb_fence));
oldptr = po->po_curbuf->plb_ptr;
oldptr = (uintptr_t) po->po_curbuf->plb_ptr;
newptr = oldptr + length;
KASSERT(oldptr != NULL,
KASSERT(oldptr != (uintptr_t) NULL,
("[pmc,%d] po=%p Null log buffer pointer", __LINE__, po));
/*
* If we have space in the current buffer, return a pointer to
* available space with the PO structure locked.
*/
if (newptr <= po->po_curbuf->plb_fence) {
po->po_curbuf->plb_ptr = newptr;
if (newptr <= (uintptr_t) po->po_curbuf->plb_fence) {
po->po_curbuf->plb_ptr = (char *) newptr;
goto done;
}
/* otherwise, schedule the current buffer and get a fresh buffer */
/*
* Otherwise, schedule the current buffer for output and get a
* fresh buffer.
*/
pmclog_schedule_io(po);
if (pmclog_get_buffer(po) != 0) {
@ -458,12 +464,12 @@ pmclog_reserve(struct pmc_owner *po, int length)
__LINE__, po, po->po_curbuf->plb_ptr, po->po_curbuf->plb_base,
po->po_curbuf->plb_fence));
oldptr = po->po_curbuf->plb_ptr;
oldptr = (uintptr_t) po->po_curbuf->plb_ptr;
done:
lh = (uint32_t *) oldptr; lh++;
/* fill in the timestamp */
getnanotime(&ts);
lh = (uint32_t *) oldptr;
lh++; /* skip header */
getnanotime(&ts); /* fill in the timestamp */
*lh++ = ts.tv_sec & 0xFFFFFFFF;
*lh++ = ts.tv_nsec & 0xFFFFFFF;
return (uint32_t *) oldptr;
@ -517,7 +523,7 @@ pmclog_stop_kthread(struct pmc_owner *po)
po->po_flags &= ~PMC_PO_OWNS_LOGFILE;
wakeup_one(po);
if (po->po_kthread)
msleep(po->po_kthread, &pmc_kthread_mtx, PPAUSE, "pmcdcl", 0);
msleep(po->po_kthread, &pmc_kthread_mtx, PPAUSE, "pmckstp", 0);
}
/*

View File

@ -1324,7 +1324,7 @@ pmc_process_csw_out(struct thread *td)
__LINE__, PMC_TO_ROWINDEX(pm), ri));
/* Stop hardware if not already stopped */
if ((pm->pm_flags & PMC_F_IS_STALLED) == 0)
if (pm->pm_stalled == 0)
md->pmd_stop_pmc(cpu, ri);
/* reduce this PMC's runcount */
@ -1855,7 +1855,7 @@ pmc_release_pmc_descriptor(struct pmc *pm)
/* switch off non-stalled CPUs */
if (pm->pm_state == PMC_STATE_RUNNING &&
(pm->pm_flags & PMC_F_IS_STALLED) == 0) {
pm->pm_stalled == 0) {
phw = pmc_pcpu[cpu]->pc_hwpmcs[ri];
@ -3395,8 +3395,7 @@ pmc_syscall_handler(struct thread *td, void *syscall_args)
/*
* Flush the per-owner log file and Write a user-entry to the
* log file.
* Write a user supplied value to the log file.
*/
case PMC_OP_WRITELOG:
@ -3474,8 +3473,8 @@ pmc_process_interrupt(int cpu, struct pmc *pm, uintfptr_t pc, int usermode)
ps = psb->ps_write;
if (ps->ps_pc) { /* in use, reader hasn't caught up */
pm->pm_stalled = 1;
atomic_add_int(&pmc_stats.pm_intr_bufferfull, 1);
atomic_set_int(&pm->pm_flags, PMC_F_IS_STALLED);
PMCDBG(SAM,INT,1,"(spc) cpu=%d pm=%p pc=%jx um=%d wr=%d rd=%d",
cpu, pm, (uint64_t) pc, usermode,
(int) (psb->ps_write - psb->ps_samples),
@ -3599,19 +3598,19 @@ pmc_process_samples(int cpu)
/*
* Restart any stalled sampling PMCs on this CPU.
*
* If the NMI handler sets PMC_F_IS_STALLED on a PMC after the
* check below, we'll end up processing the stalled PMC at the
* next hardclock tick.
* If the NMI handler sets the pm_stalled field of a PMC after
* the check below, we'll end up processing the stalled PMC at
* the next hardclock tick.
*/
for (n = 0; n < md->pmd_npmc; n++) {
(void) (*md->pmd_get_config)(cpu,n,&pm);
if (pm == NULL || /* !cfg'ed */
pm->pm_state != PMC_STATE_RUNNING || /* !active */
!PMC_IS_SAMPLING_MODE(PMC_TO_MODE(pm)) || /* !sampling */
(pm->pm_flags & PMC_F_IS_STALLED) == 0) /* !stalled */
pm->pm_stalled == 0) /* !stalled */
continue;
pm->pm_flags &= ~PMC_F_IS_STALLED;
pm->pm_stalled = 0;
ri = PMC_TO_ROWINDEX(pm);
(*md->pmd_start_pmc)(cpu, ri);
}
@ -3733,9 +3732,9 @@ pmc_process_exit(void *arg __unused, struct proc *p)
("[pmc,%d] bad runcount ri %d rc %d",
__LINE__, ri, pm->pm_runcount));
/* Stopped the hardware only if it is actually on */
/* Stop hardware only if it is actually running */
if (pm->pm_state == PMC_STATE_RUNNING &&
(pm->pm_flags & PMC_F_IS_STALLED) == 0) {
pm->pm_stalled == 0) {
md->pmd_read_pmc(cpu, ri, &newvalue);
tmp = newvalue -
PMC_PCPU_SAVED(cpu,ri);
@ -3771,7 +3770,8 @@ pmc_process_exit(void *arg __unused, struct proc *p)
*/
for (ri = 0; ri < md->pmd_npmc; ri++)
if ((pm = pp->pp_pmcs[ri].pp_pmc) != NULL) {
if (pm->pm_flags & PMC_F_NEEDS_LOGFILE)
if (pm->pm_flags & PMC_F_NEEDS_LOGFILE &&
PMC_IS_COUNTING_MODE(PMC_TO_MODE(pm)))
pmclog_process_procexit(pm, pp);
pmc_unlink_target_process(pm, pp);
}

View File

@ -1674,8 +1674,9 @@ p4_intr(int cpu, uintptr_t eip, int usermode)
if (did_interrupt)
pmc_x86_lapic_enable_pmc_interrupt();
else
atomic_add_int(&pmc_stats.pm_intr_ignored, 1);
atomic_add_int(did_interrupt ? &pmc_stats.pm_intr_processed :
&pmc_stats.pm_intr_ignored, 1);
return did_interrupt;
}

View File

@ -762,8 +762,9 @@ p6_intr(int cpu, uintptr_t eip, int usermode)
*/
if (retval)
pmc_x86_lapic_enable_pmc_interrupt();
else
atomic_add_int(&pmc_stats.pm_intr_ignored, 1);
atomic_add_int(retval ? &pmc_stats.pm_intr_processed :
&pmc_stats.pm_intr_ignored, 1);
/* restart counters that can be restarted */
P6_SYNC_CTR_STATE(pc);

View File

@ -306,7 +306,6 @@ enum pmc_ops {
#define PMC_F_ATTACHED_TO_OWNER 0x00010000 /*attached to owner*/
#define PMC_F_NEEDS_LOGFILE 0x00020000 /*needs log file */
#define PMC_F_ATTACH_DONE 0x00040000 /*attached at least once */
#define PMC_F_IS_STALLED 0x00080000 /*sampling is stalled*/
/*
* Cookies used to denote allocated PMCs, and the values of PMCs.
@ -646,6 +645,7 @@ struct pmc {
pmc_value_t pm_initial; /* counting PMC modes */
} pm_sc;
uint32_t pm_stalled; /* true for stalled sampling PMCs */
uint32_t pm_caps; /* PMC capabilities */
enum pmc_event pm_event; /* event being measured */
uint32_t pm_flags; /* additional flags PMC_F_... */
@ -915,7 +915,7 @@ extern struct pmc_debugflags pmc_debugflags;
#define PMC_DEBUG_DEFAULT_FLAGS { 0, 0, 0, 0, 0, 0, 0, 0 }
#define PMCDBG(M,N,L,F,...) do { \
if (pmc_debugflags.pdb_ ## M & PMC_DEBUG_MIN_ ## N) \
if (pmc_debugflags.pdb_ ## M & (1 << PMC_DEBUG_MIN_ ## N)) \
printf(#M ":" #N ":" #L ": " F "\n", __VA_ARGS__); \
} while (0)