Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,769,065 Members 40,874 Now Online
XDA Developers Android and Mobile Development Forum

[APK] Seeder 2.0.0 entropy generator to provide significant lag reduction

Tip us?
 
lambgx02
Old
(Last edited by lambgx02; 22nd January 2013 at 12:31 PM.)
#1  
Senior Member - OP
Thanks Meter 2938
Posts: 235
Join Date: Jul 2008
Location: Montreal
Default [APK] Seeder 2.0.0 entropy generator to provide significant lag reduction

Hey everyone,

Version 2.0.0 released!

This version introduces performance tuning, power management control, and an optional MMC I/O queue extension/timing change.

For those of you who have seen reboots / black screens that seem to be caused by Seeder, I suspect it may be due to the power management implemented in previous versions. Disabling power management (by unchecking "Suspend RNG service while screen off") may help. In my testing, battery impact was negligible (less than 2% per 24h).

The performance profiles are Light, Moderate, and Aggressive, and they control how frequently rngd wakes. The default configuration (Light) is unchanged from previous versions. Moderate and Aggressive may impact battery life (slightly), but may also help on devices where the entropy pool is drained quickly and often.

Last but not least, the "Extend I/O queue" option increases the nr_requests on MMC devices to 1024, and increases the dirty page expiry time, allowing more outstanding writes to accumulate. This may allow the I/O scheduler to make better decisions and combine more writes; some users have reported an improvement under heavy I/O.

Feedback appreciated!

---

On some (older) versions of Android, the JVM (and other components) often read random data from the blocking /dev/random device. On newer builds, this problem has been solved, yet depletion of the input entropy pool still seems to slow devices.

So, I cross-compiled rngd, and used it to feed /dev/urandom into /dev/random at 1 second intervals.

Result? Significant lag reduction (for some people)!

Note - if you want to try it, you must be running a rooted device, and you only need to install one of the APKs (latest version is best). Then, just open it, and turn it on. The other files (patches / .zips) are intended for recompiling, packaging, and init.d integration. If you uninstall the app, either turn off rngd first (open, and click the on/off button), or reboot afterwards; the UI does not presently kill the daemon on uninstallation.

For more information on using the .zip flashing method, see Ryuinferno's post here:

http://forum.xda-developers.com/show...postcount=1924

FAQ
Q: Do I need the .apk or the .zip?
A: The easiest method is simply installing the latest .apk, attached below. You do not need to use the patch or the .zip file.

Q: What is the patch for?
A: The patch file contains the source differences needed to recompile the Seeder version of the rngd binary. You only need it if you want to recompile rngd yourself.

Q: What is the .zip file for?
A: The .zip file contains the latest rngd binary. It is intended for ROM builders or those who want to build their own CWMR packages.

Q: Seeder keeps shutting down! Does this mean I have to restart it?
A: The Seeder UI is only used to configure and start/stop the RNG service, which runs in the background. The RNG service is not visible from Android, since it is a native Linux process. You can terminate the UI at any time, and the service will continue running.

Q: Does seeder cause excessive battery drain?
A: Seeder 1.2.7 introduced an RNG service power-saving mode. The process automatically suspends whenever the screen is off. The code is actually in the rngd native binary, so suspend/resume events happen independently of the UI; you can see it in action by attaching to the running process with strace. This means that battery drain while the screen is off is highly unlikely.

While the screen is on, the RNG service simply polls a file descriptor every second, and, when needed, injects a small amount of random data into /dev/random (and calls an ioctl). It's unlikely that this would present enough load to trigger a CPU governor state change at 10mhz (let alone 200mhz), so it shouldn't impact battery life. Having said that, I have received sporadic reports that it does reduce battery life on some devices. They may be coincidental (other software installed at the same time), or due to extra device use while testing. Or, they may be real. If you think your battery drain has increased, shoot me a PM!

Q: How can I see the RNG service Linux process?
A: In a terminal, type: ps | grep rngd

Q: How do I uninstall the .apk?
A: Launch Seeder, and stop the RNG service. Then, uninstall the app as you normally would. Alternatively, uninstall the app, and reboot.

Q: Is seeding /dev/random with /dev/urandom safe?
A: Seeding /dev/random with PRNG-derived data does reduce the quality of its random data. However, it's worth noting that nearly all major OSes except Linux do this. Linux is one of the very few to offer a blocking RNG device. And, at least as of ICS, Dalvik doesn't even read /dev/random, so there is little difference anyway.

Updates
There has been a lot of controversy about Seeder/rngd. In newer versions of Dalvik, nothing touches /dev/random, and yet many users (including myself) still notice a lag reduction. There are theories ranging from kernel lock contention to UI polling load when crediting the entropy pool to simply kicking the governor. And many who believe it's all placebo. I'm trying my best to figure out what exactly is happening, and others are as well.

Someone asked how I arrived at the conclusion I did when I started the thread back in November, and I posted this; I think it might be better served here:

A while back one of the webapps I was hosting on Tomcat (server-side) was experiencing some inexplicable latency and while stracing java I saw it frequently hanging on read()'s from /dev/random. I checked the available entropy, and it was constantly under 250 or so. It was a VM, no HWRNG, so I decided to use rngd to push urandom->random.

Dropped session creation times under load from 5-10 seconds to less than a second.

It's worth noting that Linux is one of very few OSes that have a blocking RNG device. Free/OpenBSD, Windows, etc.. essentially only provide urandom. It's generally considered secure, even for long-term crypto keys, so long as the initial seed is big (and random) enough.

Checked on my device, and saw a few processes grabbing /dev/random. /proc/sys/kernel/random/entropy_avail reporting depleted input pool. Figured it was worth a shot, so I rebuilt rngd for arm (with a few patches, linked on first page), and tried it out. It made a significant difference. Posted it up on this thread, and had a lot of positive feedback. Wanted to get into Android development, so figured.. why not wrap a little UI around it. More positive feedback, so I threw it on the market as well.

I had no idea it would take off like this and was shocked when I saw it Thursday morning. I'm in the awkward position now of explaining why it seems to work for some people, and not for others, especially given the fact Dalvik doesn't have references to /dev/random as of ICS. Theories abound, but it looks like it might be an issue of polling the UI for input events when the entropy pool drops (which never happens so long as rngd is running).

I'm doing this as a hobby. I'm a *nix admin by trade, and can only spend time working on this stuff on evenings and weekends, and the last few weeks have been kinda nuts.

I want to stress to everyone that:

a) It doesn't work the way I thought it did on later Android builds, but it does reduce latency for me and many others even on these builds,
b) I'm offering (and always will offer) Seeder for free to everyone on XDA,
c) Like I say in the market description, if anyone has purchased it and it isn't working, PLEASE email me for a refund (and let me know what device you're on if you're willing).

I was one of the first to root the Captivate glide (my first Android phone), and submitted the A2DP bitpool patch; I was active in the n900 community. I hope everyone understands that I'm doing my best here!


I hope the technique proves useful to people, and if there is in fact contention at the kernel level, I hope it's solved so we all benefit.

Version 2.0.0 attached. No changes.

Version 2.0.0b1 attached. New performance profile selector, I/O queue extender, and power saving control. Improved root checking.

Version 1.4.0 attached. Major refactoring. Service control now fully asynchronous.

Version 1.3.1 attached. No changes from 1.3.1-beta.

Version 1.3.1-beta released. New root check method during ANR-sensitive code.

Version 1.3.0 attached. Proper IntentServices for process control, and notification on upgrade / loss of root / autostart failure.

Version 1.2.9 attached. Yet another update to the upgrade/autostart code.

Version 1.2.8 attached. Asynchronous startup of rngd during boot; this should solve the remaining autostart problems some users have reported.

Version 1.2.7 released. This version introduces a much more efficient suspend-on-sleep mode for rngd.

Version 1.2.6 released. This version reverts the suspend-on-sleep rngd change which may have been contributing to new latency. I'm sorting out a better way of implementing it.

Version 1.2.5 released. This version should fix the autostart failure some users have seen.

Version 1.2.4 released. This version implements a progress bar displaying your currently available entropy, as well as automatic rngd restart on upgrade.

Version 1.2 released. This version implements rngd suspend-on-sleep, and contains minor user interface updates, more robust process and superuser checks, and a new icon (thanks Nathanel!)

Version 1.1 released. This version uses the release signature, so you will need to uninstall the old XDA version first!

This version fixes the issue some users were seeing on later Jellybean ROMs, where the UI would misreport the RNG service status.

Caveats
  • There is a (theoretical) security risk, in that seeding /dev/random with /dev/urandom decreases the quality of the random data. In practice, the odds of this being cryptographically exploited are far lower than the odds of someone attacking the OS itself (a much simpler challenge). It's worth noting that as of ICS, Dalvik uses /dev/urandom exclusively, anyway, and that Linux is one of very few modern operating systems that even offer a blocking RNG device to begin with.
  • Support for rngd suspend-on-sleep was added to Seeder 1.2. It should no longer impact battery life while the device is asleep.
  • There has been a large amount of speculation on why/if this actually improves performance on ICS+ devices. I'm continuing to investigate and will post updates to this thread.

If you try it, let me know how it goes.

ROM builders - feel free to integrate this into your ROMs (either the .apk / application, or just the rngd binary called from init.d)!

If anyone's interested, I've launched a paid app on the Play store for non-xda users. As I add features I'll post the new versions here as a thanks to you guys (and xda community at large for being such a great resource). But if anyone's interested in the market's auto-update feature, just thought I'd mention it.

Cheers!
Attached Files
File Type: zip rngd_suspend-on-sleep_v2.zip - [Click for QR Code] (419.8 KB, 13782 views)
File Type: patch rngd-tools_android_suspend-on-sleep_v2.patch - [Click for QR Code] (7.4 KB, 4355 views)
File Type: apk Seeder-1.2.8.apk - [Click for QR Code] (584.4 KB, 9621 views)
File Type: apk Seeder-1.2.9.apk - [Click for QR Code] (584.8 KB, 3006 views)
File Type: apk Seeder-1.3.0.apk - [Click for QR Code] (586.3 KB, 6301 views)
File Type: apk Seeder-1.3.1.apk - [Click for QR Code] (589.1 KB, 14448 views)
File Type: apk Seeder-1.4.0.apk - [Click for QR Code] (591.8 KB, 334141 views)
File Type: apk Seeder-2.0.0b1.apk - [Click for QR Code] (1.05 MB, 71180 views)
File Type: zip rngd_suspend-on-sleep_v3.zip - [Click for QR Code] (420.9 KB, 8521 views)
File Type: patch rng-tools_android_suspend-on-sleep_v3.patch - [Click for QR Code] (9.1 KB, 5674 views)
File Type: zip extend_io_queue.zip - [Click for QR Code] (654 Bytes, 9049 views)
File Type: apk Seeder-2.0.0.apk - [Click for QR Code] (1.05 MB, 384676 views)
The Following 2,392 Users Say Thank You to lambgx02 For This Useful Post: [ Click to Expand ]
 
Warren87
Old
#2  
Senior Member
Thanks Meter 107
Posts: 532
Join Date: May 2012
This seems absolutely amazing!I think I'll try it out on the weekend, cheers!
I’ve learned… That life is like a roll of toilet paper. The closer it gets to the end, the faster it goes.
The Following 10 Users Say Thank You to Warren87 For This Useful Post: [ Click to Expand ]
 
Laugher19
Old
#3  
Laugher19's Avatar
Senior Member
Thanks Meter 15
Posts: 170
Join Date: Oct 2012
Will this work for cwmr 6

Sent from my SGH-I927 using xda app-developers app
 
soadzoor
Old
#4  
Senior Member
Thanks Meter 85
Posts: 218
Join Date: Sep 2012
Hi,

I would try this, cause I experienced these lags, and they're really annoying, but I'd really need a simple instruction for what to do. You wrote how you managed to discover what to do and stuff, but I'm lost between the lines. Since I'm kind of a newbie, I'm kindly asking you to write some kind of instruction manual step by step, and forgive my ignorance
The Following 11 Users Say Thank You to soadzoor For This Useful Post: [ Click to Expand ]
 
lambgx02
Old
#5  
Senior Member - OP
Thanks Meter 2938
Posts: 235
Join Date: Jul 2008
Location: Montreal
Quote:
Originally Posted by Laugher19 View Post
Will this work for cwmr 6
Not yet. If a few people try it and report positive results, I'll make a flashable image. Stay tuned.

Quote:
Originally Posted by soadzoor View Post
Hi,

I would try this, cause I experienced these lags, and they're really annoying, but I'd really need a simple instruction for what to do. You wrote how you managed to discover what to do and stuff, but I'm lost between the lines. Since I'm kind of a newbie, I'm kindly asking you to write some kind of instruction manual step by step, and forgive my ignorance
I updated the first post with instructions. Please be careful, though! Let me know if you need more detail.
The Following 20 Users Say Thank You to lambgx02 For This Useful Post: [ Click to Expand ]
 
soadzoor
Old
#6  
Senior Member
Thanks Meter 85
Posts: 218
Join Date: Sep 2012
Quote:
Originally Posted by lambgx02 View Post
I updated the first post with instructions. Please be careful, though! Let me know if you need more detail.
I got troubles. Using Terminal Emulator I got an error message when I type the 3rd line ("cp /mnt/sdcard/rngd /system/xbin"), it says: "sh: cp: not found"
The Following User Says Thank You to soadzoor For This Useful Post: [ Click to Expand ]
 
lambgx02
Old
#7  
Senior Member - OP
Thanks Meter 2938
Posts: 235
Join Date: Jul 2008
Location: Montreal
Quote:
Originally Posted by soadzoor View Post
I got troubles. Using Terminal Emulator I got an error message when I type the 3rd line ("cp /mnt/sdcard/rngd /system/xbin"), it says: "sh: cp: not found"
Where did you transfer rngd to on your phone? Have to make sure the source path matches.
The Following 7 Users Say Thank You to lambgx02 For This Useful Post: [ Click to Expand ]
 
soadzoor
Old
#8  
Senior Member
Thanks Meter 85
Posts: 218
Join Date: Sep 2012
Quote:
Originally Posted by lambgx02 View Post
Where did you transfer rngd to on your phone? Have to make sure the source path matches.
It does match, that's why I'm confused.. :\ which terminal do you use?
 
Zero Computing
Old
(Last edited by Zero Computing; 12th November 2012 at 06:50 PM.)
#9  
Senior Member
Thanks Meter 30
Posts: 112
Join Date: Sep 2012
Will test this later, for sure! If all goes well, may I request permissions to include this with the MIUI build I will be learning to make and attempting to produce?

edit: My phone wasnt particularly laggy before except when playing games, but there is a noticeable difference after executing this binary. Noticed a few small hangs but unsure if it is related to this binary.
The Following User Says Thank You to Zero Computing For This Useful Post: [ Click to Expand ]
 
thegreatergood
Old
(Last edited by thegreatergood; 12th November 2012 at 07:25 PM.)
#10  
Senior Member
Thanks Meter 845
Posts: 644
Join Date: Sep 2012

 
DONATE TO ME
I've tested it ... integrated it into my rom and installed ... there was no lag even right after it first boot ... its incredibly smooth ... though I too noticed small hangs ... though I attributed this to the device getting ahead of itself ....

Sent from my SGH-I927 using xda premium
Samsung Captivate Glide
-Roms-
Liquid Smooth - 4.2
CM10.1 - 4.2
AOKP - 4.2
RootBox - 4.2
RootBox - 4.1
LiteROM - 4.0
-Kernels-
LiteKernel - ICS
LiteKernel - JB
-Recovery-
TWRP

If you like my work, donate

The Following 15 Users Say Thank You to thegreatergood For This Useful Post: [ Click to Expand ]
Tags
entropy, mbq was here, performance
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes