Re: knowing-current-time

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

 



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 ?

The function do_gettimeofday() makes sure that
the tv_sec and tv_usec values returned by it are
consistent, using an internal kernel lock.  The
values returned in your tv structure are a snapshot
of the time, and will not be modified by ongoing
kernel timekeeping after the call.

There is no need to disable interrupts around a call
to do_gettimeofday().

FYI, on most platforms, do_gettimeofday() returns
values that have a resolution that is much better
than jiffies. That is, more than JUST the timer
interrupt is a factor in determining the value to
be returned.  Usually it's a combination of
jiffies and some other high resolution clock
on the system.

> 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 ?

I don't understand this question.  Who is "they"?
What is the purpose of reading the time, and in what
context (kernel or user-space) is the time value wanted?

>         cli();
>         do_gettimeofday(&tv);
>         printk("\n\t The current time is %f",( time_t
> )tv.tv_sec);
>         restore_flags( flags );
>         sti();

I'm not sure I understand the purpose of the module.
Is it to provide a user-space manifestation of the current
time?  If so, why not use a system call instead of a kernel
module?

With regard to the code itself, even if there was a
requirement to disable interrupts when using the value,
this particular code only uses one of the two parts of
the time value (tv_sec and not tv_usec), so it wouldn't
have a problem anyway.

=============================
Tim Bird
Architecture Group Chair, CE Linux Forum
Senior Staff Engineer, Sony Electronics
=============================


--
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