changeset 2948:041821fb5427

* kernel/current/src/common/thread.cxx, services/cpuload/current/src/cpuload.cxx: Add volatile to thread_idle_loops for correct operation when built with GCC 4.
author jld
date Mon, 10 May 2010 15:58:36 +0000
parents 9b59569aaea9
children ae816c83f082
files packages/kernel/current/ChangeLog packages/kernel/current/src/common/thread.cxx packages/services/cpuload/current/ChangeLog packages/services/cpuload/current/src/cpuload.cxx
diffstat 4 files changed, 16 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/packages/kernel/current/ChangeLog
+++ b/packages/kernel/current/ChangeLog
@@ -1,3 +1,8 @@
+2010-03-29  Lars Povlsen  <lpovlsen@vitesse.com>
+
+	* src/common/thread.cxx: Add volatile to idle_thread_loops for use with
+	cpuload package and GCC 4.
+
 2010-02-25  John Dallaway  <john@dallaway.org.uk>
 
 	* doc/kernel.sgml: Indicate that cyg_alarm_initialize() takes an
--- a/packages/kernel/current/src/common/thread.cxx
+++ b/packages/kernel/current/src/common/thread.cxx
@@ -1211,7 +1211,7 @@ Cyg_ThreadTimer::alarm(
 #endif // CYGNUM_HAL_STACK_SIZE_MINIMUM
 
 // Loop counter for debugging/housekeeping
-cyg_uint32 idle_thread_loops[CYGNUM_KERNEL_CPU_MAX];
+cyg_uint32 volatile idle_thread_loops[CYGNUM_KERNEL_CPU_MAX];
 
 static char idle_thread_stack[CYGNUM_KERNEL_CPU_MAX][CYGNUM_KERNEL_THREADS_IDLE_STACK_SIZE];
 
--- a/packages/services/cpuload/current/ChangeLog
+++ b/packages/services/cpuload/current/ChangeLog
@@ -1,3 +1,7 @@
+2010-03-29  Lars Povlsen  <lpovlsen@vitesse.com>
+
+	* src/cpuload.cxx: Update idle_thread_loops reference (volatile, array)
+
 2003-02-24  Jonathan Larmour  <jifl@eCosCentric.com>
 
 	* cdl/cpuload.cdl: Add doc link.
--- a/packages/services/cpuload/current/src/cpuload.cxx
+++ b/packages/services/cpuload/current/src/cpuload.cxx
@@ -58,6 +58,7 @@
 #include <cyg/kernel/kapi.h>
 #include <cyg/hal/hal_arch.h> 
 #include <cyg/cpuload/cpuload.h>
+#include <cyg/kernel/sched.hxx>
 
 /* Here we run the idle thread as a high priority thread for 0.1
    second.  We see how much the counter in the idle loop is
@@ -65,7 +66,7 @@
    running at priority 1 and 2 */
 
 static cyg_thread thread;
-externC cyg_uint32 idle_thread_loops;
+externC cyg_uint32 volatile idle_thread_loops[CYGNUM_KERNEL_CPU_MAX];
 char idle_stack[CYGNUM_HAL_STACK_SIZE_MINIMUM];
 
 extern void idle_thread_main( CYG_ADDRESS data );
@@ -108,7 +109,7 @@ cyg_cpuload_calibrate(cyg_uint32  *calib
   cyg_alarm_initialize(alarmH,cyg_current_time()+10,0);
   cyg_alarm_enable(alarmH);
   
-  idle_loops_start = idle_thread_loops;
+  idle_loops_start = idle_thread_loops[CYG_KERNEL_CPU_THIS()];
   
   /* Dont be decieved, remember this is a multithreaded system ! */
   old_priority = cyg_thread_get_priority(cyg_thread_self());
@@ -116,7 +117,7 @@ cyg_cpuload_calibrate(cyg_uint32  *calib
   cyg_thread_resume(idleH);
   cyg_thread_set_priority(cyg_thread_self(),old_priority);
   
-  *calibration = idle_thread_loops - idle_loops_start;
+  *calibration = idle_thread_loops[CYG_KERNEL_CPU_THIS()] - idle_loops_start;
   cyg_alarm_delete(alarmH);
   cyg_thread_kill(idleH);
   cyg_thread_delete(idleH);
@@ -125,7 +126,7 @@ cyg_cpuload_calibrate(cyg_uint32  *calib
 static void 
 cpuload_alarm_func(cyg_handle_t alarm,cyg_addrword_t data) { 
   cyg_cpuload_t * cpuload = (cyg_cpuload_t *)data;
-  cyg_uint32 idle_loops_now = idle_thread_loops;
+  cyg_uint32 idle_loops_now = idle_thread_loops[CYG_KERNEL_CPU_THIS()];
   cyg_uint32 idle_loops;
   cyg_uint32 load;
   
@@ -162,7 +163,7 @@ cyg_cpuload_create(cyg_cpuload_t *cpuloa
   cpuload->average_1s = 0;
   cpuload->average_10s = 0;
   cpuload->calibration = calibration;
-  cpuload->last_idle_loops = idle_thread_loops;
+  cpuload->last_idle_loops = idle_thread_loops[CYG_KERNEL_CPU_THIS()];
 
   cyg_clock_to_counter(cyg_real_time_clock(),&counter);
   cyg_alarm_create(counter,