Ignore:
Timestamp:
May 16, 2018, 4:15:22 PM (4 years ago)
Author:
alain
Message:

Fix few bugs whike debugging the sort multi-thread application.

File:
1 edited

Legend:

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

    r407 r443  
    11/*
    2  * sys_trace.c - show kernel active processes and threads
     2 * sys_trace.c - activate / desactivate the context switches trace for a given core
    33 *
    4  * Author    Alain Greiner (c) (2016,2017)
     4 * Author    Alain Greiner (c) (2016,2017,2018)
    55 *
    66 * Copyright (c) UPMC Sorbonne Universites
     
    2727#include <thread.h>
    2828#include <errno.h>
     29#include <shared_syscalls.h>
    2930#include <syscalls.h>
    3031
    31 //////////////////////////////////
    32 int sys_trace( uint32_t operation,
    33                pid_t    pid,
    34                uint32_t trdid )
     32///////////////////////////////
     33int sys_trace( bool_t   active,
     34               cxy_t    cxy,
     35               lid_t    lid )
    3536{
    36     // get extended pointer on target thread
    37     xptr_t thread_xp = thread_get_xptr( pid , trdid );
     37    uint32_t    ncores;
    3838
    39     if( thread_xp == XPTR_NULL )
     39    thread_t  * this    = CURRENT_THREAD;
     40    process_t * process = this->process;
     41
     42#if DEBUG_SYS_TRACE
     43uint64_t    tm_start;
     44uint64_t    tm_end;
     45tm_start = hal_get_cycles();
     46if( DEBUG_SYS_TRACE < tm_start )
     47printk("\n[DBG] %s : thread %d enter / process %x / cycle = %d\n",
     48__FUNCTION__, this, this->process->pid, (uint32_t)tm_start );
     49#endif
     50
     51    // check cluster identifier
     52    if( cluster_is_undefined( cxy ) )
    4053    {
    41         printk("\n[ERROR] in %s : undefined thread for PID = %x / TRDID = %x\n",
    42                __FUNCTION__ , pid , trdid );
    43         CURRENT_THREAD->errno = EINVAL;
     54
     55#if DEBUG_SYSCALLS_ERROR
     56printk("\n[ERROR] in %s : illegal cxy argument %x / thread %x / process %x\n",
     57__FUNCTION__ , cxy , this->trdid , process->pid );
     58#endif
     59        this->errno = EINVAL;
    4460        return -1;
    4561    }
    4662
    47     if( operation == TRACE_OFF )
     63    // check core local index
     64    ncores = hal_remote_lw( XPTR( cxy , &LOCAL_CLUSTER->cores_nr ) );
     65    if( lid >= ncores )
    4866    {
    49         // desactivate thread trace TODO
    5067
    51             printk("\n[DBG] %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[DBG] %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;
     68#if DEBUG_SYSCALLS_ERROR
     69printk("\n[ERROR] in %s : illegal lid argument %x / thread %x / process %x\n",
     70__FUNCTION__ , lid , this->trdid , process->pid );
     71#endif
     72        this->errno = EINVAL;
    6573        return -1;
    6674    }
    6775
     76    // get local pointer on target core
     77    core_t * core = &LOCAL_CLUSTER->core_tbl[lid];
     78
     79    // get extended pointer on target scheduler trace field
     80    xptr_t trace_xp = XPTR( cxy , &core->scheduler.trace );
     81
     82    if ( active ) hal_remote_sw( trace_xp , 1 );
     83    else          hal_remote_sw( trace_xp , 0 );
     84   
    6885    hal_fence();
     86
     87#if DEBUG_SYS_TRACE
     88tm_end = hal_get_cycles();
     89if( DEBUG_SYS_TRACE < tm_end )
     90printk("\n[DBG] %s : thread %x exit / process %x / cost = %d / cycle %d\n",
     91__FUNCTION__, this, this->process->pid, (uint32_t)(tm_end - tm_start) , (uint32_t)tm_end );
     92#endif
    6993
    7094    return 0;
Note: See TracChangeset for help on using the changeset viewer.