Skip to content

Commit 57946d7

Browse files
committed
Fix tm parser crash on 6.6
1 parent e790acc commit 57946d7

File tree

12 files changed

+105
-65
lines changed

12 files changed

+105
-65
lines changed

CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ set_target_properties(tm PROPERTIES PREFIX "")
277277
# =================== build meminfo ===================
278278
add_library(meminfo SHARED
279279
${PLUGIN_SOURCES}
280+
devicetree/devicetree.cpp
280281
memory/meminfo.cpp)
281282
set_target_properties(meminfo PROPERTIES PREFIX "")
282283

USAGE.md

+16-16
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,28 @@ Supprot command:
44

55
| command | kernel 5.4 | kernel 5.15 | kernel 6.1 | kernel 6.6 | comment |
66
| -------- | -------- | -------- | -------- | -------- | ----------------- |
7-
| dts ||| | | show device tree |
8-
| cma ||| | | show cma memory |
9-
| reserved ||| | | show reserved memory |
10-
| vmalloc ||| | | show vmalloc memory |
11-
| memblock ||| | | show memblock memory |
12-
| dmabuf ||| | | show dmabuf memory |
13-
| iomem ||| | | show iomem memory |
14-
| buddy ||| | | show buddy info |
7+
| dts ||| | | show device tree |
8+
| cma ||| | | show cma memory |
9+
| reserved ||| | | show reserved memory |
10+
| vmalloc ||| | | show vmalloc memory |
11+
| memblock ||| | | show memblock memory |
12+
| dmabuf ||| | | show dmabuf memory |
13+
| iomem ||| | | show iomem memory |
14+
| buddy ||| | | show buddy info |
1515
| zram ||| | | show zram memory |
16-
| meminfo ||| | | show process memory |
17-
| procrank ||| | | show process memory |
16+
| meminfo ||| | | show process memory |
17+
| procrank ||| | | show process memory |
1818
| binder ||| | | show binder info |
1919
| slub ||| | | show slub memory |
20-
| dd ||| | | show device driver info |
21-
| wq ||| | | show workqueue |
22-
| df ||| | | show mount info |
20+
| dd ||| | | show device driver info |
21+
| wq ||| | x | show workqueue |
22+
| df ||| | | show mount info |
2323
| pageowner ||| | | show pageowner |
2424
| swap ||| | | show swap info |
25-
| rtb ||| | | show rtb log |
26-
| cpu ||| | | show cpu frequency |
25+
| rtb ||| x | x | show rtb log |
26+
| cpu ||| | | show cpu frequency |
2727
| coredump ||| | | generate coredump |
28-
| tm ||| | | show thermal info |
28+
| tm ||| | | show thermal info |
2929

3030

3131
| command | Android-11(30) | Android-12(31) | Android-13(33) | comment |

memory/cma.cpp

+13-7
Original file line numberDiff line numberDiff line change
@@ -160,15 +160,19 @@ void Cma::print_cma_areas(){
160160
fprintf(fp, "=====================================================================================================\n");
161161
int index = 1;
162162
size_t max_len = 0;
163+
size_t addr_len = 0;
163164
for (const auto& cma : mem_list) {
164165
max_len = std::max(max_len,cma->name.size());
166+
std::stringstream tmp;
167+
tmp << std::hex << (cma->base_pfn << 12);
168+
addr_len = std::max(addr_len,tmp.str().length());
165169
}
166170
std::ostringstream oss_hd;
167-
oss_hd << std::left << std::setw(max_len) << "Name" << " "
168-
<< std::left << std::setw(VADDR_PRLEN) << "cma" << " "
169-
<< std::left << std::setw(VADDR_PRLEN + 3) << "Range" << " "
170-
<< std::left << std::setw(10) << "Size" << " "
171-
<< std::left << std::setw(10) << "Used" << " "
171+
oss_hd << std::left << std::setw(max_len) << "Name" << " "
172+
<< std::left << std::setw(VADDR_PRLEN) << "cma" << " "
173+
<< std::left << std::setw(addr_len *2 + 3) << "Range" << " "
174+
<< std::left << std::setw(10) << "Size" << " "
175+
<< std::left << std::setw(10) << "Used" << " "
172176
<< std::left << "Order";
173177
fprintf(fp, "%s \n",oss_hd.str().c_str());
174178
for (const auto& cma : mem_list) {
@@ -177,8 +181,10 @@ void Cma::print_cma_areas(){
177181
std::ostringstream oss;
178182
oss << std::left << std::setw(max_len) << cma->name << " "
179183
<< std::left << std::hex << std::setw(VADDR_PRLEN) << cma->addr << " "
180-
<< std::left << "[" << std::hex << (cma->base_pfn << 12) << "~" << std::left << std::hex << ((cma->base_pfn + cma->count) << 12) << "]" << " "
181-
<< std::left << std::setw(10) << csize(cma->count * page_size) << " "
184+
<< std::right << "[" << std::hex << std::setw(addr_len) << std::setfill('0') << (cma->base_pfn << 12)
185+
<< "~"
186+
<< std::right << std::hex << std::setw(addr_len) << std::setfill('0') << ((cma->base_pfn + cma->count) << 12) << "]" << " "
187+
<< std::left << std::setw(10) << std::setfill(' ') << csize(cma->count * page_size) << " "
182188
<< std::left << std::setw(10) << csize(cma->allocated_size) << " "
183189
<< cma->order_per_bit;
184190
fprintf(fp, "%s \n",oss.str().c_str());

memory/dmabuf/dmabuf.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,9 @@ std::vector<std::shared_ptr<attachment>> Dmabuf::parser_attachments(ulong list_h
304304
void Dmabuf::print_dma_buf_list(){
305305
int index = 1;
306306
int total_size = 0;
307+
if (buf_list.size() == 0){
308+
return;
309+
}
307310
std::sort(buf_list.begin(), buf_list.end(),[&](const std::shared_ptr<dma_buf>& a, const std::shared_ptr<dma_buf>& b){
308311
return a->size > b->size;
309312
});

memory/memblock.cpp

+9-3
Original file line numberDiff line numberDiff line change
@@ -182,14 +182,20 @@ void Memblock::print_memblock(){
182182
}
183183

184184
void Memblock::print_memblock_type(memblock_type* type){
185+
size_t addr_len = 0;
186+
for (int i = 0; i < type->cnt; ++i) {
187+
std::stringstream tmp;
188+
tmp << std::hex << (type->regions[i]->base + type->regions[i]->size);
189+
addr_len = std::max(addr_len,tmp.str().length());
190+
}
185191
for (int i = 0; i < type->cnt; ++i) {
186192
std::ostringstream oss;
187193
oss << " ["
188194
<< std::setw(5) << std::setfill('0') << i << "]"
189195
<< "memblock_region:" << std::hex << std::setfill(' ') << type->regions[i]->addr
190-
<< " range:[" << std::hex << type->regions[i]->base
191-
<< "~" << std::hex << (type->regions[i]->base + type->regions[i]->size) << "]"
192-
<< " size:" << std::left << std::setw(10) << csize(type->regions[i]->size)
196+
<< " range:[" << std::right << std::hex << std::setw(addr_len) << std::setfill('0') << type->regions[i]->base
197+
<< "~" << std::right << std::hex << std::setw(addr_len) << std::setfill('0') << (type->regions[i]->base + type->regions[i]->size) << "]"
198+
<< " size:" << std::left << std::setw(10) << std::setfill(' ') << csize(type->regions[i]->size)
193199
<< " flags:" << flags_str[type->regions[i]->flags];
194200
fprintf(fp, "%s \n",oss.str().c_str());
195201
}

memory/reserved.cpp

+11-5
Original file line numberDiff line numberDiff line change
@@ -129,23 +129,29 @@ void Reserved::print_reserved_mem(){
129129
return a->base < b->base;
130130
});
131131
size_t max_name_len = 0;
132+
size_t addr_len = 0;
132133
for (const auto& mem : mem_list) {
133134
max_name_len = std::max(max_name_len,mem->name.size());
135+
std::stringstream tmp;
136+
tmp << std::hex << mem->base;
137+
addr_len = std::max(addr_len,tmp.str().length());
134138
}
135139
std::ostringstream oss_hd;
136140
oss_hd << std::left << std::setw(max_name_len) << "Name" << " "
137-
<< std::left << std::setw(VADDR_PRLEN + 2) << "reserved_mem" << " "
138-
<< std::left << std::setw(VADDR_PRLEN + 3) << "Range" << " "
141+
<< std::left << std::setw(VADDR_PRLEN + 5) << "reserved_mem" << " "
142+
<< std::left << std::setw(2 * addr_len + 3) << "Range" << " "
139143
<< std::left << std::setw(10) << "Size" << " "
140144
<< std::left << "Flag";
141145
fprintf(fp, "%s \n",oss_hd.str().c_str());
142146
for (const auto& mem : mem_list) {
143147
total_size += mem->size;
144148
std::ostringstream oss;
145149
oss << std::left << std::setw(max_name_len) << mem->name << " "
146-
<< std::left << std::hex << std::setw(VADDR_PRLEN + 2) << mem->addr << " ["
147-
<< std::left << std::hex << mem->base << "~" << std::hex << (mem->base + mem->size) << "]" << " "
148-
<< std::left << std::setw(10) << csize(mem->size) << " [";
150+
<< std::left << std::hex << std::setw(VADDR_PRLEN + 5) << mem->addr << " ["
151+
<< std::right << std::hex << std::setw(addr_len) << std::setfill('0') << mem->base
152+
<< "~"
153+
<< std::right << std::hex << std::setw(addr_len) << std::setfill('0') << (mem->base + mem->size) << "]" << " "
154+
<< std::left << std::setw(10) << std::setfill(' ') << csize(mem->size) << " [";
149155
if (mem->type == Type::NO_MAP){
150156
oss << "no-map";
151157
nomap_size += mem->size;

memory/swapinfo.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,15 @@ Swapinfo::Swapinfo(std::shared_ptr<Zraminfo> zram): zram_ptr(zram){
2727
}
2828

2929
Swapinfo::Swapinfo(){
30-
init_command();
3130
zram_ptr = std::make_shared<Zraminfo>();
31+
init_command();
3232
//print_table();
3333
}
3434

35+
bool Swapinfo::is_zram_enable(){
36+
return zram_ptr->is_zram_enable();
37+
}
38+
3539
void Swapinfo::init_command(){
3640
field_init(swap_info_struct,pages);
3741
field_init(swap_info_struct,inuse_pages);

memory/swapinfo.h

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class Swapinfo : public PaserPlugin {
4343
std::unordered_map<size_t, char*> zram_page_cahe; //<PTE, buf>
4444
public:
4545
Swapinfo();
46+
bool is_zram_enable();
4647
Swapinfo(std::shared_ptr<Zraminfo> zram);
4748
~Swapinfo();
4849
void init_command();

memory/vmalloc.cpp

+17-13
Original file line numberDiff line numberDiff line change
@@ -179,13 +179,18 @@ void Vmalloc::parser_vmap_area_list(){
179179
fprintf(fp, "Failed to read vm_struct structure at address %lx\n", vm_addr);
180180
continue;
181181
}
182+
size_t vm_size = ULONG(vm_buf + field_offset(vm_struct,size));
183+
int nr_pages = UINT(vm_buf + field_offset(vm_struct,nr_pages));
184+
if (vm_size % page_size != 0 || (vm_size / page_size) != (nr_pages + 1)) {
185+
FREEBUF(vm_buf);
186+
break;
187+
}
182188
std::shared_ptr<vm_struct> vm_ptr = std::make_shared<vm_struct>();
183189
vm_ptr->addr = vm_addr;
184190
vm_ptr->kaddr = ULONG(vm_buf + field_offset(vm_struct,addr));
185-
vm_ptr->size = ULONG(vm_buf + field_offset(vm_struct,size));
186-
vm_ptr->nr_pages = UINT(vm_buf + field_offset(vm_struct,nr_pages));
191+
vm_ptr->size = vm_size;
192+
vm_ptr->nr_pages = nr_pages;
187193
vm_ptr->phys_addr = ULONG(vm_buf + field_offset(vm_struct,phys_addr));
188-
189194
ulong caller = ULONG(vm_buf + field_offset(vm_struct,caller));
190195
ulong next = ULONG(vm_buf + field_offset(vm_struct,next));
191196
ulong pages = ULONG(vm_buf + field_offset(vm_struct,pages));
@@ -217,17 +222,16 @@ void Vmalloc::parser_vmap_area_list(){
217222
if (offset)
218223
vm_ptr->caller.append("+").append(std::to_string(offset));
219224
}
220-
for (int j = 0; j < vm_ptr->nr_pages; ++j) {
221-
ulong addr = pages + j * sizeof(void *);
222-
ulong page_addr = read_pointer(addr,"vm_struct pages");
223-
if (!is_kvaddr(page_addr)) {
224-
continue;
225-
}
226-
physaddr_t paddr = page_to_phy(page_addr);
227-
if (paddr <= 0){
228-
continue;
225+
if (is_kvaddr(pages)) {
226+
for (int j = 0; j < vm_ptr->nr_pages; ++j) {
227+
ulong addr = pages + j * sizeof(void *);
228+
if (!is_kvaddr(addr)) break;
229+
ulong page_addr = read_pointer(addr,"vm_struct pages");
230+
if (!is_kvaddr(page_addr)) continue;
231+
physaddr_t paddr = page_to_phy(page_addr);
232+
if (paddr <= 0) continue;
233+
vm_ptr->page_list.push_back(page_addr);
229234
}
230-
vm_ptr->page_list.push_back(page_addr);
231235
}
232236
area_ptr->vm_list.push_back(vm_ptr);
233237
vm_addr = next;

procrank/procrank.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ void Procrank::init_command(){
7272
}
7373

7474
void Procrank::parser_process_memory() {
75+
if (!swap_ptr->is_zram_enable()){
76+
return;
77+
}
7578
if (procrank_list.size() == 0){
7679
for(ulong task_addr: for_each_process()){
7780
auto procrank_result = std::make_shared<procrank>();

rtb/rtb.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ Rtb::Rtb(){
8181
"dump rtb log", /* short description */
8282
"-a \n"
8383
" rtb -c <cpu>\n"
84-
" rtb -i\n"
8584
" This command dumps the rtb log.",
8685
"\n",
8786
"EXAMPLES",

thermal/thermal.cpp

+26-19
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ void Thermal::parser_thrermal_zone(){
161161
zone_ptr->governor = read_cstring(governor_addr,20, "governor name");
162162
int trip_cnt = 0;
163163
ulong trip_addr = 0;
164-
if (field_offset(thermal_zone_device,num_trips) != -1){
164+
if (field_offset(thermal_zone_device,trips) != -1){
165165
trip_cnt = INT(dev_buf + field_offset(thermal_zone_device,num_trips));
166166
trip_addr = ULONG(dev_buf + field_offset(thermal_zone_device,trips));
167167
}else{
@@ -182,25 +182,32 @@ void Thermal::parser_thrermal_zone(){
182182
zone_ptr->trip_list.push_back(trip_ptr);
183183
}
184184
}
185-
int node_offset = field_offset(thermal_instance, tz_node);
186-
ulong head_addr = addr + field_offset(thermal_zone_device,thermal_instances);
187-
for (const auto& ins_addr : for_each_list(head_addr,node_offset)) {
188-
void *ins_buf = read_struct(ins_addr,"thermal_instance");
189-
int trip = INT(ins_buf + field_offset(thermal_instance,trip));
190-
if (trip > zone_ptr->trip_list.size()) {
191-
continue;
192-
}
193-
ulong cdev = ULONG(ins_buf + field_offset(thermal_instance,cdev));
194-
FREEBUF(ins_buf);
195-
if (!is_kvaddr(cdev)) {
196-
continue;
185+
if (zone_ptr->trip_list.size() > 0){
186+
int node_offset = field_offset(thermal_instance, tz_node);
187+
ulong head_addr = addr + field_offset(thermal_zone_device,thermal_instances);
188+
for (const auto& ins_addr : for_each_list(head_addr,node_offset)) {
189+
void *ins_buf = read_struct(ins_addr,"thermal_instance");
190+
int trip = INT(ins_buf + field_offset(thermal_instance,trip));
191+
if (trip > zone_ptr->trip_list.size()) {
192+
continue;
193+
}
194+
ulong cdev = ULONG(ins_buf + field_offset(thermal_instance,cdev));
195+
FREEBUF(ins_buf);
196+
if (!is_kvaddr(cdev)) {
197+
continue;
198+
}
199+
std::shared_ptr<cool_dev> cdev_ptr = std::make_shared<cool_dev>();
200+
cdev_ptr->addr = cdev;
201+
ulong type_addr = read_pointer(cdev + field_offset(thermal_cooling_device,type),"type addr");
202+
if (is_kvaddr(type_addr)){
203+
cdev_ptr->name = read_cstring(type_addr,64, "type");
204+
}else{
205+
cdev_ptr->name = "";
206+
}
207+
cdev_ptr->id = read_int(cdev + field_offset(thermal_cooling_device,id), "id");
208+
// fprintf(fp, "trip:%d cdev name:%s\n",trip,cdev_ptr->name.c_str());
209+
zone_ptr->trip_list[trip]->cool_list.push_back(cdev_ptr);
197210
}
198-
std::shared_ptr<cool_dev> cdev_ptr = std::make_shared<cool_dev>();
199-
cdev_ptr->addr = cdev;
200-
cdev_ptr->name = read_cstring(cdev + field_offset(thermal_cooling_device,type),20, "type");
201-
cdev_ptr->id = read_int(cdev + field_offset(thermal_cooling_device,id), "id");
202-
// fprintf(fp, "trip:%d cdev name:%s\n",trip,cdev_ptr->name.c_str());
203-
zone_ptr->trip_list[trip]->cool_list.push_back(cdev_ptr);
204211
}
205212
FREEBUF(dev_buf);
206213
zone_list.push_back(zone_ptr);

0 commit comments

Comments
 (0)