Skip to content

cpu/mips32r2_common: use periph_common timer_set#8720

Closed
cladmi wants to merge 2 commits intoRIOT-OS:masterfrom
cladmi:pr/cpu/mips32r2_common/remove_timer_set
Closed

cpu/mips32r2_common: use periph_common timer_set#8720
cladmi wants to merge 2 commits intoRIOT-OS:masterfrom
cladmi:pr/cpu/mips32r2_common/remove_timer_set

Conversation

@cladmi
Copy link
Contributor

@cladmi cladmi commented Mar 1, 2018

Use 'timer_set' provided by 'periph_common' instead of re-implementing it.

It also fixes 'mips32r2_generic' that should have been defining
'PERIPH_TIMER_PROVIDES_SET' as 'mips32r2_common' uses 'periph_common' but is not
necessary if removing the function.

Issues/PRs references

Its required for #8711

It was also disabled by #5757 in periph_conf.h but the function can be removed as it has the same behavior as periph_common https://github.com/RIOT-OS/RIOT/blob/2018.01/drivers/periph_common/timer.c#L24.

Use 'timer_set' provided by 'periph_common' instead of re-implementing it.

It also fixes 'mips32r2_generic' that should have been defining
'PERIPH_TIMER_PROVIDES_SET' as 'mips32r2_common' uses 'periph_common' but is not
necessary if removing the function.
@cladmi cladmi added Type: cleanup The issue proposes a clean-up / The PR cleans-up parts of the codebase / documentation CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Platform: MIPS Platform: This PR/issue effects MIPS-based platforms labels Mar 1, 2018
@cladmi
Copy link
Contributor Author

cladmi commented Mar 1, 2018

I have not tested that the board still works. And I will let Murdock check the builds.

@cladmi
Copy link
Contributor Author

cladmi commented Mar 1, 2018

Another option to solve this could be to define PERIPH_TIMER_PROVIDES_SET for mips32r2_generic.

Copy link
Member

@jnohlgard jnohlgard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks OK to me, but I don't have any MIPS board to test on.

Also, the return value of timer_set_absolute and timer_clear are wrong compared to the API documentation, should be return 1. Feel free to fix it or leave it

@jnohlgard jnohlgard added this to the Release 2018.04 milestone Mar 2, 2018
@smlng smlng added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Mar 2, 2018
Fix 'timer_set_absolute' and 'timer_clear' return value to 1 on success as
documented in the API.
@neiljay
Copy link
Contributor

neiljay commented Mar 2, 2018

Is the generic timer_set always called with interrupts disabled ?

int timer_set(tim_t dev, int channel, unsigned int timeout)
{
return timer_set_absolute(dev, channel, timer_read(dev) + timeout);
}

if you took a high latency interrupt (or even worse rescheduled) between the timer_read and the timer_set_absolute your timer is not going to be very accurate ?

@cladmi
Copy link
Contributor Author

cladmi commented Mar 2, 2018

@neiljay I did not think about that, I just copied what was done for other cpus. I could change it to defining PERIPH_TIMER_PROVIDES_SET in mips32r2_generic periph_conf.h if you prefer.

@neiljay
Copy link
Contributor

neiljay commented Mar 2, 2018

@cladmi maybe fix the generic implementation to disable interrupts as well first ?

int timer_set(tim_t dev, int channel, unsigned int timeout)
{
uint32_t status = irq_disable();
int ret = timer_set_absolute(dev, channel, timer_read(dev) + timeout);
irq_restore(status);
return ret
}

@jnohlgard
Copy link
Member

I agree, it's better to fix the generic implementation

@cladmi
Copy link
Contributor Author

cladmi commented Mar 2, 2018

The general fix should be done in another PR then. This one can wait until its done.
I could do something next week.

@cladmi
Copy link
Contributor Author

cladmi commented Mar 5, 2018

Thinking again about this. Would it really help to put this irq_disable ?
I think, it does not really change the final behavior.
Let me explain my thoughts with a timer_set(5 seconds) and a 3 seconds re-schedule (to give numbers).

Without irq_disable

  • if re-scheduled between timer_get and timer_set_absolute, timer_get is evaluated before re-scheduling, so the callback is triggered after 5 seconds since the function call.
  • If re-scheduled before timer_get, timer_get will be done 3 seconds after and the callback is after 8 seconds in total.

With irq_disable

  • In the irq_disable section, it cannot be re-scheduled so its a 5 seconds in total.
  • If re-scheduled before irq_disable, timer_get will also be done 3 seconds after and the callback is after 8 seconds in total.

So adding irq_disable only protects a few cycles more. Your precision depend on how long can a high priority task take the cpu anyway.

@neiljay
Copy link
Contributor

neiljay commented Mar 5, 2018 via email

@jnohlgard
Copy link
Member

I am working on a benchmark for periph_timer which will be useful for giving some statistics on latency and target accuracy,. It will not however be able to interrupt the timer_set function in the precise place you are discussing for triggering that particular race condition. See #8531 for the WIP state.

@cladmi
Copy link
Contributor Author

cladmi commented Mar 22, 2018

I proposed another PR that just fixes the double definition to allow merging it now: #8817
This way it keeps the current behavior but disables defining timer_set in periph_common.

@cladmi
Copy link
Contributor Author

cladmi commented Apr 13, 2018

Closed in favor of #8817

@cladmi cladmi closed this Apr 13, 2018
@cladmi cladmi deleted the pr/cpu/mips32r2_common/remove_timer_set branch April 19, 2018 11:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Platform: MIPS Platform: This PR/issue effects MIPS-based platforms Type: cleanup The issue proposes a clean-up / The PR cleans-up parts of the codebase / documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants