You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by "wangchdo (via GitHub)" <gi...@apache.org> on 2025/11/13 09:46:15 UTC

[PR] sched/clock: Only allow clock_get_sched_ticks() to access g_system_ticks [nuttx]

wangchdo opened a new pull request, #17326:
URL: https://github.com/apache/nuttx/pull/17326

   ## Summary
   
   This PR makes g_system_ticks a static variable, so it can only be accessed through clock_get_sched_ticks().
   This change improves code modularity and enhances safety, as clock_get_sched_ticks() performs proper synchronization when reading g_system_ticks.s
   
   ## Impact
   
   improved g_system_ticks implementation, no impact to existing nuttx functions
   
   ## Testing
   
   **ostest passed on board a2g-tc397-5v-tft**
   
   ```
   NuttShell (NSH)
   nsh>
   nsh> uname -a
   NuttX 0.0.0 457ed45dd7 Nov 13 2025 17:38:10 tricore a2g-tc397-5v-tft
   nsh>
   nsh> ostest
   
   (...)
   
   user_main: scheduler lock test
   sched_lock: Starting lowpri_thread at 97
   sched_lock: Set lowpri_thread priority to 97
   sched_lock: Starting highpri_thread at 98
   sched_lock: Set highpri_thread priority to 98
   sched_lock: Waiting...
   sched_lock: PASSED No pre-emption occurred while scheduler was locked.
   sched_lock: Starting lowpri_thread at 97
   sched_lock: Set lowpri_thread priority to 97
   sched_lock: Starting highpri_thread at 98
   sched_lock: Set highpri_thread priority to 98
   sched_lock: Waiting...
   sched_lock: PASSED No pre-emption occurred while scheduler was locked.
   sched_lock: Finished
   
   End of test memory usage:
   VARIABLE  BEFORE   AFTER
   ======== ======== ========
   arena       28dfc    28dfc
   ordblks         7        6
   mxordblk    1f8c8    1f8c8
   uordblks     553c     553c
   fordblks    238c0    238c0
   
   user_main: nxevent test
   
   End of test memory usage:
   VARIABLE  BEFORE   AFTER
   ======== ======== ========
   arena       28dfc    28dfc
   ordblks         6        6
   mxordblk    1f8c8    1f8c8
   uordblks     553c     553c
   fordblks    238c0    238c0
   
   Final memory usage:
   VARIABLE  BEFORE   AFTER
   ======== ======== ========
   arena       28dfc    28dfc
   ordblks         1        6
   mxordblk    24238    1f8c8
   uordblks     4bc4     553c
   fordblks    24238    238c0
   user_main: Exiting
   ostest_main: Exiting with status 0
   nsh>
   ```
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] sched/clock: Only allow clock_get_sched_ticks() to access g_system_ticks [nuttx]

Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #17326:
URL: https://github.com/apache/nuttx/pull/17326#discussion_r2522839721


##########
arch/arm/src/lc823450/lc823450_timer.c:
##########
@@ -705,7 +705,7 @@ int up_rtc_gettime(struct timespec *tp)
 
   /* Get the elapsed time */
 
-  elapsed = NSEC_PER_TICK * (uint64_t)g_system_ticks;
+  elapsed = NSEC_PER_TICK * (uint64_t)clock_get_sched_ticks();

Review Comment:
   why not  change this to clock_systime_ticks? so we don't need add a new api



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] sched/clock: Only allow clock_systime_ticks() to access g_system_ticks [nuttx]

Posted by "wangchdo (via GitHub)" <gi...@apache.org>.
wangchdo commented on code in PR #17326:
URL: https://github.com/apache/nuttx/pull/17326#discussion_r2523022778


##########
arch/arm/src/lc823450/lc823450_timer.c:
##########
@@ -705,7 +705,7 @@ int up_rtc_gettime(struct timespec *tp)
 
   /* Get the elapsed time */
 
-  elapsed = NSEC_PER_TICK * (uint64_t)g_system_ticks;
+  elapsed = NSEC_PER_TICK * (uint64_t)clock_get_sched_ticks();

Review Comment:
   Done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] sched/clock: Only allow clock_systime_ticks() to access g_system_ticks [nuttx]

Posted by "acassis (via GitHub)" <gi...@apache.org>.
acassis merged PR #17326:
URL: https://github.com/apache/nuttx/pull/17326


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] sched/clock: Only allow clock_get_sched_ticks() to access g_system_ticks [nuttx]

Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #17326:
URL: https://github.com/apache/nuttx/pull/17326#discussion_r2522839721


##########
arch/arm/src/lc823450/lc823450_timer.c:
##########
@@ -705,7 +705,7 @@ int up_rtc_gettime(struct timespec *tp)
 
   /* Get the elapsed time */
 
-  elapsed = NSEC_PER_TICK * (uint64_t)g_system_ticks;
+  elapsed = NSEC_PER_TICK * (uint64_t)clock_get_sched_ticks();

Review Comment:
   why not  change this to clock_systime_ticks



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org