00001 /*! 00002 * \file cpu_reserve/server/src/granularity.c 00003 * \brief CPU timeslice granularity functions 00004 * 00005 * \date 09/14/2004 00006 * \author Jork Loeser <jork.loeser@inf.tu-dresden.de> 00007 * 00008 */ 00009 /* (c) 2004 Technische Universitaet Dresden 00010 * This file is part of DROPS, which is distributed under the terms of the 00011 * GNU General Public License 2. Please see the COPYING file for details. 00012 */ 00013 #include <l4/sigma0/kip.h> 00014 #include <l4/util/util.h> 00015 #include <l4/env/errno.h> 00016 #include "granularity.h" 00017 00018 static int kernel_granularity; 00019 00020 /*!\brief Obtain the timer granularity from the kip 00021 * \retval 0 ok 00022 * \retval !0 error 00023 */ 00024 static int granularity_init(void){ 00025 l4_kernel_info_t *kip; 00026 if(kernel_granularity) return 0; 00027 00028 kip = l4sigma0_kip_map(L4_INVALID_ID); 00029 if(kip==0) return -L4_EINVAL; 00030 kernel_granularity = kip->scheduler_granularity; 00031 return 0; 00032 } 00033 00034 /*!\brief Return scheduling granularity 00035 */ 00036 int granularity(void){ 00037 if(granularity_init()) return 0; 00038 return kernel_granularity; 00039 } 00040 00041 /*!\brief Round time up to the next kernel-supported granularity 00042 * 00043 * \retval 0 some error occured 00044 * \retval >0 OK 00045 */ 00046 int granularity_roundup(unsigned time){ 00047 if(!time) return 0; 00048 00049 if(granularity_init()) return 0; 00050 time = (time-1)/kernel_granularity; 00051 return (time+1)*kernel_granularity; 00052 } 00053