diff --git a/.gitignore b/.gitignore index e5e62afa..5f98b90a 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,4 @@ initrds hdd.img netdump.dat build-* +graph_kernel_deps.png diff --git a/gen_dep_graph.py b/gen_dep_graph.py new file mode 100755 index 00000000..f7c97a0a --- /dev/null +++ b/gen_dep_graph.py @@ -0,0 +1,71 @@ +#!/usr/bin/env python3 +# Generates a graph of the Kernel's init dependencies + +import os +import subprocess +from matplotlib import pyplot as plt +import networkx as nx +from networkx.drawing.nx_agraph import graphviz_layout + +path = os.path.abspath(__file__) +kernel_source = os.path.dirname(path) + '/kernel-src' + +routine_dependencies = {} + +lines = subprocess.Popen(['grep', '-R', 'INIT_ROUTINE_DEFINE(', kernel_source], stdout=subprocess.PIPE).stdout.readlines() + +for line in lines: + if b"#define" in line: + continue + + line = line.strip() + + junk, line = line.split(b'(') + + line = line.replace(b';', b'').replace(b')', b'') + + if line.count(b',') > 2: + name, flags, function, dependencies = line.split(b',', 3) + else: + # no dependencies + name, flags, function = line.split(b',', 2) + dependencies = b'' + + name = name.strip().decode('utf-8') + routine_dependencies[name] = [] + + dependencies = dependencies.split(b',') + + for dep in dependencies: + dep = dep.strip().decode('utf-8') + if dep == '': + continue + + routine_dependencies[name].insert(0, dep) + +for routine in routine_dependencies: + print("routine '", routine, "' has dependencies: ", end='', sep='') + dependencies = routine_dependencies[routine] + print(dependencies) + +# plot + +graph = nx.DiGraph() + +graph.add_nodes_from(routine_dependencies.keys()) + +edges = [] +for routine in routine_dependencies: + for dep in routine_dependencies[routine]: + edges.insert(0, (dep, routine)) + +graph.add_edges_from(edges) + +plt.figure(figsize=(20, 16)) + +pos = graphviz_layout(graph, prog='dot') +nx.draw(graph, pos, with_labels=True, node_size=3000) +plt.title("Kernel init dependencies") +plt.savefig('graph_kernel_deps.png') + +print("File saved in graph_kernel_deps.png") diff --git a/kernel-src/main.c b/kernel-src/main.c index fba17a5f..dd3560c3 100644 --- a/kernel-src/main.c +++ b/kernel-src/main.c @@ -9,11 +9,7 @@ static cpu_t bsp_cpu; -INIT_ROUTINE_DEFINE(bsp_early, - INIT_ROUTINE_FLAGS_PHONY, - NULL, - alloc, term, cpu - ); +INIT_ROUTINE_DEFINE(bsp_early, INIT_ROUTINE_FLAGS_PHONY, NULL, alloc, term, cpu); DEFINE_KERNEL_ARGUMENT(root, char *); DEFINE_KERNEL_ARGUMENT(rootfs, char *); diff --git a/kernel-src/mm/pmm.c b/kernel-src/mm/pmm.c index 45fa9c64..239eb771 100644 --- a/kernel-src/mm/pmm.c +++ b/kernel-src/mm/pmm.c @@ -267,10 +267,7 @@ void pmm_init() { MUTEX_INIT(&freelistmutex); } -INIT_ROUTINE_DEFINE(pmm, - INIT_ROUTINE_FLAGS_NONE, - pmm_init, - arch_early); +INIT_ROUTINE_DEFINE(pmm, INIT_ROUTINE_FLAGS_NONE, pmm_init, arch_early); // XXX pmm_alloc won't be able to take pages from the page cache when the allocation size is over 1 page