/*nice*/
顯示具有 Linux 標籤的文章。 顯示所有文章
顯示具有 Linux 標籤的文章。 顯示所有文章

2023年12月11日 星期一

smp_affinity, taskset and isolcpus 指定CPU方法

  • smp_affinity
    MV31是走USB介面,用lsusb查看,是用xhci_hcd
    $ lsusb
    Bus 004 Device 002: ID 1e2d:00b3 Gemalto M2M GmbH Cinterion PID 0x00B3 USB Mobile Broadband
    Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
    
    $ lsusb -t
    /:  Bus 04.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/8p, 20000M/x2
        |__ Port 2: Dev 2, If 0, Class=Communications, Driver=cdc_mbim, 5000M
        |__ Port 2: Dev 2, If 1, Class=CDC Data, Driver=cdc_mbim, 5000M
        |__ Port 2: Dev 2, If 2, Class=Vendor Specific Class, Driver=option, 5000M
        |__ Port 2: Dev 2, If 3, Class=Vendor Specific Class, Driver=, 5000M
        |__ Port 2: Dev 2, If 4, Class=Vendor Specific Class, Driver=option, 5000M
        |__ Port 2: Dev 2, If 5, Class=Vendor Specific Class, Driver=option, 5000M
    
    

    查下中斷表是否有xhci_hcd
    $ cat /proc/interrupts | grep -i xhci_hcd
     130:          0          0          0          0          0          0          0          0          0          0          0          0          0          0          0          0  IR-PCI-MSI-0000:00:0d.0    0-edge      xhci_hcd
     132:          0        537          0          0          0          0          0          0          0          0          0          0          0      19774          0          0  IR-PCI-MSI-0000:00:14.0    0-edge      xhci_hcd
    

    中斷號碼132看起來在CPU13用得比較多(19774)
    用ping再度確認下
    CPU13變高到25209
    $ ping -I wwan0 8.8.8.8
    PING 8.8.8.8 (8.8.8.8) from 10.238.24.92 wwan0: 56(84) bytes of data.
    64 bytes from 8.8.8.8: icmp_seq=1 ttl=55 time=41.2 ms
    64 bytes from 8.8.8.8: icmp_seq=2 ttl=55 time=23.8 ms
    64 bytes from 8.8.8.8: icmp_seq=3 ttl=55 time=37.3 ms
    ^C
    --- 8.8.8.8 ping statistics ---
    3 packets transmitted, 3 received, 0% packet loss, time 2003ms
    rtt min/avg/max/mdev = 23.798/34.110/41.199/7.460 ms
    
    $ cat /proc/interrupts | grep -i xhci_hcd
     130:          0          0          0          0          0          0          0          0          0          0          0          0          0          0          0          0  IR-PCI-MSI-0000:00:0d.0    0-edge      xhci_hcd
     132:          0        537          0          0          0          0          0          0          0          0          0          0          0      25209          0          0  IR-PCI-MSI-0000:00:14.0    0-edge      xhci_hcd
    

    系統用哪顆CPU來處理這個中斷
    $ cat /proc/irq/132/smp_affinity
    2020
    

    試著改變到CPU14和CPU15,並用PING再測試
    # echo "c000" > /proc/irq/132/smp_affinity
    
    # cat /proc/irq/132/smp_affinity
    c000
    
    $ cat /proc/interrupts | grep -i xhci_hcd
     130:          0          0          0          0          0          0          0          0          0          0          0          0          0          0          0          0  IR-PCI-MSI-0000:00:0d.0    0-edge      xhci_hcd
     132:          0        537          0          0          0          0          0          0          0          0          0          0          0      35409       1373          0  IR-PCI-MSI-0000:00:14.0    0-edge      xhci_hcd
    

    queues
    $ cd /sys/class/net/wwan0/queues
    $ tree -L 1
    .
    ├── rx-0
    └── tx-0
    
    $ cat rx-0/rps_cpus
    0000  //這個值也能調整來提高效率
    

  • taskset
    Install:
    $ sudo apt-get install util-linux
    

    查訊程式用哪顆CPU處理
    $ taskset -p PID
    $ taskset -p 6151
    pid 6151's current affinity mask: ffff
    

    指定程式用哪顆CPU處理
    $ taskset 8 /usr/local/bin/my_programer
    or
    $ taskset -p CPU_number PID
    
    $ taskset -p c000 6195
    pid 6195's current affinity mask: ffff
    pid 6195's new affinity mask: c000
    


  • isolcpus尚末使用


ref:
1. [转]再转载一篇关于SMP IRQ affinity的好文章(包含RPS/RFS)
2. CPU Affinity taskset (cpuset)
3. 在 Linux 中以特定的 CPU 核心執行程式

2022年11月28日 星期一

Arm compiler

编译器命名规则

Linaro的64bitc
linaro support 64bit

也有 aarch64--musl 和 aarch64--uclibc

Linaro的32bit好像只到7.5就沒更新了, 接下來都是64bit
linaro support 32bit

arm-none-eabi-gcc
arm-none-eabi-gcc

aarch64-none-linux-gnu (Android)
aarch64-none-linux-gnu

2021年11月1日 星期一

vimrc

https://github.com/cposture/my-vim/blob/master/.vimrc


環境: (xubuntu 20.04) vim8.1 + Terminator + tmux 3.0a

目前的設定,基本上都是拷貝上面的
(注意這個 g:ycm_global_ycm_extra_conf)
"設置空格和 tab 字符可見
setlocal list
set listchars=tab:>~,trail:.
"set nocompatible,關閉兼容模式,發揮vim擴展功能
set nocompatible
"保存全局变量
set viminfo+=!
"设置文件格式为unix,这样换行不会带 ^M
set fileformat=unix

"############################################### apt-get        ################################
" ctags
"sudo apt-get install exuberant-ctags
" ag (silversearcher-ag)
" sudo apt-get install silversearcher-ag
"############################################### begin vim-plug ################################
call plug#begin()
"CurtineIncSw.vim 插件,用于头文件源文件来回切换
Plug 'ericcurtin/CurtineIncSw.vim'
"YouCompleteMe 插件,用于补全和提示
Plug 'ycm-core/YouCompleteMe', {'on': []}
"YouCompleteMe 辅助插件,生成项目 .ycm_extra_conf.py 文件
Plug 'rdnetto/YCM-Generator', { 'branch': 'stable'}
"类/方法/变量相关侧边栏,依赖 ctags
Plug 'https://github.com/majutsushi/tagbar.git'
" 括号自动补全
"Plug 'jiangmiao/auto-pairs'
"状态栏
Plug 'vim-airline/vim-airline'
"开箱即用型的语法高亮包,支持大部分前端后台语言
Plug 'sheerun/vim-polyglot'
"树形目录插件,延迟加载
Plug 'scrooloose/nerdtree', {'on': 'NERDTreeToggle'}
"配对标签跳转
Plug 'andymass/vim-matchup'
"python PEP8标准自动缩进,在函数多行定义下有用
Plug 'Vimjas/vim-python-pep8-indent'
"python 折叠
Plug 'tmhedberg/SimpylFold'
" vim 中文版文档
Plug 'yianwillis/vimcdoc'
"nerdtree 辅助插件,展示文件状态
Plug 'Xuyuanp/nerdtree-git-plugin'
"查看和切换缓冲区
Plug 'bsdelf/bufferhint'
" ycm 辅助
Plug 'tenfyzhong/CompleteParameter.vim'
" ycm 辅助,用于 python 补全
Plug 'davidhalter/jedi-vim'
" 语法检查
Plug 'w0rp/ale'
" 自动生成 tags
Plug 'ludovicchabant/vim-gutentags'
" fzf-vim
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plug 'junegunn/fzf.vim'
" Projectroot
Plug 'git://github.com/dbakker/vim-projectroot.git'
call plug#end()
"############################################### end vim-plug ##################################
"############################################### begin common-conf #############################
"=========================================
" 键盘配置
"=========================================
"设置快捷键的前缀
let mapleader = "\<Space>"
"可以在buffer的任何地方使用鼠标(类似office中在工作区双击鼠标定位)
"set mouse=a
" CTRL + LEFT 打开 buffer 文件列表下个文件
nnoremap <C-LEFT> :bn<CR>
" CTRL + RIGHT 打开 buffer 文件列表上个文件
nnoremap <C-RIGHT> :bp<CR>
" CTRL + N 打开下一个 tab
"nnoremap <C-N> :tabn<CR>
nnoremap <C-N> :bn<CR>
" CTRL + P 打开上一个 tab
"nnoremap <C-P> :tabp<CR>
nnoremap <C-P> :bp<CR>
"tags 跳转,ctrl+左键跳转,且当前行移动到屏幕的顶部
nnoremap <C-LeftMouse> <C-]>zt<CR>
"可视模式 Ctrl + C 选择复制到系统剪贴板
vnoremap <silent> <C-c> "+y<CR>:wviminfo! ~/.viminfo<CR>
"可视模式 CTRL + X 剪切到系统剪贴板
vnoremap <silent> <C-X> "+x<CR>:wviminfo! ~/.viminfo<CR>
"插入模式 CTRL + V 粘贴到系统剪贴板
inoremap <silent> <C-V> :rviminfo! ~/.viminfo<CR>"+p<CR>
"命令模式 CTRL + V 粘贴到系统剪贴板
cnoremap <C-V> <C-R>+<CR>
"Pasting blockwise and linewise selections is not possible in Insert and
" Visual mode without the +virtualedit feature.  They are pasted as if they
" were characterwise instead.
" Uses the paste.vim autoload script.
exe 'inoremap <script> <C-V>' paste#paste_cmd['i']
exe 'vnoremap <script> <C-V>' paste#paste_cmd['v']
"可视模式 CTRL-d vim 和 shell 来回切换
nnoremap <C-d> :shell<CR>
"leader z 最大化或恢复当前窗口
function! Zoom ()
    " check if is the zoomed state (tabnumber > 1 && window == 1)
    if tabpagenr(') > 1 && tabpagewinnr(tabpagenr(), ') == 1
        let l:cur_winview = winsaveview()
        let l:cur_bufname = bufname('')
        tabclose

        " restore the view
        if l:cur_bufname == bufname('')
            call winrestview(cur_winview)
        endif
    else
        tab split
    endif
endfunction
nnoremap <leader>z :call Zoom()<CR>
"=========================================
" 语言配置
"=========================================
"编码
set termencoding=utf-8
set encoding=utf-8
set fileencodings=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936

" python tab 长度为 4
autocmd Filetype python setlocal expandtab tabstop=4 shiftwidth=4 softtabstop=4
" 开启文件类型检查,这将触发FileType事件,该事件可用于设置语法突出显示,设置选项等
filetype on
" 开启文件类型插件,会在'runtimepath'中加载文件“ftplugin.vim”
filetype plugin on
" 开启文件类型缩进,会在'runtimepath'中加载文件“indent.vim”
filetype indent on
"将输入的TAB自动展开成空格。开启后要输入TAB,需要Ctrl-V<TAB>
set expandtab
"使用每层缩进的空格数
set shiftwidth=4
"编辑时一个TAB字符占多少个空格的位置
set tabstop=4
"方便在开启了et后使用退格(backspace)键,每次退格将删除X个空格
set softtabstop=4
" 使回格键(backspace)正常处理indent(缩进位置), eol(行结束符), start(段首), 很奇怪 Vim 默认竟然不允许在这些地方使用 backspace
set backspace=indent,eol,start
"开启时,在行首按TAB将加入 shiftwidth 个空格,否则加入 tabstop 个空格
set smarttab
"设置光标超过 130 列的时候折行
set tw=130
"不在单词中间断行,如果一行文字非常长,无法在一行内显示完的话,它会在单词与单词间的空白处断开
"尽量不会把一个单词分成两截放在两个不同的行里
set lbr
"打开断行模块对亚洲语言支持
"m 表示允许在两个汉字之间断行,即使汉字之间没有出现空格
"B 表示将两行合并为一行的时候,汉字与汉字之间不要补空格
set fo+=mB
"显示括号配对情况。打开这个选项后,当输入后括号(包括小括号、中括号、大括号) 的时候,光标会跳回前括号片刻,然后跳回来,以此显示括号的配对情况
"带有如下符号的单词不要被换行分割
set iskeyword+=$,@,%,#,-,_
set sm
"缩进方式,每一行都和前一行有相同的缩进量,当遇到右花括号(})等,则取消缩进形式
"set smartindent
"缩进方式,用C语言的缩进格式来处理程序的缩进结构
"set cindent
"设置当文件被改动时自动载入
set autoread
"当你编辑下一个文件的时候,目前正在编辑的文件如果改动,将会自动保存
set autowrite
"tags 配置
set tags=tags;
"输出时只有文件名,不带./ ../等目录前缀(默认了执行%在当前的目录下)
set autochdir 
"禁止生成临时文件
set noundofile
set nobackup
set noswapfile
"搜索忽略大小写
set ignorecase
augroup file_type
    autocmd!
    "为特定后缀的文件设置文件类型
    autocmd BufRead,BufNewFile *.{md,mdown,mkd,mkdn,markdown,mdwn}   set filetype=mkd
    autocmd BufRead,BufNewFile *.{go}   set filetype=go
    autocmd BufRead,BufNewFile *.{js}   set filetype=javascript
    autocmd BufRead,BufNewFile *.{htm}   set filetype=html
augroup END
"=========================================
" 显示配置
"=========================================
if has("gui_running")
    au GUIEnter * simalt ~x " 窗口启动时自动最大化
    set guioptions-=m " 隐藏菜单栏
    set guioptions-=T " 隐藏工具栏
    set guioptions-=L " 隐藏左侧滚动条
    set guioptions-=r " 隐藏右侧滚动条
    set guioptions-=b " 隐藏底部滚动条
    "set showtabline=0 " 隐藏Tab栏
endif
"打开 vim 语法高亮
syntax on
"在命令模式下使用 Tab 自动补全的时候,将补全内容使用一个漂亮的单行菜单形式显示出来
set wildmenu
"指定在选择文本时,光标所在位置也属于被选中的范围。如果指定 selection=exclusive 的话,可能会出现某些文本无法被选中的情况
set selection=inclusive
"选择字符,使用鼠标时或 shift+特殊键时进入选择模式
"set selectmode=mouse,key
"当右键单击窗口的时候,弹出快捷菜单, GUI
set mousemodel=popup
"256位色
set t_Co=256
"高亮光标所在行
set cul
"高亮光标所在列
set cuc
"显示行号
set number
"历史记录数
set history=1000
"在屏幕右下角显示未完成的指令输入,有时候我们输入的命令不是立即生效的,它会稍作等待,等候你是否输入某种组合指令 
set showcmd
"光标移动到buffer的顶部和底部时保持3行距离
set scrolloff=3
"光标移动的距离
set scroll=1
"高亮显示匹配的括号
set showmatch
"匹配括号高亮的时间(单位是十分之一秒)
set matchtime=1
"显示状态栏
set laststatus=2
"關閉突出显示当前行
set nocursorline
"關閉游標垂直方向
set nocursorcolumn
"设置魔术
set magic
"打开搜索高亮模式,若搜索找到匹配项就高亮显示所有匹配项
set hlsearch
"打开增量搜索模式,Vim 会即时匹配你当前输入的内容,这样会给你更好的搜索反馈
set incsearch
"语言设置
set langmenu=zh_TW.UTF-8
"如果有,就使用vim 中文帮助文档
set helplang=tw
"设置命令行的高度
set cmdheight=1
"menu:匹配多于一个使用弹框显示补全,longest:不懂
set completeopt=longest,menu
"在处理未保存或只读文件的时候,弹出确认
set confirm
"使用 :commands 命令模式时总是报告修改的行数
set report=0
" 在被分割的窗口间显示空白,便于阅读
set fillchars=vert:\ ,stl:\ ,stlnc:\ 
augroup vimrcEx
    "当打开一个文件,跳到上次光标所在位置
    autocmd BufReadPost *
                \ if line("'\"") > 0 && line("'\"") <= line("$") |
                \   exe "normal g`\"" |
                \ endif
    " quickfix 模式
    autocmd FileType c,cpp noremap <buffer> <leader><space> :w<cr>:make<cr>
augroup END

"=========================================
" vim omnicompletion 配置
"=========================================
"OmniCppComplete 是根据 Ctags 生成的索引文件进行补全
"开启各种语言的补全
autocmd FileType java setlocal omnifunc=javacomplete2#Complete
autocmd FileType cs setlocal omnifunc=OmniSharp#Complete
autocmd FileType python set omnifunc=python3complete#Complete
autocmd FileType JavaScript set omnifunc=javascriptcomplete#CompleteJS
autocmd FileType html set omnifunc=htmlcomplete#CompleteTags
autocmd FileType css set omnifunc=csscomplete#CompleteCSS
autocmd FileType xml set omnifunc=xmlcomplete#CompleteTags
autocmd FileType php set omnifunc=phpcomplete#CompletePHP
autocmd FileType c set omnifunc=ccomplete#Complete
autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS
"############################################### end common-conf ###############################






"############################################### begin 所有插件配置 #############################
"=========================================
" CurtineIncSw.vim 插件配置
"=========================================
"CTRL + R 头文件源文件来回切换
noremap <C-R> :call CurtineIncSw()<CR>

"=========================================
" YouCompleteMe 插件配置
"=========================================
augroup load_ycm
    autocmd!
    "延迟加载,在 insert 模式手动加载插件
    autocmd InsertEnter * call plug#load('YouCompleteMe') | autocmd! load_ycm
augroup END
".ycm_extra_conf.py 文件路径 (python 換版本時,記得要執行build.py)
let g:ycm_global_ycm_extra_conf = '/home/ubuntu/.vim/plugged/YouCompleteMe/third_party/ycmd/.ycm_extra_conf.py'
"是否开启语义补全
let g:ycm_seed_identifiers_with_syntax=1
"打开vim时不再询问是否加载.ycm_extra_conf.py配置
let g:ycm_confirm_extra_conf=0
"提示框展示
set completeopt=longest,menu
"跳转快捷键
" space + j + c 跳转到声明处
nnoremap <leader>jc :YcmCompleter GoToDeclaration<CR>
"space + j + f 跳转到定义处
nnoremap <leader>jf :YcmCompleter GoToDefinition<CR>
"space + j + j 跳转到声明或定义处
nnoremap <leader>jj :YcmCompleter GoToDefinitionElseDeclaration<CR>
"YCM将使用此选项的值作为Vim装订线中错误的符号
let g:ycm_error_symbol = '>>'
"YCM将使用此选项的值作为Vim装订线中警告的符号
let g:ycm_warning_symbol = '>*'
"回车即选中当前项"
inoremap <expr> <CR>       pumvisible() ? '<C-y>' : '<CR>'
let g:ycm_autoclose_preview_window_after_completion = 0
inoremap <expr> <CR> pumvisible() ? "\<C-Y>\<ESC>a" : "\<CR>"

"=========================================
" CurtineIncSw.vim 插件配置
"=========================================
" CTRL-R头文件源文件来回切换
noremap <C-R> :call CurtineIncSw()<CR>

"=========================================
" YCM-Generator 插件配置
"=========================================
" ctrl-I 自动生成 .ycm_extra_conf.py 文件
noremap <C-I> :YcmGenerateConfig --verbose -c c++ -x c++ -f -b make .<CR>

"=========================================
" tagbar 插件配置,依赖 ctags
"=========================================
" F9 展示类/方法/变量相关侧边栏
nnoremap <F9> :TagbarToggle<CR>
"启动时自动focus
let g:tagbar_autofocus = 1

"=========================================
" auto-pairs 插件配置
"=========================================

"=========================================
" vim-airline 插件配置
"=========================================
"当只打开一个选项卡时自动显示所有缓冲区
let g:airline#extensions#tabline#enabled = 1

"=========================================
" NERDTree 插件配置
"=========================================
"打开树形目录
noremap <F3> :NERDTreeToggle<CR>
inoremap <F3> <ESC> :NERDTreeToggle<CR>
"noremap <F4> :NERDTreeFind<CR>
"inoremap <F4> <ESC> :NERDTreeFind<CR>
augroup vimrcEx-NERDTree
    "只剩 NERDTree 时自动关闭
    autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif
augroup END

"=========================================
" vim-matchup 插件配置
"=========================================

"=========================================
" SimpylFold 插件配置
"=========================================
"在折叠文本中预览 python docstring
let g:SimpylFold_docstring_preview = 0	
let g:SimpylFold_fold_docstring	= 0
let b:SimpylFold_fold_docstring	= 0
let g:SimpylFold_fold_import = 0 
let b:SimpylFold_fold_import = 0


"=========================================
" nerdtree-git-plugin 插件配置
"=========================================
let g:NERDTreeIndicatorMapCustom = {
    \ "Modified"  : "✹",
    \ "Staged"    : "✚",
    \ "Untracked" : "✭",
    \ "Renamed"   : "➜",
    \ "Unmerged"  : "═",
    \ "Deleted"   : "✖",
    \ "Dirty"     : "✗",
    \ "Clean"     : "✔︎",
    \ 'Ignored'   : '☒',
    \ "Unknown"   : "?"
    \ }

"=========================================
" bufferhint 插件配置
"=========================================
"buffer 排序规则,0: sort by path,1: sort by LRU
let g:bufferhint_SortMode=0
" - 快捷键打开缓冲区列表,再按一下关闭
nnoremap - :call bufferhint#Popup()<CR>
" 切回上一个缓冲区
nnoremap \ :call bufferhint#LoadPrevious()<CR>

"=========================================
" vim-python-pep8-indent 插件配置
"=========================================
let g:python_pep8_indent_hang_closing = 1
let g:python_pep8_indent_multiline_string = -2

"=========================================
" CompleteParameter 插件配置
"=========================================
let g:AutoPairs = {'[':']', '{':'}',"'":"'",'"':'"', '`':'`'}
"inoremap <buffer><silent> ) <C-R>=AutoPairsInsert(')')<CR>
"補括號
"inoremap <silent><expr> ( complete_parameter#pre_complete("()")
smap <c-j> <Plug>(complete_parameter#goto_next_parameter)
imap <c-j> <Plug>(complete_parameter#goto_next_parameter)
smap <c-k> <Plug>(complete_parameter#goto_previous_parameter)
imap <c-k> <Plug>(complete_parameter#goto_previous_parameter)

"=========================================
" jedi-vim 插件配置
"=========================================
let g:jedi#force_py_version=3
let g:jedi#goto_command = "<leader>d"
let g:jedi#goto_assignments_command = "<leader>g"
let g:jedi#goto_definitions_command = ""
let g:jedi#documentation_command = "K"
let g:jedi#usages_command = "<leader>n"
let g:jedi#completions_command = "<C-Space>"
let g:jedi#rename_command = "<leader>r"


"=========================================
" ale 插件配置
"=========================================
"keep the sign gutter open
let g:ale_sign_column_always = 1
let g:ale_sign_error = '>>'
let g:ale_sign_warning = '--'
" show errors or warnings in my statusline
let g:airline#extensions#ale#enabled = 1
let g:ale_echo_msg_error_str = 'E'
let g:ale_echo_msg_warning_str = 'W'
let g:ale_echo_msg_format = '[%linter%] %s [%severity%]'
"普通模式下,sp前往上一个错误或警告,sn前往下一个错误或警告
nmap sp <Plug>(ale_previous_wrap)
nmap sn <Plug>(ale_next_wrap)
""<Leader>s触发/关闭语法检查
nmap <Leader>s :ALEToggle<CR>
"<Leader>d查看错误或警告的详细信息
nmap <Leader>d :ALEDetail<CR>
" only the linters from g:ale_linters and b:ale_linters will be enable
let g:ale_linters_explicit = 1
let g:ale_linters = {
            \   'cpp': ['cppcheck'],
            \   'c': ['cppcheck'],
            \   'python': ['pylint'],
            \}
" normal 模式下文字改变运行 linter
let g:ale_lint_on_text_changed = 'normal'
" 离开 insert 模式的时候运行 linter
let g:ale_lint_on_insert_leave = 1
let g:ale_c_gcc_options = '-Wall -O2 -std=c99'
let g:ale_cpp_gcc_options = '-Wall -O2 -std=c++0x'
let g:ale_c_cppcheck_options = '--enable=all'
let g:ale_cpp_cppcheck_options = '--enable=all'

"=========================================
" vim-gutentags 插件配置
"=========================================
"gutentags 搜索工程目录的标志,碰到这些文件/目录名就停止向上一级目录递归
let g:gutentags_project_root = ['.root', '.svn', '.git', '.hg', '.project']
"所生成的数据文件的名称
let g:gutentags_ctags_tagfile = '.tags'
" 将自动生成的 tags 文件全部放入 ~/.cache/tags 目录中,避免污染工程目录
let s:vim_tags = expand('~/.cache/tags')
let g:gutentags_cache_dir = s:vim_tags
"配置 ctags 的参数
let g:gutentags_ctags_extra_args = ['--fields=+niazS', '--extra=+q']
let g:gutentags_ctags_extra_args += ['--c++-kinds=+px']
let g:gutentags_ctags_extra_args += ['--c-kinds=+px']
"检测 ~/.cache/tags 不存在就新建
if !isdirectory(s:vim_tags)
    silent! call mkdir(s:vim_tags, 'p')
endif

"=======================================
" cscope
"=======================================
if has("cscope")
    set csprg=/usr/bin/cscope
    set csto=0
    set cst
    "set csverb "提示載入了cscope.files
    set cspc=3
    "add any database in current dir
    if filereadable("cscope.out")
        cs add cscope.out
        "cs show
    "else search cscope.out elsewhere
    "else
    "    let cscope_file=findfile("cscope.out", ".;")
    "    let cscope_pre=matchstr(cscope_file, ".*/")
    "    if !empty(cscope_file) && filereadable(cscope_file)
    "        exe "cs add" cscope_file cscope_pre
    "    endif
    endif
endif

"":cs find s {name} : 找出C語言name的符號
"":cs find g {name} : 找出name定義的地方
"":cs find c {name} : 找出使用name的地方
"":cs find t {name} : 找出name的字串
"":cs find e {name} : 相當於egrep功能,但速度更佳
"":cs find f {name} : 尋找檔案
"":cs find i {name} : 尋找include此檔案的檔案
"":cs find d {name} : 尋找name裡面使用到的函式

nmap cs :cs find s <C-R>=expand("<cword>")<CR><CR>
nmap cg :cs find g <C-R>=expand("<cword>")<CR><CR>
nmap cc :cs find c <C-R>=expand("<cword>")<CR><CR>
nmap ct :cs find t <C-R>=expand("<cword>")<CR><CR>
nmap ce :cs find e <C-R>=expand("<cword>")<CR><CR>
nmap cf :cs find f <C-R>=expand("<cfile>")<CR><CR>
nmap ci :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
nmap cd :cs find d <C-R>=expand("<cword>")<CR><CR>

"=======================================
" fzf
"=======================================
Plug '~/.fzf'
" [Buffers] Jump to the existing window if possible
let g:fzf_buffers_jump = 1

" [[B]Commits] Customize the options used by 'git log':
let g:fzf_commits_log_options = '--graph --color=always --format="%C(auto)%h%d %s %C(black)%C(bold)%cr"'

" [Tags] Command to generate tags file
let g:fzf_tags_command = 'ctags -R'

" [Commands] --expect expression for directly executing the command
let g:fzf_commands_expect = 'alt-enter,ctrl-x'

nmap ; :Buffers<CR>
nmap <C-T> :Files<CR>
nmap <Leader>r :Tags<CR>
inoremap <expr> <c-x><c-k> fzf#vim#complete#word({'left': '15%'})

"===================================================
"  silversearcher-ag
"===================================================
command! -bang -nargs=* Ag
  \ call fzf#vim#grep(
  \   'ag --column --numbers --noheading --color --hidden --ignore ./tags --ignore ./cscope.out --smart-case '.shellescape(<q-args>), 1,
  \   fzf#vim#with_preview(), <bang>0)
if executable('ag')
      " Use ag over grep
      "set grepprg=ag\ --nogroup\ --nocolor
    set grepprg=ag\ --nocolor
      let g:ackprg = 'ag --vimgrep'
    
      " Use ag in CtrlP for listing files. Lightning fast and respects .gitignore
    let g:ctrlp_user_command = 'ag %s -l --nocolor -g ""'
    
      let $FZF_DEFAULT_COMMAND = 'ag --hidden --ignore ./tags -g ""'
    
      " bind zs to grep word under cursor
    nnoremap zs :Ag <C-R>=expand("<cword>")<CR><CR>
      "nmap zs :cs find s <C-R>=expand("<cword>")<CR><CR>
    " Search keyword
    nnoremap <C-F> :Ag<Space>
endif

"===================================================
"  ProjectRoot
"===================================================
nnoremap <leader>dp :ProjectRootCD<cr>
nnoremap <silent> <leader>dt :ProjectRootExe NERDTreeFind<cr>


"===================================================
"  functions
"===================================================
function! GotoJump()
  jumps
  let j = input("Please select your jump: ")
  if j != ''
    let pattern = '\v\c^\+'
    if j =~ pattern
      let j = substitute(j, pattern, '', 'g')
      execute "normal " . j . "\<c-]>"
    else
      execute "normal " . j . "\<c-o>"
    endif
  endif
endfunction
"nmap <Leader>j :call GotoJump()<CR>
nmap <C-j> :call GotoJump()<CR>

"Mouse
function! MouseToggle()
    " check if mouse is enabled
    if &mouse == 'a'
        " disable mouse
        set mouse=
    else
        " enable mouse everywhere
        set mouse=a
    endif
endfunc
nmap <C-m> :call MouseToggle()<CR>


"############################################### enc 所有插件配置 ###############################
"
"for vim version 8.2
set shortmess-=S
let &t_TI = ""
let &t_TE = ""


沒試過的vimrc設定
1. 隨便寫寫, github



小技巧:
1. ctrl + z 暫時離開 vim, fg後返回
2. bookmark
3. 折code
拆起來(folding):
    反白後,zf
    
打開:
    zo 將游標所在處的折疊打開。open。
    zc 將游標所在處已打開的內容再度折疊起來。close。


ref: 把Vim折疊

2021年7月12日 星期一

protobuf

$ sudo apt-get install autoconf automake libtool curl make g++ unzip -y
$ git clone https://github.com/google/protobuf.git
$ cd protobuf
$ git submodule update --init --recursive(necessary)
$ ./autogen.sh
$ ./configure
$ make
$ make check
$ sudo make install
$ sudo ldconfig

码农家园

2021年3月1日 星期一

Arm_Docker_Qemu

這樣應該可以減少cross copile的機會
Dockerfile
FROM arm32v7/ubuntu:xenial

COPY qemu-arm-static /usr/bin
(用qemu-system-arm會有問題)
...
...
...

Here
問題:用sudo時,會碰到下面的訊息,沒找到好的解決方法,就先用su來擋了
Unknown host QEMU_IFLA type: 50
Unknown host QEMU_IFLA type: 51
Unknown host QEMU_IFLA type: 47
Unknown host QEMU_IFLA type: 48
Unknown host QEMU_IFLA type: 43
Unknown host QEMU_IFLA type: 50
Unknown host QEMU_IFLA type: 51
Unknown host QEMU_IFLA type: 47
Unknown host QEMU_IFLA type: 48
Unknown host QEMU_IFLA type: 43


ref: ubuntu

2021年2月8日 星期一

Login SSH with .ppk

WHAT IS A .PPK FILE?
PPK files are PuTTY Private Key Files developed by Putty


convert .ppk file to .pem, copy it from Login SSH with .ppk file on Ubuntu Terminal
$ sudo apt-get install putty-tools
$ puttygen yourkey.ppk -O private-openssh -o yourkey.pem
$ ssh -i yourkey.pem serverusername@server-ip


ref:
1. WHAT IS A .PPK FILE?
2. Login SSH with .ppk file on Ubuntu Terminal

2020年12月29日 星期二

https-ssl/tls

Copy it form Wiki
Hypertext Transfer Protocol Secure (HTTPS) is an extension of the Hypertext Transfer Protocol (HTTP). The protocol is therefore also referred to as HTTP over TLS, or HTTP over SSL.

Generate Private key (key) and Certificate
openssl genrsa 2048 > host.key
chmod 400 host.key
openssl req -new -x509 -nodes -sha256 -days 365 -key host.key -out host.crt

分析 curl 執行時到底使用了哪一個 ca-certificates.crt 檔
$ strace curl https://localhost:5001 2>&1 | grep ca-certificates.crt

openat(AT_FDCWD, "/etc/ssl/certs/ca-certificates.crt", O_RDONLY) = 6

將剛剛產生的 host.crt 內容拷貝到/etc/ssl/certs/ca-certificates.crt的最下方
cat /path/host.crt >> /etc/ssl/certs/ca-certificates.crt

ref:
1. What is .crt and .key files and how to generate them?
2. What is the difference between .pem, .csr, .key and .crt and other such file extensions?
3. 如何讓 cURL 可以連接自簽憑證提供的 TLS/SSL 加密連線網站
4. 認識 PKI 架構下的數位憑證格式與憑證格式轉換的心得分享

2020年12月24日 星期四

nnn - text file browser

1. 下載:
    nnn
    和
    icons-in-terminal 

2. 編譯:
    a. icons-in-terminal:
        $ cd your_path/icons-in-terminal
        $ ./install.sh
    b. nnn:
        $ sudo apt-get install libreadline-dev
        $ cd your_path/nnn
        $ make O_ICONS=1
        $ sudo make install


3. 修改 ~/.bashrc
#for nnn (text file browser)
export EDITOR=/usr/bin/vim
export VISUAL=/home/nice/.config/nnn/plugins/detached_text.sh
export NNN_PLUG='f:finder;o:fzopen;p:mocplay;d:diffs;t:treeview;v:imgview'
export NNN_OPTS="cEnrx"
export NNN_ARCHIVE="\\.(7z|bz2|gz|tar|tgz|zip)$"
export NNN_COLORS='1234'
export NNN_FCOLORS='c1e2272e006033f7c6d6abc4'
export NNN_RCLONE='rclone mount --read-only'
export NNN_SEL='/tmp/.sel'
export NNN_FIFO='/tmp/nnn.fifo'
export NNN_LOCKER='saidar -c'
export NO_COLOR=1
#enter nn to start up nnn
nn ()  
{
    # Block nesting of nnn in subshells
    if [ -n $NNNLVL ] && [ "${NNNLVL:-0}" -ge 1 ]; then
        echo "nnn is already running"
        return
    fi

    # The default behaviour is to cd on quit (nnn checks if NNN_TMPFILE is set)
    # To cd on quit only on ^G, remove the "export" as in:
    #     NNN_TMPFILE="${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.lastd"
    # NOTE: NNN_TMPFILE is fixed, should not be modified
    export NNN_TMPFILE="${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.lastd"

    # Unmask ^Q (, ^V etc.) (if required, see `stty -a`) to Quit nnn
    # stty start undef
    # stty stop undef
    # stty lwrap undef
    # stty lnext undef

    nnn -de "$@"

    if [ -f "$NNN_TMPFILE" ]; then
            . "$NNN_TMPFILE"
            rm -f "$NNN_TMPFILE" > /dev/null
    fi
}


cp & mv:
    follow the article
   
    select file and press <space>:
    .move file press v
    .copy file press p
    .delete file press x
    

plugin:
    $ cp -r your_path/nnn/plugins/* $HOME/.config/nnn/plugins
    export NNN_PLUG='f:finder;d:diffs;t:treeview' (可自已增減), 壓;f, ;d, ...動作 


啟動 plugin 功能:
    1. 壓 ; 下方會有 list
    2. 壓 f/d/t ( $NNN_PLUG)


基本使用:
1. cd on quit (離開 nnn 後,會切換到最後的目錄)
2. search:
    壓 / (像vim)
3. edit:
    在檔案上壓 e 會進入 vim ($EDITOR=/usr/bin/vim)
4. cp:
    在檔案上壓space,會出現個+,切換到其它目錄後再壓 p
5. mv:
    在檔案上壓space,會出現個+,切換到其它目錄後再壓 v
6. delete
     在檔案上壓space,會出現個+,壓x
     a. 一個一個問是否刪除: 選s後enter
     b. 直接刪除:選s後y
7. rename
    在檔案上壓ctrl+r, 左下角修改檔名

treeview
tmux split-window -h "tree -ps | $EDITOR -"


6. mmore keyboard map

2020年10月29日 星期四

max count of PID and TID

  • cat /proc/sys/kernel/pid_max
  • cat /proc/sys/kernel/threads-max

2020年8月12日 星期三

go 安裝

go:
    download

grpcurl:
    a. download
    b. $ make install
    c. $ go env  (check your GOPATH)
    d. cd your_GOPATH/bin
    e. copy to /opt/...

2020年2月5日 星期三

字型, font

Env: Debian, Ubuntu

Free font download:
1. JetBrains Mono更適合閱讀程式碼的等寬字型, Download(zip file)
2. Cascadia Code 微軟釋出免費等寬字型

Font path:
    /usr/share/fonts

Install new fonts:
1. $ sudo apt-get install ttf-mscorefonts-installer
   $ sudo apt-get install fontconfig

2. Copy fonts or dir_fonts to /usr/share/fonts

3. $ sudo chmod -R dir_fonts 755

4. $ sudo mkfontscale
   $ sudo mkfontdir
   $ fc-cache -fv

System Language:
/etc/default/locale – on Ubuntu/Debian

LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=en_US.UTF-8

2019年10月21日 星期一

How to create /dev/tty0

Create tty0~tty15
CONFIG_VT=y
Create ttyS0
CONFIG_SERIAL_CONSOLE=y


enable ttyS0 with systemctl (test on Debian Jessie)
# systemctl enable serial-getty@ttyS0.service
It will create the link file in /etc/systemd/system/getty.target.wants
ex: 
# ls /etc/systemd/system/getty.target.wants
  serial-getty@ttyS0.service -> /lib/systemd/system/serial-getty@.service


# systemctl mask serial-getty@ttyS0.service
It will link to /dev/null in /etc/systemd/system/
ex: 
# ls /etc/systemd/system/serial-getty@ttyS0.service -> /dev/null


# systemctl disable serial-getty@ttyS0.service
It will remove the file in /etc/systemd/system/getty.target.wants
ref:
1. Here
2. stackoverflow
3. Pid Eins

2019年7月10日 星期三

compile alsa-1.1.0

下載


新版的alsa有加入topology的功能,compile時會出現如下的錯誤,需修改下 Makefile
alsa_utils/alsa-utils-1.1.0/topology/topology.c:99: undefined reference to `snd_tplg_new'
alsa_utils/alsa-utils-1.1.0/topology/topology.c:105: undefined reference to `snd_tplg_verbose'
alsa_utils/alsa-utils-1.1.0/topology/topology.c:107: undefined reference to `snd_tplg_build_file'
apps/alsa_utils/alsa-utils-1.1.0/topology/topology.c:114: undefined reference to `snd_tplg_free'
apps/alsa_utils/alsa-utils-1.1.0/topology/topology.c:110: undefined reference to `snd_tplg_free'
Makefile:
加入 /usr/lib & /usr/include


...
ALSA_CFLAGS = -I/usr/include
ALSA_LIBS = -L/usr/lib -lasound -lm -ldl -lpthread
...
...
FFTW_CFLAGS = -g -O2 -I/usr/lib
...
FFTW_LIB = -lpthread -lm -lasound -L/usr/lib -lm -ldl -lpthread
...
LDFLAGS = -L/usr/lib 
...
LIBS = -lasound -L/usr/lib -lm -ldl -lpthread
...
...
...
...

2019年3月19日 星期二

ping: icmp open socket: Operation not permitted

1. chroot後,發現ping不能使用, 解決方法

Fix the permissions:
chown root:root /bin/ping; chmod u+srwx,go=rx /bin/ping
2.  關掉kernel config - CONFIG_ANDROID_PARANOID_NETWORK

ref:
superuser
發願。隨筆

2018年11月14日 星期三

Cover fhe format to other format via ffmpeg

mp3 -> wav
ffmpeg -i input.mp3 output.wav

wav -> mp3
ffmpeg -i input.wav -acodec mp3 -ab 160k -af aformat=s16:44100 output.mp3

m4a -> mp3
ffmpeg -i input.m4a -acodec libmp3lame -ab 128k output.mp3

webm -> mp3
ffmpeg -i input.webm -vn -ab 128k -ar 44100 -y output.mp3;

wav -> pcm/raw
ffmpeg -i input.wav -f s16le -ac 1 -ar 16000 output.raw;

Alsa Equalizer

環境: ubuntu 16.04 Install:
sudo apt install libasound2-plugin-equal
#!/bin/bash
amixer -D equal sset '01. 31 Hz' 89
amixer -D equal sset '02. 63 Hz' 89
amixer -D equal sset '03. 125 Hz' 89
amixer -D equal sset '04. 250 Hz' 84
amixer -D equal sset '05. 500 Hz' 77
amixer -D equal sset '06. 1 kHz' 50
amixer -D equal sset '07. 2 kHz' 65
amixer -D equal sset '08. 4 kHz' 61
amixer -D equal sset '09. 8 kHz' 60
amixer -D equal sset '10. 16 kHz' 59 
------------------------------------------------------
amixer -D equal sset '01. 31 Hz' 50
amixer -D equal sset '02. 63 Hz' 70
amixer -D equal sset '03. 125 Hz' 86
amixer -D equal sset '04. 250 Hz' 62
amixer -D equal sset '05. 500 Hz' 50
amixer -D equal sset '06. 1 kHz' 50
amixer -D equal sset '07. 2 kHz' 71
amixer -D equal sset '08. 4 kHz' 79
amixer -D equal sset '09. 8 kHz' 77
amixer -D equal sset '10. 16 kHz' 50
------------------------------------------------------
amixer -D equal sset '01. 31 Hz' 50
amixer -D equal sset '02. 63 Hz' 50
amixer -D equal sset '03. 125 Hz' 100
amixer -D equal sset '04. 250 Hz' 100
amixer -D equal sset '05. 500 Hz' 50
amixer -D equal sset '06. 1 kHz' 50
amixer -D equal sset '07. 2 kHz' 50
amixer -D equal sset '08. 4 kHz' 50
amixer -D equal sset '09. 8 kHz' 100
amixer -D equal sset '10. 16 kHz' 100

2018年11月4日 星期日

ALSA

PackageDescription
Firmware (alsa-firmware)Firmware for cards that require it
Library (alsa-lib)Userspace library
Plugins (alsa-plugins)Additional library plugins Eg.jack, pulse, maemo ...
Utilities (alsa-utils)Utilities aplay,arecord,amixer etc
Tools (alsa-tools)Tools
PyALSA (pyalsa)Python bindings for ALSA lib
OSS compat lib (alsa-oss)OSS compatibility library

ref: ALSA, Download or Download each version

2018年8月19日 星期日

Docker - basic command


Dockerfile, tag
FROM ubuntu:amd64/ubuntu:24.10 //先確認tag存在

RUN apt-get update
RUN apt-get -y install vim
RUN apt-get -y install sudo
RUN apt-get -y install locales

# Set the locale
RUN locale-gen en_US.UTF-8
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8

RUN useradd -G sudo -u 1000 --create-home ubuntu
RUN echo "ubuntu:ubuntu" | chpasswd
RUN echo "root:ubuntu" | chpasswd

ENV HOME /home/ubuntu
WORKDIR /home/ubuntu
$ docker build -t=amd64/ubuntu:24.10 --no-cache .


run.sh
#!/bin/bash

xhost +local:
docker run -it  \
        --privileged \
        -v /tmp/.X11-unix:/tmp/.X11-unix \
        -v $HOME:/home/ubuntu/host_home \  (-v host:container, 如果Dockerfile有用cmd,cmd的路徑必需在host有一份)
        -v /home/ubuntu:/home/ubuntu/ \ (共用家目錄)
        -e DISPLAY=$DISPLAY \
        --user 1000 \
        image_name:tag_name

xhost -local:
Parameter:
a. --privileged: use the option to docker run. This removes most of the restrictions normally placed on a Docker container
b. -v: host file path mapping to docker container

If it cannot switch to root
$ docker exec -u 0 -it <container_id_or_name> /bin/bash


01. Install
ref: Here - Install Docker CE with Ubuntu/Mint
( If the installation is successful, the command of ifconfig will show docker0 )
$ run docker command without sudo:
$ sudo groupadd docker
$ sudo gpasswd -a $USER docker


(only for myself)
$ sudo mv /var/lib/docker/ /home/$USER/Docker
$ sudo ln -s /home/$USER/Docker /var/lib/docker

reboot

02. Remember to install QEMU package if wanting to install ARM Ubuntu/Linux
$ sudo apt-get install qemu-user-static

03. Get an Image (ex: amd64/ubuntu:24.10)
$sudo docker pull amd64/ubuntu:24.10

04. List the Image and the Container
Container:
    $ docker ps -a
    
List Images
    $ docker image ls

05. Run
a. create a new container or refer to the bellow Dockerfile
       $sudo docker run -t -i ubuntu:16.04
b. Enter container
       $ sudo docker start C_ID (ContainerID)
       $ sudo docker attach C_ID (ContainerID)
       
c. Enter container (Run at least once)
       $sudo docker exec -i -t C_ID /bin/bash


06. Delete
a. Delete Container
       $ docker stop C_ID || true && docker rm C_ID || true
       (C_ID = Container ID)
b. Delete Image
       $ docker rmi image_ID

07. Rename
a. Rename Container
    $ docker rename current_name new_name

b. Rename Image/tag
    $ docker tag current_name:curretn_tag_name new_name:new_tag

08. Copy
a. Copy a file from hostPC to docker
$ docker cp source_file C_ID:/home/user_name
       (like scp command)
       
b. Copy a file from docker to hostPC
       $ docker cp C_ID:/home/user_name/123.txt ./
       (like scp command)

09. Find the image ID and parent ID (dependency)
$ docker inspect --format='{{.Id}} {{.Parent}}' $(docker images --filter since=Image_ID -q)
       or
$ docker image inspect --format='{{.RepoTags}} {{.Id}} {{.Parent}}' $(docker image ls -q --filter since=Image_ID -q)
$ docker rmi {parent_id}
       or
$ docker rm REPOSITORY:TAG

ref:
1. iT邦
2. Mount linux image in docker container
3. 清風軟件測試

2018年7月12日 星期四

sudo a user to do command

-c: command
-l or -: user

$ sudo su -c 'cd /home/ubuntu/test; ls -alh' - ubuntu

2018年7月11日 星期三

Get CPU speed

 #cat  /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq

/*nice*/