Skip to content

Commit

Permalink
Add a feature named enable-console-log
Browse files Browse the repository at this point in the history
This feature can be enable to print log messages to console in
addition to storing them in the log buffer.
Enable this feature by default for debug builds.

Signed-off-by: Vasant Karasulli <[email protected]>
  • Loading branch information
vsntk18 committed Jun 17, 2024
1 parent 22fd0a3 commit efa8e9c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
# ld to work, so build all the objects without performing the
# final linking step.
- name: Build
run: make FEATURES="default,enable-gdb" bin/svsm-kernel.elf stage1/stage1.o stage1/reset.o
run: make FEATURES="default-debug,enable-gdb" bin/svsm-kernel.elf stage1/stage1.o stage1/reset.o

- name: Run tests
run: make test
Expand Down
11 changes: 7 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
FEATURES ?= "default"
SVSM_ARGS = --features ${FEATURES}

SVSM_ARGS_TEST = --no-default-features
ifdef FEATURES_TEST
SVSM_ARGS_TEST += --features ${FEATURES_TEST}
endif

ifdef RELEASE
TARGET_PATH=release
FEATURES ?= "default"
SVSM_ARGS = --features ${FEATURES}
CARGO_ARGS += --release
STAGE2_ARGS =
else
TARGET_PATH=debug
FEATURES ?= "default-debug"
SVSM_ARGS = --features ${FEATURES}
STAGE2_ARGS = --features "enable-console-log"
endif

ifdef OFFLINE
Expand Down Expand Up @@ -111,7 +114,7 @@ bin/meta.bin: utils/gen_meta utils/print-meta
./utils/gen_meta $@

bin/stage2.bin: bin
cargo build --manifest-path kernel/Cargo.toml ${CARGO_ARGS} --no-default-features --bin stage2
cargo build --manifest-path kernel/Cargo.toml ${CARGO_ARGS} ${STAGE2_ARGS} --no-default-features --bin stage2
objcopy -O binary ${STAGE2_ELF} $@

bin/svsm-kernel.elf: bin
Expand Down
2 changes: 2 additions & 0 deletions kernel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ test.workspace = true

[features]
default = ["mstpm"]
default-debug = ["enable-console-log", "mstpm"]
enable-gdb = ["dep:gdbstub", "dep:gdbstub_arch"]
mstpm = ["dep:libmstpm"]
enable-console-log = []

[dev-dependencies]

Expand Down
14 changes: 14 additions & 0 deletions kernel/src/cpu/line_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// Copyright (c) 2022-2023 SUSE LLC
//
// Author: Vasant Karasulli <[email protected]>
#[cfg(feature = "enable-console-log")]
use crate::console::_print;

use crate::cpu::percpu::this_cpu;
use crate::log_buffer::log_buffer;
Expand Down Expand Up @@ -77,18 +79,30 @@ impl log::Log for BufferLogger {
line_buf
.write_fmt(format_args!("[{}] {}: {}\n", comp, lvl, rec_args))
.unwrap();
#[cfg(feature = "enable-console-log")]
{
_print(format_args!("[{}] {}: {}\n", comp, lvl, rec_args));
}
}

log::Level::Info => {
line_buf
.write_fmt(format_args!("[{}] {}\n", comp, rec_args))
.unwrap();
#[cfg(feature = "enable-console-log")]
{
_print(format_args!("[{}] {}\n", comp, rec_args));
}
}

log::Level::Debug | log::Level::Trace => {
line_buf
.write_fmt(format_args!("[{}/{}] {} {}\n", comp, target, lvl, rec_args))
.unwrap();
#[cfg(feature = "enable-console-log")]
{
_print(format_args!("[{}/{}] {} {}\n", comp, target, lvl, rec_args));
}
}
}
}
Expand Down

0 comments on commit efa8e9c

Please sign in to comment.