Skip to content
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

Heap usage improvements #1355

Merged
merged 8 commits into from Jul 12, 2017

Conversation

@avtolstoy
Copy link
Member

commented Jul 10, 2017

Problem

  1. Photon uses too much heap when connecting to WPA Enterprise access point
  2. When using WPA Enterprise access point and constantly reconnecting to it, heap gets fragmented which results in inability to connect to the access point anymore

Solution

  1. Switched to FreeRTOS heap_4 allocator, as it was confirmed during testing that it performs better than newlib_nano with constant allocations/deallocations under the same initial conditions (Electron/Photon/P1, other platforms still use newlib_nano)
  2. EAP-TLS certificate/key and CA certificate is stored in DER format in DCT, which removes the necessity to convert PEM to DER each time we connect to WPA Enterprise access point and reduces heap usage as DER certificates/keys can be directly loaded from flash

Flash usage

0.7.0-rc.1 Photon (DEBUG_BUILD=n):

   text	   data	    bss	    dec	    hex	filename
 261460	    156	    268	 261884	  3fefc	../../../build/target/system-part1/platform-6-m/system-part1.elf
   text	   data	    bss	    dec	    hex	filename
 252668	   2240	  38464	 293372	  479fc	../../../build/target/system-part2/platform-6-m/system-part2.elf

This branch Photon (DEBUG_BUILD=n):

   text	   data	    bss	    dec	    hex	filename
 261460	    156	    268	 261884	  3fefc	../../../build/target/system-part1/platform-6-m/system-part1.elf
   text	   data	    bss	    dec	    hex	filename
 254780	   2244	  38484	 295508	  48254	../../../build/target/system-part2/platform-6-m/system-part2.elf

0.7.0-rc.1 Electron (DEBUG_BUILD=y):

   text	   data	    bss	    dec	    hex	filename
  54304	    424	   2524	  57252	   dfa4	../../../build/target/system-part1/platform-10-m/system-part1.elf
   text	   data	    bss	    dec	    hex	filename
 124004	    220	    500	 124724	  1e734	../../../build/target/system-part2/platform-10-m/system-part2.elf
   text	   data	    bss	    dec	    hex	filename
 114276	   2548	   3516	 120340	  1d614	../../../build/target/system-part3/platform-10-m/system-part3.elf

This branch Electron (DEBUG_BUILD=y):

   text	   data	    bss	    dec	    hex	filename
  54304	    424	   2524	  57252	   dfa4	../../../build/target/system-part1/platform-10-m/system-part1.elf
   text	   data	    bss	    dec	    hex	filename
 124084	    220	    500	 124804	  1e784	../../../build/target/system-part2/platform-10-m/system-part2.elf
   text	   data	    bss	    dec	    hex	filename
 115012	   2552	   3532	 121096	  1d908	../../../build/target/system-part3/platform-10-m/system-part3.elf

Tests

wiring/no_fixture

Example App

A simple app that reconnects to the wifi access point in a loop and reports heap usage:

#include "application.h"

SYSTEM_MODE(SEMI_AUTOMATIC);
SYSTEM_THREAD(ENABLED);

Serial1LogHandler dbg(115200, LOG_LEVEL_ALL);

/* executes once at startup */
void setup() {
    WiFi.on();
    delay(1000);
    LOG(TRACE, "Free in setup(): %lu", System.freeMemory());
}

static bool wifinotready() {
    return !WiFi.ready();
}

/* executes continuously after setup() runs */
void loop() {
    Particle.connect();
    waitUntil(Particle.connected);
    delay(1000);
    LOG(TRACE, "Free connected %lu", System.freeMemory());
    Particle.publish("test");
    delay(1000);
    WiFi.disconnect();
    waitUntil(wifinotready);
    delay(1000);
    LOG(TRACE, "Free disconnected %lu", System.freeMemory());
}

References

particle-iot/photon-wiced#16


Completeness

  • User is totes amazing for contributing!
  • Contributor has signed CLA (Info here)
  • Problem and Solution clearly stated
  • Run unit/integration/application tests on device
  • Added documentation (N/A)
  • Added to CHANGELOG.md after merging (add links to docs and issues)

Bug fix

  • [PR #1355] When using WPA Enterprise access point and constantly reconnecting to it, heap was becoming fragmented which resulted in inability to connect to the access point anymore. Also reduced overall heap usage.

@technobly technobly added enhancement bug and removed enhancement labels Jul 10, 2017

@avtolstoy avtolstoy added this to the 0.7.0 milestone Jul 11, 2017

@technobly technobly merged commit 5e98687 into develop Jul 12, 2017

0 of 2 checks passed

continuous-integration/travis-ci/push The Travis CI build failed
Details
continuous-integration/travis-ci/pr The Travis CI build is in progress
Details

@technobly technobly deleted the feature/reduced-heap-usage branch Jul 12, 2017

technobly added a commit that referenced this pull request Jul 12, 2017
Merge branch 'develop' into release/v0.7.0-rc.2
 Conflicts:
	hal/src/photon/lib/Supplicant_BESL.a
        used the version from PR #1355
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.