2 * Copyright (c) 2005-2006,2012 Intel Corporation. All rights reserved.
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39 #include <sys/types.h>
40 #include <sys/socket.h>
43 #include <rdma/rdma_cma.h>
48 int get_rdma_addr(const char *src, const char *dst, const char *port,
49 struct rdma_addrinfo *hints, struct rdma_addrinfo **rai)
51 struct rdma_addrinfo rai_hints, *res;
54 if (hints->ai_flags & RAI_PASSIVE)
55 return rdma_getaddrinfo(src, port, hints, rai);
59 rai_hints.ai_flags |= RAI_PASSIVE;
60 ret = rdma_getaddrinfo(src, NULL, &rai_hints, &res);
64 rai_hints.ai_src_addr = res->ai_src_addr;
65 rai_hints.ai_src_len = res->ai_src_len;
66 rai_hints.ai_flags &= ~RAI_PASSIVE;
69 ret = rdma_getaddrinfo(dst, port, &rai_hints, rai);
71 rdma_freeaddrinfo(res);
76 void size_str(char *str, size_t ssize, long long size)
78 long long base, fraction = 0;
81 if (size >= (1 << 30)) {
84 } else if (size >= (1 << 20)) {
87 } else if (size >= (1 << 10)) {
96 fraction = (size % base) * 10 / base;
98 snprintf(str, ssize, "%lld.%lld%c", size / base, fraction, mag);
100 snprintf(str, ssize, "%lld%c", size / base, mag);
104 void cnt_str(char *str, size_t ssize, long long cnt)
106 if (cnt >= 1000000000)
107 snprintf(str, ssize, "%lldb", cnt / 1000000000);
108 else if (cnt >= 1000000)
109 snprintf(str, ssize, "%lldm", cnt / 1000000);
110 else if (cnt >= 1000)
111 snprintf(str, ssize, "%lldk", cnt / 1000);
113 snprintf(str, ssize, "%lld", cnt);
116 int size_to_count(int size)
118 if (size >= (1 << 20))
120 else if (size >= (1 << 16))
122 else if (size >= (1 << 10))
128 void format_buf(void *buf, int size)
130 uint8_t *array = buf;
134 for (i = 0; i < size; i++)
138 int verify_buf(void *buf, int size)
140 static long long total_bytes;
141 uint8_t *array = buf;
145 for (i = 0; i < size; i++, total_bytes++) {
146 if (array[i] != data++) {
147 printf("data verification failed byte %lld\n", total_bytes);
154 int do_poll(struct pollfd *fds, int timeout)
160 ret = rs_poll(fds, 1, timeout);
162 ret = poll(fds, 1, timeout);
166 return ret == 1 ? (fds->revents & (POLLERR | POLLHUP)) : ret;