How do I know the dwell time of the Darwin kernel kernel scheduler?

Linux sched.h contains a definition

int sched_rr_get_interval(pid_t pid, struct timespec * tp);

to get the time span of the process. However, sending a file with OS X El Capitan does not support this definition.

Is there an alternative for this in OS X?

+5
source share
1 answer

The API associated with this material is quite Byzantine and poorly documented, but here's what I found.

First, the data types associated with RR scheduling seem to be in /usr/include/mach/policy.h , around line 155. There is this structure:

 struct policy_rr_info { ... integer_t quantum; .... }; 

quantum , I think the time limit is (not sure about the units.) Then grepping around for this or related types defined in the same place, I found the file /usr/include/mach/mach_types.def , which says that type struct thread_policy_t contains the field policy_rr_info_t in line 203.

Next, I found in /usr/include/mach/thread_act.h public thread_policy_get function, which can receive thread policy information in struct thread_policy_t * .

So, work back. I think (but have not tried it at all) that you can

  • Use the thread_policy_get() procedure to return thread planning status information to thread_policy_t
  • This structure seems to have a sub-substructure of policy_rr_info_t
  • This substructure must have a quantum field.
  • This field seems to be a temporary sheet, but I don't know about devices.

There are no man pages for this part of the API, but this Apple developer page explains at least a little about how to use this API.

Please note that this is all derived only from grepping various kernel headers, and I definitely have not tried to use any of these APIs in any valid code.

0
source

Source: https://habr.com/ru/post/1263147/


All Articles