aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char/random.c
diff options
context:
space:
mode:
authorGreg Price <price@MIT.EDU>2013-12-06 21:28:03 -0500
committerTheodore Ts'o <tytso@mit.edu>2014-03-19 22:18:51 -0400
commit2132a96f66b6b4d865113e7d4cb56d5f7c6e3cdf (patch)
tree6d8ba662272c64cd38ed5049572b73923efef7ae /drivers/char/random.c
parent7d1b08c40c4f02c119476b29eca9bbc8d98d2a83 (diff)
random: clarify bits/bytes in wakeup thresholds
These are a recurring cause of confusion, so rename them to hopefully be clearer. Signed-off-by: Greg Price <price@mit.edu> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Diffstat (limited to 'drivers/char/random.c')
-rw-r--r--drivers/char/random.c34
1 files changed, 17 insertions, 17 deletions
diff --git a/drivers/char/random.c b/drivers/char/random.c
index 581d806823e9..8cc7d6515676 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -295,14 +295,14 @@
295 * The minimum number of bits of entropy before we wake up a read on 295 * The minimum number of bits of entropy before we wake up a read on
296 * /dev/random. Should be enough to do a significant reseed. 296 * /dev/random. Should be enough to do a significant reseed.
297 */ 297 */
298static int random_read_wakeup_thresh = 64; 298static int random_read_wakeup_bits = 64;
299 299
300/* 300/*
301 * If the entropy count falls under this number of bits, then we 301 * If the entropy count falls under this number of bits, then we
302 * should wake up processes which are selecting or polling on write 302 * should wake up processes which are selecting or polling on write
303 * access to /dev/random. 303 * access to /dev/random.
304 */ 304 */
305static int random_write_wakeup_thresh = 28 * OUTPUT_POOL_WORDS; 305static int random_write_wakeup_bits = 28 * OUTPUT_POOL_WORDS;
306 306
307/* 307/*
308 * The minimum number of seconds between urandom pool reseeding. We 308 * The minimum number of seconds between urandom pool reseeding. We
@@ -669,7 +669,7 @@ retry:
669 int entropy_bits = entropy_count >> ENTROPY_SHIFT; 669 int entropy_bits = entropy_count >> ENTROPY_SHIFT;
670 670
671 /* should we wake readers? */ 671 /* should we wake readers? */
672 if (entropy_bits >= random_read_wakeup_thresh) { 672 if (entropy_bits >= random_read_wakeup_bits) {
673 wake_up_interruptible(&random_read_wait); 673 wake_up_interruptible(&random_read_wait);
674 kill_fasync(&fasync, SIGIO, POLL_IN); 674 kill_fasync(&fasync, SIGIO, POLL_IN);
675 } 675 }
@@ -678,9 +678,9 @@ retry:
678 * forth between them, until the output pools are 75% 678 * forth between them, until the output pools are 75%
679 * full. 679 * full.
680 */ 680 */
681 if (entropy_bits > random_write_wakeup_thresh && 681 if (entropy_bits > random_write_wakeup_bits &&
682 r->initialized && 682 r->initialized &&
683 r->entropy_total >= 2*random_read_wakeup_thresh) { 683 r->entropy_total >= 2*random_read_wakeup_bits) {
684 static struct entropy_store *last = &blocking_pool; 684 static struct entropy_store *last = &blocking_pool;
685 struct entropy_store *other = &blocking_pool; 685 struct entropy_store *other = &blocking_pool;
686 686
@@ -924,19 +924,19 @@ static void _xfer_secondary_pool(struct entropy_store *r, size_t nbytes)
924{ 924{
925 __u32 tmp[OUTPUT_POOL_WORDS]; 925 __u32 tmp[OUTPUT_POOL_WORDS];
926 926
927 /* For /dev/random's pool, always leave two wakeup worth's BITS */ 927 /* For /dev/random's pool, always leave two wakeups' worth */
928 int rsvd = r->limit ? 0 : random_read_wakeup_thresh/4; 928 int rsvd_bytes = r->limit ? 0 : random_read_wakeup_bits / 4;
929 int bytes = nbytes; 929 int bytes = nbytes;
930 930
931 /* pull at least as many as BYTES as wakeup BITS */ 931 /* pull at least as much as a wakeup */
932 bytes = max_t(int, bytes, random_read_wakeup_thresh / 8); 932 bytes = max_t(int, bytes, random_read_wakeup_bits / 8);
933 /* but never more than the buffer size */ 933 /* but never more than the buffer size */
934 bytes = min_t(int, bytes, sizeof(tmp)); 934 bytes = min_t(int, bytes, sizeof(tmp));
935 935
936 trace_xfer_secondary_pool(r->name, bytes * 8, nbytes * 8, 936 trace_xfer_secondary_pool(r->name, bytes * 8, nbytes * 8,
937 ENTROPY_BITS(r), ENTROPY_BITS(r->pull)); 937 ENTROPY_BITS(r), ENTROPY_BITS(r->pull));
938 bytes = extract_entropy(r->pull, tmp, bytes, 938 bytes = extract_entropy(r->pull, tmp, bytes,
939 random_read_wakeup_thresh / 8, rsvd); 939 random_read_wakeup_bits / 8, rsvd_bytes);
940 mix_pool_bytes(r, tmp, bytes, NULL); 940 mix_pool_bytes(r, tmp, bytes, NULL);
941 credit_entropy_bits(r, bytes*8); 941 credit_entropy_bits(r, bytes*8);
942} 942}
@@ -952,7 +952,7 @@ static void push_to_pool(struct work_struct *work)
952 struct entropy_store *r = container_of(work, struct entropy_store, 952 struct entropy_store *r = container_of(work, struct entropy_store,
953 push_work); 953 push_work);
954 BUG_ON(!r); 954 BUG_ON(!r);
955 _xfer_secondary_pool(r, random_read_wakeup_thresh/8); 955 _xfer_secondary_pool(r, random_read_wakeup_bits/8);
956 trace_push_to_pool(r->name, r->entropy_count >> ENTROPY_SHIFT, 956 trace_push_to_pool(r->name, r->entropy_count >> ENTROPY_SHIFT,
957 r->pull->entropy_count >> ENTROPY_SHIFT); 957 r->pull->entropy_count >> ENTROPY_SHIFT);
958} 958}
@@ -987,7 +987,7 @@ retry:
987 987
988 trace_debit_entropy(r->name, 8 * ibytes); 988 trace_debit_entropy(r->name, 8 * ibytes);
989 if (ibytes && 989 if (ibytes &&
990 (r->entropy_count >> ENTROPY_SHIFT) < random_write_wakeup_thresh) { 990 (r->entropy_count >> ENTROPY_SHIFT) < random_write_wakeup_bits) {
991 wake_up_interruptible(&random_write_wait); 991 wake_up_interruptible(&random_write_wait);
992 kill_fasync(&fasync, SIGIO, POLL_OUT); 992 kill_fasync(&fasync, SIGIO, POLL_OUT);
993 } 993 }
@@ -1303,7 +1303,7 @@ random_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos)
1303 1303
1304 wait_event_interruptible(random_read_wait, 1304 wait_event_interruptible(random_read_wait,
1305 ENTROPY_BITS(&input_pool) >= 1305 ENTROPY_BITS(&input_pool) >=
1306 random_read_wakeup_thresh); 1306 random_read_wakeup_bits);
1307 if (signal_pending(current)) 1307 if (signal_pending(current))
1308 return -ERESTARTSYS; 1308 return -ERESTARTSYS;
1309 } 1309 }
@@ -1334,9 +1334,9 @@ random_poll(struct file *file, poll_table * wait)
1334 poll_wait(file, &random_read_wait, wait); 1334 poll_wait(file, &random_read_wait, wait);
1335 poll_wait(file, &random_write_wait, wait); 1335 poll_wait(file, &random_write_wait, wait);
1336 mask = 0; 1336 mask = 0;
1337 if (ENTROPY_BITS(&input_pool) >= random_read_wakeup_thresh) 1337 if (ENTROPY_BITS(&input_pool) >= random_read_wakeup_bits)
1338 mask |= POLLIN | POLLRDNORM; 1338 mask |= POLLIN | POLLRDNORM;
1339 if (ENTROPY_BITS(&input_pool) < random_write_wakeup_thresh) 1339 if (ENTROPY_BITS(&input_pool) < random_write_wakeup_bits)
1340 mask |= POLLOUT | POLLWRNORM; 1340 mask |= POLLOUT | POLLWRNORM;
1341 return mask; 1341 return mask;
1342} 1342}
@@ -1559,7 +1559,7 @@ struct ctl_table random_table[] = {
1559 }, 1559 },
1560 { 1560 {
1561 .procname = "read_wakeup_threshold", 1561 .procname = "read_wakeup_threshold",
1562 .data = &random_read_wakeup_thresh, 1562 .data = &random_read_wakeup_bits,
1563 .maxlen = sizeof(int), 1563 .maxlen = sizeof(int),
1564 .mode = 0644, 1564 .mode = 0644,
1565 .proc_handler = proc_dointvec_minmax, 1565 .proc_handler = proc_dointvec_minmax,
@@ -1568,7 +1568,7 @@ struct ctl_table random_table[] = {
1568 }, 1568 },
1569 { 1569 {
1570 .procname = "write_wakeup_threshold", 1570 .procname = "write_wakeup_threshold",
1571 .data = &random_write_wakeup_thresh, 1571 .data = &random_write_wakeup_bits,
1572 .maxlen = sizeof(int), 1572 .maxlen = sizeof(int),
1573 .mode = 0644, 1573 .mode = 0644,
1574 .proc_handler = proc_dointvec_minmax, 1574 .proc_handler = proc_dointvec_minmax,