WIP: Local Pool Refactoring #239

Closed
muellerr wants to merge 0 commits from KSat:mueller/LocalPoolRefactoring into master
Owner

The current local pool implementation is still very similar to C code.
There are a lot of features in C++ which would make the handling a little bit more intuitive. Furthermore, the number of pool sizes does not really have to be a template.

I experimented with the local pool a long time ago (also to experiment whether C++ containers can be used instead of raw C arrays) and picked up on that again when I added a few features which could also be useful. I think the result is worth the effort and worth a pull request.

The pool is now configured by providing a reference to a multiset which contains pairs. The first value of a pair is the number of elements on a page and the second value is the size of the page. This logically groups data that belong together. Furthermore, being a multiset, the entries are sorted automatically by page size (custom comparator provided). Lastly, the number of pools can be derived by the number of pairs contained inside that multiset automatically. The pool containers itself are now vectors or nested vectors.

A big advantage is that no special destructor is necessary. Also, if i see correctly, no pointers are used anymore, so a pool can propably even be copied without providing custom (move) constructors (although I am not sure where this would be needed..)

Example (because this is also an API change unfortunately):

Old pool config:

	    const uint8_t numberOfIpcPools = 4;
	    uint16_t numberOfElements[numberOfIpcPools] = {100, 30, 20, 10};
	    uint16_t sizeofElements[numberOfIpcPools] = {32, 64, 128, 265};
	    new PoolManager<numberOfIpcPools>(objects::IPC_STORE,sizeofElements,
	            numberOfElements);

New pool config:

	/* Pool manager handles storage und mutexes */
	const LocalPool::LocalPoolConfig poolConfig = {
			{100, 32}, {30, 64}, {20, 128}, {10, 265}
	};
	new PoolManager(objects::IPC_STORE, poolConfig);
	new PoolManager(objects::TM_STORE, poolConfig);
	new PoolManager(objects::TC_STORE, poolConfig);

I also added a few helper functions:

  1. getFillCount: Writes the fill count of each page and a median of the fill counts of each page in percent to a buffer.
  2. clearPage : Clear a specific page of the pool
  3. getTotalSize: Calculates the full size allocated for the store itself and also calculates the size of the sizes container optionally.

Pool Manager:

1 lockMutex: Can be used by developer if lock needs to persist beyond a function call
2. unlockMutex: Complement

All changes were unit tested. I also tested it in our current mission code in general.
Unfortunately, unit tests don't exist yet for the EventManager and the PacketMatcher which use the pool too, but the test coverage of the unit tests is very high in any case. This also requires the new FSFWConfig.h file with the define FSFW_DEBUGGING defined.

This is an API change (small though for developers). It would propbly be good to merge this after the first official release of the FSFW.

The current local pool implementation is still very similar to C code. There are a lot of features in C++ which would make the handling a little bit more intuitive. Furthermore, the number of pool sizes does not really have to be a template. I experimented with the local pool a long time ago (also to experiment whether C++ containers can be used instead of raw C arrays) and picked up on that again when I added a few features which could also be useful. I think the result is worth the effort and worth a pull request. The pool is now configured by providing a reference to a multiset which contains pairs. The first value of a pair is the number of elements on a page and the second value is the size of the page. This logically groups data that belong together. Furthermore, being a multiset, the entries are sorted automatically by page size (custom comparator provided). Lastly, the number of pools can be derived by the number of pairs contained inside that multiset automatically. The pool containers itself are now vectors or nested vectors. A big advantage is that no special destructor is necessary. Also, if i see correctly, no pointers are used anymore, so a pool can propably even be copied without providing custom (move) constructors (although I am not sure where this would be needed..) Example (because this is also an API change unfortunately): Old pool config: ```cpp const uint8_t numberOfIpcPools = 4; uint16_t numberOfElements[numberOfIpcPools] = {100, 30, 20, 10}; uint16_t sizeofElements[numberOfIpcPools] = {32, 64, 128, 265}; new PoolManager<numberOfIpcPools>(objects::IPC_STORE,sizeofElements, numberOfElements); ``` New pool config: ```cpp /* Pool manager handles storage und mutexes */ const LocalPool::LocalPoolConfig poolConfig = { {100, 32}, {30, 64}, {20, 128}, {10, 265} }; new PoolManager(objects::IPC_STORE, poolConfig); new PoolManager(objects::TM_STORE, poolConfig); new PoolManager(objects::TC_STORE, poolConfig); ``` I also added a few helper functions: 1. `getFillCount`: Writes the fill count of each page and a median of the fill counts of each page in percent to a buffer. 2. `clearPage` : Clear a specific page of the pool 3. `getTotalSize`: Calculates the full size allocated for the store itself and also calculates the size of the sizes container optionally. Pool Manager: 1 `lockMutex`: Can be used by developer if lock needs to persist beyond a function call 2. `unlockMutex`: Complement All changes were unit tested. I also tested it in our current mission code in general. Unfortunately, unit tests don't exist yet for the EventManager and the PacketMatcher which use the pool too, but the test coverage of the unit tests is very high in any case. This also requires the new `FSFWConfig.h` file with the define `FSFW_DEBUGGING` defined. This is an API change (small though for developers). It would propbly be good to merge this after the first official release of the FSFW.
muellerr added the
feature
label 2020-10-15 14:07:18 +02:00
muellerr added the
API Change
label 2020-10-15 14:09:43 +02:00
Author
Owner

UPDATE: I will change this request to be merged into the new development branch

UPDATE: I will change this request to be merged into the new development branch
muellerr changed title from Local Pool Refactoring to WIP: Local Pool Refactoring 2020-11-10 20:05:26 +01:00
Author
Owner

second update: I will include unit tests written as well.

second update: I will include unit tests written as well.
Author
Owner

target into devel

target into devel
muellerr closed this pull request 2020-12-01 13:53:02 +01:00

Pull request closed

Sign in to join this conversation.
No description provided.