Skip to main content

Posts

Softlockup vs. Hardlockup

Demistifying Softlockup & Hardlockup A ' softlockup ' is defined as a bug that causes the kernel to loop in kernel mode for more than 20 seconds. without giving other tasks a chance to run The currentstack trace is displayed upon detection and, by default, the system will stay locked up. A ' hardlockup ' is defined as a bug that causes the CPU to loop inkernel mode for more than 10 seconds. without letting other interrupts have a chance to run. Similarly to the softlockup case, the current stack trace is displayed upon detection and the system will stay locked up unless the default behavior is changed. Details: The so-called lockup refers to a section of kernel code that holds the CPU.  A serious lockup can cause the entire system to lose its response.  Lockup has several features: First of all, only the kernel code can cause lockup, because user code can be preempted, it is impossible to form a lockup (only one exception, real-time pr...

Macro "container_of"

Understanding container_of macro in the Linux kernel When you begin with the kernel, and you start to look around and read the code, you will eventually come across this magical preprocessor construct. What does it do? Well, precisely what its name indicates. It takes three arguments – a  pointer ,  type  of the container, and the  name  of the member the pointer refers to. The macro will then expand to a new address pointing to the container which accommodates the respective member. It is indeed a particularly clever macro, but how the hell can this possibly work? Let me illustrate… The first diagram illustrates the principle of the  container_of(ptr, type, member)  macro for who might find the above description too clumsy. I llustration of how the containter_of macro works. Bellow is the actual implementation of the macro from Linux Kernel: #define container_of(ptr, type, member) ({ \ const typeof( ((...