[584] | 1 | /* |
---|
| 2 | * sys_get_core.c - get calling core cluster and local index. |
---|
| 3 | * |
---|
[623] | 4 | * Author Alain Greiner (2016,2017,2018,2019) |
---|
[584] | 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 <hal_special.h> |
---|
| 27 | #include <errno.h> |
---|
| 28 | #include <core.h> |
---|
| 29 | #include <thread.h> |
---|
| 30 | #include <process.h> |
---|
| 31 | #include <vmm.h> |
---|
| 32 | #include <printk.h> |
---|
| 33 | |
---|
| 34 | #include <syscalls.h> |
---|
| 35 | |
---|
| 36 | /////////////////////////////////// |
---|
| 37 | int sys_place_fork( uint32_t cxy ) |
---|
| 38 | { |
---|
| 39 | thread_t * this = CURRENT_THREAD; |
---|
| 40 | |
---|
[670] | 41 | #if DEBUG_SYS_PLACE_FORK || DEBUG_SYSCALLS_ERROR || CONFIG_INSTRUMENTATION_SYSCALLS |
---|
| 42 | uint64_t tm_start = hal_get_cycles(); |
---|
| 43 | process_t * process = this->process; |
---|
[637] | 44 | #endif |
---|
| 45 | |
---|
| 46 | #if DEBUG_SYS_PLACE_FORK |
---|
| 47 | if( DEBUG_SYS_PLACE_FORK < tm_start ) |
---|
| 48 | printk("\n[%s] thread[%x,%x] enter / cxy %x / cycle %d\n", |
---|
| 49 | __FUNCTION__, process->pid, this->trdid, cxy, (uint32_t)tm_start ); |
---|
| 50 | #endif |
---|
| 51 | |
---|
[584] | 52 | // check cxy argument |
---|
[637] | 53 | if( cluster_is_active( cxy ) == false ) |
---|
[584] | 54 | { |
---|
| 55 | |
---|
| 56 | #if DEBUG_SYSCALLS_ERROR |
---|
[683] | 57 | if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start ) |
---|
[584] | 58 | printk("\n[ERROR] in %s : thread[%x,‰x] / illegal cxy argument %x\n", |
---|
| 59 | __FUNCTION__ , process->pid , this->trdid , cxy ); |
---|
| 60 | #endif |
---|
| 61 | this->errno = EFAULT; |
---|
| 62 | return -1; |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | // set relevant arguments in calling thread descriptor |
---|
| 66 | this->fork_user = true; |
---|
| 67 | this->fork_cxy = cxy; |
---|
| 68 | |
---|
[637] | 69 | #if (DEBUG_SYS_PLACE_FORK || CONFIG_INSTRUMENTATION_SYSCALLS) |
---|
| 70 | uint64_t tm_end = hal_get_cycles(); |
---|
| 71 | #endif |
---|
| 72 | |
---|
| 73 | #if DEBUG_SYS_PLACE_FORK |
---|
| 74 | if( DEBUG_SYS_PLACE_FORK < tm_end ) |
---|
| 75 | printk("\n[%s] thread[%x,%x] exit / cycle %d\n", |
---|
| 76 | __FUNCTION__ , process->pid, this->trdid, (uint32_t)tm_end ); |
---|
| 77 | #endif |
---|
| 78 | |
---|
| 79 | #if CONFIG_INSTRUMENTATION_SYSCALLS |
---|
| 80 | hal_atomic_add( &syscalls_cumul_cost[SYS_PLACE_FORK] , tm_end - tm_start ); |
---|
| 81 | hal_atomic_add( &syscalls_occurences[SYS_PLACE_FORK] , 1 ); |
---|
| 82 | #endif |
---|
| 83 | |
---|
[584] | 84 | return 0; |
---|
| 85 | |
---|
| 86 | } // end sys_place_fork() |
---|