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

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

Introduce sys_place_fork() function.

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