equal
deleted
inserted
replaced
|
1 /* Title: Pure/System/numa.scala |
|
2 Author: Makarius |
|
3 |
|
4 Support for Non-Uniform Memory Access of separate CPU nodes. |
|
5 */ |
|
6 |
|
7 package isabelle |
|
8 |
|
9 |
|
10 object NUMA |
|
11 { |
|
12 /* available nodes */ |
|
13 |
|
14 def nodes(): List[Int] = |
|
15 { |
|
16 val numa_nodes_linux = Path.explode("/sys/devices/system/node/online") |
|
17 |
|
18 val Single = """^(\d+)$""".r |
|
19 val Multiple = """^(\d+)-(\d+)$""".r |
|
20 |
|
21 def read(s: String): List[Int] = |
|
22 s match { |
|
23 case Single(Value.Int(i)) => List(i) |
|
24 case Multiple(Value.Int(i), Value.Int(j)) => (i to j).toList |
|
25 case _ => error("Cannot parse CPU node specification: " + quote(s)) |
|
26 } |
|
27 |
|
28 if (numa_nodes_linux.is_file) { |
|
29 Library.space_explode(',', Library.trim_line(File.read(numa_nodes_linux))).flatMap(read(_)) |
|
30 } |
|
31 else Nil |
|
32 } |
|
33 |
|
34 |
|
35 /* CPU policy via numactl tool */ |
|
36 |
|
37 lazy val numactl_available: Boolean = Isabelle_System.bash("numactl --hardware").ok |
|
38 |
|
39 def policy(node: Int): String = |
|
40 if (numactl_available) "numactl -m" + node + " -N" + node else "" |
|
41 } |