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

Function MClock_parse_params

libCacheSim/cache/eviction/priv/MClock.c:423–475  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

421}
422
423static void MClock_parse_params(cache_t *cache,
424 const char *cache_specific_params) {
425 MClock_params_t *params = (MClock_params_t *)cache->eviction_params;
426 char *params_str = strdup(cache_specific_params);
427 char *old_params_str = params_str;
428 char *end;
429
430 while (params_str != NULL && params_str[0] != '\0') {
431 /* different parameters are separated by comma,
432 * key and value are separated by = */
433 char *key = strsep((char **)&params_str, "=");
434 char *value = strsep((char **)&params_str, ",");
435
436 // skip the white space
437 while (params_str != NULL && *params_str == ' ') {
438 params_str++;
439 }
440
441 if (strcasecmp(key, "hand-pos") == 0) {
442 int n_hands = 0;
443#define MClock_MAX_N_HAND 16
444 double hand_pos[MClock_MAX_N_HAND];
445 char *v = strsep((char **)&value, ":");
446 while (v != NULL) {
447 hand_pos[n_hands++] = strtod(v, &end);
448 v = strsep((char **)&value, ":");
449 }
450 params->n_hands = n_hands;
451 if (params->hands != NULL) {
452 free(params->hands);
453 }
454 if (params->hand_pos != NULL) {
455 free(params->hand_pos);
456 }
457 params->hands = calloc(params->n_hands, sizeof(cache_obj_t *));
458 params->hand_pos = calloc(params->n_hands, sizeof(double));
459 for (int i = 0; i < n_hands; i++) {
460 params->hand_pos[i] = hand_pos[i];
461 }
462 assert(hand_pos[0] == 0);
463 assert(hand_pos[n_hands - 1] == 1);
464 } else if (strcasecmp(key, "n-consider-obj") == 0) {
465 params->n_consider_obj = (int)strtol(value, &end, 10);
466 } else if (strcasecmp(key, "print") == 0) {
467 printf("current parameters: %s\n", MClock_current_params(cache, params));
468 exit(0);
469 } else {
470 ERROR("%s does not have parameter %s\n", cache->cache_name, key);
471 exit(1);
472 }
473 }
474 free(old_params_str);
475}
476
477#ifdef __cplusplus
478}

Callers 1

MClock_initFunction · 0.85

Calls 2

assertFunction · 0.85
MClock_current_paramsFunction · 0.85

Tested by

no test coverage detected