[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 368
  • Last Modified:

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
0
yogithite
Asked:
yogithite
  • 2
1 Solution
 
wesly_chenCommented:
First, procfs is virtual filesystem (memory).
http://en.wikipedia.org/wiki/Procfs

How to Read and Write a /proc File
http://tldp.org/LDP/lkmpg/2.6/html/x769.html
0
 
yogithiteAuthor Commented:
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
0
 
HappyCactusCommented:
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.
0
 
wesly_chenCommented:
> 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/
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now