Gentoo Archives: gentoo-dev

From: Chris White <chriswhite@g.o>
To: gentoo-dev@l.g.o
Subject: [gentoo-dev] Portage, Jobs, and Niceness
Date: Tue, 31 May 2005 08:47:57
Message-Id: 20050531174821.53e95fd3@localhost
1 Hi all,
2
3 -- Niceness --
4
5 While waiting for kde to compile (read as hours), I decided to take a chance and talk about niceness and jobs this time. Ok so, we'll start with niceness first:
6
7 if portage.settings.has_key("PORTAGE_NICENESS"):
8 try:
9 os.nice(int(portage.settings["PORTAGE_NICENESS"]))
10 except SystemExit, e:
11 raise # Needed else can't exit
12 except Exception,e:
13 print "!!! Failed to change nice value to '"+str(portage.setting
14 s["PORTAGE_NICENESS"])+"'"
15 print "!!!",e
16
17 the setting PORTAGE_NICENESS in make.conf sets up the portage niceness. This code gives you an idea of how it is done. if it sees PORTAGE_NICENESS, it simply uses the os module's nice function to set the niceness. Now.. niceness is kind of weird.. so let's demonstrate using American Idol(tm)! Alright.. so you have your two wannabe singers here, ProcessPest and ProcessPrincess. Now.. Simon is the cpu here, having to judge which singer he wants more (it is safe to note here that one doesn't suck). Now, instead of showing who he likes more, he shows who he hates less! So, we have something like this:
18
19 nice -n -19 ProcessPrincess
20 nice -n 10 ProcessPest
21
22 So Simon says to ProcessPrincess "You suck -19, which means I like you, you get more cpu"
23 So Simon says to ProcessPest "You suck 10, which means you suck, you get screwed"
24
25 Now back to our regularly scheduled technical form... Ok, so now that we know what's going on, niceness means how "nice" you are to other programs. The more "nice" you are, the more willing you are to share your cpu to other programs. The less "nice" you are, the more you want to hog it to yourself. Now, when a process is set niceness, it does it by INCREMENT, not setting. This basically means that if you do this:
26
27 PORTAGE_NICENESS=10
28
29 portage will increase your niceness from its original (normally 0 unless nice was already applied to it) by 10, giving you 10 niceness. Now if you do it negative:
30
31 PORTAGE_NICENESS=-3
32
33 it increases by a negative number.. so it DECREASES portage niceness. In this case, it would be -3, which is generally an ok value. Note that the values go from -20 to 20, and that while you can increase niceness no problem, if you want to increases, you're probably going to need to be root. Note to BE CAREFUL ABOUT NICENESS. Remember, the same niceness that portage gets will be thusly applied to its child processes. That means if you're running -j5 with PORTAGE_NICENESS=-19, subprocesses will all recieve -19 niceness too. That's a lot of programs trying to grab for the cpu (I can tell you from experience that it can happen..)! Only try this if you have some spectacular multi processor elite setup. So that's what you get with niceness. Now let's look at jobs:
34
35 -- Jobs --
36
37 Then there's jobs. Now, this is extremly usefull for people that realized "Oh crap, I'm in the middle of emerge-ing such and such package and I just realized I need all my cpu for something more important (homework maybe?)". No need to fear! Bash has this nice little deal called jobs. Let's take a look:
38
39 Scenario
40
41 <ChrisWhite> Ahh crud! My xorg-x11 compile is halfway through and I just noticed this security patch I need to get through asap! What to do! (or I'm compiling kde and realize I missed an assignment at school!). Nice little handy bash function called jobs can take care of this. To work with jobs, simply press CTRL+Z during the compile. This stops the process as so:
42
43 (please note I was lazy here and removed my japanese error messages.. now you're not dreaming)
44
45 making imake with BOOTSTRAPCFLAGS= and CROSSCOMPILEFLAGS=-DCROSSCOMPILEDIR="" in config/imake
46 make[2]: Leaving directory `/var/tmp/portage/xorg-x11-6.8.99.8/work/xc/config/imake'
47 rm -f ./config/makedepend/Makefile.proto
48 ./config/imake/imake -I./config/cf -s ./config/makedepend/Makefile.proto -f ./config/makedepend/Imakefile -DTOPDIR=../.. -DCURDIR=./config/makedepend
49 ./config/cf/Imake.tmpl:109 include
50 Imakefile.c:35 :
51 ./config/cf/linux.cf:390: Warning: "BuildLibGlxWithoutPIC" redefined
52 ./config/cf/site.def:44 include ,
53 ./config/cf/Imake.tmpl:46
54 Imakefile.c:35 :
55 ./config/cf/host.def:63: Warning: this is the location of the previous definition
56 cd ./config/makedepend && rm -f -r Makefile Makefile.dep makedepend *.o bootstrap
57 cd ./config/makedepend && make -f Makefile.proto bootstrap
58 make[2]: Entering directory `/var/tmp/portage/xorg-x11-6.8.99.8/work/xc/config/makedepend'
59 make[2]: `bootstrap'
60 make[2]: Leaving directory `/var/tmp/portage/xorg-x11-6.8.99.8/work/xc/config/makedepend'
61 ./config/imake/imake -I./config/cf -s ./config/imake/Makefile.proto -f ./config/imake/Imakefile -DTOPDIR=../.. -DCURDIR=./config/imake -DBootStrap
62
63 [1]+ Stopped emerge xorg-x11
64
65 And it stopped! Now that you've done your stuff, you'd like it to run again. First off, we do a jobs listing like such:
66
67 secures chris # jobs
68 [1]+ Stopped emerge xorg-x11
69
70 Job 1 is listed here as our stopped emerge xorg-x11. Please note that jobs are PER SESSION. This means you can't just pull another console up and expect the current console's jobs to show up in it. One session, one job list. So, you have two options:
71
72 1) fg 1
73 2) bg 1
74
75 the first puts the process in the foreground
76 the second puts the process in the background
77
78 Let's pull it to the foreground in this case:
79
80 secures chris # fg 1
81 emerge xorg-x11
82 ./config/cf/Imake.tmpl:109 include
83 Imakefile.c:35 :
84 ./config/cf/linux.cf:390: : "BuildLibGlxWithoutPIC" redefined
85 ./config/cf/site.def:44 include
86 ./config/cf/Imake.tmpl:46 ,
87 Imakefile.c:35 :
88 ./config/cf/host.def:63: : this is the location of the previous definition
89 cd ./config/imake && make -f Makefile.proto bootstrapdepend
90 make[2]: Entering directory `/var/tmp/portage/xorg-x11-6.8.99.8/work/xc/config/imake'
91 make[2]: `bootstrapdepend'
92 make[2]: Leaving directory `/var/tmp/portage/xorg-x11-6.8.99.8/work/xc/config/imake'
93 cd ./config/imake && make -w -f Makefile.ini BOOTSTRAPCFLAGS="" CC="cc" bootstrap
94 make[2]: Entering directory `/var/tmp/portage/xorg-x11-6.8.99.8/work/xc/config/imake'
95 make[2]: `bootstrap'
96 make[2]: Leaving directory `/var/tmp/portage/xorg-x11-6.8.99.8/work/xc/config/imake'
97 cd ./config/imake && make -f Makefile.proto imakeonly
98 make[2]: Entering directory `/var/tmp/portage/xorg-x11-6.8.99.8/work/xc/config/imake'
99 make[2]: `imakeonly'
100 make[2]: Leaving directory `/var/tmp/portage/xorg-x11-6.8.99.8/work/xc/config/imake'
101 + rm -f xmakefile.bak
102 + mv xmakefile xmakefile.bak
103
104 and viola! Our compile moves right on! Please note that jobs is NOT A PROGRAM, it's a part of the shell. I know bash does it.. I'm not sure if others do. That's it for now, hope this becomes usefull to some people.
105
106 Chris White

Replies

Subject Author
Re: [gentoo-dev] Portage, Jobs, and Niceness Georgi Georgiev <chutz@×××.net>
Re: [gentoo-dev] Portage, Jobs, and Niceness Aron Griffis <agriffis@g.o>