Building with GCC - success!

News, Setup, Compiling, Flashing, Development

Re: Building with GCC - success!

Postby wangyeee » Mon Apr 11, 2016 5:03 am

Hi Max,

The changes are here:
https://github.com/wangyeee/aq_flight_c ... b60185aff6

I've increase size of the three stacks:
COMM_STACK_SIZE 336 -> 768
DIMU_STACK_SIZE 248 -> 384
FILER_STACK_SIZE 200 -> 256

I didn't increase stack size of supervisor as I have successfully saved dimu calib data before.

If the widest member of a struct is 4 bytes (pointers/floats/32b ints only, no doubles), can we use 4-byte alignment or does that not make any difference?


I'd like to check struct size and try 4 bytes alignment as it should save some RAM.

I seem to recall that GCC-ARM also had some way to deal with this (exclude the "long" versions if one doesn't need them, since they take up flash space), but I don't remember the details now.


"-u _scanf_float -u _printf_float" is passed to linker in the makefile. Is this what you mean? By default float io is disabled in gcc, and hopefully gcc could automatically detect float io and enable it in the future.
https://blueprints.launchpad.net/gcc-ar ... oat-printf

Regards,
Ye
wangyeee
 
Posts: 37
Joined: Sun Feb 22, 2015 5:20 am

Re: Building with GCC - success!

Postby wangyeee » Mon Apr 11, 2016 5:05 am

rput wrote:No expert on this, but can you do something with pragma?

http://infocenter.arm.com/help/index.js ... FEEDG.html


Yes, I'm using "aligned" attribute of gcc:
https://github.com/wangyeee/aq_flight_c ... c/aq.h#L91

Regards,
Ye
wangyeee
 
Posts: 37
Joined: Sun Feb 22, 2015 5:20 am

Re: Building with GCC - success!

Postby Max » Mon Apr 11, 2016 5:32 am

Hi Ye,

wangyeee wrote:COMM_STACK_SIZE 336 -> 768
DIMU_STACK_SIZE 248 -> 384
FILER_STACK_SIZE 200 -> 256


That's quite a bit... especially the first two. The COMM stack has always been a "problem" since it may use resources from many different places in the code. That's a huge jump though. Is there a point when it takes a big hit, eg. when requesting params save via Mavlink (QGC)?

Do you know if the RAM increase is mostly due to the printf/scanf being so much less efficient, or the new struct aligned(8) strategy? Or some of both maybe?

wangyeee wrote:"-u _scanf_float -u _printf_float" is passed to linker in the makefile. Is this what you mean?

Yep, that was it.

I'm attaching a batch file which runs a version of the ELF memory report from the Makefile but on any AQ .elf. Maybe it'll be useful for comparing builds or something. You'll need to edit the first two lines to point to your GCC 'size' and GNU 'gawk' executables (gawk from cygwin works well, some others don't).

Best,
-Max
Attachments
elf-memory-report.bat
The first two lines of this script will need to be edited to suit your environment.
(1.88 KiB) Downloaded 131 times
Max
 
Posts: 2814
Joined: Mon Aug 13, 2012 9:45 pm
Location: Near Ithaca, NY, USA

Re: Building with GCC - success!

Postby wangyeee » Mon Apr 11, 2016 8:27 am

Hi Max,

Thanks for your script, I'll try it later.

I think printf/scanf contributes most part of the problem. The code stops crashing after I increase stack size, but it doesn't produce expected outputs until I apply the aligned(8) fix.

Another thing I'd like to try it to move params io to another low priority task, which only gets executed when it's requested to read/write params. In this case, the stack of other tasks can be reduced.

Regards,
Ye
wangyeee
 
Posts: 37
Joined: Sun Feb 22, 2015 5:20 am

Re: Building with GCC - success!

Postby wangyeee » Thu Apr 14, 2016 3:42 pm

Quick Update:
I tried to apply aligned(4) for structs with no 64 bit member, e.g. long long and double. Then printf starts to generate rubbish info in sd card. So I'll keep 8 bytes alignment for now.
wangyeee
 
Posts: 37
Joined: Sun Feb 22, 2015 5:20 am

Re: Building with GCC - success!

Postby Max » Thu Apr 14, 2016 5:46 pm

Ye, try with

Code: Select all
 __attribute__((aligned))


I'm merging some changes together and ran into the misalignment/printf() issue again. This time I even knew the exact new code which was causing the problem, but my usual methods of aligning the structs manually didn't work. Thanks to your hints, __attribute__((aligned)) saved the day (aligned(8) also worked but aligned(4) didn't). I've gone through and added this to most/all data structs in CCM. There is no difference at all in RAM usage. If this solves the problem forever, I'm very happy indeed.

I'm about to push a slew of changes to the repo, including re-alignment of all the structs and some stack size changes, etc. This should probably become the new baseline. I'll update here when it's up.

Cheers,
-Max
Max
 
Posts: 2814
Joined: Mon Aug 13, 2012 9:45 pm
Location: Near Ithaca, NY, USA

Re: Building with GCC - success!

Postby Max » Thu Apr 14, 2016 9:39 pm

OK, many updates.... https://github.com/mpaperno/aq_flight_c ... ntegration

"feature_integration" branch has everything so far combined together. There are also separate standalone branches for some of the changes. Summary: https://github.com/mpaperno/aq_flight_c ... CHANGES.md

Ye, the memory changes are also in their own branch, possibly a bit clearer for review: https://github.com/mpaperno/aq_flight_c ... ory_manage (but please make changes against the feature_integration branch.)

Cheers,
-Max
Max
 
Posts: 2814
Joined: Mon Aug 13, 2012 9:45 pm
Location: Near Ithaca, NY, USA

Re: Building with GCC - success!

Postby wangyeee » Fri Apr 15, 2016 3:39 am

Wow, that's huge amount of work. I'll go through those changes and puts my $0.01 there :D

Regards,
Ye
wangyeee
 
Posts: 37
Joined: Sun Feb 22, 2015 5:20 am

Re: Building with GCC - success!

Postby Max » Fri Apr 15, 2016 4:05 am

It does look like a lot, but hopefully mostly because I broke it down into many smaller pieces... ;)

BTW, I implemented the idea of having all the config param reads/write requests funneled through one thread -- supervisor. It's low-priority, and was already calling most of those routines anyway (eg. when using stick commands to save params). This reduces required COMM stack space quite a bit. I did add some space to SUPERVISOR stack, just in case, but it's not really required.

Anyway, the relevant commit is here: https://github.com/mpaperno/aq_flight_c ... 0cb0dc2dae

-Max
Max
 
Posts: 2814
Joined: Mon Aug 13, 2012 9:45 pm
Location: Near Ithaca, NY, USA

Re: Building with GCC - success!

Postby fly_boy » Sun Jul 24, 2016 1:27 pm

that is a good news, great job!
fly_boy
 
Posts: 2
Joined: Sat Jul 23, 2016 3:29 pm

PreviousNext

Return to AQ Firmware

Who is online

Users browsing this forum: No registered users and 1 guest

cron