Skip to content
Snippets Groups Projects
Commit 8a4ef356 authored by Martin Karsten's avatar Martin Karsten
Browse files

- sample support for LTTng userspace tracing

parent c1abe650
No related branches found
No related tags found
No related merge requests found
Pipeline #97323 passed
OPTIM?=1
TRACING?=0
DYNSTACK?=0
OLDURING?=0
......@@ -6,10 +7,26 @@ CFGFLAGS=-pthread -fPIC -Wall -Wextra
DBGFLAGS=-ggdb # -fsanitize=address
LANGFLAGS=-std=c++11
CFLAGS=$(CFGFLAGS) $(DBGFLAGS) $(OPTFLAGS) $(STACKFLAGS) $(TLSFLAGS)
CXXFLAGS=$(CFLAGS) $(LANGFLAGS)
ifeq ($(OPTIM),1)
OPTFLAGS=-O3 -fno-omit-frame-pointer
endif
ifeq ($(TRACING),1)
LTTNG:=$(shell lttng-gen-tp --help 2>/dev/null)
ifdef LTTNG
CFLAGS+=-DTRACING
else
TRACING=0
endif
endif
ifeq ($(OLDURING),1)
CFLAGS+=-DOLDURING
endif
ifeq ($(DYNSTACK),1)
STACKFLAGS=-fsplit-stack -DSPLIT_STACK
else
......@@ -24,10 +41,3 @@ endif
ifeq ($(CC),clang)
CXX=clang++
endif
CFLAGS=$(CFGFLAGS) $(DBGFLAGS) $(OPTFLAGS) $(STACKFLAGS) $(TLSFLAGS)
CXXFLAGS=$(CFLAGS) $(LANGFLAGS)
ifeq ($(OLDURING),1)
CFLAGS+=-DOLDURING
endif
......@@ -36,6 +36,7 @@ In addition, the following students (in alphabetical order) have helped with var
- Vrajang Parikh (gdb names & watchpoints)
- Wen Shi (gdb extension)
- Kai Sun (ARM64, mutex locks)
- JinYang (Luke) Tao (LTTng)
- Shuangyi Tong (event scopes)
- Gan Wang (API/Apache)
- Xinyi Zhou (worker/core affinity)
......
......@@ -19,6 +19,10 @@ LIBS+=-L/usr/local/lib -Wl,-rpath=/usr/local/lib -luring
endif
endif
ifeq ($(TRACING),1)
LIBS+=-llttng-ust -ldl
endif
ifeq ($(shell uname),FreeBSD)
LIBS+=-lpthread -lexecinfo # needed for backtrace_symbols()
endif
......
......@@ -8,6 +8,11 @@ COBJECTS=$(subst .c,.o,$(notdir $(CSOURCES)))
ASOURCES=$(wildcard $(addsuffix /*.S,$(SOURCEDIRS)))
AOBJECTS=$(subst .S,.o,$(notdir $(ASOURCES)))
ifeq ($(TRACING),1)
TSOURCES=$(subst .tp,.c,$(wildcard tracing/*.tp))
TOBJECTS=$(subst .tp,.o,$(wildcard tracing/*.tp))
endif
DEPENDS=$(subst .cc,.d,$(notdir $(SOURCES))) $(subst .c,.d,$(notdir $(CSOURCES))) $(subst .S,.d,$(notdir $(ASOURCES)))
DEPENDS+=$(subst .c,.d,$(notdir $(CSOURCES)))
......@@ -35,18 +40,18 @@ else
@for f in $^; do diff -y -W 80 --suppress-common-lines $$f.default $$f; done; true
endif
$(LIBA): $(OBJECTS) $(COBJECTS) $(AOBJECTS)
$(LIBA): $(OBJECTS) $(COBJECTS) $(AOBJECTS) $(TOBJECTS)
$(AR) cr $@ $^
ranlib $@
$(LIBSO): $(OBJECTS) $(COBJECTS) $(AOBJECTS)
$(LIBSO): $(OBJECTS) $(COBJECTS) $(AOBJECTS) $(TOBJECTS)
$(CXX) -shared -pthread $^ -o $@
$(GENHEADERS): %: %.default
@cp $< $@
# also creates dependencies
$(OBJECTS): %.o: %.cc $(GENHEADERS)
$(OBJECTS): %.o: %.cc $(GENHEADERS) $(TSOURCES)
$(CXX) $(CXXFLAGS) -MMD -c $< -o $@
$(COBJECTS): %.o: %.c
......@@ -55,13 +60,16 @@ $(COBJECTS): %.o: %.c
$(AOBJECTS): %.o: %.S
$(CC) $(CFLAGS) -MMD -c $< -o $@
$(TSOURCES): %.c: %.tp
lttng-gen-tp $< -o $@ -o $(subst .c,.h,$@)
$(OBJECTS) errnoname/errnoname.c: errnoname/errnoname.h
errnoname/errnoname.h:
git submodule update --init errnoname
clean:
rm -f $(LIBA) $(LIBSO) $(OBJECTS) $(COBJECTS) $(AOBJECTS) $(DEPENDS)
rm -f $(LIBA) $(LIBSO) $(OBJECTS) $(COBJECTS) $(AOBJECTS) $(DEPENDS) tracing/*.?
vclean: clean
rm -f $(GENHEADERS)
......
......@@ -28,6 +28,12 @@
#include <map>
#if TRACING
#include "tracing/BlockingSyncTrace.h"
#else
#define lttng_ust_tracepoint(provider, name, ...)
#endif
/****************************** Basics ******************************/
struct Suspender { // funnel suspend calls through this class for access control
......@@ -165,7 +171,9 @@ class BlockingQueue {
queue.push_back(node);
lock.release();
// block, potentially with timeout
lttng_ust_tracepoint(BlockingSyncTrace, blocking, (uintptr_t)Context::CurrFred(), (uintptr_t)this, "block");
ptr_t winner = blockHelper(*cf, args...);
lttng_ust_tracepoint(BlockingSyncTrace, blocking, (uintptr_t)Context::CurrFred(), (uintptr_t)this, "unblock");
if (winner == &queue) return true; // blocking completed;
// clean up
ScopedLock<Lock> sl(lock);
......@@ -177,7 +185,9 @@ class BlockingQueue {
BlockingQueue& operator=(const BlockingQueue&) = delete; // no assignment
public:
BlockingQueue() = default;
BlockingQueue() {
lttng_ust_tracepoint(BlockingSyncTrace, blocking, (uintptr_t)Context::CurrFred(), (uintptr_t)this, "init");
}
~BlockingQueue() { RASSERT0(empty()); }
bool empty() const { return queue.empty(); }
......@@ -207,12 +217,14 @@ public:
template<bool Enqueue>
Fred* unblock() { // Note that caller must hold lock
lttng_ust_tracepoint(BlockingSyncTrace, blocking, (uintptr_t)Context::CurrFred(), (uintptr_t)this, "resume");
for (Node* node = queue.front(); node != queue.edge(); node = IntrusiveList<Node>::next(*node)) {
Fred* f = &node->fred;
if (f->raceResume(&queue)) {
IntrusiveList<Node>::remove(*node);
DBG::outl(DBG::Level::Blocking, "Fred ", FmtHex(f), " resume from ", FmtHex(&queue));
if (Enqueue) f->resume();
lttng_ust_tracepoint(BlockingSyncTrace, blocking, (uintptr_t)f, (uintptr_t)this, "resumed");
return f;
}
}
......
LTTNG_UST_TRACEPOINT_EVENT(
BlockingSyncTrace, blocking,
LTTNG_UST_TP_ARGS(uintptr_t, cfibreptr, uintptr_t, queueptr, const char *, eventstr),
LTTNG_UST_TP_FIELDS(
lttng_ust_field_integer(uintptr_t, fibre_address, cfibreptr)
lttng_ust_field_integer(uintptr_t, queue_address, queueptr)
lttng_ust_field_string(event_string, eventstr)
)
)
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