From 74d5d82f57b368a6f656d57c02512eae9fdaa1e1 Mon Sep 17 00:00:00 2001 From: Patrick Date: Sun, 15 Sep 2024 19:24:26 +0200 Subject: [PATCH] =?UTF-8?q?=C2=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- benchies.md | 2 + benchies/embench/CMakeLists.txt | 7 + benchies/embench/README.rst | 97 +++++++++++++ benchies/embench/prj.conf | 9 ++ benchies/embench/sample.yaml | 12 ++ benchies/embench/src/bench.c | 244 ++++++++++++++++++++++++++++++++ benchies/embench/src/main.c | 47 ++++++ benchies/embench/src/support.h | 69 +++++++++ 8 files changed, 487 insertions(+) create mode 100644 benchies/embench/CMakeLists.txt create mode 100644 benchies/embench/README.rst create mode 100644 benchies/embench/prj.conf create mode 100644 benchies/embench/sample.yaml create mode 100644 benchies/embench/src/bench.c create mode 100644 benchies/embench/src/main.c create mode 100644 benchies/embench/src/support.h diff --git a/benchies.md b/benchies.md index 1e10097946..571fb40940 100644 --- a/benchies.md +++ b/benchies.md @@ -13,3 +13,5 @@ linpack: LTO && CFI -> ~ 4000000 KFLOPS LTO && !CFI -> ~ 3650000 KFLOPS !LTO && !CFI -> ~ 3650000 KFLOPS + +mibench -> not implemented for zephyr and no reason to suspect result differ from linpack diff --git a/benchies/embench/CMakeLists.txt b/benchies/embench/CMakeLists.txt new file mode 100644 index 0000000000..b24b8c5250 --- /dev/null +++ b/benchies/embench/CMakeLists.txt @@ -0,0 +1,7 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(blinky) + +target_sources(app PRIVATE src/main.c src/bench.c) diff --git a/benchies/embench/README.rst b/benchies/embench/README.rst new file mode 100644 index 0000000000..ec23fe5403 --- /dev/null +++ b/benchies/embench/README.rst @@ -0,0 +1,97 @@ +.. zephyr:code-sample:: blinky + :name: Blinky + :relevant-api: gpio_interface + + Blink an LED forever using the GPIO API. + +Overview +******** + +The Blinky sample blinks an LED forever using the :ref:`GPIO API `. + +The source code shows how to: + +#. Get a pin specification from the :ref:`devicetree ` as a + :c:struct:`gpio_dt_spec` +#. Configure the GPIO pin as an output +#. Toggle the pin forever + +See :zephyr:code-sample:`pwm-blinky` for a similar sample that uses the PWM API instead. + +.. _blinky-sample-requirements: + +Requirements +************ + +Your board must: + +#. Have an LED connected via a GPIO pin (these are called "User LEDs" on many of + Zephyr's :ref:`boards`). +#. Have the LED configured using the ``led0`` devicetree alias. + +Building and Running +******************** + +Build and flash Blinky as follows, changing ``reel_board`` for your board: + +.. zephyr-app-commands:: + :zephyr-app: samples/basic/blinky + :board: reel_board + :goals: build flash + :compact: + +After flashing, the LED starts to blink and messages with the current LED state +are printed on the console. If a runtime error occurs, the sample exits without +printing to the console. + +Build errors +************ + +You will see a build error at the source code line defining the ``struct +gpio_dt_spec led`` variable if you try to build Blinky for an unsupported +board. + +On GCC-based toolchains, the error looks like this: + +.. code-block:: none + + error: '__device_dts_ord_DT_N_ALIAS_led_P_gpios_IDX_0_PH_ORD' undeclared here (not in a function) + +Adding board support +******************** + +To add support for your board, add something like this to your devicetree: + +.. code-block:: DTS + + / { + aliases { + led0 = &myled0; + }; + + leds { + compatible = "gpio-leds"; + myled0: led_0 { + gpios = <&gpio0 13 GPIO_ACTIVE_LOW>; + }; + }; + }; + +The above sets your board's ``led0`` alias to use pin 13 on GPIO controller +``gpio0``. The pin flags :c:macro:`GPIO_ACTIVE_HIGH` mean the LED is on when +the pin is set to its high state, and off when the pin is in its low state. + +Tips: + +- See :dtcompatible:`gpio-leds` for more information on defining GPIO-based LEDs + in devicetree. + +- If you're not sure what to do, check the devicetrees for supported boards which + use the same SoC as your target. See :ref:`get-devicetree-outputs` for details. + +- See :zephyr_file:`include/zephyr/dt-bindings/gpio/gpio.h` for the flags you can use + in devicetree. + +- If the LED is built in to your board hardware, the alias should be defined in + your :ref:`BOARD.dts file `. Otherwise, you can + define one in a :ref:`devicetree overlay `. diff --git a/benchies/embench/prj.conf b/benchies/embench/prj.conf new file mode 100644 index 0000000000..0c48afbef4 --- /dev/null +++ b/benchies/embench/prj.conf @@ -0,0 +1,9 @@ +CONFIG_GPIO=y +#CONFIG_ASAN=y +#CONFIG_CFI=y +CONFIG_LLVM_USE_LLD=y +#CONFIG_LTO=y + +#CONFIG_DEBUG=y +#CONFIG_DEBUG_INFO=y +#CONFIG_DEBUG_OPTIMIZATIONS=y diff --git a/benchies/embench/sample.yaml b/benchies/embench/sample.yaml new file mode 100644 index 0000000000..de711910da --- /dev/null +++ b/benchies/embench/sample.yaml @@ -0,0 +1,12 @@ +sample: + name: Blinky Sample +tests: + sample.basic.blinky: + tags: + - LED + - gpio + filter: dt_enabled_alias_with_parent_compat("led0", "gpio-leds") + depends_on: gpio + harness: led + integration_platforms: + - frdm_k64f diff --git a/benchies/embench/src/bench.c b/benchies/embench/src/bench.c new file mode 100644 index 0000000000..1aa1bd427e --- /dev/null +++ b/benchies/embench/src/bench.c @@ -0,0 +1,244 @@ +/* + * Simple MD5 implementation + * by Creationix + * https://gist.github.com/creationix/4710780 + * Licensed under MIT + * + * modified by Julian Kunkel for Embench-iot + * Compile with: gcc -o md5 -O3 -lm md5.c + */ +#include +#include +#include +#include + +#include "support.h" + +#define LOCAL_SCALE_FACTOR 51 + +/* BEEBS heap is just an array */ +/* MSG_SIZE * 2 + ((((MSG_SIZE+8)/64 + 1) * 64) - 8) + 64 */ +#define HEAP_SIZE (2000 + 1016 + 64) +#define MSG_SIZE 1000 +/* Result obtained with a single run on the native target on x86 with a MSG_SIZE + * of 1000 and a msg initiated incrementally from 0 to 999 as in benchmark_body. + * If MSG_SIZE or the initialization mechanism of the array change the RESULT + * value needs to be updated accordingly. */ +#define RESULT 0x33f673b4 + +static char heap[HEAP_SIZE]; + +// leftrotate function definition +#define LEFTROTATE(x, c) (((x) << (c)) | ((x) >> (32 - (c)))) + +// These vars will contain the hash +static uint32_t h0, h1, h2, h3; + +void md5(uint8_t *initial_msg, size_t initial_len) { + + // Message (to prepare) + uint8_t *msg = NULL; + + // Note: All variables are unsigned 32 bit and wrap modulo 2^32 when calculating + + // r specifies the per-round shift amounts + + uint32_t r[] = {7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, + 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, + 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, + 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21}; + + // Use binary integer part of the sines of integers (in radians) as constants// Initialize variables: + uint32_t k[] = { + 0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee, + 0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501, + 0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be, + 0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821, + 0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa, + 0xd62f105d, 0x02441453, 0xd8a1e681, 0xe7d3fbc8, + 0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed, + 0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a, + 0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c, + 0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70, + 0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x04881d05, + 0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665, + 0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039, + 0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1, + 0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1, + 0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391}; + + h0 = 0x67452301; + h1 = 0xefcdab89; + h2 = 0x98badcfe; + h3 = 0x10325476; + + // Pre-processing: adding a single 1 bit + //append "1" bit to message + /* Notice: the input bytes are considered as bits strings, + where the first bit is the most significant bit of the byte.[37] */ + + // Pre-processing: padding with zeros + //append "0" bit until message length in bit ≡ 448 (mod 512) + //append length mod (2 pow 64) to message + + int new_len = ((((initial_len + 8) / 64) + 1) * 64) - 8; + + msg = calloc(new_len + 64, 1); // also appends "0" bits + // (we alloc also 64 extra bytes...) + memcpy(msg, initial_msg, initial_len); + msg[initial_len] = 128; // write the "1" bit + + uint32_t bits_len = 8*initial_len; // note, we append the len + memcpy(msg + new_len, &bits_len, 4); // in bits at the end of the buffer + + // Process the message in successive 512-bit chunks: + //for each 512-bit chunk of message: + int offset; + for(offset=0; offset + Contributor: Jeremy Bennett + + This file is part of Embench and was formerly part of the Bristol/Embecosm + Embedded Benchmark Suite. + + SPDX-License-Identifier: GPL-3.0-or-later */ + +#include "support.h" +#include + +int __attribute__((used)) main(int argc __attribute__((unused)), + char *argv[] __attribute__((unused))) +{ + int i; + volatile int result; + int correct; + + puts("Initialising benchmark"); + initialise_benchmark(); + puts("Warming up caches"); + warm_caches(WARMUP_HEAT); + + puts("Running benchmark"); + result = benchmark(); + puts("finished benchmark"); + + /* bmarks that use arrays will check a global array rather than int result */ + + correct = verify_benchmark(result); + + puts("returning"); + return (!correct); + +} /* main () */ + +/* + Local Variables: + mode: C + c-file-style: "gnu" + End: +*/ diff --git a/benchies/embench/src/support.h b/benchies/embench/src/support.h new file mode 100644 index 0000000000..1fce309f34 --- /dev/null +++ b/benchies/embench/src/support.h @@ -0,0 +1,69 @@ +/* Support header for BEEBS. + + Copyright (C) 2014 Embecosm Limited and the University of Bristol + Copyright (C) 2019 Embecosm Limited + + Contributor James Pallister + + Contributor Jeremy Bennett + + This file is part of Embench and was formerly part of the Bristol/Embecosm + Embedded Benchmark Suite. + + SPDX-License-Identifier: GPL-3.0-or-later */ + +#ifndef SUPPORT_H +#define SUPPORT_H + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +//#define DEBUG +#define CPU_MHZ 1 +#define WARMUP_HEAT 1000 + +/* Include board support header if we have one */ + +/* Benchmarks must implement verify_benchmark, which must return -1 if no + verification is done. */ + +int verify_benchmark (int result); + +/* Standard functions implemented for each board */ + +void initialise_board (void); +void start_trigger (void); +void stop_trigger (void); + +/* Every benchmark implements this for one-off data initialization. This is + only used for initialization that is independent of how often benchmark () + is called. */ + +void initialise_benchmark (void); + +/* Every benchmark implements this for cache warm up, typically calling + benchmark several times. The argument controls how much warming up is + done, with 0 meaning no warming. */ + +void warm_caches (int temperature); + +/* Every benchmark implements this as its entry point. Don't allow it to be + inlined! */ + +int benchmark (void) __attribute__ ((noinline)); + +/* Every benchmark must implement this to validate the result of the + benchmark. */ + +int verify_benchmark (int res); + + +#endif /* SUPPORT_H */ + +/* + Local Variables: + mode: C + c-file-style: "gnu" + End: +*/