Fixed getCPUCount | Issue #16268#16457
Conversation
|
Hey @alalek, I do not have the environments of the failing builds, any idea how to solve? I'll fix Android now |
|
In I'm not sure if it is true. [EDIT] |
|
Checks pass now, open to suggestions. |
|
Thank you for contribution! Could you please squash commits and rebase onto 3.4 branch? |
Minor new line changes Android fix | efficient linux checks Android fix 2 Fixed cpu logic for non linux platforms Android fix 3 Android fix 4
ffeca39 to
f06c4be
Compare
|
Thanks @alalek, done. |
|
@mshabunin, I have combined some of the android and linux code to reduce duplicates, I have also fixed the logic of cpus-sets by reusing android code. |
|
Looks like this approach not work with Perhaps we need to handle this case too by dividing cfs_quota to cfs_period and rounding the value, because this parameter supports fractional numbers. |
|
Oh, thanks @mshabunin for finding this, I'll read up on this and get back to you |
|
@mshabunin, I've handled |
mshabunin
left a comment
There was a problem hiding this comment.
Several comments in general:
- it is not clear which value have bigger priority and how they are chosen: platform-specific values should have bigger priority, if several valid values have been returned, minimum should be chosen
- preprocessor macros should be made more readable, e.g.
CV_HAVE_CGROUPS_V1,CV_HAVE_LINUX_SHED
|
Thanks for the review @mshabunin, I'll address them. As for priority, I think we can take minimum most value if we have many options as that is always the most probable value. |
|
@ganesh-k13 , yes minimum should be good. Maybe something like this will be more clear (variables and functions should have meaningful names ofc): int result = 0;
#if CV_HAVE_METHOD_1
static const int m1 = getCPUS_method1();
if (result > 0 && m1 > 0 && result > m1 || result == 0 && m1 > 0)
result = m1;
#endif
#if CV_HAVE_METHOD_2
...
#endif
return result > 0 ? result : 1; |
|
Yes, that is much clearer @mshabunin, I'll do like that. Thanks. |
|
Ok so Andriod is just hard when it comes to |
|
@ganesh-k13 I propose to preserve original implementation for Andoird and do not use cgroups option there. |
|
Sure @asmorkalov, will do. |
|
@alalek / @asmorkalov / @mshabunin , can you please review? |
|
@alalek and @asmorkalov, I have made some changes. Open to any changes, this was just my first thoughts on handling Linux and Andriod based stuff. Let me know what needs to be done. |
This pullrequest changes
Fixed getCPUCount to account for cgroups.
Added common code to parse CPU files into a generic function for android and Linux
Tested on Linux VMs, docker images, Kubernetes pods.
resolves #16268
resolves #16183