SHD-WebsiteFingerprintingLab/part3/worker.js

51 lines
1.3 KiB
JavaScript
Raw Permalink Normal View History

2024-11-02 12:50:02 +00:00
const N= 393216; // Number of cache lines 24MB/64B
2023-08-17 02:19:15 +00:00
// Number of sweep counts
2024-02-01 21:12:05 +00:00
// TODO (Exercise 3-1): Choose an appropriate value!
2024-11-02 12:50:02 +00:00
let P = 10;
2023-01-31 20:06:27 +00:00
2023-08-17 02:19:15 +00:00
// Number of elements in your trace
let K = 5 * 1000 / P;
// Array of length K with your trace's values
2023-01-31 20:06:27 +00:00
let T;
// Value of performance.now() when you started recording your trace
let start;
function record() {
2024-11-02 12:50:02 +00:00
2023-01-31 20:06:27 +00:00
// Create empty array for saving trace values
2023-08-17 02:19:15 +00:00
T = new Array(K);
2023-01-31 20:06:27 +00:00
// Fill array with -1 so we can be sure memory is allocated
T.fill(-1, 0, T.length);
2024-11-02 12:50:02 +00:00
const LINE_SIZE = 8; // 64/sizeof(double) Note that js treats all numbers as double
const M = new Array(N * LINE_SIZE).fill(-1);
2023-01-31 20:06:27 +00:00
// Save start timestamp
start = performance.now();
2024-11-02 12:50:02 +00:00
for (let i = 0; i < K; i++) {
let count=0;
while (performance.now() - start < P*(i+1)) {
// sweep the cache
for (let j = 0; j < N; j++) {
// let val = M[j * LINE_SIZE];
}
count++;
}
T[i]=count;
}
2023-01-31 20:06:27 +00:00
2024-11-02 12:50:02 +00:00
// TODO (Exercise 2-1): Record data for 5 seconds and save values to T.
2023-01-31 20:06:27 +00:00
// Once done recording, send result to main thread
postMessage(JSON.stringify(T));
2024-11-02 12:50:02 +00:00
console.log(T);
2023-01-31 20:06:27 +00:00
}
// DO NOT MODIFY BELOW THIS LINE -- PROVIDED BY COURSE STAFF
self.onmessage = (e) => {
if (e.data.type === "start") {
setTimeout(record, 0);
}
};