Crates.io | carbond-lib |
lib.rs | carbond-lib |
version | 0.1.0 |
source | src |
created_at | 2024-09-10 10:27:21.021883 |
updated_at | 2024-09-10 10:27:21.021883 |
description | Type-safe interface to the managed information provided by the system daemon 'carbond' for Rust. |
homepage | |
repository | https://gitlab.com/sustainable-computing-systems/carbond |
max_upload_size | |
id | 1370225 |
size | 85,056 |
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.
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
/var/carbond
.carbond-lib
Library
/var/carbond
for Rust.carbond
binary and the carbond-lib
lib.carbond-macros
Library
fn
with carbon tracking.The installation comprises several steps that must be carried out one after the other.
This binary is provided as a .deb
or .rpm
package for easy installation of the daemon on compatible Linux systems.
uname -m
.deb
package matching your CPU architecture.dpkg -i ./carbond-{TAG}-{CPU Arch}.deb
.rpm
package.dnf install ./carbond-{TAG}.x86_64.rpm
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).
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
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
ServiceThis 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.
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
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
LibraryA 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.
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
Carbond was developed with the help of the following contributors:
Don't hesitate to file an issue or contact @netzdoktor via e-mail.
Please have a look at the issues or open one if you feel that something is needed.
Any contributions are very welcome!
Yes, but we believe an operating-system service should be the future to achieve carbon awareness.
carbond
leverages them as external data sources.Licensed under the MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT).
This work was funded by the German Research Foundation (DFG) grant 389792660 as part of TRR 248 – CPEC.
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}
}
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.