Skip to content

Commit a165dcb

Browse files
committed
style: improve user-facing kernel messages
- Move subjects to beginning of each message - Unify certain messages across architecture-specific implementations - State the component/task at the beginning of most messages (before verbs) to make log scrolling and pinpointing failures easier - Grammar-related improvements - Increase consistency of used wording - In some cases, display relevant variables - Replace debug! with error! before errors are returned. - Replace some debug! instances with trace! - Decrease the length of some sentences - Make messages of standard actions (e.g. driver init) consistent (mostly.) - Correct mentions of RTL8139 in the driver's messages - Add more variables inside of placeholders This change is not intended to be perfect and does not improve ALL messages, with many changes being highly subjective. It has a primary focus on debugging information and drivers. The primary motivation for this change is mostly the high amount of time spent trying to understand sequences of actions (and e.g. where specifically the booting of a kernel may break), while also assisting those that do not have a full picture of the kernel's source code. Some messages were not modified to include the name of the component, as it may be self-evident depending on the context and the debugging activity (see: src/drivers/gem.rs) and increase the mental noise, rather than decrease it.
1 parent 565ef14 commit a165dcb

File tree

43 files changed

+341
-370
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+341
-370
lines changed

src/arch/aarch64/kernel/interrupts.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ pub(crate) extern "C" fn do_error(_state: &State) -> ! {
260260
}
261261

262262
pub fn wakeup_core(core_id: CoreId) {
263-
debug!("Wakeup core {core_id}");
263+
debug!("CPU {core_id}: Waking up core...");
264264
let reschedid = IntId::sgi(SGI_RESCHED.into());
265265

266266
GicV3::send_sgi(
@@ -276,8 +276,7 @@ pub fn wakeup_core(core_id: CoreId) {
276276
}
277277

278278
pub(crate) fn init() {
279-
info!("Initialize generic interrupt controller");
280-
279+
info!("GIC: Initializing...");
281280
let fdt = env::fdt().unwrap();
282281

283282
let intc_node = fdt.find_node("/intc").unwrap();
@@ -307,15 +306,13 @@ pub(crate) fn init() {
307306
panic!("{compatible} isn't supported")
308307
};
309308

310-
info!("Found GIC Distributor interface at {gicd_start:p} (size {gicd_size:#X})");
311-
info!(
312-
"Found generic interrupt controller redistributor at {gicr_start:p} (size {gicr_size:#X})"
313-
);
309+
info!("GIC Distributor: Found interface at {gicd_start:p} (size {gicd_size:#X})");
310+
info!("GIC Redistributor: Found interface at {gicr_start:p} (size {gicr_size:#X})");
314311

315312
let layout = PageLayout::from_size_align(gicd_size.try_into().unwrap(), 0x10000).unwrap();
316313
let page_range = KERNEL_FREE_LIST.lock().allocate(layout).unwrap();
317314
let gicd_address = VirtAddr::from(page_range.start());
318-
debug!("Mapping GIC Distributor interface to virtual address {gicd_address:p}");
315+
debug!("GIC: Mapping distributor interface to virtual address {gicd_address:p}");
319316

320317
let mut flags = PageTableEntryFlags::empty();
321318
flags.device().writable().execute_disable();
@@ -329,7 +326,7 @@ pub(crate) fn init() {
329326
let layout = PageLayout::from_size_align(gicr_size.try_into().unwrap(), 0x10000).unwrap();
330327
let page_range = KERNEL_FREE_LIST.lock().allocate(layout).unwrap();
331328
let gicr_address = VirtAddr::from(page_range.start());
332-
debug!("Mapping generic interrupt controller to virtual address {gicr_address:p}");
329+
debug!("GIC: Mapping controller to virtual address {gicr_address:p}");
333330
paging::map::<BasePageSize>(
334331
gicr_address,
335332
gicr_start,
@@ -378,7 +375,7 @@ pub(crate) fn init() {
378375
} else if irqtype == 0 {
379376
IntId::spi(irq)
380377
} else {
381-
panic!("Invalid interrupt type");
378+
panic!("Invalid interrupt type {irqtype}!");
382379
};
383380
gic.set_interrupt_priority(timer_irqid, Some(cpu_id), 0x00);
384381
if (irqflags & 0xf) == 4 || (irqflags & 0xf) == 8 {
@@ -416,7 +413,7 @@ pub(crate) fn init() {
416413
} else if irqtype == 0 {
417414
IntId::spi(irq)
418415
} else {
419-
panic!("Invalid interrupt type");
416+
panic!("Invalid interrupt type {irqtype}!");
420417
};
421418
gic.set_interrupt_priority(uart_irqid, Some(cpu_id), 0x00);
422419
if (irqflags & 0xf) == 4 || (irqflags & 0xf) == 8 {
@@ -442,7 +439,7 @@ pub fn init_cpu() {
442439
let cpu_id: usize = core_id().try_into().unwrap();
443440

444441
if let Some(ref mut gic) = *GIC.lock() {
445-
debug!("Mark cpu {cpu_id} as awake");
442+
debug!("CPU {cpu_id}: Marking as awake");
446443

447444
gic.setup(cpu_id);
448445
GicV3::set_priority_mask(0xff);
@@ -469,7 +466,7 @@ pub fn init_cpu() {
469466
} else if irqtype == 0 {
470467
IntId::spi(irq)
471468
} else {
472-
panic!("Invalid interrupt type");
469+
panic!("Invalid interrupt type {irqtype}!");
473470
};
474471
gic.set_interrupt_priority(timer_irqid, Some(cpu_id), 0x00);
475472
if (irqflags & 0xf) == 4 || (irqflags & 0xf) == 8 {
@@ -493,7 +490,7 @@ static IRQ_NAMES: InterruptTicketMutex<HashMap<u8, &'static str, RandomState>> =
493490

494491
#[allow(dead_code)]
495492
pub(crate) fn add_irq_name(irq_number: u8, name: &'static str) {
496-
debug!("Register name \"{name}\" for interrupt {irq_number}");
493+
debug!("Assigning register name \"{name}\" for interrupt {irq_number}");
497494
IRQ_NAMES.lock().insert(SPI_START + irq_number, name);
498495
}
499496

src/arch/aarch64/kernel/mmio.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ pub fn init_drivers() {
6666
if i == "virtio,mmio" {
6767
let virtio_region = node
6868
.reg()
69-
.expect("reg property for virtio mmio not found in FDT")
69+
.expect("DT: reg property for virtio-mmio not found in FDT")
7070
.next()
7171
.unwrap();
7272
let mut irq = 0;
@@ -104,15 +104,17 @@ pub fn init_drivers() {
104104

105105
const MMIO_MAGIC_VALUE: u32 = 0x7472_6976;
106106
if magic != MMIO_MAGIC_VALUE {
107-
error!("It's not a MMIO-device at {mmio:p}");
107+
error!("virtio-mmio: No MMIO device present at {mmio:p}");
108108
}
109109

110110
if version != 2 {
111-
warn!("Found a legacy device, which isn't supported");
111+
warn!(
112+
"virtio-mmio: Found an unsupported legacy device (version: {version})"
113+
);
112114
}
113115

114116
// We found a MMIO-device (whose 512-bit address in this structure).
115-
trace!("Found a MMIO-device at {mmio:p}");
117+
trace!("virtio-mmio: Device found at {mmio:p}");
116118

117119
// Verify the device-ID to find the network card
118120
let id = mmio.as_ptr().device_id().read();
@@ -122,7 +124,7 @@ pub fn init_drivers() {
122124
#[cfg(feature = "virtio-net")]
123125
virtio::Id::Net => {
124126
debug!(
125-
"Found network card at {mmio:p}, irq: {irq}, type: {irqtype}, flags: {irqflags}"
127+
"virtio-net: Network card found at {mmio:p} (irq: {irq}, type: {irqtype}, flags: {irqflags})"
126128
);
127129
if let Ok(VirtioDriver::Network(drv)) =
128130
mmio_virtio::init_device(mmio, irq.try_into().unwrap())
@@ -134,7 +136,7 @@ pub fn init_drivers() {
134136
} else if irqtype == 0 {
135137
IntId::spi(irq)
136138
} else {
137-
panic!("Invalid interrupt type");
139+
panic!("Invalid interrupt type {irqtype}!");
138140
};
139141
gic.set_interrupt_priority(
140142
virtio_irqid,
@@ -164,7 +166,7 @@ pub fn init_drivers() {
164166
#[cfg(feature = "console")]
165167
virtio::Id::Console => {
166168
debug!(
167-
"Found console at {mmio:p}, irq: {irq}, type: {irqtype}, flags: {irqflags}"
169+
"virtio-console: Console found at {mmio:p} (irq: {irq}, type: {irqtype}, flags: {irqflags})"
168170
);
169171
if let Ok(VirtioDriver::Console(drv)) =
170172
mmio_virtio::init_device(mmio, irq.try_into().unwrap())
@@ -176,7 +178,7 @@ pub fn init_drivers() {
176178
} else if irqtype == 0 {
177179
IntId::spi(irq)
178180
} else {
179-
panic!("Invalid interrupt type");
181+
panic!("Invalid interrupt type {irqtype}!");
180182
};
181183
gic.set_interrupt_priority(
182184
virtio_irqid,
@@ -214,7 +216,7 @@ pub fn init_drivers() {
214216
}
215217
}
216218
} else {
217-
error!("No device tree found, cannot initialize MMIO drivers");
219+
error!("Device tree not found: MMIO drivers cannot be initialized.");
218220
}
219221
});
220222

src/arch/aarch64/kernel/mod.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,7 @@ pub fn application_processor_init() {
111111
}
112112

113113
fn finish_processor_init() {
114-
debug!("Initialized processor {}", core_id());
115-
114+
debug!("CPU {}: Initialized", core_id());
116115
// Allocate stack for the CPU and pass the addresses.
117116
let layout = Layout::from_size_align(KERNEL_STACK_SIZE, BasePageSize::SIZE as usize).unwrap();
118117
let stack = unsafe { alloc(layout) };
@@ -139,8 +138,8 @@ pub fn boot_next_processor() {
139138
let phys_start = virtual_to_physical(virt_start).unwrap();
140139
assert!(virt_start.as_u64() == phys_start.as_u64());
141140

142-
trace!("Virtual address of smp_start 0x{virt_start:x}");
143-
trace!("Physical address of smp_start 0x{phys_start:x}");
141+
trace!("Virtual address of smp_start: 0x{virt_start:x}");
142+
trace!("Physical address of smp_start: 0x{phys_start:x}");
144143

145144
let fdt = env::fdt().unwrap();
146145
let psci_node = fdt.find_node("/psci").unwrap();
@@ -164,8 +163,7 @@ pub fn boot_next_processor() {
164163
TTBR0.store(ttbr0, Ordering::Relaxed);
165164

166165
for cpu_id in 1..get_possible_cpus() {
167-
debug!("Try to wake-up core {cpu_id}");
168-
166+
debug!("CPU {cpu_id}: Attempting to wake up...");
169167
if method == "hvc" {
170168
// call hypervisor to wakeup next core
171169
unsafe {
@@ -177,7 +175,7 @@ pub fn boot_next_processor() {
177175
asm!("smc #0", in("x0") cpu_on, in("x1") cpu_id, in("x2") phys_start.as_u64(), in("x3") cpu_id, options(nomem, nostack));
178176
}
179177
} else {
180-
warn!("Method {method} isn't supported!");
178+
warn!("CPU {cpu_id}: Wakeup method {method} not supported!");
181179
return;
182180
}
183181

src/arch/aarch64/kernel/pci.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ fn detect_pci_regions(pci_node: FdtNode<'_, '_>) -> (u64, u64, u64) {
7979
0b01 => {
8080
debug!("IO space");
8181
if io_start != 0 {
82-
warn!("Found already IO space");
82+
warn!("IO space: Already found (io_start: {io_start:#x})");
8383
}
8484

8585
(value_slice, residual_slice) =
@@ -88,9 +88,9 @@ fn detect_pci_regions(pci_node: FdtNode<'_, '_>) -> (u64, u64, u64) {
8888
}
8989
0b10 => {
9090
let prefetchable = high.get_bit(30);
91-
debug!("32 bit memory space: prefetchable {prefetchable}");
91+
debug!("32-bit memory space: prefetchable {prefetchable}");
9292
if mem32_start != 0 {
93-
warn!("Found already 32 bit memory space");
93+
warn!("32-bit memory space: Already found (mem32_start: {mem32_start:#x}");
9494
}
9595

9696
(value_slice, residual_slice) =
@@ -99,9 +99,9 @@ fn detect_pci_regions(pci_node: FdtNode<'_, '_>) -> (u64, u64, u64) {
9999
}
100100
0b11 => {
101101
let prefetchable = high.get_bit(30);
102-
debug!("64 bit memory space: prefetchable {prefetchable}");
102+
debug!("64-bit memory space: prefetchable {prefetchable}");
103103
if mem64_start != 0 {
104-
warn!("Found already 64 bit memory space");
104+
warn!("64-bit memory space: Already found (mem64_start: {mem64_start:#x})");
105105
}
106106

107107
(value_slice, residual_slice) =
@@ -189,7 +189,6 @@ fn detect_interrupt(
189189
let irq_flags = u32::from_be_bytes(value_slice.try_into().unwrap());
190190

191191
trace!("Interrupt type {irq_type:#x}, number {irq_number:#x} flags {irq_flags:#x}");
192-
193192
if high.get_bits(0..24) == addr {
194193
pin += 1;
195194
if irq_type == 0 {
@@ -228,7 +227,7 @@ pub fn init() {
228227
let page_range = KERNEL_FREE_LIST.lock().allocate(layout).unwrap();
229228
let pci_address = VirtAddr::from(page_range.start());
230229
info!(
231-
"Mapping PCI Enhanced Configuration Space interface to virtual address {pci_address:p} (size {size:#X})"
230+
"PCI Enhanced Configuration Space: Mapping interface to virtual address {pci_address:p} (size {size:#X})"
232231
);
233232

234233
let mut flags = PageTableEntryFlags::empty();
@@ -242,9 +241,9 @@ pub fn init() {
242241

243242
let (mut io_start, mut mem32_start, mut mem64_start) = detect_pci_regions(pci_node);
244243

245-
debug!("IO address space starts at{io_start:#X}");
246-
debug!("Memory32 address space starts at {mem32_start:#X}");
247-
debug!("Memory64 address space starts {mem64_start:#X}");
244+
debug!("IO space: Starts at {io_start:#X}");
245+
debug!("32-bit memory space: Starts at {mem32_start:#X}");
246+
debug!("64-bit memory space: Starts at {mem64_start:#X}");
248247
assert!(io_start > 0);
249248
assert!(mem32_start > 0);
250249
assert!(mem64_start > 0);
@@ -253,7 +252,7 @@ pub fn init() {
253252
/ (u64::from(PCI_MAX_DEVICE_NUMBER)
254253
* u64::from(PCI_MAX_FUNCTION_NUMBER)
255254
* BasePageSize::SIZE);
256-
info!("Scanning PCI Busses 0 to {}", max_bus_number - 1);
255+
info!("PCI: Scanning {max_bus_number} buses (zero-indexed)");
257256

258257
let pci_config = PciConfigRegion::new(pci_address);
259258
for bus in 0..max_bus_number {
@@ -326,7 +325,7 @@ pub fn init() {
326325
detect_interrupt(bus.try_into().unwrap(), device.into(), fdt, pci_node)
327326
{
328327
debug!(
329-
"Initialize interrupt pin {pin} and line {line} for device {device_id}"
328+
"Device {device_id}: Initialize interrupt pin {pin} and line {line}"
330329
);
331330
dev.set_irq(pin, line);
332331
}
@@ -338,7 +337,7 @@ pub fn init() {
338337

339338
return;
340339
} else if let Some(_pci_node) = fdt.find_compatible(&["pci-host-cam-generic"]) {
341-
warn!("Currently, pci-host-cam-generic isn't supported!");
340+
warn!("pci-host-cam-generic is not currently supported!");
342341
}
343342

344343
warn!("Unable to find PCI bus");

src/arch/aarch64/kernel/processor.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,8 @@ pub fn configure() {
312312
out(reg) pmcr_el0,
313313
options(nostack, nomem),
314314
);
315-
debug!("PMCR_EL0 (has RES1 bits and therefore mustn't be zero): {pmcr_el0:#X}");
315+
// Has RES1 bits, therefore must not be zero.
316+
debug!("PMCR_EL0 contents: {pmcr_el0:#X}");
316317
pmcr_el0 |= (1 << 0) | (1 << 2) | (1 << 6);
317318
asm!(
318319
"msr pmcr_el0, {}",

src/arch/aarch64/kernel/scheduler.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,11 @@ impl TaskStacks {
142142
let frame_range = PHYSICAL_FREE_LIST
143143
.lock()
144144
.allocate(frame_layout)
145-
.expect("Failed to allocate Physical Memory for TaskStacks");
145+
.expect("Task stacks: Physical memory allocation failed!");
146146
let phys_addr = PhysAddr::from(frame_range.start());
147147

148148
debug!(
149-
"Create stacks at {:p} with a size of {} KB",
149+
"Task stacks: Create at virtual {:p} (size: {}KB)",
150150
virt_addr,
151151
total_size >> 10
152152
);
@@ -188,7 +188,7 @@ impl TaskStacks {
188188

189189
pub fn from_boot_stacks() -> TaskStacks {
190190
let stack = VirtAddr::new(CURRENT_STACK_ADDRESS.load(Ordering::Relaxed) as u64);
191-
debug!("Using boot stack {stack:p}");
191+
debug!("Task stacks: Deriving from boot stack {stack:p}");
192192

193193
TaskStacks::Boot(BootStack { stack })
194194
}
@@ -231,7 +231,7 @@ impl Drop for TaskStacks {
231231
TaskStacks::Boot(_) => {}
232232
TaskStacks::Common(stacks) => {
233233
debug!(
234-
"Deallocating stacks at {:p} with a size of {} KB",
234+
"Task stacks: Deallocating at {:p} (size: {}KB)",
235235
stacks.virt_addr,
236236
stacks.total_size >> 10,
237237
);

src/arch/aarch64/kernel/systemtime.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,13 @@ pub fn init() {
6363
let addr = PhysAddr::from(reg.starting_address.addr());
6464
let size = u64::try_from(reg.size.unwrap()).unwrap();
6565

66-
debug!("Found RTC at {addr:p} (size {size:#X})");
66+
debug!("RTC: Found at {addr:p} (size {size:#X})");
6767

6868
let layout = PageLayout::from_size(size.try_into().unwrap()).unwrap();
6969
let page_range = KERNEL_FREE_LIST.lock().allocate(layout).unwrap();
7070
let pl031_address = VirtAddr::from(page_range.start());
7171
PL031_ADDRESS.set(pl031_address).unwrap();
72-
debug!("Mapping RTC to virtual address {pl031_address:p}");
72+
debug!("RTC: Mapping to virtual address {pl031_address:p}");
7373

7474
let mut flags = PageTableEntryFlags::empty();
7575
flags.device().writable().execute_disable();

0 commit comments

Comments
 (0)