Hello,
I am using two embedded boards connected to each other with wired GigE link: Jetson TX2 with Orbitty Carrier and FriendlyArm NanoPi Neo4.
Static IPV4 addresses assigned on both sides of this link.
I’m quite upset with CPU usage on Jetson TX2 side while running TCP/IP upload test program using all available bandwidth (code attached):
Nvidia Jetson TX2, Running MAXQ, jetson_clocks.sh executed
gyrolab@jetson-ai:~$ pidstat -u -p 24715 2
Linux 4.9.140-tegra (jetson-ai) 22.05.20 _aarch64_ (6 CPU)
19:38:08 UID PID %usr %system %guest %wait %CPU CPU Command
19:38:10 1000 24715 0,50 29,50 0,00 2,00 30,00 5 tcpclient
19:38:12 1000 24715 0,50 29,50 0,00 2,50 30,00 3 tcpclient
19:38:14 1000 24715 0,50 28,36 0,00 1,00 28,86 5 tcpclient
19:38:16 1000 24715 0,50 29,50 0,00 1,50 30,00 5 tcpclient
Running this code vise versa (client on Nanopi’s side):
pi@nanopineo4:~$ pidstat -u -p 6944 5
Linux 5.6.11-rockchip64 (nanopineo4) 05/22/20 _aarch64_ (6 CPU)
16:46:01 UID PID %usr %system %guest %wait %CPU CPU Command
16:46:06 1000 6944 0.20 14.20 0.00 0.00 14.40 1 tcpclient
16:46:11 1000 6944 0.20 14.20 0.00 0.00 14.40 1 tcpclient
16:46:16 1000 6944 0.00 14.40 0.00 0.00 14.40 1 tcpclient
16:46:21 1000 6944 0.20 14.00 0.00 0.00 14.20 1 tcpclient
Seems like CPU usage on Jetson’s side is two times higher comparing with old FriendlyArm’s H5 CPU for the same task.
Is this performance issue related to old 4.9 kernel, or this is driver side issue or something else?
I would be glad for any advice for related to optimization Jetson TX’2 wired network performance.
Sergiy
tcpserver.c
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <sys/time.h>
#define BUFSIZE (1024 * 1024)
#define PORT 8091
#define SA struct sockaddr
void func(int sockfd)
{
char * buff;
buff = malloc(BUFSIZE);
static struct timeval start_ts, ts;
uint32_t tx_size = 1024 * 1024;
uint32_t i = 0;
uint32_t tm;
fprintf(stderr, "Socket read started\n");
read(sockfd, buff, 0);
gettimeofday (&start_ts, NULL);
fprintf(stderr, "Start NULL-packet received\n");
for (;;) {
gettimeofday (&ts, NULL);
tm = ((ts.tv_sec - start_ts.tv_sec) * 1000000 +
(ts.tv_usec - start_ts.tv_usec)) / 1000;
if (i % 100 == 0)
fprintf(stderr, "%03d.%03d.Sending TX Buffer %d, size = %d\n",
tm / 1000, tm % 1000, i, tx_size);
write(sockfd, buff, tx_size);
i++;
}
}
int main()
{
socklen_t sockfd, connfd, len;
struct sockaddr_in servaddr, cli;
// socket create and verification
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd == -1) {
fprintf(stderr, "socket creation failed...\n");
exit(0);
}
else
fprintf(stderr, "Socket successfully created..\n");
bzero(&servaddr, sizeof(servaddr));
// assign IP, PORT
servaddr.sin_family = AF_INET;
servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
servaddr.sin_port = htons(PORT);
// Binding newly created socket to given IP and verification
if ((bind(sockfd, (SA*)&servaddr, sizeof(servaddr))) != 0) {
fprintf(stderr, "socket bind failed...\n");
exit(0);
}
else
fprintf(stderr, "Socket successfully binded..\n");
// Now server is ready to listen and verification
if ((listen(sockfd, 5)) != 0) {
fprintf(stderr, "Listen failed...\n");
exit(0);
}
else
fprintf(stderr, "Server listening..\n");
len = sizeof(cli);
// Accept the data packet from client and verification
connfd = accept(sockfd, (SA*)&cli, &len);
if (connfd < 0) {
fprintf(stderr, "server acccept failed...\n");
exit(0);
}
else
fprintf(stderr, "server acccept the client...\n");
func(connfd);
close(sockfd);
}
tcpclient.c
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <sys/time.h>
#define SERVER_IP "10.10.75.2"
#define BUFSIZE (1024 * 1024)
#define PORT 8091
#define SA struct sockaddr
void func(int sockfd)
{
char * buff;
static struct timeval start_ts, ts;
buff = malloc(BUFSIZE);
memset(buff, 0xFA, BUFSIZE);
uint32_t i = 0;
uint32_t tm;
write(sockfd, buff, 0);
fprintf(stderr, "Start NULL-packet sent\n");
gettimeofday (&start_ts, NULL);
for (;;) {
gettimeofday (&ts, NULL);
tm = ((ts.tv_sec - start_ts.tv_sec) * 1000000 +
(ts.tv_usec - start_ts.tv_usec)) / 1000;
uint32_t size = 0;
while (size < 1024 * 1024) {
size += read(sockfd, buff, BUFSIZE - size);
}
if (i % 100 == 0)
fprintf(stderr, "%03d.%03d.Received RX Buffer %d, size = %d\n",
tm / 1000, tm % 1000, i, size);
i++;
}
}
int main()
{
int sockfd;
struct sockaddr_in servaddr;
// socket create and varification
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd == -1) {
fprintf(stderr, "Socket creation failed...\n");
exit(0);
}
else
fprintf(stderr, "Socket successfully created..\n");
bzero(&servaddr, sizeof(servaddr));
// assign IP, PORT
servaddr.sin_family = AF_INET;
servaddr.sin_addr.s_addr = inet_addr(SERVER_IP);
servaddr.sin_port = htons(PORT);
// connect the client socket to server socket
if (connect(sockfd, (SA*)&servaddr, sizeof(servaddr)) != 0) {
fprintf(stderr, "Connection with the server failed...\n");
exit(0);
}
else
fprintf(stderr, "Connected to the server..\n");
func(sockfd);
close(sockfd);
}