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

Remove use of internal RTX types #4776

Merged
merged 1 commit into from
Sep 6, 2017
Merged

Conversation

c1728p9
Copy link
Contributor

@c1728p9 c1728p9 commented Jul 18, 2017

Make calls to cmsis-os to get thread state, stack size, and max stack usage rather than accessing internal RTX data directly. Wrap the code which has no public RTX function in TARGET_CORTEX_M since this needs to be defined for RTX to be included.

@c1728p9 c1728p9 requested a review from bulislaw July 18, 2017 17:06
@c1728p9
Copy link
Contributor Author

c1728p9 commented Jul 18, 2017

/morph test

@mbed-bot
Copy link

Result: FAILURE

Your command has finished executing! Here's what you wrote!

/morph test

Output

mbed Build Number: 848

Test failed!

rtos/Thread.cpp Outdated
@@ -238,10 +237,12 @@ uint32_t Thread::free_stack() {
uint32_t size = 0;
_mutex.lock();

#if defined(TARGET_CORTEX_M)
Copy link
Member

Choose a reason for hiding this comment

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

Why are we adding that? I would hope the new Cortex A support in RTX is not that different

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll add Cortex A to this as well.

rtos/Thread.cpp Outdated
@@ -168,7 +168,7 @@ Thread::State Thread::get_state() {
_mutex.lock();

if (_tid != NULL) {
state = _obj_mem.state;
state = osThreadGetState(_tid);
Copy link
Member

Choose a reason for hiding this comment

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

That's possibly incorrect, if we want to preserve compatibility with pre CMSIS5 code, the osThreadGetState compresses statuses to short list, RTOS C++ API have quite extensive list. I personally agree we don't need all this detailed states like ('waiting for semaphore' as opposed to 'Waiting') but that's what we used to return.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can revert this back to what it was. Just let me know what you prefer.

Copy link
Contributor

Choose a reason for hiding this comment

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

To be backward compatible if there is no strong reason to break this. In this case it is not?

rtos/Thread.cpp Outdated
while (((uint32_t *)(thread->stack_mem))[high_mark] == 0xE25A2EA5)
high_mark++;
size = thread->stack_size - (high_mark * sizeof(uint32_t));
size = osThreadGetStackSize(_tid) - osThreadGetStackSpace(_tid);
Copy link
Member

Choose a reason for hiding this comment

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

to use osGetStackSpace we need to enable OS_STACK_WATERMARK, right now we only do it conditionally.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't realize that, thanks for pointing it out. I think this code will be ok since osThreadGetStackSpace isn't compiled out when OS_STACK_WATERMARK isn't set, it just returns 0. Regardless, if stack watermarking isn't turned out then this code won't work as expected, since the stack won't be filled with 0xE25A2EA5.

Copy link
Member

Choose a reason for hiding this comment

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

I would say we should either leave it the way it was or define OS_STACK_WATERMARK and change the code to fit it (eg not fill the stack with our pattern and let the RTX to use their 0xCCCCCCCCU).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, I forgot there were two watermarking schemes. So the existing code would actually work when OS_STACK_WATERMARK isn't set. Either way works for me. Defining OS_STACK_WATERMARK seems like it might unify the code more, so that would be my preference.

Copy link
Member

Choose a reason for hiding this comment

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

Agreed

@c1728p9
Copy link
Contributor Author

c1728p9 commented Jul 19, 2017

/morph test

@mbed-bot
Copy link

Result: FAILURE

Your command has finished executing! Here's what you wrote!

/morph test

Output

mbed Build Number: 851

Test failed!

@c1728p9
Copy link
Contributor Author

c1728p9 commented Jul 19, 2017

/morph test

@mbed-bot
Copy link

Result: SUCCESS

Your command has finished executing! Here's what you wrote!

/morph test

Output

mbed Build Number: 853

All builds and test passed!

@@ -24,6 +24,11 @@

#include "mbed_rtx.h"

/** Any access to RTX5 specific data structures used in common code should be wrapped in ifdef OS_BACKEND_RTX5 */
Copy link
Member

Choose a reason for hiding this comment

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

I don't get why we have it this way. I would say it's fair enough to try to be 'generic' and let people replace RTX with other RTOSs as long as they implement CMSIS-RTOS2 API. But why do you enable it for CORTEX A and M? In any case that's the only HW we support. We could just define this flag in mbed_rtx_conf.h without checking the cores as it's RTX config and I would expect it should be provided per implementation (together with the storage and handlers files). Also I'm a big fan of mbed flags starting with mbed, so maybe something like MBED_OS_BACKEND_RTX5 for clarity.

@c1728p9
Copy link
Contributor Author

c1728p9 commented Jul 20, 2017

This will be updated once #4786 has been merged.

@theotherjimmy
Copy link
Contributor

@c1728p9 Does this really need #4786 to go in first?

@c1728p9
Copy link
Contributor Author

c1728p9 commented Jul 27, 2017

The only dependency is the TARGET_CORTEX change.

@c1728p9
Copy link
Contributor Author

c1728p9 commented Jul 27, 2017

Updated this PR to include the TARGET_CORTEX directory addition. Also, expanded the scope of this PR to remove the use of internal RTX structures everywhere in the codebase.

@c1728p9
Copy link
Contributor Author

c1728p9 commented Jul 27, 2017

/morph test

@theotherjimmy
Copy link
Contributor

@c1728p9 that change does make more sense here.

@c1728p9
Copy link
Contributor Author

c1728p9 commented Jul 27, 2017

retest uvisor

@c1728p9
Copy link
Contributor Author

c1728p9 commented Jul 27, 2017

/morph test

@c1728p9
Copy link
Contributor Author

c1728p9 commented Aug 31, 2017

@bulislaw has already worked with the cmsis-rtos team to try and get the new types added, but this enhancement was rejected.

@c1728p9
Copy link
Contributor Author

c1728p9 commented Sep 1, 2017

I created a PR #5003 for the directory restructuring and rebased this to master.

@c1728p9
Copy link
Contributor Author

c1728p9 commented Sep 1, 2017

/morph test

@mbed-bot
Copy link

mbed-bot commented Sep 1, 2017

Result: FAILURE

Your command has finished executing! Here's what you wrote!

/morph test

Output

mbed Build Number: 1149

Test failed!

@@ -29,7 +29,7 @@
extern void SVC_Handler(void);
extern void PendSV_Handler(void);
extern void SysTick_Handler(void);
extern uint32_t svcRtxKernelLock(void);
Copy link
Member

Choose a reason for hiding this comment

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

That's going to be overwritten by next uvisor drop.

Copy link
Contributor

Choose a reason for hiding this comment

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

It was merged by uvisor, the new update contains this, its ready for merge: https://github.com/ARMmbed/mbed-os/pull/4907/files . This will be rebased once it gets in

Copy link
Contributor

Choose a reason for hiding this comment

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

This PR shouldn't do the update, but should use the uVisor v0.30.0 changes.

Does this PR need to raise the priority of PR #4907? We thought the v0.30.0 PR was optional for 5.6, but maybe because this PR depends on it, the uVisor PR must go into 5.6.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks @Patater. If both gets in, it would be nice. This is nice to have.
We will wait for uvisor to get in with the change, and rebase this one afterwards.

Copy link
Member

@bulislaw bulislaw left a comment

Choose a reason for hiding this comment

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

LGTM

@c1728p9
Copy link
Contributor Author

c1728p9 commented Sep 1, 2017

/morph test

@mbed-bot
Copy link

mbed-bot commented Sep 1, 2017

Result: SUCCESS

Your command has finished executing! Here's what you wrote!

/morph test

Output

mbed Build Number: 1156

All builds and test passed!

@0xc0170
Copy link
Contributor

0xc0170 commented Sep 4, 2017

As marked above (#4776 (comment)), waiting for uvisor update.

@0xc0170
Copy link
Contributor

0xc0170 commented Sep 4, 2017

@c1728p9 Please rebase, uvisor PR update was merged to master

Make calls to cmsis-os to get thread state, stack size, and max stack
usage rather than accessing internal RTX data directly. Wrap RTX5
specific code in OS_BACKEND_RTX5.

Also refactor the code to use mbed types rather than RTX types:
os_timer_t -> mbed_rtos_storage_timer_t
os_event_flags_t -> mbed_rtos_storage_event_flags_t
osRtxMutex_t -> mbed_rtos_storage_thread_t
@c1728p9
Copy link
Contributor Author

c1728p9 commented Sep 4, 2017

Rebased and removed uvisor changes to rtx_box_index.h.

@c1728p9
Copy link
Contributor Author

c1728p9 commented Sep 4, 2017

/morph test

@mbed-bot
Copy link

mbed-bot commented Sep 5, 2017

Result: SUCCESS

Your command has finished executing! Here's what you wrote!

/morph test

Output

mbed Build Number: 1215

All builds and test passed!

@0xc0170
Copy link
Contributor

0xc0170 commented Sep 6, 2017

Ready for intergration.

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.

None yet

8 participants