You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2021/07/20 05:40:37 UTC

[GitHub] [incubator-nuttx] xiaoxiang781216 opened a new pull request #4186: libc: Implement times function

xiaoxiang781216 opened a new pull request #4186:
URL: https://github.com/apache/incubator-nuttx/pull/4186


   ## Summary
   
   ## 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] [incubator-nuttx] acassis edited a comment on pull request #4186: libc: Implement times function

Posted by GitBox <gi...@apache.org>.
acassis edited a comment on pull request #4186:
URL: https://github.com/apache/incubator-nuttx/pull/4186#issuecomment-883350583


   Hi @xiaoxiang781216 why aren't the fields of tms filled?
   What happens when you run this example:
   ```
   #include <sys/times.h>
   #include <stdio.h>
   ...
   void start_clock(void);
   void end_clock(char *msg);
   ...
   static clock_t st_time;
   static clock_t en_time;
   static struct tms st_cpu;
   static struct tms en_cpu;
   ...
   void
   start_clock()
   {
       st_time = times(&st_cpu);
   }
   
   
   /* This example assumes that the result of each subtraction
      is within the range of values that can be represented in
      an integer type. */
   void
   end_clock(char *msg)
   {
       en_time = times(&en_cpu);
   
   
       fputs(msg,stdout);
       printf("Real Time: %jd, User Time %jd, System Time %jd\n",
           (intmax_t)(en_time - st_time),
           (intmax_t)(en_cpu.tms_utime - st_cpu.tms_utime),
           (intmax_t)(en_cpu.tms_stime - st_cpu.tms_stime));
   }
   ```


-- 
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] [incubator-nuttx] xiaoxiang781216 commented on a change in pull request #4186: libc: Implement times function

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on a change in pull request #4186:
URL: https://github.com/apache/incubator-nuttx/pull/4186#discussion_r673100882



##########
File path: libs/libc/unistd/lib_times.c
##########
@@ -0,0 +1,37 @@
+/****************************************************************************
+ * libs/libc/unistd/lib_times.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 <string.h>
+#include <sys/times.h>
+#include <time.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+

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



[GitHub] [incubator-nuttx] Ouss4 commented on a change in pull request #4186: libc: Implement times function

Posted by GitBox <gi...@apache.org>.
Ouss4 commented on a change in pull request #4186:
URL: https://github.com/apache/incubator-nuttx/pull/4186#discussion_r673176320



##########
File path: libs/libc/unistd/lib_times.c
##########
@@ -0,0 +1,61 @@
+/****************************************************************************
+ * libs/libc/unistd/lib_times.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 <errno.h>
+#include <string.h>
+#include <sys/times.h>
+#include <time.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: times
+ *
+ * Description:
+ *   The times() function shall fill the tms structure pointed to by buffer
+ *   with time-accounting information.
+ *
+ * Returned Value:
+ *   Upon successful completion, times() shall return the elapsed real time,
+ *   in clock ticks, since an arbitrary point in the past (for example,
+ *   system start-up time). This point does not change from one invocation
+ *   of times() within the process to another. The return value may overflow
+ *   the possible range of type clock_t. If times() fails, (clock_t)-1 shall
+ *   be returned and errno set to indicate the error.
+ *
+ ****************************************************************************/
+
+clock_t times(FAR struct tms *buffer)
+{
+  if (buffer == NULL)
+    {
+      set_errno(EINVAL);

Review comment:
       is `EINVAL` standard?  I can only see `EOVERFLOW`.




-- 
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] [incubator-nuttx] acassis commented on pull request #4186: libc: Implement times function

Posted by GitBox <gi...@apache.org>.
acassis commented on pull request #4186:
URL: https://github.com/apache/incubator-nuttx/pull/4186#issuecomment-883350583


   Hi @xiaoxiang781216 why aren't the fields of tms filled?
   What happens when you run this example:
   ```
   void
   end_clock(char *msg)
   {
       en_time = times(&en_cpu);
   
   
       fputs(msg,stdout);
       printf("Real Time: %jd, User Time %jd, System Time %jd\n",
           (intmax_t)(en_time - st_time),
           (intmax_t)(en_cpu.tms_utime - st_cpu.tms_utime),
           (intmax_t)(en_cpu.tms_stime - st_cpu.tms_stime));
   }
   ```


-- 
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] [incubator-nuttx] xiaoxiang781216 commented on pull request #4186: libc: Implement times function

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on pull request #4186:
URL: https://github.com/apache/incubator-nuttx/pull/4186#issuecomment-884303886


   @acassis could you merge it if my answer resolve your concern.


-- 
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] [incubator-nuttx] acassis merged pull request #4186: libc: Implement times function

Posted by GitBox <gi...@apache.org>.
acassis merged pull request #4186:
URL: https://github.com/apache/incubator-nuttx/pull/4186


   


-- 
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] [incubator-nuttx] xiaoxiang781216 commented on a change in pull request #4186: libc: Implement times function

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on a change in pull request #4186:
URL: https://github.com/apache/incubator-nuttx/pull/4186#discussion_r673198887



##########
File path: libs/libc/unistd/lib_times.c
##########
@@ -0,0 +1,61 @@
+/****************************************************************************
+ * libs/libc/unistd/lib_times.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 <errno.h>
+#include <string.h>
+#include <sys/times.h>
+#include <time.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: times
+ *
+ * Description:
+ *   The times() function shall fill the tms structure pointed to by buffer
+ *   with time-accounting information.
+ *
+ * Returned Value:
+ *   Upon successful completion, times() shall return the elapsed real time,
+ *   in clock ticks, since an arbitrary point in the past (for example,
+ *   system start-up time). This point does not change from one invocation
+ *   of times() within the process to another. The return value may overflow
+ *   the possible range of type clock_t. If times() fails, (clock_t)-1 shall
+ *   be returned and errno set to indicate the error.
+ *
+ ****************************************************************************/
+
+clock_t times(FAR struct tms *buffer)
+{
+  if (buffer == NULL)
+    {
+      set_errno(EINVAL);

Review comment:
       The same question has been dissussed before, please reference there:
   https://github.com/apache/incubator-nuttx/pull/4121#discussion_r668207133




-- 
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] [incubator-nuttx] xiaoxiang781216 commented on pull request #4186: libc: Implement times function

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on pull request #4186:
URL: https://github.com/apache/incubator-nuttx/pull/4186#issuecomment-883371066


   > Hi @xiaoxiang781216 why aren't the fields of tms filled?
   > What happens when you run this example:
   > }
   > ```
   
   per task/child don't consume any user/kernel time, but the returned clock is right.
   


-- 
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] [incubator-nuttx] saramonteiro commented on a change in pull request #4186: libc: Implement times function

Posted by GitBox <gi...@apache.org>.
saramonteiro commented on a change in pull request #4186:
URL: https://github.com/apache/incubator-nuttx/pull/4186#discussion_r673079415



##########
File path: libs/libc/unistd/lib_times.c
##########
@@ -0,0 +1,37 @@
+/****************************************************************************
+ * libs/libc/unistd/lib_times.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 <string.h>
+#include <sys/times.h>
+#include <time.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+

Review comment:
       ```suggestion
   /****************************************************************************
    * Name: times
    *
    * Description:
    *   The times() function shall fill the tms structure pointed to by buffer
    *   with time-accounting information.
    *
    * Returned Value:
    *   Upon successful completion, times() shall return the elapsed real time,
    *   in clock ticks, since an arbitrary point in the past (for example,
    *   system start-up time). This point does not change from one invocation
    *   of times() within the process to another. The return value may overflow
    *   the possible range of type clock_t. If times() fails, (clock_t)-1 shall
    *   be returned and errno set to indicate the error.
    *
    ****************************************************************************/
   ```
   BTW, shouldn't you verify the fail scenario and set `errno` here?




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