forked from Imagelibrary/rtems
posix: Improve clock_gettime()
Return CPU usage values for CLOCK_PROCESS_CPUTIME_ID and CLOCK_THREAD_CPUTIME_ID.
This commit is contained in:
committed by
Kinsey Moore
parent
5a9484e6cb
commit
294761ca8d
@@ -39,6 +39,6 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "cpuuseimpl.h"
|
||||
#include <rtems/cpuuseimpl.h>
|
||||
|
||||
Timestamp_Control CPU_usage_Uptime_at_last_reset;
|
||||
|
||||
@@ -46,12 +46,11 @@
|
||||
#include <inttypes.h>
|
||||
|
||||
#include <rtems/cpuuse.h>
|
||||
#include <rtems/cpuuseimpl.h>
|
||||
#include <rtems/printer.h>
|
||||
#include <rtems/score/threadimpl.h>
|
||||
#include <rtems/score/todimpl.h>
|
||||
|
||||
#include "cpuuseimpl.h"
|
||||
|
||||
typedef struct {
|
||||
const rtems_printer *printer;
|
||||
Timestamp_Control total;
|
||||
|
||||
@@ -40,14 +40,13 @@
|
||||
#endif
|
||||
|
||||
#include <rtems/cpuuse.h>
|
||||
#include <rtems/cpuuseimpl.h>
|
||||
#include <rtems/rtems/scheduler.h>
|
||||
#include <rtems/score/percpu.h>
|
||||
#include <rtems/score/todimpl.h>
|
||||
#include <rtems/score/schedulerimpl.h>
|
||||
#include <rtems/score/watchdogimpl.h>
|
||||
|
||||
#include "cpuuseimpl.h"
|
||||
|
||||
static bool CPU_usage_Per_thread_handler(
|
||||
Thread_Control *the_thread,
|
||||
void *arg
|
||||
|
||||
@@ -53,6 +53,7 @@
|
||||
#include <inttypes.h>
|
||||
|
||||
#include <rtems/cpuuse.h>
|
||||
#include <rtems/cpuuseimpl.h>
|
||||
#include <rtems/printer.h>
|
||||
#include <rtems/malloc.h>
|
||||
#include <rtems/score/objectimpl.h>
|
||||
@@ -64,8 +65,6 @@
|
||||
#include <rtems/score/wkspace.h>
|
||||
#include <rtems/rtems/tasksimpl.h>
|
||||
|
||||
#include "cpuuseimpl.h"
|
||||
|
||||
/*
|
||||
* Use a struct for all data to allow more than one top and to support the
|
||||
* thread iterator.
|
||||
|
||||
@@ -5,10 +5,12 @@
|
||||
*
|
||||
* @ingroup POSIXAPI
|
||||
*
|
||||
* @brief Retrieves the Specified Clock Time
|
||||
* @brief This source file contains the implementation of clock_gettime().
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2024 embedded brains GmbH & Co. KG
|
||||
*
|
||||
* COPYRIGHT (c) 1989-2007.
|
||||
* On-Line Applications Research Corporation (OAR).
|
||||
*
|
||||
@@ -41,6 +43,9 @@
|
||||
#include <time.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <rtems/cpuuseimpl.h>
|
||||
#include <rtems/score/threadimpl.h>
|
||||
#include <rtems/score/timestampimpl.h>
|
||||
#include <rtems/score/todimpl.h>
|
||||
#include <rtems/seterr.h>
|
||||
|
||||
@@ -70,17 +75,29 @@ int clock_gettime(
|
||||
|
||||
#ifdef _POSIX_CPUTIME
|
||||
if ( clock_id == CLOCK_PROCESS_CPUTIME_ID ) {
|
||||
_Timecounter_Nanouptime( tp );
|
||||
Timestamp_Control uptime;
|
||||
Timestamp_Control last_reset;
|
||||
Timestamp_Control process_time;
|
||||
|
||||
last_reset = CPU_usage_Uptime_at_last_reset;
|
||||
_TOD_Get_uptime( &uptime );
|
||||
_Timestamp_Subtract( &last_reset, &uptime, &process_time );
|
||||
_Timestamp_To_timespec( &process_time, tp );
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef _POSIX_THREAD_CPUTIME
|
||||
if ( clock_id == CLOCK_THREAD_CPUTIME_ID )
|
||||
rtems_set_errno_and_return_minus_one( ENOSYS );
|
||||
if ( clock_id == CLOCK_THREAD_CPUTIME_ID ) {
|
||||
Timestamp_Control used;
|
||||
|
||||
used = _Thread_Get_CPU_time_used_after_last_reset(
|
||||
_Thread_Get_executing()
|
||||
);
|
||||
_Timestamp_To_timespec( &used, tp );
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
rtems_set_errno_and_return_minus_one( EINVAL );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -386,7 +386,19 @@ static rtems_task Init(
|
||||
/* print new times to make sure it has changed and we can get the realtime */
|
||||
sc = clock_gettime( CLOCK_PROCESS_CPUTIME_ID, &tv );
|
||||
rtems_test_assert( !sc );
|
||||
printf("Time since boot: (%" PRIdtime_t ", %ld)\n", tv.tv_sec,tv.tv_nsec );
|
||||
printf(
|
||||
"Time since last CPU usage reset: (%" PRIdtime_t ", %ld)\n",
|
||||
tv.tv_sec,
|
||||
tv.tv_nsec
|
||||
);
|
||||
|
||||
sc = clock_gettime( CLOCK_THREAD_CPUTIME_ID, &tv );
|
||||
rtems_test_assert( !sc );
|
||||
printf(
|
||||
"CPU time used since last CPU usage reset: (%" PRIdtime_t ", %ld)\n",
|
||||
tv.tv_sec,
|
||||
tv.tv_nsec
|
||||
);
|
||||
|
||||
sc = clock_gettime( CLOCK_REALTIME, &tv );
|
||||
rtems_test_assert( !sc );
|
||||
@@ -499,14 +511,6 @@ static rtems_task Init(
|
||||
printf( ctime( &tv.tv_sec ) );
|
||||
|
||||
empty_line();
|
||||
puts( "clock_gettime - CLOCK_THREAD_CPUTIME_ID -- ENOSYS" );
|
||||
#if defined(_POSIX_THREAD_CPUTIME)
|
||||
{
|
||||
struct timespec tp;
|
||||
sc = clock_gettime( CLOCK_THREAD_CPUTIME_ID, &tp );
|
||||
check_enosys( sc );
|
||||
}
|
||||
#endif
|
||||
|
||||
puts( "clock_settime - CLOCK_PROCESS_CPUTIME_ID -- ENOSYS" );
|
||||
#if defined(_POSIX_CPUTIME)
|
||||
|
||||
Reference in New Issue
Block a user