source: trunk/kernel/syscalls/sys_getpid.c @ 566

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

Complete restructuration of kernel locks.

File size: 2.0 KB
Line 
1/*
2 * kern/sys_getpid.c - Kernel function implementing the "get_pid" system call.
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 <thread.h>
25#include <process.h>
26#include <syscalls.h>
27
28//////////////////////
29int sys_getpid( void )
30{
31    thread_t  * this    = CURRENT_THREAD;
32    process_t * process = this->process;
33
34#if (DEBUG_SYS_GETPID || CONFIG_INSTRUMENTATION_SYSCALLS)
35uint64_t     tm_start = hal_get_cycles();
36#endif
37
38#if DEBUG_SYS_GETPID
39tm_start = hal_get_cycles();
40if( DEBUG_SYS_FG < tm_start )
41printk("\n[DBG] %s : thread %x in process %x enter / cycle %d\n",
42__FUNCTION__ , this->trdid , process->pid, (uint32_t)tm_start );
43#endif
44
45    // get pid value from local process descriptor   
46    pid_t pid = process->pid;
47
48#if (DEBUG_SYS_GETPID || CONFIG_INSTRUMENTATION_SYSCALLS)
49uint64_t     tm_end = hal_get_cycles();
50#endif
51
52#if DEBUG_SYS_GETPID
53tm_end = hal_get_cycles();
54if( DEBUG_SYS_GETPID < tm_end )
55printk("\n[DBG] %s : thread %x in process %x exit / cycle %d\n",
56__FUNCTION__, this->trdid, process->pid, (uint32_t)tm_end );
57#endif
58
59#if CONFIG_INSTRUMENTATION_SYSCALLS
60hal_atomic_add( &syscalls_cumul_cost[SYS_GETPID] , tm_end - tm_start );
61hal_atomic_add( &syscalls_occurences[SYS_GETPID] , 1 );
62#endif
63
64        return pid;
65
66}  // end sys_getpid()
Note: See TracBrowser for help on using the repository browser.