MCPcopy Create free account
hub / github.com/cvut/qtrvsim / configure_cache

Function configure_cache

src/cli/main.cpp:92–147  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

90}
91
92void configure_cache(CacheConfig &cacheconf, const QStringList &cachearg, const QString &which) {
93 if (cachearg.empty()) { return; }
94 cacheconf.set_enabled(true);
95 QStringList pieces = cachearg.at(cachearg.size() - 1).split(",");
96 if (pieces.size() < 3) {
97 fprintf(
98 stderr, "Parameters %s cache incorrect (correct lru,4,2,2,wb).\n", qPrintable(which));
99 exit(EXIT_FAILURE);
100 }
101 if (pieces.at(0).size() < 1) {
102 fprintf(stderr, "Policy for %s cache is incorrect.\n", qPrintable(which));
103 exit(EXIT_FAILURE);
104 }
105 if (!pieces.at(0).at(0).isDigit()) {
106 if (pieces.at(0).toLower() == "random") {
107 cacheconf.set_replacement_policy(CacheConfig::RP_RAND);
108 } else if (pieces.at(0).toLower() == "lru") {
109 cacheconf.set_replacement_policy(CacheConfig::RP_LRU);
110 } else if (pieces.at(0).toLower() == "lfu") {
111 cacheconf.set_replacement_policy(CacheConfig::RP_LFU);
112 } else {
113 fprintf(stderr, "Policy for %s cache is incorrect.\n", qPrintable(which));
114 exit(EXIT_FAILURE);
115 }
116 pieces.removeFirst();
117 }
118 if (pieces.size() < 3) {
119 fprintf(
120 stderr, "Parameters for %s cache incorrect (correct lru,4,2,2,wb). \n",
121 qPrintable(which));
122 exit(EXIT_FAILURE);
123 }
124 cacheconf.set_set_count(pieces.at(0).toLong());
125 cacheconf.set_block_size(pieces.at(1).toLong());
126 cacheconf.set_associativity(pieces.at(2).toLong());
127 if (cacheconf.set_count() == 0 || cacheconf.block_size() == 0
128 || cacheconf.associativity() == 0) {
129 fprintf(
130 stderr, "Parameters for %s cache cannot have zero component. \n", qPrintable(which));
131 exit(EXIT_FAILURE);
132 }
133 if (pieces.size() > 3) {
134 if (pieces.at(3).toLower() == "wb") {
135 cacheconf.set_write_policy(CacheConfig::WP_BACK);
136 } else if (pieces.at(3).toLower() == "wt" || pieces.at(3).toLower() == "wtna") {
137 cacheconf.set_write_policy(CacheConfig::WP_THROUGH_NOALLOC);
138 } else if (pieces.at(3).toLower() == "wta") {
139 cacheconf.set_write_policy(CacheConfig::WP_THROUGH_ALLOC);
140 } else {
141 fprintf(
142 stderr, "Write policy for %s cache is incorrect (correct wb/wt/wtna/wta). \n",
143 qPrintable(which));
144 exit(EXIT_FAILURE);
145 }
146 }
147}
148
149void parse_u32_option(

Callers 1

configure_machineFunction · 0.85

Calls 12

emptyMethod · 0.80
set_enabledMethod · 0.80
set_set_countMethod · 0.80
set_block_sizeMethod · 0.80
set_associativityMethod · 0.80
set_countMethod · 0.80
block_sizeMethod · 0.80
associativityMethod · 0.80
set_write_policyMethod · 0.80
atMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected