1/* 2 * Copyright 2014, General Dynamics C4 Systems 3 * 4 * This software may be distributed and modified according to the terms of 5 * the GNU General Public License version 2. Note that NO WARRANTY is provided. 6 * See "LICENSE_GPLv2.txt" for details. 7 * 8 * @TAG(GD_GPL) 9 */ 10 11#ifndef BENCHMARK_H 12#define BENCHMARK_H 13 14#include <arch/benchmark.h> 15#include <machine/io.h> 16#include <arch/api/constants.h> 17#include <arch/machine/hardware.h> 18#include <benchmark/benchmark_tracepoints_types.h> 19#include <mode/hardware.h> 20 21#if CONFIG_MAX_NUM_TRACE_POINTS > 0 22#define TRACE_POINT_START(x) trace_point_start(x) 23#define TRACE_POINT_STOP(x) trace_point_stop(x) 24 25#define MAX_LOG_SIZE (seL4_LogBufferSize / sizeof(benchmark_tracepoint_log_entry_t)) 26 27extern timestamp_t ksEntries[CONFIG_MAX_NUM_TRACE_POINTS]; 28extern bool_t ksStarted[CONFIG_MAX_NUM_TRACE_POINTS]; 29extern timestamp_t ksExit; 30extern seL4_Word ksLogIndex; 31extern seL4_Word ksLogIndexFinalized; 32extern paddr_t ksUserLogBuffer; 33 34static inline void 35trace_point_start(word_t id) 36{ 37 ksEntries[id] = timestamp(); 38 ksStarted[id] = true; 39} 40 41static inline void 42trace_point_stop(word_t id) 43{ 44 benchmark_tracepoint_log_entry_t *ksLog = (benchmark_tracepoint_log_entry_t *) KS_LOG_PPTR; 45 ksExit = timestamp(); 46 47 if (likely(ksUserLogBuffer != 0)) { 48 if (likely(ksStarted[id])) { 49 ksStarted[id] = false; 50 if (likely(ksLogIndex < MAX_LOG_SIZE)) { 51 ksLog[ksLogIndex] = (benchmark_tracepoint_log_entry_t) { 52 id, ksExit - ksEntries[id] 53 }; 54 } 55 /* increment the log index even if we have exceeded the log size 56 * this is so we can tell if we need a bigger log */ 57 ksLogIndex++; 58 } 59 /* If this fails integer overflow has occurred. */ 60 assert(ksLogIndex > 0); 61 } 62} 63 64#else 65 66#define TRACE_POINT_START(x) 67#define TRACE_POINT_STOP(x) 68 69#endif /* CONFIG_MAX_NUM_TRACE_POINTS > 0 */ 70 71#endif /* BENCHMARK_H */ 72