[421] | 1 | /* |
---|
| 2 | * sys_fg.c - Kernel function implementing the "fg" system call. |
---|
| 3 | * |
---|
| 4 | * Author Alain Greiner (2016,2017) |
---|
| 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 <kernel_config.h> |
---|
| 25 | #include <hal_types.h> |
---|
| 26 | #include <hal_irqmask.h> |
---|
| 27 | #include <errno.h> |
---|
| 28 | #include <thread.h> |
---|
| 29 | #include <printk.h> |
---|
| 30 | #include <process.h> |
---|
| 31 | #include <shared_syscalls.h> |
---|
| 32 | #include <cluster.h> |
---|
| 33 | #include <rpc.h> |
---|
| 34 | |
---|
| 35 | ////////////////////////// |
---|
| 36 | int sys_fg( pid_t pid ) |
---|
| 37 | { |
---|
| 38 | xptr_t process_xp; |
---|
| 39 | process_t * process_ptr; |
---|
| 40 | cxy_t process_cxy; |
---|
| 41 | xptr_t chdev_xp; |
---|
| 42 | chdev_t * chdev_ptr; |
---|
| 43 | cxy_t chdev_cxy; |
---|
| 44 | |
---|
| 45 | thread_t * this = CURRENT_THREAD; |
---|
| 46 | |
---|
[436] | 47 | #if CONFIG_DEBUG_SYS_FG |
---|
[421] | 48 | uint64_t tm_start; |
---|
| 49 | uint64_t tm_end; |
---|
| 50 | tm_start = hal_get_cycles(); |
---|
[436] | 51 | if( CONFIG_DEBUG_SYS_FG < tm_start ) |
---|
| 52 | printk("\n[DBG] %s : thread %x enter / process %x / cycle %d\n", |
---|
| 53 | __FUNCTION__ , CURRENT_THREAD , pid, (uint32_t)tm_start ); |
---|
[421] | 54 | #endif |
---|
| 55 | |
---|
| 56 | // check process existence |
---|
| 57 | process_xp = cluster_get_reference_process_from_pid( pid ); |
---|
| 58 | |
---|
| 59 | if( process_xp == XPTR_NULL ) |
---|
| 60 | { |
---|
[436] | 61 | |
---|
| 62 | #if CONFIG_DEBUG_SYSCALLS_ERROR |
---|
| 63 | printk("\n[ERROR] in %s : process %x not found\n", __FUNCTION__ , pid ); |
---|
| 64 | #endif |
---|
[421] | 65 | this->errno = EINVAL; |
---|
| 66 | return -1; |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | // get reference process cluster and local pointer |
---|
| 70 | process_ptr = (process_t *)GET_PTR( process_xp ); |
---|
| 71 | process_cxy = GET_CXY( process_xp ); |
---|
| 72 | |
---|
| 73 | // get extended pointer on TXT_RX chdev |
---|
| 74 | chdev_xp = chdev_from_file( XPTR( process_cxy , &process_ptr->fd_array.array[0] ) ); |
---|
| 75 | |
---|
| 76 | // get chdev cluster and local pointer |
---|
[436] | 77 | chdev_ptr = GET_PTR( chdev_xp ); |
---|
[421] | 78 | chdev_cxy = GET_CXY( chdev_xp ); |
---|
| 79 | |
---|
| 80 | // set reference process owner in TXT_RX chdev |
---|
| 81 | hal_remote_swd( XPTR( chdev_cxy , &chdev_ptr->ext.txt.owner_xp ) , process_xp ); |
---|
| 82 | |
---|
| 83 | hal_fence(); |
---|
| 84 | |
---|
[436] | 85 | #if CONFIG_DEBUG_SYS_FG |
---|
[421] | 86 | tm_end = hal_get_cycles(); |
---|
[436] | 87 | if( CONFIG_DEBUG_SYS_FG < tm_end ) |
---|
| 88 | printk("\n[DBG] %s : thread %x exit / process %x get TXT_%d ownership / cycle %d\n", |
---|
| 89 | __FUNCTION__ , CURRENT_THREAD , pid, |
---|
| 90 | hal_remote_lw( XPTR( chdev_cxy , &chdev_ptr->channel ) ) , (uint32_t)tm_end ); |
---|
[421] | 91 | #endif |
---|
[436] | 92 | |
---|
[421] | 93 | return 0; |
---|
| 94 | |
---|
[436] | 95 | } // end sys_fg() |
---|
[421] | 96 | |
---|