1 // Copyright 2017 The Fuchsia Authors 2 // 3 // Use of this source code is governed by a MIT-style 4 // license that can be found in the LICENSE file or at 5 // https://opensource.org/licenses/MIT 6 #pragma once 7 8 #include <arch/ops.h> 9 #include <kernel/align.h> 10 #include <kernel/event.h> 11 #include <kernel/stats.h> 12 #include <kernel/thread.h> 13 #include <kernel/timer.h> 14 #include <list.h> 15 #include <sys/types.h> 16 #include <zircon/compiler.h> 17 18 __BEGIN_CDECLS 19 20 struct percpu { 21 // per cpu timer queue 22 struct list_node timer_queue; 23 24 // per cpu preemption timer; ZX_TIME_INFINITE means not set 25 zx_time_t preempt_timer_deadline; 26 27 // deadline of this cpu's platform timer or ZX_TIME_INFINITE if not set 28 zx_time_t next_timer_deadline; 29 30 // per cpu run queue and bitmap to indicate which queues are non empty 31 struct list_node run_queue[NUM_PRIORITIES]; 32 uint32_t run_queue_bitmap; 33 34 #if WITH_LOCK_DEP 35 // state for runtime lock validation when in irq context 36 lockdep_state_t lock_state; 37 #endif 38 39 // thread/cpu level statistics 40 struct cpu_stats stats; 41 42 // per cpu idle thread 43 thread_t idle_thread; 44 45 // kernel counters arena 46 int64_t* counters; 47 48 // dpc context 49 list_node_t dpc_list; 50 event_t dpc_event; 51 // request the dpc thread to stop by setting to true; guarded by dpc_lock 52 bool dpc_stop; 53 // each cpu has a dedicated thread for processing dpcs 54 thread_t* dpc_thread; 55 } __CPU_ALIGN; 56 57 // the kernel per-cpu structure 58 extern struct percpu percpu[SMP_MAX_CPUS]; 59 60 // make sure the bitmap is large enough to cover our number of priorities 61 static_assert(NUM_PRIORITIES <= sizeof(percpu[0].run_queue_bitmap) * CHAR_BIT, ""); 62 get_local_percpu(void)63static inline struct percpu* get_local_percpu(void) { 64 return &percpu[arch_curr_cpu_num()]; 65 } 66 67 __END_CDECLS 68