Changed a lot of files. Summary: profiler support; "SafeFunction"; UnlockDeadLock kernel config; Code optimization & more

This commit is contained in:
Alex
2022-11-28 08:25:37 +02:00
parent 2fba834d41
commit 0289054900
62 changed files with 1462 additions and 558 deletions

87
Profiling/cyg.cpp Normal file
View File

@ -0,0 +1,87 @@
#include <types.h>
#include <printf.h>
#include <uart.hpp>
#include "../kernel.h"
bool EnableProfiler = false;
bool Wait = false;
unsigned long long LogDepth = 0;
unsigned int Level = 0;
using namespace UniversalAsynchronousReceiverTransmitter;
static inline SafeFunction __no_instrument_function void profiler_uart_wrapper(char c, void *unused)
{
bool renable = EnableProfiler;
EnableProfiler = false;
UART(COM2).Write(c);
(void)unused;
if (renable)
EnableProfiler = true;
}
EXTERNC SafeFunction __no_instrument_function void __cyg_profile_func_enter(void *Function, void *CallSite)
{
if (!EnableProfiler)
return;
while (Wait)
asmv("pause");
Wait = true;
if (Level > 40)
Level--;
Level++;
if (!KernelSymbolTable)
fctprintf(profiler_uart_wrapper, nullptr, "%lld [%02d]: \033[42m->\033[0m%*c \033[33m%p\033[0m - \033[33m%p\033[0m\n",
LogDepth++,
Level - 1,
Level,
' ',
Function,
CallSite);
else
fctprintf(profiler_uart_wrapper, nullptr, "%lld [%02d]: \033[42m->\033[0m%*c \033[33m%s\033[0m - \033[33m%s\033[0m\n",
LogDepth++,
Level - 1,
Level,
' ',
KernelSymbolTable->GetSymbolFromAddress((uint64_t)Function),
KernelSymbolTable->GetSymbolFromAddress((uint64_t)CallSite));
Wait = false;
}
EXTERNC SafeFunction __no_instrument_function void __cyg_profile_func_exit(void *Function, void *CallSite)
{
if (!EnableProfiler)
return;
while (Wait)
asmv("pause");
Wait = true;
if (Level > 40)
Level--;
Level--;
if (!KernelSymbolTable)
fctprintf(profiler_uart_wrapper, nullptr, "%lld [%02d]: \033[41m<-\033[0m%*c \033[33m%p\033[0m - \033[33m%p\033[0m\n",
LogDepth++,
Level - 1,
Level,
' ',
Function,
CallSite);
else
fctprintf(profiler_uart_wrapper, nullptr, "%lld [%02d]: \033[41m<-\033[0m%*c \033[33m%s\033[0m - \033[33m%s\033[0m\n",
LogDepth++,
Level - 1,
Level,
' ',
KernelSymbolTable->GetSymbolFromAddress((uint64_t)Function),
KernelSymbolTable->GetSymbolFromAddress((uint64_t)CallSite));
Wait = false;
}

67
Profiling/gcov.cpp Normal file
View File

@ -0,0 +1,67 @@
#include <types.h>
#include <printf.h>
#include <uart.hpp>
#include "../kernel.h"
using namespace UniversalAsynchronousReceiverTransmitter;
#if BITS_PER_LONG >= 64
typedef long gcov_type;
#else
typedef long long gcov_type;
#endif
struct gcov_fn_info
{
unsigned int ident;
unsigned int checksum;
unsigned int n_ctrs[0];
};
struct gcov_ctr_info
{
unsigned int num;
gcov_type *values;
void (*merge)(gcov_type *, unsigned int);
};
struct gcov_info
{
unsigned int version;
struct gcov_info *next;
unsigned int stamp;
const char *filename;
unsigned int n_functions;
const struct gcov_fn_info *functions;
unsigned int ctr_mask;
struct gcov_ctr_info counts[0];
};
static inline SafeFunction __no_instrument_function void gcov_uart_wrapper(char c, void *unused)
{
UART(COM2).Write(c);
(void)unused;
}
// TODO: Implement
EXTERNC SafeFunction __no_instrument_function void __gcov_init(gcov_info *p __unused)
{
}
EXTERNC SafeFunction __no_instrument_function void __gcov_exit(void)
{
}
EXTERNC SafeFunction __no_instrument_function void __gcov_flush(void)
{
}
EXTERNC SafeFunction __no_instrument_function void __gcov_merge_add(gcov_type *counters, unsigned int n_counters)
{
}
EXTERNC SafeFunction __no_instrument_function void __gcov_merge_single(gcov_type *counters, unsigned int n_counters)
{
}

19
Profiling/gprof.cpp Normal file
View File

@ -0,0 +1,19 @@
#include <types.h>
#include <printf.h>
#include <uart.hpp>
#include "../kernel.h"
using namespace UniversalAsynchronousReceiverTransmitter;
static inline SafeFunction __no_instrument_function void gprof_uart_wrapper(char c, void *unused)
{
UART(COM2).Write(c);
(void)unused;
}
EXTERNC SafeFunction __no_instrument_function void mcount(unsigned long frompc, unsigned long selfpc)
{
// TODO: Implement
/* https://docs.kernel.org/trace/ftrace-design.html */
}