Bug fix - runtime statistics collection

philpem wrote on Wednesday, August 14, 2013:

Hi,

There appears to be a bug in FreeRTOS 7.5.2’s tasks.c.

If a FreeRTOS application enables runtime statistics and defines the portALT_GET_RUN_TIME_COUNTER_VALUE macro but does not provide the portGET_RUN_TIME_COUNTER_VALUE function, tasks.c will fail to link (or possibly fail to compile at all, depending on compiler warning/error promotion options).

To fix this, replace the following code block in tasks.c:

				#if ( configGENERATE_RUN_TIME_STATS == 1)
				{
					if( pulTotalRunTime != NULL )
					{
						*pulTotalRunTime = portGET_RUN_TIME_COUNTER_VALUE();
					}
				}
				#else

With this:

				#if ( configGENERATE_RUN_TIME_STATS == 1)
				{
					if( pulTotalRunTime != NULL )
					{
					#ifdef portALT_GET_RUN_TIME_COUNTER_VALUE
						portALT_GET_RUN_TIME_COUNTER_VALUE( *pulTotalRunTime );
					#else
						*pulTotalRunTime = portGET_RUN_TIME_COUNTER_VALUE();
					#endif
					}
				}
				#else

Thanks,
Phil.

philpem wrote on Wednesday, August 14, 2013:

Just had a dig through SVN. Looks like this was introduced in rev 1960 (FreeRTOS 7.4.2 probably didn’t have this bug, but 7.5.0 certainly did):

http://freertos.svn.sourceforge.net/viewvc/freertos/trunk/FreeRTOS/Source/tasks.c?r1=1959&r2=1960&

The proverbial “smoking gun” is at Line 1489. Note that rev 1959 contains an ifdef to check whether the portALT_GET_RUN_TIME_COUNTER_VALUE macro is declared and uses the aforementioned macro if it is. Failing that, it falls back to using portGET_RUN_TIME_COUNTER_VALUE. The replacement code on the right (line 1491 onwards) does not contain this ifdef and thus introduces a bug.

rtel wrote on Wednesday, August 14, 2013:

Thank you for taking the time to report this.

I have committed the fix to SVN and added a note with a link to the fix in the “known issues” list.

Regards.