From 6ff2876a49a3fcc6d74770b8a2230dd936929c8b Mon Sep 17 00:00:00 2001
From: Georges Da Costa <dacosta@irit.fr>
Date: Wed, 17 Mar 2021 21:44:45 +0100
Subject: [PATCH] Changes the type for performance counters to uint64

---
 counters.h            |  2 +-
 counters_individual.c | 13 ++++++++-----
 makefile              |  2 +-
 mojitos.c             | 22 ++++++++++++++--------
 4 files changed, 24 insertions(+), 15 deletions(-)

diff --git a/counters.h b/counters.h
index d919c95..1592612 100644
--- a/counters.h
+++ b/counters.h
@@ -26,4 +26,4 @@ counter_t init_counters(const int nb_perf, const __u32 *types, const __u64 *name
 void clean_counters(counter_t fd);
 void start_counters(counter_t fd);
 void reset_counters(counter_t fd);
-void get_counters(counter_t fd, long long *values);
+void get_counters(counter_t fd, uint64_t *values);
diff --git a/counters_individual.c b/counters_individual.c
index f964870..2d20e91 100644
--- a/counters_individual.c
+++ b/counters_individual.c
@@ -26,6 +26,7 @@
 #include <stdio.h>
 #include <stdint.h>
 #include <asm/unistd.h>
+#include <stdint.h>
 
 #include "counters.h"
 
@@ -91,19 +92,21 @@ void reset_counters(counter_t counters) {
       ioctl(counters->counters[counter][core], PERF_EVENT_IOC_RESET, 0);
 }
 
-void get_counters(counter_t counters, long long *values) {
+void get_counters(counter_t counters, uint64_t *values) {
   //memset(values, 0, nb_perf*sizeof(long long));
   for(int i=0; i<counters->nbperf; i++) {
-    long long accu=0;
-    long long count;
+    uint64_t accu=0;
+    uint64_t count=0;
     for (int core=0; core<counters->nbcores; core++) {
-      if (-1 == read(counters->counters[i][core], &count, sizeof(long long))) {
+      if (-1 == read(counters->counters[i][core], &count, sizeof(uint64_t))) {
 	fprintf(stderr, "PB Lecture resultat");
 	exit(EXIT_FAILURE);
       }
       accu += count;
     }
+    printf("%lu! \n", accu);
+
     values[i] = accu;
   }
-  reset_counters(counters);
+  //reset_counters(counters);
 }
diff --git a/makefile b/makefile
index 759677e..23c02dc 100644
--- a/makefile
+++ b/makefile
@@ -1,6 +1,6 @@
 all: mojitos
 
-OBJECTS = mojitos.o counters_individual.o counters.h rapl.o network.o load.o infiniband.o
+OBJECTS = mojitos.o counters_individual.o rapl.o network.o load.o infiniband.o
 
 mojitos:$(OBJECTS) counters_option.h
 	gcc $(DEBUG) -O3 -Wall -o mojitos $(OBJECTS) -lpowercap
diff --git a/mojitos.c b/mojitos.c
index fe26e93..23908c5 100644
--- a/mojitos.c
+++ b/mojitos.c
@@ -221,9 +221,9 @@ int main(int argc, char **argv) {
     // prepare rapl data stores
     rapl_size = rapl->nb * sizeof(uint64_t);
     //rapl_values = malloc(rapl_size);
-    rapl_values = calloc(sizeof(char), rapl_size);
+    rapl_values = calloc(sizeof(uint64_t), rapl_size);
     //tmp_rapl_values = malloc(rapl_size);
-    tmp_rapl_values = calloc(sizeof(char), rapl_size);
+    tmp_rapl_values = calloc(sizeof(uint64_t), rapl_size);
     // initialize with dummy values
     get_rapl(rapl_values, rapl);
   }
@@ -231,13 +231,16 @@ int main(int argc, char **argv) {
   __u32* perf_type;
   __u64* perf_key;
   counter_t fd=0;
-  long long *counter_values=NULL;
+  uint64_t *counter_values=NULL;
+  uint64_t *tmp_counter_values=NULL;
   if(perf_mode==0) {
     perf_type_key(&perf_type, &perf_key, perf_indexes, nb_perf);
     fd = init_counters(nb_perf, perf_type, perf_key);
-    reset_counters(fd);
-    // reading HPC will reset their values so no need for a buffer
-    counter_values = malloc(nb_perf*sizeof(long long));
+
+    counter_values = malloc(nb_perf*sizeof(uint64_t));
+    tmp_counter_values = malloc(nb_perf*sizeof(uint64_t));
+
+    get_counters(fd, counter_values);
   }
   struct timespec ts;
   struct timespec ts_ref;
@@ -272,7 +275,7 @@ int main(int argc, char **argv) {
 
     // Get Data
     if(perf_mode==0)
-      get_counters(fd, counter_values);
+      get_counters(fd, tmp_counter_values);
     if(dev != NULL)
       get_network(tmp_network_values, network_sources);
     if(infi_path != NULL)
@@ -316,7 +319,7 @@ int main(int argc, char **argv) {
     }
     if(perf_mode==0)
       for(int i=0; i<nb_perf;i++) 
-	fprintf(output, "%lld ", counter_values[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]);
@@ -337,6 +340,8 @@ int main(int argc, char **argv) {
 
     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, rapl_size);
     if(load_mode==0)
@@ -363,6 +368,7 @@ int main(int argc, char **argv) {
   if(perf_mode==0){
     clean_counters(fd);
     free(counter_values);
+    free(tmp_counter_values);
     free(perf_type);
     free(perf_key);
     free(perf_indexes);
-- 
GitLab