All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: Strange behavior for create_proc_read_entry
@ 2010-06-18 17:52 Randy Dunlap
  2010-06-18 17:58 ` Prashant Shah
  2010-06-18 19:43 ` Matthew Wilcox
  0 siblings, 2 replies; 3+ messages in thread
From: Randy Dunlap @ 2010-06-18 17:52 UTC (permalink / raw)
  To: kernel-janitors

On Fri, 18 Jun 2010 23:16:29 +0530 Prashant Shah wrote:

> Hi,
> 
> Below is a small module that I was trying out (code at the end of message)
> 
> This module creates a file called /proc/jiffies that adds a message to
> the log file using printk and shows the current jiffies value to the
> user when it is read.
> 
> If I cat the /proc/jiffies file once, in the dmesg log there are three
> entries. The function create_proc_read_entry() is calling the
> my_proc_read() thrice.
> 
> o/p :
> [  997.261195] ******** Reading jiffies files *********
> [  997.261205] ******** Reading jiffies files *********
> [  997.261233] ******** Reading jiffies files *********


Is there a question here??

Here's what I would try:  in my_proc_read(), printk the values of
off and count.

> -------------- module code ---------------
> 
> #include <linux/module.h>
> #include <linux/init.h>
> #include <linux/jiffies.h>
> #include <linux/delay.h>
> #include <linux/proc_fs.h>
> 
> #define SUCCESS 0
> static char modname[] = "jiffies";
> 
> static int my_proc_read(char *buf, char **start, off_t off,
>                 int count, int *eof, void *data)
> {
>         printk("******** Reading jiffies files *********\n");
>         return sprintf(buf, "jiffies = %lu\n", jiffies);
> }
> 
> static int __init mod_entry(void)
> {
>         printk(KERN_INFO "***** START *******\n");
>         create_proc_read_entry(modname, 0, NULL, my_proc_read, NULL);
>         return SUCCESS;
> }
> 
> static void __exit mod_exit(void)
> {
>         printk("******** END *********\n");
>         remove_proc_entry(modname, NULL);
>         return;
> }
> MODULE_LICENSE("GPL");
> module_init(mod_entry);
> module_exit(mod_exit);
> --

---
~Randy
*** Remember to use Documentation/SubmitChecklist when testing your code ***

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Strange behavior for create_proc_read_entry
  2010-06-18 17:52 Strange behavior for create_proc_read_entry Randy Dunlap
@ 2010-06-18 17:58 ` Prashant Shah
  2010-06-18 19:43 ` Matthew Wilcox
  1 sibling, 0 replies; 3+ messages in thread
From: Prashant Shah @ 2010-06-18 17:58 UTC (permalink / raw)
  To: kernel-janitors

Hi,

Below is a small module that I was trying out (code at the end of message)

This module creates a file called /proc/jiffies that adds a message to
the log file using printk and shows the current jiffies value to the
user when it is read.

If I cat the /proc/jiffies file once, in the dmesg log there are three
entries. The function create_proc_read_entry() is calling the
my_proc_read() thrice.

o/p :
[  997.261195] ******** Reading jiffies files *********
[  997.261205] ******** Reading jiffies files *********
[  997.261233] ******** Reading jiffies files *********

-------------- module code ---------------

#include <linux/module.h>
#include <linux/init.h>
#include <linux/jiffies.h>
#include <linux/delay.h>
#include <linux/proc_fs.h>

#define SUCCESS 0
static char modname[] = "jiffies";

static int my_proc_read(char *buf, char **start, off_t off,
                int count, int *eof, void *data)
{
        printk("******** Reading jiffies files *********\n");
        return sprintf(buf, "jiffies = %lu\n", jiffies);
}

static int __init mod_entry(void)
{
        printk(KERN_INFO "***** START *******\n");
        create_proc_read_entry(modname, 0, NULL, my_proc_read, NULL);
        return SUCCESS;
}

static void __exit mod_exit(void)
{
        printk("******** END *********\n");
        remove_proc_entry(modname, NULL);
        return;
}
MODULE_LICENSE("GPL");
module_init(mod_entry);
module_exit(mod_exit);

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Strange behavior for create_proc_read_entry
  2010-06-18 17:52 Strange behavior for create_proc_read_entry Randy Dunlap
  2010-06-18 17:58 ` Prashant Shah
@ 2010-06-18 19:43 ` Matthew Wilcox
  1 sibling, 0 replies; 3+ messages in thread
From: Matthew Wilcox @ 2010-06-18 19:43 UTC (permalink / raw)
  To: kernel-janitors

On Fri, Jun 18, 2010 at 11:16:29PM +0530, Prashant Shah wrote:
> Hi,
> 
> Below is a small module that I was trying out (code at the end of message)
> 
> This module creates a file called /proc/jiffies that adds a message to
> the log file using printk and shows the current jiffies value to the
> user when it is read.
> 
> If I cat the /proc/jiffies file once, in the dmesg log there are three
> entries. The function create_proc_read_entry() is calling the
> my_proc_read() thrice.
> 
> o/p :
> [  997.261195] ******** Reading jiffies files *********
> [  997.261205] ******** Reading jiffies files *********
> [  997.261233] ******** Reading jiffies files *********

Try running 'strace cat /proc/jiffies'.  I wouldn't be surprised if cat
is reading the file more than once.

-- 
Matthew Wilcox				Intel Open Source Technology Centre
"Bill, look, we understand that you're interested in selling us this
operating system, but compare it to ours.  We can't possibly take such
a retrograde step."

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-06-18 19:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-06-18 17:52 Strange behavior for create_proc_read_entry Randy Dunlap
2010-06-18 17:58 ` Prashant Shah
2010-06-18 19:43 ` Matthew Wilcox

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.