what's clock time?what's user CPU time?what's system CPU time?

what's clock time?what's user CPU time?what's system CPU time?

Post by kelantas k » Thu, 11 Jul 2002 12:13:07



When we measure the excution time of a process,We'll see that Unix
maintains three values for a process:
        clock time
        user CPU time
        system CPU time
The clock time is sometimes call walled clock time.It is the amount of
time the process takes to run,and its
value depends on the number of process being run on the
system.Whenever we report the clock time,the measurements
are makde with no other activities on the system.

I have some question about the clock time:
1.if the "clock time" = "user CPU time" + "system CPU time"
2.Why clock time's value depends on the number of process being run on
the system.If I have many processes in the
system,so when I start A process,A process's  clock time includes the
time in which it is suspended or swapped by the kernel
and waits for other processes to run?
3.Whenever we report the clock time,the measurements are makde with no
other activities on the system.Why?? the reason is
like question 2?
I get a copy of source  code from Rechard Stevens <Advanced
Programmming in the UNIX Environment> as following:
#include        <sys/times.h>
#include        "ourhdr.h"

static void     pr_times(clock_t, struct tms *, struct tms *);
static void     do_cmd(char *);

int
main(int argc, char *argv[])
{
        int             i;

        for (i = 1; i < argc; i++)
                do_cmd(argv[i]);        /* once for each command-line arg */
        exit(0);

Quote:}

static void
do_cmd(char *cmd)               /* execute and time the "cmd" */
{
        struct tms      tmsstart, tmsend;
        clock_t         start, end;
        int                     status;
        int             i=0;

        fprintf(stderr, "\ncommand: %s\n", cmd);

        if ( (start = times(&tmsstart)) == -1)      /* starting values */
                err_sys("times error");

        if ( (status = system(cmd)) < 0)             /* execute command */
                err_sys("system() error");

        if ( (end = times(&tmsend)) == -1)          /* ending values */
                err_sys("times error");

        pr_times(end-start, &tmsstart, &tmsend);
        pr_exit(status);

Quote:}

static void
pr_times(clock_t real, struct tms *tmsstart, struct tms *tmsend)
{
        static long             clktck = 0;

        if (clktck == 0)        /* fetch clock ticks per second first time */
                if ( (clktck = sysconf(_SC_CLK_TCK)) < 0)
                        err_sys("sysconf error");
        fprintf(stderr, "  real:  %7.2f\n", real / (double) clktck);
        fprintf(stderr, "  user:  %7.2f\n",
                        (tmsend->tms_utime - tmsstart->tms_utime) / (double) clktck);
        fprintf(stderr, "  sys:   %7.2f\n",
                        (tmsend->tms_stime - tmsstart->tms_stime) / (double) clktck);
        fprintf(stderr, "  child user:  %7.2f\n",
                        (tmsend->tms_cutime - tmsstart->tms_cutime) / (double) clktck);
        fprintf(stderr, "  child sys:   %7.2f\n",
                        (tmsend->tms_cstime - tmsstart->tms_cstime) / (double) clktck);

Quote:}

I notice that
real time = ( end - start )/(double)clktck
user time = (tmsend->tms_utime - tmsstart->tms_utime) / (double)
clktck
sys  time = (tmsend->tms_stime - tmsstart->tms_stime) / (double)
clktck
child user =(tmsend->tms_cutime - tmsstart->tms_cutime) / (double)
clktck
child sys  =(tmsend->tms_cstime - tmsstart->tms_cstime) / (double)
clktck

When I run command like this,I can get the output.
$a.out "sleep 5" "date"

command: sleep 5
  real:     5.02
  user:     0.00
  sys:      0.00
  child user:     0.01
  child sys:      0.00

command: date
Tue Jul  9 22:50:59 CST 2002
  real:     0.01
  user:     0.00
  sys:      0.00
  child user:     0.00
  child sys:      0.01

it's ture that the "real time != user + sys + child user + child
sys",as to command "sleep 5",
5.02 - 5 -0.01 = 0.01 ,so what takes the 0.01sec?the sys kernel swap?
or some other reason?

 
 
 

what's clock time?what's user CPU time?what's system CPU time?

Post by Andreas K?h? » Thu, 11 Jul 2002 13:22:37


Submitted by "kelantas kou" to comp.unix.programmer:

Quote:> When we measure the excution time of a process,We'll see that Unix
> maintains three values for a process:
>    clock time

Real time taken to run program.

Quote:>    user CPU time

Time spent by the CPU in the user code.

Quote:>    system CPU time

Time spent by CPU in kernel on behalf of user code.

Quote:> The clock time is sometimes call walled clock time.It is the amount of
> time the process takes to run,and its
> value depends on the number of process being run on the
> system.Whenever we report the clock time,the measurements
> are makde with no other activities on the system.

> I have some question about the clock time:
> 1.if the "clock time" = "user CPU time" + "system CPU time"

Only if your process is the only process executing on the entire
system.

Quote:> 2.Why clock time's value depends on the number of process being run on
> the system.If I have many processes in the
> system,so when I start A process,A process's  clock time includes the
> time in which it is suspended or swapped by the kernel
> and waits for other processes to run?
> 3.Whenever we report the clock time,the measurements are makde with no
> other activities on the system.Why?? the reason is
> like question 2?

I didn't quite understand question 2, and question 3 is related
to my answer to question 1.

If you run process A and B at the same time, and if they both
use 5s of user CPU time and 1s of system CPU time, they have
used 6s of the CPU.  However, they probably took about 12s
(wallclock) to run since they only got 50% each of the CPU.

Now, replace process B with all processes of other users.

Quote:> I get a copy of source  code from Rechard Stevens <Advanced
> Programmming in the UNIX Environment> as following:
[cut]
> it's ture that the "real time != user + sys + child user + child
> sys",as to command "sleep 5",
> 5.02 - 5 -0.01 = 0.01 ,so what takes the 0.01sec?the sys kernel swap?
> or some other reason?

See above.

--
Andreas K?h?ri
--------------------------------------------------------------
Stable, secure, clean, free:  www.netbsd.org

 
 
 

what's clock time?what's user CPU time?what's system CPU time?

Post by David Schwart » Fri, 12 Jul 2002 01:33:37



> 2.Why clock time's value depends on the number of process being run on
> the system.If I have many processes in the
> system,so when I start A process,A process's  clock time includes the
> time in which it is suspended or swapped by the kernel
> and waits for other processes to run?

        Clock time (or wall time) is how many actual seconds of real time
elapsed between when the program started and when it stopped. A busy
system will devote less actual time to each process because it has to
give some time to the others.

Quote:> 3.Whenever we report the clock time,the measurements are makde with no
> other activities on the system.Why?? the reason is
> like question 2?

        Otherwise all your measuring is how busy your system as a whole is.

Quote:> When I run command like this,I can get the output.
> $a.out "sleep 5" "date"

> command: sleep 5
>   real:     5.02
>   user:     0.00
>   sys:      0.00
>   child user:     0.01
>   child sys:      0.00

> command: date
> Tue Jul  9 22:50:59 CST 2002
>   real:     0.01
>   user:     0.00
>   sys:      0.00
>   child user:     0.00
>   child sys:      0.01

> it's ture that the "real time != user + sys + child user + child
> sys",as to command "sleep 5",

        Absolutely.

Quote:> 5.02 - 5 -0.01 = 0.01 ,so what takes the 0.01sec?the sys kernel swap?
> or some other reason?

        Read the man page for the 'sleep' command. 'sleep 5' means to sleep for
*at* *least* 5 seconds.

        DS

 
 
 

what's clock time?what's user CPU time?what's system CPU time?

Post by Eric Sosma » Fri, 12 Jul 2002 07:28:49



> Submitted by "kelantas kou" to comp.unix.programmer:

> > I have some question about the clock time:
> > 1.if the "clock time" = "user CPU time" + "system CPU time"

> Only if your process is the only process executing on the entire
> system.

    And if your process never blocks for I/O, never takes a
page fault, never calls sleep(), never waits for a mutex ...
Even when your process stalls and does nothing at all for a
while, the external world keeps on ticking (as best we can
tell, anyhow): Earth continues along its orbit, spam keeps
piling up in your in-box, and your immobilized process keeps
on accumulating "clock time" simply by existing.

--

 
 
 

1. CPU time used on 4 CPU's?

If I have 4 CPU's and am looking at one of the  various time output
programs, is the number real, or is it divided by 4?  or instance,
is it possible for me to get a cpu time usage on the system of 4
hours in a one hour period?  Or, will it only be 1 hour max.  Then,
how do I determine if all CPU's are being used equally.

BTW: This is  a DGUX system.  But, I would take any Unix flavor as
an example.

Side line:  I am looking for a good product for generating reports on
CPU usage sorted by users, Processes, and groups.  Not % of capacity,
but raw seconds of CPU time used.  Like time(1) or times(2).
Commercial is fine.  We would pay for it if it is good.

Is there a way to get times(2) to give up every process, as if it were
run by init.  I am looking for something other than inittab.  If an
inittab entry is the only way, examples would be appreciated.  I can't
play with this system to test it first!  (Crontab likewise.)

--

Sysop - Home Brew University BBS   Brew City Campus       414-238-9074
Genealogy Search:  Brickner, Kane, Kimbro, LaClaire, Snyder|Snider,
                   Seecs|Seetch|Sich, and Thorton.
  Visit my homepage for more ...          http://www.execpc.com/~jkane

2. LOST /dev/zero file. HELP!!!

3. 'date' and 'clock' show different times

4. LILO version 21.6.1 released

5. Is the time in gprof CPU time or elapsed time?

6. building smp kernel

7. 'update' eats all my CPU time!!

8. ppp-on: peer authentication required but no authentication files accessible

9. 'CPU time limit exceeded' message

10. Timing info from 'time'

11. time synchronization ('timed')

12. Running 'clock -Ar' each time a user logs in

13. Anyone using 'timed'as a time server?