|
Packit |
577717 |
/* $Id: x86.c,v 1.6 2005/03/14 01:48:42 mikpe Exp $
|
|
Packit |
577717 |
* x86-specific code.
|
|
Packit |
577717 |
*
|
|
Packit |
577717 |
* Copyright (C) 1999-2004 Mikael Pettersson
|
|
Packit |
577717 |
*/
|
|
Packit |
577717 |
#include <stdio.h>
|
|
Packit |
577717 |
#include <stdlib.h>
|
|
Packit |
577717 |
#include "libperfctr.h"
|
|
Packit |
577717 |
#include "arch.h"
|
|
Packit |
577717 |
|
|
Packit |
577717 |
void do_print(FILE *resfile,
|
|
Packit |
577717 |
const struct perfctr_cpu_control *cpu_control,
|
|
Packit |
577717 |
const struct perfctr_sum_ctrs *sum,
|
|
Packit |
577717 |
const struct perfctr_sum_ctrs *children)
|
|
Packit |
577717 |
{
|
|
Packit |
577717 |
unsigned int nrctrs, i;
|
|
Packit |
577717 |
|
|
Packit |
577717 |
if( cpu_control->tsc_on )
|
|
Packit |
577717 |
fprintf(resfile, "tsc\t\t\t%19lld\n", sum->tsc + children->tsc);
|
|
Packit |
577717 |
nrctrs = cpu_control->nractrs;
|
|
Packit |
577717 |
for(i = 0; i < nrctrs; ++i) {
|
|
Packit |
577717 |
fprintf(resfile, "event 0x%08X",
|
|
Packit |
577717 |
cpu_control->evntsel[i]);
|
|
Packit |
577717 |
if( cpu_control->p4.escr[i] )
|
|
Packit |
577717 |
fprintf(resfile, "/0x%08X",
|
|
Packit |
577717 |
cpu_control->p4.escr[i]);
|
|
Packit |
577717 |
fprintf(resfile, "\t%19lld\n", sum->pmc[i] + children->pmc[i]);
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
if( cpu_control->p4.pebs_enable )
|
|
Packit |
577717 |
fprintf(resfile, "PEBS_ENABLE 0x%08X\n",
|
|
Packit |
577717 |
cpu_control->p4.pebs_enable);
|
|
Packit |
577717 |
if( cpu_control->p4.pebs_matrix_vert )
|
|
Packit |
577717 |
fprintf(resfile, "PEBS_MATRIX_VERT 0x%08X\n",
|
|
Packit |
577717 |
cpu_control->p4.pebs_matrix_vert);
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
void do_arch_usage(void)
|
|
Packit |
577717 |
{
|
|
Packit |
577717 |
fprintf(stderr, "\t--p4pe=<value>\t\t\tValue for PEBS_ENABLE (P4 only)\n");
|
|
Packit |
577717 |
fprintf(stderr, "\t--p4_pebs_enable=<value>\tSame as --p4pe=<value>\n");
|
|
Packit |
577717 |
fprintf(stderr, "\t--p4pmv=<value>\t\t\tValue for PEBS_MATRIX_VERT (P4 only)\n");
|
|
Packit |
577717 |
fprintf(stderr, "\t--p4_pebs_matrix_vert=<value>\tSame as --p4pmv=<value>\n");
|
|
Packit |
577717 |
fprintf(stderr, "\n");
|
|
Packit |
577717 |
fprintf(stderr, "Syntax of event specifiers:\n");
|
|
Packit |
577717 |
fprintf(stderr, "\tevent ::= evntsel[/escr][@pmc]\n");
|
|
Packit |
577717 |
fprintf(stderr, "\n");
|
|
Packit |
577717 |
fprintf(stderr, "\tevntsel, escr, and pmc are decimal or hexadecimal numbers.\n");
|
|
Packit |
577717 |
fprintf(stderr, "\n");
|
|
Packit |
577717 |
fprintf(stderr, "\tevntsel is the primary processor-specific event selection code\n");
|
|
Packit |
577717 |
fprintf(stderr, "\tto use for this counter. This field is mandatory.\n");
|
|
Packit |
577717 |
fprintf(stderr, "\tOn a P4, evntsel is written to the counter's CCCR register.\n");
|
|
Packit |
577717 |
fprintf(stderr, "\n");
|
|
Packit |
577717 |
fprintf(stderr, "\tescr describes the additional event selection data written to\n");
|
|
Packit |
577717 |
fprintf(stderr, "\tthe counter's associated ESCR register. (P4 only)\n");
|
|
Packit |
577717 |
fprintf(stderr, "\n");
|
|
Packit |
577717 |
fprintf(stderr, "\tpmc describes which CPU counter to use for this event.\n");
|
|
Packit |
577717 |
fprintf(stderr, "\tBy default the events use counters 0 and up in the order listed.\n");
|
|
Packit |
577717 |
fprintf(stderr, "\tOn P4, each event is compatible with only a small subset of the\n");
|
|
Packit |
577717 |
fprintf(stderr, "\tcounters, and explicit counter assignment is mandatory. Also,\n");
|
|
Packit |
577717 |
fprintf(stderr, "\ton P4 bit 31 should be set in pmc to enable 'fast rdpmc'.\n");
|
|
Packit |
577717 |
fprintf(stderr, "\tVIA C3 accepts a single event only, but it must use counter 1.\n");
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
static int parse_event_spec(const char *arg, unsigned int *evntsel,
|
|
Packit |
577717 |
unsigned int *escr, unsigned int *pmc)
|
|
Packit |
577717 |
{
|
|
Packit |
577717 |
char *endp;
|
|
Packit |
577717 |
|
|
Packit |
577717 |
*evntsel = my_strtoul(arg, &endp);
|
|
Packit |
577717 |
if( endp[0] != '/' ) {
|
|
Packit |
577717 |
*escr = 0;
|
|
Packit |
577717 |
} else {
|
|
Packit |
577717 |
arg = endp + 1;
|
|
Packit |
577717 |
*escr = my_strtoul(arg, &endp);
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
if( endp[0] != '@' ) {
|
|
Packit |
577717 |
*pmc = (unsigned int)-1;
|
|
Packit |
577717 |
} else {
|
|
Packit |
577717 |
arg = endp + 1;
|
|
Packit |
577717 |
*pmc = my_strtoul(arg, &endp);
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
return endp[0] != '\0';
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
unsigned int do_event_spec(unsigned int n,
|
|
Packit |
577717 |
const char *arg,
|
|
Packit |
577717 |
struct perfctr_cpu_control *cpu_control)
|
|
Packit |
577717 |
{
|
|
Packit |
577717 |
unsigned int spec_evntsel, spec_escr, spec_pmc;
|
|
Packit |
577717 |
|
|
Packit |
577717 |
if( parse_event_spec(arg, &spec_evntsel, &spec_escr, &spec_pmc) ) {
|
|
Packit |
577717 |
fprintf(stderr, "perfex: invalid event specifier: '%s'\n", arg);
|
|
Packit |
577717 |
exit(1);
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
if( n >= ARRAY_SIZE(cpu_control->evntsel) ) {
|
|
Packit |
577717 |
fprintf(stderr, "perfex: too many event specifiers\n");
|
|
Packit |
577717 |
exit(1);
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
if( spec_pmc == (unsigned int)-1 )
|
|
Packit |
577717 |
spec_pmc = n;
|
|
Packit |
577717 |
cpu_control->evntsel[n] = spec_evntsel;
|
|
Packit |
577717 |
cpu_control->p4.escr[n] = spec_escr;
|
|
Packit |
577717 |
cpu_control->pmc_map[n] = spec_pmc;
|
|
Packit |
577717 |
cpu_control->nractrs = ++n;
|
|
Packit |
577717 |
return n;
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
static int parse_value(const char *arg, unsigned int *value)
|
|
Packit |
577717 |
{
|
|
Packit |
577717 |
char *endp;
|
|
Packit |
577717 |
|
|
Packit |
577717 |
*value = my_strtoul(arg, &endp);
|
|
Packit |
577717 |
return endp[0] != '\0';
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
int do_arch_option(int ch,
|
|
Packit |
577717 |
const char *arg,
|
|
Packit |
577717 |
struct perfctr_cpu_control *cpu_control)
|
|
Packit |
577717 |
{
|
|
Packit |
577717 |
unsigned int spec_value;
|
|
Packit |
577717 |
|
|
Packit |
577717 |
switch( ch ) {
|
|
Packit |
577717 |
case 1:
|
|
Packit |
577717 |
if( parse_value(arg, &spec_value) ) {
|
|
Packit |
577717 |
fprintf(stderr, "perfex: invalid value: '%s'\n", arg);
|
|
Packit |
577717 |
exit(1);
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
cpu_control->p4.pebs_enable = spec_value;
|
|
Packit |
577717 |
return 0;
|
|
Packit |
577717 |
case 2:
|
|
Packit |
577717 |
if( parse_value(arg, &spec_value) ) {
|
|
Packit |
577717 |
fprintf(stderr, "perfex: invalid value: '%s'\n", arg);
|
|
Packit |
577717 |
exit(1);
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
cpu_control->p4.pebs_matrix_vert = spec_value;
|
|
Packit |
577717 |
return 0;
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
return -1;
|
|
Packit |
577717 |
}
|