source: trunk/kernel/syscalls/sys_is_fg.c @ 628

Last change on this file since 628 was 626, checked in by alain, 5 years ago

This version has been tested on the sort multithreaded application
for TSAR_IOB architectures ranging from 1 to 8 clusters.
It fixes three bigs bugs:
1) the dev_ioc device API has been modified: the dev_ioc_sync_read()
and dev_ioc_sync_write() function use now extended pointers on the
kernel buffer to access a mapper stored in any cluster.
2) the hal_uspace API has been modified: the hal_copy_to_uspace()
and hal_copy_from_uspace() functions use now a (cxy,ptr) couple
to identify the target buffer (equivalent to an extended pointer.
3) an implementation bug has been fixed in the assembly code contained
in the hal_copy_to_uspace() and hal_copy_from_uspace() functions.

File size: 3.3 KB
Line 
1/*
2 * sys_fg.c - Kernel function implementing the "is_fg" system call.
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 <kernel_config.h>
25#include <hal_kernel_types.h>
26#include <hal_uspace.h>
27#include <hal_vmm.h>
28#include <hal_special.h>
29#include <errno.h>
30#include <thread.h>
31#include <printk.h>
32#include <process.h>
33#include <vseg.h>
34#include <shared_syscalls.h>
35#include <cluster.h>
36
37#include <syscalls.h>
38
39//////////////////////////////
40int sys_is_fg( pid_t      pid,
41               uint32_t * is_fg )
42{
43    xptr_t      process_xp;       // extended pointer on process descriptor in owner cluster
44    uint32_t    is_txt_owner;     // kernel buffer for is_fg
45    vseg_t    * vseg;             // for buffer mapping check
46    error_t     error;
47
48    thread_t  * this    = CURRENT_THREAD;
49    process_t * process = this->process;
50
51#if (DEBUG_SYS_IS_FG || CONFIG_INSTRUMENTATION_SYSCALLS)
52uint64_t     tm_start = hal_get_cycles();
53#endif
54
55#if DEBUG_SYS_IS_FG
56tm_start = hal_get_cycles();
57if( DEBUG_SYS_IS_FG < tm_start )
58printk("\n[DBG] %s : thread %x in process %x enter for pid %x / cycle %d\n",
59__FUNCTION__ , this->trdid , process->pid, pid, (uint32_t)tm_start );
60#endif
61
62    // check buffer in user vspace
63        error = vmm_get_vseg( process , (intptr_t)is_fg , &vseg );
64    if( error )
65    {
66
67#if DEBUG_SYSCALLS_ERROR
68printk("\n[ERROR] in %s : unmapped owner buffer %x / thread %x in process %x\n",
69__FUNCTION__ , (intptr_t)is_fg, this->trdid, process->pid );
70hal_vmm_display( process , false );
71#endif
72         this->errno = EINVAL;
73         return -1;
74    }
75
76    // check target process existence
77    process_xp = cluster_get_owner_process_from_pid( pid );
78
79    if( process_xp == XPTR_NULL )
80    {
81
82#if DEBUG_SYSCALLS_ERROR
83printk("\n[ERROR] in %s : process %x not found\n", __FUNCTION__ , pid );
84#endif
85        this->errno = EINVAL;
86        return -1;
87    }
88   
89    // call relevant kernel function
90    is_txt_owner = process_txt_is_owner( process_xp );
91
92    // copy to user space
93    hal_copy_to_uspace( local_cxy, &is_txt_owner, is_fg, sizeof(uint32_t) );
94
95    hal_fence();
96
97#if (DEBUG_SYS_IS_FG || CONFIG_INSTRUMENTATION_SYSCALLS)
98uint64_t     tm_end = hal_get_cycles();
99#endif
100
101#if DEBUG_SYS_IS_FG
102tm_end = hal_get_cycles();
103if( DEBUG_SYS_IS_FG < tm_end )
104printk("\n[DBG] %s : thread %x in process %x exit / is_txt_owner %d / cycle %d\n",
105__FUNCTION__, this->trdid, process->pid, is_txt_owner, (uint32_t)tm_end );
106#endif
107
108#if CONFIG_INSTRUMENTATION_SYSCALLS
109hal_atomic_add( &syscalls_cumul_cost[SYS_IS_FG] , tm_end - tm_start );
110hal_atomic_add( &syscalls_occurences[SYS_IS_FG] , 1 );
111#endif
112
113return 0;
114
115}  // end sys_is_fg()
116
Note: See TracBrowser for help on using the repository browser.