Skip to content

Commit

Permalink
Update GC thresholds, init and traces
Browse files Browse the repository at this point in the history
  • Loading branch information
Arto Kinnunen committed Jul 30, 2019
1 parent 1acd1cc commit 01e7d84
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
18 changes: 10 additions & 8 deletions source/Core/ns_monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ typedef enum {
NS_MONITOR_STATE_GC_CRITICAL
} ns_monitor_state_e;

#define HEAP_HIGH_THRESHOLD (0.7) /* Heap usage HIGH threshold */
#define HEAP_CRITICAL_THRESHOLD (0.9) /* Heap usage CRITICAL threshold */
#define HEAP_HIGH_WATERWARK (0.80) /* Heap usage HIGH threshold */
#define HEAP_CRITICAL_WATERMARK (0.90) /* Heap usage CRITICAL threshold */

#define NS_MAINTENANCE_TIMER_INTERVAL 10 // Maintenance interval

Expand Down Expand Up @@ -81,17 +81,19 @@ static void ns_monitor_heap_gc(bool full_gc)
static void ns_monitor_periodic_heap_health_check(void)
{
if (ns_monitor_ptr->mem_stats->heap_sector_allocated_bytes > ns_monitor_ptr->heap_critical_watermark) {
// Heap usage above CRITICAL
if (ns_monitor_ptr->ns_monitor_heap_gc_state != NS_MONITOR_STATE_GC_CRITICAL) {
ns_mem_heap_size_t prev_heap_sector_allocated_bytes = ns_monitor_ptr->mem_stats->heap_sector_allocated_bytes;
// Heap usage above CRITICAL
tr_debug("heap %lu/%lu", (unsigned long)ns_monitor_ptr->mem_stats->heap_sector_allocated_bytes, (unsigned long)ns_monitor_ptr->mem_stats->heap_sector_size);
ns_monitor_heap_gc(true);
ns_monitor_ptr->ns_monitor_heap_gc_state = NS_MONITOR_STATE_GC_CRITICAL;
tr_info("Stack GC critical: freed %lu bytes", (unsigned long)(prev_heap_sector_allocated_bytes - ns_monitor_ptr->mem_stats->heap_sector_allocated_bytes));
}
} else if (ns_monitor_ptr->mem_stats->heap_sector_allocated_bytes > ns_monitor_ptr->heap_high_watermark) {
// Heap usage above HIGH
if (ns_monitor_ptr->ns_monitor_heap_gc_state == NS_MONITOR_STATE_HEAP_GC_IDLE) {
ns_mem_heap_size_t prev_heap_sector_allocated_bytes = ns_monitor_ptr->mem_stats->heap_sector_allocated_bytes;
// Heap usage above HIGH
tr_debug("heap %lu/%lu", (unsigned long)ns_monitor_ptr->mem_stats->heap_sector_allocated_bytes, (unsigned long)ns_monitor_ptr->mem_stats->heap_sector_size);
ns_monitor_heap_gc(false);
ns_monitor_ptr->ns_monitor_heap_gc_state = NS_MONITOR_STATE_HEAP_GC_HIGH;
tr_info("Stack GC high: freed %lu bytes", (unsigned long)(prev_heap_sector_allocated_bytes - ns_monitor_ptr->mem_stats->heap_sector_allocated_bytes));
Expand Down Expand Up @@ -119,7 +121,6 @@ void ns_monitor_timer(uint16_t seconds)

if (ns_monitor_ptr->ns_maintenance_timer >= NS_MAINTENANCE_TIMER_INTERVAL) {
ns_monitor_ptr->ns_maintenance_timer -= NS_MAINTENANCE_TIMER_INTERVAL;
tr_debug("ns_monitor_maintenance_timer(), used %lu/%lu", (unsigned long)ns_monitor_ptr->mem_stats->heap_sector_allocated_bytes, (unsigned long)ns_monitor_ptr->mem_stats->heap_sector_size);
ns_monitor_periodic_heap_health_check();
}
}
Expand All @@ -136,12 +137,12 @@ int ns_monitor_init(void)

if (ns_monitor_ptr) {
ns_monitor_ptr->mem_stats = ns_dyn_mem_get_mem_stat();
ns_monitor_ptr->heap_high_watermark = ns_monitor_ptr->mem_stats->heap_sector_size * HEAP_HIGH_THRESHOLD;
ns_monitor_ptr->heap_critical_watermark = ns_monitor_ptr->mem_stats->heap_sector_size * HEAP_CRITICAL_THRESHOLD;
ns_monitor_ptr->heap_high_watermark = ns_monitor_ptr->mem_stats->heap_sector_size * HEAP_HIGH_WATERWARK;
ns_monitor_ptr->heap_critical_watermark = ns_monitor_ptr->mem_stats->heap_sector_size * HEAP_CRITICAL_WATERMARK;
ns_monitor_ptr->ns_monitor_heap_gc_state = NS_MONITOR_STATE_HEAP_GC_IDLE;
ns_monitor_ptr->ns_maintenance_timer = 0;
ns_monitor_ptr->prev_heap_alloc_fail_cnt = 0;
tr_debug("monitor high %lu, critical %lu", (unsigned long)ns_monitor_ptr->heap_high_watermark, (unsigned long)ns_monitor_ptr->heap_critical_watermark);
tr_debug("Monitor high:%lu, critical:%lu total:%lu", (unsigned long)ns_monitor_ptr->heap_high_watermark, (unsigned long)ns_monitor_ptr->heap_critical_watermark, (unsigned long)ns_monitor_ptr->mem_stats->heap_sector_size);
return 0;
}

Expand All @@ -164,6 +165,7 @@ int ns_monitor_heap_gc_threshold_set(uint8_t percentage_high, uint8_t percentage
if (ns_monitor_ptr && (percentage_critical <= 100) && (percentage_high < percentage_critical)) {
ns_monitor_ptr->heap_high_watermark = ns_monitor_ptr->mem_stats->heap_sector_size * percentage_high / 100;
ns_monitor_ptr->heap_critical_watermark = ns_monitor_ptr->mem_stats->heap_sector_size * percentage_critical / 100;
tr_debug("Monitor high:%lu, critical:%lu total:%lu", (unsigned long)ns_monitor_ptr->heap_high_watermark, (unsigned long)ns_monitor_ptr->heap_critical_watermark, (unsigned long)ns_monitor_ptr->mem_stats->heap_sector_size);
return 0;
}

Expand Down
3 changes: 1 addition & 2 deletions source/NWK_INTERFACE/protocol_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ void protocol_root_tasklet(arm_event_t *event)
switch (event_type) {
case ARM_LIB_TASKLET_INIT_EVENT:
tr_debug("NS Root task Init");
ns_monitor_init();
break;

case ARM_IN_PROTOCOL_TIMER_EVENT: {
Expand Down Expand Up @@ -387,8 +388,6 @@ void protocol_core_init(void)
protocol_core_timer_info.core_security_ticks_counter = SEC_LIB_X_100MS_COUNTER;

protocol_timer_start(PROTOCOL_TIMER_STACK_TIM, protocol_core_cb, 100);
ns_monitor_init();

}

void protocol_core_interface_info_reset(protocol_interface_info_entry_t *entry)
Expand Down

0 comments on commit 01e7d84

Please sign in to comment.