BL618的wifi性能太低了,如何进行优化
之前的帖子中测试了BL618的wifi性能,不是很理想,TCP传输率太低了,UDP的传输率还可以,这两个测试都是使用官方SDK提供的测试程序,自己改了下demo中提供udp测试程序,发现比官方的程序慢了将近10倍
自己写的iperf测试
官方SDK的iperf测试程序
把SDK翻遍了才发现官方的测试程序也打包进wifi库了,没有代码,只有个libwifi6.a文件,一步步排查代码,发现是socket的sendto函数延时过高造成的,不管发送多少字节,哪怕只是100字节,也至少有2ms的阻塞延时,改成非阻塞模式,也没能解决这个阻塞情况。
- void iperf_client(void *thread_param)
- {
- int sock = -1,i;
- int opt = -1;
- struct sockaddr_in udp_addr, remote_addr;
- uint8_t* send_buf;
- u32_t tick1, tick2;
- uint64_t sentlen;
- socklen_t addr_len;
- int32_t *pkt_id_p;
- int32_t pkt_cnt = 0;
- int actual_send = 0;
- int want_send = 0;
- int send_time = 0;
- send_buf = (uint8_t *) pvPortMalloc(IPERF_BUFSZ);
- if (!send_buf)
- return ;
- for (i = 0; i < IPERF_BUFSZ; i ++)
- send_buf[i] = i & 0xff;
-
- vTaskDelay(2000);
- pkt_id_p = (int32_t *)send_buf;
- want_send = IPERF_BUFSZ;
- while(1)
- {
- if ((sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
- printf("udp create socket error\r\n");
- continue;
- }
- setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
- udp_addr.sin_family = AF_INET;
- udp_addr.sin_port = htons(UDP_PORT);
- udp_addr.sin_addr.s_addr = INADDR_ANY;
- memset(&(udp_addr.sin_zero), 0, sizeof(udp_addr.sin_zero));
- printf("Server ip Address : %s:%d\r\n", udp_addr.sin_addr.s_addr, UDP_PORT);
- if (bind(sock, (struct sockaddr *)&udp_addr, sizeof(struct sockaddr)) != 0) {
- printf("udp bind falied!\r\n");
- closesocket(sock);
- continue;
- }
- printf("udp bind port success!\r\n");
- printf("UDP Test Start...\r\n");
- long n = 1;
- lwip_ioctl(sock,FIONBIO,&n);
- remote_addr.sin_family = AF_INET;
- remote_addr.sin_port = htons(UDP_PORT);
- remote_addr.sin_addr.s_addr = inet_addr("192.168.2.248");
- memset(&(udp_addr.sin_zero), 0, sizeof(udp_addr.sin_zero));
- addr_len = sizeof(struct sockaddr);
- if (connect(sock,(struct sockaddr *)&remote_addr,sizeof(struct sockaddr)) == -1)
- {
- printf("Connect failed!\n");
- closesocket(sock);
- vTaskDelay(10);
- continue;
- }
- printf("Connect to iperf server successful!\n");
- tick1 = sys_now();
- while (1)
- {
- tick2 = sys_now();
- if (tick2 - tick1 >= configTICK_RATE_HZ * 5)
- {
- float f;
- f = (float)(sentlen*configTICK_RATE_HZ/125/(tick2 - tick1));
- f /= 1000.0f;
- printf("send speed = %.4f Mbps!\n", f);
- tick1 = tick2;
- sentlen = 0;
- }
- *pkt_id_p = htonl(pkt_cnt); // datagrams need to be sequentially numbered
- if (pkt_cnt >= INT32_MAX) pkt_cnt = 0;
- else pkt_cnt++;
- send_time = bflb_mtimer_get_time_us();
- actual_send = sendto(sock, send_buf, want_send, 0, (struct sockaddr *)&remote_addr, addr_len);
- send_time = bflb_mtimer_get_time_us() - send_time;
- printf("sendtime = %dus\r\n",send_time);
- if (actual_send != want_send)
- {
- printf("send fail,%d\r\n",actual_send);
- }
- else
- {
- sentlen += actual_send;
- }
-
- }
- closesocket(sock);
- }
- }
复制代码
|