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

Add option to specify stack size to pthread_create #2073

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

sirknightj
Copy link
Contributor

What was changed?

  • See Thread stack sizes #1924 and Default stack size change and Rolling buffer config rework #2011 for the original PRs.
  • Add an option KVS_STACK_SIZE to specify the thread stack size of threads. By default, THREAD_CREATE (defined in PIC, which calls pthread_create), will use the system default settings (ulimit -s). These changes allow the user to set the stack sizes for threads created by the SDK without needing to change system defaults.
  • For backwards compatibility, if the option is not present, the SDK will continue to use the system default stack sizes.
  • Users can also control stack size for individual threads by using THREAD_CREATE_WITH_PARAMS API instead of THREAD_CREATE. (Added in PIC#243)

Why was it changed?

  • Reduce unused stack memory (virtual memory).

How was it changed?

  • KVS_STACK_SIZE option will get passed to kvsCommonLws (Producer-C), who forwards it to PIC, which contains the thread creation definitions.

What testing was done for the changes?

  • See the original pull requests for more details.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

jdelapla and others added 3 commits October 29, 2024 12:57
* Working reduced stack sizes. Adjusted default stack size to 64kb, moved Offer/Answer messages to be on heap instead of stack

* Custom stack sizes in Common.c

* CMake flag working and added to README

* Adjust connection listener stack size for datachannels

* Change stack size for media related threads and connection listener again. Add README notes to highlight this potential problem threads for other applications

* Unnecessary memset

* nit picks

* Update CMakeLists.txt

fix for ZLIB since it is not found on Windows, that way we can verify the stack side change on Windows platform, previously it was not running at all due to build fail.

* Update CMake dependency back to develop since the other PRs have merged

* README update

---------

Co-authored-by: Hassan Sahibzada <[email protected]>
Co-authored-by: Divya Sampath Kumar <[email protected]>
@@ -52,6 +52,15 @@ execute_process(
add_definitions(-DSDK_VERSION=\"${GIT_COMMIT_HASH}\")
add_definitions(-DVERSION_STRING=\"${PROJECT_VERSION}\")
add_definitions(-DDETECTED_GIT_HASH)
if(NOT KVS_STACK_SIZE OR KVS_STACK_SIZE STREQUAL "")
Copy link
Contributor

Choose a reason for hiding this comment

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

Rather than checking for an empty string, can we validate that it is a numeric value with something like:

if(KVS_STACK_SIZE MATCHES "^[+-]?[0-9]+$")

Copy link
Contributor Author

@sirknightj sirknightj Nov 8, 2024

Choose a reason for hiding this comment

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

I'm thinking of removing this section actually. Because when I ran Producer-C with the thread stacksize changes, I was able to pass it in via producer-c's CMake command:

Producer-C/build $ cmake .. -DBUILD_DEPENDENCIES=OFF -DKVS_DEFAULT_STACK_SIZE= 524288 -DCONSTRAINED_DEVICE=ON
...
CMake Error at dependency/libkvspic/kvspic-src/CMakeLists.txt:62 (message):
  Conflicting parameters: KVS_DEFAULT_STACK_SIZE and CONSTRAINED_DEVICE
  cannot both be set.

-- Configuring incomplete, errors occurred!

Which would indicate this section is redundant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants