1/* 2 * Copyright 2016, General Dynamics C4 Systems 3 * 4 * SPDX-License-Identifier: GPL-2.0-only 5 */ 6 7#pragma once 8 9#include <config.h> 10#include <util.h> 11#include <arch/kernel/traps.h> 12#include <smp/lock.h> 13 14/* This C function should be the first thing called from C after entry from 15 * assembly. It provides a single place to do any entry work that is not 16 * done in assembly for various reasons */ 17static inline void c_entry_hook(void) 18{ 19 arch_c_entry_hook(); 20#if defined(CONFIG_BENCHMARK_TRACK_KERNEL_ENTRIES) || defined(CONFIG_BENCHMARK_TRACK_UTILISATION) 21 ksEnter = timestamp(); 22#endif 23} 24 25/* This C function should be the last thing called from C before exiting 26 * the kernel (be it to assembly or returning to user space). It provides 27 * a place to provide any additional instrumentation or functionality 28 * in C before leaving the kernel */ 29static inline void c_exit_hook(void) 30{ 31#ifdef CONFIG_BENCHMARK_TRACK_KERNEL_ENTRIES 32 benchmark_track_exit(); 33#endif /* CONFIG_BENCHMARK_TRACK_KERNEL_ENTRIES */ 34#ifdef CONFIG_BENCHMARK_TRACK_UTILISATION 35 if (likely(NODE_STATE(benchmark_log_utilisation_enabled))) { 36 timestamp_t exit = timestamp(); 37 NODE_STATE(ksCurThread)->benchmark.number_kernel_entries++; 38 NODE_STATE(ksCurThread)->benchmark.kernel_utilisation += exit - ksEnter; 39 NODE_STATE(benchmark_kernel_number_entries)++; 40 NODE_STATE(benchmark_kernel_time) += exit - ksEnter; 41 } 42#endif /* CONFIG_BENCHMARK_TRACK_UTILISATION */ 43 44 arch_c_exit_hook(); 45} 46 47