![]() |
|
|||
File indexing completed on 2025-05-11 08:24:15
0001 /* SPDX-License-Identifier: BSD-2-Clause */ 0002 0003 /** 0004 * @file 0005 * 0006 * @brief Get Process Times 0007 * @ingroup libcsupport 0008 */ 0009 0010 /* 0011 * COPYRIGHT (c) 1989-2013. 0012 * On-Line Applications Research Corporation (OAR). 0013 * 0014 * Redistribution and use in source and binary forms, with or without 0015 * modification, are permitted provided that the following conditions 0016 * are met: 0017 * 1. Redistributions of source code must retain the above copyright 0018 * notice, this list of conditions and the following disclaimer. 0019 * 2. Redistributions in binary form must reproduce the above copyright 0020 * notice, this list of conditions and the following disclaimer in the 0021 * documentation and/or other materials provided with the distribution. 0022 * 0023 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 0024 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 0025 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 0026 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 0027 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 0028 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 0029 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 0030 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 0031 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 0032 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 0033 * POSSIBILITY OF SUCH DAMAGE. 0034 */ 0035 0036 #ifdef HAVE_CONFIG_H 0037 #include "config.h" 0038 #endif 0039 0040 /* 0041 * Needed to get the prototype for this libc helper method 0042 */ 0043 #define _LIBC 0044 0045 #include <rtems.h> 0046 0047 #include <sys/times.h> 0048 #include <sys/time.h> 0049 0050 #include <string.h> 0051 #include <time.h> 0052 0053 #include <rtems/seterr.h> 0054 #include <rtems/score/todimpl.h> 0055 #include <rtems/score/timestamp.h> 0056 #include <rtems/score/threadimpl.h> 0057 0058 /** 0059 * POSIX 1003.1b 4.5.2 - Get Process Times 0060 */ 0061 clock_t _times( 0062 struct tms *ptms 0063 ) 0064 { 0065 uint32_t tick_interval; 0066 sbintime_t uptime; 0067 sbintime_t cpu_time_used; 0068 0069 if ( !ptms ) 0070 rtems_set_errno_and_return_minus_one( EFAULT ); 0071 0072 tick_interval = (uint32_t) 0073 (SBT_1US * rtems_configuration_get_microseconds_per_tick()); 0074 0075 ptms = memset( ptms, 0, sizeof( *ptms ) ); 0076 0077 _TOD_Get_zero_based_uptime( &uptime ); 0078 ptms->tms_stime = ((clock_t) uptime) / tick_interval; 0079 0080 /* 0081 * RTEMS technically has no notion of system versus user time 0082 * since there is no separation of OS from application tasks. 0083 * But we can at least make a distinction between the number 0084 * of ticks since boot and the number of ticks executed by this 0085 * this thread. 0086 */ 0087 cpu_time_used = 0088 _Thread_Get_CPU_time_used_after_last_reset( _Thread_Get_executing() ); 0089 ptms->tms_utime = ((clock_t) cpu_time_used) / tick_interval; 0090 0091 return ptms->tms_stime; 0092 } 0093 0094 /** 0095 * times() system call wrapper for _times() above. 0096 */ 0097 clock_t times( 0098 struct tms *ptms 0099 ) 0100 { 0101 return _times( ptms ); 0102 } 0103 0104 #if defined(RTEMS_NEWLIB) 0105 0106 #include <reent.h> 0107 0108 /** 0109 * This is the Newlib dependent reentrant version of times(). 0110 */ 0111 clock_t _times_r( 0112 struct _reent *ptr RTEMS_UNUSED, 0113 struct tms *ptms 0114 ) 0115 { 0116 return _times( ptms ); 0117 } 0118 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |