2015年9月18日 星期五

using tmpfs

We have big memory in nowadays computers, so we can use it to accelerate. But sometimes we have to deal with data which may larger than our memory, then I did a little test whether the tmpfs can larger than our memory size. One can mount a tmpfs bigger than free space, but when it is filled with data, it would cause error. And the answer to deal with data larger than memory is having a big swap space to increasing the free space, which is composed by main memory and swap space.  So the scheme is having big swap space, then you can use tmpfs happily every time, but notice that if the power failed, all your results would be gone.

2015年9月13日 星期日

To change job scheduling policy in Linux.

To change job scheduling policy (job scheduler) in Linux, we can use "chrt" to achieve our goal.

Scheduling policies: 
-b | --batch set policy to SCHED_BATCH
-f | --fifo set policy to SCHED_FIFO
-i | --idle set policy to SCHED_IDLE
-o | --other set policy to SCHED_OTHER
-r | --rr set policy to SCHED_RR (default)

2015年7月24日 星期五

inline vs define

inline通常用於作為小而短的function的修飾字,用來提示compiler這段code很少,可以考慮直接在call它的地方作展開而不用真的作為function,作為function會有functions間跳轉之stack opeartions的overhead,直接在被call的地方展開就不用這些overhead,但會造成code體積變大,或許會造成cahce hit rate下降,所以交由compiler去安排

define的話就是直接展開了

Use tar and pigz to compress things in multithread



install pigz first

and then
tar -c --use-compress-program=pigz -f <tar.filename> <dir_to_zip>

2015年7月22日 星期三

make a big file

fallocate -l 10g filename
只有分配空間

dd if=/dev/zero of=fiename bs=1M count=10240
填零填到10GB後結束

2015年6月14日 星期日

Compile QEMU in ubuntu 14.04

To compile QEMU in ubuntu 14.04, you need to download the needed libraries first
sudo apt-get install zlib1g-dev libglib2.0-dev autoconf automake libtool
If you need to browse the execution screen via a window in host instead of using VNC, you will need to install gtk.
sudo apt-get install build-essential libgtk2.0-dev libvte-dev
Then command ./configure --target-list="What you desire" --enable-gtk.
ex: ./configure --target-list="x86_64-softmmu" --enable-gtk
Then command make, and it will make the files in some directory, ex:"x86_64-softmmmu".
Btw, you can use -j8 to accelerate with 8 threads,' there is no space between 'j' and8', unlike compiling linux kernel.

pthread

除了要#include <pthread.h>
編譯的時候還要下-pthread指令
ex:gcc test.c -o test -pthread

pthread_create(pid,NULL,*void,(*void)arg);
第三項是pthread要跑的function位置,這個function只能接受一個argument傳入,限定為void type,有需求傳入多個arguments時,定一個struct把需要的arguments都包起來。可以回傳值,所以也限定為void*,因此function定義時要定成void* mydeffunc(void* arg)

ex:


void *doit(void *arg);

/*define a struct to wrap needed arguments*/
struct myDefStruct
{
struct sockaddr_in servaddr;
int sockfd;
};

/*call pthread_create的時候*/
/*when call pthread_create*/
struct myDefStruct *myDefPtr;
for ( ; ; ) {
clilen = sizeof(cliaddr);
connfd = accept(listenfd, (__SOCKADDR_ARG) &cliaddr, &clilen);
myDefPtr= (struct myDefStruct*)malloc(sizeof(struct myDefStruct));
myDefPtr->servaddr = cliaddr;
myDefPtr->sockfd = connfd;
pthread_create(&tid, NULL, &doit, (void*)myDefPtr);
 }


/*如何取出void*型別的資訊*/
/*How to retrieve the data in void* type by casting*/
void *doit(void *arg)
{
int sockfd = ((struct myDefStruct*)arg)->sockfd;
struct sockaddr_in servaddr = ((struct myDefStruct*)arg)->servaddr;
...............
}