Skip to content
Snippets Groups Projects
Commit 598d2f8e authored by ghuter's avatar ghuter
Browse files

msc changes (mostly reformating)

parent ae671211
Branches
Tags
4 merge requests!9fix sensor example (doc),!4Amd, Tests, Doc, CI/CD,!2build system (v0), add long options,!1build system (v0), add long options, corrections
...@@ -44,8 +44,10 @@ typedef struct _counter_t *counter_t; ...@@ -44,8 +44,10 @@ typedef struct _counter_t *counter_t;
void show_all_counters() void show_all_counters()
{ {
for(unsigned int i=0; i<nb_counter_option; i++) for (unsigned int i = 0; i < nb_counter_option; i++)
printf("%s\n", perf_static_info[i].name); {
printf("%s\n", perf_static_info[i].name);
}
} }
void perf_type_key(__u32 **perf_type, __u64 **perf_key, int *indexes, int nb) void perf_type_key(__u32 **perf_type, __u64 **perf_key, int *indexes, int nb)
...@@ -134,16 +136,20 @@ void clean_counters(void *ptr) ...@@ -134,16 +136,20 @@ void clean_counters(void *ptr)
void start_counters(counter_t counters) void start_counters(counter_t counters)
{ {
for(int counter=0; counter<counters->nbperf; counter++) for (int counter = 0; counter < counters->nbperf; counter++)
for(int core=0; core<counters->nbcores; core++) for (int core = 0; core < counters->nbcores; core++)
ioctl(counters->counters[counter][core], PERF_EVENT_IOC_ENABLE, 0); {
ioctl(counters->counters[counter][core], PERF_EVENT_IOC_ENABLE, 0);
}
} }
void reset_counters(counter_t counters) void reset_counters(counter_t counters)
{ {
for(int counter=0; counter<counters->nbperf; counter++) for (int counter = 0; counter < counters->nbperf; counter++)
for(int core=0; core<counters->nbcores; core++) for (int core = 0; core < counters->nbcores; core++)
ioctl(counters->counters[counter][core], PERF_EVENT_IOC_RESET, 0); {
ioctl(counters->counters[counter][core], PERF_EVENT_IOC_RESET, 0);
}
} }
void _get_counters(counter_t counters, uint64_t *values) void _get_counters(counter_t counters, uint64_t *values)
...@@ -170,7 +176,7 @@ void _get_counters(counter_t counters, uint64_t *values) ...@@ -170,7 +176,7 @@ void _get_counters(counter_t counters, uint64_t *values)
unsigned int init_counters(char *args, void **state) unsigned int init_counters(char *args, void **state)
{ {
int nb_perf; int nb_perf;
int *perf_indexes=NULL; int *perf_indexes = NULL;
perf_event_list(args, &nb_perf, &perf_indexes); perf_event_list(args, &nb_perf, &perf_indexes);
...@@ -182,8 +188,8 @@ unsigned int init_counters(char *args, void **state) ...@@ -182,8 +188,8 @@ unsigned int init_counters(char *args, void **state)
free(perf_key); free(perf_key);
fd->perf_indexes = perf_indexes; fd->perf_indexes = perf_indexes;
fd->counters_values = malloc(nb_perf*sizeof(uint64_t)); fd->counters_values = malloc(nb_perf * sizeof(uint64_t));
fd->tmp_counters_values = malloc(nb_perf*sizeof(uint64_t)); fd->tmp_counters_values = malloc(nb_perf * sizeof(uint64_t));
start_counters(fd); start_counters(fd);
_get_counters(fd, fd->counters_values); _get_counters(fd, fd->counters_values);
*state = (void *) fd; *state = (void *) fd;
...@@ -196,8 +202,10 @@ unsigned int get_counters(uint64_t *results, void *ptr) ...@@ -196,8 +202,10 @@ unsigned int get_counters(uint64_t *results, void *ptr)
counter_t state = (counter_t) ptr; counter_t state = (counter_t) ptr;
_get_counters(state, state->tmp_counters_values); _get_counters(state, state->tmp_counters_values);
for(int i=0; i<state->nbperf; i++) for (int i = 0; i < state->nbperf; i++)
results[i] = state->tmp_counters_values[i] - state->counters_values[i]; {
results[i] = state->tmp_counters_values[i] - state->counters_values[i];
}
memcpy(state->counters_values, state->tmp_counters_values, state->nbperf * sizeof(uint64_t)); memcpy(state->counters_values, state->tmp_counters_values, state->nbperf * sizeof(uint64_t));
return state->nbperf; return state->nbperf;
...@@ -206,7 +214,9 @@ unsigned int get_counters(uint64_t *results, void *ptr) ...@@ -206,7 +214,9 @@ unsigned int get_counters(uint64_t *results, void *ptr)
void label_counters(char **labels, void *ptr) void label_counters(char **labels, void *ptr)
{ {
counter_t state = (counter_t) ptr; counter_t state = (counter_t) ptr;
for(int i=0; i<state->nbperf; i++) for (int i = 0; i < state->nbperf; i++)
labels[i] = perf_static_info[state->perf_indexes[i]].name; {
labels[i] = perf_static_info[state->perf_indexes[i]].name;
}
} }
/*******************************************************
Copyright (C) 2018-2021 Georges Da Costa <georges.da-costa@irit.fr>
This file is part of Mojitos.
Mojitos is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Mojitos is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with MojitO/S. If not, see <https://www.gnu.org/licenses/>.
*******************************************************/
#include <linux/perf_event.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/ioctl.h>
#include <stdio.h>
#include <stdint.h>
#include <asm/unistd.h>
#include "counters.h"
struct _counter_t
{
int nbcores;
int nbperf;
int *counters;
};
static long perf_event_open(struct perf_event_attr *hw_event, pid_t pid,
int cpu, int group_fd, unsigned long flags)
{
long res = syscall(__NR_perf_event_open, hw_event, pid, cpu, group_fd, flags);
if (res == -1)
{
perror("perf_event_open");
fprintf(stderr, "Error opening leader %llx\n", hw_event->config);
exit(EXIT_FAILURE);
}
return res;
}
counter_t init_counters(const int nb_perf, const __u32 *types, const __u64 *names)
{
struct perf_event_attr pe;
struct _counter_t *counters = malloc(sizeof(struct _counter_t));
unsigned int nbcores = sysconf(_SC_NPROCESSORS_ONLN);
counters->nbcores = nbcores;
counters->nbperf = nb_perf;
memset(&pe, 0, sizeof(struct perf_event_attr));
pe.size = sizeof(struct perf_event_attr);
pe.disabled = 1;
pe.read_format = PERF_FORMAT_GROUP;
counters->counters = malloc((nbcores + 1) * sizeof(int));
for (int core = 0; core < nbcores; core++)
{
counters->counters[core] = -1;
for (int idperf = 0; idperf < nb_perf; idperf ++)
{
pe.type = types[idperf];
pe.config = names[idperf];
int res = perf_event_open(&pe, -1, core, counters->counters[core], PERF_FLAG_FD_CLOEXEC);
if (counters->counters[core] == -1)
{
counters->counters[core] = res;
}
}
}
return counters;
}
void clean_counters(counter_t counters)
{
for (int core = 0; core < counters->nbcores; core++)
{
close(counters->counters[core]);
}
free(counters->counters);
free(counters);
}
void start_counters(counter_t counters)
{
for (int core = 0; core < counters->nbcores; core++)
{
ioctl(counters->counters[core], PERF_EVENT_IOC_ENABLE, PERF_IOC_FLAG_GROUP);
}
}
void reset_counters(counter_t counters)
{
for (int core = 0; core < counters->nbcores; core++)
{
ioctl(counters->counters[core], PERF_EVENT_IOC_RESET, PERF_IOC_FLAG_GROUP);
}
}
struct read_format
{
uint64_t nr;
struct
{
uint64_t value;
} values[];
};
void get_counters(counter_t counters, long long *values)
{
int nb_perf = counters->nbperf;
size_t buffer_size = sizeof(uint64_t) * (1 + nb_perf);
struct read_format *buffer = NULL;
if (buffer == NULL)
{
buffer = malloc(buffer_size);
}
memset(values, 0, nb_perf * sizeof(long long));
for (int core = 0; core < counters->nbcores; core++)
{
if (-1 == read(counters->counters[core], buffer, buffer_size))
{
perror("PB Lecture resultat");
exit(EXIT_FAILURE);
}
for (int idperf = 0; idperf <= nb_perf; idperf++)
{
values[idperf] += buffer->values[idperf].value;
}
}
reset_counters(counters);
}
...@@ -40,7 +40,7 @@ char *get_frapl_string(const char *filename) ...@@ -40,7 +40,7 @@ char *get_frapl_string(const char *filename)
char *result = malloc(MAX_HEADER); char *result = malloc(MAX_HEADER);
int nb = read(fd, result, MAX_HEADER); int nb = read(fd, result, MAX_HEADER);
close(fd); close(fd);
result[nb-1] = 0; result[nb - 1] = 0;
return (result); return (result);
} }
...@@ -49,7 +49,7 @@ void test_append(char *name, int i) ...@@ -49,7 +49,7 @@ void test_append(char *name, int i)
//char last = name[strlen(name)-1]; //char last = name[strlen(name)-1];
//if (last>='0' && last <= '9') //if (last>='0' && last <= '9')
// return; // return;
sprintf(name+strlen(name), "%d", i); sprintf(name + strlen(name), "%d", i);
} }
...@@ -70,8 +70,8 @@ void add_frapl_source(_frapl_t *rapl, char *name, char *energy_uj) ...@@ -70,8 +70,8 @@ void add_frapl_source(_frapl_t *rapl, char *name, char *energy_uj)
rapl->names = realloc(rapl->names, sizeof(char **)*rapl->nb); rapl->names = realloc(rapl->names, sizeof(char **)*rapl->nb);
rapl->fids = realloc(rapl->fids, sizeof(int *)*rapl->nb); rapl->fids = realloc(rapl->fids, sizeof(int *)*rapl->nb);
rapl->names[rapl->nb-1] = malloc(strlen(name)+1); rapl->names[rapl->nb - 1] = malloc(strlen(name) + 1);
strcpy(rapl->names[rapl->nb-1], name); strcpy(rapl->names[rapl->nb - 1], name);
//printf("%s\n", energy_uj); //printf("%s\n", energy_uj);
int fd = open(energy_uj, O_RDONLY); int fd = open(energy_uj, O_RDONLY);
...@@ -154,8 +154,10 @@ unsigned int get_frapl(uint64_t *results, void *ptr) ...@@ -154,8 +154,10 @@ unsigned int get_frapl(uint64_t *results, void *ptr)
{ {
_frapl_t *state = (_frapl_t *) ptr; _frapl_t *state = (_frapl_t *) ptr;
_get_frapl(state->tmp_values, state); _get_frapl(state->tmp_values, state);
for(unsigned int i=0; i<state->nb; i++) for (unsigned int i = 0; i < state->nb; i++)
results[i] = state->tmp_values[i] - state->values[i]; {
results[i] = state->tmp_values[i] - state->values[i];
}
memcpy(state->values, state->tmp_values, sizeof(uint64_t)*state->nb); memcpy(state->values, state->tmp_values, sizeof(uint64_t)*state->nb);
return state->nb; return state->nb;
......
...@@ -39,8 +39,10 @@ unsigned int _get_network(uint64_t *results, int *sources); ...@@ -39,8 +39,10 @@ unsigned int _get_network(uint64_t *results, int *sources);
unsigned int init_infiniband(char *infi_path, void **ptr) unsigned int init_infiniband(char *infi_path, void **ptr)
{ {
if(infi_path==NULL) if (infi_path == NULL)
return 0; {
return 0;
}
if(strcmp(infi_path,"X")==0) { if(strcmp(infi_path,"X")==0) {
......
...@@ -28,9 +28,9 @@ ...@@ -28,9 +28,9 @@
#define UNUSED(expr) do { (void)(expr); } while (0) #define UNUSED(expr) do { (void)(expr); } while (0)
char buffer[LOAD_BUFFER_SIZE]; char buffer[LOAD_BUFFER_SIZE];
static int load_fid=-1; static int load_fid = -1;
static uint64_t load_values[10]= {0,0,0,0,0,0,0,0,0,0}; static uint64_t load_values[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
static uint64_t tmp_load_values[10]= {0,0,0,0,0,0,0,0,0,0}; static uint64_t tmp_load_values[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
static char *stat = "/proc/stat"; static char *stat = "/proc/stat";
void _get_load(uint64_t *results) void _get_load(uint64_t *results)
...@@ -68,8 +68,10 @@ unsigned int get_load(uint64_t *results, void *state) ...@@ -68,8 +68,10 @@ unsigned int get_load(uint64_t *results, void *state)
{ {
UNUSED(state); UNUSED(state);
_get_load(tmp_load_values); _get_load(tmp_load_values);
for(int i=0; i<10; i++) for (int i = 0; i < 10; i++)
results[i] = tmp_load_values[i] - load_values[i]; {
results[i] = tmp_load_values[i] - load_values[i];
}
memcpy(load_values, tmp_load_values, sizeof(load_values)); memcpy(load_values, tmp_load_values, sizeof(load_values));
return 10; return 10;
...@@ -81,8 +83,8 @@ void clean_load(void *state) ...@@ -81,8 +83,8 @@ void clean_load(void *state)
close(load_fid); close(load_fid);
} }
char *_labels[10] = {"user","nice","system","idle","iowait","irq", char *_labels[10] = {"user", "nice", "system", "idle", "iowait", "irq",
"softirq","steal","guest","guest_nice" "softirq", "steal", "guest", "guest_nice"
}; };
void label_load(char **labels, void *none) void label_load(char **labels, void *none)
{ {
......
...@@ -19,19 +19,19 @@ ...@@ -19,19 +19,19 @@
*******************************************************/ *******************************************************/
#include <stdlib.h> #include <inttypes.h>
#include <signal.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <time.h> #include <time.h>
#include <signal.h>
#include <inttypes.h>
#include <unistd.h> #include <unistd.h>
#include "counters.h" #include "counters.h"
#include "rapl.h"
#include "frapl.h" #include "frapl.h"
#include "network.h"
#include "infiniband.h" #include "infiniband.h"
#include "load.h" #include "load.h"
#include "network.h"
#include "rapl.h"
#include "temperature.h" #include "temperature.h"
#define UNUSED(expr) do { (void)(expr); } while (0) #define UNUSED(expr) do { (void)(expr); } while (0)
......
...@@ -36,8 +36,10 @@ struct network_t { ...@@ -36,8 +36,10 @@ struct network_t {
unsigned int _get_network(uint64_t *results, int *sources) unsigned int _get_network(uint64_t *results, int *sources)
{ {
if(sources==NULL) if (sources == NULL)
return 0; {
return 0;
}
char buffer[128]; char buffer[128];
for(int i=0; i<NB_SENSOR; i++) { for(int i=0; i<NB_SENSOR; i++) {
if (pread(sources[i], buffer, 127, 0) < 0) { if (pread(sources[i], buffer, 127, 0) < 0) {
...@@ -54,8 +56,10 @@ unsigned int _get_network(uint64_t *results, int *sources) ...@@ -54,8 +56,10 @@ unsigned int _get_network(uint64_t *results, int *sources)
unsigned int init_network(char *dev, void **ptr) unsigned int init_network(char *dev, void **ptr)
{ {
if(dev==NULL) if (dev == NULL)
return 0; {
return 0;
}
if(strcmp(dev,"X")==0) { if(strcmp(dev,"X")==0) {
int fd = open(route, O_RDONLY); int fd = open(route, O_RDONLY);
...@@ -102,20 +106,26 @@ unsigned int get_network(uint64_t *results, void *ptr) ...@@ -102,20 +106,26 @@ unsigned int get_network(uint64_t *results, void *ptr)
{ {
struct network_t *state = (struct network_t *) ptr; struct network_t *state = (struct network_t *) ptr;
_get_network(state->tmp_values, state->sources); _get_network(state->tmp_values, state->sources);
for(int i=0; i<NB_SENSOR; i++) for (int i = 0; i < NB_SENSOR; i++)
results[i] = state->tmp_values[i] - state->values[i]; {
results[i] = state->tmp_values[i] - state->values[i];
}
memcpy(state->values, state->tmp_values, NB_SENSOR*sizeof(uint64_t)); memcpy(state->values, state->tmp_values, NB_SENSOR * sizeof(uint64_t));
return NB_SENSOR; return NB_SENSOR;
} }
void clean_network(void *ptr) void clean_network(void *ptr)
{ {
struct network_t *state = (struct network_t *) ptr; struct network_t *state = (struct network_t *) ptr;
if(state==NULL) if (state == NULL)
return; {
for(int i=0; i<NB_SENSOR; i++) return;
close(state->sources[i]); }
for (int i = 0; i < NB_SENSOR; i++)
{
close(state->sources[i]);
}
free(state); free(state);
} }
......
...@@ -70,7 +70,7 @@ unsigned int init_rapl(char *none, void **ptr) ...@@ -70,7 +70,7 @@ unsigned int init_rapl(char *none, void **ptr)
{ {
UNUSED(none); UNUSED(none);
// get number of processor sockets // 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->nb = 0;
rapl->packages = NULL; rapl->packages = NULL;
rapl->zones = NULL; rapl->zones = NULL;
...@@ -91,8 +91,8 @@ unsigned int init_rapl(char *none, void **ptr) ...@@ -91,8 +91,8 @@ unsigned int init_rapl(char *none, void **ptr)
rapl->names = NULL; rapl->names = NULL;
char _name[MAX_LEN_NAME+1]; char _name[MAX_LEN_NAME + 1];
char _name2[MAX_LEN_NAME+11]; char _name2[MAX_LEN_NAME + 11];
for (unsigned int package = 0; package < rapl->nb_pkgs; package++) { for (unsigned int package = 0; package < rapl->nb_pkgs; package++) {
for(unsigned int zone=0; zone < nb_zones; zone++) { for(unsigned int zone=0; zone < nb_zones; zone++) {
...@@ -119,8 +119,10 @@ unsigned int init_rapl(char *none, void **ptr) ...@@ -119,8 +119,10 @@ unsigned int init_rapl(char *none, void **ptr)
} }
#ifdef DEBUG #ifdef DEBUG
printf("Result of init\n"); printf("Result of init\n");
for(unsigned int i=0; i<rapl->nb; i++) for (unsigned int i = 0; i < rapl->nb; i++)
printf("package %d, zone %d, name %s\n", rapl->packages[i], rapl->zones[i], rapl->names[i]); {
printf("package %d, zone %d, name %s\n", rapl->packages[i], rapl->zones[i], rapl->names[i]);
}
#endif #endif
rapl->values = calloc(sizeof(uint64_t), rapl->nb); rapl->values = calloc(sizeof(uint64_t), rapl->nb);
...@@ -138,8 +140,10 @@ unsigned int get_rapl(uint64_t *results, void *ptr) ...@@ -138,8 +140,10 @@ unsigned int get_rapl(uint64_t *results, void *ptr)
{ {
_rapl_t *state = (_rapl_t *) ptr; _rapl_t *state = (_rapl_t *) ptr;
_get_rapl(state->tmp_values, state); _get_rapl(state->tmp_values, state);
for(unsigned int i=0; i<state->nb; i++) for (unsigned int i = 0; i < state->nb; i++)
results[i] = state->tmp_values[i] - state->values[i]; {
results[i] = state->tmp_values[i] - state->values[i];
}
memcpy(state->values, state->tmp_values, sizeof(uint64_t)*state->nb); memcpy(state->values, state->tmp_values, sizeof(uint64_t)*state->nb);
return state->nb; return state->nb;
...@@ -153,9 +157,13 @@ void clean_rapl(void *ptr) ...@@ -153,9 +157,13 @@ void clean_rapl(void *ptr)
_rapl_t *rapl = (_rapl_t *) ptr; _rapl_t *rapl = (_rapl_t *) ptr;
for (unsigned int package = 0; package < rapl->nb_pkgs; package++) for (unsigned int package = 0; package < rapl->nb_pkgs; package++)
if (powercap_rapl_destroy(&rapl->pkgs[package])) if (powercap_rapl_destroy(&rapl->pkgs[package]))
perror("powercap_rapl_destroy"); {
for (unsigned int elem=0; elem<rapl->nb; elem++) perror("powercap_rapl_destroy");
free(rapl->names[elem]); }
for (unsigned int elem = 0; elem < rapl->nb; elem++)
{
free(rapl->names[elem]);
}
free(rapl->names); free(rapl->names);
free(rapl->pkgs); free(rapl->pkgs);
...@@ -169,6 +177,8 @@ void clean_rapl(void *ptr) ...@@ -169,6 +177,8 @@ void clean_rapl(void *ptr)
void label_rapl(char **labels, void *ptr) void label_rapl(char **labels, void *ptr)
{ {
_rapl_t *rapl = (_rapl_t *) ptr; _rapl_t *rapl = (_rapl_t *) ptr;
for(unsigned int i=0; i<rapl->nb; i++) for (unsigned int i = 0; i < rapl->nb; i++)
labels[i] = rapl->names[i]; {
labels[i] = rapl->names[i];
}
} }
...@@ -37,8 +37,10 @@ int get_string(char *filename, char *buffer, int max_size) ...@@ -37,8 +37,10 @@ int get_string(char *filename, char *buffer, int max_size)
{ {
int fid = open(filename, O_RDONLY); int fid = open(filename, O_RDONLY);
//printf("Tries to open : %s : %d\n", filename, fid); //printf("Tries to open : %s : %d\n", filename, fid);
if(fid == -1) if (fid == -1)
return -1; {
return -1;
}
int nb = read(fid, buffer, max_size); int nb = read(fid, buffer, max_size);
if(nb == -1) { if(nb == -1) {
...@@ -46,7 +48,7 @@ int get_string(char *filename, char *buffer, int max_size) ...@@ -46,7 +48,7 @@ int get_string(char *filename, char *buffer, int max_size)
return -1; return -1;
} }
buffer[nb]=0; buffer[nb] = 0;
close(fid); close(fid);
return 0; return 0;
} }
...@@ -54,15 +56,15 @@ int get_string(char *filename, char *buffer, int max_size) ...@@ -54,15 +56,15 @@ int get_string(char *filename, char *buffer, int max_size)
void add_to_list(char ***list_name, char *source, int nb_elem) void add_to_list(char ***list_name, char *source, int nb_elem)
{ {
//printf("Adds: %s\n", source); //printf("Adds: %s\n", source);
*list_name = realloc(*list_name, (nb_elem+1)*sizeof(char *)); *list_name = realloc(*list_name, (nb_elem + 1) * sizeof(char *));
(*list_name)[nb_elem] = malloc(strlen(source)+1); (*list_name)[nb_elem] = malloc(strlen(source) + 1);
strcpy((*list_name)[nb_elem], source); strcpy((*list_name)[nb_elem], source);
} }
void add_temperature_sensor(int id_rep, struct temperature_t *state) void add_temperature_sensor(int id_rep, struct temperature_t *state)
{ {
static int key=0; static int key = 0;
static char buffer_filename[512]; static char buffer_filename[512];
static char buffer_label[512]; static char buffer_label[512];
...@@ -150,6 +152,8 @@ void clean_temperature(void *ptr) ...@@ -150,6 +152,8 @@ void clean_temperature(void *ptr)
void label_temperature(char **labels, void *ptr) void label_temperature(char **labels, void *ptr)
{ {
struct temperature_t *state = (struct temperature_t *)ptr; struct temperature_t *state = (struct temperature_t *)ptr;
for(int i=0; i<state->nb_elem; i++) for (int i = 0; i < state->nb_elem; i++)
labels[i] = state->label_list[i]; {
labels[i] = state->label_list[i];
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment