Index: trunk/kernel/kern/thread.c
===================================================================
--- trunk/kernel/kern/thread.c	(revision 1)
+++ trunk/kernel/kern/thread.c	(revision 5)
@@ -8,11 +8,11 @@
  * Copyright (c) UPMC Sorbonne Universites
  *
- * This file is part of ALMOS-MKH..
+ * This file is part of ALMOS-MKH.
  *
- * ALMOS-MKH. is free software; you can redistribute it and/or modify it
+ * ALMOS-MKH is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License as published by
  * the Free Software Foundation; version 2.0 of the License.
  *
- * ALMOS-MKH. is distributed in the hope that it will be useful, but
+ * ALMOS-MKH is distributed in the hope that it will be useful, but
  * WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
@@ -20,5 +20,5 @@
  *
  * You should have received a copy of the GNU General Public License
- * along with ALMOS-MKH.; if not, write to the Free Software Foundation,
+ * along with ALMOS-MKH; if not, write to the Free Software Foundation,
  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  */
@@ -62,4 +62,17 @@
 };
 
+//////////////////////////////////////////////////////////////////////////////////////
+// This static function returns a printable string for the thread type.
+//////////////////////////////////////////////////////////////////////////////////////
+char * thread_type_str( uint32_t type )
+{
+    if     ( type == THREAD_USER   ) return "THREAD_USER";
+    else if( type == THREAD_RPC    ) return "THREAD_RPC";
+    else if( type == THREAD_DEV    ) return "THREAD_DEV";
+    else if( type == THREAD_KERNEL ) return "THREAD_KERNEL";
+    else if( type == THREAD_IDLE   ) return "THREAD_IDLE";
+    else                             return "undefined";
+}
+
 /////////////////////////////////////////////////////////////////////////////////////
 // This static function makes the actual allocation and initialisation for a thread
@@ -76,12 +89,12 @@
 // @ core_lid   : target core local index.
 /////////////////////////////////////////////////////////////////////////////////////
-static error_t __thread_create( thread_t     ** new_thread,
-                                process_t     * process,
-                                thread_type_t   type,
-                                void          * func,
-                                void          * args,
-                                lid_t           core_lid,
-                                intptr_t        u_stack_base,
-                                uint32_t        u_stack_size )
+static error_t thread_create( thread_t     ** new_thread,
+                              process_t     * process,
+                              thread_type_t   type,
+                              void          * func,
+                              void          * args,
+                              lid_t           core_lid,
+                              intptr_t        u_stack_base,
+                              uint32_t        u_stack_size )
 {
     error_t        error;
@@ -171,5 +184,5 @@
     *new_thread = thread;
 	return 0;
-} // end __thread_create()
+} // end thread_create()
 
 
@@ -185,4 +198,7 @@
     lid_t          core_lid;     // selected core local index
 
+    thread_dmsg("\n[INFO] %s : enters\n", 
+                __FUNCTION__ );
+
 	cluster_t    * local_cluster = LOCAL_CLUSTER;
 
@@ -199,12 +215,12 @@
 
     // make allocation / initialisation
-    error = __thread_create( &thread,
-                             process,
-                             THREAD_USER,
-                             attr->entry_func,
-                             attr->entry_args,
-                             core_lid,
-                             u_stack_base,
-                             u_stack_size );
+    error = thread_create( &thread,
+                           process,
+                           THREAD_USER,
+                           attr->entry_func,
+                           attr->entry_args,
+                           core_lid,
+                           u_stack_base,
+                           u_stack_size );
     if( error ) return ENOMEM;
 
@@ -220,7 +236,7 @@
     error = hal_fpu_context_create( thread ); 
     if( error ) return ENOMEM;
-
-    thread_dmsg("INFO : %s thread %x for process %x on core %d in cluster %x\n", 
-                 __FUNCTION__, thread->trdid, process->pid, core_lid, local_cluster->cxy );
+  
+    thread_dmsg("\n[INFO] %s : exit / trdid = %x / process %x / core = %d\n", 
+                __FUNCTION__ , thread->trdid , process->pid , core_lid );
 
     *new_thread = thread;
@@ -239,4 +255,7 @@
     lid_t          core_lid;     // selected core local index
 
+    thread_dmsg("\n[INFO] %s : enters\n", 
+                __FUNCTION__ );
+
     // select a target core in local cluster
     core_lid = cluster_select_local_core();
@@ -246,12 +265,12 @@
 
     // make allocation / initialisation
-    error = __thread_create( &new,
-                             process,
-                             THREAD_USER,
-                             this->entry_func,
-                             this->entry_args,
-                             core_lid,
-                             u_stack_base,
-                             u_stack_size );
+    error = thread_create( &new,
+                           process,
+                           THREAD_USER,
+                           this->entry_func,
+                           this->entry_args,
+                           core_lid,
+                           u_stack_base,
+                           u_stack_size );
     if( error ) return ENOMEM;
 
@@ -268,8 +287,9 @@
 
     thread_dmsg("INFO : %s thread %x for process %x on core %d in cluster %x\n", 
-                 __FUNCTION__, new->trdid, process->pid, core_lid, local_cluster->cxy );
+                 __FUNCTION__, new->trdid, process->pid, core_lid, local_cxy );
 
     *new_thread = new;
 	return 0;
+
 } // end thread_user_fork()
 
@@ -286,33 +306,26 @@
 	thread_t     * new;        // pointer on new thread descriptor
 
-    cluster_t    * local_cluster = LOCAL_CLUSTER;
-
-    // check type argument
-    if( (type != THREAD_KERNEL) && (type != THREAD_RPC) && 
-        (type != THREAD_IDLE) && (type != THREAD_DEV) )
-    {
-        printk("ERROR : %s received an illegal thread type\n", __FUNCTION__ );
-        hal_core_sleep();
-    }
-
-    // check core local index
-    if( core_lid >= local_cluster->cores_nr )
-    {
-        printk("ERROR : %s received an illegal core_lid\n", __FUNCTION__ );
-        hal_core_sleep();
-    }
+    thread_dmsg("\n[INFO] %s : enters for %s in cluster %x\n",
+                __FUNCTION__ , thread_type_str( type ) , local_cxy );
+
+    assert( ( (type == THREAD_KERNEL) || (type == THREAD_RPC) || 
+              (type == THREAD_IDLE)   || (type == THREAD_DEV) ) ,
+              __FUNCTION__ , "illegal thread type" );
+
+    assert( (core_lid < LOCAL_CLUSTER->cores_nr) , 
+            __FUNCTION__ , "illegal core_lid" );
 
     // make allocation / initialisation
-    error = __thread_create( &new,
-                             &process_zero,
-                             type,
-                             func,
-                             args,
-                             core_lid,
-                             0 , 0 );  // no user stack for a kernel thread
+    error = thread_create( &new,
+                           &process_zero,
+                           type,
+                           func,
+                           args,
+                           core_lid,
+                           0 , 0 );  // no user stack for a kernel thread
     if( error ) 
     {
-        printk("ERROR : %s cannot create thread\n", __FUNCTION__ );
-        hal_core_sleep();
+        printk("\n[ERROR] in %s : cannot create thread\n", __FUNCTION__ );
+        return ENOMEM;
     }
 
@@ -320,9 +333,10 @@
 	hal_cpu_context_create( new ); 
 
-    thread_dmsg("INFO : %s thread %x in cluster %x on core %d\n", 
-                 __FUNCTION__ , new->trdid , local_cluster->cxy , core_lid );
+    thread_dmsg("\n[INFO] %s : sucessfully exit / trdid = %x / core = %d\n", 
+                 __FUNCTION__ , new->trdid , core_lid );
 
     *new_thread = new; 
 	return 0;
+
 } // end thread_kernel_create()
 
@@ -341,20 +355,13 @@
     core_t     * core       = thread->core;
 
-    if( thread->children_nr )
-    {
-        printk("\n[PANIC] in %s : thread %x for process %x on core %d in cluster %x"
-               " has still attached children\n",
-               __FUNCTION__, thread->trdid, process->pid, core->lid, local_cxy );
-        hal_core_sleep();
-    }
-
-    if( (thread->local_locks != 0) || (thread->remote_locks != 0) )
-    {
-        printk("\n[PANIC] in %s : thread %x for process %x on core %d in cluster %x"
-               " did not released all locks\n",
-               __FUNCTION__, thread->trdid, process->pid, core->lid, local_cxy );
-        hal_core_sleep();
-    }
+    thread_dmsg("\n[INFO] %s : enters for thread %x in process %x / type = %s\n",
+                __FUNCTION__ , thread->trdid , process->pid , thread_type_str( thread->type ) );
+
+    assert( (thread->children_nr == 0) , __FUNCTION__ , "still attached children" );
+
+    assert( (thread->local_locks == 0) , __FUNCTION__ , "all local locks not released" );
     
+    assert( (thread->remote_locks == 0) , __FUNCTION__ , "all remote locks not released" );
+
 	tm_start = hal_time_stamp();
 
@@ -402,8 +409,6 @@
 	tm_end = hal_time_stamp();
 
-	thread_dmsg("INFO : %s destroy thread %x for process %x on core %d in cluster %x\n"
-                 " / duration = %d / page_faults = %d / ticks = %d\n",
-	               __FUNCTION__, trdid , pid , core_lid , local_cxy ,
-	               tm_end - tm_start , pgfaults , ticks );
+	thread_dmsg("\n[INFO] %s : exit for thread %x in process %x / duration = %d\n",
+	               __FUNCTION__, thread->trdid , process->pid , tm_end - tm_start );
 
 }  // end thread_destroy()
@@ -592,12 +597,12 @@
     while( 1 )
     {
-        thread_dmsg("INFO : core %d in cluster %x goes to sleeping state at cycle\n",
-                     core->lid , cluster->cxy, hal_time_stamp() );
+        thread_dmsg("\n[INFO] %s : core %d in cluster %x goes to sleeping state at cycle\n",
+                    __FUNCTION__ , core->lid , local_cxy , hal_time_stamp() );
 
         // force core to sleeping state
         hal_core_sleep();
 
-        thread_dmsg("INFO : core %d in cluster %x wake up at cycle %d\n",
-                     core->lid , cluster->cxy, hal_time_stamp() );
+        thread_dmsg("\n[INFO] %s : core %d in cluster %x wake up at cycle %d\n",
+                    __FUNCTION__ , core->lid , local_cxy , hal_time_stamp() );
 
         // force scheduling at wake-up
