Skip to content

Commit

Permalink
doc: deps: imgBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
xieby1 committed Nov 13, 2024
1 parent 256bf5d commit ac06621
Show file tree
Hide file tree
Showing 10 changed files with 138 additions and 33 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ backup*

# doc
book
*_dot.svg
*_py.dot
*_py.svg
4 changes: 4 additions & 0 deletions .vimrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
""" show existing tab with 2 spaces width
set tabstop=2
""" when indenting with '>', use 2 spaces width
set shiftwidth=2
9 changes: 7 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
doc: $(wildcard docs/*.md) docs/images/deps_dot.svg
.NOTINTERMEDIATE:

PYSVGs=$(subst _dot.py,_py.svg,$(shell find docs/ -name "*_dot.py"))
doc: $(wildcard docs/*.md) ${PYSVGs}
mdbook build

%_dot.svg: %.dot
%_py.dot: %_dot.py
python3 $<
%.svg: %.dot
dot -Tsvg $< -o $@
# css can only recognize intrinsic size in px
# https://developer.mozilla.org/en-US/docs/Glossary/Intrinsic_Size
Expand Down
23 changes: 0 additions & 23 deletions docs/images/deps.dot

This file was deleted.

113 changes: 113 additions & 0 deletions docs/images/deps_dot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
from pydot import Dot, Edge, Node, Graph, Cluster
class CCluster(Cluster): # Connectable Cluster
def __init__(self, *args, **kwargs):
Cluster.__init__(self, *args, **kwargs)
self._connect_node_ = addNode(self, "_connect_node_", label="",
shape="none", width=0, height=0, margin=0)

def addNode(g: Graph|CCluster, name, **args):
if "label" not in args: args["label"] = name
n = Node(g.get_name()+name, **args)
g.add_node(n)
return n
def addEdge(g: Graph, n1: Node|CCluster, n2: Node|CCluster, **args):
if isinstance(n1, CCluster): l = n1._connect_node_; args["ltail"] = n1.get_name()
else: l = n1
if isinstance(n2, CCluster): r = n2._connect_node_; args["lhead"] = n2.get_name()
else: r = n2
g.add_edge(Edge(l.get_name(), r.get_name(), **args))
def addCluster(g: Graph|CCluster, name, **args):
if "label" not in args: args["label"] = name
s=CCluster(g.get_name()+name, **args)
g.add_subgraph(s)
return s
def add(g: Graph, item: Node|Edge|Graph):
if isinstance(item, Node): g.add_node(item)
elif isinstance(item, Edge): g.add_edge(item)
elif isinstance(item, CCluster): g.add_subgraph(item)
return item
def Cluster_init(self, name, **args):
# args["cluster"] = True
if "label" not in args: args["label"] = name
CCluster.__init__(self, name, **args)

graph = Dot(label="Deterministic Checkpoint Dependency Graph", bgcolor="transparent", splines="line", compound=True)
graph.set_node_defaults(shape="box")
graph.set_edge_defaults(color="#00000044")


riscv64_cc = addNode(graph, "riscv64-cc")
riscv64_libc_static = addNode(graph, "riscv64-libc-static")
riscv64_fortran = addNode(graph, "riscv64-fortran")
riscv64_jemalloc = addNode(graph, "riscv64-jemalloc")

spec2006 = addCluster(graph, "spec2006", cluster=True)
checkpoints = addNode(graph, "checkpoints")

openblas = addNode(graph, "openblas")
checkpoints_openblas = addNode(graph, "checkpoints-openblas")

class ImgBuilder(CCluster):
class GCPT(CCluster):
class OpenSBI(CCluster):
class Linux(CCluster):
class InitRamFs(CCluster):
class Base(CCluster):
def __init__(self, **args):
Cluster_init(self, "base", **args)
self.gen_init_cpio = addNode(self, "gen_init_cpio")
self.cpio_list = addNode(self, "cpio_list")
class Overlays(CCluster):
def __init__(self, **args):
Cluster_init(self, "overlays", **args)
self.before_workload = addNode(self, "before_workload")
self.qemu_trap = addNode(self, "qemu_trap")
self.nemu_trap = addNode(self, "nemu_trap")
self.inittab = addNode(self, "inittab")
self.run_sh = addNode(self, "run_sh", label="run.sh")
def __init__(self, **args):
Cluster_init(self, "initramfs", **args)
self.base = self.Base(); add(self, self.base)
self.overlays = self.Overlays(); add(self, self.overlays)
def __init__(self, **args):
Cluster_init(self, "linux", **args)
self.initramfs = self.InitRamFs(); add(self, self.initramfs)
self.common_build = addNode(self, "common-build")
def __init__(self, **args):
Cluster_init(self, "opensbi", **args)
self.dts = addNode(self, "dts")
self.common_build = addNode(self, "common-build")
addEdge(self, self.dts, self.common_build)
self.linux = self.Linux(); add(self, self.linux)
def __init__(self, **args):
Cluster_init(self, "gcpt", **args)
self.opensbi = self.OpenSBI(); add(self, self.opensbi)
def __init__(self, **args):
Cluster_init(self, "imgBuilder", **args)
self.riscv64_cc = addNode(self, "riscv64-cc")
self.riscv64_libc_static = addNode(self, "riscv64-libc-static")
self.riscv64_busybox = addNode(self, "riscv64-busybox")
self.gcpt = self.GCPT(); add(self, self.gcpt)
addEdge(self, self.riscv64_cc, self.gcpt.opensbi.common_build)
addEdge(self, self.riscv64_cc, self.gcpt.opensbi.linux.common_build)
for i in (self.riscv64_cc, self.riscv64_libc_static):
overlays = self.gcpt.opensbi.linux.initramfs.overlays
for j in (overlays.before_workload, overlays.qemu_trap, overlays.nemu_trap):
addEdge(self, i, j)
addEdge(self, self.riscv64_busybox, self.gcpt.opensbi.linux.initramfs.overlays)
imgBuilder = ImgBuilder(); add(graph, imgBuilder)

pkgs = addNode(graph, "pkgs")
addEdge(graph, pkgs, imgBuilder.riscv64_cc)
addEdge(graph, pkgs, imgBuilder.riscv64_libc_static)
addEdge(graph, pkgs, imgBuilder.riscv64_busybox)

class Benchmark(CCluster):
def __init__(self, name, **args):
Cluster_init(self, name, **args)
self.run = addNode(self, "run")
benchmark = Benchmark("benchmark"); add(graph, benchmark)
addEdge(graph, benchmark.run, imgBuilder.gcpt.opensbi.linux.initramfs.overlays.run_sh)
addEdge(graph, benchmark, imgBuilder.gcpt.opensbi.linux.initramfs)

graph.write(__file__.replace("_dot.py", "_py.dot"))
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# 简介(Intro)

![](./images/deps_dot.svg)
![](./images/deps_py.svg)
4 changes: 2 additions & 2 deletions imgBuilder/linux/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
inherit benchmark;
};
# TODO: use overlayfs to reduce disk usage
linux-common-build = callPackage ./common-build.nix {inherit riscv64-cc;};
common-build = callPackage ./common-build.nix {inherit riscv64-cc;};
in stdenv.mkDerivation {
name = "${benchmark.name}.linux";
src = linux-common-build;
src = common-build;
buildInputs = [
bc
flex
Expand Down
4 changes: 2 additions & 2 deletions imgBuilder/linux/initramfs/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
}: let
cpioPatched = cpio.overrideAttrs (old: { patches = [./cpio_reset_timestamp.patch]; });
base = callPackage ./base {};
initramfs_overlays = callPackage ./overlays {
overlays = callPackage ./overlays {
inherit riscv64-cc riscv64-libc-static riscv64-busybox;
# TODO: check if `run` doest not exist, throw an error
benchmark-run = benchmark.run;
Expand All @@ -19,6 +19,6 @@ in runCommand "${benchmark.name}.cpio" {} ''
chmod +w $out
cd ${benchmark}
find . | sort -n | ${cpioPatched}/bin/cpio --reproducible -H newc -oAF $out
cd ${initramfs_overlays}
cd ${overlays}
find . | sort -n | ${cpioPatched}/bin/cpio --reproducible -H newc -oAF $out
''
4 changes: 2 additions & 2 deletions imgBuilder/opensbi/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
inherit benchmark;
};
dts = callPackage ./dts {};
opensbi-common-build = callPackage ./common-build.nix {inherit riscv64-cc dts;};
common-build = callPackage ./common-build.nix {inherit riscv64-cc dts;};
in stdenv.mkDerivation {
name = "${benchmark.name}.opensbi";

src = opensbi-common-build;
src = common-build;

buildInputs = [
python3
Expand Down
5 changes: 5 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
let
name = "deterministic_checkpoints";
pkgs = import <nixpkgs> {};
my-python3 = pkgs.python3.withPackages (python-pkgs: [
# for docs
python-pkgs.pydot
]);
h_content = builtins.toFile "h_content" ''
# ${pkgs.lib.toUpper "${name} usage tips"}
Expand All @@ -25,6 +29,7 @@ pkgs.mkShell {
pkgs.nix-output-monitor
pkgs.mdbook
pkgs.graphviz
my-python3
];
shellHook = ''
h
Expand Down

0 comments on commit ac06621

Please sign in to comment.