|
Packit |
577717 |
/*
|
|
Packit |
577717 |
* check_events.c - check if event assignment is possible
|
|
Packit |
577717 |
*
|
|
Packit |
577717 |
* Copyright (c) 2008 Google, Inc
|
|
Packit |
577717 |
* Contributed by Stephane Eranian <eranian@gmail.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.
|
|
Packit |
577717 |
*/
|
|
Packit |
577717 |
#include <sys/types.h>
|
|
Packit |
577717 |
#include <inttypes.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 |
#include <inttypes.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 |
#define MAX_PMU_NAME_LEN 32
|
|
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 |
/*
|
|
Packit |
577717 |
* The goal of this program is to exercise the event assignment
|
|
Packit |
577717 |
* code for a specific PMU model. This program is independent of
|
|
Packit |
577717 |
* the kernel API.
|
|
Packit |
577717 |
*/
|
|
Packit |
577717 |
int
|
|
Packit |
577717 |
main(int argc, char **argv)
|
|
Packit |
577717 |
{
|
|
Packit |
577717 |
char **p;
|
|
Packit |
577717 |
unsigned int i;
|
|
Packit |
577717 |
int ret;
|
|
Packit |
577717 |
pfmlib_input_param_t inp;
|
|
Packit |
577717 |
pfmlib_output_param_t outp;
|
|
Packit |
577717 |
pfmlib_options_t pfmlib_options;
|
|
Packit |
577717 |
char model[MAX_PMU_NAME_LEN];
|
|
Packit |
577717 |
unsigned int num_counters;
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/*
|
|
Packit |
577717 |
* pass options to library (optional)
|
|
Packit |
577717 |
*/
|
|
Packit |
577717 |
memset(&pfmlib_options, 0, sizeof(pfmlib_options));
|
|
Packit |
577717 |
pfmlib_options.pfm_debug = 0; /* set to 1 for debug */
|
|
Packit |
577717 |
pfmlib_options.pfm_verbose = 0; /* set to 1 for verbose */
|
|
Packit |
577717 |
pfm_set_options(&pfmlib_options);
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/*
|
|
Packit |
577717 |
* Initialize pfm library (required before we can use it)
|
|
Packit |
577717 |
*/
|
|
Packit |
577717 |
ret = pfm_initialize();
|
|
Packit |
577717 |
if (ret != PFMLIB_SUCCESS)
|
|
Packit |
577717 |
fatal_error("Cannot initialize library: %s\n", pfm_strerror(ret));
|
|
Packit |
577717 |
|
|
Packit |
577717 |
pfm_get_pmu_name(model, MAX_PMU_NAME_LEN);
|
|
Packit |
577717 |
printf("PMU model: %s\n", model);
|
|
Packit |
577717 |
|
|
Packit |
577717 |
pfm_get_num_counters(&num_counters);
|
|
Packit |
577717 |
printf("%u counters available\n", num_counters);
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/*
|
|
Packit |
577717 |
* prepare parameters to library.
|
|
Packit |
577717 |
*/
|
|
Packit |
577717 |
memset(&inp,0, sizeof(inp));
|
|
Packit |
577717 |
memset(&outp,0, sizeof(outp));
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/*
|
|
Packit |
577717 |
* be nice to user!
|
|
Packit |
577717 |
*/
|
|
Packit |
577717 |
if (argc > 1) {
|
|
Packit |
577717 |
p = argv+1;
|
|
Packit |
577717 |
for (i=0; *p ; i++, p++) {
|
|
Packit |
577717 |
ret = pfm_find_full_event(*p, &inp.pfp_events[i]);
|
|
Packit |
577717 |
if (ret != PFMLIB_SUCCESS)
|
|
Packit |
577717 |
fatal_error("event %s: %s\n", *p, pfm_strerror(ret));
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
} else {
|
|
Packit |
577717 |
if (pfm_get_cycle_event(&inp.pfp_events[0]) != PFMLIB_SUCCESS)
|
|
Packit |
577717 |
fatal_error("cannot find cycle event\n");
|
|
Packit |
577717 |
|
|
Packit |
577717 |
if (pfm_get_inst_retired_event(&inp.pfp_events[1]) != PFMLIB_SUCCESS)
|
|
Packit |
577717 |
fatal_error("cannot find inst retired event\n");
|
|
Packit |
577717 |
i = 2;
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/*
|
|
Packit |
577717 |
* set the default privilege mode for all counters:
|
|
Packit |
577717 |
* PFM_PLM3 : user level only
|
|
Packit |
577717 |
*/
|
|
Packit |
577717 |
inp.pfp_dfl_plm = PFM_PLM3;
|
|
Packit |
577717 |
|
|
Packit |
577717 |
if (i > num_counters) {
|
|
Packit |
577717 |
i = num_counters;
|
|
Packit |
577717 |
printf("too many events provided (max=%d events), using first %d event(s)\n", num_counters, i);
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/*
|
|
Packit |
577717 |
* how many counters we use
|
|
Packit |
577717 |
*/
|
|
Packit |
577717 |
inp.pfp_event_count = i;
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/*
|
|
Packit |
577717 |
* let the library figure out the values for the PMCS
|
|
Packit |
577717 |
*/
|
|
Packit |
577717 |
if ((ret=pfm_dispatch_events(&inp, NULL, &outp, NULL)) != PFMLIB_SUCCESS)
|
|
Packit |
577717 |
fatal_error("cannot configure events: %s\n", pfm_strerror(ret));
|
|
Packit |
577717 |
|
|
Packit |
577717 |
for (i=0; i < outp.pfp_pmc_count; i++)
|
|
Packit |
577717 |
printf("PMC%u=0x%llx\n",
|
|
Packit |
577717 |
outp.pfp_pmcs[i].reg_num,
|
|
Packit |
577717 |
outp.pfp_pmcs[i].reg_value);
|
|
Packit |
577717 |
|
|
Packit |
577717 |
for (i=0; i < outp.pfp_pmd_count; i++)
|
|
Packit |
577717 |
printf("PMD%u\n", outp.pfp_pmds[i].reg_num);
|
|
Packit |
577717 |
return 0;
|
|
Packit |
577717 |
}
|