1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337
|
/**
* Copyright (c) NVIDIA CORPORATION & AFFILIATES, 2019. ALL RIGHTS RESERVED.
*
* See file LICENSE for terms.
*/
#include <infiniband/verbs.h>
extern "C" {
#include <uct/ib/mlx5/ib_mlx5.h>
}
#include <uct/api/uct.h>
#include <uct/uct_test.h>
#include <common/test.h>
class test_devx : public uct_test {
public:
entity* m_e;
void init() {
uct_test::init();
m_e = create_entity(0);
m_entities.push_back(m_e);
if (!(md()->super.dev.flags & UCT_IB_DEVICE_FLAG_MLX5_PRM &&
md()->flags & UCT_IB_MLX5_MD_FLAG_DEVX)) {
std::stringstream ss;
ss << "DEVX is not supported by " << GetParam();
UCS_TEST_SKIP_R(ss.str());
}
}
uct_ib_mlx5_md_t *md() const {
return ucs_derived_of(m_e->md(), uct_ib_mlx5_md_t);
}
uct_priv_worker_t *worker() const {
return ucs_derived_of(m_e->worker(), uct_priv_worker_t);
}
};
UCS_TEST_P(test_devx, dbrec)
{
uct_ib_mlx5_dbrec_t *dbrec;
dbrec = (uct_ib_mlx5_dbrec_t *)ucs_mpool_get_inline(&md()->dbrec_pool);
ASSERT_FALSE(dbrec == NULL);
ucs_mpool_put_inline(dbrec);
}
UCT_INSTANTIATE_IB_TEST_CASE(test_devx);
class test_devx_umr_mkey : public test_devx {
public:
void init() {
test_devx::init();
}
bool check_xgvmi() const {
return md()->super.cap_flags & UCT_MD_FLAG_EXPORTED_MKEY;
}
void skip_no_xgvmi() const {
if (!check_xgvmi()) {
UCS_TEST_SKIP_R("XGVMI capability is not supported");
}
}
uct_ib_mlx5_devx_mem_t *create_memh(size_t length) const {
void *addr = ucs_malloc(length, "test");
uct_md_mem_reg_params_t params = {};
uct_mem_h memh;
EXPECT_NE(nullptr, addr);
ASSERT_UCS_OK(uct_ib_mlx5_devx_mem_reg(m_e->md(), addr, length, ¶ms,
&memh));
return ucs_derived_of(memh, uct_ib_mlx5_devx_mem_t);
}
uct_ib_mlx5_devx_mem_t *
import_memh(const uct_ib_mlx5_devx_mem_t *exported_memh, uint64_t uuid = 0,
uint8_t mkey_size = sizeof(uct_ib_md_packed_mkey_t)) const {
uct_ib_md_packed_mkey_t packed_mkey = {
.lkey = exported_memh->exported_lkey,
.vhca_id = md()->super.vhca_id,
.md_uuid = uuid
};
uct_md_mem_attach_params_t params = {};
params.field_mask = UCT_MD_MEM_ATTACH_FIELD_MKEY_SIZE;
params.mkey_size = mkey_size;
uct_ib_mlx5_devx_mem_t *imported_memh;
ASSERT_UCS_OK(uct_ib_mlx5_devx_mem_attach(m_e->md(), &packed_mkey,
¶ms,
(uct_mem_h*)&imported_memh));
return imported_memh;
}
void destroy_memh(uct_ib_mlx5_devx_mem_t *memh) const {
void *addr = memh->address;
uct_md_mem_dereg_params_t params;
params.field_mask = UCT_MD_MEM_DEREG_FIELD_MEMH;
params.memh = (uct_mem_h)memh;
ASSERT_UCS_OK(uct_ib_mlx5_devx_mem_dereg(m_e->md(), ¶ms));
ucs_free(addr);
}
void check_umr_init(bool init_export, bool init_import) const {
EXPECT_EQ(init_export, nullptr != md()->umr.qp);
EXPECT_EQ(init_export, nullptr != md()->umr.cq);
if (!init_export) {
EXPECT_TRUE(ucs_list_is_empty(&md()->umr.mkey_pool));
}
EXPECT_EQ(init_import, nullptr != md()->umr.mkey_hash);
}
static void check_memh_export(uct_ib_mlx5_devx_mem_t *memh, bool is_umr) {
EXPECT_EQ(is_umr,
UCT_IB_MLX5_MKEY_TAG_UMR == (memh->exported_lkey & 0xff));
EXPECT_EQ(is_umr, nullptr != memh->exported_umr_mkey);
EXPECT_EQ(is_umr, nullptr == memh->cross_mr);
}
void perf_export_import_mkey(size_t memh_count, size_t memh_size,
ucs_time_t &export_time,
ucs_time_t &import_time) {
std::vector<uct_ib_mlx5_devx_mem_t*> exported_memh, imported_memh;
exported_memh.reserve(memh_count);
imported_memh.reserve(memh_count);
for (size_t i = 0; i < memh_count; ++i) {
exported_memh.push_back(create_memh(memh_size));
}
ucs_time_t start_time = ucs_get_time();
for (auto it : exported_memh) {
ASSERT_UCS_OK(uct_ib_mlx5_devx_reg_exported_key(md(), it));
check_memh_export(it, true);
}
export_time = ucs_get_time() - start_time;
start_time = ucs_get_time();
for (auto it : exported_memh) {
imported_memh.push_back(import_memh(it));
}
import_time = ucs_get_time() - start_time;
for (size_t i = 0; i < memh_count; ++i) {
destroy_memh(imported_memh[i]);
destroy_memh(exported_memh[i]);
}
}
};
UCS_TEST_P(test_devx_umr_mkey, lazy_init)
{
check_umr_init(false, false);
}
UCS_TEST_P(test_devx_umr_mkey, export_mkey_no_xgvmi, "IB_XGVMI_UMR_ENABLE=n")
{
skip_no_xgvmi();
uct_ib_mlx5_devx_mem_t *memh = create_memh(1024);
ASSERT_UCS_OK(uct_ib_mlx5_devx_reg_exported_key(md(), memh));
/* UMR objects remains uninitialized, exported key is not UMR one */
check_umr_init(false, false);
check_memh_export(memh, false);
destroy_memh(memh);
}
UCS_TEST_P(test_devx_umr_mkey, export_mkey_xgvmi)
{
skip_no_xgvmi();
uct_ib_mlx5_devx_mem_t *memh = create_memh(1024);
ASSERT_UCS_OK(uct_ib_mlx5_devx_reg_exported_key(md(), memh));
/* XGVMI capability might be dropped by this point! */
/* UMR export transport objects must be initialized */
check_umr_init(true, false);
/* UMR mkey pool must be empty */
EXPECT_TRUE(ucs_list_is_empty(&md()->umr.mkey_pool));
/* Whether mkey is UMR depends on XGVMI capability */
check_memh_export(memh, true);
destroy_memh(memh);
/* After release of memh, associated UMR mkey is moved back to mkey pool */
EXPECT_EQ(1, ucs_list_length(&md()->umr.mkey_pool));
}
UCS_TEST_P(test_devx_umr_mkey, import_mkey_no_umr, "IB_XGVMI_UMR_ENABLE=n")
{
skip_no_xgvmi();
/* Export any mkey */
uct_ib_mlx5_devx_mem_t *exported_memh = create_memh(1024);
ASSERT_UCS_OK(uct_ib_mlx5_devx_reg_exported_key(md(), exported_memh));
/* Import as non-UMR mkey */
uct_ib_mlx5_devx_mem_t *imported_memh = import_memh(exported_memh);
EXPECT_NE(nullptr, imported_memh);
/* UMR hash map remains uninitialized */
EXPECT_EQ(nullptr, md()->umr.mkey_hash);
destroy_memh(imported_memh);
destroy_memh(exported_memh);
}
UCS_TEST_P(test_devx_umr_mkey, import_mkey_umr)
{
skip_no_xgvmi();
/* Export UMR mkey */
uct_ib_mlx5_devx_mem_t *exported_memh = create_memh(1024);
ASSERT_UCS_OK(uct_ib_mlx5_devx_reg_exported_key(md(), exported_memh));
check_memh_export(exported_memh, true);
/* Import first UMR mkey */
uct_ib_mlx5_devx_mem_t *imported_memh = import_memh(exported_memh);
check_umr_init(true, true);
EXPECT_EQ(1, kh_size(md()->umr.mkey_hash));
/* Second import with the same packed mkey, should reuse alias */
uct_ib_mlx5_devx_mem_t *imported_memh2 = import_memh(exported_memh);
EXPECT_NE(imported_memh, imported_memh2);
EXPECT_EQ(imported_memh->super.lkey, imported_memh2->super.lkey);
EXPECT_EQ(1, kh_size(md()->umr.mkey_hash));
destroy_memh(imported_memh);
destroy_memh(imported_memh2);
destroy_memh(exported_memh);
}
UCS_TEST_P(test_devx_umr_mkey, perf_export_import_mkey_xgvmi)
{
skip_no_xgvmi();
const size_t MEMH_COUNT = RUNNING_ON_VALGRIND ? 100 : 1000;
ucs_time_t export_create_time, import_create_time;
perf_export_import_mkey(MEMH_COUNT, 1024, export_create_time,
import_create_time);
/* After release all allocated UMR keys go back to the mkey pool */
EXPECT_EQ(MEMH_COUNT, ucs_list_length(&md()->umr.mkey_pool));
/* Now reuse the keys for different handles of different size */
ucs_time_t export_reuse_time, import_reuse_time;
perf_export_import_mkey(MEMH_COUNT, 2048, export_reuse_time,
import_reuse_time);
/* Reusing existing UMR mkeys is normally 200x faster than creating new
* ones, given jitter we check that it's at least 10 times faster */
EXPECT_LT(export_reuse_time, export_create_time / 10);
EXPECT_LT(export_reuse_time, export_create_time / 10);
char buf[1024] = {};
snprintf(buf, sizeof(buf), "Create %zu UMR mkeys, export: %.3f ms, import: "
"%.3f ms", MEMH_COUNT, ucs_time_to_msec(export_create_time),
ucs_time_to_msec(import_create_time));
UCS_TEST_MESSAGE << buf;
snprintf(buf, sizeof(buf), "Reuse %zu UMR mkeys, export: %.3f ms, import: "
"%.3f ms", MEMH_COUNT, ucs_time_to_msec(export_reuse_time),
ucs_time_to_msec(import_reuse_time));
UCS_TEST_MESSAGE << buf;
EXPECT_EQ(MEMH_COUNT, ucs_list_length(&md()->umr.mkey_pool));
}
UCS_TEST_P(test_devx_umr_mkey, import_same_mkey_from_different_md)
{
skip_no_xgvmi();
/* Export UMR mkey */
uct_ib_mlx5_devx_mem_t *exported_memh = create_memh(1024);
ASSERT_UCS_OK(uct_ib_mlx5_devx_reg_exported_key(md(), exported_memh));
check_memh_export(exported_memh, true);
/* Import UMR mkey from MD with uuid 1 */
uct_ib_mlx5_devx_mem_t *imported_memh = import_memh(exported_memh, 1);
check_umr_init(true, true);
EXPECT_EQ(1, kh_size(md()->umr.mkey_hash));
uct_ib_mlx5_devx_umr_alias_t mkey_alias;
kh_foreach_value(md()->umr.mkey_hash, mkey_alias, {
EXPECT_EQ(1, mkey_alias.md_uuid);
});
/* Import the same UMR key, but from another MD with uuid 2 */
uct_ib_mlx5_devx_mem_t *imported_memh2 = import_memh(exported_memh, 2);
EXPECT_NE(imported_memh, imported_memh2);
EXPECT_EQ(1, kh_size(md()->umr.mkey_hash));
/* Check that stale mkey had been replaced by a new one */
kh_foreach_value(md()->umr.mkey_hash, mkey_alias, {
EXPECT_EQ(2, mkey_alias.md_uuid);
});
destroy_memh(imported_memh);
destroy_memh(imported_memh2);
destroy_memh(exported_memh);
}
UCS_TEST_P(test_devx_umr_mkey, import_backward_compatible)
{
skip_no_xgvmi();
/* Export UMR mkey */
uct_ib_mlx5_devx_mem_t *exported_memh = create_memh(1024);
ASSERT_UCS_OK(uct_ib_mlx5_devx_reg_exported_key(md(), exported_memh));
check_memh_export(exported_memh, true);
/* Import UMR mkey from previous version without md_uuid field. In this
* case md_uuid field will be always 0 */
uct_ib_mlx5_devx_mem_t *imported_memh = import_memh(exported_memh, 3, 0);
check_umr_init(true, true);
EXPECT_EQ(1, kh_size(md()->umr.mkey_hash));
uct_ib_mlx5_devx_umr_alias_t mkey_alias;
kh_foreach_value(md()->umr.mkey_hash, mkey_alias, {
EXPECT_EQ(0, mkey_alias.md_uuid);
});
destroy_memh(imported_memh);
destroy_memh(exported_memh);
}
UCT_INSTANTIATE_IB_TEST_CASE(test_devx_umr_mkey);
|