Lev Serebryakov
2018-10-13 15:40:06 UTC
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?
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:***@FreeBSD.org
Best regards,
Lev mailto:***@FreeBSD.org