Changeset View
Changeset View
Standalone View
Standalone View
sys/dev/random/random_harvestq.c
Show First 20 Lines • Show All 517 Lines • ▼ Show 20 Lines | |||||
*/ | */ | ||||
void | void | ||||
random_harvest_queue_(const void *entropy, u_int size, enum random_entropy_source origin) | random_harvest_queue_(const void *entropy, u_int size, enum random_entropy_source origin) | ||||
{ | { | ||||
struct harvest_event *event; | struct harvest_event *event; | ||||
u_int ring_in; | u_int ring_in; | ||||
KASSERT(origin >= RANDOM_START && origin < ENTROPYSOURCE, ("%s: origin %d invalid\n", __func__, origin)); | KASSERT(origin >= RANDOM_START && origin < ENTROPYSOURCE, ("%s: origin %d invalid\n", __func__, origin)); | ||||
/* Do a very dirty check to avoid taking lock if not necessary */ | |||||
if (((harvest_context.hc_entropy_ring.in + 1) % RANDOM_RING_MAX) | |||||
== harvest_context.hc_entropy_ring.out) | |||||
return; | |||||
RANDOM_HARVEST_LOCK(); | RANDOM_HARVEST_LOCK(); | ||||
ring_in = (harvest_context.hc_entropy_ring.in + 1)%RANDOM_RING_MAX; | ring_in = (harvest_context.hc_entropy_ring.in + 1)%RANDOM_RING_MAX; | ||||
if (ring_in != harvest_context.hc_entropy_ring.out) { | if (ring_in != harvest_context.hc_entropy_ring.out) { | ||||
/* The ring is not full */ | /* The ring is not full */ | ||||
event = harvest_context.hc_entropy_ring.ring + ring_in; | event = harvest_context.hc_entropy_ring.ring + ring_in; | ||||
event->he_somecounter = (uint32_t)get_cyclecount(); | event->he_somecounter = (uint32_t)get_cyclecount(); | ||||
event->he_source = origin; | event->he_source = origin; | ||||
event->he_destination = harvest_context.hc_destination[origin]++; | event->he_destination = harvest_context.hc_destination[origin]++; | ||||
▲ Show 20 Lines • Show All 136 Lines • Show Last 20 Lines |