Blame src/perfctr-2.7.x/examples/perfex/ppc64.c

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);
Packit 577717
    nrctrs = cpu_control->nractrs;
Packit 577717
    for(i = 0; i < nrctrs; ++i) {
Packit 577717
	fprintf(resfile, "\t%19lld\n", sum->pmc[i]);
Packit 577717
    }
Packit 577717
    if( cpu_control->ppc64.mmcr0 )
Packit 577717
	fprintf(resfile, "mmcr0 0x%08X\n",
Packit 577717
		cpu_control->ppc64.mmcr0);
Packit 577717
    if( cpu_control->ppc64.mmcr1 )
Packit 577717
	fprintf(resfile, "mmcr1 0x%016llX\n",
Packit 577717
		(unsigned long long)cpu_control->ppc64.mmcr1);
Packit 577717
    if( cpu_control->ppc64.mmcra )
Packit 577717
	fprintf(resfile, "mmcra 0x%08X\n",
Packit 577717
		cpu_control->ppc64.mmcra);
Packit 577717
		
Packit 577717
}
Packit 577717
Packit 577717
void do_arch_usage(void)
Packit 577717
{
Packit 577717
    fprintf(stderr, "\t--mmcr0=<value>\t\t\tValue for MMCR0\n");
Packit 577717
    fprintf(stderr, "\t--mmcr1=<value>\t\t\tValue for MMCR1\n");
Packit 577717
    fprintf(stderr, "\t--mmcra=<value>\t\t\tValue for MMCRA\n");
Packit 577717
    fprintf(stderr, "\n");
Packit 577717
    fprintf(stderr, "Syntax of event specifiers:\n");
Packit 577717
    fprintf(stderr, "\tevent ::= @pmc\n");
Packit 577717
    fprintf(stderr, "\n");
Packit 577717
    fprintf(stderr, "\tpmc is a decimal or hexadecimal number.\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
}
Packit 577717
Packit 577717
static int parse_event_spec(const char *arg, unsigned int *pmc)
Packit 577717
{
Packit 577717
    char *endp;
Packit 577717
    if( arg[0] != '@' )
Packit 577717
    	return -1;
Packit 577717
    *pmc = strtoul(arg+1, &endp, 0);
Packit 577717
    return endp[0] != '\0';
Packit 577717
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_pmc;
Packit 577717
Packit 577717
    if( parse_event_spec(arg, &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->pmc_map)) {
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
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 long *value)
Packit 577717
{
Packit 577717
    char *endp;
Packit 577717
Packit 577717
    *value = strtoul(arg, &endp, 16);
Packit 577717
    return endp[0] != '\0';
Packit 577717
}
Packit 577717
Packit 577717
static int parse_value_ull(const char *arg, unsigned long long *value)
Packit 577717
{
Packit 577717
    char *endp;
Packit 577717
Packit 577717
    *value = strtoull(arg, &endp, 16);
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 long spec_value;
Packit 577717
    unsigned long long spec_value_ull;
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->ppc64.mmcr0 = spec_value;
Packit 577717
	return 0;
Packit 577717
      case 2:
Packit 577717
	if( parse_value_ull(arg, &spec_value_ull) ) {
Packit 577717
	    fprintf(stderr, "perfex: invalid value: '%s'\n", arg);
Packit 577717
	    exit(1);
Packit 577717
	}
Packit 577717
	cpu_control->ppc64.mmcr1 = spec_value_ull;
Packit 577717
	return 0;
Packit 577717
      case 3:
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->ppc64.mmcra = spec_value;
Packit 577717
	return 0;
Packit 577717
    }
Packit 577717
    return -1;
Packit 577717
}