On Sun, Apr 17, 2011 at 4:05 PM, Zak Elep <[email protected]> wrote:
> On Fri, Apr 15, 2011 at 7:40 PM, Ambrosio Berdijo <[email protected]> wrote:
>>
>> That was an Awesome post from fooler...
>
> Yes, very instructive indeed. Interestingly though, the waste.c
> program displays a different behavior on a non-Linux system. In my
> case, I tried it on an OpenBSD box, and found it wouldn't eat CPU load
> for any value other than 100 percent.
i downloaded and run the latest openbsd version 4.8 and test the
waste.c code inside my licensed vmware workstation version 7.1.4 for
windows simulating 2 processors and 2 cores per processor with a total
of 4 processor cores and here is what i got..
openbsd:fooler {8} id
uid=1001(fooler) gid=1001(fooler) groups=1001(fooler), 0(wheel)
openbsd:fooler {9} uname -a
OpenBSD openbsd.nokia.com 4.8 GENERIC.MP#359 i386
openbsd:fooler {10} gcc -v
Reading specs from /usr/lib/gcc-lib/i386-unknown-openbsd4.8/4.2.1/specs
Target: i386-unknown-openbsd4.8
Configured with: OpenBSD/i386 system compiler
Thread model: posix
gcc version 4.2.1 20070719
openbsd:fooler {11} gcc waste.c -o waste
openbsd:fooler {12} ./waste 70
Start to sampling clock speed...
Sampling done. Wasting CPU approximately 70 percent...
top output (run top and press shift + C)..
load averages: 0.75, 0.66, 0.44 openbsd.nokia.com 18:40:45
22 processes: 20 idle, 2 on processor
CPU0 states: 69.1% user, 0.0% nice, 0.0% system, 0.0% interrupt, 30.9% idle
CPU1 states: 0.0% user, 0.0% nice, 0.0% system, 0.0% interrupt, 100% idle
CPU2 states: 0.0% user, 0.0% nice, 0.0% system, 0.0% interrupt, 100% idle
CPU3 states: 0.0% user, 0.0% nice, 0.2% system, 0.0% interrupt, 99.8% idle
Memory: Real: 8328K/47M act/tot Free: 195M Swap: 0K/145M used/tot
PID USERNAME PRI NICE SIZE RES STATE WAIT TIME CPU COMMAND
31357 fooler 53 0 260K 648K onproc/0 - 4:44 70.17% ./waste 70
27635 fooler 28 0 668K 1392K onproc/1 - 0:07 0.78% top
7215 root 2 0 3316K 2512K idle netio 0:55 0.00% sshd: foole
9121 root 2 0 3212K 2520K idle netio 0:05 0.00% sshd: foole
1649 root 2 0 1020K 1460K sleep/2 select 0:01 0.00% sendmail: a
24867 root 2 0 688K 1204K idle select 0:01 0.00% /usr/sbin/s
26571 _pflogd 4 0 724K 312K sleep/2 bpf 0:01 0.00% pflogd: [ru
29532 _syslogd 2 0 416K 700K idle poll 0:00 0.00% syslogd -a
7095 fooler 18 0 540K 412K idle pause 0:00 0.00% -csh
6695 root 3 0 352K 760K idle ttyin 0:00 0.00% /usr/libexe
11632 fooler 2 0 3316K 1968K sleep/2 select 0:00 0.00% sshd: foole
9732 root 3 0 460K 768K idle ttyin 0:00 0.00% /usr/libexe
7725 fooler 18 0 460K 420K idle pause 0:00 0.00% -csh
32663 root 3 0 464K 760K idle ttyin 0:00 0.00% /usr/libexe
11108 root 3 0 244K 772K idle ttyin 0:00 0.00% /usr/libexe
21026 root 2 0 520K 712K idle select 0:00 0.00% inetd
6674 root 2 0 576K 800K idle select 0:00 0.00% cron
1 root 10 0 304K 304K idle wait 0:00 0.00% /sbin/init
1393 root 3 0 364K 764K idle ttyin 0:00 0.00% /usr/libexe
1263 root 2 0 660K 396K idle netio 0:00 0.00% pflogd: [pr
21366 fooler 2 0 3196K 1992K idle select 0:00 0.00% sshd: foole
28155 root 2 0 396K 672K idle netio 0:00 0.00% syslogd: [p
also tested in latest freebsd version 8.2 with the same vmware
settings with openbsd...
%id
uid=1002(fooler) gid=1002(fooler) groups=1002(fooler),0(wheel)
%uname -a
FreeBSD freebsd.nokia.com 8.2-RELEASE FreeBSD 8.2-RELEASE #1: Fri Mar
4 12:09:38 SGT 2011
[email protected]:/usr/obj/usr/src/sys/FREEBSD i386
%gcc -v
Using built-in specs.
Target: i386-undermydesk-freebsd
Configured with: FreeBSD/i386 system compiler
Thread model: posix
gcc version 4.2.1 20070719 [FreeBSD]
%gcc waste.c -o waste
%./waste 70
Start to sampling clock speed...
Sampling done. Wasting CPU approximately 70 percent...
top output (run top -P and press shift C and press small A)...
last pid: 1273; load averages: 0.91, 0.71, 0.47 up 0+00:43:47 10:47:40
18 processes: 2 running, 16 sleeping
CPU 0: 0.0% user, 0.0% nice, 0.0% system, 0.0% interrupt, 100% idle
CPU 1: 70.0% user, 0.0% nice, 0.0% system, 0.0% interrupt, 30.0% idle
CPU 2: 0.0% user, 0.0% nice, 0.0% system, 2.2% interrupt, 97.8% idle
CPU 3: 0.0% user, 0.0% nice, 0.0% system, 0.0% interrupt, 100% idle
Mem: 8912K Active, 12M Inact, 21M Wired, 64K Cache, 10M Buf, 201M Free
Swap: 512M Total, 512M Free
PID USERNAME THR PRI NICE SIZE RES STATE C TIME CPU COMMAND
1254 fooler 1 111 0 3292K 920K CPU1 1 9:15 71.00% ./waste 70
1210 fooler 1 44 0 9436K 4492K select 3 0:00 0.00% sshd: fooler
1257 fooler 1 44 0 3688K 1892K CPU0 0 0:00 0.00% top -P
984 root 1 44 0 6092K 3328K select 0 0:00 0.00% sendmail: ac
692 root 1 44 0 3352K 1208K select 0 0:00 0.00% /usr/sbin/sy
1207 root 1 46 0 9436K 4480K sbwait 2 0:00 0.00% sshd: fooler
1216 fooler 1 44 0 9436K 4492K select 0 0:00 0.00% sshd: fooler
976 root 1 44 0 6712K 3708K select 0 0:00 0.00% /usr/sbin/ss
1213 root 1 46 0 9436K 4480K sbwait 2 0:00 0.00% sshd: fooler
995 root 1 44 0 3380K 1336K nanslp 2 0:00 0.00% /usr/sbin/cr
1217 fooler 1 44 0 4672K 2320K pause 1 0:00 0.00% -csh (csh)
492 root 1 54 0 3292K 1292K select 0 0:00 0.00% dhclient: em
1211 fooler 1 44 0 4672K 2320K pause 1 0:00 0.00% -csh (csh)
526 _dhcp 1 44 0 3292K 1444K select 3 0:00 0.00% dhclient: em
988 smmsp 1 44 0 6092K 3384K pause 2 0:00 0.00% sendmail: Qu
549 root 1 44 0 1888K 584K select 1 0:00 0.00% /sbin/devd
1065 root 1 76 0 3352K 1108K ttyin 2 0:00 0.00% /usr/libexec
131 root 1 76 0 1544K 848K pause 0 0:00 0.00% adjkerntz -i
just compile waste.c without gcc optimization (eg. gcc waste.c -o
waste) and make sure that during the sampling of clock speed time is
more than 1 second to get a better results...
or give me the openbsd version you have there and i will download and
double check running inside my vmware...
by the way.. you can replace this line ..
waste = (int) (SAMPLING / cps / (100.0 / percent));
with...
waste = (int) (SAMPLING / cps * percent / 100.0);
to avoid division by zero when you pass zero percent value as an argument...
fooler.
_________________________________________________
Philippine Linux Users' Group (PLUG) Mailing List
http://lists.linux.org.ph/mailman/listinfo/plug
Searchable Archives: http://archives.free.net.ph