tock / libtock-rs

Rust userland library for Tock
Apache License 2.0
160 stars 105 forks source link

Is there any API function for timing? #532

Open gentooza opened 4 months ago

gentooza commented 4 months ago

Hi!

As we are not using std we have no Instant() function, also, I've seen old code, that does not work for me using current version, using kernel::hl1::... for timer functionality

The question! (hehehe)

Is there any tool for measuring time? It could be interesting for benchmarking purposes, for example.

Thanks! (I'm really in love with your project)

jrvanwhy commented 4 months ago

Retrieving the current time (clock ticks, to be precise) is done by using the alarm syscall driver. We do have a library for interfacing with the alarm syscall driver, but it doesn't currently appear to have a function for retrieving the current time.

You're welcome to help complete it, as it should support all functions the alarm syscall driver has.

gentooza commented 3 months ago

Hi @jrvanwhy !

I'm going to share here the modification I have done to get Ticks back from the Alarm API component, ok?

Code is here: https://github.com/gentooza/libtock-rs/blob/alarm_get_ticks/apis/alarm/src/lib.rs

I don't feel enough confident with Rust (yet :-D) for opening a pull request

What I have done is adding methods to struct Ticks:

It's working for me, at least it gives me a coherent increasing number I can operate with. :-D

Is it ok?

Cheers