Forum Discussion
Altera_Forum
Honored Contributor
14 years agoHow to improve my ethernet's transfer speed?
My board : DE2-115
SOPCBuilder : DE2_115_WEB_SERVER_RGMII_ENET1 NIOS II software :Simple_Socket_Server(RGMII) Now I can transfer data to my PC in both 1000Mbps and 100Mbps mode. But the speed is really low, and 1000Mbps and 100Mbps mode don't have any differences. The speed is about 2.1MB/s. My codes in simple_socket_server.c are as follows. I hope that I can get some help to raise the transfer speed. ****************************************************** ********************simple_socket_server.c***************** ****************************************************** #include <stdio.h># include <string.h># include <ctype.h> /* MicroC/OS-II definitions */# include "includes.h" /* Simple UDP Client definitions */# include "simple_socket_server.h" # include "alt_error_handler.h" /* Nichestack definitions */# include "ipport.h"# include "tcpport.h"# define MAXDATASIZE 1450 void SSSSimpleSocketServerTask() { int fd_listen;// max_socket int fd_listen1; int long bytes_sent; int long bytes_recv; int nSendBufSize=SSS_TX_BUF_SIZE; struct sockaddr_in server_addr; struct sockaddr_in client_addr; fd_listen = socket(AF_INET, SOCK_STREAM, 0); setsockopt(fd_listen,SOL_SOCKET,SO_SNDBUF,(char * )&nSendBufSize,sizeof(int)); if (fd_listen< 0) { alt_NetworkErrorHandler(EXPANDED_DIAGNOSIS_CODE,"[sss_task] Socket creation failed"); } else { printf("Socket created"); } server_addr.sin_family = AF_INET; server_addr.sin_port = htons(SSS_PORT); server_addr.sin_addr.s_addr = INADDR_ANY; memset(&(server_addr.sin_zero), '\0', 8); if ((bind(fd_listen,(struct sockaddr *)&server_addr,sizeof(server_addr))) < 0) { alt_NetworkErrorHandler(EXPANDED_DIAGNOSIS_CODE,"[sss_task] Bind failed"); } else { printf("Bind is OK\n"); } if ((listen(fd_listen,5)) < 0 { alt_NetworkErrorHandler(EXPANDED_DIAGNOSIS_CODE,"[sss_task] Listen failed"); } else { printf("Listen is OK\n"); } int client_addrlen; client_addrlen=sizeof(client_addr); fd_listen1 = accept(fd_listen,(struct sockaddr *)&client_addr,&client_addrlen); while(1) { if(fd_listen1<0) { alt_NetworkErrorHandler(EXPANDED_DIAGNOSIS_CODE,"[sss_task] Accept creation failed"); } else { printf("accepted connection request\n"); } fd_listen = fd_listen1; break; } printf("Server: Sending some test data to client...\n"); char sendbuf[MAXDATASIZE] = "Bjtuxuxu Love FPGA!"; char recvbuf[200] = ""; while(1) { bytes_sent = send(fd_listen,sendbuf,SSS_BUF_LEN,0);//strlen(sendbuf) } if(bytes_sent<0) { alt_NetworkErrorHandler(EXPANDED_DIAGNOSIS_CODE,"[sss_task] Send failed"); } else { printf("SERVER : Send is OK \n"); printf("SERVER : Bytes sent:%ld.\n",bytes_sent); } bytes_recv = recv(fd_listen,recvbuf,200,0); if(bytes_recv<0) { alt_NetworkErrorHandler(EXPANDED_DIAGNOSIS_CODE,"[sss_task] Recv failed"); } else { printf("SERVER: recv() is OK.\n"); printf("SERVER: Received data is: \"%s\"\n", recvbuf); printf("SERVER: Bytes received: %ld.\n", bytes_recv); } return ; } ****************************************************** ********************simple_socket_server.c***************** ******************************************************5 Replies
- Altera_Forum
Honored Contributor
Hi,
a good start is to read the AN440 wich describes optimizations (CPU frequency increase, cache, etc...). - Altera_Forum
Honored Contributor
Minimize the number of receive call's by using Bigger TCP packet
- Altera_Forum
Honored Contributor
Thank you, I will read AN440 as you say.
- Altera_Forum
Honored Contributor
Yeah, I also want to use bigger TCP packet.
I should change the value of SSS_BUF_LEN or something else. Please give me some more advice, thank you! - Altera_Forum
Honored Contributor
Thank you again, your advice is really helpful.