Skip to content

Commit 01e7d84

Browse files
author
Arto Kinnunen
committed
Update GC thresholds, init and traces
1 parent 1acd1cc commit 01e7d84

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

source/Core/ns_monitor.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ typedef enum {
4242
NS_MONITOR_STATE_GC_CRITICAL
4343
} ns_monitor_state_e;
4444

45-
#define HEAP_HIGH_THRESHOLD (0.7) /* Heap usage HIGH threshold */
46-
#define HEAP_CRITICAL_THRESHOLD (0.9) /* Heap usage CRITICAL threshold */
45+
#define HEAP_HIGH_WATERWARK (0.80) /* Heap usage HIGH threshold */
46+
#define HEAP_CRITICAL_WATERMARK (0.90) /* Heap usage CRITICAL threshold */
4747

4848
#define NS_MAINTENANCE_TIMER_INTERVAL 10 // Maintenance interval
4949

@@ -81,17 +81,19 @@ static void ns_monitor_heap_gc(bool full_gc)
8181
static void ns_monitor_periodic_heap_health_check(void)
8282
{
8383
if (ns_monitor_ptr->mem_stats->heap_sector_allocated_bytes > ns_monitor_ptr->heap_critical_watermark) {
84+
// Heap usage above CRITICAL
8485
if (ns_monitor_ptr->ns_monitor_heap_gc_state != NS_MONITOR_STATE_GC_CRITICAL) {
8586
ns_mem_heap_size_t prev_heap_sector_allocated_bytes = ns_monitor_ptr->mem_stats->heap_sector_allocated_bytes;
86-
// Heap usage above CRITICAL
87+
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);
8788
ns_monitor_heap_gc(true);
8889
ns_monitor_ptr->ns_monitor_heap_gc_state = NS_MONITOR_STATE_GC_CRITICAL;
8990
tr_info("Stack GC critical: freed %lu bytes", (unsigned long)(prev_heap_sector_allocated_bytes - ns_monitor_ptr->mem_stats->heap_sector_allocated_bytes));
9091
}
9192
} else if (ns_monitor_ptr->mem_stats->heap_sector_allocated_bytes > ns_monitor_ptr->heap_high_watermark) {
93+
// Heap usage above HIGH
9294
if (ns_monitor_ptr->ns_monitor_heap_gc_state == NS_MONITOR_STATE_HEAP_GC_IDLE) {
9395
ns_mem_heap_size_t prev_heap_sector_allocated_bytes = ns_monitor_ptr->mem_stats->heap_sector_allocated_bytes;
94-
// Heap usage above HIGH
96+
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);
9597
ns_monitor_heap_gc(false);
9698
ns_monitor_ptr->ns_monitor_heap_gc_state = NS_MONITOR_STATE_HEAP_GC_HIGH;
9799
tr_info("Stack GC high: freed %lu bytes", (unsigned long)(prev_heap_sector_allocated_bytes - ns_monitor_ptr->mem_stats->heap_sector_allocated_bytes));
@@ -119,7 +121,6 @@ void ns_monitor_timer(uint16_t seconds)
119121

120122
if (ns_monitor_ptr->ns_maintenance_timer >= NS_MAINTENANCE_TIMER_INTERVAL) {
121123
ns_monitor_ptr->ns_maintenance_timer -= NS_MAINTENANCE_TIMER_INTERVAL;
122-
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);
123124
ns_monitor_periodic_heap_health_check();
124125
}
125126
}
@@ -136,12 +137,12 @@ int ns_monitor_init(void)
136137

137138
if (ns_monitor_ptr) {
138139
ns_monitor_ptr->mem_stats = ns_dyn_mem_get_mem_stat();
139-
ns_monitor_ptr->heap_high_watermark = ns_monitor_ptr->mem_stats->heap_sector_size * HEAP_HIGH_THRESHOLD;
140-
ns_monitor_ptr->heap_critical_watermark = ns_monitor_ptr->mem_stats->heap_sector_size * HEAP_CRITICAL_THRESHOLD;
140+
ns_monitor_ptr->heap_high_watermark = ns_monitor_ptr->mem_stats->heap_sector_size * HEAP_HIGH_WATERWARK;
141+
ns_monitor_ptr->heap_critical_watermark = ns_monitor_ptr->mem_stats->heap_sector_size * HEAP_CRITICAL_WATERMARK;
141142
ns_monitor_ptr->ns_monitor_heap_gc_state = NS_MONITOR_STATE_HEAP_GC_IDLE;
142143
ns_monitor_ptr->ns_maintenance_timer = 0;
143144
ns_monitor_ptr->prev_heap_alloc_fail_cnt = 0;
144-
tr_debug("monitor high %lu, critical %lu", (unsigned long)ns_monitor_ptr->heap_high_watermark, (unsigned long)ns_monitor_ptr->heap_critical_watermark);
145+
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);
145146
return 0;
146147
}
147148

@@ -164,6 +165,7 @@ int ns_monitor_heap_gc_threshold_set(uint8_t percentage_high, uint8_t percentage
164165
if (ns_monitor_ptr && (percentage_critical <= 100) && (percentage_high < percentage_critical)) {
165166
ns_monitor_ptr->heap_high_watermark = ns_monitor_ptr->mem_stats->heap_sector_size * percentage_high / 100;
166167
ns_monitor_ptr->heap_critical_watermark = ns_monitor_ptr->mem_stats->heap_sector_size * percentage_critical / 100;
168+
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);
167169
return 0;
168170
}
169171

source/NWK_INTERFACE/protocol_core.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ void protocol_root_tasklet(arm_event_t *event)
176176
switch (event_type) {
177177
case ARM_LIB_TASKLET_INIT_EVENT:
178178
tr_debug("NS Root task Init");
179+
ns_monitor_init();
179180
break;
180181

181182
case ARM_IN_PROTOCOL_TIMER_EVENT: {
@@ -387,8 +388,6 @@ void protocol_core_init(void)
387388
protocol_core_timer_info.core_security_ticks_counter = SEC_LIB_X_100MS_COUNTER;
388389

389390
protocol_timer_start(PROTOCOL_TIMER_STACK_TIM, protocol_core_cb, 100);
390-
ns_monitor_init();
391-
392391
}
393392

394393
void protocol_core_interface_info_reset(protocol_interface_info_entry_t *entry)

0 commit comments

Comments
 (0)