1 unstable release
0.1.0 | Sep 10, 2024 |
---|
#136 in Operating systems
48KB
803 lines
An operating-system daemon for carbon awareness
The goal of this project is to provide a system service and a matching interfacing libraries to make software carbon-aware.
The end goal of this project is to enable tracking carbon footprint of anything from whole processes down to single programming language functions.
Overview
Carbond is an operating-system daemon for carbon awareness. It comes with a Rust library for easy consumption of the daemon's file system API but can be used by any program with access to the file system.
At the moment, the project consists of the following crates:
carbond
: Executable Binary- Query carbon intensity from external data providers.
- Manage system resource embodied emissions (e.g. CPU, Battery).
- Provide collected information via a file system API under
/var/carbond
. - Integrates the efficiency of the power supply unit for AC-DC conversion.
- This is future work and is currently only approximately implemented by a 90% efficiency.
- Provides a battery tracker for the carbon intensity of stored energy in the battery.
- Incorporates the configured embodied emissions of the battery.
- Provides a system carbon intensity depending on system state (plugged-in, plugged-out)
carbond-lib
Library- Type-safe interface to the managed information in
/var/carbond
for Rust. - Functionality to calculate carbon emissions from collected operational data.
- Provide definitions of embodied and operational metrics.
- Common functionality used by both the
carbond
binary and thecarbond-lib
lib.
- Type-safe interface to the managed information in
carbond-macros
Library- Provide macros to wrap arbitrary
fn
with carbon tracking. - Exposes information about run CPU cycles and used operational energy.
- Provide macros to wrap arbitrary
Install
The installation comprises several steps that must be carried out one after the other.
1. Install service
This binary is provided as a .deb
or .rpm
package for easy installation of the daemon on compatible Linux systems.
Ubuntu/Debian
- Find your CPU architecture with:
uname -m
- Download the latest
.deb
package matching your CPU architecture. - Install the package with:
dpkg -i ./carbond-{TAG}-{CPU Arch}.deb
RHEL/Fedora (ATM. only x86 supported)
- Download the latest
.rpm
package. - Install the package with:
dnf install ./carbond-{TAG}.x86_64.rpm
2. Create necessary folders (optional)
This step is only required if the user who will execute the binary has no permissions to create the following folders:
/etc/carbond
[for battery, intensity, and emission data]/var/carbond
[for configuration files]
If applicable, the folders must be created and either the owner changed or appropriate permissions given (cf. chown or chmod).
3. Initialize / Configure
Since it is hard to provide a default configuration, carbond
requires a manual initialization.
For a more user-friendly initialization, carbond
provides the init command, which guides the user through the configuration of the service.
The config for carbond
is stored at /etc/carbond/config.toml
.
carbond init
4. Start service
If the service is not to be started manually each time after reboot, carbond
can be used as a systemd service after initialization.
To do this, the service can be activated and then started as a systemd service:
systemctl enable --now carbond
carbond
Service
This binary is the main component of carbond
.
It provides carbon information to other system services and applications via its file system API. For that it queries external data providers for the Marginal Operating Emissions Rate (MOER) of the configured zone. The data is converted into standardized uom units and made accessible via the file system.
API
Carbond exposes its collected data via an file system based API under /var/carbond
:
/var/carbond
├── battery // contains battery tracker data
│ ├── carbond // stored carbon in battery
│ └── energy // stored energy in battery
├── embodied // contains embodied intensities
│ ├── battery // battery embodied intensity
│ └── cpu // CPU embodied intensity
└── operational // contains operational intensities
├── grid
│ └── intensity // intensity of the grid
├── PSU
│ ├── efficiency // current efficiency of the PSU (0-100%)
│ └── intensity // intensity of DC current after AC-DC conversion (Higher than grid)
└── system-intensity // intensity the system is actually using:
// -> Plugged-In: PSU
// -> On Battery: Battery intensity + Battery embodied intensity
Testing
Can be tested with a provided Dockerfile which compiles carbond
using the musl libc implementation.
To start the testing environment open a terminal on your host system:
docker build -t carbond .
docker run -dt carbond
docker exec -it *container_id* bash
You should now have access to a terminal within the container with the created binary file. You can then carry out the initialization steps from the installation instructions.
carbond-lib
Library
A library for the Rust programming language that allows easy use of the carbond
file system API.
Provides functionality to calculate emitted emissions from collected runtime data, such as the emitted embodied emission of the CPU from the number of CPU cycles executed.
The runtime data can either be collected manually and used with the carbon intensities to calculate the emitted emissions or collected through provided macros.
Example
use carbond_macros::carbond_track;
use carbond_lib::embodied;
#[carbond_track]
fn tracked_function() -> u32 {
let a = 50;
let b = 22;
b + a
}
#[tokio::main]
fn main() {
// run tracked function
let track: CarbonTracking<u32> = tracked_function();
println!("{:#?}", track);
// load cpu's embodied intensity (per cycle)
let cpu_embodied_emission: Mass = embodied::cpu::load_cpu_embodied_intensity().await?;
// calculate the emission by multiplying the embodied cpu intensity (per cycle) with the number of cycles
let carbon_emission: Mass = cpu_embodied_emission * track.cpu_track.cpu_cycles as f64;
println!("{:?}", carbon_emission.get::<microgram>());
}
Which generates the following outputs:
CarbonTracking {
data: 72,
cpu_track: {
core: 0,
cpu_cycles: 44
},
...
}
0.000286 mg
Contributors
Carbond was developed with the help of the following contributors:
- Andreas Schmidt (DSS)
- Robin Ohs (DSS)
- Henry Janson (DSS)
- BOSS - Assistance with the theoretical background
FAQ
I need help
Don't hesitate to file an issue or contact @netzdoktor via e-mail.
How can I help?
Please have a look at the issues or open one if you feel that something is needed.
Any contributions are very welcome!
How to cite this code?
Aren't there similar projects?
Yes, but we believe an operating-system service should be the future to achieve carbon awareness.
- carbon-aware-sdk
- is similar in that it harmonizes information providers (centralizes credential handling),
- in itself provides data via HTTP again and is not a system service but an SDK,
- currently, embodied carbon of system-local resources seem out of scope (they rather focus on carbon-intensity).
- carbonQL aims to provide a unified emission measurement/query framework
- Real Time Energy and Carbon Standard for Cloud Providers, where carbond could be integrated.
- WattTime, ElectricityMap, are independent data providers for operational carbon intensity. While they also provide history and forecasts, they do not provide any solution for embodied emissions. Furthermore,
carbond
leverages them as external data sources.
License
Licensed under the MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT).
Acknowledgements
This work was funded by the German Research Foundation (DFG) grant 389792660 as part of TRR 248 – CPEC.
Citation
Cite this work as
@inproceedings{carbond:2023:hotcarbon,
title={carbond: An Operating-System Daemon for Carbon Awareness},
author={Schmidt, Andreas and Stock, Gregory and Ohs, Robin and Gerhorst, Luis and Herzog, Benedict and Hönig, Timo},
booktitle={2nd Workshop on Sustainable Computer Systems (HotCarbon)},
address={Boston, MA, USA},
month=7,
doi={https://doi.org/10.1145/3604930.3605707},
year={2023}
}
Contributing
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, shall be MIT licensed as above, without any additional terms or conditions.
Dependencies
~5–12MB
~114K SLoC