Hi Vikas,

 

Do you have any proposed patch for point 1.

For point 2, my point is, if the child thread can terminate itself, why bother let the parent do that.

But I figured out it’s not possible for manual memory management scenario, right?

 

Best Regards,

Kevin

 

From: Vikas Katariya <Vikas.Katariya@arm.com>
Sent: Monday, February 10, 2020 5:49 PM
To: Kevin Peng <Kevin.Peng@arm.com>; 'tf-m@lists.trustedfirmware.org' <tf-m@lists.trustedfirmware.org>
Cc: nd <nd@arm.com>
Subject: RE: Changes to OS wrapper

 

Hi Kevin,

 

               Thanks for the e-mail.

               The main idea of the whole patchset is to support manual memory management for the OS.

To achieve that:

manually managed resources.

 

               Hope this answers your query.

 

Thanks & Best Regards,

Vikas Katariya

 

From: Kevin Peng <Kevin.Peng@arm.com>
Sent: Monday, February 10, 2020 08:40
To: Vikas Katariya <Vikas.Katariya@arm.com>; Gyorgy Szing <Gyorgy.Szing@arm.com>; Jamie Fox <Jamie.Fox@arm.com>; Anton Komlev <Anton.Komlev@arm.com>; 'tf-m@lists.trustedfirmware.org' <tf-m@lists.trustedfirmware.org>
Cc: nd <nd@arm.com>
Subject: RE: Changes to OS wrapper

 

Hi Vikas,

 

I’m seeing two topics here if I understand correctly.

The first one is how to deal with memory management in the os wrapper implementation.

The second one is how to safely “exit” and “delete” a child thread.

 

Please first check if my understanding is correct.

For the first topic, except the handles of threads, semaphores or mutex (which are the OS handles I guess), the OS wrapper needs some extra handles for resource handling.

For example the pointer of the memory allocated in the OS wrapper API. The two handles forms the new OS wrapper handle you proposed.

 

For the second topic, can we just terminate or delete the child thread by itself after it has done its job?

 

Best Regards,

Kevin

 

From: TF-M <tf-m-bounces@lists.trustedfirmware.org> On Behalf Of Vikas Katariya via TF-M
Sent: Friday, February 7, 2020 12:55 AM
To: Gyorgy Szing <Gyorgy.Szing@arm.com>; Jamie Fox <Jamie.Fox@arm.com>; Anton Komlev <Anton.Komlev@arm.com>; tf-m@lists.trustedfirmware.org
Cc: nd <nd@arm.com>
Subject: Re: [TF-M] Changes to OS wrapper

 

Hi all,

 

Thanks for the e-mail.
I would like to highlight a few issues with the current API implementation.

 

So a change in the API implementation is required to address the above issues.

 

Comments towards the arguments:

 

Depreciating the old API will ensure the following:

 

Further, if there is a matter of handling deprecation of API, then I would like to know how that can be achieved in TF-M?

 

Thanks & Best Regards,

Vikas Katariya

 

From: TF-M <tf-m-bounces@lists.trustedfirmware.org> On Behalf Of Anton Komlev via TF-M
Sent: Thursday, February 6, 2020 12:16
To: tf-m@lists.trustedfirmware.org
Cc: nd <nd@arm.com>
Subject: Re: [TF-M] Changes to OS wrapper

 

Hello,

 

Agree with Jamie seeing not enough arguments for extension of existing API. Looks like the required functionality can be hidden inside a specific os_wrapper, which is a main purpose of it.

@Vikas, could you explain a bit differently why you are blocked with the current API?

 

Cheers,

Anton

 

 

From: TF-M <tf-m-bounces@lists.trustedfirmware.org> On Behalf Of Gyorgy Szing via TF-M
Sent: 06 February 2020 09:10
To: Vikas Katariya <Vikas.Katariya@arm.com>; Jamie Fox <Jamie.Fox@arm.com>; tf-m@lists.trustedfirmware.org
Cc: nd <nd@arm.com>
Subject: Re: [TF-M] Changes to OS wrapper

 

Hi,

 

From the architecture point of view, when an “owner” (sw entity) defines an API, the best is to do that based on it’s own needs. This gives the most flexibility and makes the API best withstand future challenges. Sometimes this is not possible. An example for this is the TRIM functionality of SSD storage, where the file-system must give extra information to the storage. In this case the extension of the API is driven by the implementation and thus implementation details. This is risky as different implementations may have conflicting needs, and sometimes the API cannot fulfill both.

If your case, a possible solution is to implement the os_theread_delete() and an empty function. If that is not possible, then a wrapper can be added where a variable captures info on if the thread has been exited, and thus if deletion is safe or not. If it is, then os_thread_delete() can exit without doing anything.

The call sequence of suspend and the delete is specific to the OS you are using or to the way you use it. Do you think does here a strong reason exist to go for an API extension driven by the implementation? I don’t have all details, but as far as I understand the specific cases you described I don’t see an imminent need for the API change.

/George

 

From: TF-M <tf-m-bounces@lists.trustedfirmware.org> On Behalf Of Vikas Katariya via TF-M
Sent: 06 February 2020 08:47
To: Jamie Fox <Jamie.Fox@arm.com>; tf-m@lists.trustedfirmware.org
Cc: nd <nd@arm.com>
Subject: Re: [TF-M] Changes to OS wrapper

 

Hi Jamie,

 

               Thanks for getting back.

 

It’s because of os_wrapper_thread_exit() is used to exit the child thread in the SST test, which means the handle is no longer valid for os_wrapper_thread_delete() to operate on, resulting in an error.

 

               The ideal way to do this properly is to use os_wrapper_thread_suspend() and then os_wrapper_thread_delete() from the parent thread.

 

Thanks & Best Regards,

Vikas Katariya

 

 

From: Jamie Fox <Jamie.Fox@arm.com>
Sent: Wednesday, February 5, 2020 17:16
To: Vikas Katariya <Vikas.Katariya@arm.com>; tf-m@lists.trustedfirmware.org
Cc: nd <nd@arm.com>
Subject: RE: Changes to OS wrapper

 

Hi Vikas,

 

I still do not really understand the rationale for these changes. If dynamic memory allocation inside the os_wrapper shim is really what you want to do, then what is stopping you from implementing the following?

 

os_wrapper_thread_new()

{

    malloc(external_to_os_resource)

 

    /* create thread */

}

 

os_wrapper_thread_delete()

{

    free(external_to_os_resource)

}

 

Kind regards,

Jamie

 

From: TF-M <tf-m-bounces@lists.trustedfirmware.org> On Behalf Of Vikas Katariya via TF-M
Sent: 05 February 2020 10:20
To: tf-m@lists.trustedfirmware.org
Subject: Re: [TF-M] Changes to OS wrapper

 

Hi all,

 

               The patch set has been updated with further changes:

 

OS wrapper layers help to create Mutex, Semaphores, and Thread on an OS. The wrapper was designed to be implemented on platforms that dynamically allocate memory or objects from a predefined OS memory pool.

The current shape of the OS wrapper is not a good fit for work with operating systems that require manual memory management.

 

For example, if the child thread created in ns_test_helpers.c does a simple os_wrapper_thread_exit(), this does not give any opportunity for manually-managed thread resources to be freed; this leads to a memory leak.

Therefore os_wrapper_current_thread_suspend() and os_wrapper_thread_delete() are introduced to aid scenarios where manual memory management is required.

 

The removal of os_wrapper_thread_exit() is warranted as it encourages applications to avoid memory leak scenarios by requiring applications to remember to call os_wrapper_thread_terminate().

If we were to keep os_wrapper_thread_exit() around, this would impose undue cognitive overhead on wrapper users by making os_wrapper_thread_exit() do something other than exit the current thread (on platforms requiring manual memory management);

an os_wrapper_thread_exit() implementation could not actually exit a thread on a manual memory managed OS, as the thread must remain valid until clean up time, and exiting the thread would invalidate the OS's thread resource.

 

These changes reflect to avoid memory leaks on operating systems that use manually managed dynamic memory allocation but not from static memory/objects pools, allowing them to free after usage.

Remove "get_handle" because it's not possible to implement it efficiently on systems that require manual memory management.

The os-wrapper handle must be different from the actual underlying OS handle on a manually-memory-managed system in order to allow the resources be freed which are not managed by the OS.

 

For example:

struct {

os_handle;

external_to_os_resource;

};

The os-wrapper knows more about the resources being managed than the OS itself. It is supposed to return an OS Wrapper handle than OS handle, because implementations can't always create an os-wrapper handle from an OS handle.

In this case the os-wrapper handle could be a pointer to this struct, but could not be just the os_handle directly.

Further os_wrapper_current_thread_get_priority() is used to avoid confusion between the top and bottom layer handles, because the older implementation can refer to different object types when operating across multiple layers.

 

 

Please review and share your thoughts.

 

Thanks & Best Regards,

Vikas Katariya

 

 

From: TF-M <tf-m-bounces@lists.trustedfirmware.org> On Behalf Of Vikas Katariya via TF-M
Sent: Monday, January 27, 2020 15:52
To: tf-m@lists.trustedfirmware.org
Subject: [TF-M] App: Changes to OS wrapper

 

Hi all,

 

I am proposing new changes to OS wrapper layer to help other RTOS use dynamic memory allocation.

 

OS wrapper layers help to create Mutex, Semaphores, and Thread on RTOS. The wrapper is designed to use static allocation of memory/objects

from predefined OS memory pool, which is not fully featured enough to allow dynamic memory allocation and freeing them after completion, if an RTOS

requires that kind of implementation.

For example, the child thread created in ns_test_helpers.c does a simple exit without passing a handle if the memory was dynamically allocated, which is a memory leak scenario.

 

Therefore os_wrapper_thread_suspend() and os_wrapper_thread_delete() are introduced to aid scenarios where dynamic memory allocation and freeing is required.

 

               In the current patch we just suspend the child thread and terminate it from parent thread.

 

The patch is open for review here: https://review.trustedfirmware.org/c/trusted-firmware-m/+/3294

 

Thanks & Best Regards,

Vikas Katariya

IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.