After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 748530 - gthread: W32 implementation of g_get_num_processors() has lame fallback
gthread: W32 implementation of g_get_num_processors() has lame fallback
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: gthread
unspecified
Other All
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2015-04-27 14:50 UTC by LRN
Modified: 2016-04-26 13:54 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
gthread: Better fallback for W32 g_get_num_processors() (1.51 KB, patch)
2015-04-27 14:50 UTC, LRN
none Details | Review
gthread: Better fallback for W32 g_get_num_processors() (1.52 KB, patch)
2016-04-26 13:53 UTC, LRN
committed Details | Review

Description LRN 2015-04-27 14:50:01 UTC
It relies solely on GetProcessAffinityMask(). If it fails (for any reason), the fallback is 1 thread.
gthread should use GetSystemInfo(), which is guaranteed to not to fail, as a fallback.
Comment 1 LRN 2015-04-27 14:50:07 UTC
Created attachment 302455 [details] [review]
gthread: Better fallback for W32 g_get_num_processors()
Comment 2 Fan, Chun-wei 2015-04-29 00:30:53 UTC
Review of attachment 302455 [details] [review]:

Hi LRN,

I think you want to do the fallback after doing GetProcessAffinityMask() (and it failed), or we might just do the fallback thing and stop using GetProcessAffinityMask().

Another thing (though could be nitpick), is to use GetNativeSystemInfo() instead of GetSystemInfo(), as we may very well be on WOW64.

With blessings.
Comment 3 LRN 2015-04-29 02:38:39 UTC
(In reply to Fan, Chun-wei from comment #2)
> Review of attachment 302455 [details] [review] [review]:
> 
> Hi LRN,
> 
> I think you want to do the fallback after doing GetProcessAffinityMask()
> (and it failed),

Why? It's not unusual when performing some kind of computation to start with a safe value, then see if you can get a better one.

If i do the fallback after GPAM(), i'll need to do it conditionally - if (count <= 0) { fallback }. This is not exactly a huge performance loss or code complexity increase, but i'd rather not change how it works (unless you know something i don't).

> or we might just do the fallback thing and stop using
> GetProcessAffinityMask().

That is not an option. GPAM() provides a better result than GSI() does. GSI() tells you the number of processors in the system, GPAM() tells you which of these processors you're allowed to use, and that can be less than the GSI() value.

> Another thing (though could be nitpick), is to use GetNativeSystemInfo()
> instead of GetSystemInfo(), as we may very well be on WOW64.

I am not aware (though i didn't dig in that direction) of any circumstances where GNSI() and GSI() will report different number of processors, so either function would be OK.
Comment 4 Fan, Chun-wei 2015-04-29 07:08:28 UTC
(In reply to LRN from comment #3)
> (In reply to Fan, Chun-wei from comment #2)
> > Review of attachment 302455 [details] [review] [review] [review]:
> 
> Why? It's not unusual when performing some kind of computation to start with
> a safe value, then see if you can get a better one.
>...

I see, okay, let it be.

> I am not aware (though i didn't dig in that direction) of any circumstances
> where GNSI() and GSI() will report different number of processors, so either
> function would be OK.

I think I would go with the GNSI() route, IMHO.

With blessings, thank you!
Comment 5 LRN 2016-04-26 13:53:43 UTC
Created attachment 326772 [details] [review]
gthread: Better fallback for W32 g_get_num_processors()

v2: Use GetNativeSystemInfo() instead of GetSystemInfo()
Comment 6 LRN 2016-04-26 13:54:29 UTC
Attachment 326772 [details] pushed as 999711a - gthread: Better fallback for W32 g_get_num_processors()