libtock-rs icon indicating copy to clipboard operation
libtock-rs copied to clipboard

Is there any API function for timing?

Open gentooza opened this issue 1 year ago • 2 comments

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)

gentooza avatar Feb 12 '24 17:02 gentooza

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.

jrvanwhy avatar Feb 12 '24 19:02 jrvanwhy

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:

  • for being able to print it:
  • for being able to make addition and subtraction operations with it
  • added a method of Alarm called get_time() to retrieve Ticks.

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

Is it ok?

Cheers

gentooza avatar Mar 14 '24 09:03 gentooza