Skip to content

Commit

Permalink
o code cleanup in jit.c
Browse files Browse the repository at this point in the history
o additional error checking for rusage_get_current() in resource.c
  • Loading branch information
Mike Miller committed Nov 12, 2023
1 parent 49c9d14 commit f614a44
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
7 changes: 0 additions & 7 deletions jit/jit.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ struct jit *jit_new(struct mmu *mmu) {
return jit;
}



void jit_free(struct jit *jit) {
bool signal_pending = !!(current->pending & ~current->blocked);
while((critical_region_count(current) > 2) || (locks_held_count(current)) || (current->process_info_being_read) || (signal_pending)) { // Wait for now, task is in one or more critical sections, and/or has locks, or signals in flight
Expand Down Expand Up @@ -166,21 +164,16 @@ static void jit_block_disconnect(struct jit *jit, struct jit_block *block) {
}
list_remove(&block->chain);
for (int i = 0; i <= 1; i++) {
////modify_critical_region_counter(current, 1, __FILE__, __LINE__);
list_remove(&block->page[i]);
list_remove_safe(&block->jumps_from_links[i]);
////modify_critical_region_counter(current, -1, __FILE__, __LINE__);

struct jit_block *prev_block, *tmp;

////modify_critical_region_counter(current, 1, __FILE__, __LINE__);
list_for_each_entry_safe(&block->jumps_from[i], prev_block, tmp, jumps_from_links[i]) {
if (prev_block->jump_ip[i] != NULL)
*prev_block->jump_ip[i] = prev_block->old_jump_ip[i]; // Crashed here June 12 2022, 19 Nov 2022
list_remove(&prev_block->jumps_from_links[i]);
}

////modify_critical_region_counter(current, -1, __FILE__, __LINE__);
}
}

Expand Down
21 changes: 14 additions & 7 deletions kernel/resource.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,31 +137,38 @@ dword_t sys_prlimit64(pid_t_ pid, dword_t resource, addr_t new_limit_addr, addr_
return 0;
}

struct rusage_ rusage_get_current() {
// only the time fields are currently implemented
struct rusage_ rusage_get_current(void) {
struct rusage_ rusage;
////modify_critical_region_counter(current, 1, __FILE__, __LINE__);
memset(&rusage, 0, sizeof(rusage));

#if __linux__
struct rusage usage;
int err = getrusage(RUSAGE_THREAD, &usage);
assert(err == 0);
if (getrusage(RUSAGE_THREAD, &usage) != 0) {
// Handle error appropriately, e.g., log an error or set default values
perror("getrusage failed");
return rusage;
}
rusage.utime.sec = usage.ru_utime.tv_sec;
rusage.utime.usec = usage.ru_utime.tv_usec;
rusage.stime.sec = usage.ru_stime.tv_sec;
rusage.stime.usec = usage.ru_stime.tv_usec;
#elif __APPLE__
thread_basic_info_data_t info;
mach_msg_type_number_t count = THREAD_BASIC_INFO_COUNT;
thread_info(mach_thread_self(), THREAD_BASIC_INFO, (thread_info_t) &info, &count);
if (thread_info(mach_thread_self(), THREAD_BASIC_INFO, (thread_info_t) &info, &count) != KERN_SUCCESS) {
// Handle error appropriately
printk("ERROR: thread_info failed (rusage_get_current()\n");
return rusage;
}
rusage.utime.sec = info.user_time.seconds;
rusage.utime.usec = info.user_time.microseconds;
rusage.stime.sec = info.system_time.seconds;
rusage.stime.usec = info.system_time.microseconds;
#endif
////modify_critical_region_counter(current, -1, __FILE__, __LINE__);
return rusage;
}


static void timeval_add(struct timeval_ *dst, struct timeval_ *src) {
dst->sec += src->sec;
dst->usec += src->usec;
Expand Down

0 comments on commit f614a44

Please sign in to comment.