Re: implement CLOCK_VIRTUAL and CLOCK_PROF

2014-10-16 Thread Joerg Jung

 Am 16.10.2014 um 06:50 schrieb Philip Guenther guent...@gmail.com:
 
 On Wed, Oct 15, 2014 at 2:08 PM, Todd C. Miller
 todd.mil...@courtesan.com wrote:
 On Wed, 15 Oct 2014 21:53:47 +0200, Alexandre Ratchov wrote:
 On Wed, Oct 15, 2014 at 11:37:26AM -0600, Todd C. Miller wrote:
 Since this came up in another thread.  Trivial implementations of
 CLOCK_VIRTUAL and CLOCK_PROF, modeled after what FreeBSD does.
 
 out of curiousity, what program needs these?
 
 Possibly none, but we currently define CLOCK_VIRTUAL but don't
 actually support it.
 
 IMO we should just delete CLOCK_VIRTUAL from sys/_time.h and clock_gettime(2).

I agree.



Re: implement CLOCK_VIRTUAL and CLOCK_PROF

2014-10-16 Thread Todd C. Miller
On Wed, 15 Oct 2014 21:50:44 -0700, Philip Guenther wrote:

 IMO we should just delete CLOCK_VIRTUAL from sys/_time.h and clock_gettime(2)

Easy enough.

 - todd

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 -   1.6
+++ sys/sys/_time.h 16 Oct 2014 12:47:02 -
@@ -33,7 +33,6 @@
 #define _SYS__TIME_H_
 
 #define CLOCK_REALTIME 0
-#define CLOCK_VIRTUAL  1
 #define CLOCK_PROCESS_CPUTIME_ID   2
 #define CLOCK_MONOTONIC3
 #define CLOCK_THREAD_CPUTIME_ID4
Index: lib/libc/sys/clock_gettime.2
===
RCS file: /home/cvs/openbsd/src/lib/libc/sys/clock_gettime.2,v
retrieving revision 1.24
diff -u -r1.24 clock_gettime.2
--- lib/libc/sys/clock_gettime.221 Jan 2014 03:15:45 -  1.24
+++ lib/libc/sys/clock_gettime.216 Oct 2014 12:43:33 -
@@ -62,9 +62,6 @@
 .Bl -tag -width CLOCK_MONOTONIC
 .It Dv CLOCK_REALTIME
 time that increments as a wall clock should
-.It Dv CLOCK_VIRTUAL
-time that increments only when
-the CPU is running in user mode on behalf of the calling process
 .It Dv CLOCK_PROCESS_CPUTIME_ID
 time that increments when the CPU is running in user or kernel mode
 on behalf of the calling process



Re: implement CLOCK_VIRTUAL and CLOCK_PROF

2014-10-16 Thread Stuart Henderson
On 2014/10/16 07:33, Todd C. Miller wrote:
 On Wed, 15 Oct 2014 21:50:44 -0700, Philip Guenther wrote:
 
  IMO we should just delete CLOCK_VIRTUAL from sys/_time.h and 
  clock_gettime(2)
 
 Easy enough.

ports should be pretty much OK with this, if there's any breakage it
will be minor and can be handled affterwards.



Re: implement CLOCK_VIRTUAL and CLOCK_PROF

2014-10-16 Thread Mark Kettenis
 From: Todd C. Miller todd.mil...@courtesan.com
 Date: Thu, 16 Oct 2014 07:33:23 -0600
 
 On Wed, 15 Oct 2014 21:50:44 -0700, Philip Guenther wrote:
 
  IMO we should just delete CLOCK_VIRTUAL from sys/_time.h and 
  clock_gettime(2)
 
 Easy enough.

ok kettenis@

 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 -   1.6
 +++ sys/sys/_time.h   16 Oct 2014 12:47:02 -
 @@ -33,7 +33,6 @@
  #define _SYS__TIME_H_
  
  #define CLOCK_REALTIME   0
 -#define CLOCK_VIRTUAL1
  #define CLOCK_PROCESS_CPUTIME_ID 2
  #define CLOCK_MONOTONIC  3
  #define CLOCK_THREAD_CPUTIME_ID  4
 Index: lib/libc/sys/clock_gettime.2
 ===
 RCS file: /home/cvs/openbsd/src/lib/libc/sys/clock_gettime.2,v
 retrieving revision 1.24
 diff -u -r1.24 clock_gettime.2
 --- lib/libc/sys/clock_gettime.2  21 Jan 2014 03:15:45 -  1.24
 +++ lib/libc/sys/clock_gettime.2  16 Oct 2014 12:43:33 -
 @@ -62,9 +62,6 @@
  .Bl -tag -width CLOCK_MONOTONIC
  .It Dv CLOCK_REALTIME
  time that increments as a wall clock should
 -.It Dv CLOCK_VIRTUAL
 -time that increments only when
 -the CPU is running in user mode on behalf of the calling process
  .It Dv CLOCK_PROCESS_CPUTIME_ID
  time that increments when the CPU is running in user or kernel mode
  on behalf of the calling process
 
 



implement CLOCK_VIRTUAL and CLOCK_PROF

2014-10-15 Thread Todd C. Miller
Since this came up in another thread.  Trivial implementations of
CLOCK_VIRTUAL and CLOCK_PROF, modeled after what FreeBSD does.

 - todd

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 -   1.6
+++ sys/sys/_time.h 15 Oct 2014 13:40:28 -
@@ -38,6 +38,7 @@
 #define CLOCK_MONOTONIC3
 #define CLOCK_THREAD_CPUTIME_ID4
 #define CLOCK_UPTIME   5
+#define CLOCK_PROF 6
 
 #if __BSD_VISIBLE
 #define__CLOCK_USE_TICKET_LOCKS8   /* 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.c15 May 2014 04:36:33 -  1.88
+++ sys/kern/kern_time.c15 Oct 2014 14:31:06 -
@@ -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);



Re: implement CLOCK_VIRTUAL and CLOCK_PROF

2014-10-15 Thread Mark Kettenis
 From: Todd C. Miller todd.mil...@courtesan.com
 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 -   1.6
 +++ sys/sys/_time.h   15 Oct 2014 13:40:28 -
 @@ -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_LOCKS8   /* 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 -  1.88
 +++ sys/kern/kern_time.c  15 Oct 2014 14:31:06 -
 @@ -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);
 
 



Re: implement CLOCK_VIRTUAL and CLOCK_PROF

2014-10-15 Thread Mark Kettenis
 Date: Wed, 15 Oct 2014 20:18:10 +0200 (CEST)
 From: Mark Kettenis mark.kette...@xs4all.nl
 
  From: Todd C. Miller todd.mil...@courtesan.com
  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.

Hmm, looking at the FreeBSD man page... isn't CLOCK_PROF the same
thing as CLOCK_PROCESS_CPUTIME_ID?



Re: implement CLOCK_VIRTUAL and CLOCK_PROF

2014-10-15 Thread Mark Kettenis
 Date: Wed, 15 Oct 2014 20:36:33 +0200 (CEST)
 From: Mark Kettenis mark.kette...@xs4all.nl
 
  Date: Wed, 15 Oct 2014 20:18:10 +0200 (CEST)
  From: Mark Kettenis mark.kette...@xs4all.nl
  
   From: Todd C. Miller todd.mil...@courtesan.com
   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.
 
 Hmm, looking at the FreeBSD man page... isn't CLOCK_PROF the same
 thing as CLOCK_PROCESS_CPUTIME_ID?

Oh, and while FreeBSD seems to implement CLOCK_VIRTUAL and CLOCK_PROF
as per-process, Solaris implements them as per-thread (but doesn't
document them).  And on Solaris CLOCK_PROF is just an alias for
CLOCK_THREAD_CPUTIME_ID.

Starting to doubt if we really want to implement these...



Re: implement CLOCK_VIRTUAL and CLOCK_PROF

2014-10-15 Thread Todd C. Miller
On Wed, 15 Oct 2014 20:36:33 +0200, Mark Kettenis wrote:

 Hmm, looking at the FreeBSD man page... isn't CLOCK_PROF the same
 thing as CLOCK_PROCESS_CPUTIME_ID?

I was wondering that too, but I get different results as they are
not calculated the same way.  CLOCK_PROCESS_CPUTIME_ID always yields
a slightly higher number.

 - todd



Re: implement CLOCK_VIRTUAL and CLOCK_PROF

2014-10-15 Thread Todd C. Miller
On Wed, 15 Oct 2014 20:18:10 +0200, Mark Kettenis wrote:

 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.

Probably.  I wasn't 100% sure going the rusage route was the correct
one.

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

Good catch.

 - todd



Re: implement CLOCK_VIRTUAL and CLOCK_PROF

2014-10-15 Thread Todd C. Miller
On Wed, 15 Oct 2014 21:04:43 +0200, Mark Kettenis wrote:

 Oh, and while FreeBSD seems to implement CLOCK_VIRTUAL and CLOCK_PROF
 as per-process, Solaris implements them as per-thread (but doesn't
 document them).  And on Solaris CLOCK_PROF is just an alias for
 CLOCK_THREAD_CPUTIME_ID.
 
 Starting to doubt if we really want to implement these...

Maybe not.  It seemed like a fairly simple thing but given the lack
of a standard or any real consensus in terms of implementation it
is probably not worth it.

Those clock types are probably more useful in conjunction with
timer_create, etc which we don't actually support.

 - todd



Re: implement CLOCK_VIRTUAL and CLOCK_PROF

2014-10-15 Thread Alexandre Ratchov
On Wed, Oct 15, 2014 at 11:37:26AM -0600, Todd C. Miller wrote:
 Since this came up in another thread.  Trivial implementations of
 CLOCK_VIRTUAL and CLOCK_PROF, modeled after what FreeBSD does.
 

out of curiousity, what program needs these?



Re: implement CLOCK_VIRTUAL and CLOCK_PROF

2014-10-15 Thread Todd C. Miller
On Wed, 15 Oct 2014 21:53:47 +0200, Alexandre Ratchov wrote:

 On Wed, Oct 15, 2014 at 11:37:26AM -0600, Todd C. Miller wrote:
  Since this came up in another thread.  Trivial implementations of
  CLOCK_VIRTUAL and CLOCK_PROF, modeled after what FreeBSD does.
  
 
 out of curiousity, what program needs these?

Possibly none, but we currently define CLOCK_VIRTUAL but don't
actually support it.

 - todd



Re: implement CLOCK_VIRTUAL and CLOCK_PROF

2014-10-15 Thread Philip Guenther
On Wed, Oct 15, 2014 at 2:08 PM, Todd C. Miller
todd.mil...@courtesan.com wrote:
 On Wed, 15 Oct 2014 21:53:47 +0200, Alexandre Ratchov wrote:
 On Wed, Oct 15, 2014 at 11:37:26AM -0600, Todd C. Miller wrote:
  Since this came up in another thread.  Trivial implementations of
  CLOCK_VIRTUAL and CLOCK_PROF, modeled after what FreeBSD does.

 out of curiousity, what program needs these?

 Possibly none, but we currently define CLOCK_VIRTUAL but don't
 actually support it.

IMO we should just delete CLOCK_VIRTUAL from sys/_time.h and clock_gettime(2).


Philip Guenther