├── .github
├── dependabot.yml
└── workflows
│ ├── ci.yml
│ └── publish.yml
├── .gitignore
├── .gitmodules
├── .vscode
├── launch.json
└── settings.json
├── Cargo.lock
├── Cargo.toml
├── LICENSE-APACHE
├── LICENSE-MIT
├── README.md
├── benches
├── alloc
│ ├── Cargo.toml
│ └── src
│ │ └── main.rs
├── micro
│ ├── Cargo.toml
│ └── src
│ │ ├── benches
│ │ └── mod.rs
│ │ └── main.rs
├── multithreaded
│ ├── Cargo.toml
│ └── src
│ │ └── main.rs
├── mutex
│ ├── Cargo.toml
│ └── src
│ │ └── main.rs
├── netbench
│ ├── Cargo.toml
│ ├── LICENSE
│ ├── README.md
│ ├── run.sh
│ └── src
│ │ ├── config.rs
│ │ ├── connection.rs
│ │ ├── lib.rs
│ │ ├── print_utils.rs
│ │ ├── rust-tcp-bw
│ │ ├── client.rs
│ │ └── server.rs
│ │ ├── rust-tcp-latency
│ │ ├── client.rs
│ │ └── server.rs
│ │ ├── rust-udp-bw
│ │ ├── client.rs
│ │ └── server.rs
│ │ ├── rust-udp-latency
│ │ ├── client.rs
│ │ └── server.rs
│ │ └── threading.rs
└── startup
│ ├── Cargo.toml
│ └── src
│ └── main.rs
├── examples
├── axum
│ ├── Cargo.toml
│ └── src
│ │ └── main.rs
├── demo
│ ├── Cargo.toml
│ └── src
│ │ ├── fs.rs
│ │ ├── laplace.rs
│ │ ├── main.rs
│ │ ├── mandelbrot.rs
│ │ ├── matmul.rs
│ │ ├── pi.rs
│ │ └── thread.rs
├── dns
│ ├── Cargo.toml
│ └── src
│ │ └── main.rs
├── fuse_test
│ ├── Cargo.toml
│ └── src
│ │ └── main.rs
├── hello_world
│ ├── Cargo.toml
│ └── src
│ │ └── main.rs
├── hermit-wasm
│ ├── .gitignore
│ ├── Cargo.toml
│ ├── Makefile
│ ├── README.md
│ ├── build.rs
│ └── src
│ │ ├── arch
│ │ ├── aarch64
│ │ │ ├── longjmp.s
│ │ │ ├── mod.rs
│ │ │ └── setjmp.s
│ │ ├── mod.rs
│ │ ├── riscv64
│ │ │ ├── longjmp.s
│ │ │ ├── mod.rs
│ │ │ └── setjmp.s
│ │ └── x86_64
│ │ │ ├── longjmp.s
│ │ │ ├── mod.rs
│ │ │ └── setjmp.s
│ │ ├── capi.rs
│ │ ├── lib.rs
│ │ ├── main.rs
│ │ └── preview1.rs
├── httpd
│ ├── Cargo.toml
│ └── src
│ │ └── main.rs
├── miotcp
│ ├── Cargo.toml
│ └── src
│ │ └── main.rs
├── mioudp
│ ├── Cargo.toml
│ └── src
│ │ └── main.rs
├── polling
│ ├── Cargo.toml
│ └── src
│ │ └── main.rs
├── rftrace-example
│ ├── Cargo.toml
│ └── src
│ │ └── main.rs
├── testtcp
│ ├── Cargo.toml
│ └── src
│ │ └── main.rs
├── testudp
│ ├── Cargo.toml
│ └── src
│ │ └── main.rs
├── thread_test
│ ├── Cargo.toml
│ └── src
│ │ └── main.rs
├── tls
│ ├── Cargo.toml
│ └── src
│ │ ├── main.rs
│ │ ├── openssl.cnf
│ │ ├── refresh-certificates.sh
│ │ ├── sample.pem
│ │ └── sample.rsa
├── tokio
│ ├── Cargo.toml
│ └── src
│ │ └── main.rs
├── vsock
│ ├── Cargo.toml
│ └── src
│ │ ├── main.rs
│ │ └── vsock.rs
├── wasm-test
│ ├── Cargo.toml
│ └── src
│ │ └── main.rs
└── webserver
│ ├── Cargo.toml
│ └── src
│ └── main.rs
├── hermit-abi
├── Cargo.toml
├── LICENSE-APACHE
├── LICENSE-MIT
├── README.md
└── src
│ ├── errno.rs
│ └── lib.rs
├── hermit
├── Cargo.toml
├── LICENSE-APACHE
├── LICENSE-MIT
├── README.md
├── build.rs
└── src
│ ├── lib.rs
│ └── syscall
│ ├── allocator.rs
│ ├── math.rs
│ ├── mod.rs
│ └── x86_64.rs
├── k8s
└── httpd.yml
├── rust-toolchain.toml
└── rustfmt.toml
/.github/dependabot.yml:
--------------------------------------------------------------------------------
1 | # https://docs.github.com/en/code-security/supply-chain-security/keeping-your-dependencies-updated-automatically/configuration-options-for-dependency-updates
2 |
3 | version: 2
4 | updates:
5 | - package-ecosystem: "cargo"
6 | directory: "/"
7 | schedule:
8 | interval: "weekly"
9 | timezone: "Europe/Berlin"
10 | - package-ecosystem: "github-actions"
11 | directory: "/"
12 | schedule:
13 | interval: "weekly"
14 | timezone: "Europe/Berlin"
15 |
--------------------------------------------------------------------------------
/.github/workflows/ci.yml:
--------------------------------------------------------------------------------
1 | name: CI
2 |
3 | on:
4 | pull_request:
5 | merge_group:
6 |
7 | env:
8 | GH_TOKEN: ${{ github.token }}
9 | RUSTFLAGS: -Dwarnings
10 | RUSTDOCFLAGS: -Dwarnings
11 |
12 | jobs:
13 | clippy:
14 | name: Clippy
15 | runs-on: ubuntu-latest
16 | steps:
17 | - uses: actions/checkout@v4
18 | with:
19 | submodules: true
20 | - uses: dtolnay/rust-toolchain@nightly
21 | with:
22 | components: rust-src
23 | - uses: mkroening/rust-toolchain-toml@main
24 | - run: |
25 | rustup component add clippy llvm-tools
26 | rustup target add wasm32-wasip1
27 | - name: Clippy
28 | run: |
29 | cargo clippy --all-targets
30 | cargo clippy -Zbuild-std=std,panic_abort --target=x86_64-unknown-hermit --all-targets
31 | cargo clippy -Zbuild-std=std,panic_abort --target=aarch64-unknown-hermit --all-targets
32 | cargo clippy -Zbuild-std=std,panic_abort --target=riscv64gc-unknown-hermit --all-targets
33 | cargo clippy -Zbuild-std=std,panic_abort --target=x86_64-unknown-hermit --package hermit --features common-os
34 |
35 | format:
36 | name: Format
37 | runs-on: ubuntu-latest
38 | steps:
39 | - uses: actions/checkout@v4
40 | - uses: mkroening/rust-toolchain-toml@main
41 | - run: rustup component add rustfmt
42 | - name: Format
43 | run: cargo fmt -- --check
44 |
45 | check-docs:
46 | name: Check docs
47 | runs-on: ubuntu-latest
48 | steps:
49 | - uses: actions/checkout@v4
50 | with:
51 | submodules: true
52 | - uses: dtolnay/rust-toolchain@nightly
53 | with:
54 | components: rust-src
55 | - uses: mkroening/rust-toolchain-toml@main
56 | - run: |
57 | rustup component add llvm-tools
58 | rustup target add wasm32-wasip1
59 | - name: Check docs
60 | run: cargo doc --no-deps --document-private-items
61 |
62 | run-hermit:
63 | name: Run
64 | runs-on: ubuntu-latest
65 | defaults:
66 | run:
67 | working-directory: kernel
68 | strategy:
69 | matrix:
70 | arch: [x86_64, aarch64, riscv64]
71 | profile: [dev, release]
72 | include:
73 | - arch: x86_64
74 | packages: qemu-system-x86
75 | flags: --accel --sudo
76 | - arch: aarch64
77 | packages: qemu-system-aarch64
78 | - arch: riscv64
79 | packages: qemu-system-misc
80 | steps:
81 | - uses: actions/checkout@v4
82 | with:
83 | submodules: true
84 | - name: Install Packages
85 | run: |
86 | sudo apt-get update
87 | sudo apt-get install ${{ matrix.packages }}
88 | - uses: dtolnay/rust-toolchain@stable
89 | - run: echo "$CARGO_HOME/bin" >> "$GITHUB_PATH"
90 | - run: cargo +stable install --locked uhyve
91 | if: matrix.arch == 'x86_64'
92 | - name: Download loader
93 | run: gh release download --repo hermit-os/loader --pattern hermit-loader-${{ matrix.arch }}
94 | - name: Dowload OpenSBI
95 | if: matrix.arch == 'riscv64'
96 | run: |
97 | gh release download v1.6 --repo riscv-software-src/opensbi --pattern 'opensbi-*-rv-bin.tar.xz'
98 | tar -xvf opensbi-*-rv-bin.tar.xz opensbi-1.6-rv-bin/share/opensbi/lp64/generic/firmware/fw_jump.bin
99 | - uses: mkroening/rust-toolchain-toml@main
100 | - uses: mkroening/rust-toolchain-toml@main
101 | with:
102 | toolchain-file: 'kernel/rust-toolchain.toml'
103 | - uses: Swatinem/rust-cache@v2
104 | with:
105 | key: ${{ matrix.arch }}-${{ matrix.profile }}
106 | save-if: ${{ github.ref == 'refs/heads/main' }}
107 | workspaces: |
108 | .
109 | kernel
110 | kernel/hermit-builtins
111 | - run: cargo xtask ci rs --arch ${{ matrix.arch }} --profile ${{ matrix.profile }} --package rusty_demo qemu ${{ matrix.flags }}
112 | - run: cargo xtask ci rs --arch ${{ matrix.arch }} --profile ${{ matrix.profile }} --package httpd --features ci,hermit/dhcpv4 qemu ${{ matrix.flags }} --netdev virtio-net-pci
113 | if: matrix.arch != 'riscv64'
114 | - run: cargo xtask ci rs --arch ${{ matrix.arch }} --profile ${{ matrix.profile }} --package miotcp --features hermit/dhcpv4 qemu ${{ matrix.flags }} --netdev virtio-net-pci
115 | if: matrix.arch != 'riscv64'
116 | - run: cargo xtask ci rs --arch ${{ matrix.arch }} --profile ${{ matrix.profile }} --package mioudp --features hermit/udp,hermit/dhcpv4 qemu ${{ matrix.flags }} --netdev virtio-net-pci
117 | if: matrix.arch != 'riscv64'
118 | - run: UHYVE=$CARGO_HOME/bin/uhyve cargo xtask ci rs --arch ${{ matrix.arch }} --profile ${{ matrix.profile }} --package rusty_demo uhyve --sudo
119 | if: matrix.arch == 'x86_64'
120 |
--------------------------------------------------------------------------------
/.github/workflows/publish.yml:
--------------------------------------------------------------------------------
1 | name: Publish container image
2 |
3 | on:
4 | push:
5 | branches:
6 | - main
7 |
8 | env:
9 | GH_TOKEN: ${{ github.token }}
10 | CARGO_TERM_COLOR: always
11 |
12 | jobs:
13 | publish_image:
14 | name: Publish container image
15 | runs-on: ubuntu-latest
16 |
17 | steps:
18 | - uses: actions/checkout@v4
19 | with:
20 | submodules: true
21 | - name: Login to GitHub Container Registry
22 | uses: docker/login-action@v3
23 | with:
24 | registry: ghcr.io
25 | username: hermit-os
26 | password: ${{ secrets.GITHUB_TOKEN }}
27 | - name: Build demo
28 | run: cargo build -Zbuild-std=std,panic_abort --target x86_64-unknown-hermit -p rusty_demo --release
29 | - name: Copy demo out of target dir
30 | run: cp target/x86_64-unknown-hermit/release/rusty_demo .
31 | - name: Download loader
32 | run: |
33 | gh release download --repo hermit-os/loader --pattern hermit-loader-x86_64
34 | gh release download --repo hermit-os/loader --pattern hermit-loader-x86_64-fc
35 | - name: Create dockerfile for rusty_demo
36 | run: |
37 | cat << END > Dockerfile
38 | FROM ghcr.io/hermit-os/hermit_env:latest
39 | COPY hermit-loader-x86_64 hermit/hermit-loader
40 | COPY hermit-loader-x86_64-fc hermit/hermit-loader-fc
41 | COPY rusty_demo hermit/rusty_demo
42 | CMD ["/hermit/rusty_demo"]
43 | END
44 | - name: Build and push container
45 | uses: docker/build-push-action@v6
46 | with:
47 | context: .
48 | push: true
49 | tags: ghcr.io/hermit-os/rusty_demo:latest
50 | - name: Build httpd
51 | run: cargo build -Zbuild-std=std,panic_abort --target x86_64-unknown-hermit -p httpd --features hermit/dhcpv4 --release
52 | - name: Copy httpd out of target dir
53 | run: cp target/x86_64-unknown-hermit/release/httpd .
54 | - name: Create dockerfile for httpd
55 | run: |
56 | cat << END > Dockerfile
57 | FROM ghcr.io/hermit-os/hermit_env:latest
58 | COPY hermit-loader-x86_64 hermit/hermit-loader
59 | COPY hermit-loader-x86_64-fc hermit/hermit-loader-fc
60 | COPY httpd hermit/httpd
61 | CMD ["/hermit/httpd"]
62 | END
63 | - name: Build and push container
64 | uses: docker/build-push-action@v6
65 | with:
66 | context: .
67 | push: true
68 | tags: ghcr.io/hermit-os/httpd:latest
69 | - name: Create dockerfile for httpd (alpine)
70 | run: |
71 | cat << END > Dockerfile
72 | FROM ghcr.io/hermit-os/hermit_env_alpine:latest
73 | COPY hermit-loader-x86_64 hermit/hermit-loader
74 | COPY hermit-loader-x86_64-fc hermit/hermit-loader-fc
75 | COPY httpd hermit/httpd
76 | CMD ["/hermit/httpd"]
77 | END
78 | - name: Build and push container
79 | uses: docker/build-push-action@v6
80 | with:
81 | context: .
82 | push: true
83 | tags: ghcr.io/hermit-os/httpd_alpine:latest
84 | - name: Build webserver
85 | run: cargo build -Zbuild-std=std,panic_abort --target x86_64-unknown-hermit -p webserver --features hermit/dhcpv4,hermit/fs --release
86 | - name: Copy webserver out of target dir
87 | run: cp target/x86_64-unknown-hermit/release/webserver .
88 | - name: Create static website
89 | run: |
90 | mkdir -p root
91 | cat << END > root/index.html
92 |
93 |
94 |
95 | Hermit-OS
96 |
97 |
98 | Hello from Hermit-OS! 🦀
99 |
100 |
101 | END
102 | - name: Create dockerfile for webserver
103 | run: |
104 | cat << END > Dockerfile
105 | FROM ghcr.io/hermit-os/hermit_env:latest
106 | COPY root root
107 | COPY hermit-loader-x86_64 hermit/hermit-loader
108 | COPY hermit-loader-x86_64-fc hermit/hermit-loader-fc
109 | COPY webserver hermit/webserver
110 | CMD ["/hermit/webserver"]
111 | END
112 | - name: Build and push container
113 | uses: docker/build-push-action@v6
114 | with:
115 | context: .
116 | push: true
117 | tags: ghcr.io/hermit-os/webserver:latest
118 | - name: Build tls-demo
119 | run: cargo build -Zbuild-std=std,panic_abort --target x86_64-unknown-hermit -p tls --features hermit/dhcpv4 --release
120 | - name: Copy tls-demo out of target dir
121 | run: cp target/x86_64-unknown-hermit/release/tls .
122 | - name: Create dockerfile for tls-demo
123 | run: |
124 | cat << END > Dockerfile
125 | FROM ghcr.io/hermit-os/hermit_env:latest
126 | COPY hermit-loader-x86_64 hermit/hermit-loader
127 | COPY hermit-loader-x86_64-fc hermit/hermit-loader-fc
128 | COPY tls hermit/tls
129 | CMD ["/hermit/tls"]
130 | END
131 | - name: Build and push container
132 | uses: docker/build-push-action@v6
133 | with:
134 | context: .
135 | push: true
136 | tags: ghcr.io/hermit-os/tls:latest
137 | - name: Build axum
138 | run: cargo build -Zbuild-std=std,panic_abort --target x86_64-unknown-hermit -p axum-example --features hermit/dhcpv4,hermit/fs --release
139 | - name: Copy axum out of target dir
140 | run: cp target/x86_64-unknown-hermit/release/axum-example .
141 | - name: Create dockerfile for axum
142 | run: |
143 | cat << END > Dockerfile
144 | FROM ghcr.io/hermit-os/hermit_env:latest
145 | COPY hermit-loader-x86_64 hermit/hermit-loader
146 | COPY hermit-loader-x86_64-fc hermit/hermit-loader-fc
147 | COPY axum-example hermit/axum-example
148 | CMD ["/hermit/axum-example"]
149 | END
150 | - name: Build and push container
151 | uses: docker/build-push-action@v6
152 | with:
153 | context: .
154 | push: true
155 | tags: ghcr.io/hermit-os/axum-example:latest
156 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /target
2 |
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "kernel"]
2 | path = kernel
3 | url = https://github.com/hermit-os/kernel.git
4 |
--------------------------------------------------------------------------------
/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | // Use IntelliSense to learn about possible attributes.
3 | // Hover to view descriptions of existing attributes.
4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5 | "version": "0.2.0",
6 | "configurations": [
7 | {
8 | "type": "gdb",
9 | "request": "attach",
10 | "name": "Attach to gdbserver",
11 | "executable": "./target/x86_64-unknown-hermit/debug/rusty_demo",
12 | "target": "localhost:6677",
13 | "remote": true,
14 | "cwd": "${workspaceRoot}",
15 | "gdbpath": "/usr/local/Cellar/x86_64-elf-gdb/8.2/bin/x86_64-elf-gdb"
16 | }
17 | ]
18 | }
19 |
--------------------------------------------------------------------------------
/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | {
2 | "search.exclude": {
3 | "**/target": true
4 | "build": true
5 | },
6 | "lldb.verboseLogging": true,
7 | "rust-client.disableRustup": true,
8 | "rust.all_targets": false,
9 | "rust.target": "x86_64-unknown-hermit",
10 | }
11 |
--------------------------------------------------------------------------------
/Cargo.toml:
--------------------------------------------------------------------------------
1 | [workspace]
2 | resolver = "2"
3 | members = [
4 | "benches/alloc",
5 | "benches/micro",
6 | "benches/netbench",
7 | "benches/mutex",
8 | "benches/startup",
9 | "benches/multithreaded",
10 | "examples/axum",
11 | "examples/demo",
12 | "examples/fuse_test",
13 | "examples/hello_world",
14 | "examples/httpd",
15 | "examples/miotcp",
16 | "examples/mioudp",
17 | "examples/polling",
18 | "examples/rftrace-example",
19 | "examples/testtcp",
20 | "examples/testudp",
21 | "examples/tls",
22 | "examples/thread_test",
23 | "examples/tokio",
24 | "examples/webserver",
25 | "examples/dns",
26 | "examples/wasm-test",
27 | "examples/hermit-wasm",
28 | "examples/vsock",
29 | "hermit",
30 | "hermit-abi",
31 | ]
32 |
33 | [patch.crates-io]
34 | hyper-util = { git = "https://github.com/hermit-os/hyper-util.git", branch = "v/0.1.11" }
35 | socket2 = { git = "https://github.com/hermit-os/socket2.git", branch = "v0.5.x" }
36 | tokio = { git = "https://github.com/hermit-os/tokio.git", branch = "v/tokio-1.45.0" }
37 |
--------------------------------------------------------------------------------
/LICENSE-APACHE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/LICENSE-MIT:
--------------------------------------------------------------------------------
1 | Permission is hereby granted, free of charge, to any
2 | person obtaining a copy of this software and associated
3 | documentation files (the "Software"), to deal in the
4 | Software without restriction, including without
5 | limitation the rights to use, copy, modify, merge,
6 | publish, distribute, sublicense, and/or sell copies of
7 | the Software, and to permit persons to whom the Software
8 | is furnished to do so, subject to the following
9 | conditions:
10 |
11 | The above copyright notice and this permission notice
12 | shall be included in all copies or substantial portions
13 | of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
16 | ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
17 | TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
18 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
19 | SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
22 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 | DEALINGS IN THE SOFTWARE.
24 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | # Hermit for Rust
4 |
5 | A Rust-based, lightweight unikernel.
6 |
7 | [](https://hermit.zulipchat.com/)
8 |
9 | [Hermit](http://hermit-os.org) is a [unikernel](http://unikernel.org) targeting a scalable and predictable runtime for high-performance and cloud computing.
10 | Unikernel means, you bundle your application directly with the kernel library, so that it can run without any installed operating system.
11 | This reduces overhead, therefore, interesting applications include virtual machines and high-performance computing.
12 |
13 | The kernel is able to run [Rust](https://github.com/hermit-os/hermit-rs) applications, as well as [C/C++/Go/Fortran](https://github.com/hermit-os/hermit-playground) applications.
14 |
15 | The repository contains following directories and submodules:
16 |
17 | 1. _demo_ is a small demo application based on the data-parallelism library [Rayon](https://github.com/rayon-rs/rayon)
18 | 2. _hermit-abi_ contains the platform APIs and builds the interface between library operating system and the application
19 | 3. _hermit_ contains a crate to automate the build process of the library operating systems
20 | 4. _kernel_ is the kernel itself
21 | 5. _netbench_ provides some basic network benchmarks
22 |
23 | ## Background
24 |
25 | **Hermit** is a rewrite of HermitCore in [Rust](https://www.rust-lang.org) developed at [RWTH-Aachen](https://www.rwth-aachen.de).
26 | HermitCore was a research unikernel written in C ([libhermit](https://github.com/hermit-os/libhermit)).
27 |
28 | The ownership model of Rust guarantees memory/thread-safety and enables us to eliminate many classes of bugs at compile-time.
29 | Consequently, the use of Rust for kernel development promises fewer vulnerabilities in comparison to common programming languages.
30 |
31 | The kernel and the integration into the Rust runtime are entirely written in Rust and do not use any C/C++ Code.
32 | We extended the Rust toolchain so that the build process is similar to Rust's usual workflow.
33 | Rust applications that use the Rust runtime and do not directly use OS services are able to run on Hermit without modifications.
34 |
35 | ## Requirements
36 |
37 | * [`rustup`](https://www.rust-lang.org/tools/install)
38 |
39 | ## Building your own applications
40 |
41 | Have a look at [the template](https://github.com/hermit-os/hermit-rs-template).
42 |
43 |
44 | ## Use Hermit for C/C++, Go, and Fortran applications
45 |
46 | If you are interested to build C/C++, Go, and Fortran applications on top of a Rust-based library operating system, please take a look at [https://github.com/hermit-os/hermit-playground](https://github.com/hermit-os/hermit-playground).
47 |
48 | ## Wiki
49 |
50 | Please use the [Wiki](https://github.com/hermit-os/hermit-rs/wiki) to get further information and configuration options.
51 |
52 | ## Credits
53 |
54 | Hermit is derived from following tutorials and software distributions:
55 |
56 | 1. Philipp Oppermann's [excellent series of blog posts][opp].
57 | 2. Erik Kidd's [toyos-rs][kidd], which is an extension of Philipp Opermann's kernel.
58 | 3. The Rust-based teaching operating system [eduOS-rs][eduos].
59 |
60 | [opp]: http://blog.phil-opp.com/
61 | [kidd]: http://www.randomhacks.net/bare-metal-rust/
62 | [eduos]: http://rwth-os.github.io/eduOS-rs/
63 |
64 | ## License
65 |
66 | Licensed under either of
67 |
68 | * Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
69 | * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
70 |
71 | at your option.
72 |
73 | ## Contribution
74 |
75 | Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
76 |
77 | Hermit is being developed on [GitHub](https://github.com/hermit-os/hermit-rs).
78 | Create your own fork, send us a pull request, and chat with us on [Zulip](https://hermit.zulipchat.com/).
79 |
--------------------------------------------------------------------------------
/benches/alloc/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "alloc_benchmarks"
3 | authors = ["Stefan Lankes "]
4 | edition = "2021"
5 |
6 | [dependencies]
7 | fastrand = "2.0.0"
8 | hermit_bench_output = "0.1.0"
9 |
10 | [target.'cfg(target_os = "hermit")'.dependencies]
11 | hermit = { path = "../../hermit", default-features = false }
12 |
13 | [target.'cfg(target_arch = "riscv64")'.dependencies]
14 | riscv = "0.13"
15 |
16 | [features]
17 | default = ["hermit/acpi", "hermit/pci"]
18 |
--------------------------------------------------------------------------------
/benches/alloc/src/main.rs:
--------------------------------------------------------------------------------
1 | /*
2 | MIT License
3 |
4 | Copyright (c) 2022 Philipp Schuster
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in all
14 | copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | /* Heavily modified by Shaun Beautement. All errors are probably my own. */
26 |
27 | /*
28 | * This benchmark was revised for Hermit by Stefan Lankes.
29 | * The original code is part of the crate `talc`.
30 | */
31 |
32 | #![feature(slice_ptr_get)]
33 |
34 | use std::alloc::{alloc, dealloc, Layout};
35 | use std::time::Instant;
36 |
37 | #[cfg(target_os = "hermit")]
38 | use hermit as _;
39 | use hermit_bench_output::log_benchmark_data;
40 |
41 | const BENCH_DURATION: f64 = 3.0;
42 |
43 | fn main() {
44 | let bench_alloc = benchmark_allocator();
45 | print_bench_results(&bench_alloc);
46 | }
47 |
48 | /// Result of a bench run.
49 | struct BenchRunResults {
50 | allocation_attempts: usize,
51 | successful_allocations: usize,
52 | pre_fail_allocations: usize,
53 | deallocations: usize,
54 |
55 | /// Sorted vector of the amount of clock ticks per successful allocation.
56 | all_alloc_measurements: Vec,
57 | /// Sorted vector of the amount of clock ticks per successful allocation under heap pressure.
58 | nofail_alloc_measurements: Vec,
59 | /// Sorted vector of the amount of clock ticks per deallocation.
60 | dealloc_measurements: Vec,
61 | }
62 |
63 | fn benchmark_allocator() -> BenchRunResults {
64 | #[cfg(target_arch = "x86_64")]
65 | let mut x = 0u32;
66 | #[cfg(target_arch = "x86_64")]
67 | let mut now_fn = || unsafe { std::arch::x86_64::__rdtscp(std::ptr::addr_of_mut!(x)) };
68 | #[cfg(target_arch = "aarch64")]
69 | let now_fn = || unsafe {
70 | let value: u64;
71 | std::arch::asm!(
72 | "mrs {value}, cntpct_el0",
73 | value = out(reg) value,
74 | options(nostack),
75 | );
76 | value
77 | };
78 | #[cfg(target_arch = "riscv64")]
79 | let now_fn = riscv::register::time::read64;
80 |
81 | let mut active_allocations = Vec::new();
82 |
83 | let mut all_alloc_measurements = Vec::new();
84 | let mut nofail_alloc_measurements = Vec::new();
85 | let mut dealloc_measurements = Vec::new();
86 |
87 | let mut allocation_attempts = 0;
88 | let mut successful_allocations = 0;
89 | let mut pre_fail_allocations = 0;
90 | let mut deallocations = 0;
91 |
92 | let mut any_alloc_failed = false;
93 |
94 | // run for 10s
95 | let bench_begin_time = Instant::now();
96 | while bench_begin_time.elapsed().as_secs_f64() <= BENCH_DURATION {
97 | let size = fastrand::usize((1 << 6)..(1 << 15));
98 | let align = 8 << (fastrand::u16(..).trailing_zeros() / 2);
99 | let layout = Layout::from_size_align(size, align).unwrap();
100 |
101 | let alloc_begin = now_fn();
102 | let ptr = unsafe { alloc(layout) };
103 | let alloc_ticks = now_fn() - alloc_begin;
104 |
105 | allocation_attempts += 1;
106 | if !ptr.is_null() {
107 | active_allocations.push((ptr, layout));
108 |
109 | successful_allocations += 1;
110 | if !any_alloc_failed {
111 | pre_fail_allocations += 1;
112 | }
113 | } else {
114 | any_alloc_failed = true;
115 | }
116 |
117 | all_alloc_measurements.push(alloc_ticks);
118 | if !any_alloc_failed {
119 | nofail_alloc_measurements.push(alloc_ticks);
120 | }
121 |
122 | if active_allocations.len() > 10 && fastrand::usize(..10) == 0 {
123 | for _ in 0..7 {
124 | let index = fastrand::usize(..active_allocations.len());
125 | let allocation = active_allocations.swap_remove(index);
126 |
127 | let dealloc_begin = now_fn();
128 | unsafe {
129 | dealloc(allocation.0, allocation.1);
130 | }
131 | let dealloc_ticks = now_fn() - dealloc_begin;
132 |
133 | deallocations += 1;
134 | dealloc_measurements.push(dealloc_ticks);
135 | }
136 | }
137 | }
138 |
139 | // sort
140 | all_alloc_measurements.sort();
141 | nofail_alloc_measurements.sort();
142 | dealloc_measurements.sort();
143 |
144 | BenchRunResults {
145 | allocation_attempts,
146 | successful_allocations,
147 | pre_fail_allocations,
148 | deallocations,
149 |
150 | all_alloc_measurements,
151 | nofail_alloc_measurements,
152 | dealloc_measurements,
153 | }
154 | }
155 |
156 | fn print_bench_results(res: &BenchRunResults) {
157 | let allocation_success =
158 | (res.successful_allocations as f64 / res.allocation_attempts as f64) * 100.0;
159 | log_benchmark_data("Allocation success", "%", allocation_success);
160 |
161 | let deallocation_success =
162 | (res.deallocations as f64 / res.successful_allocations as f64) * 100.0;
163 | log_benchmark_data("Deallocation success", "%", deallocation_success);
164 |
165 | let pre_fail_alloc = (res.pre_fail_allocations as f64 / res.allocation_attempts as f64) * 100.0;
166 | log_benchmark_data("Pre-fail Allocations", "%", pre_fail_alloc);
167 |
168 | let avg_all_alloc = res.all_alloc_measurements.iter().sum::() as f64
169 | / res.all_alloc_measurements.len() as f64;
170 | log_benchmark_data("Average Allocation time", "Ticks", avg_all_alloc);
171 |
172 | let avg_nofail_alloc = res.nofail_alloc_measurements.iter().sum::() as f64
173 | / res.nofail_alloc_measurements.len() as f64;
174 | log_benchmark_data(
175 | "Average Allocation time (no fail)",
176 | "Ticks",
177 | avg_nofail_alloc,
178 | );
179 |
180 | let avg_dealloc =
181 | res.dealloc_measurements.iter().sum::() as f64 / res.dealloc_measurements.len() as f64;
182 | log_benchmark_data("Average Deallocation time", "Ticks", avg_dealloc);
183 | }
184 |
--------------------------------------------------------------------------------
/benches/micro/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "micro_benchmarks"
3 | authors = ["Stefan Lankes "]
4 | edition = "2021"
5 |
6 | [dependencies]
7 | rayon = "1.5"
8 | hermit_bench_output = "0.1.1"
9 |
10 | [target.'cfg(target_os = "hermit")'.dependencies]
11 | hermit = { path = "../../hermit", default-features = false }
12 |
13 | [target.'cfg(target_arch = "aarch64")'.dependencies]
14 | aarch64-cpu = "10"
15 |
16 | [target.'cfg(target_arch = "riscv64")'.dependencies]
17 | riscv = "0.13"
18 |
19 | [target.'cfg(target_os = "linux")'.dependencies]
20 | syscalls = { version = "0.6", default-features = false }
21 |
22 | [features]
23 | default = ["hermit/acpi", "hermit/pci", "hermit/smp"]
24 |
--------------------------------------------------------------------------------
/benches/micro/src/benches/mod.rs:
--------------------------------------------------------------------------------
1 | use std::ffi::c_void;
2 | use std::hint::black_box;
3 | use std::time::Instant;
4 | use std::{thread, vec};
5 |
6 | extern "C" {
7 | pub fn memcpy(dest: *mut c_void, src: *const c_void, n: usize) -> *mut c_void;
8 | pub fn memset(dest: *mut c_void, c: u8, n: usize) -> *mut c_void;
9 | }
10 |
11 | const NR_RUNS: usize = 1000;
12 |
13 | #[cfg(target_arch = "x86_64")]
14 | #[inline]
15 | fn get_timestamp() -> u64 {
16 | unsafe {
17 | let mut _aux = 0;
18 | let value = core::arch::x86_64::__rdtscp(&mut _aux);
19 | core::arch::x86_64::_mm_lfence();
20 | value
21 | }
22 | }
23 |
24 | #[cfg(target_arch = "aarch64")]
25 | #[inline]
26 | fn get_timestamp() -> u64 {
27 | use aarch64_cpu::registers::{Readable, CNTPCT_EL0};
28 |
29 | CNTPCT_EL0.get()
30 | }
31 |
32 | #[cfg(target_arch = "riscv64")]
33 | #[inline]
34 | fn get_timestamp() -> u64 {
35 | riscv::register::time::read64()
36 | }
37 |
38 | extern "C" {
39 | #[cfg(target_os = "hermit")]
40 | fn sys_getpid() -> u32;
41 | }
42 |
43 | pub fn bench_syscall() -> Result<(), ()> {
44 | let n = 1000000;
45 |
46 | let ticks = {
47 | // cache warmup
48 | #[cfg(target_os = "hermit")]
49 | let _ = unsafe { sys_getpid() };
50 | #[cfg(target_os = "linux")]
51 | let _ = unsafe { syscalls::syscall!(syscalls::Sysno::getpid) };
52 | let _ = get_timestamp();
53 |
54 | let start = get_timestamp();
55 | for _ in 0..n {
56 | #[cfg(target_os = "hermit")]
57 | let _ = unsafe { sys_getpid() };
58 | #[cfg(target_os = "linux")]
59 | let _ = unsafe { syscalls::syscall!(syscalls::Sysno::getpid) };
60 | }
61 | get_timestamp() - start
62 | };
63 |
64 | hermit_bench_output::log_benchmark_data(
65 | "Time for syscall (getpid)",
66 | "ticks",
67 | ticks as f64 / n as f64,
68 | );
69 |
70 | Ok(())
71 | }
72 |
73 | pub fn bench_sched_one_thread() -> Result<(), ()> {
74 | let n = 1000000;
75 |
76 | // cache warmup
77 | thread::yield_now();
78 | thread::yield_now();
79 | let _ = get_timestamp();
80 |
81 | let start = get_timestamp();
82 | for _ in 0..n {
83 | thread::yield_now();
84 | }
85 | let ticks = get_timestamp() - start;
86 |
87 | hermit_bench_output::log_benchmark_data_with_group(
88 | "1 thread",
89 | "ticks",
90 | ticks as f64 / n as f64,
91 | "Scheduling time",
92 | );
93 |
94 | Ok(())
95 | }
96 |
97 | pub fn bench_sched_two_threads() -> Result<(), ()> {
98 | let n = 1000000;
99 | let nthreads = 2;
100 |
101 | // cache warmup
102 | thread::yield_now();
103 | thread::yield_now();
104 | let _ = get_timestamp();
105 |
106 | let start = get_timestamp();
107 | let threads: Vec<_> = (0..nthreads - 1)
108 | .map(|_| {
109 | thread::spawn(move || {
110 | for _ in 0..n {
111 | thread::yield_now();
112 | }
113 | })
114 | })
115 | .collect();
116 |
117 | for _ in 0..n {
118 | thread::yield_now();
119 | }
120 |
121 | let ticks = get_timestamp() - start;
122 |
123 | for t in threads {
124 | t.join().unwrap();
125 | }
126 |
127 | hermit_bench_output::log_benchmark_data_with_group(
128 | "2 threads",
129 | "ticks",
130 | ticks as f64 / (nthreads * n) as f64,
131 | "Scheduling time",
132 | );
133 |
134 | Ok(())
135 | }
136 |
137 | // derived from
138 | // https://github.com/rust-lang/compiler-builtins/blob/master/testcrate/benches/mem.rs
139 | fn memcpy_builtin(n: usize) {
140 | let v1 = vec![1u8; n];
141 | let mut v2 = vec![0u8; n];
142 |
143 | let now = Instant::now();
144 | for _i in 0..NR_RUNS {
145 | let src: &[u8] = black_box(&v1);
146 | let dst: &mut [u8] = black_box(&mut v2);
147 | dst.copy_from_slice(src);
148 | }
149 |
150 | hermit_bench_output::log_benchmark_data_with_group(
151 | &format!("(built_in) block size {n}"),
152 | "MByte/s",
153 | (NR_RUNS * n) as f64 / (1024.0 * 1024.0 * now.elapsed().as_secs_f64()),
154 | "Memcpy speed",
155 | );
156 | }
157 |
158 | // derived from
159 | // https://github.com/rust-lang/compiler-builtins/blob/master/testcrate/benches/mem.rs
160 | fn memset_builtin(n: usize) {
161 | let mut v1 = vec![0u8; n];
162 | let now = Instant::now();
163 | for _i in 0..NR_RUNS {
164 | let dst: &mut [u8] = black_box(&mut v1);
165 | let val: u8 = black_box(27);
166 | for b in dst {
167 | *b = val;
168 | }
169 | }
170 |
171 | hermit_bench_output::log_benchmark_data_with_group(
172 | &format!("(built_in) block size {n}"),
173 | "MByte/s",
174 | ((NR_RUNS * n) >> 20) as f64 / now.elapsed().as_secs_f64(),
175 | "Memset speed",
176 | );
177 | }
178 |
179 | // derived from
180 | // https://github.com/rust-lang/compiler-builtins/blob/master/testcrate/benches/mem.rs
181 | fn memcpy_rust(n: usize) {
182 | let v1 = vec![1u8; n];
183 | let mut v2 = vec![0u8; n];
184 | let now = Instant::now();
185 | for _i in 0..NR_RUNS {
186 | let src: &[u8] = black_box(&v1[0..]);
187 | let dst: &mut [u8] = black_box(&mut v2[0..]);
188 | unsafe {
189 | memcpy(
190 | dst.as_mut_ptr() as *mut c_void,
191 | src.as_ptr() as *mut c_void,
192 | n,
193 | );
194 | }
195 | }
196 |
197 | hermit_bench_output::log_benchmark_data_with_group(
198 | &format!("(rust) block size {n}"),
199 | "MByte/s",
200 | ((NR_RUNS * n) >> 20) as f64 / now.elapsed().as_secs_f64(),
201 | "Memcpy speed",
202 | );
203 | }
204 |
205 | // derived from
206 | // https://github.com/rust-lang/compiler-builtins/blob/master/testcrate/benches/mem.rs
207 | fn memset_rust(n: usize) {
208 | let mut v1 = vec![0u8; n];
209 | let now = Instant::now();
210 | for _i in 0..NR_RUNS {
211 | let dst: &mut [u8] = black_box(&mut v1[0..]);
212 | let val = black_box(27);
213 | unsafe {
214 | memset(dst.as_mut_ptr() as *mut c_void, val, n);
215 | }
216 | }
217 |
218 | hermit_bench_output::log_benchmark_data_with_group(
219 | &format!("(rust) block size {n}"),
220 | "MByte/s",
221 | ((NR_RUNS * n) >> 20) as f64 / now.elapsed().as_secs_f64(),
222 | "Memset speed",
223 | );
224 | }
225 |
226 | pub fn bench_mem() -> Result<(), ()> {
227 | memcpy_builtin(black_box(4096));
228 | memcpy_builtin(black_box(1048576));
229 | memcpy_builtin(black_box(16 * 1048576));
230 | memset_builtin(black_box(4096));
231 | memset_builtin(black_box(1048576));
232 | memset_builtin(black_box(16 * 1048576));
233 | memcpy_rust(black_box(4096));
234 | memcpy_rust(black_box(1048576));
235 | memcpy_rust(black_box(16 * 1048576));
236 | memset_rust(black_box(4096));
237 | memset_rust(black_box(1048576));
238 | memset_rust(black_box(16 * 1048576));
239 |
240 | Ok(())
241 | }
242 |
--------------------------------------------------------------------------------
/benches/micro/src/main.rs:
--------------------------------------------------------------------------------
1 | #![feature(test)]
2 |
3 | #[cfg(target_os = "hermit")]
4 | use hermit as _;
5 |
6 | mod benches;
7 |
8 | use benches::*;
9 |
10 | fn main() {
11 | bench_sched_one_thread().unwrap();
12 | bench_sched_two_threads().unwrap();
13 | bench_syscall().unwrap();
14 | bench_mem().unwrap();
15 | }
16 |
--------------------------------------------------------------------------------
/benches/multithreaded/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "multithreaded_benchmark"
3 | authors = ["Carl Wachter"]
4 | edition = "2021"
5 |
6 | [dependencies]
7 | hermit_bench_output = "0.1.0"
8 |
9 | [target.'cfg(target_os = "hermit")'.dependencies]
10 | hermit = { path = "../../hermit", default-features = false }
11 |
12 | [features]
13 |
--------------------------------------------------------------------------------
/benches/multithreaded/src/main.rs:
--------------------------------------------------------------------------------
1 | use std::hint::black_box;
2 | use std::thread;
3 | use std::time::{Duration, Instant};
4 |
5 | #[cfg(target_os = "hermit")]
6 | use hermit as _;
7 | use hermit_bench_output::log_benchmark_data;
8 |
9 | fn calc_pi_multi_threaded(n: u64, threads: u64) -> f64 {
10 | let mut handles = vec![];
11 | let mut pi = 0.0;
12 | let step = 1.0 / n as f64;
13 | for i in 0..threads {
14 | let start = i * n / threads;
15 | let end = (i + 1) * n / threads;
16 | let handle = thread::spawn(move || {
17 | let mut pi = 0.0;
18 | for i in start..end {
19 | let x = (i as f64 + 0.5) * step;
20 | pi += 4.0 / (1.0 + x * x);
21 | }
22 | pi
23 | });
24 | handles.push(handle);
25 | }
26 | for handle in handles {
27 | pi += handle.join().unwrap();
28 | }
29 | pi *= step;
30 | pi
31 | }
32 |
33 | fn main() {
34 | let n = 100000000;
35 | //let n = 1000000000;
36 | let mut times: Vec = Vec::new();
37 |
38 | for i in 1..=8 {
39 | let now = Instant::now();
40 | black_box(calc_pi_multi_threaded(black_box(n), black_box(i)));
41 | let elapsed = now.elapsed();
42 | times.push(elapsed);
43 | }
44 |
45 | // Calc speedup
46 | let speedup1_2 = times[0].as_secs_f64() / times[1].as_secs_f64();
47 | let speedup1_4 = times[0].as_secs_f64() / times[2].as_secs_f64();
48 | let speedup1_8 = times[0].as_secs_f64() / times[7].as_secs_f64();
49 |
50 | // Calc efficiency
51 | let efficiency1_2 = speedup1_2 / 2.0;
52 | let efficiency1_4 = speedup1_4 / 4.0;
53 | let efficiency1_8 = speedup1_8 / 8.0;
54 |
55 | log_benchmark_data("2 Threads", "%", efficiency1_2 * 100.0);
56 | log_benchmark_data("4 Threads", "%", efficiency1_4 * 100.0);
57 | log_benchmark_data("8 Threads", "%", efficiency1_8 * 100.0);
58 | }
59 |
--------------------------------------------------------------------------------
/benches/mutex/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "mutex"
3 | authors = ["Stefan Lankes "]
4 | edition = "2021"
5 |
6 | [target.'cfg(target_os = "hermit")'.dependencies]
7 | hermit = { path = "../../hermit", default-features = false }
8 |
9 | [dependencies]
10 | hermit_bench_output = "0.1.1"
11 |
12 | [features]
13 | default = ["hermit/acpi", "hermit/pci", "hermit/smp"]
14 |
--------------------------------------------------------------------------------
/benches/mutex/src/main.rs:
--------------------------------------------------------------------------------
1 | use std::hint::black_box;
2 | use std::sync::atomic::{AtomicUsize, Ordering};
3 | use std::sync::{Arc, Mutex};
4 | use std::time::{Duration, Instant};
5 | use std::{hint, thread};
6 |
7 | #[cfg(target_os = "hermit")]
8 | use hermit as _;
9 | use hermit_bench_output::log_benchmark_data_with_group;
10 |
11 | const NUMBER_OF_ITERATIONS: usize = 10000000;
12 |
13 | pub struct SpinBarrier {
14 | num_threads: AtomicUsize,
15 | }
16 |
17 | impl SpinBarrier {
18 | pub const fn new(n: usize) -> Self {
19 | Self {
20 | num_threads: AtomicUsize::new(n),
21 | }
22 | }
23 |
24 | pub fn wait(&self) {
25 | self.num_threads.fetch_sub(1, Ordering::Relaxed);
26 | while self.num_threads.load(Ordering::Relaxed) != 0 {
27 | hint::spin_loop();
28 | }
29 | }
30 | }
31 |
32 | fn mutex_stress_test(no_threads: usize) {
33 | println!("Stress mutex with {no_threads} threads!");
34 |
35 | let counter = Arc::new(Mutex::new(0));
36 |
37 | let barrier = Arc::new(SpinBarrier::new(no_threads));
38 |
39 | let handles = (0..no_threads)
40 | .map(|_| {
41 | let barrier = barrier.clone();
42 | let counter = counter.clone();
43 | thread::spawn(move || {
44 | // Warmup
45 | let now = Instant::now();
46 | for _ in 0..NUMBER_OF_ITERATIONS {
47 | let mut guard = counter.lock().unwrap();
48 | *guard += 1;
49 | }
50 | let _ = now.elapsed();
51 | barrier.wait();
52 |
53 | let now = Instant::now();
54 | for _ in 0..NUMBER_OF_ITERATIONS {
55 | let mut guard = counter.lock().unwrap();
56 | *guard += 1;
57 | }
58 | now.elapsed()
59 | })
60 | })
61 | .collect::>();
62 |
63 | let durations = handles
64 | .into_iter()
65 | .map(|handle| handle.join().unwrap())
66 | .collect::>();
67 |
68 | assert_eq!(
69 | *counter.lock().unwrap(),
70 | 2 * NUMBER_OF_ITERATIONS * no_threads
71 | );
72 |
73 | let average = durations.iter().sum::()
74 | / u32::try_from(no_threads).unwrap()
75 | / u32::try_from(NUMBER_OF_ITERATIONS * no_threads).unwrap();
76 | log_benchmark_data_with_group(
77 | &format!("{no_threads} Threads"),
78 | "ns",
79 | average.as_nanos() as f64,
80 | "Mutex Stress Test Average Time per Iteration",
81 | );
82 | }
83 |
84 | fn main() {
85 | let available_parallelism = thread::available_parallelism().unwrap().get();
86 |
87 | let mut i = 1;
88 | while i <= available_parallelism {
89 | mutex_stress_test(black_box(i));
90 | i *= 2;
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/benches/netbench/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 |
3 | name = "rust-tcp-io-perf"
4 | authors = ["Lorenzo Martini "]
5 | edition = "2021"
6 | readme = "README.md"
7 |
8 | description = "A Rust program to measure bandwidth or latency over a Rust TCP connection"
9 |
10 | [dependencies]
11 | bytes = "1.1"
12 | clap = { version ="4.5", features = ["derive"] }
13 | core_affinity = "0.8"
14 | hdrhist = "0.5"
15 | hermit_bench_output = "0.1.0"
16 |
17 | [target.'cfg(target_os = "hermit")'.dependencies]
18 | hermit = { path = "../../hermit", default-features = false }
19 |
20 | [features]
21 | default = ["hermit/acpi", "hermit/pci", "hermit/smp", "hermit/tcp", "hermit/udp"]
22 |
23 | [[bin]]
24 | name = "tcp-server-bw"
25 | path = "src/rust-tcp-bw/server.rs"
26 |
27 | [[bin]]
28 | name = "tcp-client-bw"
29 | path = "src/rust-tcp-bw/client.rs"
30 |
31 | [[bin]]
32 | name = "tcp-server-latency"
33 | path = "src/rust-tcp-latency/server.rs"
34 |
35 | [[bin]]
36 | name = "tcp-client-latency"
37 | path = "src/rust-tcp-latency/client.rs"
38 |
39 | [[bin]]
40 | name = "udp-server-bw"
41 | path = "src/rust-udp-bw/server.rs"
42 |
43 | [[bin]]
44 | name = "udp-client-bw"
45 | path = "src/rust-udp-bw/client.rs"
46 |
47 | [[bin]]
48 | name = "udp-server-latency"
49 | path = "src/rust-udp-latency/server.rs"
50 |
51 | [[bin]]
52 | name = "udp-client-latency"
53 | path = "src/rust-udp-latency/client.rs"
54 |
--------------------------------------------------------------------------------
/benches/netbench/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2020 Lorenzo Martini
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/benches/netbench/README.md:
--------------------------------------------------------------------------------
1 | # rust-tcp-io-perf
2 |
3 | This repo contains programs to benchmark how much bandwidth we effectively have available on a communication channel and what's the latency on that channel.
4 |
5 | It is froked from [rust-tcp-io-perf](https://github.com/LorenzoMartini/rust-tcp-io-perf) and used to measure the network performance of Hermit.
6 |
7 | ## Bandwidth measure
8 |
9 | We measure the effective bandwidth available on a communication channel.
10 |
11 | We run a server and a client at the two ends of the channel, and start sending big quantities of data from one end to the other. On the server side we can then measure (only in stable state) how much data we have received in how much time and derive an approximation of the bandwidth.
12 |
13 | ## Latency measure
14 |
15 | We measure the latency between the two machines at the end of a communication channel.
16 |
17 | We run a server and a client at the two ends of the channel, and start sending data from one end to the other and back. On the client side we can then measure the roundtrip time of every message sent and derive latency info.
18 |
19 | ## Instructions
20 |
21 | For both programs, you can run them the same way. We will use `bw` as example. To run `latency` just replace `bw` with `latency` whenever it appears in the instructions.
22 |
23 | ### Running .rs directly
24 |
25 | #### Prerequisites
26 | - Have Rust and Cargo correctly installed on your machine
27 |
28 | #### Instructions
29 |
30 | 1) Run server
31 | - Go on the machine where you want to launch the server (or ssh into it)
32 | - Open a terminal
33 | - `cd` into the inner `code` folder
34 | - Run `cargo run --bin server-bw --release` (or compile and run, meaning `cargo build --bin server-bw --release` and once compiled `./target/release/server-bw`). You can specify the port you want to listen on with `-p `.
35 |
36 | 2) Run client
37 | - Go on the machine where you want to launch the client (or ssh into it)
38 | - Open a terminal
39 | - `cd` into the inner `code` folder
40 | - Run `cargo run --bin client-bw --release` (or compile and run, meaning `cargo build --bin client-bw --release` and once compiled `./target/release/client-bw`). You can specify a bunch of parameters. Run the program with the `-h` option to see available params. Make sure you specify the right address and port to connect to the server, using parameters `-a -p `.
41 |
42 | You should see the client tracking progress, and when he's done you should see the server printing a visual distribution of data, followed by a summary with the bandwidth information.
43 |
44 | If you want to test the two-way communication, then setup 2 servers and then run the 2 clients together.
45 |
46 | ### Running via scripts
47 |
48 | I have provided scripts to run the benchmarks automatically, runner.py and runner_bidirectional.py.
49 | For these scripts you will need to edit the configuration file. Change values in `config_bw.config` (or `config_latency.config`), or create a config file in the same format with the same keys and change values. You can specify the program to test (whether `bw` or `latency`) in your config file.
50 |
51 | The config file is important because it will contain a bunch of things like machines names, ssh keys, username to use for the ssh, that will be necessary to run your programs.
52 |
53 | #### Prerequisites
54 |
55 | - Make sure you can ssh into the machines you want to use for your benchmark.
56 | - Make sure you have set up the ssh connections correctly and have the machines in your known host and have the ssh keys somewhere in your pc (or the machine you will start the script from).
57 |
58 | #### Instructions
59 | For both scripts, run: `python