Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: macOS feasibility incorporation #71

Open
wants to merge 34 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
202638b
feat: added macro-benchmarking notebook of probe
saleha-muzammil Nov 1, 2024
c89bd06
feat: macOS feasibility incorporation
saleha-muzammil Nov 3, 2024
23a0200
Update flake.nix
saleha-muzammil Nov 3, 2024
2828dad
refactor: separate headers for macOS and linux
saleha-muzammil Nov 8, 2024
3d47beb
refactor: remove unnecessary changes
saleha-muzammil Nov 8, 2024
a5178aa
Update interpose.c
saleha-muzammil Nov 8, 2024
cf3bda8
Update test_program.c
saleha-muzammil Nov 8, 2024
a3289c3
Help with Linux only functions
charmoniumQ Nov 8, 2024
ed2a72f
Irrelevant changes for next PR
charmoniumQ Nov 8, 2024
bdb7047
refactor: modify rust for macOS compatibility
saleha-muzammil Nov 9, 2024
da236b1
refactor: aljendra fixes
saleha-muzammil Nov 10, 2024
30a6f7f
refactor: remove re-definitions
saleha-muzammil Nov 10, 2024
a265082
refactor: define thred_local
saleha-muzammil Nov 10, 2024
bef794d
refactor: remove redefinition
saleha-muzammil Nov 10, 2024
8e6aeb0
refactor: remove from
saleha-muzammil Nov 10, 2024
a7db307
Help with interposing C on mac
charmoniumQ Nov 19, 2024
17bdd38
refactor: moving interpose to lib
saleha-muzammil Nov 22, 2024
1093470
Fix regex
charmoniumQ Nov 22, 2024
528d1f7
Fix generator
charmoniumQ Nov 22, 2024
247a6b7
refactor: put linux only flags
saleha-muzammil Nov 22, 2024
e28ffcf
Fix generator
charmoniumQ Nov 22, 2024
6333485
refactor: fstat64
saleha-muzammil Nov 22, 2024
fa70174
Fix macos defines
charmoniumQ Nov 22, 2024
5b110c6
thread problem
saleha-muzammil Nov 22, 2024
1e9b75e
fix: using POSIX thread-specific data
saleha-muzammil Nov 23, 2024
b43735a
shifting to gcc instead of clang
Jan 27, 2025
ba7876f
Modifications for debugging __thread
charmoniumQ Jan 31, 2025
3601d2e
Modfiied for debugging
charmoniumQ Jan 31, 2025
bd2fbc2
Change ArenaDir to ArenaDir*
charmoniumQ Jan 31, 2025
94889f2
Push stuff
charmoniumQ Jan 31, 2025
445403f
long list implmentation
Feb 14, 2025
92152de
Update flake.nix
saleha-muzammil Feb 14, 2025
339dbb8
Update flake.nix
saleha-muzammil Feb 14, 2025
065d36f
Update flake.nix
saleha-muzammil Feb 14, 2025
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
95 changes: 73 additions & 22 deletions probe_src/libprobe/src/global_state.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,32 +188,83 @@ static int get_inodes_dirfd() {
return __inodes_dirfd;
}

static __thread struct ArenaDir* __op_arena = NULL;
static __thread struct ArenaDir* __data_arena = NULL;
static const size_t prov_log_arena_size = 64 * 1024;
static void init_log_arena() {
DEBUG("I AM IN INIT LOG ARENA");
DEBUG("__op_arena %p", __op_arena);
__op_arena = calloc(1, sizeof(struct ArenaDir));
DEBUG("Here2")
__data_arena = calloc(1, sizeof(struct ArenaDir));
DEBUG("__op_arena address: %p", __op_arena);
DEBUG("__data_arena address: %p", __data_arena);
assert(!arena_is_initialized(__op_arena));
DEBUG("FIRST ASSERTION PASSED");
assert(!arena_is_initialized(__data_arena));
DEBUG("Going to \"%s/%d/%d/%d\" (mkdir %d)", __probe_dir, getpid(), get_exec_epoch(), my_gettid(), true);


// for macOS

typedef struct {
struct ArenaDir* op_arena;
struct ArenaDir* data_arena;
} ThreadLocalData;

void init_log_arena(ThreadLocalData* tld);
static void ensure_process_initted() {
if (!__process_inited) {
__process_inited = true;

DEBUG("Initializing process");
init_function_pointers();
check_function_pointers();
init_process_global_state();

pthread_key_create(&tld_key, free);

__process_inited_done = true;
}
while (!__process_inited_done) {
sched_yield();
}

Comment on lines +203 to +218
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there may be a race if multiple threads try to init at the same. I think I specified the algorihtm incorrectly (slightly the first time). Here's what it should be:

if (is process inited) {
  if (test_and_set(is first thread)) {
      ... do your process initialization you have here
      is process initted = true;
   } else {
     // process is not initted, but someone else is already handling it.
     while (!process is inited) { sched_yield(); }
   }
}
// process is inited here. Yay!

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test_and_set should be replaced __sync_bool_compare_and_swap

DEBUG("Process newly or already initialized");
}

static bool ensure_thread_initted() {
ThreadLocalData* tld = (ThreadLocalData*)pthread_getspecific(tld_key);

if (tld == NULL) {
DEBUG("Initializing thread-local data");
tld = (ThreadLocalData*)malloc(sizeof(ThreadLocalData));
tld->op_arena = NULL;
tld->data_arena = NULL;

init_log_arena(tld);

pthread_setspecific(tld_key, tld);
return true;
}

return false;
}



static void init_log_arena(ThreadLocalData* tld) {
DEBUG("Initializing log arena for thread");

tld->op_arena = calloc(1, sizeof(struct ArenaDir));
tld->data_arena = calloc(1, sizeof(struct ArenaDir));

DEBUG("__op_arena address: %p", tld->op_arena);
DEBUG("__data_arena address: %p", tld->data_arena);

assert(!arena_is_initialized(tld->op_arena));
assert(!arena_is_initialized(tld->data_arena));

int thread_dirfd = mkdir_and_descend(get_epoch_dirfd(), NULL, my_gettid(), true, false);
EXPECT( == 0, arena_create(__op_arena, thread_dirfd, "ops", prov_log_arena_size));
EXPECT( == 0, arena_create(__data_arena, thread_dirfd, "data", prov_log_arena_size));
EXPECT( == 0, arena_create(tld->op_arena, thread_dirfd, "ops", prov_log_arena_size));
EXPECT( == 0, arena_create(tld->data_arena, thread_dirfd, "data", prov_log_arena_size));
}
static struct ArenaDir* get_op_arena() {
assert(arena_is_initialized(__op_arena));
return __op_arena;
struct ArenaDir* get_op_arena() {
ThreadLocalData* tld = (ThreadLocalData*)pthread_getspecific(tld_key);
assert(tld != NULL);
return tld->op_arena;
}
static struct ArenaDir* get_data_arena() {
assert(arena_is_initialized(__data_arena));
return __data_arena;

struct ArenaDir* get_data_arena() {
ThreadLocalData* tld = (ThreadLocalData*)pthread_getspecific(tld_key);
assert(tld != NULL);
return tld->data_arena;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion probe_src/libprobe/src/lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ static void reinit_process();
static void prov_log_disable();
static int get_exec_epoch_safe();
static bool __process_inited = false;

static bool __process_inited_done= false;
#define ENV_VAR_PREFIX "PROBE_"

#define PRIVATE_ENV_VAR_PREFIX "__PROBE_"
Expand Down