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

Last change on this file since 580 was 580, checked in by alain, 3 years ago

1) Register the kernel process in the cluster manager local list.
2) Introduce a new service in idbg : display the set of busylocks taken by a given thread.

File size: 7.8 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
207        // check cxy argument
208            if( cluster_is_undefined( cxy ) )
209        {
210
211#if DEBUG_SYSCALLS_ERROR
212printk("\n[ERROR] in %s for CLUSTER_PROCESSES : illegal cxy argument %x\n",
213__FUNCTION__ , cxy );
214#endif
215            this->errno = EINVAL;
216            return -1;
217        }
218
219        cluster_processes_display( cxy );
220    }
221    //////////////////////////////
222    else if( type == DISPLAY_VFS )
223    {
224        vfs_display( process->vfs_root_xp );
225    }
226    ////////////////////////////////
227    else if( type == DISPLAY_CHDEV )
228    {
229        chdev_dir_display();
230    }
231    ////////////////////////////////////////
232    else if( type == DISPLAY_TXT_PROCESSES )
233    {
234        uint32_t txt_id = (uint32_t)arg0;
235
236        // check argument
237            if( txt_id >= LOCAL_CLUSTER->nb_txt_channels )
238        {
239
240#if DEBUG_SYSCALLS_ERROR
241printk("\n[ERROR] in %s for TXT_PROCESSES : illegal txt_id argument %d\n",
242__FUNCTION__ , txt_id );
243#endif
244            this->errno = EINVAL;
245            return -1;
246        }
247
248        process_txt_display( txt_id );
249    }
250    ///////////////////////////////
251    else if( type == DISPLAY_DQDT )
252    {
253        dqdt_display();
254    }
255    ////////////////////////////////////
256    else if( type == DISPLAY_BUSYLOCKS )
257    {
258        pid_t   pid   = (cxy_t)arg0;
259        trdid_t trdid = (trdid_t)arg1;
260
261        // get extended pointer on target thread
262        xptr_t thread_xp = thread_get_xptr( pid , trdid );
263
264        if( thread_xp == XPTR_NULL )
265        {
266
267#if DEBUG_SYSCALLS_ERROR
268printk("\n[ERROR] in %s for BUSYLOCKS : thread %x in process %x not found\n",
269__FUNCTION__ , trdid , pid );
270#endif
271            this->errno = EINVAL;
272            return -1;
273        }
274
275        thread_display_busylocks( thread_xp );
276    }
277    ////
278    else 
279    {
280
281#if DEBUG_SYSCALLS_ERROR
282printk("\n[ERROR] in %s : undefined display type %d\n",
283        __FUNCTION__ , type );
284#endif
285        this->errno = EINVAL;
286        return -1;
287    }
288
289#if DEBUG_SYS_DISPLAY
290tm_end = hal_get_cycles();
291if( DEBUG_SYS_DISPLAY < tm_end )
292printk("\n[DBG] %s : thread %x exit / process %x / cost = %d / cycle %d\n",
293__FUNCTION__, this, this->process->pid, (uint32_t)(tm_end - tm_start) , (uint32_t)tm_end );
294#endif
295
296    return 0;
297
298}  // end sys_display()
Note: See TracBrowser for help on using the repository browser.