Some general rules to optimize the C code:
- Profile your code and focus on time-consuming code segments
- Use -O2, -O3 compiler optimization macros. Sometimes you should be careful while these macros. One example is HW modifying some variables and s/w uses these variables which compiler may not be aware of it. If we use proper qualifiers like volatile , there may not be issues
- loop optimizations , memory optimizations, inline functions, reduce function calls, pre-fetch operations, cache optimizations
- Avoid global variables, optimize I/O operations, use right data types, avoid redundant code
Apart from these general optimizations, we did some kind of research while implementing data path functionalities. Some of this research is published as below patents:
- IPSec patent explains a method avoiding hash table search for IPSec SA
- Openflow data path-related patent explains how to avoid going through the flow tables, flow index tables, flow instructions, and a method to cache this information
- A method to optimize DMA operations explains a method of how we can program key-table to avoid fetching multiple hash table entries.
Some part of this research is published as defensive publications at IP.com:
- Implementation of SDN cumulative actions
- Support for multiple keys in table lookup engine, enhancing efficiency and versatility