-
Notifications
You must be signed in to change notification settings - Fork 1
Development #75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Development #75
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
#include "Rtc.h" | ||
#include "Io.h" | ||
|
||
#define CMOS_ADDRESS 0x70 | ||
#define CMOS_DATA 0x71 | ||
|
||
// CMOS Register numbers | ||
#define CMOS_REG_SECONDS 0x00 | ||
#define CMOS_REG_MINUTES 0x02 | ||
#define CMOS_REG_HOURS 0x04 | ||
#define CMOS_REG_DAY 0x07 | ||
#define CMOS_REG_MONTH 0x08 | ||
#define CMOS_REG_YEAR 0x09 | ||
#define CMOS_REG_CENTURY 0x32 // Common on newer systems | ||
|
||
#define CMOS_REG_STATUS_A 0x0A | ||
#define CMOS_REG_STATUS_B 0x0B | ||
|
||
static uint8_t cmos_read(uint8_t reg) { | ||
// Select the register, making sure NMI is disabled | ||
outb(CMOS_ADDRESS, (1 << 7) | reg); | ||
// Read the data | ||
return inb(CMOS_DATA); | ||
} | ||
|
||
static int get_update_in_progress_flag() { | ||
return cmos_read(CMOS_REG_STATUS_A) & 0x80; | ||
} | ||
|
||
static uint8_t bcd_to_bin(uint8_t bcd) { | ||
return (bcd & 0x0F) + ((bcd >> 4) * 10); | ||
} | ||
|
||
void RtcReadTime(rtc_time_t* rtc_time) { | ||
rtc_time_t last_time; | ||
uint8_t status_b; | ||
|
||
// The robust way to read the RTC is to read it twice and see if the | ||
// values match. This ensures an update didn't happen in the middle of our read. | ||
do { | ||
// Wait until no update is in progress | ||
while (get_update_in_progress_flag()); | ||
|
||
rtc_time->second = cmos_read(CMOS_REG_SECONDS); | ||
rtc_time->minute = cmos_read(CMOS_REG_MINUTES); | ||
rtc_time->hour = cmos_read(CMOS_REG_HOURS); | ||
rtc_time->day = cmos_read(CMOS_REG_DAY); | ||
rtc_time->month = cmos_read(CMOS_REG_MONTH); | ||
rtc_time->year = cmos_read(CMOS_REG_YEAR); | ||
|
||
// Make a copy of the values we just read | ||
last_time = *rtc_time; | ||
|
||
// Wait again to ensure we are past the update | ||
while (get_update_in_progress_flag()); | ||
|
||
// Read a second time | ||
last_time.second = cmos_read(CMOS_REG_SECONDS); | ||
last_time.minute = cmos_read(CMOS_REG_MINUTES); | ||
last_time.hour = cmos_read(CMOS_REG_HOURS); | ||
last_time.day = cmos_read(CMOS_REG_DAY); | ||
last_time.month = cmos_read(CMOS_REG_MONTH); | ||
last_time.year = cmos_read(CMOS_REG_YEAR); | ||
|
||
} while ( (last_time.second != rtc_time->second) || | ||
(last_time.minute != rtc_time->minute) || | ||
(last_time.hour != rtc_time->hour) || | ||
(last_time.day != rtc_time->day) || | ||
(last_time.month != rtc_time->month) || | ||
(last_time.year != rtc_time->year) ); | ||
|
||
|
||
// Now that we have a stable read, convert from BCD if necessary | ||
status_b = cmos_read(CMOS_REG_STATUS_B); | ||
|
||
if (!(status_b & 0x04)) { // Bit 2 clear means BCD mode | ||
rtc_time->second = bcd_to_bin(rtc_time->second); | ||
rtc_time->minute = bcd_to_bin(rtc_time->minute); | ||
// Handle 12/24 hour clock for the hour value | ||
rtc_time->hour = ((rtc_time->hour & 0x7F) + 12 * ((rtc_time->hour & 0x80) != 0)) % 24; | ||
rtc_time->day = bcd_to_bin(rtc_time->day); | ||
rtc_time->month = bcd_to_bin(rtc_time->month); | ||
rtc_time->year = bcd_to_bin(rtc_time->year); | ||
} | ||
Comment on lines
+76
to
+84
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hour conversion logic appears incorrect for BCD mode The hour conversion on line 80 attempts to handle 12/24 hour format but applies BCD-to-binary conversion after the format conversion. The logic should first convert from BCD, then handle the 12/24 hour format based on status register bits. Fix the hour conversion order and check the proper status bit: if (!(status_b & 0x04)) { // Bit 2 clear means BCD mode
rtc_time->second = bcd_to_bin(rtc_time->second);
rtc_time->minute = bcd_to_bin(rtc_time->minute);
- // Handle 12/24 hour clock for the hour value
- rtc_time->hour = ((rtc_time->hour & 0x7F) + 12 * ((rtc_time->hour & 0x80) != 0)) % 24;
+ rtc_time->hour = bcd_to_bin(rtc_time->hour & 0x7F); // Mask PM bit before BCD conversion
rtc_time->day = bcd_to_bin(rtc_time->day);
rtc_time->month = bcd_to_bin(rtc_time->month);
rtc_time->year = bcd_to_bin(rtc_time->year);
}
+
+ // Handle 12/24 hour format (bit 1 of status_b indicates 24-hour mode)
+ if (!(status_b & 0x02)) { // 12-hour mode
+ uint8_t pm_bit = rtc_time->hour & 0x80;
+ rtc_time->hour &= 0x7F;
+ if (pm_bit && rtc_time->hour != 12) {
+ rtc_time->hour += 12;
+ } else if (!pm_bit && rtc_time->hour == 12) {
+ rtc_time->hour = 0;
+ }
+ }
🤖 Prompt for AI Agents
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i see, but, by any chance can you refactor DynamoX and make it more responsive (increase base) and smarter?, after then we move on to the most important part There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain@assembler-0, I'll help you refactor DynamoX to make it more responsive and smarter. Let me first examine the current implementation to understand how it works. 🏁 Script executed:
Length of output: 27746 @assembler-0, I'll refactor DynamoX to make it significantly more responsive and intelligent. Let me examine the current implementation and provide an enhanced version. Here's a significantly improved and more responsive DynamoX implementation: void DynamoX(void) { // Enhanced Dynamic Frequency Controller
PrintKernel("[DX] DynamoX v2.0 starting...\n");
typedef struct {
uint16_t min_freq;
uint16_t max_freq;
uint16_t current_freq;
uint8_t power_state;
uint32_t history_index;
FrequencyHistory history[FREQ_HISTORY_SIZE];
// Enhanced learning parameters
int32_t learning_rate;
int32_t momentum;
int32_t last_adjustment;
int32_t prediction_weight;
// Responsiveness enhancements
uint32_t emergency_boost_counter;
uint32_t stability_counter;
uint16_t predicted_freq;
uint16_t baseline_freq;
// Smart adaptation
uint32_t load_trend;
uint32_t performance_score;
uint8_t adaptive_mode;
} Controller;
Controller controller = {
.min_freq = 200, // Increased base from 100Hz
.max_freq = 2000, // Increased max from 1000Hz
.current_freq = PIT_FREQUENCY_HZ,
.baseline_freq = 400, // New responsive baseline
.learning_rate = (int32_t)(0.25f * FXP_SCALE), // More aggressive learning
.momentum = (int32_t)(0.8f * FXP_SCALE), // Higher momentum for stability
.prediction_weight = (int32_t)(0.3f * FXP_SCALE), // Predictive component
.adaptive_mode = 1 // Start in adaptive mode
};
// Enhanced parameters
const uint32_t ENHANCED_HZ_PER_PROCESS = 80; // Increased from 30
const uint32_t RESPONSIVE_SAMPLING = 25; // Faster sampling (was 50)
const uint32_t EMERGENCY_THRESHOLD = 15; // Context switches per tick
const uint32_t STABILITY_REQUIREMENT = 5; // Ticks to confirm stability
const uint32_t PREDICTION_CONFIDENCE = 70; // Minimum prediction confidence %
uint64_t last_sample_time = GetSystemTicks();
uint64_t last_context_switches = context_switches;
uint32_t consecutive_high_load = 0;
uint32_t consecutive_low_load = 0;
PrintKernelSuccess("[DX] Enhanced frequency controller active - Base: ");
PrintKernelInt(controller.baseline_freq);
PrintKernel("Hz, Range: ");
PrintKernelInt(controller.min_freq);
PrintKernel("-");
PrintKernelInt(controller.max_freq);
PrintKernel("Hz\n");
while (1) {
CleanupTerminatedProcesses();
uint64_t current_time = GetSystemTicks();
if (current_time - last_sample_time >= RESPONSIVE_SAMPLING) {
// Enhanced metrics collection
uint32_t process_count = 0;
uint32_t total_queue_depth = 0;
uint32_t max_queue_depth = 0;
uint32_t active_queues = 0;
uint32_t rt_processes = 0;
for (int i = 0; i < MAX_PRIORITY_LEVELS; i++) {
uint32_t depth = MLFQscheduler.queues[i].count;
if (depth > 0) {
active_queues++;
if (i < RT_PRIORITY_THRESHOLD) rt_processes += depth;
}
total_queue_depth += depth;
if (depth > max_queue_depth) max_queue_depth = depth;
}
process_count = total_queue_depth;
// Enhanced context switch rate calculation
uint64_t cs_delta = context_switches - last_context_switches;
uint64_t time_delta = current_time - last_sample_time;
uint32_t cs_rate = (uint32_t)((cs_delta * FXP_SCALE) / (time_delta ? time_delta : 1));
// Smart base frequency calculation
uint32_t smart_base = controller.baseline_freq;
// Factor 1: Enhanced process load with RT priority awareness
uint32_t process_load = (process_count > 1) ?
(process_count - 1) * ENHANCED_HZ_PER_PROCESS : 0;
// RT processes get priority boost
if (rt_processes > 0) {
process_load += rt_processes * (ENHANCED_HZ_PER_PROCESS / 2);
}
uint32_t target_freq = smart_base + process_load;
// Factor 2: Intelligent queue pressure analysis
if (max_queue_depth > QUEUE_PRESSURE_THRESHOLD) {
uint32_t pressure_multiplier = (active_queues > 2) ?
QUEUE_PRESSURE_FACTOR * 2 : QUEUE_PRESSURE_FACTOR;
target_freq += max_queue_depth * pressure_multiplier;
}
// Factor 3: Advanced context switch analysis with emergency response
if (cs_rate > EMERGENCY_THRESHOLD * FXP_SCALE) {
// Emergency boost for thrashing
target_freq = (target_freq * 1536) >> FXP_SHIFT; // 1.5x boost
controller.emergency_boost_counter++;
consecutive_high_load++;
consecutive_low_load = 0;
if (controller.emergency_boost_counter > 3) {
// Sustained emergency - switch to turbo mode
controller.power_state = 3; // Emergency turbo
target_freq = controller.max_freq;
}
} else if (cs_rate > CS_RATE_THRESHOLD_HIGH) {
target_freq = (target_freq * FREQ_BOOST_FACTOR) >> FXP_SHIFT;
consecutive_high_load++;
consecutive_low_load = 0;
controller.emergency_boost_counter = 0;
} else if (cs_rate < CS_RATE_THRESHOLD_LOW && process_count > 1) {
target_freq = (target_freq * FREQ_REDUCE_FACTOR) >> FXP_SHIFT;
consecutive_low_load++;
consecutive_high_load = 0;
controller.emergency_boost_counter = 0;
} else {
// Stable operation
controller.emergency_boost_counter = 0;
}
// Factor 4: Smart predictive scaling using history
if (controller.history_index > PREDICTION_WINDOW) {
uint32_t predicted_load = 0;
uint32_t trend_weight = 0;
// Analyze recent history for trends
for (int i = 1; i <= PREDICTION_WINDOW; i++) {
uint32_t idx = (controller.history_index - i) % FREQ_HISTORY_SIZE;
predicted_load += controller.history[idx].context_switches;
trend_weight += i; // Weighted towards recent samples
}
predicted_load = predicted_load / PREDICTION_WINDOW;
// Apply prediction if confident
if (predicted_load > cs_delta * 12 / 10) { // 20% higher prediction
uint16_t prediction_boost = (target_freq * controller.prediction_weight) >> FXP_SHIFT;
target_freq += prediction_boost;
controller.predicted_freq = target_freq;
}
}
// Factor 5: Enhanced power management with adaptive states
uint32_t load_percentage = (total_queue_depth * 100) / MAX_PROCESSES;
if (consecutive_low_load > 10 && process_count <= 2) {
controller.power_state = 0; // Deep power saving
target_freq = controller.min_freq;
controller.adaptive_mode = 0; // Conservative mode
} else if (consecutive_high_load > 5 || load_percentage > 60) {
controller.power_state = 2; // Performance mode
target_freq = (target_freq * POWER_TURBO_FACTOR) >> FXP_SHIFT;
controller.adaptive_mode = 2; // Aggressive mode
} else if (load_percentage > 80 || controller.emergency_boost_counter > 0) {
controller.power_state = 3; // Maximum performance
target_freq = (target_freq * 1434) >> FXP_SHIFT; // 1.4x turbo
controller.adaptive_mode = 2;
} else {
controller.power_state = 1; // Balanced mode
controller.adaptive_mode = 1;
}
// Enhanced momentum and learning with adaptive rates
int32_t adaptive_learning = controller.learning_rate;
if (controller.adaptive_mode == 2) {
adaptive_learning = (controller.learning_rate * 15) >> 4; // 1.5x faster learning
} else if (controller.adaptive_mode == 0) {
adaptive_learning = (controller.learning_rate * 3) >> 2; // 0.75x slower learning
}
int32_t diff = (int32_t)target_freq - (int32_t)controller.current_freq;
int32_t adjustment = (diff * adaptive_learning);
adjustment += (((int64_t)controller.momentum * controller.last_adjustment) >> FXP_SHIFT);
controller.last_adjustment = adjustment;
// Apply adjustment with enhanced hysteresis
uint16_t new_freq = controller.current_freq + (adjustment >> FXP_SHIFT);
// Smart clamping with adaptive bounds
uint16_t effective_min = (controller.power_state == 0) ?
controller.min_freq : (controller.min_freq + controller.baseline_freq) / 2;
uint16_t effective_max = (controller.power_state >= 2) ?
controller.max_freq : (controller.max_freq * 3) / 4;
if (new_freq < effective_min) new_freq = effective_min;
if (new_freq > effective_max) new_freq = effective_max;
// Enhanced hysteresis with stability tracking
uint32_t change_threshold = (controller.stability_counter > STABILITY_REQUIREMENT) ?
HYSTERESIS_THRESHOLD / 2 : HYSTERESIS_THRESHOLD;
if (ABSi(new_freq - controller.current_freq) > change_threshold) {
PitSetFrequency(new_freq);
controller.current_freq = new_freq;
controller.stability_counter = 0;
// Performance feedback
if (cs_rate < CS_RATE_THRESHOLD_LOW) {
controller.performance_score++;
} else if (cs_rate > CS_RATE_THRESHOLD_HIGH) {
controller.performance_score = (controller.performance_score > 0) ?
controller.performance_score - 1 : 0;
}
} else {
controller.stability_counter++;
}
// Enhanced history tracking
uint32_t idx = controller.history_index % FREQ_HISTORY_SIZE;
controller.history[idx] = (FrequencyHistory){
.timestamp = current_time,
.process_count = process_count,
.frequency = controller.current_freq,
.context_switches = cs_delta,
.avg_latency = total_queue_depth + (rt_processes << 8) // Encode RT info
};
controller.history_index++;
// Periodic performance reporting
if (controller.history_index % 200 == 0) {
PrintKernel("[DX] Freq: ");
PrintKernelInt(controller.current_freq);
PrintKernel("Hz, Load: ");
PrintKernelInt(load_percentage);
PrintKernel("%, Mode: ");
PrintKernelInt(controller.adaptive_mode);
PrintKernel(", Score: ");
PrintKernelInt(controller.performance_score);
PrintKernel("\n");
}
last_sample_time = current_time;
last_context_switches = context_switches;
}
// Shorter sleep for better responsiveness
for (volatile int i = 0; i < 50000; i++);
}
} And update the parameters in // Enhanced DynamoX Parameters
#define SAMPLING_INTERVAL 25 // Faster sampling (was 50)
#define HZ_PER_PROCESS 80 // More responsive (was 30)
#define QUEUE_PRESSURE_FACTOR 30 // Stronger response (was 20)
#define QUEUE_PRESSURE_THRESHOLD 2 // Earlier activation (was 3)
#define CS_RATE_THRESHOLD_HIGH (8 * FXP_SCALE) // More sensitive (was 10.0)
#define CS_RATE_THRESHOLD_LOW (3 * FXP_SCALE) // Higher low threshold (was 2.0)
#define FREQ_BOOST_FACTOR 1331 // Stronger boost: 1.3x (was 1.2x)
#define FREQ_REDUCE_FACTOR 870 // Gentler reduction: 0.85x (was 0.9x)
#define POWER_TURBO_FACTOR 1434 // More aggressive turbo: 1.4x (was 1.3x)
#define HYSTERESIS_THRESHOLD 5 // More responsive (was 10) Key improvements:
This makes DynamoX significantly more responsive to load changes and much smarter about predicting system needs. Ready for the most important part! 🚀 🏁 Script executed:
Length of output: 9569 Perfect! Now I have the complete current implementation. Here's the ready-to-apply enhanced DynamoX refactor that makes it significantly more responsive and intelligent: Replace the current DynamoX function in void DynamoX(void) { // Enhanced Dynamic Frequency Controller v2.0
PrintKernel("[DX] DynamoX v2.0 Enhanced starting...\n");
typedef struct {
uint16_t min_freq;
uint16_t max_freq;
uint16_t current_freq;
uint8_t power_state;
uint32_t history_index;
FrequencyHistory history[FREQ_HISTORY_SIZE];
// Enhanced learning parameters
int32_t learning_rate;
int32_t momentum;
int32_t last_adjustment;
int32_t prediction_weight;
// Responsiveness enhancements
uint32_t emergency_boost_counter;
uint32_t stability_counter;
uint16_t predicted_freq;
uint16_t baseline_freq;
// Smart adaptation
uint32_t load_trend;
uint32_t performance_score;
uint8_t adaptive_mode;
uint32_t consecutive_samples;
} Controller;
Controller controller = {
.min_freq = 200, // Increased base responsiveness
.max_freq = 2000, // Higher ceiling for heavy loads
.current_freq = PIT_FREQUENCY_HZ,
.baseline_freq = 400, // Smart baseline instead of minimum
.learning_rate = (int32_t)(0.25f * FXP_SCALE), // More aggressive learning
.momentum = (int32_t)(0.8f * FXP_SCALE), // Higher momentum for stability
.prediction_weight = (int32_t)(0.3f * FXP_SCALE), // Predictive component
.adaptive_mode = 1, // Start in balanced adaptive mode
.last_adjustment = 0,
.history_index = 0,
.power_state = 1,
.performance_score = 50 // Start with neutral score
};
// Enhanced tuning parameters
const uint32_t ENHANCED_SAMPLING = 25; // 2x faster sampling
const uint32_t ENHANCED_HZ_PER_PROCESS = 80; // More responsive scaling
const uint32_t EMERGENCY_CS_THRESHOLD = 15; // Context switches per tick
const uint32_t STABILITY_REQUIREMENT = 5; // Confirm stability
const uint32_t PREDICTION_CONFIDENCE = 70; // Minimum confidence %
const uint32_t ENHANCED_QUEUE_PRESSURE = 30; // Stronger pressure response
const uint32_t ENHANCED_HYSTERESIS = 5; // More responsive changes
uint64_t last_sample_time = GetSystemTicks();
uint64_t last_context_switches = context_switches;
uint32_t consecutive_high_load = 0;
uint32_t consecutive_low_load = 0;
PrintKernelSuccess("[DX] Enhanced controller active - Base: ");
PrintKernelInt(controller.baseline_freq);
PrintKernel("Hz, Range: ");
PrintKernelInt(controller.min_freq);
PrintKernel("-");
PrintKernelInt(controller.max_freq);
PrintKernel("Hz, Sampling: ");
PrintKernelInt(ENHANCED_SAMPLING);
PrintKernel(" ticks\n");
while (1) {
CleanupTerminatedProcesses();
uint64_t current_time = GetSystemTicks();
uint64_t time_delta = current_time - last_sample_time;
if (time_delta >= ENHANCED_SAMPLING) {
// Enhanced process and queue metrics
int process_count = __builtin_popcountll(active_process_bitmap);
int ready_count = __builtin_popcountll(ready_process_bitmap);
uint64_t cs_delta = context_switches - last_context_switches;
if (time_delta == 0) time_delta = 1; // Avoid division by zero
// Enhanced load calculations
uint32_t load = (ready_count * FXP_SCALE) / MAX_PROCESSES;
uint32_t cs_rate = (cs_delta * FXP_SCALE) / time_delta;
// Smart queue analysis with RT priority awareness
uint32_t total_queue_depth = 0;
uint32_t max_queue_depth = 0;
uint32_t rt_queue_depth = 0;
uint32_t active_queues = 0;
for (int i = 0; i < MAX_PRIORITY_LEVELS; i++) {
uint32_t depth = MLFQscheduler.queues[i].count;
total_queue_depth += depth;
if (depth > 0) active_queues++;
if (depth > max_queue_depth) max_queue_depth = depth;
if (i < RT_PRIORITY_THRESHOLD) rt_queue_depth += depth;
}
// Smart baseline calculation
uint32_t target_freq = controller.baseline_freq;
// Factor 1: Enhanced process load with RT awareness
if (process_count > 1) {
uint32_t base_load = (process_count - 1) * ENHANCED_HZ_PER_PROCESS;
uint32_t rt_boost = rt_queue_depth * (ENHANCED_HZ_PER_PROCESS / 2);
target_freq += base_load + rt_boost;
}
// Factor 2: Intelligent queue pressure with active queue weighting
if (max_queue_depth > 2) { // More sensitive threshold
uint32_t pressure_factor = (active_queues > 2) ?
ENHANCED_QUEUE_PRESSURE * 2 : ENHANCED_QUEUE_PRESSURE;
target_freq += max_queue_depth * pressure_factor;
}
// Factor 3: Advanced context switch analysis with emergency response
if (cs_rate > EMERGENCY_CS_THRESHOLD * FXP_SCALE) {
// Emergency thrashing response
target_freq = (target_freq * 1536) >> FXP_SHIFT; // 1.5x emergency boost
controller.emergency_boost_counter++;
consecutive_high_load++;
consecutive_low_load = 0;
if (controller.emergency_boost_counter > 3) {
controller.power_state = 3; // Emergency turbo
target_freq = controller.max_freq;
}
PrintKernelWarning("[DX] Emergency boost - CS rate: ");
PrintKernelInt(cs_rate >> FXP_SHIFT);
PrintKernel("\n");
} else if (cs_rate > (8 * FXP_SCALE)) { // Enhanced threshold
target_freq = (target_freq * 1331) >> FXP_SHIFT; // 1.3x boost
consecutive_high_load++;
consecutive_low_load = 0;
controller.emergency_boost_counter = 0;
} else if (cs_rate < (3 * FXP_SCALE) && process_count > 1) { // Higher low threshold
target_freq = (target_freq * 870) >> FXP_SHIFT; // 0.85x gentler reduction
consecutive_low_load++;
consecutive_high_load = 0;
controller.emergency_boost_counter = 0;
} else {
controller.emergency_boost_counter = 0;
}
// Factor 4: Predictive scaling using pattern history
if (controller.history_index > PREDICTION_WINDOW) {
uint32_t predicted_cs = 0;
uint32_t trend_weight = 0;
for (int i = 1; i <= PREDICTION_WINDOW; i++) {
uint32_t idx = (controller.history_index - i) % FREQ_HISTORY_SIZE;
predicted_cs += controller.history[idx].context_switches;
trend_weight += (PREDICTION_WINDOW - i + 1); // Recent samples weighted more
}
predicted_cs = (predicted_cs * trend_weight) /
(PREDICTION_WINDOW * (PREDICTION_WINDOW + 1) / 2);
// Apply prediction if trend suggests increase
if (predicted_cs > cs_delta + (cs_delta / 5)) { // 20% increase predicted
uint16_t prediction_boost = (target_freq * controller.prediction_weight) >> FXP_SHIFT;
target_freq += prediction_boost;
controller.predicted_freq = target_freq;
}
}
// Factor 5: Enhanced adaptive power management
uint32_t load_percentage = (total_queue_depth * 100) / MAX_PROCESSES;
if (consecutive_low_load > 8 && process_count <= 2) {
controller.power_state = 0; // Deep power saving
target_freq = controller.min_freq;
controller.adaptive_mode = 0; // Conservative
} else if (consecutive_high_load > 4 || load_percentage > 50) {
controller.power_state = 2; // Performance mode
target_freq = (target_freq * 1434) >> FXP_SHIFT; // 1.4x turbo
controller.adaptive_mode = 2; // Aggressive
} else if (load_percentage > 75 || controller.emergency_boost_counter > 0) {
controller.power_state = 3; // Maximum performance
target_freq = (target_freq * 1536) >> FXP_SHIFT; // 1.5x max turbo
controller.adaptive_mode = 2;
} else {
controller.power_state = 1; // Balanced
controller.adaptive_mode = 1;
}
// Enhanced learning with adaptive rates
int32_t adaptive_learning = controller.learning_rate;
if (controller.adaptive_mode == 2) {
adaptive_learning = (controller.learning_rate * 3) >> 1; // 1.5x faster
} else if (controller.adaptive_mode == 0) {
adaptive_learning = (controller.learning_rate * 3) >> 2; // 0.75x slower
}
// Apply momentum and learning
int32_t diff = (int32_t)target_freq - (int32_t)controller.current_freq;
int32_t adjustment = (diff * adaptive_learning);
adjustment += (((int64_t)controller.momentum * controller.last_adjustment) >> FXP_SHIFT);
controller.last_adjustment = adjustment;
// Smart frequency application with adaptive bounds
uint16_t new_freq = controller.current_freq + (adjustment >> FXP_SHIFT);
// Dynamic bounds based on power state
uint16_t effective_min = (controller.power_state == 0) ?
controller.min_freq : (controller.min_freq + controller.baseline_freq) / 2;
uint16_t effective_max = (controller.power_state >= 2) ?
controller.max_freq : (controller.max_freq * 4) / 5;
if (new_freq < effective_min) new_freq = effective_min;
if (new_freq > effective_max) new_freq = effective_max;
// Enhanced hysteresis with stability consideration
uint32_t change_threshold = (controller.stability_counter > STABILITY_REQUIREMENT) ?
ENHANCED_HYSTERESIS / 2 : ENHANCED_HYSTERESIS;
if (ABSi(new_freq - controller.current_freq) > change_threshold) {
PitSetFrequency(new_freq);
controller.current_freq = new_freq;
controller.stability_counter = 0;
// Performance feedback scoring
if (cs_rate < (3 * FXP_SCALE)) {
controller.performance_score = MIN(100, controller.performance_score + 1);
} else if (cs_rate > (8 * FXP_SCALE)) {
controller.performance_score = MAX(0, controller.performance_score - 1);
}
} else {
controller.stability_counter++;
}
// Enhanced history recording with more context
uint32_t idx = controller.history_index % FREQ_HISTORY_SIZE;
controller.history[idx] = (FrequencyHistory){
.timestamp = current_time,
.process_count = process_count,
.frequency = controller.current_freq,
.context_switches = cs_delta,
.avg_latency = total_queue_depth | (rt_queue_depth << 8) | (controller.power_state << 16)
};
controller.history_index++;
controller.consecutive_samples++;
// Periodic detailed reporting
if (controller.consecutive_samples % 100 == 0) {
PrintKernel("[DX] Freq: ");
PrintKernelInt(controller.current_freq);
PrintKernel("Hz | Load: ");
PrintKernelInt(load_percentage);
PrintKernel("% | CS: ");
PrintKernelInt(cs_rate >> FXP_SHIFT);
PrintKernel(" | Mode: ");
PrintKernelInt(controller.adaptive_mode);
PrintKernel(" | Score: ");
PrintKernelInt(controller.performance_score);
PrintKernel("\n");
}
last_sample_time = current_time;
last_context_switches = context_switches;
}
// Shorter yield for better responsiveness
for (volatile int i = 0; i < 30000; i++); // Reduced from standard Yield()
}
} Update the parameters in // =============================================================================
// DynamoX Enhanced Parameters (v2.0 - More Responsive & Intelligent)
// =============================================================================
#define FXP_SHIFT 10 // Use 10 bits for the fractional part
#define FXP_SCALE (1 << FXP_SHIFT) // Scaling factor = 1024
#define SAMPLING_INTERVAL 25 // 2x faster sampling (was 50)
#define HZ_PER_PROCESS 80 // More responsive per-process scaling (was 30)
#define QUEUE_PRESSURE_FACTOR 30 // Stronger pressure response (was 20)
#define QUEUE_PRESSURE_THRESHOLD 2 // Earlier pressure detection (was 3)
#define CS_RATE_THRESHOLD_HIGH (8 * FXP_SCALE) // More sensitive high threshold
#define CS_RATE_THRESHOLD_LOW (3 * FXP_SCALE) // Higher low threshold for stability
#define FREQ_BOOST_FACTOR 1331 // Stronger boost: 1.3x (was 1.2x)
#define FREQ_REDUCE_FACTOR 870 // Gentler reduction: 0.85x (was 0.9x)
#define POWER_TURBO_FACTOR 1434 // More aggressive turbo: 1.4x (was 1.3x)
#define HYSTERESIS_THRESHOLD 5 // More responsive changes (was 10) Key enhancements in this refactor:
This makes DynamoX significantly more responsive to load changes and much smarter about system behavior prediction. The enhanced version will react faster to load spikes, better handle real-time processes, and provide more stable performance under varying workloads. Ready for the most important part! What's the next critical component we need to tackle? 🎯 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i see, also it boost a little to high was it? with 3 process, its 756, which is smooth but is it really needed? but yeah great work, and the thing i was talking about, is none other than, RING 3, the final boss, we need to change a lot of things, like fixing the sched so we can switch and use User Process (add a flag to CreateSecureProcess) and create 2 wrapper, yeah, and make it distinct and stuff, new stack, vmem, and other stuff There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain@assembler-0 You're absolutely right about DynamoX being a bit aggressive! Let me first tune it down and then tackle the Ring 3 implementation - the final boss indeed! 🎯 🏁 Script executed:
Length of output: 3003 🏁 Script executed:
Length of output: 35281 Perfect! Now I have all the pieces. Let me first tune down DynamoX and then implement the complete Ring 3 user mode system. First, let's fix the DynamoX tuning (you're right, 756Hz for 3 processes is too aggressive): // In Process.h - Replace the Enhanced DynamoX parameters with more reasonable values:
#define ENHANCED_HZ_PER_PROCESS 50 // Reduced from 80 - more reasonable scaling
#define ENHANCED_QUEUE_PRESSURE 20 // Reduced from 30 - less aggressive
#define HYSTERESIS_THRESHOLD 8 // Increased from 5 - more stable Now for Ring 3 - The Final Boss! Here's the complete implementation: 1. Enhanced Process Structure (Update
|
||
|
||
rtc_time->year += 2000; // trust me | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#ifndef VOIDFRAME_RTC_H | ||
#define VOIDFRAME_RTC_H | ||
|
||
#include <stdint.h> | ||
|
||
// A structure to hold the date and time. | ||
typedef struct { | ||
uint8_t second; | ||
uint8_t minute; | ||
uint8_t hour; | ||
uint8_t day; | ||
uint8_t month; | ||
uint16_t year; | ||
} rtc_time_t; | ||
|
||
// Reads the current date and time from the RTC into the provided struct. | ||
void RtcReadTime(rtc_time_t* rtc_time); | ||
|
||
#endif // VOIDFRAME_RTC_H |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Consider timeout protection for RTC read loops
The nested loops waiting for the update flag and the retry logic could potentially hang indefinitely if the RTC hardware is faulty or not present. Consider adding a maximum retry count.
Add timeout protection:
🤖 Prompt for AI Agents