What are ck_queue.h guarantees?

Lev Serebryakov lev at FreeBSD.org
Sat Oct 13 15:40:08 UTC 2018


Hello Freebsd-hackers,

  Concurrency Kit documentation says:

====
ck_queue is a queue.h-compatible implementation of many-reader-single-
writer queues. It allows for safe concurrent iteration, peeking and read-
side access in the presence of a single concurrent writer without any
usage of locks.
====

 But in all places at kernel I peeked, CK_XXXX macros are protected by
locks. Yes, even read ones.

  For example, there are a lot of addresses enumeration under locks in
 networks drivers, like this:

if_maddr_rlock(ifp);
CK_STAILQ_FOREACH(inm, &ifp->if_multiaddrs, ifma_link) {
    if (inm->ifma_addr->sa_family != AF_LINK)
        continue;
    crc = ether_crc32_le(LLADDR((struct sockaddr_dl *)
        inm->ifma_addr), ETHER_ADDR_LEN);

    /* Just want the 6 most significant bits. */
    crc >>= 26;

    /* Set the corresponding bit in the filter. */
    hash[crc >> 4] |= 1 << (crc & 0xf);
}
if_maddr_runlock(ifp);

  Why is it so? Why do we bother to use CK_XXX API (which adds all needed
barriers and uses CASes) if all accesses are protected by locks, anyway?

-- 
Best regards,
 Lev                          mailto:lev at FreeBSD.org



More information about the freebsd-hackers mailing list