Skip to content

Commit 3f702fa

Browse files
committed
[checkpoint] Some updates and python bindings
This version was used for all the IMWUT benchmarks in 2020-08
1 parent 9d0dc0d commit 3f702fa

File tree

3 files changed

+79
-5
lines changed

3 files changed

+79
-5
lines changed

lib/checkpoint/checkpoint.c

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
#define CP_BSS (1)
5555
#define CP_ALLOCATIONS (1)
5656

57-
#define GDB_LOG_CP (1)
57+
#define GDB_LOG_CP (0)
5858

5959

6060
/* Debug options */
@@ -145,6 +145,44 @@ digitalio_digitalinout_obj_t rst_pin_nv;
145145

146146
digitalio_digitalinout_obj_t pfail_pin_nv;
147147

148+
/**
149+
* Benchmark
150+
*/
151+
152+
digitalio_digitalinout_obj_t cpbench_checkpoint_pin;
153+
digitalio_digitalinout_obj_t cpbench_restore_pin;
154+
#define CPBENCH_CHECKPOINT_PINDEF (&pin_PA08) // D4
155+
#define CPBENCH_RESTORE_PINDEF (&pin_PA15) // D5
156+
157+
static inline void cpbench_init(void) {
158+
#if CHECKPOINT_BENCHMARK
159+
cpbench_checkpoint_pin.base.type = &digitalio_digitalinout_type;
160+
common_hal_digitalio_digitalinout_construct(&cpbench_checkpoint_pin, CPBENCH_CHECKPOINT_PINDEF);
161+
common_hal_digitalio_digitalinout_switch_to_output(&cpbench_checkpoint_pin, true, DRIVE_MODE_PUSH_PULL);
162+
common_hal_digitalio_digitalinout_never_reset(&cpbench_checkpoint_pin);
163+
common_hal_digitalio_digitalinout_set_value(&cpbench_checkpoint_pin, false);
164+
165+
cpbench_restore_pin.base.type = &digitalio_digitalinout_type;
166+
common_hal_digitalio_digitalinout_construct(&cpbench_restore_pin, CPBENCH_RESTORE_PINDEF);
167+
common_hal_digitalio_digitalinout_switch_to_output(&cpbench_restore_pin, true, DRIVE_MODE_PUSH_PULL);
168+
common_hal_digitalio_digitalinout_never_reset(&cpbench_restore_pin);
169+
common_hal_digitalio_digitalinout_set_value(&cpbench_restore_pin, false);
170+
#endif
171+
}
172+
173+
static inline void cpbench_checkpoint_pin_set_value(bool value) {
174+
#if CHECKPOINT_BENCHMARK
175+
common_hal_digitalio_digitalinout_set_value(&cpbench_checkpoint_pin, value);
176+
#endif
177+
}
178+
179+
static inline void cpbench_restore_pin_set_value(bool value) {
180+
#if CHECKPOINT_BENCHMARK
181+
common_hal_digitalio_digitalinout_set_value(&cpbench_restore_pin, value);
182+
#endif
183+
}
184+
185+
148186
void nvm_wait_process(void) {
149187
// Wait untill the NVM signals it's ready
150188
while (common_hal_digitalio_digitalinout_get_value(&wr_pin_nv) == false) {
@@ -188,6 +226,9 @@ void nvm_comm_init(void) {
188226
common_hal_digitalio_digitalinout_construct(&pfail_pin_nv, &pin_PA20);
189227
common_hal_digitalio_digitalinout_switch_to_input(&pfail_pin_nv, PULL_NONE);
190228
common_hal_digitalio_digitalinout_never_reset(&pfail_pin_nv);
229+
230+
/* Benchmark pins */
231+
cpbench_init();
191232
}
192233

193234
void nvm_reset(void) {
@@ -427,6 +468,8 @@ __attribute__((noinline))
427468
static int pyrestore_process(void) {
428469
segment_size_t addr_start, addr_end, size;
429470

471+
cpbench_restore_pin_set_value(true);
472+
430473
nvm_write_byte(CPCMND_REQUEST_RESTORE);
431474

432475
bool restore_registers_pending = false;
@@ -561,6 +604,7 @@ void pyrestore(void) {
561604

562605
uint32_t checkpoint_skipped = 0; // skip count
563606
uint32_t checkpoint_performed = 0; // checkpoint count
607+
uint32_t checkpoint_restore_performed = 0; // restore count
564608

565609
static inline void checkpoint_schedule_callback(void);
566610

@@ -597,6 +641,8 @@ int checkpoint(void)
597641
return 0;
598642
}
599643

644+
cpbench_checkpoint_pin_set_value(true);
645+
600646
nvm_write_byte(CPCMND_REQUEST_CHECKPOINT);
601647

602648
resp = nvm_read_byte();
@@ -618,6 +664,8 @@ int checkpoint(void)
618664
if (checkpoint_restored() == 0) {
619665
/* Normal operation */
620666
nvm_write_byte(CPCMND_CONTINUE);
667+
} else {
668+
++checkpoint_restore_performed;
621669
}
622670

623671
/* remove the pending status */
@@ -628,6 +676,14 @@ int checkpoint(void)
628676

629677
checkpoint_performed++;
630678

679+
#if CHECKPOINT_BENCHMARK
680+
if (checkpoint_restored() == 0) {
681+
cpbench_checkpoint_pin_set_value(false);
682+
} else {
683+
cpbench_restore_pin_set_value(false);
684+
}
685+
#endif
686+
631687
return checkpoint_restored();
632688
}
633689
#endif /* CP_CHECKPOINT_DISABLE */
@@ -696,13 +752,13 @@ static void checkpoint_schedule_update_time(const uint64_t period_ms) {
696752

697753
static void checkpoint_schedule_update_trigger(void) {
698754
// If the threshold voltage is reached PFAIL is high
699-
if (common_hal_digitalio_digitalinout_get_value(&pfail_pin_nv) == true) {
755+
if (common_hal_digitalio_digitalinout_get_value(&pfail_pin_nv) == false) {
700756
checkpoint_schedule_update_time(checkpoint_cfg.cps_period_ms);
701757
}
702758
}
703759

704760
static void checkpoint_schedule_update_hybrid(void) {
705-
if (common_hal_digitalio_digitalinout_get_value(&pfail_pin_nv) == true) {
761+
if (common_hal_digitalio_digitalinout_get_value(&pfail_pin_nv) == false) {
706762
checkpoint_schedule_update_time(checkpoint_cfg.cps_period_ms);
707763
} else {
708764
checkpoint_schedule_update_time(checkpoint_cfg.cps_hybrid_period_ms);

lib/checkpoint/checkpoint.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef MICROPY_INCLUDED_LIB_CHECKPOINT_CHECKPOINT_H
22
#define MICROPY_INCLUDED_LIB_CHECKPOINT_CHECKPOINT_H
33

4+
#define CHECKPOINT_BENCHMARK (0)
5+
46
#define CHECKPOINT_SCHEDULE_UPDATE (1)
57
#define CHECKPOINT_PERIOD_MS 200
68
#define CHECKPOINT_HYBRID_PERIOD_MS 1000

shared-bindings/checkpoint/__init__.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,26 @@ STATIC mp_obj_t checkpointruntime_disable(void) {
3636
checkpoint_disable();
3737
return mp_const_none;
3838
}
39-
MP_DEFINE_CONST_FUN_OBJ_0(checkpointruntime_disable_obj, checkpointruntime_disable);
39+
STATIC MP_DEFINE_CONST_FUN_OBJ_0(checkpointruntime_disable_obj, checkpointruntime_disable);
4040

4141
STATIC mp_obj_t checkpointruntime_enable(void) {
4242
checkpoint_enable();
4343
return mp_const_none;
4444
}
45-
MP_DEFINE_CONST_FUN_OBJ_0(checkpointruntime_enable_obj, checkpointruntime_enable);
45+
STATIC MP_DEFINE_CONST_FUN_OBJ_0(checkpointruntime_enable_obj, checkpointruntime_enable);
46+
47+
48+
extern uint32_t checkpoint_performed;
49+
STATIC mp_obj_t checkpointruntime_checkpoint_count(void) {
50+
return mp_obj_new_int(checkpoint_performed);
51+
}
52+
STATIC MP_DEFINE_CONST_FUN_OBJ_0(checkpointruntime_checkpoint_count_obj, checkpointruntime_checkpoint_count);
53+
54+
extern uint32_t checkpoint_restore_performed;
55+
STATIC mp_obj_t checkpointruntime_restore_count(void) {
56+
return mp_obj_new_int(checkpoint_restore_performed);
57+
}
58+
STATIC MP_DEFINE_CONST_FUN_OBJ_0(checkpointruntime_restore_count_obj, checkpointruntime_restore_count);
4659

4760

4861
//
@@ -93,6 +106,9 @@ STATIC const mp_rom_map_elem_t checkpoint_module_globals_table[] = {
93106
{ MP_OBJ_NEW_QSTR(MP_QSTR_disable), MP_ROM_PTR(&checkpointruntime_disable_obj) },
94107
{ MP_OBJ_NEW_QSTR(MP_QSTR_enable), MP_ROM_PTR(&checkpointruntime_enable_obj) },
95108

109+
{ MP_OBJ_NEW_QSTR(MP_QSTR_checkpoint_count), MP_ROM_PTR(&checkpointruntime_checkpoint_count_obj) },
110+
{ MP_OBJ_NEW_QSTR(MP_QSTR_restore_count), MP_ROM_PTR(&checkpointruntime_restore_count_obj) },
111+
96112
{ MP_OBJ_NEW_QSTR(MP_QSTR_set_schedule), MP_ROM_PTR(&checkpointruntime_set_schedule_obj) },
97113
{ MP_OBJ_NEW_QSTR(MP_QSTR_set_period), MP_ROM_PTR(&checkpointruntime_set_period_obj) },
98114
{ MP_OBJ_NEW_QSTR(MP_QSTR_set_hybrid_period), MP_ROM_PTR(&checkpointruntime_set_hybrid_period_obj) },

0 commit comments

Comments
 (0)