L'ingegnere di Intel, Noah Goldstein, ha ottimizzato la funzione memset() nella libreria glibc. Questa ottimizzazione offre un aumento delle prestazioni del circa 7,5% sulle versioni desktop dei processori delle architetture Skylake-X e Ice Lake. Per le versioni server, l'aumento delle prestazioni è leggermente inferiore, principalmente a causa della minore potenza complessiva di un singolo core.
Nella precedente implementazione della funzione memset() veniva utilizzata l'istruzione assembler rep stosb. Fino a poco tempo fa, questa istruzione funzionava abbastanza rapidamente grazie all'ottimizzazione intra-processore zero-over-zero writeback. Tuttavia, è stata trovata una potenziale vulnerabilità in questa ottimizzazione, che potrebbe portare a un attacco tramite canale laterale. Di conseguenza, l'ottimizzazione zero-over-zero writeback è stata annullata, il che ha portato a un degrado delle prestazioni di rep stosb. Nella nuova versione di memset() l'istruzione rep stosb è ancora utilizzata, ma sotto condizioni più rigorose.
Ciò che è cambiato può essere compreso attraverso la modifica del seguente commento nel codice, che descrive i dettagli dell'implementazione di memset()
Versione precedente della descrizione:
/* 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. */
Nuova versione della descrizione:
/* 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. */
Fonte: linux.org.ru
