PadicoTM

Documentation

« back to PM2 home.
infiniband-verbs.c
Go to the documentation of this file.
1/*
2 * Padico -- a High Performance Parallel and Distributed Computing Environment
3 * Copyright (c) 2002-2025 INRIA and the University of Rennes 1
4 * Alexandre DENIS <Alexandre.Denis@inria.fr>
5 * Christian PEREZ <Christian.Perez@inria.fr>
6 *
7 * The software has been registered at the Agency for the Protection of
8 * Programs (APP) under the number IDDN.FR.001.260013.000.S.P.2002.000.10000.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 */
24
34#include <endian.h>
35#include <net/if_arp.h>
36
37#include <Padico/Puk.h>
38#include <Padico/Module.h>
39
40#include "InfinibandVerbs.h"
41
42static int padico_ibv_init(void);
43static void padico_ibv_finalize(void);
44
46 "Topology");
47
48
49/* ********************************************************* */
50
55
56/* ********************************************************* */
57
58static void padico_ibv_create_port(struct ibv_device*ib_dev, int port_num)
59{
64
65 /* detect HCA GUID */
68 ibv_port->guid = be64toh(device_attr.node_guid);
69 ibv_port->port_num = port_num;
70 assert(port_num <= device_attr.phys_port_cnt);
71 /* detect subnet GID */
72 union ibv_gid gid;
73 ibv_query_gid(ibv_port->context, ibv_port->port_num, 0, &gid);
74 ibv_port->subnet = be64toh(gid.global.subnet_prefix);
75 /* Get port LID */
77 int rc = ibv_query_port(ibv_port->context, port_num, &port_attr);
78 if(rc)
79 {
80 padico_fatal("couldn't get port attributes for device = %s; port = %d; rc = %d (%s).\n", ib_devname, port_num, rc, strerror(rc));
81 }
82 if(port_attr.state != IBV_PORT_ACTIVE)
83 {
84 padico_out(puk_verbose_notice, "device = %s; port %d is not active.\n", ib_devname, ibv_port->port_num);
85 padico_free((void*)ibv_port->devname);
87 return;
88 }
89 ibv_port->port_lid = port_attr.lid;
90 int link_width = -1;
91 switch(port_attr.active_width)
92 {
93 case 1: link_width = 1; break;
94 case 2: link_width = 4; break;
95 case 4: link_width = 8; break;
96 case 8: link_width = 12; break;
97 case 16: link_width = 2; break;
98 }
99 int link_rate = -1;
100 switch(port_attr.active_speed)
101 {
102 case 0x01: link_rate = 2; break;
103 case 0x02: link_rate = 4; break;
104 case 0x04: link_rate = 8; break;
105 case 0x08: link_rate = 10; break;
106 case 0x10: link_rate = 14; break;
107 case 0x20: link_rate = 25; break;
108 case 0x40: link_rate = 50; break;
109 case 0x80: link_rate = 100; break;
110 default: padico_out(puk_verbose_notice, "unknown active_speed = %x\n", port_attr.active_speed);
111 }
112 const int data_rate = link_width * link_rate;
113
114 padico_print("device: '%s'; subnet GID: %04X:%04X:%04X:%04X; hca GUID: %04X:%04X:%04X:%04X; link width: %d; rate: %d (%dGb/s)\n",
116 (unsigned)((ibv_port->subnet >> 48) & 0xFFFF), (unsigned)((ibv_port->subnet >> 32) & 0xFFFF),
117 (unsigned)((ibv_port->subnet >> 16) & 0xFFFF), (unsigned)(ibv_port->subnet & 0xFFFF),
118 (unsigned)((ibv_port->guid >> 48) & 0xFFFF), (unsigned)((ibv_port->guid >> 32) & 0xFFFF),
119 (unsigned)((ibv_port->guid >> 16) & 0xFFFF), (unsigned)(ibv_port->guid & 0xFFFF),
121 if(port_attr.lid == 0)
122 {
123 padico_out(puk_verbose_notice, "device = %s; port %d; ignoring port with LID = 0.\n", ib_devname, ibv_port->port_num);
124 padico_free((void*)ibv_port->devname);
126 return;
127 }
128 const uint64_t default_subnet = 0xFE80000000000000ULL;
129 if(ibv_port->subnet == default_subnet)
130 {
131 padico_out(puk_verbose_notice, "device '%s' subnet has factory default GID prefix %04X:%04X:%04X:%04X. NetSelector is likely to detect wrong routes. Please customize subnet GID in opensm configuration.\n",
133 (unsigned)((ibv_port->subnet >> 48) & 0xFFFF), (unsigned)((ibv_port->subnet >> 32) & 0xFFFF),
134 (unsigned)((ibv_port->subnet >> 16) & 0xFFFF), (unsigned)(ibv_port->subnet & 0xFFFF));
135 }
136
137 /* *** Topology */
139 padico_string_printf(s_net, "Infiniband-%dGbps-(w%d-s0x%02X)-[%04X:%04X:%04X:%04X]",
140 data_rate, port_attr.active_width, port_attr.active_speed,
141 ((ibv_port->subnet >> 48) & 0xFFFF), ((ibv_port->subnet >> 32) & 0xFFFF),
142 ((ibv_port->subnet >> 16) & 0xFFFF), (ibv_port->subnet & 0xFFFF));
144 if(network)
145 {
146 ibv_port->network = network;
147 }
148 else
149 {
151 }
153 padico_topo_network_set_perf(ibv_port->network, 2000, 1024 * 1024 * (data_rate / 8) * 0.75);
155 padico_topo_hwaddr_t hwaddr = padico_topo_hwaddr_create(ib_devname, -1 /* no rtnetlink index */, ARPHRD_INFINIBAND, sizeof(ibv_port->guid), &ibv_port->guid);
156 padico_topo_binding_add_hwaddr(binding, hwaddr);
158 padico_topo_binding_add_index(binding, port_num);
159
161
162}
163
164static void padico_ibv_discover(void)
165{
166 /* scan device list */
167 int num_devices = -1;
169 if(!dev_list)
170 {
171 padico_warning("no device found.\n");
172 }
173 else
174 {
175 padico_print("detected %d devices.\n", num_devices);
176 }
177 if(*dev_list == NULL)
178 {
179 padico_warning("no device found.\n");
180 }
181 int d = 0;
182 while(dev_list[d] != NULL)
183 {
184 struct ibv_device*ib_dev = dev_list[d];
186 struct ibv_context*context = ibv_open_device(ib_dev);
187 if(context == NULL)
188 {
189 padico_fatal("couldn't get context for IB device %s (%s)\n", ib_devname, strerror(errno));
190 }
192 ibv_query_device(context, &device_attr);
193 int port_count = device_attr.phys_port_cnt;
194 ibv_close_device(context);
195 int p;
196 for(p = 1; p <= port_count; p++)
197 {
199 }
200 d++;
201 }
202
204
205
206}
207
208
209
211{
212 return &padico_ibv.ports;
213}
214
215static int padico_ibv_init(void)
216{
219 return 0;
220}
221
222static void padico_ibv_finalize(void)
223{
226 {
227 struct padico_ibv_port_s*ibv_port = *i;
228 ibv_close_device(ibv_port->context);
229 padico_free((void*)ibv_port->devname);
231 }
232}
Infiniband Verbs topology detection and description.
assert(slab_size > 0)
return NULL
Definition Shm.h:88
puk_tagged_ptr_t p
Definition Shm.h:88
static int done
Definition console-mod.c:49
padico_rc_t rc
Definition PadicoTM.h:146
padico_topo_network_t padico_topo_network_create(const char *id, padico_topo_binding_scope_t scope, size_t addr_size, int family)
Definition topology.c:1853
padico_topo_hwaddr_t padico_topo_hwaddr_create(const char *name, int index, int type, size_t len, const void *addr)
Definition topology.c:126
padico_topo_network_t padico_topo_network_getbyid(const char *network_id)
Definition topology.c:2351
#define padico_topo_getlocalhost()
Definition Topology.h:319
void padico_topo_network_set_perf(padico_topo_network_t n, int latency_nsec, int bandwidth_kbps)
Definition topology.c:2324
void padico_topo_hwaddr_add(padico_topo_host_t host, padico_topo_hwaddr_t *_hwaddr)
Definition topology.c:153
void padico_topo_binding_add_index(padico_topo_binding_t binding, int64_t index)
Definition topology.c:205
padico_topo_binding_t padico_topo_host_bind(padico_topo_host_t host, padico_topo_network_t network, const void *address)
Declare a new binding for a host.
Definition topology.c:1609
void padico_topo_binding_add_hwaddr(padico_topo_binding_t binding, padico_topo_hwaddr_t hwaddr)
Definition topology.c:196
@ PADICO_TOPO_SCOPE_HOST
Definition Topology.h:95
static struct padico_ibv_s padico_ibv
static void padico_ibv_create_port(struct ibv_device *ib_dev, int port_num)
static void padico_ibv_discover(void)
static int padico_ibv_init(void)
static void padico_ibv_finalize(void)
const struct padico_ibv_port_vect_s * padico_ibv_get_ports(void)
int done
Definition psp-ibv.c:211
padico_topo_network_t network
Definition psp-mx.c:113
an active IB port
struct padico_ibv_port_vect_s ports
a binding of an entity with a network (protocol level)
a hardware address- identifies a host
a network, containing entities with bindings