linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Eugene Surovegin <ebs@ebshome.net>
To: Yang <yangqs@163.com>
Cc: linuxppc-embedded@lists.linuxppc.org
Subject: Re: clock() seems not work !
Date: Sun, 15 Feb 2004 23:20:35 -0800	[thread overview]
Message-ID: <20040216072035.GB25104@gate.ebshome.net> (raw)


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/

             reply	other threads:[~2004-02-16  7:20 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-02-16  7:20 Eugene Surovegin [this message]
     [not found] <200402160354.VAA15020@lists.linuxppc.org>
2004-02-16  5:14 ` clock() seems not work ! Eugene Surovegin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20040216072035.GB25104@gate.ebshome.net \
    --to=ebs@ebshome.net \
    --cc=linuxppc-embedded@lists.linuxppc.org \
    --cc=yangqs@163.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).