linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* Re: clock() seems not work !
@ 2004-02-16  7:20 Eugene Surovegin
  0 siblings, 0 replies; 2+ messages in thread
From: Eugene Surovegin @ 2004-02-16  7:20 UTC (permalink / raw)
  To: Yang; +Cc: linuxppc-embedded


On Mon, Feb 16, 2004 at 03:13:55PM +0800, Yang wrote:
> >On Mon, Feb 16, 2004 at 11:58:07AM +0800, Yang wrote:
> >>
> >>  i am writting applications based ppc+MVL3.0, which i want to get CPU
> >> time,but clock() seems not work for me, for this i did a simple test,as
> >> follows:
> >> /*----------------*/
> >>   while(1)
> >> 	{
> >>       printf("current time is ld \n",clock());
> >> 	  sleep(1);
> >> 	}
> >> /*----------------*/
> >>      But it printed the same value all the while. How is it?
> >>
> >
> >What do you expect from this function?
> >
> >Did you read manual entry for clock()?
> >
> >On POSIX systems clock() returns (number of seconds * CLOCKS_PER_SEC)
> >spent by the process, not a system time/tick count...
> >
> >Your program is doing _nothing_, so it's normal that clock() returns
> >the same number. Change sleep(1) to some busy loop and you'll see the
> >difference.
> >
> >Eugene.
>
> In fact i want to get a "timeout" utility ,which check periodically if a program has expired.
> Based X86

What do you mean under x86?

You aren't talking about Linux x86, are you ?

I'm just curious, what OS are you porting this code from (looks like
DOS to me :) ?

>i use clock() to set a timeout and it return the tick count of CPU.
> But it's entirely different in Linux. In most my case the timeout is a couple of 10ms.
>   The following codes are some fragments in my X86 system, how can i migrate them to Linux?
> /*------------------------------------------------*/
>  long set_timeout(long timeout)
>  {
>   return(clock()+timeout/55);  /* i386 tick once per 55ms */
>  }
>
>  char chk_timeout(long settime)
>  {
>    return (clock() >= settime) ? TIMEOUT : NO_TIMEOUT;
>  }
> /*-------------------------------------------------*/
>

OK, I think you should check gettimeofday() function.

Eugene.

** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/

^ permalink raw reply	[flat|nested] 2+ messages in thread
[parent not found: <200402160354.VAA15020@lists.linuxppc.org>]

end of thread, other threads:[~2004-02-16  7:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-02-16  7:20 clock() seems not work ! Eugene Surovegin
     [not found] <200402160354.VAA15020@lists.linuxppc.org>
2004-02-16  5:14 ` Eugene Surovegin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).