-
Notifications
You must be signed in to change notification settings - Fork 64
Remove GLib dependency within bin/ #184
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
base: develop
Are you sure you want to change the base?
Conversation
This commit is the first in a series of commits to remove gLib. This commit moves an unused thread pool library within traceAnalyzer to the utils directory, which may find its use elsewhere.
This reverts commit 1155efd.
This commit is the first in series (ignoring reverted) to remove gLib. This commit introduces [hashmap.h](https://github.com/sheredom/hashmap.h) in an effort to remove GHashTable dependencies from the project. Future commits shall introduce similar header-only libs as well.
just FYI, it might be better to start with a small PR :) |
Thanks for the suggestion. So let's begin with something like "remove GLib dependency from main executable" first? Since gLib usage within the algo part is more extensive and complicated, maybe I shall get rid of GLib in BTW the quality gate check is complaining about duplicated code on |
Move from GThreadPool to a homebrewed threadpool adapted from https://nachtimwald.com/2019/04/12/thread-pool-in-c Note that this code **only** runs with UBSan enabled. Not for production use (yet).
Sounds good! |
Finalize move from GThreadPool to a homebrewed threadpool adapted from https://nachtimwald.com/2019/04/12/thread-pool-in-c Note, that simulation results differ from original. Reason for this is under investigation.
@1a1a11a Hi! I would say that this PR is near finished. In the meantime, I'm observing an at-most 1% difference in simulation results for some algorithms (e.g. FIFO) with Right now sanitizers are not throwing any useful error, and vvverbose logs look good as well. Since PS: that |
loop in @JasonGuo98 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR is focused on removing GLib dependencies in favor of using native pthreads and custom data structures. Key changes include replacing GLib’s GMutex, GThreadPool, and GHashTable with pthread-based synchronization primitives and custom thread pool/hashmap implementations, as well as updating include paths and launch configurations.
Reviewed Changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
libCacheSim/traceReader/reader.c | Replace non-thread safe boolean flag with a volatile qualifier |
libCacheSim/profiler/threadpool.c | Introduce custom threadpool implementation adapted from external source |
libCacheSim/profiler/simulator.c | Replace GThreadPool and GMutex with pthread equivalents and update index conversion |
libCacheSim/profiler/profilerLRU.c | Switch from g_hash_table to custom hashmap functions |
libCacheSim/profiler/dist.c | Replace GLib hash table calls with custom hashmap functions |
libCacheSim/include/libCacheSim/threadpool.h | New header for threadpool API |
libCacheSim/include/libCacheSim/hashmap_defs.in | New header for hashmap definitions |
.vscode/launch.json | Updated executable path and arguments |
Did a quick test, it seems that the thread pool library that I'm quoting is problematic. I switched to a battle-tested thread pool library, and (from preliminary test results) the problem is gone :) Gotta do some git rebase afterwards...
Upd: seems more like a problem with simulation steps, rather than reader problem. Introduced with the latest commit. Overlooked the problem since TSan keeps reporting the other way. |
Add these two lines to respective functions in INFO("actual progress %d\n", progress);
INFO("actual num_of_caches %d\n", num_of_caches); Before commit af3ff57:
After commit af3ff57:
The logic of the original code says: while (progress < num_of_caches - 1) {
print_progress((double)progress / (double)(num_of_caches - 1) * 100);
}
Update: it is designed for purpose, my bad. Pushing a fix. Anyways, marking this PR as ready for review. |
The previous commit af3ff57 introduced pthread_cond_t to synchronize progress. However, in some circumstances, the simulate_* functions may exit prematurely due to incorrect conditional wait. This commit fix the abovementioned problem.
Yes, you can add a separate section for data structures in doc |
Just noted that there seems to be a deadlock problem that I didn't notice while pushing. Trying to fix |
In Release builds, access to params->n_caches is optimized to a stack access. In Debug builds however, access is by pointer. Failure to initialize this leads to infinite loop in _simulate, thus deadlock in simulate_* functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[optional] it would be good to have a benchmark for hash table.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shall figure out a way to do so
Does it need to be a benchmark on libCacheSim, or a independent/use case-irrelevant benchmark?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An independent benchmark should be sufficient, and it would be good to compare with a common library, e.g., Glib, C++ std, or absl hashtable. BTW, I am also creating a new issue to build a performance test for libCacheSim.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
work in progress
@1a1a11a Where shall I put the benckmark? As a test program or just detail in the docs
@1a1a11a Sorry for not working this week, having some personal issues that I have to fix. Shall resume next week |
Includes comments cleanup, formatting issues, FIXME notes on conversion macros (in next commit), spelling, etc.
You can create a separate benchmark folder in the top directory, i.e., |
That makes sense considering that you want to add benchmark to the simulator. |
Shall I take a look? |
Yeah I consider this PR "finished" (except for the benchmark part) |
@haochengxia Can you take a look at this PR? |
|
@@ -85,7 +91,7 @@ int64_t get_stack_dist_add_req(const request_t *req, sTree **splay_tree, | |||
newtree = insert(curr_ts, *splay_tree); | |||
} else { | |||
// not first time access |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When converting a pointer to an integer, can we use int64_t old_ts = (int64_t)(uintptr_t)gp;
to avoid potential issues across archs?
BTW, as we removed glib, is gp
still a good variable name?
#define cptr_t_ const void* | ||
|
||
// platform-depedent | ||
#define ptr_size_t_ size_t |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is now quite good, and I recommend using stdint.h
for robustness and readability.
e.g.,
#define ptr_uintptr_t_ uintptr_t
#define ptr_intptr_t_ intptr_t
#define int_to_ptr(i) (ptr_t_)((ptr_intptr_t_)i)
#define uint_to_ptr(i) (ptr_t_)((ptr_uintptr_t_)i)
#define int_to_cptr(i) (cptr_t_)((ptr_intptr_t_)i)
#define uint_to_cptr(i) (cptr_t_)((ptr_uintptr_t_)i)
#define ptr_to_int(p) (int)((ptr_intptr_t_)p)
#define ptr_to_uint(p) (unsigned int)((ptr_uintptr_t_)p)
...
#include "../include/libCacheSim/profilerLRU.h" | ||
|
||
#include "../dataStructure/splay.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can preserve the order of header files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to preserve the order, but the current order is determined by clang-format
.
@haochengxia Thanks for the code suggestions. |
See #133.