Repository navigation
UCS/TOPO: Build device inventory #11869
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
Changes from all commits
0e5b9f4
e21dd8a
0c9b8ad
424f2d2
cbd7dfa
41c7ade
57bd182
d2a186d
43544e8
8ec91cd
851958e
76366e8
ace0d12
e53e42c
f44a84f
5493800
a428a81
8800dbd
fbb6c3c
ad06365
2e64a83
b5295f0
c165b6b
defab99
37644d6
bb0864b
bf8a946
01680f3
5a6bbb4
615a075
11ec84c
26b23e5
e841f67
7712e2f
b8c3681
7abeb61
76fc542
9036f03
474ca21
e8c5650
4e72f2a
ae53143
5ce1fca
f462319
db4b326
4f362eb
cf07023
1ffc5f3
2fa6f80
0503e2e
6ede74a
6101659
11d1227
cfc44cf
f2eafa6
6f22749
a7eb44e
05c3e35
defdf86
c020a4b
0fbc99d
33a2ba7
dcd7127
cab9de0
7a2e3ff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -268,6 +268,45 @@ ucs_topo_bus_value_key_make(const ucs_sys_bus_id_t *bus_id, | |
| return key; | ||
| } | ||
|
|
||
| int ucs_topo_sys_device_cmp_nolock(ucs_sys_device_t sys_dev1, | ||
| ucs_sys_device_t sys_dev2) | ||
| { | ||
| const ucs_topo_sys_device_info_t *device1, *device2; | ||
| ucs_bus_id_bit_rep_t bus_id1, bus_id2; | ||
|
|
||
| ucs_assertv(sys_dev1 < ucs_topo_global_ctx.num_devices, | ||
|
guy-ealey-morag marked this conversation as resolved.
Resolved
|
||
| "invalid sys_dev1: %u", sys_dev1); | ||
| ucs_assertv(sys_dev2 < ucs_topo_global_ctx.num_devices, | ||
| "invalid sys_dev2: %u", sys_dev2); | ||
|
|
||
| device1 = &ucs_topo_global_ctx.devices[sys_dev1]; | ||
| device2 = &ucs_topo_global_ctx.devices[sys_dev2]; | ||
|
|
||
| /* Compare by bus id.*/ | ||
| bus_id1 = ucs_topo_get_bus_id_bit_repr(&device1->bus_id); | ||
| bus_id2 = ucs_topo_get_bus_id_bit_repr(&device2->bus_id); | ||
|
|
||
| if (bus_id1 != bus_id2) { | ||
| return (bus_id1 > bus_id2) - (bus_id1 < bus_id2); | ||
| } | ||
|
|
||
| /* Compare by user value. */ | ||
| return (device1->user_value > device2->user_value) - | ||
| (device1->user_value < device2->user_value); | ||
| } | ||
|
|
||
| int ucs_topo_sys_device_cmp(ucs_sys_device_t sys_dev1, | ||
| ucs_sys_device_t sys_dev2) | ||
| { | ||
| int result; | ||
|
|
||
| ucs_spin_lock(&ucs_topo_global_ctx.lock); | ||
| result = ucs_topo_sys_device_cmp_nolock(sys_dev1, sys_dev2); | ||
| ucs_spin_unlock(&ucs_topo_global_ctx.lock); | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| unsigned ucs_topo_num_devices() | ||
| { | ||
| unsigned num_devices; | ||
|
|
@@ -283,17 +322,16 @@ static void ucs_topo_bus_id_str(const ucs_sys_bus_id_t *bus_id, int abbreviate, | |
| char *str, size_t max) | ||
| { | ||
| if (abbreviate && (bus_id->domain == 0)) { | ||
|
guy-ealey-morag marked this conversation as resolved.
Resolved
|
||
| ucs_snprintf_safe(str, max, "%02x:%02x.%d", bus_id->bus, bus_id->slot, | ||
| bus_id->function); | ||
| ucs_snprintf_safe(str, max, UCS_SYS_BUS_ID_ABBREVIATED_FMT, | ||
| UCS_SYS_BUS_ID_ABBREVIATED_ARG(bus_id)); | ||
| } else { | ||
| ucs_snprintf_safe(str, max, "%04x:%02x:%02x.%d", bus_id->domain, | ||
| bus_id->bus, bus_id->slot, bus_id->function); | ||
| ucs_snprintf_safe(str, max, UCS_SYS_BUS_ID_FMT, | ||
| UCS_SYS_BUS_ID_ARG(bus_id)); | ||
| } | ||
| } | ||
|
|
||
| static ucs_status_t | ||
| ucs_topo_bus_id_to_sysfs_path(const ucs_sys_bus_id_t *bus_id, char *path, | ||
| size_t max) | ||
| ucs_status_t ucs_topo_bus_id_to_sysfs_path(const ucs_sys_bus_id_t *bus_id, | ||
| char *path, size_t max) | ||
| { | ||
| const size_t prefix_length = strlen(UCS_TOPO_SYSFS_PCI_PREFIX); | ||
| ucs_status_t status; | ||
|
|
@@ -1366,44 +1404,25 @@ static void ucs_topo_release_devices() | |
| } | ||
| } | ||
|
|
||
| static ucs_topo_groups_type_t ucs_topo_groups_type_detect() | ||
| { | ||
| return (ucs_arch_get_cpu_model() == UCS_CPU_MODEL_NVIDIA_VERA) ? | ||
| UCS_TOPO_GROUPS_TYPE_VERA_RUBIN : | ||
| UCS_TOPO_GROUPS_TYPE_UNKNOWN; | ||
| } | ||
|
|
||
| ucs_status_t ucs_topo_build_groups(ucs_topo_groups_t *groups_p) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
bot commented like above, could we add test to this pr addressing it and/or remove untested code? if it is from another pr could we maybe add some of them here?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Related #11869 (comment) |
||
| { | ||
| ucs_status_t status; | ||
|
|
||
| if (ucs_arch_get_cpu_model() != UCS_CPU_MODEL_NVIDIA_VERA) { | ||
|
guy-ealey-morag marked this conversation as resolved.
Resolved
|
||
| /* Currently only Vera Rubin architecture supports topology groups. */ | ||
| ucs_debug("topology groups are not supported on this architecture"); | ||
| return UCS_ERR_UNSUPPORTED; | ||
| } | ||
|
|
||
| ucs_spin_lock(&ucs_topo_global_ctx.lock); | ||
| status = ucs_topo_build_groups_inner(ucs_topo_global_ctx.devices, | ||
| ucs_topo_global_ctx.num_devices, | ||
| ucs_topo_groups_type_detect(), | ||
| groups_p); | ||
| ucs_spin_unlock(&ucs_topo_global_ctx.lock); | ||
|
|
||
| return status; | ||
| } | ||
|
|
||
| static void ucs_topo_release_group(ucs_topo_group_t *group) | ||
| { | ||
| ucs_array_cleanup_dynamic(&group->nics); | ||
| ucs_array_cleanup_dynamic(&group->gpus); | ||
| } | ||
|
|
||
| void ucs_topo_release_groups(ucs_topo_groups_t *groups) | ||
| { | ||
| size_t i; | ||
|
|
||
| for (i = 0; i < ucs_array_length(&groups->groups); ++i) { | ||
| ucs_topo_release_group(&ucs_array_elem(&groups->groups, i)); | ||
| } | ||
|
|
||
| ucs_array_cleanup_dynamic(&groups->groups); | ||
| } | ||
|
|
||
| ucs_global_state_t *ucs_topo_extract_state(void) | ||
| { | ||
| ucs_global_state_t *state; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,6 +35,18 @@ BEGIN_C_DECLS | |
| /* Maximal size of BDF string */ | ||
| #define UCS_SYS_BDF_NAME_MAX 16 | ||
|
|
||
| /* Bus ID string formatting */ | ||
| #define UCS_SYS_BUS_ID_FMT "%04x:%02x:%02x.%u" | ||
| #define UCS_SYS_BUS_ID_ARG(_bus_id) \ | ||
| (unsigned)(_bus_id)->domain, (unsigned)(_bus_id)->bus, \ | ||
| (unsigned)(_bus_id)->slot, (unsigned)(_bus_id)->function | ||
|
|
||
| /* Bus ID string formatting without the domain */ | ||
| #define UCS_SYS_BUS_ID_ABBREVIATED_FMT "%02x:%02x.%u" | ||
| #define UCS_SYS_BUS_ID_ABBREVIATED_ARG(_bus_id) \ | ||
| (unsigned)(_bus_id)->bus, (unsigned)(_bus_id)->slot, \ | ||
| (unsigned)(_bus_id)->function | ||
|
|
||
| /* Special values for undefined PCI identifiers */ | ||
| #define UCS_SYS_PCI_ID_VALUE_UNDEFINED 0x0000 | ||
| #define UCS_SYS_PCI_ID_UNDEFINED \ | ||
|
|
@@ -48,6 +60,7 @@ BEGIN_C_DECLS | |
| #define UCS_SYS_PCI_ID_FMT "[%04x:%04x]" | ||
| #define UCS_SYS_PCI_ID_ARG(_pci_id) ((_pci_id)->vendor), ((_pci_id)->device) | ||
|
|
||
|
|
||
|
guy-ealey-morag marked this conversation as resolved.
Resolved
guy-ealey-morag marked this conversation as resolved.
Resolved
guy-ealey-morag marked this conversation as resolved.
Resolved
|
||
| typedef struct ucs_sys_bus_id { | ||
| uint16_t domain; /* range: 0 to ffff */ | ||
| uint8_t bus; /* range: 0 to ff */ | ||
|
|
@@ -262,6 +275,22 @@ ucs_bus_id_bit_rep_t | |
| ucs_topo_get_bus_id_bit_repr(const ucs_sys_bus_id_t *bus_id); | ||
|
|
||
|
|
||
| /** | ||
| * Compare two system devices by their topology identity. | ||
| * | ||
| * Registered devices are ordered by PCI bus id, then by user-defined value. | ||
| * Device identifiers must be valid and registered (not UNKNOWN). | ||
| * | ||
| * @param [in] sys_dev1 First system device. | ||
| * @param [in] sys_dev2 Second system device. | ||
| * | ||
| * @return A negative value if @a sys_dev1 precedes @a sys_dev2, a positive | ||
| * value if @a sys_dev2 precedes @a sys_dev1, or zero if equal. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. minor: with this PR there are three identical |
||
| */ | ||
| int ucs_topo_sys_device_cmp(ucs_sys_device_t sys_dev1, | ||
| ucs_sys_device_t sys_dev2); | ||
|
|
||
|
|
||
| /** | ||
| * Find the distance between two system devices (in terms of latency, | ||
| * bandwidth, hops, etc). | ||
|
|
||
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.
ucp_proto_multi_sys_dev_cmphere,ucs_topo_groups_sys_dev_cmpin topo_groups.c, andtopo_test_sys_device_cmpin test_topo.cc are the sameqsort_rtrampoline. Can we export aqsort_r-compatible comparator fromucs/sys/topo/base/topo.hand drop this one and the gtest copy?