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 08:35:12 UTC
[GitHub] [nuttx] extinguish commented on a diff in pull request #9691: sched/clock/clock_getcpuclockid: add clock_getcpuclockid implementation
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