Skip to content

Commit d833f41

Browse files
committed
Refactor: Rename variables to fix compiler error about "main" should not be used as a variable name
- Updated variable names in QDLP, S3FIFO, S3FIFOd, S3FIFOv0, WTinyLFU, and S3LRU eviction algorithms to improve code readability. - Changed 'fifo' to 'small_fifo' and 'main' to 'main_cache' for consistency across the codebase. - Ensured that all references to cache objects are clear and descriptive, enhancing maintainability.
1 parent c9f041e commit d833f41

6 files changed

Lines changed: 98 additions & 96 deletions

File tree

libCacheSim/cache/eviction/QDLP.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -331,25 +331,25 @@ static cache_obj_t *QDLP_to_evict(cache_t *cache, const request_t *req) {
331331
static void QDLP_evict(cache_t *cache, const request_t *req) {
332332
QDLP_params_t *params = (QDLP_params_t *)cache->eviction_params;
333333

334-
cache_t *fifo = params->fifo;
335-
cache_t *ghost = params->fifo_ghost;
336-
cache_t *main = params->main_cache;
334+
cache_t *small_fifo = params->fifo;
335+
cache_t *ghost_fifo = params->fifo_ghost;
336+
cache_t *main_cache = params->main_cache;
337337

338-
if (fifo->get_occupied_byte(fifo) == 0) {
338+
if (small_fifo->get_occupied_byte(small_fifo) == 0) {
339339
#if defined(TRACK_EVICTION_V_AGE)
340-
cache_obj_t *obj = main->to_evict(main, req);
340+
cache_obj_t *obj = main_cache->to_evict(main_cache, req);
341341
record_eviction_age(cache, obj, CURR_TIME(cache, req) - obj->create_time);
342342
#endif
343343

344-
assert(main->get_occupied_byte(main) <= cache->cache_size);
344+
assert(main_cache->get_occupied_byte(main_cache) <= cache->cache_size);
345345
// evict from main cache
346-
main->evict(main, req);
346+
main_cache->evict(main_cache, req);
347347

348348
return;
349349
}
350350

351351
// evict from FIFO
352-
cache_obj_t *obj = fifo->to_evict(fifo, req);
352+
cache_obj_t *obj = small_fifo->to_evict(small_fifo, req);
353353
assert(obj != NULL);
354354
// need to copy the object before it is evicted
355355
copy_cache_obj_to_request(params->req_local, obj);
@@ -361,21 +361,22 @@ static void QDLP_evict(cache_t *cache, const request_t *req) {
361361

362362
params->main_cache->get(params->main_cache, params->req_local);
363363
#if defined(TRACK_EVICTION_V_AGE)
364-
main->find(main, params->req_local, false)->create_time = obj->create_time;
364+
main_cache->find(main_cache, params->req_local, false)->create_time =
365+
obj->create_time;
365366
} else {
366367
record_eviction_age(cache, obj, CURR_TIME(cache, req) - obj->create_time);
367368
#else
368369
} else {
369370
#endif
370371
// insert to ghost
371-
if (ghost != NULL) {
372-
ghost->get(ghost, params->req_local);
372+
if (ghost_fifo != NULL) {
373+
ghost_fifo->get(ghost_fifo, params->req_local);
373374
}
374375
}
375376

376377
// remove from fifo, but do not update stat
377378
// bool removed = fifo->remove(fifo, params->req_local->obj_id);
378-
fifo->evict(fifo, req);
379+
small_fifo->evict(small_fifo, req);
379380
}
380381

381382
/**

libCacheSim/cache/eviction/S3FIFO.c

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -256,24 +256,24 @@ static cache_obj_t *S3FIFO_insert(cache_t *cache, const request_t *req) {
256256
S3FIFO_params_t *params = (S3FIFO_params_t *)cache->eviction_params;
257257
cache_obj_t *obj = NULL;
258258

259-
cache_t *small = params->small_fifo;
260-
cache_t *main = params->main_fifo;
259+
cache_t *small_fifo = params->small_fifo;
260+
cache_t *main_fifo = params->main_fifo;
261261

262262
if (params->hit_on_ghost) {
263263
/* insert into main FIFO */
264264
params->hit_on_ghost = false;
265-
obj = main->insert(main, req);
265+
obj = main_fifo->insert(main_fifo, req);
266266
} else {
267267
/* insert into small fifo */
268-
if (req->obj_size >= small->cache_size) {
268+
if (req->obj_size >= small_fifo->cache_size) {
269269
return NULL;
270270
}
271271

272272
if (!params->has_evicted &&
273-
small->get_occupied_byte(small) >= small->cache_size) {
274-
obj = main->insert(main, req);
273+
small_fifo->get_occupied_byte(small_fifo) >= small_fifo->cache_size) {
274+
obj = main_fifo->insert(main_fifo, req);
275275
} else {
276-
obj = small->insert(small, req);
276+
obj = small_fifo->insert(small_fifo, req);
277277
}
278278
}
279279

@@ -299,19 +299,19 @@ static cache_obj_t *S3FIFO_to_evict(cache_t *cache, const request_t *req) {
299299

300300
static void S3FIFO_evict_small(cache_t *cache, const request_t *req) {
301301
S3FIFO_params_t *params = (S3FIFO_params_t *)cache->eviction_params;
302-
cache_t *small = params->small_fifo;
302+
cache_t *small_fifo = params->small_fifo;
303303
cache_t *ghost = params->ghost_fifo;
304-
cache_t *main = params->main_fifo;
304+
cache_t *main_fifo = params->main_fifo;
305305

306306
bool has_evicted = false;
307-
while (!has_evicted && small->get_occupied_byte(small) > 0) {
308-
cache_obj_t *obj_to_evict = small->to_evict(small, req);
307+
while (!has_evicted && small_fifo->get_occupied_byte(small_fifo) > 0) {
308+
cache_obj_t *obj_to_evict = small_fifo->to_evict(small_fifo, req);
309309
DEBUG_ASSERT(obj_to_evict != NULL);
310310
// need to copy the object before it is evicted
311311
copy_cache_obj_to_request(params->req_local, obj_to_evict);
312312

313313
if (obj_to_evict->S3FIFO.freq >= params->move_to_main_threshold) {
314-
main->insert(main, params->req_local);
314+
main_fifo->insert(main_fifo, params->req_local);
315315
} else {
316316
// insert to ghost
317317
if (ghost != NULL) {
@@ -321,32 +321,32 @@ static void S3FIFO_evict_small(cache_t *cache, const request_t *req) {
321321
}
322322

323323
// remove from small fifo, but do not update stat
324-
bool removed = small->remove(small, params->req_local->obj_id);
324+
bool removed = small_fifo->remove(small_fifo, params->req_local->obj_id);
325325
DEBUG_ASSERT(removed);
326326
}
327327
}
328328

329329
static void S3FIFO_evict_main(cache_t *cache, const request_t *req) {
330330
S3FIFO_params_t *params = (S3FIFO_params_t *)cache->eviction_params;
331-
cache_t *main = params->main_fifo;
331+
cache_t *main_fifo = params->main_fifo;
332332

333333
bool has_evicted = false;
334-
while (!has_evicted && main->get_occupied_byte(main) > 0) {
335-
cache_obj_t *obj_to_evict = main->to_evict(main, req);
334+
while (!has_evicted && main_fifo->get_occupied_byte(main_fifo) > 0) {
335+
cache_obj_t *obj_to_evict = main_fifo->to_evict(main_fifo, req);
336336
DEBUG_ASSERT(obj_to_evict != NULL);
337337
int freq = obj_to_evict->S3FIFO.freq;
338338
copy_cache_obj_to_request(params->req_local, obj_to_evict);
339339
if (freq >= 1) {
340340
// we need to evict first because the object to insert has the same obj_id
341-
main->remove(main, obj_to_evict->obj_id);
341+
main_fifo->remove(main_fifo, obj_to_evict->obj_id);
342342
obj_to_evict = NULL;
343343

344-
cache_obj_t *new_obj = main->insert(main, params->req_local);
344+
cache_obj_t *new_obj = main_fifo->insert(main_fifo, params->req_local);
345345
// clock with 2-bit counter
346346
new_obj->S3FIFO.freq = MIN(freq, 3) - 1;
347347

348348
} else {
349-
bool removed = main->remove(main, obj_to_evict->obj_id);
349+
bool removed = main_fifo->remove(main_fifo, obj_to_evict->obj_id);
350350
DEBUG_ASSERT(removed);
351351

352352
has_evicted = true;
@@ -367,11 +367,11 @@ static void S3FIFO_evict(cache_t *cache, const request_t *req) {
367367
S3FIFO_params_t *params = (S3FIFO_params_t *)cache->eviction_params;
368368
params->has_evicted = true;
369369

370-
cache_t *small = params->small_fifo;
371-
cache_t *main = params->main_fifo;
370+
cache_t *small_fifo = params->small_fifo;
371+
cache_t *main_fifo = params->main_fifo;
372372

373-
if (main->get_occupied_byte(main) > main->cache_size ||
374-
small->get_occupied_byte(small) == 0) {
373+
if (main_fifo->get_occupied_byte(main_fifo) > main_fifo->cache_size ||
374+
small_fifo->get_occupied_byte(small_fifo) == 0) {
375375
S3FIFO_evict_main(cache, req);
376376
} else {
377377
S3FIFO_evict_small(cache, req);

libCacheSim/cache/eviction/S3FIFOd.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -399,50 +399,50 @@ static cache_obj_t *S3FIFOd_to_evict(cache_t *cache, const request_t *req) {
399399
static void S3FIFOd_evict(cache_t *cache, const request_t *req) {
400400
S3FIFOd_params_t *params = (S3FIFOd_params_t *)cache->eviction_params;
401401

402-
cache_t *fifo = params->fifo;
402+
cache_t *small_fifo = params->fifo;
403403
cache_t *ghost = params->fifo_ghost;
404-
cache_t *main = params->main_cache;
404+
cache_t *main_cache = params->main_cache;
405405

406-
if (fifo->get_occupied_byte(fifo) == 0) {
407-
assert(main->get_occupied_byte(main) <= cache->cache_size);
406+
if (small_fifo->get_occupied_byte(small_fifo) == 0) {
407+
assert(main_cache->get_occupied_byte(main_cache) <= cache->cache_size);
408408
// evict from main cache
409-
cache_obj_t *obj = main->to_evict(main, req);
409+
cache_obj_t *obj = main_cache->to_evict(main_cache, req);
410410
#if defined(TRACK_EVICTION_V_AGE)
411411
record_eviction_age(cache, obj, CURR_TIME(cache, req) - obj->create_time);
412412
#endif
413413
copy_cache_obj_to_request(params->req_local, obj);
414414
params->main_cache_eviction->get(params->main_cache_eviction,
415415
params->req_local);
416-
main->evict(main, req);
416+
main_cache->evict(main_cache, req);
417417
return;
418418
}
419419

420420
// evict from FIFO
421-
cache_obj_t *obj = fifo->to_evict(fifo, req);
421+
cache_obj_t *obj = small_fifo->to_evict(small_fifo, req);
422422
assert(obj != NULL);
423423
// need to copy the object before it is evicted
424424
copy_cache_obj_to_request(params->req_local, obj);
425425

426426
#if defined(TRACK_EVICTION_V_AGE)
427427
if (obj->misc.freq >= params->move_to_main_threshold) {
428428
// promote to main cache
429-
cache_obj_t *new_obj = main->insert(main, params->req_local);
429+
cache_obj_t *new_obj = main_cache->insert(main_cache, params->req_local);
430430
new_obj->create_time = obj->create_time;
431431
// evict from fifo, must be after copy eviction age
432-
bool removed = fifo->remove(fifo, params->req_local->obj_id);
432+
bool removed = small_fifo->remove(small_fifo, params->req_local->obj_id);
433433
assert(removed);
434434

435-
while (main->get_occupied_byte(main) > main->cache_size) {
435+
while (main_cache->get_occupied_byte(main_cache) > main_cache->cache_size) {
436436
// evict from main cache
437-
obj = main->to_evict(main, req);
437+
obj = main_cache->to_evict(main_cache, req);
438438
copy_cache_obj_to_request(params->req_local, obj);
439439
params->main_cache_eviction->get(params->main_cache_eviction,
440440
params->req_local);
441-
main->evict(main, req);
441+
main_cache->evict(main_cache, req);
442442
}
443443
} else {
444444
// evict from fifo, must be after copy eviction age
445-
bool removed = fifo->remove(fifo, params->req_local->obj_id);
445+
bool removed = small_fifo->remove(small_fifo, params->req_local->obj_id);
446446
assert(removed);
447447

448448
record_eviction_age(cache, obj, CURR_TIME(cache, req) - obj->create_time);
@@ -453,20 +453,20 @@ static void S3FIFOd_evict(cache_t *cache, const request_t *req) {
453453

454454
#else
455455
// evict from fifo
456-
bool removed = fifo->remove(fifo, params->req_local->obj_id);
456+
bool removed = small_fifo->remove(small_fifo, params->req_local->obj_id);
457457
assert(removed);
458458

459459
if (obj->misc.freq >= params->move_to_main_threshold) {
460460
// promote to main cache
461-
main->insert(main, params->req_local);
461+
main_cache->insert(main_cache, params->req_local);
462462

463-
while (main->get_occupied_byte(main) > main->cache_size) {
463+
while (main_cache->get_occupied_byte(main_cache) > main_cache->cache_size) {
464464
// evict from main cache
465-
obj = main->to_evict(main, req);
465+
obj = main_cache->to_evict(main_cache, req);
466466
copy_cache_obj_to_request(params->req_local, obj);
467467
params->main_cache_eviction->get(params->main_cache_eviction,
468468
params->req_local);
469-
main->evict(main, req);
469+
main_cache->evict(main_cache, req);
470470
}
471471
} else {
472472
// insert to ghost

0 commit comments

Comments
 (0)