> From: "Todd C. Miller" <[email protected]>
> Date: Wed, 15 Oct 2014 11:37:26 -0600
> 
> Since this came up in another thread.  Trivial implementations of
> CLOCK_VIRTUAL and CLOCK_PROF, modeled after what FreeBSD does.

Shouldn't this do a tuagg() on all the threads of the process like we
do for getrusage?  Otherwise the CLOCK_VIRTUAL and CLOCK_PROF clocks
will only be updated upon a context switch.

Also, you should add support for these to clock_getres(2).

Oh, and documenting CLOCK_PROF in the man page would be good.

> Index: sys/sys/_time.h
> ===================================================================
> RCS file: /home/cvs/openbsd/src/sys/sys/_time.h,v
> retrieving revision 1.6
> diff -u -r1.6 _time.h
> --- sys/sys/_time.h   6 Oct 2013 01:27:49 -0000       1.6
> +++ sys/sys/_time.h   15 Oct 2014 13:40:28 -0000
> @@ -38,6 +38,7 @@
>  #define CLOCK_MONOTONIC                      3
>  #define CLOCK_THREAD_CPUTIME_ID              4
>  #define CLOCK_UPTIME                 5
> +#define CLOCK_PROF                   6
>  
>  #if __BSD_VISIBLE
>  #define      __CLOCK_USE_TICKET_LOCKS        8       /* flag for 
> __thrsleep() */
> Index: sys/kern/kern_time.c
> ===================================================================
> RCS file: /home/cvs/openbsd/src/sys/kern/kern_time.c,v
> retrieving revision 1.88
> diff -u -r1.88 kern_time.c
> --- sys/kern/kern_time.c      15 May 2014 04:36:33 -0000      1.88
> +++ sys/kern/kern_time.c      15 Oct 2014 14:31:06 -0000
> @@ -108,12 +108,20 @@
>  int
>  clock_gettime(struct proc *p, clockid_t clock_id, struct timespec *tp)
>  {
> +     struct timespec sys;
>       struct bintime bt;
>       struct proc *q;
>  
>       switch (clock_id) {
>       case CLOCK_REALTIME:
>               nanotime(tp);
> +             break;
> +     case CLOCK_VIRTUAL:
> +             calctsru(&p->p_p->ps_tu, tp, &sys, NULL);
> +             break;
> +     case CLOCK_PROF:
> +             calctsru(&p->p_p->ps_tu, tp, &sys, NULL);
> +             timespecadd(tp, &sys, tp);
>               break;
>       case CLOCK_UPTIME:
>               binuptime(&bt);
> 
> 

Reply via email to