[1] | 1 | /* |
---|
[443] | 2 | * sys_trace.c - activate / desactivate the context switches trace for a given core |
---|
[1] | 3 | * |
---|
[637] | 4 | * Author Alain Greiner (c) (2016,2017,2018,2019) |
---|
[1] | 5 | * |
---|
[23] | 6 | * Copyright (c) UPMC Sorbonne Universites |
---|
[1] | 7 | * |
---|
[23] | 8 | * This file is part of ALMOS-MKH. |
---|
| 9 | * |
---|
| 10 | * ALMOS-MKH is free software; you can redistribute it and/or modify it |
---|
[1] | 11 | * under the terms of the GNU General Public License as published by |
---|
| 12 | * the Free Software Foundation; version 2.0 of the License. |
---|
| 13 | * |
---|
[23] | 14 | * ALMOS-MKH is distributed in the hope that it will be useful, but |
---|
[1] | 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
| 17 | * General Public License for more details. |
---|
| 18 | * |
---|
| 19 | * You should have received a copy of the GNU General Public License |
---|
[23] | 20 | * along with ALMOS-MKH; if not, write to the Free Software Foundation, |
---|
[1] | 21 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
| 22 | */ |
---|
| 23 | |
---|
[457] | 24 | #include <hal_kernel_types.h> |
---|
[23] | 25 | #include <hal_special.h> |
---|
| 26 | #include <printk.h> |
---|
[1] | 27 | #include <thread.h> |
---|
| 28 | #include <errno.h> |
---|
[443] | 29 | #include <shared_syscalls.h> |
---|
[23] | 30 | #include <syscalls.h> |
---|
[1] | 31 | |
---|
[443] | 32 | /////////////////////////////// |
---|
| 33 | int sys_trace( bool_t active, |
---|
| 34 | cxy_t cxy, |
---|
| 35 | lid_t lid ) |
---|
[1] | 36 | { |
---|
[443] | 37 | uint32_t ncores; |
---|
[1] | 38 | |
---|
[443] | 39 | thread_t * this = CURRENT_THREAD; |
---|
| 40 | |
---|
[670] | 41 | #if DEBUG_SYS_TRACE || DEBUG_SYSCALLS_ERROR || CONFIG_INSTRUMENTATION_SYSCALLS |
---|
| 42 | process_t * process = this->process; |
---|
| 43 | uint64_t tm_start = hal_get_cycles(); |
---|
[637] | 44 | #endif |
---|
| 45 | |
---|
[443] | 46 | #if DEBUG_SYS_TRACE |
---|
| 47 | if( DEBUG_SYS_TRACE < tm_start ) |
---|
[637] | 48 | printk("\n[%s] thread[%x,%x] enters / cycle = %d\n", |
---|
| 49 | __FUNCTION__, this->process->pid, this->trdid, (uint32_t)tm_start ); |
---|
[443] | 50 | #endif |
---|
| 51 | |
---|
| 52 | // check cluster identifier |
---|
[637] | 53 | if( cluster_is_active( cxy ) == false ) |
---|
[23] | 54 | { |
---|
[443] | 55 | |
---|
| 56 | #if DEBUG_SYSCALLS_ERROR |
---|
[670] | 57 | if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start ) |
---|
| 58 | printk("\n[ERROR] in %s : thread[%x,%x] / illegal cxy argument %x\n", |
---|
| 59 | __FUNCTION__ , this->trdid , process->pid , cxy ); |
---|
[443] | 60 | #endif |
---|
| 61 | this->errno = EINVAL; |
---|
[23] | 62 | return -1; |
---|
| 63 | } |
---|
[1] | 64 | |
---|
[443] | 65 | // check core local index |
---|
[566] | 66 | ncores = hal_remote_l32( XPTR( cxy , &LOCAL_CLUSTER->cores_nr ) ); |
---|
[443] | 67 | if( lid >= ncores ) |
---|
[23] | 68 | { |
---|
[1] | 69 | |
---|
[443] | 70 | #if DEBUG_SYSCALLS_ERROR |
---|
[670] | 71 | if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start ) |
---|
| 72 | printk("\n[ERROR] in %s : thread[%x,%x] / illegal lid argument %x\n", |
---|
| 73 | __FUNCTION__ , this->trdid , process->pid , lid ); |
---|
[443] | 74 | #endif |
---|
| 75 | this->errno = EINVAL; |
---|
[23] | 76 | return -1; |
---|
| 77 | } |
---|
[1] | 78 | |
---|
[443] | 79 | // get local pointer on target core |
---|
| 80 | core_t * core = &LOCAL_CLUSTER->core_tbl[lid]; |
---|
| 81 | |
---|
| 82 | // get extended pointer on target scheduler trace field |
---|
| 83 | xptr_t trace_xp = XPTR( cxy , &core->scheduler.trace ); |
---|
| 84 | |
---|
[566] | 85 | if ( active ) hal_remote_s32( trace_xp , 1 ); |
---|
| 86 | else hal_remote_s32( trace_xp , 0 ); |
---|
[443] | 87 | |
---|
[124] | 88 | hal_fence(); |
---|
[1] | 89 | |
---|
[637] | 90 | #if (DEBUG_SYS_TRACE || CONFIG_INSTRUMENTATION_SYSCALLS) |
---|
| 91 | uint64_t tm_end = hal_get_cycles(); |
---|
| 92 | #endif |
---|
| 93 | |
---|
[443] | 94 | #if DEBUG_SYS_TRACE |
---|
| 95 | if( DEBUG_SYS_TRACE < tm_end ) |
---|
[637] | 96 | printk("\n[%s] thread[%x,%x] exit / cycle %d\n", |
---|
| 97 | __FUNCTION__, this->process->pid, this->trdid, (uint32_t)tm_end ); |
---|
[443] | 98 | #endif |
---|
| 99 | |
---|
[637] | 100 | #if CONFIG_INSTRUMENTATION_SYSCALLS |
---|
| 101 | hal_atomic_add( &syscalls_cumul_cost[SYS_TRACE] , tm_end - tm_start ); |
---|
| 102 | hal_atomic_add( &syscalls_occurences[SYS_TRACE] , 1 ); |
---|
| 103 | #endif |
---|
[670] | 104 | |
---|
[23] | 105 | return 0; |
---|
[1] | 106 | |
---|
[23] | 107 | } // end sys_trace() |
---|