Skip to content

pkg/libfixmath: several improvements and 8bit fix#12687

Merged
aabadie merged 7 commits intoRIOT-OS:masterfrom
aabadie:pr/pkg/libfixmath_update
Nov 21, 2019
Merged

pkg/libfixmath: several improvements and 8bit fix#12687
aabadie merged 7 commits intoRIOT-OS:masterfrom
aabadie:pr/pkg/libfixmath_update

Conversation

@aabadie
Copy link
Copy Markdown
Contributor

@aabadie aabadie commented Nov 11, 2019

Contribution description

This PR is providing several improvements to the libfixmath package:

  • Rework of the build system integration: this simplifies the maintenance of the package and removes the need to patch some Makefiles directly
  • Reorganize the patches, because of the previous point
  • Define the FIXMATH_OPTIMIZE_8BIT CFLAGS when building for 8bit architectures. This single change fixes the libfixmath test on Atmega
  • Rename the tests/libfixmath_* application in tests/pkg_libfixmath_* to make it consistent with other pkg test applications. Because of this change, some pep8 issues were raised by the static test which are also fixed by this PR.
  • Use FEATURES_BLACKLIST at package level for unittests: 8bit and msp430 architectures are blacklisted and this allows to get rid of the BOARD_BLACKLIST variable in the unittests test application

Testing procedure

  • All the following commands should work:
$ make -C tests/pkg_libfixmath all test
$ make BOARD=atmega256rfr2-xpro -C tests/pkg_libfixmath flash test
  • boards with 8bit and msp430 based architectures are correctly blacklisted from the tests/pkg_libfixmath_unittests application:
$ BUILD_IN_DOCKER=1 make --no-print-directory BOARD=z1 -C tests/pkg_libfixmath_unittests/
Some feature requirements are blacklisted: arch_msp430
/work/riot/RIOT/tests/pkg_libfixmath_unittests/../../Makefile.include:818: *** You can let the build continue on expected errors by setting CONTINUE_ON_EXPECTED_ERRORS=1 to the command line.  Stop.
$ BUILD_IN_DOCKER=1 make --no-print-directory BOARD=atmega256rfr2-xpro -C tests/pkg_libfixmath_unittests/
Some feature requirements are blacklisted: arch_8bit
/work/riot/RIOT/tests/pkg_libfixmath_unittests/../../Makefile.include:818: *** You can let the build continue on expected errors by setting CONTINUE_ON_EXPECTED_ERRORS=1 to the command line.  Stop.
  • Compare the list of boards supported by tests/pkg_libfixmath_unittests between master and this PR (from BUILD_IN_DOCKER=1 make --no-print-directory -C tests/pkg_libfixmath_unittests/ info-boards-supported):
this PR
acd52832 airfy-beacon arduino-due arduino-mkr1000 arduino-mkrfox1200 arduino-mkrwan1300 arduino-mkrzero arduino-zero avsextrem b-l072z-lrwan1 b-l475e-iot01a blackpill blackpill-128kib bluepill bluepill-128kib calliope-mini cc1352-launchpad cc2538dk cc2650-launchpad cc2650stk ek-lm4f120xl esp32-mh-et-live-minikit esp32-olimex-evb esp32-wemos-lolin-d32-pro esp32-wroom-32 esp32-wrover-kit esp8266-esp-12x esp8266-olimex-mod esp8266-sparkfun-thing f4vi1 feather-m0 firefly fox frdm-k22f frdm-k64f frdm-kw41z hamilton hifive1 hifive1b i-nucleo-lrwan1 ikea-tradfri iotlab-a8-m3 iotlab-m3 limifrog-v1 lobaro-lorabox lsn50 maple-mini mbed_lpc1768 microbit msba2 msbiot mulle native nrf51dk nrf51dongle nrf52832-mdk nrf52840-mdk nrf52840dk nrf52dk nrf6310 nucleo-f030r8 nucleo-f031k6 nucleo-f042k6 nucleo-f070rb nucleo-f072rb nucleo-f091rc nucleo-f103rb nucleo-f207zg nucleo-f302r8 nucleo-f303k8 nucleo-f303re nucleo-f303ze nucleo-f334r8 nucleo-f401re nucleo-f410rb nucleo-f411re nucleo-f412zg nucleo-f413zh nucleo-f429zi nucleo-f446re nucleo-f446ze nucleo-f722ze nucleo-f746zg nucleo-f767zi nucleo-l031k6 nucleo-l053r8 nucleo-l073rz nucleo-l152re nucleo-l432kc nucleo-l433rc nucleo-l452re nucleo-l476rg nucleo-l496zg nucleo-l4r5zi nz32-sc151 opencm904 openmote-b openmote-cc2538 p-l496g-cell02 particle-argon particle-boron particle-xenon pba-d-01-kw2x phynode-kw41z pic32-clicker pic32-wifire pyboard reel remote-pa remote-reva remote-revb ruuvitag samd21-xpro same54-xpro saml10-xpro saml11-xpro saml21-xpro samr21-xpro samr30-xpro samr34-xpro seeeduino_arch-pro sensebox_samd21 slstk3401a slstk3402a sltb001a slwstk6000b-slwrb4150a slwstk6000b-slwrb4162a slwstk6220a sodaq-autonomo sodaq-explorer sodaq-one sodaq-sara-aff spark-core stk3600 stk3700 stm32f030f4-demo stm32f0discovery stm32f3discovery stm32f429i-disc1 stm32f4discovery stm32f723e-disco stm32f769i-disco stm32l0538-disco stm32l476g-disco teensy31 thingy52 ublox-c030-u201 udoo usb-kw41z yunjia-nrf51822
master
acd52832 airfy-beacon arduino-due arduino-mkr1000 arduino-mkrfox1200 arduino-mkrwan1300 arduino-mkrzero arduino-zero avsextrem b-l072z-lrwan1 b-l475e-iot01a blackpill blackpill-128kib bluepill bluepill-128kib calliope-mini cc1352-launchpad cc2538dk cc2650-launchpad cc2650stk ek-lm4f120xl esp32-mh-et-live-minikit esp32-olimex-evb esp32-wemos-lolin-d32-pro esp32-wroom-32 esp32-wrover-kit esp8266-esp-12x esp8266-olimex-mod esp8266-sparkfun-thing f4vi1 feather-m0 firefly fox frdm-k22f frdm-k64f frdm-kw41z hamilton hifive1 hifive1b i-nucleo-lrwan1 ikea-tradfri iotlab-a8-m3 iotlab-m3 limifrog-v1 lobaro-lorabox lsn50 maple-mini mbed_lpc1768 microbit msba2 msbiot mulle native nrf51dk nrf51dongle nrf52832-mdk nrf52840-mdk nrf52840dk nrf52dk nrf6310 nucleo-f030r8 nucleo-f031k6 nucleo-f042k6 nucleo-f070rb nucleo-f072rb nucleo-f091rc nucleo-f103rb nucleo-f207zg nucleo-f302r8 nucleo-f303k8 nucleo-f303re nucleo-f303ze nucleo-f334r8 nucleo-f401re nucleo-f410rb nucleo-f411re nucleo-f412zg nucleo-f413zh nucleo-f429zi nucleo-f446re nucleo-f446ze nucleo-f722ze nucleo-f746zg nucleo-f767zi nucleo-l031k6 nucleo-l053r8 nucleo-l073rz nucleo-l152re nucleo-l432kc nucleo-l433rc nucleo-l452re nucleo-l476rg nucleo-l496zg nucleo-l4r5zi nz32-sc151 opencm904 openmote-b openmote-cc2538 p-l496g-cell02 particle-argon particle-boron particle-xenon pba-d-01-kw2x phynode-kw41z pic32-clicker pic32-wifire pyboard reel remote-pa remote-reva remote-revb ruuvitag samd21-xpro same54-xpro saml10-xpro saml11-xpro saml21-xpro samr21-xpro samr30-xpro samr34-xpro seeeduino_arch-pro sensebox_samd21 slstk3401a slstk3402a sltb001a slwstk6000b-slwrb4150a slwstk6000b-slwrb4162a slwstk6220a sodaq-autonomo sodaq-explorer sodaq-one sodaq-sara-aff spark-core stk3600 stk3700 stm32f030f4-demo stm32f0discovery stm32f3discovery stm32f429i-disc1 stm32f4discovery stm32f723e-disco stm32f769i-disco stm32l0538-disco stm32l476g-disco teensy31 thingy52 ublox-c030-u201 udoo usb-kw41z yunjia-nrf51822
diff

Issues/PRs references

Tick the libfixmath item in #12651

@aabadie aabadie added Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation Area: tests Area: tests and testing framework Area: pkg Area: External package ports CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR CI: run tests If set, CI server will run tests on hardware for the labeled PR labels Nov 11, 2019
@aabadie aabadie requested review from fjmolinas and maribu November 11, 2019 15:29
@maribu
Copy link
Copy Markdown
Member

maribu commented Nov 11, 2019

* Define the `FIXMATH_OPTIMIZE_8BIT` CFLAGS when building for 8bit architectures. This single change fixes the libfixmath test on Atmega

You still blacklisted the package on 8bit platforms. Unless I miss something, this should no longer be needed due to this fix, right?

@aabadie
Copy link
Copy Markdown
Contributor Author

aabadie commented Nov 11, 2019

You still blacklisted the package on 8bit platforms. Unless I miss something, this should no longer be needed due to this fix, right?

Only the unittests part is blacklisted. The rest is working...

@maribu maribu added Reviewed: 1-fundamentals The fundamentals of the PR were reviewed according to the maintainer guidelines Reviewed: 2-code-design The code design of the PR was reviewed according to the maintainer guidelines Reviewed: 4-code-style The adherence to coding conventions by the PR were reviewed according to the maintainer guidelines Reviewed: 5-documentation The documentation details of the PR were reviewed according to the maintainer guidelines labels Nov 14, 2019
@maribu
Copy link
Copy Markdown
Member

maribu commented Nov 14, 2019

OK, on an ATmega328p clocked at 8MHz I get

Timeout in expect script at "child.expect_exact('SUCCESS')" (tests/pkg_libfixmath/tests/01-run.py:39)

Could you double the timeout for this test in an additional commit to allow it to pass on slow MCUs?

@aabadie
Copy link
Copy Markdown
Contributor Author

aabadie commented Nov 14, 2019

Could you double the timeout for this test in an additional commit to allow it to pass on slow MCUs?

Sure, can you tell me a suitable value ? I think I don't have an ATmega clocked at 8MHz (well, this can be changed with fuses but I'm lazy and I don't have the time today ;) ).

@maribu
Copy link
Copy Markdown
Member

maribu commented Nov 14, 2019

The ATmegas all have the same IPC. So when it worked for time x on 16MHz, it will work with
2x on 8MHz. (I don't know what the current value is, but just doubling it should work.)

except Exception as exc:
errors += 1
print('ERROR {}'.format(line))
print('ERROR: {}: {}'.format(line, exc))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The commit message states "tests/pkg_libfixmath: fix PEP8 issues". Its unclear to me which PEP8 issue is fixed by this line (comment originally made in #12706 (comment)).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The issue was: E722 "bare except". So the fix is to use:

    except Exception as exc:

And make use of it in the error message. In the end, it improves the message: you know it's an error, you get the line and you get the complete exception message.

Copy link
Copy Markdown
Contributor Author

@aabadie aabadie Nov 14, 2019

Choose a reason for hiding this comment

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

I think the commit message should be "tests/pkg_libfixmath: fix flake8 issues"

Copy link
Copy Markdown
Contributor

@fjmolinas fjmolinas left a comment

Choose a reason for hiding this comment

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

The timeout issue is because of improper ranges. Here are the correct ones, this should fix @maribu issue.

But to be honest this test takes way too long on slow cpu, on native it is fast on any other cpu it is ridiculous how long it takes, It should probably change the test range according to the cpu speed or just use a smaller test set if non-native.

@fjmolinas
Copy link
Copy Markdown
Contributor

But to be honest this test takes way too long on slow cpu, on native it is fast on any other cpu it is ridiculous how long it takes, It should probably change the test range according to the cpu speed or just use a smaller test set if non-native.

9m54.386s on arduino-uno, I'm guessing it should take @maribu atmega328p twice as long?

@maribu
Copy link
Copy Markdown
Member

maribu commented Nov 14, 2019

9m54.386s on arduino-uno, I'm guessing it should take @maribu atmega328p twice as long?

Correct. When running at 8MHz (using the internal oscillator) it should be exactly twice as long. But I like the idea of reducing the number of calculations done to speed up the test (at least for non-native) targets.

@aabadie
Copy link
Copy Markdown
Contributor Author

aabadie commented Nov 14, 2019

Ok, I see there are even more problems than the ones already spotted by this PR. I'll change the test as you suggest (reducing the range for non native board + use precise number of printed calculations).
Is it ok for you @maribu and @fjmolinas ?

@aabadie
Copy link
Copy Markdown
Contributor Author

aabadie commented Nov 14, 2019

I went ahead and reworked a bit the test application and script. It should be a little faster now on boards that are not native due to a reduced number of iterations for each sub-tests. On native, the number of iterations of each sub-test is still the same.
I only tested the change on native and both cases (full iterations/reduced number of iterations) are working. I have no idea of the time it saves on other platforms (no hw with me ATM).

@aabadie aabadie force-pushed the pr/pkg/libfixmath_update branch 2 times, most recently from 9b18ceb to 42ac3a8 Compare November 14, 2019 21:17
@aabadie
Copy link
Copy Markdown
Contributor Author

aabadie commented Nov 15, 2019

Made some tests on real hardware: the last version of the test is much faster now.

Using

time make --no-print-directory BOARD=<board> -C tests/pkg_libfixmath flash test

I get the following results (only keep the time results):

arduino-uno
real	1m46,583s
user	0m2,999s
sys	0m0,610s
atmeg256rfr2-xpro
real	0m22,941s
user	0m1,012s
sys	0m0,157s
samr21-xpro
real	0m25,662s
user	0m11,434s
sys	0m1,125s
nucleo-l073rz
real	0m25,808s
user	0m8,803s
sys	0m1,273s

With the previous version (of this PR but without the last commit):

arduino-uno
Timeout in expect script at "child.expect_exact('SUCCESS')" (tests/pkg_libfixmath/tests/01-run.py:39)

make: *** [/work/riot/RIOT/tests/pkg_libfixmath/../../Makefile.include:703: test] Error 1

real	9m48,111s
user	0m7,494s
sys	0m1,453s
atmeg256rfr2-xpro
real	1m50,206s
user	0m5,585s
sys	0m1,245s
samr21-xpro
real	0m56,285s
user	0m2,796s
sys	0m0,632s

arduino-uno and atmega256rfr2-xpro are both clocked at 16MHz but there is a huge difference between the results. My guess is because the baudrates used for stdio are different: 9600 for arduino-uno, 115200 for the atmega256rfr2 and this makes a huge difference in speed since a lot of data is printed to stdout.

@fjmolinas
Copy link
Copy Markdown
Contributor

@aabadie I think you arduino-uno test results are wrong, or flipped, I got ~1:50 when testing with the latest commit.

@aabadie
Copy link
Copy Markdown
Contributor Author

aabadie commented Nov 15, 2019

I got ~1:50 when testing with the latest commit.

Indeed, results are now at the right place ;)

@fjmolinas
Copy link
Copy Markdown
Contributor

@aabadie needs rebasing.

@aabadie aabadie force-pushed the pr/pkg/libfixmath_update branch from 42ac3a8 to dc37170 Compare November 20, 2019 13:57
@aabadie
Copy link
Copy Markdown
Contributor Author

aabadie commented Nov 20, 2019

rebased

@fjmolinas
Copy link
Copy Markdown
Contributor

This PR is good for me now @maribu can you confirm it works on your slow hw?

@maribu
Copy link
Copy Markdown
Member

maribu commented Nov 20, 2019

This PR is good for me now @maribu can you confirm it works on your slow hw?

Yep. Works now like a charm!

@aabadie: Another merge conflict has popped up.

8bit architectures are not compatible. round function is not provided by
the msp430 toolchain.
The implementation of libfixmath is not compatible with architecture smaller than 32bit
Use pkg_ prefix to have a consistent name with other pkg tests applications
Print the range of iterations for each subtests and catch the value in the Python script. The number of iterations is reduced on boards that are not native, this is because this test takes a lot of time on slow platforms
@aabadie aabadie force-pushed the pr/pkg/libfixmath_update branch from dc37170 to 07f7ac5 Compare November 20, 2019 21:28
@aabadie
Copy link
Copy Markdown
Contributor Author

aabadie commented Nov 20, 2019

Another merge conflict has popped up.

Too much AVR boards merged ;) Fixed!

@maribu maribu added the Reviewed: 3-testing The PR was tested according to the maintainer guidelines label Nov 20, 2019
Copy link
Copy Markdown
Member

@maribu maribu left a comment

Choose a reason for hiding this comment

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

ACK. (One suggestion, but feel free to ignore. Feel also free to squash it right in, if you take it.)

Comment on lines +63 to +71
#ifdef BOARD_NATIVE
fix16_t _min = fix16_from_dbl(-5.0);
fix16_t _max = fix16_from_dbl(5.0);
fix16_t _step = fix16_from_dbl(0.25);
#else
fix16_t _min = fix16_from_dbl(-2.0);
fix16_t _max = fix16_from_dbl(2.0);
fix16_t _step = fix16_from_dbl(0.25);
#endif
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The new IS_USED() feature could be used here. (But I'm not insisting.)

const double _range = (IS_USED(BOARD_NATIVE)) ? 5.0 : 2.0;
fix16_t _min = fix16_from_dbl(- _range);
fix16_t _max = fix16_from_dbl(_range);
fix16_t _step = fix16_from_dbl(0.25);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Indeed. But for macros directly related to the target board, I think IS_USED() is not really helpful since the build on Murdock will cover all the cases.

Copy link
Copy Markdown
Contributor

@fjmolinas fjmolinas left a comment

Choose a reason for hiding this comment

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

ACK

@fjmolinas fjmolinas added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR CI: run tests If set, CI server will run tests on hardware 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 CI: run tests If set, CI server will run tests on hardware for the labeled PR labels Nov 21, 2019
@fjmolinas
Copy link
Copy Markdown
Contributor

@aabadie if you wont address @maribu last comment press the merge button :)

@aabadie aabadie merged commit 8f90da6 into RIOT-OS:master Nov 21, 2019
@aabadie aabadie deleted the pr/pkg/libfixmath_update branch November 21, 2019 08:55
@aabadie
Copy link
Copy Markdown
Contributor Author

aabadie commented Nov 21, 2019

Thanks @maribu and @fjmolinas for reviewing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: pkg Area: External package ports Area: tests Area: tests and testing framework CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR CI: run tests If set, CI server will run tests on hardware for the labeled PR Reviewed: 1-fundamentals The fundamentals of the PR were reviewed according to the maintainer guidelines Reviewed: 2-code-design The code design of the PR was reviewed according to the maintainer guidelines Reviewed: 3-testing The PR was tested according to the maintainer guidelines Reviewed: 4-code-style The adherence to coding conventions by the PR were reviewed according to the maintainer guidelines Reviewed: 5-documentation The documentation details of the PR were reviewed according to the maintainer guidelines Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants