How to display messages from kernel module without using dmesg? - kernel-module

In order to display the messages loaded into a kernel module, I can use the command
dmesg
Is there any alternatives for this command? How this function gets all these kernel messages?

Related

in linux kernel module programming can i use any library?

is it possible that i use FILE I/O instead character device driver?
in my kernel module code i used character device driver source code
(ex. alloc_chrdev_region()....) it because i want to read any number from specific files and process them in module. but when i tried first time, i used FILE I/O in module code and it didn't work. okay.. simply..
character device driver is only method for interacting with user application in kernel module programming?(it include with block, network)

How to bind my linux kernel module to InfiniBand HCA ports to send and receive messages via this module?

I want my kernel module get bind to an InfiniBand port and in turn register to the subnet administrator for future operations like query, send , receive.
I have searched on the web but unfortunately there is very little info about it.
At present, I'm referring the IPoIB implementation but it seems to have lots of structures and funtions which are irrelevant to my kernel module.
So, I'm searching the minimalistic and optimised steps to register my module to the InfiniBand SA.

How to read data form WinCE 5.0 's Debug Serial port?

In my project, I need to input some command into my WinCE device through the debug Serial Port. But I found that I can only use "printf" or "RETAILMSG" to output my debug info but I can't simply call "scanf" to get the data of debug Serial Port.
By look up the MSDN, I have found a function named "OEMReadDebugByte". It is a KERNEL function of WinCE, but when I try to call this function in my WinCE application, the Platform Builder post "error LNK2019: unresolved external symbol OEMReadDebugByte referenced in function wmain"
Can I use insert a case in the KernelIoControl? How ? Which file define the "KernelIoControl"?
Or... there are any solutions else?
Thanks a lot!!!
Thank you!
This function is meant to be used in the bootloader to read input from the user to set-up bot mode, network configuration etc. It's not used by the kernel. Serial is used for debug output and there is no easy way to change this. What you may do is to implement an application that provide a serial console and change your BSP removing serial debug and changing it to a system that sends this information to the application (using shared memory or something like this) that then outputs it on the serial port console.
Implementing it will require some knowledge of the OAL and BSP structure and features.

Getting Linux kernel debug information after a kernel crash

Is there a way to get kernel previous debug information after kernel crash occurs.
I am trying to develop a kernel module which basically captures IP packets in the IP layer inside the kernel network stack and after some modification I have to send the same packet back to the NIC for transmission.
During all these processes I'm writing debug information with the help of printk(). But if any thing goes wrong and a kernel failure occurs, we have to restart the system. Is there a way to get my previous debug information, because after rebooting the debug information is not present as I try to get it by dmesg command?
Actually, the /var/log/dmesg file contains the current boot print message log. The /var/log/kern.log file contains your previous boot kernel print message log in Ubuntu. In other Linux flavours it will contain in the /var/log/messages file in Fedora, etc..
Kernel log messages can be viewed in /var/log/dmesg files even after restart of the system.
There will be so many files with dmesg.X, and those files are previous kernel logs. dmesg is the latest file.
See difference between dmesg and /var/log/kern.log
You could try to interact with your hung system by entering magic SysRq key sequences via your keyboard or a serial console.
Recent versions of Linux support crash dumps. When successful, these will include a full dump of memory, including kernel log messages and stack traces.
Actually, the crash information (dmesg) is present in the location /var/crash/.
Here we have the folders for every system crash. Folder names like 127.0.0.1-date-time. vmcore-dmesg.txt are present inside the folders. From these file, we have get the dmesg which are executed before the crash.
GNOME Logs is a very useful software for that. You can limit the log messages to the last session and easily read what the last messages before the crash were.

How to call functions and variables from the kernel module (A) in the kernel module (B) and then send notification to the user space?

I'm developing an application (user space) which send notifications of value changes via network.
I want to develop a kernel module (A) in order to notify my application (user space) in case of value change in a parameter in other kernel module (B).
How to send signal from the kernel module (A) to my user space application ?
How to send data from the kernel module (A) to my user space application ?
How to call functions and variables from the kernel module (A) in the kernel module (B)?
Accessing module B from module A
Define a header in module B like a normal C header that includes the variables/functions that A wants to use, and of course #include it in A.
In one of the source files of B, write:
EXPORT_SYMBOL(your_symbol);
for each of the variables/functions.
In the Makefile of module A, make sure you add the path to Module.symvers of B in the KBUILD_EXTRA_SYMBOLS to get rid of dependency warnings and be able to load the module if your kernel has been configured with CONFIG_MODVERSIONS
Signalling a user-land process
Honestly, this one I don't know much. I personally code with a real-time extension of Linux (RTAI) for my work and I have facilities that I don't think exist in plain Linux. These facilities are shared memory (between kernel and user), and shared semaphores (again between kernel and user) and the like. If you could find such a thing in Linux, then you can use it.
If those are not available (which I believe they are not), you can always simply write a /sys or /proc file that outputs a simple 0/1 showing whether the user-space application needs to be signalled or not. Then the user-space application can poll this file.

Resources