You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by "extinguish (via GitHub)" <gi...@apache.org> on 2023/07/04 03:14:23 UTC

[GitHub] [nuttx] extinguish opened a new pull request, #9691: sched/clock/clock_getcpuclockid: add clock_getcpuclockid implementation

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

   ## Summary
   1. the implementation can pass the full ltp/open_posix_testsuite/clock_getcpuclockid testcases
   2. the modification are referred to https://pubs.opengroup.org/onlinepubs/9699919799/functions/clock_getcpuclockid.html
   
   ## Impact
   
   ## Testing
   
   


-- 
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


[GitHub] [nuttx] xiaoxiang781216 commented on a diff in pull request #9691: sched/clock/clock_getcpuclockid: add clock_getcpuclockid implementation

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


##########
sched/clock/clock_getcpuclockid.c:
##########
@@ -0,0 +1,74 @@
+/****************************************************************************
+ * sched/clock/clock_getcpuclockid.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <time.h>
+#include <errno.h>
+#include <unistd.h>
+
+#include "clock/clock.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: clock_getcpuclockid
+ *
+ * Description:
+ *   The function shall return clock id of the CPU-time clock of the process
+ *   specified by pid
+ *
+ * Input Parameters:
+ *   pid - the specified process id
+ *   clockid - the clock type that need to setup
+ *
+ * Returned Value:
+ *   Return 0 on success, return error number on error
+ *
+ ****************************************************************************/
+
+int clock_getcpuclockid(pid_t pid, FAR clockid_t *clockid)
+{
+  if (pid < 0)
+    {
+      set_errno(EINVAL);
+      return ERROR;
+    }

Review Comment:
   yes, you are right. @extinguish please modify the error code handling



-- 
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


[GitHub] [nuttx] extinguish commented on a diff in pull request #9691: sched/clock/clock_getcpuclockid: add clock_getcpuclockid implementation

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


##########
sched/clock/clock_getcpuclockid.c:
##########
@@ -0,0 +1,74 @@
+/****************************************************************************
+ * sched/clock/clock_getcpuclockid.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <time.h>
+#include <errno.h>
+#include <unistd.h>
+
+#include "clock/clock.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: clock_getcpuclockid
+ *
+ * Description:
+ *   The function shall return clock id of the CPU-time clock of the process
+ *   specified by pid
+ *
+ * Input Parameters:
+ *   pid - the specified process id
+ *   clockid - the clock type that need to setup
+ *
+ * Returned Value:
+ *   Return 0 on success, return error number on error
+ *
+ ****************************************************************************/
+
+int clock_getcpuclockid(pid_t pid, FAR clockid_t *clockid)
+{
+  if (pid < 0)
+    {
+      set_errno(EINVAL);
+      return ERROR;
+    }
+
+  /* If the pid is 0, we need to use the pid of current process */
+
+  if (pid == 0)
+    {
+      pid = getpid();
+    }
+
+  /* For clock_getcpuclockid, the clock type are
+   * CLOCK_PROCESS_CPUTIME_ID
+   */
+
+  *clockid = (pid << CLOCK_SHIFT) | CLOCK_PROCESS_CPUTIME_ID;
+  return OK;

Review Comment:
   since clock_getres(), clock_gettime() are defined as syscall, and clock_getcpuclockid() are also a method that uesed together with clock_getres(), clock_gettime(), so it's better to define clock_getcpuclockid() as a syscall.



-- 
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


[GitHub] [nuttx] pkarashchenko commented on a diff in pull request #9691: sched/clock/clock_getcpuclockid: add clock_getcpuclockid implementation

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


##########
sched/clock/clock_gettime.c:
##########
@@ -131,6 +137,57 @@ int clock_gettime(clockid_t clock_id, struct timespec *tp)
         }
 #endif /* CONFIG_CLOCK_TIMEKEEPING */
     }
+#ifdef CONFIG_SCHED_CRITMONITOR
+  else if (clock_type == CLOCK_THREAD_CPUTIME_ID)
+    {
+      FAR struct tcb_s *tcb;
+
+      if (pid == 0)
+        {
+          /* Fetch the THREAD_CPUTIME for current thread */
+
+          tcb = nxsched_self();
+        }
+      else
+        {
+          tcb = nxsched_get_tcb(pid);
+        }
+
+      up_perf_convert(tcb->run_time, tp);
+    }
+  else if (clock_type == CLOCK_PROCESS_CPUTIME_ID)
+    {
+      FAR struct task_group_s *group;
+      unsigned long runtime;
+      irqstate_t flags;
+      int i;
+      FAR struct tcb_s *tcb;
+
+      if (pid == 0)
+        {
+          /* Fetch the PROCESS_CPUTIME for current process */
+
+          tcb = nxsched_self();
+        }
+      else
+        {
+           tcb = nxsched_get_tcb(pid);
+        }
+

Review Comment:
   ```suggestion
           {
             tcb = nxsched_get_tcb(pid);
           }
   
   ```
   



-- 
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


[GitHub] [nuttx] pkarashchenko commented on a diff in pull request #9691: sched/clock/clock_getcpuclockid: add clock_getcpuclockid implementation

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


##########
sched/clock/clock_getcpuclockid.c:
##########
@@ -0,0 +1,74 @@
+/****************************************************************************
+ * sched/clock/clock_getcpuclockid.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <time.h>
+#include <errno.h>
+#include <unistd.h>
+
+#include "clock/clock.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: clock_getcpuclockid
+ *
+ * Description:
+ *   The function shall return clock id of the CPU-time clock of the process
+ *   specified by pid
+ *
+ * Input Parameters:
+ *   pid - the specified process id
+ *   clockid - the clock type that need to setup
+ *
+ * Returned Value:
+ *   Return 0 on success, return error number on error
+ *
+ ****************************************************************************/
+
+int clock_getcpuclockid(pid_t pid, FAR clockid_t *clockid)
+{
+  if (pid < 0)
+    {
+      set_errno(EINVAL);
+      return ERROR;
+    }
+
+  /* If the pid is 0, we need to use the pid of current process */
+
+  if (pid == 0)
+    {
+      pid = getpid();
+    }
+
+  /* For clock_getcpuclockid, the clock type are
+   * CLOCK_PROCESS_CPUTIME_ID
+   */
+
+  *clockid = (pid << CLOCK_SHIFT) | CLOCK_PROCESS_CPUTIME_ID;
+  return OK;

Review Comment:
   I'm wrong with the `clock_getres` assumption. It should reside in the kernel. We can proceed with the current approach and optimize later. Please fix C89 incompatibility and let's move forward.



-- 
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


[GitHub] [nuttx] pkarashchenko commented on a diff in pull request #9691: sched/clock/clock_getcpuclockid: add clock_getcpuclockid implementation

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


##########
sched/clock/clock_getcpuclockid.c:
##########
@@ -0,0 +1,74 @@
+/****************************************************************************
+ * sched/clock/clock_getcpuclockid.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <time.h>
+#include <errno.h>
+#include <unistd.h>
+
+#include "clock/clock.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: clock_getcpuclockid
+ *
+ * Description:
+ *   The function shall return clock id of the CPU-time clock of the process
+ *   specified by pid
+ *
+ * Input Parameters:
+ *   pid - the specified process id
+ *   clockid - the clock type that need to setup
+ *
+ * Returned Value:
+ *   Return 0 on success, return error number on error
+ *
+ ****************************************************************************/
+
+int clock_getcpuclockid(pid_t pid, FAR clockid_t *clockid)
+{
+  if (pid < 0)
+    {
+      set_errno(EINVAL);
+      return ERROR;
+    }
+
+  /* If the pid is 0, we need to use the pid of current process */
+
+  if (pid == 0)
+    {
+      pid = getpid();
+    }
+
+  /* For clock_getcpuclockid, the clock type are
+   * CLOCK_PROCESS_CPUTIME_ID
+   */
+
+  *clockid = (pid << CLOCK_SHIFT) | CLOCK_PROCESS_CPUTIME_ID;
+  return OK;

Review Comment:
   `clock_getres` can be easily moved to libc as well while `clock_gettime` should remain a sys call. @xiaoxiang781216 what is your opinion on this? I think that simple functions that do not need interaction with kernel services should be placed in libc to reduce the number of system calls.



-- 
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


[GitHub] [nuttx] pkarashchenko commented on a diff in pull request #9691: sched/clock/clock_getcpuclockid: add clock_getcpuclockid implementation

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


##########
sched/clock/clock_gettime.c:
##########
@@ -131,6 +137,55 @@ int clock_gettime(clockid_t clock_id, struct timespec *tp)
         }
 #endif /* CONFIG_CLOCK_TIMEKEEPING */
     }
+#ifdef CONFIG_SCHED_CRITMONITOR
+  else if (clock_type == CLOCK_THREAD_CPUTIME_ID)
+    {
+      FAR struct tcb_s *tcb;
+
+      if (pid == 0)
+        {
+          /* Fetch the THREAD_CPUTIME for current thread */
+
+          tcb = nxsched_self();
+        }
+      else
+        {
+          tcb = nxsched_get_tcb(pid);
+        }
+
+      up_perf_convert(tcb->run_time, tp);
+    }
+  else if (clock_type == CLOCK_PROCESS_CPUTIME_ID)
+    {
+      FAR struct tcb_s *tcb;
+
+      if (pid == 0)
+        {
+          /* Fetch the PROCESS_CPUTIME for current process */
+
+          tcb = nxsched_self();
+        }
+      else
+        {
+           tcb = nxsched_get_tcb(pid);
+        }
+
+      FAR struct task_group_s *group = tcb->group;
+      unsigned long runtime = 0;
+      irqstate_t flags;
+      int i;

Review Comment:
   C89 incompatible



##########
sched/clock/clock_getcpuclockid.c:
##########
@@ -0,0 +1,74 @@
+/****************************************************************************
+ * sched/clock/clock_getcpuclockid.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <time.h>
+#include <errno.h>
+#include <unistd.h>
+
+#include "clock/clock.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: clock_getcpuclockid
+ *
+ * Description:
+ *   The function shall return clock id of the CPU-time clock of the process
+ *   specified by pid
+ *
+ * Input Parameters:
+ *   pid - the specified process id
+ *   clockid - the clock type that need to setup
+ *
+ * Returned Value:
+ *   Return 0 on success, return error number on error
+ *
+ ****************************************************************************/
+
+int clock_getcpuclockid(pid_t pid, FAR clockid_t *clockid)
+{
+  if (pid < 0)
+    {
+      set_errno(EINVAL);
+      return ERROR;
+    }
+
+  /* If the pid is 0, we need to use the pid of current process */
+
+  if (pid == 0)
+    {
+      pid = getpid();
+    }
+
+  /* For clock_getcpuclockid, the clock type are
+   * CLOCK_PROCESS_CPUTIME_ID
+   */
+
+  *clockid = (pid << CLOCK_SHIFT) | CLOCK_PROCESS_CPUTIME_ID;
+  return OK;

Review Comment:
   Can this be a part of libc?



-- 
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


[GitHub] [nuttx] pkarashchenko commented on a diff in pull request #9691: sched/clock/clock_getcpuclockid: add clock_getcpuclockid implementation

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


##########
sched/clock/clock_getcpuclockid.c:
##########
@@ -0,0 +1,74 @@
+/****************************************************************************
+ * sched/clock/clock_getcpuclockid.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <time.h>
+#include <errno.h>
+#include <unistd.h>
+
+#include "clock/clock.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: clock_getcpuclockid
+ *
+ * Description:
+ *   The function shall return clock id of the CPU-time clock of the process
+ *   specified by pid
+ *
+ * Input Parameters:
+ *   pid - the specified process id
+ *   clockid - the clock type that need to setup
+ *
+ * Returned Value:
+ *   Return 0 on success, return error number on error
+ *
+ ****************************************************************************/
+
+int clock_getcpuclockid(pid_t pid, FAR clockid_t *clockid)
+{
+  if (pid < 0)
+    {
+      set_errno(EINVAL);
+      return ERROR;
+    }

Review Comment:
   This in fact also is not compatible with https://pubs.opengroup.org/onlinepubs/9699919799/functions/clock_getcpuclockid.html
   Most probably should be
   ```
     if (pid == 0)
       {
         pid = getpid();
       }
     else if (kill(pid, 0) < 0)
       {
         return ERROR;
       }
   ```



-- 
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


[GitHub] [nuttx] pkarashchenko commented on a diff in pull request #9691: sched/clock/clock_getcpuclockid: add clock_getcpuclockid implementation

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


##########
sched/clock/clock_getcpuclockid.c:
##########
@@ -0,0 +1,74 @@
+/****************************************************************************
+ * sched/clock/clock_getcpuclockid.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <time.h>
+#include <errno.h>
+#include <unistd.h>
+
+#include "clock/clock.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: clock_getcpuclockid
+ *
+ * Description:
+ *   The function shall return clock id of the CPU-time clock of the process
+ *   specified by pid
+ *
+ * Input Parameters:
+ *   pid - the specified process id
+ *   clockid - the clock type that need to setup
+ *
+ * Returned Value:
+ *   Return 0 on success, return error number on error
+ *
+ ****************************************************************************/
+
+int clock_getcpuclockid(pid_t pid, FAR clockid_t *clockid)
+{
+  if (pid < 0)
+    {
+      set_errno(EINVAL);
+      return ERROR;
+    }

Review Comment:
   Addressed here https://github.com/apache/nuttx/pull/9735



-- 
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


[GitHub] [nuttx] extinguish commented on a diff in pull request #9691: sched/clock/clock_getcpuclockid: add clock_getcpuclockid implementation

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


##########
sched/clock/clock_gettime.c:
##########
@@ -131,6 +137,57 @@ int clock_gettime(clockid_t clock_id, struct timespec *tp)
         }
 #endif /* CONFIG_CLOCK_TIMEKEEPING */
     }
+#ifdef CONFIG_SCHED_CRITMONITOR
+  else if (clock_type == CLOCK_THREAD_CPUTIME_ID)
+    {
+      FAR struct tcb_s *tcb;
+
+      if (pid == 0)
+        {
+          /* Fetch the THREAD_CPUTIME for current thread */
+
+          tcb = nxsched_self();
+        }
+      else
+        {
+          tcb = nxsched_get_tcb(pid);
+        }
+
+      up_perf_convert(tcb->run_time, tp);
+    }
+  else if (clock_type == CLOCK_PROCESS_CPUTIME_ID)
+    {
+      FAR struct task_group_s *group;
+      unsigned long runtime;
+      irqstate_t flags;
+      int i;
+      FAR struct tcb_s *tcb;
+
+      if (pid == 0)
+        {
+          /* Fetch the PROCESS_CPUTIME for current process */
+
+          tcb = nxsched_self();
+        }
+      else
+        {
+           tcb = nxsched_get_tcb(pid);
+        }
+

Review Comment:
   fixed in https://github.com/apache/nuttx/pull/9701



-- 
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


[GitHub] [nuttx] pkarashchenko commented on a diff in pull request #9691: sched/clock/clock_getcpuclockid: add clock_getcpuclockid implementation

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


##########
sched/clock/clock_getcpuclockid.c:
##########
@@ -0,0 +1,74 @@
+/****************************************************************************
+ * sched/clock/clock_getcpuclockid.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <time.h>
+#include <errno.h>
+#include <unistd.h>
+
+#include "clock/clock.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: clock_getcpuclockid
+ *
+ * Description:
+ *   The function shall return clock id of the CPU-time clock of the process
+ *   specified by pid
+ *
+ * Input Parameters:
+ *   pid - the specified process id
+ *   clockid - the clock type that need to setup
+ *
+ * Returned Value:
+ *   Return 0 on success, return error number on error
+ *
+ ****************************************************************************/
+
+int clock_getcpuclockid(pid_t pid, FAR clockid_t *clockid)
+{
+  if (pid < 0)
+    {
+      set_errno(EINVAL);
+      return ERROR;
+    }
+
+  /* If the pid is 0, we need to use the pid of current process */
+
+  if (pid == 0)
+    {
+      pid = getpid();
+    }
+
+  /* For clock_getcpuclockid, the clock type are
+   * CLOCK_PROCESS_CPUTIME_ID
+   */
+
+  *clockid = (pid << CLOCK_SHIFT) | CLOCK_PROCESS_CPUTIME_ID;
+  return OK;

Review Comment:
   Yes. I do not see a reason for adding new system call.
   We can use `pid = _SCHED_GETPID();` and implement it as a libc function



-- 
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


[GitHub] [nuttx] extinguish commented on a diff in pull request #9691: sched/clock/clock_getcpuclockid: add clock_getcpuclockid implementation

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


##########
sched/clock/clock_getcpuclockid.c:
##########
@@ -0,0 +1,74 @@
+/****************************************************************************
+ * sched/clock/clock_getcpuclockid.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <time.h>
+#include <errno.h>
+#include <unistd.h>
+
+#include "clock/clock.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: clock_getcpuclockid
+ *
+ * Description:
+ *   The function shall return clock id of the CPU-time clock of the process
+ *   specified by pid
+ *
+ * Input Parameters:
+ *   pid - the specified process id
+ *   clockid - the clock type that need to setup
+ *
+ * Returned Value:
+ *   Return 0 on success, return error number on error
+ *
+ ****************************************************************************/
+
+int clock_getcpuclockid(pid_t pid, FAR clockid_t *clockid)
+{
+  if (pid < 0)
+    {
+      set_errno(EINVAL);
+      return ERROR;
+    }
+
+  /* If the pid is 0, we need to use the pid of current process */
+
+  if (pid == 0)
+    {
+      pid = getpid();
+    }
+
+  /* For clock_getcpuclockid, the clock type are
+   * CLOCK_PROCESS_CPUTIME_ID
+   */
+
+  *clockid = (pid << CLOCK_SHIFT) | CLOCK_PROCESS_CPUTIME_ID;
+  return OK;

Review Comment:
   do you mean that this "clock_getcpuclockid()" method should not defined as a syscall, but as a libc method direct ?



-- 
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


[GitHub] [nuttx] pkarashchenko commented on a diff in pull request #9691: sched/clock/clock_getcpuclockid: add clock_getcpuclockid implementation

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


##########
sched/clock/clock_gettime.c:
##########
@@ -58,6 +59,13 @@ int clock_gettime(clockid_t clock_id, struct timespec *tp)
 #endif
   int ret = OK;
 
+  clockid_t clock_type = clock_id & CLOCK_MASK;
+#ifdef CONFIG_SCHED_CRITMONITOR
+  FAR struct task_group_s *group;

Review Comment:
   Let's place it in `else if (clock_type == CLOCK_PROCESS_CPUTIME_ID)` scope



-- 
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


[GitHub] [nuttx] pkarashchenko commented on a diff in pull request #9691: sched/clock/clock_getcpuclockid: add clock_getcpuclockid implementation

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


##########
sched/clock/clock_gettime.c:
##########
@@ -131,6 +137,57 @@ int clock_gettime(clockid_t clock_id, struct timespec *tp)
         }
 #endif /* CONFIG_CLOCK_TIMEKEEPING */
     }
+#ifdef CONFIG_SCHED_CRITMONITOR
+  else if (clock_type == CLOCK_THREAD_CPUTIME_ID)
+    {
+      FAR struct tcb_s *tcb;
+
+      if (pid == 0)
+        {
+          /* Fetch the THREAD_CPUTIME for current thread */
+
+          tcb = nxsched_self();
+        }
+      else
+        {
+          tcb = nxsched_get_tcb(pid);
+        }
+
+      up_perf_convert(tcb->run_time, tp);
+    }
+  else if (clock_type == CLOCK_PROCESS_CPUTIME_ID)
+    {
+      FAR struct task_group_s *group;
+      unsigned long runtime;
+      FAR struct tcb_s *tcb;
+
+      if (pid == 0)
+        {
+          /* Fetch the PROCESS_CPUTIME for current process */
+
+          tcb = nxsched_self();
+        }
+      else
+        {
+           tcb = nxsched_get_tcb(pid);
+        }
+
+      group = tcb->group;
+      runtime = 0;
+      irqstate_t flags;
+      int i;

Review Comment:
   Please move this to the beginning of the `else if (clock_type == CLOCK_PROCESS_CPUTIME_ID)` scope as well



-- 
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


[GitHub] [nuttx] xiaoxiang781216 merged pull request #9691: sched/clock/clock_getcpuclockid: add clock_getcpuclockid implementation

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


-- 
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