diff --git a/Makefile b/Makefile index f3b6d5b11e9fa797ba5a02f99f2bce02aa9eb5ab..eea5e2513a58da05708cb1dd96667da16b2f6658 100644 --- a/Makefile +++ b/Makefile @@ -121,14 +121,15 @@ LDSCRIPT= $(STARTUPLD)/STM32F411xE.ld # C sources that can be compiled in ARM or THUMB mode depending on the global # setting. -CSRC = $(ALLCSRC) \ - $(SRCDIR)/crc32.c \ - $(SRCDIR)/benchmarks.c \ - $(SRCDIR)/benchmarks/memory.c \ - $(SRCDIR)/main.c \ - $(SRCDIR)/random.c \ - $(SRCDIR)/serial.c \ - $(SRCDIR)/tests.c \ +CSRC = $(ALLCSRC) \ + $(SRCDIR)/crc32.c \ + $(SRCDIR)/benchmarks.c \ + $(SRCDIR)/benchmarks/memory.c \ + $(SRCDIR)/benchmarks/blind_abstraction.c \ + $(SRCDIR)/main.c \ + $(SRCDIR)/random.c \ + $(SRCDIR)/serial.c \ + $(SRCDIR)/tests.c \ $(SRCDIR)/usb.c # C++ sources that can be compiled in ARM or THUMB mode depending on the global diff --git a/scripts/benchmarks/blind_abstraction.py b/scripts/benchmarks/blind_abstraction.py new file mode 100644 index 0000000000000000000000000000000000000000..15edde324565f39a21bd472cc06e54a4b9107f2c --- /dev/null +++ b/scripts/benchmarks/blind_abstraction.py @@ -0,0 +1,62 @@ +## This file is part of the execution-time evaluation for the qronos observer abstractions. +## Copyright (C) 2022-2023 Tim Rheinfels <tim.rheinfels@fau.de> +## See https://gitlab.cs.fau.de/qronos-state-abstractions/execution-time +## +## This program 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. +## +## This program 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 this program. If not, see <https://www.gnu.org/licenses/>. + +### +### @file benchmarks/blind_abstraction.py +### +### @brief Provides @p blind_abstraction.BlindAbstraction, the @p benchmark.Benchmark +### subclass for the blind abstraction benchmark +### +### @author Tim Rheinfels <tim.rheinfels@fau.de> +### + +import numpy as np +import json + +from benchmark import Benchmark +from data import decode + +### +### @brief Encapsulates the blind abstraction execution time benchmark +### +class BlindAbstraction(Benchmark): + + ### + ### @brief Validates the computations performed on the STM32 by running them + ### again in numpy and comparing the results. + ### + ### @see benchmark.Benchmark._validate for parameters + ### + def _validate(self, benchmark, key): + for run in benchmark['tests']: + v = decode(run['setup']['v']) + rho = decode(run['setup']['rho']) + beta = decode(run['setup']['beta']) + + for i in range(benchmark['repetition_count']): + v = rho * v + beta + + v_p = decode(run['teardown']['v_p']) + assert(np.isclose(v, v_p)) + + ### + ### @brief Constructor + ### + ### @see benchmark.Benchmark.__init__ for parameters + ### + def __init__(self, data): + Benchmark.__init__(self, data, 'Blind Abstraction', r'blind_abstraction_([0-9]+)', lambda m: m.group(1)) diff --git a/src/benchmarks.c b/src/benchmarks.c index 549024721c4db8d58368ad35cdbd578b2efd2351..b9447988d7864c972dc411096edd2335a1632102 100644 --- a/src/benchmarks.c +++ b/src/benchmarks.c @@ -27,6 +27,8 @@ #include <benchmarks/campaign.h> +#include <benchmarks/blind_abstraction.h> + void benchmarks_run(void) { @@ -37,4 +39,7 @@ void benchmarks_run(void) BENCHMARKS_CAMPAIGN("chSysPolledDelayX_1000", chSysPolledDelayX(1000u), {}, {}, 10u, 10u); BENCHMARKS_CAMPAIGN("chSysPolledDelayX_10000", chSysPolledDelayX(10000u), {}, {}, 10u, 10u); + // Comparative execution time benchmarks + benchmarks_run_blind_abstraction(); + } diff --git a/src/benchmarks/blind_abstraction.c b/src/benchmarks/blind_abstraction.c new file mode 100644 index 0000000000000000000000000000000000000000..1b0081dad6feb91ae16f9648a34653cc5913368c --- /dev/null +++ b/src/benchmarks/blind_abstraction.c @@ -0,0 +1,124 @@ +// This file is part of the execution-time evaluation for the qronos observer abstractions. +// Copyright (C) 2022-2023 Tim Rheinfels <tim.rheinfels@fau.de> +// See https://gitlab.cs.fau.de/qronos-state-abstractions/execution-time +// +// This program 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. +// +// This program 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 this program. If not, see <https://www.gnu.org/licenses/>. + +/// +/// @file benchmarks/blind_abstraction.c +/// +/// @brief Provides the implementation of the blind abstraction execution time benchmark +/// +/// @author Tim Rheinfels <tim.rheinfels@fau.de> +/// + +#include "blind_abstraction.h" + +#include <stdlib.h> +#include <string.h> + +#include <random.h> +#include <serial.h> +#include <benchmarks/campaign.h> + +void benchmarks_run_blind_abstraction(void) +{ + // Volatile to make sure v not optimized away + volatile float v; + float rho; + float beta; + + #define SETUP(N_Y) { \ + v = random_float(); \ + rho = random_float(); \ + beta = random_float(); \ + serial_printf("\"v\": %u, \"rho\": %u, \"beta\": %u,\n", serial_encode(v), serial_encode(rho), serial_encode(beta)); \ + } + + #define TEARDOWN { \ + serial_printf("\"v_p\": %u,\n", serial_encode(v)); \ + } + + #define CAMPAIGN(N_Y) { \ + BENCHMARKS_CAMPAIGN("blind_abstraction_" #N_Y, \ + {v = rho * v + beta;}, \ + SETUP(N_Y), \ + TEARDOWN, \ + 10u, \ + 10u \ + ) \ + } + + CAMPAIGN(1); + CAMPAIGN(2); + CAMPAIGN(3); + CAMPAIGN(4); + CAMPAIGN(5); + CAMPAIGN(6); + CAMPAIGN(7); + CAMPAIGN(8); + CAMPAIGN(9); + CAMPAIGN(10); + CAMPAIGN(11); + CAMPAIGN(12); + CAMPAIGN(13); + CAMPAIGN(14); + CAMPAIGN(15); + CAMPAIGN(16); + CAMPAIGN(17); + CAMPAIGN(18); + CAMPAIGN(19); + CAMPAIGN(20); + CAMPAIGN(21); + CAMPAIGN(22); + CAMPAIGN(23); + CAMPAIGN(24); + CAMPAIGN(25); + CAMPAIGN(26); + CAMPAIGN(27); + CAMPAIGN(28); + CAMPAIGN(29); + CAMPAIGN(30); + CAMPAIGN(31); + CAMPAIGN(32); + CAMPAIGN(33); + CAMPAIGN(34); + CAMPAIGN(35); + CAMPAIGN(36); + CAMPAIGN(37); + CAMPAIGN(38); + CAMPAIGN(39); + CAMPAIGN(40); + CAMPAIGN(41); + CAMPAIGN(42); + CAMPAIGN(43); + CAMPAIGN(44); + CAMPAIGN(45); + CAMPAIGN(46); + CAMPAIGN(47); + CAMPAIGN(48); + CAMPAIGN(49); + CAMPAIGN(50); + CAMPAIGN(51); + CAMPAIGN(52); + CAMPAIGN(53); + CAMPAIGN(54); + CAMPAIGN(55); + CAMPAIGN(56); + CAMPAIGN(57); + CAMPAIGN(58); + CAMPAIGN(59); + CAMPAIGN(60); + +} diff --git a/src/benchmarks/blind_abstraction.h b/src/benchmarks/blind_abstraction.h new file mode 100644 index 0000000000000000000000000000000000000000..ee98639cdb2f6b4037fee2b115569ca5f7fcad87 --- /dev/null +++ b/src/benchmarks/blind_abstraction.h @@ -0,0 +1,44 @@ +// This file is part of the execution-time evaluation for the qronos observer abstractions. +// Copyright (C) 2022-2023 Tim Rheinfels <tim.rheinfels@fau.de> +// See https://gitlab.cs.fau.de/qronos-state-abstractions/execution-time +// +// This program 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. +// +// This program 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 this program. If not, see <https://www.gnu.org/licenses/>. + +/// +/// @file benchmarks/blind_abstraction.h +/// +/// @brief Provides the interface for the blind abstraction execution time benchmark +/// +/// @author Tim Rheinfels <tim.rheinfels@fau.de> +/// + +#ifndef BENCHMARKS_BLINDABSTRACTION_H +#define BENCHMARKS_BLINDABSTRACTION_H + +#include <benchmarks/memory.h> + +/// +/// @brief Memory required for running the blind abstraction execution time benchmark +/// +#define BENCHMARKS_BLIND_ABSTRACTION_WORK_SIZE 0u + +/// +/// @brief Runs the blind abstraction execution time benchmark +/// +/// This function measures the execution time needed in order to update the +/// blind abstraction proposed in @cite ECRTS23-Rheinfels by equation (6a). +/// +void benchmarks_run_blind_abstraction(void); + +#endif // BENCHMARKS_BLINDABSTRACTION_H diff --git a/src/benchmarks/memory.c b/src/benchmarks/memory.c index 7df4b0246f9d1222571011e95128e7e8144043ae..c8d2ef42a601d77de858e1cd74b2ee2fae60813f 100644 --- a/src/benchmarks/memory.c +++ b/src/benchmarks/memory.c @@ -28,6 +28,8 @@ #include <stdint.h> #include <string.h> +#include <benchmarks/blind_abstraction.h> + /// /// @brief Size of the padding in bytes used for checking memory violations /// @@ -46,7 +48,9 @@ /// /// @brief Actual benchmark memory /// -static float work[2u * PADDING]; +static float work[2u * PADDING + + BENCHMARKS_BLIND_ABSTRACTION_WORK_SIZE +]; float * const benchmarks_memory = work + PADDING;