<div dir="auto">He passed me the correct one via Discord and I ran tests on leon3 and two failed like his results.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Aug 11, 2021, 12:09 PM Gedare Bloom <<a href="mailto:gedare@rtems.org">gedare@rtems.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">this was the wrong patch version.<br>
<br>
On Wed, Aug 11, 2021 at 11:03 AM Joel Sherrill <<a href="mailto:joel@rtems.org" target="_blank" rel="noreferrer">joel@rtems.org</a>> wrote:<br>
><br>
> Module:    rtems<br>
> Branch:    master<br>
> Commit:    8df57649b09f31a58660d9b3c2478195f15f40ce<br>
> Changeset: <a href="http://git.rtems.org/rtems/commit/?id=8df57649b09f31a58660d9b3c2478195f15f40ce" rel="noreferrer noreferrer" target="_blank">http://git.rtems.org/rtems/commit/?id=8df57649b09f31a58660d9b3c2478195f15f40ce</a><br>
><br>
> Author:    Zacchaeus Leung <<a href="mailto:zakthertemsdev@outlook.com" target="_blank" rel="noreferrer">zakthertemsdev@outlook.com</a>><br>
> Date:      Fri Aug  6 11:20:41 2021 -0400<br>
><br>
> Test needed for timer_create with CLOCK_MONOTONC<br>
><br>
> the timer_create() method can use CLOCK_MONOTONIC<br>
> but there was  no test for this.<br>
> Also it implements the functionality to<br>
> create a CLOCK_MONOTONIC timer and gettime() .<br>
> Closes #3888<br>
><br>
> ---<br>
><br>
>  cpukit/include/rtems/posix/timer.h            |  1 +<br>
>  cpukit/posix/src/psxtimercreate.c             |  3 +-<br>
>  cpukit/posix/src/timergettime.c               | 48 +++++++++++++++++----------<br>
>  testsuites/psxtests/psxtimer02/psxtimer.c     | 26 +++++++++++++++<br>
>  testsuites/psxtests/psxtimer02/psxtimer02.scn |  5 +++<br>
>  5 files changed, 64 insertions(+), 19 deletions(-)<br>
><br>
> diff --git a/cpukit/include/rtems/posix/timer.h b/cpukit/include/rtems/posix/timer.h<br>
> index bcbf07a..7ae0891 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 a63cf1d..2b5a101 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 ee2a566..f4b2596 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>
> @@ -42,32 +43,43 @@ int timer_gettime(<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>
> \ No newline at end of file<br>
> diff --git a/testsuites/psxtests/psxtimer02/psxtimer.c b/testsuites/psxtests/psxtimer02/psxtimer.c<br>
> index 9f79d33..874a789 100644<br>
> --- a/testsuites/psxtests/psxtimer02/psxtimer.c<br>
> +++ b/testsuites/psxtests/psxtimer02/psxtimer.c<br>
> @@ -127,6 +127,32 @@ void *POSIX_Init (<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>
>  }<br>
> diff --git a/testsuites/psxtests/psxtimer02/psxtimer02.scn b/testsuites/psxtests/psxtimer02/psxtimer02.scn<br>
> index e78425a..71638aa 100644<br>
> --- a/testsuites/psxtests/psxtimer02/psxtimer02.scn<br>
> +++ b/testsuites/psxtests/psxtimer02/psxtimer02.scn<br>
> @@ -13,4 +13,9 @@ 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>
>  *** END OF POSIX Timers Test 02 ***<br>
><br>
> _______________________________________________<br>
> vc mailing list<br>
> <a href="mailto:vc@rtems.org" target="_blank" rel="noreferrer">vc@rtems.org</a><br>
> <a href="http://lists.rtems.org/mailman/listinfo/vc" rel="noreferrer noreferrer" target="_blank">http://lists.rtems.org/mailman/listinfo/vc</a><br>
</blockquote></div>