This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MCU-PLUS-SDK-AM263X: ipc_spinlock_sharedmem_am263x SDK example Spinlock Usage

Part Number: MCU-PLUS-SDK-AM263X

I have a question regarding the SDK example:

  ipc_spinlock_sharedmem_am263x-cc_r5fss0-0_freertos_ti-arm-clang

In this example the two cores are both accessing a uint32_t variable in shared memory.

The documentation says:

"Spinlocks are used to protect this shared memory access. This ensures that the access is atomic and the shared variable is incremented properly."

Questions:

1)

Since the applications is only to increment a uint32_t is spinlock actually needed? Shouldn't the gUserSharedMem++ operation be atomic?

2a)

Is it true that accessing shared memory without spinlock is not problematic unless the atomic access is required?

2b)

For example, If one core needs to share various uint32_t counters that are independent/orthogonal for another core to process, then no spinlock is needed. Correct?

 

  • Hello,

    Can you provide more details on your use case here? And why do you want non-atomic access to memory?
    Do you want to access and update same variable in different cores or different variables in different cores?

    Regards,
    Gunjan

  • Hi Gunjan,

    I am planning of implementing inter-core communication using RPMessage.

    However, I want to make sure my understanding of the concept is sound, so I implement the correct IPC mechanism where required.

    Regarding:

    "And why do you want non-atomic access to memory?"

    ... I might use non-atomic access if there is no disadvantage. For instance, using IPC unnecessarily may affect interrupt handling latency.

    Regarding:

    "Do you want to access and update same variable in different cores or different variables in different cores?"

    ... In my 'orthogonal uint32_t array example, only one core would be writing to the memory. In the ipc_spinlock_sharedmem_am263x-cc_r5fss0-0_freertos_ti-arm-clang SDK example there are two cores each intend to update the counter SPINLOCK_TEST_LOOPCNT times.

    Question 1:

    Is the spinlock in the ipc_spinlock_sharedmem_am263x-cc_r5fss0-0_freertos_ti-arm-clang SDK example really doing anything significant?

    Question 2:

    It seems to me that sharing an array of uint32_t that are orthogonal where only one core is writing to that memory would not require Spinlock, RPMessage, or any other IPC mechanism. Is this true?

    Regards,

    Tollman

  • UPDATE:

    I will try to answer Question 1:

    Since, without spinlock each core may simultaneously, be incrementing gUserSharedMem the value may not equal  SPINLOCK_TEST_LOOPCNT * 2 upon completion of the test. This is because the each core may load, increment, and store the same value. This makes it seem that some of the increment instructions were ‘missed’.

    Is this correct?

  • Hello TollMan,

    Yes, without spinlock each core may simultaneously be accessing and updating gUserSharedMem and can lead to incorrect value of gUserSharedMem.

    Regards,
    Gunjan

  • Hello,

    About question2, if array is orthogonal and used in one core only, then do we need to have it in shared memory? I think no.

    If you want to say that array is written/updated from one core and read in another core, then also you can miss some values if spinlocks are not used. For eg. a core started updating array and before completion of this updation another core is also tries to read it, this way it might read old value.

    Regards,
    Gunjan

  • Thanks Gunjan.

    It is clear now.

    Regards,

    Tollman