網頁

2010年5月12日 星期三

VSPM

Linux Highlight (1)

lsmod (list modules)- observe how many modules included in kernel now
         -- display content: module name, size, and used by
 
insmod (insert modules) - mount modules to the kernel
rmmod (remove modules) - unmount modules from the kernel


TODO

HW/SW Co-Design Note

Synthesis 合成  Allocation + Binding + Scheduling

排程(scheduling)、連結(binding)、與分配(allocation)
                          (運算對資源的指定)    (貼標籤)

Problem : what is the goal? (計算)
Architecture : system arch. (表示component 與其連接)
Specification : Possible Mapping

partitioning - optimization
computation < --------------MAPPING--------------- > component

Bi-partitioning :     SW       +          HW
                         processor +       ASIC

Partitioning (Level of Abstraction)
functional - system level - system parameter unknown
structural - RTL level , netlist level

[Reference]
http://www.nioswiki.com/

2010年5月11日 星期二

AWK

Pattern { Action }
     -> If Pattern is true, do Action.

Pattern will exploit "Relational Expression".


[Relational Expression]
>, <, ==, != ...etc.
~(match)
!~(Not Match)


[EXE]
1. awk -f awkfile [file]
2. $ awk 'shell action' [file]
3. script and chmod +x to instruction

[awk action format]
awk 'pattern' file : display rows which match patterns
awk '{action}' file : execute the action in {} for every row
awk 'pattern{action}' file: execute the action for the rows which match patterns

[argument passing]
awk -v varible 'pattern' file
ex: awk -v avar="$svar" '$0 == avar' file

[Reference]
AWK tutorial

Regular Expression

 regular expression

一個 regular expression是被表示於斜線( / / )之間,並且比對是採用 =~ 為操作子

. # 任何單一字元除了 newline
^ # 一行或一字串的起始 [限制字串出現於行首]
$ # 一行或一字串的尾端 [限制字串出現於行末]
* # 零或多個最後的字元 [重複出現 - 可以沒有]
+ # 一或多個最後的字元 [重複出現 - 至少一個]
? # 零或一個最後的字元 [重複0或1個]

Network Simulation Evaluation (NS2)

Wireless new trace format

[Example]
s -t 0.001978125 -Hs 12 -Hd -2 -Ni 12 -Nx 0.00 -Ny 0.00 -Nz 0.00 -Ne -1.000000 -Nl MAC -Nw --- -Ma 0 -Md c000000 -Ms ffff0008 -Mt message -Is 12.42 -Id -1.42 -It message -Il 30 -If 0 -Ii 2 -Iv 32 




1st field - Packet event
s: send
r: recv
d:drop
f: forward

2nd field - Event time 
-t time

3rd field - Next hop info
-Hs: id for this node
-Hd: id to the next hop towards the destination
  -> -1 broadcast
  -> -2 not deployed yet

4th field - Node property
-Ni:
-Nx -Ny -Nz : node's coordinate
Ne: node energy level
Nl: trace level (ex: AGT..etc)
Nw: reason for the event - 
“END” DROP_END_OF_SIMULATION“COL” DROP_MAC_COLLISION“DUP” DROP_MAC_DUPLICATE“ERR” DROP_MAC_PACKET_ERROR“RET” DROP_MAC_RETRY_COUNT_EXCEEDED“STA” DROP_MAC_INVALID_STATE“BSY” DROP_MAC_BUSY“NRTE” DROP_RTR_NO_ROUTE 
“LOOP” DROP_RTR_ROUTE_LOOP 
“TTL” DROP_RTR_TTL 
“TOUT” DROP_RTR_QTIMEOUT 
“CBK” DROP_RTR_MAC_CALLBACK“IFQ” DROP_IFQ_QFULL  
“ARP” DROP_IFQ_ARP_FULL 
“OUT” DROP_OUTSIDE_SUBNET

5th field - Packet info at IP level
-Is: source address.port
-Id: dst address.port
-It: packet type
-Il: packet size
-If: flow id
-Ii: unique id
-Iv: time to live

6th field - Packet info at MAC level
-Ma: duration
-Md: destination's addr
-Ms: source's addr
-Mt: ethernet type


2010年5月7日 星期五

[轉錄] struct的初始化,拷貝及指標成員的使用技巧



struct是C中重要的ADT。但是在一般講C的書中,往往只介紹了struct的定義、順序初始化及位域。
本文將筆者曾經用到的、看到的知識點羅列出來,與大家分享。


為了方便後面的介紹,先定義一個struct類型:
struct User
{
int id; //id
char name[100]; //user name
char *home; //home directory
int passwd; //password
};




1初始化
struct數據有3中初始化方法:順序,C風格及C++風格的亂序。


1)順序
這種方法很常見,在一般的介紹C的書中都有介紹。順序初始化的特點是:按照成員定義的順序,從前到後逐個初始化;允許只初始化部分成員;在被初始化的成員之前,不能有未初始化的成員。
eg:
struct User oneUser = {10, "Lucy", "/home/Lucy"};
初始化之後,oneUser各個成員的值為:
oneUser.id = 10;
oneUser.name = "Lucy";
oneUser.home = "/home/Lucy";
oneUser.passwd = 0;


2)亂序(C風格)
順序的缺陷是必須按成員定義的順序逐個初始化,不能間隔。而亂序的方式則很好的解決了這個問題,因為這種方式是按照成員名進行。
eg:
struct User oneUser = {
.name = "Lucy",
.id = 10,
.home = "/home/Lucy"
};


3)亂序(C++風格)
C++風格的亂序初始化方式跟C風格的一樣,只是它更常用在C++代碼裡。
eg:
struct User oneUser = {
name:"Lucy",
id:10,
home:"/home/Lucy"
};




不論是哪種方式,都允許只初始化部分成員;未被初始化的成員默認為0(指標類型的成員默認為NULL)。兩種亂序初始化方法,即可以用在C代碼中,也可以用在C++代碼中。




2拷貝
struct有兩種拷貝方式,一是直接賦值(=),另一種是用memcpy等庫函數實行內存拷貝。
eg:
struct Temp a, b;
//Set value to members of b
a = b;
memcpy(&a, &b, sizeof(a));
不管是哪種拷貝方式,都是將以&b開始的,大小為sizeof (struct Temp)的內存區域中的數據,簡單地複製到以&a開始的,同樣大小的內存區域。所以,這兩種方式與按成員賦值是等價的:
a.id = b.id;
a.name = b.name;
a.home = b.home;
a.passwd = b.passwd;
由此,我們不難看出,上面兩種拷貝方式都屬於淺拷貝。
           


3指標成員的兩種使用技巧
1)為多個指標成員同時分配內存
如果一個struct中有多個指標類型的成員,我們通常需要為每個指標逐個成員分配內存空間,並在使用完時釋放它們;這樣頻繁調用malloc/free,難免讓人生厭。如果在分配內存之前,每個指標所指向內存區域的大小是確定的,那麼,我們可以為所有指標一次性分配內存區域;並在使用完後,一次性釋放。
eg:
struct Inode
{
int id;


char *file;
int fie_len;


char *path;
int path_len;


char *user;
int user_len;
};


struct Inode data = {
.file_len = X,
.path_len = Y,
.user_len = X
};


//Allocate memory
data.file = (char *)malloc(data.file_len + data.path_len, data.user_len);
data.path = data.file + data.file_len;
data.user = data.path + data .path_len;




//User
       ...




//Free memory
free(data.file);




2)變長數組的另類實現
將下面的定義
struct File
{
TypeA dataA;
          ......
char *data;
TypeN dataN;
};
改成:
struct File
{
TypeA dataA;
          ......      
TypeN dataN;
char data[0];
};
即將指標成員換成大小為0的一維數組,作為struct的最後一個成員(數據結構的可變部分必須作為最後一個成員),有兩個優點:
(1)在緊鄰struct處為data分配內存區域,這樣在分配內存後無須為data賦值;
(2)利用數組的特性,以指標的方式通過越界訪問data數組外的內存區域。
eg:
struct File *pVar = (struct File *)malloc(sizeof(struct File) + DATA_LEN);
strncpy(pVar->data, "Source data", DATA_LEN);