Skip to content

Commit

Permalink
issue: WIP Remove VLAs to fix clang-18 build
Browse files Browse the repository at this point in the history
clang-18 generates a warning that VLA is a clang extension. Allocate
the arrays on heap instead of stack.

Signed-off-by: Dmytro Podgornyi <dmytrop@nvidia.com>
  • Loading branch information
pasis committed Apr 26, 2024
1 parent 2cf07c1 commit a2b51dc
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/core/dev/net_device_table_mgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ int net_device_table_mgr::global_ring_wait_for_notification_and_process_element(
{
ndtm_logfunc("");
int ret_total = 0;
int max_fd = 16;
constexpr int max_fd = 16;
struct epoll_event events[max_fd];

int res = SYSCALL(epoll_wait, global_ring_epfd_get(), events, max_fd, 0);
Expand Down
11 changes: 8 additions & 3 deletions src/core/dev/ring_tap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -597,20 +597,25 @@ int ring_tap::mem_buf_tx_release(mem_buf_desc_t *buff_list, bool b_accounting, b

int ring_tap::send_buffer(xlio_ibv_send_wr *wr, xlio_wr_tx_packet_attr attr)
{
int ret = 0;
iovec iovec[wr->num_sge];
NOT_IN_USE(attr);

struct iovec *iovec = new struct iovec[wr->num_sge];
if (!iovec) {
errno = ENOMEM;
return -1;
}

for (int i = 0; i < wr->num_sge; i++) {
iovec[i].iov_base = (void *)wr->sg_list[i].addr;
iovec[i].iov_len = wr->sg_list[i].length;
}

ret = SYSCALL(writev, m_tap_fd, iovec, wr->num_sge);
int ret = SYSCALL(writev, m_tap_fd, iovec, wr->num_sge);
if (ret < 0) {
ring_logdbg("writev: tap_fd %d, errno: %d\n", m_tap_fd, errno);
}

delete[] iovec;
return ret;
}

Expand Down
21 changes: 13 additions & 8 deletions src/core/sock/sockinfo_tcp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2225,15 +2225,20 @@ err_t sockinfo_tcp::rx_lwip_cb_recv_callback(void *arg, struct tcp_pcb *pcb, str
}

// fill io vector array with data buffer pointers
iovec iov[p_first_desc->rx.n_frags];
nr_frags = 0;
for (tmp = p_first_desc; tmp; tmp = tmp->p_next_desc) {
iov[nr_frags++] = tmp->rx.frag;
}
struct iovec *iov = new struct iovec[p_first_desc->rx.n_frags];
if (likely(iov)) {
nr_frags = 0;
for (tmp = p_first_desc; tmp; tmp = tmp->p_next_desc) {
iov[nr_frags++] = tmp->rx.frag;
}

// call user callback
callback_retval =
conn->m_rx_callback(conn->m_fd, nr_frags, iov, &pkt_info, conn->m_rx_callback_context);
// call user callback
callback_retval = conn->m_rx_callback(conn->m_fd, nr_frags, iov, &pkt_info,
conn->m_rx_callback_context);
delete[] iov;
} else {
callback_retval = XLIO_PACKET_DROP;
}
}

if (callback_retval == XLIO_PACKET_DROP) {
Expand Down
11 changes: 9 additions & 2 deletions src/core/sock/sockinfo_udp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2319,15 +2319,22 @@ inline xlio_recv_callback_retval_t sockinfo_udp::inspect_by_user_cb(mem_buf_desc
}

// fill io vector array with data buffer pointers
iovec iov[p_desc->rx.n_frags];
int nr_frags = 0;
struct iovec *iov = new struct iovec[p_desc->rx.n_frags];
if (!iov) {
return XLIO_PACKET_DROP;
}

for (mem_buf_desc_t *tmp = p_desc; tmp; tmp = tmp->p_next_desc) {
iov[nr_frags++] = tmp->rx.frag;
}

// call user callback
return m_rx_callback(m_fd, nr_frags, iov, &pkt_info, m_rx_callback_context);
xlio_recv_callback_retval_t ret =
m_rx_callback(m_fd, nr_frags, iov, &pkt_info, m_rx_callback_context);

delete[] iov;
return ret;
}

/* Update completion with
Expand Down
2 changes: 1 addition & 1 deletion src/core/util/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ int get_base_interface_name(const char *if_name, char *base_ifname, size_t sz_ba
}
}

unsigned char tmp_mac[ADDR_LEN];
unsigned char tmp_mac[MAX_L2_ADDR_LEN];
if (ADDR_LEN == get_local_ll_addr(ifa->ifa_name, tmp_mac, ADDR_LEN, false)) {
int size_to_compare = 0;
if (ADDR_LEN == ETH_ALEN) {
Expand Down
8 changes: 6 additions & 2 deletions src/stats/stats_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2265,9 +2265,12 @@ void get_all_processes_pids(std::vector<int> &pids)
int print_processes_stats(const std::vector<int> &pids)
{
const int SIZE = pids.size();

int num_instances = 0;
sh_mem_info_t sh_mem_info[SIZE];

sh_mem_info_t *sh_mem_info = new sh_mem_info_t[SIZE];
if (!sh_mem_info) {
return 1;
}

// 1. N * prepare shmem and indicate XLIO to update shmem
for (int i = 0; i < SIZE; ++i) {
Expand All @@ -2287,6 +2290,7 @@ int print_processes_stats(const std::vector<int> &pids)
complete_print_process_stats(sh_mem_info[i]);
}

delete[] sh_mem_info;
return 0;
}

Expand Down

0 comments on commit a2b51dc

Please sign in to comment.