Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/kern KNF (Khange Not Functional)
details: https://anonhg.NetBSD.org/src/rev/47572f45d8d4
branches: trunk
changeset: 339721:47572f45d8d4
user: riastradh <riastradh%NetBSD.org@localhost>
date: Wed Aug 05 16:51:09 2015 +0000
description:
KNF (Khange Not Functional)
diffstat:
sys/kern/kern_rndq.c | 149 +++++++++++++++++++++++++++-----------------------
1 files changed, 81 insertions(+), 68 deletions(-)
diffs (truncated from 505 to 300 lines):
diff -r 15d7ce330fad -r 47572f45d8d4 sys/kern/kern_rndq.c
--- a/sys/kern/kern_rndq.c Wed Aug 05 16:37:27 2015 +0000
+++ b/sys/kern/kern_rndq.c Wed Aug 05 16:51:09 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_rndq.c,v 1.71 2015/08/05 16:37:27 riastradh Exp $ */
+/* $NetBSD: kern_rndq.c,v 1.72 2015/08/05 16:51:09 riastradh Exp $ */
/*-
* Copyright (c) 1997-2013 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_rndq.c,v 1.71 2015/08/05 16:37:27 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_rndq.c,v 1.72 2015/08/05 16:51:09 riastradh Exp $");
#include <sys/param.h>
#include <sys/atomic.h>
@@ -190,7 +190,9 @@
}
void
-rnd_init_softint(void) {
+rnd_init_softint(void)
+{
+
rnd_process = softint_establish(SOFTINT_SERIAL|SOFTINT_MPSAFE,
rnd_intr, NULL);
rnd_wakeup = softint_establish(SOFTINT_CLOCK|SOFTINT_MPSAFE,
@@ -231,6 +233,7 @@
static inline void
rnd_schedule_softint(void *softint)
{
+
kpreempt_disable();
softint_schedule(softint);
kpreempt_enable();
@@ -239,16 +242,18 @@
static inline void
rnd_schedule_process(void)
{
+
if (__predict_true(rnd_process)) {
rnd_schedule_softint(rnd_process);
return;
- }
+ }
rnd_process_events();
}
static inline void
rnd_schedule_wakeup(void)
{
+
if (__predict_true(rnd_wakeup)) {
rnd_schedule_softint(rnd_wakeup);
return;
@@ -328,10 +333,10 @@
* might have something.
*/
if (delta == 0 || delta2 == 0 || delta3 == 0)
- return (0);
+ return 0;
d->outbits++;
- return (1);
+ return 1;
}
/*
@@ -593,13 +598,13 @@
c = pool_cache_get(rnd_mempc, PR_WAITOK);
if (c == NULL)
- return (NULL);
+ return NULL;
c->source = source;
c->cursor = 0;
c->entropy = 0;
- return (c);
+ return c;
}
/*
@@ -612,18 +617,19 @@
c = pool_cache_get(rnd_mempc, PR_NOWAIT);
if (c == NULL)
- return (NULL);
+ return NULL;
c->source = source;
c->cursor = 0;
c->entropy = 0;
- return (c);
+ return c;
}
static void
rnd_sample_free(rnd_sample_t *c)
{
+
memset(c, 0, sizeof(*c));
pool_cache_put(rnd_mempc, c);
}
@@ -656,17 +662,17 @@
}
switch (type) {
- case RND_TYPE_NET: /* Don't collect by default */
+ case RND_TYPE_NET: /* Don't collect by default */
flags |= (RND_FLAG_NO_COLLECT | RND_FLAG_NO_ESTIMATE);
break;
- case RND_TYPE_RNG: /* Space for statistical testing */
+ case RND_TYPE_RNG: /* Space for statistical testing */
rs->test = kmem_alloc(sizeof(rngtest_t), KM_NOSLEEP);
rs->test_cnt = 0;
/* FALLTHRU */
- case RND_TYPE_VM: /* Process samples in bulk always */
+ case RND_TYPE_VM: /* Process samples in bulk always */
flags |= RND_FLAG_FAST;
break;
- default:
+ default:
break;
}
@@ -686,9 +692,9 @@
rnd_printf_verbose("collecting");
if (flags & RND_FLAG_NO_ESTIMATE)
rnd_printf_verbose(" without estimation");
+ } else {
+ rnd_printf_verbose("off");
}
- else
- rnd_printf_verbose("off");
rnd_printf_verbose(")\n");
#endif
@@ -774,7 +780,7 @@
void
_rnd_add_uint32(krndsource_t *rs, uint32_t val)
{
- uint32_t ts;
+ uint32_t ts;
uint32_t entropy = 0;
if (rs->flags & RND_FLAG_NO_COLLECT)
@@ -798,7 +804,7 @@
void
_rnd_add_uint64(krndsource_t *rs, uint64_t val)
{
- uint32_t ts;
+ uint32_t ts;
uint32_t entropy = 0;
if (rs->flags & RND_FLAG_NO_COLLECT)
@@ -823,6 +829,7 @@
rnd_add_data(krndsource_t *rs, const void *const data, uint32_t len,
uint32_t entropy)
{
+
/*
* This interface is meant for feeding data which is,
* itself, random. Don't estimate entropy based on
@@ -848,10 +855,10 @@
int sample_count;
struct rnd_sampleq tmp_samples = SIMPLEQ_HEAD_INITIALIZER(tmp_samples);
- if (rs && (rs->flags & RND_FLAG_NO_COLLECT ||
- __predict_false(!(rs->flags &
- (RND_FLAG_COLLECT_TIME|
- RND_FLAG_COLLECT_VALUE))))) {
+ if (rs &&
+ (rs->flags & RND_FLAG_NO_COLLECT ||
+ __predict_false(!(rs->flags &
+ (RND_FLAG_COLLECT_TIME|RND_FLAG_COLLECT_VALUE))))) {
return;
}
todo = len / sizeof(dint);
@@ -869,7 +876,7 @@
struct timeval upt;
getmicrouptime(&upt);
- if ( (upt.tv_sec > 0 && rs->total > upt.tv_sec * 10) ||
+ if ((upt.tv_sec > 0 && rs->total > upt.tv_sec * 10) ||
(upt.tv_sec > 10 && rs->total > upt.tv_sec) ||
(upt.tv_sec > 100 &&
rs->total > upt.tv_sec / 10)) {
@@ -970,8 +977,9 @@
v2 = (uint8_t *)sample->values + cmplen;
if (__predict_false(!memcmp(v1, v2, cmplen))) {
- rnd_printf("rnd: source \"%s\" failed continuous-output test.\n",
- source->name);
+ rnd_printf("rnd: source \"%s\""
+ " failed continuous-output test.\n",
+ source->name);
return 1;
}
@@ -991,8 +999,9 @@
strlcpy(source->test->rt_name, source->name,
sizeof(source->test->rt_name));
if (rngtest(source->test)) {
- rnd_printf("rnd: source \"%s\" failed statistical test.",
- source->name);
+ rnd_printf("rnd: source \"%s\""
+ " failed statistical test.",
+ source->name);
return 1;
}
source->test_cnt = -1;
@@ -1031,8 +1040,7 @@
* after the entry was queued.
*/
if (__predict_false(!(sample->source->flags &
- (RND_FLAG_COLLECT_TIME|
- RND_FLAG_COLLECT_VALUE)))) {
+ (RND_FLAG_COLLECT_TIME|RND_FLAG_COLLECT_VALUE)))) {
SIMPLEQ_INSERT_TAIL(&df_samples, sample, next);
} else {
SIMPLEQ_INSERT_TAIL(&dq_samples, sample, next);
@@ -1087,15 +1095,13 @@
if (source->flags & RND_FLAG_COLLECT_VALUE) {
rndpool_add_data(&rnd_global.pool, sample->values,
- sample_count *
- sizeof(sample->values[1]),
- 0);
+ sample_count * sizeof(sample->values[1]),
+ 0);
}
if (source->flags & RND_FLAG_COLLECT_TIME) {
rndpool_add_data(&rnd_global.pool, sample->ts,
- sample_count *
- sizeof(sample->ts[1]),
- 0);
+ sample_count * sizeof(sample->ts[1]),
+ 0);
}
pool_entropy += entropy;
@@ -1136,12 +1142,14 @@
static void
rnd_intr(void *arg)
{
+
rnd_process_events();
}
static void
rnd_wake(void *arg)
{
+
rndsinks_distribute();
}
@@ -1156,7 +1164,7 @@
if (__predict_false(!timed_in)) {
if (boottime.tv_sec) {
rndpool_add_data(&rnd_global.pool, &boottime,
- sizeof(boottime), 0);
+ sizeof(boottime), 0);
}
timed_in++;
}
@@ -1164,7 +1172,7 @@
uint32_t c;
rnd_printf_verbose("rnd: WARNING! initial entropy low (%u).\n",
- rndpool_get_entropy_count(&rnd_global.pool));
+ rndpool_get_entropy_count(&rnd_global.pool));
/* Try once again to put something in the pool */
c = rnd_counter();
rndpool_add_data(&rnd_global.pool, &c, sizeof(c), 1);
@@ -1177,7 +1185,7 @@
" entropy = %d.\n",
entropy_count);
if (rndpool_extract_data(&rnd_global.pool, rnd_rt.rt_b,
- sizeof(rnd_rt.rt_b), RND_EXTRACT_ANY)
+ sizeof(rnd_rt.rt_b), RND_EXTRACT_ANY)
!= sizeof(rnd_rt.rt_b)) {
panic("rnd: could not get bits for statistical test");
}
@@ -1189,7 +1197,8 @@
* entropy.
*/
memcpy(rnd_testbits, rnd_rt.rt_b, sizeof(rnd_rt.rt_b));
- strlcpy(rnd_rt.rt_name, "entropy pool", sizeof(rnd_rt.rt_name));
+ strlcpy(rnd_rt.rt_name, "entropy pool",
+ sizeof(rnd_rt.rt_name));
if (rngtest(&rnd_rt)) {
/*
* The probabiliity of a Type I error is 3/10000,
@@ -1198,7 +1207,7 @@
* but developers objected...
Home |
Main Index |
Thread Index |
Old Index