Re: measure boot time

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,

On 11/22/06, Keppler Alecrim <alecrim@xxxxxxxxx> wrote:
Hi all ,
   I created a simple module to measure boot time,that is loaded on last run level of my machine. Any comment about the code or a better way?
thanks  ;)

static int proc_read ( char *buf, char **start, off_t off, int count )
{
        int     len;
        unsigned long jiffiesinit,freq;
        len = 0;
        jiffiesinit=INITIAL_JIFFIES;
        freq=HZ;
        len += sprintf (buf+len, "timestamp-cpu freq (HZ) = %lu \n",freq);
        len += sprintf (buf+len, "timestamp-jiffies init= %lu \n",jiffiesinit);
        len += sprintf( buf+len, "timestamp-jiffies end = %lu \n", jiffiesend );
        len += sprintf( buf+len, "timestamp-jiffies diff= %lu \n", (jiffiesend-jiffiesinit) );
        len += sprintf (buf+len, "timestamp-boot time in sec  = %lu \n",((jiffiesend-jiffiesinit)/freq) );

        return  len;
}

Is buf always large enough?
What happens when I do something like this?:

#define MSIZE 4
int fd;
char mbuf[MSIZE];

fd=open(modname, O_RDONLY);
read(fd, mbuf, MSIZE);


int init_module( void )
{
        printk( "<1>\nInstalling \'%s\' module\n", modname );
        jiffiesend=jiffies;
        create_proc_info_entry( modname, 0, NULL, proc_read );
        return  0;  //SUCCESS
}

AFAIK, using the proc_read mechanism is not safe. Suppose that
your module gets rmmod-ed when some process is inside your
proc_read(). Kernel panics on return.

A safe way is to use create_proc_entry() and then set proc_fops
member of the returned struct proc_dir_entry.

The proc_fops is of type struct file_operations. It is enough
to implement the open(), read(), and release() functions.
Inside the open(), you would call try_module_get(THIS_MODULE).
Inside the release(), you would call module_put(). This way,
the rmmod would not succeed if there was a process reading
your proc file.


BlackHole

[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux