Skip to content

Commit 3afc068

Browse files
committed
experiment with pci
1 parent 57b3be2 commit 3afc068

File tree

4 files changed

+77
-1
lines changed

4 files changed

+77
-1
lines changed

Project.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
88
CEnum = "fa961155-64e5-5f13-b03f-caf6b980ea82"
99
CpuId = "adafc99b-e345-5852-983c-f28acb93d879"
1010
Sockets = "6462fe0b-24de-5631-8697-dd941f90decc"
11-
ThreadPools = "b189fb0b-2eb5-4ed4-bc0c-d34c51242431"
1211

1312
[compat]
13+
AbstractTrees = "0.4"
1414
CEnum = "0.4"
15+
CpuId = "0.3"

test/Project.toml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name = "NIC Test"
2+
uuid = "6f74fd91-2978-43ad-8164-3af8c0ec0142"
3+
authors = ["Johannes Blaschke <[email protected]>"]
4+
version = "0.1.0"
5+
6+
[deps]
7+
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
8+
CEnum = "fa961155-64e5-5f13-b03f-caf6b980ea82"
9+
CpuId = "adafc99b-e345-5852-983c-f28acb93d879"
10+
Sockets = "6462fe0b-24de-5631-8697-dd941f90decc"
11+
12+
[compat]
13+
AbstractTrees = "0.4"
14+
CEnum = "0.4"
15+
CpuId = "0.3"

test/get_pci.jl

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
using Hwloc, AbstractTrees
2+
3+
x = gettopology()
4+
t = HwlocTreeNode{UInt8}(x)
5+
6+
print_tree(t; maxdepth=10)
7+
8+
function distance_to_core!(node, target_index)
9+
# shield re-entrance when iterating
10+
node.tag = 1
11+
12+
if node.type == :Core
13+
if nodevalue(node).logical_index == target_index
14+
return true, 0
15+
end
16+
end
17+
18+
for child in node.children
19+
if child.tag == 1
20+
continue
21+
end
22+
23+
found, dist = distance_to_core!(child, target_index)
24+
if found
25+
return true, dist + 1
26+
end
27+
28+
end
29+
30+
if node.parent != nothing
31+
found, dist = distance_to_core!(node.parent, target_index)
32+
if found
33+
return true, dist + 1
34+
end
35+
end
36+
37+
return false, typemax(Int)
38+
end
39+
40+
function distance_to_core(root, node, target_index)
41+
Hwloc.tag_subtree!(t, 0)
42+
found, dist = distance_to_core!(node, target_index)
43+
Hwloc.tag_subtree!(t, 0)
44+
return found, dist
45+
end
46+
47+
pci_devs = Hwloc.get_nodes(t, :PCI_Device)
48+
49+
network_devs = filter(
50+
x->Hwloc.hwloc_pci_class_string(nodevalue(x).attr.class_id) == "Ethernet",
51+
pci_devs
52+
)
53+
54+
println(length(network_devs))
55+
56+
for net in collect(network_devs)
57+
found, dist = distance_to_core(t, net, 20)
58+
print("$(dist): ")
59+
print_tree(net)
60+
end

0 commit comments

Comments
 (0)