Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

posix: implement clock_getcpuclockid() #59954

Closed
Tracked by #51211
ycsin opened this issue Jul 3, 2023 · 11 comments · Fixed by #67337
Closed
Tracked by #51211

posix: implement clock_getcpuclockid() #59954

ycsin opened this issue Jul 3, 2023 · 11 comments · Fixed by #67337
Labels
area: POSIX POSIX API Library Feature Request A request for a new feature Good first issue Good for a first time contributor to take

Comments

@ycsin
Copy link
Member

ycsin commented Jul 3, 2023

There are currently 20 missing POSIX functions with trivial implementations, clock_getcpuclockid() is one of them.

clock_getcpuclockid - access a process CPU-time clock (ADVANCED REALTIME)

The clock_getcpuclockid() function shall return the clock ID of the CPU-time clock of the process specified by pid. If the process described by pid exists and the calling process has permission, the clock ID of this clock shall be returned in clock_id.

If pid is zero, the clock_getcpuclockid() function shall return the clock ID of the CPU-time clock of the process making the call, in clock_id.

The conditions under which one process has permission to obtain the CPU-time clock ID of other processes are implementation-defined.

See https://pubs.opengroup.org/onlinepubs/9699919799/functions/clock_getcpuclockid.html

See RFC #51211 for more info.

@ycsin ycsin added Feature Request A request for a new feature Good first issue Good for a first time contributor to take area: POSIX POSIX API Library labels Jul 3, 2023
@ycsin ycsin moved this from To Do to LTS3 Goals in Release Plan Jul 3, 2023
@ycsin ycsin added this to the v3.5.0 milestone Jul 3, 2023
@cfriedt cfriedt assigned cfriedt and unassigned cfriedt Jul 4, 2023
@cfriedt cfriedt removed the status in Release Plan Sep 12, 2023
@nashif nashif removed this from Release Plan Sep 13, 2023
@cfriedt cfriedt removed this from the v3.5.0 milestone Oct 13, 2023
@jaiiarora
Copy link
Contributor

jaiiarora commented Dec 20, 2023

I would like to work on this issue. Can you assign it to me? @cfriedt

@cfriedt
Copy link
Member

cfriedt commented Dec 20, 2023

I would like to work on this issue. Can you assign it to me? @cfriedt

Hi @jaiiarora - typically maintainers get assigned issues, but you are absolutely free to create a pull request to add this feature

Thanks for your help, and I look forward to your PR

@jaiiarora
Copy link
Contributor

@cfriedt Hi I am trying to implement clock_getcpuclockid() but I could not find pid_t or getpid() function that are needed for the implementation. Can you suggest me how to tackle this?

@cfriedt
Copy link
Member

cfriedt commented Dec 22, 2023

@cfriedt Hi I am trying to implement clock_getcpuclockid() but I could not find pid_t or getpid() function that are needed for the implementation. Can you suggest me how to tackle this?

I don't think we have pid_t or getpid() yet.

I do have a draft PR to add them though :-) (#65920).

In any case, probably the best way to ask for feedback on a PR before it's ready for review is to create a draft PR.

The "Create PR" button in GitHub also has a drop-down menu where you can select "Create Draft PR" instead.

@cfriedt
Copy link
Member

cfriedt commented Dec 22, 2023

@jaiiarora - I'll separate-out the declaration of pid_t and getpid() to another PR. That will hopefully unblock you. In the mean time, you can just use this:

typedef int pid_t;

pid_t getpid(void);
// in some c file
pid_t getpid(void)
{
    return 42;
}

Keep in mind, that Zephyr only (conceptually) supports a single process at any given time, so for the purposes of your PR, you can probably just ignore pid entirely in the implementation of clock_getcpuclockid(pid_t pid, clockid_t *clock_id).

@jaiiarora
Copy link
Contributor

jaiiarora commented Dec 22, 2023

Sure. Thanks a lot @cfriedt :)

jaiiarora added a commit to jaiiarora/zephyr that referenced this issue Dec 28, 2023
implements clock_getcpuclockid function and
adds zephyr test.

Fixes zephyrproject-rtos#59954

Signed-off-by: Jai Arora <infolinesoni@gmail.com>
@jaiiarora
Copy link
Contributor

Hi @cfriedt. I have created a draft PR. Kindly have a look at it. Please let me know if any changes are needed. Thanks

@cfriedt
Copy link
Member

cfriedt commented Dec 28, 2023

Hi @cfriedt. I have created a draft PR. Kindly have a look at it. Please let me know if any changes are needed. Thanks

Hi @jaiiarora - are you on discord by any chance? Can you add me?

I would be happy to give you a few pointers "offline" so you can get your draft in better shape before publishing.

@jaiiarora
Copy link
Contributor

Sure. Let me ping you @cfriedt

jaiiarora added a commit to jaiiarora/zephyr that referenced this issue Dec 30, 2023
Implements clock_getcpuclockid function and
adds zephyr test cases.

Fixes zephyrproject-rtos#59954

Signed-off-by: Jai Arora <infolinesoni@gmail.com>
@jaiiarora
Copy link
Contributor

Hi @cfriedt. I have added the requested changes.

  • added new macro for CLOCK_PROCESS_CPUTIME_ID
  • changed clock_getcpuclockid accordingly
  • moved getpid delcaration to zephyr/posix/unistd.h
    Please have a look at it and let me know if any changes are needed.

jaiiarora added a commit to jaiiarora/zephyr that referenced this issue Jan 1, 2024
Implements clock_getcpuclockid function

Fixes zephyrproject-rtos#59954

Signed-off-by: Jai Arora <infolinesoni@gmail.com>
jaiiarora added a commit to jaiiarora/zephyr that referenced this issue Jan 2, 2024
Implements clock_getcpuclockid function

Fixes zephyrproject-rtos#59954

Signed-off-by: Jai Arora <infolinesoni@gmail.com>
jaiiarora added a commit to jaiiarora/zephyr that referenced this issue Jan 3, 2024
Implements clock_getcpuclockid function

Fixes zephyrproject-rtos#59954

Signed-off-by: Jai Arora <infolinesoni@gmail.com>
jaiiarora added a commit to jaiiarora/zephyr that referenced this issue Jan 3, 2024
Implements clock_getcpuclockid function

Fixes zephyrproject-rtos#59954

Signed-off-by: Jai Arora <infolinesoni@gmail.com>
jaiiarora added a commit to jaiiarora/zephyr that referenced this issue Jan 5, 2024
Implements clock_getcpuclockid function

Fixes zephyrproject-rtos#59954

Signed-off-by: Jai Arora <infolinesoni@gmail.com>
jaiiarora added a commit to jaiiarora/zephyr that referenced this issue Jan 8, 2024
Adds test for clock_getcpuclockid() to
make sure clock_id is equal to CLOCK_PROCESS_CPUTIME_ID
after a successful call

Fixes zephyrproject-rtos#59954

Signed-off-by: Jai Arora <infolinesoni@gmail.com>
jaiiarora added a commit to jaiiarora/zephyr that referenced this issue Jan 8, 2024
Adds test for clock_getcpuclockid() to
make sure clock_id is equal to CLOCK_PROCESS_CPUTIME_ID
after a successful call

Fixes zephyrproject-rtos#59954

Signed-off-by: Jai Arora <infolinesoni@gmail.com>
jaiiarora added a commit to jaiiarora/zephyr that referenced this issue Jan 8, 2024
Adds test for clock_getcpuclockid() to
make sure clock_id is equal to CLOCK_PROCESS_CPUTIME_ID
after a successful call

Fixes zephyrproject-rtos#59954

Signed-off-by: Jai Arora <infolinesoni@gmail.com>
@jaiiarora
Copy link
Contributor

Hi @cfriedt. I have added the missing test case in this PR. Please have a look at it. Thanks

jaiiarora added a commit to jaiiarora/zephyr that referenced this issue Jan 19, 2024
Adds test for clock_getcpuclockid() to
make sure clock_id is equal to CLOCK_PROCESS_CPUTIME_ID
after a successful call

Fixes zephyrproject-rtos#59954

Signed-off-by: Jai Arora <infolinesoni@gmail.com>
aescolar pushed a commit that referenced this issue Jan 20, 2024
Adds test for clock_getcpuclockid() to
make sure clock_id is equal to CLOCK_PROCESS_CPUTIME_ID
after a successful call

Fixes #59954

Signed-off-by: Jai Arora <infolinesoni@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: POSIX POSIX API Library Feature Request A request for a new feature Good first issue Good for a first time contributor to take
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants