Skip to content

Commit

Permalink
Kernel: Make syscall counters and page fault counters per-thread
Browse files Browse the repository at this point in the history
Now that we show individual threads in SystemMonitor and "top",
it's also very nice to have individual counters for the threads. :^)
  • Loading branch information
awesomekling committed Nov 26, 2019
1 parent 712ae73 commit 5b8cf2e
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 38 deletions.
8 changes: 4 additions & 4 deletions Applications/SystemMonitor/ProcessModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,10 @@ void ProcessModel::update()
ThreadState state;
state.pid = it.value.pid;
state.user = it.value.username;
state.syscall_count = it.value.syscall_count;
state.inode_faults = it.value.inode_faults;
state.zero_faults = it.value.zero_faults;
state.cow_faults = it.value.cow_faults;
state.syscall_count = thread.syscall_count;
state.inode_faults = thread.inode_faults;
state.zero_faults = thread.zero_faults;
state.cow_faults = thread.cow_faults;
state.name = it.value.name;
state.amount_virtual = it.value.amount_virtual;
state.amount_resident = it.value.amount_resident;
Expand Down
8 changes: 4 additions & 4 deletions Kernel/FileSystem/ProcFS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -689,10 +689,6 @@ Optional<KBuffer> procfs$all(InodeIdentifier)
process_object.add("amount_virtual", (u32)process.amount_virtual());
process_object.add("amount_resident", (u32)process.amount_resident());
process_object.add("amount_shared", (u32)process.amount_shared());
process_object.add("syscall_count", process.syscall_count());
process_object.add("inode_faults", process.inode_faults());
process_object.add("zero_faults", process.zero_faults());
process_object.add("cow_faults", process.cow_faults());
process_object.add("icon_id", process.icon_id());
auto thread_array = process_object.add_array("threads");
process.for_each_thread([&](const Thread& thread) {
Expand All @@ -702,6 +698,10 @@ Optional<KBuffer> procfs$all(InodeIdentifier)
thread_object.add("ticks", thread.ticks());
thread_object.add("state", thread.state_string());
thread_object.add("priority", to_string(thread.priority()));
thread_object.add("syscall_count", thread.syscall_count());
thread_object.add("inode_faults", thread.inode_faults());
thread_object.add("zero_faults", thread.zero_faults());
thread_object.add("cow_faults", thread.cow_faults());
return IterationDecision::Continue;
});
};
Expand Down
14 changes: 0 additions & 14 deletions Kernel/Process.h
Original file line number Diff line number Diff line change
Expand Up @@ -286,15 +286,6 @@ class Process : public InlineLinkedListNode<Process>

Lock& big_lock() { return m_big_lock; }

unsigned syscall_count() const { return m_syscall_count; }
void did_syscall() { ++m_syscall_count; }
unsigned inode_faults() const { return m_inode_faults; }
void did_inode_fault() { ++m_inode_faults; }
unsigned zero_faults() const { return m_zero_faults; }
void did_zero_fault() { ++m_zero_faults; }
unsigned cow_faults() const { return m_cow_faults; }
void did_cow_fault() { ++m_cow_faults; }

const ELFLoader* elf_loader() const { return m_elf_loader.ptr(); }

int icon_id() const { return m_icon_id; }
Expand Down Expand Up @@ -373,11 +364,6 @@ class Process : public InlineLinkedListNode<Process>

int m_next_tid { 0 };

unsigned m_syscall_count { 0 };
unsigned m_inode_faults { 0 };
unsigned m_zero_faults { 0 };
unsigned m_cow_faults { 0 };

RefPtr<ProcessTracer> m_tracer;
OwnPtr<ELFLoader> m_elf_loader;

Expand Down
2 changes: 1 addition & 1 deletion Kernel/Syscall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ int handle(RegisterDump& regs, u32 function, u32 arg1, u32 arg2, u32 arg3)
{
ASSERT_INTERRUPTS_ENABLED();
auto& process = current->process();
process.did_syscall();
current->did_syscall();

if (function == SC_exit || function == SC_exit_thread) {
// These syscalls need special handling since they never return to the caller.
Expand Down
14 changes: 14 additions & 0 deletions Kernel/Thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,15 @@ class Thread {

void make_thread_specific_region(Badge<Process>);

unsigned syscall_count() const { return m_syscall_count; }
void did_syscall() { ++m_syscall_count; }
unsigned inode_faults() const { return m_inode_faults; }
void did_inode_fault() { ++m_inode_faults; }
unsigned zero_faults() const { return m_zero_faults; }
void did_zero_fault() { ++m_zero_faults; }
unsigned cow_faults() const { return m_cow_faults; }
void did_cow_fault() { ++m_cow_faults; }

Thread* clone(Process&);

template<typename Callback>
Expand Down Expand Up @@ -376,6 +385,11 @@ class Thread {
Thread* m_joinee { nullptr };
void* m_exit_value { nullptr };

unsigned m_syscall_count { 0 };
unsigned m_inode_faults { 0 };
unsigned m_zero_faults { 0 };
unsigned m_cow_faults { 0 };

FPUState* m_fpu_state { nullptr };
State m_state { Invalid };
ThreadPriority m_priority { ThreadPriority::Normal };
Expand Down
6 changes: 3 additions & 3 deletions Kernel/VM/Region.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ PageFaultResponse Region::handle_zero_fault(size_t page_index_in_region)
}

if (current)
current->process().did_zero_fault();
current->did_zero_fault();

auto physical_page = MM.allocate_user_physical_page(MemoryManager::ShouldZeroFill::Yes);
if (physical_page.is_null()) {
Expand Down Expand Up @@ -338,7 +338,7 @@ PageFaultResponse Region::handle_cow_fault(size_t page_index_in_region)
}

if (current)
current->process().did_cow_fault();
current->did_cow_fault();

#ifdef PAGE_FAULT_DEBUG
dbgprintf(" >> It's a COW page and it's time to COW!\n");
Expand Down Expand Up @@ -382,7 +382,7 @@ PageFaultResponse Region::handle_inode_fault(size_t page_index_in_region)
}

if (current)
current->process().did_inode_fault();
current->did_inode_fault();

#ifdef MM_DEBUG
dbgprintf("MM: page_in_from_inode ready to read from inode\n");
Expand Down
8 changes: 4 additions & 4 deletions Libraries/LibCore/CProcessStatisticsReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ HashMap<pid_t, CProcessStatistics> CProcessStatisticsReader::get_all()
process.amount_virtual = process_object.get("amount_virtual").to_u32();
process.amount_resident = process_object.get("amount_resident").to_u32();
process.amount_shared = process_object.get("amount_shared").to_u32();
process.syscall_count = process_object.get("syscall_count").to_u32();
process.inode_faults = process_object.get("inode_faults").to_u32();
process.zero_faults = process_object.get("zero_faults").to_u32();
process.cow_faults = process_object.get("cow_faults").to_u32();
process.icon_id = process_object.get("icon_id").to_int();

auto thread_array = process_object.get("threads").as_array();
Expand All @@ -53,6 +49,10 @@ HashMap<pid_t, CProcessStatistics> CProcessStatisticsReader::get_all()
thread.state = thread_object.get("state").to_string();
thread.ticks = thread_object.get("ticks").to_u32();
thread.priority = thread_object.get("priority").to_string();
thread.syscall_count = thread_object.get("syscall_count").to_u32();
thread.inode_faults = thread_object.get("inode_faults").to_u32();
thread.zero_faults = thread_object.get("zero_faults").to_u32();
thread.cow_faults = thread_object.get("cow_faults").to_u32();
process.threads.append(move(thread));
});

Expand Down
8 changes: 4 additions & 4 deletions Libraries/LibCore/CProcessStatisticsReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ struct CThreadStatistics {
int tid;
unsigned times_scheduled;
unsigned ticks;
unsigned syscall_count;
unsigned inode_faults;
unsigned zero_faults;
unsigned cow_faults;
String state;
String priority;
};
Expand All @@ -28,10 +32,6 @@ struct CProcessStatistics {
size_t amount_virtual;
size_t amount_resident;
size_t amount_shared;
unsigned syscall_count;
unsigned inode_faults;
unsigned zero_faults;
unsigned cow_faults;
int icon_id;

Vector<CThreadStatistics> threads;
Expand Down
8 changes: 4 additions & 4 deletions Userland/top.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ static Snapshot get_snapshot()
thread_data.amount_virtual = stats.amount_virtual;
thread_data.amount_resident = stats.amount_resident;
thread_data.amount_shared = stats.amount_shared;
thread_data.syscall_count = stats.syscall_count;
thread_data.inode_faults = stats.inode_faults;
thread_data.zero_faults = stats.zero_faults;
thread_data.cow_faults = stats.cow_faults;
thread_data.syscall_count = thread.syscall_count;
thread_data.inode_faults = thread.inode_faults;
thread_data.zero_faults = thread.zero_faults;
thread_data.cow_faults = thread.cow_faults;
thread_data.icon_id = stats.icon_id;
thread_data.times_scheduled = thread.times_scheduled;
thread_data.priority = thread.priority;
Expand Down

0 comments on commit 5b8cf2e

Please sign in to comment.