Author Topic: uTasker API  (Read 15438 times)

Offline abhimanyum

  • Newbie
  • *
  • Posts: 24
    • View Profile
    • Ae Applications
uTasker API
« on: August 16, 2011, 12:28:53 PM »
Hi Mark,

I'm looking to measure following things on uTasker RTOS, since I'm a newbie in this field, so can please help me with this. I've managed to create a Task (as per your PDF Guide), I want to perform following:

1. Timer in uTasker, when code execution started and when ended and getting how much time taken to execute that function. (Is there any way to do through uTasker)

2. Secondly, I'm looking how to create tasks with priority and context switch between them.



Thanks for your time,

Cheers,
Ab
« Last Edit: August 16, 2011, 04:46:42 PM by abhimanyum »

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: uTasker API
« Reply #1 on: August 17, 2011, 09:42:03 AM »
Hi Ab

1) In some newer project packages there is a define MONITOR_PERFORMANCE. This allows a hardware timer to be used to measure the time taken for each task to run, plus the time spent in idle. Via the command line menu the information can be displayed for all tasks, including the CPU load in %. Since you are working with the STR9, which is not being further maintained due to its unpopularity, you will not have this new code. I will send you a different package so that you can can see the code that is used - as long as you can configure a HW timer in a similar fashion this will work on your processor.

2) The uTasker scheduler is a co-operative scheduler and so doesn't perform context switches. The philosopy is based on state-event operation and the use of interrupts for high priority work and some prioritising. There are advantages and disadvantages with different scheduling strategies, but experience has shown that the used method enables a high percentage of embedded projects to be realised simpler and with less risk using this method, resulting in much lower use of resources and also very good response times, when used correctly.

In addition, it has been suprising to learn that many (professional) developers prefer not to to use any operating system in embedded designs. Of course they still (usually) need some form of scheduling loop, so the uTasker schedule gives a more formal solution to such users who otherwise prefer to rather have nothing at all.

Embedded systems can be designed and developed using different techniques and the actual operating system/scheduling strategy used doesn't necessarily say much about the final solution. The final solution can be very good - or very bad - using every possible strategy. A good solution is of course to be strived for and, as mentioned above, can very often be achieved faster and more efficiently using the co-operative strategy; in some cases it may be the other way around so it is always up to the embedded software designer to decide what is best suited to a particular case and design the system accordingly. It is felt that the uTasker strategy offers many advantages and so it was decided to follow this strategy - if every embedded operating system, worked the same and could only be compared by the number of machine instructions to perform a context switch it would make life very restrictive - different people prefer different strategies and that is why the uTasker project is there, to offer a certain style for those who find it suits them.

It is not to be forgotten that the heart of the project is also the simulator. The goal is to allow users to save time developing/testing/debugging  real systems. The simulator and the scheduler together are what can make big development time differences in comparision to convertional methods.

Regards

Mark

P.S. There are various other discussions about this - see, for example, http://www.utasker.com/forum/index.php?topic=846.0

Offline abhimanyum

  • Newbie
  • *
  • Posts: 24
    • View Profile
    • Ae Applications
Re: uTasker API
« Reply #2 on: August 17, 2011, 11:58:12 AM »
Hi Mark,

Thanks for your reply. Do really appreciate that.

I was not able to find this define MONITOR_PERFORMANCE in Kinetis Project.
Can you please help me with that.


Thanks,
Regards,
Ab

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: uTasker API
« Reply #3 on: August 17, 2011, 04:30:11 PM »
Hi Ab

Make sure that you don't use the initial Kinetis version (there are 13 versions at the moment: http://www.utasker.com/forum/index.php?topic=1252.0 )

The performance monitor was added in Beta V0.5 - in older ones it is not there but in all newers ones it is (therefore use one towards the bottom of that thread)

Regards

Mark

Offline abhimanyum

  • Newbie
  • *
  • Posts: 24
    • View Profile
    • Ae Applications
Re: uTasker API
« Reply #4 on: August 18, 2011, 02:47:31 PM »
Hi Mark,


Thanks for your reply.
I've managed to extract some of METHOD_PERFORMANCE definations and methods from the project.
Now I'm getting couple of errors with some of PIT & SIM Definations (which are located in Kinetis.h).

Code: [Select]
#ifdef MONITOR_PERFORMANCE
    #define INITIALISE_MONITOR_TIMER()   POWER_UP(6, SIM_SCGC6_PIT); PIT_MCR = 0; LOAD_PIT(0, 0xffffffff); PIT_TCTRL0 = PIT_TCTRL_TEN
    #define EXECUTION_DURATION()  (0xffffffff - PIT_CVAL0); LOAD_PIT(0, 0xffffffff) // read the elapsed count value and reset the counter back to 0xffffffff
    #define PIT_TIMER_USED_BY_PERFORMANCE_MONITOR                        // since a PIT timer is used for the monitoring function don't allow PITS to be powered down
#endif

If you can help me in Identify how to get PIT and SIM for STR9Comstick, would really be helpfull.

Thanks & Regards,
Ab
« Last Edit: August 19, 2011, 01:45:19 PM by abhimanyum »

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: uTasker API
« Reply #5 on: August 20, 2011, 11:25:53 PM »
Hi Ab

In order to measure the elapsed time a hardware timer needs to be used. On the STR912x I would suggest using timer 2, which is otherwise not used in the demo project.

The two macros that you need to define to suit the timer are
INITIALISE_MONITOR_TIMER()
and
EXECUTION_DURATION()



INITIALISE_MONITOR_TIMER() also needs to be called once (for example, it can be added to fnUserHWInit() in application.c).

Possible macros may be as follows:
#define INITIALISE_MONITOR_TIMER()     SCU_PCGR1 |= (TIM23);  TIM_CR1_2 = 0; TIM_CR2_2  = (CLOCK_DIV_256); TIM_CR1_2 = (COUNTER_ENABLE);
#define EXECUTION_DURATION()    (TIM_CNTR_2 - 0xfffc); TIM_CNTR_2 = 0;



These have not been tested but the first one powers up the timer block and configures the timer to be clocked at the slowest speed (bus clock divided by 256) and sets it running (it runs in free-run mode, starting at 0xfffc and overflowing at 0xffff back to 0x0000). This means that it can count to 256 x 64k bus clocks and the resolution is bus clock / 256.

The second reads the number of clocks counted and then resets the timer back to 0xfffc, where it restarts counting from.

You could try this but may need to debug in case the macros are not yet all correct. Sometimes the chip also needs a delay between powering on the peripheral block and actually using it so it may also be an idea to call SCU_PCGR1 |= (TIM23); earlier in the code than the rest of the initialisation.

Regards

Mark
« Last Edit: August 21, 2011, 11:43:32 AM by mark »

Offline abhimanyum

  • Newbie
  • *
  • Posts: 24
    • View Profile
    • Ae Applications
Re: uTasker API
« Reply #6 on: August 22, 2011, 03:17:07 PM »
Hi Mark,

Thanks for your reply. It is working now, able to get what I was looking for.  :)

Wondering, is there is any short and simple method to create Dummy Tasks or any method of that sort of.


Thanks & Regards,
Ab

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: uTasker API
« Reply #7 on: August 22, 2011, 11:17:49 PM »
Ab

What do you mean by dummy tasks?
It is possible to add a number of tasks to the task table which don't actually do anything but I am not sure what this would be good for (?)

Regards

Mark

Offline abhimanyum

  • Newbie
  • *
  • Posts: 24
    • View Profile
    • Ae Applications
Re: uTasker API
« Reply #8 on: August 23, 2011, 12:11:41 AM »
Mark,

Thanks for your reply.
By the term "Dummy Task", I meant task which just run to occupy scheduler ( task with a loop) and System, and then to measure the uTasker on various things.

Since you always have to go and modify "TaskCongif" file, to add task to your RTOS, I was looking for a method/API through which I can create a these type of tasks, or do I have to manually go and add multiple tasks in it.

Cheers,
Ab

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: uTasker API
« Reply #9 on: August 23, 2011, 01:14:11 PM »
Ab

New tasks can only be added in TaskConfig.h.

Regards

Mark

Offline abhimanyum

  • Newbie
  • *
  • Posts: 24
    • View Profile
    • Ae Applications
Re: uTasker API
« Reply #10 on: August 26, 2011, 04:03:16 PM »
Hi Mark,

I'm executing following code as a uTasker task, to fetch the value of h/w timer, as per your specified Macros.

Task Config:

Code: [Select]
{ "1", fnIntroTask, NO_QUE, 10, 1, UTASKER_STOP},
Task Code:

Code: [Select]
long i = 0;
i = EXECUTION_DURATION();
fnDebugDec(i,0,0);

The output I'm getting is a same number again and again, I'm not sure where I'm going wrong, Is there any other way to fetch the Hardware Timer Value.

Thanks a million.

Regards,
Ab

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: uTasker API
« Reply #11 on: August 26, 2011, 10:12:13 PM »
Hi Ab

If you add the code to debug.c (search for MONITOR_PERFORMANCE in that file) you can then request all task information using the "tasks" command. The timing routine is called in uTasker.c (search also for MONITOR_PERFORMANCE in that file) and so you don't need to call it yourself.

The output looks something like this and shows the maximum, average and minimum time that a task needed as well as the amount of times that it has been executed:

#tasks
Task "Wdog" executed 173 times - Task duration [min/av/max] = 0/34086/65415 [Max. at 700 TICKs] - CPU = 33%
Task "ARP" executed 1 times - Task duration [min/av/max] = 1460/1460/1460 [Max. at 5 TICKs] - CPU = 0%
Task "Eth" executed 1 times - Task duration [min/av/max] = 1460/1460/1460 [Max. at 5 TICKs] - CPU = 0%
Task "TCP" executed 35 times - Task duration [min/av/max] = 584/30649/59276 [Max. at 3310 TICKs] - CPU = 6%
Task "app" executed 38 times - Task duration [min/av/max] = 292/32235/64094 [Max. at 3376 TICKs] - CPU = 7%
Task "maintenace" executed 1 times - Task duration [min/av/max] = 16861/16861/16861 [Max. at 10 TICKs] - CPU = 0%
Task "MassSt" executed 4 times - Task duration [min/av/max] = 11714/13000/16861 [Max. at 10 TICKs] - CPU = 0%
Task "DHCP" executed 0 times - Task duration [min/av/max] = 0/0/0 [Max. at 0 TICKs] - CPU = 0%
Task "dNS" executed 1 times - Task duration [min/av/max] = 1460/1460/1460 [Max. at 5 TICKs] - CPU = 0%
Task "SMTP" executed 0 times - Task duration [min/av/max] = 0/0/0 [Max. at 0 TICKs] - CPU = 0%
Task "tFTP" executed 0 times - Task duration [min/av/max] = 0/0/0 [Max. at 0 TICKs] - CPU = 0%
Task "LCD" executed 22 times - Task duration [min/av/max] = 10546/20811/54638 [Max. at 162 TICKs] - CPU = 2%
Task "zero" executed 0 times - Task duration [min/av/max] = 0/0/0 [Max. at 0 TICKs] - CPU = 0%
Total CPU task load = 50% (8725767/8715841/17441608)


Regards

Mark

P.S. The values above were from the simulator - the values are approximate and so don't represent the values obtained on the real HW.

Offline abhimanyum

  • Newbie
  • *
  • Posts: 24
    • View Profile
    • Ae Applications
Re: uTasker API
« Reply #12 on: August 26, 2011, 10:30:29 PM »
Thanks a lot Mark for your support. I do really appreciate that.

Just a sheer curiousity, is there any way to geth the ComStick Hardware Timer Ticks or read ComStick Timer.
If something like this is possible.


Cheers,
Ab

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: uTasker API
« Reply #13 on: August 27, 2011, 10:05:26 PM »
Ab

I don't understand the question.

What is "ComStick Timer"?

There is a TICK counter "uTaskerSystemTick" which is global and so readable by any code.

Regards

Mark

Offline abhimanyum

  • Newbie
  • *
  • Posts: 24
    • View Profile
    • Ae Applications
Re: uTasker API
« Reply #14 on: August 28, 2011, 01:01:49 PM »
Mark,

I think uTaskerSystemTick, will help me.

Thanks,
Ab