yashsingh1/xdaforums huggingface dataset:
[G1 Android Development] Ohsaka:
The "renice" command is general isnt working because the usage appears to have changed...

I tried doing "renice -r +20 `pidof com.google.process.gapps`" but it doesn't seem to work.
[G1 Android Development] devsk:
post the output of the command. what does it say?

also, post the output of which renice . Note the italics. That's the command as you should type it.
[G1 Android Development] turboyo:
where do i enter this code su terminal? or are you guys using adb or something?
[G1 Android Development] Ohsaka:
which renice = /system/bin/renice

The reason I think it is not working originally is from the logcat when the phone boots:

08-17 23:12:21.623: INFO//system/bin/sh(56): --- Executing userinit.sh
08-17 23:12:29.183: INFO//system/bin/sh(56): rzscontrol /dev/block/ramzswap0 --memlimit_kb=18432 --backing_swap=/dev/block/mmcblk0p3 --init
08-17 23:12:29.183: INFO//system/bin/sh(56): vm.swappiness = 28
08-17 23:12:29.323: INFO//system/bin/sh(56): USAGE: renice [[-r] priority pids ...] [-g pid]
08-17 23:12:29.363: INFO//system/bin/sh(56): USAGE: renice [[-r] priority pids ...] [-g pid]
08-17 23:12:29.393: INFO//system/bin/sh(56): USAGE: renice [[-r] priority pids ...] [-g pid]
08-17 23:12:29.413: INFO//system/bin/sh(56): +++ Apps-to-SD successfully enabled
08-17 23:12:29.933: INFO/logwrapper(56): /system/bin/sh terminated by exit(0)

the bottom of my userinit.sh file:

renice -r +20 `pidof com.google.process.gapps`
renice -r -20 `pidof com.android.phone`
renice -r -20 `pidof mediaserver`

exit 0;

However, when i run those commands manually in the terminal, I get the following:

sched_set_scheduler: Invalid argument

I am thinking maybe the userinit.sh is getting executed before those processes exist. That would make the pidof command return blank, and then the usage message show up....
[G1 Android Development] :
USAGE: renice [[-r] priority pids ...] [-g pid]

have you tried this(adding the -g switch):

renice -r +20 -g `pidof com.google.process.gapps`
[G1 Android Development] stellarman:
I suspect that the reason it is not working on boot from the userinit.sh file is that renice changes the priority of a running process. I am pretty sure those processes are not running at the time userinit.sh runs.

Also, from my reading, it looks like we should be using a smaller integer for our priority. I read that -20 means almost nothing else gets to run, and the +20 only runs if nothing else is. I am thinking -5 and +5 would probably achieve the results we want.

I have searched quite a bit to find out what the switches mean/do (-u, -r, -g), but I can't seem to find anything. Anyone know?

Edit: Also, it looks like the integer range that the program looks for is from -20 to 19. And, it looks like the '+' sign is not needed (and might cause an error?).
[G1 Android Development] Deicist:
this might be of use?

according to that -20 means 'run very quickly' and 20 means 'run only when nothing else is running'

-g is 'group id'

-u is 'user id'

-p (we don't have this :/ ) is process id...

anyone got a guess for -r?
[G1 Android Development] devsk:
Guys, the diagnosis is correct. The processes are not there when userinit.sh is run....:(

It only works when run from adb or a root shell in a terminal AFTER the boot has completed.

As for arguments, deicist has it right. -g means change it for all processes belonging that group id, -u means change it for all processes belonging that user id, -p and -n are sort of superfluous because PID is a separate argument and PRIORITY is also a separate argument (Adjusting the NICE value is same as adjusting the effective priority of the process.)

No idea why it shows in help but -r is not there in busybox 1.14.2 or in util-linux-2.16, which are the two possible sources for renice on linux. It is possible that it is some variant of BSD syntax.
[G1 Android Development] devsk:
1. You are right about the + sign. If setting the nice value (with -n switch) is being incremented or decremented, it is required. It is not required if you are setting the priority straight. It will not cause an error though (+20 as integer = 20 as integer).

2. You want the extreme priorities because you want to use this device as a phone first and everything else as a bonus after that. A well written program will give away CPU when it doesn't need it. So, its not like com.android.phone or mediaserver are going hog the CPU forever with -20 priority. They are going to block on IO of some sort eventually or give up the CPU voluntarily.
[G1 Android Development] Deicist:
as an additional note: this is also a way to fix the 'missing sms' bug that plagues the hero roms isn't it?

I'm trying this on a hero rom:

renice -20 `pidof com.android.mms`
renice -19 `pidof com.android.phone`
[G1 Android Development] devsk:
Actually, lowering the gapps priority down seems to have improved my battery, even with constant suspend-resume cycles (its a bug in cyanogen 3.9.X, which only I seem to hit) during the time when the phone is actually supposed to be in standby.
[G1 Android Development] miketaylor00:
A couple of things. I am on a different ROM so maybe this is different for you guys. I can get them to run using the same file that does what your userinit.sh does. I can tell because when I log in, I can do a -s for status and it shows that the processes were changed. The phone/google processes start up immediately, before the userinit.sh runs. My other processes do not. However, the uid does not appear to change like the pid does. I'm going to try setting that on the other applications and it might work for all of them. Try putting it in this format in your userinit.sh

echo renice -20 `pidof mediaserver`

Then reboot and go into terminal. Execute the sh file with the -s to see the status. Because of the echo you will see if it worked or if there are any errors. You can also run the sh file to test it without rebooting but we need to know if it works on boot.
[G1 Android Development] Dare{D}evil:
Hey guys i am on the latest cyanogen and i put it with the echo as you said n i think it did work...here is the output from the status

renice -r +20 1656

renice -r -20 1615

renice -r -20 1556
[G1 Android Development] miketaylor00:
As I looked at it more, I think that it will show that whether it worked during startup or not. We will have to log it while the phone is starting up. Try testing it and see if it is working for you by calling your phone.
[G1 Android Development] overpower:
I could be wrong about shell scripting, but whenever you start a line with echo, the entire line isn't executed by the shell but merely outputted to standardout. Thus the echo before a line, will repeat everything after the echo, with the exception of the things in between `` which are run. So in effect, having the echo in the front does not run renice at all.

It's good for seeing what the shell would run and to prove pidof is actually finding a valid process.

The error message is due to the -20 flags in the 2 last lines. renice is reading that as arguments and not as a negative value. I'm not sure what the -r flag is doing, but its forcing renice to expect some numeric value after it. As soon as it sees the -20, which it thinks is another argument, it outputs a syntax error.

I'm using this, and receiving no error messages, but admittedly I don't know how to check whether the process priority has been adjusted to see if its working.

renice 15 `pidof com.google.process.gapps`
renice -20 `pidof com.android.phone`
renice -20 `pidof mediaserver`

Edit: Correction, its not that I don't know how to check, but rather our version of ps appears to be crippled and doesn't report a nice value. Anyone know of alternative ways to check?

Here's a nice linux priority primer.
[G1 Android Development] Dare{D}evil:
here is the log..u might find this intresting

08-18 23:15:03.984 I//system/bin/sh( 55): --- Executing userinit.sh
08-18 23:15:11.184 I//system/bin/sh( 55): Setting up swapspace version 1, size = 33550336 bytes
08-18 23:15:11.918 I//system/bin/sh( 55): rzscontrol /dev/block/ramzswap0 --disksize_kb=32768 --init
08-18 23:15:11.924 I//system/bin/sh( 55): vm.swappiness = 45
08-18 23:15:12.074 I//system/bin/sh( 55): renice -r +20
08-18 23:15:12.074 I//system/bin/sh( 55): renice -r -20
08-18 23:15:12.104 I//system/bin/sh( 55): renice -r -20
08-18 23:15:12.114 I//system/bin/sh( 55): +++ Apps-to-SD successfully enabled
08-18 23:15:12.654 I/logwrapper( 55): /system/bin/sh terminated by exit(0)
08-18 23:15:12.694 I/vold ( 1552): Android Volume Daemon version 2.0

[highlight]n so overpower is actually right i guess..it is juss echoing the renice without actually executing the command[/highlight]
[G1 Android Development] overpower:
What this echo shows is that the processes aren't starting yet, so its too early to renice. We'll probably need to run userinit.sh later, or ask Cyanogen to have userinit.sh run on a delayed start so all other processes can be loaded. I'm pretty sure a delay in the shell script wouldn't help as the shell script may block anything else from happening after it.
[G1 Android Development] devsk:
you can workaround that by doing the sleep and the commands in a function and invoking the function in the background with '&'. Like this (tested now):

# this is towards the end of userinit.sh
setPriorityLater()
{
# sleep for 2 minutes
sleep 120

# phone and all processes should surely by up by now
renice 20 `pidof com.google.process.gapps`
renice -20 `pidof com.android.phone`
renice -20 `pidof mediaserver`
}
setPriorityLater > /dev/null 2>&1 &

Also, note that people are doing a 'exit 0' towards the end of userinit.sh. They should not. Its not needed, and its bad to do that. For example, if you do that none of the shell programs can source your script.

Actually, nohup may not be needed/work under ash.
[G1 Android Development] ckrest:
Increase your time to forward (25 second max)

**61*1-ForwardToNumber**seconds#
[G1 Android Development] miketaylor00:
I believe that if you use a ; after the command it executes it and prints it to the screen. Here is what I get:

$ su
# sh /system/bin/swap -s
renice -20 1543
renice -18 113
renice +10 1581
===CompCache status===
CompCache version 0.6+
Compcache enabled
CompCache: MemLimit 18432(system) 18432(user)
CompCache: BackingSwap /dev/block/mmcblk0p3(system) /dev/block/mmcblk0p3(user)
CompCache: cc_swappiness - 28(system) 28(user)

If it isn't executing anything, how did it get the pid?
[G1 Android Development] devsk:
I have now verified this to be working on my phone. The extra sleep in the function and putting it in background does the trick. I logged these commands to a log file and could see that the pids were valid.
[G1 Android Development] cytown:
try

"busybox pidof" instead of "pidof"
[G1 Android Development] overpower:
Are you sure this works? I wrote my script without the standard out/standard error redirection, and it appears to me that as soon as the calling shell script exits, all its child processes are being terminated.

Anything in between backticks (`) is executed immediately by the shell script. Thus you're getting the pids because of the backticks.

How are you verifying that the processes are being properly changed by renice?
[G1 Android Development] devsk:
I was thinking the same thing. But it doesn't really kill it the child processes started in the background with '&' when the script exits. I verified that by writing scripts of my own....:D

Three steps:

1. Verify the renice command is doing the right thing by calling setpriority system call with correct args and setpriority returns 0. Used strace for this.

2. Echo each command to /sdcard/setpri.log and verify the PIDS written in that are the same one currently running using 'ps'.

3. Printed the eventual priority of the processes by doing:

cat /proc/`pidof com.android.phone`/stat | busybox awk '{print $18+$19}'

and got -20, which means nice value was adjusted.

Note that there is no way to get the task priority (ps and top don't return that), so I had to resort to basics...:D Get it from the /proc straight. 18th field is the priority and 19th field is the nice value. They are reported separately by 'top' in Linux but summed by 'ps'.
[G1 Android Development] mlevin:
Nope, you are not alone. I have had this problem for a long time, too.
[G1 Android Development] overpower:
Makes sense, anyway you can share your function? I noticed for com.android.process.apps that the cat stat isn't returning the same values as you get with com.android.phone. My guess is its because its running under the dalvikvm.
[G1 Android Development] gurnted:
I've been following this thread for a few days now, and it is progressing quite nicely. This solution seems to work rather well. I thought this morning to attempt setting a higher priority for Sipdroid, and got rather amazing results.

I used to get first ring after 3-5 rings on the caller's end, which left me with only a ring or two to answer. Now I get first reaction & CID almost instanly and first ring within 1-2 rings for caller. The latancy issues I was having during sip calls is also resolved now. Went a little further and raised GV's too. That got me instant loading of SMS & Call Log. Thank you to all who have been working on this.
[G1 Android Development] Ohsaka:
You know....

We should be able to take this methodology and turn it into an app that would let a user change the priority of any running process on their phone. It would require a reboot for the changes to take effect, But would probably be pretty useful to alot of people.
[G1 Android Development] miketaylor00:
It wouldn't require a reboot. The app could make the renice call and write the info to the startup file at the same time. I think this would be a dangerous application in novice hands. I suppose you could only allow them to set the priorities between 10 and -10 which would still help a lot. The default priority for most prociesses is 10 and -10 is the highest priority I have seen in Logcat for any system process. If the user was allowed to set anything to -20 they could really hose up their phone. My com.android.phone processes screwed up one time and my phone just kept ringing non stop, even after the voice mail was answered I had to do a hard reset of my phone to get it to stop. I use -18 now instead of -20 and it hasn't happened again. Imagine if someone set some really crappy apps to -20 that already hog the processor.
[G1 Android Development] devsk:
oh yeah! This has to be limited and scoped. It can hang the phone if done wrongly or done for a wrong process.
[G1 Android Development] miketaylor00:
@devsk, how are you changing the priority for apps that pop in and out and the pid is changing? I tried doing it with the uid, because custom apps seem to be assigned a unique uid but I haven't been able to make it work. For instance, Toggle Settings (com.cooolmagic.android.toggle5) starts up when my phone is booting up and gives me at least 2 wait screens. There is no reason for it to startup this early but it does. I was hoping to drop the priority on it way low so it won't load until everything else is loaded. Any ideas?
[G1 Android Development] devsk:
I think what you are asking for is not doable with renice command. Your requirement, if I understood it correctly, is: if a process belonging to user 'uid' comes up, assign it priority P. This can be done only with cgroups feature (which I think is present in cyanogen's kernel).
[G1 Android Development] AverageCanadian:
sorry for the newb question, but where is the userinit.sh file located? google told me system/sd but I didnt' see it there.
[G1 Android Development] miketaylor00:
Maybe it isn't an option here, but I did some research on renice and there was a -u option that would allow you to do it.

I don't know how to set priority for apps that turn on and off at different times. They aren't necessarily launched when the process runs at startup.

http://linux.about.com/library/cmd/blcmdl8_renice.htm
[G1 Android Development] miketaylor00:
Which ROM are you on? You might not have one. If not, check out this thread:

http://xdaforums.com/showthread.php?t=542899
[G1 Android Development] AverageCanadian:
I have CyanogenMod 4.0.1
[G1 Android Development] miketaylor00:
Cyanogen stopped using a userinit.sh. You can still use it if you want to but you will need to follow the thread I posted to set it up.
[G1 Android Development] AverageCanadian:
thanks. I imagine the only way to set up the script that was posted earlier in this thread is by creating a userinit.sh or equivilant via the thread you linked to?

What I mean to say, there is no other file in Cyanogen's mod that I could add to?
[G1 Android Development] devsk:
I am afraid that's not correct. here is a snippet from 4.0.1 /system/bin/a2sd:

# call a userinit.sh script if it's present on the sdcard
# otherwise just enable compcache with no backing swap
if [ -e /system/sd/userinit.sh ];
then
echo "--- Executing userinit.sh"
busybox chmod +x /system/sd/userinit.sh
/system/bin/sh /system/sd/userinit.sh;
else
modprobe ramzswap;
/system/bin/rzscontrol /dev/block/ramzswap0 --init
swapon /dev/block/ramzswap0
fi
[G1 Android Development] devsk:
-u will change only the processes which are running at the time when renice is run. Its just a way of filtering who to apply the renice command to. With -u, you are saying "set the NICE value of all processes running at this time belonging to user id 'uid'". It doesn't take care of processes which will be created in future.
[G1 Android Development] AverageCanadian:
so then, going by the comments, if I just create a userinit.sh in /system/bin/a2sd, it should pick it up automatically?

Also when does Cyanogen call that bit of code? Is the sleep code still required?
[G1 Android Development] miketaylor00:
Trust me on this one. He does allow for it. All that code does is check if the userinit.sh exists. If it does, it uses those settings. If it doesn't, it turns on compcache. The original install for it doesn't have a userinit.sh. It supports a userinit.sh but it doesn't use one by default.

I know this because people got mad at me when I told them to use my user.conf with 4.0.1 and it didn't work.
[G1 Android Development] Ohsaka:
You have to create the userinit.sh file in the /system/sd/ directory...
[G1 Android Development] bigballa:
referencing to that

if you have the overclock widget on and have it customized so that when the screen is off it has a different freq range compared to when it has the screen on that also causes a delay in the phone's screen turning on and receiving phone calls.

so on the overclock widget just set the min to 245 and the max to 528 and leave the screen off freq disabled/unchecked

hope it helps...
[G1 Android Development] devsk:
ohh...ok. I thought you meant CM doesn't support userinit.sh anymore. It does support it but it doesn't supply one but if the user has put one in /system/sd, it utilizes it.
[G1 Android Development] rikupw:
theres an app for that ;)

I found an app on the market called 'Autostart (root)' that will run a script placed at /data/opt/autostart.sh after the phone is completely finished booting

I just tested it using the following in the autostart.sh:

busybox renice 15 `pidof com.google.process.gapps`
busybox renice -20 `pidof com.android.phone`
busybox renice -20 `pidof mediaserver`

I haven't tested it after a long period of time, but right after booting, (tested before autostart.sh and after the appJust thought I will put in the script I wrote for getting the priority and NICE value of a process by name. Save the attached file as printPriority.sh in the folder /system/sd when /system/sd is mounted.) the ringtime was quite literally at the first ring,

without the autostart.sh app it was after around the 2nd or 3rd ring, depending.

anyone else want to confirm this?

(confirmed by devsk two posts down)

I'm also running CyanogenMod 4.0.1 :)

EDIT: now to find the best settings, I'm not sure exactly how to use the renice command properly, etc etc, so I'll wait to use it actively until I know more, but the app does work, using the script devsk provided to check the nice values (with or without the autostart.sh script) i can see it working :). maybe a script-meister can help us out there ? :)
[G1 Android Development] devsk:
Nice find!! Exactly what we need!
[G1 Android Development] devsk:
Just thought I will put in the script I wrote for getting the priority and NICE value of a process by name. Save the attached file as printPriority.sh in the folder /system/sd when /system/sd is mounted.

Run it like this:

/ # sh /system/sd/printPriority.sh phone

BTW, the Autostart from market works! I just tested it.

Edit: Modify a little to account for multiple processes with same name. Sample output:

# adb shell sh /system/sd/printPriority.sh apps
PATH=com.google.process.gapps NAME=(app_process) PID=225 PRI=39 NICE=19
PATH=com.google.android.apps.googlevoice NAME=(app_process) PID=374 PRI=20 NICE=0
PATH=com.smartandroidapps.audiowidget NAME=(app_process) PID=465 PRI=20 NICE=0
[G1 Android Development] Deicist:
just to sum up this thread so far:

if an app is currently running you can change its priority with renice, -20 for 'run this no matter what else is running', 20 for 'only run this app if nothing else is running'

setting com.android.phone & mediaserver to high priority (-18 or so) and com.google.process.gapps to low priority (15 or so) gives a quicker ringtime

there's currently no way of setting a priority for apps that aren't currently running, or setting persistent priorities so that apps can close and open and keep the same priority

now:

if we had some kind of cron scheduler we could run it every 30 seconds or so and renice everything that's running... that's not an elegant solution, but short of having a built in persistent priority setting it might be our best bet. Of course, if the list of renice commands was huge you'd probably bog the phone down running through it every 30 seconds.... something to think about though maybe?
[G1 Android Development] stellarman:
Did we determine that the code above DID or DID NOT work? I have been following the thread pretty carefully, but might have missed something. Is there a particular advantage to using the AutoStart (root) program from the market, instead of using this code in userinit.sh? I like the idea of adding this to userinit, instead of running another program at start-up, if this works as expected.

Thanks.
[G1 Android Development] rjlan82:
The time it takes for the phone to start ringing (playing ringtone) is a bit annoying. It starts vibrating quickly enough, atleast. But what really bugs me is how long it takes to repeat the ringtone. I use 'Standard 4', and it takes waaay to long to repeat the ringer sound. I don't have another phone next to me right now, but I've observed in the past that when I receive a few calls back-to-back, it will ring like a normal phone should (as far as ringing speed is concerned).
[G1 Android Development] devsk:
Autostart is a sure shot of way doing this. It was reported that the code above which puts stuff in background by using '&' may not work in some versions. It worked for me but did not work for another person here. Autostart method works for sure because it was designed for that purpose.
[G1 Android Development] rikupw:
regarding ringtone playback speed

I noticed the same thing in older cyanogen builds, and it doesn't seem like using renice works for the mediaserver, occasionally it kills itself >.> haha

however, regarding the time it takes for the ringtones to load up, try using some of the ringtones from this thread:

http://xdaforums.com/showthread.php?t=544530

they are re-ogg'd audio files compressed a little more for space, I put them on cyanogen's builds and WAMMO, they ring hardly without any lag!

good luck! :)