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

[FEATURE] Add SoC time stamp forwarding feature in BSD semaphore design #229

Conversation

powerlink-team-kalycito
  • Create a shared memory between kernel and user layer to store SoC
    timestamps using mmap.
  • The initialized shared memory is unmapped during the exit of the
    function.

This pull request also takes care of the comments from the previous pull request #227

 - Create a shared memory between kernel and user layer to store SoC
   timestamps using mmap.
 - The initialized shared memory is unmapped during the exit of the
   function.

Change-Id: Ia1e0926db05520ea7bf7e12c4a801d05e54c4fa9
// Close the semaphore
sem_close(instance_l.syncSem);
// Unlink the semaphore
sem_unlink(TIMESYNC_SYNC_BSDSEM);
Copy link
Contributor

Choose a reason for hiding this comment

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

Please do the semaphore cleanup outside of this function!

Choose a reason for hiding this comment

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

Not handled semaphore clean up outside the function, instead the handling is done using goto statements inside the same function itself.

Copy link
Contributor

Choose a reason for hiding this comment

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

Code duplication: If you do sem_close() and sem_unlink() in timesynckcal_init() if createTimestampShm() fails, you can workaround code duplication!

Choose a reason for hiding this comment

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

Okay.

// Close the semaphore
sem_close(instance_l.syncSem);
// Unlink the semaphore and timesync shared memory
sem_unlink(TIMESYNC_SYNC_BSDSEM);
Copy link
Contributor

Choose a reason for hiding this comment

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

Please do the semaphore cleanup outside of this function!

Choose a reason for hiding this comment

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

Not handled semaphore clean up outside the function, instead the handling is done using goto statements inside the same function itself.

Copy link
Contributor

Choose a reason for hiding this comment

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

Code duplication: If you do sem_close() and sem_unlink() in timesynckcal_init() if createTimestampShm() fails, you can workaround code duplication!

Choose a reason for hiding this comment

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

Okay.

//Close the semaphore
sem_close(instance_l.syncSem);
//Unlink the semaphore and timesync shared memory
sem_unlink(TIMESYNC_SYNC_BSDSEM);
Copy link
Contributor

Choose a reason for hiding this comment

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

Please do the semaphore cleanup outside of this function!

Choose a reason for hiding this comment

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

Not handled semaphore clean up outside the function, instead the handling is done using goto statements inside the same function itself.

Copy link
Contributor

Choose a reason for hiding this comment

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

Code duplication: If you do sem_close() and sem_unlink() in timesynckcal_init() if createTimestampShm() fails, you can workaround code duplication!

Choose a reason for hiding this comment

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

Okay.

#if defined(CONFIG_INCLUDE_SOC_TIME_FORWARD)
ret = createTimestampShm();
if (ret != kErrorOk)
return ret;
Copy link
Contributor

Choose a reason for hiding this comment

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

Do semaphore cleanup here if createTimestampShm() fails!

Choose a reason for hiding this comment

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

Semaphore cleanup is already done at createTimestampShm() so it is not required to do it again here.

Copy link
Contributor

Choose a reason for hiding this comment

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

A function should only clean up those resources which are created in the same function before in case of an error during creation. Of course the clean up in case of an exit might happen in an other function. createTimestampShm() is not creating the semaphore, thus, I would prefer to clean up the semaphore in timesynckcal_init() if createTimestampShm() fails!

Choose a reason for hiding this comment

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

Okay.

ret = destroyTimestampShm();
if (ret != kErrorOk)
{
DEBUG_LVL_ERROR_TRACE("%s() timesync shared memory exit failed", __func__); // TODO:Handle ret value in upper layers
Copy link
Contributor

Choose a reason for hiding this comment

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

drop that TODO

Choose a reason for hiding this comment

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

If the user tries to re run the POWERLINK application after an unsuccessful "POWERLINK exit" he will be facing errors due to improper exit, so the previous error handling traces will support the user to debug and progress further.

Hence it is necessary to handle the return value in the upper layers as well, so the TODO is essential here.

Copy link
Contributor

Choose a reason for hiding this comment

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

I didn't mean to drop the error trace! I completely agree with the scenario you describe that it helps to debug unsuccessful exits.

However, adding to every single exit function a TODO now is not reasonable. Doing this in every exit function would increase the number of TODOs unnecessarily. Instead - if there is a good working way to handle a failing exit except system reset :) - raise an issue to equip all the exit functions with a return value again.

Choose a reason for hiding this comment

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

TODO shall be removed and issue shall be raised.

Choose a reason for hiding this comment

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

Issue has been raised: #234

ret = destroyTimestampShm();
if (ret != kErrorOk)
{
DEBUG_LVL_ERROR_TRACE("%s() exit failed", __func__); // TODO:Handle ret value in upper layers
Copy link
Contributor

Choose a reason for hiding this comment

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

drop that TODO

Choose a reason for hiding this comment

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

If the user tries to re run the POWERLINK application after an unsuccessful "POWERLINK exit" he will be facing errors due to improper exit, so the previous error handling traces will support the user to debug and progress further.

Hence it is necessary to handle the return value in the upper layers as well, so the TODO is essential here.

Copy link
Contributor

Choose a reason for hiding this comment

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

same here...

DEBUG_LVL_ERROR_TRACE("%s() Initialization of shared memory failed!\n",
__func__);
// Close the semaphore
sem_close(instance_l.syncSem);
Copy link
Contributor

Choose a reason for hiding this comment

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

Please do the semaphore cleanup outside of this function!

Choose a reason for hiding this comment

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

Not handled semaphore clean up outside the function, instead the handling is done using goto statements inside the same function itself.

Copy link
Contributor

@zelenkaj zelenkaj Apr 27, 2017

Choose a reason for hiding this comment

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

Choose a reason for hiding this comment

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

Okay.

// Close the semaphore
sem_close(instance_l.syncSem);
// Unlink the semaphore and timesync shared memory
sem_unlink(TIMESYNC_SYNC_BSDSEM);
Copy link
Contributor

Choose a reason for hiding this comment

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

Please do the semaphore cleanup outside of this function!

Choose a reason for hiding this comment

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

Not handled semaphore clean up outside the function, instead the handling is done using goto statements inside the same function itself.

Copy link
Contributor

Choose a reason for hiding this comment

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

Choose a reason for hiding this comment

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

Okay.

#if defined(CONFIG_INCLUDE_SOC_TIME_FORWARD)
ret = createTimestampShm();
if (ret != kErrorOk)
return ret;
Copy link
Contributor

Choose a reason for hiding this comment

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

Do semaphore cleanup here if createTimestampShm() fails!

Choose a reason for hiding this comment

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

Not handled semaphore clean up outside the function, instead the handling is done using goto statements inside the same function itself.

Copy link
Contributor

Choose a reason for hiding this comment

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

Choose a reason for hiding this comment

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

Okay.

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.

2 participants