-
Notifications
You must be signed in to change notification settings - Fork 224
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
OS_API_Init() failure due to 0 stack size #525
Comments
Related to #508. Both console and timebase: osal/src/os/posix/src/os-impl-timebase.c Line 351 in 33471c7
osal/src/os/posix/src/os-impl-console.c Lines 132 to 133 in 33471c7
|
I will look into this..... Not clear why this didn't show up when testing #506. |
Might have to rethink the previous change which removed the stack size tweaking .... Reviewing the manpage of
So while I still think we should NOT be accepting zero as a stack size, probably cannot just pass a nonzero value straight through due to the additional requirements of pthread stack size. |
Yeah, I don't follow why it didn't show up either. Just rebuilt the unit tests and was digging in a bit but no answer yet. A bit concerning... |
I have an explanation, actually... The reason the previous testing missed this is because we run everything as non-root using the "permissive" mode setting when running CI, as well as myself with my own local testing. Only when running as "root" in a dedicated VM does the error show up. Enhanced CI should include this mode of operation.... |
The stack size setting code is actually in the same block as the scheduling policy setting. So if you run as non-root with permissive mode, it skips setting the stack size too (which might itself be a different bug - seems like stack size should still be applicable even if non-root). |
Wouldn't be that hard to add one non-permissive test to the matrix in travis also. |
Actually doesn't really need to change the matrix - technically do not need to rebuild without Clearly, the admins of Travis CI has not granted random users this permission (understandably) so this will have to be limited to our own local testing environment. |
Sudo is enabled on the Travis Ubuntu environments. We did this in the past. |
Strictly following POSIX, pthread_attr_setstacksize() will fail if stack_size is less than the minimum stack size. FWIW RTEMS doesn't follow this philosophy on at least the Classic API and will give the thread a stack of minimum size if the call is less than or equal to the minimum. We judged the ability to set a minimum stack size in configuration and have all the thread stacks increase in size without touching code as a desirable behavior. Personally, I think the POSIX requirement is a portability barrier. Your code could specify a low requested stack size but the pthreads implementation could have something large and your code would break. It should be treated as a floor on the allocated stack size. |
And yes, we should add to the matrix. Changing everything to a user with elevated privileges would then miss the case without elevated privileges. It's not clear to me why we'd drop the non-elevated case. |
Hmm, then maybe it can be as simple as executing at least one of the existing matix builds in "sudo" - worth a shot at least. My suggestion would be to run the debug build as a normal non-root user, and release build as sudo. Prefer not to rebuild the code again if we don't have to as this consumes resources and extends the test time. |
Adding to the matrix does not extend test time. Unless the test added is longer than all the rest... That's the point of the matrix. |
Aren't projects limited with respect to the total time they can consume for the CI scripts running in the cloud? That was my understanding of the free-to-use cloud environment we are using, anyway. Running the tests again in parallel may not consume extra wall time but will consume extra CPU time, especially if another code rebuild is involved. That would be the main reason for pursuing a lighter-weight approach at least, but maybe it is not a concern. |
There's a jobs limit, and a time limit per job. The elevated privileges build addition does not put us at risk of exceeding either of these. |
The pthread_attr_setstacksize() function stipulates that it may fail if the user-supplied stack size is not at least PTHREAD_STACK_MIN and also possibly a multiple of page size. This partially reverts previous PR nasa#508 and adds back rounding up to PTHREAD_STACK_MIN and also adds rounding up to a system page size. However the check for zero stack still remains at the shared level so attempts to create a task with zero stack will still fail. This allows internal helper threads to be created with a default minimum stack size, however.
I didn't saw Also, not sure why the test will pass when running with no-root user but the
But if using
|
So, for non-root user, it will failed at When doing |
The pthread_attr_setstacksize() function stipulates that it may fail if the user-supplied stack size is not at least PTHREAD_STACK_MIN and also possibly a multiple of page size. This partially reverts previous PR nasa#508 and adds back rounding up to PTHREAD_STACK_MIN and also adds rounding up to a system page size. However the check for zero stack still remains at the shared level so attempts to create a task with zero stack will still fail. This allows internal helper threads to be created with a default minimum stack size, however.
@mlouielu there is a configuration setting |
Fix #525, ensure POSIX stack size meets requirements
Fix nasa#525, Message Requirements Scrub
Describe the bug
OS_API_Init() fails on generic-linux due to a stack size of 0 being used for the console task.
To Reproduce
Expected behavior
The three test tasks should execute.
Actual behavior
OS_API_Init() fails with the following error message (debug messages enabled):
OS_Posix_InternalTaskCreate_Impl():473:pthread_attr_setstacksize error in OS_TaskCreate: Invalid argument
Code snips
The error occurs on the following call to pthread stack size in OS_Posix_InternalTaskCreate_Impl():
return_code = pthread_attr_setstacksize(&custom_attr, stacksz);
The reason it fails is because the stacksz is set to zero in OS_ConsoleCreate_Impl():
return_code = OS_Posix_InternalTaskCreate_Impl(&consoletask, OS_CONSOLE_TASK_PRIORITY, 0, OS_ConsoleTask_Entry, local_arg.opaque_arg);
System observed on:
Additional context
This issue is resolved by using a stack size of PTHREAD_STACK_MIN instead of 0:
return_code = OS_Posix_InternalTaskCreate_Impl(&consoletask, OS_CONSOLE_TASK_PRIORITY, PTHREAD_STACK_MIN, OS_ConsoleTask_Entry, local_arg.opaque_arg);
Reporter Info
Adam St. Amand
The text was updated successfully, but these errors were encountered: