Wednesday, May 02, 2007

Programming pthread under different Linux distributions

This time a bit far from FreeBSD.
I've noticed that using exit() function in thread may cause different action. Under Ubuntu it kill not only running thread but also a parent process. Under monoppix it kills only a thread which called this function.
Strange behaviour, but how pthread works? In fact creating threads in pthread create a new process like fork() function, and using exit() may work like exiting process which called it or killing also a parent process for thread.

Labels:

Friday, January 05, 2007

Less terminals more memory

How to get more free memory on router box? Answer is easy: remove that things which isn't important and go on. This is an easy and effective hack. Usually we don't need all 8 virtual terminals switched by pressing Alt+F1 to F8. These terminals occupy about 800k per terminal, we have 8 terminals so 6,4MB is taken by not so important processes.
How to do it? Let see into the file "/etc/ttys".

# Virtual terminals
ttyv1 "/usr/libexec/getty Pc" cons25 on secure
ttyv2 "/usr/libexec/getty Pc" cons25 on secure
ttyv3 "/usr/libexec/getty Pc" cons25 on secure
ttyv4 "/usr/libexec/getty Pc" cons25 on secure
ttyv5 "/usr/libexec/getty Pc" cons25 on secure
ttyv6 "/usr/libexec/getty Pc" cons25 on secure
ttyv7 "/usr/libexec/getty Pc" cons25 on secure
ttyv8 "/usr/X11R6/bin/xdm -nodaemon" xterm off secure

In the middle of beginning there are several lines. To turn off some of theses terminals we will comment corresponding lines by putting "#" at beginning of each line. I left only two first terminals working and get about 5MB of memory to use it in another way.

Labels: , , , ,

Monday, September 04, 2006

Faster booting FreeBSD

Time when system is fully usable depends on:

  1. How long POST will end it's self tests

  2. When bootloader begin loading system

  3. How long system will be loading (kernel and modules load up)

  4. How long various services will be starting


Good router/gateway should be usable as fast as possible after turning it on.
The first point depends on hardware and BIOS. Some BIOSES have features defining type of POST for example fast, full, etc. We won't discuss it this time.
Kernel and modules - it's clear that smaller kernel and fewer modules make all system faster, not only when it's booting. This is story for another time. Similar to kernel, fewer services - faster booting.
The bootloader, especially boot0 can be easily tuned using boot0cfg:
boot0cfg -Bv -b /boot/boot0 -t ticks /dev/ad0
Ticks means quantity of impulses in RTC clock, it's about 18.2/s
Next thing wich can delay booting process is so called "beastie menu" or loader. It's next piece of code run after boot0. Loader directly loads kernel with selected parameters. Configuration file /boot/loader.conf includes many options, but we change only one value:
autoboot_delay="10"
It's in seconds let's change it to smaller piece of time. We can also disable beastie menu by setting this value:
beastie_disable="YES"

Saturday, September 02, 2006

Silent system: No beeping boot0 and console

Beeping can be stressful. Starting computer emits couple of beeps, some of them can be avoided. In fact computer working as router/gateway don't need to inform everyone that it is starting. The first beep we will deactivate, appears when boot0 loads. Let's look into one interesting file /usr/src/sys/boot/i386/boot0/boot0.S. There are two key lines of code:
204: movb $ASCII_BEL,%al # Signal
205: callw putchr # beep

We can remove them without any fear that something will gone wrong.
Next compile the source using make command:
# make
In order Copy the 512 byte long file (boot0) to /boot
And install on disk using boot0cfg as follows:
# boot0cfg -Bv -b /boot/boot0 /dev/ad0
Where ad0 means disk where the changed bootloader will be installed.
boot0cfg manual warns about problems with geom when installing on mounted drive, I didn't have such problems and I don't have to temporarily disable this geom feature as described in manual.

Next beeping thing in FreeBSD is console. Personally I don't like when it beeps, so I removed this feature permanently.
Let's add one line in /etc/rc.conf:
allscreens_kbdflags="-b off"
Next time system is started console will not beep anymore. We can disable beeping temporarily by using this command:
# kbdcontrol -b off

Labels: , ,

Friday, September 01, 2006

How to change files in /usr/local/etc on nanoBSD

This is a major problem when we install software from packages or ports on nanobsd system. Root partition is readonly. Third party software keep their configuration files under /usr/local/etc Only /etc can be changed during runtime.
This custom function used after installing ports/packages during build solve this problem:

#
# Create symlinks in /usr/local/etc to /etc due to readonly filesystem in
# /usr
#
cust_fix_usr_local() (
mkdir ${NANO_WORLDDIR}/etc/uletc
cp -R ${NANO_WORLDDIR}/usr/local/etc/* ${NANO_WORLDDIR}/etc/uletc
rm -r ${NANO_WORLDDIR}/usr/local/etc
#rmdir ${NANO_WORLDDIR}/usr/locla/etc
chroot ${NANO_WORLDDIR} sh -c 'ln -s /etc/uletc /usr/local/etc'
)