Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In the Proxy Kernel, gettimeofday always returns 0 #1

Closed
forresti opened this issue Nov 13, 2013 · 2 comments
Closed

In the Proxy Kernel, gettimeofday always returns 0 #1

forresti opened this issue Nov 13, 2013 · 2 comments

Comments

@forresti
Copy link

I'm building a simple program with riscv-gcc and running with the proxy kernel. I'm using the proxy kernel to obtain some system libraries such as time.h.

Here's an example usage:

struct timeval tp;
struct timezone tzp;
gettimeofday(&tp,&tzp);
printf("time = %f \n", (double)tp.tv_sec + (double)tp.tv_usec*1.e-6); 

This always prints 0.0000, even when called in a long loop. Strange...

Any ideas what might be going wrong?

I can provide code and give more details if anyone wants to try to reproduce it.

Thanks,
Forrest

@ccelio
Copy link
Contributor

ccelio commented Nov 13, 2013

Well, if we disassemble that code we get this:

00000000000187d8 <gettimeofday>:
  187d8:   00093423    sd zero,8(a0)
  187dc:   00093023    sd zero,0(a0)
  187e0:   00000813    li v0,0
  187e4:   0000806f    ret

So yah, it's only ever going to return zero. "gettimeofday" should make a syscall, which would be handled by the riscv-pk (SYS_time) properly and return a value based off of "rdcycle()" and assuming a 1GHz clock.

So the question is why is the compiler giving us the wrong code, when the proxy-kernel is waiting for a SYS_time syscall? I'm guessing a stub somewhere in riscv-gcc didn't get filled out, but I don't really know where to look myself.

@aswaterman
Copy link
Collaborator

Newlib's implementation of gettimeofday was doing exactly what Chris'
disassembly would suggest. I've changed it to use rdtime, assuming a
timebase of 1 GHz, which is on the right order of magnitude, at least.

Need to rebuild riscv-gcc before rebuilding riscv-pk.

On Tue, Nov 12, 2013 at 10:54 PM, Christopher Celio <
notifications@github.com> wrote:

Well, if we disassemble that code we get this:

00000000000187d8 :
187d8: 00093423 sd zero,8(a0)
187dc: 00093023 sd zero,0(a0)
187e0: 00000813 li v0,0
187e4: 0000806f ret

So yah, it's only ever going to return zero. "gettimeofday" should make a
syscall, which would be handled by the riscv-pk (SYS_time) properly and
return a value based off of "rdcycle()" and assuming a 1GHz clock.

So the question is why is the compiler giving us the wrong code, when the
proxy-kernel is waiting for a SYS_time syscall?


Reply to this email directly or view it on GitHubhttps://github.com//issues/1#issuecomment-28370649
.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants