Skip to content
Snippets Groups Projects
Commit 0fc68415 authored by TwilCynder's avatar TwilCynder
Browse files

utils file

parent f38c9908
Branches
No related tags found
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
*.o *.o
src/counters_option.h src/counters_option.h
bin bin
obj obj
This diff is collapsed.
...@@ -4,7 +4,7 @@ SRC_DIR = src ...@@ -4,7 +4,7 @@ SRC_DIR = src
OBJ_DIR = obj OBJ_DIR = obj
BIN_DIR = bin BIN_DIR = bin
OBJECTS = $(addprefix $(OBJ_DIR)/, mojitos.o counters.o rapl.o network.o load.o infiniband.o temperature.o) OBJECTS = $(addprefix $(OBJ_DIR)/, mojitos.o counters.o rapl.o network.o load.o infiniband.o temperature.o util.o)
OBJECTS_GRP = $(subst _individual,_group, $(OBJECTS)) OBJECTS_GRP = $(subst _individual,_group, $(OBJECTS))
CC = gcc CC = gcc
......
/******************************************************* /*******************************************************
Copyright (C) 2018-2019 Georges Da Costa <georges.da-costa@irit.fr> Copyright (C) 2018-2019 Georges Da Costa <georges.da-costa@irit.fr>
This file is part of Mojitos. This file is part of Mojitos.
Mojitos is free software: you can redistribute it and/or modify Mojitos is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
Mojitos is distributed in the hope that it will be useful, Mojitos is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with MojitO/S. If not, see <https://www.gnu.org/licenses/>. along with MojitO/S. If not, see <https://www.gnu.org/licenses/>.
*******************************************************/ *******************************************************/
unsigned int init_counters(char *, void **); unsigned int init_counters(char *, void **);
unsigned int get_counters(uint64_t *results, void *); unsigned int get_counters(uint64_t *results, void *);
void clean_counters(void *); void clean_counters(void *);
void label_counters(char **labels, void *); void label_counters(char **labels, void *);
void show_all_counters(); void show_all_counters();
#! /usr/bin/python3 #! /usr/bin/python3
# SPDX-License-Identifier: GPL-3.0-or-later # SPDX-License-Identifier: GPL-3.0-or-later
# Copyright (C) 2018-2021 Georges Da Costa <georges.da-costa@irit.fr> # Copyright (C) 2018-2021 Georges Da Costa <georges.da-costa@irit.fr>
linux_include = '/usr/include/linux/perf_event.h' linux_include = '/usr/include/linux/perf_event.h'
string = """#include <linux/perf_event.h> string = """#include <linux/perf_event.h>
typedef struct counter_option { typedef struct counter_option {
char *name; char *name;
__u32 perf_type; __u32 perf_type;
__u64 perf_key; __u64 perf_key;
} counter_option; } counter_option;
static counter_option perf_static_info[] = {""" static counter_option perf_static_info[] = {"""
print(string) print(string)
nb = 0 nb = 0
black_list = ['stalled_cycles_frontend','stalled_cycles_backend', black_list = ['stalled_cycles_frontend','stalled_cycles_backend',
'cache_l1i', 'cache_op_write', 'cache_result_miss'] 'cache_l1i', 'cache_op_write', 'cache_result_miss']
with open(linux_include, 'r') as infile: with open(linux_include, 'r') as infile:
mode = '' mode = ''
for line in infile: for line in infile:
if 'perf_hw_id' in line: if 'perf_hw_id' in line:
mode = 'PERF_TYPE_HARDWARE' mode = 'PERF_TYPE_HARDWARE'
elif 'perf_hw_cache_' in line: elif 'perf_hw_cache_' in line:
mode = 'PERF_TYPE_HW_CACHE' mode = 'PERF_TYPE_HW_CACHE'
elif 'perf_sw_id' in line: elif 'perf_sw_id' in line:
mode = 'PERF_TYPE_SOFTWARE' mode = 'PERF_TYPE_SOFTWARE'
elif 'PERF_COUNT_' in line and '=' in line: elif 'PERF_COUNT_' in line and '=' in line:
perf_name = line.split()[0] perf_name = line.split()[0]
short_perf = perf_name[14:].lower() short_perf = perf_name[14:].lower()
if short_perf in black_list: if short_perf in black_list:
continue continue
if mode == 'PERF_TYPE_HW_CACHE': if mode == 'PERF_TYPE_HW_CACHE':
for op_id, op_id_str in enumerate(['r', 'w', 'p']): for op_id, op_id_str in enumerate(['r', 'w', 'p']):
op_id_names = ['PERF_COUNT_HW_CACHE_OP_READ', 'PERF_COUNT_HW_CACHE_OP_WRITE', 'PERF_COUNT_HW_CACHE_OP_PREFETCH'] op_id_names = ['PERF_COUNT_HW_CACHE_OP_READ', 'PERF_COUNT_HW_CACHE_OP_WRITE', 'PERF_COUNT_HW_CACHE_OP_PREFETCH']
for result_id, result_id_str in enumerate(['a', 'm']): for result_id, result_id_str in enumerate(['a', 'm']):
result_id_names = ['PERF_COUNT_HW_CACHE_RESULT_ACCESS', 'PERF_COUNT_HW_CACHE_RESULT_MISS'] result_id_names = ['PERF_COUNT_HW_CACHE_RESULT_ACCESS', 'PERF_COUNT_HW_CACHE_RESULT_MISS']
res = '{ .name = "%s_%s_%s", .perf_type = %s, .perf_key = %s | (%s >> 8) | (%s >> 16) },' % ( res = '{ .name = "%s_%s_%s", .perf_type = %s, .perf_key = %s | (%s >> 8) | (%s >> 16) },' % (
short_perf, op_id_str, result_id_str, short_perf, op_id_str, result_id_str,
mode, mode,
perf_name, perf_name,
op_id_names[op_id], op_id_names[op_id],
result_id_names[result_id]) result_id_names[result_id])
print(res) print(res)
nb += 1 nb += 1
else: else:
res = '{ .name = "'+short_perf+'", .perf_type = '+mode+', .perf_key = '+perf_name+'},' res = '{ .name = "'+short_perf+'", .perf_type = '+mode+', .perf_key = '+perf_name+'},'
print(res) print(res)
nb += 1 nb += 1
print('};') print('};')
print('static unsigned int nb_counter_option =',nb,';') print('static unsigned int nb_counter_option =',nb,';')
/******************************************************* /*******************************************************
Copyright (C) 2018-2019 Georges Da Costa <georges.da-costa@irit.fr> Copyright (C) 2018-2019 Georges Da Costa <georges.da-costa@irit.fr>
This file is part of Mojitos. This file is part of Mojitos.
Mojitos is free software: you can redistribute it and/or modify Mojitos is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
Mojitos is distributed in the hope that it will be useful, Mojitos is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with MojitO/S. If not, see <https://www.gnu.org/licenses/>. along with MojitO/S. If not, see <https://www.gnu.org/licenses/>.
*******************************************************/ *******************************************************/
unsigned int init_infiniband(char *infi_path, void **ptr); unsigned int init_infiniband(char *infi_path, void **ptr);
void label_infiniband(char **labels, void *); void label_infiniband(char **labels, void *);
/******************************************************* /*******************************************************
Copyright (C) 2018-2019 Georges Da Costa <georges.da-costa@irit.fr> Copyright (C) 2018-2019 Georges Da Costa <georges.da-costa@irit.fr>
This file is part of Mojitos. This file is part of Mojitos.
Mojitos is free software: you can redistribute it and/or modify Mojitos is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
Mojitos is distributed in the hope that it will be useful, Mojitos is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with MojitO/S. If not, see <https://www.gnu.org/licenses/>. along with MojitO/S. If not, see <https://www.gnu.org/licenses/>.
*******************************************************/ *******************************************************/
unsigned int init_load(char *, void **); unsigned int init_load(char *, void **);
unsigned int get_load(uint64_t *results, void *); unsigned int get_load(uint64_t *results, void *);
void clean_load(void *); void clean_load(void *);
void label_load(char **labels, void *); void label_load(char **labels, void *);
/******************************************************* /*******************************************************
Copyright (C) 2018-2019 Georges Da Costa <georges.da-costa@irit.fr> Copyright (C) 2018-2019 Georges Da Costa <georges.da-costa@irit.fr>
This file is part of Mojitos. This file is part of Mojitos.
Mojitos is free software: you can redistribute it and/or modify Mojitos is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
Mojitos is distributed in the hope that it will be useful, Mojitos is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with MojitO/S. If not, see <https://www.gnu.org/licenses/>. along with MojitO/S. If not, see <https://www.gnu.org/licenses/>.
*******************************************************/ *******************************************************/
unsigned int init_network(char *, void **); unsigned int init_network(char *, void **);
unsigned int get_network(uint64_t *results, void *); unsigned int get_network(uint64_t *results, void *);
void clean_network(void *); void clean_network(void *);
void label_network(char **labels, void *); void label_network(char **labels, void *);
/******************************************************* /*******************************************************
Copyright (C) 2018-2021 Georges Da Costa <georges.da-costa@irit.fr> Copyright (C) 2018-2021 Georges Da Costa <georges.da-costa@irit.fr>
This file is part of Mojitos. This file is part of Mojitos.
Mojitos is free software: you can redistribute it and/or modify Mojitos is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
Mojitos is distributed in the hope that it will be useful, Mojitos is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with MojitO/S. If not, see <https://www.gnu.org/licenses/>. along with MojitO/S. If not, see <https://www.gnu.org/licenses/>.
*******************************************************/ *******************************************************/
unsigned int init_temperature(char *, void **); unsigned int init_temperature(char *, void **);
unsigned int get_temperature(uint64_t *results, void *); unsigned int get_temperature(uint64_t *results, void *);
void clean_temperature(void *); void clean_temperature(void *);
void label_temperature(char **labels, void *); void label_temperature(char **labels, void *);
#include "util.h"
inline uint64_t substractAcc(const uint64_t l, const uint64_t r)
{
return (l < r) ? UINT64_MAX + (l - r) : l - r;
}
\ No newline at end of file
#pragma once
#include <stdint.h>
inline uint64_t substractAcc(const uint64_t l, const uint64_t r);
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment