Skip to content
Snippets Groups Projects
Commit e3754444 authored by Guy Zana's avatar Guy Zana
Browse files

Merge branch 'master' of https://github.com/cloudius-systems/osv

parents 53c0f270 3705cc09
No related branches found
No related tags found
No related merge requests found
......@@ -48,3 +48,20 @@ To run OSv
(gdb) connect
(gdb) osv syms
(gdb) bt
Tracing
=======
Uncomment the "tracing-flags =" line in build.mak, and rebuild.
Run the program until it aborts, then in gdb:
set pagination off
set print elements 0
set print array-indexes on
set print pretty on
set logging on
print trace_log
print trace_record_last._M_i % trace_max
gdb.txt will contain the the log, the last line contains the array index
of the last trace entry, read backwards from there.
......@@ -2,6 +2,7 @@
#define ARCH_HH_
#include "processor.hh"
#include "msr.hh"
// namespace arch - architecture independent interface for architecture
// dependent operations (e.g. irq_disable vs. cli)
......@@ -33,11 +34,23 @@ public:
void restore() {
asm volatile("sub $128, %%rsp; pushq %0; popfq; add $128, %%rsp" : : "r"(_rflags));
}
bool enabled() const {
return _rflags & 0x200;
}
private:
unsigned long _rflags;
};
extern bool tls_available() __attribute__((no_instrument_function));
inline bool tls_available()
{
unsigned a, d;
asm("rdmsr" : "=a"(a), "=d"(d) : "c"(msr::IA32_FS_BASE));
// don't call rdmsr, since we don't want function instrumentation
return a != 0 || d != 0;
}
}
#endif /* ARCH_HH_ */
arch = x64
#cmdline = java.so Hello
cmdline = testrunner.so
cmdline = java.so Hello
#cmdline = testrunner.so
INCLUDES = -I. -I$(src)/arch/$(arch) -I$(src) -I$(src)/external/libunwind/include -I$(src)/include
INCLUDES += -I$(src)/external/acpica/source/include
COMMON = $(autodepend) -g -Wall -Wno-pointer-arith -Werror -Wformat=0 \
-U _FORTIFY_SOURCE -fno-stack-protector $(INCLUDES) \
$(arch-cflags) $(cflags-$(mode)) $(acpi-defines)
$(arch-cflags) $(cflags-$(mode)) $(acpi-defines) $(tracing-flags)
tracing-flags =
#tracing-flags = -finstrument-functions -finstrument-functions-exclude-file-list=atomic,trace.cc
CXXFLAGS = -std=gnu++11 -lstdc++ $(do-sys-includes) $(COMMON)
CFLAGS = -std=gnu99 $(COMMON)
......@@ -193,6 +196,7 @@ objects += core/sched.o
objects += core/mmio.o
objects += core/sglist.o
objects += core/kprintf.o
objects += core/trace.o
unittests:= tests/tst-hub.o
......
#include "osv/trace.hh"
#include "sched.hh"
#include "arch.hh"
#include <atomic>
enum class trace_record_type {
invalid,
entry,
exit,
};
struct trace_record {
trace_record_type type;
sched::thread* thread;
void* fn;
void* caller;
};
constexpr unsigned max_trace = 100000;
trace_record trace_log[max_trace];
std::atomic<unsigned> trace_record_last;
bool trace_enabled;
void enable_trace()
{
trace_enabled = true;
}
void add_trace_record(const trace_record& tr)
{
unsigned p = trace_record_last.fetch_add(1, std::memory_order_relaxed);
p %= max_trace;
trace_log[p] = tr;
}
extern "C" void __cyg_profile_func_enter(void *this_fn, void *call_site)
{
if (!trace_enabled) {
return;
}
add_trace_record(trace_record{trace_record_type::entry, sched::thread::current(),
this_fn, call_site});
}
extern "C" void __cyg_profile_func_exit(void *this_fn, void *call_site)
{
if (!trace_enabled || !arch::tls_available()) {
return;
}
add_trace_record(trace_record{trace_record_type::exit, sched::thread::current(),
this_fn, call_site});
}
#ifndef TRACE_HH_
#define TRACE_HH_
void enable_trace();
#endif /* TRACE_HH_ */
......@@ -151,7 +151,7 @@ public:
void wake();
static void sleep_until(u64 abstime);
static void yield();
static thread* current();
static thread* current() __attribute((no_instrument_function));
stack_info get_stack_info();
cpu* tcpu();
void join();
......
......@@ -22,6 +22,7 @@
#include "barrier.hh"
#include "tests/tst-hub.hh"
#include "arch.hh"
#include "osv/trace.hh"
asm(".pushsection \".debug_gdb_scripts\", \"MS\",@progbits,1 \n"
".byte 1 \n"
......@@ -93,6 +94,7 @@ int main(int ac, char **av)
void main_cont(int ac, char** av)
{
smp_launch();
enable_trace();
sched::init_detached_threads_reaper();
vfs_init();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment