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

Unify SystemPool and lib/support/Pool #9590

Closed
wants to merge 2 commits into from

Conversation

kghost
Copy link
Contributor

@kghost kghost commented Sep 10, 2021

Problem

We have too many pool implementations

Change overview

Unify the interface of system/SystemPool and lib/support/pool. This PR change the interface of SystemPool to match lib/support/Pool. The pool provides following interface functions:

    T * CreateObject(Args&&... args)
    void ReleaseObject(T * object)
    template <typename Function> bool ForEachActiveObject(Function && function)

And also provides statistics interface:

    void ResetStatistics() {}
    void GetStatistics(Stats::count_t & aNumInUse, Stats::count_t & aHighWatermark) {}

Following features are decoupled from the pool implementation:

  • Reference counter: if the target require this feature, it can derive from lib/core/ReferenceCounted class
  • DeferredRelease: this feature should be orthogonal to pool implementation, the target class should implement it by itself.

Files changes:
Removed

  • src/system/SystemObject.cpp
  • src/system/SystemObject.h

Implementation on platforms with heap (POSIX):

  • src/system/SystemPoolHeap.h

Implementation on platforms w/o heap (Embedded):

  • src/system/SystemPoolNonHeap.h
  • src/system/SystemPoolNonHeapBitmapAllocator.cpp
  • src/system/SystemPoolNonHeapBitmapAllocator.h

Statistics:

  • src/system/SystemPoolStatistics.h

Select implementation based on pre-defined macro

  • src/system/SystemPool.h

Note: this PR depends on #9674 (merged) and #9678

Testing

Verified on posix platform.

Next PR will remove lib/support/Pool and migrate all usage to SystemPool.

@github-actions
Copy link

Size increase report for "gn_qpg-example-build" from 8e86c9e

File Section File VM
chip-qpg6100-lighting-example.out .text 268 268
chip-qpg6100-lighting-example.out .bss 0 16
chip-qpg6100-lighting-example.out .data 8 8
chip-qpg6100-lighting-example.out .heap 0 -24
Full report output
BLOAT REPORT

Files found only in the build output:
    report.csv

Comparing ./master_artifact/chip-qpg6100-lighting-example.out.map and ./pull_artifact/chip-qpg6100-lighting-example.out.map:

BLOAT EXECUTION FAILED WITH CODE 1:
bloaty: unknown file type for file './pull_artifact/chip-qpg6100-lighting-example.out.map'

Comparing ./master_artifact/chip-qpg6100-lighting-example.out and ./pull_artifact/chip-qpg6100-lighting-example.out:

sections,vmsize,filesize
.debug_str,0,5448
.debug_loc,0,1960
.debug_ranges,0,736
.strtab,0,530
.symtab,0,384
.text,268,268
.debug_frame,0,172
.debug_aranges,0,64
.bss,16,0
.data,8,8
.shstrtab,0,2
.heap,-24,0
[Unmapped],0,-268
.debug_abbrev,0,-5606
.debug_line,0,-11604
.debug_info,0,-292854


@github-actions
Copy link

Size increase report for "nrfconnect-example-build" from 8e86c9e

File Section File VM
chip-lock.elf text 168 168
chip-lock.elf bss 0 32
chip-lock.elf init_array 8 8
chip-shell.elf text 172 172
chip-shell.elf bss 0 26
chip-shell.elf init_array 8 8
chip-shell.elf device_handles -4 -4
chip-shell.elf [LOAD #3 [RW]] 0 -26
Full report output
BLOAT REPORT

Files found only in the build output:
    report.csv

Comparing ./master_artifact/chip-lock.elf and ./pull_artifact/chip-lock.elf:

sections,vmsize,filesize
.debug_str,0,5253
.debug_loc,0,1619
.debug_ranges,0,568
.strtab,0,364
.symtab,0,336
text,168,168
.debug_frame,0,128
.debug_aranges,0,48
bss,32,0
init_array,8,8
.debug_abbrev,0,-4318
.debug_line,0,-16361
.debug_info,0,-344185

Comparing ./master_artifact/chip-shell.elf and ./pull_artifact/chip-shell.elf:

sections,vmsize,filesize
.debug_str,0,5246
.debug_loc,0,1814
.debug_ranges,0,568
.strtab,0,364
.symtab,0,336
.debug_abbrev,0,289
text,172,172
.debug_frame,0,128
.debug_aranges,0,48
bss,26,0
init_array,8,8
device_handles,-4,-4
[LOAD #3 [RW]],-26,0
.debug_line,0,-7140
.debug_info,0,-151785


@github-actions
Copy link

Size increase report for "esp32-example-build" from 8e86c9e

File Section File VM
chip-all-clusters-app.elf .dram0.bss 0 648
chip-all-clusters-app.elf .flash.text 412 412
chip-all-clusters-app.elf .iram0.text_end 0 56
chip-all-clusters-app.elf .dram0.heap_start 0 8
chip-all-clusters-app.elf .flash.rodata -16 -16
chip-all-clusters-app.elf .iram0.text -56 -56
Full report output
BLOAT REPORT

Files found only in the build output:
    report.csv

Comparing ./master_artifact/chip-all-clusters-app.elf and ./pull_artifact/chip-all-clusters-app.elf:

sections,vmsize,filesize
.debug_info,0,2837091
.debug_line,0,25222
.debug_abbrev,0,12065
.debug_str,0,6678
[Unmapped],0,3756
.debug_loc,0,1804
.dram0.bss,648,0
.strtab,0,587
.debug_ranges,0,448
.flash.text,412,412
.debug_frame,0,372
.symtab,0,128
.debug_aranges,0,120
.iram0.text_end,56,0
.dram0.heap_start,8,0
.shstrtab,0,1
.flash.rodata,-16,-16
.iram0.text,-56,-56


@msandstedt msandstedt self-requested a review September 16, 2021 13:15
@andy31415
Copy link
Contributor

@kghost - conflicts

@msandstedt msandstedt self-requested a review September 20, 2021 15:23
@msandstedt
Copy link
Contributor

Is this superseded by #9748? It appears that PR already includes most or all of this content.

If so, we should close this or at least mark it for no-merge.

template <typename... Args>
T * CreateObject(Args &&... args)
{
std::lock_guard<std::recursive_mutex> lock(mutex);
Copy link
Contributor

Choose a reason for hiding this comment

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

No, we should not change std::mutex to std::recursive_mutex, we already have consensus before not using recursive_mutex in our SDK, this will hide some problems which is extremely difficult to debug


void ReleaseObject(T * object)
{
std::lock_guard<std::recursive_mutex> lock(mutex);
Copy link
Contributor

@yufengwangca yufengwangca Sep 20, 2021

Choose a reason for hiding this comment

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

We should use std::mutex instead of std::recursive_mutex

@yufengwangca
Copy link
Contributor

Is this superseded by #9748? It appears that PR already includes most or all of this content.

If so, we should close this or at least mark it for no-merge.

Yes, same change is also included in #9748, and there is change request on that PR, we should close this one and proceed with #9748

@stale
Copy link

stale bot commented Sep 27, 2021

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@stale stale bot added the stale Stale issue or PR label Sep 27, 2021
@stale
Copy link

stale bot commented Oct 4, 2021

This stale pull request has been automatically closed. Thank you for your contributions.

@stale stale bot closed this Oct 4, 2021
kpschoedel added a commit to kpschoedel/connectedhomeip that referenced this pull request Nov 11, 2021
#### Problem

We have too many pool allocators.

Previous PRs (project-chip#11428, project-chip#11487) transitionally use `BitMapObjectPool`
where previously `System::ObjectPool` had been used, but this lost
the ability to configure heap allocation.

#### Change overview

- Add a heap allocator (from project-chip#9590)
- Add allocation selection (from project-chip#11371)
- Use this for `System::Timer` (complementing project-chip#11487)

Co-authored-by: Zang MingJie <zealot0630@gmail.com>
Co-authored-by: C Freeman <cecille@google.com>

A future PR will use this for Inet pools (complementing project-chip#11428);
that is not done here because it would conflict with other Inet
changes under way.

#### Testing

CI; no changes to functionality.

CI should show `.bss` decreases corresponding to increases in project-chip#11487.
kpschoedel added a commit to kpschoedel/connectedhomeip that referenced this pull request Nov 11, 2021
#### Problem

We have too many pool allocators.

Previous PRs (project-chip#11428, project-chip#11487) transitionally use `BitMapObjectPool`
where previously `System::ObjectPool` had been used, but this lost
the ability to configure heap allocation.

#### Change overview

- Add a heap allocator (from project-chip#9590)
- Add allocation selection (from project-chip#11371)
- Use this for `System::Timer` (complementing project-chip#11487)

Co-authored-by: Zang MingJie <zealot0630@gmail.com>
Co-authored-by: C Freeman <cecille@google.com>

A future PR will use this for Inet pools (complementing project-chip#11428);
that is not done here because it would conflict with other Inet
changes under way.

#### Testing

Added heap versions of unit tests in TestPool. (A future PR will add
`System::Object`-style statistics and re-unify most of these tests.)

CI should show `.bss` decreases corresponding to increases in project-chip#11487.
kpschoedel added a commit to kpschoedel/connectedhomeip that referenced this pull request Nov 15, 2021
#### Problem

We have too many pool allocators.

Previous PRs (project-chip#11428, project-chip#11487) transitionally use `BitMapObjectPool`
where previously `System::ObjectPool` had been used, but this lost
the ability to configure heap allocation.

#### Change overview

- Add a heap allocator (from project-chip#9590)
- Add allocation selection (from project-chip#11371)
- Use this for `System::Timer` (complementing project-chip#11487)

Co-authored-by: Zang MingJie <zealot0630@gmail.com>
Co-authored-by: C Freeman <cecille@google.com>

A future PR will use this for Inet pools (complementing project-chip#11428);
that is not done here because it would conflict with other Inet
changes under way.

#### Testing

Added heap versions of unit tests in TestPool. (A future PR will add
`System::Object`-style statistics and re-unify most of these tests.)

CI should show `.bss` decreases corresponding to increases in project-chip#11487.
kpschoedel added a commit to kpschoedel/connectedhomeip that referenced this pull request Nov 16, 2021
#### Problem

We have too many pool allocators.

Previous PRs (project-chip#11428, project-chip#11487) transitionally use `BitMapObjectPool`
where previously `System::ObjectPool` had been used, but this lost
the ability to configure heap allocation.

#### Change overview

- Add a heap allocator (from project-chip#9590)
- Add allocation selection (from project-chip#11371)
- Use this for `System::Timer` (complementing project-chip#11487)

Co-authored-by: Zang MingJie <zealot0630@gmail.com>
Co-authored-by: C Freeman <cecille@google.com>

A future PR will use this for Inet pools (complementing project-chip#11428);
that is not done here because it would conflict with other Inet
changes under way.

#### Testing

Added heap versions of unit tests in TestPool. (A future PR will add
`System::Object`-style statistics and re-unify most of these tests.)

CI should show `.bss` decreases corresponding to increases in project-chip#11487.
kpschoedel added a commit to kpschoedel/connectedhomeip that referenced this pull request Nov 16, 2021
#### Problem

We have too many pool allocators.

Previous PRs (project-chip#11428, project-chip#11487) transitionally use `BitMapObjectPool`
where previously `System::ObjectPool` had been used, but this lost
the ability to configure heap allocation.

#### Change overview

- Add a heap allocator (from project-chip#9590)
- Add allocation selection (from project-chip#11371)
- Use this for `System::Timer` (complementing project-chip#11487)

Co-authored-by: Zang MingJie <zealot0630@gmail.com>
Co-authored-by: C Freeman <cecille@google.com>

A future PR will use this for Inet pools (complementing project-chip#11428);
that is not done here because it would conflict with other Inet
changes under way.

#### Testing

Added heap versions of unit tests in TestPool. (A future PR will add
`System::Object`-style statistics and re-unify most of these tests.)

CI should show `.bss` decreases corresponding to increases in project-chip#11487.
kpschoedel added a commit that referenced this pull request Nov 19, 2021
#### Problem

We have too many pool allocators.

Previous PRs (#11428, #11487) transitionally use `BitMapObjectPool`
where previously `System::ObjectPool` had been used, but this lost
the ability to configure heap allocation.

#### Change overview

- Add a heap allocator (from #9590)
- Add allocation selection (from #11371)
- Use this for `System::Timer` (complementing #11487)

- Factor out common code.
- Use a heap-allocated list to track heap-allocated objects.
- More unit tests.

Co-authored-by: Zang MingJie <zealot0630@gmail.com>
Co-authored-by: C Freeman <cecille@google.com>

A future PR will use this for Inet pools (complementing #11428);
that is not done here because it would conflict with other Inet
changes under way.

#### Testing

Added heap versions of unit tests in TestPool. (A future PR will add
`System::Object`-style statistics and re-unify most of these tests.)

CI should show `.bss` decreases corresponding to increases in #11487.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants