Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F146545468
D14684.id40336.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
D14684.id40336.diff
View Options
Index: sys/dev/random/randomdev.c
===================================================================
--- sys/dev/random/randomdev.c
+++ sys/dev/random/randomdev.c
@@ -130,6 +130,8 @@
uint8_t *random_buf;
int error, spamcount;
ssize_t read_len, total_read, c;
+ /* 16 MiB takes about 0.08 s CPU time on my 2017 AMD Zen CPU */
+ const size_t sigchk_period = 16 * 1024 * 1024;
random_buf = malloc(PAGE_SIZE, M_ENTROPY, M_WAITOK);
p_random_alg_context->ra_pre_read();
@@ -167,12 +169,26 @@
read_len = MIN(read_len, PAGE_SIZE);
p_random_alg_context->ra_read(random_buf, read_len);
c = MIN(uio->uio_resid, read_len);
+ /*
+ * uiomove() may yield the CPU before each 'c' bytes
+ * (up to PAGE_SIZE) are copied out.
+ */
error = uiomove(random_buf, c, uio);
total_read += c;
+ /*
+ * Poll for signals every few MBs to avoid very long
+ * uninterruptible syscalls.
+ */
+ if (error == 0 && uio->uio_resid != 0 &&
+ (total_read - c) / sigchk_period !=
+ total_read / sigchk_period)
+ error = tsleep_sbt(&random_alg_context, PCATCH,
+ "randrd", SBT_1NS, 0, C_HARDCLOCK);
}
- if (total_read != uio->uio_resid && (error == ERESTART || error == EINTR))
+ if (error == ERESTART || error == EINTR) {
/* Return partial read, not error. */
error = 0;
+ }
}
free(random_buf, M_ENTROPY);
return (error);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Mar 4, 1:15 PM (13 h, 55 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
29244057
Default Alt Text
D14684.id40336.diff (1 KB)
Attached To
Mode
D14684: random(4): Poll for signals during large reads
Attached
Detach File
Event Timeline
Log In to Comment