This repository has been archived by the owner on Dec 2, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmeasure.rb
69 lines (57 loc) · 1.5 KB
/
measure.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/ruby
# -*- encoding: utf-8 -*-
$: << "ext/"
require "RHUtils"
require "pp"
require "json"
include RHUtils
# obf latency routine
def genseed(*bits)
$seed.map {|s|
pa = $base + s
pb = $base + bit_flip(s, *bits)
va = p2v($pages, pa)
vb = p2v($pages, pb)
[va, vb]
}
end
def latency(*bits)
genseed(*bits).count {|x| conflict?(*x) }
end
def access(*bits)
genseed(*bits).map {|x| access_time(*x) }
end
# -- 1. allocate memory
mb = (ARGV[0] || 2048).to_i
$pages = allocate_cap(mb)
$base = $pages[0].p
order = 63-bit_clz($pages.size)+12
puts "we can control the least #{order} bits of phys-addr"
# -- 2. generate very small seed (6) for quick measure
srand
$seed = Array.new(5) {rand(1 << order)}
# -- 3. measure latency
begin
$latency_map = {}
$access_map = {}
(1..2).each {|m|
(3...order).to_a.combination(m).each {|bits|
$access_map[bits] = access(*bits)
$latency_map[bits] = $access_map[bits].count {|x| x >= RHUtils.threshold}
puts "#{bits} => #{$access_map[bits]} => #{$latency_map[bits]}"
}
}
puts "---------------"
# -- 4. generate large seed (100) for precise measure
$seed = Array.new(100) {rand(1 << order)}
$latency_map.keys.select {|k| $latency_map[k] > 0 }.each {|k|
$latency_map[k] = latency(*k)
puts "#{k} => #{$latency_map[k]}"
}
rescue Interrupt
puts "Interrupted"
end
File.open("result_measure.txt", "w") {|f| f.puts JSON.dump($latency_map)}
# -- 4. cleanup
puts "cleanup..."
$pages.each &:release