From 0f372005f93030d7acfc87d4fd817e1a064136c0 Mon Sep 17 00:00:00 2001 From: Cheng Date: Wed, 3 Sep 2025 19:55:26 +1000 Subject: [PATCH 01/18] Draft of the dvfs example Signed-off-by: Cheng --- .gitignore | 1 + examples/dvfs/Cargo.toml | 11 ++ examples/dvfs/Makefile | 32 ++++ examples/dvfs/dvfs.mk | 146 ++++++++++++++++++ examples/dvfs/idle.c | 4 + examples/dvfs/meta.py | 98 ++++++++++++ examples/dvfs/rust-toolchain.toml | 10 ++ examples/dvfs/src/helper.c | 33 ++++ examples/dvfs/src/helper.rs | 9 ++ examples/dvfs/src/main.rs | 84 ++++++++++ examples/dvfs/src/platforms/mod.rs | 1 + examples/dvfs/src/platforms/xilinx.rs | 37 +++++ .../aarch64-sel4-microkit-minimal.json | 35 +++++ 13 files changed, 501 insertions(+) create mode 100644 examples/dvfs/Cargo.toml create mode 100644 examples/dvfs/Makefile create mode 100644 examples/dvfs/dvfs.mk create mode 100644 examples/dvfs/idle.c create mode 100644 examples/dvfs/meta.py create mode 100644 examples/dvfs/rust-toolchain.toml create mode 100644 examples/dvfs/src/helper.c create mode 100644 examples/dvfs/src/helper.rs create mode 100644 examples/dvfs/src/main.rs create mode 100644 examples/dvfs/src/platforms/mod.rs create mode 100644 examples/dvfs/src/platforms/xilinx.rs create mode 100644 examples/dvfs/support/targets/aarch64-sel4-microkit-minimal.json diff --git a/.gitignore b/.gitignore index 607bbf772..0e43bb224 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,7 @@ ci_logs/ zig-out/ .zig-cache/ venv/ +target/ __pycache__ .*.sw* *.dtb diff --git a/examples/dvfs/Cargo.toml b/examples/dvfs/Cargo.toml new file mode 100644 index 000000000..693adad0d --- /dev/null +++ b/examples/dvfs/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "dvfs" +version = "0.1.0" +edition = "2024" + +[dependencies] +sel4-microkit = { git = "https://github.com/seL4/rust-sel4.git", rev = "d2bc5cf71c5455f85898a4768e9dcbaea39e1a7e" } +cpufreq = { git = "https://github.com/Cheng-Li1/freq-scaling-rs.git", rev = "29da4a2b7817c306e282783474a4b99d7442f066" } + +[net] +net.git-fetch-with-cli = true \ No newline at end of file diff --git a/examples/dvfs/Makefile b/examples/dvfs/Makefile new file mode 100644 index 000000000..cab7c83f2 --- /dev/null +++ b/examples/dvfs/Makefile @@ -0,0 +1,32 @@ +# +# Copyright 2025, UNSW +# +# SPDX-License-Identifier: BSD-2-Clause +# + +ifeq ($(strip $(MICROKIT_SDK)),) +$(error MICROKIT_SDK must be specified) +endif + +ifeq ($(strip $(MICROKIT_BOARD)),) +$(error MICROKIT_BOARD must be specified) +endif +BUILD_DIR ?= build +override BUILD_DIR := $(abspath ${BUILD_DIR}) +export BUILD_DIR +export SDDF := $(abspath ../..) +override MICROKIT_SDK := $(abspath ${MICROKIT_SDK}) + +IMAGE_FILE := ${BUILD_DIR}/loader.img +REPORT_FILE := ${BUILD_DIR}/report.txt + +all: ${IMAGE_FILE} + +qemu ${IMAGE_FILE} ${REPORT_FILE} clean clobber: ${BUILD_DIR}/Makefile FORCE + ${MAKE} -C ${BUILD_DIR} MICROKIT_SDK=${MICROKIT_SDK} $(notdir $@) + +${BUILD_DIR}/Makefile: dvfs.mk + mkdir -p ${BUILD_DIR} + cp dvfs.mk $@ + +FORCE: diff --git a/examples/dvfs/dvfs.mk b/examples/dvfs/dvfs.mk new file mode 100644 index 000000000..63f3a8f37 --- /dev/null +++ b/examples/dvfs/dvfs.mk @@ -0,0 +1,146 @@ +# +# Copyright 2025, UNSW +# +# SPDX-License-Identifier: BSD-2-Clause +# +# This Makefile is copied into the build directory +# and operated on from there. +# + +ifeq ($(strip $(MICROKIT_SDK)),) +$(error MICROKIT_SDK must be specified) +endif + +ifeq ($(strip $(SDDF)),) +$(error SDDF must be specified) +endif + +ifeq ($(strip $(TOOLCHAIN)),) + TOOLCHAIN := clang +endif + +ifeq ($(strip $(TOOLCHAIN)), clang) + CC := clang + LD := ld.lld + AR := llvm-ar + RANLIB := llvm-ranlib + OBJCOPY := llvm-objcopy +else + CC := $(TOOLCHAIN)-gcc + LD := $(TOOLCHAIN)-ld + AS := $(TOOLCHAIN)-as + AR := $(TOOLCHAIN)-ar + RANLIB := $(TOOLCHAIN)-ranlib + OBJCOPY := $(TOOLCHAIN)-objcopy +endif + +# Allow to user to specify a custom partition +PARTITION := +ifdef PARTITION + PARTITION_ARG := --partition $(PARTITION) +endif + +IMAGE_FILE := loader.img +REPORT_FILE := report.txt +SYSTEM_FILE := dvfs.system + +ifeq ($(strip $(MICROKIT_BOARD)), zcu102) + CPU := cortex-a53 + SERIAL_DRIVER_DIR := zynqmp + TIMER_DRIVER_DIR := cdns +else +$(error Unsupported MICROKIT_BOARD given) +endif + +DTC := dtc +PYTHON ?= python3 + +BUILD_DIR ?= build +MICROKIT_CONFIG ?= debug + +TOP := ${SDDF}/examples/dvfs +CONFIGS_INCLUDE := ${TOP} + +MICROKIT_TOOL ?= $(MICROKIT_SDK)/bin/microkit + +BOARD_DIR := $(MICROKIT_SDK)/board/$(MICROKIT_BOARD)/$(MICROKIT_CONFIG) +ARCH := ${shell grep 'CONFIG_SEL4_ARCH ' $(BOARD_DIR)/include/kernel/gen_config.h | cut -d' ' -f4} +SDDF_CUSTOM_LIBC := 1 + +IMAGES := dvfs.elf serial_virt_tx.elf serial_driver.elf timer_driver.elf idle.elf +CFLAGS := -nostdlib \ + -ffreestanding \ + -g3 \ + -O3 \ + -Wall -Wno-unused-function -Werror -Wno-unused-command-line-argument \ + -I$(BOARD_DIR)/include \ + -I$(SDDF)/include \ + -I$(SDDF)/include/microkit \ + -I$(CONFIGS_INCLUDE) +LDFLAGS := -L$(BOARD_DIR)/lib +LIBS := --start-group -lmicrokit -Tmicrokit.ld libsddf_util_debug.a --end-group + +ifeq ($(ARCH),aarch64) + CFLAGS += -mcpu=$(CPU) -target aarch64-none-elf +else ifeq ($(ARCH),riscv64) + CFLAGS += -march=rv64imafdc -target riscv64-none-elf +endif + +DTS := $(SDDF)/dts/$(MICROKIT_BOARD).dts +DTB := $(MICROKIT_BOARD).dtb +METAPROGRAM := $(TOP)/meta.py + +SERIAL_DRIVER := $(SDDF)/drivers/serial/${SERIAL_DRIVER_DIR} + +all: $(IMAGE_FILE) + +include ${SDDF}/drivers/serial/${SERIAL_DRIVER_DIR}/serial_driver.mk +include ${SDDF}/drivers/timer/${TIMER_DRIVER_DIR}/timer_driver.mk + +include ${SDDF}/util/util.mk +include ${SDDF}/serial/components/serial_components.mk + +${IMAGES}: libsddf_util_debug.a + +microkit_sdk_config_dir := $(MICROKIT_SDK)/board/$(MICROKIT_BOARD)/$(MICROKIT_CONFIG) +sel4_include_dirs := $(microkit_sdk_config_dir)/include + +idle.elf: ${SDDF}/examples/dvfs/idle.c + $(CC) -c $(CFLAGS) -I. $< -o idle.o + $(LD) $(LDFLAGS) $^ $(LIBS) -o $@ + +helper.o: ${SDDF}/examples/dvfs/src/helper.c + $(CC) -c $(CFLAGS) $< -o $@ + +libhelper.a: helper.o + ${AR} rcs $@ $< + +dvfs.elf: libhelper.a + @echo "Building dvfs.elf for board $(MICROKIT_BOARD)..." && \ + echo "MICROKIT SDK config directory: $(microkit_sdk_config_dir)" && \ + echo "SEl4 include directories: $(sel4_include_dirs)" && \ + cd .. && \ + SEL4_INCLUDE_DIRS=$(abspath $(sel4_include_dirs)) \ + RUSTFLAGS="-L $(BUILD_DIR)/ -l static=helper" \ + cargo build \ + -Z build-std=core,alloc,compiler_builtins \ + -Z build-std-features=compiler-builtins-mem \ + --target-dir $(BUILD_DIR) \ + --target support/targets/aarch64-sel4-microkit-minimal.json + @echo "Build complete: $(TARGET_ELF)" + cp ./aarch64-sel4-microkit-minimal/debug/dvfs.elf $(BUILD_DIR) + +$(DTB): $(DTS) + dtc -q -I dts -O dtb $(DTS) > $(DTB) + +$(SYSTEM_FILE): $(METAPROGRAM) $(IMAGES) $(DTB) + $(PYTHON) $(METAPROGRAM) --sddf $(SDDF) --board $(MICROKIT_BOARD) --dtb $(DTB) --output . --sdf $(SYSTEM_FILE) $(PARTITION_ARG) + $(OBJCOPY) --update-section .device_resources=timer_driver_device_resources.data timer_driver.elf + $(OBJCOPY) --update-section .timer_client_config=timer_client_blk_driver.data dvfs.elf + $(OBJCOPY) --update-section .device_resources=serial_driver_device_resources.data serial_driver.elf + $(OBJCOPY) --update-section .serial_driver_config=serial_driver_config.data serial_driver.elf + $(OBJCOPY) --update-section .serial_virt_tx_config=serial_virt_tx.data serial_virt_tx.elf + $(OBJCOPY) --update-section .serial_client_config=serial_client_client.data dvfs.elf + +$(IMAGE_FILE) $(REPORT_FILE): $(IMAGES) $(SYSTEM_FILE) + $(MICROKIT_TOOL) $(SYSTEM_FILE) --search-path $(BUILD_DIR) --board $(MICROKIT_BOARD) --config $(MICROKIT_CONFIG) -o $(IMAGE_FILE) -r $(REPORT_FILE) diff --git a/examples/dvfs/idle.c b/examples/dvfs/idle.c new file mode 100644 index 000000000..ebf44a7e8 --- /dev/null +++ b/examples/dvfs/idle.c @@ -0,0 +1,4 @@ +void init(void) +{ + while (1) {} +} \ No newline at end of file diff --git a/examples/dvfs/meta.py b/examples/dvfs/meta.py new file mode 100644 index 000000000..c4b7f5d79 --- /dev/null +++ b/examples/dvfs/meta.py @@ -0,0 +1,98 @@ +# Copyright 2025, UNSW +# SPDX-License-Identifier: BSD-2-Clause +import argparse +from typing import List +from dataclasses import dataclass +from sdfgen import SystemDescription, Sddf, DeviceTree +from importlib.metadata import version + +assert version("sdfgen").split(".")[1] == "24", "Unexpected sdfgen version" + +ProtectionDomain = SystemDescription.ProtectionDomain +MemoryRegion = SystemDescription.MemoryRegion +Map = SystemDescription.Map + +@dataclass +class Board: + name: str + arch: SystemDescription.Arch + paddr_top: int + timer: str + serial: str + + +BOARDS: List[Board] = [ + Board( + name="zcu102", + arch=SystemDescription.Arch.AARCH64, + paddr_top=0xA0000000, + timer="axi/timer@ff140000", + serial="axi/serial@ff000000", + ), +] + + +def generate(sdf_file: str, output_dir: str, dtb: DeviceTree): + timer_driver = ProtectionDomain("timer_driver", "timer_driver.elf", priority=254) + + client = ProtectionDomain("client", "dvfs.elf", priority=100) + + idle = ProtectionDomain("idle", "idle.elf", priority=1) + + serial_driver = ProtectionDomain("serial_driver", "serial_driver.elf", priority=200) + + # Increase the stack size as running with UBSAN uses more stack space than normal. + serial_virt_tx = ProtectionDomain( + "serial_virt_tx", "serial_virt_tx.elf", priority=199, stack_size=0x2000 + ) + + serial_node = dtb.node(board.serial) + assert serial_node is not None + + serial_system = Sddf.Serial( + sdf, serial_node, serial_driver, serial_virt_tx, enable_color=False + ) + serial_system.add_client(client) + + clk_mr = MemoryRegion("clk", 0x1000, paddr=0xFD1A0000) + client.add_map(Map(clk_mr, 0xFD1A0000, "rw", cached=False)) + sdf.add_mr(clk_mr) + + timer_node = dtb.node(board.timer) + assert timer_node is not None + + timer_system = Sddf.Timer(sdf, timer_node, timer_driver) + timer_system.add_client(client) + + pds = [timer_driver, client, serial_driver, serial_virt_tx, idle.elf] + for pd in pds: + sdf.add_pd(pd) + + assert timer_system.connect() + assert timer_system.serialise_config(output_dir) + assert serial_system.connect() + assert serial_system.serialise_config(output_dir) + + with open(f"{output_dir}/{sdf_file}", "w+") as f: + f.write(sdf.render()) + + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument("--dtb", required=True) + parser.add_argument("--sddf", required=True) + parser.add_argument("--board", required=True, choices=[b.name for b in BOARDS]) + parser.add_argument("--output", required=True) + parser.add_argument("--sdf", required=True) + + args = parser.parse_args() + + board = next(filter(lambda b: b.name == args.board, BOARDS)) + + sdf = SystemDescription(board.arch, board.paddr_top) + sddf = Sddf(args.sddf) + + with open(args.dtb, "rb") as f: + dtb = DeviceTree(f.read()) + + generate(args.sdf, args.output, dtb) diff --git a/examples/dvfs/rust-toolchain.toml b/examples/dvfs/rust-toolchain.toml new file mode 100644 index 000000000..65e0b332e --- /dev/null +++ b/examples/dvfs/rust-toolchain.toml @@ -0,0 +1,10 @@ +# +# Copyright 2023, Colias Group, LLC +# +# SPDX-License-Identifier: BSD-2-Clause +# + +[toolchain] +channel = "nightly-2025-07-07" +components = [ "rust-src", "rustc-dev", "llvm-tools-preview" ] +profile = "default" diff --git a/examples/dvfs/src/helper.c b/examples/dvfs/src/helper.c new file mode 100644 index 000000000..7bc072a11 --- /dev/null +++ b/examples/dvfs/src/helper.c @@ -0,0 +1,33 @@ +#include +#include +#include +#include +#include +#include + +__attribute__((__section__(".timer_client_config"))) timer_client_config_t timer_config; + +__attribute__((__section__(".serial_client_config"))) serial_client_config_t serial_config; + +serial_queue_handle_t serial_tx_queue_handle; + +void wait() { + sddf_timer_set_timeout(timer_config.driver_id, 1000000000); +} + +void print_count(uint64_t cycle) { + sddf_printf("Cycle count: %lu\n", cycle); +} + +uint64_t read_count() { + uint64_t ccnt; + SEL4BENCH_READ_CCNT(ccnt); + return ccnt; +} + +void counter_init() { + serial_queue_init(&serial_tx_queue_handle, serial_config.tx.queue.vaddr, serial_config.tx.data.size, + serial_config.tx.data.vaddr); + serial_putchar_init(serial_config.tx.id, &serial_tx_queue_handle); + sel4bench_init(); +} diff --git a/examples/dvfs/src/helper.rs b/examples/dvfs/src/helper.rs new file mode 100644 index 000000000..306a1219c --- /dev/null +++ b/examples/dvfs/src/helper.rs @@ -0,0 +1,9 @@ +unsafe extern "C" { + pub unsafe fn wait(); + + pub unsafe fn print_count(cycle: u64); + + pub unsafe fn counter_init(); + + pub unsafe fn read_count() -> u64; +} \ No newline at end of file diff --git a/examples/dvfs/src/main.rs b/examples/dvfs/src/main.rs new file mode 100644 index 000000000..1d5f3627f --- /dev/null +++ b/examples/dvfs/src/main.rs @@ -0,0 +1,84 @@ +#![no_std] // Don't link the standard library +#![no_main] // Don't use the default entry point + +use core::convert::Infallible; + +use cpufreq::freq_trait::FreqOps; + +use crate::platforms::xilinx::Xilinx; + +use sel4_microkit::{debug_println, protection_domain, Handler}; + +mod platforms; + +mod helper; + +#[protection_domain] +fn init() -> impl Handler { + unsafe { + helper::counter_init(); + } + + let res: u64 = Xilinx::get_freq(0); + + debug_println!("Current {:#x}", res); + + unsafe { + let pre_count = helper::read_count(); + helper::wait(); + let post_count = helper::read_count(); + helper::print_count(post_count - pre_count); + } + + debug_println!("Change clk frequency"); + + Xilinx::set_freq(0); + + let res: u64 = Xilinx::get_freq(0); + + debug_println!("Current {:#x}", res); + + unsafe { + let pre_count = helper::read_count(); + helper::wait(); + let post_count = helper::read_count(); + helper::print_count(post_count - pre_count); + } + + HandlerImpl{} +} + +struct HandlerImpl { +} + +impl Handler for HandlerImpl +{ + type Error = Infallible; + + fn notified(&mut self, channels: sel4_microkit::ChannelSet) -> Result<(), Self::Error> { + core::panic!( + "unexpected notification from channels {}", + channels.display() + ) + } + + fn protected( + &mut self, + channel: sel4_microkit::Channel, + msg_info: sel4_microkit::MessageInfo, + ) -> Result { + core::panic!("unexpected protected procedure call from channel {channel:?} with msg_info={msg_info:?}") + } + + fn fault( + &mut self, + child: sel4_microkit::Child, + msg_info: sel4_microkit::MessageInfo, + ) -> Result, Self::Error> { + core::panic!("unexpected fault from protection domain {child:?} with msg_info={msg_info:?}") + } + + fn take_deferred_action(&mut self) -> Option { + None + } +} \ No newline at end of file diff --git a/examples/dvfs/src/platforms/mod.rs b/examples/dvfs/src/platforms/mod.rs new file mode 100644 index 000000000..81800575e --- /dev/null +++ b/examples/dvfs/src/platforms/mod.rs @@ -0,0 +1 @@ +pub mod xilinx; \ No newline at end of file diff --git a/examples/dvfs/src/platforms/xilinx.rs b/examples/dvfs/src/platforms/xilinx.rs new file mode 100644 index 000000000..f48734e92 --- /dev/null +++ b/examples/dvfs/src/platforms/xilinx.rs @@ -0,0 +1,37 @@ +use cpufreq::freq_trait::{FreqOps, OppEntry}; + +pub const OPP_TABLE: &[OppEntry] = &[ + OppEntry { + freq_hz: 1199999988, + voltage_uv: 1000000, + latency_ns: 500000, + }, + OppEntry { + freq_hz: 599999994, + voltage_uv: 1000000, + latency_ns: 500000, + }, + OppEntry { + freq_hz: 399999996, + voltage_uv: 1000000, + latency_ns: 500000, + }, + OppEntry { + freq_hz: 299999997, + voltage_uv: 1000000, + latency_ns: 500000, + }, +]; + +pub const CPU_OPP_TABLE: &[&[OppEntry]] = &[ + OPP_TABLE, + OPP_TABLE, + OPP_TABLE, + OPP_TABLE, +]; + +pub struct Xilinx {} + +impl FreqOps for Xilinx { + const CPU_OPP_TABLE: &[&[OppEntry]] = CPU_OPP_TABLE; +} \ No newline at end of file diff --git a/examples/dvfs/support/targets/aarch64-sel4-microkit-minimal.json b/examples/dvfs/support/targets/aarch64-sel4-microkit-minimal.json new file mode 100644 index 000000000..322a1359d --- /dev/null +++ b/examples/dvfs/support/targets/aarch64-sel4-microkit-minimal.json @@ -0,0 +1,35 @@ +{ + "arch": "aarch64", + "crt-objects-fallback": "false", + "data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32", + "disable-redzone": true, + "exe-suffix": ".elf", + "features": "+v8a,+strict-align,+neon,+fp-armv8", + "link-script": "__sel4_ipc_buffer_obj = (__ehdr_start & ~(4096 - 1)) - 4096;", + "linker": "rust-lld", + "linker-flavor": "gnu-lld", + "llvm-target": "aarch64-unknown-none", + "max-atomic-width": 128, + "metadata": { + "description": null, + "host_tools": null, + "std": null, + "tier": null + }, + "panic-strategy": "abort", + "pre-link-args": { + "gnu-lld": [ + "-z", + "max-page-size=4096" + ] + }, + "relocation-model": "static", + "stack-probes": { + "kind": "inline" + }, + "supported-sanitizers": [ + "kcfi", + "kernel-address" + ], + "target-pointer-width": "64" +} From 9df09612f220dbe060ed39ef7e431a67e95be955 Mon Sep 17 00:00:00 2001 From: Cheng Date: Fri, 20 Jun 2025 17:42:07 +1000 Subject: [PATCH 02/18] Add timer driver interface in Rust Signed-off-by: Cheng --- include/sddf_rust/timer/Cargo.toml | 13 +++++++++++++ include/sddf_rust/timer/lib.rs | 3 +++ include/sddf_rust/timer/timer.rs | 30 ++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 include/sddf_rust/timer/Cargo.toml create mode 100644 include/sddf_rust/timer/lib.rs create mode 100644 include/sddf_rust/timer/timer.rs diff --git a/include/sddf_rust/timer/Cargo.toml b/include/sddf_rust/timer/Cargo.toml new file mode 100644 index 000000000..2fbc153ae --- /dev/null +++ b/include/sddf_rust/timer/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "sddf_timer" +version = "0.1.0" +edition = "2021" +authors = ["Cheng Li 李澄 "] + +[lib] +name = "sddf_timer" +path = "lib.rs" + +[dependencies] +sel4-microkit = { git = "https://github.com/seL4/rust-sel4.git", rev = "ac5627ba7a67e71f33a8eb1c5d05de09bf94ef5e" } +# sel4-microkit-message = { git = "https://github.com/seL4/rust-sel4.git", rev = "ac5627ba7a67e71f33a8eb1c5d05de09bf94ef5e" } \ No newline at end of file diff --git a/include/sddf_rust/timer/lib.rs b/include/sddf_rust/timer/lib.rs new file mode 100644 index 000000000..471cc85a6 --- /dev/null +++ b/include/sddf_rust/timer/lib.rs @@ -0,0 +1,3 @@ +#![no_std] // Don't link the standard library + +pub mod timer; diff --git a/include/sddf_rust/timer/timer.rs b/include/sddf_rust/timer/timer.rs new file mode 100644 index 000000000..cd7f36df7 --- /dev/null +++ b/include/sddf_rust/timer/timer.rs @@ -0,0 +1,30 @@ +use sel4_microkit::MessageInfo; + +enum SddfTimer { + GetTime = 0, + SetTimeout = 1, +} + +pub struct Timer { + channel: sel4_microkit::Channel, +} + +impl Timer { + pub const fn new(server_channel: sel4_microkit::Channel) -> Self { + Timer { + channel: server_channel, + } + } + + pub fn set_timeout(&self, timeout: u64) { + sel4_microkit::set_mr(0, timeout); + let msg_info: MessageInfo = MessageInfo::new(SddfTimer::SetTimeout as u64, 1); + self.channel.pp_call(msg_info); + } + + pub fn time_now(&self) -> u64 { + let msg_info: MessageInfo = MessageInfo::new(SddfTimer::GetTime as u64, 0); + self.channel.pp_call(msg_info); + sel4_microkit::get_mr(0) + } +} From e488171c8f83474e9f28c52d7116afcbb0d1c307 Mon Sep 17 00:00:00 2001 From: Cheng Date: Wed, 16 Jul 2025 16:21:37 +1000 Subject: [PATCH 03/18] Update rust-sel4 for timer Signed-off-by: Cheng --- include/sddf_rust/timer/Cargo.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/sddf_rust/timer/Cargo.toml b/include/sddf_rust/timer/Cargo.toml index 2fbc153ae..f2cc7a4ae 100644 --- a/include/sddf_rust/timer/Cargo.toml +++ b/include/sddf_rust/timer/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "sddf_timer" version = "0.1.0" -edition = "2021" +edition = "2024" authors = ["Cheng Li 李澄 "] [lib] @@ -9,5 +9,5 @@ name = "sddf_timer" path = "lib.rs" [dependencies] -sel4-microkit = { git = "https://github.com/seL4/rust-sel4.git", rev = "ac5627ba7a67e71f33a8eb1c5d05de09bf94ef5e" } -# sel4-microkit-message = { git = "https://github.com/seL4/rust-sel4.git", rev = "ac5627ba7a67e71f33a8eb1c5d05de09bf94ef5e" } \ No newline at end of file +sel4-microkit = { git = "https://github.com/seL4/rust-sel4.git", rev = "d2bc5cf71c5455f85898a4768e9dcbaea39e1a7e" } +# sel4-microkit-message = { git = "https://github.com/seL4/rust-sel4.git", rev = "d2bc5cf71c5455f85898a4768e9dcbaea39e1a7e" } \ No newline at end of file From 47f5739cdaa6c9bc04602abf52a9fc8b4e27402f Mon Sep 17 00:00:00 2001 From: Cheng Date: Thu, 4 Sep 2025 15:19:32 +1000 Subject: [PATCH 04/18] Successfully validated the correctness of the DVFS driver for ZCU102 Signed-off-by: Cheng --- examples/dvfs/Cargo.toml | 1 + examples/dvfs/dvfs.mk | 24 ++------------------ examples/dvfs/idle.c | 4 ---- examples/dvfs/meta.py | 23 +------------------ examples/dvfs/src/helper.c | 33 ---------------------------- examples/dvfs/src/helper.rs | 9 -------- examples/dvfs/src/main.rs | 44 +++++++++++++++++++++++-------------- 7 files changed, 31 insertions(+), 107 deletions(-) delete mode 100644 examples/dvfs/idle.c delete mode 100644 examples/dvfs/src/helper.c delete mode 100644 examples/dvfs/src/helper.rs diff --git a/examples/dvfs/Cargo.toml b/examples/dvfs/Cargo.toml index 693adad0d..0c5949685 100644 --- a/examples/dvfs/Cargo.toml +++ b/examples/dvfs/Cargo.toml @@ -6,6 +6,7 @@ edition = "2024" [dependencies] sel4-microkit = { git = "https://github.com/seL4/rust-sel4.git", rev = "d2bc5cf71c5455f85898a4768e9dcbaea39e1a7e" } cpufreq = { git = "https://github.com/Cheng-Li1/freq-scaling-rs.git", rev = "29da4a2b7817c306e282783474a4b99d7442f066" } +sddf_timer = { path = "../../include/sddf_rust/timer" } [net] net.git-fetch-with-cli = true \ No newline at end of file diff --git a/examples/dvfs/dvfs.mk b/examples/dvfs/dvfs.mk index 63f3a8f37..9d3048ba3 100644 --- a/examples/dvfs/dvfs.mk +++ b/examples/dvfs/dvfs.mk @@ -46,7 +46,6 @@ SYSTEM_FILE := dvfs.system ifeq ($(strip $(MICROKIT_BOARD)), zcu102) CPU := cortex-a53 - SERIAL_DRIVER_DIR := zynqmp TIMER_DRIVER_DIR := cdns else $(error Unsupported MICROKIT_BOARD given) @@ -67,7 +66,7 @@ BOARD_DIR := $(MICROKIT_SDK)/board/$(MICROKIT_BOARD)/$(MICROKIT_CONFIG) ARCH := ${shell grep 'CONFIG_SEL4_ARCH ' $(BOARD_DIR)/include/kernel/gen_config.h | cut -d' ' -f4} SDDF_CUSTOM_LIBC := 1 -IMAGES := dvfs.elf serial_virt_tx.elf serial_driver.elf timer_driver.elf idle.elf +IMAGES := dvfs.elf timer_driver.elf CFLAGS := -nostdlib \ -ffreestanding \ -g3 \ @@ -90,32 +89,18 @@ DTS := $(SDDF)/dts/$(MICROKIT_BOARD).dts DTB := $(MICROKIT_BOARD).dtb METAPROGRAM := $(TOP)/meta.py -SERIAL_DRIVER := $(SDDF)/drivers/serial/${SERIAL_DRIVER_DIR} - all: $(IMAGE_FILE) -include ${SDDF}/drivers/serial/${SERIAL_DRIVER_DIR}/serial_driver.mk include ${SDDF}/drivers/timer/${TIMER_DRIVER_DIR}/timer_driver.mk include ${SDDF}/util/util.mk -include ${SDDF}/serial/components/serial_components.mk ${IMAGES}: libsddf_util_debug.a microkit_sdk_config_dir := $(MICROKIT_SDK)/board/$(MICROKIT_BOARD)/$(MICROKIT_CONFIG) sel4_include_dirs := $(microkit_sdk_config_dir)/include -idle.elf: ${SDDF}/examples/dvfs/idle.c - $(CC) -c $(CFLAGS) -I. $< -o idle.o - $(LD) $(LDFLAGS) $^ $(LIBS) -o $@ - -helper.o: ${SDDF}/examples/dvfs/src/helper.c - $(CC) -c $(CFLAGS) $< -o $@ - -libhelper.a: helper.o - ${AR} rcs $@ $< - -dvfs.elf: libhelper.a +dvfs.elf: @echo "Building dvfs.elf for board $(MICROKIT_BOARD)..." && \ echo "MICROKIT SDK config directory: $(microkit_sdk_config_dir)" && \ echo "SEl4 include directories: $(sel4_include_dirs)" && \ @@ -136,11 +121,6 @@ $(DTB): $(DTS) $(SYSTEM_FILE): $(METAPROGRAM) $(IMAGES) $(DTB) $(PYTHON) $(METAPROGRAM) --sddf $(SDDF) --board $(MICROKIT_BOARD) --dtb $(DTB) --output . --sdf $(SYSTEM_FILE) $(PARTITION_ARG) $(OBJCOPY) --update-section .device_resources=timer_driver_device_resources.data timer_driver.elf - $(OBJCOPY) --update-section .timer_client_config=timer_client_blk_driver.data dvfs.elf - $(OBJCOPY) --update-section .device_resources=serial_driver_device_resources.data serial_driver.elf - $(OBJCOPY) --update-section .serial_driver_config=serial_driver_config.data serial_driver.elf - $(OBJCOPY) --update-section .serial_virt_tx_config=serial_virt_tx.data serial_virt_tx.elf - $(OBJCOPY) --update-section .serial_client_config=serial_client_client.data dvfs.elf $(IMAGE_FILE) $(REPORT_FILE): $(IMAGES) $(SYSTEM_FILE) $(MICROKIT_TOOL) $(SYSTEM_FILE) --search-path $(BUILD_DIR) --board $(MICROKIT_BOARD) --config $(MICROKIT_CONFIG) -o $(IMAGE_FILE) -r $(REPORT_FILE) diff --git a/examples/dvfs/idle.c b/examples/dvfs/idle.c deleted file mode 100644 index ebf44a7e8..000000000 --- a/examples/dvfs/idle.c +++ /dev/null @@ -1,4 +0,0 @@ -void init(void) -{ - while (1) {} -} \ No newline at end of file diff --git a/examples/dvfs/meta.py b/examples/dvfs/meta.py index c4b7f5d79..1528dc7fe 100644 --- a/examples/dvfs/meta.py +++ b/examples/dvfs/meta.py @@ -18,7 +18,6 @@ class Board: arch: SystemDescription.Arch paddr_top: int timer: str - serial: str BOARDS: List[Board] = [ @@ -27,7 +26,6 @@ class Board: arch=SystemDescription.Arch.AARCH64, paddr_top=0xA0000000, timer="axi/timer@ff140000", - serial="axi/serial@ff000000", ), ] @@ -37,23 +35,6 @@ def generate(sdf_file: str, output_dir: str, dtb: DeviceTree): client = ProtectionDomain("client", "dvfs.elf", priority=100) - idle = ProtectionDomain("idle", "idle.elf", priority=1) - - serial_driver = ProtectionDomain("serial_driver", "serial_driver.elf", priority=200) - - # Increase the stack size as running with UBSAN uses more stack space than normal. - serial_virt_tx = ProtectionDomain( - "serial_virt_tx", "serial_virt_tx.elf", priority=199, stack_size=0x2000 - ) - - serial_node = dtb.node(board.serial) - assert serial_node is not None - - serial_system = Sddf.Serial( - sdf, serial_node, serial_driver, serial_virt_tx, enable_color=False - ) - serial_system.add_client(client) - clk_mr = MemoryRegion("clk", 0x1000, paddr=0xFD1A0000) client.add_map(Map(clk_mr, 0xFD1A0000, "rw", cached=False)) sdf.add_mr(clk_mr) @@ -64,14 +45,12 @@ def generate(sdf_file: str, output_dir: str, dtb: DeviceTree): timer_system = Sddf.Timer(sdf, timer_node, timer_driver) timer_system.add_client(client) - pds = [timer_driver, client, serial_driver, serial_virt_tx, idle.elf] + pds = [timer_driver, client] for pd in pds: sdf.add_pd(pd) assert timer_system.connect() assert timer_system.serialise_config(output_dir) - assert serial_system.connect() - assert serial_system.serialise_config(output_dir) with open(f"{output_dir}/{sdf_file}", "w+") as f: f.write(sdf.render()) diff --git a/examples/dvfs/src/helper.c b/examples/dvfs/src/helper.c deleted file mode 100644 index 7bc072a11..000000000 --- a/examples/dvfs/src/helper.c +++ /dev/null @@ -1,33 +0,0 @@ -#include -#include -#include -#include -#include -#include - -__attribute__((__section__(".timer_client_config"))) timer_client_config_t timer_config; - -__attribute__((__section__(".serial_client_config"))) serial_client_config_t serial_config; - -serial_queue_handle_t serial_tx_queue_handle; - -void wait() { - sddf_timer_set_timeout(timer_config.driver_id, 1000000000); -} - -void print_count(uint64_t cycle) { - sddf_printf("Cycle count: %lu\n", cycle); -} - -uint64_t read_count() { - uint64_t ccnt; - SEL4BENCH_READ_CCNT(ccnt); - return ccnt; -} - -void counter_init() { - serial_queue_init(&serial_tx_queue_handle, serial_config.tx.queue.vaddr, serial_config.tx.data.size, - serial_config.tx.data.vaddr); - serial_putchar_init(serial_config.tx.id, &serial_tx_queue_handle); - sel4bench_init(); -} diff --git a/examples/dvfs/src/helper.rs b/examples/dvfs/src/helper.rs deleted file mode 100644 index 306a1219c..000000000 --- a/examples/dvfs/src/helper.rs +++ /dev/null @@ -1,9 +0,0 @@ -unsafe extern "C" { - pub unsafe fn wait(); - - pub unsafe fn print_count(cycle: u64); - - pub unsafe fn counter_init(); - - pub unsafe fn read_count() -> u64; -} \ No newline at end of file diff --git a/examples/dvfs/src/main.rs b/examples/dvfs/src/main.rs index 1d5f3627f..cb923426c 100644 --- a/examples/dvfs/src/main.rs +++ b/examples/dvfs/src/main.rs @@ -4,6 +4,7 @@ use core::convert::Infallible; use cpufreq::freq_trait::FreqOps; +use sddf_timer::timer::Timer; use crate::platforms::xilinx::Xilinx; @@ -11,24 +12,30 @@ use sel4_microkit::{debug_println, protection_domain, Handler}; mod platforms; -mod helper; +const TIMER: Timer = Timer::new(sel4_microkit::Channel::new(0)); -#[protection_domain] -fn init() -> impl Handler { - unsafe { - helper::counter_init(); +fn usleep(time_us: u32) { + let time_ns: u64 = time_us as u64 * 1000; + for _ in 0..time_ns { + core::hint::spin_loop(); // Use spin loop hint to reduce contention during the wait } +} +#[protection_domain] +fn init() -> impl Handler { let res: u64 = Xilinx::get_freq(0); debug_println!("Current {:#x}", res); - unsafe { - let pre_count = helper::read_count(); - helper::wait(); - let post_count = helper::read_count(); - helper::print_count(post_count - pre_count); - } + let mut past_time: u64 = TIMER.time_now(); + + usleep(1000_000); + + let mut current_time: u64 = TIMER.time_now(); + + let mut time_elapsed: u64 = current_time - past_time; + + debug_println!("Elapsed time: {} ns", time_elapsed); debug_println!("Change clk frequency"); @@ -38,12 +45,15 @@ fn init() -> impl Handler { debug_println!("Current {:#x}", res); - unsafe { - let pre_count = helper::read_count(); - helper::wait(); - let post_count = helper::read_count(); - helper::print_count(post_count - pre_count); - } + past_time = TIMER.time_now(); + + usleep(1000_000); + + current_time = TIMER.time_now(); + + time_elapsed = current_time - past_time; + + debug_println!("Elapsed time: {} ns", time_elapsed); HandlerImpl{} } From 7fd3db71bb734f9d7493347da4f8f0b56df53a01 Mon Sep 17 00:00:00 2001 From: Cheng Li Date: Mon, 10 Nov 2025 16:56:12 +1100 Subject: [PATCH 05/18] Add C version of DVFS interfaces. Signed-off-by: Cheng Li --- include/sddf/dvfs/client.h | 70 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 include/sddf/dvfs/client.h diff --git a/include/sddf/dvfs/client.h b/include/sddf/dvfs/client.h new file mode 100644 index 000000000..72a7497a7 --- /dev/null +++ b/include/sddf/dvfs/client.h @@ -0,0 +1,70 @@ +/* + * Copyright 2025, UNSW + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include +#include + +typedef struct { + uint64_t freq_hz; + uint64_t voltage_uv; + uint64_t latency_ns; +} OppEntry; + +typedef struct { + uint64_t core_ident; + uint64_t clock_source_ident; + const OppEntry *opptable; + size_t opptable_len; +} CoreInfo; + +#ifdef CONFIG_PLAT_ZYNQMP_ZCU102 +const OppEntry OPP_TABLE[] = { + { .freq_hz = 1199999988, .voltage_uv = 1000000, .latency_ns = 500000 }, + { .freq_hz = 599999994, .voltage_uv = 1000000, .latency_ns = 500000 }, + { .freq_hz = 399999996, .voltage_uv = 1000000, .latency_ns = 500000 }, + { .freq_hz = 299999997, .voltage_uv = 1000000, .latency_ns = 500000 }, +}; + +const size_t OPP_TABLE_LEN = sizeof(OPP_TABLE) / sizeof(OPP_TABLE[0]); + +const CoreInfo CPU_INFO[] = { + { .core_ident = 0, .clock_source_ident = 0, .opptable = OPP_TABLE, .opptable_len = OPP_TABLE_LEN }, + { .core_ident = 1, .clock_source_ident = 0, .opptable = OPP_TABLE, .opptable_len = OPP_TABLE_LEN }, + { .core_ident = 2, .clock_source_ident = 0, .opptable = OPP_TABLE, .opptable_len = OPP_TABLE_LEN }, + { .core_ident = 3, .clock_source_ident = 0, .opptable = OPP_TABLE, .opptable_len = OPP_TABLE_LEN }, +}; + +const size_t CPU_INFO_LEN = sizeof(CPU_INFO) / sizeof(CPU_INFO[0]); +#endif + +#define SDDF_DVFS_GET_FREQ 0 +#define SDDF_DVFS_SET_FREQ 1 + +static inline int32_t get_freq(unsigned int channel, uint64_t core_ident, uint32_t *freq) +{ + sddf_set_mr(0, core_ident); + + sddf_ppcall(channel, seL4_MessageInfo_new(SDDF_DVFS_GET_FREQ, 0, 0, 1)); + + uint32_t error = sddf_get_mr(0); + if (!error) { + *freq = sddf_get_mr(1); + } + return error; +} + +static inline int32_t set_freq(unsigned int channel, uint64_t core_ident, uint32_t freq) +{ + sddf_set_mr(0, core_ident); + sddf_set_mr(1, freq); + + sddf_ppcall(channel, seL4_MessageInfo_new(SDDF_DVFS_SET_FREQ, 0, 0, 2)); + + return sddf_get_mr(0); +} \ No newline at end of file From dd88f5fbf265065cd74df18cb7a997e0eea352e6 Mon Sep 17 00:00:00 2001 From: Cheng Li Date: Tue, 11 Nov 2025 14:06:47 +1100 Subject: [PATCH 06/18] Add C version of DVFS example and modify the name of functions. Signed-off-by: Cheng Li --- examples/dvfs/client.c | 55 ++++++++++++++++++++++++++++++++++++++ include/sddf/dvfs/client.h | 4 +-- 2 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 examples/dvfs/client.c diff --git a/examples/dvfs/client.c b/examples/dvfs/client.c new file mode 100644 index 000000000..b57fd6633 --- /dev/null +++ b/examples/dvfs/client.c @@ -0,0 +1,55 @@ +/* + * Copyright 2025, UNSW + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include "microkit.h" +#include +#include +#include +#include +#include + +__attribute__((__section__(".timer_client_config"))) timer_client_config_t config; + +microkit_channel timer_channel; +microkit_channel dvfs_channel; + +#define LOOP_LIMITATION 100000 +void cpu_intensive_loop() { + volatile int i; + + for (i = 0; i < LOOP_LIMITATION; i++) { + + } +} + +void init(void) { + uint64_t time_start = sddf_timer_time_now(timer_channel); + + uint32_t freq = 0; + + uint32_t res = sddf_dvfs_get_freq(dvfs_channel, CPU_INFO[0].core_ident, &freq); + + if (res != 0) { + sddf_printf_("DVFS Client: Fail to get the frequency\n"); + } + + cpu_intensive_loop(); + + uint64_t time_mid = sddf_timer_time_now(timer_channel); + + res = sddf_dvfs_set_freq(dvfs_channel, CPU_INFO[0].core_ident, CPU_INFO[0].opptable[1].freq_hz); + + if (res != 0) { + sddf_printf_("DVFS Client: Fail to set the frequency\n"); + } + + cpu_intensive_loop(); + + uint64_t time_end = sddf_timer_time_now(timer_channel); + + sddf_printf_("%lu ns takes under Frequency: %d", time_mid - time_start, freq); + + sddf_printf_("%lu ns takes under Frequency: %lu", time_end - time_mid, CPU_INFO[0].opptable[1].freq_hz); +} \ No newline at end of file diff --git a/include/sddf/dvfs/client.h b/include/sddf/dvfs/client.h index 72a7497a7..4d4f28e45 100644 --- a/include/sddf/dvfs/client.h +++ b/include/sddf/dvfs/client.h @@ -46,7 +46,7 @@ const size_t CPU_INFO_LEN = sizeof(CPU_INFO) / sizeof(CPU_INFO[0]); #define SDDF_DVFS_GET_FREQ 0 #define SDDF_DVFS_SET_FREQ 1 -static inline int32_t get_freq(unsigned int channel, uint64_t core_ident, uint32_t *freq) +static inline int32_t sddf_dvfs_get_freq(unsigned int channel, uint64_t core_ident, uint32_t *freq) { sddf_set_mr(0, core_ident); @@ -59,7 +59,7 @@ static inline int32_t get_freq(unsigned int channel, uint64_t core_ident, uint32 return error; } -static inline int32_t set_freq(unsigned int channel, uint64_t core_ident, uint32_t freq) +static inline int32_t sddf_dvfs_set_freq(unsigned int channel, uint64_t core_ident, uint32_t freq) { sddf_set_mr(0, core_ident); sddf_set_mr(1, freq); From c53cc7510602f4c3c4ad9439ff95d0d9b60194bd Mon Sep 17 00:00:00 2001 From: Cheng Li Date: Mon, 17 Nov 2025 16:54:26 +1100 Subject: [PATCH 07/18] Minor change to the dvfs client. Signed-off-by: Cheng Li --- examples/dvfs/client.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/dvfs/client.c b/examples/dvfs/client.c index b57fd6633..963d1d836 100644 --- a/examples/dvfs/client.c +++ b/examples/dvfs/client.c @@ -33,6 +33,7 @@ void init(void) { if (res != 0) { sddf_printf_("DVFS Client: Fail to get the frequency\n"); + return; } cpu_intensive_loop(); @@ -43,6 +44,7 @@ void init(void) { if (res != 0) { sddf_printf_("DVFS Client: Fail to set the frequency\n"); + return; } cpu_intensive_loop(); From 9ef2269ac87c5d91e2a28d25dc838469e0e3fe93 Mon Sep 17 00:00:00 2001 From: Cheng Li Date: Tue, 18 Nov 2025 15:04:29 +1100 Subject: [PATCH 08/18] Integrate the changes from the DVFS driver. Signed-off-by: Cheng Li --- drivers/dvfs/.cargo/config.toml | 11 +++ drivers/dvfs/Cargo.toml | 11 +++ .../dvfs/rust-toolchain.toml | 2 +- drivers/dvfs/src/main.rs | 50 ++++++++++ examples/dvfs/Cargo.toml | 12 --- examples/dvfs/Makefile | 10 +- examples/dvfs/client.c | 15 ++- examples/dvfs/dvfs.mk | 23 ++--- examples/dvfs/src/main.rs | 94 ------------------- examples/dvfs/src/platforms/mod.rs | 1 - examples/dvfs/src/platforms/xilinx.rs | 37 -------- .../aarch64-sel4-microkit-minimal.json | 0 12 files changed, 95 insertions(+), 171 deletions(-) create mode 100644 drivers/dvfs/.cargo/config.toml create mode 100644 drivers/dvfs/Cargo.toml rename {examples => drivers}/dvfs/rust-toolchain.toml (85%) create mode 100644 drivers/dvfs/src/main.rs delete mode 100644 examples/dvfs/Cargo.toml delete mode 100644 examples/dvfs/src/main.rs delete mode 100644 examples/dvfs/src/platforms/mod.rs delete mode 100644 examples/dvfs/src/platforms/xilinx.rs rename {examples/dvfs/support => support}/targets/aarch64-sel4-microkit-minimal.json (100%) diff --git a/drivers/dvfs/.cargo/config.toml b/drivers/dvfs/.cargo/config.toml new file mode 100644 index 000000000..e905109ce --- /dev/null +++ b/drivers/dvfs/.cargo/config.toml @@ -0,0 +1,11 @@ +[build] +target = "../../support/targets/aarch64-sel4-microkit-minimal.json" + +[unstable] +build-std = ["core", "compiler_builtins", "alloc"] +build-std-features = ["compiler-builtins-mem"] + +[net] +git-fetch-with-cli = true + +[target."aarch64-sel4-microkit-minimal"] \ No newline at end of file diff --git a/drivers/dvfs/Cargo.toml b/drivers/dvfs/Cargo.toml new file mode 100644 index 000000000..e09134e4c --- /dev/null +++ b/drivers/dvfs/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "dvfs_driver" +version = "0.1.0" +edition = "2021" +authors = ["Cheng Li 李澄 "] + +[dependencies] +cpufreq = { git = "ssh://git@github.com/Cheng-Li1/freq-scaling-rs.git", rev = "80c5d93d258b1e2abf8939592643f105b53c7fed" } +sel4-microkit = { git = "https://github.com/seL4/rust-sel4.git", tag = "v2.0.0" } +sddf-ipc-types = { git = "https://github.com/seL4/rust-sel4.git", rev = "95feffab18a1b46b9feb78aa599dd2f23c8eb364" } +sddf-rust = { path = "../../" } \ No newline at end of file diff --git a/examples/dvfs/rust-toolchain.toml b/drivers/dvfs/rust-toolchain.toml similarity index 85% rename from examples/dvfs/rust-toolchain.toml rename to drivers/dvfs/rust-toolchain.toml index 65e0b332e..ff579f5f7 100644 --- a/examples/dvfs/rust-toolchain.toml +++ b/drivers/dvfs/rust-toolchain.toml @@ -5,6 +5,6 @@ # [toolchain] -channel = "nightly-2025-07-07" +channel = "nightly-2025-10-20" components = [ "rust-src", "rustc-dev", "llvm-tools-preview" ] profile = "default" diff --git a/drivers/dvfs/src/main.rs b/drivers/dvfs/src/main.rs new file mode 100644 index 000000000..8efbbff00 --- /dev/null +++ b/drivers/dvfs/src/main.rs @@ -0,0 +1,50 @@ +#![no_std] // Don't link the standard library +#![no_main] // Don't use the default entry point + +use core::convert::Infallible; + +use cpufreq::{freq_trait::FreqOps, platforms::xilinx::Xilinx}; +use sddf_ipc_types::{MessageWriter, ReadFromMessage}; +use sddf_rust::dvfs::dvfs::{DvfsReq, DvfsResp}; +use sel4_microkit::{Channel, Handler, MessageInfo, debug_println, protection_domain, with_msg_regs, with_msg_regs_mut}; + +#[protection_domain] +fn init() -> impl Handler { + HandlerImpl {} +} + +struct HandlerImpl {} + +impl Handler for HandlerImpl { + type Error = Infallible; + fn protected( + &mut self, + channel: Channel, + msg_info: MessageInfo, + ) -> Result { + debug_println!("Coming from channel: {}", channel.index()); + + let message = with_msg_regs(|buf| DvfsReq::read_from_message(msg_info.label(), buf)); + + let resp = match message { + Ok(req) => match req { + DvfsReq::GetFreq { core_ident } => match Xilinx::get_freq(core_ident) { + Ok(freq) => DvfsResp::GetFreq { freq_hz: freq }, + Err(_) => DvfsResp::Error, + }, + DvfsReq::SetFreq { + core_ident, + freq_hz, + } => match Xilinx::set_freq(core_ident, freq_hz) { + Ok(()) => DvfsResp::SetFreq, + Err(_) => DvfsResp::Error, + }, + }, + Err(_) => DvfsResp::Error, + }; + + let (label, count) = with_msg_regs_mut(|buf| resp.write_message(buf)).unwrap(); + + Ok(MessageInfo::new(label, count)) + } +} diff --git a/examples/dvfs/Cargo.toml b/examples/dvfs/Cargo.toml deleted file mode 100644 index 0c5949685..000000000 --- a/examples/dvfs/Cargo.toml +++ /dev/null @@ -1,12 +0,0 @@ -[package] -name = "dvfs" -version = "0.1.0" -edition = "2024" - -[dependencies] -sel4-microkit = { git = "https://github.com/seL4/rust-sel4.git", rev = "d2bc5cf71c5455f85898a4768e9dcbaea39e1a7e" } -cpufreq = { git = "https://github.com/Cheng-Li1/freq-scaling-rs.git", rev = "29da4a2b7817c306e282783474a4b99d7442f066" } -sddf_timer = { path = "../../include/sddf_rust/timer" } - -[net] -net.git-fetch-with-cli = true \ No newline at end of file diff --git a/examples/dvfs/Makefile b/examples/dvfs/Makefile index cab7c83f2..75aa8c7ae 100644 --- a/examples/dvfs/Makefile +++ b/examples/dvfs/Makefile @@ -17,16 +17,16 @@ export BUILD_DIR export SDDF := $(abspath ../..) override MICROKIT_SDK := $(abspath ${MICROKIT_SDK}) -IMAGE_FILE := ${BUILD_DIR}/loader.img -REPORT_FILE := ${BUILD_DIR}/report.txt +IMAGE_FILE := $(BUILD_DIR)/loader.img +REPORT_FILE := $(BUILD_DIR)/report.txt all: ${IMAGE_FILE} -qemu ${IMAGE_FILE} ${REPORT_FILE} clean clobber: ${BUILD_DIR}/Makefile FORCE - ${MAKE} -C ${BUILD_DIR} MICROKIT_SDK=${MICROKIT_SDK} $(notdir $@) +qemu ${IMAGE_FILE} ${REPORT_FILE} clean clobber: $(IMAGE_FILE) ${BUILD_DIR}/Makefile FORCE + ${MAKE} -C ${BUILD_DIR} MICROKIT_SDK=${MICROKIT_SDK} $(notdir $@) ${BUILD_DIR}/Makefile: dvfs.mk mkdir -p ${BUILD_DIR} - cp dvfs.mk $@ + cp dvfs.mk ${BUILD_DIR}/Makefile FORCE: diff --git a/examples/dvfs/client.c b/examples/dvfs/client.c index 963d1d836..5e8bbe036 100644 --- a/examples/dvfs/client.c +++ b/examples/dvfs/client.c @@ -12,10 +12,9 @@ __attribute__((__section__(".timer_client_config"))) timer_client_config_t config; -microkit_channel timer_channel; -microkit_channel dvfs_channel; - +#define DVFS_CHANNEL 1 #define LOOP_LIMITATION 100000 + void cpu_intensive_loop() { volatile int i; @@ -25,11 +24,11 @@ void cpu_intensive_loop() { } void init(void) { - uint64_t time_start = sddf_timer_time_now(timer_channel); + uint64_t time_start = sddf_timer_time_now(config.driver_id); uint32_t freq = 0; - uint32_t res = sddf_dvfs_get_freq(dvfs_channel, CPU_INFO[0].core_ident, &freq); + uint32_t res = sddf_dvfs_get_freq(DVFS_CHANNEL, CPU_INFO[0].core_ident, &freq); if (res != 0) { sddf_printf_("DVFS Client: Fail to get the frequency\n"); @@ -38,9 +37,9 @@ void init(void) { cpu_intensive_loop(); - uint64_t time_mid = sddf_timer_time_now(timer_channel); + uint64_t time_mid = sddf_timer_time_now(config.driver_id); - res = sddf_dvfs_set_freq(dvfs_channel, CPU_INFO[0].core_ident, CPU_INFO[0].opptable[1].freq_hz); + res = sddf_dvfs_set_freq(DVFS_CHANNEL, CPU_INFO[0].core_ident, CPU_INFO[0].opptable[1].freq_hz); if (res != 0) { sddf_printf_("DVFS Client: Fail to set the frequency\n"); @@ -49,7 +48,7 @@ void init(void) { cpu_intensive_loop(); - uint64_t time_end = sddf_timer_time_now(timer_channel); + uint64_t time_end = sddf_timer_time_now(config.driver_id); sddf_printf_("%lu ns takes under Frequency: %d", time_mid - time_start, freq); diff --git a/examples/dvfs/dvfs.mk b/examples/dvfs/dvfs.mk index 9d3048ba3..ce13fc271 100644 --- a/examples/dvfs/dvfs.mk +++ b/examples/dvfs/dvfs.mk @@ -34,12 +34,6 @@ else OBJCOPY := $(TOOLCHAIN)-objcopy endif -# Allow to user to specify a custom partition -PARTITION := -ifdef PARTITION - PARTITION_ARG := --partition $(PARTITION) -endif - IMAGE_FILE := loader.img REPORT_FILE := report.txt SYSTEM_FILE := dvfs.system @@ -66,11 +60,11 @@ BOARD_DIR := $(MICROKIT_SDK)/board/$(MICROKIT_BOARD)/$(MICROKIT_CONFIG) ARCH := ${shell grep 'CONFIG_SEL4_ARCH ' $(BOARD_DIR)/include/kernel/gen_config.h | cut -d' ' -f4} SDDF_CUSTOM_LIBC := 1 -IMAGES := dvfs.elf timer_driver.elf +IMAGES := dvfs.elf timer_driver.elf client.elf CFLAGS := -nostdlib \ -ffreestanding \ -g3 \ - -O3 \ + -O0 \ -Wall -Wno-unused-function -Werror -Wno-unused-command-line-argument \ -I$(BOARD_DIR)/include \ -I$(SDDF)/include \ @@ -100,18 +94,20 @@ ${IMAGES}: libsddf_util_debug.a microkit_sdk_config_dir := $(MICROKIT_SDK)/board/$(MICROKIT_BOARD)/$(MICROKIT_CONFIG) sel4_include_dirs := $(microkit_sdk_config_dir)/include +client.o: ${TOP}/client.c + $(CC) -c $(CFLAGS) $< -o client.o + +client.elf: client.o + $(LD) $(LDFLAGS) $< $(LIBS) -o $@ + dvfs.elf: @echo "Building dvfs.elf for board $(MICROKIT_BOARD)..." && \ echo "MICROKIT SDK config directory: $(microkit_sdk_config_dir)" && \ echo "SEl4 include directories: $(sel4_include_dirs)" && \ cd .. && \ SEL4_INCLUDE_DIRS=$(abspath $(sel4_include_dirs)) \ - RUSTFLAGS="-L $(BUILD_DIR)/ -l static=helper" \ cargo build \ - -Z build-std=core,alloc,compiler_builtins \ - -Z build-std-features=compiler-builtins-mem \ - --target-dir $(BUILD_DIR) \ - --target support/targets/aarch64-sel4-microkit-minimal.json + --target-dir $(BUILD_DIR) @echo "Build complete: $(TARGET_ELF)" cp ./aarch64-sel4-microkit-minimal/debug/dvfs.elf $(BUILD_DIR) @@ -121,6 +117,7 @@ $(DTB): $(DTS) $(SYSTEM_FILE): $(METAPROGRAM) $(IMAGES) $(DTB) $(PYTHON) $(METAPROGRAM) --sddf $(SDDF) --board $(MICROKIT_BOARD) --dtb $(DTB) --output . --sdf $(SYSTEM_FILE) $(PARTITION_ARG) $(OBJCOPY) --update-section .device_resources=timer_driver_device_resources.data timer_driver.elf + $(OBJCOPY) --update-section .timer_client_config=timer_client_client.data client.elf $(IMAGE_FILE) $(REPORT_FILE): $(IMAGES) $(SYSTEM_FILE) $(MICROKIT_TOOL) $(SYSTEM_FILE) --search-path $(BUILD_DIR) --board $(MICROKIT_BOARD) --config $(MICROKIT_CONFIG) -o $(IMAGE_FILE) -r $(REPORT_FILE) diff --git a/examples/dvfs/src/main.rs b/examples/dvfs/src/main.rs deleted file mode 100644 index cb923426c..000000000 --- a/examples/dvfs/src/main.rs +++ /dev/null @@ -1,94 +0,0 @@ -#![no_std] // Don't link the standard library -#![no_main] // Don't use the default entry point - -use core::convert::Infallible; - -use cpufreq::freq_trait::FreqOps; -use sddf_timer::timer::Timer; - -use crate::platforms::xilinx::Xilinx; - -use sel4_microkit::{debug_println, protection_domain, Handler}; - -mod platforms; - -const TIMER: Timer = Timer::new(sel4_microkit::Channel::new(0)); - -fn usleep(time_us: u32) { - let time_ns: u64 = time_us as u64 * 1000; - for _ in 0..time_ns { - core::hint::spin_loop(); // Use spin loop hint to reduce contention during the wait - } -} - -#[protection_domain] -fn init() -> impl Handler { - let res: u64 = Xilinx::get_freq(0); - - debug_println!("Current {:#x}", res); - - let mut past_time: u64 = TIMER.time_now(); - - usleep(1000_000); - - let mut current_time: u64 = TIMER.time_now(); - - let mut time_elapsed: u64 = current_time - past_time; - - debug_println!("Elapsed time: {} ns", time_elapsed); - - debug_println!("Change clk frequency"); - - Xilinx::set_freq(0); - - let res: u64 = Xilinx::get_freq(0); - - debug_println!("Current {:#x}", res); - - past_time = TIMER.time_now(); - - usleep(1000_000); - - current_time = TIMER.time_now(); - - time_elapsed = current_time - past_time; - - debug_println!("Elapsed time: {} ns", time_elapsed); - - HandlerImpl{} -} - -struct HandlerImpl { -} - -impl Handler for HandlerImpl -{ - type Error = Infallible; - - fn notified(&mut self, channels: sel4_microkit::ChannelSet) -> Result<(), Self::Error> { - core::panic!( - "unexpected notification from channels {}", - channels.display() - ) - } - - fn protected( - &mut self, - channel: sel4_microkit::Channel, - msg_info: sel4_microkit::MessageInfo, - ) -> Result { - core::panic!("unexpected protected procedure call from channel {channel:?} with msg_info={msg_info:?}") - } - - fn fault( - &mut self, - child: sel4_microkit::Child, - msg_info: sel4_microkit::MessageInfo, - ) -> Result, Self::Error> { - core::panic!("unexpected fault from protection domain {child:?} with msg_info={msg_info:?}") - } - - fn take_deferred_action(&mut self) -> Option { - None - } -} \ No newline at end of file diff --git a/examples/dvfs/src/platforms/mod.rs b/examples/dvfs/src/platforms/mod.rs deleted file mode 100644 index 81800575e..000000000 --- a/examples/dvfs/src/platforms/mod.rs +++ /dev/null @@ -1 +0,0 @@ -pub mod xilinx; \ No newline at end of file diff --git a/examples/dvfs/src/platforms/xilinx.rs b/examples/dvfs/src/platforms/xilinx.rs deleted file mode 100644 index f48734e92..000000000 --- a/examples/dvfs/src/platforms/xilinx.rs +++ /dev/null @@ -1,37 +0,0 @@ -use cpufreq::freq_trait::{FreqOps, OppEntry}; - -pub const OPP_TABLE: &[OppEntry] = &[ - OppEntry { - freq_hz: 1199999988, - voltage_uv: 1000000, - latency_ns: 500000, - }, - OppEntry { - freq_hz: 599999994, - voltage_uv: 1000000, - latency_ns: 500000, - }, - OppEntry { - freq_hz: 399999996, - voltage_uv: 1000000, - latency_ns: 500000, - }, - OppEntry { - freq_hz: 299999997, - voltage_uv: 1000000, - latency_ns: 500000, - }, -]; - -pub const CPU_OPP_TABLE: &[&[OppEntry]] = &[ - OPP_TABLE, - OPP_TABLE, - OPP_TABLE, - OPP_TABLE, -]; - -pub struct Xilinx {} - -impl FreqOps for Xilinx { - const CPU_OPP_TABLE: &[&[OppEntry]] = CPU_OPP_TABLE; -} \ No newline at end of file diff --git a/examples/dvfs/support/targets/aarch64-sel4-microkit-minimal.json b/support/targets/aarch64-sel4-microkit-minimal.json similarity index 100% rename from examples/dvfs/support/targets/aarch64-sel4-microkit-minimal.json rename to support/targets/aarch64-sel4-microkit-minimal.json From c921a17ac7a8100d951e4a44553fcb7c840bcc9c Mon Sep 17 00:00:00 2001 From: Cheng Li Date: Tue, 18 Nov 2025 15:45:59 +1100 Subject: [PATCH 09/18] The example compiles, still needs the ZCU102 to test. Signed-off-by: Cheng Li --- drivers/dvfs/Cargo.lock | 748 +++++++++++++++++++++++++++++++ drivers/dvfs/Cargo.toml | 4 +- drivers/dvfs/rust-toolchain.toml | 2 +- examples/dvfs/client.c | 6 +- examples/dvfs/dvfs.mk | 4 +- examples/dvfs/meta.py | 17 +- 6 files changed, 768 insertions(+), 13 deletions(-) create mode 100644 drivers/dvfs/Cargo.lock diff --git a/drivers/dvfs/Cargo.lock b/drivers/dvfs/Cargo.lock new file mode 100644 index 000000000..c59071f00 --- /dev/null +++ b/drivers/dvfs/Cargo.lock @@ -0,0 +1,748 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "aho-corasick" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddd31a130427c27518df266943a5308ed92d4b226cc639f5a8f1002816174301" +dependencies = [ + "memchr", +] + +[[package]] +name = "bindgen" +version = "0.71.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f58bf3d7db68cfbac37cfc485a8d711e87e064c3d0fe0435b92f7a407f9d6b3" +dependencies = [ + "bitflags", + "cexpr", + "clang-sys", + "itertools", + "log", + "prettyplease", + "proc-macro2", + "quote", + "regex", + "rustc-hash", + "shlex", + "syn", +] + +[[package]] +name = "bitflags" +version = "2.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3" + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "cexpr" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" +dependencies = [ + "nom", +] + +[[package]] +name = "cfg-if" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" + +[[package]] +name = "clang-sys" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b023947811758c97c59bf9d1c188fd619ad4718dcaa767947df1cadb14f39f4" +dependencies = [ + "glob", + "libc", + "libloading", +] + +[[package]] +name = "cpufeatures" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280" +dependencies = [ + "libc", +] + +[[package]] +name = "cpufreq" +version = "0.1.0" +source = "git+ssh://git@github.com/Cheng-Li1/freq-scaling-rs.git?rev=80c5d93d258b1e2abf8939592643f105b53c7fed#80c5d93d258b1e2abf8939592643f105b53c7fed" + +[[package]] +name = "crypto-common" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "crypto-common", +] + +[[package]] +name = "dlmalloc" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6738d2e996274e499bc7b0d693c858b7720b9cd2543a0643a3087e6cb0a4fa16" +dependencies = [ + "cfg-if", + "libc", + "windows-sys", +] + +[[package]] +name = "dvfs_driver" +version = "0.1.0" +dependencies = [ + "cpufreq", + "sddf-ipc-types", + "sddf-rust", + "sel4-microkit", +] + +[[package]] +name = "either" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" + +[[package]] +name = "fallible-iterator" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2acce4a10f12dc2fb14a218589d4f1f62ef011b2d0cc4b3cb1bba8e94da14649" + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "gimli" +version = "0.32.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e629b9b98ef3dd8afe6ca2bd0f89306cec16d43d907889945bc5d6687f2f13c7" + +[[package]] +name = "glob" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0cc23270f6e1808e30a928bdc84dea0b9b4136a8bc82338574f23baf47bbd280" + +[[package]] +name = "itertools" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186" +dependencies = [ + "either", +] + +[[package]] +name = "itoa" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + +[[package]] +name = "libc" +version = "0.2.177" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2874a2af47a2325c2001a6e6fad9b16a53b802102b528163885171cf92b15976" + +[[package]] +name = "libloading" +version = "0.8.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7c4b02199fee7c5d21a5ae7d8cfa79a6ef5bb2fc834d6e9058e89c825efdc55" +dependencies = [ + "cfg-if", + "windows-link", +] + +[[package]] +name = "lock_api" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965" +dependencies = [ + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34080505efa8e45a4b816c349525ebe327ceaa8559756f0356cba97ef3bf7432" + +[[package]] +name = "memchr" +version = "2.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273" + +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + +[[package]] +name = "num_enum" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1207a7e20ad57b847bbddc6776b968420d38292bbfe2089accff5e19e82454c" +dependencies = [ + "num_enum_derive", + "rustversion", +] + +[[package]] +name = "num_enum_derive" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff32365de1b6743cb203b710788263c44a03de03802daf96092f2da4fe6ba4d7" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "one-shot-mutex" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cbb10614a03e671fcbb7f1421656788f9a761aab44563b83b07140c354fa9334" +dependencies = [ + "lock_api", +] + +[[package]] +name = "pest" +version = "2.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "989e7521a040efde50c3ab6bbadafbe15ab6dc042686926be59ac35d74607df4" +dependencies = [ + "memchr", + "ucd-trie", +] + +[[package]] +name = "pest_derive" +version = "2.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "187da9a3030dbafabbbfb20cb323b976dc7b7ce91fcd84f2f74d6e31d378e2de" +dependencies = [ + "pest", + "pest_generator", +] + +[[package]] +name = "pest_generator" +version = "2.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49b401d98f5757ebe97a26085998d6c0eecec4995cad6ab7fc30ffdf4b052843" +dependencies = [ + "pest", + "pest_meta", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "pest_meta" +version = "2.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72f27a2cfee9f9039c4d86faa5af122a0ac3851441a34865b8a043b46be0065a" +dependencies = [ + "pest", + "sha2", +] + +[[package]] +name = "prettyplease" +version = "0.2.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b" +dependencies = [ + "proc-macro2", + "syn", +] + +[[package]] +name = "proc-macro2" +version = "1.0.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ee95bc4ef87b8d5ba32e8b7714ccc834865276eab0aed5c9958d00ec45f49e8" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a338cc41d27e6cc6dce6cefc13a0729dfbb81c262b1f519331575dd80ef3067f" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "regex" +version = "1.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "843bc0191f75f3e22651ae5f1e72939ab2f72a4bc30fa80a066bd66edefc24d4" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5276caf25ac86c8d810222b3dbb938e512c55c6831a10f3e6ed1c93b84041f1c" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a2d987857b319362043e95f5353c0535c1f58eec5336fdfcf626430af7def58" + +[[package]] +name = "rustc-hash" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d" + +[[package]] +name = "rustversion" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" + +[[package]] +name = "ryu" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "sddf-ipc-types" +version = "0.1.0" +source = "git+https://github.com/seL4/rust-sel4.git?rev=95feffab18a1b46b9feb78aa599dd2f23c8eb364#95feffab18a1b46b9feb78aa599dd2f23c8eb364" + +[[package]] +name = "sddf-rust" +version = "0.1.0" +source = "git+ssh://git@github.com/Cheng-Li1/sddf-rust.git#348811e395b0cb3cf888f66f1391e56bd0591840" +dependencies = [ + "num_enum", + "sddf-ipc-types", + "sel4-microkit", +] + +[[package]] +name = "sel4" +version = "0.1.0" +source = "git+https://github.com/seL4/rust-sel4.git?tag=v2.0.0#3248eeed830a163e90cffc143d7cd173267c3bf5" +dependencies = [ + "cfg-if", + "sel4-config", + "sel4-sys", +] + +[[package]] +name = "sel4-alloca" +version = "0.1.0" +source = "git+https://github.com/seL4/rust-sel4.git?tag=v2.0.0#3248eeed830a163e90cffc143d7cd173267c3bf5" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "sel4-bitfield-ops" +version = "0.1.0" +source = "git+https://github.com/seL4/rust-sel4.git?tag=v2.0.0#3248eeed830a163e90cffc143d7cd173267c3bf5" +dependencies = [ + "rustversion", +] + +[[package]] +name = "sel4-build-env" +version = "0.1.0" +source = "git+https://github.com/seL4/rust-sel4.git?tag=v2.0.0#3248eeed830a163e90cffc143d7cd173267c3bf5" + +[[package]] +name = "sel4-config" +version = "0.1.0" +source = "git+https://github.com/seL4/rust-sel4.git?tag=v2.0.0#3248eeed830a163e90cffc143d7cd173267c3bf5" +dependencies = [ + "prettyplease", + "proc-macro2", + "quote", + "sel4-config-data", + "sel4-config-macros", + "sel4-config-types", + "syn", +] + +[[package]] +name = "sel4-config-data" +version = "0.1.0" +source = "git+https://github.com/seL4/rust-sel4.git?tag=v2.0.0#3248eeed830a163e90cffc143d7cd173267c3bf5" +dependencies = [ + "lazy_static", + "sel4-build-env", + "sel4-config-types", + "serde_json", +] + +[[package]] +name = "sel4-config-macros" +version = "0.1.0" +source = "git+https://github.com/seL4/rust-sel4.git?tag=v2.0.0#3248eeed830a163e90cffc143d7cd173267c3bf5" +dependencies = [ + "fallible-iterator", + "proc-macro2", + "quote", + "sel4-config-data", + "sel4-config-types", + "syn", +] + +[[package]] +name = "sel4-config-types" +version = "0.1.0" +source = "git+https://github.com/seL4/rust-sel4.git?tag=v2.0.0#3248eeed830a163e90cffc143d7cd173267c3bf5" +dependencies = [ + "serde", +] + +[[package]] +name = "sel4-ctors-dtors" +version = "0.1.0" +source = "git+https://github.com/seL4/rust-sel4.git?tag=v2.0.0#3248eeed830a163e90cffc143d7cd173267c3bf5" + +[[package]] +name = "sel4-dlmalloc" +version = "0.1.0" +source = "git+https://github.com/seL4/rust-sel4.git?tag=v2.0.0#3248eeed830a163e90cffc143d7cd173267c3bf5" +dependencies = [ + "dlmalloc", + "lock_api", +] + +[[package]] +name = "sel4-elf-header" +version = "0.1.0" +source = "git+https://github.com/seL4/rust-sel4.git?tag=v2.0.0#3248eeed830a163e90cffc143d7cd173267c3bf5" + +[[package]] +name = "sel4-immediate-sync-once-cell" +version = "0.1.0" +source = "git+https://github.com/seL4/rust-sel4.git?tag=v2.0.0#3248eeed830a163e90cffc143d7cd173267c3bf5" + +[[package]] +name = "sel4-immutable-cell" +version = "0.1.0" +source = "git+https://github.com/seL4/rust-sel4.git?tag=v2.0.0#3248eeed830a163e90cffc143d7cd173267c3bf5" + +[[package]] +name = "sel4-initialize-tls" +version = "0.1.0" +source = "git+https://github.com/seL4/rust-sel4.git?tag=v2.0.0#3248eeed830a163e90cffc143d7cd173267c3bf5" +dependencies = [ + "cfg-if", + "sel4-alloca", +] + +[[package]] +name = "sel4-microkit" +version = "0.1.0" +source = "git+https://github.com/seL4/rust-sel4.git?tag=v2.0.0#3248eeed830a163e90cffc143d7cd173267c3bf5" +dependencies = [ + "cfg-if", + "one-shot-mutex", + "sel4", + "sel4-dlmalloc", + "sel4-immediate-sync-once-cell", + "sel4-microkit-base", + "sel4-microkit-macros", + "sel4-panicking", + "sel4-panicking-env", + "sel4-runtime-common", +] + +[[package]] +name = "sel4-microkit-base" +version = "0.1.0" +source = "git+https://github.com/seL4/rust-sel4.git?tag=v2.0.0#3248eeed830a163e90cffc143d7cd173267c3bf5" +dependencies = [ + "sel4", + "sel4-immutable-cell", +] + +[[package]] +name = "sel4-microkit-macros" +version = "0.1.0" +source = "git+https://github.com/seL4/rust-sel4.git?tag=v2.0.0#3248eeed830a163e90cffc143d7cd173267c3bf5" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "sel4-panicking" +version = "0.1.0" +source = "git+https://github.com/seL4/rust-sel4.git?tag=v2.0.0#3248eeed830a163e90cffc143d7cd173267c3bf5" +dependencies = [ + "cfg-if", + "sel4-immediate-sync-once-cell", + "sel4-panicking-env", + "unwinding", +] + +[[package]] +name = "sel4-panicking-env" +version = "0.1.0" +source = "git+https://github.com/seL4/rust-sel4.git?tag=v2.0.0#3248eeed830a163e90cffc143d7cd173267c3bf5" + +[[package]] +name = "sel4-runtime-common" +version = "0.1.0" +source = "git+https://github.com/seL4/rust-sel4.git?tag=v2.0.0#3248eeed830a163e90cffc143d7cd173267c3bf5" +dependencies = [ + "cfg-if", + "sel4", + "sel4-ctors-dtors", + "sel4-elf-header", + "sel4-initialize-tls", + "sel4-panicking-env", + "sel4-stack", + "unwinding", +] + +[[package]] +name = "sel4-stack" +version = "0.1.0" +source = "git+https://github.com/seL4/rust-sel4.git?tag=v2.0.0#3248eeed830a163e90cffc143d7cd173267c3bf5" + +[[package]] +name = "sel4-sys" +version = "0.1.0" +source = "git+https://github.com/seL4/rust-sel4.git?tag=v2.0.0#3248eeed830a163e90cffc143d7cd173267c3bf5" +dependencies = [ + "bindgen", + "glob", + "log", + "pest", + "pest_derive", + "prettyplease", + "proc-macro2", + "quote", + "regex", + "sel4-bitfield-ops", + "sel4-build-env", + "sel4-config", + "sel4-config-data", + "syn", + "xmltree", +] + +[[package]] +name = "serde" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_core" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.145" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "402a6f66d8c709116cf22f558eab210f5a50187f702eb4d7e5ef38d9a7f1c79c" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", + "serde_core", +] + +[[package]] +name = "sha2" +version = "0.10.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "syn" +version = "2.0.110" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a99801b5bd34ede4cf3fc688c5919368fea4e4814a4664359503e6015b280aea" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "typenum" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "562d481066bde0658276a35467c4af00bdc6ee726305698a55b86e61d7ad82bb" + +[[package]] +name = "ucd-trie" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2896d95c02a80c6d6a5d6e953d479f5ddf2dfdb6a244441010e373ac0fb88971" + +[[package]] +name = "unicode-ident" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5" + +[[package]] +name = "unwinding" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60612c845ef41699f39dc8c5391f252942c0a88b7d15da672eff0d14101bbd6d" +dependencies = [ + "gimli", +] + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "windows-link" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" + +[[package]] +name = "windows-sys" +version = "0.61.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" +dependencies = [ + "windows-link", +] + +[[package]] +name = "xml-rs" +version = "0.8.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ae8337f8a065cfc972643663ea4279e04e7256de865aa66fe25cec5fb912d3f" + +[[package]] +name = "xmltree" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b619f8c85654798007fb10afa5125590b43b088c225a25fc2fec100a9fad0fc6" +dependencies = [ + "xml-rs", +] diff --git a/drivers/dvfs/Cargo.toml b/drivers/dvfs/Cargo.toml index e09134e4c..a9ceaf7ed 100644 --- a/drivers/dvfs/Cargo.toml +++ b/drivers/dvfs/Cargo.toml @@ -1,11 +1,11 @@ [package] name = "dvfs_driver" version = "0.1.0" -edition = "2021" +edition = "2024" authors = ["Cheng Li 李澄 "] [dependencies] cpufreq = { git = "ssh://git@github.com/Cheng-Li1/freq-scaling-rs.git", rev = "80c5d93d258b1e2abf8939592643f105b53c7fed" } sel4-microkit = { git = "https://github.com/seL4/rust-sel4.git", tag = "v2.0.0" } sddf-ipc-types = { git = "https://github.com/seL4/rust-sel4.git", rev = "95feffab18a1b46b9feb78aa599dd2f23c8eb364" } -sddf-rust = { path = "../../" } \ No newline at end of file +sddf-rust = { git = "ssh://git@github.com/Cheng-Li1/sddf-rust.git" } \ No newline at end of file diff --git a/drivers/dvfs/rust-toolchain.toml b/drivers/dvfs/rust-toolchain.toml index ff579f5f7..65e0b332e 100644 --- a/drivers/dvfs/rust-toolchain.toml +++ b/drivers/dvfs/rust-toolchain.toml @@ -5,6 +5,6 @@ # [toolchain] -channel = "nightly-2025-10-20" +channel = "nightly-2025-07-07" components = [ "rust-src", "rustc-dev", "llvm-tools-preview" ] profile = "default" diff --git a/examples/dvfs/client.c b/examples/dvfs/client.c index 5e8bbe036..faeb67286 100644 --- a/examples/dvfs/client.c +++ b/examples/dvfs/client.c @@ -12,7 +12,7 @@ __attribute__((__section__(".timer_client_config"))) timer_client_config_t config; -#define DVFS_CHANNEL 1 +#define DVFS_CHANNEL 0 #define LOOP_LIMITATION 100000 void cpu_intensive_loop() { @@ -53,4 +53,6 @@ void init(void) { sddf_printf_("%lu ns takes under Frequency: %d", time_mid - time_start, freq); sddf_printf_("%lu ns takes under Frequency: %lu", time_end - time_mid, CPU_INFO[0].opptable[1].freq_hz); -} \ No newline at end of file +} + +void notified(microkit_channel ch) {} \ No newline at end of file diff --git a/examples/dvfs/dvfs.mk b/examples/dvfs/dvfs.mk index ce13fc271..98c06873c 100644 --- a/examples/dvfs/dvfs.mk +++ b/examples/dvfs/dvfs.mk @@ -104,12 +104,12 @@ dvfs.elf: @echo "Building dvfs.elf for board $(MICROKIT_BOARD)..." && \ echo "MICROKIT SDK config directory: $(microkit_sdk_config_dir)" && \ echo "SEl4 include directories: $(sel4_include_dirs)" && \ - cd .. && \ + cd ${SDDF}/drivers/dvfs && \ SEL4_INCLUDE_DIRS=$(abspath $(sel4_include_dirs)) \ cargo build \ --target-dir $(BUILD_DIR) @echo "Build complete: $(TARGET_ELF)" - cp ./aarch64-sel4-microkit-minimal/debug/dvfs.elf $(BUILD_DIR) + cp ./aarch64-sel4-microkit-minimal/debug/dvfs_driver.elf $(BUILD_DIR) $(DTB): $(DTS) dtc -q -I dts -O dtb $(DTS) > $(DTB) diff --git a/examples/dvfs/meta.py b/examples/dvfs/meta.py index 1528dc7fe..ed8f4edfd 100644 --- a/examples/dvfs/meta.py +++ b/examples/dvfs/meta.py @@ -6,11 +6,12 @@ from sdfgen import SystemDescription, Sddf, DeviceTree from importlib.metadata import version -assert version("sdfgen").split(".")[1] == "24", "Unexpected sdfgen version" +assert version("sdfgen").split(".")[1] == "27", "Unexpected sdfgen version" ProtectionDomain = SystemDescription.ProtectionDomain MemoryRegion = SystemDescription.MemoryRegion Map = SystemDescription.Map +Channel = SystemDescription.Channel @dataclass class Board: @@ -33,10 +34,12 @@ class Board: def generate(sdf_file: str, output_dir: str, dtb: DeviceTree): timer_driver = ProtectionDomain("timer_driver", "timer_driver.elf", priority=254) - client = ProtectionDomain("client", "dvfs.elf", priority=100) + dvfs_driver = ProtectionDomain("dvfs_driver", "dvfs_driver.elf", priority=100) - clk_mr = MemoryRegion("clk", 0x1000, paddr=0xFD1A0000) - client.add_map(Map(clk_mr, 0xFD1A0000, "rw", cached=False)) + client = ProtectionDomain("client", "client.elf", priority=1) + + clk_mr = MemoryRegion(sdf, "clk", 0x1000, paddr=0xFD1A0000) + dvfs_driver.add_map(Map(clk_mr, 0xFD1A0000, "rw", cached=False)) sdf.add_mr(clk_mr) timer_node = dtb.node(board.timer) @@ -45,7 +48,10 @@ def generate(sdf_file: str, output_dir: str, dtb: DeviceTree): timer_system = Sddf.Timer(sdf, timer_node, timer_driver) timer_system.add_client(client) - pds = [timer_driver, client] + dvfs_ch = Channel(client, dvfs_driver, pp_a = True) + sdf.add_channel(dvfs_ch) + + pds = [timer_driver, client, dvfs_driver] for pd in pds: sdf.add_pd(pd) @@ -55,7 +61,6 @@ def generate(sdf_file: str, output_dir: str, dtb: DeviceTree): with open(f"{output_dir}/{sdf_file}", "w+") as f: f.write(sdf.render()) - if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("--dtb", required=True) From a063a52e5506e7d1dd341ed67c529f697ff26fc8 Mon Sep 17 00:00:00 2001 From: Cheng Li Date: Tue, 18 Nov 2025 17:25:43 +1100 Subject: [PATCH 10/18] Still have some minor issues. Signed-off-by: Cheng Li --- drivers/dvfs/Cargo.lock | 2 +- drivers/dvfs/src/main.rs | 2 ++ examples/dvfs/client.c | 36 ++++++++++++++++++++++++++---------- include/sddf/dvfs/client.h | 5 ++++- 4 files changed, 33 insertions(+), 12 deletions(-) diff --git a/drivers/dvfs/Cargo.lock b/drivers/dvfs/Cargo.lock index c59071f00..e841a8b68 100644 --- a/drivers/dvfs/Cargo.lock +++ b/drivers/dvfs/Cargo.lock @@ -397,7 +397,7 @@ source = "git+https://github.com/seL4/rust-sel4.git?rev=95feffab18a1b46b9feb78aa [[package]] name = "sddf-rust" version = "0.1.0" -source = "git+ssh://git@github.com/Cheng-Li1/sddf-rust.git#348811e395b0cb3cf888f66f1391e56bd0591840" +source = "git+ssh://git@github.com/Cheng-Li1/sddf-rust.git?rev=f46f4d7efefa175de42e2590462257a485898f1d#f46f4d7efefa175de42e2590462257a485898f1d" dependencies = [ "num_enum", "sddf-ipc-types", diff --git a/drivers/dvfs/src/main.rs b/drivers/dvfs/src/main.rs index 8efbbff00..6ca56205d 100644 --- a/drivers/dvfs/src/main.rs +++ b/drivers/dvfs/src/main.rs @@ -45,6 +45,8 @@ impl Handler for HandlerImpl { let (label, count) = with_msg_regs_mut(|buf| resp.write_message(buf)).unwrap(); + debug_println!("exiting from dvfs"); + Ok(MessageInfo::new(label, count)) } } diff --git a/examples/dvfs/client.c b/examples/dvfs/client.c index faeb67286..e2d5a5d33 100644 --- a/examples/dvfs/client.c +++ b/examples/dvfs/client.c @@ -24,35 +24,51 @@ void cpu_intensive_loop() { } void init(void) { - uint64_t time_start = sddf_timer_time_now(config.driver_id); - uint32_t freq = 0; uint32_t res = sddf_dvfs_get_freq(DVFS_CHANNEL, CPU_INFO[0].core_ident, &freq); - if (res != 0) { - sddf_printf_("DVFS Client: Fail to get the frequency\n"); + if (res != SDDF_DVFS_SUCCESS) { + sddf_printf_("DVFS Client: Fail to get the frequency, Error: %d\n", res); return; } + sddf_printf_("DVFS Client: BEGIN FIRST ROUND\n"); + + uint64_t time_start_1 = sddf_timer_time_now(config.driver_id); + cpu_intensive_loop(); - uint64_t time_mid = sddf_timer_time_now(config.driver_id); + uint64_t time_end_1 = sddf_timer_time_now(config.driver_id); + + sddf_printf_("DVFS Client: BEGIN SECOND ROUND\n"); res = sddf_dvfs_set_freq(DVFS_CHANNEL, CPU_INFO[0].core_ident, CPU_INFO[0].opptable[1].freq_hz); - if (res != 0) { - sddf_printf_("DVFS Client: Fail to set the frequency\n"); + sddf_printf_("DVFS Client: TEST\n"); + + if (res != SDDF_DVFS_SUCCESS) { + sddf_printf_("DVFS Client: Fail to set the frequency, Error: %d\n", res); return; } + sddf_printf_("DVFS Client: TEST\n"); + + uint64_t time_start_2 = sddf_timer_time_now(config.driver_id); + + sddf_printf_("DVFS Client: TEST\n"); + cpu_intensive_loop(); - uint64_t time_end = sddf_timer_time_now(config.driver_id); + uint64_t time_end_2 = sddf_timer_time_now(config.driver_id); + + sddf_printf_("DVFS Client: TEST\n"); + + sddf_printf_("%lu ns takes under Frequency: %d\n", time_end_1 - time_start_1, freq); - sddf_printf_("%lu ns takes under Frequency: %d", time_mid - time_start, freq); + sddf_printf_("%lu ns takes under Frequency: %d\n", time_end_2 - time_start_2, sddf_dvfs_get_freq(DVFS_CHANNEL, CPU_INFO[0].core_ident, &freq)); - sddf_printf_("%lu ns takes under Frequency: %lu", time_end - time_mid, CPU_INFO[0].opptable[1].freq_hz); + sddf_printf_("DVFS Client: TEST\n"); } void notified(microkit_channel ch) {} \ No newline at end of file diff --git a/include/sddf/dvfs/client.h b/include/sddf/dvfs/client.h index 4d4f28e45..96862c450 100644 --- a/include/sddf/dvfs/client.h +++ b/include/sddf/dvfs/client.h @@ -46,6 +46,9 @@ const size_t CPU_INFO_LEN = sizeof(CPU_INFO) / sizeof(CPU_INFO[0]); #define SDDF_DVFS_GET_FREQ 0 #define SDDF_DVFS_SET_FREQ 1 +#define SDDF_DVFS_SUCCESS 0 +#define SDDF_DVFS_RESPONSE_ERROR 1 + static inline int32_t sddf_dvfs_get_freq(unsigned int channel, uint64_t core_ident, uint32_t *freq) { sddf_set_mr(0, core_ident); @@ -53,7 +56,7 @@ static inline int32_t sddf_dvfs_get_freq(unsigned int channel, uint64_t core_ide sddf_ppcall(channel, seL4_MessageInfo_new(SDDF_DVFS_GET_FREQ, 0, 0, 1)); uint32_t error = sddf_get_mr(0); - if (!error) { + if (error == SDDF_DVFS_SUCCESS) { *freq = sddf_get_mr(1); } return error; From 06a5494026ebf10b1d34d8e3cdca11f439779e04 Mon Sep 17 00:00:00 2001 From: Cheng Li Date: Wed, 19 Nov 2025 14:19:08 +1100 Subject: [PATCH 11/18] Example fully working. Signed-off-by: Cheng Li --- drivers/dvfs/Cargo.lock | 2 - drivers/dvfs/Cargo.toml | 9 +- drivers/dvfs/cpufreq/Cargo.toml | 12 +++ drivers/dvfs/cpufreq/freq_trait.rs | 48 +++++++++++ drivers/dvfs/cpufreq/lib.rs | 7 ++ drivers/dvfs/cpufreq/platforms/mod.rs | 4 + drivers/dvfs/cpufreq/platforms/xilinx.rs | 100 +++++++++++++++++++++++ drivers/dvfs/src/main.rs | 13 +-- examples/dvfs/client.c | 53 +++++------- include/sddf-rust/Cargo.toml | 15 ++++ include/sddf-rust/dvfs/dvfs.rs | 94 +++++++++++++++++++++ include/sddf-rust/dvfs/mod.rs | 4 + include/sddf-rust/lib.rs | 6 ++ include/sddf_rust/timer/Cargo.toml | 13 --- include/sddf_rust/timer/lib.rs | 3 - include/sddf_rust/timer/timer.rs | 30 ------- 16 files changed, 325 insertions(+), 88 deletions(-) create mode 100644 drivers/dvfs/cpufreq/Cargo.toml create mode 100644 drivers/dvfs/cpufreq/freq_trait.rs create mode 100644 drivers/dvfs/cpufreq/lib.rs create mode 100644 drivers/dvfs/cpufreq/platforms/mod.rs create mode 100644 drivers/dvfs/cpufreq/platforms/xilinx.rs create mode 100644 include/sddf-rust/Cargo.toml create mode 100644 include/sddf-rust/dvfs/dvfs.rs create mode 100644 include/sddf-rust/dvfs/mod.rs create mode 100644 include/sddf-rust/lib.rs delete mode 100644 include/sddf_rust/timer/Cargo.toml delete mode 100644 include/sddf_rust/timer/lib.rs delete mode 100644 include/sddf_rust/timer/timer.rs diff --git a/drivers/dvfs/Cargo.lock b/drivers/dvfs/Cargo.lock index e841a8b68..5eb17c945 100644 --- a/drivers/dvfs/Cargo.lock +++ b/drivers/dvfs/Cargo.lock @@ -84,7 +84,6 @@ dependencies = [ [[package]] name = "cpufreq" version = "0.1.0" -source = "git+ssh://git@github.com/Cheng-Li1/freq-scaling-rs.git?rev=80c5d93d258b1e2abf8939592643f105b53c7fed#80c5d93d258b1e2abf8939592643f105b53c7fed" [[package]] name = "crypto-common" @@ -397,7 +396,6 @@ source = "git+https://github.com/seL4/rust-sel4.git?rev=95feffab18a1b46b9feb78aa [[package]] name = "sddf-rust" version = "0.1.0" -source = "git+ssh://git@github.com/Cheng-Li1/sddf-rust.git?rev=f46f4d7efefa175de42e2590462257a485898f1d#f46f4d7efefa175de42e2590462257a485898f1d" dependencies = [ "num_enum", "sddf-ipc-types", diff --git a/drivers/dvfs/Cargo.toml b/drivers/dvfs/Cargo.toml index a9ceaf7ed..65bcad456 100644 --- a/drivers/dvfs/Cargo.toml +++ b/drivers/dvfs/Cargo.toml @@ -1,3 +1,6 @@ +# Copyright 2025, UNSW +# SPDX-License-Identifier: BSD-2-Clause + [package] name = "dvfs_driver" version = "0.1.0" @@ -5,7 +8,7 @@ edition = "2024" authors = ["Cheng Li 李澄 "] [dependencies] -cpufreq = { git = "ssh://git@github.com/Cheng-Li1/freq-scaling-rs.git", rev = "80c5d93d258b1e2abf8939592643f105b53c7fed" } +cpufreq = { path = "cpufreq" } +sddf-rust = { path = "../../include/sddf-rust" } sel4-microkit = { git = "https://github.com/seL4/rust-sel4.git", tag = "v2.0.0" } -sddf-ipc-types = { git = "https://github.com/seL4/rust-sel4.git", rev = "95feffab18a1b46b9feb78aa599dd2f23c8eb364" } -sddf-rust = { git = "ssh://git@github.com/Cheng-Li1/sddf-rust.git" } \ No newline at end of file +sddf-ipc-types = { git = "https://github.com/seL4/rust-sel4.git", rev = "95feffab18a1b46b9feb78aa599dd2f23c8eb364" } \ No newline at end of file diff --git a/drivers/dvfs/cpufreq/Cargo.toml b/drivers/dvfs/cpufreq/Cargo.toml new file mode 100644 index 000000000..e94e8b4c3 --- /dev/null +++ b/drivers/dvfs/cpufreq/Cargo.toml @@ -0,0 +1,12 @@ +# Copyright 2025, UNSW +# SPDX-License-Identifier: BSD-2-Clause + +[package] +name = "cpufreq" +version = "0.1.0" +edition = "2024" +authors = ["Cheng Li 李澄 "] + +[lib] +name = "cpufreq" +path = "lib.rs" \ No newline at end of file diff --git a/drivers/dvfs/cpufreq/freq_trait.rs b/drivers/dvfs/cpufreq/freq_trait.rs new file mode 100644 index 000000000..9c456cdf2 --- /dev/null +++ b/drivers/dvfs/cpufreq/freq_trait.rs @@ -0,0 +1,48 @@ +// Copyright 2025, UNSW +// SPDX-License-Identifier: BSD-2-Clause + +#[derive(Debug)] +pub struct OppEntry { + pub freq_hz: u64, + pub voltage_uv: u64, + pub latency_ns: u64, +} + +#[derive(Debug)] +pub struct CoreInfo { + pub core_ident: u64, + pub clock_source_ident: u64, + pub opptable: &'static [OppEntry], +} + +#[derive(Debug)] +pub enum Error { + EINVAL = 0, +} + +pub trait FreqOps { + const CPU_OPP_TABLE: &[CoreInfo]; + const CORE_NUM: u32 = Self::CPU_OPP_TABLE.len() as u32; + + const _CHECK_OPP_TABLE_LEN: () = { + core::assert!( + Self::CORE_NUM as usize == Self::CPU_OPP_TABLE.len(), + "Mismatch between CORE_NUM and the actual length of OPP_TABLE" + ); + }; + + fn get_freq(core_ident: u64) -> Result { + core::panic!( + "DVFS is not implemented by get request for CPU{:?}", + core_ident + ); + } + + fn set_freq(core_ident: u64, freq_hz: u64) -> Result<(), Error> { + core::panic!( + "DVFS is not implemented by get request for CPU{:?}, freq {:?} cannot be set", + core_ident, + freq_hz + ); + } +} diff --git a/drivers/dvfs/cpufreq/lib.rs b/drivers/dvfs/cpufreq/lib.rs new file mode 100644 index 000000000..dfb1b09e6 --- /dev/null +++ b/drivers/dvfs/cpufreq/lib.rs @@ -0,0 +1,7 @@ +// Copyright 2025, UNSW +// SPDX-License-Identifier: BSD-2-Clause + +#![no_std] // Don't link the standard library + +pub mod freq_trait; +pub mod platforms; diff --git a/drivers/dvfs/cpufreq/platforms/mod.rs b/drivers/dvfs/cpufreq/platforms/mod.rs new file mode 100644 index 000000000..4de67f99d --- /dev/null +++ b/drivers/dvfs/cpufreq/platforms/mod.rs @@ -0,0 +1,4 @@ +// Copyright 2025, UNSW +// SPDX-License-Identifier: BSD-2-Clause + +pub mod xilinx; diff --git a/drivers/dvfs/cpufreq/platforms/xilinx.rs b/drivers/dvfs/cpufreq/platforms/xilinx.rs new file mode 100644 index 000000000..3682b779c --- /dev/null +++ b/drivers/dvfs/cpufreq/platforms/xilinx.rs @@ -0,0 +1,100 @@ +// Copyright 2025, UNSW +// SPDX-License-Identifier: BSD-2-Clause + +use core::ptr::{read_volatile, write_volatile}; + +use crate::freq_trait::{CoreInfo, Error, FreqOps, OppEntry}; + +// The memory address of ACPU controller +const ACPU_CTRL: usize = 0x00FD1A0060; +const ACPU_CTRL_DIVISOR_MASK: u32 = 0x3F00; + +// When uboot boots up, the APLL clock is set to 1199999988 +const APLL_CLK_FREQ: u32 = 1199999988; + +pub const OPP_TABLE: &[OppEntry] = &[ + OppEntry { + freq_hz: 1199999988, + voltage_uv: 1000000, + latency_ns: 500000, + }, + OppEntry { + freq_hz: 599999994, + voltage_uv: 1000000, + latency_ns: 500000, + }, + OppEntry { + freq_hz: 399999996, + voltage_uv: 1000000, + latency_ns: 500000, + }, + OppEntry { + freq_hz: 299999997, + voltage_uv: 1000000, + latency_ns: 500000, + }, +]; + +pub const ZCU102_CPU: &[CoreInfo] = &[ + CoreInfo { + core_ident: 0, + clock_source_ident: 0, + opptable: OPP_TABLE, + }, + CoreInfo { + core_ident: 1, + clock_source_ident: 0, + opptable: OPP_TABLE, + }, + CoreInfo { + core_ident: 2, + clock_source_ident: 0, + opptable: OPP_TABLE, + }, + CoreInfo { + core_ident: 3, + clock_source_ident: 0, + opptable: OPP_TABLE, + }, +]; + +pub struct Xilinx {} + +impl FreqOps for Xilinx { + const CPU_OPP_TABLE: &[CoreInfo] = ZCU102_CPU; + + fn get_freq(core_ident: u64) -> Result { + if core_ident >= Self::CORE_NUM as u64 { + return Err(Error::EINVAL); + } + + let divisor = (unsafe { read_volatile(ACPU_CTRL as *const u32) } & ACPU_CTRL_DIVISOR_MASK) + >> ACPU_CTRL_DIVISOR_MASK.trailing_zeros(); + + Ok((APLL_CLK_FREQ / divisor) as u64) + } + + fn set_freq(core_ident: u64, freq_hz: u64) -> Result<(), Error> { + if core_ident < Self::CORE_NUM as u64 + && let Some(entry) = ZCU102_CPU[core_ident as usize] + .opptable + .iter() + .find(|item| item.freq_hz == freq_hz) + { + let divisor = (APLL_CLK_FREQ as u64 / entry.freq_hz) as u32; + + unsafe { + let register_value = read_volatile(ACPU_CTRL as *const u32); + + write_volatile( + ACPU_CTRL as *mut u32, + register_value & (!ACPU_CTRL_DIVISOR_MASK) + | (divisor << ACPU_CTRL_DIVISOR_MASK.trailing_zeros()), + ); + } + return Ok(()); + } + + Err(Error::EINVAL) + } +} diff --git a/drivers/dvfs/src/main.rs b/drivers/dvfs/src/main.rs index 6ca56205d..7ab838d90 100644 --- a/drivers/dvfs/src/main.rs +++ b/drivers/dvfs/src/main.rs @@ -1,3 +1,6 @@ +// Copyright 2025, UNSW +// SPDX-License-Identifier: BSD-2-Clause + #![no_std] // Don't link the standard library #![no_main] // Don't use the default entry point @@ -6,7 +9,9 @@ use core::convert::Infallible; use cpufreq::{freq_trait::FreqOps, platforms::xilinx::Xilinx}; use sddf_ipc_types::{MessageWriter, ReadFromMessage}; use sddf_rust::dvfs::dvfs::{DvfsReq, DvfsResp}; -use sel4_microkit::{Channel, Handler, MessageInfo, debug_println, protection_domain, with_msg_regs, with_msg_regs_mut}; +use sel4_microkit::{ + Channel, Handler, MessageInfo, protection_domain, with_msg_regs, with_msg_regs_mut, +}; #[protection_domain] fn init() -> impl Handler { @@ -19,11 +24,9 @@ impl Handler for HandlerImpl { type Error = Infallible; fn protected( &mut self, - channel: Channel, + _channel: Channel, msg_info: MessageInfo, ) -> Result { - debug_println!("Coming from channel: {}", channel.index()); - let message = with_msg_regs(|buf| DvfsReq::read_from_message(msg_info.label(), buf)); let resp = match message { @@ -45,8 +48,6 @@ impl Handler for HandlerImpl { let (label, count) = with_msg_regs_mut(|buf| resp.write_message(buf)).unwrap(); - debug_println!("exiting from dvfs"); - Ok(MessageInfo::new(label, count)) } } diff --git a/examples/dvfs/client.c b/examples/dvfs/client.c index e2d5a5d33..0543df71a 100644 --- a/examples/dvfs/client.c +++ b/examples/dvfs/client.c @@ -13,62 +13,53 @@ __attribute__((__section__(".timer_client_config"))) timer_client_config_t config; #define DVFS_CHANNEL 0 -#define LOOP_LIMITATION 100000 + +#define LOOP_LIMIT 5000000 void cpu_intensive_loop() { volatile int i; - for (i = 0; i < LOOP_LIMITATION; i++) { + for (i = 0; i < LOOP_LIMIT; i++) { } } -void init(void) { - uint32_t freq = 0; - - uint32_t res = sddf_dvfs_get_freq(DVFS_CHANNEL, CPU_INFO[0].core_ident, &freq); - +int test_cpu_freq(uint64_t core_freq) { + uint32_t res = sddf_dvfs_set_freq(DVFS_CHANNEL, CPU_INFO[0].core_ident, core_freq); + if (res != SDDF_DVFS_SUCCESS) { sddf_printf_("DVFS Client: Fail to get the frequency, Error: %d\n", res); - return; + return 1; } - sddf_printf_("DVFS Client: BEGIN FIRST ROUND\n"); - - uint64_t time_start_1 = sddf_timer_time_now(config.driver_id); - - cpu_intensive_loop(); - - uint64_t time_end_1 = sddf_timer_time_now(config.driver_id); - - sddf_printf_("DVFS Client: BEGIN SECOND ROUND\n"); - - res = sddf_dvfs_set_freq(DVFS_CHANNEL, CPU_INFO[0].core_ident, CPU_INFO[0].opptable[1].freq_hz); + uint32_t freq = 0; - sddf_printf_("DVFS Client: TEST\n"); + res = sddf_dvfs_get_freq(DVFS_CHANNEL, CPU_INFO[0].core_ident, &freq); if (res != SDDF_DVFS_SUCCESS) { - sddf_printf_("DVFS Client: Fail to set the frequency, Error: %d\n", res); - return; + sddf_printf_("DVFS Client: Fail to get the frequency, Error: %d\n", res); + return 1; } - sddf_printf_("DVFS Client: TEST\n"); + sddf_printf_("\nDVFS Client: CURRENT FREQ: %d\n", freq); - uint64_t time_start_2 = sddf_timer_time_now(config.driver_id); - - sddf_printf_("DVFS Client: TEST\n"); + uint64_t time_start = sddf_timer_time_now(config.driver_id); cpu_intensive_loop(); - uint64_t time_end_2 = sddf_timer_time_now(config.driver_id); + uint64_t time_end = sddf_timer_time_now(config.driver_id); + + sddf_printf_("DVFS Client: %lu ns was used for running the test\n", time_end - time_start); - sddf_printf_("DVFS Client: TEST\n"); + return 0; +} - sddf_printf_("%lu ns takes under Frequency: %d\n", time_end_1 - time_start_1, freq); +void init(void) { + test_cpu_freq(CPU_INFO[0].opptable[0].freq_hz); - sddf_printf_("%lu ns takes under Frequency: %d\n", time_end_2 - time_start_2, sddf_dvfs_get_freq(DVFS_CHANNEL, CPU_INFO[0].core_ident, &freq)); + test_cpu_freq(CPU_INFO[0].opptable[1].freq_hz); - sddf_printf_("DVFS Client: TEST\n"); + test_cpu_freq(CPU_INFO[0].opptable[2].freq_hz); } void notified(microkit_channel ch) {} \ No newline at end of file diff --git a/include/sddf-rust/Cargo.toml b/include/sddf-rust/Cargo.toml new file mode 100644 index 000000000..4d48d119b --- /dev/null +++ b/include/sddf-rust/Cargo.toml @@ -0,0 +1,15 @@ +# Copyright 2025, UNSW +# SPDX-License-Identifier: BSD-2-Clause + +[package] +name = "sddf-rust" +version = "0.1.0" +edition = "2024" + +[lib] +path = "lib.rs" + +[dependencies] +sddf-ipc-types = { git = "https://github.com/seL4/rust-sel4.git", rev = "95feffab18a1b46b9feb78aa599dd2f23c8eb364" } +sel4-microkit = { git = "https://github.com/seL4/rust-sel4.git", tag = "v2.0.0" } +num_enum = { version = "0.7.5", default-features = false } \ No newline at end of file diff --git a/include/sddf-rust/dvfs/dvfs.rs b/include/sddf-rust/dvfs/dvfs.rs new file mode 100644 index 000000000..22228fa89 --- /dev/null +++ b/include/sddf-rust/dvfs/dvfs.rs @@ -0,0 +1,94 @@ +// Copyright 2025, UNSW +// SPDX-License-Identifier: BSD-2-Clause + +use core::convert::Infallible; + +use num_enum::{IntoPrimitive, TryFromPrimitive}; +use sddf_ipc_types::{ + MessagParseError, MessageBuilder, MessageParser, MessageWriter, ReadFromMessage, +}; + +#[derive(Debug)] +pub enum DvfsReq { + GetFreq { core_ident: u64 }, + SetFreq { core_ident: u64, freq_hz: u64 }, +} + +#[derive(IntoPrimitive, TryFromPrimitive)] +#[cfg_attr(target_pointer_width = "32", repr(u32))] +#[cfg_attr(target_pointer_width = "64", repr(u64))] +#[derive(Debug)] +enum DvfsMessageLabel { + GetFreq = 0, + SetFreq = 1, +} + +#[derive(Debug)] +pub enum DvfsResp { + Error, + GetFreq { freq_hz: u64 }, + SetFreq, +} + +#[derive(IntoPrimitive, TryFromPrimitive)] +#[cfg_attr(target_pointer_width = "32", repr(u32))] +#[cfg_attr(target_pointer_width = "64", repr(u64))] +#[derive(Debug)] +enum DvfsRespLabel { + Success = 0, + Error = 1, +} + +impl ReadFromMessage for DvfsReq { + type Error = MessagParseError; + + fn read_from_message( + label: sddf_ipc_types::MessageLabel, + buf: &[sddf_ipc_types::MessageRegisterValue], + ) -> Result { + let parser = MessageParser::new(label, buf); + Ok(match parser.label_try_into()? { + DvfsMessageLabel::GetFreq => { + let mut i = 0..; + let core_ident = parser.get_mr(i.next().unwrap())?; + DvfsReq::GetFreq { core_ident } + } + DvfsMessageLabel::SetFreq => { + let mut i = 0..; + let core_ident = parser.get_mr(i.next().unwrap())?; + let freq_hz = parser.get_mr(i.next().unwrap())?; + DvfsReq::SetFreq { + core_ident, + freq_hz, + } + } + }) + } +} + +impl MessageWriter for DvfsResp { + type Error = Infallible; + + fn write_message( + &self, + buf: &mut [sddf_ipc_types::MessageRegisterValue], + ) -> Result<(sddf_ipc_types::MessageLabel, usize), ::Error> { + let mut builder = MessageBuilder::new(buf); + + let mut i = 0..; + match self { + DvfsResp::Error => { + builder.set_mr(i.next().unwrap(), DvfsRespLabel::Error as u64); + } + DvfsResp::GetFreq { freq_hz } => { + builder.set_mr(i.next().unwrap(), DvfsRespLabel::Success as u64); + builder.set_mr(i.next().unwrap(), *freq_hz); + } + DvfsResp::SetFreq => { + builder.set_mr(i.next().unwrap(), DvfsRespLabel::Success as u64); + } + } + + Ok(builder.build()) + } +} diff --git a/include/sddf-rust/dvfs/mod.rs b/include/sddf-rust/dvfs/mod.rs new file mode 100644 index 000000000..c1eadc1a6 --- /dev/null +++ b/include/sddf-rust/dvfs/mod.rs @@ -0,0 +1,4 @@ +// Copyright 2025, UNSW +// SPDX-License-Identifier: BSD-2-Clause + +pub mod dvfs; diff --git a/include/sddf-rust/lib.rs b/include/sddf-rust/lib.rs new file mode 100644 index 000000000..b1f2b84a4 --- /dev/null +++ b/include/sddf-rust/lib.rs @@ -0,0 +1,6 @@ +// Copyright 2025, UNSW +// SPDX-License-Identifier: BSD-2-Clause + +#![no_std] // Don't link the standard library + +pub mod dvfs; diff --git a/include/sddf_rust/timer/Cargo.toml b/include/sddf_rust/timer/Cargo.toml deleted file mode 100644 index f2cc7a4ae..000000000 --- a/include/sddf_rust/timer/Cargo.toml +++ /dev/null @@ -1,13 +0,0 @@ -[package] -name = "sddf_timer" -version = "0.1.0" -edition = "2024" -authors = ["Cheng Li 李澄 "] - -[lib] -name = "sddf_timer" -path = "lib.rs" - -[dependencies] -sel4-microkit = { git = "https://github.com/seL4/rust-sel4.git", rev = "d2bc5cf71c5455f85898a4768e9dcbaea39e1a7e" } -# sel4-microkit-message = { git = "https://github.com/seL4/rust-sel4.git", rev = "d2bc5cf71c5455f85898a4768e9dcbaea39e1a7e" } \ No newline at end of file diff --git a/include/sddf_rust/timer/lib.rs b/include/sddf_rust/timer/lib.rs deleted file mode 100644 index 471cc85a6..000000000 --- a/include/sddf_rust/timer/lib.rs +++ /dev/null @@ -1,3 +0,0 @@ -#![no_std] // Don't link the standard library - -pub mod timer; diff --git a/include/sddf_rust/timer/timer.rs b/include/sddf_rust/timer/timer.rs deleted file mode 100644 index cd7f36df7..000000000 --- a/include/sddf_rust/timer/timer.rs +++ /dev/null @@ -1,30 +0,0 @@ -use sel4_microkit::MessageInfo; - -enum SddfTimer { - GetTime = 0, - SetTimeout = 1, -} - -pub struct Timer { - channel: sel4_microkit::Channel, -} - -impl Timer { - pub const fn new(server_channel: sel4_microkit::Channel) -> Self { - Timer { - channel: server_channel, - } - } - - pub fn set_timeout(&self, timeout: u64) { - sel4_microkit::set_mr(0, timeout); - let msg_info: MessageInfo = MessageInfo::new(SddfTimer::SetTimeout as u64, 1); - self.channel.pp_call(msg_info); - } - - pub fn time_now(&self) -> u64 { - let msg_info: MessageInfo = MessageInfo::new(SddfTimer::GetTime as u64, 0); - self.channel.pp_call(msg_info); - sel4_microkit::get_mr(0) - } -} From 1882a0147091f59bdd1d53d1845fe18c8f2d9e11 Mon Sep 17 00:00:00 2001 From: Cheng Li Date: Wed, 19 Nov 2025 15:00:07 +1100 Subject: [PATCH 12/18] Deal with format and license issues. Signed-off-by: Cheng Li --- .reuse/dep5 | 5 ++ drivers/dvfs/.cargo/config.toml | 3 + examples/dvfs/client.c | 19 +++--- examples/dvfs/meta.py | 4 +- .../aarch64-sel4-microkit-minimal.json | 66 +++++++++---------- 5 files changed, 55 insertions(+), 42 deletions(-) diff --git a/.reuse/dep5 b/.reuse/dep5 index cbab57da7..78111e9ae 100644 --- a/.reuse/dep5 +++ b/.reuse/dep5 @@ -4,6 +4,7 @@ Source: https://github.com/au-ts/sddf Files: flake.lock + Cargo.lock CHANGES.md build.zig.zon docs/design/* @@ -52,3 +53,7 @@ License: ISC Files: network/ipstacks/lwip/* Copyright: Copyright (c) 2001-2004 Swedish Institute of Computer Science License: LicenseRef-BSD-LWIP + +Files: support/targets/aarch64-sel4-microkit-minimal.json +Copyright: Copyright 2023, Colias Group, LLC +License: BSD-2-Clause diff --git a/drivers/dvfs/.cargo/config.toml b/drivers/dvfs/.cargo/config.toml index e905109ce..15b397e4f 100644 --- a/drivers/dvfs/.cargo/config.toml +++ b/drivers/dvfs/.cargo/config.toml @@ -1,3 +1,6 @@ +# Copyright 2025, UNSW +# SPDX-License-Identifier: BSD-2-Clause + [build] target = "../../support/targets/aarch64-sel4-microkit-minimal.json" diff --git a/examples/dvfs/client.c b/examples/dvfs/client.c index 0543df71a..1bbae4a78 100644 --- a/examples/dvfs/client.c +++ b/examples/dvfs/client.c @@ -16,17 +16,17 @@ __attribute__((__section__(".timer_client_config"))) timer_client_config_t confi #define LOOP_LIMIT 5000000 -void cpu_intensive_loop() { +void cpu_intensive_loop() +{ volatile int i; - for (i = 0; i < LOOP_LIMIT; i++) { - - } + for (i = 0; i < LOOP_LIMIT; i++) {} } -int test_cpu_freq(uint64_t core_freq) { +int test_cpu_freq(uint64_t core_freq) +{ uint32_t res = sddf_dvfs_set_freq(DVFS_CHANNEL, CPU_INFO[0].core_ident, core_freq); - + if (res != SDDF_DVFS_SUCCESS) { sddf_printf_("DVFS Client: Fail to get the frequency, Error: %d\n", res); return 1; @@ -54,7 +54,8 @@ int test_cpu_freq(uint64_t core_freq) { return 0; } -void init(void) { +void init(void) +{ test_cpu_freq(CPU_INFO[0].opptable[0].freq_hz); test_cpu_freq(CPU_INFO[0].opptable[1].freq_hz); @@ -62,4 +63,6 @@ void init(void) { test_cpu_freq(CPU_INFO[0].opptable[2].freq_hz); } -void notified(microkit_channel ch) {} \ No newline at end of file +void notified(microkit_channel ch) +{ +} \ No newline at end of file diff --git a/examples/dvfs/meta.py b/examples/dvfs/meta.py index ed8f4edfd..ae69e3af9 100644 --- a/examples/dvfs/meta.py +++ b/examples/dvfs/meta.py @@ -13,6 +13,7 @@ Map = SystemDescription.Map Channel = SystemDescription.Channel + @dataclass class Board: name: str @@ -48,7 +49,7 @@ def generate(sdf_file: str, output_dir: str, dtb: DeviceTree): timer_system = Sddf.Timer(sdf, timer_node, timer_driver) timer_system.add_client(client) - dvfs_ch = Channel(client, dvfs_driver, pp_a = True) + dvfs_ch = Channel(client, dvfs_driver, pp_a=True) sdf.add_channel(dvfs_ch) pds = [timer_driver, client, dvfs_driver] @@ -61,6 +62,7 @@ def generate(sdf_file: str, output_dir: str, dtb: DeviceTree): with open(f"{output_dir}/{sdf_file}", "w+") as f: f.write(sdf.render()) + if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("--dtb", required=True) diff --git a/support/targets/aarch64-sel4-microkit-minimal.json b/support/targets/aarch64-sel4-microkit-minimal.json index 322a1359d..f78c779e1 100644 --- a/support/targets/aarch64-sel4-microkit-minimal.json +++ b/support/targets/aarch64-sel4-microkit-minimal.json @@ -1,35 +1,35 @@ { - "arch": "aarch64", - "crt-objects-fallback": "false", - "data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32", - "disable-redzone": true, - "exe-suffix": ".elf", - "features": "+v8a,+strict-align,+neon,+fp-armv8", - "link-script": "__sel4_ipc_buffer_obj = (__ehdr_start & ~(4096 - 1)) - 4096;", - "linker": "rust-lld", - "linker-flavor": "gnu-lld", - "llvm-target": "aarch64-unknown-none", - "max-atomic-width": 128, - "metadata": { - "description": null, - "host_tools": null, - "std": null, - "tier": null - }, - "panic-strategy": "abort", - "pre-link-args": { - "gnu-lld": [ - "-z", - "max-page-size=4096" - ] - }, - "relocation-model": "static", - "stack-probes": { - "kind": "inline" - }, - "supported-sanitizers": [ - "kcfi", - "kernel-address" - ], - "target-pointer-width": "64" + "arch": "aarch64", + "crt-objects-fallback": "false", + "data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32", + "disable-redzone": true, + "exe-suffix": ".elf", + "features": "+v8a,+strict-align,+neon,+fp-armv8", + "link-script": "__sel4_ipc_buffer_obj = (__ehdr_start & ~(4096 - 1)) - 4096;", + "linker": "rust-lld", + "linker-flavor": "gnu-lld", + "llvm-target": "aarch64-unknown-none", + "max-atomic-width": 128, + "metadata": { + "description": null, + "host_tools": null, + "std": null, + "tier": null + }, + "panic-strategy": "abort", + "pre-link-args": { + "gnu-lld": [ + "-z", + "max-page-size=4096" + ] + }, + "relocation-model": "static", + "stack-probes": { + "kind": "inline" + }, + "supported-sanitizers": [ + "kcfi", + "kernel-address" + ], + "target-pointer-width": "64" } From 50a87d351ae51d9a39c09c050c5d1181a1a0bb26 Mon Sep 17 00:00:00 2001 From: Cheng Li Date: Wed, 19 Nov 2025 15:08:51 +1100 Subject: [PATCH 13/18] Try to fix the license issue. Signed-off-by: Cheng Li --- .reuse/dep5 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.reuse/dep5 b/.reuse/dep5 index 78111e9ae..cd64c0bf6 100644 --- a/.reuse/dep5 +++ b/.reuse/dep5 @@ -4,7 +4,6 @@ Source: https://github.com/au-ts/sddf Files: flake.lock - Cargo.lock CHANGES.md build.zig.zon docs/design/* @@ -36,6 +35,7 @@ Files: drivers/timer/cdns/config.json drivers/timer/bcm2835/config.json drivers/timer/apb_timer/config.json + drivers/dvfs/Cargo.lock Copyright: UNSW License: BSD-2-Clause From 024ff39dde605b8bd429e9bdfc7e983eb713f4ae Mon Sep 17 00:00:00 2001 From: Cheng Li Date: Tue, 25 Nov 2025 16:24:44 +1100 Subject: [PATCH 14/18] Add comments. The docs are still WIP. Signed-off-by: Cheng Li --- examples/dvfs/client.c | 4 ++-- include/sddf/dvfs/client.h | 30 ++++++++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/examples/dvfs/client.c b/examples/dvfs/client.c index 1bbae4a78..f2408195e 100644 --- a/examples/dvfs/client.c +++ b/examples/dvfs/client.c @@ -32,7 +32,7 @@ int test_cpu_freq(uint64_t core_freq) return 1; } - uint32_t freq = 0; + uint64_t freq = 0; res = sddf_dvfs_get_freq(DVFS_CHANNEL, CPU_INFO[0].core_ident, &freq); @@ -41,7 +41,7 @@ int test_cpu_freq(uint64_t core_freq) return 1; } - sddf_printf_("\nDVFS Client: CURRENT FREQ: %d\n", freq); + sddf_printf_("\nDVFS Client: CURRENT FREQ: %lu\n", freq); uint64_t time_start = sddf_timer_time_now(config.driver_id); diff --git a/include/sddf/dvfs/client.h b/include/sddf/dvfs/client.h index 96862c450..364b951ce 100644 --- a/include/sddf/dvfs/client.h +++ b/include/sddf/dvfs/client.h @@ -10,12 +10,22 @@ #include #include +/** + * The struct that describes an operating performance point table entry. + */ typedef struct { uint64_t freq_hz; uint64_t voltage_uv; uint64_t latency_ns; } OppEntry; +/** + * The struct that describes one CPU core. + * It includes the identifier of the core, + * the identifier of the clock that controls the core, + * and the operating performance point table that describe the + * frequency and the voltage that the core can be operating under. + */ typedef struct { uint64_t core_ident; uint64_t clock_source_ident; @@ -49,7 +59,15 @@ const size_t CPU_INFO_LEN = sizeof(CPU_INFO) / sizeof(CPU_INFO[0]); #define SDDF_DVFS_SUCCESS 0 #define SDDF_DVFS_RESPONSE_ERROR 1 -static inline int32_t sddf_dvfs_get_freq(unsigned int channel, uint64_t core_ident, uint32_t *freq) +/** + * Get the frequency of a specific CPU core via PPC into the DVFS driver. + * Use the label to indicate this request. + * A return value of zero means the request is completed successfully. + * @param channel ID of the DVFS driver. + * @param core_ident The unique identifier of the CPU core. + * @param freq A pointer to a unsighed integer to pass back the returned frequency. + */ +static inline int32_t sddf_dvfs_get_freq(unsigned int channel, uint64_t core_ident, uint64_t *freq) { sddf_set_mr(0, core_ident); @@ -62,7 +80,15 @@ static inline int32_t sddf_dvfs_get_freq(unsigned int channel, uint64_t core_ide return error; } -static inline int32_t sddf_dvfs_set_freq(unsigned int channel, uint64_t core_ident, uint32_t freq) +/** + * Set the frequency of a specific CPU core via PPC into the DVFS driver. + * Use the label to indicate this request. + * A return value of zero means the request is completed successfully. + * @param channel ID of the DVFS driver. + * @param core_ident The unique identifier of the CPU core. + * @param freq The desired core frequency. + */ +static inline int32_t sddf_dvfs_set_freq(unsigned int channel, uint64_t core_ident, uint64_t freq) { sddf_set_mr(0, core_ident); sddf_set_mr(1, freq); From a283186e2dc5d87dc08c515f59c2a76ce6025a03 Mon Sep 17 00:00:00 2001 From: Cheng Li Date: Wed, 26 Nov 2025 16:11:08 +1100 Subject: [PATCH 15/18] Add DVFS section to the design doc. Signed-off-by: Cheng Li --- docs/design/design.tex | 84 +++++++++++++++++++++++++++++++++++++- include/sddf/dvfs/client.h | 7 ++++ 2 files changed, 90 insertions(+), 1 deletion(-) diff --git a/docs/design/design.tex b/docs/design/design.tex index eadbc14d7..53021f3dc 100644 --- a/docs/design/design.tex +++ b/docs/design/design.tex @@ -2542,9 +2542,91 @@ \subsection{Status} This device-class specification is \textbf{subject to change}. +\section{Dynamic Voltage and Frequency Scaling}\label{s:DVFS} +Dynamic Voltage and Frequency Scaling is a power management technology +to adjust the frequency and the voltage applied on the processing units in runtime +depending on the actual needs. + +\subsection{Principle of the operation} +The power consumption of CMOS circuits can be defined by the following formula: + +\begin{equation} + P_{total} = P_{dynamic} + P_{static} +\end{equation} + +Where dynamic power can be roughly defined as: + +\begin{equation} + P_{dynamic} \approx C \cdot V^2 \cdot f +\end{equation} + +\begin{itemize} + \item \textbf{C}: Capacitance (fixed by hardware design). + \item \textbf{V}: Supply Voltage. + \item \textbf{f}: Clock Frequency. +\end{itemize} + +The power scales linearly with the frequency and quadratically with voltage. Lowering +the frequency, which usually allows a lower supply voltage, can dramatically lower +the power consumption as well as the generated heat. + +\subsection{Implementing DVFS on different platforms} +There are generally two ways to implement DVFS, and which one to use is heavily depended +on the hardware platform. + +\paragraph{Direct Interact with the clock/regulator:} The DVFS driver directly interact +with the clock and the regulator that control the frequency and the voltage the processing +units are operating on. This approach is used on most of the ARM or RISC-V platforms. + +\paragraph{Firmware Abstraction:} For some very new ARM platforms, System Control and +Management Interface (SCMI) is supported, providing a unified framework to manage the +the power state of the processing units. For X86 platforms, ACPI and HWP are the common +framework to provide platform agnostic power management interfaces. + +\subsection{Data Structures and Interface Specification} +The interface contains static configuration tables to describe the hardware. These are +exposed to the client at compile time. + +\paragraph{Operating Performance Point} +Describes a valid discrete state the processing unit can operate on. +\begin{lstlisting} +typedef struct { + uint64_t freq_hz; // Target Frequency in Hertz + uint64_t voltage_uv; // Target Voltage in Microvolts + uint64_t latency_ns; // Transition latency in Nanoseconds +} OppEntry; +\end{lstlisting} + +\paragraph{Core Configuration (CPU\_INFO)} +Describes the topology of the processor. The configuration describes +the number of the processing units, the clock source they are operating under +(one clock source may provide clock for multiple processing units, which means +changing the frequency for one unit would change the frequency of all the units +which has the same clock source), and the Operating Performance Point table. + +\begin{lstlisting} +typedef struct { + uint64_t core_ident; // Logical Core ID + uint64_t clock_source_ident; // ID of the clock source + const OppEntry *opptable; // Pointer to valid OPPs for this core + size_t opptable_len; // Number of OPPs +} CoreInfo; +\end{lstlisting} + +The interface for DVFS uses \gls{ppc}, and has the following +procedures that can be called: +\begin{description} + \item[\texttt{get\_freq(\emph{core\_identifier})}] + Retrieves the current actual frequency of a specific processing unit. + \item[\texttt{set\_freq(\emph{core\_identifier}, \emph{frequency})}] + Sets the designate processing unit to a specific target frequency. The frequency + must be a valid value from the opp table for that specific core or the request + will be rejected. +\end{description} + \section{Sensors, PWM, GPIO, etc}\label{s:sensors} -These device classes are all very similar, and tend tend to be low +These device classes are all very similar, and tend to be low bandwidth --- transferring one bit to a few bytes at a time. They fall into the ``simple device'' category introduced in \autoref{s:dr-overview}; rather than diff --git a/include/sddf/dvfs/client.h b/include/sddf/dvfs/client.h index 364b951ce..a4e331440 100644 --- a/include/sddf/dvfs/client.h +++ b/include/sddf/dvfs/client.h @@ -14,8 +14,11 @@ * The struct that describes an operating performance point table entry. */ typedef struct { + // Target Frequency in Hertz uint64_t freq_hz; + // Target Voltage in Microvolts uint64_t voltage_uv; + // Transition latency in Nanoseconds uint64_t latency_ns; } OppEntry; @@ -27,9 +30,13 @@ typedef struct { * frequency and the voltage that the core can be operating under. */ typedef struct { + // Logical Core ID uint64_t core_ident; + // ID of the clock source uint64_t clock_source_ident; + // Pointer to valid OPPs for this core const OppEntry *opptable; + // Number of the OPPs size_t opptable_len; } CoreInfo; From 594cb78fa89dab1cb6e4b46b62d2fba5e73ff5a2 Mon Sep 17 00:00:00 2001 From: Cheng Li Date: Wed, 26 Nov 2025 16:25:13 +1100 Subject: [PATCH 16/18] Update the DVFS section in the design doc. Signed-off-by: Cheng Li --- docs/design/design.tex | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/docs/design/design.tex b/docs/design/design.tex index 53021f3dc..dcb267eec 100644 --- a/docs/design/design.tex +++ b/docs/design/design.tex @@ -2543,12 +2543,13 @@ \subsection{Status} This device-class specification is \textbf{subject to change}. \section{Dynamic Voltage and Frequency Scaling}\label{s:DVFS} -Dynamic Voltage and Frequency Scaling is a power management technology +Dynamic Voltage and Frequency Scaling(DVFS) is a power management technology to adjust the frequency and the voltage applied on the processing units in runtime depending on the actual needs. \subsection{Principle of the operation} -The power consumption of CMOS circuits can be defined by the following formula: +The power consumption of CMOS(Complementary Metal-Oxide-Semiconductor) circuits can +be defined by the following formula: \begin{equation} P_{total} = P_{dynamic} + P_{static} @@ -2571,20 +2572,20 @@ \subsection{Principle of the operation} the power consumption as well as the generated heat. \subsection{Implementing DVFS on different platforms} -There are generally two ways to implement DVFS, and which one to use is heavily depended +There are generally two ways to implement DVFS, and which one to use is heavily depended on the hardware platform. -\paragraph{Direct Interact with the clock/regulator:} The DVFS driver directly interact -with the clock and the regulator that control the frequency and the voltage the processing +\paragraph{Direct interact with the clock/regulator:} The DVFS driver directly interacts +with the clock and the regulator that control the frequency and the voltage the processing units are operating on. This approach is used on most of the ARM or RISC-V platforms. -\paragraph{Firmware Abstraction:} For some very new ARM platforms, System Control and -Management Interface (SCMI) is supported, providing a unified framework to manage the -the power state of the processing units. For X86 platforms, ACPI and HWP are the common +\paragraph{Firmware Abstraction:} For some very new ARM platforms, System Control and +Management Interface (SCMI) is supported, providing a unified framework to manage the +the power state of the processing units. For x86 platforms, ACPI and HWP are the common framework to provide platform agnostic power management interfaces. \subsection{Data Structures and Interface Specification} -The interface contains static configuration tables to describe the hardware. These are +The interface contains static configuration tables to describe the hardware. These are exposed to the client at compile time. \paragraph{Operating Performance Point} @@ -2597,9 +2598,9 @@ \subsection{Data Structures and Interface Specification} } OppEntry; \end{lstlisting} -\paragraph{Core Configuration (CPU\_INFO)} -Describes the topology of the processor. The configuration describes -the number of the processing units, the clock source they are operating under +\paragraph{Core Configuration (CoreInfo)} +Describes the topology of the processor. The configuration describes +the number of the processing units, the clock source they are operating under (one clock source may provide clock for multiple processing units, which means changing the frequency for one unit would change the frequency of all the units which has the same clock source), and the Operating Performance Point table. @@ -2616,11 +2617,11 @@ \subsection{Data Structures and Interface Specification} The interface for DVFS uses \gls{ppc}, and has the following procedures that can be called: \begin{description} - \item[\texttt{get\_freq(\emph{core\_identifier})}] + \item[\texttt{get\_freq(core\_identifier)}] Retrieves the current actual frequency of a specific processing unit. - \item[\texttt{set\_freq(\emph{core\_identifier}, \emph{frequency})}] - Sets the designate processing unit to a specific target frequency. The frequency - must be a valid value from the opp table for that specific core or the request + \item[\texttt{set\_freq(core\_identifier, frequency)}] + Sets the designated processing unit to a specific target frequency. The frequency + must be a valid value from the opp table for that specific core or the request will be rejected. \end{description} From aeadcf5dbf562c2abc47ce93c662a8b621d7f6d8 Mon Sep 17 00:00:00 2001 From: Cheng Li Date: Thu, 27 Nov 2025 11:27:35 +1100 Subject: [PATCH 17/18] Update the driver to use microkit 2.1.0 and Rust-Sel4 3.0 Signed-off-by: Cheng Li --- drivers/dvfs/Cargo.lock | 57 +++++++-------- drivers/dvfs/Cargo.toml | 4 +- drivers/dvfs/rust-toolchain.toml | 17 ++++- include/sddf-rust/Cargo.toml | 4 +- .../aarch64-sel4-microkit-minimal.json | 70 ++++++++++--------- 5 files changed, 81 insertions(+), 71 deletions(-) diff --git a/drivers/dvfs/Cargo.lock b/drivers/dvfs/Cargo.lock index 5eb17c945..f5201acca 100644 --- a/drivers/dvfs/Cargo.lock +++ b/drivers/dvfs/Cargo.lock @@ -13,9 +13,9 @@ dependencies = [ [[package]] name = "bindgen" -version = "0.71.1" +version = "0.72.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f58bf3d7db68cfbac37cfc485a8d711e87e064c3d0fe0435b92f7a407f9d6b3" +checksum = "993776b509cfb49c750f11b8f07a46fa23e0a1386ffc01fb1e7d343efc387895" dependencies = [ "bitflags", "cexpr", @@ -175,12 +175,6 @@ version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" -[[package]] -name = "lazy_static" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" - [[package]] name = "libc" version = "0.2.177" @@ -391,7 +385,7 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "sddf-ipc-types" version = "0.1.0" -source = "git+https://github.com/seL4/rust-sel4.git?rev=95feffab18a1b46b9feb78aa599dd2f23c8eb364#95feffab18a1b46b9feb78aa599dd2f23c8eb364" +source = "git+https://github.com/seL4/rust-sel4.git?tag=v3.0.0#2c9786744900433f37e803c25ab208835a802cf3" [[package]] name = "sddf-rust" @@ -405,7 +399,7 @@ dependencies = [ [[package]] name = "sel4" version = "0.1.0" -source = "git+https://github.com/seL4/rust-sel4.git?tag=v2.0.0#3248eeed830a163e90cffc143d7cd173267c3bf5" +source = "git+https://github.com/seL4/rust-sel4.git?tag=v3.0.0#2c9786744900433f37e803c25ab208835a802cf3" dependencies = [ "cfg-if", "sel4-config", @@ -415,7 +409,7 @@ dependencies = [ [[package]] name = "sel4-alloca" version = "0.1.0" -source = "git+https://github.com/seL4/rust-sel4.git?tag=v2.0.0#3248eeed830a163e90cffc143d7cd173267c3bf5" +source = "git+https://github.com/seL4/rust-sel4.git?tag=v3.0.0#2c9786744900433f37e803c25ab208835a802cf3" dependencies = [ "cfg-if", ] @@ -423,7 +417,7 @@ dependencies = [ [[package]] name = "sel4-bitfield-ops" version = "0.1.0" -source = "git+https://github.com/seL4/rust-sel4.git?tag=v2.0.0#3248eeed830a163e90cffc143d7cd173267c3bf5" +source = "git+https://github.com/seL4/rust-sel4.git?tag=v3.0.0#2c9786744900433f37e803c25ab208835a802cf3" dependencies = [ "rustversion", ] @@ -431,12 +425,12 @@ dependencies = [ [[package]] name = "sel4-build-env" version = "0.1.0" -source = "git+https://github.com/seL4/rust-sel4.git?tag=v2.0.0#3248eeed830a163e90cffc143d7cd173267c3bf5" +source = "git+https://github.com/seL4/rust-sel4.git?tag=v3.0.0#2c9786744900433f37e803c25ab208835a802cf3" [[package]] name = "sel4-config" version = "0.1.0" -source = "git+https://github.com/seL4/rust-sel4.git?tag=v2.0.0#3248eeed830a163e90cffc143d7cd173267c3bf5" +source = "git+https://github.com/seL4/rust-sel4.git?tag=v3.0.0#2c9786744900433f37e803c25ab208835a802cf3" dependencies = [ "prettyplease", "proc-macro2", @@ -450,9 +444,8 @@ dependencies = [ [[package]] name = "sel4-config-data" version = "0.1.0" -source = "git+https://github.com/seL4/rust-sel4.git?tag=v2.0.0#3248eeed830a163e90cffc143d7cd173267c3bf5" +source = "git+https://github.com/seL4/rust-sel4.git?tag=v3.0.0#2c9786744900433f37e803c25ab208835a802cf3" dependencies = [ - "lazy_static", "sel4-build-env", "sel4-config-types", "serde_json", @@ -461,7 +454,7 @@ dependencies = [ [[package]] name = "sel4-config-macros" version = "0.1.0" -source = "git+https://github.com/seL4/rust-sel4.git?tag=v2.0.0#3248eeed830a163e90cffc143d7cd173267c3bf5" +source = "git+https://github.com/seL4/rust-sel4.git?tag=v3.0.0#2c9786744900433f37e803c25ab208835a802cf3" dependencies = [ "fallible-iterator", "proc-macro2", @@ -474,7 +467,7 @@ dependencies = [ [[package]] name = "sel4-config-types" version = "0.1.0" -source = "git+https://github.com/seL4/rust-sel4.git?tag=v2.0.0#3248eeed830a163e90cffc143d7cd173267c3bf5" +source = "git+https://github.com/seL4/rust-sel4.git?tag=v3.0.0#2c9786744900433f37e803c25ab208835a802cf3" dependencies = [ "serde", ] @@ -482,12 +475,12 @@ dependencies = [ [[package]] name = "sel4-ctors-dtors" version = "0.1.0" -source = "git+https://github.com/seL4/rust-sel4.git?tag=v2.0.0#3248eeed830a163e90cffc143d7cd173267c3bf5" +source = "git+https://github.com/seL4/rust-sel4.git?tag=v3.0.0#2c9786744900433f37e803c25ab208835a802cf3" [[package]] name = "sel4-dlmalloc" version = "0.1.0" -source = "git+https://github.com/seL4/rust-sel4.git?tag=v2.0.0#3248eeed830a163e90cffc143d7cd173267c3bf5" +source = "git+https://github.com/seL4/rust-sel4.git?tag=v3.0.0#2c9786744900433f37e803c25ab208835a802cf3" dependencies = [ "dlmalloc", "lock_api", @@ -496,22 +489,22 @@ dependencies = [ [[package]] name = "sel4-elf-header" version = "0.1.0" -source = "git+https://github.com/seL4/rust-sel4.git?tag=v2.0.0#3248eeed830a163e90cffc143d7cd173267c3bf5" +source = "git+https://github.com/seL4/rust-sel4.git?tag=v3.0.0#2c9786744900433f37e803c25ab208835a802cf3" [[package]] name = "sel4-immediate-sync-once-cell" version = "0.1.0" -source = "git+https://github.com/seL4/rust-sel4.git?tag=v2.0.0#3248eeed830a163e90cffc143d7cd173267c3bf5" +source = "git+https://github.com/seL4/rust-sel4.git?tag=v3.0.0#2c9786744900433f37e803c25ab208835a802cf3" [[package]] name = "sel4-immutable-cell" version = "0.1.0" -source = "git+https://github.com/seL4/rust-sel4.git?tag=v2.0.0#3248eeed830a163e90cffc143d7cd173267c3bf5" +source = "git+https://github.com/seL4/rust-sel4.git?tag=v3.0.0#2c9786744900433f37e803c25ab208835a802cf3" [[package]] name = "sel4-initialize-tls" version = "0.1.0" -source = "git+https://github.com/seL4/rust-sel4.git?tag=v2.0.0#3248eeed830a163e90cffc143d7cd173267c3bf5" +source = "git+https://github.com/seL4/rust-sel4.git?tag=v3.0.0#2c9786744900433f37e803c25ab208835a802cf3" dependencies = [ "cfg-if", "sel4-alloca", @@ -520,7 +513,7 @@ dependencies = [ [[package]] name = "sel4-microkit" version = "0.1.0" -source = "git+https://github.com/seL4/rust-sel4.git?tag=v2.0.0#3248eeed830a163e90cffc143d7cd173267c3bf5" +source = "git+https://github.com/seL4/rust-sel4.git?tag=v3.0.0#2c9786744900433f37e803c25ab208835a802cf3" dependencies = [ "cfg-if", "one-shot-mutex", @@ -537,7 +530,7 @@ dependencies = [ [[package]] name = "sel4-microkit-base" version = "0.1.0" -source = "git+https://github.com/seL4/rust-sel4.git?tag=v2.0.0#3248eeed830a163e90cffc143d7cd173267c3bf5" +source = "git+https://github.com/seL4/rust-sel4.git?tag=v3.0.0#2c9786744900433f37e803c25ab208835a802cf3" dependencies = [ "sel4", "sel4-immutable-cell", @@ -546,7 +539,7 @@ dependencies = [ [[package]] name = "sel4-microkit-macros" version = "0.1.0" -source = "git+https://github.com/seL4/rust-sel4.git?tag=v2.0.0#3248eeed830a163e90cffc143d7cd173267c3bf5" +source = "git+https://github.com/seL4/rust-sel4.git?tag=v3.0.0#2c9786744900433f37e803c25ab208835a802cf3" dependencies = [ "proc-macro2", "quote", @@ -556,7 +549,7 @@ dependencies = [ [[package]] name = "sel4-panicking" version = "0.1.0" -source = "git+https://github.com/seL4/rust-sel4.git?tag=v2.0.0#3248eeed830a163e90cffc143d7cd173267c3bf5" +source = "git+https://github.com/seL4/rust-sel4.git?tag=v3.0.0#2c9786744900433f37e803c25ab208835a802cf3" dependencies = [ "cfg-if", "sel4-immediate-sync-once-cell", @@ -567,12 +560,12 @@ dependencies = [ [[package]] name = "sel4-panicking-env" version = "0.1.0" -source = "git+https://github.com/seL4/rust-sel4.git?tag=v2.0.0#3248eeed830a163e90cffc143d7cd173267c3bf5" +source = "git+https://github.com/seL4/rust-sel4.git?tag=v3.0.0#2c9786744900433f37e803c25ab208835a802cf3" [[package]] name = "sel4-runtime-common" version = "0.1.0" -source = "git+https://github.com/seL4/rust-sel4.git?tag=v2.0.0#3248eeed830a163e90cffc143d7cd173267c3bf5" +source = "git+https://github.com/seL4/rust-sel4.git?tag=v3.0.0#2c9786744900433f37e803c25ab208835a802cf3" dependencies = [ "cfg-if", "sel4", @@ -587,12 +580,12 @@ dependencies = [ [[package]] name = "sel4-stack" version = "0.1.0" -source = "git+https://github.com/seL4/rust-sel4.git?tag=v2.0.0#3248eeed830a163e90cffc143d7cd173267c3bf5" +source = "git+https://github.com/seL4/rust-sel4.git?tag=v3.0.0#2c9786744900433f37e803c25ab208835a802cf3" [[package]] name = "sel4-sys" version = "0.1.0" -source = "git+https://github.com/seL4/rust-sel4.git?tag=v2.0.0#3248eeed830a163e90cffc143d7cd173267c3bf5" +source = "git+https://github.com/seL4/rust-sel4.git?tag=v3.0.0#2c9786744900433f37e803c25ab208835a802cf3" dependencies = [ "bindgen", "glob", diff --git a/drivers/dvfs/Cargo.toml b/drivers/dvfs/Cargo.toml index 65bcad456..1066d1b7d 100644 --- a/drivers/dvfs/Cargo.toml +++ b/drivers/dvfs/Cargo.toml @@ -10,5 +10,5 @@ authors = ["Cheng Li 李澄 "] [dependencies] cpufreq = { path = "cpufreq" } sddf-rust = { path = "../../include/sddf-rust" } -sel4-microkit = { git = "https://github.com/seL4/rust-sel4.git", tag = "v2.0.0" } -sddf-ipc-types = { git = "https://github.com/seL4/rust-sel4.git", rev = "95feffab18a1b46b9feb78aa599dd2f23c8eb364" } \ No newline at end of file +sel4-microkit = { git = "https://github.com/seL4/rust-sel4.git", tag = "v3.0.0" } +sddf-ipc-types = { git = "https://github.com/seL4/rust-sel4.git", tag = "v3.0.0" } \ No newline at end of file diff --git a/drivers/dvfs/rust-toolchain.toml b/drivers/dvfs/rust-toolchain.toml index 65e0b332e..65b7a8554 100644 --- a/drivers/dvfs/rust-toolchain.toml +++ b/drivers/dvfs/rust-toolchain.toml @@ -5,6 +5,19 @@ # [toolchain] -channel = "nightly-2025-07-07" -components = [ "rust-src", "rustc-dev", "llvm-tools-preview" ] +channel = "nightly-2025-10-20" profile = "default" +components = [ + "rust-src", + "rustc-dev", + "llvm-tools-preview", + "rust-analyzer", +] +targets = [ + "x86_64-unknown-linux-musl", + "aarch64-unknown-linux-musl", + "armv7-unknown-linux-musleabi", + "riscv64gc-unknown-linux-musl", + # tier 2, not available via rustup + # "riscv32gc-unknown-linux-musl", +] \ No newline at end of file diff --git a/include/sddf-rust/Cargo.toml b/include/sddf-rust/Cargo.toml index 4d48d119b..4e509dce6 100644 --- a/include/sddf-rust/Cargo.toml +++ b/include/sddf-rust/Cargo.toml @@ -10,6 +10,6 @@ edition = "2024" path = "lib.rs" [dependencies] -sddf-ipc-types = { git = "https://github.com/seL4/rust-sel4.git", rev = "95feffab18a1b46b9feb78aa599dd2f23c8eb364" } -sel4-microkit = { git = "https://github.com/seL4/rust-sel4.git", tag = "v2.0.0" } +sddf-ipc-types = { git = "https://github.com/seL4/rust-sel4.git", tag = "v3.0.0" } +sel4-microkit = { git = "https://github.com/seL4/rust-sel4.git", tag = "v3.0.0" } num_enum = { version = "0.7.5", default-features = false } \ No newline at end of file diff --git a/support/targets/aarch64-sel4-microkit-minimal.json b/support/targets/aarch64-sel4-microkit-minimal.json index f78c779e1..f5c0e42eb 100644 --- a/support/targets/aarch64-sel4-microkit-minimal.json +++ b/support/targets/aarch64-sel4-microkit-minimal.json @@ -1,35 +1,39 @@ { - "arch": "aarch64", - "crt-objects-fallback": "false", - "data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32", - "disable-redzone": true, - "exe-suffix": ".elf", - "features": "+v8a,+strict-align,+neon,+fp-armv8", - "link-script": "__sel4_ipc_buffer_obj = (__ehdr_start & ~(4096 - 1)) - 4096;", - "linker": "rust-lld", - "linker-flavor": "gnu-lld", - "llvm-target": "aarch64-unknown-none", - "max-atomic-width": 128, - "metadata": { - "description": null, - "host_tools": null, - "std": null, - "tier": null - }, - "panic-strategy": "abort", - "pre-link-args": { - "gnu-lld": [ - "-z", - "max-page-size=4096" - ] - }, - "relocation-model": "static", - "stack-probes": { - "kind": "inline" - }, - "supported-sanitizers": [ - "kcfi", - "kernel-address" + "arch": "aarch64", + "crt-objects-fallback": "false", + "data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32", + "disable-redzone": true, + "exe-suffix": ".elf", + "features": "+v8a,+strict-align,+neon,+fp-armv8", + "link-script": "__sel4_ipc_buffer_obj = (__ehdr_start & ~(4096 - 1)) - 4096;", + "linker": "rust-lld", + "linker-flavor": "gnu-lld", + "llvm-target": "aarch64-unknown-none", + "max-atomic-width": 128, + "metadata": { + "description": null, + "host_tools": null, + "std": null, + "tier": null + }, + "panic-strategy": "abort", + "pre-link-args": { + "gnu": [ + "--fix-cortex-a53-843419" ], - "target-pointer-width": "64" -} + "gnu-lld": [ + "--fix-cortex-a53-843419", + "-z", + "max-page-size=4096" + ] + }, + "relocation-model": "static", + "stack-probes": { + "kind": "inline" + }, + "supported-sanitizers": [ + "kcfi", + "kernel-address" + ], + "target-pointer-width": 64 +} \ No newline at end of file From 91e0f16145d1232d013a52693e8675180316d208 Mon Sep 17 00:00:00 2001 From: Cheng Li Date: Thu, 27 Nov 2025 11:33:31 +1100 Subject: [PATCH 18/18] Fix the json format. Signed-off-by: Cheng Li --- .../aarch64-sel4-microkit-minimal.json | 72 +++++++++---------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/support/targets/aarch64-sel4-microkit-minimal.json b/support/targets/aarch64-sel4-microkit-minimal.json index f5c0e42eb..5f35f8c45 100644 --- a/support/targets/aarch64-sel4-microkit-minimal.json +++ b/support/targets/aarch64-sel4-microkit-minimal.json @@ -1,39 +1,39 @@ { - "arch": "aarch64", - "crt-objects-fallback": "false", - "data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32", - "disable-redzone": true, - "exe-suffix": ".elf", - "features": "+v8a,+strict-align,+neon,+fp-armv8", - "link-script": "__sel4_ipc_buffer_obj = (__ehdr_start & ~(4096 - 1)) - 4096;", - "linker": "rust-lld", - "linker-flavor": "gnu-lld", - "llvm-target": "aarch64-unknown-none", - "max-atomic-width": 128, - "metadata": { - "description": null, - "host_tools": null, - "std": null, - "tier": null - }, - "panic-strategy": "abort", - "pre-link-args": { - "gnu": [ - "--fix-cortex-a53-843419" + "arch": "aarch64", + "crt-objects-fallback": "false", + "data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32", + "disable-redzone": true, + "exe-suffix": ".elf", + "features": "+v8a,+strict-align,+neon,+fp-armv8", + "link-script": "__sel4_ipc_buffer_obj = (__ehdr_start & ~(4096 - 1)) - 4096;", + "linker": "rust-lld", + "linker-flavor": "gnu-lld", + "llvm-target": "aarch64-unknown-none", + "max-atomic-width": 128, + "metadata": { + "description": null, + "host_tools": null, + "std": null, + "tier": null + }, + "panic-strategy": "abort", + "pre-link-args": { + "gnu": [ + "--fix-cortex-a53-843419" + ], + "gnu-lld": [ + "--fix-cortex-a53-843419", + "-z", + "max-page-size=4096" + ] + }, + "relocation-model": "static", + "stack-probes": { + "kind": "inline" + }, + "supported-sanitizers": [ + "kcfi", + "kernel-address" ], - "gnu-lld": [ - "--fix-cortex-a53-843419", - "-z", - "max-page-size=4096" - ] - }, - "relocation-model": "static", - "stack-probes": { - "kind": "inline" - }, - "supported-sanitizers": [ - "kcfi", - "kernel-address" - ], - "target-pointer-width": 64 + "target-pointer-width": 64 } \ No newline at end of file