-
-
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
Extend cpu_count() API to get sockets and NUMA nodes count #1392
Comments
Yes, checkout |
@giampaolo Maybe I did not make myself clear: |
Ah you mean the number of physical sockets. Generally speaking one wants |
@giampaolo Sorry for the confusion and thanks for your reply. A lot of servers, cloud or otherwise, tend to have more than one socket - and the bandwidth between the sockets is usually significantly lower than between the cores of one individual CPU. This is why you want to avoid spreading certain parallel workloads across multiple sockets. Having this information from |
Re-opening given the recent discussion at #1727. It turns out that knowing the number of CPU sockets is desirable after all. The point is how to expose this in terms of API. Alex @amanusk suggests: #1727 (comment) |
OK, here's a bit of brainstorming. Currently psutil is able to return logical (hyper threading) and physical cores. The goal is to provide CPU sockets count (and possibly others). IMO, the ideal API if we were to start from scratch today would be having a single function accepting a # number of logical / hyper-threading CPU cores, same as os.cpu_count()
psutil.cpu_count(kind="logical")
# number of physical cores (currently supported on all platforms except OpenBSD and NetBSD)
psutil.cpu_count(kind="cores")
# number of sockets
psutil.cpu_count(kind="sockets")
# number of usable CPUs, aka len(os.sched_getaffinity(0)) on Linux
# or len(psutil.Process().cpu_affinity())
psutil.cpu_count(kind="usable")
# number of NUMA nodes
psutil.cpu_count(kind="numa") (similarly to The current function signature unfortunately is: psutil.cpu_count(logical=True) What we MAY do in order to keep supporting psutil.cpu_count(kind='logical', logical=None) If the function is invoked as such we will assume the user is asking for logical cores: >>> psutil.cpu_count()
8
>>> psutil.cpu_count(True)
DeprecationWarning('use of boolean as first parameter is deprecated, use kind="logical"')
8
>>> psutil.cpu_count(logical=True)
DeprecationWarning('"logical" parameter is deprecated, use kind="logical"')
8 If the function is invoked as such we will assume the user is asking for physical cores: >>> psutil.cpu_count(False)
DeprecationWarning('use of boolean as first parameter is deprecated; use kind="cores"')
4
>>> psutil.cpu_count(logical=False)
DeprecationWarning('"logical" parameter is deprecated; use kind="cores"')
4 |
I think calling all that cpu just makes the code more confusing, why not: numa_count(), group_count(), socket_count(), cpu_count(group=, numa=) ? Then you can get the number of logical/physical cpus in a group or numa node and also the numa and group count. For windows you still need to know in which group is each numa node so something like numa_group(numa=) is also needed. A numa node has a group (on cpus with more than 64 logical cores in the same numa node windows actually creates virtual numa nodes for them) and an affinity mask in that group as sometimes machines with < 64 total logical cpus but more than one numa node will get their cpus as different affinity masks on the same group eg. a 2 socket machine with two 20 logical core die will get 2 numa nodes, 1 group and an affinity mask of the first 20 logical cores for numa node 1 and the rest for numa node 2. |
Barring a few exceptions, all APIs start with
Mmm that complicates things quite a bit. I'm not sure how to express that in terms of API. To my understanding, and judging from lscpu output on Linux, we have 2 kind of info: number of NUMA nodes and what CPUs are in each node (what you call "groups" I suppose), e.g.:
Is Windows different? >>> psutil.cpu_count(kind="numa_nodes") # maybe not necessary at all?
2
>>> psutil.cpu_numa_nodes()
{0: [0, 2, 4, 6, 8, 10, 12, 14], 1: [1, 3, 5, 7, 9, 11, 13, 15]} CC-ing @amanusk just in case he wants to chime in. |
Windows has the additional complication of processor groups, which complicate the node numbering. You can have processor numbers 0-63 on group 0, and 0-63 on group 1, for example. When combining with NUMA nodes, the numbering for OS lookup in the counters, etc. is tied to the NUMA node, not the processor number, so each of NUMA nodes 0 thru 3 would have processors 0-31, for example. See oshi/oshi#1373 for some background. The canonical (?) enumeration in Windows is |
I think it would be more useful to have a more generic At that point I wanted to add that if numa support is added, please include setting attributes for network interfaces as well to indicated which numa node they are attached to. In Linux this is found in |
Hi |
Use cases from Stackoverflow:
|
I could not find anything related in the documentation. I am currently using a "hack" working on some Intel-based systems: Messing around with temperature sensors, but it really is not clean ...
EDIT: The above is working on Linux x86_64 for 4.4, 4.10 and 4.15 kernels.
The text was updated successfully, but these errors were encountered: