Skip to content
Closed

test #305

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
12 changes: 12 additions & 0 deletions libCacheSim/bin/cachesim/cache_init.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ static inline cache_t *create_cache(const char *trace_path,
{"flashProb", flashProb_init},
{"gdsf", GDSF_init},
{"lhd", LHD_init},
{"lhd_compute", LHD_compute_init},
{"lecar", LeCaR_init},
{"lecarv0", LeCaRv0_init},
{"lfu", LFU_init},
Expand Down Expand Up @@ -146,6 +147,17 @@ static inline cache_t *create_cache(const char *trace_path,
}
cc_params.hashpower = MAX(cc_params.hashpower - 8, 16);
cache = BeladySize_init(cc_params, eviction_params);
} else if (strcasecmp(eviction_algo, "beladyCompute") == 0) {
if (strcasestr(trace_path, "oracleGeneral") == NULL &&
strcasestr(trace_path, "lcs") == NULL) {
WARN("beladyCompute is only supported for oracleGeneral and lcs trace\n");
WARN("to convert a trace to lcs format\n");
WARN("./bin/traceConv input_trace trace_format output_trace\n");
WARN("./bin/traceConv ../data/cloudPhysicsIO.txt txt\n");
exit(1);
}
cc_params.hashpower = MAX(cc_params.hashpower - 8, 16);
cache = BeladyCompute_init(cc_params, eviction_params);
} else {
ERROR("do not support algorithm %s\n", eviction_algo);
abort();
Expand Down
6 changes: 6 additions & 0 deletions libCacheSim/cache/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ set(eviction_sources_c
eviction/ARCv0.c # an inefficient version but easier to understand
eviction/Belady.c
eviction/BeladySize.c
eviction/BeladyCompute.c
eviction/CAR.c
eviction/Cacheus.c
eviction/Clock.c
Expand All @@ -51,6 +52,8 @@ set(eviction_sources_c
eviction/RandomLRU.c
eviction/RandomTwo.c
eviction/S3FIFO.c
eviction/S3FIFOSize.c
eviction/S3FIFOCompute.c
eviction/Sieve.c
eviction/Size.c
eviction/SLRU.c
Expand All @@ -75,8 +78,11 @@ set(eviction_sources_c
set(eviction_sources_cpp
eviction/cpp/LFU.cpp
eviction/cpp/GDSF.cpp
eviction/cpp/GDSF_compute.cpp
eviction/LHD/lhd.cpp
eviction/LHD/LHD_Interface.cpp
eviction/LHD/lhd_compute.cpp
eviction/LHD/LHD_compute_interface.cpp
)

# LRB
Expand Down
25 changes: 25 additions & 0 deletions libCacheSim/cache/cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,26 @@
extern "C" {
#endif

#ifdef RECORD_EVICTION_PROCESS
FILE *eviction_process_ofile = NULL;

void set_new_record_eviction_process_file(const char *ofilepath) {
if (eviction_process_ofile != NULL) {
fclose(eviction_process_ofile);
}
eviction_process_ofile = fopen(ofilepath, "w");
if (eviction_process_ofile == NULL) {
ERROR("cannot open eviction process file %s\n", ofilepath);
}
}

void print_eviction_debug_message(const char *msg) {
if (eviction_process_ofile != NULL) {
fprintf(eviction_process_ofile, "%s\n", msg);
}
}
#endif /* RECORD_EVICTION_PROCESS */
Comment on lines +14 to +32
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The RECORD_EVICTION_PROCESS feature uses a global file pointer eviction_process_ofile. This is not thread-safe. If multiple threads use the cache simulator simultaneously, they will race on this global variable, leading to corrupted output or crashes. Consider making this thread-local using __thread or protecting access with a mutex if multi-threaded use is intended.


/** this file contains both base function, which should be called by all
*eviction algorithms, and the queue related functions, which should be called
*by algorithm that uses only one queue and needs to update the queue such as
Expand Down Expand Up @@ -336,6 +356,11 @@ void cache_evict_base(cache_t *cache, cache_obj_t *obj,
*/
void cache_remove_obj_base(cache_t *cache, cache_obj_t *obj,
bool remove_from_hashtable) {
#ifdef RECORD_EVICTION_PROCESS
if (eviction_process_ofile != NULL) {
fprintf(eviction_process_ofile, "%ld\n", (long)obj->obj_id);
}
#endif /* RECORD_EVICTION_PROCESS */
DEBUG_ASSERT(cache->occupied_byte >= obj->obj_size + cache->obj_md_size);
cache->occupied_byte -= (obj->obj_size + cache->obj_md_size);
cache->n_obj -= 1;
Expand Down
Loading
Loading