[技術] FreeBSD benchmarks software list

Written on 9:41 上午 by Yu Lai

版權宣告:
轉載自yuwen學弟在築夢BBS(cd.twbbs.org)的個人板《P_yuwen》

autobench : Automating the process of benchmarking a web server
bonnie : Performance Test of Filesystem I/O
bonnie++ : Performance Test of Filesystem I/O
bytebench : The BYTE magazine benchmark suite
dbench : A simulation of the Ziff-Davis netbench benchmark
dbs : A distributed network benchmarking system
forkbomb : System stress testing tool
hpl : High Performance Computing Linpack Benchmark
httperf : A tool for measuring webserver performance
iozone : Performance Test of Sequential File I/O
iozone21 : Performance Test of Sequential File I/O (older version)
lmbench : A system performance measurement tool
nbench : BYTE Magazine's native benchmarks
netperf : Network performance benchmarking package
netpipe : A self-scaling network benchmark
nttcp : A client/server program for testing network performance
pipebench : Pipebench shows current throughput/amount of data through a pipe
pnetmark : Benchmarking tool for Common Language Runtime (CLR)
polygraph : A benchmarking tool for Web proxies
postal : Benchmark SMTP/POP servers
postmark : NetApps file system benchmark
pybench : An extensible benchmark suite for Python
rawio : Test performance of low-level storage devices
scimark2 : A Java benchmark for scientific and numerical computing
scimark2c : An ANSI C version of the SciMark2 benchmark
siege : A http regression testing and benchmarking utility
stream : Synthetic benchmark program that measures sustainable memory bandwidth
tcpblast : Measures the throughput of a tcp connection
tmetric : A bandwidth measurement tool
ttcp : Benchmarking tool for analysing TCP and UDP performance
ubench : Unix Benchmark Utility for CPU(s) and memory
webbench : Simple forking web benchmark
xengine : Reciprocating engine for X
himenobench : Himeno bench benchmark, solves Poisson eq. with Jacobi's method
blogbench : Performance Test of Filesystem I/O
dkftpbench : A FTP benchmark program
iperf : A tool to measure maximum TCP and UDP bandwidth
netio : Network benchmark
nqueens : N-queens benchmark
pathchirp : A measurement tool for available bandwidth estimation
pathload : A measurement tool for network path available bandwidth estimation
pathrate : A measurement tool for capacity estimation of network paths
pear-Benchmark : PEAR framework to benchmark PHP scripts or function calls
raidtest : Test performance of storage devices
unixbench : The BYTE magazine's Public Domain benchmark for UNIX
flops : Floating point benchmark to give your MFLOPS rating
libmicro : Set of utilities to benchmark productivity of system calls
thrulay : Network capacity tester
fhourstones : The Fhourstones Benchmark
gsbench : Benchmarking tool for GNUstep
gtkperf : Measure your system's GTK+ performance
imb : Intel MPI Benchmark
mdtest : A filesystem metadata benchmark utility
p5-Benchmark-Forking : Run benchmarks in separate processes
p5-Benchmark-Stopwatch : Simple timing of stages of your code
rubygem-railsbench : Scripts designed for benchmarking of Rails applications
super-smack : A benchmarking, stress testing, and load generation tool for Databases
sysbench : A modular, cross-platform and multi-threaded benchmark tool
tsung : Multi-protocol distributed load testing tool
sipp : SIP testing tool
xdd : Tool for measuring and characterizing disk subsystem I/O

[技術] 用GPIO實做I2C介面(Bit-Banging)

Written on 12:00 上午 by Yu Lai

最近工作上需要去讀寫I2C介面的IC,
是顆用來量測環境溫度的IC-LM75。
I2C是由2支腳-SDA和SCL所組成的並聯介面,
所有I2C的IC都接在這2支腳上,
I2C相關資訊可以自行到Googlewiki找找。

而我們的板子的CPU本身沒有I2C的介面,
它是透過2支GPIO腳來連接LM75,
所以就必須以軟體的方式來控制GPIO來模擬I2C的Signal,
以上的實做也被稱做Bit-Banging。

照著LM75的Datasheet和網路上相關的資料,
還蠻順利的完成整個Bit-Banging的實做。

以下就是相關實做的source code。

#define SCL_PORT  6
#define SDA_PORT 23

#define ADDR_LM75 0x94 /* 1001 010 x */
#define I2C_DELAY_TIME 10 /* us */

#define ACK 1
#define NO_ACK 0

首先是會用到的#define。
SCL腳位是使用GPIO6,SDA是使用GPIO23。
而LM75使用的Address則是固定的1001配上
板子上A2,A1,A0腳位所接的電位的010當前7個bit。
另外,由於I2C算是比較慢的介面,所以要有個delay time。
void i2c_init(void) {

/* Enable SDA & SCL gpio port */
gpio_enable(SDA_PORT);
gpio_enable(SCL_PORT);

/* Set SDA & SCL to High */
gpio_set(SDA_PORT, __HIGH__);
gpio_set(SCL_PORT, __HIGH__);

}

這裡是將GPIO腳位設定啟動,並將SDA和SCL電位設成HIGH,
完成Initial的動作。
void i2c_start(void) {

/* I2C start sequence is defined as
* a High to Low Transition on the data
* line as the CLK pin is high */

gpio_set(SDA_PORT, __HIGH__); /* SDA: High */
gpio_set(SCL_PORT, __HIGH__); /* SCL: High */
HAL_DELAY_US(I2C_DELAY_TIME);

gpio_set(SDA_PORT, __LOW__); /* SDA: Low */
gpio_set(SCL_PORT, __LOW__); /* SCL: Low */
HAL_DELAY_US(I2C_DELAY_TIME);

}

void i2c_stop(void) {

/* I2C stop sequence is defined as
* data pin is low, then CLK pin is high,
* finally data pin is high. */

gpio_set(SDA_PORT, __LOW__); /* SDA: Low */
gpio_set(SCL_PORT, __HIGH__); /* SCL: High */
gpio_set(SDA_PORT, __HIGH__); /* SDA: High */

}

如source code裡我comment所寫的,
I2C介面溝通的start就是SDA和SCL都是由本來保持的High變成Low所開始。
而stop就是SDA和SCL由High-Low傳遞資料之間變為High持續下去。
void i2c_write(unsigned char data) {

/* An I2C output byte is bits 7-0
* (MSB to LSB). Shift one bit at a time
* to the MDO output, and then clock the
* data to the I2C Slave */

unsigned char i;

/* Write to slave */
for(i = 0; i < 8; i++) {
gpio_set(SDA_PORT, (data&0x80)?1:0); /* Send data bit */
data <<= 1; /* Shift one bit */
gpio_set(SCL_PORT, __HIGH__); /* SCL: High */
HAL_DELAY_US(I2C_DELAY_TIME);
gpio_set(SCL_PORT, __LOW__); /* SCL: Low */
HAL_DELAY_US(I2C_DELAY_TIME);
}

/* Read ACK bit from slave */
gpio_get(SDA_PORT);
gpio_set(SCL_PORT, __HIGH__); /* SCL: High */
HAL_DELAY_US(I2C_DELAY_TIME);
gpio_set(SCL_PORT, __LOW__); /* SCL: Low */
HAL_DELAY_US(I2C_DELAY_TIME);

}

unsigned char i2c_read(unsigned char send_ack) {

unsigned char i, data;

data = 0x00;

/* Read from slave */
for(i = 0; i < 8; i++) {
data <<= 1; /* Shift one bit */
data |= gpio_get(SDA_PORT); /* Read data bit */
gpio_set(SCL_PORT, __HIGH__); /* SCL: High */
HAL_DELAY_US(I2C_DELAY_TIME);
gpio_set(SCL_PORT, __LOW__); /* SCL: Low */
HAL_DELAY_US(I2C_DELAY_TIME);
}

/* Send ACK bit to slave */
if(send_ack)
gpio_set(SDA_PORT, __LOW__); /* SDA: Low */
else
gpio_set(SDA_PORT, __HIGH__); /* SDA: High */
gpio_set(SCL_PORT, __HIGH__); /* SCL: High */
HAL_DELAY_US(I2C_DELAY_TIME);
gpio_set(SCL_PORT, __LOW__); /* SCL: Low */
HAL_DELAY_US(I2C_DELAY_TIME);

return data;

}

接著就是傳送的過程了,
一般I2C都是由高位先寫入(這個不一定,要看Datasheet)。
在寫入時,Master(指CPU)先把SDA設成寫入的bit,
再把SCL依照我們delay的時間來做clock signal的產生(low->high->low->...)。
接著重複上面的動作依序把整個byte都寫入。
寫完整個byte後要讀取一下Slave(指LM75)所回傳的ACK bit。

而在讀取時,一樣先讀入SDA的電位當成data的bit,
再把SCL產生clock signal給Slave,
Slave在收到clock signal後會在SDA上變動電位把資料依序傳出來。
所以同樣的重複上面的動作就可以把組合出整個byte的資料。
當Master讀完byte後也要有回傳ACK的動作來告知是否繼續有下一個byte要讀取。
int get_lm75_temp(void) {

unsigned char msb = 0x00, lsb = 0x00;

i2c_start();
i2c_write(ADDR_LM75); /* Ask LM75 write */
i2c_write(0x00);

i2c_start();

i2c_write(ADDR_LM75+1); /* Ask LM75 read */
msb = i2c_read(ACK);
lsb = i2c_read(NO_ACK);
i2c_stop();

return (msb << 8) | lsb;

}

最後,照著LM75的Datasheet,
Master先傳送address byte給Slave,
Slave在收到address後會先比對自己A2,A1,A0,
若符合再依照address byte的最後一個bit來回應之後的動作,
若為0則是write動作,若為1則是read動作。

所以我們要讀取現在溫度資料時,
CPU先把address byte+0給寫到LM75,告知接下來要寫入register設定,
接著把0x00寫入表示要讀取第0個register,也就是現在的溫度。
再來就是重新開始先寫入address byte+1給LM75,告知要讀取資料。
接著就把溫度資料讀出,共2個byte,所以讀了2次囉。
最後就是把資料組合起來return出去囉。

[技術] 執行檔的檔案格式轉換

Written on 6:04 下午 by Yu Lai

最近為了產生flash的image raw file,
需要將compiler編好的srec格式檔或elf檔式檔進行轉換。
上網找了老半天,原來我們的gnu binutils就有提供這些功能了 ^^。

使用方法如下:
objcopy -I -O

例1: 將srec轉成binary raw file
objcopy -I srec -O binary image.srec image.bin

例2: 將elf32-bigmips轉成binary raw file
objcopy -I elf32-bigmips -O binary image.srec image.bin

[技術] Busybox使用心得

Written on 11:58 上午 by Yu Lai

最近為了產品的新功能以及業務反應的功能,
我重新配置了busybox來達到以上需求。
之前的busybox是由嘉義那邊的同事安裝好打包過來的,
也沒把source code一起帶過來,加上版本也有點舊了,
所以我就安裝新版的當做順便更新囉。

以下是安裝過程中遇到的問題與心得的筆記,
就當做分享與記錄囉。

首先,busybox可以到[http://busybox.net/]下載回來。
然後解開後,如果有需要透過cross-compile來編譯的話,
可以在Makefile裡找到ARCH與CROSS_COMPILE配置它,
另外也可以在Makefile.flags裡直接配置CC、AR和LD等變數。

設定好後直接執行make menuconfig來進行busybox的applet設定囉。
這裡有幾個比較要注意的地方,在Build Options中,我是建議把
Busybox設成Build BusyBox as a static binary (no shared libs)。
雖然比較佔空間,但省下來搞library的時間就夠值得了。
而在設定Login/Password Management Utilities的時候,
為了免去配置glibc的麻煩,最好設置使用busybox自己的password
和shadow文件的功能(Use internal password and group functions
rather than system functions)。
同時要把(login)和(Support for login scripts)打勾,
這樣login才會正常運作。

接著直接使用make和make install就可以把busybox編譯出來啦。
編譯好busybox後並把buxybox copy到rootfs中,
接著要配置好rootfs以配合busybox的運作。
這裡要配置的有etc/inittab、etc/init.d/rcS
以及etc/passwd和etc/shadow(有勾選的話)。

最後就把rootfs包起來燒到target裡就可以啦。

(PS: 以上要配置的檔案可以在網路上找到許多範例,改天再補進來吧)

[技術] Linux的SysRq機制

Written on 1:28 下午 by Yu Lai

最早SysRq是IBM在PC/AT上用來執行低階OS指令的function key。

後來在Linux則是被用來設定kernel提供系統除錯或回復crash的機制。
也就是所謂的"Magic SysRq key"。

以下是透過Linux SysRq機制的操作方法。
首先enable或disable:
# echo 0 > /proc/sys/kernel/sysrq
# echo 1 > /proc/sys/kernel/sysrq

執行magic commands,可以透過echo指令來達成:
# echo b > /proc/sysrq-trigger
以上指令等價於組合鍵Alt + SysRq + B,也就是重新開機。

同理,強制關機可以使用:
# echo o > /proc/sysrq-trigger

[技術] GNU的configure的build、host和target的差別

Written on 2:28 上午 by Yu Lai

相信有編過cross-platform的程式的人,
多多少少會遇到設定這三個參數的時候,
今天正好在編GDB,也就對這3個參數研究了一下。

其實心得可以用一句話來形容這3個:
"讓套件在build下編好,使之在host中執行的target平台版本。"

也就是說:
1. build就是你編這個套件的環境。
通常可以不用設,讓configure自己猜。

2. host就是這個套件的執行環境。
這個通常配cross-compile來編在不同平台執行的套件。
e.g. 要編出在mips-linux下執行的net-snmp套件
./configure --host=mips-linux --prefix=blahblah

3. target是指套件內容的版本或產出物版本。
這個常用於GNU的gcc或binutils等支援不同平台的套件。
e.g. 要編出一個在x86下執行的arm-elf格式的gcc
./configure --host=i686-pc-linux-gnu --target=arm-elf --prefix=blahblah

參考資料: http://www.airs.com/ian/configure/configure_5.html

[技術] C的function call與stack frame心得

Written on 12:00 上午 by Yu Lai

從大二的Program Language中學到stack對於C的function call的實做與功用的概念,
以及各個register的功用,但從未實際地深入了解其中register的變化.
剛好最近T40灌了Ubuntu Linux (x86),就直接寫了些C code,
配合objdump與gdb來trace其中register的變化,於是有了這篇的心得.

首先是複習一下register:
%eip:instruction pointer,用來指到下一個instruction的位置.
%esp:stack pointer,用來指到目前stack的top.
%ebp:Frame pointer,用來指到目前stack frame的開頭.

這次所使用的source code:

#include <stdio.h>
void hi(int a, int b) {
int i = 3;
return;
}
int main(int argc, char *argv[]) {
hi(1, 2);
return 0;
}

我們先透過$ gcc -o test test.c編出test,
然後再透過objdump -d test來觀察disassemble出來的部份:
 08048344 <hi>:
8048344: 55 push %ebp
8048345: 89 e5 mov %esp,%ebp
8048347: 83 ec 10 sub $0x10,%esp
804834a: c7 45 fc 03 00 00 00 movl $0x3,-0x4(%ebp)
8048351: c9 leave
8048352: c3 ret

08048353 <main>:
8048353: 8d 4c 24 04 lea 0x4(%esp),%ecx
8048357: 83 e4 f0 and $0xfffffff0,%esp
804835a: ff 71 fc pushl -0x4(%ecx)
804835d: 55 push %ebp
804835e: 89 e5 mov %esp,%ebp
8048360: 51 push %ecx
8048361: 83 ec 08 sub $0x8,%esp
8048364: c7 44 24 04 02 00 00 movl $0x2,0x4(%esp)
804836b: 00
804836c: c7 04 24 01 00 00 00 movl $0x1,(%esp)
8048373: e8 cc ff ff ff call 8048344 <hi>
8048378: b8 00 00 00 00 mov $0x0,%eax
804837d: 83 c4 08 add $0x8,%esp
8048380: 59 pop %ecx
8048381: 5d pop %ebp
8048382: 8d 61 fc lea -0x4(%ecx),%esp
8048385: c3 ret
8048386: 90 nop

從0x0804835d開始,我們可以看到main()在呼叫hi()時的步驟,
首先先把ebp的值塞進stack中,然後把esp的值塞到ebp裡.
接著把esp減8(因為stack是由高位往低位),再分別把0x2和0x1塞入stack中,
這2個其實就是把hi()所需的變數放入stack中,最後就是call 8048344 <hi>.
接著透過gdb設好breakpoint把stack中的值給印出來.
$ gdb -q test
(gdb) b hi
Breakpoint 1 at 0x804834a
(gdb) r
Starting program: /home/lazyf/test

Breakpoint 1, 0x0804834a in hi ()
Current language: auto; currently asm
(gdb) x/32xw $esp
0xbfb9a074: 0x0804953c 0xbfb9a088 0x08048280 0xb7f95ff4
0xbfb9a084: 0xbfb9a098 0x08048378 0x00000001 0x00000002
0xbfb9a094: 0xbfb9a0b0 0xbfb9a108 0xb7e61450 0xb7fc8ce0
0xbfb9a0a4: 0x080483a0 0xbfb9a108 0xb7e61450 0x00000001
0xbfb9a0b4: 0xbfb9a134 0xbfb9a13c 0xb7facb38 0x00000000
0xbfb9a0c4: 0x00000001 0x00000000 0x080481f5 0xb7f95ff4
0xbfb9a0d4: 0xb7fc8ce0 0x00000000 0xbfb9a108 0x67416081
0xbfb9a0e4: 0xd8282a91 0x00000000 0x00000000 0x00000000
(gdb)

從stack內的值我們可以觀察到,其實call指令所做的動作就是把下一筆instruction的
address(eip)給push進stack裡(0x08048378被放入0xbfb9a088中),接著再把call的address
塞到eip再執行它.

接著到了hi()中,和main()一樣的先把ebp塞入stack中,然後把把esp的值塞到ebp裡.
從這裡我們可以知道,一個function開始時,會先把上一個function的ebp放入stack中,
接著馬上設定自己的ebp.從這裡可以用來確保目前所在function的ebp的值的正確性,
以及保存之後要return時上一個function的ebp的值.

在hi()中把ebp設定好後,它先在stack中allocate了16個byte來使用,接著我們看到了
在ebp-4的位置上被填入了0x3的值,也就是我們在程式中宣告的變數int i = 3;的實做.

最後是leave指令和ret指令所實做出來的return;.在這裡leave指令的操作相當於
把ebp的值放到esp中,然後從stack中pop出值來放到ebp裡,而ret指令的操作則相當於從
stack中pop出值來放到eip裡.也就是說除了eip外,esp和ebp都回到呼叫hi()之前的狀況.
完成hi()的呼叫.

另外,如果hi()有值需要被return時,通常會透過eax register來傳遞.
也就是說在$lt;hi>中的leave指令前會加入mov xxx,%eax指令,
在<main>中call <hi>指令的下一個指令會是mov %eax,yyy指令讀出eax放入yyy中
和mov $0x0,%eax指令把eax清空.

以上就是我從gdb與objdump中所觀察到的一個C的function被呼叫的過程.
如內容有所錯誤,煩請有看到的人不吝賜教.Thanks.

[技術] Ubuntu的dash

Written on 4:39 下午 by Yu Lai

這幾天把舊的T40裝了Ubuntu,用一用發現有些怪怪的地方.
原本可以用的script有些怪怪的,後來查了一下才發現是dash在做怪.
Ubuntu為了加速開機,使用了dash來取代bash成為/bin/sh.
但dash實做的有些不完整,自然就被它給婊到了.

解決方法除了使用指令$ sudo dpkg-reconfigure dash外
也可以用ln手動把/bin/sh -> /bin/dash 改回 /bin/sh -> /bin/bash即可.

[技術] Google Code Prettify

Written on 2:41 上午 by Yu Lai

今天在部落格裡加入了google-code-prettify。
http://code.google.com/p/google-code-prettify/
所以現在在文章中的程式碼,只要透過<pre class="prettyprint">...</pre>的方式,即可得到有highlight效果的呈現。以下是demo:

int main() {
printf("Hello World");
return 0;
}

[閒聊] 網誌改版

Written on 7:24 下午 by Yu Lai

買了Dell E228WFP後才發現,
原本的template已經被我改的只能用在1024x768下,
在寬螢幕下顯示都跑掉了.

於是就改版一下囉, 換了個template,
感覺還不錯 ^^

[技術] 使用Linux的mmap心得

Written on 11:40 上午 by Yu Lai

最近的工作有遇到一個用mmap解決的issue,
讓我了解到mmap原來也可以這樣使用.
以下是使用的心得, 寫下來分享一下.

一般我們在Linux中使用mmap不外乎是用來做IPC的實做,
或是配合driver的file node來操控外部的device,
或者是特殊的需求-加速存取or動態載入.

但我這次遇到的問題居然是空間的需求. 在採用Linux來實做
Embedded System時, 往往會使用Ramdisk或ramfs等技術
來implement出file system來. 而這類的file system有個特點-
它佔memory. 所以在存取較大的檔案時, e.g. image raw file.
若採用傳統malloc出空間再讀進此空間進行操作時, e.g. MD5
checksum, 勢必會遇到記憶不夠的情況.
(PS. 還意外知道原來Linux有oom-killer這東東 XD)

此時我採用了mmap來將原本就在memory裡的file另外對映到
其他記憶體空間中, 把這個當成pointer來操作, 而不用額外花費
真實的memory空間. 以下是相關的source code:

int fd;
struct stat fstat;

fd = open(TMPMD5, O_RDONLY);
stat(TMPMD5, &fstat);
image = mmap(NULL, fstat.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
if(image == MAP_FAILED) {
printf("Error.\n");
close(fd);
return -1;
}

[技術] Linux在x86與non-x86開機程序比較

Written on 1:28 上午 by Yu Lai

感謝jserv在blog中分享, 在IBM developerWorks上的好文章: [Migrating from x86 to PowerPC, Part 2: Anatomy of the Linux boot],探討 GNU/Linux 在不同硬體架構下的開機程序差異,這篇文章有兩張很好的附圖可作為比較:

典型 x86 Linux 啟動程序:



典型 ARM / PowerPC Linux 啟動程序:


[技術] 各家Database分頁實作

Written on 11:25 上午 by Yu Lai

Ref: http://blog.blueshop.com.tw/gpx1981/archive/2007/08/24/52129.aspx

DB2
1.1. SELECT * FROM STUDENT ORDER BY SCORE DESC fetch first 10 rows only
1.2. select * from ( SELECT rownumber() over(ORDER BY SCORE DESC) as row_,
* FROM STUDENT ORDER BY SCORE DESC ) as temp_ where row_ <= 10
2. select * from ( SELECT rownumber() over(ORDER BY SCORE DESC) as row_,
* FROM STUDENT ORDER BY SCORE DESC ) as temp_ where row_ between 11
and 20

Firebird
1. SELECT first 10 * FROM student ORDER BY score DESC
2. SELECT first 10 SKIP 10 * FROM student ORDER BY score DESC
 
HypersonicSQL(HSQL)
1. SELECT TOP 10 * FROM student ORDER BY score DESC
2. SELECT LIMIT 10 10 FROM student ORDER BY score DESC
 
Interbase
1. SELECT * FROM student ORDER BY score DESC ROWS 10
2. SELECT * FROM student ORDER BY score DESC ROWS 10 TO 10
 
MySQL
1. SELECT * FROM student ORDER BY score DESC LIMIT 10
2. SELECT * FROM student ORDER BY score DESC LIMIT 10, 10
 
Oracle
1. select * from ( SELECT * FROM STUDENT ORDER BY SCORE DESC ) where
rownum <= 10
2. select * from ( select err.*, rownum rownum_ from ( SELECT * FROM
errormsg order by seqno) err where rownum <= 20) where rownum_ > 10
 
PostgreSQL
1. SELECT * FROM student ORDER BY score DESC limit 10
2. SELECT * FROM student ORDER BY score DESC limit 10 OFFSET 10
 
SQLServer
1. SELECT top 10 * FROM STUDENT ORDER BY SCORE DESC
 
paged queries not supported
FrontBase, Informix, Ingres, Mckoi, NoArgSQL, Pointbase, Progress, SAPDB,
StandardSQL, Sysbase

[技術] vim的方向鍵問題

Written on 11:25 上午 by Yu Lai

原來我用了那麼久的vi,
今天總算知道怎麼解決ABCD亂跳
與backspace不會刪除的問題。

解決方法:在.vimrc中設定

    set nocompatible
set backspace=2

[閒聊] 我破千了

Written on 6:04 下午 by Yu Lai

就在昨天,
那個倒數的Flash總算跑出正確的3位數了。
也就是正式進入破千的日子了。XD

[閒聊] 一些符號的英文名稱對應

Written on 4:17 下午 by Yu Lai

plus sign (+) 加號

minus sign (-) 減號

forward slash (/) 斜線

backslash (\) 反斜線

percent symbol (%) 百分號

exclamation point symbol (!) 驚嘆號

underscore (_) 底線

equal sign (=) 等號

decimal points (.) 點

semicolon (;) 分號

increment (++) operators 遞增

decrement (--) operators 遞減

( ) Parenthesis 小括號

{ } Braces 大括號

[ ] Brackets 中括號

, Comma 逗號

[技術] 在C中動態配置2維陣列

Written on 5:04 下午 by Yu Lai

在網路上找到的,就記錄下來筆記一下囉。

在C中動態配置一[m][n]的二維陣列
有下列幾種作法

(ㄧ)

int **Array, *pData;
int m,n,i;
Array = (int**)malloc(m*sizeof(int *));
pData = (int*)malloc(m*n*sizeof(int));
for(i = 0; i < m; i++, pData += n)
Array[i] = pData;

只需做兩次malloc,free只要free Array和Array[0]就可以了

(二)
int i;
int **Array;
Array = (int **)malloc(m*sizeof(void *));
for (i = 0; i < m; i++)
Array[i] = (int *)malloc(n*sizeof(int *));

這樣子的配置方式要做很多次的malloc,,並容易造成記憶體碎片化(memory fragment)

(三)
int i;
int **Array, *pData;
Array = (int **)malloc(m*sizeof(int *)+m*n*sizeof(int));
for (i = 0, pData = (int *)(Array+m); i < m; i++, pData += n)
Array[i]=pData;

這樣是最簡便的寫法 只要mallocㄧ次完成,free只要free Array即可

[投資] 權值股

Written on 12:02 上午 by Yu Lai

臺灣證券交易所發行量加權股價指數前50大成分股暨市值比重
排行

證券名稱

市值佔 大盤比重

排行

證券名稱

市值佔 大盤比重
1 2330 台積電 7.984%
2 2317 鴻海 6.193%
3 6505 台塑化 4.372%
4 1303 南亞 3.195%
5 2882 國泰金 3.056%
6 1301 臺塑 2.540%
7 2002 中鋼 2.437%
8 2409 友達 2.419%
9 1326 臺化 2.235%
10 2454 聯發科 2.136%
11 2357 華碩 1.760%
12 2498 宏達電 1.673%
13 3009 奇美電 1.505%
14 3481 群創 1.470%
15 2303 聯電 1.298%
16 2308 台達電 1.139%
17 2881 富邦金 1.083%
18 2886 兆豐金 1.075%
19 3045 台灣大 1.060%
20 2354 鴻準 0.976%
21 2891 中信金 0.945%
22 2325 矽品 0.872%
23 2311 日月光 0.863%
24 2885 元大金 0.857%
25 1402 遠紡 0.831%
26 2382 廣達 0.780%
27 4904 遠傳 0.774%
28 1216 統一 0.761%
29 2353 宏碁 0.744%
30 1101 台泥 0.712%
31 2892 第一金 0.711%
32 2883 開發金 0.684%
33 2324 仁寶 0.669%
34 8046 南電 0.666%
35 1102 亞泥 0.632%
36 2880 華南金 0.620%
37 2301 光寶科 0.601%
38 2888 新光金 0.546%
39 5854 合庫 0.536%
40 2474 可成 0.499%
41 2475 華映 0.465%
42 2603 長榮 0.435%
43 2347 聯強 0.428%
44 2890 永豐金 0.420%
45 2408 南科 0.419%
46 3474 華亞科 0.418%
47 2448 晶電 0.417%
48 2801 彰銀 0.416%
49 3231 緯創 0.406%
50 1722 台肥 0.380%

[閒聊] 小改版

Written on 11:22 上午 by Yu Lai

在看了王小明的征服藍星,
我也加了點新東東在右邊囉。XD
就當做是些資料的統計吧。 *^^*

[技術] 802.3ad

Written on 6:49 下午 by Yu Lai

Ref: 酷學園 & PCDVD

NTEL 叫 LINK AGGREGATION
CISCO 叫 FAST ETHERCHANNEL
3COM 叫 PORT TRUNKING
現在國際標準叫 IEEE802.3ad
白話一點叫併頻寬或頻寬聚集
一般用在解決伺服器網路瓶頸或交換器與交換器連接

從硬體的角度來看

INTEL 伺服器等級的網路卡可以設定以下3個模式

1.AFT(Adapter Fault Tolerance)(希望沒有拼錯好像怪怪的)
假設有兩張網卡時一張是PRIMARY另一張是STANDBY
這時候流量只在PRIMARY上跑
當PRIMARY掛掉時STANDBY會自動啟用接手變成PRIMARY
如果原來PRIMARY恢復時會自動變成STANDBY
(因為大家ALB和ALA都包含AFT,所以基本上沒人會單獨設AFT運作)

2.ALB(Adapter Load Balance)
假設將兩張網路卡設成ALB時
進來流量為100M出去流量為200M
這時候無論接往何種交換器或集線器都可支援
同時間ALB包含容錯功能如果一張網卡故障另一張依然運作
現在INTEL可以做到8張網卡併頻寬

3.ALA(Adapter Link Aggregation)
假設將兩張網路卡設成ALA時
進來流量為200M出去流量為200M
這時候需接往支援LINK AGGREGATION的交換器
同時間ALA包含容錯功能如果一張網卡故障另一張依然運作
現在INTEL可以做到8張網卡併頻寬

Intel 的 teaming 叫做 ians Intel(R) Advanced Network Services

intel 分成

1、Adapter Fault Tolerance (AFT)
2、Switch Fault Tolerance (SFT)
3、Adaptive Load Balancing (ALB)
4、Intel Link Aggregation, Cisco*'s Fast EtherChannel* Technology or static 802.3ad (FEC or FEC/LA/802.3ad: static)

intel pro 若只使用 windows 系統提供的驅動程式的話 , 其 teaming mode 只能支援到 RLB , 若要完全使用其他 teaming mode (LA , Cisco FEC ..)的功能 , 除了需要有支援 802.3ad 規格的 switch 配合外 , 還需要安裝 Intel ANS !!

在使用2張 INTEL SERVER ADAPTER 以上時
正常來說會選 ALB 或 ALA
不管選 ALB 或 ALA 這時 AFT 是一定有作用

當你的交換器是一般或早期的請選 ALB
這時主網卡跑雙工其他子網卡跑單工
系統以主網卡為主
假設四張的話就是進去 100 出來 400

當你的交換器支援 FAST ETHERCHANNEL 或 LINK AGGREGATION 或 802.3ad
這時可以啟用 ALA
所有網卡都跑全雙工
系統以代表所有實體網卡的虛擬網卡為主
假設有四張時就是進去 400 出來 400

[技術] Wireshark抓vlan tag資訊整理

Written on 11:05 上午 by Yu Lai

使用Wireshark時居然發生抓不到VLAN的資訊,
上網找了一下果然是有問題的。
以下為找到的ref: http://blog.rogerz.cn/archives/553

某一些網卡驅動默認會在接收封包的時候過濾vlan tag,使得用wireshark抓到的封包中不含vlan tag,此時需要通過修改註冊表讓驅動保留vlan tag。

對於Intel PRO/1000或PRO/100網卡,需要將註冊表HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\00xx下(以DriverDesc來判定xx值為何)的MonitorModeEnabled改為1,如果不存在則新建這麼一個dword鍵。

對於Broadcom Giga網卡,需要在註冊表裡增加一項PreserveVlanInfoInRxPacket=1,類型為string。位置與TxCoalescingTicks相同,後者可以在HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet下搜索到。

修改後需要重啟機器讓它生效。這個修改辦法是在UniCA User Manual中看到的,較新的網卡驅動裡都支持這個設置,原文如下:

Intel PRO/1000 or PRO/100 Ethernet controller which are used in e.g. IBM Notebooks (T40 series and others) do not forward VLAN tags to the upper layers; By default, Intel adapters strip the VLAN tag before passing it up the stack. If you need to see the tag you need to use these driver versions: PRO/100 6.x or 7.x or later base driver, PRO/1000 7.2.17.803 (plain 7.2.17 does not have this feature). To enable, you must go into the registry and either add a registry dword and value (for e100) or change the value of the registry key (for e1000). The registry dword is MonitorModeEnabled (for both). It should be placed at HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Class{4D36E972-E325-11CE-BFC1-08002BE10318}\00xx where xx is the instance of the network adapter that you need to see tags on. (Check by opening and viewing the name of the adapter). It should be set to read: MonitorModeEnabled= 1. Note: ControlSet001 may need to be CurrentControlSet or another 00x number

For Broadcom 570x Gigabit adapters (for example in Dell systems); Add a registry key under HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet to cause the driver not to strip the 802.1Q VLAN header. In order to set that key, you need to find the right instance of the driver in Registry Editor and set that key for it.

* Run the Registry Editor (regedt32).
* Search for 「TxCoalescingTicks」 under "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet" and ensure this is the only instance that you have.
* Right-click on the instance number (eg. 0008) and add a new string value.
* Enter 「PreserveVlanInfoInRxPacket」 and give it the value 「1〞.
* Save and Reboot
* You may need to install a recent driver (version 8.27) to make this setting effective

[技術] Linux MTD Driver Reference

Written on 9:52 上午 by Yu Lai

以下是幾個有關MTD的Reference,記錄下來當成筆記一下。

MTD NAND Driver Programming Interface
Thomas Gleixner
http://www.linux-mtd.infradead.org/tech/mtdnand/book1.html

HOW TO USE MTD/JFFS2 UNDER µClinux
Patrice KADIONIK, Professor Assistant at the ENSEIRB School of Electrical Engineering, Telecommunication, and Computer Science
http://uuu.enseirb.fr/~kadionik/embedded/uclinux/mtd/howto_mtd.html

Find your Root File System with MTD
http://www.ucdot.org/article.pl?sid=03/01/11/1049210&mode=thread