Skip to content

TESTS: common_tickers handle wrap-around case #6462

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

Closed

Conversation

LMESTM
Copy link
Contributor

@LMESTM LMESTM commented Mar 26, 2018

Description

it seems that count_ticks function does not consider the case of a
16 its counter wrap-around - proposal added here.

Pull request type

[x ] Fix
[ ] Refactor
[ ] New target
[ ] Feature
[ ] Breaking change

c1728p9 and others added 28 commits March 24, 2018 18:27
Add documentation and test header for the HAL Ticker API.
…header files.

Add one potential bug to the test description.
Fix test function names to be consistant with desctiption and test header.
Fix typos.
…pecific drivers.

Since target specific ticker drivers are not ready also features which uses ticker in upper layers may not work correctly and tests for these features.
We need to disable also failing higher level ticker related tests (by adding check if DEVICE_USTICKER symbol is available and raise #error [NOT_SUPPORTED] if not).
Current version:
The function ticker_init resets the internal count and disables the ticker interrupt.

Proposed version:
The function ticker_init allows the ticker to keep counting and disables the ticker interrupt.

This is a result of the following discussion:
ARMmbed#5233 (review)
The intention was to use ticker_overflow_delta equal to 0 for low power ticker tests and ticker_overflow_delta equal to 50 for high frequency ticker tests. Current implementation is invalid since for devices which provide LOW_POWER_TIMER feature delta is equal to 0 and for devices without this feature delta is equal 50.
- provide ticker configuration: 1MHz/32 bit counter.
- us_ticker_init() routine disables interrupts.
- adapt comments.
Low power ticker time counter is created based on RTC which is driven by 32KHz clock. Additional low power timer is used to generate interrupts.
We need to adapt driver to operate on ticks instead of us.

Perform the following updates:
- provide lp ticker configuration: 32KHz/32 bit counter.
- lp_ticker_init() routine disables lp ticker interrupts .
- adapt the driver functions to operate on ticks instead us.
- adapt comments.
- add us_ticker_free() routine.
Since according to the ticker requirements min acceptable counter size is 12 bits (low power timer) for which max count is 4095, then all test cases must be executed in this time window.
HAL ticker layer handles overflow and it is not handled in the target ticker drivers.
On some platforms (e.g. K64F) different counters are used for time measurement and interrupt generation.
Because of that we should relax interrupt test case and give additional time before checking if interrupt handler has been executed.
…lts on all compilers

count_ticks() function counts ticker ticks elapsed during execution of N cycles of empty while loop.
In current version N value (cycles) is given as volatile paramater in order to disable possible compiler optimalisation.
There was a problem with measured time on different compilers and additionally results on ARM compiler were unexpected (the difference beetween measured elapsed ticks for the same number of cycles was to large). This might be caused by the memory access in order to store updated variable in memory. To fix this issue given numer of cycles has been stored into register and register is decremented (no memory access).

With this fix count_ticks(NUM_OF_CYCLES, 1) call returns 2500 +/-1 for us ticker ticks using each compiler (K64F).
…pecific drivers.

Since target specific ticker drivers are not ready also features which uses ticker in upper layers may not work correctly and tests for these features.
We need to disable also failing higher level ticker related tests (by adding check if DEVICE_USTICKER symbol is available and raise #error [NOT_SUPPORTED] if not).

Note:
tests-mbed_drivers-rtc is new and uses us ticker to perform a delay.
Test that lp ticker does not glitch backwards due to an incorrectly implemented ripple counter driver.
That's to match DEVICE_USTICKER.
The current implementation of tickless requires LPTICKER to be present.
it seems that count_ticks function does not consider the case of a
16 its counter wrap-around - proposal added here.
@LMESTM LMESTM mentioned this pull request Mar 26, 2018
@cmonr
Copy link
Contributor

cmonr commented Mar 27, 2018

@LMESTM Interesting that the counter is only 16 bits.

Since this is a test, why not simplify things even further and instead increase the size of the counter type?

@cmonr
Copy link
Contributor

cmonr commented Mar 27, 2018

Ah, never mind. Just went through your other PR, and now it makes sense why this was set to 16 bits.

Something that bothers me. There's now an overflow check, but what happens if the counter overflows twice? Would this change catch multiple overflows?

You might consider catching overflows inside of the while loop.

@cmonr
Copy link
Contributor

cmonr commented Mar 27, 2018

I'm also curious to hear about how you tested the overflow edge case.

@LMESTM
Copy link
Contributor Author

LMESTM commented Mar 27, 2018

I'm also curious to hear about how you tested the overflow edge case.

I just tested on L073RZ target which happens to be a relatively slow CPU, with 16bits counter.
Error message below was somehow leading to overflow. I'm fine with any other fix for the test.

[1522085572.44][CONN][RXD] >>> Running case #8: 'Microsecond ticker increment test'...
[1522085572.50][CONN][INF] found KV pair in stream: {{__testcase_start;Microsecond ticker increment test}}, queued...
[1522085572.59][CONN][RXD] :314::FAIL: Values Not Within Delta 1 Expected 4294911135 Was 9375
[1522085572.64][CONN][INF] found KV pair in stream: {{__testcase_finish;Microsecond ticker increment test;0;1}}, queued...
[1522085572.75][CONN][RXD] >>> 'Microsecond ticker increment test': 0 passed, 1 failed with reason 'Assertion Failed'

@0xc0170 0xc0170 requested review from c1728p9 and bulislaw March 27, 2018 07:27
@bulislaw bulislaw force-pushed the feature-hal-spec-ticker branch from afd66ab to 6daa7fc Compare March 27, 2018 14:06
@theotherjimmy
Copy link
Contributor

It looks like you have conflicts with the base branch. This may require a rebase. Also, it looks like this PR includes many changes that @LMESTM did not make. These two observations are probably related.

@LMESTM
Copy link
Contributor Author

LMESTM commented Mar 29, 2018

@cmonr this was a quick fix made during workshop to unblock situation. I'm fin if you fix it another way or use the same kind of protect overflow that have been proposed in other PRs.

@0xc0170
Copy link
Contributor

0xc0170 commented Apr 3, 2018

@LMESTM This should fix the problem #6492 and can this be closed or still relevant?

@LMESTM
Copy link
Contributor Author

LMESTM commented Apr 3, 2018

@0xc0170 - do you refer to another PR that would fix this issue ? Is there a missing link. I am not sure if #6492 covers the common_tickers tests, does it ?
But I agree that overflow_protect() mechanism could be used as in #6492. I'd be fine to close this PR and let @mprse do a better fix than b2aa2dd

@LMESTM
Copy link
Contributor Author

LMESTM commented Apr 3, 2018

I'm saying this because previous comment from @cmonr makes definitely sense

Something that bothers me. There's now an overflow check, but what happens if the counter overflows twice? Would this change catch multiple overflows?

@mprse
Copy link
Contributor

mprse commented Apr 4, 2018

@LMESTM Hi! I'm sure that count_ticks() function is protected against overflow. It does not use standard overflow_protect() mechanism since we can not predict how many times count_ticks() will be executed during ticker_increment_test.

I checked on slow board like 16 MHz NRF51_DK, that count_ticks(NUM_OF_CYCLES, 1) takes:
~25 000 us ticker ticks (16 bits / 1 MHz counter)
~820 lp ticker ticks (24 bits / 32 768 Hz counter)
so this should be successfully handled by the regular overflow check which is implemented as follows and already on ticker feature branch:

const uint32_t stop = intf->read();
core_util_critical_section_exit();
/* Handle overflow - overflow protection may not work in this case. */
uint32_t diff = (start <= stop) ? (stop - start) : (uint32_t)(max_count - start + stop + 1);
return (diff);

Please update your local branch.

@0xc0170
Copy link
Contributor

0xc0170 commented Apr 9, 2018

@LMESTM Does the latest comment from @mprse answer your question about overflows? Shall this be closed or rework needed?

@0xc0170
Copy link
Contributor

0xc0170 commented Apr 11, 2018

@LMESTM I am closing this due inactivity. Please reopen if this is still needed (with an update - needs rebase)

@0xc0170 0xc0170 closed this Apr 11, 2018
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

Successfully merging this pull request may close these issues.

7 participants