Ignore:
Timestamp:
Nov 14, 2019, 11:50:09 AM (4 years ago)
Author:
alain
Message:

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:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/syscalls/sys_lseek.c

    r457 r651  
    11/*
    2  * kern/sys_lseek.c - set the read/write offset of an opened file
     2 * kern/sys_lseek.c - Kernel function implementing the lseek system call.
    33 *
    4  * Copyright (c) 2008,2009,2010,2011,2012 Ghassan Almaless
    5  * Copyright (c) 2011,2012 UPMC Sorbonne Universites
     4 * AUthor        Alain Greiner (2016,2017,2018,2019)
     5s
     6 * Copyright (c) UPMC Sorbonne Universites
    67 *
    7  * This file is part of ALMOS-kernel.
     8 * This file is part of ALMOS-MKH.
    89 *
    9  * ALMOS-kernel is free software; you can redistribute it and/or modify it
     10 * ALMOS-MKH is free software; you can redistribute it and/or modify it
    1011 * under the terms of the GNU General Public License as published by
    1112 * the Free Software Foundation; version 2.0 of the License.
    1213 *
    13  * ALMOS-kernel is distributed in the hope that it will be useful, but
     14 * ALMOS-MKH is distributed in the hope that it will be useful, but
    1415 * WITHOUT ANY WARRANTY; without even the implied warranty of
    1516 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     
    1718 *
    1819 * You should have received a copy of the GNU General Public License
    19  * along with ALMOS-kernel; if not, write to the Free Software Foundation,
     20 * along with ALMOS-MKH; if not, write to the Free Software Foundation,
    2021 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
    2122 */
     
    3132#include <process.h>
    3233
    33 ////////////////////////////////
    34 int sys_lseek (uint32_t file_id,
    35                uint32_t offset,
    36                uint32_t whence )
     34/////////////////////////////////
     35int sys_lseek ( uint32_t file_id,
     36                uint32_t offset,
     37                uint32_t whence )
    3738{
    3839        error_t    error;
     
    4344        process_t * process = this->process;
    4445
     46#if (DEBUG_SYS_LSEEK || CONFIG_INSTRUMENTATION_SYSCALLS)
     47uint64_t     tm_start = hal_get_cycles();
     48#endif
     49
     50#if DEBUG_SYS_LSEEK
     51if( DEBUG_SYS_LSEEK < tm_start )
     52printk("\n[%s] thread[%x,%x] enter / file_id %d / offset %d / cycle %d\n",
     53__FUNCTION__, process->pid, this->trdid, file_id, offset, (uint32_t)tm_start );
     54#endif
     55
    4556    // check file_id argument
    4657        if( file_id >= CONFIG_PROCESS_FILE_MAX_NR )
    4758        {
    48         printk("\n[ERROR] in %s : illegal file descriptor index = %d\n",
    49                __FUNCTION__ , file_id );
     59
     60#if DEBUG_SYSCALLS_ERROR
     61printk("\n[ERROR] in %s : thread[%x,%x] illegal file descriptor index %d\n",
     62__FUNCTION__ , process->pid, this->trdid, file_id );
     63#endif
    5064                this->errno = EBADFD;
    5165                return -1;
     
    5771    if( file_xp == XPTR_NULL )
    5872    {
    59         printk("\n[ERROR] in %s : undefined file descriptor index = %d\n",
    60                __FUNCTION__ , file_id );
     73
     74#if DEBUG_SYSCALLS_ERROR
     75printk("\n[ERROR] in %s : thread[%x,%x] undefined fd_id %d\n",
     76__FUNCTION__, process->pid, this->trdid, file_id );
     77#endif
    6178                this->errno = EBADFD;
    6279                return -1;
    6380    }
    6481
    65         /* FIXME: file may be closed in parallel
    66          * of seek/read/write/mmap ..etc
    67          * so file may be NULL or invalid */
     82// FIXME: file may be closed in parallel of seek/read/write/mmap ..etc
    6883
    6984    // call relevant VFS function
     
    7287        if( error )
    7388        {
    74         printk("\n[ERROR] in %s : cannot seek file = %d\n",
    75                __FUNCTION__ , file_id );
     89
     90#if DEBUG_SYSCALLS_ERROR
     91printk("\n[ERROR] in %s : thread[%x,%x] cannot seek file_id %d\n",
     92__FUNCTION__, process->pid, this->trdid, file_id );
     93#endif
    7694                this->errno = error;
    7795                return -1;
    7896        }
     97
     98#if (DEBUG_SYS_LSEEK || CONFIG_INSTRUMENTATION_SYSCALLS)
     99uint64_t     tm_end = hal_get_cycles();
     100#endif
     101
     102#if DEBUG_SYS_LSEEK
     103if( DEBUG_SYS_LSEEK < tm_end )
     104printk("\n[%s] thread[%x,%x] exit / cycle %d\n",
     105__FUNCTION__ , process->pid, this->trdid, (uint32_t)tm_end );
     106#endif
     107
     108#if CONFIG_INSTRUMENTATION_SYSCALLS
     109hal_atomic_add( &syscalls_cumul_cost[SYS_LSEEK] , tm_end - tm_start );
     110hal_atomic_add( &syscalls_occurences[SYS_LSEEK] , 1 );
     111#endif
    79112 
    80113        return new_offset;
Note: See TracChangeset for help on using the changeset viewer.