mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 04:57:44 +00:00
Kernel: Use a raw VM region for sorting ELF symbols instead of a Vector.
This avoids putting pressure on kmalloc() during backtrace symbolication. Since we dump backtrace for every process that exits, this is actually a decent performance improvement for things like GCC that chain a lot of processes together.
This commit is contained in:
parent
7a3f59ae3f
commit
f83263a72b
2 changed files with 36 additions and 6 deletions
|
@ -2,6 +2,10 @@
|
||||||
#include <AK/QuickSort.h>
|
#include <AK/QuickSort.h>
|
||||||
#include <AK/kstdio.h>
|
#include <AK/kstdio.h>
|
||||||
|
|
||||||
|
#ifdef KERNEL
|
||||||
|
#include <Kernel/VM/MemoryManager.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
//#define ELFLOADER_DEBUG
|
//#define ELFLOADER_DEBUG
|
||||||
|
|
||||||
ELFLoader::ELFLoader(const byte* buffer)
|
ELFLoader::ELFLoader(const byte* buffer)
|
||||||
|
@ -79,6 +83,24 @@ char* ELFLoader::symbol_ptr(const char* name)
|
||||||
|
|
||||||
String ELFLoader::symbolicate(dword address) const
|
String ELFLoader::symbolicate(dword address) const
|
||||||
{
|
{
|
||||||
|
SortedSymbol* sorted_symbols = nullptr;
|
||||||
|
#ifdef KERNEL
|
||||||
|
if (!m_sorted_symbols_region) {
|
||||||
|
m_sorted_symbols_region = MM.allocate_kernel_region(PAGE_ROUND_UP(m_image.symbol_count() * sizeof(SortedSymbol)), "Sorted symbols");
|
||||||
|
sorted_symbols = (SortedSymbol*)m_sorted_symbols_region->vaddr().as_ptr();
|
||||||
|
dbgprintf("sorted_symbols: %p\n", sorted_symbols);
|
||||||
|
size_t index = 0;
|
||||||
|
m_image.for_each_symbol([&](auto& symbol) {
|
||||||
|
sorted_symbols[index++] = { symbol.value(), symbol.name() };
|
||||||
|
return IterationDecision::Continue;
|
||||||
|
});
|
||||||
|
quick_sort(sorted_symbols, sorted_symbols + m_image.symbol_count(), [](auto& a, auto& b) {
|
||||||
|
return a.address < b.address;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
sorted_symbols = (SortedSymbol*)m_sorted_symbols_region->vaddr().as_ptr();
|
||||||
|
}
|
||||||
|
#else
|
||||||
if (m_sorted_symbols.is_empty()) {
|
if (m_sorted_symbols.is_empty()) {
|
||||||
m_sorted_symbols.ensure_capacity(m_image.symbol_count());
|
m_sorted_symbols.ensure_capacity(m_image.symbol_count());
|
||||||
m_image.for_each_symbol([this](auto& symbol) {
|
m_image.for_each_symbol([this](auto& symbol) {
|
||||||
|
@ -89,12 +111,14 @@ String ELFLoader::symbolicate(dword address) const
|
||||||
return a.address < b.address;
|
return a.address < b.address;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
sorted_symbols = m_sorted_symbols.data();
|
||||||
|
#endif
|
||||||
|
|
||||||
for (int i = 0; i < m_sorted_symbols.size(); ++i) {
|
for (size_t i = 0; i < m_image.symbol_count(); ++i) {
|
||||||
if (m_sorted_symbols[i].address > address) {
|
if (sorted_symbols[i].address > address) {
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
return "!!";
|
return "!!";
|
||||||
auto& symbol = m_sorted_symbols[i - 1];
|
auto& symbol = sorted_symbols[i - 1];
|
||||||
return String::format("%s +%u", symbol.name, address - symbol.address);
|
return String::format("%s +%u", symbol.name, address - symbol.address);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,11 +4,13 @@
|
||||||
#include <AK/HashMap.h>
|
#include <AK/HashMap.h>
|
||||||
#include <AK/OwnPtr.h>
|
#include <AK/OwnPtr.h>
|
||||||
#include <AK/Vector.h>
|
#include <AK/Vector.h>
|
||||||
#if defined(KERNEL)
|
|
||||||
# include <Kernel/VirtualAddress.h>
|
|
||||||
#endif
|
|
||||||
#include <AK/ELF/ELFImage.h>
|
#include <AK/ELF/ELFImage.h>
|
||||||
|
|
||||||
|
#ifdef KERNEL
|
||||||
|
#include <Kernel/VirtualAddress.h>
|
||||||
|
class Region;
|
||||||
|
#endif
|
||||||
|
|
||||||
class ELFLoader {
|
class ELFLoader {
|
||||||
public:
|
public:
|
||||||
explicit ELFLoader(const byte*);
|
explicit ELFLoader(const byte*);
|
||||||
|
@ -50,5 +52,9 @@ private:
|
||||||
dword address;
|
dword address;
|
||||||
const char* name;
|
const char* name;
|
||||||
};
|
};
|
||||||
|
#ifdef KERNEL
|
||||||
|
mutable RefPtr<Region> m_sorted_symbols_region;
|
||||||
|
#else
|
||||||
mutable Vector<SortedSymbol> m_sorted_symbols;
|
mutable Vector<SortedSymbol> m_sorted_symbols;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue