kernel: Track load produced by interrupt handlers
This commit is contained in:
@@ -19,6 +19,16 @@
|
||||
struct kernel_args;
|
||||
|
||||
|
||||
enum interrupt_type {
|
||||
INTERRUPT_TYPE_EXCEPTION,
|
||||
INTERRUPT_TYPE_IRQ,
|
||||
INTERRUPT_TYPE_LOCAL_IRQ,
|
||||
INTERRUPT_TYPE_SYSCALL,
|
||||
INTERRUPT_TYPE_ICI,
|
||||
INTERRUPT_TYPE_UNKNOWN
|
||||
};
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
@@ -53,7 +63,8 @@ are_interrupts_enabled(void)
|
||||
#define restore_interrupts(status) arch_int_restore_interrupts(status)
|
||||
|
||||
|
||||
status_t reserve_io_interrupt_vectors(long count, long startVector);
|
||||
status_t reserve_io_interrupt_vectors(long count, long startVector,
|
||||
enum interrupt_type type);
|
||||
status_t allocate_io_interrupt_vectors(long count, long *startVector);
|
||||
void free_io_interrupt_vectors(long count, long startVector);
|
||||
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright 2013 Paweł Dziepak, [email protected].
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _KERNEL_LOAD_TRACKING_H
|
||||
#define _KERNEL_LOAD_TRACKING_H
|
||||
|
||||
|
||||
const int32 kMaxLoad = 1000;
|
||||
const bigtime_t kLoadMeasureInterval = 50000;
|
||||
const bigtime_t kIntervalInaccuracy = kLoadMeasureInterval / 4;
|
||||
|
||||
|
||||
static int32
|
||||
compute_load(bigtime_t& measureTime, bigtime_t& measureActiveTime, int32& load)
|
||||
{
|
||||
bigtime_t now = system_time();
|
||||
|
||||
if (measureTime == 0) {
|
||||
measureTime = now;
|
||||
return -1;
|
||||
}
|
||||
|
||||
bigtime_t deltaTime = now - measureTime;
|
||||
|
||||
if (deltaTime < kLoadMeasureInterval)
|
||||
return -1;
|
||||
|
||||
int32 oldLoad = load;
|
||||
ASSERT(oldLoad >= 0 && oldLoad <= kMaxLoad);
|
||||
|
||||
int32 newLoad = measureActiveTime * kMaxLoad;
|
||||
newLoad /= max_c(deltaTime, 1);
|
||||
newLoad = max_c(min_c(newLoad, kMaxLoad), 0);
|
||||
|
||||
measureActiveTime = 0;
|
||||
measureTime = now;
|
||||
|
||||
deltaTime += kIntervalInaccuracy;
|
||||
int n = deltaTime / kLoadMeasureInterval;
|
||||
ASSERT(n > 0);
|
||||
|
||||
if (n > 10)
|
||||
load = newLoad;
|
||||
else {
|
||||
newLoad *= (1 << n) - 1;
|
||||
load = (load + newLoad) / (1 << n);
|
||||
ASSERT(load >= 0 && load <= kMaxLoad);
|
||||
}
|
||||
|
||||
return oldLoad;
|
||||
}
|
||||
|
||||
|
||||
#endif // _KERNEL_LOAD_TRACKING_H
|
||||
Reference in New Issue
Block a user