mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-16 08:46:48 +00:00
Print who and on which CPU the kernel panics
This commit is contained in:
parent
c1fd09fd41
commit
25a918d132
@ -25,6 +25,7 @@ pub mod work_queue;
|
|||||||
pub type Tid = u32;
|
pub type Tid = u32;
|
||||||
|
|
||||||
/// A thread is a wrapper on top of task.
|
/// A thread is a wrapper on top of task.
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct Thread {
|
pub struct Thread {
|
||||||
// immutable part
|
// immutable part
|
||||||
/// Low-level info
|
/// Low-level info
|
||||||
|
@ -22,7 +22,7 @@ use core::{
|
|||||||
sync::atomic::{AtomicBool, AtomicUsize, Ordering},
|
sync::atomic::{AtomicBool, AtomicUsize, Ordering},
|
||||||
};
|
};
|
||||||
|
|
||||||
use ostd::panic;
|
use ostd::{cpu::PinCurrentCpu, panic, task::disable_preempt};
|
||||||
|
|
||||||
use super::Thread;
|
use super::Thread;
|
||||||
|
|
||||||
@ -97,16 +97,27 @@ fn panic_handler(info: &core::panic::PanicInfo) -> ! {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let preempt_guard = disable_preempt();
|
||||||
|
let thread = Thread::current();
|
||||||
|
let cpu = preempt_guard.current_cpu();
|
||||||
|
|
||||||
// Halt the system if the panic is not caught.
|
// Halt the system if the panic is not caught.
|
||||||
if let Some(location) = info.location() {
|
if let Some(location) = info.location() {
|
||||||
log::error!(
|
log::error!(
|
||||||
"Uncaught panic: {}\nat {}:{}",
|
"Uncaught panic:\n\t{}\n\tat {}:{}\n\ton CPU {} by thread {:?}",
|
||||||
message,
|
message,
|
||||||
location.file(),
|
location.file(),
|
||||||
location.line(),
|
location.line(),
|
||||||
|
cpu.as_usize(),
|
||||||
|
thread,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
log::error!("Uncaught panic: {}", message);
|
log::error!(
|
||||||
|
"Uncaught panic:\n\t{}\n\ton CPU {} by thread {:?}",
|
||||||
|
message,
|
||||||
|
cpu.as_usize(),
|
||||||
|
thread,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if info.can_unwind() {
|
if info.can_unwind() {
|
||||||
|
@ -26,6 +26,7 @@ use crate::{prelude::*, user::UserSpace};
|
|||||||
/// Each task is associated with per-task data and an optional user space.
|
/// Each task is associated with per-task data and an optional user space.
|
||||||
/// If having a user space, the task can switch to the user space to
|
/// If having a user space, the task can switch to the user space to
|
||||||
/// execute user code. Multiple tasks can share a single user space.
|
/// execute user code. Multiple tasks can share a single user space.
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct Task {
|
pub struct Task {
|
||||||
func: SyncUnsafeCell<Option<Box<dyn FnOnce() + Send + Sync>>>,
|
func: SyncUnsafeCell<Option<Box<dyn FnOnce() + Send + Sync>>>,
|
||||||
data: Box<dyn Any + Send + Sync>,
|
data: Box<dyn Any + Send + Sync>,
|
||||||
|
@ -14,12 +14,14 @@ use crate::{cpu::CpuId, task::Task};
|
|||||||
/// define them, such as
|
/// define them, such as
|
||||||
/// [existential types](https://github.com/rust-lang/rfcs/pull/2492) do not
|
/// [existential types](https://github.com/rust-lang/rfcs/pull/2492) do not
|
||||||
/// exist yet. So we decide to define them in OSTD.
|
/// exist yet. So we decide to define them in OSTD.
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct TaskScheduleInfo {
|
pub struct TaskScheduleInfo {
|
||||||
/// The CPU that the task would like to be running on.
|
/// The CPU that the task would like to be running on.
|
||||||
pub cpu: AtomicCpuId,
|
pub cpu: AtomicCpuId,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An atomic CPUID container.
|
/// An atomic CPUID container.
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct AtomicCpuId(AtomicU32);
|
pub struct AtomicCpuId(AtomicU32);
|
||||||
|
|
||||||
impl AtomicCpuId {
|
impl AtomicCpuId {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user