Entries Tagged as ''

Extreme Programing

Just browse my favorite book Thinking in C++. In the preface, it mentioned XP (Extreme Programing) approach.

What’s Extreme Programing

Probably only someone who has experienced XP and non-XP can tell us what’s the benefits. I am the one of them. I used to work for two companies, which have different opinions according to XP. The first company adopted XP approach. When new feature has documented and begin coding, test cases will be documented as well and prototype is shown for the customers. Any enhancement and improvement will be easily implemented in the circle of three guys. The life circle of development will be short.

The second company didn’t adopt XP approach. Here is an example which will be interesting. Developer lead make a function specification. (I believe he just imagine what the feature looks like and put them to the document). Developer began to coding followed the function spec. After coding done, he/she check in branch build. QA begin to test after build is ready. There are bunch of bugs need to be fixed, some of them are just because QA has different opinion of how the feature works. Argument is obviously. Finally, the new feature can be released. However, the sales engineers, who represent the customers, are not satisfied with some part of new feature. So, again, customer requirement will be sent back. After argument, developers have to make changes for function spec and redo coding. That is the story. Normally, the life circle of development of one feature will be triple time of the first company. The following is a simple chart that you can compare.

two_company_compare.jpg

Smart company can do the same thing by using few people and few cost. Other company, although very diligent, cannot achieve good result. That’s the benefit of XP.

COUNTING SET BITS IN A BYTE

Probably to count set bits in a byte or in 4 bytes will be most frequent asked question in the interview. Fortunately, I found four solution.

  1. The mask and shift approach.
  2. The Brian Kernighan approach.
  3. The index into an array approach.
  4. The MIT HACKMEM approach.

Make and Shift

unsigned char countbits_shift_method (unsigned char b)
{
unsigned char mask, count;

for (count = 0, mask = 0×80; mask != 0; mask >>= 1)
{
if (b & mask)
count++;
}

return (count);
}

Brian Kernighan

unsigned char countbits_bk_method (unsigned char b)
{
unsigned char count;

for (count = 0; b != 0; count++)
{
b &= b – 1; // this clears the LSB-most set bit
}

return (count);
}

Index into an Array

unsigned char parity_array [256] =
{ 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, … };
// Note that you need to fill-in this array

unsigned char countbits_array_method (unsigned char b)
{
return (parity_array [b]);
}

MIT Hack Memo

int BitCount(unsigned int u)

{
unsigned int uCount;

uCount = u
- ((u >> 1) & 033333333333)
- ((u >> 2) & 011111111111);
return
((uCount + (uCount >> 3))
& 030707070707) % 63;

}

Network Installation Linux (5) – KickStart

KickStart configuration is actually instruction to guide kernel to complete the process of the installation. Normally, we will put ks.cfg to somewhere located on NFS server. The exact path is indicated by PXE default configuration,  /tftpboot/linux-install/pxelinux.cfg/defaul, or special configuration you came up with. The whole process of network installation will be:

  1. The client asks IP address from DHCP server.
  2. The DHCP server distribute one IP to the client, at the same time, indicate PXE parameters to the client, especially pxelinux.0.
  3. The client get pxelinux.0 via TFTP.
  4. After user interact with boot.msg, the client will get vmlinuz and initrd.img followed the instruction of pxelinux.cfg/default.
  5. After kernel and driver installation, the client will follow the instruction of ks.cfg to complete the whole process.

The following is my ks.cfg, just for your reference.

# Kickstart file automatically generated by anaconda.

install
nfs –server=10.2.0.78 –dir=/mnt/fc7
### Choose the most popular language in the world.
lang en_US.UTF-8
langsupport –default=en_US.UTF-8 en_US.UTF-8 en_US en en_US.UTF-8 en_US en
keyboard us
xconfig –card “VESA driver (generic)” –videoram 16384 –hsync 30-83 –vsync 56-75 –resolution 800×600 –depth 16
### Tell it what the ethernet cards settings should be
network –device eth0 –bootproto dhcp –hostname localhost
network –device eth1 –bootproto dhcp
rootpw –iscrypted $1$bvL7zhTO$EtXKneiWhfvXJ3DSUq3tb0
firewall –disabled
selinux –disabled
authconfig –enableshadow –enablemd5
timezone America
###used to be lilo, but now is bootloader
bootloader –location=mbr –driveorder=sda
# The following is the partition information you requested
# Note that any partitions you deleted are not expressed
# here so unless you clear all partitions first, this is
# not guaranteed to work
clearpart –linux –drives=sda
part /boot –fstype ext3 –size=100 –ondisk=sda
part pv.4 –size=0 –grow –ondisk=sda
volgroup VolGroup00 –pesize=32768 pv.4
logvol swap –fstype swap –name=LogVol01 –vgname=VolGroup00 –size=1000 –grow
#logvol swap –fstype swap –name=LogVol01 –vgname=VolGroup00 –size=1000 –grow –maxsize=6656
logvol / –fstype ext3 –name=LogVol00 –vgname=VolGroup00 –size=1024 –grow

%packages
@ dialup
@ java
kernel-smp-devel
kernel-smp
grub
e2fsprogs
lvm2

%post

Network Installation Linux (4) – PXE

PXE (Preboot Execution Environment) is a server which allows clients to boot from NIC (Network Interface Card). Since 1998, most of NICs and BIOS support PXE agents, especially for Intel’s. For PXE Linux, it works with DHCP and TFTP, which I have mentioned in the past. This time, I will say something about how to set up PXE.

We need pxeos, which is command with bunch of options, or “system-config-netboot”, which is GUI configuration tool. Most of linux distributions have these package. However, if you don’t have it, you can simply “yum -y install system-config-netboot“. After installation, you will find linux-install directory under /tftpboot. Under that directory, you will observe sub-directories and file.

[root@henrydu linux-install]# ls -ltr
total 36
-rw-r–r– 1 root root 13100 2005-12-19 17:03 pxelinux.0
drwxr-xr-x 2 root root 4096 2007-11-08 14:41 msgs
drwxr-xr-x 2 root root 4096 2007-11-08 15:14 pxelinux.cfg

pxelinux.0 is a binary file which renders several basic message to the client screen at the beginning and also follows configuration file under ./pexlinux.cfg to get environment information. There is a default configuration.

default fc7
prompt 1
timeout 5
display boot.msg
F1 boot.msg
F2 options.msg
F3 general.msg
F4 param.msg
F5 rescue.msg

label rhel5
kernel /rhel5/vmlinuz
append ksdevice=eth0 ks=nfs:10.2.0.78:/mnt/ks/rhel5.cfg initrd=/rhel5/initrd.img

label fc7
kernel /fc7/vmlinuz
append ksdevice=eth0 ks=nfs:10.2.0.78:/mnt/ks/fc7.cfg initrd=/fc7/initrd.img

The root directory of /fc7/vmlinuz and /fc7/initrd.img is /tftpboot/linux-boot/. You can copy two files, which is located in Linux distributed image, to that directory, one is vmlinuz and the other is initrd.img. Also, you need to specify kickstart directory, which is located on NFS server.

Network Installation Linux (3) – TFTP Server

TFTP is a trivial FTP, which is special for transfer images via UDP. If you don’t have it, you can simply “yum -y install tftp“. If you have already installed xined, then it comes with tftpd.

First, you need to configure tftp.

vi /etc/xinetd.d/tftp
service tftp
{
disable = no
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -s -c /tftpboot
per_source = 11
cps = 100 2
flags = IPv4
}

To enable TFTP server, set “disable = no”. The default “server_args” is “-s”, which means you can download images from the server. But I like add “-c” option, which means you can upload images to the server as well. The TFTP root directory is “/tftpboot”. All image files will be stored under this directory.

Then, you can reboot xined

service xined restart

Network Installation Linux (2) – DHCP Server

Make dhcpd start as default

Since request-installed box need IP address, the dhcpd deamon should be up every time when server is up. If we don’t want to start X, then we can go to /etc/inittab to change id:5:initdefault: to id:3:initdefault:. Then, we can go to /etc/rc3.d to double check. If there is a file named S65dhcpd (which means start deamon when reboot), then we are done. If there is a “K” at the beginning of the “dhcpd” file (For example, K65dhcpd, which means kill deamon when reboot), then we have to change file from “K” to “S”.

Change dhcpd.conf for PXELINUX purpose

After DHCP Pool statement, we need to add some configuration for PXELINUX clients. When they get IP address, they will try to get pxelinux default configuration.

allow booting; allow bootp; class “pxeclients” { match if substring(option vendor-class-identifier, 0, 9) = “PXEClient”; next-server 10.2.0.78; filename “linux-install/pxelinux.0″; }

next-server” is actually TFTP server. I will mention that on next article. The TFTP server root is /tftpboot/, so the pxelinux.0 is stored in /tftpboot/linux-install/pxelinux.0. PXELINUX will take MAC address as substring to match first.

ddns-update-style interim;
ignore client-updates;

allow booting;
allow bootp;
class “pxeclients” {
match if substring(option vendor-class-identifier, 0, 9) = “PXEClient”;
next-server 192.168.50.22;
filename “linux-install/pxelinux.0″;
}

subnet 192.168.50.0 netmask 255.255.255.0 {

# — default gateway
option routers 192.168.50.1;
option subnet-mask 255.255.255.0;

# option nis-domain “lab.com”;
# option domain-name “lab.com”;
option domain-name-servers 172.16.100.100;

option time-offset -18000; # Eastern Standard Time
# option ntp-servers 192.168.1.1;
# option netbios-name-servers 192.168.1.1;
# — Selects point-to-point node (default is hybrid). Don’t change this unless
# — you understand Netbios very well
# option netbios-node-type 2;

range dynamic-bootp 192.168.50.2 192.168.50.254;
default-lease-time 21600;
max-lease-time 43200;

}

Start DHCP service

/etc/init.d/dhcpd start

Network Installation Linux (1) – Overall

Without installation DVD, we can use bootable USB key to install Linux. However, if we try to install same version of Linux to several boxes, we don’t need to install them one by one. The solution is to install from the network. To do the job, we need to prepare several things. Of course, I assume you already have NIC with PXE agent and Boot from NIC option in the BIOS.

I will put some words on each of them at the upcoming blogs.

10 Years Working Experience, Have to Quit?

I read a news about Huawei, the company has already been the biggest Telecom equipment vendor in China. They even tried to compete with Cisco in the markets of North American. Cisco sued Huawei in 2002, which actually made Huawei more famous.

Well, the story is really funny. China government has issued Labor Contract Regulation and will be effective in Jan 1st 2008. Some items in the regulation said that, if one employee has worked for the company for 10 years or more, he/she should get unlimited date contract with the company. For Huawei’s point of view, if that take effect, they cannot easily make some employees, who worked more than 10 years for Huawei, and who somehow kind of “lazy”, to be unemployment.

So, Mr. Ren, the spirit leader of Huawei, issued the one company policy.  Those who have worked for Huawei for almost 10 years, have to quit and compete with the same position with others. There are 7000 employees need to do that in terms of the company policy. Of course, everyone will get some compensation.

Well, this is Huawei, the legend of Huawei.   If you are interesting in this company, just google it. You will find a lot of more interesting story.