Blame src/libpfm4/lib/pfmlib_arm_perf_event.c

Packit 577717
/*
Packit 577717
 * pfmlib_arm_perf_event.c : perf_event ARM 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
Packit 577717
/* private headers */
Packit 577717
#include "pfmlib_priv.h"		/* library private */
Packit 577717
#include "pfmlib_arm_priv.h"
Packit 577717
#include "pfmlib_perf_event_priv.h"
Packit 577717
Packit 577717
int
Packit 577717
pfm_arm_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
	 * use generic raw encoding function first
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
	if (e->count > 1) {
Packit 577717
		DPRINT("%s: unsupported count=%d\n", e->count);
Packit 577717
		return PFM_ERR_NOTSUPP;
Packit 577717
	}
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
void
Packit 577717
pfm_arm_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
		 * with perf_events, u and k, hv are handled at the OS
Packit 577717
		 * level via attr.exclude_* fields
Packit 577717
		 */
Packit 577717
		if (arm_has_plm(this, e) && e->pattrs[i].ctrl == PFM_ATTR_CTRL_PMU) {
Packit 577717
			if (   e->pattrs[i].idx == ARM_ATTR_U
Packit 577717
			    || e->pattrs[i].idx == ARM_ATTR_K
Packit 577717
			    || e->pattrs[i].idx == ARM_ATTR_HV)
Packit 577717
				compact = 1;
Packit 577717
		}
Packit 577717
		if (e->pattrs[i].ctrl == PFM_ATTR_CTRL_PERF_EVENT) {
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
}