Uus memset() funktsiooni optimeerimine glibc-s

Intel'i insener Noah Goldstein optimeeris glibc teegi memset() funktsiooni. See optimeerimine toob kaasa umbes 7,5% jõudluse kasvu Skylake-X ja Ice Lake arhitektuuri desktopiprotsessorite puhul. Serveriversioonide jõudlus on veidi madalam, peamiselt ühe tuuma üldise jõudluse tõttu.

Eelmises memset() funktsiooni teostuses kasutati assembleri käsku rep stosb. Kuni hiljuti töötas see käsk piisavalt kiiresti, tänu protsessori sees toimunud zero-over-zero writeback optimeerimisele. Siiski leiti selles optimeerimises potentsiaalne haavatavus, mis võib viia külgkanali rünnakuni. Tulemuseks tühistati zero-over-zero writeback optimeerimine, mis tõi kaasa rep stosb jõudluse languse. Uues memset() versioonis kasutatakse käsku rep stosb endiselt, kuid ainult rangemate tingimuste täitmisel.

Mida täpselt muutus, saab aru järgmise kommentaari muutusest koodis, mis kirjeldab memset() teostuse üksikasju.

Eelmise versiooni kirjeldus:

/* memset is implemented as: 1. Use overlapping store to avoid branch. 2. If size is less than VEC, use integer register stores. 3. If size is from VEC_SIZE to 2 * VEC_SIZE, use 2 VEC stores. 4. If size is from 2 * VEC_SIZE to 4 * VEC_SIZE, use 4 VEC stores. 5. On machines ERMS feature, if size is greater or equal than __x86_rep_stosb_threshold then REP STOSB will be used. 6. If size is more to 4 * VEC_SIZE, align to 4 * VEC_SIZE with 4 VEC stores and store 4 * VEC at a time until done. */

Uue versiooni kirjeldus:

/* memset is implemented as: 1. Use overlapping store to avoid branch. 2. If size is less than VEC, use integer register stores. 3. If size is from VEC_SIZE to 2 * VEC_SIZE, use 2 VEC stores. 4. If size is from 2 * VEC_SIZE to 4 * VEC_SIZE, use 4 VEC stores. 5. If size is more to 4 * VEC_SIZE, align to 1 * VEC_SIZE with 4 VEC stores and store 4 * VEC at a time until done. 6. On machines ERMS feature, if size is range [__x86_rep_stosb_threshold, __x86_memset_non_temporal_threshold) then REP STOSB will be used. 7. If size >= __x86_memset_non_temporal_threshold, use a non-temporal stores. */

Allikas: linux.org.ru

Osta usaldusväärne veebihosting DDoS kaitsega, VPS VDS serverid 🔥 Osta usaldusväärne veebihosting DDoS kaitsega, VPS VDS serverid | ProHoster