forked from tock/tock
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request tock#1443 from gendx/add-strace-feature
Add strace feature to trace syscalls in the kernel.
- Loading branch information
Showing
7 changed files
with
164 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
Configuration | ||
============= | ||
|
||
Because Tock is meant to run on various platforms (spanning multiple | ||
architectures and various available peripherals), and with multiple use cases in | ||
mind (for example, "production" vs. debug build with various levels of debugging | ||
detail), Tock provides various configuration options so that each build can be | ||
adapted to each use case. | ||
|
||
In Tock, configuration follows some principles to avoid pitfalls of "ifdef" | ||
conditional code (which can be tricky to test). This is currently done in two | ||
ways. | ||
|
||
- **Separation of the code into multiple packages.** Each level of abstraction | ||
(core kernel, CPU architecture, chip, board) has its own package, so that | ||
configuring a board is done by depending on the relevant chip and declaring | ||
the relevant drivers for peripherals avaialble on the board. You can see more | ||
details on the [compilation page](Compilation.md). | ||
|
||
- **Custom kernel configuration.** To facilitate fine-grained configuration of | ||
the kernel (for example to enable tracing the syscalls to the debug output), a | ||
`Config` struct is defined in `kernel/src/config.rs`. To change the | ||
configuration, modify the values in the static `const` object defined in this | ||
file. To use the configuration, simply read the values. For example, to use a | ||
boolean configuration, just use an if statement: the fact that the | ||
configuration is `const` should allow the compiler to optimize away dead code | ||
(so that this configuration has zero cost), while still checking syntax and | ||
types. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
//! Data structure for storing compile-time configuration options in the kernel. | ||
//! | ||
//! The rationale for configuration based on a `const` object is twofold. | ||
//! | ||
//! - In theory, Cargo features could be used for boolean-based configuration. However, these | ||
//! features are generally error-prone for non-trivial use cases. First, they are globally enabled | ||
//! as long as a dependency relationship requires a feature (even for other dependency | ||
//! relationships that do not want the feature). Second, code gated by a non-enabled feature | ||
//! isn't even type-checked by the compiler, and therefore we can end up with broken features due | ||
//! to refactoring code (if these features aren't tested during the refactoring), or to | ||
//! incompatible feature combinations. | ||
//! | ||
//! - Cargo features can only contain bits. On the other hand, a constant value can contain | ||
//! arbitrary types, which allow configuration based on integers, strings, or even more complex | ||
//! values. | ||
//! | ||
//! With a typed `const` configuration, all code paths are type-checked by the compiler - even | ||
//! those that end up disabled - which greatly reduces the risks of breaking a feature or | ||
//! combination of features because they are disabled in tests. | ||
//! | ||
//! In the meantime, after type-checking, the compiler can optimize away dead code by folding | ||
//! constants throughout the code, so for example a boolean condition used in an `if` block will in | ||
//! principle have a zero cost on the resulting binary - as if a Cargo feature was used instead. | ||
//! Some simple experiments on generated Tock code have confirmed this zero cost in practice. | ||
/// Data structure holding compile-time configuration options. | ||
/// | ||
/// To change the configuration, modify the relevant values in the `CONFIG` constant object defined | ||
/// at the end of this file. | ||
crate struct Config { | ||
/// Whether the kernel should trace syscalls to the debug output. | ||
/// | ||
/// If enabled, the kernel will print a message in the debug output for each system call and | ||
/// callback, with details including the application ID, and system call or callback parameters. | ||
crate trace_syscalls: bool, | ||
} | ||
|
||
/// A unique instance of `Config` where compile-time configuration options are defined. These | ||
/// options are available in the kernel crate to be used for relevant configuration. | ||
crate const CONFIG: Config = Config { | ||
trace_syscalls: false, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ pub mod ipc; | |
pub mod syscall; | ||
|
||
mod callback; | ||
mod config; | ||
mod driver; | ||
mod grant; | ||
mod mem; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters