Blame src/components/perf_event_uncore/tests/perf_event_uncore.c

Packit 577717
/*
Packit 577717
 * This file tests uncore events on perf_event kernels
Packit 577717
 *
Packit 577717
 * In this test we use the :cpu=0 way of attaching to the CPU
Packit 577717
 * rather than the legacy PAPI way.
Packit 577717
 */
Packit 577717
Packit 577717
#include <stdio.h>
Packit 577717
Packit 577717
#include "papi.h"
Packit 577717
#include "papi_test.h"
Packit 577717
Packit 577717
#include "do_loops.h"
Packit 577717
Packit 577717
#include "perf_event_uncore_lib.h"
Packit 577717
Packit 577717
int main( int argc, char **argv ) {
Packit 577717
Packit 577717
	int retval,quiet;
Packit 577717
	int EventSet = PAPI_NULL;
Packit 577717
	long long values[1];
Packit 577717
	char *uncore_event=NULL;
Packit 577717
	char event_name[BUFSIZ];
Packit 577717
	int uncore_cidx=-1;
Packit 577717
	const PAPI_component_info_t *info;
Packit 577717
Packit 577717
	/* Set TESTS_QUIET variable */
Packit 577717
	quiet = tests_quiet( argc, argv );
Packit 577717
Packit 577717
	if (!quiet) {
Packit 577717
		printf("Testing the :cpu=0 way of attaching an uncore event to a core\n");
Packit 577717
	}
Packit 577717
Packit 577717
	/* Init the PAPI library */
Packit 577717
	retval = PAPI_library_init( PAPI_VER_CURRENT );
Packit 577717
	if ( retval != PAPI_VER_CURRENT ) {
Packit 577717
		test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
Packit 577717
	}
Packit 577717
Packit 577717
	/* Find the uncore PMU */
Packit 577717
	uncore_cidx=PAPI_get_component_index("perf_event_uncore");
Packit 577717
	if (uncore_cidx<0) {
Packit 577717
		if (!quiet) {
Packit 577717
			printf("perf_event_uncore component not found\n");
Packit 577717
		}
Packit 577717
		test_skip(__FILE__,__LINE__,"perf_event_uncore component not found",0);
Packit 577717
	}
Packit 577717
Packit 577717
	/* Check if component disabled */
Packit 577717
	info=PAPI_get_component_info(uncore_cidx);
Packit 577717
	if (info->disabled) {
Packit 577717
		if (!quiet) {
Packit 577717
			printf("perf_event_uncore component is disabled\n");
Packit 577717
		}
Packit 577717
		test_skip(__FILE__,__LINE__,"uncore component disabled",0);
Packit 577717
	}
Packit 577717
Packit 577717
	/* Get a relevant event name */
Packit 577717
	uncore_event=get_uncore_event(event_name, BUFSIZ);
Packit 577717
	if (uncore_event==NULL) {
Packit 577717
		if (!quiet) {
Packit 577717
			printf("uncore event name not available\n");
Packit 577717
		}
Packit 577717
		test_skip( __FILE__, __LINE__,
Packit 577717
			"PAPI does not support uncore on this processor",
Packit 577717
			PAPI_ENOSUPP );
Packit 577717
	}
Packit 577717
Packit 577717
	sprintf(uncore_event,"%s:cpu=0",uncore_event);
Packit 577717
Packit 577717
	/* Create an eventset */
Packit 577717
	retval = PAPI_create_eventset(&EventSet);
Packit 577717
	if (retval != PAPI_OK) {
Packit 577717
		test_fail(__FILE__, __LINE__, "PAPI_create_eventset",retval);
Packit 577717
	}
Packit 577717
Packit 577717
	/* Add our uncore event */
Packit 577717
	retval = PAPI_add_named_event(EventSet, uncore_event);
Packit 577717
	if (retval != PAPI_OK) {
Packit 577717
		if ( !quiet ) {
Packit 577717
			printf("Error trying to use event %s\n", uncore_event);
Packit 577717
		}
Packit 577717
		test_fail(__FILE__, __LINE__, "adding uncore event",retval);
Packit 577717
	}
Packit 577717
Packit 577717
	/* Start PAPI */
Packit 577717
	retval = PAPI_start( EventSet );
Packit 577717
	if ( retval != PAPI_OK ) {
Packit 577717
		test_fail( __FILE__, __LINE__, "PAPI_start", retval );
Packit 577717
	}
Packit 577717
Packit 577717
	/* our work code */
Packit 577717
	do_flops( NUM_FLOPS );
Packit 577717
Packit 577717
	/* Stop PAPI */
Packit 577717
	retval = PAPI_stop( EventSet, values );
Packit 577717
	if ( retval != PAPI_OK ) {
Packit 577717
		test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
Packit 577717
	}
Packit 577717
Packit 577717
	if ( !quiet ) {
Packit 577717
		printf("\tUsing event %s\n",uncore_event);
Packit 577717
		printf("\t%s: %lld\n",uncore_event,values[0]);
Packit 577717
	}
Packit 577717
Packit 577717
	test_pass( __FILE__ );
Packit 577717
Packit 577717
	return 0;
Packit 577717
}