Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions interpreter/perl/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,7 @@ func (i *perlInstance) UpdateLibcInfo(ebpf interpreter.EbpfHandler, pid libpf.PI
Version: d.version,
StateAddr: uint64(d.stateAddr) + uint64(i.bias),
StateInTSD: stateInTSD,

TsdInfo: support.TSDInfo{
Offset: libcInfo.TSDInfo.Offset,
Multiplier: libcInfo.TSDInfo.Multiplier,
Indirect: libcInfo.TSDInfo.Indirect,
},
TsdInfo: libcInfo.TSDInfo,

Interpreter_curcop: uint16(vms.interpreter.curcop),
Interpreter_curstackinfo: uint16(vms.interpreter.curstackinfo),
Expand Down
7 changes: 1 addition & 6 deletions interpreter/python/python.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,12 +378,7 @@ func (p *pythonInstance) UpdateLibcInfo(ebpf interpreter.EbpfHandler, pid libpf.
cdata := support.PyProcInfo{
AutoTLSKeyAddr: uint64(d.autoTLSKey) + uint64(p.bias),
Version: d.version,

TsdInfo: support.TSDInfo{
Offset: libcInfo.TSDInfo.Offset,
Multiplier: libcInfo.TSDInfo.Multiplier,
Indirect: libcInfo.TSDInfo.Indirect,
},
TsdInfo: libcInfo.TSDInfo,

PyThreadState_frame: uint8(vm.PyThreadState.Frame),
PyCFrame_current_frame: uint8(vm.PyCFrame.CurrentFrame),
Expand Down
37 changes: 11 additions & 26 deletions libc/libc.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,17 @@ import (
"regexp"

"go.opentelemetry.io/ebpf-profiler/libpf/pfelf"
"go.opentelemetry.io/ebpf-profiler/support"
)

type TSDInfo = support.TSDInfo

// LibcInfo contains introspection information extracted from the C-library
type LibcInfo struct {
// TSDInfo is the TSDInfo extracted for this C-library
TSDInfo TSDInfo
}

// TSDInfo contains information to access C-library's Thread Specific Data from eBPF
type TSDInfo struct {
// Offset is the pointer difference from "tpbase" pointer to the C-library
// specific struct pthread's member containing the thread specific data:
// .tsd (musl) or .specific (glibc).
// Note: on x86_64 it's positive value, and arm64 it is negative value as
// "tpbase" register has different purpose and pointer value per platform ABI.
Offset int16

// Multiplier is the TSD specific value array element size.
// Typically 8 bytes on 64bit musl and 16 bytes on 64bit glibc
Multiplier uint8

// Indirect is a flag indicating if the "tpbase + Offset" points to a member
// which is a pointer the array (musl) and not the array itself (glibc).
Indirect uint8
}

// This code analyzes the C-library provided POSIX defined function which is used
// to read thread-specific data (TSD):
// void *pthread_getspecific(pthread_key_t key);
Expand Down Expand Up @@ -97,21 +82,21 @@ func ExtractLibcInfo(ef *pfelf.File) (*LibcInfo, error) {
}

return &LibcInfo{
TSDInfo: *tsdinfo,
TSDInfo: tsdinfo,
}, nil
}

// ExtractTSDInfo extracts the introspection data for pthread thread specific data.
func extractTSDInfo(ef *pfelf.File) (*TSDInfo, error) {
// extractTSDInfo extracts the introspection data for pthread thread specific data.
func extractTSDInfo(ef *pfelf.File) (TSDInfo, error) {
_, code, err := ef.SymbolData("__pthread_getspecific", 2048)
if err != nil {
_, code, err = ef.SymbolData("pthread_getspecific", 2048)
if err != nil {
return nil, fmt.Errorf("unable to read 'pthread_getspecific': %s", err)
return TSDInfo{}, fmt.Errorf("unable to read 'pthread_getspecific': %s", err)
}
}
if len(code) < 8 {
return nil, fmt.Errorf("getspecific function size is %d", len(code))
return TSDInfo{}, fmt.Errorf("getspecific function size is %d", len(code))
}

var info TSDInfo
Expand All @@ -121,10 +106,10 @@ func extractTSDInfo(ef *pfelf.File) (*TSDInfo, error) {
case elf.EM_X86_64:
info, err = extractTSDInfoX86(code)
default:
return nil, fmt.Errorf("unsupported arch %s", ef.Machine.String())
return TSDInfo{}, fmt.Errorf("unsupported arch %s", ef.Machine.String())
}
if err != nil {
return nil, fmt.Errorf("failed to extract getspecific data: %s", err)
return TSDInfo{}, fmt.Errorf("failed to extract getspecific data: %s", err)
}
return &info, nil
return info, nil
}
9 changes: 9 additions & 0 deletions support/ebpf/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,17 @@ _Static_assert(sizeof(Frame) == 3 * 8, "frame padding not working as expected");

// TSDInfo contains data needed to extract Thread Specific Data (TSD) values
typedef struct TSDInfo {
// Offset is the pointer difference from "tpbase" pointer to the C-library
// specific struct pthread's member containing the thread specific data:
// .tsd (musl) or .specific (glibc).
// Note: on x86_64 it's positive value, and arm64 it is negative value as
// "tpbase" register has different purpose and pointer value per platform ABI.
s16 offset;
// Multiplier is the TSD specific value array element size.
// Typically 8 bytes on 64bit musl and 16 bytes on 64bit glibc
u8 multiplier;
// Indirect is a flag indicating if the "tpbase + Offset" points to a member
// which is a pointer the array (musl) and not the array itself (glibc).
u8 indirect;
} TSDInfo;

Expand Down