diff --git a/Kernel/Arch/i386/CPU.cpp b/Kernel/Arch/i386/CPU.cpp index 63cdb482cba..fc444d19b34 100644 --- a/Kernel/Arch/i386/CPU.cpp +++ b/Kernel/Arch/i386/CPU.cpp @@ -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())); diff --git a/Kernel/FileSystem/ProcFS.cpp b/Kernel/FileSystem/ProcFS.cpp index 1b46072390f..b4539717454 100644 --- a/Kernel/FileSystem/ProcFS.cpp +++ b/Kernel/FileSystem/ProcFS.cpp @@ -864,6 +864,7 @@ Optional 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()); diff --git a/Kernel/Thread.h b/Kernel/Thread.h index c4a39c97044..77c140b4512 100644 --- a/Kernel/Thread.h +++ b/Kernel/Thread.h @@ -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 m_cpu { 0 }; u32 m_ticks { 0 }; u32 m_ticks_left { 0 }; u32 m_times_scheduled { 0 }; diff --git a/Libraries/LibCore/ProcessStatisticsReader.cpp b/Libraries/LibCore/ProcessStatisticsReader.cpp index b9a55eb0c33..e13a27dcb48 100644 --- a/Libraries/LibCore/ProcessStatisticsReader.cpp +++ b/Libraries/LibCore/ProcessStatisticsReader.cpp @@ -85,6 +85,7 @@ HashMap 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(); diff --git a/Libraries/LibCore/ProcessStatisticsReader.h b/Libraries/LibCore/ProcessStatisticsReader.h index d0850f2d485..c260735ffa6 100644 --- a/Libraries/LibCore/ProcessStatisticsReader.h +++ b/Libraries/LibCore/ProcessStatisticsReader.h @@ -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;