Compare commits

...

194 Commits

Author SHA1 Message Date
openharmony_ci
c18b51182b !759 fix: MMU竞态问题修复
Merge pull request !759 from Harylee/mmu
2022-01-10 13:07:43 +00:00
openharmony_ci
d6dc0642c5 !764 Codex告警清除
Merge pull request !764 from xuxinyu/master
2022-01-10 04:56:46 +00:00
Haryslee
748e0d8ffb fix: MMU竞态问题修复
背景:同一个进程的多个线程读写同一个PTE时,由于PTE无保护,存在竞态问题。
方案:新增spinlock保护PTE,包括大锁跟小锁。大锁:一个进程只有一个spinlock锁,多个线程
读写PTE时竞争一把锁,锁的内存占用小,但系统性能降低;小锁:每个页表持有一把spinlock,
由于锁是page结构体的一个字段,内存消耗较大,但是相对大锁性能较优。系统默认使用大锁,用
户可根据具体需要配置使用大锁还是小锁。

close #I2WARC

Signed-off-by: Haryslee <lihao189@huawei.com>
Change-Id: I5612eeac1f65507160035eae16af61f285182eda
2022-01-08 14:55:45 +08:00
x-xiny
1cdd7307f3 Codex告警清除
【背景】
 Codex扫描告警清除

【修改方案】
 将不可屏蔽告警进行修复

 re #I4PNO3

 Signed-off-by: xuiny <xuxinyu6@huawei.com>

Change-Id: If6f85eb9679d47e6256f24cdc74246df78da579d
2022-01-07 09:49:47 +00:00
openharmony_ci
9995d8e0e4 !749 Clang triple renaming
Merge pull request !749 from maweiye/master
2022-01-07 03:19:25 +00:00
openharmony_ci
0ca4a128d2 !763 fix: 修复 virpart.c 不适配的格式化打印问题
Merge pull request !763 from Far/master
2022-01-07 02:08:49 +00:00
Far
de29140edf fix: 修复 virpart.c 不适配的格式化打印问题
Close #I4PEVP

Signed-off-by: Far <yesiyuan2@huawei.com>
2022-01-05 10:59:50 +08:00
openharmony_ci
997e61ed53 !756 fix: 修复重复执行内存用例导致系统卡死问题
Merge pull request !756 from Harylee/print
2021-12-30 08:23:14 +00:00
Haryslee
6c2b163c7d fix: 修复重复执行内存用例导致系统卡死问题
背景:重复执行内存测试用例约几百次,系统大概率出现卡死现象,经分析知,系统卡在
内存spinlock锁中,CPU1在获取内存spinlock锁后打印异常信息,此时循环buffer满了,
CPU0此时进入异常且尝试拿取内存spinlock锁,两个核都处于锁中断锁任务状态,CPU1
写事件触发调度打印输出失败,进而在write接口中死循环无法退出,导致两个核都卡住。
方案:在write接口中增加一个判断条件:当前核处于锁任务状态且循环buffer满了时候,
直接退出循环,丢弃打印信息(持有spinlock锁后一般禁止输出打印信息)。

close #I4F7PO

Signed-off-by: Haryslee <lihao189@huawei.com>
Change-Id: I3f49a1bb211821e9c5d1d220d6867962d6a45a79
2021-12-29 14:27:43 +08:00
openharmony_ci
979a8a8f27 !738 fix: 修复xts权限用例压测异常问题
Merge pull request !738 from Harylee/readme
2021-12-25 02:10:18 +00:00
openharmony_ci
b6f9dbbdba !747 修改procfs默认权限为550
Merge pull request !747 from LeonChan/master
2021-12-24 09:03:50 +00:00
maweiye
e567467b8a clang triple renaming
Signed-off-by: maweiye <maweiye@huawei.com>
2021-12-24 16:43:41 +08:00
Leon Chan
a776c04a3d fix: change default permission of procfs to 0550
close: #I4NY49

Signed-off-by: Leon Chan <chenwei26@huawei.com>
2021-12-24 12:03:58 +08:00
openharmony_ci
f7932bd006 !744 LOS_Panic和魔法键功能中的使用PRINTK打印,依赖任务调度,特殊情况下存在打印不出来的问题
Merge pull request !744 from zhangfanfan2/master
2021-12-23 07:08:02 +00:00
Haryslee
b0d31cb43f fix: 修复xts权限用例压测异常问题
用例异常时出现Domain fault或者unknown fault,经分析发现是TLB缓存一致性问题,
在缺页异常入口,对上述两种异常类型做异常地址TLB缓存清理即可。

close #I3ZJ1D

Signed-off-by: Haryslee <lihao189@huawei.com>
Change-Id: Ib84e3e87047fcac392b83a4cf6cca0d91754e66f
2021-12-23 08:50:43 +08:00
zff
53addea304 fix: LOS_Panic和魔法键功能中的使用PRINTK打印,依赖任务调度,特殊情况下存在打印不出来的问题
close: #I4NOC7

Signed-off-by: zff <zhangfanfan2@huawei.com>
Change-Id: I7f28e79293d3388e2b1d7208c2b8ff8ff133528a
2021-12-22 17:02:58 +08:00
openharmony_ci
954e7eb0cf !735 支持产品定制化hilog内核缓存大小
Merge pull request !735 from shenchenkai/master
2021-12-18 06:52:23 +00:00
shenchenkai
0e48a0dd12 Description:[feature] support customized hilog ring buffer size
Change-Id: I5d23deaada5939bbb6fb57505f72c2348bd6afe9
Signed-off-by: shenchenkai <shenchenkai@huawei.com>
2021-12-17 15:45:53 +08:00
openharmony_ci
52c12f7c9d !730 【轻量级PR】 console.c 分支优化
Merge pull request !730 from 雷电_SWAT/master
2021-12-16 04:26:19 +00:00
openharmony_ci
1e875d921b !734 fix: Watchdog test case repair
Merge pull request !734 from 尹树清/master
2021-12-15 02:59:56 +00:00
openharmony_ci
1db7aa7ada !733 refactor:los_cir_buf.c接口整合
Merge pull request !733 from Zhaotianyu/1213cirbuf_refactor
2021-12-15 01:46:39 +00:00
openharmony_ci
6a0c169780 !732 内核的编译框架在做编译入口的统一
Merge pull request !732 from wangchen/kernel_build
2021-12-15 01:09:40 +00:00
wangchen
bdb9864436 fix: 编译框架在做编译入口的统一
【背景】编译框架在做编译入口的统一,a核两种编译方式生成结果有差异

【修改方案】
1,修改kernel依赖

【影响】
对现有的产品编译不会有影响。

re #I4KRQN
Signed-off-by: wangchen <253227059@qq.com>
2021-12-14 13:19:31 +00:00
yinshuqing
bc69ca104c Watchdog test case repair
Signed-off-by: yinshuqing <yinshuqing@huawei.com>
2021-12-14 20:28:32 +08:00
arvinzzz
0d325c56a1 refactor: los_cir_buf.c中接口整合
将循环buf的上/解锁操作合进读/写操作里,删除对外上/解锁接口

BREAKING CHANGE:
1. 删除 LOS_CirBufLock(),LOS_CirBufUnlock()内核对外接口
2. LOS_CirBufWrite(),LOS_CirBufRead()由原先内部不进行上/解锁操作,变为默认已包含上/解锁操作。

close: #I4MC13

Signed-off-by: arvinzzz <zhaotianyu9@huawei.com>
Change-Id: Ie3cc1abde7fa0e5479ccbf4e596426e509b5cef5
2021-12-14 11:00:36 +08:00
openharmony_ci
5bed688ca6 !731 【请求检视】fix: 修复LOSCFG_FS_FAT_CACHE宏关闭后编译失败的BUG
Merge pull request !731 from Far/master
2021-12-13 10:03:58 +00:00
Far
63e71feca0 fix: 修复LOSCFG_FS_FAT_CACHE宏关闭后编译失败的BUG
1. 在必要处增加宏开关关闭部分代码的编译;
2. 由于驱动是一个独立的内核线程,在一些场景下文件系统会将用户态地址透传给驱动,这会导致内核崩溃。
因此在需要透传用户态地址时增加了一个内核buffer作为中转。

Close #I3T3N0

Signed-off-by: Far <yesiyuan2@huawei.com>
2021-12-13 15:01:16 +08:00
lcjh
2ada41c826 分支优化
去除不必要分支,使用三元操作符优化简单分支
Signed-off-by: lcjh <120989324@qq.com>
2021-12-11 12:35:41 +08:00
openharmony_ci
9b397173fe !728 移除顶层BUILD.gn中的visibility属性设置
Merge pull request !728 from Caoruihong/remove_visibility
2021-12-08 13:57:00 +00:00
openharmony_ci
2fa85a2c72 !703 fix: 解决dmesg -s参数double lock问题
Merge pull request !703 from Kiita/1109_dmesg
2021-12-08 10:56:48 +00:00
Caoruihong
63a0fcaefb chore(build): remove visibility of the top BUILD.gn
Signed-off-by: Caoruihong <crh.cao@huawei.com>
Change-Id: I83616f794d169c8637ab79b2dd96d3858d11fce7
2021-12-08 17:55:07 +08:00
openharmony_ci
144214869f !643 添加对GCC工具链的支持
Merge pull request !643 from Caoruihong/support_gcc
2021-12-08 07:20:38 +00:00
Kiita
e1512566e3 fix: 解决dmesg -s参数double lock问题
【背景】自研shell或者mksh拉起后使用dmesg -s命令出现自旋锁double lock的问题。

【修改方案】
dmesg -s参数设置dmesg缓冲区过程需要访问UartOutput所访问的全局缓冲区,这意味着两个功能模块
使用了同一把自旋锁,若在dmesg命令执行过程使用了打印,则就可能会导致double lock。因此拆分
了dmesg -s命令过程中自旋锁的使用区域,避开内核中必要的打印。

re #I4HIJK

Signed-off-by: yansira <yansira@hotmail.com>
Change-Id: Iad74c058c9a8090fd3d9f338caab7d8f2170f9ac
2021-12-06 11:28:07 +08:00
Caoruihong
6e886d4233 feat(build): support gcc toolchain
Signed-off-by: Caoruihong <crh.cao@huawei.com>
Change-Id: I6f2dea19cbd2e5b562bb51e30592205a2bb4fbdb
2021-12-05 02:49:48 +08:00
openharmony_ci
67e31f7b45 !726 fix: 删除冗余的头文件los_pmm.h
Merge pull request !726 from kenneth/los_pmm.h
2021-12-03 07:02:35 +00:00
openharmony_ci
26c09d26fc !727 fix: 修改MMU模块的注释错误
Merge pull request !727 from kenneth/page_idx
2021-12-03 07:01:51 +00:00
kenneth
1a8e22dcf1 fix: 修改MMU模块的注释错误
修改los_arch_mmu.c中的page_idx 为scanIndex,修改pmm_alloc_page为LOS_PhysPageAlloc。

fix #I4KMMJ

Signed-off-by: kenneth <zhushangyuan@huawei.com>
2021-12-03 11:07:18 +08:00
kenneth
8e614bb161 fix: 删除冗余的头文件
删除无用的头文件kernel\base\include\los_pmm.h

fix #I4KN63

Signed-off-by: kenneth <zhushangyuan@huawei.com>
2021-12-03 10:59:20 +08:00
openharmony_ci
f88608e5a4 !722 内核ERR打印,无进程和线程信息,不方便问题定位
Merge pull request !722 from zhangfanfan2/other3
2021-12-03 02:38:15 +00:00
openharmony_ci
30d5badbce !723 用户态进程主线程退出时,其他子线程刚好进入异常处理流程会导致系统卡死
Merge pull request !723 from zhangfanfan2/master
2021-12-03 02:37:54 +00:00
openharmony_ci
c8c07261ca !724 fix: los_stat_pri.h中缺少依赖的头文件
Merge pull request !724 from zhushengle/sched
2021-12-01 07:48:13 +00:00
zhushengle
2cd03c55b7 fix: los_stat_pri.h中缺少依赖的头文件
在los_stat_pri.h中添加los_typedef.h

Close #I4KEZ1

Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: I19f8b79f9f559e1324432280f123a911bf8caf27
2021-12-01 09:24:52 +08:00
openharmony_ci
b3489d49d7 !721 feat: 提供低功耗默认处理框架
Merge pull request !721 from zhushengle/pm
2021-11-30 09:51:39 +00:00
zff
d955790a44 fix: 用户态进程主线程退出时,其他子线程刚好进入异常处理流程会导致系统卡死
接口OsTaskExitGroup被同一个进程的两个互等线程重入,逻辑出现死循环,导致系统卡死

close: #I4KGBT

Signed-off-by: zff <zhangfanfan2@huawei.com>
Change-Id: I484bba67473f7d0edbfdff95549ffb32bffb4988
2021-11-30 16:14:22 +08:00
zhangfanfan2
540b2017c5 fix: 内核ERR级别及以上的打印输出当前进程和线程名
Signed-off-by: zff <zhangfanfan2@huawei.com>
2021-11-30 07:41:03 +00:00
zhushengle
212d1bd1e8 feat: 提供低功耗默认处理框架
添加系统在不同低功耗下的默认处理函数。
Close #I4KBG9

Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: I7d9a32d03daf32998f4cfca17c57b3f0e614d4ac
2021-11-30 10:49:47 +08:00
openharmony_ci
ba8438257a !715 feat: 支持L1 低功耗框架
Merge pull request !715 from zhushengle/pm
2021-11-29 07:04:55 +00:00
zhushengle
64e49aba7c feat: 支持L1 低功耗框架
方案描述:
   和L0保持一致,上层通过proc文件系统操作:
   power_mode  支持的低功耗模式,通过对该文件进行write操作可以设置低功耗模式
   power_count powermanager模块通过对该文件操作,和内核进行交互,简要流程如下:
     while (1) {
       open  // 打开该文件
       read  // 使powermanager低功耗任务常阻塞,当系统无任何模块持锁时,会唤醒该任务
       write // 进行低功耗流程
       close // 关闭该文件
     }
   power_lock    write该文件,持锁
   power_unlock  writw该文件,释放锁

Close #I4JSO

Change-Id: I73fcdeeb5e2039484b3351a81b46a0892b349fe9
Signed-off-by: zhushengle <zhushengle@huawei.com>
2021-11-29 11:58:47 +08:00
openharmony_ci
3e7cfaa520 !708 feat: L0-L1 支持Lms轻量级地址消毒
Merge pull request !708 from LiteOS/lms
2021-11-27 07:07:52 +00:00
LiteOS2021
e748fdbe57 feat: L0~L1 支持Lms
1.【需求描述】:
   支持内核态和用户态堆内存非法访问检测,包括:越界访问、double free、释放后使用;支持libc常用高频函数内存检测;支持安全函数内存检测;读写检测可配可裁剪。
2.【方案描述】:
   L0 ~ L1:
   (1).影子内存映射与标记
   (2).编译器使能-fsanitize=kernel-address 自动插桩检测点
   (3).实时校验影子内存的合法性;
   (4).错误访问打印回溯栈

BREAKING CHANGE: 新增支持API:

LOS_LmsCheckPoolAdd使能检测指定内存池
LOS_LmsCheckPoolDel不检测指定内存池
LOS_LmsAddrProtect为指定内存段上锁,不允许访问
LOS_LmsAddrDisableProtect去能指定内存段的访问保护

Close #I4HYAV

Signed-off-by: LiteOS2021 <dinglu@huawei.com>
Change-Id: Id8e5c890656da9edc4a22227e6a3c32205c024ce
2021-11-27 11:13:41 +08:00
openharmony_ci
48f645db84 !717 refactor:内核安全函数库编译复用三方目录安全函数库中的配置
Merge pull request !717 from Zhaotianyu/1125libsec
2021-11-26 06:46:02 +00:00
arvinzzz
d73aff846b refactor: 内核编译安全函数库复用三方安全函数库中的配置清单,减少冗余
close: #I4JUKM

Signed-off-by: arvinzzz <zhaotianyu9@huawei.com>
Change-Id: I30115a12b9244ac4821c443a838aa248b47d4fb9
2021-11-26 11:04:12 +08:00
openharmony_ci
ce4323ff16 !704 【fix】smp启动时副核冗余的启动框架调用
Merge pull request !704 from Zhaotianyu/1110smpinit_fix
2021-11-25 22:48:51 +00:00
openharmony_ci
f6a7003c16 !711 硬件随机数配置选项增加arm virt平台支持
Merge pull request !711 from laokz/rng
2021-11-25 13:57:33 +00:00
openharmony_ci
c12bef84b2 !716 [LTS-3.0]修复jffs2适配层错误释放锁的BUG
Merge pull request !716 from Far/cherry-pick-1637845785
2021-11-25 13:56:13 +00:00
openharmony_ci
7a7c67cbdd !712 修复jffs2适配层错误释放锁的BUG
Merge pull request !712 from Far/master
2021-11-25 13:56:12 +00:00
Far
d2a2f96adf fixed 011a55f from https://gitee.com/yesiyuanjim/kernel_liteos_a/pulls/712
fix: 修复jffs2适配层错误释放锁的BUG

修复重复释放jffs2全局锁的BUG

Close #I4FH9M

Signed-off-by: Far <yesiyuan2@huawei.com>
2021-11-25 13:09:48 +00:00
openharmony_ci
5db6c62313 !710 清理YES/NO宏
Merge pull request !710 from Caoruihong/remove_yesno
2021-11-18 09:32:42 +00:00
Far
011a55ff21 fix: 修复jffs2适配层错误释放锁的BUG
修复重复释放jffs2全局锁的BUG

Close #I4FH9M

Signed-off-by: Far <yesiyuan2@huawei.com>
2021-11-18 14:22:25 +08:00
laokz
68f9f49c2a fix(arm-virt): HW_RANDOM_ENABLE配置支持arm virt平台
Signed-off-by: laokz <laokz@foxmail.com>
Change-Id: Idb6b7327d3773abe2ddf0cbc4996650d96c85887
2021-11-17 11:41:51 +08:00
openharmony_ci
fe4082ca9e !709 A核代码静态告警定期清理
Merge pull request !709 from wangchen/1112_codex
2021-11-16 06:47:22 +00:00
openharmony_ci
ac08912230 !706 fix: 修复los_vm_scan.c中内部函数OsInactiveListIsLow冗余代码
Merge pull request !706 from kenneth/los_vm_scan
2021-11-16 00:48:50 +00:00
openharmony_ci
a32a7c4fad !707 chore: 优化函数OsVmRegionRightCheck命名
Merge pull request !707 from kenneth/OsVmRegionRightCheck
2021-11-16 00:48:26 +00:00
Caoruihong
bba832ea08 chore: replace YES/NO macros to 1/0
Signed-off-by: Caoruihong <crh.cao@huawei.com>
Change-Id: I40e31e82c33418019c1afc16ac174919e72fbb07
2021-11-16 01:27:06 +08:00
openharmony_ci
09fd11bc38 !705 清理"bits/xxx.h"类头文件包含
Merge pull request !705 from Caoruihong/clean_bits
2021-11-15 09:35:09 +00:00
lnlan
9ba725c3d4 fix: A核代码静态告警定期清理
【背景】A核代码静态告警定期清理

【修改方案】
1,根据codex等工具分析结果,进行必要的规范等问题修改

【影响】
对现有的产品编译不会有影响。

re #I4I0O8
Signed-off-by: wangchen <253227059@qq.com>
2021-11-15 02:47:08 +00:00
kenneth
2bddff54c8 chore: 优化函数OsVmRegionRightCheck命名
函数名称OsVmRegionRightCheck修改为OsVmRegionPermissonCheck进行内存区间权限检查

close #I4HR6I

Signed-off-by: kenneth <zhushangyuan@huawei.com>
2021-11-11 19:52:25 +08:00
kenneth
bc32a1ec0f fix: 修复los_vm_scan.c中内部函数OsInactiveListIsLow冗余代码
函数OsInactiveListIsLow()和InactiveListIsLow()代码重复,删除冗余代码。

close #I4HKFF

Signed-off-by: kenneth <zhushangyuan@huawei.com>
2021-11-11 19:44:34 +08:00
Caoruihong
5d5df3a5d7 chore: clean "bits/xx.h" includes
Signed-off-by: Caoruihong <crh.cao@huawei.com>
Change-Id: I3dcf576ceba66b0fa447573e997d064026eb8785
2021-11-11 12:03:56 +08:00
openharmony_ci
07cab40473 !696 chore: 修复社区反馈问题Percpu结构体注释错误
Merge pull request !696 from kenneth/core_typo
2021-11-11 01:29:52 +00:00
arvinzzz
5ce70a50c3 fix: smp初始化中副核冗余的启动框架调用
close: #I4F8A5

Signed-off-by: arvinzzz <zhaotianyu9@huawei.com>
Change-Id: I9a863d3265fd18051d8bfcaab51ad59216630e91
2021-11-10 19:14:29 +08:00
kenneth
0f878febb7 chore: 修复社区反馈问题Percpu结构体注释错误
修复社区反馈问题Percpu结构体注释错误,排查下其他拼写错误。

close #I4GMLH

Signed-off-by: kenneth <zhushangyuan@huawei.com>
2021-11-10 10:20:33 +08:00
openharmony_ci
f63ce99399 !692 chore: 修复内存模块的一些不规范用语
Merge pull request !692 from kenneth/mmu_fix
2021-11-10 02:06:29 +00:00
openharmony_ci
e317f9b5b5 !702 fix: shell支持exit退出,完善帮助信息,特殊处理不可见字符
Merge pull request !702 from huangshan/chore
2021-11-09 09:26:47 +00:00
huangshan
cc6e11281e fix: shell支持exit退出,完善帮助信息,特殊处理不可见字符
Change-Id: Ia6dbff0faed4ec73fcf35691676f1acb2b8df78d
Signed-off-by: huangshan <huangshan9@huawei.com>
2021-11-08 18:13:38 +08:00
openharmony_ci
9525ca2826 !697 修改blackbox生成的文件和文件夹权限
Merge pull request !697 from mgceshuang/upload_teeee
2021-11-08 02:27:30 +00:00
openharmony_ci
a412bfb275 !686 增加内核epoll系统调用适配musl接口并增加测试用例
Merge pull request !686 from wangchen/tocommit
2021-11-08 01:30:05 +00:00
openharmony_ci
3b8083815c !701 按照门禁要求对所有BUILD.gn脚本进行格式化
Merge pull request !701 from Caoruihong/gnformat
2021-11-06 04:48:29 +00:00
Caoruihong
a2fed9a56c chore(build): format all BUILD.gn files
Signed-off-by: Caoruihong <crh.cao@huawei.com>
Change-Id: Ifd3bf13f53a27e0a0bbd051cf35662e7409e6ed0
2021-11-06 11:55:58 +08:00
lnlan
2251b8a2d1 fix: 增加内核epoll系统调用
【背景】增加内核epoll系统调用适配musl接口并增加测试用例

【修改方案】
1, 删除musl仓的porting
2,内核实现epoll对应接口及注册系统调用
3,testsuit目录添加对应的用例

【影响】
对现有的产品编译不会有影响。

re #I4FXPT
Signed-off-by: wangchen <253227059@qq.com>

Change-Id: Ia97ea49067aa1ff47b8c1c83675ac75e75d25955
2021-11-05 08:17:43 +00:00
openharmony_ci
5077b1793f !693 fix: 修复Ctrl+C会终止所有进程的问题
Merge pull request !693 from huangshan/fix-pgrp
2021-11-05 05:58:22 +00:00
openharmony_ci
e99aba9d0f !695 feat: 进程cpup占用率结构优化为动态分配
Merge pull request !695 from zhushengle/cpup
2021-11-04 09:03:24 +00:00
YOUR_NAME
eedde91826 Modify folder and file permissions
Signed-off-by: YOUR_NAME <mashuang9@huawei.com>
2021-11-04 14:50:42 +08:00
huangshan
cdc0877f16 修复Ctrl+C会终止所有进程的问题
Signed-off-by: huangshan <huangshan9@huawei.com>
Change-Id: I5861569c63fd6c1adf8c702797e4d79eba76211f
2021-11-04 12:23:20 +08:00
openharmony_ci
0f8ff8f545 !662 fix SYSCALL SysFstat,SysFstat64,SysFstatat64(fix struct kstat with stat) & add 19 IO testcases
Merge pull request !662 from 刘治万/1015_unitest
2021-11-04 01:46:08 +00:00
zhushengle
f06e090a10 feat: 进程cpup占用率结构优化为动态分配
Close #I4GLNT
Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: I7f3dd61bbf014fa157b1f9a0a089fd985fe188c2
2021-11-02 19:57:26 +08:00
openharmony_ci
38163de8f3 !687 feat: liteipc 静态内存优化
Merge pull request !687 from zhushengle/liteipc
2021-11-02 11:05:46 +00:00
openharmony_ci
fcb21ffc8a !676 修复ppoll接口"[ERR]OsMemFree check error!"报错
Merge pull request !676 from pef/ppoll-1
2021-11-02 09:35:09 +00:00
lnlan
2e3bbf1e61 修复ppoll接口"[ERR]OsMemFree check error!"报错
【背景】
1.内核中释放用户空间指针报错:"[ERR]OsMemFree check error!"
2.现有ppoll实现存在问题
3.相关用例需要整理
【修改方案】
1.去掉释放用户空间指针操作
2.更正逻辑错误
3.更正掩码设置与恢复不起作用
4.修复补充现有用例
【影响】
对现有的产品编译不会有影响。

re #I47YWZ

Change-Id: Ib2f60986e9cafb2ea5ef1097ab8552cbb1ede5b4
Signed-off-by: lnlan <lanleinan@163.com>
2021-11-02 07:04:35 +00:00
kenneth
466996b2e1 chore: 修复内存模块的一些不规范用语
layes修正为layers,alreay修正为already,Continous修正为Continuous等等

close #I4GHLR

Signed-off-by: kenneth <zhushangyuan@huawei.com>
2021-11-02 12:01:59 +08:00
zhushengle
52379242c1 feat: liteipc 静态内存优化
Close #I4G4HP
Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: I259c792365d9747f391c5bd275e77f04b83e0792
2021-11-02 11:54:08 +08:00
openharmony_ci
e0a6e1f9f0 !679 fix: 修复OsVmPhysFreeListAdd和OsVmPhysFreeListAddUnsafe函数内容重复
Merge pull request !679 from kenneth/los_vm_phys
2021-11-02 03:00:02 +00:00
openharmony_ci
e54eb9e34d !690 chore: 修复任务调度代码中部分函数、变量命名不规范问题
Merge pull request !690 from kenneth/typos
2021-11-02 02:50:03 +00:00
kenneth
ef1d9f848d chore: 修复任务调度代码中部分函数、变量命名不规范问题
变量readTasks应该为readyTasks;函数OsSchedTaskSwicth应该为OsSchedTaskSwitch;其他拼写错误。

close #I4GFJ7

Signed-off-by: kenneth <zhushangyuan@huawei.com>
2021-11-02 08:49:52 +08:00
openharmony_ci
ebfac57d54 !685 fix: 优化liteipc任务状态,删除功能重复字段
Merge pull request !685 from zhushengle/liteipc
2021-10-30 02:31:41 +00:00
openharmony_ci
3074449c79 !665 修复misc09用例因依赖hosts文件而失败
Merge pull request !665 from lnlan/sys_misc_test_fix
2021-10-30 02:15:26 +00:00
pef
78a297fd4e 修复ppoll接口"[ERR]OsMemFree check error!"报错
【背景】
内核中释放用户空间指针报错:"[ERR]OsMemFree check error!"

【修改方案】
修改SysPpoll函数。

【影响】
对现有的产品编译不会有影响。

re #I47YWZ

Change-Id: Id7f86036870d4f32be8fc438b9aad85cdda59546
Signed-off-by: pef <cyd1997@126.com>
2021-10-29 08:14:20 +00:00
zhushengle
5004ef4d87 fix: 优化liteipc任务状态,删除功能重复字段
LosTaskCB 中 字段waitFlag 用于专门记录任务被阻塞的原因,与ipcStatus 功能重复
Close #I4FVHK

Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: Ie0998b987ba6e1db050596dec3b359e73ca47686
2021-10-29 12:02:00 +08:00
teamol
79839a4325 OOfix SYSCALL SysFstat,SysFstat64,SysFstatat64(fix struct kstat with stat) & add 19 IO testcases
1.modifications:
    modified:   testsuites/unittest/IO/It_test_IO.h
    modified:   testsuites/unittest/IO/full/IO_test_duplocale_001.cpp
    modified:   testsuites/unittest/IO/io_test.cpp
2.add 19 testcases:
    IO_test_dcgettext_001.cpp
    IO_test_dcgettext_002.cpp
    IO_test_dcngettext_001.cpp
    IO_test_dcngettext_002.cpp
    IO_test_dngettext_001.cpp
    IO_test_dngettext_002.cpp
    IO_test_duplocale_001.cpp
    IO_test_locale_001.cpp
    IO_test_ngettext_001.cpp
    IO_test_nl_langinfo_001.cpp
    IO_test_nl_langinfo_l_001.cpp
    IO_test_strcasecmp_l_001.cpp
    IO_test_strfmon_l_001.cpp
    IO_test_strncasecmp_l_001.cpp
    It_stdio_hasmntopt_001.cpp
    IO_test_gettext_001.cpp
    IO_test_locale_002.cpp
    IO_test_strcasecmp_l_002.cpp
    IO_test_strfmon_l_002.cpp
    IO_test_strncasecmp_l_002.cpp
3.influence:
    none

Signed-off-by: liuzhiwan <liuzhiwan2020@163.com>
Change-Id: Ib5883ddb14cfd545f2c5b1685a082f098def0965
2021-10-29 03:05:20 +00:00
openharmony_ci
b2274a009e !683 fix: 非当前进程退出时,销毁liteipc时错误的销毁了当前进程的
Merge pull request !683 from zhushengle/liteipc
2021-10-29 01:51:33 +00:00
teamol
a55f68f957 fix: fix ppoll
1.modifications:
modified:   syscall/fs_syscall.c
2.modify 2 testcases:
IO/full/IO_test_ppoll_001.cpp
IO/full/IO_test_ppoll_002.cpp
3.influence:
none

Signed-off-by: pef <cyd1997@126.com>
Change-Id: I85fc091098a6dfef1a4694a3bbc489640ee6dda2
2021-10-28 11:54:19 +00:00
zhushengle
0f0e85b7a6 fix: 非当前进程销毁时,销毁liteipc时错误的销毁了当前进程的liteipc资源
Close #I4FSA7
Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: I8b24a1e1554b4b867a841bc1b6765cbfd648cdbd
2021-10-28 17:30:54 +08:00
openharmony_ci
308750199f !682 fix: 修复进程process_test_045.cpp用例导致门禁概率失败
Merge pull request !682 from zhushengle/test
2021-10-28 08:18:42 +00:00
openharmony_ci
2f6cd46372 !664 feat: 支持LOS_TaskJoin 和 LOS_TaskDetach
Merge pull request !664 from zhushengle/Join
2021-10-28 08:01:08 +00:00
openharmony_ci
ea45982e1f !669 feat: 进程rlimit修改为动态分配,减少静态内存占用
Merge pull request !669 from zhushengle/rlimit
2021-10-28 02:35:27 +00:00
lnlan
f2f5c5fdc3 fix(test): misc09用例因依赖hosts文件而失败
【背景】
1.etc/hosts文件不存在,misc09依赖hosts文件而失败

【修改方案】
1.用例执行前检查是否存在这些配置文件,不存在就跳过该用例

re#I48IZ0

Change-Id: I193cb03770932c1f681cd726ceb383816aa2257a

Signed-off-by: lnlan <lanleinan@163.com>
Change-Id: I3fb7ca1ed5f8cc79a56cd1872f3b303ab325a7a9
2021-10-28 02:06:08 +00:00
openharmony_ci
91c1737d1b !670 当hilog/hievent驱动缓存出问题时,进行恢复处理
Merge pull request !670 from shenchenkai/master
2021-10-28 02:03:03 +00:00
openharmony_ci
557f4ccb66 !666 复sys部分用例因依赖passwd、group文件而失败
Merge pull request !666 from lnlan/sys_test_fixed
2021-10-28 01:36:46 +00:00
zhushengle
1ed28b4c80 fix: 修复进程用例导致门禁概率失败
Close #I4FO0N
Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: I9dc9819f2ebceaceea337651cc747d737e437661
2021-10-28 09:26:30 +08:00
kenneth
6827bd2a22 fix: 修复OsVmPhysFreeListAdd和OsVmPhysFreeListAddUnsafe函数内容重复
删除OsVmPhysFreeListAdd/OsVmPhysFreeListAddUnsafe、OsVmPhysFreeListDel/OsVmPhysFreeListDelUnsafe两对内部函数内容重复的部分。

close #I4FL95

Signed-off-by: kenneth <zhushangyuan@huawei.com>
2021-10-27 15:35:43 +08:00
lnlan
614cdccf91 fix(test): 修复sys部分用例因依赖passwd、group文件而失败
【背景】
1.sys部分用例因依赖passwd、group文件而失败

【修改方案】
1.用例执行前检查是否存在这些配置文件,不存在就跳过该用例

re#I48IUC

Change-Id: I787ce4b200f2a7546e57290b7dd073127caa07bb
Signed-off-by: lnlan <lanleinan@163.com>
2021-10-27 01:25:38 +00:00
openharmony_ci
23c4f2b81b !673 fix: implicit declaration of function 'syscall' in apps/shell
Merge pull request !673 from uhamc/fix-apps-shell-build
2021-10-26 06:43:57 +00:00
openharmony_ci
d6f48477a4 !658 增加内核pselect系统调用适配musl pselect接口并增加测试用例。
Merge pull request !658 from wangchen/pselect
2021-10-26 01:44:20 +00:00
openharmony_ci
7676cdb886 !656 修复PR520的修改缺陷
Merge pull request !656 from lnlan/sigwait_patch
2021-10-26 01:39:06 +00:00
uhamc
bd0c0835fc fix: implicit declaration of function 'syscall' in apps/shell
Change-Id: Id3f56ac53ec5a3c86b04bcb7a4611f2eb77f4b80
Signed-off-by: uhamc <uhamc@foxmail.com>
2021-10-25 17:12:08 +08:00
openharmony_ci
24ba16a01e !671 fix: 修复进程线程不稳定用例
Merge pull request !671 from zhushengle/test
2021-10-25 03:20:45 +00:00
zhushengle
f6ac03d3e3 fix: 修复进程线程不稳定用例
Close #I4F1XL
Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: Ifdde21a2ff4213218a0fa44ad17af0c15a426758
2021-10-25 10:15:53 +08:00
teamol
f601c16b9e fix: 增加pselect SYSCALL函数及测试用例
1.modifications:
modified:   syscall/fs_syscall.c
modified:   syscall/los_syscall.h
modified:   syscall/syscall_lookup.h
2.add 1 testcases:
modified:   testsuites/unittest/IO/BUILD.gn
modified:   testsuites/unittest/IO/full/IO_test_pselect_001.cpp
modified:   testsuites/unittest/IO/io_test.cpp
3.influence:
none

re #I45SXU
Signed-off-by: wangchen <253227059@qq.com>
Change-Id: I03a5d464fd5423c360e42f7d141035ce0d83d8a8
2021-10-22 09:25:20 +00:00
shenchenkai
c121d0eea3 Description:[fix] clean hilog/hievent ring buffer after memory verification failed
Change-Id: I9310fe807ec95721be78deb60ed9728ef9b56e48
Signed-off-by: shenchenkai <shenchenkai@huawei.com>
2021-10-22 17:00:10 +08:00
zhushengle
cf8446c941 feat: 进程rlimit修改为动态分配,减少静态内存占用
Close #I4EZY5

Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: I47ed0ff7a52f72e38875c3308b20e183cc5c4563
2021-10-22 11:55:52 +08:00
openharmony_ci
e328c528b1 !667 fix: 添加进程线程冒烟用例
Merge pull request !667 from zhushengle/test
2021-10-22 03:16:45 +00:00
zhushengle
2be59680f2 fix: 添加进程线程冒烟用例
Close #I4EOGA
Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: I0f10f81d41564d4d34fc2f89692da0b3211f5918
2021-10-21 14:39:13 +08:00
openharmony_ci
805a67ae2f !661 文件系统Open性能优化
Merge pull request !661 from Far/master
2021-10-20 09:28:40 +00:00
zhushengle
37bc11fa88 feat: 支持LOS_TaskJoin 和 LOS_TaskDetach
Close #I4EENF
Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: Iaa1582f567eb3524262bea383e0b8238b89b5fe2
2021-10-19 14:26:10 +08:00
openharmony_ci
0507b9e8ea !654 内核ERR打印,无进程和线程信息,不方便问题定位
Merge pull request !654 from zhangfanfan2/master
2021-10-18 03:03:28 +00:00
openharmony_ci
acd631c731 !657 【fix】los_trace.h注释修正
Merge pull request !657 from Zhaotianyu/1012trace_fix
2021-10-15 07:42:21 +00:00
Far
c1c2be2a87 refactor: 文件系统Open性能优化
优化包括:
1. 提供VnodeLookupFullpath接口,如果路径是规范化的路径,则调用此接口可减少一次vfs_normalizepath接口的调用;
2. fatfs open钩子函数FIL和buffer同时malloc,减少一次malloc调用,同时去除不必要的数据写回;
3. 其他小细节的优化。

Close #I4E0CT

Signed-off-by: Far <yesiyuan2@huawei.com>
2021-10-15 11:59:38 +08:00
openharmony_ci
bda00e6747 !655 TCB中使用的execFile字段改为execVnode
Merge pull request !655 from LeonChan/execfile
2021-10-15 01:45:58 +00:00
zff
cb423f8454 fix: 内核ERR打印,无进程和线程信息,不方便问题定位。
close: #I4DAKM

Signed-off-by: zff <zhangfanfan2@huawei.com>
Change-Id: I5acc8b2b632633b0717eb4186773e6cae35ea0e4
2021-10-14 19:03:11 +08:00
openharmony_ci
d3b618887a !660 fix: 优化trace buffer初始化,删除swtmr 桩中的无效参数
Merge pull request !660 from LiteOS/master
2021-10-14 02:41:05 +00:00
openharmony_ci
e8f5a286aa !659 ioctl支持SIOCGIFBRDADDR选项
Merge pull request !659 from 刘建东/master
2021-10-14 01:48:15 +00:00
LiteOS2021
b551270ef5 fix: 优化trace buffer初始化,删除swtmr 桩中的无效参数
close #I4DQ1X
Signed-off-by: LiteOS2021 <dinglu@huawei.com>

Change-Id: I79b416720f5327749a5884a65a5e61db07f2a17c
2021-10-14 09:47:11 +08:00
YOUR_NAME
4ecc473843 feat: add option SIOCGIFBRDADDR for ioctl
add option SIOCGIFBRDADDR for ioctl

close: #I4DNRF

Signed-off-by: liujiandong <liujiandong1@huawei.com>
2021-10-13 11:53:49 +08:00
openharmony_ci
8096d9f575 !651 fix: 修复硬随机不可用时,地址随机化不可用问题
Merge pull request !651 from Harylee/shm
2021-10-12 03:25:40 +00:00
arvinzzz
6d249618ae fix: los_trace.h接口注释错误修正
1. LOS_TraceStop接口的功能描述应该是stop

close: #I4CYPZ

Signed-off-by: arvinzzz <zhaotianyu9@huawei.com>
Change-Id: Iee0cf43f6e5ee8e544e233c0c307725c5bfebdcf
2021-10-12 10:30:30 +08:00
lnlan
40338918d9 fix: 修复PR520缺陷
【背景】
https://gitee.com/openharmony/kernel_liteos_a/pulls/520
上面修改,信号处理时才会释放申请的内存,当信号被屏蔽,且一直发送该信号时,
内存占用会不断变大
【修改方案】
1.
信号发送时已经有该信号的siginfo在链表中时,不再重新申请,重复使用之前的siginfo.

【影响】
对现有的产品编译不会有影响。

re#I4DEG5

Signed-off-by: lanleinan <lanleinan@163.com>

Change-Id: I74b3b7ff0b9efb0179313af9a0c8d1e12d1db5bb
2021-10-11 12:37:58 +00:00
openharmony_ci
fd4b97e3f8 !650 通过g_uart_fputc_en关闭打印后,shell进程不能正常启动
Merge pull request !650 from zhangfanfan2/master
2021-10-11 07:46:26 +00:00
openharmony_ci
13e1e70358 !652 OsFutexWaitParamCheck函数中absTime为0时,直接返回,不需要打印
Merge pull request !652 from zhangfanfan2/other
2021-10-11 07:45:35 +00:00
openharmony_ci
c360a97bab !631 fix: 进程在退出前回收vmspace中的所有Region
Merge pull request !631 from zhushengle/process
2021-10-11 03:55:22 +00:00
Haryslee
665c152c27 fix: 修复硬随机不可用时,地址随机化不可用问题
方案:硬随机不可用时,默认使用软随机数代替硬随机数

close #I4D4TK

Signed-off-by: Haryslee <lihao189@huawei.com>
Change-Id: Ia7d2a9583257d7b8041b8994a70a7c36149c33fb
2021-10-11 10:00:08 +08:00
zhangfanfan2
3f71be7535 fix: OsFutexWaitParamCheck函数中absTime为0时,直接返回,不需要打印
当设置的超时时间比较短时,会出现absTime为0的情况,直接返回,不需要阻塞和打印。

close: #I4D67E

Signed-off-by: zff <zhangfanfan2@huawei.com>
2021-10-10 08:49:56 +00:00
zhushengle
298ccea3fe fix: 进程退出前自己回收vmspace中的所有region
背景:
父进程fork一个子进程,调用waitpid等待子进程结束。
子进程dlopen一个文件a.so,并退出。当守护进程正在
1核回收子进程资源时,父进程在0核运行从waitpid返
回后,同时remove a.so概率失败。

Close #I4CKQC

Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: Ie7940e7c931ced10ee357cf9aa7c64355effed49
2021-10-09 12:14:45 +08:00
openharmony_ci
56a92f9207 !641 feat: 支持AT_RANDOM以增强用户态栈保护能力
Merge pull request !641 from Harylee/shm
2021-10-08 06:01:21 +00:00
zff
d21b05c0f6 fix: 通过g_uart_fputc_en关闭打印后,shell进程不能正常启动
console层的实现中复用g_uart_fputc_en用于关闭打印的功能,代码设计上认为
g_uart_fputc_en为0时console层未使能,导致shell进程中ioctl操作失败,shell
进程不能正常启动。

close: #I4CTY2

Signed-off-by: zff <zhangfanfan2@huawei.com>
Change-Id: I0a225c1db42f2b384ad590ca05b048c4b61db99c
2021-10-08 10:01:31 +08:00
openharmony_ci
29df5dc1f2 !646 将menuconfig 与 update_config功能做成一样
Merge pull request !646 from Caoruihong/menuconfig2
2021-09-30 07:19:01 +00:00
Leon Chan
e4a06623ce fix: change the execFile field in TCB to execVnode
TEE需要借用TCB中的execFile来校验打开的文件,pagecache修改后,可执行程序在mmap之后,会被立即关闭,因此将execFile改为execVnode

close: #I4CLL9

Signed-off-by: Leon Chan <chenwei26@huawei.com>
2021-09-30 14:33:36 +08:00
openharmony_ci
e1b36bfe41 !594 临终遗言重定向内容缺失task相关信息,对应的shell命令中申请的内存需要cacheline对齐
Merge pull request !594 from zhushengle/excinfo
2021-09-30 06:17:48 +00:00
Caoruihong
3dd952b0b7 chore(make): make menuconfig same as update_config
Signed-off-by: Caoruihong <crh.cao@huawei.com>
Change-Id: I5c4a1a0601865c1c7d6ae40b829abdb53f13ccd3
2021-09-30 12:04:48 +08:00
Haryslee
06ea03715f feat: 支持AT_RANDOM以增强用户态栈保护能力
背景:不开地址随机化时,用户态栈CANARY值是固定值
方案:支持AT_RANDOM,CANARY从AT_RANDOM获取随机值以增强用户态栈保护能力

close #I4CB8M

Signed-off-by: Haryslee <lihao189@huawei.com>
Change-Id: I28cef09f7016a5096e2096d4f6aa72722fcf1fd7
2021-09-30 10:36:12 +08:00
zhushengle
48ca854bf0 fix: 临终遗言重定向内容缺失task相关信息,对应的shell命令中申请的内存需要cacheline对齐
1.内核打印的地方支持异常时重定向打印信息
2.excinfo 命令中申请的内存64对齐
Close #I482S5

Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: I4e8a971cc5b14f62d573bb160682089d9d50e64e
2021-09-29 16:26:31 +08:00
openharmony_ci
c7da23695c !644 Open lwip netif extern callback interface
Merge pull request !644 from steve/master
2021-09-29 06:43:48 +00:00
openharmony_ci
2c33cfce86 !599 feat: L0~L1 支持Perf
Merge pull request !599 from LiteOS/perf
2021-09-29 06:15:02 +00:00
openharmony_ci
9bf580b1f6 !634 fix(mtd): 去除mtd对hisilicon驱动的依赖
Merge pull request !634 from SimonLi/master
2021-09-29 06:07:44 +00:00
fanxiaoyu
3be31d1cfb Description:open lwip netif extern callback interface
Feature or Bugfix:Feature
Binary Source: No

Signed-off-by: fanxiaoyu <fanxiaoyu3@huawei.com>
2021-09-29 04:06:44 +00:00
openharmony_ci
ee72b21aff !640 中断中调用PRINTK概率卡死,导致系统不能正常响应中断
Merge pull request !640 from zhangfanfan2/master
2021-09-29 02:48:49 +00:00
LiteOS2021
6e0a3f10bb feat: L0-L1 支持Perf
1.【需求描述】:
         L0-L1 支持Perf,提供2种模式的配置, 及3大类型的事件配置:
         2种模式:计数模式(仅统计事件发生次数)、采样模式(收集上下文如任务ID、pc、backtrace等)。
         3种事件类型:CPU硬件事件(cycle、branch、icache、dcache等)、OS软件事件(task switch、mux pend、irq等)、高精度周期事件(cpu          clock)。
    2.【方案描述】:
         L0:
         基于事件采样原理,以性能事件为基础,当事件发生时,相应的事件计数器溢出发生中断,在中断处理函数中记录事件信息,包括当前的pc、当前运         行的任务ID以及调用栈等信息。
         L1:
         新增perf字符设备,位于“dev/perf”,通过对设备节点的read\ioctl,实现用户态perf

    BREAKING CHANGE:
    1.新增一系列perf的对外API,位于los_perf.h中.
    LOS_PerfInit配置采样数据缓冲区
    LOS_PerfStart开启Perf采样
    LOS_PerfStop停止Perf采样
    LOS_PerfConfig配置Perf采样事件
    LOS_PerfDataRead读取采样数据
    LOS_PerfNotifyHookReg 注册采样数据缓冲区的钩子函数
    LOS_PerfFlushHookReg 注册缓冲区刷cache的钩子

    2. 用户态新增perf命令
  【Usage】:
./perf [start] /[start id] Start perf.
./perf [stop] Stop perf.
./perf [read nBytes] Read nBytes raw data from perf buffer and print out.
./perf [list] List events to be used in -e.
./perf [stat] or [record] <option> <command>
         -e, event selector. use './perf list' to list available events.
         -p, event period.
         -o, perf data output filename.
         -t, taskId filter(whiltelist), if not set perf will sample all tasks.
         -s, type of data to sample defined in PerfSampleType los_perf.h.
         -P, processId filter(whiltelist), if not set perf will sample all processes.
         -d, whether to prescaler (once every 64 counts), which only take effect on cpu cycle hardware event.

    Close #I47I9A

Signed-off-by: LiteOS2021 <dinglu@huawei.com>
Change-Id: Ieb9b7483c85d1495df7c55bc0027f4309dff9814
2021-09-28 19:28:34 +08:00
openharmony_ci
e1b85a4570 !636 修正函数声明与定义不一致的问题
Merge pull request !636 from Caoruihong/fix_decl
2021-09-28 07:18:18 +00:00
zff
9726ba11a7 fix: 中断中调用PRINTK概率卡死,导致系统不能正常响应中断
当console层的打印缓冲buffer满且打印任务被饿死时,函数ConsoleOutput会出现在for循环中
不退出的情况,导致中断打印时卡死

close: #I4C9GC

Signed-off-by: zff <zhangfanfan2@huawei.com>
Change-Id: I70b9d7c848dce7d351c5679e7b08049df27a6f10
2021-09-28 15:03:43 +08:00
openharmony_ci
0fa1310a32 !584 OsLockDepCheckIn异常处理中存在g_lockdepAvailable锁嵌套调用,导致死锁异常信息不正常输出
Merge pull request !584 from zhangfanfan2/master
2021-09-28 06:14:00 +00:00
SimonLi
f7d010dfa4 fix(mtd): 去除mtd对hisilicon驱动的依赖
【背景】
1. liteos-a内核drivers/mtd/multi_partition/用到了device/hisilicon下的驱动函数实
现,这样导致三方芯片适配时,会依赖hisilicon的驱动。
2. HDF的mtd驱动提供了这几个函数的实现,但是未暴露头文件出来。

【修改方案】
1. 修改BUILD.gn去除/device/hisilicon的依赖。
2. 修改mtd_partition.c,将hisilicon的头文件改为hdf的头文件依赖。

【遗留问题】
liteos-a内核与HDF mtd驱动的分界线还不明确,导致依赖关系不清楚

close: #I49FKL

Signed-off-by: SimonLi <likailong@huawei.com>
2021-09-28 11:19:42 +08:00
zff
bf030b6bb5 fix: OsLockDepCheckIn异常处理中存在g_lockdepAvailable锁嵌套调用,
导致死锁异常信息不正常输出

close: #I457ZZ

Signed-off-by: zff <zhangfanfan2@huawei.com>
Change-Id: Ic54ece064a4c85103b644dcbe8ed8bbdecbfc491
2021-09-27 21:56:20 +08:00
Caoruihong
63fd8bc39b fix: fix some function declarations
Signed-off-by: Caoruihong <crh.cao@huawei.com>
Change-Id: I3dfcc308de6fc24035d27bc4ed4a65a2d2b6650d
2021-09-27 21:01:46 +08:00
openharmony_ci
7d7cff4c51 !633 fix: codex清理
Merge pull request !633 from Far/master
2021-09-27 08:38:37 +00:00
Far
9ab3e351d3 fix: codex 清理
Close #I4BL3S

Signed-off-by: Far <yesiyuan2@huawei.com>
2021-09-27 14:43:28 +08:00
openharmony_ci
492264b8e6 !629 修复dispatch单词拼写错误。
Merge pull request !629 from pef/typo
2021-09-24 10:32:58 +00:00
openharmony_ci
d59aad1f3a !580 新增解析异常和backtrace信息脚本
Merge pull request !580 from zhangfanfan2/script
2021-09-24 08:29:13 +00:00
pef
9b07aece2d fix: 修复dispatch单词拼写错误。
【背景】
打印有错误单词的提示语
[ERR] Dsipatch signals failed!, ret: 22
这里单词应该是 dispatch 。
【修改方案】
1. 将Dsipatch改为Dispatch。

【影响】
对现有的产品编译不会有影响。

re #I4BLE8

Change-Id: I26d4336d6d7f7bfc4811819be0a1e8ba9d7d50a8
Signed-off-by: pef <cyd1997@126.com>
2021-09-24 03:45:08 +00:00
openharmony_ci
de8bd2866a !609 三方库FatFs升级至r0.14a版本
Merge pull request !609 from Far/fatfs_update
2021-09-24 00:53:43 +00:00
openharmony_ci
1150f86d46 !628 fix: 共享内存问题修复
Merge pull request !628 from Harylee/shm
2021-09-24 00:31:51 +00:00
Haryslee
9fdb80f85f fix: 共享内存问题修复
Signed-off-by: Haryslee <lihao189@huawei.com>
背景:父进程移除共享内存并标记SHM_SEG_REMOVE,当子进程资源回收时在
ShmFindSeg接口中判断该共享内存具有SHM_SEG_REMOVE时返回空,但是此时
seg->ds.shm_nattch不为0,不应返回空。
方案:ShmFindSeg接口中增加seg->ds.shm_nattch为0的判断。

close #I47X2Z

Change-Id: I8735cd11ac237b17fa745c50313da0fd0649bb9f
2021-09-23 21:04:36 +08:00
openharmony_ci
93e74c5f0b !520 修复sigwait等待到的信号值与获取的siginfo中的值不一致
Merge pull request !520 from lnlan/fixed_sigwait
2021-09-23 03:22:04 +00:00
Far
d23f2fc73f feat:适配三方库FatFs升级至r0.14a版本
适配了_mkfs和find_volume接口的修改

Signed-off-by: Far <yesiyuan2@huawei.com>
2021-09-22 15:00:40 +08:00
openharmony_ci
c0721f4f0b !626 处理链接器失败时关闭打开的文件
Merge pull request !626 from LeonChan/codex
2021-09-18 09:41:31 +00:00
Leon Chan
a375bf5668 fix: close file when process interpretor failed
close: #I4ATQX

Signed-off-by: Leon Chan <chenwei26@huawei.com>
2021-09-18 15:02:22 +08:00
openharmony_ci
52d1d8d8d0 !623 procfs 使用统一的权限
Merge pull request !623 from LeonChan/procfs_mode
2021-09-16 11:35:42 +00:00
Leon Chan
c79bcd028e fix: same file mode for procfs files
close: #I4ACTC

Signed-off-by: Leon Chan <chenwei26@huawei.com>
2021-09-16 16:18:02 +08:00
openharmony_ci
ecd9ca7781 !534 pagecache从filep改为使用vnode
Merge pull request !534 from LeonChan/pg
2021-09-15 03:51:50 +00:00
Leon Chan
38a6b804e9 feat: page cache backed by vnode instead of filep
1, change the owner of page to vnode
2, save the file path in vnode

close: #I44TBS
Signed-off-by: Leon Chan <chenwei26@huawei.com>
2021-09-14 15:31:33 +08:00
openharmony_ci
92f33ab9c4 !620 refactor: 清理Makefile冗余项
Merge pull request !620 from Zhaotianyu/0911refactor_makefile
2021-09-13 12:33:41 +00:00
arvinzzz
b3d96d166c refactor: 清理Makefile冗余项
清理Makefile冗余项,各模块Makefile里不需要再次引用公共路径,只需引用私有头文件路径

close: #I49MOO

Signed-off-by: arvinzzz <zhaotianyu9@huawei.com>
Change-Id: I2dd7189c866498896461f78bfed5444ae1d86876
2021-09-13 18:14:15 +08:00
openharmony_ci
0326cbf12e !619 简化make脚本
Merge pull request !619 from Caoruihong/opt_make_scripts
2021-09-10 07:53:14 +00:00
lnlan
c3facd1b95 fix: 修复sigwait等待到的信号值与获取的siginfo中的值不一致
【背景】
集成测试发送两个不同的信号,sigwait第二次等到的仍是第一个信号
经定位,信号在kill时会将相关的siginfo信息拷贝到taskcb的unbinfo中,sigwait
处理时从unbinfo拷贝给用户。若此信号发送时处于屏蔽状态,再有其他信号发送会覆盖
掉unbinfo,此时sigwait等待这个信号获取到的info已经被覆盖
【修改方案】
1. 每个任务添加一个siginfo缓存链表,在处理信号前夕从缓存链表取出info到unbinfo中

【影响】
对现有的产品编译不会有影响。

re #I3M12H

Signed-off-by: lanleinan <lanleinan@163.com>

Change-Id: If4b064c18773f8eca7419c665977260167b09810
2021-09-10 03:21:58 +00:00
openharmony_ci
8713997548 !617 syscall review bugfix
Merge pull request !617 from 野生毛霉君/master
2021-09-09 14:53:55 +00:00
Caoruihong
a627cdba0c chore(make): simplify build scripts
remove redundant script codes

Signed-off-by: Caoruihong <crh.cao@huawei.com>
Change-Id: I67695a69cccefc220ede55add9372bce0c59d7f5
2021-09-09 18:56:47 +08:00
mucor
214f44e935 fix: syscall review bugfix
close: #149BPF
Signed-off-by: mucor <mucorwang@gmail.com>
2021-09-09 15:19:03 +08:00
openharmony_ci
ba977dd5ab !605 refactor: 内核目录结构整理
Merge pull request !605 from Zhaotianyu/0902dir_refactor
2021-09-09 01:23:33 +00:00
openharmony_ci
1ecacc15b1 !593 feat: add sync() to vfs
Merge pull request !593 from MGY917/sync
2021-09-08 08:56:12 +00:00
arvinzzz
33d0c1bd0b refactor: 内核目录结构整理
1. 原kernel/common目录下属于内核拓展组件,统一移入kernel/extend管理
2. Kconfig分层,各模块自己的配置放到自己目录下管理
3. 原platform下不属于平台的公共代码抽到kernel/common下,只留板级链接脚本和一些编译脚本指向device目录下触发平台相关的编译
4. 对外公共头文件统一抽到对外include路径
5. 废弃宏,头文件清理

close: #I48KI4

Signed-off-by: arvinzzz <zhaotianyu9@huawei.com>
Change-Id: I0cf5ea81c92a8fa7b113da9cbdc8b7bc935f5aae
2021-09-08 16:36:28 +08:00
openharmony_ci
e095e87682 !574 fix: solve SIGCHLD ignored in sigsuspend()
Merge pull request !574 from MGY917/sigsuspend
2021-09-08 08:27:12 +00:00
openharmony_ci
597ced7948 !595 fix: dyload open close failed
Merge pull request !595 from MGY917/dyload_fd
2021-09-08 08:26:55 +00:00
Guangyao Ma
f67c4dae51 feat: add sync() to vfs
新增sync方法,该方法每次调用,会遍历系统内所有的mount点,调用各个文件系统注册
的sync方法,完成对所有已挂载文件系统的sync操作。

close #I480HV

Signed-off-by: Guangyao Ma <guangyao.ma@outlook.com>
Change-Id: I57ced9c3f7685a448defd17ae56c842796b5668f
2021-09-08 15:41:52 +08:00
Guangyao Ma
5e87d8c183 fix: dyload open close failed
本次提交修复内核加载器,异常情况分支的一个bug:mksh通过exec命令(mksh内置命令
,正常情况下,该命令成功执行会复用mksh进程空间,拉起新的指定进程)。但是如果
进程没有成功加载的情况下,内核加载器的异常分支会错误释放mksh的fd句柄。最终导致
下次拉起其他进程时(fork + exec方式),新的进程会继承fd,映射了早就释放的sysfd
,此时的sysfd可能已经被复用,issue场景下这个sysfd被加载过程中打开的libc.so占用
,exec时会释放procfd->sysfd(错误的映射关系),最终新进程libc.so被关闭。
导致内核崩溃。

close #I452Z7

Signed-off-by: Guangyao Ma <guangyao.ma@outlook.com>
Change-Id: Ifca809f88b5ffcfb879dc5520d1f6adf5cf92bcd
2021-09-07 16:28:37 +08:00
YOUR_NAME
7019fdfcbb feat: 新增解析异常和backtrace信息脚本
close: #I47EVQ

Signed-off-by: zff <zhangfanfan2@huawei.com>
Change-Id: Id9c373bf6b36cda024317f927974b08ca61fd9ec
2021-08-27 15:09:50 +08:00
Guangyao Ma
5a80d4e1a3 fix: solve SIGCHLD ignored in sigsuspend()
在如下场景signal可能得不到及时处理:
1、进程A设置信号a阻塞
2、进程A收到信号a
3、进程A调用sigsuspend结束阻塞
原则上,步骤三应该立刻处理之前被阻塞的信号a,调用信号处理函数,并且sigsuspend
返回。现在的问题是,信号a没有得到及时处理,并且进程A阻塞在sigsuspend()调用流程
。
本次修改,在1、2、3场景下,sigsuspend()处理过程中,如果发现已经收到信号,待处理
时,会立刻进行调度切换,再次调度回来时,在调度模块中,会先主动处理已经收到的信
号,最后sigsuspend返回用户态。

close #I47CKK

Signed-off-by: Guangyao Ma <guangyao.ma@outlook.com>
Change-Id: I1b30a938a2d18c3f58989d40eee0503ceffb27b5
2021-08-26 15:36:13 +08:00
449 changed files with 14858 additions and 4055 deletions

162
BUILD.gn
View File

@@ -29,17 +29,14 @@
import("//build/lite/config/component/lite_component.gni")
LITEOS_MENUCONFIG_H = rebase_path("$root_out_dir/config.h")
declare_args() {
tee_enable = false
liteos_name = "OHOS_Image"
liteos_skip_make = false
}
cmd = "if [ -f $device_path/BUILD.gn ]; then echo true; else echo false; fi"
HAVE_DEVICE_SDK = exec_script("//build/lite/run_shell_cmd.py", [ cmd ], "value")
LITEOS_MENUCONFIG_H = rebase_path("$root_out_dir/config.h")
tee = ""
if (tee_enable) {
tee = "_tee"
@@ -49,29 +46,27 @@ declare_args() {
liteos_config_file = "${ohos_build_type}${tee}.config"
}
liteos_config_file = rebase_path(liteos_config_file, "", "$product_path/kernel_configs")
liteos_config_file =
rebase_path(liteos_config_file, "", "$product_path/kernel_configs")
print("liteos_config_file:", liteos_config_file)
exec_script("//build/lite/run_shell_cmd.py",
[
"env" +
" CONFIG_=LOSCFG_" +
" KCONFIG_CONFIG_HEADER='y=true'" +
" KCONFIG_CONFIG=$liteos_config_file" +
" DEVICE_PATH=$device_path" +
" srctree=" + rebase_path(".") +
" genconfig" +
" --header-path $LITEOS_MENUCONFIG_H" +
" --file-list kconfig_files.txt" +
" --env-list kconfig_env.txt" +
" --config-out config.gni",
], "", [ liteos_config_file ])
[ "env" + " CONFIG_=LOSCFG_" + " KCONFIG_CONFIG_HEADER='y=true'" +
" KCONFIG_CONFIG=$liteos_config_file" +
" DEVICE_PATH=$device_path" + " srctree=" + rebase_path(".") +
" genconfig" + " --header-path $LITEOS_MENUCONFIG_H" +
" --file-list kconfig_files.txt" +
" --env-list kconfig_env.txt" + " --config-out config.gni" ],
"",
[ liteos_config_file ])
import("liteos.gni")
assert(ARCH != "", "ARCH not set!")
assert(ARCH == arch, "ARCH not match! details: $ARCH != $arch")
assert(tee_enable == defined(LOSCFG_TEE_ENABLE), "TEE switch not match!")
assert(ohos_build_compiler == "clang" == defined(LOSCFG_COMPILER_CLANG_LLVM),
"compiler not match!")
generate_notice_file("kernel_notice_file") {
module_name = "kernel"
@@ -113,7 +108,7 @@ config("arch_config") {
ldflags = cflags
if (defined(LOSCFG_ARCH_ARM_AARCH32)) {
if (!defined(LOSCFG_COMPILER_CLANG_LLVM)) {
cflags += ["-mthumb-interwork"]
cflags += [ "-mthumb-interwork" ]
}
}
if (defined(LOSCFG_THUMB)) {
@@ -127,7 +122,9 @@ config("arch_config") {
}
config("stdinc_config") {
std_include = exec_script("//build/lite/run_shell_cmd.py", [ "$cc -print-file-name=include" ], "trim string")
std_include = exec_script("//build/lite/run_shell_cmd.py",
[ "$cc -print-file-name=include" ],
"trim string")
cflags = [
"-isystem",
std_include,
@@ -177,7 +174,7 @@ config("optimize_config") {
if (defined(LOSCFG_COMPILER_CLANG_LLVM)) {
cflags += [ "-flto=thin" ]
} else {
cflags += [ "-flto" ]
#cflags += [ "-flto" ]
}
}
cflags += [ optimization_cflag ]
@@ -199,8 +196,10 @@ config("warn_config") {
"-Wpointer-arith",
"-Wstrict-prototypes",
"-Winvalid-pch",
"-Wno-address-of-packed-member",
]
if (defined(LOSCFG_COMPILER_CLANG_LLVM)) {
cflags += [ "-Wno-address-of-packed-member" ]
}
asmflags = cflags
}
@@ -211,6 +210,7 @@ config("dialect_config") {
config("misc_config") {
defines = [ "__LITEOS__" ]
defines += [ "__LITEOS_A__" ]
if (!defined(LOSCFG_DEBUG_VERSION)) {
defines += [ "NDEBUG" ]
}
@@ -250,62 +250,12 @@ config("los_config") {
]
}
executable("liteos") {
configs = [] # clear default configs
configs += [ ":arch_config" ]
configs += [ ":public" ]
ldflags = [
"-static",
"-nostdlib",
"-Wl,--gc-sections",
"-Wl,-Map=$liteos_name.map",
"-Wl,--no-eh-frame-hdr",
]
libgcc = exec_script("//build/lite/run_shell_cmd.py", [ "$cc -print-libgcc-file-name" ], "trim string")
libs = [ libgcc ]
if (defined(LOSCFG_COMPILER_CLANG_LLVM)) {
ldflags += [ "-Wl,-T" + rebase_path("tools/build/liteos_llvm.ld", root_build_dir) ]
inputs = [ "tools/build/liteos_llvm.ld" ]
} else {
ldflags += [ "-Wl,-T" + rebase_path("tools/build/liteos.ld", root_build_dir) ]
ldflags += [ "-Wl,-nostartfiles" ]
inputs = [ "tools/build/liteos.ld" ]
}
inputs += [ "$root_out_dir/board.ld" ]
output_dir = target_out_dir
deps = [
"platform:copy_board.ld",
":modules",
]
}
copy("copy_liteos") {
deps = [ ":liteos" ]
sources = [ "$target_out_dir/unstripped/bin/liteos" ]
outputs = [ "$root_out_dir/$liteos_name" ]
}
build_ext_component("build_kernel_image") {
deps = [ ":copy_liteos" ]
exec_path = rebase_path(root_out_dir)
objcopy = "${compile_prefix}objcopy$toolchain_cmd_suffix"
objdump = "${compile_prefix}objdump$toolchain_cmd_suffix"
command = "$objcopy -O binary $liteos_name $liteos_name.bin"
command += " && sh -c '$objdump -t $liteos_name | sort >$liteos_name.sym.sorted'"
command += " && sh -c '$objdump -d $liteos_name >$liteos_name.asm'"
}
cmd = "if [ -f $device_path/BUILD.gn ]; then echo true; else echo false; fi"
HAVE_DEVICE_SDK = exec_script("//build/lite/run_shell_cmd.py", [ cmd ], "value")
config("public") {
configs = [
"arch:public",
"platform:public",
"kernel:public",
"compat:public",
"bsd:public",
@@ -337,15 +287,14 @@ group("modules") {
"kernel",
"lib",
"net",
"platform",
"security",
"shell",
"syscall",
]
deps += [
HDFTOPDIR,
"//drivers/liteos",
HDFTOPDIR,
]
if (HAVE_DEVICE_SDK) {
@@ -369,10 +318,69 @@ group("liteos_a") {
deps = [
":apps",
":kernel",
":make",
":tests",
"//prebuilts/lite/sysroot/build:strip",
]
}
executable("liteos") {
configs = [] # clear default configs
configs += [ ":arch_config" ]
configs += [ ":public" ]
ldflags = [
"-static",
"-nostdlib",
"-Wl,--gc-sections",
"-Wl,-Map=$liteos_name.map",
"-Wl,--no-eh-frame-hdr",
]
libgcc = exec_script("//build/lite/run_shell_cmd.py",
[ "$cc -print-libgcc-file-name" ],
"trim string")
libs = [ libgcc ]
if (defined(LOSCFG_COMPILER_CLANG_LLVM)) {
ldflags +=
[ "-Wl,-T" + rebase_path("tools/build/liteos_llvm.ld", root_build_dir) ]
inputs = [ "tools/build/liteos_llvm.ld" ]
} else {
ldflags +=
[ "-Wl,-T" + rebase_path("tools/build/liteos.ld", root_build_dir) ]
ldflags += [ "-Wl,-nostartfiles" ]
inputs = [ "tools/build/liteos.ld" ]
}
inputs += [ "$root_out_dir/board.ld" ]
output_dir = target_out_dir
deps = [
":modules",
"platform:copy_board.ld",
]
}
copy("copy_liteos") {
deps = [ ":liteos" ]
sources = [ "$target_out_dir/unstripped/bin/liteos" ]
outputs = [ "$root_out_dir/$liteos_name" ]
}
build_ext_component("build_kernel_image") {
deps = [ ":copy_liteos" ]
exec_path = rebase_path(root_out_dir)
objcopy = "${compile_prefix}objcopy$toolchain_cmd_suffix"
objdump = "${compile_prefix}objdump$toolchain_cmd_suffix"
command = "$objcopy -O binary $liteos_name $liteos_name.bin"
command +=
" && sh -c '$objdump -t $liteos_name | sort >$liteos_name.sym.sorted'"
command += " && sh -c '$objdump -d $liteos_name >$liteos_name.asm'"
}
build_ext_component("make") {
exec_path = rebase_path(".", root_build_dir)
outdir = rebase_path("$target_out_dir/${target_name}_out")

65
Kconfig
View File

@@ -50,7 +50,7 @@ config COMPILER_CLANG_LLVM
config LLVM_TARGET
string "Clang LLVM target"
depends on COMPILER_CLANG_LLVM
default "arm-liteos" if ARCH_ARM_AARCH32
default "arm-liteos-ohos" if ARCH_ARM_AARCH32
endchoice
@@ -94,15 +94,6 @@ source "platform/Kconfig"
######################### config options of cpu arch ################
source "arch/Kconfig"
######################### config options of rootfs #####################
source "kernel/common/rootfs/Kconfig"
######################### config options of patchfs #####################
source "kernel/common/patchfs/Kconfig"
######################### config options of blackbox #####################
source "kernel/common/blackbox/Kconfig"
######################### config options of hidumper #####################
source "kernel/common/hidumper/Kconfig"
config QUICK_START
bool "Enable QUICK_START"
default n
@@ -123,36 +114,7 @@ endmenu
######################## config options of filesystem ##################
menu "FileSystem"
source "fs/vfs/Kconfig"
source "fs/fat/Kconfig"
source "fs/ramfs/Kconfig"
source "fs/romfs/Kconfig"
source "fs/nfs/Kconfig"
source "fs/proc/Kconfig"
source "fs/jffs2/Kconfig"
source "fs/zpfs/Kconfig"
config ENABLE_READ_BUFFER
bool "Enable read buffer Option"
default n
depends on FS_VFS
help
Answer Y to add enable read buffer Option.
config MAX_VNODE_SIZE
int "Vnode max number"
range 0 512
default 512
depends on FS_VFS
help
vnode number, range from 0 to 512.
config MAX_PATH_CACHE_SIZE
int "PathCache max number"
range 0 1024
default 512
depends on FS_VFS
help
pathCache number, range from 0 to 1024.
source "fs/Kconfig"
endmenu
######################## config options of net ############################
@@ -324,29 +286,10 @@ endmenu
######################## config options os drivers ########################
menu "Driver"
config DRIVERS
bool "Enable Driver"
default y
help
Answer Y to enable LiteOS support driver.
source "bsd/dev/usb/Kconfig"
source "../../drivers/adapter/khdf/liteos/Kconfig"
# Device driver Kconfig import
source "$(DEVICE_PATH)/drivers/Kconfig"
source "drivers/char/mem/Kconfig"
source "drivers/char/quickstart/Kconfig"
source "drivers/char/random/Kconfig"
source "drivers/char/video/Kconfig"
source "drivers/char/trace/Kconfig"
source "../../drivers/liteos/tzdriver/Kconfig"
source "../../drivers/liteos/hievent/Kconfig"
source "drivers/Kconfig"
endmenu
######################## config options os security #######################
menu "Security"
source "security/Kconfig"
endmenu

View File

@@ -61,12 +61,6 @@ endif
KCONFIG_CONFIG ?= $(CONFIG)
SYSROOT_PATH ?= $(OUT)/sysroot
LITEOS_MENUCONFIG_H ?= $(LITEOSTOPDIR)/config.h
LITEOS_CONFIG_FILE ?= $(LITEOSTOPDIR)/.config
# export los_config.mk related environment variables
export LITEOS_MENUCONFIG_H
export LITEOS_CONFIG_FILE
# export subdir Makefile related environment variables
export SYSROOT_PATH
@@ -125,7 +119,6 @@ help:
sysroot:
$(HIDE)echo "sysroot:" $(abspath $(SYSROOT_PATH))
ifeq ($(LOSCFG_COMPILER_CLANG_LLVM), y)
ifeq ($(origin SYSROOT_PATH),file)
$(HIDE)mkdir -p $(SYSROOT_PATH)/build && cd $(SYSROOT_PATH)/build && \
ln -snf $(LITEOSTOPDIR)/../../prebuilts/lite/sysroot/build/Makefile && \
@@ -135,20 +128,18 @@ ifeq ($(origin SYSROOT_PATH),file)
ARCH_CFLAGS="$(LITEOS_CORE_COPTS) -w" \
TOPDIR="$(LITEOSTOPDIR)/../.." \
SYSROOTDIR="$(SYSROOT_PATH)" \
CLANG="$(LITEOS_COMPILER_PATH)clang" \
BUILD_ALL_MULTILIB=false \
$(if $(LOSCFG_COMPILER_CLANG_LLVM),CLANG="$(LITEOS_COMPILER_PATH)clang",GCC="$(CC)") \
BUILD_DEBUG=$(if $(patsubst y,,$(or $(RELEASE:1=y),n)),true,false)
endif
endif
$(KCONFIG_CMDS):
$(filter-out menuconfig,$(KCONFIG_CMDS)):
$(HIDE)$@ $(args)
$(LITEOS_CONFIG_FILE): $(KCONFIG_CONFIG)
$(HIDE)env KCONFIG_CONFIG=$< genconfig --config-out $@ --header-path $(LITEOS_MENUCONFIG_H)
update_config:
$(HIDE)test -f "$(CONFIG)" && cp -v "$(CONFIG)" .config && menuconfig && savedefconfig --out "$(CONFIG)"
update_config menuconfig:
$(HIDE)test -f "$(CONFIG)" && cp -v "$(CONFIG)" .config && menuconfig $(args) && savedefconfig --out "$(CONFIG)"
$(LITEOS_LIBS_TARGET): sysroot
$(HIDE)for dir in $(LIB_SUBDIRS); do $(MAKE) -C $$dir all || exit 1; done

View File

@@ -34,8 +34,8 @@ group("apps") {
if (defined(LOSCFG_SHELL)) {
deps += [
"shell",
"mksh",
"shell",
"toybox",
]
}
@@ -51,4 +51,12 @@ group("apps") {
if (defined(LOSCFG_DRIVERS_TRACE)) {
deps += [ "trace" ]
}
if (defined(LOSCFG_DRIVERS_PERF)) {
deps += [ "perf" ]
}
if (defined(LOSCFG_KERNEL_LMS)) {
deps += [ "lms:sample_usr_lms" ]
}
}

View File

@@ -34,14 +34,7 @@ export APPSTOPDIR
include $(APPSTOPDIR)/config.mk
all:
ifneq ($(APP_SUBDIRS), )
$(HIDE) for dir in $(APP_SUBDIRS); do $(MAKE) -C $$dir all || exit 1; done
endif
clean:
ifneq ($(APP_SUBDIRS), )
$(HIDE) for dir in $(APP_SUBDIRS); do $(MAKE) -C $$dir clean || exit 1; done
endif
all clean:
$(HIDE) for dir in $(APP_SUBDIRS); do $(MAKE) -C $$dir $@ || exit 1; done
.PHONY: all clean

View File

@@ -27,88 +27,6 @@
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
OBJOUT := $(BUILD)$(dir $(subst $(LITEOSTOPDIR),,$(shell pwd)))$(APP_NAME)
override TARGET = $(OUT)/bin/$(APP_NAME)
APP := $(OUT)/bin/$(APP_NAME)
# create a separate list of objects per source type
LOCAL_CSRCS := $(filter %.c,$(LOCAL_SRCS))
LOCAL_CPPSRCS := $(filter %.cpp,$(LOCAL_SRCS))
LOCAL_ASMSRCS := $(filter %.S,$(LOCAL_SRCS))
LOCAL_ASMSRCS2 := $(filter %.s,$(LOCAL_SRCS))
LOCAL_CCSRCS := $(filter %.cc,$(LOCAL_SRCS))
LOCAL_COBJS := $(patsubst %.c,$(OBJOUT)/%.o,$(LOCAL_CSRCS))
LOCAL_CPPOBJS := $(patsubst %.cpp,$(OBJOUT)/%.o,$(LOCAL_CPPSRCS))
LOCAL_ASMOBJS := $(patsubst %.S,$(OBJOUT)/%.o,$(LOCAL_ASMSRCS))
LOCAL_ASMOBJS2 := $(patsubst %.s,$(OBJOUT)/%.o,$(LOCAL_ASMSRCS2))
LOCAL_CCOBJS := $(patsubst %.cc,$(OBJOUT)/%.o,$(LOCAL_CCSRCS))
LOCAL_OBJS := $(LOCAL_COBJS) $(LOCAL_CPPOBJS) $(LOCAL_ASMOBJS) $(LOCAL_ASMOBJS2) $(LOCAL_CCOBJS)
LOCAL_CGCH := $(patsubst %.h,%.h.gch,$(LOCAL_CHS))
LOCAL_CPPGCH := $(patsubst %.h,%.h.gch,$(LOCAL_CPPHS))
all : $(APP)
define ECHO =
ifeq ($$(HIDE),@)
_$(1) := $($(1))
$(1) = echo " $(1)" $$(patsubst $$(OUT)/%,%,$$@) && $$(_$(1))
endif
endef
$(foreach cmd,CC GPP AS,$(eval $(call ECHO,$(cmd))))
LOCAL_FLAGS += -MD -MP
-include $(LOCAL_OBJS:%.o=%.d)
$(LOCAL_COBJS): $(OBJOUT)/%.o: %.c
$(HIDE)$(OBJ_MKDIR)
$(HIDE)$(CC) $(CFLAGS) $(LOCAL_FLAGS) $(LOCAL_CFLAGS) -c $< -o $@
$(LOCAL_CPPOBJS): $(OBJOUT)/%.o: %.cpp
$(HIDE)$(OBJ_MKDIR)
$(HIDE)$(GPP) $(CXXFLAGS) $(LOCAL_FLAGS) $(LOCAL_CPPFLAGS) -c $< -o $@
$(LOCAL_ASMOBJS): $(OBJOUT)/%.o: %.S
$(HIDE)$(OBJ_MKDIR)
$(HIDE)$(CC) $(CFLAGS) $(LOCAL_FLAGS) $(LOCAL_ASFLAGS) -c $< -o $@
$(LOCAL_ASMOBJS2): $(OBJOUT)/%.o: %.s
$(HIDE)$(OBJ_MKDIR)
$(HIDE)$(AS) $(ASFLAGS) $(LOCAL_FLAGS) $(LOCAL_ASFLAGS) -c $< -o $@
$(LOCAL_CCOBJS): $(OBJOUT)/%.o: %.cc
$(HIDE)$(OBJ_MKDIR)
$(HIDE)$(GPP) $(CXXFLAGS) $(LOCAL_FLAGS) $(LOCAL_CPPFLAGS) -c $< -o $@
$(LOCAL_CGCH): %.h.gch : %.h
$(HIDE)$(CC) $(CFLAGS) $(LOCAL_FLAGS) $(LOCAL_CFLAGS) $> $^
$(LOCAL_CPPGCH): %.h.gch : %.h
$(HIDE)$(GPP) $(CXXFLAGS) $(LOCAL_FLAGS) $(LOCAL_CPPFLAGS) -x c++-header $> $^
LOCAL_GCH := $(LOCAL_CGCH) $(LOCAL_CPPGCH)
$(LOCAL_OBJS): $(LOCAL_GCH)
$(APP): $(LOCAL_OBJS)
$(HIDE)$(OBJ_MKDIR)
$(HIDE)$(GPP) $(LDFLAGS) -o $@ $^
clean:
$(HIDE)$(RM) $(APP) $(OBJOUT) $(LOCAL_GCH) *.bak *~
.PHONY: all clean
# clear some variables we set here
LOCAL_CSRCS :=
LOCAL_CPPSRCS :=
LOCAL_ASMSRCS :=
LOCAL_COBJS :=
LOCAL_CPPOBJS :=
LOCAL_ASMOBJS :=
LOCAL_ASMOBJS2 :=
# LOCAL_OBJS is passed back
#LOCAL_OBJS :=
include $(MODULE)

View File

@@ -30,7 +30,7 @@
include $(LITEOSTOPDIR)/config.mk
# common flags config
BASE_OPTS := -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE $(LITEOS_GCOV_OPTS)
BASE_OPTS := -D_FORTIFY_SOURCE=2 -D_XOPEN_SOURCE=700
ASFLAGS :=
CFLAGS := $(LITEOS_COPTS) $(BASE_OPTS) -fPIE
@@ -70,11 +70,6 @@ ifeq ($(LOSCFG_DRIVERS_TRACE), y)
APP_SUBDIRS += trace
endif
# clear all local variables
LOCAL_FLAGS :=
LOCAL_CFLAGS :=
LOCAL_CPPFLAGS :=
LOCAL_ASFLAGS :=
LOCAL_SRCS :=
LOCAL_CHS :=
LOCAL_CPPHS :=
ifeq ($(LOSCFG_DRIVERS_PERF), y)
APP_SUBDIRS += perf
endif

77
apps/lms/BUILD.gn Normal file
View File

@@ -0,0 +1,77 @@
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this list of
# conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
# of conditions and the following disclaimer in the documentation and/or other materials
# provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors may be used
# to endorse or promote products derived from this software without specific prior written
# permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import("//build/lite/config/component/lite_component.gni")
lite_component("LMS-Sample") {
features = [ ":sample_usr_lms" ]
}
executable("sample_usr_lms") {
output_name = "sample_usr_lms"
sources = [ "src/sample_usr_lms.c" ]
include_dirs = []
defines = []
if (ohos_build_compiler == "gcc") {
cflags_c = [
"-O0",
"-fsanitize=kernel-address",
"-funwind-tables",
"-fasynchronous-unwind-tables",
]
} else {
cflags_c = [
"-O0",
"-fsanitize=kernel-address",
"-mllvm",
"-asan-instrumentation-with-call-threshold=0",
"-mllvm",
"-asan-stack=0",
"-mllvm",
"-asan-globals=0",
"-funwind-tables",
"-fasynchronous-unwind-tables",
]
}
ldflags = [
"-rdynamic",
"-lunwind",
"-lusrlms",
"-Wl,--wrap=realloc",
"-Wl,--wrap=calloc",
"-Wl,--wrap=malloc",
"-Wl,--wrap=free",
"-Wl,--wrap=valloc",
"-Wl,--wrap=aligned_alloc",
"-Wl,--wrap=memset",
"-Wl,--wrap=memcpy",
"-Wl,--wrap=memmove",
"-Wl,--wrap=strcpy",
"-Wl,--wrap=strcat",
]
deps = [ "//kernel/liteos_a/kernel/extended/lms/usr:usrlmslib" ]
}

208
apps/lms/src/sample_usr_lms.c Executable file
View File

@@ -0,0 +1,208 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static void BufWriteTest(void *buf, int start, int end)
{
for (int i = start; i <= end; i++) {
((char *)buf)[i] = 'a';
}
}
static void BufReadTest(void *buf, int start, int end)
{
char tmp;
for (int i = start; i <= end; i++) {
tmp = ((char *)buf)[i];
}
}
static void LmsMallocTest(void)
{
printf("\n-------- LmsMallocTest Start --------\n");
char *buf = (char *)malloc(16);
printf("[LmsMallocTest] malloc addr:%p size:%d\n", buf, 16);
printf("[LmsMallocTest] read overflow & underflow error should be triggered, read range[-1,16]\n");
BufReadTest(buf, -1, 16);
printf("[LmsMallocTest] write overflow error should be triggered, write range[0,16]\n");
BufWriteTest(buf, 0, 16);
free(buf);
printf("\n-------- LmsMallocTest End --------\n");
}
static void LmsReallocTest(void)
{
printf("\n-------- LmsReallocTest Start --------\n");
char *buf = (char *)malloc(64);
printf("[LmsReallocTest] malloc addr:%p size:%d\n", buf, 64);
printf("[LmsReallocTest] read overflow & underflow error should be triggered, read range[-1,64]\n");
BufReadTest(buf, -1, 64);
buf = (char *)realloc(buf, 32);
printf("[LmsReallocTest] realloc addr:%p size:%d\n", buf, 32);
printf("[LmsReallocTest] read overflow & underflow error should be triggered, read range[-1,32]\n");
BufReadTest(buf, -1, 32);
free(buf);
printf("\n-------- LmsReallocTest End --------\n");
}
static void LmsCallocTest(void)
{
printf("\n-------- LmsCallocTest Start --------\n");
char *buf = (char *)calloc(4, 4);
printf("[LmsCallocTest] calloc addr:%p size:%d\n", buf, 16);
printf("[LmsCallocTest] read overflow & underflow error should be triggered, read range[-1,16]\n");
BufReadTest(buf, -1, 16);
free(buf);
printf("\n-------- LmsCallocTest End --------\n");
}
static void LmsVallocTest(void)
{
printf("\n-------- LmsVallocTest Start --------\n");
char *buf = (char *)valloc(4096);
printf("[LmsVallocTest] valloc addr:%p size:%d\n", buf, 4096);
printf("[LmsVallocTest] read overflow & underflow error should be triggered, read range[-1,4096]\n");
BufReadTest(buf, -1, 4096);
free(buf);
printf("\n-------- LmsVallocTest End --------\n");
}
static void LmsAlignedAllocTest(void)
{
printf("\n-------- LmsAlignedAllocTest Start --------\n");
char *buf = (char *)aligned_alloc(64, 128);
printf("[LmsAlignedAllocTest] aligned_alloc boundsize:%d addr:%p size:%d\n", 64, buf, 128);
printf("[LmsAlignedAllocTest] read overflow & underflow error should be triggered, read range[-1,128]\n");
BufReadTest(buf, -1, 128);
free(buf);
printf("\n-------- LmsAlignedAllocTest End --------\n");
}
static void LmsMemsetTest(void)
{
printf("\n-------- LmsMemsetTest Start --------\n");
char *buf = (char *)malloc(32);
printf("[LmsMemsetTest] malloc addr:%p size:%d\n", buf, 32);
printf("[LmsMemsetTest] memset overflow & underflow error should be triggered, memset size:%d\n", 33);
memset(buf, 0, 33);
free(buf);
printf("\n-------- LmsMemsetTest End --------\n");
}
static void LmsMemcpyTest(void)
{
printf("\n-------- LmsMemcpyTest Start --------\n");
char *buf = (char *)malloc(20);
printf("[LmsMemcpyTest] malloc addr:%p size:%d\n", buf, 20);
char localBuf[32] = {0};
printf("[LmsMemcpyTest] memcpy overflow error should be triggered, memcpy size:%d\n", 21);
memcpy(buf, localBuf, 21);
free(buf);
printf("\n-------- LmsMemcpyTest End --------\n");
}
static void LmsMemmoveTest(void)
{
printf("\n-------- LmsMemmoveTest Start --------\n");
char *buf = (char *)malloc(20);
printf("[LmsMemmoveTest] malloc addr:%p size:%d\n", buf, 20);
printf("[LmsMemmoveTest] memmove overflow error should be triggered, dest addr:%p src addr:%p size:%d\n", buf + 12,
buf, 10);
memmove(buf + 12, buf, 10);
free(buf);
printf("\n-------- LmsMemmoveTest End --------\n");
}
static void LmsStrcpyTest(void)
{
printf("\n-------- LmsStrcpyTest Start --------\n");
char *buf = (char *)malloc(16);
printf("[LmsStrcpyTest] malloc addr:%p size:%d\n", buf, 16);
char *testStr = "bbbbbbbbbbbbbbbbb";
printf("[LmsStrcpyTest] strcpy overflow error should be triggered, src string buf size:%d\n", strlen(testStr) + 1);
strcpy(buf, testStr);
free(buf);
printf("\n-------- LmsStrcpyTest End --------\n");
}
static void LmsStrcatTest(void)
{
printf("\n-------- LmsStrcatTest Start --------\n");
char *buf = (char *)malloc(16);
printf("[LmsStrcatTest] malloc addr:%p size:%d\n", buf, 16);
buf[0] = 'a';
buf[1] = 'b';
buf[2] = 0;
char *testStr = "cccccccccccccc";
printf("[LmsStrcatTest] strcat overflow error should be triggered, src string:%s dest string:%s"
"total buf size:%d\n",
testStr, buf, strlen(testStr) + strlen(buf) + 1);
strcat(buf, testStr);
free(buf);
printf("\n-------- LmsStrcatTest End --------\n");
}
static void LmsFreeTest(void)
{
printf("\n-------- LmsFreeTest Start --------\n");
char *buf = (char *)malloc(16);
printf("[LmsFreeTest] malloc addr:%p size:%d\n", buf, 16);
printf("[LmsFreeTest] free addr:%p\n", buf, 16);
free(buf);
printf("[LmsFreeTest] Use after free error should be triggered, read addr:%p range[1,1]\n", buf);
BufReadTest(buf, 1, 1);
printf("[LmsFreeTest] double free error should be triggered, free addr:%p\n", buf);
free(buf);
printf("\n-------- LmsFreeTest End --------\n");
}
int main(int argc, char * const * argv)
{
printf("\n############### Lms Test start ###############\n");
char *tmp = (char *)malloc(5000);
LmsMallocTest();
LmsReallocTest();
LmsCallocTest();
LmsVallocTest();
LmsAlignedAllocTest();
LmsMemsetTest();
LmsMemcpyTest();
LmsMemmoveTest();
LmsStrcpyTest();
LmsStrcatTest();
LmsFreeTest();
printf("\n############### Lms Test End ###############\n");
}

63
apps/perf/BUILD.gn Normal file
View File

@@ -0,0 +1,63 @@
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this list of
# conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
# of conditions and the following disclaimer in the documentation and/or other materials
# provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors may be used
# to endorse or promote products derived from this software without specific prior written
# permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import("//kernel/liteos_a/liteos.gni")
executable("perf") {
sources = [
"src/main.c",
"src/option.c",
"src/perf.c",
"src/perf_list.c",
"src/perf_record.c",
"src/perf_stat.c",
]
include_dirs = [ "include" ]
defines = []
if (defined(LOSCFG_PERF_HW_PMU)) {
defines += [ "LOSCFG_PERF_HW_PMU" ]
}
if (defined(LOSCFG_PERF_TIMED_PMU)) {
defines += [ "LOSCFG_PERF_TIMED_PMU" ]
}
if (defined(LOSCFG_PERF_SW_PMU)) {
defines += [ "LOSCFG_PERF_SW_PMU" ]
}
if (defined(LOSCFG_FS_VFS)) {
defines += [ "LOSCFG_FS_VFS" ]
}
defines += [ "LOSCFG_PERF_BUFFER_SIZE=$LOSCFG_PERF_BUFFER_SIZE" ]
deps = [ "$LITEOSTHIRDPARTY/bounds_checking_function:libsec_static" ]
}

62
apps/perf/Makefile Normal file
View File

@@ -0,0 +1,62 @@
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this list of
# conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
# of conditions and the following disclaimer in the documentation and/or other materials
# provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors may be used
# to endorse or promote products derived from this software without specific prior written
# permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
include $(APPSTOPDIR)/config.mk
APP_NAME := $(notdir $(shell pwd))
SECUREC_DIR := $(LITEOSTHIRDPARTY)/bounds_checking_function
LOCAL_SRCS = $(wildcard src/*.c)
LOCAL_SRCS += $(wildcard $(SECUREC_DIR)/src/*.c)
LOCAL_INCLUDE := \
-I include \
-I $(SECUREC_DIR)/include
LOCAL_FLAGS += $(LOCAL_INCLUDE)
ifeq ($(LOSCFG_PERF_HW_PMU), y)
CFLAGS += -DLOSCFG_PERF_HW_PMU
endif
ifeq ($(LOSCFG_PERF_TIMED_PMU), y)
CFLAGS += -DLOSCFG_PERF_TIMED_PMU
endif
ifeq ($(LOSCFG_PERF_SW_PMU), y)
CFLAGS += -DLOSCFG_PERF_SW_PMU
endif
ifeq ($(LOSCFG_FS_VFS), y)
CFLAGS += -DLOSCFG_FS_VFS
endif
CFLAGS += -DLOSCFG_PERF_BUFFER_SIZE=$(LOSCFG_PERF_BUFFER_SIZE)
include $(APP)

View File

@@ -0,0 +1,81 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _OPTION_H
#define _OPTION_H
#include "perf.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#define CMD_MAX_PARAMS 10
typedef int (*CALL_BACK)(const char *argv);
enum OptionType {
OPTION_TYPE_UINT,
OPTION_TYPE_STRING,
OPTION_TYPE_CALLBACK,
};
typedef struct {
int type;
const char *name;
const char **str;
unsigned int *value;
CALL_BACK cb;
} PerfOption;
typedef struct {
const char *path;
char *params[CMD_MAX_PARAMS];
} SubCmd;
#define OPTION_END() {.name = ""}
#define OPTION_UINT(n, v) {.type = OPTION_TYPE_UINT, .name = (n), .value = (v)}
#define OPTION_STRING(n, s) {.type = OPTION_TYPE_STRING, .name = (n), .str = (s)}
#define OPTION_CALLBACK(n, c) {.type = OPTION_TYPE_CALLBACK, .name = (n), .cb = (c)}
int ParseOptions(int argc, char **argv, PerfOption *opt, SubCmd *cmd);
int ParseEvents(const char *argv, PerfEventConfig *eventsCfg, unsigned int *len);
int ParseIds(const char *argv, int *arr, unsigned int *len);
#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif
#endif /* _OPTION_H */

163
apps/perf/include/perf.h Normal file
View File

@@ -0,0 +1,163 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _PERF_H
#define _PERF_H
#include <stdlib.h>
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#define PERF_MAX_EVENT 7
#define PERF_MAX_FILTER_TSKS 32
#ifdef PERF_DEBUG
#define printf_debug(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#define printf_debug(fmt, ...)
#endif
/*
* Perf types
*/
enum PerfEventType {
PERF_EVENT_TYPE_HW, /* boards common hw events */
PERF_EVENT_TYPE_TIMED, /* hrtimer timed events */
PERF_EVENT_TYPE_SW, /* software trace events */
PERF_EVENT_TYPE_RAW, /* boards special hw events, see enum PmuEventType in corresponding arch headfile */
PERF_EVENT_TYPE_MAX
};
/*
* Common hardware pmu events
*/
enum PmuHwId {
PERF_COUNT_HW_CPU_CYCLES = 0, /* cpu cycle event */
PERF_COUNT_HW_INSTRUCTIONS, /* instruction event */
PERF_COUNT_HW_DCACHE_REFERENCES, /* dcache access event */
PERF_COUNT_HW_DCACHE_MISSES, /* dcache miss event */
PERF_COUNT_HW_ICACHE_REFERENCES, /* icache access event */
PERF_COUNT_HW_ICACHE_MISSES, /* icache miss event */
PERF_COUNT_HW_BRANCH_INSTRUCTIONS, /* software change of pc event */
PERF_COUNT_HW_BRANCH_MISSES, /* branch miss event */
PERF_COUNT_HW_MAX,
};
/*
* Common hrtimer timed events
*/
enum PmuTimedId {
PERF_COUNT_CPU_CLOCK = 0, /* hrtimer timed event */
};
/*
* Common software pmu events
*/
enum PmuSwId {
PERF_COUNT_SW_TASK_SWITCH = 1, /* task switch event */
PERF_COUNT_SW_IRQ_RESPONSE, /* irq response event */
PERF_COUNT_SW_MEM_ALLOC, /* memory alloc event */
PERF_COUNT_SW_MUX_PEND, /* mutex pend event */
PERF_COUNT_SW_MAX,
};
/*
* perf sample data types
* Config it through PerfConfigAttr->sampleType.
*/
enum PerfSampleType {
PERF_RECORD_CPU = 1U << 0, /* record current cpuid */
PERF_RECORD_TID = 1U << 1, /* record current task id */
PERF_RECORD_TYPE = 1U << 2, /* record event type */
PERF_RECORD_PERIOD = 1U << 3, /* record event period */
PERF_RECORD_TIMESTAMP = 1U << 4, /* record timestamp */
PERF_RECORD_IP = 1U << 5, /* record instruction pointer */
PERF_RECORD_CALLCHAIN = 1U << 6, /* record backtrace */
PERF_RECORD_PID = 1U << 7, /* record current process id */
};
/*
* perf configuration sub event information
*
* This structure is used to config specific events attributes.
*/
typedef struct {
unsigned int type; /* enum PerfEventType */
struct {
unsigned int eventId; /* the specific event corresponds to the PerfEventType */
unsigned int period; /* event period, for every "period"th occurrence of the event a
sample will be recorded */
} events[PERF_MAX_EVENT]; /* perf event list */
unsigned int eventsNr; /* total perf event number */
size_t predivided; /* whether to prescaler (once every 64 counts),
which only take effect on cpu cycle hardware event */
} PerfEventConfig;
/*
* perf configuration main information
*
* This structure is used to set perf sampling attributes, including events, tasks and other information.
*/
typedef struct {
PerfEventConfig eventsCfg; /* perf event config */
unsigned int taskIds[PERF_MAX_FILTER_TSKS]; /* perf task filter list (allowlist) */
unsigned int taskIdsNr; /* task numbers of task filter allowlist,
if set 0 perf will sample all tasks */
unsigned int processIds[PERF_MAX_FILTER_TSKS]; /* perf process filter list (allowlist) */
unsigned int processIdsNr; /* process numbers of process filter allowlist,
if set 0 perf will sample all processes */
unsigned int sampleType; /* type of data to sample defined in PerfSampleType */
size_t needSample; /* whether to sample data */
} PerfConfigAttr;
void PerfUsage(void);
void PerfDumpAttr(PerfConfigAttr *attr);
int PerfConfig(int fd, PerfConfigAttr *attr);
void PerfStart(int fd, size_t sectionId);
void PerfStop(int fd);
ssize_t PerfRead(int fd, char *buf, size_t size);
void PerfPrintBuffer(const char *buf, ssize_t num);
#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif
#endif /* _PERF_H */

View File

@@ -29,28 +29,29 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @defgroup los_pmm physical memory management
* @ingroup kernel
*/
#ifndef __LOS_PMM_H__
#define __LOS_PMM_H__
#ifndef _PERF_LIST_H
#define _PERF_LIST_H
#include "los_typedef.h"
#ifdef __cplusplus
#if __cplusplus
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
BOOL OsIsPaddrValid(paddr_t pa);
typedef struct {
const char *name;
int event;
int type;
} PerfEvent;
extern const PerfEvent g_events[];
void PerfList(void);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif
#endif
#endif /* __LOS_PMM_H__ */
#endif /* _PERF_LIST_H */

View File

@@ -0,0 +1,49 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _PERF_RECORD_H
#define _PERF_RECORD_H
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
void PerfRecord(int fd, int argc, char **argv);
#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif
#endif /* _PERF_RECORD_H */

View File

@@ -0,0 +1,49 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _PERF_STAT_H
#define _PERF_STAT_H
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
void PerfStat(int fd, int argc, char **argv);
#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif
#endif /* _PERF_STAT_H */

82
apps/perf/src/main.c Normal file
View File

@@ -0,0 +1,82 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include "perf.h"
#include "perf_list.h"
#include "perf_stat.h"
#include "perf_record.h"
int main(int argc, char **argv)
{
#define TWO_ARGS 2
#define THREE_ARGS 3
int fd = open("/dev/perf", O_RDWR);
if (fd == -1) {
printf("Perf open failed.\n");
exit(EXIT_FAILURE);
}
if (argc == 1) {
PerfUsage();
} else if ((argc == TWO_ARGS) && strcmp(argv[1], "start") == 0) {
PerfStart(fd, 0);
} else if ((argc == THREE_ARGS) && strcmp(argv[1], "start") == 0) {
size_t id = strtoul(argv[THREE_ARGS - 1], NULL, 0);
PerfStart(fd, id);
} else if ((argc == TWO_ARGS) && strcmp(argv[1], "stop") == 0) {
PerfStop(fd);
} else if ((argc == THREE_ARGS) && strcmp(argv[1], "read") == 0) {
size_t size = strtoul(argv[THREE_ARGS - 1], NULL, 0);
char *buf = (char *)malloc(size);
int len = PerfRead(fd, buf, size);
PerfPrintBuffer(buf, len);
free(buf);
} else if ((argc == TWO_ARGS) && strcmp(argv[1], "list") == 0) {
PerfList();
} else if ((argc >= THREE_ARGS) && strcmp(argv[1], "stat") == 0) {
PerfStat(fd, argc, argv);
} else if ((argc >= THREE_ARGS) && strcmp(argv[1], "record") == 0) {
PerfRecord(fd, argc, argv);
} else {
printf("Unsupported perf command.\n");
PerfUsage();
}
close(fd);
return 0;
}

182
apps/perf/src/option.c Normal file
View File

@@ -0,0 +1,182 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include <string.h>
#include "option.h"
#include "perf_list.h"
static int ParseOption(char **argv, int *index, PerfOption *opts)
{
int ret = 0;
const char *str = NULL;
while ((opts->name != NULL) && (*opts->name != 0)) {
if (strcmp(argv[*index], opts->name) == 0) {
switch (opts->type) {
case OPTION_TYPE_UINT:
*opts->value = strtoul(argv[++(*index)], NULL, 0);
break;
case OPTION_TYPE_STRING:
*opts->str = argv[++(*index)];
break;
case OPTION_TYPE_CALLBACK:
str = argv[++(*index)];
if ((*opts->cb)(str) != 0) {
printf("parse error\n");
ret = -1;
}
break;
default:
printf("invalid option\n");
ret = -1;
break;
}
return ret;
}
opts++;
}
return -1;
}
int ParseOptions(int argc, char **argv, PerfOption *opts, SubCmd *cmd)
{
int i;
int index = 0;
while ((index < argc) && (argv[index] != NULL) && (*argv[index] == '-')) {
if (ParseOption(argv, &index, opts) != 0) {
return -1;
}
index++;
}
if ((index < argc) && (argv[index] != NULL)) {
cmd->path = argv[index];
cmd->params[0] = argv[index];
index++;
} else {
printf("no subcmd to execute\n");
return -1;
}
for (i = 1; (index < argc) && (i < CMD_MAX_PARAMS); index++, i++) {
cmd->params[i] = argv[index];
}
printf_debug("subcmd = %s\n", cmd->path);
for (int j = 0; j < i; j++) {
printf_debug("paras[%d]:%s\n", j, cmd->params[j]);
}
return 0;
}
int ParseIds(const char *argv, int *arr, unsigned int *len)
{
int res, ret;
unsigned int index = 0;
char *sp = NULL;
char *this = NULL;
char *list = strdup(argv);
if (list == NULL) {
printf("no memory for ParseIds\n");
return -1;
}
sp = strtok_r(list, ",", &this);
while (sp) {
res = strtoul(sp, NULL, 0);
if (res < 0) {
ret = -1;
goto EXIT;
}
arr[index++] = res;
sp = strtok_r(NULL, ",", &this);
}
*len = index;
ret = 0;
EXIT:
free(list);
return ret;
}
static inline const PerfEvent *StrToEvent(const char *str)
{
const PerfEvent *evt = &g_events[0];
for (; evt->event != -1; evt++) {
if (strcmp(str, evt->name) == 0) {
return evt;
}
}
return NULL;
}
int ParseEvents(const char *argv, PerfEventConfig *eventsCfg, unsigned int *len)
{
int ret;
unsigned int index = 0;
const PerfEvent *event = NULL;
char *sp = NULL;
char *this = NULL;
char *list = strdup(argv);
if (list == NULL) {
printf("no memory for ParseEvents\n");
return -1;
}
sp = strtok_r(list, ",", &this);
while (sp) {
event = StrToEvent(sp);
if (event == NULL) {
ret = -1;
goto EXIT;
}
if (index == 0) {
eventsCfg->type = event->type;
} else if (eventsCfg->type != event->type) {
printf("events type must be same\n");
ret = -1;
goto EXIT;
}
eventsCfg->events[index].eventId = event->event;
sp = strtok_r(NULL, ",", &this);
index++;
}
*len = index;
ret = 0;
EXIT:
free(list);
return ret;
}

136
apps/perf/src/perf.c Normal file
View File

@@ -0,0 +1,136 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <unistd.h>
#include "perf.h"
#define PERF_IOC_MAGIC 'T'
#define PERF_START _IO(PERF_IOC_MAGIC, 1)
#define PERF_STOP _IO(PERF_IOC_MAGIC, 2)
void PerfUsage(void)
{
printf("\nUsage: ./perf start [id]. Start perf.\n");
printf("\nUsage: ./perf stop. Stop perf.\n");
printf("\nUsage: ./perf read <nBytes>. Read nBytes raw data from perf buffer and print out.\n");
printf("\nUsage: ./perf list. List events to be used in -e.\n");
printf("\nUsage: ./perf stat/record [option] <command>. \n"
"-e, event selector. use './perf list' to list available events.\n"
"-p, event period.\n"
"-o, perf data output filename.\n"
"-t, taskId filter(allowlist), if not set perf will sample all tasks.\n"
"-s, type of data to sample defined in PerfSampleType los_perf.h.\n"
"-P, processId filter(allowlist), if not set perf will sample all processes.\n"
"-d, whether to prescaler (once every 64 counts),"
"which only take effect on cpu cycle hardware event.\n"
);
}
static void PerfSetPeriod(PerfConfigAttr *attr)
{
int i;
for (i = 1; i < attr->eventsCfg.eventsNr; i++) {
attr->eventsCfg.events[i].period = attr->eventsCfg.events[0].period;
}
}
void PerfPrintBuffer(const char *buf, ssize_t num)
{
#define BYTES_PER_LINE 4
ssize_t i;
for (i = 0; i < num; i++) {
printf(" %02x", (unsigned char)buf[i]);
if (((i + 1) % BYTES_PER_LINE) == 0) {
printf("\n");
}
}
printf("\n");
}
void PerfDumpAttr(PerfConfigAttr *attr)
{
int i;
printf_debug("attr->type: %d\n", attr->eventsCfg.type);
for (i = 0; i < attr->eventsCfg.eventsNr; i++) {
printf_debug("attr->events[%d]: %d, 0x%x\n", i, attr->eventsCfg.events[i].eventId,
attr->eventsCfg.events[i].period);
}
printf_debug("attr->predivided: %d\n", attr->eventsCfg.predivided);
printf_debug("attr->sampleType: 0x%x\n", attr->sampleType);
for (i = 0; i < attr->taskIdsNr; i++) {
printf_debug("attr->taskIds[%d]: %d\n", i, attr->taskIds[i]);
}
for (i = 0; i < attr->processIdsNr; i++) {
printf_debug("attr->processIds[%d]: %d\n", i, attr->processIds[i]);
}
printf_debug("attr->needSample: %d\n", attr->needSample);
}
void PerfStart(int fd, size_t sectionId)
{
(void)ioctl(fd, PERF_START, sectionId);
}
void PerfStop(int fd)
{
(void)ioctl(fd, PERF_STOP, NULL);
}
int PerfConfig(int fd, PerfConfigAttr *attr)
{
if (attr == NULL) {
return -1;
}
PerfSetPeriod(attr);
PerfDumpAttr(attr);
return write(fd, attr, sizeof(PerfConfigAttr));
}
ssize_t PerfRead(int fd, char *buf, size_t size)
{
ssize_t len;
if (buf == NULL) {
printf("Read buffer is null.\n");
return 0;
}
len = read(fd, buf, size);
return len;
}

129
apps/perf/src/perf_list.c Normal file
View File

@@ -0,0 +1,129 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include "perf.h"
#include "perf_list.h"
static const char *g_eventTypeStr[] = {
"[Hardware event]",
"[Timed event]",
"[Software event]",
};
const PerfEvent g_events[] = {
#ifdef LOSCFG_PERF_HW_PMU
{
.name = "cycles",
.event = PERF_COUNT_HW_CPU_CYCLES,
.type = PERF_EVENT_TYPE_HW,
},
{
.name = "instruction",
.event = PERF_COUNT_HW_INSTRUCTIONS,
.type = PERF_EVENT_TYPE_HW,
},
{
.name = "dcache",
.event = PERF_COUNT_HW_DCACHE_REFERENCES,
.type = PERF_EVENT_TYPE_HW,
},
{
.name = "dcache-miss",
.event = PERF_COUNT_HW_DCACHE_MISSES,
.type = PERF_EVENT_TYPE_HW,
},
{
.name = "icache",
.event = PERF_COUNT_HW_ICACHE_REFERENCES,
.type = PERF_EVENT_TYPE_HW,
},
{
.name = "icache-miss",
.event = PERF_COUNT_HW_ICACHE_MISSES,
.type = PERF_EVENT_TYPE_HW,
},
{
.name = "branch",
.event = PERF_COUNT_HW_BRANCH_INSTRUCTIONS,
.type = PERF_EVENT_TYPE_HW,
},
{
.name = "branch-miss",
.event = PERF_COUNT_HW_BRANCH_MISSES,
.type = PERF_EVENT_TYPE_HW,
},
#endif
#ifdef LOSCFG_PERF_TIMED_PMU
{
.name = "clock",
.event = PERF_COUNT_CPU_CLOCK,
.type = PERF_EVENT_TYPE_TIMED,
},
#endif
#ifdef LOSCFG_PERF_SW_PMU
{
.name = "task-switch",
.event = PERF_COUNT_SW_TASK_SWITCH,
.type = PERF_EVENT_TYPE_SW,
},
{
.name = "irq-in",
.event = PERF_COUNT_SW_IRQ_RESPONSE,
.type = PERF_EVENT_TYPE_SW,
},
{
.name = "mem-alloc",
.event = PERF_COUNT_SW_MEM_ALLOC,
.type = PERF_EVENT_TYPE_SW,
},
{
.name = "mux-pend",
.event = PERF_COUNT_SW_MUX_PEND,
.type = PERF_EVENT_TYPE_SW,
},
#endif
{
.name = "",
.event = -1,
.type = PERF_EVENT_TYPE_MAX,
}
};
void PerfList(void)
{
const PerfEvent *evt = &g_events[0];
printf("\n");
for (; evt->event != -1; evt++) {
printf("\t %-25s%30s\n", evt->name, g_eventTypeStr[evt->type]);
}
printf("\n");
}

204
apps/perf/src/perf_record.c Normal file
View File

@@ -0,0 +1,204 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <unistd.h>
#include <sys/wait.h>
#include <securec.h>
#ifdef LOSCFG_FS_VFS
#include <fcntl.h>
#include <errno.h>
#endif
#include "perf.h"
#include "option.h"
#include "perf_record.h"
#define PERF_FILE_MODE 0644
static PerfConfigAttr g_recordAttr;
static const char *g_savePath = "/storage/data/perf.data";
static inline int GetEvents(const char *argv)
{
return ParseEvents(argv, &g_recordAttr.eventsCfg, &g_recordAttr.eventsCfg.eventsNr);
}
static inline int GetTids(const char *argv)
{
return ParseIds(argv, (int *)g_recordAttr.taskIds, &g_recordAttr.taskIdsNr);
}
static inline int GetPids(const char *argv)
{
return ParseIds(argv, (int *)g_recordAttr.processIds, &g_recordAttr.processIdsNr);
}
static PerfOption g_recordOpts[] = {
OPTION_CALLBACK("-e", GetEvents),
OPTION_CALLBACK("-t", GetTids),
OPTION_CALLBACK("-P", GetPids),
OPTION_STRING("-o", &g_savePath),
OPTION_UINT("-p", &g_recordAttr.eventsCfg.events[0].period),
OPTION_UINT("-s", &g_recordAttr.sampleType),
OPTION_UINT("-d", &g_recordAttr.eventsCfg.predivided),
};
static int PerfRecordAttrInit(void)
{
PerfConfigAttr attr = {
.eventsCfg = {
#ifdef LOSCFG_PERF_HW_PMU
.type = PERF_EVENT_TYPE_HW,
.events = {
[0] = {PERF_COUNT_HW_CPU_CYCLES, 0xFFFF},
},
#elif defined LOSCFG_PERF_TIMED_PMU
.type = PERF_EVENT_TYPE_TIMED,
.events = {
[0] = {PERF_COUNT_CPU_CLOCK, 100},
},
#elif defined LOSCFG_PERF_SW_PMU
.type = PERF_EVENT_TYPE_SW,
.events = {
[0] = {PERF_COUNT_SW_TASK_SWITCH, 1},
},
#endif
.eventsNr = 1, /* 1 event */
.predivided = 0,
},
.taskIds = {0},
.taskIdsNr = 0,
.processIds = {0},
.processIdsNr = 0,
.needSample = 1,
.sampleType = PERF_RECORD_IP | PERF_RECORD_CALLCHAIN,
};
return memcpy_s(&g_recordAttr, sizeof(PerfConfigAttr), &attr, sizeof(PerfConfigAttr)) != EOK ? -1 : 0;
}
ssize_t PerfWriteFile(const char *filePath, const char *buf, ssize_t bufSize)
{
#ifdef LOSCFG_FS_VFS
int fd = -1;
ssize_t totalToWrite = bufSize;
ssize_t totalWrite = 0;
if (filePath == NULL || buf == NULL || bufSize == 0) {
printf("filePath: %p, buf: %p, bufSize: %u!\n", filePath, buf, bufSize);
return -1;
}
fd = open(filePath, O_CREAT | O_RDWR | O_TRUNC, PERF_FILE_MODE);
if (fd < 0) {
printf("create file [%s] failed, fd: %d, %s!\n", filePath, fd, strerror(errno));
return -1;
}
while (totalToWrite > 0) {
ssize_t writeThisTime = write(fd, buf, totalToWrite);
if (writeThisTime < 0) {
printf("failed to write file [%s], %s!\n", filePath, strerror(errno));
(void)close(fd);
return -1;
}
buf += writeThisTime;
totalToWrite -= writeThisTime;
totalWrite += writeThisTime;
}
(void)fsync(fd);
(void)close(fd);
return (totalWrite == bufSize) ? 0 : -1;
#else
(void)filePath;
PerfPrintBuffer(buf, bufSize);
return 0;
#endif
}
void PerfRecord(int fd, int argc, char **argv)
{
int ret;
int child;
char *buf;
ssize_t len;
SubCmd cmd = {0};
if (argc < 3) { /* perf record argc is at least 3 */
return;
}
ret = PerfRecordAttrInit();
if (ret != 0) {
printf("perf record attr init failed\n");
return;
}
ret = ParseOptions(argc - 2, &argv[2], g_recordOpts, &cmd); /* parse option and cmd begin at index 2 */
if (ret != 0) {
printf("parse error\n");
return;
}
ret = PerfConfig(fd, &g_recordAttr);
if (ret != 0) {
printf("perf config failed\n");
return;
}
PerfStart(fd, 0);
child = fork();
if (child < 0) {
printf("fork error\n");
PerfStop(fd);
return;
} else if (child == 0) {
(void)execve(cmd.path, cmd.params, NULL);
exit(0);
}
waitpid(child, 0, 0);
PerfStop(fd);
buf = (char *)malloc(LOSCFG_PERF_BUFFER_SIZE);
if (buf == NULL) {
printf("no memory for read perf 0x%x\n", LOSCFG_PERF_BUFFER_SIZE);
return;
}
len = PerfRead(fd, buf, LOSCFG_PERF_BUFFER_SIZE);
ret = PerfWriteFile(g_savePath, buf, len);
if (ret == 0) {
printf("save perf data success at %s\n", g_savePath);
} else {
printf("save perf data failed at %s\n", g_savePath);
}
free(buf);
}

149
apps/perf/src/perf_stat.c Normal file
View File

@@ -0,0 +1,149 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <unistd.h>
#include <securec.h>
#include <sys/wait.h>
#include "perf.h"
#include "option.h"
#include "perf_stat.h"
static PerfConfigAttr g_statAttr;
static inline int GetEvents(const char *argv)
{
return ParseEvents(argv, &g_statAttr.eventsCfg, &g_statAttr.eventsCfg.eventsNr);
}
static inline int GetTids(const char *argv)
{
return ParseIds(argv, (int *)g_statAttr.taskIds, &g_statAttr.taskIdsNr);
}
static inline int GetPids(const char *argv)
{
return ParseIds(argv, (int *)g_statAttr.processIds, &g_statAttr.processIdsNr);
}
static PerfOption g_statOpts[] = {
OPTION_CALLBACK("-e", GetEvents),
OPTION_CALLBACK("-t", GetTids),
OPTION_CALLBACK("-P", GetPids),
OPTION_UINT("-p", &g_statAttr.eventsCfg.events[0].period),
OPTION_UINT("-s", &g_statAttr.sampleType),
OPTION_UINT("-d", &g_statAttr.eventsCfg.predivided),
};
static int PerfStatAttrInit(void)
{
PerfConfigAttr attr = {
.eventsCfg = {
#ifdef LOSCFG_PERF_HW_PMU
.type = PERF_EVENT_TYPE_HW,
.events = {
[0] = {PERF_COUNT_HW_CPU_CYCLES, 0xFFFF},
[1] = {PERF_COUNT_HW_INSTRUCTIONS, 0xFFFFFF00},
[2] = {PERF_COUNT_HW_ICACHE_REFERENCES, 0xFFFF},
[3] = {PERF_COUNT_HW_DCACHE_REFERENCES, 0xFFFF},
},
.eventsNr = 4, /* 4 events */
#elif defined LOSCFG_PERF_TIMED_PMU
.type = PERF_EVENT_TYPE_TIMED,
.events = {
[0] = {PERF_COUNT_CPU_CLOCK, 100},
},
.eventsNr = 1, /* 1 event */
#elif defined LOSCFG_PERF_SW_PMU
.type = PERF_EVENT_TYPE_SW,
.events = {
[0] = {PERF_COUNT_SW_TASK_SWITCH, 1},
[1] = {PERF_COUNT_SW_IRQ_RESPONSE, 1},
[2] = {PERF_COUNT_SW_MEM_ALLOC, 1},
[3] = {PERF_COUNT_SW_MUX_PEND, 1},
},
.eventsNr = 4, /* 4 events */
#endif
.predivided = 0,
},
.taskIds = {0},
.taskIdsNr = 0,
.processIds = {0},
.processIdsNr = 0,
.needSample = 0,
.sampleType = 0,
};
return memcpy_s(&g_statAttr, sizeof(PerfConfigAttr), &attr, sizeof(PerfConfigAttr)) != EOK ? -1 : 0;
}
void PerfStat(int fd, int argc, char **argv)
{
int ret;
int child;
SubCmd cmd = {0};
if (argc < 3) { /* perf stat argc is at least 3 */
return;
}
ret = PerfStatAttrInit();
if (ret != 0) {
printf("perf stat attr init failed\n");
return;
}
ret = ParseOptions(argc - 2, &argv[2], g_statOpts, &cmd); /* parse option and cmd begin at index 2 */
if (ret != 0) {
printf("parse error\n");
return;
}
ret = PerfConfig(fd, &g_statAttr);
if (ret != 0) {
printf("perf config failed\n");
return;
}
PerfStart(fd, 0);
child = fork();
if (child < 0) {
printf("fork error\n");
goto EXIT;
} else if (child == 0) {
(void)execve(cmd.path, cmd.params, NULL);
exit(0);
}
(void)waitpid(child, 0, 0);
EXIT:
PerfStop(fd);
}

View File

@@ -29,9 +29,7 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include "unistd.h"
#include "shcmd.h"
@@ -48,7 +46,7 @@ int Chdir(const char *tgtDir)
ret = chdir(tgtDir);
if (ret == 0) {
ret = OsShellSetWorkingDirtectory(tgtDir, strlen(tgtDir) + 1); /* 1: the length of '\0' */
ret = OsShellSetWorkingDirectory(tgtDir, strlen(tgtDir) + 1); /* 1: the length of '\0' */
}
return ret;

View File

@@ -53,7 +53,7 @@ typedef struct {
} CmdKeyLink;
#define NEED_NEW_LINE(timesPrint, lineCap) ((timesPrint) % (lineCap) == 0)
#define SCREEN_IS_FULL(timesPrint, lineCap) ((timesPrint) >= ((lineCap) * DEFAULT_SCREEN_HEIGNT))
#define SCREEN_IS_FULL(timesPrint, lineCap) ((timesPrint) >= ((lineCap) * DEFAULT_SCREEN_HEIGHT))
extern unsigned int OsCmdExec(CmdParsed *cmdParsed, char *cmdStr);
extern unsigned int OsCmdKeyShift(const char *cmdKey, char *cmdOut, unsigned int size);
@@ -62,7 +62,7 @@ extern void OsShellCmdPush(const char *string, CmdKeyLink *cmdKeyLink);
extern void OsShellHistoryShow(unsigned int value, ShellCB *shellCB);
extern unsigned int OsShellKeyInit(ShellCB *shellCB);
extern void OsShellKeyDeInit(CmdKeyLink *cmdKeyLink);
extern int OsShellSetWorkingDirtectory(const char *dir, size_t len);
extern int OsShellSetWorkingDirectory(const char *dir, size_t len);
#ifdef __cplusplus
#if __cplusplus

View File

@@ -54,7 +54,7 @@ extern "C" {
#define CMD_HISTORY_LEN 10
#define CMD_MAX_PATH 256
#define DEFAULT_SCREEN_WIDTH 80
#define DEFAULT_SCREEN_HEIGNT 24
#define DEFAULT_SCREEN_HEIGHT 24
#define SWITCH_QUOTES_STATUS(qu) do { \
if ((qu) == TRUE) { \

View File

@@ -32,10 +32,6 @@
#ifndef _SHELL_PRI_H
#define _SHELL_PRI_H
#include "sys/types.h"
#include "bits/alltypes.h"
#include "shcmd.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {

View File

@@ -32,9 +32,6 @@
#ifndef _SHERR_H
#define _SHERR_H
#include "sys/types.h"
#include "bits/alltypes.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {

View File

@@ -43,8 +43,13 @@ extern "C" {
#define SHELL_ENTRY_STACKSIZE 0x1000
#define SHELL_TASK_STACKSIZE 0x3000
#define SHELL_EXEC_COMMAND "exec "
#define SHELL_EXEC_COMMAND_BYTES 5
#define SHELL_EXEC_COMMAND "exec"
#define SHELL_EXEC_COMMAND_BYTES 4
#define CMD_EXEC_COMMAND SHELL_EXEC_COMMAND" "
#define CMD_EXEC_COMMAND_BYTES (SHELL_EXEC_COMMAND_BYTES + 1)
#define CMD_EXIT_COMMAND "exit"
#define CMD_EXIT_COMMAND_BYTES 4
#define CMD_EXIT_CODE_BASE_DEC 10
#define CONSOLE_IOC_MAGIC 'c'
#define CONSOLE_CONTROL_REG_USERTASK _IO(CONSOLE_IOC_MAGIC, 7)
@@ -54,9 +59,10 @@ extern "C" {
#define COLOR_L_RED "\e[1;31m"
#define SHELL_PROMPT COLOR_L_RED"OHOS # "COLOR_NONE
typedef void (*OutputFunc)(const char *fmt, ...);
typedef void (* OutputFunc)(const char *fmt, ...);
extern int ShellTaskInit(ShellCB *shellCB);
extern int ShellEntryInit(ShellCB *shellCB);
extern void ChildExec(const char *cmdName, char *const paramArray[]);
extern void ShellCmdLineParse(char c, OutputFunc outputFunc, ShellCB *shellCB);
extern int ShellNotify(ShellCB *shellCB);

View File

@@ -42,7 +42,7 @@ extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
extern char *OsShellGetWorkingDirtectory(void);
extern char *OsShellGetWorkingDirectory(void);
extern unsigned int OsShellInit(void);
extern int OsShellDeinit(ShellCB *shellCB);
extern ShellCB *OsGetShellCb(void);

View File

@@ -29,6 +29,8 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#define _GNU_SOURCE
#include "show.h"
#include "shmsg.h"
#include "shcmd.h"
@@ -95,6 +97,9 @@ static int DoShellExec(char **argv)
int ret = SH_NOK;
char *cmdLine = NULL;
if (strncmp(argv[0], SHELL_EXEC_COMMAND, SHELL_EXEC_COMMAND_BYTES) == 0) {
ChildExec(argv[1], argv + 1);
}
for (i = 0; argv[i]; i++) {
len += strlen(argv[i]);
}
@@ -105,12 +110,12 @@ static int DoShellExec(char **argv)
}
memset_s(cmdLine, len, 0, len);
for(j = 0; j < i; j++) {
for (j = 0; j < i; j++) {
strcat_s(cmdLine, len, argv[j]);
strcat_s(cmdLine, len, " ");
}
cmdLine[len - 2] = '\0';
cmdLine[len - 2] = '\0'; /* 2, (len - 2) is the end of cmdline buf */
ret = syscall(__NR_shellexec, argv[0], cmdLine);
free(cmdLine);
return ret;
@@ -121,7 +126,7 @@ int main(int argc, char **argv)
int ret = SH_NOK;
ShellCB *shellCB = NULL;
if (!strcmp(argv[0], "shell") && argv[1]) {
if (argc > 1) {
ret = DoShellExec(argv + 1);
return ret;
}

View File

@@ -91,12 +91,12 @@ static int OsStrSeparateTabStrGet(const char **tabStr, CmdParsed *parsed, unsign
return SH_OK;
}
char *OsShellGetWorkingDirtectory()
char *OsShellGetWorkingDirectory(void)
{
return OsGetShellCb()->shellWorkingDirectory;
}
int OsShellSetWorkingDirtectory(const char *dir, size_t len)
int OsShellSetWorkingDirectory(const char *dir, size_t len)
{
if (dir == NULL) {
return SH_NOK;
@@ -115,7 +115,7 @@ static int OsStrSeparate(const char *tabStr, char *strPath, char *nameLooking, u
char *strEnd = NULL;
char *cutPos = NULL;
CmdParsed parsed = {0};
char *shellWorkingDirectory = OsShellGetWorkingDirtectory();
char *shellWorkingDirectory = OsShellGetWorkingDirectory();
int ret;
ret = OsStrSeparateTabStrGet(&tabStr, &parsed, tabStrLen);
@@ -223,7 +223,7 @@ static int OsPrintMatchList(unsigned int count, const char *strPath, const char
return (int)SH_ERROR;
}
if (count > (lineCap * DEFAULT_SCREEN_HEIGNT)) {
if (count > (lineCap * DEFAULT_SCREEN_HEIGHT)) {
ret = OsSurePrintAll(count);
if (ret != 1) {
return ret;
@@ -375,10 +375,10 @@ static int OsTabMatchFile(char *cmdKey, unsigned int *len)
}
/*
* Description: Pass in the string and clear useless space ,which inlcude:
* Description: Pass in the string and clear useless space ,which include:
* 1) The overmatch space which is not be marked by Quote's area
* Squeeze the overmatch space into one space
* 2) Clear all space before first vaild charatctor
* 2) Clear all space before first valid charatctor
* Input: cmdKey : Pass in the buff string, which is ready to be operated
* cmdOut : Pass out the buffer string ,which has already been operated
* size : cmdKey length
@@ -407,7 +407,7 @@ unsigned int OsCmdKeyShift(const char *cmdKey, char *cmdOut, unsigned int size)
/* Backup the 'output' start address */
outputBak = output;
/* Scan each charactor in 'cmdKey',and squeeze the overmuch space and ignore invaild charactor */
/* Scan each charactor in 'cmdKey',and squeeze the overmuch space and ignore invalid charactor */
for (; *cmdKey != '\0'; cmdKey++) {
/* Detected a Double Quotes, switch the matching status */
if (*(cmdKey) == '\"') {
@@ -417,7 +417,7 @@ unsigned int OsCmdKeyShift(const char *cmdKey, char *cmdOut, unsigned int size)
/* 1) Quotes matching status is FALSE (which said that the space is not been marked by double quotes) */
/* 2) Current charactor is a space */
/* 3) Next charactor is a space too, or the string is been seeked to the end already(\0) */
/* 4) Invaild charactor, such as single quotes */
/* 4) Invalid charactor, such as single quotes */
if ((*cmdKey == ' ') && ((*(cmdKey + 1) == ' ') || (*(cmdKey + 1) == '\0')) && QUOTES_STATUS_CLOSE(quotes)) {
continue;
}

View File

@@ -29,6 +29,8 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#define _GNU_SOURCE
#include "stdlib.h"
#include "stdio.h"
#include "unistd.h"
@@ -42,7 +44,10 @@
#include "shell_pri.h"
#include "shcmd.h"
#define CHAR_CTRL_C '\x03'
#define CHAR_CTRL_DEL '\x7F'
#define VISIABLE_CHAR(ch) ((ch) > 0x1F && (ch) < 0x7F)
char *GetCmdline(ShellCB *shellCB)
{
@@ -128,7 +133,7 @@ int ShellNotify(ShellCB *shellCB)
}
enum {
STAT_NOMAL_KEY,
STAT_NORMAL_KEY,
STAT_ESC_KEY,
STAT_MULTI_KEY
};
@@ -147,23 +152,23 @@ static int ShellCmdLineCheckUDRL(const char ch, ShellCB *shellCB)
} else if (ch == 0x41) { /* up */
if (shellCB->shellKeyType == STAT_MULTI_KEY) {
OsShellHistoryShow(CMD_KEY_UP, shellCB);
shellCB->shellKeyType = STAT_NOMAL_KEY;
shellCB->shellKeyType = STAT_NORMAL_KEY;
return ret;
}
} else if (ch == 0x42) { /* down */
if (shellCB->shellKeyType == STAT_MULTI_KEY) {
shellCB->shellKeyType = STAT_NOMAL_KEY;
shellCB->shellKeyType = STAT_NORMAL_KEY;
OsShellHistoryShow(CMD_KEY_DOWN, shellCB);
return ret;
}
} else if (ch == 0x43) { /* right */
if (shellCB->shellKeyType == STAT_MULTI_KEY) {
shellCB->shellKeyType = STAT_NOMAL_KEY;
shellCB->shellKeyType = STAT_NORMAL_KEY;
return ret;
}
} else if (ch == 0x44) { /* left */
if (shellCB->shellKeyType == STAT_MULTI_KEY) {
shellCB->shellKeyType = STAT_NOMAL_KEY;
shellCB->shellKeyType = STAT_NORMAL_KEY;
return ret;
}
}
@@ -200,7 +205,21 @@ void ParseEnterKey(OutputFunc outputFunc, ShellCB *shellCB)
shellCB->shellBuf[shellCB->shellBufOffset] = '\0';
}
NOTIFY:
outputFunc("\n");
shellCB->shellBufOffset = 0;
ShellTaskNotify(shellCB);
}
void ParseCancelKey(OutputFunc outputFunc, ShellCB *shellCB)
{
if ((shellCB == NULL) || (outputFunc == NULL)) {
return;
}
if (shellCB->shellBufOffset <= (SHOW_MAX_LEN - 1)) {
shellCB->shellBuf[0] = CHAR_CTRL_C;
shellCB->shellBuf[1] = '\0';
}
shellCB->shellBufOffset = 0;
ShellTaskNotify(shellCB);
}
@@ -236,7 +255,7 @@ void ParseTabKey(OutputFunc outputFunc, ShellCB *shellCB)
void ParseNormalChar(char ch, OutputFunc outputFunc, ShellCB *shellCB)
{
if ((shellCB == NULL) || (outputFunc == NULL)) {
if ((shellCB == NULL) || (outputFunc == NULL) || !VISIABLE_CHAR(ch)) {
return;
}
@@ -246,7 +265,7 @@ void ParseNormalChar(char ch, OutputFunc outputFunc, ShellCB *shellCB)
outputFunc("%c", ch);
}
shellCB->shellKeyType = STAT_NOMAL_KEY;
shellCB->shellKeyType = STAT_NORMAL_KEY;
}
void ShellCmdLineParse(char c, OutputFunc outputFunc, ShellCB *shellCB)
@@ -254,7 +273,7 @@ void ShellCmdLineParse(char c, OutputFunc outputFunc, ShellCB *shellCB)
const char ch = c;
int ret;
if ((shellCB->shellBufOffset == 0) && (ch != '\n') && (ch != '\0')) {
if ((shellCB->shellBufOffset == 0) && (ch != '\n') && (ch != CHAR_CTRL_C) && (ch != '\0')) {
(void)memset_s(shellCB->shellBuf, SHOW_MAX_LEN, 0, SHOW_MAX_LEN);
}
@@ -263,8 +282,11 @@ void ShellCmdLineParse(char c, OutputFunc outputFunc, ShellCB *shellCB)
case '\n': /* enter */
ParseEnterKey(outputFunc, shellCB);
break;
case CHAR_CTRL_C: /* ctrl + c */
ParseCancelKey(outputFunc, shellCB);
break;
case '\b': /* backspace */
case 0x7F: /* delete(0x7F) */
case CHAR_CTRL_DEL: /* delete(0x7F) */
ParseDeleteKey(outputFunc, shellCB);
break;
case '\t': /* tab */
@@ -329,40 +351,82 @@ char *GetCmdName(const char *cmdline, unsigned int len)
return cmdName;
}
void ChildExec(const char *cmdName, char *const paramArray[])
{
int ret;
pid_t gid;
ret = setpgrp();
if (ret == -1) {
exit(1);
}
gid = getpgrp();
if (gid < 0) {
printf("get group id failed, pgrpid %d, errno %d\n", gid, errno);
exit(1);
}
ret = tcsetpgrp(STDIN_FILENO, gid);
if (ret != 0) {
printf("tcsetpgrp failed, errno %d\n", errno);
exit(1);
}
ret = execve(cmdName, paramArray, NULL);
if (ret == -1) {
perror("execve");
exit(-1);
}
}
int CheckExit(const char *cmdName, const CmdParsed *cmdParsed)
{
int ret = 0;
if (strlen(cmdName) != CMD_EXIT_COMMAND_BYTES || strncmp(cmdName, CMD_EXIT_COMMAND, CMD_EXIT_COMMAND_BYTES) != 0) {
return 0;
}
if (cmdParsed->paramCnt > 1) {
printf("exit: too many arguments\n");
return -1;
}
if (cmdParsed->paramCnt == 1) {
char *p = NULL;
ret = strtol(cmdParsed->paramArray[0], &p, CMD_EXIT_CODE_BASE_DEC);
if (*p != '\0') {
printf("exit: bad number: %s\n", cmdParsed->paramArray[0]);
return -1;
}
}
exit(ret);
}
static void DoCmdExec(const char *cmdName, const char *cmdline, unsigned int len, const CmdParsed *cmdParsed)
{
int ret;
pid_t forkPid;
pid_t gid;
if (strncmp(cmdline, SHELL_EXEC_COMMAND, SHELL_EXEC_COMMAND_BYTES) == 0) {
if (strncmp(cmdline, CMD_EXEC_COMMAND, CMD_EXEC_COMMAND_BYTES) == 0) {
forkPid = fork();
if (forkPid < 0) {
printf("Faild to fork from shell\n");
return;
} else if (forkPid == 0) {
ret = setpgrp();
if (ret == -1) {
exit(1);
}
gid = getpgrp();
if (gid < 0) {
printf("get group id failed, pgrpid %d, errno %d\n", gid, errno);
}
ret = tcsetpgrp(STDIN_FILENO, gid);
ChildExec(cmdParsed->paramArray[0], cmdParsed->paramArray);
} else {
waitpid(forkPid, 0, 0);
ret = tcsetpgrp(STDIN_FILENO, getpid());
if (ret != 0) {
printf("tcsetpgrp failed, errno %d\n", errno);
}
ret = execve((const char *)cmdParsed->paramArray[0], (char * const *)cmdParsed->paramArray, NULL);
if (ret == -1) {
perror("execve");
exit(-1);
}
}
} else {
if (CheckExit(cmdName, cmdParsed) < 0) {
return;
}
(void)syscall(__NR_shellexec, cmdName, cmdline);
}
}
@@ -397,7 +461,7 @@ static void ParseAndExecCmdline(CmdParsed *cmdParsed, const char *cmdline, unsig
DoCmdExec(cmdName, cmdlineOrigin, len, cmdParsed);
if (getcwd(shellWorkingDirectory, PATH_MAX) != NULL) {
(void)OsShellSetWorkingDirtectory(shellWorkingDirectory, (PATH_MAX + 1));
(void)OsShellSetWorkingDirectory(shellWorkingDirectory, (PATH_MAX + 1));
}
OUT:
@@ -417,7 +481,7 @@ unsigned int PreHandleCmdline(const char *input, char **output, unsigned int *ou
unsigned int removeLen = strlen("./"); /* "./" needs to be removed if it exists */
unsigned int ret;
char *newCmd = NULL;
char *execCmd = SHELL_EXEC_COMMAND;
char *execCmd = CMD_EXEC_COMMAND;
const char *cmdBuf = input;
unsigned int cmdBufLen = strlen(cmdBuf);
char *shiftStr = (char *)malloc(cmdBufLen + 1);
@@ -520,7 +584,11 @@ static void ShellCmdProcess(ShellCB *shellCB)
if (buf == NULL) {
break;
}
if (buf[0] == CHAR_CTRL_C) {
printf("^C");
buf[0] = '\n';
}
printf("\n");
ExecCmdline(buf);
ShellSaveHistoryCmd(buf, shellCB);
shellCB->cmdMaskKeyLink = shellCB->cmdHistoryKeyLink;

View File

@@ -46,7 +46,10 @@ copy("copy_toybox_config") {
}
build_ext_component("build_toybox") {
deps = [ ":copy_toybox_src", ":copy_toybox_config" ]
deps = [
":copy_toybox_config",
":copy_toybox_src",
]
deps += [ "//prebuilts/lite/sysroot" ]
exec_path = rebase_path("$target_out_dir/toybox_build")

View File

@@ -31,4 +31,4 @@ import("//kernel/liteos_a/liteos.gni")
executable("trace") {
sources = [ "src/trace.c" ]
}
}

View File

@@ -88,11 +88,13 @@ static void TraceWrite(int fd, int argc, char **argv)
{
int i;
UsrEventInfo info = {0};
info.eventType = strtoul(argv[2], NULL, 0);
info.identity = strtoul(argv[3], NULL, 0);
info.eventType = strtoul(argv[2], NULL, 0); /* 2, argv number */
info.identity = strtoul(argv[3], NULL, 0); /* 3, argv number */
/* 4, argc -4 means user argv that does not contain argv[0]~argv[3] */
int paramNum = (argc - 4) > TRACE_USR_MAX_PARAMS ? TRACE_USR_MAX_PARAMS : (argc - 4);
for (i = 0; i < paramNum; i++) {
/* 4, argc -4 means user argv that does not contain argv[0]~argv[3] */
info.params[i] = strtoul(argv[4 + i], NULL, 0);
}
(void)write(fd, &info, sizeof(UsrEventInfo));
@@ -108,22 +110,22 @@ int main(int argc, char **argv)
if (argc == 1) {
TraceUsage();
} else if (argc == 2 && strcmp(argv[1], "start") == 0) {
} else if (argc == 2 && strcmp(argv[1], "start") == 0) { /* 2, argv num, no special meaning */
ioctl(fd, TRACE_START, NULL);
} else if (argc == 2 && strcmp(argv[1], "stop") == 0) {
} else if (argc == 2 && strcmp(argv[1], "stop") == 0) { /* 2, argv num, no special meaning */
ioctl(fd, TRACE_STOP, NULL);
} else if (argc == 2 && strcmp(argv[1], "reset") == 0) {
} else if (argc == 2 && strcmp(argv[1], "reset") == 0) { /* 2, argv num, no special meaning */
ioctl(fd, TRACE_RESET, NULL);
} else if (argc == 3 && strcmp(argv[1], "mask") == 0) {
} else if (argc == 3 && strcmp(argv[1], "mask") == 0) { /* 3, argv num, no special meaning */
size_t mask = strtoul(argv[2], NULL, 0);
ioctl(fd, TRACE_SET_MASK, mask);
} else if (argc == 3 && strcmp(argv[1], "dump") == 0) {
} else if (argc == 3 && strcmp(argv[1], "dump") == 0) { /* 3, argv num, no special meaning */
size_t flag = strtoul(argv[2], NULL, 0);
ioctl(fd, TRACE_DUMP, flag);
} else if (argc == 3 && strcmp(argv[1], "read") == 0) {
} else if (argc == 3 && strcmp(argv[1], "read") == 0) { /* 3, argv num, no special meaning */
size_t size = strtoul(argv[2], NULL, 0);
TraceRead(fd, size);
} else if (argc >= 4 && strcmp(argv[1], "write") == 0) {
} else if (argc >= 4 && strcmp(argv[1], "write") == 0) { /* 4, argv num, no special meaning */
TraceWrite(fd, argc, argv);
} else {
printf("Unsupported trace command.\n");

View File

@@ -74,12 +74,3 @@ ARCH_INCLUDE := -I $(LITEOSTOPDIR)/arch/arm/include \
-I $(LITEOSTOPDIR)/arch/arm/$(ARCH)/src/include
LITEOS_PLATFORM_INCLUDE += $(ARCH_INCLUDE)
# expose FPU info to assembly code
ifeq ($(LOSCFG_ARCH_FPU_DISABLE), y)
LITEOS_CMACRO += -DLOSCFG_ARCH_FPU_DISABLE
else ifeq ($(LOSCFG_ARCH_FPU_VFP_D16), y)
LITEOS_CMACRO += -DLOSCFG_ARCH_FPU_VFP_D16
else ifeq ($(LOSCFG_ARCH_FPU_VFP_D32), y)
LITEOS_CMACRO += -DLOSCFG_ARCH_FPU_VFP_D32
endif

View File

@@ -46,10 +46,10 @@ kernel_module(module_name) {
"src/los_hw_runstop.S",
"src/los_hw_tick.c",
"src/los_hwi.c",
"src/smp.c",
"src/strncpy_from_user.c",
"src/strnlen_user.c",
"src/user_copy.c",
"src/smp.c",
]
if (LOSCFG_ARCH_ARM_VER == "armv7-a") {
@@ -64,6 +64,10 @@ kernel_module(module_name) {
include_dirs = [ "src/include" ]
if (defined(LOSCFG_PERF_HW_PMU)) {
sources += [ "src/pmu/armv7_pmu.c" ]
}
if (defined(LOSCFG_GDB)) {
configs += [ ":as_objs_libc_flags" ]
}
@@ -82,9 +86,11 @@ config("as_objs_libc_flags") {
defines = [ "__ASSEMBLY__" ]
# linux style macros
if (defined(LOSCFG_ARCH_ARM_V7A) || defined(LOSCFG_ARCH_ARM_V7R) || defined(LOSCFG_ARCH_ARM_V7M)) {
if (defined(LOSCFG_ARCH_ARM_V7A) || defined(LOSCFG_ARCH_ARM_V7R) ||
defined(LOSCFG_ARCH_ARM_V7M)) {
defines += [ "__LINUX_ARM_ARCH__=7" ]
} else if (defined(LOSCFG_ARCH_ARM_V8A) || defined(LOSCFG_ARCH_ARM_V8R) || defined(LOSCFG_ARCH_ARM_V8M)) {
} else if (defined(LOSCFG_ARCH_ARM_V8A) || defined(LOSCFG_ARCH_ARM_V8R) ||
defined(LOSCFG_ARCH_ARM_V8M)) {
defines += [ "__LINUX_ARM_ARCH__=8" ]
}
}

View File

@@ -32,11 +32,6 @@ include $(LITEOSTOPDIR)/config.mk
MODULE_NAME := $(LOSCFG_ARCH_CPU)
LOCAL_SRCS := $(wildcard src/*.c) $(wildcard src/*.S)
LOCAL_INCLUDE := \
-I $(LITEOSTOPDIR)/kernel/base/include \
-I $(LITEOSTOPDIR)/kernel/extended/include \
-I $(LITEOSTOPDIR)/kernel/extended/dynload/include \
-I $(LITEOSTOPDIR)/arch/arm/arm/include \
ifeq ($(LOSCFG_ARCH_ARM_VER), "armv7-a")
LOCAL_SRCS += $(wildcard src/armv7a/*.S)
@@ -48,7 +43,11 @@ else
LOCAL_SRCS += src/startup/reset_vector_up.S
endif
LOCAL_FLAGS := $(LOCAL_INCLUDE) $(LITEOS_GCOV_OPTS)
ifeq ($(LOSCFG_PERF_HW_PMU), y)
LOCAL_SRCS += src/pmu/armv7_pmu.c
endif
LOCAL_FLAGS := $(LOCAL_INCLUDE)
AS_OBJS_LIBC_FLAGS = -D__ASSEMBLY__
# linux style macros

View File

@@ -38,7 +38,10 @@
#define __LOS_ARCH_MMU_H__
#include "los_typedef.h"
#include "los_mux.h"
#include "los_vm_phys.h"
#ifndef LOSCFG_PAGE_TABLE_FINE_LOCK
#include "los_spinlock.h"
#endif
#ifdef __cplusplus
#if __cplusplus
@@ -47,7 +50,9 @@ extern "C" {
#endif /* __cplusplus */
typedef struct ArchMmu {
LosMux mtx; /**< arch mmu page table entry modification mutex lock */
#ifndef LOSCFG_PAGE_TABLE_FINE_LOCK
SPIN_LOCK_S lock; /**< arch mmu page table entry modification spin lock */
#endif
VADDR_T *virtTtb; /**< translation table base virtual addr */
PADDR_T physTtb; /**< translation table base phys addr */
UINT32 asid; /**< TLB asid */
@@ -71,5 +76,5 @@ VADDR_T *OsGFirstTableGet(VOID);
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* __LOS_VM_PAGE_H__ */
#endif /* __LOS_ARCH_MMU_H__ */

View File

@@ -69,6 +69,11 @@ STATIC INLINE VOID OsClearPte1(PTE_T *pte1Ptr)
OsSavePte1(pte1Ptr, 0);
}
STATIC INLINE PADDR_T OsGetPte1Paddr(PADDR_T PhysTtb, vaddr_t va)
{
return (PhysTtb + (OsGetPte1Index(va) * sizeof(PADDR_T)));
}
STATIC INLINE PTE_T *OsGetPte1Ptr(PTE_T *pte1BasePtr, vaddr_t va)
{
return (pte1BasePtr + OsGetPte1Index(va));

View File

@@ -0,0 +1,108 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _ARMV7_PMU_PRI_H
#define _ARMV7_PMU_PRI_H
#include "los_typedef.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
/* counters overflow flag status reg */
#define ARMV7_FLAG_MASK 0xffffffff /* Mask for writable bits */
#define ARMV7_OVERFLOWED_MASK ARMV7_FLAG_MASK /* Mask for pmu overflowed */
/* pmnc config reg */
#define ARMV7_PMNC_E (1U << 0) /* Enable all counters */
#define ARMV7_PMNC_P (1U << 1) /* Reset all counters */
#define ARMV7_PMNC_C (1U << 2) /* Cycle counter reset */
#define ARMV7_PMNC_D (1U << 3) /* CCNT counts every 64th cpu cycle */
#define ARMV7_PMNC_X (1U << 4) /* Export to ETM */
#define ARMV7_PMNC_DP (1U << 5) /* Disable CCNT if non-invasive debug */
#define ARMV7_PMNC_MASK 0x3f /* Mask for writable bits */
/* pmxevtyper event selection reg */
#define ARMV7_EVTYPE_MASK 0xc80000ff /* Mask for writable bits */
/* armv7 counters index */
#define ARMV7_IDX_COUNTER0 1
#define ARMV7_IDX_CYCLE_COUNTER 0
#define ARMV7_IDX_MAX_COUNTER 9
#define ARMV7_MAX_COUNTERS 32
#define ARMV7_IDX_COUNTER_LAST (ARMV7_IDX_CYCLE_COUNTER + ARMV7_MAX_COUNTERS - 1)
#define ARMV7_COUNTER_MASK (ARMV7_MAX_COUNTERS - 1)
/* armv7 event counter index mapping */
#define ARMV7_CNT2BIT(x) (1UL << (x))
#define ARMV7_IDX2CNT(x) (((x) - ARMV7_IDX_COUNTER0) & ARMV7_COUNTER_MASK)
enum PmuEventType {
ARMV7_PERF_HW_CYCLES = 0xFF, /* cycles */
ARMV7_PERF_HW_INSTRUCTIONS = 0x08, /* instructions */
ARMV7_PERF_HW_DCACHES = 0x04, /* dcache */
ARMV7_PERF_HW_DCACHE_MISSES = 0x03, /* dcache-misses */
ARMV7_PERF_HW_ICACHES = 0x14, /* icache */
ARMV7_PERF_HW_ICACHE_MISSES = 0x01, /* icache-misses */
ARMV7_PERF_HW_BRANCHES = 0x0C, /* software change of pc */
ARMV7_PERF_HW_BRANCE_MISSES = 0x10, /* branch-misses */
ARMV7_PERF_HW_PRED_BRANCH = 0x12, /* predictable branches */
ARMV7_PERF_HW_NUM_CYC_IRQ = 0x50, /* number of cycles Irqs are interrupted */
ARMV7_PERF_HW_EXC_TAKEN = 0x09, /* exception_taken */
ARMV7_PERF_HW_DATA_READ = 0x06, /* data read */
ARMV7_PERF_HW_DATA_WRITE = 0x07, /* data write */
ARMV7_PERF_HW_STREX_PASSED = 0x80, /* strex passed */
ARMV7_PERF_HW_STREX_FAILED = 0x81, /* strex failed */
ARMV7_PERF_HW_LP_IN_TCM = 0x82, /* literal pool in TCM region */
ARMV7_PERF_HW_DMB_STALL = 0x90, /* DMB stall */
ARMV7_PERF_HW_ITCM_ACCESS = 0x91, /* ITCM access */
ARMV7_PERF_HW_DTCM_ACCESS = 0x92, /* DTCM access */
ARMV7_PERF_HW_DATA_EVICTION = 0x93, /* data eviction */
ARMV7_PERF_HW_SCU = 0x94, /* SCU coherency operation */
ARMV7_PERF_HW_INSCACHE_DEP_DW = 0x95, /* instruction cache dependent stall */
ARMV7_PERF_HW_DATA_CACHE_DEP_STALL = 0x96, /* data cache dependent stall */
ARMV7_PERF_HW_NOCACHE_NO_PER_DEP_STALL = 0x97, /* non-cacheable no peripheral dependent stall */
ARMV7_PERF_HW_NOCACHE_PER_DEP_STALL = 0x98, /* non-Cacheable peripheral dependent stall */
ARMV7_PERF_HW_DATA_CACHE_HP_DEP_STALL = 0x99, /* data cache high priority dependent stall */
ARMV7_PERF_HW_AXI_FAST_PERIPHERAL = 0x9A, /* Accesses_to_AXI_fast_peripheral_port(reads_and_writes) */
};
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _ARMV7_PMU_PRI_H */

View File

@@ -44,10 +44,24 @@ extern "C" {
#define OS_SYSTEM_EXC_CURR_CPU 1
#define OS_SYSTEM_EXC_OTHER_CPU 2
#define REGION_PATH_MAX 32
typedef struct {
#ifdef LOSCFG_KERNEL_VM
UINTPTR ip;
UINT32 len; /* f_path length */
CHAR f_path[REGION_PATH_MAX];
#else
UINTPTR ip;
#endif
} IpInfo;
extern UINT32 OsGetSystemStatus(VOID);
extern VOID BackTraceSub(UINTPTR regFP);
extern VOID OsExcInit(VOID);
extern BOOL OsSystemExcIsReset(VOID);
extern UINT32 BackTraceGet(UINTPTR regFP, IpInfo *callChain, UINT32 maxDepth);
extern BOOL OsGetUsrIpInfo(UINTPTR ip, IpInfo *info);
#ifdef __cplusplus
#if __cplusplus

View File

@@ -39,14 +39,21 @@
#include "los_pte_ops.h"
#include "los_tlb_v6.h"
#include "los_printf.h"
#include "los_vm_phys.h"
#include "los_vm_common.h"
#include "los_vm_map.h"
#include "los_vm_boot.h"
#include "los_mmu_descriptor_v6.h"
#include "los_process_pri.h"
#ifdef LOSCFG_KERNEL_MMU
typedef struct {
LosArchMmu *archMmu;
VADDR_T *vaddr;
PADDR_T *paddr;
UINT32 *flags;
} MmuMapInfo;
#define TRY_MAX_TIMES 10
__attribute__((aligned(MMU_DESCRIPTOR_L1_SMALL_ENTRY_NUMBERS))) \
__attribute__((section(".bss.prebss.translation_table"))) UINT8 \
@@ -61,6 +68,75 @@ extern CHAR __mmu_ttlb_begin; /* defined in .ld script */
UINT8 *g_mmuJumpPageTable = (UINT8 *)&__mmu_ttlb_begin; /* temp page table, this is only used when system power up */
#endif
STATIC SPIN_LOCK_S *OsGetPteLock(LosArchMmu *archMmu, PADDR_T paddr, UINT32 *intSave)
{
SPIN_LOCK_S *lock = NULL;
#ifdef LOSCFG_PAGE_TABLE_FINE_LOCK
LosVmPage *vmPage = NULL;
vmPage = OsVmPaddrToPage(paddr);
if (vmPage == NULL) {
return NULL;
}
lock = &vmPage->lock;
#else
lock = &archMmu->lock;
#endif
LOS_SpinLockSave(lock, intSave);
return lock;
}
STATIC SPIN_LOCK_S *OsGetPte1Lock(LosArchMmu *archMmu, PADDR_T paddr, UINT32 *intSave)
{
return OsGetPteLock(archMmu, paddr, intSave);
}
STATIC INLINE VOID OsUnlockPte1(SPIN_LOCK_S *lock, UINT32 intSave)
{
if (lock == NULL) {
return;
}
LOS_SpinUnlockRestore(lock, intSave);
}
STATIC SPIN_LOCK_S *OsGetPte1LockTmp(LosArchMmu *archMmu, PADDR_T paddr, UINT32 *intSave)
{
SPIN_LOCK_S *spinLock = NULL;
#ifdef LOSCFG_PAGE_TABLE_FINE_LOCK
spinLock = OsGetPteLock(archMmu, paddr, intSave);
#else
(VOID)archMmu;
(VOID)paddr;
(VOID)intSave;
#endif
return spinLock;
}
STATIC INLINE VOID OsUnlockPte1Tmp(SPIN_LOCK_S *lock, UINT32 intSave)
{
#ifdef LOSCFG_PAGE_TABLE_FINE_LOCK
if (lock == NULL) {
return;
}
LOS_SpinUnlockRestore(lock, intSave);
#else
(VOID)lock;
(VOID)intSave;
#endif
}
STATIC INLINE SPIN_LOCK_S *OsGetPte2Lock(LosArchMmu *archMmu, PTE_T pte1, UINT32 *intSave)
{
PADDR_T pa = MMU_DESCRIPTOR_L1_PAGE_TABLE_ADDR(pte1);
return OsGetPteLock(archMmu, pa, intSave);
}
STATIC INLINE VOID OsUnlockPte2(SPIN_LOCK_S *lock, UINT32 intSave)
{
return OsUnlockPte1(lock, intSave);
}
STATIC INLINE PTE_T *OsGetPte2BasePtr(PTE_T pte1)
{
PADDR_T pa = MMU_DESCRIPTOR_L1_PAGE_TABLE_ADDR(pte1);
@@ -172,20 +248,30 @@ STATIC VOID OsPutL2Table(const LosArchMmu *archMmu, UINT32 l1Index, paddr_t l2Pa
#endif
}
STATIC VOID OsTryUnmapL1PTE(const LosArchMmu *archMmu, vaddr_t vaddr, UINT32 scanIndex, UINT32 scanCount)
STATIC VOID OsTryUnmapL1PTE(LosArchMmu *archMmu, PTE_T *l1Entry, vaddr_t vaddr, UINT32 scanIndex, UINT32 scanCount)
{
/*
* Check if all pages related to this l1 entry are deallocated.
* We only need to check pages that we did not clear above starting
* from page_idx and wrapped around SECTION.
* from scanIndex and wrapped around SECTION.
*/
UINT32 l1Index;
PTE_T l1Entry;
PTE_T *pte2BasePtr = NULL;
SPIN_LOCK_S *pte1Lock = NULL;
SPIN_LOCK_S *pte2Lock = NULL;
UINT32 pte1IntSave;
UINT32 pte2IntSave;
PTE_T pte1Val;
PADDR_T pte1Paddr;
pte2BasePtr = OsGetPte2BasePtr(OsGetPte1(archMmu->virtTtb, vaddr));
pte1Paddr = OsGetPte1Paddr(archMmu->physTtb, vaddr);
pte2Lock = OsGetPte2Lock(archMmu, *l1Entry, &pte2IntSave);
if (pte2Lock == NULL) {
return;
}
pte2BasePtr = OsGetPte2BasePtr(*l1Entry);
if (pte2BasePtr == NULL) {
VM_ERR("pte2 base ptr is NULL");
OsUnlockPte2(pte2Lock, pte2IntSave);
return;
}
@@ -200,15 +286,27 @@ STATIC VOID OsTryUnmapL1PTE(const LosArchMmu *archMmu, vaddr_t vaddr, UINT32 sca
}
if (!scanCount) {
l1Index = OsGetPte1Index(vaddr);
l1Entry = archMmu->virtTtb[l1Index];
/*
* The pte1 of kprocess is placed in kernel image when compiled. So the pte1Lock will be null.
* There is no situation to simultaneous access the pte1 of kprocess.
*/
pte1Lock = OsGetPte1LockTmp(archMmu, pte1Paddr, &pte1IntSave);
if (!OsIsPte1PageTable(*l1Entry)) {
OsUnlockPte1Tmp(pte1Lock, pte1IntSave);
OsUnlockPte2(pte2Lock, pte2IntSave);
return;
}
pte1Val = *l1Entry;
/* we can kill l1 entry */
OsClearPte1(&archMmu->virtTtb[l1Index]);
OsClearPte1(l1Entry);
l1Index = OsGetPte1Index(vaddr);
OsArmInvalidateTlbMvaNoBarrier(l1Index << MMU_DESCRIPTOR_L1_SMALL_SHIFT);
/* try to free l2 page itself */
OsPutL2Table(archMmu, l1Index, MMU_DESCRIPTOR_L1_PAGE_TABLE_ADDR(l1Entry));
OsPutL2Table(archMmu, l1Index, MMU_DESCRIPTOR_L1_PAGE_TABLE_ADDR(pte1Val));
OsUnlockPte1Tmp(pte1Lock, pte1IntSave);
}
OsUnlockPte2(pte2Lock, pte2IntSave);
}
STATIC UINT32 OsCvtSecCacheFlagsToMMUFlags(UINT32 flags)
@@ -340,34 +438,54 @@ STATIC VOID OsCvtSecAttsToFlags(PTE_T l1Entry, UINT32 *flags)
}
}
STATIC UINT32 OsUnmapL2PTE(const LosArchMmu *archMmu, vaddr_t vaddr, UINT32 *count)
STATIC UINT32 OsUnmapL2PTE(LosArchMmu *archMmu, PTE_T *pte1, vaddr_t vaddr, UINT32 *count)
{
UINT32 unmapCount;
UINT32 pte2Index;
UINT32 intSave;
PTE_T *pte2BasePtr = NULL;
pte2BasePtr = OsGetPte2BasePtr(OsGetPte1((PTE_T *)archMmu->virtTtb, vaddr));
if (pte2BasePtr == NULL) {
LOS_Panic("%s %d, pte2 base ptr is NULL\n", __FUNCTION__, __LINE__);
}
SPIN_LOCK_S *lock = NULL;
pte2Index = OsGetPte2Index(vaddr);
unmapCount = MIN2(MMU_DESCRIPTOR_L2_NUMBERS_PER_L1 - pte2Index, *count);
lock = OsGetPte2Lock(archMmu, *pte1, &intSave);
if (lock == NULL) {
return unmapCount;
}
pte2BasePtr = OsGetPte2BasePtr(*pte1);
if (pte2BasePtr == NULL) {
OsUnlockPte2(lock, intSave);
return unmapCount;
}
/* unmap page run */
OsClearPte2Continuous(&pte2BasePtr[pte2Index], unmapCount);
/* invalidate tlb */
OsArmInvalidateTlbMvaRangeNoBarrier(vaddr, unmapCount);
OsUnlockPte2(lock, intSave);
*count -= unmapCount;
return unmapCount;
}
STATIC UINT32 OsUnmapSection(LosArchMmu *archMmu, vaddr_t *vaddr, UINT32 *count)
STATIC UINT32 OsUnmapSection(LosArchMmu *archMmu, PTE_T *l1Entry, vaddr_t *vaddr, UINT32 *count)
{
UINT32 intSave;
PADDR_T pte1Paddr;
SPIN_LOCK_S *lock = NULL;
pte1Paddr = OsGetPte1Paddr(archMmu->physTtb, *vaddr);
lock = OsGetPte1Lock(archMmu, pte1Paddr, &intSave);
if (!OsIsPte1Section(*l1Entry)) {
OsUnlockPte1(lock, intSave);
return 0;
}
OsClearPte1(OsGetPte1Ptr((PTE_T *)archMmu->virtTtb, *vaddr));
OsArmInvalidateTlbMvaNoBarrier(*vaddr);
OsUnlockPte1(lock, intSave);
*vaddr += MMU_DESCRIPTOR_L1_SMALL_SIZE;
*count -= MMU_DESCRIPTOR_L2_NUMBERS_PER_L1;
@@ -384,12 +502,9 @@ BOOL OsArchMmuInit(LosArchMmu *archMmu, VADDR_T *virtTtb)
}
#endif
status_t retval = LOS_MuxInit(&archMmu->mtx, NULL);
if (retval != LOS_OK) {
VM_ERR("Create mutex for arch mmu failed, status: %d", retval);
return FALSE;
}
#ifndef LOSCFG_PAGE_TABLE_FINE_LOCK
LOS_SpinInit(&archMmu->lock);
#endif
LOS_ListInit(&archMmu->ptList);
archMmu->virtTtb = virtTtb;
archMmu->physTtb = (VADDR_T)(UINTPTR)virtTtb - KERNEL_ASPACE_BASE + SYS_MEM_BASE;
@@ -438,45 +553,55 @@ STATUS_T LOS_ArchMmuQuery(const LosArchMmu *archMmu, VADDR_T vaddr, PADDR_T *pad
STATUS_T LOS_ArchMmuUnmap(LosArchMmu *archMmu, VADDR_T vaddr, size_t count)
{
PTE_T l1Entry;
PTE_T *l1Entry = NULL;
INT32 unmapped = 0;
UINT32 unmapCount = 0;
INT32 tryTime = TRY_MAX_TIMES;
while (count > 0) {
l1Entry = OsGetPte1(archMmu->virtTtb, vaddr);
if (OsIsPte1Invalid(l1Entry)) {
l1Entry = OsGetPte1Ptr(archMmu->virtTtb, vaddr);
if (OsIsPte1Invalid(*l1Entry)) {
unmapCount = OsUnmapL1Invalid(&vaddr, &count);
} else if (OsIsPte1Section(l1Entry)) {
} else if (OsIsPte1Section(*l1Entry)) {
if (MMU_DESCRIPTOR_IS_L1_SIZE_ALIGNED(vaddr) && count >= MMU_DESCRIPTOR_L2_NUMBERS_PER_L1) {
unmapCount = OsUnmapSection(archMmu, &vaddr, &count);
unmapCount = OsUnmapSection(archMmu, l1Entry, &vaddr, &count);
} else {
LOS_Panic("%s %d, unimplemented\n", __FUNCTION__, __LINE__);
}
} else if (OsIsPte1PageTable(l1Entry)) {
unmapCount = OsUnmapL2PTE(archMmu, vaddr, &count);
OsTryUnmapL1PTE(archMmu, vaddr, OsGetPte2Index(vaddr) + unmapCount,
MMU_DESCRIPTOR_L2_NUMBERS_PER_L1 - unmapCount);
} else if (OsIsPte1PageTable(*l1Entry)) {
unmapCount = OsUnmapL2PTE(archMmu, l1Entry, vaddr, &count);
OsTryUnmapL1PTE(archMmu, l1Entry, vaddr, OsGetPte2Index(vaddr) + unmapCount,
MMU_DESCRIPTOR_L2_NUMBERS_PER_L1);
vaddr += unmapCount << MMU_DESCRIPTOR_L2_SMALL_SHIFT;
} else {
LOS_Panic("%s %d, unimplemented\n", __FUNCTION__, __LINE__);
}
tryTime = (unmapCount == 0) ? (tryTime - 1) : tryTime;
if (tryTime == 0) {
return LOS_ERRNO_VM_FAULT;
}
unmapped += unmapCount;
}
OsArmInvalidateTlbBarrier();
return unmapped;
}
STATIC UINT32 OsMapSection(const LosArchMmu *archMmu, UINT32 flags, VADDR_T *vaddr,
PADDR_T *paddr, UINT32 *count)
STATIC UINT32 OsMapSection(MmuMapInfo *mmuMapInfo, UINT32 *count)
{
UINT32 mmuFlags = 0;
UINT32 intSave;
PADDR_T pte1Paddr;
SPIN_LOCK_S *lock = NULL;
mmuFlags |= OsCvtSecFlagsToAttrs(flags);
OsSavePte1(OsGetPte1Ptr(archMmu->virtTtb, *vaddr),
OsTruncPte1(*paddr) | mmuFlags | MMU_DESCRIPTOR_L1_TYPE_SECTION);
mmuFlags |= OsCvtSecFlagsToAttrs(*mmuMapInfo->flags);
pte1Paddr = OsGetPte1Paddr(mmuMapInfo->archMmu->physTtb, *mmuMapInfo->vaddr);
lock = OsGetPte1Lock(mmuMapInfo->archMmu, pte1Paddr, &intSave);
OsSavePte1(OsGetPte1Ptr(mmuMapInfo->archMmu->virtTtb, *mmuMapInfo->vaddr),
OsTruncPte1(*mmuMapInfo->paddr) | mmuFlags | MMU_DESCRIPTOR_L1_TYPE_SECTION);
OsUnlockPte1(lock, intSave);
*count -= MMU_DESCRIPTOR_L2_NUMBERS_PER_L1;
*vaddr += MMU_DESCRIPTOR_L1_SMALL_SIZE;
*paddr += MMU_DESCRIPTOR_L1_SMALL_SIZE;
*mmuMapInfo->vaddr += MMU_DESCRIPTOR_L1_SMALL_SIZE;
*mmuMapInfo->paddr += MMU_DESCRIPTOR_L1_SMALL_SIZE;
return MMU_DESCRIPTOR_L2_NUMBERS_PER_L1;
}
@@ -517,27 +642,10 @@ STATIC STATUS_T OsGetL2Table(LosArchMmu *archMmu, UINT32 l1Index, paddr_t *ppa)
(VOID)memset_s(kvaddr, MMU_DESCRIPTOR_L2_SMALL_SIZE, 0, MMU_DESCRIPTOR_L2_SMALL_SIZE);
/* get physical address */
*ppa = LOS_PaddrQuery(kvaddr) + l2Offset;
*ppa = OsKVaddrToPaddr((VADDR_T)kvaddr) + l2Offset;
return LOS_OK;
}
STATIC VOID OsMapL1PTE(LosArchMmu *archMmu, PTE_T *pte1Ptr, vaddr_t vaddr, UINT32 flags)
{
paddr_t pte2Base = 0;
if (OsGetL2Table(archMmu, OsGetPte1Index(vaddr), &pte2Base) != LOS_OK) {
LOS_Panic("%s %d, failed to allocate pagetable\n", __FUNCTION__, __LINE__);
}
*pte1Ptr = pte2Base | MMU_DESCRIPTOR_L1_TYPE_PAGE_TABLE;
if (flags & VM_MAP_REGION_FLAG_NS) {
*pte1Ptr |= MMU_DESCRIPTOR_L1_PAGETABLE_NON_SECURE;
}
*pte1Ptr &= MMU_DESCRIPTOR_L1_SMALL_DOMAIN_MASK;
*pte1Ptr |= MMU_DESCRIPTOR_L1_SMALL_DOMAIN_CLIENT; // use client AP
OsSavePte1(OsGetPte1Ptr(archMmu->virtTtb, vaddr), *pte1Ptr);
}
STATIC UINT32 OsCvtPte2CacheFlagsToMMUFlags(UINT32 flags)
{
UINT32 mmuFlags = 0;
@@ -618,32 +726,93 @@ STATIC UINT32 OsCvtPte2FlagsToAttrs(UINT32 flags)
return mmuFlags;
}
STATIC UINT32 OsMapL2PageContinous(PTE_T pte1, UINT32 flags, VADDR_T *vaddr, PADDR_T *paddr, UINT32 *count)
STATIC UINT32 OsMapL1PTE(MmuMapInfo *mmuMapInfo, PTE_T *l1Entry, UINT32 *count)
{
PADDR_T pte2Base = 0;
PADDR_T pte1Paddr;
SPIN_LOCK_S *pte1Lock = NULL;
SPIN_LOCK_S *pte2Lock = NULL;
PTE_T *pte2BasePtr = NULL;
UINT32 saveCounts, archFlags, pte1IntSave, pte2IntSave;
pte1Paddr = OsGetPte1Paddr(mmuMapInfo->archMmu->physTtb, *mmuMapInfo->vaddr);
pte1Lock = OsGetPte1Lock(mmuMapInfo->archMmu, pte1Paddr, &pte1IntSave);
if (!OsIsPte1Invalid(*l1Entry)) {
OsUnlockPte1(pte1Lock, pte1IntSave);
return 0;
}
if (OsGetL2Table(mmuMapInfo->archMmu, OsGetPte1Index(*mmuMapInfo->vaddr), &pte2Base) != LOS_OK) {
LOS_Panic("%s %d, failed to allocate pagetable\n", __FUNCTION__, __LINE__);
}
*l1Entry = pte2Base | MMU_DESCRIPTOR_L1_TYPE_PAGE_TABLE;
if (*mmuMapInfo->flags & VM_MAP_REGION_FLAG_NS) {
*l1Entry |= MMU_DESCRIPTOR_L1_PAGETABLE_NON_SECURE;
}
*l1Entry &= MMU_DESCRIPTOR_L1_SMALL_DOMAIN_MASK;
*l1Entry |= MMU_DESCRIPTOR_L1_SMALL_DOMAIN_CLIENT; // use client AP
OsSavePte1(OsGetPte1Ptr(mmuMapInfo->archMmu->virtTtb, *mmuMapInfo->vaddr), *l1Entry);
OsUnlockPte1(pte1Lock, pte1IntSave);
pte2Lock = OsGetPte2Lock(mmuMapInfo->archMmu, *l1Entry, &pte2IntSave);
if (pte2Lock == NULL) {
LOS_Panic("pte2 should not be null!\n");
}
pte2BasePtr = (PTE_T *)LOS_PaddrToKVaddr(pte2Base);
/* compute the arch flags for L2 4K pages */
archFlags = OsCvtPte2FlagsToAttrs(*mmuMapInfo->flags);
saveCounts = OsSavePte2Continuous(pte2BasePtr, OsGetPte2Index(*mmuMapInfo->vaddr), *mmuMapInfo->paddr | archFlags,
*count);
OsUnlockPte2(pte2Lock, pte2IntSave);
*mmuMapInfo->paddr += (saveCounts << MMU_DESCRIPTOR_L2_SMALL_SHIFT);
*mmuMapInfo->vaddr += (saveCounts << MMU_DESCRIPTOR_L2_SMALL_SHIFT);
*count -= saveCounts;
return saveCounts;
}
STATIC UINT32 OsMapL2PageContinous(MmuMapInfo *mmuMapInfo, PTE_T *pte1, UINT32 *count)
{
PTE_T *pte2BasePtr = NULL;
UINT32 archFlags;
UINT32 saveCounts;
UINT32 intSave;
SPIN_LOCK_S *lock = NULL;
pte2BasePtr = OsGetPte2BasePtr(pte1);
lock = OsGetPte2Lock(mmuMapInfo->archMmu, *pte1, &intSave);
if (lock == NULL) {
return 0;
}
pte2BasePtr = OsGetPte2BasePtr(*pte1);
if (pte2BasePtr == NULL) {
LOS_Panic("%s %d, pte1 %#x error\n", __FUNCTION__, __LINE__, pte1);
OsUnlockPte2(lock, intSave);
return 0;
}
/* compute the arch flags for L2 4K pages */
archFlags = OsCvtPte2FlagsToAttrs(flags);
saveCounts = OsSavePte2Continuous(pte2BasePtr, OsGetPte2Index(*vaddr), *paddr | archFlags, *count);
*paddr += (saveCounts << MMU_DESCRIPTOR_L2_SMALL_SHIFT);
*vaddr += (saveCounts << MMU_DESCRIPTOR_L2_SMALL_SHIFT);
archFlags = OsCvtPte2FlagsToAttrs(*mmuMapInfo->flags);
saveCounts = OsSavePte2Continuous(pte2BasePtr, OsGetPte2Index(*mmuMapInfo->vaddr), *mmuMapInfo->paddr | archFlags,
*count);
OsUnlockPte2(lock, intSave);
*mmuMapInfo->paddr += (saveCounts << MMU_DESCRIPTOR_L2_SMALL_SHIFT);
*mmuMapInfo->vaddr += (saveCounts << MMU_DESCRIPTOR_L2_SMALL_SHIFT);
*count -= saveCounts;
return saveCounts;
}
status_t LOS_ArchMmuMap(LosArchMmu *archMmu, VADDR_T vaddr, PADDR_T paddr, size_t count, UINT32 flags)
{
PTE_T l1Entry;
PTE_T *l1Entry = NULL;
UINT32 saveCounts = 0;
INT32 mapped = 0;
INT32 tryTime = TRY_MAX_TIMES;
INT32 checkRst;
MmuMapInfo mmuMapInfo = {
.archMmu = archMmu,
.vaddr = &vaddr,
.paddr = &paddr,
.flags = &flags,
};
checkRst = OsMapParamCheck(flags, vaddr, paddr);
if (checkRst < 0) {
@@ -652,24 +821,27 @@ status_t LOS_ArchMmuMap(LosArchMmu *archMmu, VADDR_T vaddr, PADDR_T paddr, size_
/* see what kind of mapping we can use */
while (count > 0) {
if (MMU_DESCRIPTOR_IS_L1_SIZE_ALIGNED(vaddr) &&
MMU_DESCRIPTOR_IS_L1_SIZE_ALIGNED(paddr) &&
if (MMU_DESCRIPTOR_IS_L1_SIZE_ALIGNED(*mmuMapInfo.vaddr) &&
MMU_DESCRIPTOR_IS_L1_SIZE_ALIGNED(*mmuMapInfo.paddr) &&
count >= MMU_DESCRIPTOR_L2_NUMBERS_PER_L1) {
/* compute the arch flags for L1 sections cache, r ,w ,x, domain and type */
saveCounts = OsMapSection(archMmu, flags, &vaddr, &paddr, &count);
saveCounts = OsMapSection(&mmuMapInfo, &count);
} else {
/* have to use a L2 mapping, we only allocate 4KB for L1, support 0 ~ 1GB */
l1Entry = OsGetPte1(archMmu->virtTtb, vaddr);
if (OsIsPte1Invalid(l1Entry)) {
OsMapL1PTE(archMmu, &l1Entry, vaddr, flags);
saveCounts = OsMapL2PageContinous(l1Entry, flags, &vaddr, &paddr, &count);
} else if (OsIsPte1PageTable(l1Entry)) {
saveCounts = OsMapL2PageContinous(l1Entry, flags, &vaddr, &paddr, &count);
l1Entry = OsGetPte1Ptr(archMmu->virtTtb, *mmuMapInfo.vaddr);
if (OsIsPte1Invalid(*l1Entry)) {
saveCounts = OsMapL1PTE(&mmuMapInfo, l1Entry, &count);
} else if (OsIsPte1PageTable(*l1Entry)) {
saveCounts = OsMapL2PageContinous(&mmuMapInfo, l1Entry, &count);
} else {
LOS_Panic("%s %d, unimplemented tt_entry %x\n", __FUNCTION__, __LINE__, l1Entry);
}
}
mapped += saveCounts;
tryTime = (saveCounts == 0) ? (tryTime - 1) : tryTime;
if (tryTime == 0) {
return LOS_ERRNO_VM_TIMED_OUT;
}
}
return mapped;
@@ -716,7 +888,7 @@ STATUS_T LOS_ArchMmuMove(LosArchMmu *archMmu, VADDR_T oldVaddr, VADDR_T newVaddr
PADDR_T paddr = 0;
if ((archMmu == NULL) || (oldVaddr == 0) || (newVaddr == 0) || (count == 0)) {
VM_ERR("invalid args: archMmu %p, oldVaddr %p, newVddr %p, count %d",
VM_ERR("invalid args: archMmu %p, oldVaddr %p, newVaddr %p, count %d",
archMmu, oldVaddr, newVaddr, count);
return LOS_NOK;
}
@@ -790,10 +962,9 @@ STATUS_T LOS_ArchMmuDestroy(LosArchMmu *archMmu)
LOS_PhysPageFree(page);
}
OsArmWriteTlbiasid(archMmu->asid);
OsArmWriteTlbiasidis(archMmu->asid);
OsFreeAsid(archMmu->asid);
#endif
(VOID)LOS_MuxDestroy(&archMmu->mtx);
return LOS_OK;
}
@@ -862,7 +1033,7 @@ STATIC VOID OsSetKSectionAttr(UINTPTR virtAddr, BOOL uncached)
LosVmSpace *kSpace = LOS_GetKVmSpace();
status_t status;
UINT32 length;
int i;
INT32 i;
LosArchMmuInitMapping *kernelMap = NULL;
UINT32 kmallocLength;
UINT32 flags;
@@ -966,4 +1137,3 @@ VOID OsInitMappingStartUp(VOID)
}
#endif

View File

@@ -147,6 +147,14 @@ OsIrqHandler:
/* disable irq, switch to svc mode */
CPSID i, #0x13
#ifdef LOSCFG_KERNEL_PERF
PUSH {R0-R3, R12, LR}
MOV R0, LR
MOV R1, FP
BL OsPerfSetIrqRegs
POP {R0-R3, R12, LR}
#endif
STMFD SP!, {R0-R3, R12, LR}
STMFD SP, {R13, R14}^
SUB SP, SP, #(4 * 4)

View File

@@ -228,7 +228,8 @@ UINT32 OsArmSharedPageFault(UINT32 excType, ExcContext *frame, UINT32 far, UINT3
break;
}
default:
ret = LOS_ERRNO_VM_NOT_FOUND;
OsArmWriteTlbimvaais(ROUNDDOWN(far, PAGE_SIZE));
ret = LOS_OK;
break;
}
#if defined(LOSCFG_KERNEL_SMP) && defined(LOSCFG_DEBUG_VERSION)
@@ -244,7 +245,7 @@ UINT32 OsArmSharedPageFault(UINT32 excType, ExcContext *frame, UINT32 far, UINT3
STATIC VOID OsExcType(UINT32 excType, ExcContext *excBufAddr, UINT32 far, UINT32 fsr)
{
/* undefinited exception handling or software interrupt */
/* undefined exception handling or software interrupt */
if ((excType == OS_EXCEPT_UNDEF_INSTR) || (excType == OS_EXCEPT_SWI)) {
if ((excBufAddr->regCPSR & INSTR_SET_MASK) == 0) { /* work status: ARM */
excBufAddr->PC = excBufAddr->PC - ARM_INSTR_LEN;
@@ -276,8 +277,8 @@ STATIC const CHAR *g_excTypeString[] = {
#ifdef LOSCFG_KERNEL_VM
STATIC VADDR_T OsGetTextRegionBase(LosVmMapRegion *region, LosProcessCB *runProcess)
{
struct file *curFilep = NULL;
struct file *lastFilep = NULL;
struct Vnode *curVnode = NULL;
struct Vnode *lastVnode = NULL;
LosVmMapRegion *curRegion = NULL;
LosVmMapRegion *lastRegion = NULL;
@@ -296,9 +297,9 @@ STATIC VADDR_T OsGetTextRegionBase(LosVmMapRegion *region, LosProcessCB *runProc
if ((lastRegion == NULL) || !LOS_IsRegionFileValid(lastRegion)) {
goto DONE;
}
curFilep = curRegion->unTypeData.rf.file;
lastFilep = lastRegion->unTypeData.rf.file;
} while (!strcmp(curFilep->f_path, lastFilep->f_path));
curVnode = curRegion->unTypeData.rf.vnode;
lastVnode = lastRegion->unTypeData.rf.vnode;
} while (curVnode == lastVnode);
DONE:
#ifdef LOSCFG_KERNEL_DYNLOAD
@@ -479,7 +480,7 @@ STATIC VOID OsDumpProcessUsedMemRegion(LosProcessCB *runProcess, LosVmSpace *run
RB_SCAN_SAFE_END(&space->regionRbTree, pstRbNodeTemp, pstRbNodeNext)
}
STATIC VOID OsDumpProcessUsedMemNode(UINT16 vmmFalgs)
STATIC VOID OsDumpProcessUsedMemNode(UINT16 vmmFlags)
{
LosProcessCB *runProcess = NULL;
LosVmSpace *runspace = NULL;
@@ -500,7 +501,7 @@ STATIC VOID OsDumpProcessUsedMemNode(UINT16 vmmFalgs)
return;
}
OsDumpProcessUsedMemRegion(runProcess, runspace, vmmFalgs);
OsDumpProcessUsedMemRegion(runProcess, runspace, vmmFlags);
return;
}
#endif
@@ -563,7 +564,6 @@ STATIC VOID OsUserExcHandle(ExcContext *excBufAddr)
#else
g_currHandleExcCpuID = INVALID_CPUID;
#endif
runProcess->processStatus &= ~OS_PROCESS_FLAG_EXIT;
#ifdef LOSCFG_KERNEL_SMP
#ifdef LOSCFG_FS_VFS
@@ -580,10 +580,10 @@ STATIC VOID OsUserExcHandle(ExcContext *excBufAddr)
#endif
OsProcessExitCodeSignalSet(runProcess, SIGUSR2);
/* An exception was raised by a task that is not the current main thread during the exit process of
/* An exception was raised by a task during the exit process of
* the current process.
*/
if ((runProcess->processStatus & OS_PROCESS_FLAG_EXIT) && (runProcess->threadGroupID != runTask->taskID)) {
if (runProcess->processStatus & OS_PROCESS_FLAG_EXIT) {
SCHEDULER_UNLOCK(intSave);
/* Exception handling All operations should be kept prior to that operation */
OsExcRestore();
@@ -690,20 +690,66 @@ FOUND:
return found;
}
VOID BackTraceSub(UINTPTR regFP)
BOOL OsGetUsrIpInfo(UINTPTR ip, IpInfo *info)
{
if (info == NULL) {
return FALSE;
}
#ifdef LOSCFG_KERNEL_VM
BOOL ret = FALSE;
const CHAR *name = NULL;
LosVmMapRegion *region = NULL;
LosProcessCB *runProcess = OsCurrProcessGet();
if (LOS_IsUserAddress((VADDR_T)ip) == FALSE) {
info->ip = ip;
name = "kernel";
ret = FALSE;
goto END;
}
region = LOS_RegionFind(runProcess->vmSpace, (VADDR_T)ip);
if (region == NULL) {
info->ip = ip;
name = "invalid";
ret = FALSE;
goto END;
}
info->ip = ip - OsGetTextRegionBase(region, runProcess);
name = OsGetRegionNameOrFilePath(region);
ret = TRUE;
if (strcmp(name, "/lib/libc.so") != 0) {
PRINT_ERR("ip = 0x%x, %s\n", info->ip, name);
}
END:
info->len = strlen(name);
if (strncpy_s(info->f_path, REGION_PATH_MAX, name, REGION_PATH_MAX - 1) != EOK) {
info->f_path[0] = '\0';
info->len = 0;
PRINT_ERR("copy f_path failed, %s\n", name);
}
return ret;
#else
info->ip = ip;
return FALSE;
#endif
}
UINT32 BackTraceGet(UINTPTR regFP, IpInfo *callChain, UINT32 maxDepth)
{
UINTPTR tmpFP, backLR;
UINTPTR stackStart, stackEnd;
UINTPTR backFP = regFP;
UINT32 count = 0;
BOOL ret;
VADDR_T kvaddr;
#ifdef LOSCFG_KERNEL_VM
LosProcessCB *runProcess = OsCurrProcessGet();
#endif
if (FindSuitableStack(regFP, &stackStart, &stackEnd, &kvaddr) == FALSE) {
PrintExcInfo("traceback error fp = 0x%x\n", regFP);
return;
if (callChain == NULL) {
PrintExcInfo("traceback error fp = 0x%x\n", regFP);
}
return 0;
}
/*
@@ -715,7 +761,9 @@ VOID BackTraceSub(UINTPTR regFP)
tmpFP = *(UINTPTR *)(UINTPTR)kvaddr;
if (IsValidFP(tmpFP, stackStart, stackEnd, NULL) == TRUE) {
backFP = tmpFP;
PrintExcInfo("traceback fp fixed, trace using fp = 0x%x\n", backFP);
if (callChain == NULL) {
PrintExcInfo("traceback fp fixed, trace using fp = 0x%x\n", backFP);
}
}
while (IsValidFP(backFP, stackStart, stackEnd, &kvaddr) == TRUE) {
@@ -723,38 +771,49 @@ VOID BackTraceSub(UINTPTR regFP)
#ifdef LOSCFG_COMPILER_CLANG_LLVM
backFP = *(UINTPTR *)(UINTPTR)kvaddr;
if (IsValidFP(tmpFP + POINTER_SIZE, stackStart, stackEnd, &kvaddr) == FALSE) {
PrintExcInfo("traceback backLR check failed, backLP: 0x%x\n", tmpFP + POINTER_SIZE);
return;
if (callChain == NULL) {
PrintExcInfo("traceback backLR check failed, backLP: 0x%x\n", tmpFP + POINTER_SIZE);
}
return 0;
}
backLR = *(UINTPTR *)(UINTPTR)kvaddr;
#else
backLR = *(UINTPTR *)(UINTPTR)kvaddr;
if (IsValidFP(tmpFP - POINTER_SIZE, stackStart, stackEnd, &kvaddr) == FALSE) {
PrintExcInfo("traceback backFP check failed, backFP: 0x%x\n", tmpFP - POINTER_SIZE);
return;
if (callChain == NULL) {
PrintExcInfo("traceback backFP check failed, backFP: 0x%x\n", tmpFP - POINTER_SIZE);
}
return 0;
}
backFP = *(UINTPTR *)(UINTPTR)kvaddr;
#endif
IpInfo info = {0};
ret = OsGetUsrIpInfo((VADDR_T)backLR, &info);
if (callChain == NULL) {
PrintExcInfo("traceback %u -- lr = 0x%x fp = 0x%x ", count, backLR, backFP);
if (ret) {
#ifdef LOSCFG_KERNEL_VM
LosVmMapRegion *region = NULL;
if (LOS_IsUserAddress((VADDR_T)backLR) == TRUE) {
region = LOS_RegionFind(runProcess->vmSpace, (VADDR_T)backLR);
}
if (region != NULL) {
PrintExcInfo("traceback %u -- lr = 0x%x fp = 0x%x lr in %s --> 0x%x\n", count, backLR, backFP,
OsGetRegionNameOrFilePath(region),
backLR - OsGetTextRegionBase(region, runProcess));
region = NULL;
} else
PrintExcInfo("lr in %s --> 0x%x\n", info.f_path, info.ip);
#else
PrintExcInfo("\n");
#endif
{
PrintExcInfo("traceback %u -- lr = 0x%x fp = 0x%x\n", count, backLR, backFP);
} else {
PrintExcInfo("\n");
}
} else {
(VOID)memcpy_s(&callChain[count], sizeof(IpInfo), &info, sizeof(IpInfo));
}
count++;
if ((count == OS_MAX_BACKTRACE) || (backFP == tmpFP)) {
if ((count == maxDepth) || (backFP == tmpFP)) {
break;
}
}
return count;
}
VOID BackTraceSub(UINTPTR regFP)
{
(VOID)BackTraceGet(regFP, NULL, OS_MAX_BACKTRACE);
}
VOID BackTrace(UINT32 regFP)
@@ -989,15 +1048,17 @@ STATIC VOID OsCheckAllCpuStatus(VOID)
LOCKDEP_CLEAR_LOCKS();
LOS_SpinLock(&g_excSerializerSpin);
/* Only the current nuclear anomaly */
/* Only the current CPU anomaly */
if (g_currHandleExcCpuID == INVALID_CPUID) {
g_currHandleExcCpuID = currCpuID;
g_currHandleExcPID = OsCurrProcessGet()->processID;
LOS_SpinUnlock(&g_excSerializerSpin);
#ifndef LOSCFG_SAVE_EXCINFO
if (g_excFromUserMode[currCpuID] == FALSE) {
target = (UINT32)(OS_MP_CPU_ALL & ~CPUID_TO_AFFI_MASK(currCpuID));
HalIrqSendIpi(target, LOS_MP_IPI_HALT);
}
#endif
} else if (g_excFromUserMode[currCpuID] == TRUE) {
/* Both cores raise exceptions, and the current core is a user-mode exception.
* Both cores are abnormal and come from the same process
@@ -1022,11 +1083,12 @@ STATIC VOID OsCheckAllCpuStatus(VOID)
while (1) {}
}
}
#ifndef LOSCFG_SAVE_EXCINFO
/* use halt ipi to stop other active cores */
if (g_excFromUserMode[ArchCurrCpuid()] == FALSE) {
WaitAllCpuStop(currCpuID);
}
#endif
}
#endif
@@ -1176,10 +1238,10 @@ __attribute__((noinline)) VOID LOS_Panic(const CHAR *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
UartVprintf(fmt, ap);
OsVprintf(fmt, ap, EXC_OUTPUT);
va_end(ap);
__asm__ __volatile__("swi 0");
while (1);
while (1) {}
}
/* stack protector */

View File

@@ -0,0 +1,373 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "armv7_pmu_pri.h"
#include "perf_pmu_pri.h"
#include "los_hw_cpu.h"
#include "asm/platform.h"
OS_PMU_INTS(LOSCFG_KERNEL_CORE_NUM, g_pmuIrqNr);
STATIC HwPmu g_armv7Pmu;
STATIC INLINE UINT32 Armv7PmncRead(VOID)
{
UINT32 value = 0;
__asm__ volatile("mrc p15, 0, %0, c9, c12, 0" : "=r"(value));
return value;
}
STATIC INLINE VOID Armv7PmncWrite(UINT32 value)
{
value &= ARMV7_PMNC_MASK;
__asm__ volatile("mcr p15, 0, %0, c9, c12, 0" : : "r"(value));
ISB;
}
STATIC INLINE UINT32 Armv7PmuOverflowed(UINT32 pmnc)
{
return pmnc & ARMV7_OVERFLOWED_MASK;
}
STATIC INLINE UINT32 Armv7PmuCntOverflowed(UINT32 pmnc, UINT32 index)
{
return pmnc & ARMV7_CNT2BIT(ARMV7_IDX2CNT(index));
}
STATIC INLINE UINT32 Armv7CntValid(UINT32 index)
{
return index <= ARMV7_IDX_COUNTER_LAST;
}
STATIC INLINE VOID Armv7PmuSelCnt(UINT32 index)
{
UINT32 counter = ARMV7_IDX2CNT(index);
__asm__ volatile("mcr p15, 0, %0, c9, c12, 5" : : "r" (counter));
ISB;
}
STATIC INLINE VOID Armv7PmuSetCntPeriod(UINT32 index, UINT32 period)
{
if (!Armv7CntValid(index)) {
PRINT_ERR("CPU writing wrong counter %u\n", index);
} else if (index == ARMV7_IDX_CYCLE_COUNTER) {
__asm__ volatile("mcr p15, 0, %0, c9, c13, 0" : : "r" (period));
} else {
Armv7PmuSelCnt(index);
__asm__ volatile("mcr p15, 0, %0, c9, c13, 2" : : "r" (period));
}
}
STATIC INLINE VOID Armv7BindEvt2Cnt(UINT32 index, UINT32 value)
{
PRINT_DEBUG("bind event: %u to counter: %u\n", value, index);
Armv7PmuSelCnt(index);
value &= ARMV7_EVTYPE_MASK;
__asm__ volatile("mcr p15, 0, %0, c9, c13, 1" : : "r" (value));
}
STATIC INLINE VOID Armv7EnableCnt(UINT32 index)
{
UINT32 counter = ARMV7_IDX2CNT(index);
PRINT_DEBUG("index : %u, counter: %u\n", index, counter);
__asm__ volatile("mcr p15, 0, %0, c9, c12, 1" : : "r" (ARMV7_CNT2BIT(counter)));
}
STATIC INLINE VOID Armv7DisableCnt(UINT32 index)
{
UINT32 counter = ARMV7_IDX2CNT(index);
PRINT_DEBUG("index : %u, counter: %u\n", index, counter);
__asm__ volatile("mcr p15, 0, %0, c9, c12, 2" : : "r" (ARMV7_CNT2BIT(counter)));
}
STATIC INLINE VOID Armv7EnableCntInterrupt(UINT32 index)
{
UINT32 counter = ARMV7_IDX2CNT(index);
__asm__ volatile("mcr p15, 0, %0, c9, c14, 1" : : "r" (ARMV7_CNT2BIT(counter)));
ISB;
}
STATIC INLINE VOID Armv7DisableCntInterrupt(UINT32 index)
{
UINT32 counter = ARMV7_IDX2CNT(index);
__asm__ volatile("mcr p15, 0, %0, c9, c14, 2" : : "r" (ARMV7_CNT2BIT(counter)));
/* Clear the overflow flag in case an interrupt is pending. */
__asm__ volatile("mcr p15, 0, %0, c9, c12, 3" : : "r" (ARMV7_CNT2BIT(counter)));
ISB;
}
STATIC INLINE UINT32 Armv7PmuGetOverflowStatus(VOID)
{
UINT32 value;
__asm__ volatile("mrc p15, 0, %0, c9, c12, 3" : "=r" (value));
value &= ARMV7_FLAG_MASK;
__asm__ volatile("mcr p15, 0, %0, c9, c12, 3" : : "r" (value));
return value;
}
STATIC VOID Armv7EnableEvent(Event *event)
{
UINT32 cnt = event->counter;
if (!Armv7CntValid(cnt)) {
PRINT_ERR("CPU enabling wrong PMNC counter IRQ enable %u\n", cnt);
return;
}
if (event->period == 0) {
PRINT_INFO("event period value not valid, counter: %u\n", cnt);
return;
}
/*
* Enable counter and interrupt, and set the counter to count
* the event that we're interested in.
*/
UINT32 intSave = LOS_IntLock();
Armv7DisableCnt(cnt);
/*
* Set event (if destined for PMNx counters)
* We only need to set the event for the cycle counter if we
* have the ability to perform event filtering.
*/
if (cnt != ARMV7_IDX_CYCLE_COUNTER) {
Armv7BindEvt2Cnt(cnt, event->eventId);
}
/* Enable interrupt for this counter */
Armv7EnableCntInterrupt(cnt);
Armv7EnableCnt(cnt);
LOS_IntRestore(intSave);
PRINT_DEBUG("enabled event: %u cnt: %u\n", event->eventId, cnt);
}
STATIC VOID Armv7DisableEvent(Event *event)
{
UINT32 cnt = event->counter;
if (!Armv7CntValid(cnt)) {
PRINT_ERR("CPU enabling wrong PMNC counter IRQ enable %u\n", cnt);
return;
}
UINT32 intSave = LOS_IntLock();
Armv7DisableCnt(cnt);
Armv7DisableCntInterrupt(cnt);
LOS_IntRestore(intSave);
}
STATIC VOID Armv7StartAllCnt(VOID)
{
PRINT_DEBUG("starting pmu...\n");
/* Enable all counters */
UINT32 reg = Armv7PmncRead() | ARMV7_PMNC_E;
if (g_armv7Pmu.cntDivided) {
reg |= ARMV7_PMNC_D;
} else {
reg &= ~ARMV7_PMNC_D;
}
Armv7PmncWrite(reg);
HalIrqUnmask(g_pmuIrqNr[ArchCurrCpuid()]);
}
STATIC VOID Armv7StopAllCnt(VOID)
{
PRINT_DEBUG("stopping pmu...\n");
/* Disable all counters */
Armv7PmncWrite(Armv7PmncRead() & ~ARMV7_PMNC_E);
HalIrqMask(g_pmuIrqNr[ArchCurrCpuid()]);
}
STATIC VOID Armv7ResetAllCnt(VOID)
{
UINT32 index;
/* The counter and interrupt enable registers are unknown at reset. */
for (index = ARMV7_IDX_CYCLE_COUNTER; index < ARMV7_IDX_MAX_COUNTER; index++) {
Armv7DisableCnt(index);
Armv7DisableCntInterrupt(index);
}
/* Initialize & Reset PMNC: C and P bits and D bits */
UINT32 reg = ARMV7_PMNC_P | ARMV7_PMNC_C | (g_armv7Pmu.cntDivided ? ARMV7_PMNC_D : 0);
Armv7PmncWrite(reg);
}
STATIC VOID Armv7SetEventPeriod(Event *event)
{
if (event->period != 0) {
PRINT_INFO("counter: %u, period: 0x%x\n", event->counter, event->period);
Armv7PmuSetCntPeriod(event->counter, PERIOD_CALC(event->period));
}
}
STATIC UINTPTR Armv7ReadEventCnt(Event *event)
{
UINT32 value = 0;
UINT32 index = event->counter;
if (!Armv7CntValid(index)) {
PRINT_ERR("CPU reading wrong counter %u\n", index);
} else if (index == ARMV7_IDX_CYCLE_COUNTER) {
__asm__ volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (value));
} else {
Armv7PmuSelCnt(index);
__asm__ volatile("mrc p15, 0, %0, c9, c13, 2" : "=r" (value));
}
if (value < PERIOD_CALC(event->period)) {
if (Armv7PmuCntOverflowed(Armv7PmuGetOverflowStatus(), event->counter)) {
value += event->period;
}
} else {
value -= PERIOD_CALC(event->period);
}
return value;
}
STATIC const UINT32 g_armv7Map[] = {
[PERF_COUNT_HW_CPU_CYCLES] = ARMV7_PERF_HW_CYCLES,
[PERF_COUNT_HW_INSTRUCTIONS] = ARMV7_PERF_HW_INSTRUCTIONS,
[PERF_COUNT_HW_DCACHE_REFERENCES] = ARMV7_PERF_HW_DCACHES,
[PERF_COUNT_HW_DCACHE_MISSES] = ARMV7_PERF_HW_DCACHE_MISSES,
[PERF_COUNT_HW_ICACHE_REFERENCES] = ARMV7_PERF_HW_ICACHES,
[PERF_COUNT_HW_ICACHE_MISSES] = ARMV7_PERF_HW_ICACHE_MISSES,
[PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = ARMV7_PERF_HW_BRANCHES,
[PERF_COUNT_HW_BRANCH_MISSES] = ARMV7_PERF_HW_BRANCE_MISSES,
};
UINT32 Armv7PmuMapEvent(UINT32 eventType, BOOL reverse)
{
if (!reverse) { /* Common event to armv7 real event */
if (eventType < ARRAY_SIZE(g_armv7Map)) {
return g_armv7Map[eventType];
}
return eventType;
} else { /* Armv7 real event to common event */
UINT32 i;
for (i = 0; i < ARRAY_SIZE(g_armv7Map); i++) {
if (g_armv7Map[i] == eventType) {
return i;
}
}
return PERF_HW_INVALID_EVENT_TYPE;
}
}
STATIC VOID Armv7PmuIrqHandler(VOID)
{
UINT32 index;
PerfRegs regs;
PerfEvent *events = &(g_armv7Pmu.pmu.events);
UINT32 eventNum = events->nr;
/* Get and reset the IRQ flags */
UINT32 pmnc = Armv7PmuGetOverflowStatus();
if (!Armv7PmuOverflowed(pmnc)) {
return;
}
(VOID)memset_s(&regs, sizeof(PerfRegs), 0, sizeof(PerfRegs));
OsPerfFetchIrqRegs(&regs);
Armv7StopAllCnt();
for (index = 0; index < eventNum; index++) {
Event *event = &(events->per[index]);
/*
* We have a single interrupt for all counters. Check that
* each counter has overflowed before we process it.
*/
if (!Armv7PmuCntOverflowed(pmnc, event->counter) || (event->period == 0)) {
continue;
}
Armv7PmuSetCntPeriod(event->counter, PERIOD_CALC(event->period));
OsPerfUpdateEventCount(event, event->period);
OsPerfHandleOverFlow(event, &regs);
}
Armv7StartAllCnt();
}
UINT32 OsGetPmuMaxCounter(VOID)
{
return ARMV7_IDX_MAX_COUNTER;
}
UINT32 OsGetPmuCycleCounter(VOID)
{
return ARMV7_IDX_CYCLE_COUNTER;
}
UINT32 OsGetPmuCounter0(VOID)
{
return ARMV7_IDX_COUNTER0;
}
STATIC HwPmu g_armv7Pmu = {
.canDivided = TRUE,
.enable = Armv7EnableEvent,
.disable = Armv7DisableEvent,
.start = Armv7StartAllCnt,
.stop = Armv7StopAllCnt,
.clear = Armv7ResetAllCnt,
.setPeriod = Armv7SetEventPeriod,
.readCnt = Armv7ReadEventCnt,
.mapEvent = Armv7PmuMapEvent,
};
UINT32 OsHwPmuInit(VOID)
{
UINT32 ret;
UINT32 index;
for (index = 0; index < LOSCFG_KERNEL_CORE_NUM; index++) {
ret = LOS_HwiCreate(g_pmuIrqNr[index], 0, 0, Armv7PmuIrqHandler, 0);
if (ret != LOS_OK) {
PRINT_ERR("pmu %u irq handler register failed\n", g_pmuIrqNr[index]);
return ret;
}
#ifdef LOSCFG_KERNEL_SMP
HalIrqSetAffinity(g_pmuIrqNr[index], CPUID_TO_AFFI_MASK(index));
#endif
}
ret = OsPerfHwInit(&g_armv7Pmu);
return ret;
}

View File

@@ -35,7 +35,6 @@
#include "los_hw.h"
#include "los_atomic.h"
#include "los_arch_mmu.h"
#include "los_init_pri.h"
#include "gic_common.h"
#include "los_task_pri.h"
@@ -55,7 +54,7 @@ VOID HalArchCpuOn(UINT32 cpuNum, ArchCpuStartFunc func, struct SmpOps *ops, VOID
{
struct OsCpuInit *cpuInit = &g_cpuInit[cpuNum - 1];
UINTPTR startEntry = (UINTPTR)&reset_vector - KERNEL_VMM_BASE + SYS_MEM_BASE;
INT32 ret = 0;
INT32 ret;
cpuInit->cpuStart = func;
cpuInit->arg = arg;
@@ -94,7 +93,6 @@ VOID HalSecondaryCpuStart(VOID)
/* store each core's hwid */
CPU_MAP_SET(cpuid, OsHwIDGet());
HalIrqInitPercpu();
OsInitCall(LOS_INIT_LEVEL_ARCH);
cpuInit->cpuStart(cpuInit->arg);

View File

@@ -31,18 +31,10 @@ include $(LITEOSTOPDIR)/config.mk
MODULE_NAME := $(notdir $(shell pwd))
# LOCAL_SRCS := $(wildcard *.c)
ifeq ($(LOSCFG_ARCH_GIC_V2), y)
LOCAL_SRCS := gic_v2.c
else ifeq ($(LOSCFG_ARCH_GIC_V3), y)
LOCAL_SRCS := gic_v3.c
endif
LOCAL_INCLUDE := \
-I $(LITEOSTOPDIR)/kernel/base/include \
-I $(LITEOSTOPDIR)/arch/arm/include \
-I $(LITEOSTOPDIR)/arch/arm/arm/src/include \
LOCAL_FLAGS := $(LOCAL_INCLUDE)
include $(MODULE)

View File

@@ -149,6 +149,9 @@ VOID HalIrqInit(VOID)
(VOID)LOS_HwiCreate(LOS_MP_IPI_WAKEUP, 0xa0, 0, OsMpWakeHandler, 0);
(VOID)LOS_HwiCreate(LOS_MP_IPI_SCHEDULE, 0xa0, 0, OsMpScheduleHandler, 0);
(VOID)LOS_HwiCreate(LOS_MP_IPI_HALT, 0xa0, 0, OsMpHaltHandler, 0);
#ifdef LOSCFG_KERNEL_SMP_CALL
(VOID)LOS_HwiCreate(LOS_MP_IPI_FUNC_CALL, 0xa0, 0, OsMpFuncCallHandler, 0);
#endif
#endif
}
@@ -169,7 +172,7 @@ VOID HalIrqHandler(VOID)
OsInterrupt(vector);
/* use orignal iar to do the EOI */
/* use original iar to do the EOI */
GIC_REG_32(GICC_EOIR) = iar;
}

View File

@@ -401,9 +401,12 @@ VOID HalIrqInit(VOID)
#ifdef LOSCFG_KERNEL_SMP
/* register inter-processor interrupt */
LOS_HwiCreate(LOS_MP_IPI_WAKEUP, 0xa0, 0, OsMpWakeHandler, 0);
LOS_HwiCreate(LOS_MP_IPI_SCHEDULE, 0xa0, 0, OsMpScheduleHandler, 0);
LOS_HwiCreate(LOS_MP_IPI_HALT, 0xa0, 0, OsMpScheduleHandler, 0);
(VOID)LOS_HwiCreate(LOS_MP_IPI_WAKEUP, 0xa0, 0, OsMpWakeHandler, 0);
(VOID)LOS_HwiCreate(LOS_MP_IPI_SCHEDULE, 0xa0, 0, OsMpScheduleHandler, 0);
(VOID)LOS_HwiCreate(LOS_MP_IPI_HALT, 0xa0, 0, OsMpScheduleHandler, 0);
#ifdef LOSCFG_KERNEL_SMP_CALL
(VOID)LOS_HwiCreate(LOS_MP_IPI_FUNC_CALL, 0xa0, 0, OsMpFuncCallHandler, 0);
#endif
#endif
}

View File

@@ -1,65 +1,61 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _SYS_CONFIG_H
#define _SYS_CONFIG_H
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#ifndef LOSCFG_MACRO_CONFIG
#define LOSCFG_MACRO_CONFIG
#ifdef LOSCFG_LIB_LIBC
#define CONFIG_STRERROR
#endif
#ifdef LOSCFG_NET_LWIP_SACK
#define LWIP_BSD_API 1
#endif
#ifdef LOSCFG_DRIVERS_USB
#define SUPPORT_LOS_USB_NEW_DRIVER
#define USB_DEBUG_VAR 5
#endif
#endif
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _SYS_CONFIG_H */
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _PERF_H
#define _PERF_H
#include "los_typedef.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#define OsPerfArchFetchCallerRegs(regs) \
do { \
(regs)->pc = (UINTPTR)__builtin_return_address(0); \
(regs)->fp = (UINTPTR)__builtin_frame_address(0); \
} while (0)
#define OsPerfArchFetchIrqRegs(regs, tcb) \
do { \
(regs)->pc = (tcb)->pc; \
(regs)->fp = (tcb)->fp; \
} while (0)
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _PERF_H */

View File

@@ -41,14 +41,6 @@ LOCAL_SRCS += $(wildcard crypto/rijndael/*.c) \
$(wildcard crypto/sha2/*.c) \
$(wildcard dev/random/*.c) \
$(wildcard libkern/*.c)
endif
LOCAL_INCLUDE := \
-I $(LITEOSTOPDIR)/kernel/base/include \
-I $(LITEOSTOPDIR)/bsd \
-I $(LITEOSTOPDIR)/bsd/kern \
LOCAL_FLAGS := $(LOCAL_INCLUDE) $(LITEOS_GCOV_OPTS)
include $(MODULE)

View File

@@ -37,10 +37,4 @@ ifneq ($(LOSCFG_HRTIMER_ENABLE), y)
LOCAL_SRCS := $(filter-out src/linux_hrtimer.c, $(LOCAL_SRCS))
endif
LOCAL_INCLUDE := \
-I $(LITEOSTOPDIR)/kernel/base/include \
-I $(LITEOSTOPDIR)/bsd/compat/linuxkpi/include
LOCAL_FLAGS := $(LOCAL_INCLUDE) $(LITEOS_GCOV_OPTS)
include $(MODULE)

View File

@@ -137,14 +137,13 @@ kernel_module(module_name) {
]
}
configs += [
"$HDFTOPDIR:hdf_config"
]
configs += [ "$HDFTOPDIR:hdf_config" ]
public_configs = [ ":public" ]
}
config("public") {
defines = [ "USB_DEBUG_VAR=5" ]
include_dirs = [ "." ]
include_dirs += [ "$LITEOSTHIRDPARTY/FreeBSD/sys/dev/evdev" ]
}

View File

@@ -135,6 +135,4 @@ LOCAL_SRCS += $(INPUT_SRC)/uhid.c \
$(CORE_SRC)/usb_hid.c
endif
LOCAL_FLAGS += $(LITEOS_GCOV_OPTS)
include $(HDF_DRIVER)

View File

@@ -33,10 +33,8 @@ MODULE_NAME := $(notdir $(shell pwd))
LOCAL_SRCS := $(wildcard src/*.c)
LOCAL_INCLUDE := \
-I $(LITEOSTOPDIR)/compat/posix/src \
-I $(LITEOSTOPDIR)/kernel/base/include \
LOCAL_INCLUDE := -I $(LITEOSTOPDIR)/compat/posix/src
LOCAL_FLAGS := $(LOCAL_INCLUDE) $(LITEOS_GCOV_OPTS)
LOCAL_FLAGS := $(LOCAL_INCLUDE)
include $(MODULE)

View File

@@ -86,6 +86,7 @@ STATIC INLINE VOID OsTick2TimeSpec(struct timespec *tp, UINT32 tick)
}
int OsTimerCreate(clockid_t, struct ksigevent *__restrict, timer_t *__restrict);
void OsAdjTime(void);
#ifdef __cplusplus
#if __cplusplus

View File

@@ -154,7 +154,9 @@ pid_t getpid(void)
int getrlimit(int resource, struct rlimit *rlim)
{
unsigned int intSave;
LosProcessCB *pcb = OsCurrProcessGet();
struct rlimit *resourceLimit = pcb->resourceLimit;
switch (resource) {
case RLIMIT_NOFILE:
@@ -163,8 +165,18 @@ int getrlimit(int resource, struct rlimit *rlim)
default:
return -EINVAL;
}
rlim->rlim_cur = pcb->pl_rlimit[resource].rlim_cur;
rlim->rlim_max = pcb->pl_rlimit[resource].rlim_max;
if (resourceLimit == NULL) {
rlim->rlim_cur = 0;
rlim->rlim_max = 0;
return 0;
}
SCHEDULER_LOCK(intSave);
rlim->rlim_cur = resourceLimit[resource].rlim_cur;
rlim->rlim_max = resourceLimit[resource].rlim_max;
SCHEDULER_UNLOCK(intSave);
return 0;
}
@@ -175,6 +187,8 @@ int getrlimit(int resource, struct rlimit *rlim)
#endif
int setrlimit(int resource, const struct rlimit *rlim)
{
unsigned int intSave;
struct rlimit *resourceLimit = NULL;
LosProcessCB *pcb = OsCurrProcessGet();
if (rlim->rlim_cur > rlim->rlim_max) {
@@ -194,8 +208,23 @@ int setrlimit(int resource, const struct rlimit *rlim)
default:
return -EINVAL;
}
pcb->pl_rlimit[resource].rlim_cur = rlim->rlim_cur;
pcb->pl_rlimit[resource].rlim_max = rlim->rlim_max;
if (pcb->resourceLimit == NULL) {
resourceLimit = LOS_MemAlloc((VOID *)m_aucSysMem0, RLIM_NLIMITS * sizeof(struct rlimit));
if (resourceLimit == NULL) {
return -EINVAL;
}
}
SCHEDULER_LOCK(intSave);
if (pcb->resourceLimit == NULL) {
pcb->resourceLimit = resourceLimit;
resourceLimit = NULL;
}
pcb->resourceLimit[resource].rlim_cur = rlim->rlim_cur;
pcb->resourceLimit[resource].rlim_max = rlim->rlim_max;
SCHEDULER_UNLOCK(intSave);
(VOID)LOS_MemFree((VOID *)m_aucSysMem0, resourceLimit);
return 0;
}
}

View File

@@ -248,7 +248,7 @@ int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
taskInitParam.uwResved = LOS_TASK_STATUS_DETACHED;
} else {
/* Set the pthread default joinable */
taskInitParam.uwResved = 0;
taskInitParam.uwResved = LOS_TASK_ATTR_JOINABLE;
}
PthreadReap();

View File

@@ -47,7 +47,7 @@ void srand(unsigned s)
int rand(void)
{
return random();
return random();
}
void _exit(int status)

View File

@@ -509,7 +509,11 @@ static int ProcessGetCputime(clockid_t clockID, struct timespec *ats)
}
SCHEDULER_LOCK(intSave);
runtime = spcb->processCpup.allTime;
if (spcb->processCpup == NULL) {
SCHEDULER_UNLOCK(intSave);
return -EINVAL;
}
runtime = spcb->processCpup->allTime;
SCHEDULER_UNLOCK(intSave);
ats->tv_sec = runtime / OS_SYS_NS_PER_SECOND;
@@ -756,7 +760,7 @@ static VOID SwtmrProc(UINTPTR tmrArg)
}
return;
EXIT:
PRINT_ERR("Dsipatch signals failed!, ret: %d\r\n", ret);
PRINT_ERR("Dispatch signals failed!, ret: %d\r\n", ret);
return;
}

View File

@@ -38,7 +38,7 @@ LITEOS_CXXOPTS := $(LITEOS_CXXOPTS_BASE)
LITEOS_INCLUDE := $(LITEOS_KERNEL_INCLUDE) $(LITEOS_EXTKERNEL_INCLUDE) \
$(LITEOS_COMPAT_INCLUDE) $(LITEOS_FS_INCLUDE) \
$(LITEOS_NET_INCLUDE) $(LITEOS_LIB_INCLUDE) \
$(LITEOS_DRIVERS_INCLUDE) $(LOSCFG_TOOLS_DEBUG_INCLUDE) \
$(LITEOS_DRIVERS_INCLUDE) $(LITEOS_TOOLS_DEBUG_INCLUDE) \
$(LITEOS_PLATFORM_INCLUDE) $(LITEOS_DFX_INCLUDE) \
$(LITEOS_SECURITY_INCLUDE)
LITEOS_LIBDEP := $(LITEOS_BASELIB)
@@ -52,10 +52,17 @@ LITEOS_LDFLAGS := $(LITEOS_LD_OPTS) $(LITEOS_LD_PATH) \
$(LITEOS_LD_SCRIPT)
# clear all local variables
LOCAL_FLAGS :=
LOCAL_CFLAGS :=
LOCAL_CPPFLAGS :=
LOCAL_ASFLAGS :=
LOCAL_SRCS :=
LOCAL_CHS :=
LOCAL_CPPHS :=
LOCAL_FLAGS =
LOCAL_CFLAGS =
LOCAL_CPPFLAGS =
LOCAL_ASFLAGS =
LOCAL_SRCS =
LOCAL_CHS =
LOCAL_CPPHS =
# basic build flags
CFLAGS := $(LITEOS_CFLAGS)
CXXFLAGS := $(LITEOS_CXXFLAGS)
ASFLAGS := $(LITEOS_ASFLAGS)
LDFLAGS := $(LITEOS_LDFLAGS)
ARFLAGS := rc

View File

@@ -29,28 +29,10 @@
import("//kernel/liteos_a/liteos.gni")
group("drivers") {
deps = [
"block/disk",
"char/bch",
"char/mem",
"char/quickstart",
"char/random",
"char/trace",
"char/video",
"mtd/multi_partition",
]
}
config("public") {
configs = [
"block/disk:public",
"char/bch:public",
"char/mem:public",
"char/quickstart:public",
"char/random:public",
"char/video:public",
"char/trace:public",
"mtd/multi_partition:public",
module_group("drivers") {
modules = [
"block",
"char",
"mtd",
]
}

21
drivers/Kconfig Normal file
View File

@@ -0,0 +1,21 @@
config DRIVERS
bool "Enable Driver"
default y
help
Answer Y to enable LiteOS support driver.
source "bsd/dev/usb/Kconfig"
source "../../drivers/adapter/khdf/liteos/Kconfig"
# Device driver Kconfig import
source "$(DEVICE_PATH)/drivers/Kconfig"
source "drivers/char/mem/Kconfig"
source "drivers/char/quickstart/Kconfig"
source "drivers/char/random/Kconfig"
source "drivers/char/video/Kconfig"
source "drivers/char/trace/Kconfig"
source "drivers/char/perf/Kconfig"
source "../../drivers/liteos/tzdriver/Kconfig"
source "../../drivers/liteos/hievent/Kconfig"

34
drivers/block/BUILD.gn Normal file
View File

@@ -0,0 +1,34 @@
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this list of
# conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
# of conditions and the following disclaimer in the documentation and/or other materials
# provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors may be used
# to endorse or promote products derived from this software without specific prior written
# permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import("//kernel/liteos_a/liteos.gni")
module_group("block") {
modules = [ "disk" ]
}

View File

@@ -33,8 +33,4 @@ MODULE_NAME := $(notdir $(shell pwd))
LOCAL_SRCS := $(wildcard src/*.c)
LOCAL_INCLUDE := \
LOCAL_FLAGS := $(LOCAL_INCLUDE) $(LITEOS_GCOV_OPTS)
include $(MODULE)

View File

@@ -165,6 +165,10 @@ extern "C" {
#define DISK_ATA_GET_MODEL 21 /* Get model name */
#define DISK_ATA_GET_SN 22 /* Get serial number */
#ifdef LOSCFG_FS_FAT_CACHE
#define DISK_DIRECT_BUFFER_SIZE 4 /* los_disk direct io buffer when bcache is off */
#endif
typedef enum _disk_status_ {
STAT_UNUSED,
STAT_INUSED,
@@ -187,6 +191,9 @@ typedef struct _los_disk_ {
CHAR *disk_name;
LOS_DL_LIST head; /* link head of all the partitions */
struct pthread_mutex disk_mutex;
#ifndef LOSCFG_FS_FAT_CACHE
UINT8 *buff;
#endif
} los_disk;
typedef struct _los_part_ {

View File

@@ -36,6 +36,10 @@
#include "sys/mount.h"
#include "linux/spinlock.h"
#include "path_cache.h"
#ifndef LOSCFG_FS_FAT_CACHE
#include "los_vm_common.h"
#include "user_copy.h"
#endif
los_disk g_sysDisk[SYS_MAX_DISK];
los_part g_sysPart[SYS_MAX_PART];
@@ -799,6 +803,78 @@ INT32 DiskPartitionRegister(los_disk *disk)
return ENOERR;
}
#ifndef LOSCFG_FS_FAT_CACHE
static INT32 disk_read_directly(los_disk *disk, VOID *buf, UINT64 sector, UINT32 count)
{
INT32 result = VFS_ERROR;
struct block_operations *bops = (struct block_operations *)((struct drv_data *)disk->dev->data)->ops;
if ((bops == NULL) || (bops->read == NULL)) {
return VFS_ERROR;
}
if (LOS_IsUserAddressRange((VADDR_T)buf, count * disk->sector_size)) {
UINT32 cnt = 0;
UINT8 *buffer = disk->buff;
for (; count != 0; count -= cnt) {
cnt = (count > DISK_DIRECT_BUFFER_SIZE) ? DISK_DIRECT_BUFFER_SIZE : count;
result = bops->read(disk->dev, buffer, sector, cnt);
if (result == (INT32)cnt) {
result = ENOERR;
} else {
break;
}
if (LOS_CopyFromKernel(buf, disk->sector_size * cnt, buffer, disk->sector_size * cnt)) {
result = VFS_ERROR;
break;
}
buf = (UINT8 *)buf + disk->sector_size * cnt;
sector += cnt;
}
} else {
result = bops->read(disk->dev, buf, sector, count);
if (result == count) {
result = ENOERR;
}
}
return result;
}
static INT32 disk_write_directly(los_disk *disk, const VOID *buf, UINT64 sector, UINT32 count)
{
struct block_operations *bops = (struct block_operations *)((struct drv_data *)disk->dev->data)->ops;
INT32 result = VFS_ERROR;
if ((bops == NULL) || (bops->read == NULL)) {
return VFS_ERROR;
}
if (LOS_IsUserAddressRange((VADDR_T)buf, count * disk->sector_size)) {
UINT32 cnt = 0;
UINT8 *buffer = disk->buff;
for (; count != 0; count -= cnt) {
cnt = (count > DISK_DIRECT_BUFFER_SIZE) ? DISK_DIRECT_BUFFER_SIZE : count;
if (LOS_CopyToKernel(buffer, disk->sector_size * cnt, buf, disk->sector_size * cnt)) {
result = VFS_ERROR;
break;
}
result = bops->write(disk->dev, buffer, sector, cnt);
if (result == (INT32)cnt) {
result = ENOERR;
} else {
break;
}
buf = (UINT8 *)buf + disk->sector_size * cnt;
sector += cnt;
}
} else {
result = bops->write(disk->dev, buf, sector, count);
if (result == count) {
result = ENOERR;
}
}
return result;
}
#endif
INT32 los_disk_read(INT32 drvID, VOID *buf, UINT64 sector, UINT32 count, BOOL useRead)
{
#ifdef LOSCFG_FS_FAT_CACHE
@@ -837,21 +913,14 @@ INT32 los_disk_read(INT32 drvID, VOID *buf, UINT64 sector, UINT32 count, BOOL us
PRINT_ERR("los_disk_read read err = %d, sector = %llu, len = %u\n", result, sector, len);
}
} else {
#endif
result = VFS_ERROR;
}
#else
if (disk->dev == NULL) {
goto ERROR_HANDLE;
}
struct block_operations *bops = (struct block_operations *)((struct drv_data *)disk->dev->data)->ops;
if ((bops != NULL) && (bops->read != NULL)) {
result = bops->read(disk->dev, (UINT8 *)buf, sector, count);
if (result == (INT32)count) {
result = ENOERR;
}
}
#ifdef LOSCFG_FS_FAT_CACHE
}
result = disk_read_directly(disk, buf, sector, count);
#endif
if (result != ENOERR) {
goto ERROR_HANDLE;
}
@@ -900,18 +969,14 @@ INT32 los_disk_write(INT32 drvID, const VOID *buf, UINT64 sector, UINT32 count)
PRINT_ERR("los_disk_write write err = %d, sector = %llu, len = %u\n", result, sector, len);
}
} else {
#endif
struct block_operations *bops = (struct block_operations *)((struct drv_data *)disk->dev->data)->ops;
if ((bops != NULL) && (bops->write != NULL)) {
result = bops->write(disk->dev, (UINT8 *)buf, sector, count);
if (result == (INT32)count) {
result = ENOERR;
}
result = VFS_ERROR;
}
#ifdef LOSCFG_FS_FAT_CACHE
#else
if (disk->dev == NULL) {
goto ERROR_HANDLE;
}
result = disk_write_directly(disk, buf, sector, count);
#endif
if (result != ENOERR) {
goto ERROR_HANDLE;
}
@@ -998,7 +1063,7 @@ INT32 los_part_read(INT32 pt, VOID *buf, UINT64 sector, UINT32 count, BOOL useRe
}
if (count > part->sector_count) {
PRINT_ERR("los_part_read failed, invaild count, count = %u\n", count);
PRINT_ERR("los_part_read failed, invalid count, count = %u\n", count);
goto ERROR_HANDLE;
}
@@ -1007,7 +1072,7 @@ INT32 los_part_read(INT32 pt, VOID *buf, UINT64 sector, UINT32 count, BOOL useRe
if ((disk->sector_count - part->sector_start) > sector) {
sector += part->sector_start;
} else {
PRINT_ERR("los_part_read failed, invaild sector, sector = %llu\n", sector);
PRINT_ERR("los_part_read failed, invalid sector, sector = %llu\n", sector);
goto ERROR_HANDLE;
}
}
@@ -1054,7 +1119,7 @@ INT32 los_part_write(INT32 pt, const VOID *buf, UINT64 sector, UINT32 count)
}
if (count > part->sector_count) {
PRINT_ERR("los_part_write failed, invaild count, count = %u\n", count);
PRINT_ERR("los_part_write failed, invalid count, count = %u\n", count);
goto ERROR_HANDLE;
}
@@ -1063,7 +1128,7 @@ INT32 los_part_write(INT32 pt, const VOID *buf, UINT64 sector, UINT32 count)
if ((disk->sector_count - part->sector_start) > sector) {
sector += part->sector_start;
} else {
PRINT_ERR("los_part_write failed, invaild sector, sector = %llu\n", sector);
PRINT_ERR("los_part_write failed, invalid sector, sector = %llu\n", sector);
goto ERROR_HANDLE;
}
}
@@ -1153,7 +1218,8 @@ ERROR_HANDLE:
INT32 los_disk_cache_clear(INT32 drvID)
{
INT32 result;
INT32 result = ENOERR;
#ifdef LOSCFG_FS_FAT_CACHE
los_part *part = get_part(drvID);
los_disk *disk = NULL;
@@ -1161,7 +1227,7 @@ INT32 los_disk_cache_clear(INT32 drvID)
return VFS_ERROR;
}
result = OsSdSync(part->disk_id);
if (result != 0) {
if (result != ENOERR) {
PRINTK("[ERROR]disk_cache_clear SD sync failed!\n");
return result;
}
@@ -1174,7 +1240,7 @@ INT32 los_disk_cache_clear(INT32 drvID)
DISK_LOCK(&disk->disk_mutex);
result = BcacheClearCache(disk->bcache);
DISK_UNLOCK(&disk->disk_mutex);
#endif
return result;
}
@@ -1324,6 +1390,10 @@ static INT32 DiskDeinit(los_disk *disk)
#ifdef LOSCFG_FS_FAT_CACHE
DiskCacheDeinit(disk);
#else
if (disk->buff != NULL) {
free(disk->buff);
}
#endif
disk->dev = NULL;
@@ -1344,12 +1414,15 @@ static INT32 DiskDeinit(los_disk *disk)
return ENOERR;
}
static VOID OsDiskInitSub(const CHAR *diskName, INT32 diskID, los_disk *disk,
struct geometry *diskInfo, struct Vnode *blkDriver)
static UINT32 OsDiskInitSub(const CHAR *diskName, INT32 diskID, los_disk *disk,
struct geometry *diskInfo, struct Vnode *blkDriver)
{
pthread_mutexattr_t attr;
#ifdef LOSCFG_FS_FAT_CACHE
OsBcache *bc = DiskCacheInit((UINT32)diskID, diskInfo, blkDriver);
if (bc == NULL) {
return VFS_ERROR;
}
disk->bcache = bc;
#endif
@@ -1358,6 +1431,16 @@ static VOID OsDiskInitSub(const CHAR *diskName, INT32 diskID, los_disk *disk,
(VOID)pthread_mutex_init(&disk->disk_mutex, &attr);
DiskStructInit(diskName, diskID, diskInfo, blkDriver, disk);
#ifndef LOSCFG_FS_FAT_CACHE
disk->buff = malloc(diskInfo->geo_sectorsize * DISK_DIRECT_BUFFER_SIZE);
if (disk->buff == NULL) {
PRINT_ERR("OsDiskInitSub: direct buffer of disk init failed\n");
return VFS_ERROR;
}
#endif
return ENOERR;
}
INT32 los_disk_init(const CHAR *diskName, const struct block_operations *bops,
@@ -1382,14 +1465,12 @@ INT32 los_disk_init(const CHAR *diskName, const struct block_operations *bops,
ret = VnodeLookup(diskName, &blkDriver, 0);
if (ret < 0) {
VnodeDrop();
PRINT_ERR("disk_init : find %s fail!\n", diskName);
ret = ENOENT;
goto DISK_FIND_ERROR;
}
struct block_operations *bops2 = (struct block_operations *)((struct drv_data *)blkDriver->data)->ops;
if ((bops2 == NULL) || (bops2->geometry == NULL) ||
(bops2->geometry(blkDriver, &diskInfo) != 0)) {
if ((bops2 == NULL) || (bops2->geometry == NULL) || (bops2->geometry(blkDriver, &diskInfo) != 0)) {
goto DISK_BLKDRIVER_ERROR;
}
@@ -1397,7 +1478,12 @@ INT32 los_disk_init(const CHAR *diskName, const struct block_operations *bops,
goto DISK_BLKDRIVER_ERROR;
}
OsDiskInitSub(diskName, diskID, disk, &diskInfo, blkDriver);
ret = OsDiskInitSub(diskName, diskID, disk, &diskInfo, blkDriver);
if (ret != ENOERR) {
(VOID)DiskDeinit(disk);
VnodeDrop();
return VFS_ERROR;
}
VnodeDrop();
if (DiskDivideAndPartitionRegister(info, disk) != ENOERR) {
(VOID)DiskDeinit(disk);

42
drivers/char/BUILD.gn Normal file
View File

@@ -0,0 +1,42 @@
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this list of
# conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
# of conditions and the following disclaimer in the documentation and/or other materials
# provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors may be used
# to endorse or promote products derived from this software without specific prior written
# permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import("//kernel/liteos_a/liteos.gni")
module_group("char") {
modules = [
"bch",
"mem",
"perf",
"quickstart",
"random",
"trace",
"video",
]
}

View File

@@ -34,9 +34,8 @@ MODULE_NAME := $(notdir $(shell pwd))
LOCAL_SRCS := $(wildcard $(LITEOSTHIRDPARTY)/NuttX/drivers/bch/*.c)
LOCAL_INCLUDE := \
-I $(LITEOSTHIRDPARTY)/NuttX/drivers/bch \
-I $(LITEOSTOPDIR)/fs/include \
-I $(LITEOSTHIRDPARTY)/NuttX/drivers/bch
LOCAL_FLAGS := $(LOCAL_INCLUDE) $(LITEOS_GCOV_OPTS)
LOCAL_FLAGS := $(LOCAL_INCLUDE)
include $(MODULE)

View File

@@ -0,0 +1,42 @@
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this list of
# conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
# of conditions and the following disclaimer in the documentation and/or other materials
# provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors may be used
# to endorse or promote products derived from this software without specific prior written
# permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import("//kernel/liteos_a/liteos.gni")
module_switch = defined(LOSCFG_DRIVERS_PERF)
module_name = "perf_dev"
kernel_module(module_name) {
sources = [ "src/perf.c" ]
public_configs = [ ":public" ]
}
config("public") {
include_dirs = [ "include" ]
}

View File

@@ -0,0 +1,6 @@
config DRIVERS_PERF
bool "Enable PERF DRIVER"
default y
depends on DRIVERS && FS_VFS && KERNEL_PERF
help
Answer Y to enable LiteOS support perf in userspace.

View File

@@ -0,0 +1,36 @@
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this list of
# conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
# of conditions and the following disclaimer in the documentation and/or other materials
# provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors may be used
# to endorse or promote products derived from this software without specific prior written
# permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
include $(LITEOSTOPDIR)/config.mk
MODULE_NAME := perf_dev
LOCAL_SRCS := $(wildcard src/*.c)
include $(MODULE)

View File

@@ -29,10 +29,8 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _LOS_TIMER_PRI_H
#define _LOS_TIMER_PRI_H
#include "los_typedef.h"
#ifndef __LOS_DEV_PERF_H__
#define __LOS_DEV_PERF_H__
#ifdef __cplusplus
#if __cplusplus
@@ -40,11 +38,12 @@ extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
extern VOID OsAdjTime(VOID);
int DevPerfRegister(void);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_TIMER_PRI_H */
#endif

View File

@@ -0,0 +1,153 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "fcntl.h"
#include "user_copy.h"
#include "sys/ioctl.h"
#include "fs/driver.h"
#include "los_dev_perf.h"
#include "los_perf.h"
#include "los_init.h"
#define PERF_DRIVER "/dev/perf"
#define PERF_DRIVER_MODE 0666
/* perf ioctl */
#define PERF_IOC_MAGIC 'T'
#define PERF_START _IO(PERF_IOC_MAGIC, 1)
#define PERF_STOP _IO(PERF_IOC_MAGIC, 2)
static int PerfOpen(struct file *filep)
{
(void)filep;
return 0;
}
static int PerfClose(struct file *filep)
{
(void)filep;
return 0;
}
static ssize_t PerfRead(struct file *filep, char *buffer, size_t buflen)
{
/* perf record buffer read */
(void)filep;
int ret;
int realLen;
char *records = LOS_MemAlloc(m_aucSysMem0, buflen);
if (records == NULL) {
return -ENOMEM;
}
realLen = LOS_PerfDataRead(records, buflen); /* get sample data */
if (realLen == 0) {
PRINT_ERR("Perf read failed, check whether perf is configured to sample mode.\n");
ret = -EINVAL;
goto EXIT;
}
ret = LOS_CopyFromKernel((void *)buffer, buflen, (void *)records, realLen);
if (ret != 0) {
ret = -EINVAL;
goto EXIT;
}
ret = realLen;
EXIT:
LOS_MemFree(m_aucSysMem0, records);
return ret;
}
static ssize_t PerfConfig(struct file *filep, const char *buffer, size_t buflen)
{
(void)filep;
int ret;
PerfConfigAttr attr = {0};
int attrlen = sizeof(PerfConfigAttr);
if (buflen != attrlen) {
PRINT_ERR("PerfConfigAttr is %d bytes not %d\n", attrlen, buflen);
return -EINVAL;
}
ret = LOS_CopyToKernel(&attr, attrlen, buffer, buflen);
if (ret != 0) {
return -EINVAL;
}
ret = LOS_PerfConfig(&attr);
if (ret != LOS_OK) {
PRINT_ERR("perf config error %u\n", ret);
return -EINVAL;
}
return 0;
}
static int PerfIoctl(struct file *filep, int cmd, unsigned long arg)
{
(void)filep;
switch (cmd) {
case PERF_START:
LOS_PerfStart((UINT32)arg);
break;
case PERF_STOP:
LOS_PerfStop();
break;
default:
PRINT_ERR("Unknown perf ioctl cmd:%d\n", cmd);
return -EINVAL;
}
return 0;
}
static const struct file_operations_vfs g_perfDevOps = {
PerfOpen, /* open */
PerfClose, /* close */
PerfRead, /* read */
PerfConfig, /* write */
NULL, /* seek */
PerfIoctl, /* ioctl */
NULL, /* mmap */
#ifndef CONFIG_DISABLE_POLL
NULL, /* poll */
#endif
NULL, /* unlink */
};
int DevPerfRegister(void)
{
return register_driver(PERF_DRIVER, &g_perfDevOps, PERF_DRIVER_MODE, 0); /* 0666: file mode */
}
LOS_MODULE_INIT(DevPerfRegister, LOS_INIT_LEVEL_KMOD_EXTENDED);

View File

@@ -5,7 +5,7 @@ config DRIVERS_RANDOM
help
Answer Y to support random.
config HW_RANDOM_ENABLE
depends on DRIVERS_RANDOM && (PLATFORM_HI3518EV300 || PLATFORM_HI3516CV300 || PLATFORM_HI3516DV300 || PLATFORM_HI3556V200)
depends on DRIVERS_RANDOM && (PLATFORM_HI3518EV300 || PLATFORM_HI3516CV300 || PLATFORM_HI3516DV300 || PLATFORM_HI3556V200 || PLATFORM_QEMU_ARM_VIRT_CA7)
bool "Select hw random"
default y
help

View File

@@ -37,9 +37,4 @@ ifdef LOSCFG_HW_RANDOM_ENABLE
LOCAL_SRCS += $(wildcard src/random_hw.c)
endif
LOCAL_INCLUDE := -I $(LITEOSTOPDIR)/drivers/char/random/include \
-I $(LITEOSTOPDIR)/../../$(LOSCFG_BOARD_CONFIG_PATH)/include
LOCAL_FLAGS := $(LOCAL_INCLUDE)
include $(MODULE)

View File

@@ -35,6 +35,6 @@ LOCAL_SRCS := $(wildcard src/*.c)
LOCAL_INCLUDE := -I $(LITEOSTOPDIR)/drivers/char/trace/include
LOCAL_FLAGS := $(LOCAL_INCLUDE) $(LITEOS_GCOV_OPTS)
LOCAL_FLAGS := $(LOCAL_INCLUDE)
include $(MODULE)

34
drivers/mtd/BUILD.gn Normal file
View File

@@ -0,0 +1,34 @@
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this list of
# conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
# of conditions and the following disclaimer in the documentation and/or other materials
# provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors may be used
# to endorse or promote products derived from this software without specific prior written
# permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import("//kernel/liteos_a/liteos.gni")
module_group("mtd") {
modules = [ "multi_partition" ]
}

View File

@@ -37,10 +37,7 @@ kernel_module(module_name) {
"src/mtd_shellcmd.c",
]
include_dirs = [
"$LITEOSTOPDIR/fs/jffs2/include",
"//device/hisilicon/drivers/include/mtd/common/include",
]
include_dirs = [ "$LITEOSTOPDIR/fs/jffs2/include" ]
if (defined(LOSCFG_PLATFORM_QEMU_ARM_VIRT_CA7)) {
include_dirs += [ "//device/qemu/drivers/cfiflash" ]

View File

@@ -34,14 +34,12 @@ MODULE_NAME := $(notdir $(shell pwd))
LOCAL_SRCS := $(wildcard src/*.c)
LOCAL_INCLUDE := \
-I $(LITEOSTOPDIR)/fs/jffs2/include \
-I $(LITEOSTOPDIR)/drivers/mtd/multi_partition/include \
-I $(LITEOSTOPDIR)/../../device/hisilicon/drivers/include/mtd/common/include
-I $(LITEOSTOPDIR)/fs/jffs2/include
ifeq ($(LOSCFG_PLATFORM_QEMU_ARM_VIRT_CA7), y)
LOCAL_INCLUDE += -I $(LITEOSTOPDIR)/../../device/qemu/drivers/cfiflash
endif
LOCAL_FLAGS := $(LOCAL_INCLUDE) $(LITEOS_GCOV_OPTS)
LOCAL_FLAGS := $(LOCAL_INCLUDE)
include $(MODULE)

View File

@@ -37,7 +37,7 @@
#include "los_config.h"
#include "los_mux.h"
#include "fs/driver.h"
#include "mtd_common.h"
#include "mtd/mtd_legacy_lite.h"
#ifdef LOSCFG_PLATFORM_QEMU_ARM_VIRT_CA7
#include "cfiflash.h"

View File

@@ -35,9 +35,11 @@ group("fs") {
"fat/virpart",
"jffs2",
"nfs",
"patchfs",
"proc",
"ramfs",
"romfs",
"rootfs",
"vfs",
"vfs/bcache",
"zpfs",
@@ -52,5 +54,7 @@ config("public") {
"fat:public",
"fat/virpart:public",
"proc:public",
"patchfs:public",
"rootfs:public",
]
}

10
fs/Kconfig Normal file
View File

@@ -0,0 +1,10 @@
source "fs/vfs/Kconfig"
source "fs/fat/Kconfig"
source "fs/ramfs/Kconfig"
source "fs/romfs/Kconfig"
source "fs/nfs/Kconfig"
source "fs/proc/Kconfig"
source "fs/jffs2/Kconfig"
source "fs/rootfs/Kconfig"
source "fs/patchfs/Kconfig"
source "fs/zpfs/Kconfig"

View File

@@ -27,7 +27,7 @@ config FS_FAT_CHINESE
Answer Y to enable LiteOS fat filesystem support Chinese.
config FS_FAT_VIRTUAL_PARTITION
bool "Enabel Virtual Partition"
bool "Enable Virtual Partition"
default n
depends on FS_FAT

View File

@@ -34,13 +34,9 @@ MODULE_NAME := $(notdir $(shell pwd))
LOCAL_SRCS := $(wildcard os_adapt/*.c)
LOCAL_SRCS += $(wildcard $(LITEOSTHIRDPARTY)/FatFs/source/*.c)
LOCAL_INCLUDE := \
-I $(LITEOSTHIRDPARTY)/FatFs/source \
-I $(LITEOSTOPDIR)/fs/fat/os_adapt \
-I $(LITEOSTOPDIR)/fs/fat/virpart/include \
-I $(LITEOSTOPDIR)/fs/vfs \
LOCAL_INCLUDE := -I $(LITEOSTOPDIR)/fs/fat/os_adapt
LOCAL_FLAGS := $(LOCAL_INCLUDE) $(LITEOS_GCOV_OPTS)
LOCAL_FLAGS := $(LOCAL_INCLUDE)
include $(MODULE)

View File

@@ -34,6 +34,7 @@
#include "ff.h"
#include "disk_pri.h"
#include "diskio.h"
#include "fs/file.h"
#include "fs/fs.h"
#include "fs/dirent_fs.h"
#include "fs/mount.h"
@@ -47,6 +48,7 @@
#include "user_copy.h"
#include "los_vm_filemap.h"
#include "los_hash.h"
#include "los_vm_common.h"
#include <time.h>
#include <errno.h>
#include <dirent.h>
@@ -604,7 +606,7 @@ int fatfs_open(struct file *filep)
FIL *fp;
int ret;
fp = (FIL *)zalloc(sizeof(FIL));
fp = (FIL *)zalloc(sizeof(FIL) + SS(fs));
if (fp == NULL) {
ret = ENOMEM;
goto ERROR_EXIT;
@@ -628,19 +630,13 @@ int fatfs_open(struct file *filep)
fp->err = 0;
fp->sect = 0;
fp->fptr = 0;
fp->buf = (BYTE*) ff_memalloc(SS(fs));
if (fp->buf == NULL) {
ret = ENOMEM;
goto ERROR_UNLOCK;
}
fp->buf = (BYTE *)fp + sizeof(FIL);
LOS_ListAdd(&finfo->fp_list, &fp->fp_entry);
unlock_fs(fs, FR_OK);
filep->f_priv = fp;
return fatfs_sync(vp->originMount->mountFlags, fs);
return 0;
ERROR_UNLOCK:
unlock_fs(fs, FR_OK);
ERROR_FREE:
free(fp);
ERROR_EXIT:
@@ -670,7 +666,6 @@ int fatfs_close(struct file *filep)
}
#endif
LOS_ListDelete(&fp->fp_entry);
ff_memfree(fp->buf);
free(fp);
filep->f_priv = NULL;
EXIT:
@@ -1297,6 +1292,29 @@ int fatfs_umount(struct Mount *mnt, struct Vnode **blkdriver)
return 0;
}
int fatfs_sync_adapt(struct Mount *mnt)
{
(void)mnt;
int ret = 0;
#ifdef LOSCFG_FS_FAT_CACHE
struct Vnode *dev = NULL;
los_part *part = NULL;
if (mnt == NULL) {
return -EINVAL;
}
dev = mnt->vnodeDev;
part = los_part_find(dev);
if (part == NULL) {
return -EINVAL;
}
ret = OsSdSync(part->disk_id);
#endif
return ret;
}
int fatfs_statfs(struct Mount *mnt, struct statfs *info)
{
FATFS *fs = (FATFS *)mnt->data;
@@ -1848,6 +1866,7 @@ int fatfs_mkfs (struct Vnode *device, int sectors, int option)
BYTE *work_buff = NULL;
los_part *part = NULL;
FRESULT result;
MKFS_PARM opt = {0};
int ret;
part = los_part_find(device);
@@ -1872,7 +1891,9 @@ int fatfs_mkfs (struct Vnode *device, int sectors, int option)
return -ENOMEM;
}
result = _mkfs(part, sectors, option, work_buff, FF_MAX_SS);
opt.n_sect = sectors;
opt.fmt = (BYTE)option;
result = _mkfs(part, &opt, work_buff, FF_MAX_SS);
free(work_buff);
if (result != FR_OK) {
return -fatfs_2_vfs(result);
@@ -2032,45 +2053,18 @@ static UINT get_oldest_time(DIR_FILE df[], DWORD *oldest_time, UINT len)
return index;
}
int fatfs_fscheck(struct Vnode* vp, struct fs_dirent_s *dir)
static FRESULT fscheck(DIR *dp)
{
FATFS *fs = (FATFS *)vp->originMount->data;
DIR_FILE df[CHECK_FILE_NUM] = {0};
DIR *dp = NULL;
FILINFO *finfo = &(((DIR_FILE *)(vp->data))->fno);
FILINFO fno;
DWORD old_time = -1;
DWORD time;
UINT count;
UINT index = 0;
los_part *part = NULL;
UINT count;
DWORD time;
DWORD old_time = -1;
FRESULT result;
int ret;
if (fs->fs_type != FS_FAT32) {
return -EINVAL;
}
if ((finfo->fattrib & AM_DIR) == 0) {
return -ENOTDIR;
}
ret = fatfs_opendir(vp, dir);
if (ret < 0) {
return ret;
}
ret = lock_fs(fs);
if (ret == FALSE) {
result = FR_TIMEOUT;
goto ERROR_WITH_DIR;
}
dp = (DIR *)dir->u.fs_dir;
dp->obj.id = fs->id;
for (count = 0; count < CHECK_FILE_NUM; count++) {
if ((result = f_readdir(dp, &fno)) != FR_OK) {
goto ERROR_UNLOCK;
return result;
} else {
if (fno.fname[0] == 0 || fno.fname[0] == (TCHAR)0xFF) {
break;
@@ -2095,15 +2089,50 @@ int fatfs_fscheck(struct Vnode* vp, struct fs_dirent_s *dir)
index = get_oldest_time(df, &old_time, CHECK_FILE_NUM);
}
}
if (result != FR_OK) {
goto ERROR_UNLOCK;
index = 0;
while (result == FR_OK && index < count) {
result = f_fcheckfat(&df[index]);
++index;
}
for (index = 0; index < count; index++) {
result = f_fcheckfat(&df[index]);
if (result != FR_OK) {
goto ERROR_UNLOCK;
}
return result;
}
int fatfs_fscheck(struct Vnode* vp, struct fs_dirent_s *dir)
{
FATFS *fs = (FATFS *)vp->originMount->data;
DIR *dp = NULL;
FILINFO *finfo = &(((DIR_FILE *)(vp->data))->fno);
#ifdef LOSCFG_FS_FAT_CACHE
los_part *part = NULL;
#endif
FRESULT result;
int ret;
if (fs->fs_type != FS_FAT32) {
return -EINVAL;
}
if ((finfo->fattrib & AM_DIR) == 0) {
return -ENOTDIR;
}
ret = fatfs_opendir(vp, dir);
if (ret < 0) {
return ret;
}
ret = lock_fs(fs);
if (ret == FALSE) {
result = FR_TIMEOUT;
goto ERROR_WITH_DIR;
}
dp = (DIR *)dir->u.fs_dir;
dp->obj.id = fs->id;
result = fscheck(dp);
if (result != FR_OK) {
goto ERROR_UNLOCK;
}
unlock_fs(fs, FR_OK);
@@ -2180,6 +2209,207 @@ ERROUT:
return -fatfs_2_vfs(res);
}
ssize_t fatfs_readpage(struct Vnode *vnode, char *buff, off_t pos)
{
FATFS *fs = (FATFS *)(vnode->originMount->data);
DIR_FILE *dfp = (DIR_FILE *)(vnode->data);
FILINFO *finfo = &(dfp->fno);
FAT_ENTRY *ep = &(dfp->fat_entry);
DWORD clust;
DWORD sclust;
QWORD sect;
QWORD step;
QWORD n;
size_t position; /* byte offset */
BYTE *buf = (BYTE *)buff;
size_t buflen = PAGE_SIZE;
FRESULT result;
int ret;
ret = lock_fs(fs);
if (ret == FALSE) {
result = FR_TIMEOUT;
goto ERROR_OUT;
}
if (finfo->fsize <= pos) {
result = FR_OK;
goto ERROR_UNLOCK;
}
if (ep->clst == 0) {
ep->clst = finfo->sclst;
}
if (pos >= ep->pos) {
clust = ep->clst;
position = ep->pos;
} else {
clust = finfo->sclst;
position = 0;
}
/* Get to the current cluster */
n = pos / SS(fs) / fs->csize - position / SS(fs) / fs->csize;
while (n--) {
clust = get_fat(&(dfp->f_dir.obj), clust);
if ((clust == BAD_CLUSTER) || (clust == DISK_ERROR)) {
result = FR_DISK_ERR;
goto ERROR_UNLOCK;
}
}
/* Get to the currnet sector */
sect = clst2sect(fs, clust);
sect += (pos / SS(fs)) & (fs->csize - 1);
/* How many sectors do we need to read once */
if (fs->csize < buflen / SS(fs)) {
step = fs->csize;
} else {
step = buflen / SS(fs);
}
n = 0;
sclust = clust;
while (n < buflen / SS(fs)) {
if (disk_read(fs->pdrv, buf, sect, step) != RES_OK) {
result = FR_DISK_ERR;
goto ERROR_UNLOCK;
}
n += step;
if (n >= buflen / SS(fs)) {
break;
}
/* As cluster size is aligned, it must jump to next cluster when cluster size is less than pagesize */
clust = get_fat(&(dfp->f_dir.obj), clust);
if ((clust == BAD_CLUSTER) || (clust == DISK_ERROR)) {
result = FR_DISK_ERR;
goto ERROR_UNLOCK;
} else if (fatfs_is_last_cluster(fs, clust)) {
break; /* read end */
}
sect = clst2sect(fs, clust);
buf += step * SS(fs);
}
ep->clst = sclust;
ep->pos = pos;
unlock_fs(fs, FR_OK);
return (ssize_t)min(finfo->fsize - pos, n * SS(fs));
ERROR_UNLOCK:
unlock_fs(fs, result);
ERROR_OUT:
return -fatfs_2_vfs(result);
}
ssize_t fatfs_writepage(struct Vnode *vnode, char *buff, off_t pos, size_t buflen)
{
FATFS *fs = (FATFS *)(vnode->originMount->data);
DIR_FILE *dfp = (DIR_FILE *)(vnode->data);
FILINFO *finfo = &(dfp->fno);
FAT_ENTRY *ep = &(dfp->fat_entry);
DWORD clust;
DWORD sclst;
QWORD sect;
QWORD step;
QWORD n;
size_t position; /* byte offset */
BYTE *buf = (BYTE *)buff;
FRESULT result;
FIL fil;
int ret;
ret = lock_fs(fs);
if (ret == FALSE) {
result = FR_TIMEOUT;
goto ERROR_OUT;
}
if (finfo->fsize <= pos) {
result = FR_OK;
goto ERROR_UNLOCK;
}
if (ep->clst == 0) {
ep->clst = finfo->sclst;
}
if (pos >= ep->pos) {
clust = ep->clst;
position = ep->pos;
} else {
clust = finfo->sclst;
position = 0;
}
/* Get to the current cluster */
n = pos / SS(fs) / fs->csize - position / SS(fs) / fs->csize;
while (n--) {
clust = get_fat(&(dfp->f_dir.obj), clust);
if ((clust == BAD_CLUSTER) || (clust == DISK_ERROR)) {
result = FR_DISK_ERR;
goto ERROR_UNLOCK;
}
}
/* Get to the currnet sector */
sect = clst2sect(fs, clust);
sect += (pos / SS(fs)) & (fs->csize - 1);
/* How many sectors do we need to read once */
if (fs->csize < buflen / SS(fs)) {
step = fs->csize;
} else {
step = buflen / SS(fs);
}
n = 0;
sclst = clust;
while (n < buflen / SS(fs)) {
if (disk_write(fs->pdrv, buf, sect, step) != RES_OK) {
result = FR_DISK_ERR;
goto ERROR_UNLOCK;
}
n += step;
if (n >= buflen / SS(fs)) {
break;
}
/* As cluster size is aligned, it must jump to next cluster when cluster size is less than pagesize */
clust = get_fat(&(dfp->f_dir.obj), clust);
if ((clust == BAD_CLUSTER) || (clust == DISK_ERROR)) {
result = FR_DISK_ERR;
goto ERROR_UNLOCK;
} else if (fatfs_is_last_cluster(fs, clust)) {
break; /* read end */
}
sect = clst2sect(fs, clust);
buf += step * SS(fs);
}
ep->clst = sclst;
ep->pos = pos;
fil.obj.fs = fs;
if (update_filbuff(finfo, &fil, NULL) < 0) {
result = FR_DISK_ERR;
goto ERROR_UNLOCK;
}
unlock_fs(fs, FR_OK);
return (ssize_t)min(finfo->fsize - pos, n * SS(fs));
ERROR_UNLOCK:
unlock_fs(fs, result);
ERROR_OUT:
return -fatfs_2_vfs(result);
}
struct VnodeOps fatfs_vops = {
/* file ops */
.Getattr = fatfs_stat,
@@ -2187,6 +2417,8 @@ struct VnodeOps fatfs_vops = {
.Lookup = fatfs_lookup,
.Rename = fatfs_rename,
.Create = fatfs_create,
.ReadPage = fatfs_readpage,
.WritePage = fatfs_writepage,
.Unlink = fatfs_unlink,
.Reclaim = fatfs_reclaim,
.Truncate = fatfs_truncate,
@@ -2207,6 +2439,7 @@ struct MountOps fatfs_mops = {
.Mount = fatfs_mount,
.Unmount = fatfs_umount,
.Statfs = fatfs_statfs,
.Sync = fatfs_sync_adapt,
};
struct file_operations_vfs fatfs_fops = {

View File

@@ -146,7 +146,7 @@ int fatfs_fscheck(struct Vnode* vnode, struct fs_dirent_s *dir);
FRESULT find_fat_partition(FATFS *fs, los_part *part, BYTE *format, QWORD *start_sector);
FRESULT init_fatobj(FATFS *fs, BYTE fmt, QWORD start_sector);
FRESULT _mkfs(los_part *partition, int sector, int opt, BYTE *work, UINT len);
FRESULT _mkfs(los_part *partition, const MKFS_PARM *opt, BYTE *work, UINT len);
#ifdef __cplusplus
#if __cplusplus

View File

@@ -33,10 +33,8 @@ MODULE_NAME := $(notdir $(shell pwd))
LOCAL_SRCS := $(wildcard src/*.c)
LOCAL_INCLUDE := \
-I $(LITEOSTOPDIR)/fs/fat/virpart/include \
-I $(LITEOSTOPDIR)/fs/fat/os_adapt
LOCAL_INCLUDE := -I $(LITEOSTOPDIR)/fs/fat/os_adapt
LOCAL_FLAGS := $(LOCAL_INCLUDE) $(LITEOS_GCOV_OPTS)
LOCAL_FLAGS := $(LOCAL_INCLUDE)
include $(MODULE)

View File

@@ -267,7 +267,7 @@ static FRESULT FatfsScanClear(INT vol)
* Acceptable Return Value:
* - FR_OK : The root directory is completely clean.
* - FR_OCCUPIED : The virtual partition entry has been occupied by the same name file.
* - FR_CHAIN_ERR : The virtual partition entry has been rebuilt along the invaild cluster
* - FR_CHAIN_ERR : The virtual partition entry has been rebuilt along the invalid cluster
* chain.
* Others Return Value:
* Followed the by the lower API
@@ -347,7 +347,7 @@ INT FatFsBindVirPart(void *handle, BYTE vol)
return -EINVAL;
}
ret = snprintf_s(path, sizeof(path), sizeof(path) - 1, "%d:/", vol);
ret = snprintf_s(path, sizeof(path), sizeof(path) - 1, "%u:/", vol);
if (ret < 0) {
return -EINVAL;
}
@@ -420,7 +420,7 @@ INT FatFsMakeVirPart(void *handle, BYTE vol)
return -EINVAL;
}
ret = snprintf_s(path, sizeof(path), sizeof(path) - 1, "%d:/", vol);
ret = snprintf_s(path, sizeof(path), sizeof(path) - 1, "%u:/", vol);
if (ret < 0) {
return -EINVAL;
}

View File

@@ -53,7 +53,7 @@ extern FATFS *FatFs[FF_VOLUMES];
* follow_virentry:
* Compare the top segment with the virtual partition entry and replace it to its CHILD FATFS
*
* Acceptable return vaule:
* Acceptable return value:
* - FR_OK : The top segment matches one of the virtual partition entries, and the FATFS
* has been replaced to the corresponding FATFS.
* - FR_DENIED : The top segment does not matched any of the virtual partition entries, and
@@ -291,7 +291,7 @@ static void FatfsSetParentFs(FATFS *pfs, FATFS *fs)
* - FR_DENIED : The virtual partition feature has been shut down by switcher
* - FR_DISK_ERR : A disk error happened
* - FR_NOT_ENOUGH_CORE : Not enough memory for allocate space for CHILD FATFS
* - FR_INVALID_PARAMETER : There is a invaild value in current setting
* - FR_INVALID_PARAMETER : There is a invalid value in current setting
*/
FRESULT f_regvirfs(FATFS *fs)
{
@@ -507,7 +507,7 @@ static void FatfsSetChildClst(BYTE *work, FATFS *fs, WORD i)
* - FR_INVAILD_FATFS : The FATFS object has error or the info in it has been occuried
* - FR_DENIED : The virtual partition feature has been shut down by switcher
* - FR_INVALID_DRIVE : The drive index is error
* - FR_DISK_ERR : A Disk error happend
* - FR_DISK_ERR : A Disk error happened
*/
FRESULT f_checkvirpart(FATFS *fs, const TCHAR *path, BYTE vol)
{
@@ -525,7 +525,7 @@ FRESULT f_checkvirpart(FATFS *fs, const TCHAR *path, BYTE vol)
}
/* Lock the filesystem object */
res = find_volume(&path, &fs, FA_WRITE); /* Update the filesystem info to the parent fs */
res = mount_volume(&path, &fs, FA_WRITE); /* Update the filesystem info to the parent fs */
if (res != FR_OK) {
LEAVE_FF(fs, res);
}
@@ -663,7 +663,7 @@ static void FatfsClacPartInfo(FATFS *fs, DOUBLE virpartper, UINT i)
* - FR_INVAILD_FATFS : The FATFS object has error or the info in it has been occuried
* - FR_DENIED : The virtual partition feature has been shut down by switcher
* - FR_INVALID_DRIVE : The drive index is error
* - FR_DISK_ERR : A Disk error happend
* - FR_DISK_ERR : A Disk error happened
*/
FRESULT f_makevirpart(FATFS *fs, const TCHAR *path, BYTE vol)
{
@@ -683,7 +683,7 @@ FRESULT f_makevirpart(FATFS *fs, const TCHAR *path, BYTE vol)
}
/* Lock the filesystem object */
res = find_volume(&path, &fs, FA_WRITE); /* Update the filesystem info to the parent fs */
res = mount_volume(&path, &fs, FA_WRITE); /* Update the filesystem info to the parent fs */
if (res != FR_OK) {
LEAVE_FF(fs, res);
}
@@ -774,7 +774,7 @@ FRESULT f_getvirfree(const TCHAR *path, DWORD *nclst, DWORD *cclst)
DIR dj;
/* Find volume to Update the global FSINFO */
res = find_volume(&path, &fs, 0);
res = mount_volume(&path, &fs, 0);
if (res != FR_OK) {
LEAVE_FF(fs, res);
}
@@ -797,7 +797,7 @@ FRESULT f_getvirfree(const TCHAR *path, DWORD *nclst, DWORD *cclst)
/* If current FATFS is a CHILD FATFS */
if (ISCHILD(fs)) {
/* If CHILD FATFS' free_clst is invaild, the scan the FAT and update it */
/* If CHILD FATFS' free_clst is invalid, the scan the FAT and update it */
if (fs->free_clst > fs->ct_clst) {
dj.obj.fs = fs;
fs->free_clst = fs->ct_clst;

View File

@@ -41,81 +41,6 @@ extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
/* vfs/fs_file_mapping.c ****************************************************/
/****************************************************************************
* Name: init_file_mapping
*
* Description:
* Init the global management structure of path <-> page_mapping
*
****************************************************************************/
extern UINT32 init_file_mapping(void);
/****************************************************************************
* Name: add_mapping
*
* Description:
* Create a new path <-> page_mapping mapping and add to global list.
*
****************************************************************************/
extern void add_mapping(struct file *filep, const char *fullpath);
/****************************************************************************
* Name: find_mapping
*
* Description:
* Find the page_mapping for path in global list.
*
****************************************************************************/
extern struct page_mapping *find_mapping(const char *path);
/****************************************************************************
* Name: remove_mapping
*
* Description:
* Drop all the page-caches for the file, and then remove mapping between
* the file and pagecache.
* ex_filp NULL: do not exclude any file, just matching the fullpath;
* ex_filp not NULL: exclude it, which means, ex_filp can be open.
*
****************************************************************************/
extern int remove_mapping(const char *fullpath);
/****************************************************************************
* Name: rename_mapping
*
* Description:
* Rename the mapping from global path <-> page_mapping list.
*
****************************************************************************/
extern void rename_mapping(const char *src, const char *dst);
/****************************************************************************
* Name: dec_mapping
*
* Description:
* Decrease the refcnt of mapping.
*
****************************************************************************/
extern void dec_mapping_nolock(struct page_mapping *mapping);
/****************************************************************************
* Name: update_file_path
*
* Description:
* Update the path in file descriptors when do renaming.
*
****************************************************************************/
extern int update_file_path(const char *old_path, const char *new_path);
/**
* @ingroup fs
* @brief Initializes the vfs filesystem

View File

@@ -61,6 +61,7 @@ struct MountOps {
int (*Mount)(struct Mount *mount, struct Vnode *vnode, const void *data);
int (*Unmount)(struct Mount *mount, struct Vnode **blkdriver);
int (*Statfs)(struct Mount *mount, struct statfs *sbp);
int (*Sync)(struct Mount *mount);
};
typedef int (*foreach_mountpoint_t)(const char *devpoint,

View File

@@ -44,14 +44,14 @@ extern "C" {
#define PATH_MAX 256
#define CONFIG_DISABLE_MQUEUE // disable posix mqueue inode configure
/* file system configur */
/* file system config */
#define CONFIG_FS_WRITABLE // enable file system can be written
#define CONFIG_FS_READABLE // enable file system can be read
#define CONFIG_DEBUG_FS // enable vfs debug function
/* fatfs cache configur */
/* fatfs cache config */
/* config block size for fat file system, only can be 0,32,64,128,256,512,1024 */
#define CONFIG_FS_FAT_SECTOR_PER_BLOCK 64
@@ -96,6 +96,7 @@ extern "C" {
#define CONFIG_NEXPANED_DESCRIPTORS (CONFIG_NTIME_DESCRIPTORS + CONFIG_NQUEUE_DESCRIPTORS)
#define TIMER_FD_OFFSET FD_SETSIZE
#define MQUEUE_FD_OFFSET (FD_SETSIZE + CONFIG_NTIME_DESCRIPTORS)
#define EPOLL_FD_OFFSET (FD_SETSIZE + CONFIG_NTIME_DESCRIPTORS + CONFIG_NQUEUE_DESCRIPTORS)
/* net configure */
@@ -129,6 +130,8 @@ extern "C" {
#define VFS_USING_WORKDIR // enable current working directory
#define CONFIG_EPOLL_DESCRIPTORS 32
/* permission configure */
#define DEFAULT_DIR_MODE 0777
#define DEFAULT_FILE_MODE 0666

View File

@@ -35,10 +35,9 @@ LOCAL_SRCS := $(wildcard src/*.c) \
$(wildcard $(LITEOSTHIRDPARTY)/Linux_Kernel/fs/jffs2/*.c)
LOCAL_INCLUDE := \
-I $(LITEOSTOPDIR)/fs/jffs2/include \
-I $(LITEOSTOPDIR)/drivers/mtd/multi_partition/include \
-I $(LITEOSTHIRDPARTY)/Linux_Kernel/fs/jffs2 \
-I $(LITEOSTHIRDPARTY)/Linux_Kernel/fs
LOCAL_FLAGS := $(LOCAL_INCLUDE) $(LITEOS_GCOV_OPTS)
LOCAL_FLAGS := $(LOCAL_INCLUDE)
include $(MODULE)

View File

@@ -201,13 +201,13 @@ int VfsJffs2Lookup(struct Vnode *parentVnode, const char *path, int len, struct
}
(void)VfsHashGet(parentVnode->originMount, node->i_ino, &newVnode, NULL, NULL);
LOS_MuxUnlock(&g_jffs2FsLock);
if (newVnode) {
if (newVnode->data == NULL) {
LOS_Panic("#####VfsHashGet error#####\n");
}
newVnode->parent = parentVnode;
*ppVnode = newVnode;
LOS_MuxUnlock(&g_jffs2FsLock);
return 0;
}
ret = VnodeAlloc(&g_jffs2Vops, &newVnode);
@@ -276,7 +276,7 @@ int VfsJffs2Close(struct file *filep)
return 0;
}
ssize_t VfsJffs2Read(struct file *filep, char *buffer, size_t bufLen)
ssize_t VfsJffs2ReadPage(struct Vnode *vnode, char *buffer, off_t off)
{
struct jffs2_inode *node = NULL;
struct jffs2_inode_info *f = NULL;
@@ -285,6 +285,32 @@ ssize_t VfsJffs2Read(struct file *filep, char *buffer, size_t bufLen)
LOS_MuxLock(&g_jffs2FsLock, (uint32_t)JFFS2_WAITING_FOREVER);
node = (struct jffs2_inode *)vnode->data;
f = JFFS2_INODE_INFO(node);
c = JFFS2_SB_INFO(node->i_sb);
off_t pos = min(node->i_size, off);
ssize_t len = min(PAGE_SIZE, (node->i_size - pos));
ret = jffs2_read_inode_range(c, f, (unsigned char *)buffer, off, len);
if (ret) {
LOS_MuxUnlock(&g_jffs2FsLock);
return ret;
}
node->i_atime = Jffs2CurSec();
LOS_MuxUnlock(&g_jffs2FsLock);
return len;
}
ssize_t VfsJffs2Read(struct file *filep, char *buffer, size_t bufLen)
{
struct jffs2_inode *node = NULL;
struct jffs2_inode_info *f = NULL;
struct jffs2_sb_info *c = NULL;
int ret;
LOS_MuxLock(&g_jffs2FsLock, (uint32_t)JFFS2_WAITING_FOREVER);
node = (struct jffs2_inode *)filep->f_vnode->data;
f = JFFS2_INODE_INFO(node);
c = JFFS2_SB_INFO(node->i_sb);
@@ -293,7 +319,6 @@ ssize_t VfsJffs2Read(struct file *filep, char *buffer, size_t bufLen)
off_t len = min(bufLen, (node->i_size - pos));
ret = jffs2_read_inode_range(c, f, (unsigned char *)buffer, filep->f_pos, len);
if (ret) {
PRINTK("VfsJffs2Read(): read_inode_range failed %d\n", ret);
LOS_MuxUnlock(&g_jffs2FsLock);
return ret;
}
@@ -305,6 +330,59 @@ ssize_t VfsJffs2Read(struct file *filep, char *buffer, size_t bufLen)
return len;
}
ssize_t VfsJffs2WritePage(struct Vnode *vnode, char *buffer, off_t pos, size_t buflen)
{
struct jffs2_inode *node = NULL;
struct jffs2_inode_info *f = NULL;
struct jffs2_sb_info *c = NULL;
struct jffs2_raw_inode ri = {0};
struct IATTR attr = {0};
int ret;
uint32_t writtenLen;
LOS_MuxLock(&g_jffs2FsLock, (uint32_t)JFFS2_WAITING_FOREVER);
node = (struct jffs2_inode *)vnode->data;
f = JFFS2_INODE_INFO(node);
c = JFFS2_SB_INFO(node->i_sb);
if (pos < 0) {
LOS_MuxUnlock(&g_jffs2FsLock);
return -EINVAL;
}
ri.ino = cpu_to_je32(f->inocache->ino);
ri.mode = cpu_to_jemode(node->i_mode);
ri.uid = cpu_to_je16(node->i_uid);
ri.gid = cpu_to_je16(node->i_gid);
ri.atime = ri.ctime = ri.mtime = cpu_to_je32(Jffs2CurSec());
if (pos > node->i_size) {
int err;
attr.attr_chg_valid = CHG_SIZE;
attr.attr_chg_size = pos;
err = jffs2_setattr(node, &attr);
if (err) {
LOS_MuxUnlock(&g_jffs2FsLock);
return err;
}
}
ri.isize = cpu_to_je32(node->i_size);
ret = jffs2_write_inode_range(c, f, &ri, (unsigned char *)buffer, pos, buflen, &writtenLen);
if (ret) {
node->i_mtime = node->i_ctime = je32_to_cpu(ri.mtime);
LOS_MuxUnlock(&g_jffs2FsLock);
return ret;
}
node->i_mtime = node->i_ctime = je32_to_cpu(ri.mtime);
LOS_MuxUnlock(&g_jffs2FsLock);
return (ssize_t)writtenLen;
}
ssize_t VfsJffs2Write(struct file *filep, const char *buffer, size_t bufLen)
{
struct jffs2_inode *node = NULL;
@@ -686,7 +764,6 @@ int VfsJffs2Symlink(struct Vnode *parentVnode, struct Vnode **newVnode, const ch
ssize_t VfsJffs2Readlink(struct Vnode *vnode, char *buffer, size_t bufLen)
{
ssize_t ret = 0;
struct jffs2_inode *inode = NULL;
struct jffs2_inode_info *f = NULL;
ssize_t targetLen;
@@ -705,14 +782,12 @@ ssize_t VfsJffs2Readlink(struct Vnode *vnode, char *buffer, size_t bufLen)
cnt = (bufLen - 1) < targetLen ? (bufLen - 1) : targetLen;
if (LOS_CopyFromKernel(buffer, bufLen, (const char *)f->target, cnt) != 0) {
cnt = 0;
ret = -EFAULT;
LOS_MuxUnlock(&g_jffs2FsLock);
return -EFAULT;
}
buffer[cnt] = '\0';
LOS_MuxUnlock(&g_jffs2FsLock);
if (ret < 0) {
return ret;
}
return cnt;
}
@@ -878,6 +953,8 @@ const struct MountOps jffs_operations = {
struct VnodeOps g_jffs2Vops = {
.Lookup = VfsJffs2Lookup,
.Create = VfsJffs2Create,
.ReadPage = VfsJffs2ReadPage,
.WritePage = VfsJffs2WritePage,
.Rename = VfsJffs2Rename,
.Mkdir = VfsJffs2Mkdir,
.Getattr = VfsJffs2Stat,

View File

@@ -33,6 +33,6 @@ MODULE_NAME := $(notdir $(shell pwd))
LOCAL_SRCS := $(wildcard $(LITEOSTHIRDPARTY)/NuttX/fs/nfs/*.c)
LOCAL_FLAGS := $(LOCAL_INCLUDE) $(LITEOS_GCOV_OPTS)
LOCAL_FLAGS := $(LOCAL_INCLUDE)
include $(MODULE)

Some files were not shown because too many files have changed in this diff Show More