Local Pool Refactoring #275

Merged
gaisser merged 19 commits from KSat/fsfw:mueller/LocalPoolRefactoring into development 2020-12-10 17:21:27 +01:00
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
API Change
labels 2020-12-01 13:54:52 +01:00
muellerr added a new dependency 2020-12-01 13:59:05 +01:00
gaisser added this to the ASTP 1.0.0 Local pools milestone 2020-12-01 14:44:28 +01:00
muellerr added 1 commit 2020-12-10 16:54:27 +01:00
muellerr added 1 commit 2020-12-10 17:09:46 +01:00
muellerr added 1 commit 2020-12-10 17:12:06 +01:00
gaisser merged commit 5577eb893f into development 2020-12-10 17:21:27 +01:00
gaisser deleted branch mueller/LocalPoolRefactoring 2020-12-10 17:21:31 +01:00
Sign in to join this conversation.
No description provided.