Bläddra i källkod

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

Tom 5 år sedan
förälder
incheckning
d99901660d

+ 4 - 1
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_fs(to_tss.fs);
     set_gs(to_tss.gs);
     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_base(to_thread->thread_specific_data().as_ptr());
     tls_descriptor.set_limit(to_thread->thread_specific_region_size());
     tls_descriptor.set_limit(to_thread->thread_specific_region_size());
 
 
     if (from_tss.cr3 != to_tss.cr3)
     if (from_tss.cr3 != to_tss.cr3)
         write_cr3(to_tss.cr3);
         write_cr3(to_tss.cr3);
 
 
+    to_thread->set_cpu(processor.id());
+
     asm volatile("fxrstor %0"
     asm volatile("fxrstor %0"
         ::"m"(to_thread->fpu_state()));
         ::"m"(to_thread->fpu_state()));
 
 

+ 1 - 0
Kernel/FileSystem/ProcFS.cpp

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

+ 4 - 0
Kernel/Thread.h

@@ -273,6 +273,9 @@ public:
 
 
     bool in_kernel() const { return (m_tss.cs & 0x03) == 0; }
     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 frame_ptr() const { return m_tss.ebp; }
     u32 stack_ptr() const { return m_tss.esp; }
     u32 stack_ptr() const { return m_tss.esp; }
 
 
@@ -466,6 +469,7 @@ private:
     int m_tid { -1 };
     int m_tid { -1 };
     TSS32 m_tss;
     TSS32 m_tss;
     FarPtr m_far_ptr;
     FarPtr m_far_ptr;
+    Atomic<u32> m_cpu { 0 };
     u32 m_ticks { 0 };
     u32 m_ticks { 0 };
     u32 m_ticks_left { 0 };
     u32 m_ticks_left { 0 };
     u32 m_times_scheduled { 0 };
     u32 m_times_scheduled { 0 };

+ 1 - 0
Libraries/LibCore/ProcessStatisticsReader.cpp

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

+ 1 - 0
Libraries/LibCore/ProcessStatisticsReader.h

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