source: trunk/kernel/syscalls/sys_trace.c @ 662

Last change on this file since 662 was 637, checked in by alain, 5 years ago

Introduce the non-standard pthread_parallel_create() system call
and re-write the <fft> and <sort> applications to improve the
intrinsic paralelism in applications.

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