<div dir="ltr"><div>Attached here are the testing logs for rtems-test for the leon3.</div><div><br></div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, 9 Aug 2021 at 01:14, Zacchaeus Leung <<a href="mailto:zakthertemsdev@gmail.com">zakthertemsdev@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">the timer_create() method can use CLOCK_MONOTONIC but there was no test for this. Also it implements the functionality to<br>
create a CLOCK_MONOTONIC timer and gettime() .<br>
Closes #3888<br>
---<br>
 cpukit/include/rtems/posix/timer.h      | 1 +<br>
 cpukit/posix/src/psxtimercreate.c       | 3 +-<br>
 cpukit/posix/src/timergettime.c        | 50 ++++++++++++-------<br>
 testsuites/psxtests/psxtimer02/psxtimer.c   | 26 ++++++++++<br>
 testsuites/psxtests/psxtimer02/psxtimer02.scn | 6 +++<br>
 5 files changed, 66 insertions(+), 20 deletions(-)<br>
<br>
diff --git a/cpukit/include/rtems/posix/timer.h b/cpukit/include/rtems/posix/timer.h<br>
index bcbf07a65a..7ae089173a 100644<br>
--- a/cpukit/include/rtems/posix/timer.h<br>
+++ b/cpukit/include/rtems/posix/timer.h<br>
@@ -48,6 +48,7 @@ typedef struct {<br>
  uint32_t     ticks;   /* Number of ticks of the initialization */<br>
  uint32_t     overrun;  /* Number of expirations of the timer  */<br>
  struct timespec  time;    /* Time at which the timer was started  */<br>
+ clockid_t     clock_type; /* The type of timer */<br>
 } POSIX_Timer_Control;<br>
<br>
 /**<br>
diff --git a/cpukit/posix/src/psxtimercreate.c b/cpukit/posix/src/psxtimercreate.c<br>
index a63cf1d100..2b5a10140f 100644<br>
--- a/cpukit/posix/src/psxtimercreate.c<br>
+++ b/cpukit/posix/src/psxtimercreate.c<br>
@@ -40,7 +40,7 @@ int timer_create(<br>
 {<br>
  POSIX_Timer_Control *ptimer;<br>
<br>
-Â if ( clock_id != CLOCK_REALTIME )<br>
+Â if (Â clock_id != CLOCK_REALTIME && clock_id != CLOCK_MONOTONIC )<br>
   rtems_set_errno_and_return_minus_one( EINVAL );<br>
<br>
  if ( !timerid )<br>
@@ -91,6 +91,7 @@ int timer_create(<br>
  ptimer->timer_data.it_value.tv_nsec  = 0;<br>
  ptimer->timer_data.it_interval.tv_sec = 0;<br>
  ptimer->timer_data.it_interval.tv_nsec = 0;<br>
+Â ptimer->clock_type = clock_id;<br>
<br>
  _Watchdog_Preinitialize( &ptimer->Timer, _Per_CPU_Get_snapshot() );<br>
  _Watchdog_Initialize( &ptimer->Timer, _POSIX_Timer_TSR );<br>
diff --git a/cpukit/posix/src/timergettime.c b/cpukit/posix/src/timergettime.c<br>
index ee2a566f0e..2ad841d517 100644<br>
--- a/cpukit/posix/src/timergettime.c<br>
+++ b/cpukit/posix/src/timergettime.c<br>
@@ -28,6 +28,7 @@<br>
 #include <rtems/score/todimpl.h><br>
 #include <rtems/score/watchdogimpl.h><br>
 #include <rtems/seterr.h><br>
+#include <rtems/timespec.h><br>
<br>
 /*<br>
 *     - When a timer is initialized, the value of the time in<br>
@@ -39,35 +40,46 @@<br>
 int timer_gettime(<br>
  timer_t      timerid,<br>
  struct itimerspec *value<br>
) <br>
 {<br>
  POSIX_Timer_Control *ptimer;<br>
- ISR_lock_Context   lock_context;<br>
- uint64_t       now;<br>
- uint32_t       remaining;<br>
+Â ISR_lock_Context lock_context;<br>
+Â Per_CPU_Control *cpu;<br>
+Â struct timespec now;<br>
+Â struct timespec expire;<br>
+Â struct timespec result;<br>
<br>
  if ( !value )<br>
   rtems_set_errno_and_return_minus_one( EINVAL );<br>
<br>
  ptimer = _POSIX_Timer_Get( timerid, &lock_context );<br>
-Â if ( ptimer != NULL ) {<br>
-Â Â Per_CPU_Control *cpu;<br>
+Â if ( ptimer == NULL ) {<br>
+Â Â rtems_set_errno_and_return_minus_one( EINVAL );<br>
+Â }<br>
<br>
-Â Â cpu = _POSIX_Timer_Acquire_critical( ptimer, &lock_context );<br>
-Â Â now = cpu->Watchdog.ticks;<br>
+Â cpu = _POSIX_Timer_Acquire_critical( ptimer, &lock_context );<br>
+Â rtems_timespec_from_ticks( ptimer->Timer.expire, &expire );<br>
<br>
-Â Â if ( now < ptimer->Timer.expire ) {<br>
-Â Â Â remaining = (uint32_t) ( ptimer->Timer.expire - now );<br>
-Â Â } else {<br>
-Â Â Â remaining = 0;<br>
-Â Â }<br>
+Â if ( ptimer->clock_type == CLOCK_MONOTONIC ) {<br>
+Â _Timecounter_Nanouptime(&now);<br>
+ } else if ( ptimer->clock_type == CLOCK_REALTIME ) {<br>
+Â Â _TOD_Get(&now);<br>
+Â } else {<br>
+Â _POSIX_Timer_Release( cpu, &lock_context );Â Â <br>
+Â rtems_set_errno_and_return_minus_one( EINVAL );<br>
+Â }<br>
<br>
-Â Â _Timespec_From_ticks( remaining, &value->it_value );<br>
-Â Â value->it_interval = ptimer->timer_data.it_interval;<br>
<br>
-Â Â _POSIX_Timer_Release( cpu, &lock_context );<br>
-Â Â return 0;<br>
+ if ( rtems_timespec_less_than( &now, &expire ) ) {<br>
+Â Â Â rtems_timespec_subtract( &now, &expire, &result );<br>
+Â } else {<br>
+Â Â Â result.tv_nsec = 0;<br>
+   result.tv_sec = 0;<br>
  }<br>
-<br>
-Â rtems_set_errno_and_return_minus_one( EINVAL );<br>
+Â <br>
+Â value->it_value = result;<br>
+Â value->it_interval = ptimer->timer_data.it_interval;<br>
+Â <br>
+Â _POSIX_Timer_Release( cpu, &lock_context );<br>
+Â return 0;<br>
 }<br>
diff --git a/testsuites/psxtests/psxtimer02/psxtimer.c b/testsuites/psxtests/psxtimer02/psxtimer.c<br>
index 9f79d33c42..1a79369efb 100644<br>
--- a/testsuites/psxtests/psxtimer02/psxtimer.c<br>
+++ b/testsuites/psxtests/psxtimer02/psxtimer.c<br>
@@ -126,6 +126,32 @@ void *POSIX_Init (<br>
  puts( "timer_delete - bad id - EINVAL" );<br>
  status = timer_delete( timer );<br>
  fatal_posix_service_status_errno( status, EINVAL, "bad id" );<br>
+Â <br>
+Â puts( "timer_create (monotonic) - bad timer id pointer - EINVAL" );<br>
+Â status = timer_create( CLOCK_MONOTONIC, &event, NULL );<br>
+Â fatal_posix_service_status_errno( status, EINVAL, "bad timer id" );<br>
+<br>
+Â puts( "timer_create (monotonic) - OK" );<br>
+Â status = timer_create( CLOCK_MONOTONIC, NULL, &timer );<br>
+Â posix_service_failed( status, "timer_create OK" );<br>
+<br>
+Â puts( "timer_create (monotonic) - too many - EAGAIN" );<br>
+Â status = timer_create( CLOCK_MONOTONIC, NULL, &timer1 );<br>
+Â fatal_posix_service_status_errno( status, EAGAIN, "too many" );<br>
+Â <br>
+Â clock_gettime( CLOCK_MONOTONIC, &now );<br>
+Â itimer.it_value = now;<br>
+Â itimer.it_value.tv_sec = itimer.it_value.tv_sec - 1;<br>
+Â puts( "timer_settime (monotonic) - bad itimer value - previous time - EINVAL" );<br>
+Â status = timer_settime( timer, TIMER_ABSTIME, &itimer, NULL );<br>
+Â fatal_posix_service_status_errno( status, EINVAL, "bad itimer value #3" );<br>
+<br>
+Â clock_gettime( CLOCK_MONOTONIC, &now );<br>
+Â itimer.it_value = now;<br>
+Â itimer.it_value.tv_sec = itimer.it_value.tv_sec + 1;<br>
+Â puts( "timer_settime (monotonic) - bad id - EINVAL" );<br>
+Â status = timer_settime( timer1, TIMER_ABSTIME, &itimer, NULL );<br>
+Â fatal_posix_service_status_errno( status, EINVAL, "bad id" );<br>
<br>
  TEST_END();<br>
  rtems_test_exit (0);<br>
diff --git a/testsuites/psxtests/psxtimer02/psxtimer02.scn b/testsuites/psxtests/psxtimer02/psxtimer02.scn<br>
index e78425a32e..995bcda4e3 100644<br>
--- a/testsuites/psxtests/psxtimer02/psxtimer02.scn<br>
+++ b/testsuites/psxtests/psxtimer02/psxtimer02.scn<br>
@@ -13,4 +13,10 @@ timer_settime - bad itimer value - negative nanosecond - EINVAL<br>
 timer_settime - bad clock value - EINVAL<br>
 timer_delete - OK<br>
 timer_delete - bad id - EINVAL<br>
+timer_create (monotonic) - bad timer id pointer - EINVAL<br>
+timer_create (monotonic) - OK<br>
+timer_create (monotonic) - too many - EAGAIN<br>
+timer_settime (monotonic) - bad itimer value - previous time - EINVAL<br>
+timer_settime (monotonic) - bad id - EINVAL<br>
+<br>
 *** END OF POSIX Timers Test 02 ***<br>
-- <br>
2.32.0<br>
<br>
</blockquote></div>