Changeset 23 for trunk/kernel/syscalls/sys_trace.c
- Timestamp:
- Jun 18, 2017, 10:06:41 PM (6 years ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/syscalls/sys_trace.c
r15 r23 1 1 /* 2 * kern/sys_ps.c - show kernel active processes and threads2 * sys_trace.c - show kernel active processes and threads 3 3 * 4 * Copyright (c) 2008,2009,2010,2011,2012 Ghassan Almaless 5 * Copyright (c) 2011,2012,2013,2014,2015 UPMC Sorbonne Universites 4 * Author Alain Greiner (c) (2016,2017) 6 5 * 7 * This file is part of ALMOS-kernel.6 * Copyright (c) UPMC Sorbonne Universites 8 7 * 9 * ALMOS-kernel is free software; you can redistribute it and/or modify it 8 * This file is part of ALMOS-MKH. 9 * 10 * ALMOS-MKH is free software; you can redistribute it and/or modify it 10 11 * under the terms of the GNU General Public License as published by 11 12 * the Free Software Foundation; version 2.0 of the License. 12 13 * 13 * ALMOS- kernelis distributed in the hope that it will be useful, but14 * ALMOS-MKH is distributed in the hope that it will be useful, but 14 15 * WITHOUT ANY WARRANTY; without even the implied warranty of 15 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU … … 17 18 * 18 19 * You should have received a copy of the GNU General Public License 19 * along with ALMOS- kernel; if not, write to the Free Software Foundation,20 * along with ALMOS-MKH; if not, write to the Free Software Foundation, 20 21 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 22 */ 22 23 23 #include < types.h>24 #include < task.h>25 #include <p id.h>24 #include <hal_types.h> 25 #include <hal_special.h> 26 #include <printk.h> 26 27 #include <thread.h> 27 #include <vmm.h>28 28 #include <errno.h> 29 #include <utils.h> 30 #include <rpc.h> 31 #include <cluster.h> 29 #include <syscalls.h> 32 30 33 extern error_t ps_func(void *param); 31 ////////////////////////////////// 32 int sys_trace( uint32_t operation, 33 pid_t pid, 34 uint32_t trdid ) 35 { 36 // get extended pointer on target thread 37 xptr_t thread_xp = thread_get_xptr( pid , trdid ); 34 38 35 /* TODO: add remote support. */ 36 static error_t sys_ps_check_thread(pid_t pid, uint_t tid, struct thread_s **th_ptr) 37 { 38 struct task_s *task; 39 struct thread_s *thread; 40 cid_t location; 39 if( thread_xp == XPTR_NULL ) 40 { 41 printk("\n[ERROR] in %s : undefined thread for PID = %x / TRDID = %x\n", 42 __FUNCTION__ , pid , trdid ); 43 CURRENT_THREAD->errno = EINVAL; 44 return -1; 45 } 41 46 42 if(pid == PID_MIN_LOCAL) 43 return EINVAL; 47 if( operation == TRACE_OFF ) 48 { 49 // desactivate thread trace TODO 44 50 45 location = task_whereis(pid); 51 printk("\n[INFO] %s : trace OFF for thread %x in process %x\n", 52 __FUNCTION__ , trdid , pid ); 53 } 54 else if( operation == TRACE_ON ) 55 { 56 // activate thread trace TODO 57 58 printk("\n[INFO] %s : trace ON for thread %x in process %x\n", 59 __FUNCTION__ , trdid , pid ); 60 } 61 else 62 { 63 printk("\n[ERROR] in %s : undefined operation\n", __FUNCTION__ ); 64 CURRENT_THREAD->errno = EINVAL; 65 return -1; 66 } 46 67 47 tasks_manager_lock(); 48 if ( location == current_cid ) 49 { 50 task = task_lookup(pid)->task; 68 hal_wbflush(); 51 69 52 if((task == NULL) || (tid > task->max_order)) 53 return EINVAL; 70 return 0; 54 71 55 thread = task->th_tbl[tid]; 56 57 if((thread == NULL) || 58 (thread->signature != THREAD_ID) || 59 (thread->info.attr.key != tid)) 60 { 61 return ESRCH; 62 } 63 64 *th_ptr = thread; 65 return 0; 66 } 67 else 68 { 69 printk(WARNING, "%s: cluster %u can't execute this function on remote task (pid %u on cluster %u)\n", \ 70 __FUNCTION__, current_cid, pid, location); 71 return ENOSYS; 72 } 73 tasks_manager_unlock(); 74 } 75 76 /*TODO: use RPC_ARG_NULL instead of sending a useless variable. 77 * It's not urgent, it's a minor change. 78 */ 79 RPC_DECLARE(__ps_func, \ 80 RPC_RET( RPC_RET_PTR(error_t, err) ), \ 81 RPC_ARG( RPC_ARG_PTR(error_t, foo) ) \ 82 ) 83 { 84 *err = ps_func(NULL); 85 } 86 87 int sys_ps(uint_t cmd, pid_t pid, uint_t tid) 88 { 89 cid_t next; 90 error_t err; 91 struct thread_s *thread; 92 struct kernel_iter_s *kernel_iter; 93 94 err = 0; 95 96 switch(cmd) 97 { 98 case TASK_PS_TRACE_OFF: 99 err = sys_ps_check_thread(pid, tid, &thread); 100 if(err) goto fail_trace_off; 101 thread->info.isTraced = false; 102 cpu_wbflush(); 103 printk(INFO,"INFO: pid %d, tid %x, tracing is turned [OFF]\n", pid, tid); 104 break; 105 106 case TASK_PS_TRACE_ON: 107 err = sys_ps_check_thread(pid, tid, &thread); 108 if(err) goto fail_trace_on; 109 thread->info.isTraced = true; 110 cpu_wbflush(); 111 printk(INFO,"INFO: pid %d, tid %x, tracing is turned [ON]\n", pid, tid); 112 break; 113 114 case TASK_PS_SHOW: 115 kernel_foreach_backward(kernel_iter, next) 116 { 117 RCPC( next, RPC_PRIO_PS, __ps_func, 118 RPC_RECV( RPC_RECV_OBJ(err) ), 119 RPC_SEND( RPC_SEND_OBJ(err) ) 120 ); 121 } 122 break; 123 } 124 125 fail_trace_on: 126 fail_trace_off: 127 current_thread->info.errno = err; 128 return err; 129 } 72 } // end sys_trace()
Note: See TracChangeset
for help on using the changeset viewer.