1 /* 2 * SPDX-License-Identifier: Apache-2.0 3 * 4 * Copyright (c) 2019 Linaro Limited 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 #ifndef H_BOOTUTIL_BENCH_H__ 20 #define H_BOOTUTIL_BENCH_H__ 21 22 #include "ignore.h" 23 24 #ifdef MCUBOOT_USE_BENCH 25 26 /* The platform-specific benchmark code should define a 27 * `bench_state_t` type that holds the information needed for the 28 * benchmark. This is generally something small, such as an integer 29 * holding the state. This should also define plat_bench_start and 30 * plat_bench_end, which likely have to be macros so that log messages 31 * come from the right place in the code. */ 32 #include <platform-bench.h> 33 34 /* 35 * These are simple barrier-type benchmarks. If a platform has 36 * benchmarks that are enabled, calling `boot_bench_start()` before a 37 * block of code and `boot_bench_stop()` after that block of code will 38 * present this information in some manner (usually through logging). 39 * The details of what is measured and how it is printed are specific 40 * to the platform and the implementation. A pointer to the 41 * platform-specific state should be passed in. 42 */ 43 #define boot_bench_start(_state) do { \ 44 plat_bench_start(_state); \ 45 } while (0) 46 47 #define boot_bench_stop(_state) do { \ 48 plat_bench_stop(_state); \ 49 } while (0) 50 51 #else /* not MCUBOOT_USE_BENCH */ 52 53 /* The type needs to take space. As long as it remains unused, the C 54 * compiler should eliminate this value entirely. */ 55 typedef int bench_state_t; 56 57 /* Without benchmarking enabled, these are just empty. */ 58 #define boot_bench_start(_state) do { \ 59 IGNORE(_state); \ 60 } while(0) 61 62 #define boot_bench_stop(_state) do { \ 63 IGNORE(_state); \ 64 } while(0) 65 66 #endif /* not MCUBOOT_USE_BENCH */ 67 68 #endif /* not H_BOOTUTIL_BENCH_H__ */ 69