source: trunk/kernel/syscalls/sys_get_nb_cores.c @ 651

Last change on this file since 651 was 651, checked in by alain, 2 years ago

1) Improve the VMM MMAP allocator: implement the "buddy" algorithm
to allocate only aligned blocks.
2) fix a bug in the pthread_join() / pthread_exit() mmechanism.

File size: 2.9 KB
Line 
1/*
2 * sys_get_core_id.c - Kernel function implementing the "get_nb_cores" syscall.
3 *
4 * Author    Alain Greiner (2016,2017,2018,2019)
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_vmm.h>
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
35#include <syscalls.h>
36
37/////////////////////////////////////
38int sys_get_nb_cores( uint32_t   cxy,
39                      uint32_t * ncores )
40{
41    vseg_t  * vseg;
42    uint32_t  k_ncores;
43
44    thread_t  * this    = CURRENT_THREAD;
45    process_t * process = this->process;
46
47#if (DEBUG_SYS_GET_NB_CORES || CONFIG_INSTRUMENTATION_SYSCALLS)
48uint64_t     tm_start = hal_get_cycles();
49#endif
50
51#if DEBUG_SYS_GET_NB_CORES
52if( DEBUG_SYS_GET_NB_CORES < tm_start )
53printk("\n[%s] thread[%x,%x] enter  for cluster %x / cycle %d\n",
54__FUNCTION__, process->pid, this->trdid, cxy, (uint32_t)tm_start );
55#endif
56
57   // check ncores buffer in user space
58    if( vmm_get_vseg( process , (intptr_t)ncores , &vseg ) )
59        {
60
61#if DEBUG_SYSCALLS_ERROR
62printk("\n[ERROR] in %s : ncores buffer unmapped %x / thread %x / process %x\n",
63__FUNCTION__ , (intptr_t)ncores , this->trdid , process->pid );
64#endif
65        this->errno = EFAULT;
66                return -1;
67        }
68
69    // get ncores
70    if( cluster_is_active( cxy ) ) 
71    {
72            k_ncores = hal_remote_l32( XPTR( cxy , &LOCAL_CLUSTER->cores_nr ) );
73    }
74    else   // target cluster undefined
75    {
76        k_ncores = 0;
77    }
78
79    // copy to user space
80        hal_copy_to_uspace( ncores,
81                        XPTR( local_cxy , &k_ncores ),
82                        sizeof(uint32_t) );
83
84#if (DEBUG_SYS_GET_NB_CORES || CONFIG_INSTRUMENTATION_SYSCALLS)
85uint64_t     tm_end = hal_get_cycles();
86#endif
87
88#if DEBUG_SYS_GET_NB_CORES
89if( DEBUG_SYS_GET_NB_CORES < tm_end )
90printk("\n[%s] thread[%x,%x] exit / ncores %d / cycle %d\n",
91__FUNCTION__ , process->pid, this->trdid, k_ncores, (uint32_t)tm_end );
92#endif
93
94#if CONFIG_INSTRUMENTATION_SYSCALLS
95hal_atomic_add( &syscalls_cumul_cost[SYS_GET_NB_CORES] , tm_end - tm_start );
96hal_atomic_add( &syscalls_occurences[SYS_GET_NB_CORES] , 1 );
97#endif
98
99        return 0; 
100
101}  // end sys_get_nb_cores()
Note: See TracBrowser for help on using the repository browser.