PAPI 7.1.0.0
Loading...
Searching...
No Matches
tests/powercap_limit.c File Reference
Include dependency graph for tests/powercap_limit.c:

Go to the source code of this file.

Macros

#define MAX_powercap_EVENTS   64
 Tests basic functionality of powercap component.
 

Functions

int main (int argc, char **argv)
 

Macro Definition Documentation

◆ MAX_powercap_EVENTS

#define MAX_powercap_EVENTS   64
Author
Philip Vaccaro Test case for powercap component

Definition at line 16 of file tests/powercap_limit.c.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 18 of file tests/powercap_limit.c.

19{
20 (void) argv;
21 (void) argc;
22 int retval,cid,powercap_cid=-1,numcmp;
23 int EventSet = PAPI_NULL;
24 long long values[MAX_powercap_EVENTS];
25 int limit_map[MAX_powercap_EVENTS];
26 int num_events=0, num_limits=0;
27 int code;
29 int r,i;
30
31 const PAPI_component_info_t *cmpinfo = NULL;
32
33 /* PAPI Initialization */
35 if ( retval != PAPI_VER_CURRENT )
36 test_fail( __FILE__, __LINE__,"PAPI_library_init()\n",retval );
37
38 if ( !TESTS_QUIET ) printf( "Trying all powercap events\n" );
39
40 numcmp = PAPI_num_components();
41
42 for( cid=0; cid<numcmp; cid++ ) {
43
44 if ( ( cmpinfo = PAPI_get_component_info( cid ) ) == NULL )
45 test_fail( __FILE__, __LINE__,"PAPI_get_component_info()\n", 0 );
46
47 if ( strstr( cmpinfo->name,"powercap" ) ) {
48 powercap_cid=cid;
49 if ( !TESTS_QUIET ) printf( "Found powercap component at cid %d\n",powercap_cid );
50 if ( cmpinfo->disabled ) {
51 if ( !TESTS_QUIET ) {
52 printf( "powercap component disabled: %s\n",
53 cmpinfo->disabled_reason );
54 }
55 test_skip( __FILE__,__LINE__,"powercap component disabled",0 );
56 }
57 break;
58 }
59 }
60
61 /* Component not found */
62 if ( cid==numcmp )
63 test_skip( __FILE__,__LINE__,"No powercap component found\n",0 );
64
65 /* Skip if component has no counters */
66 if ( cmpinfo->num_cntrs==0 )
67 test_skip( __FILE__,__LINE__,"No counters in the powercap component\n",0 );
68
69 /* Create EventSet */
71 if ( retval != PAPI_OK )
72 test_fail( __FILE__, __LINE__, "PAPI_create_eventset()",retval );
73
74 /* Add all package limit events */
75 code = PAPI_NATIVE_MASK;
76 r = PAPI_enum_cmp_event( &code, PAPI_ENUM_FIRST, powercap_cid );
77
78
79 /* find all package power events */
80 while ( r == PAPI_OK ) {
82 if ( retval != PAPI_OK )
83 test_fail( __FILE__, __LINE__,"PAPI_event_code_to_name()", retval );
84
86 if (retval != PAPI_OK)
87 break; /* We've hit an event limit */
88
89 if (!(strstr(event_names[num_events],"SUBZONE")) && (strstr(event_names[num_events],"POWER_LIMIT"))) {
90
91 limit_map[num_limits] = num_events;
92 num_limits++;
93 }
94 num_events++;
95 r = PAPI_enum_cmp_event( &code, PAPI_ENUM_EVENTS, powercap_cid );
96 }
97
98
99 /* start collecting power data */
101 if ( retval != PAPI_OK )
102 test_fail( __FILE__, __LINE__, "PAPI_start()",retval );
103
104 /* initial read of package limits */
106 if ( retval != PAPI_OK )
107 test_fail( __FILE__, __LINE__, "PAPI_read()",retval );
108
109
110 printf("\nCURRENT LIMITS\n");
111 for( i=0; i<num_limits; i++ ) {
112 printf("EVENT: %s\tLIMIT: %0.2lf Watts\n", event_names[limit_map[i]], ((double)values[limit_map[i]]*1e-6));
113 values[limit_map[i]] = values[limit_map[i]] - (10 * 1e6); //minus 10 Watts
114 }
115 usleep(10000);
116
117 printf("\nSETTING LIMITS 10 WATTS BELOW CURRENT LIMITS\n");
119 if ( retval != PAPI_OK )
120 test_fail( __FILE__, __LINE__, "PAPI_write()",retval );
121
122 usleep(10000);
123
124 printf("\nREADING LIMITS TO MAKE SURE THEY ARE SET\n");
126 if ( retval != PAPI_OK )
127 test_fail( __FILE__, __LINE__, "PAPI_read()",retval );
128 usleep(10000);
129
130 printf("\nNEW LIMITS\n");
131 for( i=0; i<num_limits; i++ ) {
132 printf("EVENT: %s\tLIMIT: %0.2lf Watts\n", event_names[limit_map[i]], ((double)values[limit_map[i]]*1e-6));
133 values[limit_map[i]] = values[limit_map[i]] + (10 * 1e6); //plus 10 Watts
134 }
135
136 printf("\nRESET LIMITS BEFORE EXITING...");
138 if ( retval != PAPI_OK )
139 test_fail( __FILE__, __LINE__, "PAPI_write()",retval );
140 usleep(10000);
141
142 printf("\nREADING RESET LIMITS TO MAKE SURE THEY ARE SET\n");
144 if ( retval != PAPI_OK )
145 test_fail( __FILE__, __LINE__, "PAPI_read()",retval );
146 usleep(10000);
147
148 printf("\nRESET LIMITS\n");
149 for( i=0; i<num_limits; i++ ) {
150 printf("EVENT: %s\tLIMIT: %0.2lf Watts\n", event_names[limit_map[i]], ((double)values[limit_map[i]]*1e-6));
151 }
152
153 printf("done\n");
154
156 if ( retval != PAPI_OK )
157 test_fail( __FILE__, __LINE__, "PAPI_stop()",retval );
158
159 /* Done, clean up */
161 if ( retval != PAPI_OK )
162 test_fail( __FILE__, __LINE__,"PAPI_cleanup_eventset()",retval );
163
165 if ( retval != PAPI_OK )
166 test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset()",retval );
167
168 test_pass( __FILE__ );
169
170 return 0;
171}
static const char * event_names[2]
Definition: Gamum.c:27
int i
add PAPI preset or native hardware event to an event set
Empty and destroy an EventSet.
Create a new empty PAPI EventSet.
Empty and destroy an EventSet.
Enumerate PAPI preset or native events for a given component.
Convert a numeric hardware event code to a name.
get information about a specific software component
initialize the PAPI library.
Get the number of components available on the system.
Read hardware counters from an event set.
Start counting hardware events in an event set.
Stop counting hardware events in an event set.
Write counter values into counters.
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
#define PAPI_ENUM_EVENTS
Definition: f90papi.h:224
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_ENUM_FIRST
Definition: f90papi.h:85
#define PAPI_NULL
Definition: f90papi.h:78
#define PAPI_MAX_STR_LEN
Definition: f90papi.h:77
static int EventSet
Definition: init_fini.c:8
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
static int num_events
int TESTS_QUIET
Definition: test_utils.c:18
#define PAPI_NATIVE_MASK
void PAPI_NORETURN test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:491
void PAPI_NORETURN test_pass(const char *filename)
Definition: test_utils.c:432
void PAPI_NORETURN test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:584
char name[PAPI_MAX_STR_LEN]
Definition: papi.h:627
char disabled_reason[PAPI_HUGE_STR_LEN]
Definition: papi.h:634
#define MAX_powercap_EVENTS
Tests basic functionality of powercap component.
int retval
Definition: zero_fork.c:53
Here is the call graph for this function: