Issue #2951 has been updated by zhtw.

swildner wrote:
> CLOCK_THREAD_CPUTIME_ID isn't broken here, as far as I can see. Are you sure 
> it returns 0 for you?

I'm sorry, didn't check it thoroughly. It indeed works with 

> CLOCK_PROF and CLOCK_VIRTUAL always return 0 here. Not sure what's the cause.
> Please check this patch for CLOCK_PROCESS_CPUTIME_ID -> 
> Not sure if that's the best fix.

Thank you for the patch.

I was unable to use it as is because the kernel didn't compile: there is no 
field "ru" in the proc struct. (I tried 4.4 & 4.6 kernels, see below why). But 
after I renamed ru to p_ru it did compile.

Unfortunately, I can't test it right now, because I only have remote access to 
both my machines (I'm on a conference now and will return only in 2 weeks). I'm 
trying to test it with vkernel, but for some reason it doesn't start (with or 
without your patch).

The message I see is:

a@hk:~/tmp$ sudo /var/vkernel/4.4/boot/kernel/kernel -m 2g -r root.img -d -p 
Using memory file: /var/vkernel/memimg.000000
KVM mapped at 0x8000000000-0x10000000000
Copyright (c) 2003-2015 The DragonFly Project.
Copyright (c) 1992-2003 The FreeBSD Project.
Copyright (c) 1979, 1980, 1983, 1986, 1988, 1989, 1991, 1992, 1993, 1994
        The Regents of the University of California. All rights reserved.
DragonFly v4.4.3.10.gfcff0-RELEASE #2: Wed Sep 21 14:47:58 CEST 2016
real memory = 2147483648 (2097152K bytes)
avail memory = 2044215296 (1996304K bytes)

Fatal trap 12: page fault while in kernel mode
cpuid = 0
fault virtual address   = 0x9
fault code              = supervisor read, page not present
instruction pointer     = 0x2b:0x6ea789
stack pointer           = 0x10:0x7fffffffe9f0
frame pointer           = 0x10:0x1
processor eflags        = interrupt enabled, resume, IOPL = 0
current process         = 0 ()
current thread          = pri 12
 <- SMP: XXX
kernel: type 12 trap, code=0

CPU0 stopping CPUs: 0x0000000000000000
Stopped at      0x6ea789:       movq    0x8(%rbp),%rdi

I'm trying 4.4 because I was never able to run 4.6 vkernel. 4.4 used to work, 
but I forgot which revision I compiled.

I will file a separate bug report for this.

Once I have physical access to my desktop I will try your patch again on the 
real kernel.

Bug #2951: clock_gettime always repots 0 sec, 0 nsec

* Author: zhtw
* Status: New
* Priority: Normal
* Assignee: 
* Category: 
* Target version: 
When called with CLOCK_PROF, clock_gettime always returns 0 sec, 0 nsec:

$ uname -a
DragonFly 4.6-RELEASE DragonFly v4.6.0.10.g16fba-RELEASE #10: Wed Aug 
17 14:26:31 CEST 2016  
$ cat time.c
#include <sys/time.h>
#include <stdio.h>

int main()
  struct timespec ts;
  struct timespec *tp = &ts;

  for (int i = 0; i != 1000000; ++i)
    for (int j = 0; j != 1000; ++j)

  int err = clock_gettime(CLOCK_PROF, tp);

  printf("err: %d\n", err);

  printf("sec: %ld\n", ts.tv_sec);
  printf("nsec: %ld\n", ts.tv_nsec);
$ cc -pedantic -Wall time.c 
$ ./a.out 
err: 0
sec: 0
nsec: 0

The same program on a FreeBSD machine seems to work:
$ uname -a
FreeBSD fbsd 10.1-RELEASE FreeBSD 10.1-RELEASE #0 r274401: Tue Nov 11 21:02:49 
UTC 2014  amd64
$ cc -pedantic -Wall time.c
$ ./a.out 
err: 0
sec: 1
nsec: 604478000

You have received this notification because you have either subscribed to it, 
or are involved in it.
To change your notification preferences, please click here:

Reply via email to