diff --git a/counters_individual.c b/counters_individual.c index 2d20e915386433c6feeaa39816e39044461a6291..fac60290570139d5439b07b7cad9c31eac6bdf28 100644 --- a/counters_individual.c +++ b/counters_individual.c @@ -104,8 +104,6 @@ void get_counters(counter_t counters, uint64_t *values) { } accu += count; } - printf("%lu! \n", accu); - values[i] = accu; } //reset_counters(counters); diff --git a/infiniband.h b/infiniband.h index 919f3fd6a4548a584d1941d742955e4d1a51b250..be3c3332a7d8a44e85d634732013e41977059ab9 100644 --- a/infiniband.h +++ b/infiniband.h @@ -18,5 +18,4 @@ *******************************************************/ - -int *init_infiniband(char* infi_path); +unsigned int init_infiniband(char* infi_path, void**ptr); diff --git a/load.c b/load.c index 8fd418da0fd86b72b045bdbc1781ad5b6a2ec8d6..10c90d0b09cd0f4465176608573863dd25639cfe 100644 --- a/load.c +++ b/load.c @@ -64,7 +64,7 @@ void clean_load(void *state) { char *_labels[10] = {"user","nice","system","idle","iowait","irq", "softirq","steal","guest","guest_nice"}; -void label_load(char **labels) { +void label_load(char **labels, void*none) { for(int i=0; i<10; i++) labels[i] = _labels[i]; } diff --git a/load.h b/load.h index 363e07ad8adb5606a71f44a7f48fd733e518c68b..42ce968062dcb68a13ebf67713eabc865abe1d7a 100644 --- a/load.h +++ b/load.h @@ -21,4 +21,4 @@ unsigned int init_load(char*, void **); unsigned int get_load(uint64_t* results, void*); void clean_load(void *); -void label_load(char **labels); +void label_load(char **labels, void*); diff --git a/mojitos.c b/mojitos.c index 2b511f323f00666427824017930c0a4110c22921..a10cd47c009e2a4c7166b3ee7100dc37f3ddd44f 100644 --- a/mojitos.c +++ b/mojitos.c @@ -28,6 +28,7 @@ #include <getopt.h> #include <signal.h> #include <inttypes.h> +#include <unistd.h> #include "counters.h" #include "rapl.h" @@ -112,7 +113,7 @@ void flushexit() { } typedef unsigned int (initializer_t)(char*, void **); -typedef void (labeler_t)(char **); +typedef void (labeler_t)(char **, void*); typedef unsigned int (*getter_t)(uint64_t*, void*); typedef void (*cleaner_t)(void*); @@ -136,7 +137,7 @@ void add_source(initializer_t init, char* arg, labeler_t labeler, int nb = init(arg, &states[nb_sources-1]); labels = realloc(labels, (nb_sensors+nb)*sizeof(char*)); - labeler(labels+nb_sensors); + labeler(labels+nb_sensors, states[nb_sources-1]); values = realloc(values, (nb_sensors+nb)*sizeof(uint64_t)); nb_sensors += nb; @@ -148,7 +149,6 @@ int main(int argc, char **argv) { int frequency=1; char **application = NULL; - int rapl_mode = -1; int perf_mode = -1; int stat_mode = -1; @@ -192,7 +192,7 @@ int main(int argc, char **argv) { perf_mode=0; break; case 'r': - rapl_mode=0; + add_source(init_rapl, NULL, label_rapl, get_rapl, clean_rapl); break; case 'u': add_source(init_load, NULL, label_load, get_load, clean_load); @@ -207,40 +207,6 @@ int main(int argc, char **argv) { usage(argv); } - - /* // Network initialization */ - /* int *network_sources = NULL; */ - /* if(dev != NULL) */ - /* network_sources = init_network(dev); */ - /* uint64_t network_values[4]={0,0,0,0}; */ - /* uint64_t tmp_network_values[4]={0,0,0,0}; */ - /* get_network(network_values, network_sources); */ - - /* int * infiniband_sources = NULL; */ - /* if(infi_path != NULL) */ - /* infiniband_sources = init_infiniband(infi_path); */ - /* if(infiniband_sources == NULL) */ - /* infi_path = NULL; */ - /* uint64_t infiniband_values[4]={0,0,0,0}; */ - /* uint64_t tmp_infiniband_values[4]={0,0,0,0}; */ - /* get_network(infiniband_values, infiniband_sources); */ - - // RAPL initialization - _rapl_t* rapl=NULL; - int nb_rapl = 0; - uint64_t * rapl_values=NULL; - uint64_t * tmp_rapl_values=NULL; - if(rapl_mode==0) { - - rapl = init_rapl(); - // prepare rapl data stores - nb_rapl = rapl->nb; - rapl_values = calloc(sizeof(uint64_t), nb_rapl); - tmp_rapl_values = calloc(sizeof(uint64_t), nb_rapl); - - // initialize with dummy values - get_rapl(rapl_values, rapl); - } // Hardware Performance Counters initialization __u32* perf_type; __u64* perf_key; @@ -263,27 +229,15 @@ int main(int argc, char **argv) { if(perf_mode==0) for(int i=0; i<nb_perf;i++) fprintf(output, "%s ", perf_static_info[perf_indexes[i]].name); - /* if(dev!=NULL) */ - /* fprintf(output, "rxp rxb txp txb "); */ - /* if(infi_path!=NULL) */ - /* fprintf(output, "irxp irxb itxp itxb "); */ - if(rapl_mode==0) - for (int r=0; r<nb_rapl; r++) - fprintf(output, "%s ", rapl->names[r]); + for(int i=0; i<nb_sensors; i++) + fprintf(output, "%s ", labels[i]); if(stat_mode==0) fprintf(output, "overhead "); - for(int i=0; i<nb_sensors; i++) - fprintf(output, "%s ", labels[i]); - fprintf(output, "\n"); - - - - unsigned long int stat_data=0; if(perf_mode==0) start_counters(fd); @@ -294,14 +248,6 @@ int main(int argc, char **argv) { // Get Data if(perf_mode==0) get_counters(fd, tmp_counter_values); - // if(dev != NULL) - // get_network(tmp_network_values, network_sources); - //if(infi_path != NULL) - // get_network(tmp_infiniband_values, infiniband_sources); - - if(rapl_mode==0) - get_rapl(tmp_rapl_values, rapl); - unsigned int current = 0; for(int i=0; i<nb_sources; i++) @@ -341,52 +287,27 @@ int main(int argc, char **argv) { if(perf_mode==0) for(int i=0; i<nb_perf;i++) fprintf(output, "%" PRIu64 " ", tmp_counter_values[i]-counter_values[i]); - /* if(dev != NULL) */ - /* for(int i=0; i<4; i++) */ - /* fprintf(output, "%" PRIu64 " ", tmp_network_values[i]-network_values[i]); */ - /* if(infi_path != NULL) */ - /* for(int i=0; i<4; i++) */ - /* fprintf(output, "%" PRIu64 " ", tmp_infiniband_values[i]-infiniband_values[i]); */ - if(rapl_mode==0) - for (int r=0; r<nb_rapl; r++) - fprintf(output, "%" PRIu64 " ", tmp_rapl_values[r]-rapl_values[r]); + for(int i=0; i<nb_sensors; i++) + fprintf(output, "%" PRIu64 " ", values[i]); + if(stat_mode==0) fprintf(output, "%ld ", stat_data); - for(int i=0; i<nb_sensors; i++) - fprintf(output, "%" PRIu64 " ", values[i]); - - fprintf(output, "\n"); if(application != NULL) break; if(perf_mode==0) memcpy(counter_values, tmp_counter_values, nb_perf*sizeof(uint64_t)); - if(rapl_mode==0) - memcpy(rapl_values, tmp_rapl_values, nb_rapl*sizeof(uint64_t)); - /* if(dev !=NULL) */ - /* memcpy(network_values, tmp_network_values, sizeof(network_values)); */ - /* if(infi_path !=NULL) */ - /* memcpy(infiniband_values, tmp_infiniband_values, sizeof(infiniband_values)); */ clock_gettime(CLOCK_MONOTONIC, &ts); usleep(1000*1000/frequency-(ts.tv_nsec/1000)%(1000*1000/frequency)); } - if(rapl_mode==0){ - clean_rapl(rapl); - free(rapl_values); - free(tmp_rapl_values); - } for(int i=0; i<nb_sources;i++) cleaner[i](states[i]); - /* if(dev!=NULL) */ - /* clean_network(network_sources); */ - /* if(infi_path!=NULL) */ - /* clean_network(infiniband_sources); */ if(perf_mode==0){ clean_counters(fd); free(counter_values); diff --git a/network.c b/network.c index f197b9770ccc0e5aa808c80273d7298fb2781429..6e3f494bd49b86c68e452efd202873821b9c6832 100644 --- a/network.c +++ b/network.c @@ -97,7 +97,7 @@ void clean_network(void *ptr) { } char *_labels_network[4] = {"rxp", "rxb", "txp", "txb"}; -void label_network(char **labels) { +void label_network(char **labels, void*none) { for(int i=0; i<4; i++) labels[i] = _labels_network[i]; } diff --git a/network.h b/network.h index df25df89448421eb8fabc73607c6778b49b77cbb..44759dcf883ac66c90aafdf6447d00d6b02e9a39 100644 --- a/network.h +++ b/network.h @@ -21,5 +21,5 @@ unsigned int init_network(char*, void **); unsigned int get_network(uint64_t* results, void*); void clean_network(void *); -void label_network(char **labels); +void label_network(char **labels, void*); diff --git a/rapl.c b/rapl.c index 0eae3c45b8c745c3c1c1272e0dedba6d7c32a30c..6c05e16cb048867641129d74102f161326786e82 100644 --- a/rapl.c +++ b/rapl.c @@ -22,15 +22,50 @@ #include <stdlib.h> #include <string.h> -#include "rapl.h" +#include <powercap/powercap-rapl.h> + +struct _rapl_t { + powercap_rapl_pkg* pkgs; + uint32_t nb_pkgs; + uint32_t nb; + char **names; + uint32_t* zones; + uint32_t* packages; + uint64_t* values; + uint64_t* tmp_values; +}; + +typedef struct _rapl_t _rapl_t; + + + + + const int nb_zones = 3; const int rapl_zones[3] = { POWERCAP_RAPL_ZONE_PACKAGE, POWERCAP_RAPL_ZONE_CORE, POWERCAP_RAPL_ZONE_DRAM}; + #define MAX_LEN_NAME 100 -_rapl_t* init_rapl() { + +// values [zone + package *nbzones] microjoules +void _get_rapl(uint64_t *values, _rapl_t* rapl) { + for (int i = 0; i < rapl->nb; i++) { +#ifdef DEBUG + int ret = +#endif + powercap_rapl_get_energy_uj(&rapl->pkgs[rapl->packages[i]], + rapl->zones[i], + &values[i]); +#ifdef DEBUG + printf("GETRAPL: package %d, zone %d, name %s, ret: %d\n", rapl->packages[i], rapl->zones[i], rapl->names[i], ret); +#endif + } +} + +unsigned int init_rapl(char* none, void **ptr) { // get number of processor sockets - _rapl_t* rapl = malloc(sizeof(struct _rapl_t)); + _rapl_t* rapl= malloc(sizeof(struct _rapl_t)); rapl->nb = 0; rapl->packages = NULL; rapl->zones = NULL; @@ -80,27 +115,33 @@ _rapl_t* init_rapl() { for(int i=0; i<rapl->nb; i++) printf("package %d, zone %d, name %s\n", rapl->packages[i], rapl->zones[i], rapl->names[i]); #endif - return rapl; + + rapl->values = calloc(sizeof(uint64_t), rapl->nb); + rapl->tmp_values = calloc(sizeof(uint64_t), rapl->nb); + + _get_rapl(rapl->values, rapl); + + *ptr = (void*)rapl; + return rapl->nb; } -// values [zone + package *nbzones] microjoules -void get_rapl(uint64_t *values, _rapl_t* rapl) { - for (int i = 0; i < rapl->nb; i++) { -#ifdef DEBUG - int ret = -#endif - powercap_rapl_get_energy_uj(&rapl->pkgs[rapl->packages[i]], - rapl->zones[i], - &values[i]); -#ifdef DEBUG - printf("GETRAPL: package %d, zone %d, name %s, ret: %d\n", rapl->packages[i], rapl->zones[i], rapl->names[i], ret); -#endif - } +unsigned int get_rapl(uint64_t* results, void* ptr) { + _rapl_t* state = (_rapl_t*) ptr; + _get_rapl(state->tmp_values, state); + for(int i=0; i<state->nb; i++) + results[i] = state->tmp_values[i] - state->values[i]; + + memcpy(state->values, state->tmp_values, sizeof(uint64_t)*state->nb); + return state->nb; } -void clean_rapl(_rapl_t* rapl) { + + + +void clean_rapl(void* ptr) { + _rapl_t* rapl = (_rapl_t*) ptr; for (int package = 0; package < rapl->nb_pkgs; package++) if (powercap_rapl_destroy(&rapl->pkgs[package])) perror("powercap_rapl_destroy"); @@ -111,5 +152,13 @@ void clean_rapl(_rapl_t* rapl) { free(rapl->pkgs); free(rapl->zones); free(rapl->packages); + free(rapl->values); + free(rapl->tmp_values); free(rapl); } + +void label_rapl(char **labels, void *ptr) { + _rapl_t* rapl = (_rapl_t*) ptr; + for(int i=0; i<rapl->nb; i++) + labels[i] = rapl->names[i]; +} diff --git a/rapl.h b/rapl.h index 5b03dbb35225367b39751d5ceb9e70a78b7e72f8..9ec5f3afdc88d5f1bcdd4dcb5fdb4208261e2db0 100644 --- a/rapl.h +++ b/rapl.h @@ -18,21 +18,8 @@ *******************************************************/ -#include <powercap/powercap-rapl.h> +unsigned int init_rapl(char*, void **); +unsigned int get_rapl(uint64_t* results, void*); +void clean_rapl(void *); +void label_rapl(char **labels, void*); -struct _rapl_t { - powercap_rapl_pkg* pkgs; - uint32_t nb_pkgs; - - uint32_t nb; - - char **names; - uint32_t* zones; - uint32_t* packages; -}; - -typedef struct _rapl_t _rapl_t; - -_rapl_t* init_rapl(); -void get_rapl(uint64_t *values, _rapl_t* rapl); -void clean_rapl(_rapl_t* rapl);