Files
Jamie LiuandgVisor bot ee96e702d6 sysfs: implement some cpu topology files
This is required for Open MPI => hwloc to detect the number of CPUs and set the
number of Open MPI slots accordingly.

Before this CL, on amd64:

```
root@0496c77e84e9:/# ls /sys/devices/system/cpu/ | grep cpu | wc -l
96
root@0496c77e84e9:/# mpirun --allow-run-as-root -np 96 /bin/true
[hwloc/linux] failed to find sysfs cpu topology directory, aborting linux discovery.
[0496c77e84e9:00667] OPAL ERROR: Not supported in file ../../../../../opal/mca/hwloc/base/hwloc_base_util.c at line 418
--------------------------------------------------------------------------
It looks like orte_init failed for some reason; your parallel process is
likely to abort.  There are many reasons that a parallel process can
fail during orte_init; some of which are due to configuration or
environment problems.  This failure appears to be an internal failure;
here's some additional information (which may only be relevant to an
Open MPI developer):

  topology discovery failed
  --> Returned value Not supported (-8) instead of ORTE_SUCCESS
--------------------------------------------------------------------------
```

Before this CL, on arm64:

```
root@bfad6b71e996:/# ls /sys/devices/system/cpu/ | grep cpu | wc -l
4
root@bfad6b71e996:/# mpirun --allow-run-as-root -np 4 /bin/true
[hwloc/linux] failed to find sysfs cpu topology directory, aborting linux discovery.
[hwloc/linux] failed to find sysfs cpu topology directory, aborting linux discovery.
--------------------------------------------------------------------------
All nodes which are allocated for this job are already filled.
--------------------------------------------------------------------------
```

After this CL, on amd64:

```
root@0512ce557005:/# ls /sys/devices/system/cpu/ | grep cpu | wc -l
96
root@0512ce557005:/# mpirun --allow-run-as-root -np 96 /bin/true
root@0512ce557005:/# mpirun --allow-run-as-root -np 97 /bin/true
--------------------------------------------------------------------------
There are not enough slots available in the system to satisfy the 97
slots that were requested by the application:
...
```

After this CL, on arm64:

```
root@faf6ff491bc5:/# ls /sys/devices/system/cpu/ | grep cpu | wc -l
4
root@faf6ff491bc5:/# mpirun --allow-run-as-root -np 4 /bin/true
root@faf6ff491bc5:/# mpirun --allow-run-as-root -np 5 /bin/true
--------------------------------------------------------------------------
There are not enough slots available in the system to satisfy the 5
slots that were requested by the application:
...
```

Per #10484, this also lets `nvidia-smi topo` make more progress:

```
root@d5a696bb7e2c:/# nvidia-smi topo -m
        GPU0    GPU1    GPU2    GPU3    GPU4    GPU5    GPU6    GPU7    CPU Affinity    NUMA Affinity   GPU NUMA ID
Failed to run topology matrix
```

PiperOrigin-RevId: 663395602
2024-08-15 12:10:36 -07:00

77 lines
1.9 KiB
Go

// Copyright 2024 The gVisor Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package sys
import (
"testing"
)
func TestFullCPUMask(t *testing.T) {
for _, test := range []struct {
cores uint
want string
}{
{1, "1"},
{2, "3"},
{3, "7"},
{4, "f"},
{5, "1f"},
{32, "ffffffff"},
{33, "1,ffffffff"},
{36, "f,ffffffff"},
{37, "1f,ffffffff"},
{64, "ffffffff,ffffffff"},
{65, "1,ffffffff,ffffffff"},
} {
if got := fullCPUMask(test.cores); got != test.want {
t.Errorf("fullCPUMask(%d): got %s, want %s", test.cores, got, test.want)
}
}
}
func TestOneCPUMask(t *testing.T) {
for _, test := range []struct {
i uint
cores uint
want string
}{
{0, 1, "1"},
{0, 4, "1"},
{1, 4, "2"},
{2, 4, "4"},
{3, 4, "8"},
{0, 5, "01"},
{4, 5, "10"},
{0, 32, "00000001"},
{26, 32, "04000000"},
{0, 33, "0,00000001"},
{31, 33, "0,80000000"},
{32, 33, "1,00000000"},
{0, 64, "00000000,00000001"},
{31, 64, "00000000,80000000"},
{32, 64, "00000001,00000000"},
{63, 64, "80000000,00000000"},
{0, 65, "0,00000000,00000001"},
{31, 65, "0,00000000,80000000"},
{32, 65, "0,00000001,00000000"},
{63, 65, "0,80000000,00000000"},
{64, 65, "1,00000000,00000000"},
} {
if got := oneCPUMask(test.i, test.cores); got != test.want {
t.Errorf("oneCPUMask(%d, %d): got %s, want %s", test.i, test.cores, got, test.want)
}
}
}