Tidy up the threading implementation

The organization of the source files is now much more rational.
Old experiments that didn't work out are now deleted. Naming of
things like files is now more intuitive.
This commit is contained in:
Justine Tunney 2022-09-10 02:56:25 -07:00
parent e9272f03fb
commit 155b378a39
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
199 changed files with 526 additions and 685 deletions

View file

@ -23,13 +23,12 @@
#include "libc/intrin/kprintf.h"
#include "libc/intrin/nopl.h"
#include "libc/macros.internal.h"
#include "libc/nexgen32e/gettls.h"
#include "libc/nexgen32e/stackframe.h"
#include "libc/nexgen32e/threaded.h"
#include "libc/runtime/internal.h"
#include "libc/runtime/stack.h"
#include "libc/runtime/symbols.internal.h"
#include "libc/thread/thread.h"
#include "libc/thread/tls.h"
#include "libc/thread/tls2.h"
#define MAX_NESTING 512
@ -44,7 +43,7 @@
void ftrace_hook(void);
static int g_stackdigs;
static struct Ftrace g_ftrace;
static struct CosmoFtrace g_ftrace;
static privileged inline int GetNestingLevelImpl(struct StackFrame *frame) {
int nesting = -2;
@ -55,12 +54,12 @@ static privileged inline int GetNestingLevelImpl(struct StackFrame *frame) {
return MAX(0, nesting);
}
static privileged inline int GetNestingLevel(struct Ftrace *ft,
static privileged inline int GetNestingLevel(struct CosmoFtrace *ft,
struct StackFrame *sf) {
int nesting;
nesting = GetNestingLevelImpl(sf);
if (nesting < ft->skew) ft->skew = nesting;
nesting -= ft->skew;
if (nesting < ft->ft_skew) ft->ft_skew = nesting;
nesting -= ft->ft_skew;
return MIN(MAX_NESTING, nesting);
}
@ -73,27 +72,27 @@ static privileged inline int GetNestingLevel(struct Ftrace *ft,
*/
privileged void ftracer(void) {
long stackuse;
struct Ftrace *ft;
struct CosmoFtrace *ft;
struct StackFrame *sf;
if (__tls_enabled) {
ft = (struct Ftrace *)(__get_tls_privileged() + 0x08);
ft = &__get_tls_privileged()->tib_ftrace;
} else {
ft = &g_ftrace;
}
if (_cmpxchg(&ft->once, false, true)) {
ft->lastaddr = -1;
ft->skew = GetNestingLevelImpl(__builtin_frame_address(0));
if (_cmpxchg(&ft->ft_once, false, true)) {
ft->ft_lastaddr = -1;
ft->ft_skew = GetNestingLevelImpl(__builtin_frame_address(0));
}
if (_cmpxchg(&ft->noreentry, false, true)) {
if (_cmpxchg(&ft->ft_noreentry, false, true)) {
sf = __builtin_frame_address(0);
sf = sf->next;
if (sf->addr != ft->lastaddr) {
if (sf->addr != ft->ft_lastaddr) {
stackuse = GetStackAddr() + GetStackSize() - (intptr_t)sf;
kprintf("%rFUN %6P %'13T %'*ld %*s%t\n", g_stackdigs, stackuse,
GetNestingLevel(ft, sf) * 2, "", sf->addr);
ft->lastaddr = sf->addr;
ft->ft_lastaddr = sf->addr;
}
ft->noreentry = false;
ft->ft_noreentry = false;
}
}