MCPcopy Create free account
hub / github.com/1a1a11a/libCacheSim / SLRU_parse_params

Function SLRU_parse_params

libCacheSim/cache/eviction/SLRU.c:418–467  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

416}
417
418static void SLRU_parse_params(cache_t *cache,
419 const char *cache_specific_params) {
420 SLRU_params_t *params = (SLRU_params_t *)cache->eviction_params;
421 char *params_str = strdup(cache_specific_params);
422 char *old_params_str = params_str;
423 char *end;
424
425 while (params_str != NULL && params_str[0] != '\0') {
426 /* different parameters are separated by comma,
427 * key and value are separated by = */
428 char *key = strsep((char **)&params_str, "=");
429 char *value = strsep((char **)&params_str, ",");
430
431 // skip the white space
432 while (params_str != NULL && *params_str == ' ') {
433 params_str++;
434 }
435
436 if (strcasecmp(key, "n-seg") == 0) {
437 params->n_seg = (int)strtol(value, &end, 0);
438 if (strlen(end) > 2) {
439 ERROR("param parsing error, find string \"%s\" after number\n", end);
440 }
441 } else if (strcasecmp(key, "seg-size") == 0) {
442 int n_seg = 0;
443 int64_t seg_size_sum = 0;
444 int64_t seg_size_array[SLRU_MAX_N_SEG];
445 char *v = strsep((char **)&value, ":");
446 while (v != NULL) {
447 seg_size_array[n_seg++] = (int64_t)strtol(v, &end, 0);
448 seg_size_sum += seg_size_array[n_seg - 1];
449 v = strsep((char **)&value, ":");
450 }
451 params->n_seg = n_seg;
452 params->lru_max_n_bytes = calloc(params->n_seg, sizeof(int64_t));
453 for (int i = 0; i < n_seg; i++) {
454 params->lru_max_n_bytes[i] =
455 (int64_t)((double)seg_size_array[i] / seg_size_sum *
456 cache->cache_size);
457 }
458 } else if (strcasecmp(key, "print") == 0) {
459 printf("current parameters: %s\n", SLRU_current_params(cache, params));
460 exit(0);
461 } else {
462 ERROR("%s does not have parameter %s\n", cache->cache_name, key);
463 exit(1);
464 }
465 }
466 free(old_params_str);
467}
468
469// ***********************************************************************
470// **** ****

Callers 1

SLRU_initFunction · 0.85

Calls 1

SLRU_current_paramsFunction · 0.85

Tested by

no test coverage detected