LwIP

Started by tha, August 29, 2021, 09:15:30 AM

Previous topic - Next topic

tha

https://www.nongnu.org/lwip/2_1_x/optimization.html

Optimization hints

สิ่งแรกที่คุณต้องการเพิ่มประสิทธิภาพคือ the lwip_standard_checksum() routine จาก src/core/inet.c. คุณสามารถข้ามผ่าน standard function นี้ด้วย the #define LWIP_CHKSUM your_checksum_routine().

มี C examples ที่ให้ไว้ใน inet.c หรือคุณอาจต้องการงานฝีมือ an assembly function สำหรับสิ่งนี้. RFC1071 เป็น a good introduction ในเรื่องนี้.

การปรับปรุงที่สำคัญอื่นๆ สามารถทำได้โดย supplying assembly หรือ inline replacements สำหรับ htons() and htonl() ถ้าคุณกำลังใช้ a little-endian architecture. #define lwip_htons(x) your_htons() #define lwip_htonl(x) your_htonl() ถ้าคุณ #define พวกมันไปยัง htons() and htonl(), คุณควร #define LWIP_DONT_PROVIDE_BYTEORDER_FUNCTIONS เพื่อป้องกัน lwIP จากการกำหนด htonx / ntohx ความเข้ากันได้ของมาโคร.

ตรวจสอบ network interface driver ของคุณถ้ามันอ่านที่ความเร็วสูงกว่า the maximum wire-speed. ถ้า the hardware ไม่ได้รับการบริการบ่อยครั้งหรือเร็วเพียงพอ buffer overflows มีแนวโน้มที่จะเกิดขึ้น.

ตัวอย่างเช่น เมื่อใช้ the cs8900 driver, เรียก cs8900if_service(ethif) ให้บ่อยที่สุดเท่าที่เป็นได้. เมื่อใช้ an RTOS ให้ the cs8900 interrupt ปลุก a high priority task ที่บริการ driver ของคุณโดยใช้ a binary semaphore หรือ event flag. บาง drivers อาจยอมให้มีการปรับแต่งเพิ่มเติมเพื่อให้ตรงกับ application and network ของคุณ.

สำหรับรุ่นที่ใช้งานจริง ขอแนะนำให้ตั้งค่า LWIP_STATS เป็น 0.  โปรดทราบว่า speed performance ไม่ได้มีผลมากนักจากการตั้งค่าสูงให้กับ the memory options.


tha

https://www.nongnu.org/lwip/2_1_x/group__lwip__nosys.html



Detailed Description

ใช้โหมดนี้ถ้าคุณไม่รัน an OS บนระบบของคุณ. #define NO_SYS เป็น 1. ป้อน incoming packets ไปยัง netif->input(pbuf, netif) function จาก mainloop, ไม่จาก interrupt context. คุณสามารถจัดสรร a Packet buffers (PBUF) ใน interrupt context และใส่พวกมันลงใน a queue ซึ่งถูกประมวลผลจาก mainloop.
เรียก sys_check_timeouts() เป็นระยะๆใน the mainloop.
Porting: จัดให้มีใช้งาน functions ทั้งหมดใน Time, Critical sections และ Compiler/platform abstraction.
คุณสามารถใช้เฉพาะ "raw" APIs ในโหมดนี้.
Sample code:
(ตัวอย่างโปรแกรมดูในเว็บเอานะครับ)


tha



ประมวลผล received ethernet frames. โดยใช้ฟังชั่นนี้แทนที่จะใช้การเรียก ip_input โดยตรงและส่งผ่าน ARP frames ผ่านทาง etharp ใน ethernetif_input, the ARP cache ถูกป้องกันจากการเข้าถึงพร้อมกัน.
ไม่เรียกโดยตรง, ส่งผ่านไปยัง netif_add() และเรียก netif->input().

Parameters
          p                the received packet, p->payload ชี้ไปยัง the ethernet header
          netif        the network interface ที่ the packet ถูกรับแล้ว

See also
          LWIP_HOOK_UNKNOWN_ETH_PROTOCOL
          ETHARP_SUPPORT_VLAN
          LWIP_HOOK_VLAN_CHECK

tha



ถ้าทั้งสอง IP versions ถูกเปิดการใช้งาน, ฟังชั่นนี้สามารถส่ง packets ไปยังตัวที่ถูกต้อง. ไม่เรียกโดยตรง, ส่งผ่านไปยัง netif_add() และเรียก netif->input().

tha



เริ่มต้น modules ทั้งหมด. ใช้สิ่งนี้ใน NO_SYS mode. ใช้ tcpip_init() ถ้าเป็นอย่างอื่น.

tha



ส่งต่อ a received packet สำหรับ input processing ด้วย ethernet_input() หรือ ip_input() ขึ้นอยู่กับ netif flags. ไม่เรียกโดยตรง, ส่งผ่านไปยัง netif_add() และเรียก netif->input(). จะทำงานเฉพาะถ้า the netif driver เซ็ต NETIF_FLAG_ETHARP และ/หรือ NETIF_FLAG_ETHERNET flag! อย่างถูกต้อง

tha



จัดการ timeouts สำหรับ NO_SYS==1 (ตัวอย่างเช่นไมมีการใช้ tcpip_thread/sys_timeouts_mbox_fetch(). ใช้ sys_now() เพื่อเรียก timeout handler functions เมื่อ timeouts หมดเวลาลง.

ต้องถูกเรียกเป็นระยะๆจาก main loop ของคุณ.