Good design to expose debug info from kernel module
Elazar Leibovich
elazarl at gmail.com
Mon Mar 30 15:44:15 IDT 2015
Sounds good, thanks (although it'll be harder to use from non-C programs).
Do you have a good idea how to stream information as a response to ioctl?
On Mon, Mar 30, 2015 at 3:31 PM, Gilboa Davara <gilboad at gmail.com> wrote:
> On Thu, Mar 26, 2015 at 11:36 PM, Elazar Leibovich <elazarl at gmail.com>
> wrote:
> > Hi,
> >
> > I'm writing a kernel module, and I want to expose some debug
> > information about it.
> >
> > The debug information is often of the form of request-response.
> >
> > For example:
> >
> > - Hey module, what's up with data at 0xffffe8ff0040c000?
> > - Cached, populated two hours ago.
> >
> > - Hey module, please invalidate data at 0xffffe8ff0002cb00
> > - Sure thing.
> >
> > - Hey module, please record all accesses to 0xffffe8ff0006bbf0.
> > - OK, ask me again for stats-5
> > ...
> > - Hey module, what's in stats-5?
> > - So far, 41 accesses by 22 users.
> >
> > Now, the question is, what is a good design to expose this information.
> >
> > I think that the most reasonable way to interact with userspace is
> > through a debugfs file.
>
> In my view, I usually prefer using ioctl-over-character device with
> *strongly* defined API / structures. Looking at the examples, your API
> should be fairly simple:
> typedef struct _debug_request_
> {
> request_t request_type;
> void *request_pointer;
> answer_t answer_type;
> union answer_data {
> int __out error_code;
> int __out next_answer_time;
> struct access_info {
> int __out access_count;
> int __out user_count;
> };
> };
> } debug_request_t;
>
> If you make sure you copy_from/to_user this structure in-and-out of
> user-space, you get fairly robust interface in a fairly short and easy
> to debug code.
> (E.g. compared to having to parse user-supplied text string in kernel
> mode or using debugfs [partial read/write, etc]).
>
> - Gilboa
>
> _______________________________________________
> Linux-il mailing list
> Linux-il at cs.huji.ac.il
> http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.cs.huji.ac.il/pipermail/linux-il/attachments/20150330/83806c2a/attachment.html>
More information about the Linux-il
mailing list