|
Packit |
577717 |
libmsr_write_test
|
|
Packit |
577717 |
|
|
Packit |
577717 |
This test demonstrates the ability of PAPI to use libmsr to read and
|
|
Packit |
577717 |
write RAPL MSRs to gather energy information and apply power
|
|
Packit |
577717 |
constraints.
|
|
Packit |
577717 |
|
|
Packit |
577717 |
See the instructions in the libmsr directory to build the component.
|
|
Packit |
577717 |
|
|
Packit |
577717 |
It works by using PAPI to read RAPL information from libmsr and write
|
|
Packit |
577717 |
it to a file. The code repeatedly runs an OpenMP multithreaded
|
|
Packit |
577717 |
routine (primes) to stress the CPU. The routine is called 100 times,
|
|
Packit |
577717 |
and at each call the power measurements are read using
|
|
Packit |
577717 |
PAPI_read(EventSet, values) and printed to a file. At every 10th call
|
|
Packit |
577717 |
the power caps for the power packages are adjusted using
|
|
Packit |
577717 |
PAPI_write(EventSet, values ).
|
|
Packit |
577717 |
|
|
Packit |
577717 |
Build and run the test as follows
|
|
Packit |
577717 |
cd components/libmsr/utils/
|
|
Packit |
577717 |
make clean && make
|
|
Packit |
577717 |
./libmsr_write_test
|
|
Packit |
577717 |
Generate a figure from the output file (libmsr_write_test_output.txt) using gnuplot.
|
|
Packit |
577717 |
sh ./libmsr_write_test.sh
|
|
Packit |
577717 |
|
|
Packit |
577717 |
In the output file, you can see the power values that are SET and the
|
|
Packit |
577717 |
power values that are READ. By comparing them you can confirm that
|
|
Packit |
577717 |
the component is performing as expected.
|
|
Packit |
577717 |
|
|
Packit |
577717 |
Note: To set the power limit for PKG_POWER_LIMIT_{1,2}:PACKAGE_{NN}
|
|
Packit |
577717 |
requires a value for PKG_TIME_WINDOW_POWER_LIMIT_{1,2}:PACKAGE_{NN}.
|
|
Packit |
577717 |
This is because the power caps need to be set to average over some
|
|
Packit |
577717 |
given time window.
|
|
Packit |
577717 |
|
|
Packit |
577717 |
Note: For some CPUs, only setting/writing PKG_POWER_LIMIT_1 will have
|
|
Packit |
577717 |
effect. Setting PKG_POWER_LIMIT_2 will not have any effect.
|
|
Packit |
577717 |
|
|
Packit |
577717 |
Note: For some CPUs, the power constraint written for one package
|
|
Packit |
577717 |
applies to all packages/sockets. So the last power constraint written
|
|
Packit |
577717 |
will be the one that is used for all the packages.
|
|
Packit |
577717 |
|
|
Packit |
577717 |
The following is not executable code, but should give an idea of how
|
|
Packit |
577717 |
to use PAPI to write event values.
|
|
Packit |
577717 |
|
|
Packit |
577717 |
PAPI_create_eventset( &EventSet );
|
|
Packit |
577717 |
PAPI_add_named_event( EventSet, "libmsr:::PKG_WATTS:PACKAGE1" );
|
|
Packit |
577717 |
PAPI_add_named_event( EventSet, "libmsr:::PKG_POWER_LIMIT_1:PACKAGE1" );
|
|
Packit |
577717 |
PAPI_add_named_event( EventSet, "libmsr:::PKG_TIME_WINDOW_POWER_LIMIT_1:PACKAGE1" );
|
|
Packit |
577717 |
|
|
Packit |
577717 |
PAPI_start( EventSet );
|
|
Packit |
577717 |
PAPI_read( EventSet, values );
|
|
Packit |
577717 |
|
|
Packit |
577717 |
// Note: the libmsr RAPL values are double precision and PAPI expects long long integers.
|
|
Packit |
577717 |
// You can use a union to handle the type conversion
|
|
Packit |
577717 |
// union { long long ll; double dbl; } tmp_ll_dbl;
|
|
Packit |
577717 |
|
|
Packit |
577717 |
values[0]=PAPI_NULL; // PKG_WATTS is not writable; value is ignored; or use PAPI_NULL
|
|
Packit |
577717 |
tmp_ll_dbl.dbl = 45.0 // use a union to transfer data between PAPI and libmsr
|
|
Packit |
577717 |
values[1]=tmp_ll_dbl.ll; // PKG_POWER_LIMIT_1 average Watts to be written
|
|
Packit |
577717 |
values[2]=put_double_in_long_long_storage(1.0); // PKG_TIME_WINDOW_POWER_LIMIT_1 averaged over 1 second
|
|
Packit |
577717 |
PAPI_write( EventSet, values );
|
|
Packit |
577717 |
|
|
Packit |
577717 |
PAPI_read( EventSet, values);
|
|
Packit |
577717 |
// print some output remembering to convert between PAPI long long ints and the double values
|
|
Packit |
577717 |
printf( "Power %lf\n", get_double_from_long_long_storage(values[0]);
|
|
Packit |
577717 |
|
|
Packit |
577717 |
retval = PAPI_stop( EventSet, values);
|