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 | ////////////////////// |
---|
29 | int 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) |
---|
35 | uint64_t tm_start = hal_get_cycles(); |
---|
36 | #endif |
---|
37 | |
---|
38 | #if DEBUG_SYS_GETPID |
---|
39 | tm_start = hal_get_cycles(); |
---|
40 | if( DEBUG_SYS_FG < tm_start ) |
---|
41 | printk("\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) |
---|
49 | uint64_t tm_end = hal_get_cycles(); |
---|
50 | #endif |
---|
51 | |
---|
52 | #if DEBUG_SYS_GETPID |
---|
53 | tm_end = hal_get_cycles(); |
---|
54 | if( DEBUG_SYS_GETPID < tm_end ) |
---|
55 | printk("\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 |
---|
60 | hal_atomic_add( &syscalls_cumul_cost[SYS_GETPID] , tm_end - tm_start ); |
---|
61 | hal_atomic_add( &syscalls_occurences[SYS_GETPID] , 1 ); |
---|
62 | #endif |
---|
63 | |
---|
64 | return pid; |
---|
65 | |
---|
66 | } // end sys_getpid() |
---|