Skip to content

Commit f2849c2

Browse files
authored
Merge pull request #63 from google/tcpd_git_comments
cleanup: address PR comments
2 parents 54f1e0b + a32203b commit f2849c2

5 files changed

Lines changed: 27 additions & 33 deletions

File tree

‎flow.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,12 +278,12 @@ void flow_delete(struct flow *f)
278278
}
279279

280280
#ifdef WITH_TCPDEVMEM_CUDA
281-
if (flow_thread(f)->opts->tcpd_gpu_pci_addr) {
281+
if (flow_thread(f)->opts->tcpd_gpu_pci_addr)
282282
cuda_flow_cleanup(f->f_mbuf);
283-
} else
284283
#endif /* WITH_TCPDEVMEM_CUDA */
285284
#ifdef WITH_TCPDEVMEM_UDMABUF
286-
if (flow_thread(f)->opts->tcpd_nic_pci_addr)
285+
if (flow_thread(f)->opts->tcpd_nic_pci_addr
286+
&& !flow_thread(f)->opts->tcpd_gpu_pci_addr)
287287
udmabuf_flow_cleanup(f->f_mbuf);
288288
#endif /* WITH_TCPDEVMEM_UDMABUF */
289289

‎stream.c‎

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,16 @@ static void *stream_alloc(struct thread *t)
3737

3838
#ifdef WITH_TCPDEVMEM_CUDA
3939
if (!t->f_mbuf && t->opts->tcpd_gpu_pci_addr) {
40-
if (tcpd_cuda_setup_alloc(t->opts, &t->f_mbuf, t)) {
40+
if (tcpd_cuda_setup_alloc(t->opts, &t->f_mbuf, t))
4141
LOG_FATAL(t->cb, "%s: failed to setup devmem CUDA socket",
4242
__func__);
43-
exit(1);
44-
}
4543
}
4644
#endif /* WITH_TCPDEVMEM_CUDA */
4745
#ifdef WITH_TCPDEVMEM_UDMABUF
4846
if (!t->f_mbuf && t->opts->tcpd_nic_pci_addr) {
49-
if (udmabuf_setup_alloc(t->opts, &t->f_mbuf, t)) {
47+
if (udmabuf_setup_alloc(t->opts, &t->f_mbuf, t))
5048
LOG_FATAL(t->cb, "%s: failed to setup devmem UDMABUF socket",
5149
__func__);
52-
exit(1);
53-
}
5450
}
5551
#endif /* WITH_TCPDEVMEM_UDMABUF */
5652

@@ -119,16 +115,16 @@ void stream_handler(struct flow *f, uint32_t events)
119115
#ifdef WITH_TCPDEVMEM_CUDA
120116
if (t->opts->tcpd_gpu_pci_addr)
121117
n = tcpd_recv(fd, mbuf,
122-
opts->buffer_size,
123-
opts->recv_flags,
124-
t);
118+
opts->buffer_size,
119+
opts->recv_flags,
120+
t);
125121
else
126122
#endif /* WITH_TCPDEVMEM_CUDA */
127123
#ifdef WITH_TCPDEVMEM_UDMABUF
128124
if (t->opts->tcpd_nic_pci_addr)
129125
n = udmabuf_recv(fd, mbuf,
130-
opts->buffer_size,
131-
t);
126+
opts->buffer_size,
127+
t);
132128
else
133129
#endif /* WITH_TCPDEVMEM_UDMABUF */
134130
n = recv(fd, mbuf, opts->buffer_size,
@@ -152,16 +148,18 @@ void stream_handler(struct flow *f, uint32_t events)
152148
do {
153149
#ifdef WITH_TCPDEVMEM_CUDA
154150
if (t->opts->tcpd_gpu_pci_addr) {
155-
n = tcpd_send(fd, mbuf, opts->buffer_size, opts->send_flags, t);
151+
n = tcpd_send(fd, mbuf,
152+
opts->buffer_size,
153+
opts->send_flags,
154+
t);
156155
} else
157156
#endif /* WITH_TCPDEVMEM_CUDA */
158157
#ifdef WITH_TCPDEVMEM_UDMABUF
159158
if (t->opts->tcpd_nic_pci_addr) {
160-
n = udmabuf_send(fd,
161-
mbuf,
162-
opts->buffer_size,
163-
opts->send_flags,
164-
t);
159+
n = udmabuf_send(fd, mbuf,
160+
opts->buffer_size,
161+
opts->send_flags,
162+
t);
165163
} else
166164
#endif /* WITH_TCPDEVMEM_UDMABUF */
167165
n = send(fd, mbuf, opts->buffer_size, opts->send_flags);

‎tcpdevmem.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ int install_flow_steering(const struct options *opts, intptr_t buf,
5959
int ret;
6060

6161
int num_queues = q_start + (t->index % q_num);
62-
printf("Bind to queue %i\n", num_queues);
62+
LOG_INFO(t->cb, "Bind to queue %i\n", num_queues);
6363
struct dma_buf_pages_bind_rx_queue bind_cmd;
6464

6565
strcpy(bind_cmd.ifname, opts->tcpd_link_name);
@@ -95,7 +95,7 @@ int install_flow_steering(const struct options *opts, intptr_t buf,
9595
sprintf(ethtool_cmd, "ethtool --set-rxfh-indir %s equal 8", opts->tcpd_link_name);
9696
RETURN_IF_NON_ZERO(system(ethtool_cmd));
9797

98-
printf("ethtool cmds returned %i, sleeping 1...\n", ret);
98+
LOG_INFO(t->cb, "ethtool cmds returned %i, sleeping 1...\n", ret);
9999
sleep(1);
100100
}
101101
return ret;

‎tcpdevmem_cuda.cu‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ int get_gpumem_dmabuf_pages_fd(const std::string& gpu_pci_addr,
132132
if (*dma_buf_fd < 0)
133133
PLOG_FATAL(t->cb, "cuMemGetHandleForAddressRange");
134134
135-
printf("Registered dmabuf region 0x%p of %lu Bytes\n",
136-
gpu_mem, gpu_mem_sz);
135+
LOG_INFO(t->cb, "Registered dmabuf region 0x%p of %lu Bytes\n",
136+
gpu_mem, gpu_mem_sz);
137137
138138
struct dma_buf_create_pages_info frags_create_info;
139139
frags_create_info.dma_buf_fd = *dma_buf_fd;
@@ -169,8 +169,6 @@ int tcpd_cuda_setup_alloc(const struct options *opts, void **f_mbuf, struct thre
169169
void *gpu_gen_mem_;
170170
int gpu_mem_fd_;
171171
int dma_buf_fd_;
172-
// int q_start = opts->queue_start;
173-
// int q_num = opts->queue_num;
174172
struct tcpdevmem_cuda_mbuf *tmbuf;
175173
const char *gpu_pci_addr = opts->tcpd_gpu_pci_addr;
176174
const char *nic_pci_addr = opts->tcpd_nic_pci_addr;
@@ -312,13 +310,13 @@ int tcpd_recv(int socket, void *f_mbuf, size_t n, int flags, struct thread *t) {
312310
313311
ssize_t received = recvmsg(socket, msg, MSG_SOCK_DEVMEM | MSG_DONTWAIT);
314312
if (received < 0 && (errno == EAGAIN || errno == EWOULDBLOCK)) {
315-
printf("%s %d: recvmsg returned < 0\n", __func__, __LINE__);
313+
LOG_ERROR(t->cb, "%s %d: recvmsg returned < 0\n", __func__, __LINE__);
316314
return -1;
317315
} else if (received < 0) {
318-
printf("%s %d\n", __func__, __LINE__);
316+
LOG_ERROR(t->cb, "%s %d\n", __func__, __LINE__);
319317
return -1;
320318
} else if (received == 0) {
321-
printf("Client exited\n");
319+
LOG_ERROR(t->cb, "Client exited\n");
322320
return -1;
323321
}
324322

‎tcpdevmem_udmabuf.c‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,20 @@ int udmabuf_setup_alloc(const struct options *opts, void **f_mbuf, struct thread
5151
if (memfd < 0)
5252
LOG_FATAL(t->cb, "[skip,no-memfd]");
5353

54-
5554
ret = fcntl(memfd, F_ADD_SEALS, F_SEAL_SHRINK);
5655
if (ret < 0)
5756
LOG_FATAL(t->cb, "[skip,fcntl-add-seals]");
5857

5958
ret = ftruncate(memfd, size);
6059
if (ret == -1)
61-
LOG_FATAL(t->cb, "[FAIL,memfd-truncate]\n");
60+
LOG_FATAL(t->cb, "[FAIL,memfd-truncate]");
6261

6362
memset(&create, 0, sizeof(create));
6463

6564
create.memfd = memfd;
6665
create.offset = 0;
6766
create.size = size;
68-
printf("size=%lu\n", size);
67+
LOG_INFO(t->cb, "udmabuf size=%lu", size);
6968
buf = ioctl(devfd, UDMABUF_CREATE, &create);
7069
if (buf < 0)
7170
LOG_FATAL(t->cb, "[FAIL, create udmabuf]");
@@ -137,7 +136,6 @@ int udmabuf_send(int socket, void *f_mbuf, size_t n, int flags, struct thread *t
137136
munmap(buf_mem, n);
138137

139138
memset(msg, 0, sizeof(struct msghdr));
140-
// memset(cmsg, 0, sizeof(struct cmsghdr));
141139

142140
iov.iov_base = buf_dummy;
143141
iov.iov_len = n - tmbuf->bytes_sent;

0 commit comments

Comments
 (0)