source: trunk/kernel/syscalls/sys_display.c @ 584

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

Introduce sys_place_fork() function.

File size: 7.9 KB
RevLine 
[421]1/*
2 * sys_display.c - display the current state of a kernel structure on TXT0
3 *
[440]4 * Author    Alain Greiner (2016,2017,2018)
[421]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
[457]24#include <hal_kernel_types.h>
[421]25#include <hal_uspace.h>
26#include <errno.h>
[433]27#include <vmm.h>
[421]28#include <cluster.h>
29#include <thread.h>
30#include <process.h>
[433]31#include <string.h>
[443]32#include <shared_syscalls.h>
[421]33
[506]34#include <syscalls.h>
35
[443]36/////////////////////////////////////////////////////////////////////////////////
37// This static function returns a printable string for the type of display.
38/////////////////////////////////////////////////////////////////////////////////
[421]39
[443]40#if DEBUG_SYS_DISPLAY
41static char* display_type_str( uint32_t type )
42{
43    if     ( type == DISPLAY_STRING            ) return "STRING"; 
44    else if( type == DISPLAY_VMM               ) return "VMM"; 
45    else if( type == DISPLAY_SCHED             ) return "SCHED"; 
46    else if( type == DISPLAY_CLUSTER_PROCESSES ) return "CLUSTER_PROCESSES"; 
47    else if( type == DISPLAY_VFS               ) return "VFS"; 
48    else if( type == DISPLAY_CHDEV             ) return "CHDEV"; 
49    else if( type == DISPLAY_TXT_PROCESSES     ) return "TXT_PROCESSES"; 
[580]50    else if( type == DISPLAY_DQDT              ) return "DQDT";
51    else if( type == DISPLAY_BUSYLOCKS         ) return "BUSYLOCKS"; 
[443]52}
53#endif
54
[421]55/////////////////////////////
56int sys_display( reg_t  type,
57                 reg_t  arg0,
58                 reg_t  arg1 )
59{
[433]60
[440]61    error_t     error;
62    vseg_t    * vseg;
63
64    thread_t  * this    = CURRENT_THREAD;
65    process_t * process = this->process;
66
[438]67#if DEBUG_SYS_DISPLAY
[433]68uint64_t    tm_start;
69uint64_t    tm_end;
70tm_start = hal_get_cycles();
[438]71if( DEBUG_SYS_DISPLAY < tm_start )
[443]72printk("\n[DBG] %s : thread %d enter / process %x / type  %s / cycle = %d\n",
73__FUNCTION__, this, this->process->pid, display_type_str(type), (uint32_t)tm_start );
[433]74#endif
75
[440]76    ////////////////////////////
[421]77    if( type == DISPLAY_STRING )
78    {
79        char      kbuf[256];
[433]80        uint32_t  length;
[421]81
82        char    * string = (char *)arg0;
[440]83
[421]84        // check string in user space
[440]85        error = vmm_get_vseg( process , (intptr_t)arg0 , &vseg );
86
87        if( error )
[433]88        {
[440]89
90#if DEBUG_SYSCALLS_ERROR
[580]91printk("\n[ERROR] in %s for STRING : string buffer %x unmapped\n",
92__FUNCTION__ , (intptr_t)arg0 );
[440]93#endif
94            this->errno = EINVAL;
[433]95            return -1;
96        }
[421]97
98        // ckeck string length
[433]99        length = hal_strlen_from_uspace( string );
[440]100
[433]101        if( length >= 256 )
102        {
[440]103
104#if DEBUG_SYSCALLS_ERROR
[580]105printk("\n[ERROR] in %s for STRING : string length %d too large\n",
106__FUNCTION__ , length );
[440]107#endif
108            this->errno = EINVAL;
[433]109            return -1;
110        }
[421]111
[440]112        // copy string to kernel space
[421]113        hal_strcpy_from_uspace( kbuf , string , 256 );
114
115        // print message on TXT0 kernel terminal
[440]116        printk("\n%s / cycle %d\n", kbuf, (uint32_t)hal_get_cycles() );
[421]117    }
[440]118    //////////////////////////////
[421]119    else if( type == DISPLAY_VMM )
120    {
[443]121        cxy_t cxy = (cxy_t)arg0;
122        pid_t pid = (pid_t)arg1;
[421]123
[443]124        // check cxy argument
125            if( cluster_is_undefined( cxy ) ) 
126        {
[421]127
[443]128#if DEBUG_SYSCALLS_ERROR
[580]129printk("\n[ERROR] in %s for VMM : process %x in cluster %x not found\n",
130__FUNCTION__ , pid , cxy );
[443]131#endif
132            this->errno = EINVAL;
133            return -1;
134        }
135
136        // get extended pointer on process PID in cluster CXY
137        xptr_t process_xp = cluster_get_process_from_pid_in_cxy( cxy , pid );
138
[433]139            if( process_xp == XPTR_NULL )
140        {
[440]141
142#if DEBUG_SYSCALLS_ERROR
[580]143printk("\n[ERROR] in %s for VMM : process %x in cluster %x not found\n",
144__FUNCTION__ , pid , cxy );
[440]145#endif
146            this->errno = EINVAL;
[433]147            return -1;
148        }
[421]149
[443]150        // get local pointer on process
151        process_t * process = (process_t *)GET_PTR( process_xp );
[421]152
153        // call kernel function
[443]154        if( cxy == local_cxy )
[421]155        {
[443]156                vmm_display( process , true );
[421]157        }
158        else
159        {
[443]160            rpc_vmm_display_client( cxy , process , true );
[421]161        }
162    }
[440]163    ////////////////////////////////
[421]164    else if( type == DISPLAY_SCHED )
165    {
166        cxy_t cxy = (cxy_t)arg0;
167        lid_t lid = (lid_t)arg1;
168
[440]169        // check cxy argument
[433]170            if( cluster_is_undefined( cxy ) ) 
171        {
[440]172
173#if DEBUG_SYSCALLS_ERROR
[580]174printk("\n[ERROR] in %s for SCHED : illegal cxy argument %x\n",
175__FUNCTION__ , cxy );
[440]176#endif
177            this->errno = EINVAL;
[433]178            return -1;
179        }
[421]180
[440]181        // check lid argument
[433]182        if( lid >= LOCAL_CLUSTER->cores_nr )
183        {
[440]184
185#if DEBUG_SYSCALLS_ERROR
[580]186printk("\n[ERROR] in %s for SCHED : illegal lid argument %x\n",
187__FUNCTION__ , lid );
[440]188#endif
189            this->errno = EINVAL;
[433]190            return -1;
191        }
[421]192
193        if( cxy == local_cxy )
194        {
195                sched_display( lid );
196        }
197        else
198        {
[450]199            sched_remote_display( cxy , lid );
[421]200        }
201    }
[440]202    ////////////////////////////////////////////
[435]203    else if( type == DISPLAY_CLUSTER_PROCESSES )
[421]204    {
[584]205        cxy_t  cxy   = (cxy_t)arg0;
206        bool_t owned = (bool_t)arg1;
[421]207
[440]208        // check cxy argument
[433]209            if( cluster_is_undefined( cxy ) )
210        {
[440]211
212#if DEBUG_SYSCALLS_ERROR
[580]213printk("\n[ERROR] in %s for CLUSTER_PROCESSES : illegal cxy argument %x\n",
214__FUNCTION__ , cxy );
[440]215#endif
216            this->errno = EINVAL;
[433]217            return -1;
218        }
[421]219
[584]220        cluster_processes_display( cxy , owned );
[421]221    }
[580]222    //////////////////////////////
223    else if( type == DISPLAY_VFS )
224    {
225        vfs_display( process->vfs_root_xp );
226    }
227    ////////////////////////////////
228    else if( type == DISPLAY_CHDEV )
229    {
230        chdev_dir_display();
231    }
[440]232    ////////////////////////////////////////
[435]233    else if( type == DISPLAY_TXT_PROCESSES )
234    {
235        uint32_t txt_id = (uint32_t)arg0;
236
237        // check argument
238            if( txt_id >= LOCAL_CLUSTER->nb_txt_channels )
239        {
[440]240
241#if DEBUG_SYSCALLS_ERROR
[580]242printk("\n[ERROR] in %s for TXT_PROCESSES : illegal txt_id argument %d\n",
243__FUNCTION__ , txt_id );
[440]244#endif
245            this->errno = EINVAL;
[435]246            return -1;
247        }
248
249        process_txt_display( txt_id );
250    }
[580]251    ///////////////////////////////
252    else if( type == DISPLAY_DQDT )
[421]253    {
[580]254        dqdt_display();
[421]255    }
[580]256    ////////////////////////////////////
257    else if( type == DISPLAY_BUSYLOCKS )
[421]258    {
[580]259        pid_t   pid   = (cxy_t)arg0;
260        trdid_t trdid = (trdid_t)arg1;
261
262        // get extended pointer on target thread
263        xptr_t thread_xp = thread_get_xptr( pid , trdid );
264
265        if( thread_xp == XPTR_NULL )
266        {
267
268#if DEBUG_SYSCALLS_ERROR
269printk("\n[ERROR] in %s for BUSYLOCKS : thread %x in process %x not found\n",
270__FUNCTION__ , trdid , pid );
271#endif
272            this->errno = EINVAL;
273            return -1;
274        }
275
276        thread_display_busylocks( thread_xp );
[421]277    }
[440]278    ////
[433]279    else 
280    {
[440]281
282#if DEBUG_SYSCALLS_ERROR
[580]283printk("\n[ERROR] in %s : undefined display type %d\n",
284        __FUNCTION__ , type );
[440]285#endif
286        this->errno = EINVAL;
[433]287        return -1;
288    }
[421]289
[438]290#if DEBUG_SYS_DISPLAY
[433]291tm_end = hal_get_cycles();
[438]292if( DEBUG_SYS_DISPLAY < tm_end )
[433]293printk("\n[DBG] %s : thread %x exit / process %x / cost = %d / cycle %d\n",
[436]294__FUNCTION__, this, this->process->pid, (uint32_t)(tm_end - tm_start) , (uint32_t)tm_end );
[433]295#endif
296
297    return 0;
298
299}  // end sys_display()
Note: See TracBrowser for help on using the repository browser.