Link to home
Start Free TrialLog in
Avatar of yogithite
yogithiteFlag for India

asked on

Linux: How to write in filesystem node from kernel for logging the kernel data

Hello experts,

Platform: Linux kernel: 2.6 +
Drivers dealing with: USB drivers, DMA driver

I have following requirement:

Requirement:
1. Create a node in filesystem (/proc or /dev) using proc filesystem or udev.
2. Write to this particular file from the driver mentioned above in all possible modes (Low power mode/ idle mode)
3. Avoid printf / kmsgs as it adds certain amount of delay while writing
4. Access file using cat command and read the data dumped by kernel components into mentioned file
5. During powerup of H/W, clear the file

I have gone through vast documentation available on internet but unable to find right solution to achieve above mentioned requirements. Please help me in identifying correct options of filesystem (udev / sysfs etc) which can be faster and easily accessible from both - kernel or userspace components.

Thanks in advance,

Yogi
ASKER CERTIFIED SOLUTION
Avatar of wesly_chen
wesly_chen
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of yogithite

ASKER

Hi Wesly_chen,

Thank you for information. I want to know whether using proc file is the "best" way for logging details from kernel driver? Will it add any delay while logging data in filesystem? Is there any other option for writing data from kernel to any file (by not using kmsg/printf functionality)?

Yogi
procfs is a pseudo file system, it is used within the kernel  to export access to the FS internal structure to the "user land". it is not created with the regular functions, but you need to write a kernel module (driver).
One of the best books about linux devices is Alessandro Rubini's "Writing linux device drivers", available online here. Take a look. When you have learned all about drivers, you should be able to write your driver, as you request.
BUT since what you ask is something to debug the kernel, why not using the kernel debugging infrastructure? You have many solutions: debugfs, kdbg, etc.
> whether using proc file is the "best" way for logging details from kernel driver?
It depends.
If they are driver parameters/setting (all possible modes :Low power mode/ idle mode), then yes.
If they arre logs, then it'd better to put to /var for the record and tracing.
The link HappyCactus mentioned "Linux device drivers" is good but old.
Here is the newer version
http://lwn.net/Kernel/LDD3/