Index: trunk/kernel/syscalls/sys_kill.c
===================================================================
--- trunk/kernel/syscalls/sys_kill.c	(revision 566)
+++ trunk/kernel/syscalls/sys_kill.c	(revision 584)
@@ -35,13 +35,27 @@
 #include <syscalls.h>
 
+
+#if DEBUG_SYS_KILL
+////////////////////////////////////////////
+static char* sig_type_str( uint32_t sig_id )
+{
+    switch( sig_id )
+    {
+        case SIGKILL: return "SIGKILL";
+        case SIGSTOP: return "SIGSTOP";
+        case SIGCONT: return "SIGCONT";
+        default:      return "undefined";
+    }
+}
+#endif
+
+
 ///////////////////////////
 int sys_kill( pid_t    pid,
               uint32_t sig_id )
 {
-    reg_t       save_sr;           // required to enable IRQs
     xptr_t      owner_xp;          // extended pointer on process in owner cluster
     cxy_t       owner_cxy;         // process owner cluster
     process_t * owner_ptr;         // local pointer on process in owner cluster
-    uint32_t    retval;            // return value for the switch
     xptr_t      parent_xp;         // extended pointer on parent process
     cxy_t       parent_cxy;        // parent process cluster
@@ -53,11 +67,14 @@
     process_t * process = this->process;
 
+#if (DEBUG_SYS_KILL || CONFIG_INSTRUMENTATION_SYSCALLS)
+uint64_t     tm_start = hal_get_cycles();
+#endif
+
 #if DEBUG_SYS_KILL
-uint64_t    tm_start;
-uint64_t    tm_end;
 tm_start = hal_get_cycles();
 if( DEBUG_SYS_KILL < tm_start )
-printk("\n[DBG] %s : thread %x enter / process %x / sig %d / cycle %d\n",
-__FUNCTION__ , this, pid, sig_id, (uint32_t)tm_start );
+printk("\n[DBG] %s : thread[%x,%x] enter / process %x / %s / cycle %d\n",
+__FUNCTION__, this->process->pid, this->trdid, pid,
+sig_type_str(sig_id), (uint32_t)tm_start );
 #endif
 
@@ -69,6 +86,6 @@
 #if (DEBUG_SYS_KILL & 1)
 if( DEBUG_SYS_KILL < tm_start )
-printk("\n[DBG] %s : thread %x get owner process %x in cluster %x\n",
-__FUNCTION__ , this, owner_ptr, owner_cxy );
+printk("\n[DBG] %s : thread[%x,%x] get owner process %x in cluster %x\n",
+__FUNCTION__ , this->process->pid, this->trdid, owner_ptr, owner_cxy );
 #endif
 
@@ -81,26 +98,4 @@
 #endif
         this->errno = EINVAL;
-        return -1;
-    }
-
-    // process cannot kill itself
-    if( (pid == process->pid) ) 
-    {
-
-#if DEBUG_SYSCALLS_ERROR
-printk("\n[ERROR] in %s : process %x cannot kill itself\n", __FUNCTION__, pid );
-#endif
-        this->errno = EINVAL;
-        return -1;
-    }
-
-    // processe INIT cannot be killed
-    if( pid == 1 )
-    {
-
-#if DEBUG_SYSCALLS_ERROR
-printk("\n[ERROR] in %s : process_init cannot be killed\n", __FUNCTION__ );
-#endif
-		this->errno = EINVAL;
         return -1;
     }
@@ -113,6 +108,6 @@
 #if (DEBUG_SYS_KILL & 1)
 if( DEBUG_SYS_KILL < tm_start )
-printk("\n[DBG] %s : thread %x get parent process %x in cluster %x\n",
-__FUNCTION__ , this, parent_ptr, parent_cxy );
+printk("\n[DBG] %s : thread[%x,%x] get parent process %x in cluster %x\n",
+__FUNCTION__ , this->process->pid, this->trdid, parent_ptr, parent_cxy );
 #endif
 
@@ -126,18 +121,10 @@
         case 0 :          // does nothing
         {
-            retval = 0;
             break;
         }
         case SIGSTOP:     // block all target process threads
         {
-            // transfer TXT ownership 
-            process_txt_transfer_ownership( owner_xp );
-
-            // block all threads in all clusters, but the main thread
+            // block all threads in all clusters
             process_sigaction( pid , BLOCK_ALL_THREADS );
-
-            // block the main thread
-            xptr_t main_xp = XPTR( owner_cxy , &owner_ptr->th_tbl[0] );
-            thread_block( main_xp , THREAD_BLOCKED_GLOBAL );
 
             // atomically update owner process termination state
@@ -145,8 +132,7 @@
                                   PROCESS_TERM_STOP );
 
-            // unblock the parent process main thread 
+            // unblock the parent process main thread
             thread_unblock( parent_main_xp , THREAD_BLOCKED_WAIT );
 
-            retval = 0;
             break;
         }
@@ -159,17 +145,39 @@
             hal_remote_atomic_and( XPTR( owner_cxy , &owner_ptr->term_state ) ,
                                    ~PROCESS_TERM_STOP );
-            retval = 0;
-            break;
-        }
-        break;
+
+            // unblock the parent process main thread 
+            thread_unblock( parent_main_xp , THREAD_BLOCKED_WAIT );
+
+            break;
+        }
         case SIGKILL:
         {
+            // a process cannot kill itself
+            if( (pid == process->pid) ) 
+            {
+
+#if DEBUG_SYSCALLS_ERROR
+printk("\n[ERROR] in %s : process %x cannot kill itself\n", __FUNCTION__, pid );
+#endif
+                this->errno = EINVAL;
+                return -1;
+            }
+
+            // processe INIT cannot be killed
+            if( pid == 1 )
+            {
+
+#if DEBUG_SYSCALLS_ERROR
+printk("\n[ERROR] in %s : process_init cannot be killed\n", __FUNCTION__ );
+#endif
+		        this->errno = EINVAL;
+                return -1;
+            }
+
             // remove process from TXT list
             process_txt_detach( owner_xp );
 
             // mark for delete all threads in all clusters, but the main 
-            hal_enable_irq( &save_sr );
             process_sigaction( pid , DELETE_ALL_THREADS );
-            hal_restore_irq( save_sr );
 
             // block main thread
@@ -185,5 +193,4 @@
             thread_unblock( parent_main_xp , THREAD_BLOCKED_WAIT );
 
-            retval = 0;
             break;
         }
@@ -195,6 +202,5 @@
 #endif
     	    this->errno = EINVAL;
-            retval = -1;
-            break;
+            return -1;
         }
     }
@@ -202,12 +208,21 @@
     hal_fence();
 
+#if (DEBUG_SYS_KILL || CONFIG_INSTRUMENTATION_SYSCALLS)
+uint64_t     tm_end = hal_get_cycles();
+#endif
+
 #if DEBUG_SYS_KILL
-tm_end = hal_get_cycles();
 if( DEBUG_SYS_KILL < tm_end )
-printk("\n[DBG] %s : thread %x exit / process %x / sig %d / cost = %d / cycle %d\n",
-__FUNCTION__ , this, pid, sig_id, (uint32_t)(tm_end - tm_start), (uint32_t)tm_end );
-#endif
-
-	return retval;
+printk("\n[DBG] %s : thread[%x,%x] exit / process %x / %s / cost = %d / cycle %d\n",
+__FUNCTION__ , this->process->pid, this->trdid, pid,
+sig_type_str(sig_id), (uint32_t)(tm_end - tm_start), (uint32_t)tm_end );
+#endif
+
+#if CONFIG_INSTRUMENTATION_SYSCALLS
+hal_atomic_add( &syscalls_cumul_cost[SYS_KILL] , tm_end - tm_start );
+hal_atomic_add( &syscalls_occurences[SYS_KILL] , 1 );
+#endif
+
+	return 0;
 
 }  // end sys_kill()
