From 976902dee16b7b203e789cb604f1c38c46a5d9ad Mon Sep 17 00:00:00 2001 From: Oleksii Oleksenko Date: Thu, 25 Jun 2020 16:05:27 +0200 Subject: [PATCH] Aggregation function MAX --- README.md | 1 + common/nanoBench.c | 8 ++++++++ common/nanoBench.h | 2 +- kernel-nanoBench.sh | 6 +++++- kernel/nb_km.c | 2 ++ user/nanoBench_main.c | 1 + 6 files changed, 18 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 922155a..fd382d6 100644 --- a/README.md +++ b/README.md @@ -144,6 +144,7 @@ Both `nanoBench.sh` and `kernel-nanoBench.sh` support the following command-line | `-avg` | Selects the arithmetic mean (excluding the top and bottom 20% of the values) as the aggregate function. `[This is the default]` | | `-median` | Selects the median as the aggregate function. | | `-min` | Selects the minimum as the aggregate function. | +| `-max` | Selects the maximum as the aggregate function. | | `-basic_mode` | The effect of this option is described in the [Generated Code](#generated-code) section. | | `-no_mem` | If this option is enabled, the code for `read_perf_ctrs` does not make any memory accesses and stores all performance counter values in registers. This can, for example, be useful for benchmarks that require that the state of the data caches does not change after the execution of `code_init`. *If this option is used, the code to be benchmarked must not modify registers* ***R8-R11 (Intel)*** *and* ***R8-R13 (AMD).*** *Furthermore, `read_perf_ctrs` will modify* ***RAX, RCX, and RDX***. | | `-cpu ` | Pins the measurement thread to CPU n. `[Default: Pin the thread to the CPU it is currently running on.]` | diff --git a/common/nanoBench.c b/common/nanoBench.c index 64c78f8..74a2729 100644 --- a/common/nanoBench.c +++ b/common/nanoBench.c @@ -659,6 +659,14 @@ int64_t get_aggregate_value_100(int64_t* values, size_t length) { } } return min * 100; + } else if (aggregate_function == MAX) { + int64_t max = values[0]; + for (int i=0; i max) { + max = values[i]; + } + } + return max * 100; } else { qsort(values, length, sizeof(int64_t), cmpInt64); diff --git a/common/nanoBench.h b/common/nanoBench.h index 259671b..846f230 100644 --- a/common/nanoBench.h +++ b/common/nanoBench.h @@ -107,7 +107,7 @@ extern int no_mem; extern int basic_mode; #define BASIC_MODE_DEFAULT 0; -enum agg_enum {AVG_20_80, MIN, MED}; +enum agg_enum {AVG_20_80, MIN, MAX, MED}; extern int aggregate_function; #define AGGREGATE_FUNCTION_DEFAULT AVG_20_80; diff --git a/kernel-nanoBench.sh b/kernel-nanoBench.sh index 5301db3..c22ef08 100755 --- a/kernel-nanoBench.sh +++ b/kernel-nanoBench.sh @@ -2,7 +2,7 @@ if [ "$EUID" -ne 0 ]; then echo "Error: nanoBench requires root privileges" - echo "Try \"sudo ./nb_km-asm.sh ...\"" + echo "Try \"sudo ./kernel-nanoBench.sh ...\"" exit 1 fi @@ -89,6 +89,9 @@ while [ "$1" ]; do elif [[ "$1" == -min* ]]; then echo "min" > /sys/nb/agg shift + elif [[ "$1" == -max* ]]; then + echo "max" > /sys/nb/agg + shift elif [[ "$1" == -med* ]]; then echo "med" > /sys/nb/agg shift @@ -112,6 +115,7 @@ while [ "$1" ]; do echo " -avg: Selects the arithmetic mean as the aggregate function." echo " -median: Selects the median as the aggregate function." echo " -min: Selects the minimum as the aggregate function." + echo " -max: Selects the maximum as the aggregate function." echo " -basic_mode: Enables basic mode." echo " -no_mem: The code for reading the perf. ctrs. does not make memory accesses." echo " -cpu : Pins the measurement thread to CPU n." diff --git a/kernel/nb_km.c b/kernel/nb_km.c index f7d4c86..68def87 100644 --- a/kernel/nb_km.c +++ b/kernel/nb_km.c @@ -270,6 +270,8 @@ static ssize_t agg_show(struct kobject *kobj, struct kobj_attribute *attr, char static ssize_t agg_store(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t count) { if (!strncmp(buf, "min", 3)) { aggregate_function = MIN; + } else if (!strncmp(buf, "max", 3)) { + aggregate_function = MAX; } else if (!strncmp(buf, "med", 3)) { aggregate_function = MED; } else { diff --git a/user/nanoBench_main.c b/user/nanoBench_main.c index ac6f156..e09db9f 100644 --- a/user/nanoBench_main.c +++ b/user/nanoBench_main.c @@ -80,6 +80,7 @@ int main(int argc, char **argv) { {"avg", no_argument, &aggregate_function, AVG_20_80}, {"median", no_argument, &aggregate_function, MED}, {"min", no_argument, &aggregate_function, MIN}, + {"max", no_argument, &aggregate_function, MAX}, {"basic_mode", no_argument, &basic_mode, 1}, {"no_mem", no_argument, &no_mem, 1}, {"verbose", no_argument, &verbose, 1},