Wednesday, February 21, 2018

install cross compiled VIM on the target machine

1. cross compiling vim8.0
2. copy vim to /usr/local/bin on the target machine
3. copy .vimrc to target machine
4. copy syntax.vim to /usr/local/share/vim/syntax on the target machine
5. copy ~/.vim/colors/kolor.vim (kolor is my favorite color theme) to the target machine
6. you are good to go

Wednesday, February 14, 2018

Migrate KVM Disk Access from IDE to Virtio

So in order to make the switch from from ide or Sata to virtio, the following steps need to be taken:
Run virsh edit <your_vm_name>. From there, edit the config file and adjust all lines of
<target dev='hda' bus='ide'/>
<target dev='sda' bus='sata'/>
so they look like this
<target dev='vda' bus='virtio'/>
Furthermore, remove all <address type .../> lines so that libvirt can regenerate them appropriately.
Inside the guest, edit /etc/fstab and replace all occurrences of /dev/sdX with /dev/vdX`.
That’s it, now shutdown the machine and start it with an virsh start <your_vm_name> (just a reboot inside the started VM won’t work).

Friday, February 9, 2018

using virt-viewer remote access KVM guest vm

sometime you try to access someone's host machine, which KVM running several vm image, you want to access one of the vm.
one the remote host (name: wawr-builder, ip 10.71.50.228) machine: 
wawr@wawr-builder:~$ virsh list
 Id    Name                           State
----------------------------------------------------
 2     Ubuntu64                       running
 11    av_virtual_3                   running

from my local machine, you can do:
jim@jim-dell-5810:~$ virt-viewer --connect qemu+ssh://wawr@10.71.50.228/system av_virtual_3

With the above, you’ll have to enter your SSH password twice – first to establish the connection to the hypervisor and secondly to establish a tunnel to the VM’s VNC/SPICE session

see original post:
https://www.jethrocarr.com/2012/08/04/virt-viewer-remote-access-tricks/

using perf for profiling

the sample code test_a.c as below:

#include <stdio.h>
#include <stdint.h>
#include <string.h>

void func3(void)
{
   int count = 0;
   char src[100];
   char dst[100];
   for(count=0; count < 0XFF; count++)
       memcpy(src,dst, sizeof(src));

   return;
}

void func2()
{
   int count = 0;
   int64_t s =1;
   for(count=0; count < 0XFF; count++)
   {
       s =s *(count+1);
       func3();
   }

   return;
}

void func4()
{
   int count = 0;
   int64_t s =1;
   for(count=0; count < 0XFF; count++)
   {
       s =s *(count+1);
       func3();
   }

   return;
}
void func1(void)
{
   int count = 0;
   for(count=0; count < 0XFFFF; count++)
       func2();

   return;
}

int main(void)
{
    printf("\n Hello World! \n");
    func1();
    printf("\n step 2! \n");
    func4();
    return 0;
}

#compiling with:
gcc -Wall  test_a.c -g -o test_a

#install perf on ubuntu 14:
 sudo apt-get install linux-tools-common linux-tools-generic linux-tools-`uname -r`

#run test_a:
./test_a

#find test_a pid as 21033 through
ps aux|grep test_a

sudo perf record -p 21033
#ctrl+c to break

sudo perf report
it will show the profiling result as below:


now you know the bottle neck--- func3()
you can also see real time cpu usage by :
sudo perf top

other option -g
perf record -g -p pid
perf report -g 'graph,0.5,caller'

perf report --max-stack=6 --stdio -s parent

ref: http://rhaas.blogspot.co.uk/2012/06/perf-good-bad-ugly.html

Thursday, February 1, 2018

My git quick start

1. setup git diff tool in ~/.gitconfig
[diff]
    tool = p4merge
You can use git difftool to show a single commit.
Say you want to see the commit with the sha1 abc123:
git difftool abc123~1 abc123
(~1 tells git to move to the previous commit, so abc123~1 is the commit before abc123)
If you use this regularly, you could make a custom git command to make it easier:
  1. Create a file called git-show somewhere on your $PATH with the following contents:
    git difftool $1~1 $1
    
  2. Give that file execute permissions:
    chmod +x ~/path/to/git-show
    
  3. Use the command git-show <sha1 or tag or ...>
For the modified files on current branch:
git difftool ./my_modified_file
After git add command (staged files)
git difftool --staged
2. git show current branch name:
git branch
3. git show all remote branches:
git branch --all
4. git switch branch:
git checkout my_branch_name
5. git Add file:
git add ./path/my_file.txt
6. git commit changes:
git commit -m "my change text"
7. git push
git push
8. git log, show change history
git log
9. delete remote branch
git push origin --delete branch_name
10. branch diff
git diff master_git master_git_test
11. Create a local branch test which will use to track remote branch origin/test:
git branch test origin/test

Monday, January 22, 2018

export KVM image to other host

steps for exporting KVM images to other host:
1. copy vm image from /var/lib/libvirt/images on source host to destination host

2. on the source host run:
    virsh dumpxml vmname > my_vm.xml
    edit my_vm.xml, removing mac address or host guid if needed.

3.  on the destination host run:
    virsh define my_vm.xml

4. start the vm:
    virsh start my_vm

Saturday, December 9, 2017

Quick DPDK log

1.DPDK log level
#define RTE_LOG_EMERG 1U /**< System is unusable. */
#define RTE_LOG_ALERT 2U /**< Action must be taken immediately. */
#define RTE_LOG_CRIT 3U /**< Critical conditions. */
#define RTE_LOG_ERR 4U /**< Error conditions. */
#define RTE_LOG_WARNING 5U /**< Warning conditions. */
#define RTE_LOG_NOTICE 6U /**< Normal but significant condition. */
#define RTE_LOG_INFO 7U /**< Informational. */
#define RTE_LOG_DEBUG 8U /**< Debug-level messages. */

rte_set_log_level(); 
eg:rte_set_log_level(RTE_LOG_DEBUG    );  
rte_set_log_level() was called inside rte_eal_init()

2.DPDK log types

defined in "./liblibrte_eal/common/include/rte_log.h":

#define RTE_LOGTYPE_EAL 0x00000001 /**< Log related to eal. */
#define RTE_LOGTYPE_MALLOC 0x00000002 /**< Log related to malloc. */
#define RTE_LOGTYPE_RING 0x00000004 /**< Log related to ring. */
#define RTE_LOGTYPE_MEMPOOL 0x00000008 /**< Log related to mempool. */
#define RTE_LOGTYPE_TIMER 0x00000010 /**< Log related to timers. */
#define RTE_LOGTYPE_PMD 0x00000020 /**< Log related to poll mode driver. */
#define RTE_LOGTYPE_HASH 0x00000040 /**< Log related to hash table. */
#define RTE_LOGTYPE_LPM 0x00000080 /**< Log related to LPM. */
#define RTE_LOGTYPE_KNI 0x00000100 /**< Log related to KNI. */
#define RTE_LOGTYPE_ACL 0x00000200 /**< Log related to ACL. */
#define RTE_LOGTYPE_POWER 0x00000400 /**< Log related to power. */
#define RTE_LOGTYPE_METER 0x00000800 /**< Log related to QoS meter. */
#define RTE_LOGTYPE_SCHED 0x00001000 /**< Log related to QoS port scheduler. */
#define RTE_LOGTYPE_PORT 0x00002000 /**< Log related to port. */
#define RTE_LOGTYPE_TABLE 0x00004000 /**< Log related to table. */
#define RTE_LOGTYPE_PIPELINE 0x00008000 /**< Log related to pipeline. */

/* these log types can be used in an application */
#define RTE_LOGTYPE_USER1 0x01000000 /**< User-defined log type 1. */
#define RTE_LOGTYPE_USER2 0x02000000 /**< User-defined log type 2. */
#define RTE_LOGTYPE_USER3 0x04000000 /**< User-defined log type 3. */
#define RTE_LOGTYPE_USER4 0x08000000 /**< User-defined log type 4. */
#define RTE_LOGTYPE_USER5 0x10000000 /**< User-defined log type 5. */
#define RTE_LOGTYPE_USER6 0x20000000 /**< User-defined log type 6. */
#define RTE_LOGTYPE_USER7 0x40000000 /**< User-defined log type 7. */
#define RTE_LOGTYPE_USER8 0x80000000 /**< User-defined log type 8. */

3. support syslog
configuration in syslog.conf

4. eal command line option
--log-level
eg: ./build/l2fwd -c 3 -n 4  --log-level  8  

5. log example code
  File *my_log = fopen("./my_log.txt", "a");
  rte_openlog_stream(my_log);
  rte_log_set_global_level(RTE_LOG_WARNING);
  RTE_LOG(ERR, USER8, "my test log, id: %d\n", 1688);