44 strcpy(
string,
"cpu idle_clocks active_clocks interrupt_clocks\n");
52 clock_t timeSinceLastEvent = now -
stat->interruptEnd;
55 stat->idleClocks += timeSinceLastEvent;
59 stat->activeClocks += timeSinceLastEvent;
61 stat->interruptEnd = now;
105 panic(
NULL,
"Failed to initialize statistics directory");
111 panic(
NULL,
"Failed to create CPU statistics file");
116 panic(
NULL,
"Failed to create memory statistics file");
132 stat->idleClocks += timeBetweenTraps;
136 stat->activeClocks += timeBetweenTraps;
148 stat->interruptClocks +=
stat->interruptEnd -
stat->interruptBegin;
#define MAX_PATH
Maximum length of filepaths.
static cpu_t * smp_cpu(cpuid_t id)
Returns a pointer to the cpu_t structure of the CPU with the given id.
static uint16_t smp_cpu_amount(void)
Returns the number of CPUs currently identified.
void statistics_init(void)
Initializes the statistics driver.
void statistics_interrupt_begin(interrupt_frame_t *frame, cpu_t *self)
Called at the beginning of an interrupt.
void statistics_cpu_ctx_init(statistics_cpu_ctx_t *ctx)
Initializes a per-CPU statistics context.
void statistics_interrupt_end(interrupt_frame_t *frame, cpu_t *self)
Called at the end of an interrupt.
#define BUFFER_READ(buffer, count, offset, src, size)
Helper macros for implementing file operations dealing with simple buffers.
NORETURN void panic(const interrupt_frame_t *frame, const char *format,...)
Panic the kernel, printing a message and halting.
uint64_t pmm_free_amount(void)
Retrieves the amount of free physical memory.
uint64_t pmm_reserved_amount(void)
Retrieves the amount of reserved physical memory.
uint64_t pmm_total_amount(void)
Retrieves the total amount of physical memory managed by the PMM.
bool sched_is_idle(cpu_t *cpu)
Checks if the CPU is idle.
static void lock_init(lock_t *lock)
Initializes a lock.
#define LOCK_SCOPE(lock)
Acquires a lock for the reminder of the current scope.
clock_t timer_uptime(void)
Time since boot.
uint64_t stat(const char *path, stat_t *stat)
System call for retrieving info about a file or directory.
#define PAGE_SIZE
Memory page size.
#define NULL
Pointer error value.
#define ERR
Integer error value.
__UINT64_TYPE__ clock_t
A nanosecond time.
EFI_PHYSICAL_ADDRESS buffer
static dentry_t * cpuFile
static dentry_t * memFile
static uint64_t statistics_mem_read(file_t *file, void *buffer, uint64_t count, uint64_t *offset)
static uint64_t statistics_cpu_read(file_t *file, void *buffer, uint64_t count, uint64_t *offset)
static dentry_t * statDir
_PUBLIC int sprintf(char *_RESTRICT s, const char *_RESTRICT format,...)
_PUBLIC void * malloc(size_t size)
_PUBLIC void free(void *ptr)
_PUBLIC size_t strlen(const char *s)
_PUBLIC char * strcpy(char *_RESTRICT s1, const char *_RESTRICT s2)
statistics_cpu_ctx_t stat
Directory entry structure.
File operations structure.
uint64_t(* read)(file_t *file, void *buffer, uint64_t count, uint64_t *offset)
Per-CPU statistics context.
dentry_t * sysfs_dir_new(dentry_t *parent, const char *name, const inode_ops_t *inodeOps, void *private)
Create a new directory inside a mounted SysFS instance.
dentry_t * sysfs_file_new(dentry_t *parent, const char *name, const inode_ops_t *inodeOps, const file_ops_t *fileOps, void *private)
Create a new file inside a mounted SysFS instance.