Blame src/libpfm-3.y/examples_ia64_v2.0/showreset.c

Packit 577717
/*
Packit 577717
 * showreset.c - getting the PAL reset values for the PMCs
Packit 577717
 *
Packit 577717
 * Copyright (c) 2002-2006 Hewlett-Packard Development Company, L.P.
Packit 577717
 * Contributed by Stephane Eranian <eranian@hpl.hp.com>
Packit 577717
 *
Packit 577717
 * Permission is hereby granted, free of charge, to any person obtaining a copy
Packit 577717
 * of this software and associated documentation files (the "Software"), to deal
Packit 577717
 * in the Software without restriction, including without limitation the rights
Packit 577717
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
Packit 577717
 * of the Software, and to permit persons to whom the Software is furnished to do so,
Packit 577717
 * subject to the following conditions:
Packit 577717
 *
Packit 577717
 * The above copyright notice and this permission notice shall be included in all
Packit 577717
 * copies or substantial portions of the Software.
Packit 577717
 *
Packit 577717
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
Packit 577717
 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
Packit 577717
 * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
Packit 577717
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
Packit 577717
 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
Packit 577717
 * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Packit 577717
 *
Packit 577717
 * This file is part of libpfm, a performance monitoring support library for
Packit 577717
 * applications on Linux/ia64.
Packit 577717
 */
Packit 577717
#include <sys/types.h>
Packit 577717
#include <stdio.h>
Packit 577717
#include <stdlib.h>
Packit 577717
#include <stdarg.h>
Packit 577717
#include <errno.h>
Packit 577717
#include <unistd.h>
Packit 577717
#include <string.h>
Packit 577717
Packit 577717
#include <perfmon/perfmon.h>
Packit 577717
#include <perfmon/pfmlib.h>
Packit 577717
Packit 577717
#define NUM_PMCS PFMLIB_MAX_PMCS
Packit 577717
#define NUM_PMDS PFMLIB_MAX_PMDS
Packit 577717
Packit 577717
static void fatal_error(char *fmt,...) __attribute__((noreturn));
Packit 577717
Packit 577717
static void
Packit 577717
fatal_error(char *fmt, ...)
Packit 577717
{
Packit 577717
	va_list ap;
Packit 577717
Packit 577717
	va_start(ap, fmt);
Packit 577717
	vfprintf(stderr, fmt, ap);
Packit 577717
	va_end(ap);
Packit 577717
Packit 577717
	exit(1);
Packit 577717
}
Packit 577717
Packit 577717
int
Packit 577717
main(int argc, char **argv)
Packit 577717
{
Packit 577717
	unsigned int i, cnum = 0;
Packit 577717
	pfarg_reg_t pc[NUM_PMCS];
Packit 577717
	pfmlib_regmask_t impl_pmcs;
Packit 577717
	unsigned int num_pmcs;
Packit 577717
Packit 577717
	/*
Packit 577717
	 * Initialize pfm library (required before we can use it)
Packit 577717
	 */
Packit 577717
	if (pfm_initialize() != PFMLIB_SUCCESS) {
Packit 577717
		printf("Can't initialize library\n");
Packit 577717
		exit(1);
Packit 577717
	}
Packit 577717
Packit 577717
	memset(&impl_pmcs, 0, sizeof(impl_pmcs));
Packit 577717
	memset(pc, 0, sizeof(pc));
Packit 577717
	
Packit 577717
	pfm_get_impl_pmcs(&impl_pmcs);
Packit 577717
	pfm_get_num_pmcs(&num_pmcs);
Packit 577717
Packit 577717
	for(i=0; num_pmcs ; i++) {
Packit 577717
		if (pfm_regmask_isset(&impl_pmcs, i) == 0) continue;
Packit 577717
		pc[cnum++].reg_num = i;
Packit 577717
		num_pmcs--;
Packit 577717
	}
Packit 577717
Packit 577717
	if (perfmonctl(0, PFM_GET_PMC_RESET_VAL, pc, cnum) == -1 ) {
Packit 577717
		if (errno == ENOSYS) {
Packit 577717
			fatal_error("Your kernel does not have performance monitoring support!\n");
Packit 577717
		}
Packit 577717
		fatal_error("cannot get reset values: %s\n", strerror(errno));
Packit 577717
	}
Packit 577717
Packit 577717
	for (i=0; i < cnum; i++) {
Packit 577717
		printf("PMC%u 0x%lx\n", pc[i].reg_num, pc[i].reg_value);
Packit 577717
Packit 577717
	}
Packit 577717
	return 0;
Packit 577717
}