-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Timebase #2011
Timebase #2011
Conversation
Makes sense. You can do that in psutil/psutil/_psutil_common.c Line 395 in 8fa1746
You should define the new global var as a C extern defined in _psutil_common.h . grep for PSUTIL_SYSTEM_INFO to see how it's done.
|
(float)pti.pti_total_user / 1000000000.0, // (float) cpu user time | ||
(float)pti.pti_total_system / 1000000000.0, // (float) cpu sys time | ||
(float)total_user / 1000000000.0, // (float) cpu user time | ||
(float)total_system / 1000000000.0, // (float) cpu sys time |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you did the new conversion above, is the / 1000000000.0
division still necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. The mach timebase conversion ratio produces nanoseconds.
Sure. I just pushed another commit doing just that. If it's good for you I can squash it to replace the previous two. About the division by a billion, the mach_timebase_info give the conversion ratio from ticks to nanoseconds so the result still needs to be converted to seconds. |
Signed-off-by: Olivier Dormond <[email protected]>
Signed-off-by: Olivier Dormond <[email protected]>
Signed-off-by: Olivier Dormond <[email protected]>
#include <mach/mach_time.h> | ||
|
||
struct mach_timebase_info MACH_TIMEBASE_INFO; | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In order to be consistent with PSUTIL_SYSTEM_INFO
, PSUTIL_CRITICAL_SECTION
and PSUTIL_DEBUG
I suggest to:
- call this
PSUTIL_MACH_TIMEBASE_INFO
- define it in
_psutil_common.h
file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In order to be consistent with
PSUTIL_SYSTEM_INFO
,PSUTIL_CRITICAL_SECTION
andPSUTIL_DEBUG
I suggest to:* call this `PSUTIL_MACH_TIMEBASE_INFO`
That makes more sense indeed. Sorry.
* define it in `_psutil_common.h` file
I don't understand this. The header file does have the extern definition and storage can only be in the .c file. What am I missing?
Signed-off-by: Olivier Dormond <[email protected]>
Signed-off-by: Giampaolo Rodola <[email protected]>
Merged. Thanks! |
Summary
Description
Mach sys calls report cpu time in "tick units" -- on intel cpus, these happen to be nsecs but on M1 machines they're about 40 nsecs. This PR corrects for this, but I think it still needs two improvements: the value of mach_timebase_info should be cached somewhere, and there are probably other places where the code depends on 1 tick=1 nsec that also need to be updated. Sounds reasonable? I can work on both of those, but I wanted to get some feedback first before I spend any more time on this.
Based on @rmalouf PR #1958.