Ignore:
Timestamp:
Jun 18, 2017, 10:06:41 PM (5 years ago)
Author:
alain
Message:

Introduce syscalls.

File:
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/kernel/syscalls/sys_trace.c

    r15 r23  
    11/*
    2  * kern/sys_ps.c - show kernel active processes and threads
     2 * sys_trace.c - show kernel active processes and threads
    33 *
    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)
    65 *
    7  * This file is part of ALMOS-kernel.
     6 * Copyright (c) UPMC Sorbonne Universites
    87 *
    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
    1011 * under the terms of the GNU General Public License as published by
    1112 * the Free Software Foundation; version 2.0 of the License.
    1213 *
    13  * ALMOS-kernel is distributed in the hope that it will be useful, but
     14 * ALMOS-MKH is distributed in the hope that it will be useful, but
    1415 * WITHOUT ANY WARRANTY; without even the implied warranty of
    1516 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     
    1718 *
    1819 * 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,
    2021 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
    2122 */
    2223
    23 #include <types.h>
    24 #include <task.h>
    25 #include <pid.h>
     24#include <hal_types.h>
     25#include <hal_special.h>
     26#include <printk.h>
    2627#include <thread.h>
    27 #include <vmm.h>
    2828#include <errno.h>
    29 #include <utils.h>
    30 #include <rpc.h>
    31 #include <cluster.h>
     29#include <syscalls.h>
    3230
    33 extern error_t ps_func(void *param);
     31//////////////////////////////////
     32int 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 );
    3438
    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    }
    4146
    42         if(pid == PID_MIN_LOCAL)
    43                 return EINVAL;
     47    if( operation == TRACE_OFF )
     48    {
     49        // desactivate thread trace TODO
    4450
    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    }
    4667
    47         tasks_manager_lock();
    48         if ( location == current_cid )
    49         {
    50                 task = task_lookup(pid)->task;
     68    hal_wbflush();
    5169
    52                 if((task == NULL) || (tid > task->max_order))
    53                         return EINVAL;
     70    return 0;
    5471
    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.