source: trunk/kernel/syscalls/sys_get_config.c @ 670

Last change on this file since 670 was 664, checked in by alain, 4 years ago
  • Introduce the sys_socket.c file implementing all socket related syscalls.
  • Improve the non-standard sys_get_config() function.
File size: 3.2 KB
RevLine 
[410]1/*
2 * sys_get_config.c - get hardware platform parameters.
3 *
[664]4 * Author    Alain Greiner (2016,2017,2018,2019,2020)
[410]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
[457]24#include <hal_kernel_types.h>
[410]25#include <hal_uspace.h>
[625]26#include <hal_vmm.h>
[410]27#include <hal_special.h>
28#include <errno.h>
29#include <core.h>
30#include <thread.h>
31#include <process.h>
32#include <vmm.h>
33#include <printk.h>
34
[506]35#include <syscalls.h>
[664]36#include <shared_syscalls.h>
[506]37
[664]38//////////////////////////////////////////////
39int sys_get_config( hard_config_t * u_config )
[410]40{
[664]41    vseg_t        * vseg;       
42    hard_config_t   k_config;    // hard_config structure in kernel space
[410]43
44    thread_t  * this    = CURRENT_THREAD;
45    process_t * process = this->process;
46
[625]47#if (DEBUG_SYS_GET_CONFIG || CONFIG_INSTRUMENTATION_SYSCALLS)
48uint64_t     tm_start = hal_get_cycles();
49#endif
50
[438]51#if DEBUG_SYS_GET_CONFIG
[435]52tm_start = hal_get_cycles();
[438]53if( DEBUG_SYS_GET_CONFIG < tm_start )
[435]54printk("\n[DBG] %s : thread %x enter / process %x / cycle %d\n",
55__FUNCTION__, this, process->pid, (uint32_t)tm_start );
56#endif
57
[664]58    // check u_config mapped in user space
59    if( vmm_get_vseg( process , (intptr_t)u_config  , &vseg ) )
[410]60        {
[435]61
[438]62#if DEBUG_SYSCALLS_ERROR
[664]63printk("\n[ERROR] in %s : config pointer %x unmapped / thread %x / process %x\n",
64__FUNCTION__ , (intptr_t)u_config , this->trdid , process->pid );
[435]65#endif
[440]66        this->errno = EINVAL;
[410]67                return -1;
68        }
69
[664]70    // copy config parameters from cluster descriptor to kernel structure
71        k_config.x_size       = LOCAL_CLUSTER->x_size;
72        k_config.y_size       = LOCAL_CLUSTER->y_size;
73        k_config.ncores       = LOCAL_CLUSTER->cores_nr;
74    k_config.txt_channels = LOCAL_CLUSTER->nb_txt_channels;
75    k_config.nic_channels = LOCAL_CLUSTER->nb_nic_channels;
76    k_config.ioc_channels = LOCAL_CLUSTER->nb_ioc_channels;
77    k_config.fbf_channels = LOCAL_CLUSTER->nb_fbf_channels;
[440]78
[664]79    // copy k_config structure to user space
80        hal_copy_to_uspace( u_config , XPTR(local_cxy, &k_config ), sizeof(hard_config_t) );
[440]81
[435]82    hal_fence();
83
[625]84#if (DEBUG_SYS_GET_CONFIG || CONFIG_INSTRUMENTATION_SYSCALLS)
85uint64_t     tm_end = hal_get_cycles();
86#endif
87
[438]88#if DEBUG_SYS_GET_CONFIG
89if( DEBUG_SYS_GET_CONFIG < tm_end )
[436]90printk("\n[DBG] %s : thread %x exit / process %x / cost %d / cycle %d\n",
[435]91__FUNCTION__, this, process->pid, (uint32_t)(tm_end-tm_start), (uint32_t)tm_end );
92#endif
93
[625]94#if CONFIG_INSTRUMENTATION_SYSCALLS
95hal_atomic_add( &syscalls_cumul_cost[SYS_GET_CONFIG] , tm_end - tm_start );
96hal_atomic_add( &syscalls_occurences[SYS_GET_CONFIG] , 1 );
97#endif
98
[410]99        return 0; 
100
101}  // end sys_get_config()
Note: See TracBrowser for help on using the repository browser.