|
Packit |
577717 |
/*
|
|
Packit |
577717 |
* pfmlib_perf_events_raw.c: support for raw event syntax
|
|
Packit |
577717 |
*
|
|
Packit |
577717 |
* Copyright (c) 2014 Google, Inc. All rights reserved
|
|
Packit |
577717 |
* Contributed by Stephane Eranian <eranian@google.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 <stdio.h>
|
|
Packit |
577717 |
#include <unistd.h>
|
|
Packit |
577717 |
#include <ctype.h>
|
|
Packit |
577717 |
|
|
Packit |
577717 |
#include "pfmlib_priv.h"
|
|
Packit |
577717 |
#include "pfmlib_perf_event_priv.h"
|
|
Packit |
577717 |
|
|
Packit |
577717 |
static int
|
|
Packit |
577717 |
pfm_perf_raw_detect(void *this)
|
|
Packit |
577717 |
{
|
|
Packit |
577717 |
#ifdef __linux__
|
|
Packit |
577717 |
/* ought to find a better way of detecting PERF */
|
|
Packit |
577717 |
#define PERF_OLD_PROC_FILE "/proc/sys/kernel/perf_counter_paranoid"
|
|
Packit |
577717 |
#define PERF_PROC_FILE "/proc/sys/kernel/perf_event_paranoid"
|
|
Packit |
577717 |
return !(access(PERF_PROC_FILE, F_OK)
|
|
Packit |
577717 |
&& access(PERF_OLD_PROC_FILE, F_OK)) ? PFM_SUCCESS: PFM_ERR_NOTSUPP;
|
|
Packit |
577717 |
#else
|
|
Packit |
577717 |
return PFM_SUCCESS;
|
|
Packit |
577717 |
#endif
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
static int
|
|
Packit |
577717 |
pfm_perf_raw_get_event_first(void *this)
|
|
Packit |
577717 |
{
|
|
Packit |
577717 |
return 0;
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
static int
|
|
Packit |
577717 |
pfm_perf_raw_get_event_next(void *this, int idx)
|
|
Packit |
577717 |
{
|
|
Packit |
577717 |
/* only one pseudo event */
|
|
Packit |
577717 |
return -1;
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
static int
|
|
Packit |
577717 |
pfm_perf_raw_get_encoding(void *this, pfmlib_event_desc_t *e)
|
|
Packit |
577717 |
{
|
|
Packit |
577717 |
/*
|
|
Packit |
577717 |
* actual enoding done in pfm_perf_raw_match_event()
|
|
Packit |
577717 |
*/
|
|
Packit |
577717 |
e->fstr[0] = '\0';
|
|
Packit |
577717 |
evt_strcat(e->fstr, "r%"PRIx64, e->codes[0]);
|
|
Packit |
577717 |
return PFM_SUCCESS;
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
static int
|
|
Packit |
577717 |
pfm_perf_raw_get_perf_encoding(void *this, pfmlib_event_desc_t *e)
|
|
Packit |
577717 |
{
|
|
Packit |
577717 |
struct perf_event_attr *attr;
|
|
Packit |
577717 |
|
|
Packit |
577717 |
attr = e->os_data;
|
|
Packit |
577717 |
attr->type = PERF_TYPE_RAW;
|
|
Packit |
577717 |
attr->config = e->codes[0];
|
|
Packit |
577717 |
|
|
Packit |
577717 |
attr->config1 = e->codes[1];
|
|
Packit |
577717 |
attr->config2 = e->codes[2];
|
|
Packit |
577717 |
|
|
Packit |
577717 |
return PFM_SUCCESS;
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
static int
|
|
Packit |
577717 |
pfm_perf_raw_event_is_valid(void *this, int idx)
|
|
Packit |
577717 |
{
|
|
Packit |
577717 |
return idx == 0;
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
static int
|
|
Packit |
577717 |
pfm_perf_raw_get_event_attr_info(void *this, int idx, int attr_idx, pfmlib_event_attr_info_t *info)
|
|
Packit |
577717 |
{
|
|
Packit |
577717 |
return PFM_ERR_ATTR;
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
static int
|
|
Packit |
577717 |
pfm_perf_raw_get_event_info(void *this, int idx, pfm_event_info_t *info)
|
|
Packit |
577717 |
{
|
|
Packit |
577717 |
pfmlib_pmu_t *pmu = this;
|
|
Packit |
577717 |
|
|
Packit |
577717 |
info->name = "r0000";
|
|
Packit |
577717 |
info->desc = "perf_events raw event syntax: r[0-9a-fA-F]+",
|
|
Packit |
577717 |
info->code = 0;
|
|
Packit |
577717 |
info->equiv = NULL;
|
|
Packit |
577717 |
info->idx = 0;
|
|
Packit |
577717 |
info->pmu = pmu->pmu;
|
|
Packit |
577717 |
info->is_precise = 0;
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* unit masks + modifiers */
|
|
Packit |
577717 |
info->nattrs = 0;
|
|
Packit |
577717 |
|
|
Packit |
577717 |
return PFM_SUCCESS;
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
static unsigned int
|
|
Packit |
577717 |
pfm_perf_raw_get_event_nattrs(void *this, int idx)
|
|
Packit |
577717 |
{
|
|
Packit |
577717 |
return 0;
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/*
|
|
Packit |
577717 |
* remove attrs which are in conflicts (or duplicated) with os layer
|
|
Packit |
577717 |
*/
|
|
Packit |
577717 |
static void
|
|
Packit |
577717 |
pfm_perf_raw_perf_validate_pattrs(void *this, pfmlib_event_desc_t *e)
|
|
Packit |
577717 |
{
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/*
|
|
Packit |
577717 |
* returns 0 if match (like strcmp())
|
|
Packit |
577717 |
*/
|
|
Packit |
577717 |
static int
|
|
Packit |
577717 |
pfm_perf_raw_match_event(void *this, pfmlib_event_desc_t *d, const char *e, const char *s)
|
|
Packit |
577717 |
{
|
|
Packit |
577717 |
uint64_t code;
|
|
Packit |
577717 |
int ret;
|
|
Packit |
577717 |
|
|
Packit |
577717 |
if (*s != 'r' || !isxdigit(*(s+1)))
|
|
Packit |
577717 |
return 1;
|
|
Packit |
577717 |
|
|
Packit |
577717 |
ret = sscanf(s+1, "%"PRIx64, &code);
|
|
Packit |
577717 |
if (ret != 1)
|
|
Packit |
577717 |
return 1;
|
|
Packit |
577717 |
/*
|
|
Packit |
577717 |
* stash code in final position
|
|
Packit |
577717 |
*/
|
|
Packit |
577717 |
d->codes[0] = code;
|
|
Packit |
577717 |
d->count = 1;
|
|
Packit |
577717 |
|
|
Packit |
577717 |
return 0;
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
pfmlib_pmu_t perf_event_raw_support={
|
|
Packit |
577717 |
.desc = "perf_events raw PMU",
|
|
Packit |
577717 |
.name = "perf_raw",
|
|
Packit |
577717 |
.pmu = PFM_PMU_PERF_EVENT_RAW,
|
|
Packit |
577717 |
.pme_count = 1,
|
|
Packit |
577717 |
.type = PFM_PMU_TYPE_OS_GENERIC,
|
|
Packit |
577717 |
.max_encoding = 1,
|
|
Packit |
577717 |
.supported_plm = PERF_PLM_ALL,
|
|
Packit |
577717 |
.pmu_detect = pfm_perf_raw_detect,
|
|
Packit |
577717 |
.get_event_encoding[PFM_OS_NONE] = pfm_perf_raw_get_encoding,
|
|
Packit |
577717 |
PFMLIB_ENCODE_PERF(pfm_perf_raw_get_perf_encoding),
|
|
Packit |
577717 |
.get_event_first = pfm_perf_raw_get_event_first,
|
|
Packit |
577717 |
.get_event_next = pfm_perf_raw_get_event_next,
|
|
Packit |
577717 |
.event_is_valid = pfm_perf_raw_event_is_valid,
|
|
Packit |
577717 |
.get_event_info = pfm_perf_raw_get_event_info,
|
|
Packit |
577717 |
.get_event_attr_info = pfm_perf_raw_get_event_attr_info,
|
|
Packit |
577717 |
.get_event_nattrs = pfm_perf_raw_get_event_nattrs,
|
|
Packit |
577717 |
.match_event = pfm_perf_raw_match_event,
|
|
Packit |
577717 |
PFMLIB_VALID_PERF_PATTRS(pfm_perf_raw_perf_validate_pattrs),
|
|
Packit |
577717 |
};
|