|
Packit |
577717 |
/*
|
|
Packit |
577717 |
* pfmlib_powerpc_perf_event.c : perf_event IBM Power/Torrent functions
|
|
Packit |
577717 |
*
|
|
Packit |
577717 |
* Copyright (c) 2011 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 |
#include <sys/types.h>
|
|
Packit |
577717 |
#include <string.h>
|
|
Packit |
577717 |
#include <stdlib.h>
|
|
Packit |
577717 |
#include <limits.h>
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* private headers */
|
|
Packit |
577717 |
#include "pfmlib_priv.h" /* library private */
|
|
Packit |
577717 |
#include "pfmlib_power_priv.h" /* architecture private */
|
|
Packit |
577717 |
#include "pfmlib_perf_event_priv.h"
|
|
Packit |
577717 |
|
|
Packit |
577717 |
int
|
|
Packit |
577717 |
pfm_gen_powerpc_get_perf_encoding(void *this, pfmlib_event_desc_t *e)
|
|
Packit |
577717 |
{
|
|
Packit |
577717 |
pfmlib_pmu_t *pmu = this;
|
|
Packit |
577717 |
struct perf_event_attr *attr = e->os_data;
|
|
Packit |
577717 |
int ret;
|
|
Packit |
577717 |
|
|
Packit |
577717 |
if (!pmu->get_event_encoding[PFM_OS_NONE])
|
|
Packit |
577717 |
return PFM_ERR_NOTSUPP;
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/*
|
|
Packit |
577717 |
* encoding routine changes based on PMU model
|
|
Packit |
577717 |
*/
|
|
Packit |
577717 |
ret = pmu->get_event_encoding[PFM_OS_NONE](this, e);
|
|
Packit |
577717 |
if (ret != PFM_SUCCESS)
|
|
Packit |
577717 |
return ret;
|
|
Packit |
577717 |
|
|
Packit |
577717 |
attr->type = PERF_TYPE_RAW;
|
|
Packit |
577717 |
attr->config = e->codes[0];
|
|
Packit |
577717 |
|
|
Packit |
577717 |
return PFM_SUCCESS;
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
static int
|
|
Packit |
577717 |
find_pmu_type_by_name(const char *name)
|
|
Packit |
577717 |
{
|
|
Packit |
577717 |
char filename[PATH_MAX];
|
|
Packit |
577717 |
FILE *fp;
|
|
Packit |
577717 |
int ret, type;
|
|
Packit |
577717 |
|
|
Packit |
577717 |
if (!name)
|
|
Packit |
577717 |
return PFM_ERR_NOTSUPP;
|
|
Packit |
577717 |
|
|
Packit |
577717 |
sprintf(filename, "/sys/bus/event_source/devices/%s/type", name);
|
|
Packit |
577717 |
|
|
Packit |
577717 |
fp = fopen(filename, "r");
|
|
Packit |
577717 |
if (!fp)
|
|
Packit |
577717 |
return PFM_ERR_NOTSUPP;
|
|
Packit |
577717 |
|
|
Packit |
577717 |
ret = fscanf(fp, "%d", &type);
|
|
Packit |
577717 |
if (ret != 1)
|
|
Packit |
577717 |
type = PFM_ERR_NOTSUPP;
|
|
Packit |
577717 |
|
|
Packit |
577717 |
fclose(fp);
|
|
Packit |
577717 |
|
|
Packit |
577717 |
return type;
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
|
|
Packit |
577717 |
int
|
|
Packit |
577717 |
pfm_gen_powerpc_get_nest_perf_encoding(void *this, pfmlib_event_desc_t *e)
|
|
Packit |
577717 |
{
|
|
Packit |
577717 |
pfmlib_pmu_t *pmu = this;
|
|
Packit |
577717 |
struct perf_event_attr *attr = e->os_data;
|
|
Packit |
577717 |
int ret;
|
|
Packit |
577717 |
|
|
Packit |
577717 |
if (!pmu->get_event_encoding[PFM_OS_NONE])
|
|
Packit |
577717 |
return PFM_ERR_NOTSUPP;
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/*
|
|
Packit |
577717 |
* encoding routine changes based on PMU model
|
|
Packit |
577717 |
*/
|
|
Packit |
577717 |
ret = pmu->get_event_encoding[PFM_OS_NONE](this, e);
|
|
Packit |
577717 |
if (ret != PFM_SUCCESS)
|
|
Packit |
577717 |
return ret;
|
|
Packit |
577717 |
|
|
Packit |
577717 |
ret = find_pmu_type_by_name(pmu->perf_name);
|
|
Packit |
577717 |
if (ret < 0)
|
|
Packit |
577717 |
return ret;
|
|
Packit |
577717 |
|
|
Packit |
577717 |
attr->type = ret;
|
|
Packit |
577717 |
attr->config = e->codes[0];
|
|
Packit |
577717 |
|
|
Packit |
577717 |
return PFM_SUCCESS;
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
|
|
Packit |
577717 |
void
|
|
Packit |
577717 |
pfm_gen_powerpc_perf_validate_pattrs(void *this, pfmlib_event_desc_t *e)
|
|
Packit |
577717 |
{
|
|
Packit |
577717 |
int i, compact;
|
|
Packit |
577717 |
|
|
Packit |
577717 |
for (i = 0; i < e->npattrs; i++) {
|
|
Packit |
577717 |
compact = 0;
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* umasks never conflict */
|
|
Packit |
577717 |
if (e->pattrs[i].type == PFM_ATTR_UMASK)
|
|
Packit |
577717 |
continue;
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/*
|
|
Packit |
577717 |
* remove PMU-provided attributes which are either
|
|
Packit |
577717 |
* not accessible under perf_events or fully controlled
|
|
Packit |
577717 |
* by perf_events, e.g., priv levels filters
|
|
Packit |
577717 |
*/
|
|
Packit |
577717 |
if (e->pattrs[i].ctrl == PFM_ATTR_CTRL_PMU) {
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/*
|
|
Packit |
577717 |
* remove perf_event generic attributes not supported
|
|
Packit |
577717 |
* by PPC
|
|
Packit |
577717 |
*/
|
|
Packit |
577717 |
if (e->pattrs[i].ctrl == PFM_ATTR_CTRL_PERF_EVENT) {
|
|
Packit |
577717 |
/* no precise sampling */
|
|
Packit |
577717 |
if (e->pattrs[i].idx == PERF_ATTR_PR)
|
|
Packit |
577717 |
compact = 1;
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
if (compact) {
|
|
Packit |
577717 |
pfmlib_compact_pattrs(e, i);
|
|
Packit |
577717 |
i--;
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
}
|