diff --git a/README.md b/README.md index 95b6d7e63fe2cc81ad34f787a17a12dd8fb43656..869c358507fb7db92fb2cadaf7b05ef3f65c9439 100644 --- a/README.md +++ b/README.md @@ -21,13 +21,22 @@ OPTIONS: -s|--overhead-stats enable overhead statistics (nanoseconds). +``` + +The following is an exhaustive list of all the sensors (it is very likely +that one will not have all the sensors activated in his build): +```bash SENSORS: +-a|--amd-rapl + AMD RAPL -p|--perf-list <perf_list> performance counters perf_list is a coma separated list of performance counters. Ex: instructions,cache_misses -l|--list list the available performance counters and quit +-i|--monitor-infiniband <infiniband_path> + infiniband monitoring (if infiniband_path is X, tries to detect it automatically) -u|--sysload system load -d|--net-dev <net_dev> diff --git a/configure.sh b/configure.sh index 196aaf8a9eac4b58680138b7fe7f94c081ce47a6..21c94eff4ef28cab03761595e6473b29c80e8b2b 100755 --- a/configure.sh +++ b/configure.sh @@ -26,18 +26,19 @@ debug=0 target_hdr=src/sensors.h target_mk=sensors.mk -nonsensor='counters_option|optparse|sensors|util|info_reader' +nonsensor='counters_option|sensors|util' hdr_blacklist=$nonsensor hdr_whitelist='' usage() { - printf -- 'Usage: %s [-l] [-e <sensor>] [-i <sensor>] [-u <sensor>]\n' "$(basename "$0")" >&2 + printf -- 'Usage: %s [-la] [-e <sensor>] [-i <sensor>] [-u <sensor>]\n' "$(basename "$0")" >&2 printf -- '-e | --exclude : exclude sensor, can be called multiple times\n' >&2 printf -- '-i | --include : include sensor, can be called multiple times\n' >&2 printf -- '-l | --list-sensors : list all sensors and exit\n' >&2 printf -- '-u | --unique : only include the specified sensor\n' >&2 printf -- ' if this option is used, any usage of `-e` or `-i` will be ignored\n' >&2 + printf -- '-a | --all : include all sensors, meant to be used only by the makefile\n' >&2 exit 1 } @@ -62,9 +63,9 @@ gen_sensors_h() { for sensor in $sensors; do sed -n 's/.*'"${sensor}"'_opt\[\([0-9]\+\)\].*/\1/p' "src/${sensor}.h" done | - paste -s -d '+' | - bc + paste -s -d '+' ) + nb_sensor_opts=$(eval "echo \$(($nb_sensor_opts))") dprint sensors >&2 dprint nb_sensor_opts >&2 @@ -106,7 +107,7 @@ gen_sensors_mk() { detect_caps() { [ -r /usr/include/linux/perf_event.h ] && hdr_whitelist=counters - [ -d /sys/class/infiniband ] && hdr_whitelist=${hdr_whitelist}|infiniband + [ -d /sys/class/infiniband ] && hdr_whitelist="${hdr_whitelist}|infiniband" [ -r /proc/stat ] && hdr_whitelist="${hdr_whitelist}|load" if [ -r /proc/net/route ]; then @@ -134,8 +135,15 @@ detect_caps() { [ $(ls -1 /sys/class/hwmon | wc -l) -gt 0 ] && hdr_whitelist="${hdr_whitelist}|temperature" } -detect_caps +case $1 in +--all|-a) + all=1 + ;; +esac +[ "$all" ] || detect_caps + +[ "$all" ] || while [ "$1" ]; do case $1 in --include|-i) diff --git a/makefile b/makefile index 646a01531d8671313342535868e0c683bb4b107a..a197961099a277e4e12d6d442236b2fd5327d14c 100644 --- a/makefile +++ b/makefile @@ -24,7 +24,7 @@ LDFLAGS = ASTYLE = astyle --style=kr -xf -s4 -k3 -n -Z -Q -all: $(BIN) readme man +all: $(BIN) man $(BIN): $(BIN_DIR) $(OBJ) $(OBJ_DIR)/$(BIN).o $(CC) $(LDFLAGS) -o $(BIN_DIR)/$(BIN) $(OBJ) $(OBJ_DIR)/$(BIN).o @@ -51,7 +51,7 @@ debug: CFLAGS = $(CPPFLAGS) -DDEBUG -g -Og debug: $(BIN) tests: - gcc $(CPPFLAGS) $(TESTS_DIR)/main.c $(SRC_DIR)/util.c -o $(TESTS_DIR)/run + $(CC) $(CPPFLAGS) $(TESTS_DIR)/main.c $(SRC_DIR)/util.c -o $(TESTS_DIR)/run $(TESTS_DIR)/run format: @@ -70,8 +70,8 @@ readme: $(BIN) sh ./tools/update-readme-usage.sh man: $(BIN) - awk -v "usage=$$($(BIN_DIR)/$(BIN) -1)" \ + awk -v "usage=$$($(BIN_DIR)/$(BIN) --dump-opts)" \ '/^USAGE/ { $$0=usage } 1' \ - doc/mojitos.pre.1 > doc/mojitos.1 2>/dev/null + doc/$(BIN).pre.1 > doc/$(BIN).1 2>/dev/null .PHONY: all clean mojitos debug format tests readme man diff --git a/src/infiniband.c b/src/infiniband.c index aa4a8de532fc61e162a1a2069815e262c3ec2b5b..6a5a6b4e2422d819269d1a470783286be8a5c162 100644 --- a/src/infiniband.c +++ b/src/infiniband.c @@ -17,25 +17,44 @@ along with MojitO/S. If not, see <https://www.gnu.org/licenses/>. *******************************************************/ -#include <stdlib.h> #include <fcntl.h> -#include <stdio.h> -#include <string.h> #include <glob.h> #include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + #include "util.h" #define NB_SENSOR 4 -struct Network { +struct Infiniband { uint64_t values[NB_SENSOR]; uint64_t tmp_values[NB_SENSOR]; int sources[NB_SENSOR]; }; -typedef struct Network Network; +typedef struct Infiniband Infiniband; + +unsigned int _get_infiniband(uint64_t *results, int *sources) +{ + if (sources == NULL) { + return 0; + } + + char buffer[128]; -unsigned int _get_network(uint64_t *results, int *sources); + for (int i = 0; i < NB_SENSOR; i++) { + if (pread(sources[i], buffer, 127, 0) < 0) { + perror("pread"); + exit(1); + } + results[i] = strtoull(buffer, NULL, 10); + } + + return NB_SENSOR; +} unsigned int init_infiniband(char *infi_path, void **ptr) { @@ -50,6 +69,7 @@ unsigned int init_infiniband(char *infi_path, void **ptr) glob("/sys/class/infiniband/*/ports/*/counters/", 0, NULL, &res); if (res.gl_pathc == 0) { + fprintf(stderr, "No infiniband found.\n"); return 0; } @@ -62,7 +82,7 @@ unsigned int init_infiniband(char *infi_path, void **ptr) "%s/port_xmit_data" }; - Network *state = malloc(sizeof(Network)); + Infiniband *state = malloc(sizeof(Infiniband)); char buffer[1024]; for (int i = 0; i < NB_SENSOR; i++) { @@ -71,11 +91,39 @@ unsigned int init_infiniband(char *infi_path, void **ptr) } *ptr = (void *) state; - _get_network(state->values, state->sources); + _get_infiniband(state->values, state->sources); return NB_SENSOR; } +unsigned int get_infiniband(uint64_t *results, void *ptr) +{ + Infiniband *state = (Infiniband *) ptr; + _get_infiniband(state->tmp_values, state->sources); + + for (int i = 0; i < NB_SENSOR; i++) { + results[i] = modulo_substraction(state->tmp_values[i], state->values[i]); + } + + memcpy(state->values, state->tmp_values, NB_SENSOR * sizeof(uint64_t)); + return NB_SENSOR; +} + +void clean_infiniband(void *ptr) +{ + Infiniband *state = (Infiniband *) ptr; + + if (state == NULL) { + return; + } + + for (int i = 0; i < NB_SENSOR; i++) { + close(state->sources[i]); + } + + free(state); +} + char *_labels_infiniband[NB_SENSOR] = {"irxp", "irxb", "itxp", "itxb"}; void label_infiniband(char **labels, void *none) { diff --git a/src/infiniband.h b/src/infiniband.h index e30d78bee90f936056e8847a071e9fe817c9bea1..8098cf5c68773326e2bda38e3748e81dfb52ee0c 100644 --- a/src/infiniband.h +++ b/src/infiniband.h @@ -19,12 +19,14 @@ *******************************************************/ unsigned int init_infiniband(char *infi_path, void **ptr); +unsigned int get_infiniband(uint64_t *results, void *ptr); +void clean_infiniband(void *ptr); void label_infiniband(char **labels, void *); Sensor infiniband = { .init = init_infiniband, - .get = NULL, - .clean = NULL, + .get = get_infiniband, + .clean = clean_infiniband, .label = label_infiniband, .nb_opt = 1, }; diff --git a/src/mojitos.c b/src/mojitos.c index 4274b6a114805b6f07fd5c52cae73d8255c2c702..e8cb6fa2a2a8100de93cfa40dee93ec20f3c0a93 100644 --- a/src/mojitos.c +++ b/src/mojitos.c @@ -23,6 +23,7 @@ #include <signal.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <time.h> #include <unistd.h> #include "util.h" @@ -218,7 +219,7 @@ int main(int argc, char **argv) usage(argv); } - if (argc == 2 && argv[1][0] == '-' && argv[1][1] == '1' && argv[1][2] == '\0') { + if (argc == 2 && strcmp(argv[1], "--dump-opts") == 0) { dumpopts(opts, NB_OPT, NB_SENSOR_OPT); exit(EXIT_SUCCESS); } diff --git a/tools/update-readme-usage.sh b/tools/update-readme-usage.sh index ad2f88f9b811b188d42acf22dc8662a88e81f05d..2c1950ec6ad9f5e2681e968b251d80f8c335969d 100755 --- a/tools/update-readme-usage.sh +++ b/tools/update-readme-usage.sh @@ -8,8 +8,24 @@ try() { "$@" || die "cannot $*"; } yell() { echo "$0: $*" >&2; } echo() { printf '%s\n' "$*"; } -usage=$(./bin/mojitos) -[ -n "$usage" ] || die 'empty usage. try to recompile mojitos.' +try ./configure.sh --all +try make mojitos +usage=$( + ./bin/mojitos | + awk ' + /^SENSORS/ { + $0 = "" + printf "```\n" + printf "\n" + printf "The following is an exhaustive list of all the sensors (it is very likely\n" + printf "that one will not have all the sensors activated in his build):\n" + printf "```bash\n" + printf "SENSORS:" + } + { print } + ' +) +[ -n "$usage" ] || die 'empty usage. cannot continue.' try awk -v "usage=$usage" ' /^Usage/ { @@ -17,7 +33,11 @@ try awk -v "usage=$usage" ' del = 1 } { - if (del == 1) { + if (del == 1 || del == 2) { + if (match($0, "^```")) { + del++ + } + } else if (del == 3) { if (match($0, "^```")) { del = 0 print $0