- 博客(57)
- 收藏
- 关注
原创 Android/Linux内存常用命令
一 、常用命令vmstatproc/meminfodumpsys meminfoprocrank (system/extras/procrank/procrank.cpp)procmemproc/slabinfosys/kernel/debug/ion/heaps/ (ion 相关)proc/buddyinfo/proc/pagetypeinfo/proc/vmallocinf/proc/sys/vm/*/proc//maps及/proc//smaps更详细展示了进程VMA的分布情
2021-07-14 20:27:51
279
原创 page compaction 基础知识
一、 查看当前系统当前碎片化的情况cat /proc/buddyinfoThis file is used primarily for diagnosing memory fragmentation issues. **cat/proc/pagetypeinfoThe pagetypinfo begins with information on the size of a page block. Itthen gives the same type of information as bu
2021-06-07 20:16:09
244
原创 Hot and cold pages
void __free_pages(struct page *page, unsigned int order){ if (put_page_testzero(page)) {//检查页框是否还有进程在使用,就是检查_count变量的值是否为0 if (order == 0) //如果是1个页框,则放回每CPU高速缓存中 free_hot_cold_page(page, false); else //如果是多个页框,则放回伙伴系统 __free_pages_ok(page, ord
2021-05-26 11:53:09
230
原创 Page migration
网址:https://www.kernel.org/doc/html/latest/vm/page_migration.htmlPage migration allows moving the physical location of pages between nodes in a NUMA system while the process is running. This means that the virtual addresses that the process sees do not cha
2021-05-24 20:46:12
172
原创 linux kernel-4.9 PageActive PageLRU等定义
code path:https://elixir.bootlin.com/linux/v4.9.269/source/include/linux/page-flags.hPAGEFLAG(Active, active, PF_HEAD) __CLEARPAGEFLAG(Active, active, PF_HEAD)TESTCLEARFLAG(Active, active, PF_HEAD)#define PAGEFLAG(uname, lname, policy) \ TESTPAGE
2021-05-24 20:20:44
807
原创 Linux gup
/** * __get_user_pages() - pin user pages in memory * @tsk: task_struct of target task * @mm: mm_struct of target mm * @start: starting user address * @nr_pages: number of pages from start to pin * @gup_flags: flags modifying pin behaviour * @pages
2021-05-24 11:58:14
1050
原创 vmap; kmap ; remap_vmalloc_range ; remap_pfn_range
vmap(). This can be used to make a long duration mapping of multiple physical pages into a contiguous virtual space. It needs global synchronization to unmap.kmap(). This permits a short duration mapping of a single page. It needs global synchronization,
2021-05-20 18:05:07
973
原创 dump_stack 实现分析
1 .lib/dump_stack.cstatic void __dump_stack(void){ dump_stack_print_info(KERN_DEFAULT); show_stack(NULL, NULL);}2 .arch/arm64/kernel/traps.cvoid show_stack(struct task_struct *tsk, unsigned long *sp){ dump_backtrace(NULL, tsk); barrier();}dum
2021-04-25 20:36:01
526
原创 v4l2 use V4L2_MEMORY_MMAP方式,driver将buffer 转换为DMA 地址
建议使用以下方式进行vb2_queue 进行initstruct vb2_queue *q;q->mem_ops = &vb2_dma_sg_memops;这样 userspace reqbufs 就会使用 vb2_dma_sg_alloc 最终得到的是 struct sg_table *sgt;[ 43.365265]<3>[W](3)[<ffffff800808bb7c>] dump_backtrace+0x0/0x2c0[ 43.366029]
2021-04-14 11:13:26
1105
原创 linux fork() 函数使用注意问题
fork 函数从哪里开始执行#include <unistd.h>;#include <sys/types.h>;main (){ pid_t pid; pid=fork(); // 1)从这里开始程序分岔,父子进程都从这一句开始执行一次 if (pid < 0) printf("error!"); else if (pid == 0) printf("chi.
2021-04-13 20:18:58
175
原创 v4l2 use V4L2_MEMORY_MMAP方式导出为 DMA BUF fd 方式使用
V4L2_MEMORY_MMAP 导出 fd 需要使用 vb2_ioctl_expbuf (只能使用于VB2_MEMORY_MMAP 方式)。int buffer_export(int v4lfd, enum v4l2_buf_type bt, int index, int *dmafd){ struct v4l2_exportbuffer expbuf; memset(&expbuf, 0, sizeof(expbuf)); expbuf.type = bt;
2021-04-13 11:57:36
4683
原创 v4l2 use dma buffer mode
user space struct v4l2_buffer buf; memset(&buf, 0, sizeof buf); buf.index = 0; buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; buf.memory = V4L2_MEMORY_DMABUF; buf.m.fd = dbuf_fd; ret = ioctl(v4lfd, VIDIOC_QBUF, &buf);kernel/** * __qbuf_d
2021-04-13 10:21:59
2949
原创 vim 常用命令汇总
1 .粘贴复制时,自动换行的关闭:set paste不再有自动换行。:set nopaste自动换行2 . linux kernel 80 字符的限制显示设置超过80长度提示set colorcolumn=813 .
2021-04-02 10:56:01
146
原创 spin_lock 调用 wait_for_completion 出现 KE 分析
spinlock_t数据类型,spin_lock(&lock)和spin_unlock(&lock)是加锁和解锁等待解锁的进程将反复检查锁是否释放,而不会进入睡眠状态(忙等待),所以常用于短期保护某段代码同时,持有自旋锁的进程也不允许睡眠,不然会造成死锁——因为睡眠可能造成持有锁的进程被重新调度,而再次申请自己已持有的锁。wait_for_completion,主要调用wait_for_common,而wait_for_common则主要是将当前线程加入等待队列,然后调用schedul
2021-03-19 21:39:39
279
原创 linux init时初始化中断号
[ 6.535890]<3>[I](3)OF: of_irq_parse_one: dev=/soc/xxx@12300000, index=0[ 6.536771]<3>[W](3)CPU: 3 PID: 1 Comm: swapper/0 Not tainted 4.9.118+ #356[ 6.537638]<3>[W](3)Hardware name: ATC Inc. AC8x (DT)[ 6.538266]<3>[W]
2021-02-22 20:42:19
455
原创 procmem工具使用
procmem 工具代码路径system/extras/procmem编译生成路径out/target/product/xxx/system/xbin3.使用方法adb rootadb remoiuntadb push procmem system/xbin使用adb shellxxx:/ # procmem 1888procmem 介绍procmem:针对每一个进程具体分析就要使用procmem工具了。procmem 给出了procrank中VSS、RSS、PSS、USS的每.
2020-12-17 20:10:56
1431
原创 dma_map_single dma_map_sg理解
What memory is DMA'able?========================The first piece of information you must know is what kernel memory canbe used with the DMA mapping facilities. There has been an unwrittenset of rules regarding this, and this text is an attempt to fin.
2020-12-09 09:34:09
5950
原创 kernel 调试 API
dump 寄存器 show_regs(regs);code : https://elixir.bootlin.com/linux/v4.9.185/source/arch/arm64/kernel/process.cvoid __show_regs(struct pt_regs *regs){int i, top_reg;u64 lr, sp;if (compat_user_mode(regs)) { lr = regs->compat_lr; sp = regs->co.
2020-10-29 09:25:29
474
原创 slab 内存泄漏
kernel log 出现 lowmemorykiller 判断 kernel 出现了内存泄漏多次测试后对比 procrank 数据adb shell procrank > C:\procrank.txt测试前:RAM: 1814588K total, 359780K free, 7372K buffers, 701496K cached, 964K shmem, 138804K slab测试后:RAM: 1814588K total, 229016K free, 10204K
2020-10-14 14:02:22
1030
原创 ION native 的使用方式
根据 Google 的 GTest 程序 其中的map test ,可以得知正确的 release操作如下TEST_F(Map, MapHandle){ static const size_t allocationSizes[] = {4*1024, 64*1024, 1024*1024, 2*1024*1024}; for (unsigned int heapMask : m_allHeaps) { for (size_t size : allocationSizes
2020-09-24 09:21:49
238
原创 Native 使用 Ashmem 使用的基本方法
在 android 使用共享buffer 的方法,下面给出一个 goggle 自带的例子https://android.googlesource.com/platform/system/core/+/master/libcutils/ashmem_test.cpp/* * Copyright (C) 2016 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "Licens
2020-09-12 18:09:31
623
原创 v4l2 mmap 的原理
1.使用方法userspacestruct v4l2_requestbuffers reqbufs = { .count = 5, .type = V4L2_BUF_TYPE_VIDEO_CAPTURE, .memory = V4L2_MEMORY_MMAP,};ioctl(dev_fd,VIDIOC_REQBUFS,&reqbufs);void *ptr[5];for (int i =0; i < 5 ; i++) { ptr[i] = mmap()NULL,buffe
2020-09-12 18:02:28
1405
原创 Native backtrace lib so库使用汇编进行分析错误位置
(200901_13:43:21.574)[ 3.854314]<3>[E](3)DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***(200901_13:43:21.574)[ 3.859079]<3>[E](3)DEBUG: Revision: '0'(200901_13:43:21.574)[ 3.859791]<3>[E](3)DEBUG: ABI: 'a
2020-09-01 20:08:11
314
原创 wait_event_interruptible 等到条件并被wakeup执行时,再次执行 wake_up_interruptible 会发生什么
wait_event_interruptible souece code#define __wait_event_interruptible(wq, condition, ret) \do { \ DEFINE_WAIT(__wait); \ \ for (;;) { \ prepare_to_wait(&wq, &__wait, TASK_INTERRUPTIBLE); \ if (condition)
2020-06-11 10:23:21
510
原创 linux kernel container_of 的使用,结构体成员数组的形式
#include <stdio.h>#ifdef offsetof#undef offsetof#endif#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) #ifdef container_of#undef container_of#endif#define container_of(ptr, type, member) ({\ const typeof( ((type *
2020-05-09 18:05:28
596
1
原创 qcom v4l2 实现分析
1.queue buf 过程Qcom HAL code/*=========================================================================== * FUNCTION : mm_stream_qbuf * * DESCRIPTION: enqueue buffer back to kernel queue for fu...
2020-04-14 21:11:44
484
原创 android YV12 地址偏移 与 line_stride 对齐
1.buffer地址偏移以分辨率 1280*720 格式为YV12 为例,Y起始地址为0x100000000 ,且是连续y_addr = 0x100000000;cb_addr = y_addr + 1280×720;cr_addr = cb_addr + 1280*720/4;2.line stride计算需要考虑到不同硬件使用相同的地址,如camera 写buffer...
2020-04-14 14:56:32
946
原创 android camera debug
adb shell dumpsys media.camera > camera.dumpdump 的摘取部分信息如下== Service global info: ==Number of camera devices: 2Number of normal camera devices: 2 Device 0 maps to "0" Device 1 maps ...
2020-04-13 10:07:00
395
1
原创 Linux 常用调试命令汇总
top -H -O CPU 查看线程运行在相应的CPU上···top -H -O CPU[?25l[0m[H[J[s[999C[999B[6n[uTasks: 907 total, 2 running, 901 sleeping, 0 stopped, 0 zombieMem: 1853188k total, 1307684k used, 54550...
2020-04-10 18:00:58
653
1
原创 Linux kill 进程后 ,fd 是否被释放,是否会调用 release ?
kill 进程后怎么验证 fd 确实被释放了?打开 APP,使用 lsof 命令 确定我们被使用的APP 确实被打开了xxxxxx:/ # lsof | grep video10lsof | grep video10camerahalserver 1695 cameraserv mem CHR 81,0 783...
2020-04-10 17:42:12
4018
原创 camera进程通信分析
1.AIDL用于 APP 和 cameraservice 端交互的https://android.googlesource.com/platform/frameworks/av/+/refs/tags/android-9.0.0_r55/camera/aidl/android/hardware编译后的路径在out/soong/.intermediates/frameworks/av/ca...
2020-04-09 20:25:05
685
原创 kernel 中 对 mutex 使用了memset 导致了 mutex_lock_nested 中出现了kernel panic
假设定义了一个结构体struct mutex_lock { struct mutex lock; }struct mutex_lock mutex_lock_t;在 mutex_init(&mutex_lock_t.lock)在后面的函数中调用了 memset(&mutex_lock_t,0,sizeof(struct mutex_lock)) ,...
2019-11-12 21:44:59
1514
原创 C++ thread 封装成 class
#include <pthread.h>#include <unistd.h>#include <stdio.h>#include <stdlib.h>/* public protected private共有继承 public protected 不可见私有继承 private ...
2019-08-15 10:34:43
613
原创 std::thread 在类内部使用
#include<iostream>#include <thread>#include <unistd.h>#include <functional>class Test{ public: Test(int m):n(m) { testThread_ = std::thread...
2019-08-15 10:33:26
2156
原创 C++ 文件操作封装成class
//#include "md5.h"#include <iostream>#include <malloc.h>#include <memory.h>#include <sys/time.h>#include <stdio.h>#include <time.h>#include <cstdlib>#...
2019-08-13 18:05:15
1025
原创 C++ 以string形式 打印 十六进制 代码示例
#include <iostream>using namespace std;int main(void){ unsigned char test[10]; test[0] = 0x85; test[1] = 0x3F; test[2] = 0x85; test[3] = 0x34; test[4] = 0x85; tes...
2019-08-12 16:57:39
6172
原创 C++ 重载和继承使用的分析
#include <stdlib.h>#include <stdio.h>#include <iostream>#include <memory>class h2o{public: virtual void hasH2o(void) = 0;};class person{public: person(); virt...
2019-07-30 13:43:56
136
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人