顯示具有 Unix 標籤的文章。 顯示所有文章
顯示具有 Unix 標籤的文章。 顯示所有文章

2016年7月20日 星期三

Install Nvidia driver with dkms may help you

DKMS is Dynamic Kernel Module Support, which can help you when you upgrade your kernel with the out come modules.

To install Nvidia Graphic Card driver with DKMS support, install DKMS first.
$ sudo apt-get install dkms
Then install the driver, take NVIDIA-Linux-x86_64-367.35.run for example
$ chmod +x  NVIDIA-Linux-x86_64-367.35.run
$ sudo sh NVIDIA-Linux-x86_64-367.35.run --dkms
When the installation finish
$ dkms status
You can find  "nvidia, 367.35, 3.19.0-64-generic, x86_64: installed".
And you can build all modules for current kernel by
$ dkms autoinstall
And for a specifi kernel by
$ dkms autoinstall -k 4.4.15 
Or install a module for all kernels
$ dkms install -m nvidia -v 367.35 --all

Reference  https://wiki.archlinux.org/index.php/Dynamic_Kernel_Module_Support

2015年10月7日 星期三

SSD optimizing in linux

If your are using ext4 as file system in SSD, you may consider add discard and noatime parameter in /etc/fstab.
discard makes it trim. And noatime makes it not modify the last read time information for file.

And you can change CFS i/o scheduler to noop scheduler.
The approach is to modify the /etc/default/grub, add elevator=noop in kernel parameter.
And do
update-grub
Or if you have many storage devices not only SSD but also motion driven devices, you can  edit or create a file in
/etc/udev/rules.d/60-schedulers.rules
contains
# set noop scheduler for non-rotating disks 
ACTION=="add|change", KERNEL=="sd[a-z]", ATTR{queue/rotational}=="0", ATTR{queue/scheduler}="noop" 
# set cfq scheduler for rotating disks 
ACTION=="add|change", KERNEL=="sd[a-z]", ATTR{queue/rotational}=="1", ATTR{queue/scheduler}="cfq"
And use
cat /sys/block/sda/queue/scheduler
to see the scheduler status.

2015年10月3日 星期六

test disk speed

hdparm -Tt /dev/sda

mount /dev/sda at /test
dd if=/dev/zero of=/test bs=1M count=1024

iotop
iometer
iozone

2015年7月24日 星期五

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日 星期日

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;
...............
}

用gcc編譯c++的檔案

要加-lstdc++指令
ex:gcc test.cc -lstdc++ -o test

unix下include math.h、cmath

在compile的時候要加上-lm的指令
ex: gcc test.c -o test -lm