小技巧--

虚拟机与主机共享
VMware桥接模式,也就是将虚拟机的虚拟网络适配器与主机的物理网络适配器进行交接,虚拟机中的虚拟网络适配器可通过主机中的物理网络适配器直接访问到外部网络(例如图中所示的局域网和Internet,下同)。简而言之,这就好像在上图所示的局域网中添加了一台新的、独立的计算机一样。因此,虚拟机也会占用局域网中的一个IP地址,并且可以和其他终端进行相互访问。桥接模式网络连接支持有线和无线主机网络适配器。如果你想把虚拟机当做一台完全独立的计算机看待,并且允许它和其他终端一样的进行网络通信,那么桥接模式通常是虚拟机访问网络的最简单途径。虚拟机中使用桥接模式,就好像是一台独立的计算机,通过samba与主机共享很方便。

将kernel inline改为uninline

修改代码为include/linux/compiler-gcc.h

#if 0	//wgz remove inline
#if !defined(CONFIG_ARCH_SUPPORTS_OPTIMIZED_INLINING) ||		\
    !defined(CONFIG_OPTIMIZE_INLINING) || (__GNUC__ < 4)
#define inline \
	inline __attribute__((always_inline, unused)) notrace __gnu_inline
#else
#define inline inline		__attribute__((unused)) notrace __gnu_inline
#endif

#define __inline__ inline
#define __inline inline
#define __always_inline	inline __attribute__((always_inline))
#define  noinline	__attribute__((noinline))
#else
#if !defined(CONFIG_ARCH_SUPPORTS_OPTIMIZED_INLINING) ||		\
    !defined(CONFIG_OPTIMIZE_INLINING) || (__GNUC__ < 4)
#define inline \
	noinline notrace __gnu_inline
#else
#define inline inline __attribute__((unused)) notrace __gnu_inline
#endif

#define __inline__ inline
#define __inline inline
#define __always_inline	inline
#define  noinline	__attribute__((noinline))
#endif

生成预编译文件的命令为

/home/gongzhenwang/project/J310_pie/android/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/bin/aarch64-linux-android-gcc -Wp,-MD,kernel/locking/.mutex.o.d  -nostdinc -isystem /home/gongzhenwang/project/J310_pie/android/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/bin/../lib/gcc/aarch64-linux-android/4.9.x/include -I/home/gongzhenwang/project/J310_pie/android/kernel/jlq_4.14/arch/arm64/include -I./arch/arm64/include/generated  -I/home/gongzhenwang/project/J310_pie/android/kernel/jlq_4.14/include -I./include -I/home/gongzhenwang/project/J310_pie/android/kernel/jlq_4.14/arch/arm64/include/uapi -I./arch/arm64/include/generated/uapi -I/home/gongzhenwang/project/J310_pie/android/kernel/jlq_4.14/include/uapi -I./include/generated/uapi -include /home/gongzhenwang/project/J310_pie/android/kernel/jlq_4.14/include/linux/kconfig.h  -I/home/gongzhenwang/project/J310_pie/android/kernel/jlq_4.14/kernel/locking -Ikernel/locking -D__KERNEL__ -mlittle-endian -E -ggdb -o kernel/locking/mutex.txt /home/gongzhenwang/project/J310_pie/android/kernel/jlq_4.14/kernel/locking/mutex.c

生成mutex.o的命令为:

 /home/gongzhenwang/project/J310_pie/android/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/bin/aarch64-linux-android-gcc -Wp,-MD,kernel/locking/.mutex.o.d  -nostdinc -isystem /home/gongzhenwang/project/J310_pie/android/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/bin/../lib/gcc/aarch64-linux-android/4.9.x/include -I/home/gongzhenwang/project/J310_pie/android/kernel/jlq_4.14/arch/arm64/include -I./arch/arm64/include/generated  -I/home/gongzhenwang/project/J310_pie/android/kernel/jlq_4.14/include -I./include -I/home/gongzhenwang/project/J310_pie/android/kernel/jlq_4.14/arch/arm64/include/uapi -I./arch/arm64/include/generated/uapi -I/home/gongzhenwang/project/J310_pie/android/kernel/jlq_4.14/include/uapi -I./include/generated/uapi -include /home/gongzhenwang/project/J310_pie/android/kernel/jlq_4.14/include/linux/kconfig.h  -I/home/gongzhenwang/project/J310_pie/android/kernel/jlq_4.14/kernel/locking -Ikernel/locking -D__KERNEL__ -mlittle-endian -c -ggdb -o kernel/locking/mutex.o /home/gongzhenwang/project/J310_pie/android/kernel/jlq_4.14/kernel/locking/mutex.c

以上两条目录要在这个目录执行:

android/out/target/product/ja310_VDK/obj/KERNEL_OBJ

gcc警告和错误

-WerrorMake all warnings into errors. 把所有的警告当作错误处理
-Wno-error取消-Werror的作用,即不将warning当作error
-Werror=

Make the specified warning into an error.  The specifier for a warning is appended; for example -Werror=switch turns the warnings controlled by -Wswitch into errors.  This switch takes a
           negative form, to be used to negate -Werror for specific warnings; for example -Wno-error=switch makes -Wswitch warnings not be errors, even when -Werror is in effect.

           The warning message for each controllable warning includes the option that controls the warning.  That option can then be used with -Werror= and -Wno-error= as described above.  (Printing
           of the option in the warning message can be disabled using the -fno-diagnostics-show-option flag.)

           Note that specifying -Werror=foo automatically implies -Wfoo.  However, -Wno-error=foo does not imply anything.

把一个特定的警告当作错误处理,
-Wno-error=-Wno-error=switch makes -Wswitch warnings not be errors, even when -Werror is in effect. 取消把警告当作错误处理
-Werror=unused-parameter -Werror=unused-variable    
-Wno-error=unused-parameter -Wno-error=unused-variable不把未使用的参数或变量当错误处理
gcc -dM -E显示出gcc预定义的宏信息
 gcc -### foo.c使用-###选项可以打印出gcc所执行的各个子命令
gcc -Q --help=optimizers

使用-Q --help=optimizers选项可以打印出gcc的所有优化(相关的)选项,以及缺省情况下它们是否打开。类似的,你也可以查看不同优化级别下,这些优化选项是否打开:

$ gcc -Q --help=optimizers -O
$ gcc -Q --help=optimizers -O1
$ gcc -Q --help=optimizers -O2
$ gcc -Q --help=optimizers -O3
$ gcc -Q --help=optimizers -Og
$ gcc -Q --help=optimizers -Os
$ gcc -Q --help=optimizers -Ofast

gcc -v foo.c如上所示,使用-v选项可以打印出gcc搜索头文件的路径和顺序。当然,也可以使用-###选项
gcc -print-file-name=libc.a
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/libc.a
如上所示,使用-print-file-name选项就可以显示出gcc究竟会连接哪个libc库了。
gcc -E -P foo.c -o foo.i-P Inhibit generation of linemarkers in the output from the preprocessor. This might be useful when running the preprocessor on something that is not C code, and will be sent to a program which might be confused by the linemarkers.
gcc -c -Wa,-L foo.c

使用-Wa,option可以将选项option传递给汇编器。

注意,逗号和选项之间不能有空格。

gcc -S -fverbose-asm foo.c使用-fverbose-asm选项就可以生成带有详细信息的汇编文件
gcc -Wl,-Map=output.map foo.c

使用-Wl,option可以将选项option传递给连接器。

注意,逗号和选项之间不能有空格。一种常见用法,就是让连接器生成内存映射文件

gcc foo.c -Wl,-I/home/xmj/tmp/ld-2.15.so设置动态连接器
 gcc -save-temps a/foo.c使用选项-save-temps可以保存gcc运行过程中生成的临时文件。这些中间文件的名字是基于源文件而来,并且保存在当前目录下。
GCC中通过--wrap选项使用包装函数

在使用GCC编译器时,如果不想工程使用系统的库函数,例如在自己的工程中可以根据选项来控制是否使用系统中提供的malloc/free, new/delete函数,可以有两种方法:

(1). 使用LD_PRELOAD环境变量:可以设置共享库的路径,并且该库将在任何其它库之前加载,即这个动态库中符号优先级是最高的。

(2). 使用GCC的--wrap选项:对symbol使用包装函数(wrapper function),任何对symbol未定义的引用(undefined reference)会被解析成__wrap_symbol,而任何对__real_symbol未定义的引用会被解析成symbol。即当一个名为symbol符号使用wrap功能时,工程中任何用到symbol符号的地方实际使用的是__wrap_symbol符号,任何用到__real_symbol的地方实际使用的是真正的symbol。注意:当__wrap_symbol是使用C++实现时,一定要加上extern “C”,否则将会出现”undefined reference to __wrap_symbol”。

arm打印backtrace 编译选项

/*
特此声明:感谢前人种树。
如果是x86平台gcc编译,可以直接编译。
如果是ARM平台arm-linux-gcc交叉编译,需要带如下编译参数
-rdynamic 
-funwind-tables 
-ffunction-sections 
否则可能backtrace返回值为0,得不到需要的信息。
*/

    void *buffer[30] = {0};  
    size_t size;  
    char **strings = NULL;  
    size_t i = 0;  

    size = backtrace(buffer, 30);  
    fprintf(stdout, "Obtained %zd stack frames.nm\n", size);  
    strings = backtrace_symbols(buffer, size);  
    if (strings == NULL)  
    {  
        perror("backtrace_symbols.");  
        exit(EXIT_FAILURE);  
    }  

    for (i = 0; i < size; i++)  
    {  
        fprintf(stdout, "%s\n", strings[i]);  
    }  

Android编译host运行程序
Android.mkAndroid.bp
include $(BUILD_HOST_EXECUTABLE)host_supported: true,
BUILD_HOST_SHARED_LIBRARY
BUILD_HOST_EXECUTABLE
BUILD_HOST_PREBUILT
BUILD_HOST_JAVA_LIBRARY
BUILD_HOST_NATIVE_TEST
BUILD_HOST_FUZZ_TEST
BUILD_HOST_SHARED_TEST_LIBRARY
BUILD_HOST_STATIC_TEST_LIBRARY
BUILD_HOST_DALVIK_JAVA_LIBRARY
BUILD_HOST_DALVIK_STATIC_JAVA_LIBRARY
BUILD_HOST_TEST_CONFIG

如果需要将代码编译为本地代码,只需要将对应的include替换为带host的即可。

这些在build/core/config.mk中配置,如下

BUILD_HOST_STATIC_LIBRARY:= $(BUILD_SYSTEM)/host_static_library.mk
BUILD_HOST_SHARED_LIBRARY:= $(BUILD_SYSTEM)/host_shared_library.mk
BUILD_HOST_EXECUTABLE:= $(BUILD_SYSTEM)/host_executable.mk
BUILD_HOST_PREBUILT:= $(BUILD_SYSTEM)/host_prebuilt.mk
BUILD_HOST_JAVA_LIBRARY:= $(BUILD_SYSTEM)/host_java_library.mk
BUILD_HOST_NATIVE_TEST := $(BUILD_SYSTEM)/host_native_test.mk
BUILD_HOST_FUZZ_TEST := $(BUILD_SYSTEM)/host_fuzz_test.mk
BUILD_HOST_SHARED_TEST_LIBRARY := $(BUILD_SYSTEM)/host_shared_test_lib.mk
BUILD_HOST_STATIC_TEST_LIBRARY := $(BUILD_SYSTEM)/host_static_test_lib.mk
BUILD_HOST_DALVIK_JAVA_LIBRARY := $(BUILD_SYSTEM)/host_dalvik_java_library.mk
BUILD_HOST_DALVIK_STATIC_JAVA_LIBRARY := $(BUILD_SYSTEM)/host_dalvik_static_java_library.mk
BUILD_HOST_TEST_CONFIG := $(BUILD_SYSTEM)/host_test_config.mk

include不同的宏实际上就include了不同的mk文件,在这些文件中会配置不同的编译工具即命令。

make的配置是在build\soong\cc\config目录下,用go语言配置的,里边有区分,如global.go配置一些都会用的功能,如-Wno-unused等

GDB命令
dir 或 directory : 设置source文件搜索路径

添加参数

      1)run  命令行参数

      2)set args  命令行参数

set sysroot ./ja310_haps/host/aarch64-buildroot-linux-gnu/sysroot : 设置so的搜索路径
layout:用于分割窗口,可以一边查看代码,一边测试。主要有以下几种用法:
layout src:显示源代码窗口
layout asm:显示汇编窗口
layout regs:显示源代码/汇编和寄存器窗口
layout split:显示源代码和汇编窗口
layout next:显示下一个layout
layout prev:显示上一个layout
Ctrl + L:刷新窗口
Ctrl + x,再按1:单窗口模式,显示一个窗口
Ctrl + x,再按2:双窗口模式,显示两个窗口
Ctrl + x,再按a:回到传统模式,即退出layout,回到执行layout之前的调试窗口。

info variables :  查看全局和静态变量

info locals : 查看当前stack frame局部变量

info args : 查看当前stack frame参数

查看汇编加源码:disassemble /m Funcname

p aaa : 打印变量aaa

p func1::bbb : 打印函数func1中的局部变量bbb

p './isp_test.c'::w : 打印./isp_test.c中的全局变量w

info threads : 显示当前可调试的所有线程, 前面有*的是当前调试的线程。

thread ID : 切换当前调试的线程为指定ID的线程。

break thread_test.c:123 thread all :  在所有线程中相应的行上设置断点

thread apply ID1 ID2 command : 让一个或者多个线程执行GDB命令command。 

thread apply all command  : 让所有被调试线程执行GDB命令command。

set scheduler-locking off|on|step : 估计是实际使用过多线程调试的人都可以发现,在使用step或者continue命令调试当前被调试线程的时候,其他线程也是同时执行的,怎么只让被调试程序执行呢?通过这个命令就可以实现这个需求。off 不锁定任何线程,也就是所有线程都执行,这是默认值。 on 只有当前被调试程序会执行。 step 在单步的时候,除了next过一个函数的情况(熟悉情况的人可能知道,这其实是一个设置断点然后continue的行为)以外,只有当前线程会执行

follow-fork-mode
用法:set follow-fork-mode [parent|child] 
进入gdb后,直接设置,默认是parent
所以如果想要调试子进程,进入gdb后设置set follow-fork-mode child,然后设置子进程的断点
可用使用show follow-fork-mode 来查询当前fork模式
detach-on-fork mode
用法:set detach-on-fork [on|off]
on: 只调试父进程或子进程的其中一个(根据follow-fork-mode来决定),这是默认的模式。
off: 父子进程都在gdb的控制之下,其中一个进程正常调试(根据follow-fork-mode来决定),另一个进程会被设置为暂停状态。
如果设置了set detach-on-fork off且follow-fork-mode为parent,fork后子进程并不运行,而是处于暂停状态。

git
git pull https://gitlab.com/xxxx/xxx.git master --allow-unrelated-histories,注意--后面表示允许不相干的两个仓库合并,因为我们之前两个仓库是完全独立的,所以直接是没办法pull下来,需要加上后面参数才行
git checkout test

这个命令两种用途:

1. 本地有test分支,则进入test分支

2. 本地没有test分支,则从远程服务区获取test分支,在本地建立test分支,并建立track关系

git checkout -b offical remotes/origin/dev-official将远程的dev-official checkout,并建立branch offical,并建立track关系
git checkout -b fromtest以当前分支建立一个新分支,不与远程建立track关系

git push origin fromtest

git push origin fromtest:fromtest

将当前的fromtest 提交到remote的fromtest,如果remote没有fromtest分支,则建立fromtest分支
git push origin test:master将本地的test分支提交到remote的master分支
git push origin :fromtest删除remote的fromtest分支
git merge fromtest将fromtest分支merge到当前分支

git format-patch

$ git format-patch HEAD^                 #生成最近的1次commit的patch

$ git format-patch HEAD^^               #生成最近的2次commit的patch

$ git format-patch HEAD^^^              #生成最近的3次commit的patch

$ git format-patch HEAD^^^^                  #生成最近的4次commit的patch

$ git format-patch <r1>..<r2>                                              #生成两个commit间的修改的patch(包含两个commit. <r1>和<r2>都是具体的commit号)

$ git format-patch -1 <r1>                                                   #生成单个commit的patch

$ git format-patch <r1>                                                       #生成某commit以来的修改patch(不包含该commit)

$ git format-patch --root <r1>               #生成从根到r1提交的所有patch

git am

$ git apply --stat 0001-limit-log-function.patch         # 查看patch的情况

$ git apply --check 0001-limit-log-function.patch        # 检查patch是否能够打上,如果没有任何输出,则说明无冲突,可以打上

(注:git apply是另外一种打patch的命令,其与git am的区别是,git apply并不会将commit message等打上去,打完patch后需要重新git add和git commit,而git am会直接将patch的所有信息打上去,而且不用重新git add和git commit,author也是patch的author而不是打patch的人)

$ git am 0001-limit-log-function.patch                                # 将名字为0001-limit-log-function.patch的patch打上

$ git am --signoff 0001-limit-log-function.patch                  # 添加-s或者--signoff,还可以把自己的名字添加为signed off by信息,作用是注明打patch的人是谁,因为有时打patch的人并不是patch的作者

$ git am ~/patch-set/*.patch             # 将路径~/patch-set/*.patch 按照先后顺序打上

$ git am --abort                                                                   # 当git am失败时,用以将已经在am过程中打上的patch废弃掉(比如有三个patch,打到第三个patch时有冲突,那么这条命令会把打上的前两个patch丢弃掉,返回没有打patch的状态)

$ git am --resolved                                                             #当git am失败,解决完冲突后,这条命令会接着打patch

如果打Patch的过程中发生了冲突(conflicts),怎么办?

解决patch冲突的过程是:

如果不想打这一系列patch了,直接:git am --abort。

如果还想打, 有两种解决方案:

方案一(个人推荐):

(1) 根据git am失败的信息,找到发生冲突的具体patch文件,然后用命令git apply --reject <patch_name>,强行打这个patch,发生冲突的部分会保存为.rej文件(例如发生冲突的文件是a.txt,那么运行完这个命令后,发生conflict的部分会保存为a.txt.rej),未发生冲突的部分会成功打上patch

(2) 根据.rej文件,通过编辑该patch文件的方式解决冲突。

(3) 废弃上一条am命令已经打了的patch:git am --abort

(4) 重新打patch:git am ~/patch-set/*.patchpatch

方案二:

(1) 根据git am失败的信息,找到发生冲突的具体patch文件,然后用命令git apply --reject <patch_name>,强行打这个patch,发生冲突的部分会保存为.rej文件(例如发生冲突的文件是a.txt,那么运行完这个命令后,发生conflict的部分会保存为a.txt.rej),未发生冲突的部分会成功打上patch

(2) 根据.rej文件,通过编辑发生冲突的code文件的方式解决冲突。

(3) 将该patch涉及到的所有文件(不仅仅是发生冲突的文件)通过命令git add <file_name>添加到工作区中

(4) 告诉git冲突已经解决,继续打patch: git am --resolved (git am --resolved 和 git am --continue是一样的)

分析:方案一和方案二主要区别是解决冲突的方法不一样。方案一是通过编辑patch文件的方式解决冲突,方案二十通过编辑冲突code文件的方式解决冲突。这两种方案区别比较大:经过实验,核心区别在于,方案二无法验证冲突有没有切实的解决。即使你在方案二的第二步乱改一通,也能“打完”发生冲突的patch(并没有检测修改后的code文件跟patch期望的是否相同)。因此,如果采用方案二,那么再解决code文件冲突后,需要人工去确认修改的正确性

git revert [m1] 2a224c481ef4429eb07807023be0e5950b70eab4revert某次提交,如果是merge的要加上m1选项
git cherry-pick e234b457d985df96b96887bbce55c9889eb87fc1将某一次提交merge到当前分支,因为id是唯一的,所以可以从任意分支获取,而不需要指定分支名。
git fetch /home/gongzhenwang/project/jcc/jlqsource/linux/kernel/jlq_4.14 kernel:old将远程的分支kernel取下来,建立新分支为old
Docker

docker run -it --rm -p 8080:80 dorowu/ubuntu-desktop-lxde-vnc

http://localhost:8080/

运行novnc的Ubuntu,运行之后可在浏览器(chrome,edge不行)中进入桌面

docker run --name wang--privileged  -t -i -v  d:\vm:/tmp msm8909_build_env

退出之后下次进入:
docker start wang
docker attach wang

docker加速:
http://f1361db2.m.daocloud.io

ps -l, top查看进程优先级
ps和top获得的pri 和ni的值是有差异的,但是记住一点就可以理解,优先级范围是0-139,他们只是使用了不同的映射而已,但是都遵循了一点,就是将nice=0都对应着120,有正序对应和倒序对应而已。
kernel编译ko
ccflags-y += -Idrivers/media/platform/jlq/camera/sensor/cciccflags-y包含的是一些cflag的信息
obj-m := allisp.o
allisp-objs := ./isp/isp_util.o                           \
                ./isp/isp_driver.o                         \
                ./isp/isp_buf_mgr.o                        \
                ./isp/isp_hw_util/isp_hw_util.o            \
                ./msm.o                                    \
allisp是要生成的ko,下面一行是包含的所有的文件,一个模块只能有一个module_init.
指定动态链接库位置
1. 在/etc/ld.so.conf.d/下创建xxx.conf,在文本中加入.so所在路径,如:/usr/xxx等等,然后使用相应ldconfig命令使之生效。
2. 将.so所在路径添加为LD_LIBRARY_PATH环境变量。
3. 在编译命令中使用-Wl,-rpath=./参数,并将相应.so拷贝到执行目录;当然也可以将‘./’指定为其他目录。
dynamic_debug操作

echo 'file ion.c +p' > /d/dynamic_debug/control : 打开文件ion.c中的dynamic打印

echo 'file sprdfb_main.c -p' > /sys/kernel/debug/dynamic_debug/control  : 关闭ion.c中的dynamic打印

cat /d/dynamic_debug/control : 查看dynamic是否打印,输出信息如下:

=p : 表示enable了打印

=_ : 表示没有enable 打印

下载android源码
bionic git clone https://aosp.tuna.tsinghua.edu.cn/platform/bionic

scp带密码拷贝
sshpass -p 密码 scp ./a.txt wanggongzhen@10.1.1.1:/home/wanggongzhen/
打印编译时间
3、__ DATE __ : 在源代码中插入当前编译日期〔注意和当前系统日期区别开来〕
4、__ TIME __ : 在源代码中插入当前编译时间〔注意和当前系统时间区别开来〕
ssh免密登陆
ssh-keygen生成密钥 ~/.ssh/
  1. # 方法1, os x 可以通过 `brew install ssh-copy-id` 安装 ssh-copy-id

  2. ssh-copy-id user@host;

  3. # 方法2

  4. cat ~/.ssh/id_rsa.pub | ssh user@host "mkdir ~/.ssh; cat >> ~/.ssh/authorized_keys"

将密钥传到bigdata2机器上,之后就可以免密登陆了

不同用户名登陆方式

ssh cluster

scp a.txt cluster:~/

修改本地登陆用户的 ~/.ssh/config 文件,如果木有的话就自个儿建一个吧,内容如下:

# configuration 1
Host cluster
	HostName 192.168.11.11
	User tom


# configuration 2
Host=aliyun
	Hostname=202.44.2.2
	User tom
ssh root@bigdata2 “/home/root/copy.sh”执行远程机器上的/home/root/copy.sh
man ssh_config
常用命令
tasksetset or retrieve a process's CPU affinity

 You can also retrieve the CPU affinity of an existing task:
              taskset -p pid

       Or set it:
              taskset -p mask pid

rsync

rsync -avz wang@10.1.1.20:/test/ ./test/

支持断点续传

perf
perf probe -x /home/xxx/test/a.out /home/xxx/test/main.c:4 argc argv k在main.c的第4行probe,打印出argc argv和k这三个参数
perf probe /home/xxx/test/a.out main argc argv在函数main的入口处probe,打印出argc和argv
perf probe /home/xxx/test/a.out main:4在main的第4行插入probe
perf probe scheduler*在所有scheduler开头的函数入口处probe
root@kickseed:~/test# perf probe -V do_sys_open
Available variables at do_sys_open
        @<do_sys_open+0>
                char*   filename
                int     dfd
                int     flags
                struct open_flags       op
                umode_t mode
查看do_sys_open有哪些变量可以在probe中使用

root@kickseed:~/test# perf probe -V do_sys_open --range

Available variables at do_sys_open
        @<do_sys_open+0>
                [INV]   int     fd      @<do_sys_open+[302-307,307-346,427-657,669-690]>
                [INV]   struct filename*        tmp     @<do_sys_open+[284-293,293-348,427-657,669-690]>
                [VAL]   char*   filename        @<do_sys_open+[0-283,320-333,354-427,657-669]>
                [VAL]   int     dfd     @<do_sys_open+[0-320,320-352,352-354,354-451,657-669,685-690]>
                [VAL]   int     flags   @<do_sys_open+[0-63,63-344,354-690]>
                [VAL]   struct open_flags       op      @<do_sys_open+[0-690]>
                [VAL]   umode_t mode    @<do_sys_open+[0-350,354-620,652-690]>

查看变量的有效范围


root@kickseed:~/test# perf probe do_sys_open filename:string flags 'op.mode'

a.out-14389 [000] .... 2459018.446122: do_sys_open: (do_sys_open+0x0/0x2c0) filename_string="/lib/x86_64-linux-gnu/libdl.so.2" flags=557056 mode=0xff20
perf probe -k /userdata/vmlinux -m /mps/ko/cexxxxv100_isp.ko cnispCreatePipe pipe=viPipe attr='pstPipeAttr->u32Maxw'perf向ko中添加kprobe event
perf buildid-cache -a /mps/ko/ceisp.ko      将ko加载到buildid中,路径是 /root/.debug/.build-id
perf top --symbols kfree// 仅显示指定的符号
echo "wakeup_latency u64 lat; pid_t pid; int prio" >> /sys/kernel/debug/tracing/synthetic_events

echo 'hist:keys=$saved_pid:saved_pid=pid:ts0=common_timestamp.usecs if comm=="time"' >> /sys/kernel/debug/tracing/events/sched/sched_waking/trigger

echo 'hist:keys=next_pid:wakeup_lat=common_timestamp.usecs-$ts0:onmatch(sched.sched_waking).wakeup_latency($wakeup_lat, $saved_pid, next_prio) if next_comm=="time"' >> /sys/kernel/debug/tracing/events/sched/sched_switch/trigger

echo 'hist:keys=pid,prio,lat:sort=pid,lat' >> /sys/kernel/debug/tracing/events/synthetic/wakeup_latency/trigger

添加一个synthetic event,统计latency。
mount -t debugfs nodev /proc/sys/debug
echo schedule > /proc/sys/debug/tracingset_graph_function
echo function_graph > /proc/sys/debug/tracingcurrent_tracer
echo 3 > /proc/sys/debug/tracingmax_graph_depth
echo 1 > /proc/sys/debug/tracingtracing_on 

echo 'r:sched_ret schedule' >> /proc/sys/debug/tracing/kprobe_events 
echo 'p:sched_ent schedule' >> /proc/sys/debug/tracing/kprobe_events 

echo 'hist:keys=common_pid:ts0=common_timestamp.usecs' >> /proc/sys/debug/tracing/events/kprobes/sched_ent/trigger

echo 'hist:keys=common_pid:wakeup_lat=common_timestamp.usecs-$ts0:onmax($wakeup_lat).snapshot()' >> /proc/sys/debug/tracing/events/kprobes/sched_ret/trigger

统计schedule函数的执行时间,并在最大时做snapshot。
buildroot qemu gdb
使用buildroot正常编译kernel,但是kernel的KASLR功能必须关闭,否则gdb断点无法起作用

{

// Use IntelliSense to learn about possible attributes.

// Hover to view descriptions of existing attributes.

// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387

"version": "0.2.0",

"configurations": [

{

"name": "kernel-debug",

"type": "cppdbg",

"request": "launch",

"miDebuggerServerAddress": "127.0.0.1:1234",

"program": "${workspaceFolder}/vmlinux",

"args": [],

"stopAtEntry": false,

"cwd": "${workspaceFolder}",

"environment": [],

"Console": false,

"logging": {

"engineLogging": false

},

"MIMode": "gdb",

}

]

}

lunch.json的配置
gcov
参考: GCC Coverage代码分析-.gcda/.gcno文件及其格式分析_学习,思考,记录,分享。-CSDN博客_gcda文件
g++ -fprofile-arcs -ftest-coverage -std=c++1z test.c

编译,会生成a.out 和 test.gcno

-fprofile-arcs:用于a.out执行时生成main.gcda文件

Add code so that program flow arcs are instrumented.  During execution the program records how many times each branch and call is executed and how many times it is taken or returns.

-ftest-coverage:生成main.gcno.

./a.out运行a.out,会生成test.gcda
gcov test.c生成test.c.gcov文件,此文件为文本文件,可以打开直接看覆盖率

lcov -c -d . -o test.info

使用当前目录下的*.gcno和*.gcda生成test.info,test.info包含了覆盖信息。

此命令会遍历当前目录的子目录,一起生成到test.info中

genhtml -o 1234 test.info根据test.info的内容生成图形化界面,放在1234目录下
module
make M=../test_module/ modules编译module方式,进入kernel编译根目录,执行左边指令
KASAN UBSAN
KASAN和UBSAN若同时enable,则生成的boot image会很大

barry

Barrier
A set of memory accesses, RWx, that are generated by the PE executing the Store-Release instruction and that appear in program order before the Store-Release instruction, together with those that originate from a different PE to the extent that the PE is required to observe them coherently, Observed-by the PE before executing the Store-release.目前的理解:在执行store-release之前,当前pe和一定范围的其他pe,都可能观察到当前pe和其他pe已经做的的内存访问
The memory access generated by the Store-Release (Wrel), such that all of the memory accesses, RWx, are Observed-by each PE to the extent that the PE is required to observe those accesses coherently, before Wrel is Observed-by that PE to the extent that the PE is required to observe that access coherently.store-release所进行的内存访问,在上面的同步之后才发生。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值