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.

C6678: Running periodic threads with separate priorites

Hello,

I need to run three separate periodic threads with different priorities on each core so a total of 24 threads on all 8 cores. Up until now I was using the clock module and creating a separate clock instance for each thread, but now I need to use different priorities for each thread. I see 4 possible solutions to this:

1) Make each thread an SWI with different priorities and run a 1 ms timer that uses a counter to call SWI_post() for each thread as needed from the timer HWI.

2) Use a 1 ms timer with a counter to create a task for each thread with different priorities as needed from the timer HWI.

3) Make each thread an SWI with different priorities and use a clock function that runs every 1 ms with a counter that calls SWI_post() for each thread as needed from the clock SWI. The clock function would need to have a higher priority than the threads.

4) Use a 1 ms clock function with a counter to create a task for each thread as needed from the clock SWI.

 

I have a few questions regarding these possible solutions.

1) Are there any other ways to implement periodic threads with different priorities?

2) Are any of these (or any other) solutions recommended for general cases for whatever reason? 

3) Is it possible to use a shared timer for the SYS/BIOS clock module (say timer 8)? I only see options 0-7 and ANY from the drop down box in the SYS/BIOS GUI, but I can set it to use 8 in the source and I don't get any errors when building. If so would this allow for all 8 cores to be in sync since they would be using the same timer?

4) In the same vein as the previous question, is it possible to use a shared timer for an HWI that would either create tasks or call SWI_post()? I would think that since each core needs to run 3 threads that each core would need its own HWI. If each core uses the same timer to generate the HWI, would this keep all 8 cores in sync at least for the HWI?

5) How much of an overhead difference is there between creating a task for each thread on a periodic basis vs calling SWI_post()? I would think that calling SWI_post() periodically would have better performance. Is there any reason to periodically create threads instead?

6) We will be using a watchdog timer as well. My understanding is that this uses the local timer for each core meaning timers 0-7 are used and only timers 8-15 would be available for other uses. Is this correct? If it is correct and the SYS/BIOS clock module can't use a timer shared between all cores (i.e. each core must have its own timer to use for the clock module) does this mean that with a watchdog timer for each core and the clock module in use for each core all 16 timers are used?

Regards,

Chris Johnson

Signalogic

  • Chris Johnson1 said:

    I have a few questions regarding these possible solutions.

    1) Are there any other ways to implement periodic threads with different priorities?

    2) Are any of these (or any other) solutions recommended for general cases for whatever reason? 

    Not that I can think of.  I like your Clock/Swi_post (idea 3 above) the best.   I would recommend this one.  Swi performance is much better than Task performance.   And you don't need a separate task for each Swi like you do for Task.

    Chris Johnson1 said:

    3) Is it possible to use a shared timer for the SYS/BIOS clock module (say timer 8)? I only see options 0-7 and ANY from the drop down box in the SYS/BIOS GUI, but I can set it to use 8 in the source and I don't get any errors when building. If so would this allow for all 8 cores to be in sync since they would be using the same timer?

    Yes.  You can configure timer8 to generate an interrupt on all 8 cores.  Core 0 could initialize it, and the other 7 will just wait for the interrupt.  The "timer64/Timer" cdoc has a code snip that shows how to do this on a 4-core device.  Change '4' to '8' below and you should be in business.   The drop down only supports 0-7, but you can add '8' with hand-edit of the .cfg in text editor.   Here's the code snip.

      // sets core 0 to init and release Timer 4.
      var Timer = xdc.useModule('ti.sysbios.timers.timer64.Timer');
      Timer.timerSettings[4].ownerCoreId = 0;
    
      var Clock = xdc.useModule('ti.sysbios.knl.Clock');
      Clock.timerId = 4;

    Chris Johnson1 said:

    4) In the same vein as the previous question, is it possible to use a shared timer for an HWI that would either create tasks or call SWI_post()? I would think that since each core needs to run 3 threads that each core would need its own HWI. If each core uses the same timer to generate the HWI, would this keep all 8 cores in sync at least for the HWI?

    See above.   Posting Swi from Clock functions makes good sense and is how I would do it.  Using shared timer will keep all 8 cores in synch.

    Chris Johnson1 said:

    5) How much of an overhead difference is there between creating a task for each thread on a periodic basis vs calling SWI_post()? I would think that calling SWI_post() periodically would have better performance. Is there any reason to periodically create threads instead?

    Check the benchmark link in the release notes.  It shows interrupt-to-Task time and interrupt-to-Swi time which are similar to what you are looking for.

    Chris Johnson1 said:

    6) We will be using a watchdog timer as well. My understanding is that this uses the local timer for each core meaning timers 0-7 are used and only timers 8-15 would be available for other uses. Is this correct? If it is correct and the SYS/BIOS clock module can't use a timer shared between all cores (i.e. each core must have its own timer to use for the clock module) does this mean that with a watchdog timer for each core and the clock module in use for each core all 16 timers are used?

    Using shared timer 8 for the OS interrupt on all 8 cores will free up 15 timers for your use.

    Regards,
    -Karl-