2003-05-03 16:03:26 +00:00
|
|
|
/*
|
2006-02-01 16:09:05 +00:00
|
|
|
* Copyright 2002-2006, Haiku Inc. All rights reserved.
|
2005-03-17 17:06:56 +00:00
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
|
*
|
|
|
|
|
* Copyright 2002, Travis Geiselbrecht. All rights reserved.
|
|
|
|
|
* Distributed under the terms of the NewOS License.
|
|
|
|
|
*/
|
2002-07-09 12:24:59 +00:00
|
|
|
#ifndef _KERNEL_CPU_H
|
|
|
|
|
#define _KERNEL_CPU_H
|
|
|
|
|
|
|
|
|
|
|
2009-08-03 12:39:56 +00:00
|
|
|
#include <setjmp.h>
|
|
|
|
|
|
2013-11-18 04:55:25 +01:00
|
|
|
#include <int.h>
|
2002-07-09 12:24:59 +00:00
|
|
|
#include <smp.h>
|
|
|
|
|
#include <timer.h>
|
2007-02-05 01:46:28 +00:00
|
|
|
#include <arch/cpu.h>
|
2002-07-09 12:24:59 +00:00
|
|
|
|
2013-12-17 23:26:37 +01:00
|
|
|
#include <scheduler.h>
|
|
|
|
|
|
2002-07-09 12:24:59 +00:00
|
|
|
|
2010-06-25 22:16:10 +00:00
|
|
|
struct kernel_args;
|
2011-01-10 21:54:38 +00:00
|
|
|
|
|
|
|
|
namespace BKernel {
|
|
|
|
|
struct Thread;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
using BKernel::Thread;
|
2009-12-11 19:06:57 +00:00
|
|
|
|
|
|
|
|
|
2013-10-02 01:19:17 +02:00
|
|
|
typedef enum cpu_topology_level {
|
|
|
|
|
CPU_TOPOLOGY_SMT,
|
|
|
|
|
CPU_TOPOLOGY_CORE,
|
|
|
|
|
CPU_TOPOLOGY_PACKAGE,
|
|
|
|
|
//
|
|
|
|
|
CPU_TOPOLOGY_LEVELS
|
|
|
|
|
} cpu_topology_level;
|
|
|
|
|
|
2013-10-21 01:33:35 +02:00
|
|
|
typedef struct cpu_topology_node {
|
|
|
|
|
cpu_topology_level level;
|
|
|
|
|
|
|
|
|
|
int id;
|
|
|
|
|
|
|
|
|
|
cpu_topology_node** children;
|
|
|
|
|
int children_count;
|
|
|
|
|
} cpu_topology_node;
|
|
|
|
|
|
2013-10-02 01:19:17 +02:00
|
|
|
|
2003-05-03 16:03:26 +00:00
|
|
|
/* CPU local data structure */
|
|
|
|
|
|
2006-04-29 22:38:19 +00:00
|
|
|
typedef struct cpu_ent {
|
2009-12-11 19:06:57 +00:00
|
|
|
int cpu_num;
|
2005-12-12 17:04:36 +00:00
|
|
|
|
2006-04-29 22:38:19 +00:00
|
|
|
// thread.c: used to force a reschedule at quantum expiration time
|
2013-11-12 04:42:12 +01:00
|
|
|
bool preempted;
|
2009-12-11 19:06:57 +00:00
|
|
|
timer quantum_timer;
|
2006-02-01 20:03:55 +00:00
|
|
|
|
2006-04-29 22:38:19 +00:00
|
|
|
// keeping track of CPU activity
|
2013-12-20 01:31:32 +01:00
|
|
|
seqlock active_time_lock;
|
2009-12-11 19:06:57 +00:00
|
|
|
bigtime_t active_time;
|
2013-11-18 01:50:37 +01:00
|
|
|
bigtime_t irq_time;
|
|
|
|
|
bigtime_t interrupt_time;
|
2009-12-11 19:06:57 +00:00
|
|
|
bigtime_t last_kernel_time;
|
|
|
|
|
bigtime_t last_user_time;
|
2009-08-03 12:39:56 +00:00
|
|
|
|
2013-11-29 03:27:00 +01:00
|
|
|
int32 ici_counter;
|
|
|
|
|
|
2009-08-03 12:39:56 +00:00
|
|
|
// used in the kernel debugger
|
2009-12-11 19:06:57 +00:00
|
|
|
addr_t fault_handler;
|
|
|
|
|
addr_t fault_handler_stack_pointer;
|
|
|
|
|
jmp_buf fault_jump_buffer;
|
|
|
|
|
|
2011-01-10 21:54:38 +00:00
|
|
|
Thread* running_thread;
|
2011-06-12 00:00:23 +00:00
|
|
|
Thread* previous_thread;
|
2009-12-11 19:06:57 +00:00
|
|
|
bool invoke_scheduler;
|
|
|
|
|
bool disabled;
|
2008-10-17 16:53:31 +00:00
|
|
|
|
2013-10-02 01:19:17 +02:00
|
|
|
// CPU topology information
|
|
|
|
|
int topology_id[CPU_TOPOLOGY_LEVELS];
|
2013-10-02 23:48:03 +02:00
|
|
|
int cache_id[CPU_MAX_CACHE_LEVEL];
|
2013-10-02 01:19:17 +02:00
|
|
|
|
2013-11-18 04:55:25 +01:00
|
|
|
// IRQs assigned to this CPU
|
|
|
|
|
struct list irqs;
|
|
|
|
|
spinlock irqs_lock;
|
|
|
|
|
|
2007-02-05 01:46:28 +00:00
|
|
|
// arch-specific stuff
|
2013-11-18 04:55:25 +01:00
|
|
|
arch_cpu_info arch;
|
2013-11-25 00:35:15 +01:00
|
|
|
} cpu_ent CACHE_LINE_ALIGN;
|
2005-12-12 17:04:36 +00:00
|
|
|
|
2002-07-09 12:24:59 +00:00
|
|
|
|
2010-06-25 22:16:10 +00:00
|
|
|
extern cpu_ent gCPU[];
|
2013-10-16 18:39:25 +02:00
|
|
|
extern uint32 gCPUCacheLevelCount;
|
2002-07-09 12:24:59 +00:00
|
|
|
|
2004-10-21 01:41:29 +00:00
|
|
|
|
2003-05-03 16:03:26 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
2002-07-09 12:24:59 +00:00
|
|
|
|
2007-02-19 00:11:24 +00:00
|
|
|
status_t cpu_preboot_init_percpu(struct kernel_args *args, int curr_cpu);
|
2004-10-21 01:41:29 +00:00
|
|
|
status_t cpu_init(struct kernel_args *args);
|
2010-06-25 22:16:10 +00:00
|
|
|
status_t cpu_init_percpu(struct kernel_args *ka, int curr_cpu);
|
2004-10-21 01:41:29 +00:00
|
|
|
status_t cpu_init_post_vm(struct kernel_args *args);
|
2005-12-13 16:34:29 +00:00
|
|
|
status_t cpu_init_post_modules(struct kernel_args *args);
|
2006-02-01 20:03:55 +00:00
|
|
|
bigtime_t cpu_get_active_time(int32 cpu);
|
2004-10-21 01:41:29 +00:00
|
|
|
|
2002-07-09 12:24:59 +00:00
|
|
|
cpu_ent *get_cpu_struct(void);
|
2006-02-01 16:09:05 +00:00
|
|
|
extern inline cpu_ent *get_cpu_struct(void) { return &gCPU[smp_get_current_cpu()]; }
|
2002-07-09 12:24:59 +00:00
|
|
|
|
2013-10-21 01:33:35 +02:00
|
|
|
status_t cpu_build_topology_tree(void);
|
2013-12-17 22:08:18 +01:00
|
|
|
const cpu_topology_node* get_cpu_topology(void);
|
2013-10-21 01:33:35 +02:00
|
|
|
|
2013-12-17 23:26:37 +01:00
|
|
|
void cpu_set_scheduler_mode(enum scheduler_mode mode);
|
|
|
|
|
|
|
|
|
|
status_t increase_cpu_performance(int delta);
|
2013-10-30 00:48:07 +01:00
|
|
|
status_t decrease_cpu_performance(int delta);
|
|
|
|
|
|
2013-11-25 23:50:27 +01:00
|
|
|
void cpu_idle(void);
|
|
|
|
|
void cpu_wait(int32* variable, int32 test);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
|
cpu_pause(void)
|
|
|
|
|
{
|
|
|
|
|
arch_cpu_pause();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-03-17 17:06:56 +00:00
|
|
|
void _user_clear_caches(void *address, size_t length, uint32 flags);
|
2006-02-01 16:09:05 +00:00
|
|
|
bool _user_cpu_enabled(int32 cpu);
|
|
|
|
|
status_t _user_set_cpu_enabled(int32 cpu, bool enabled);
|
2005-03-17 17:06:56 +00:00
|
|
|
|
2002-07-09 12:24:59 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2003-05-03 16:03:26 +00:00
|
|
|
#endif /* _KERNEL_CPU_H */
|