Monday, June 27, 2011

Adding header to kernel-headers rpm package

I wanted to distribute the header files placed on /usr/include/linux by a custom kernel-headers package.

Isn't it just put the file at /home/peter/rpmbuild/BUILD/kernel-2.6.38.fc15.new/include/linux ?

No! This is only 50% of the work. The other 50% consists of adding a line to the file:
/home/peter/rpmbuild/BUILD/kernel-2.6.38.fc15.new/include/linux/Kbuild

The line looks like:
header-y += pst_syscalls.h

And voila! Now it is done!

The expected result is:

[peter@KDPeter ~]$ rpm -qf /usr/include/linux/pst_syscalls.h
kernel-headers-2.6.38.6-27.peter4.fc15.x86_64

How to tell rpmbuild the number of simultaneous jobs? (make -j)

On Fedora 15, setting the environment variable RPM_BUILD_NCPUS allows you to configure the number up to 16 simultaneous jobs. For example to set the number of simultaneous jobs to 12, so rpmbuild will call make -j12:

$ export RPM_BUILD_NCPUS=12

But if you need more than 16 simultaneous jobs, you will need to edit ~/.rpmmacros file. To allow numbers greater than 16, I've modified this file to:


[peter@notepeter ~]$ cat .rpmmacros

%_topdir %(echo $HOME)/rpmbuild

%_smp_mflags %( \
[ -z "$RPM_BUILD_NCPUS" ] \\\
&& RPM_BUILD_NCPUS="`/usr/bin/getconf _NPROCESSORS_ONLN`"; \\\
if [ "$RPM_BUILD_NCPUS" -gt 16 ]; then \\\
echo "-j$RPM_BUILD_NCPUS"; \\\
elif [ "$RPM_BUILD_NCPUS" -gt 3 ]; then \\\
echo "-j$RPM_BUILD_NCPUS"; \\\
else \\\
echo "-j3"; \\\
fi )

%__arch_install_post \
[ "%{buildarch}" = "noarch" ] || QA_CHECK_RPATHS=1 ; \
case "${QA_CHECK_RPATHS:-}" in [1yY]*) /usr/lib/rpm/check-rpaths ;; esac \
/usr/lib/rpm/check-buildroot

There were the number 16 where is the $RPM_BUILD_NCPUS.

Reference:
Fedora Source RPM

distcc is my friend!

Last month I spent some time on distcc trying to reduce Kernel build time. The original post is here. I had no success that time. I've tried it again. Now it was a true success. :-)

distcc reduced the build time of Fedora Kernel ~ 53% when using 3 PCs instead of one. From 25m5.938s to 11m52.751s.

Details:

With distcc:
[peter@notepeter SPECS]$ cd /home/peter/distcc/
[peter@notepeter distcc]$ ls -la
total 8
drwxrwxr-x 2 peter peter 4096 Jun 27 20:33 .
drwx------. 49 peter peter 4096 Jun 27 20:48 ..
lrwxrwxrwx 1 peter peter 15 Jun 27 20:33 c++ -> /usr/bin/distcc
lrwxrwxrwx 1 peter peter 15 Jun 27 20:33 cc -> /usr/bin/distcc
lrwxrwxrwx 1 peter peter 15 Jun 27 20:33 g++ -> /usr/bin/distcc
lrwxrwxrwx 1 peter peter 15 Jun 27 20:33 gcc -> /usr/bin/distcc

[peter@notepeter distcc]$ cd -
[peter@notepeter SPECS]$ rpmbuild --clean kernel.spec
[peter@notepeter SPECS]$ export PATH=/home/peter/distcc/:$PATH
[peter@notepeter SPECS]$ export DISTCC_HOSTS='localhost 10.0.0.111 10.0.0.121'
[peter@notepeter SPECS]$ export RPM_BUILD_NCPUS=20
[peter@notepeter SPECS]$ time rpmbuild -bb --with baseonly --without debuginfo --target=`uname -m` kernel.spec

real 11m52.751s
user 20m5.209s
sys 6m47.263s

Without distcc:
[peter@notepeter SPECS]$ rpmbuild --clean kernel.spec
[peter@notepeter SPECS]$ time rpmbuild -bb --with baseonly --without debuginfo --target=`uname -m` kernel.spec

real 25m5.938s
user 69m33.427s
sys 10m57.658s

Hardware:

localhost: Core i7 2620M, 8GB RAM, 256 GB SSD, Gigabit LAN
10.0.0.111: Core2 Quad CPU Q8400, 4GB RAM, 500GB SATA, Gigabit LAN
10.0.0.121: Core2 Quad CPU Q8400, 4GB RAM, 500GB SATA, Gigabit LAN

Reference:

Faster compilation with distcc

Thursday, June 23, 2011

It works!

I've just successfully run my code into Kernel 2.6.38.6-27.

# This shows that my kernel_thread is running
[peter@KDPeter ~]$ ps -ef |grep pst
root 1373 2 0 21:09 ? 00:00:00 [pst_daemon2]


I wasn't being able to invoke my system calls from user land because I was using the obsolete _syscall1 macro instead of using syscall().

The original and old documentation that describes system calls and kernel_thread is here.

There will be new documentation soon... :-)

Sunday, June 5, 2011

Peter's "content" contribution 1

It is not Kernel code yet, but I liked it.

I added some lines to Fedora Wiki on Building Custom Kernel:
http://fedoraproject.org/wiki/Docs/CustomKernel#Building_a_Kernel_from_the_source_RPM

As I do not know about how many time this content will be available on the site, I took a screenshot of it. :-)