Re: knowing-current-time

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

 



On Wed, 10 Aug 2005, Deepak Joshi wrote:

Hi all,

I read that in order to get the current time by using
do_gettimeofday( struct timeval *tv) function we need
to disable the inturrepts because we can't access both
fields of timeval struct tv_sec and tv_usec. Why is it
so ?
Timing on linux kernel are base on Timer interrupts,that are
generated by system's timing hardware at regular intervlas,
according to the value of HZ. Every time a timer interrupt occurs,
jiffies incremented. I suppose that fields of timeval struct are
computed through jiffies, so it isn't safe to read them without
first disabling interrupts.

also i read code from Linux device drivers book that
they are reading all the values in /proc interface. is
it compulsary to do so ?
When u make a implemented action to a proc file,
a specified for the kernel function will execute,
so this function must take care of time interrupts.

This is my code ....

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/time.h>
#include <asm-i386/system.h>



int init_module(void)
{
       struct timeval tv;
       unsigned long flags;
       save_flags( flags );
       cli();
       do_gettimeofday(&tv);
       printk("\n\t The current time is %f",( time_t
)tv.tv_sec);
       restore_flags( flags );
       sti();
       return 0;
}



void cleanup_module(void)
{



}

Plz guide me where i am going wrong.

Thanks in advance,
Deepak Joshi.

hope to help you,
Stavros Passas

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[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