Kernel/LibCore: Expose processor id where a thread last ran

This commit is contained in:
Tom 2020-06-27 22:36:15 -06:00 committed by Andreas Kling
parent d98edb3171
commit d99901660d
Notes: sideshowbarker 2024-07-19 05:18:06 +09:00
5 changed files with 11 additions and 1 deletions

View File

@ -904,13 +904,16 @@ extern "C" void enter_thread_context(Thread* from_thread, Thread* to_thread)
set_fs(to_tss.fs);
set_gs(to_tss.gs);
auto& tls_descriptor = Processor::current().get_gdt_entry(GDT_SELECTOR_TLS);
auto& processor = Processor::current();
auto& tls_descriptor = processor.get_gdt_entry(GDT_SELECTOR_TLS);
tls_descriptor.set_base(to_thread->thread_specific_data().as_ptr());
tls_descriptor.set_limit(to_thread->thread_specific_region_size());
if (from_tss.cr3 != to_tss.cr3)
write_cr3(to_tss.cr3);
to_thread->set_cpu(processor.id());
asm volatile("fxrstor %0"
::"m"(to_thread->fpu_state()));

View File

@ -864,6 +864,7 @@ Optional<KBuffer> procfs$all(InodeIdentifier)
thread_object.add("times_scheduled", thread.times_scheduled());
thread_object.add("ticks", thread.ticks());
thread_object.add("state", thread.state_string());
thread_object.add("cpu", thread.cpu());
thread_object.add("priority", thread.priority());
thread_object.add("effective_priority", thread.effective_priority());
thread_object.add("syscall_count", thread.syscall_count());

View File

@ -273,6 +273,9 @@ public:
bool in_kernel() const { return (m_tss.cs & 0x03) == 0; }
u32 cpu() const { return m_cpu.load(AK::MemoryOrder::memory_order_consume); }
void set_cpu(u32 cpu) { m_cpu.store(cpu, AK::MemoryOrder::memory_order_release); }
u32 frame_ptr() const { return m_tss.ebp; }
u32 stack_ptr() const { return m_tss.esp; }
@ -466,6 +469,7 @@ private:
int m_tid { -1 };
TSS32 m_tss;
FarPtr m_far_ptr;
Atomic<u32> m_cpu { 0 };
u32 m_ticks { 0 };
u32 m_ticks_left { 0 };
u32 m_times_scheduled { 0 };

View File

@ -85,6 +85,7 @@ HashMap<pid_t, Core::ProcessStatistics> ProcessStatisticsReader::get_all()
thread.name = thread_object.get("name").to_string();
thread.state = thread_object.get("state").to_string();
thread.ticks = thread_object.get("ticks").to_u32();
thread.cpu = thread_object.get("cpu").to_u32();
thread.priority = thread_object.get("priority").to_u32();
thread.effective_priority = thread_object.get("effective_priority").to_u32();
thread.syscall_count = thread_object.get("syscall_count").to_u32();

View File

@ -47,6 +47,7 @@ struct ThreadStatistics {
unsigned file_read_bytes;
unsigned file_write_bytes;
String state;
u32 cpu;
u32 priority;
u32 effective_priority;
String name;