Skip to content

Commit eae68db

Browse files
committed
sys/log: Add FCB 2 bookmarks per sector to improve reading
- Add sector bookmarks for FCB2 reading optimization - Retain older absolute bookmarks behavior
1 parent 165790f commit eae68db

File tree

7 files changed

+78
-9
lines changed

7 files changed

+78
-9
lines changed

fs/fcb2/include/fcb/fcb2.h

+24
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,19 @@ int fcb2_walk(struct fcb2 *fcb, int sector, fcb2_walk_cb cb, void *cb_arg);
196196
*/
197197
int fcb2_getnext(struct fcb2 *fcb, struct fcb2_entry *loc);
198198

199+
/**
200+
* Get first entry in the provided flash area
201+
*
202+
* @param fcb Pointer to FCB
203+
* @param range Optional range in flash sector
204+
* @param loc Pointer to first FCB entry in the provided flash area
205+
*
206+
* @return 0 on success, non-zero on failure
207+
*/
208+
int
209+
fcb2_getnext_in_area(struct fcb2 *fcb, struct flash_sector_range *range,
210+
struct fcb2_entry *loc);
211+
199212
/**
200213
* Walk through entries within FCB from newest to oldest.
201214
* fcb_getprev() finds the previous valid entry backwards from loc, and fills in
@@ -304,6 +317,17 @@ int fcb2_clear(struct fcb2 *fcb);
304317
*/
305318
int fcb2_area_info(struct fcb2 *fcb, int sector, int *elemsp, int *bytesp);
306319

320+
/**
321+
* Returns the next sector flash range, given current entry
322+
*
323+
* @param fcb Pointer to the FCB
324+
* @param loc Pointer to the location
325+
*
326+
* @return Flash sector range of the next sector
327+
*/
328+
struct flash_sector_range *
329+
fcb2_getnext_range(struct fcb2 *fcb, struct fcb2_entry *loc);
330+
307331
#ifdef __cplusplus
308332
}
309333

fs/fcb2/src/fcb.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ fcb2_init(struct fcb2 *fcb)
8888
fcb->f_active_id = newest;
8989

9090
while (1) {
91-
rc = fcb2_getnext_in_area(fcb, &fcb->f_active);
91+
rc = fcb2_getnext_in_area(fcb, NULL, &fcb->f_active);
9292
if (rc == FCB2_ERR_NOVAR) {
9393
rc = FCB2_OK;
9494
break;

fs/fcb2/src/fcb_getnext.c

+24-3
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,23 @@
2222
#include "fcb_priv.h"
2323

2424
int
25-
fcb2_getnext_in_area(struct fcb2 *fcb, struct fcb2_entry *loc)
25+
fcb2_getnext_in_area(struct fcb2 *fcb, struct flash_sector_range *range,
26+
struct fcb2_entry *loc)
2627
{
2728
int rc = FCB2_ERR_CRC;
2829
int len;
2930
int next_data_offset;
3031
int next_entry_offset;
3132

33+
/* If a flash range is specified, find first entry in that area */
34+
if (range) {
35+
loc->fe_range = range;
36+
loc->fe_data_off = fcb2_len_in_flash(range, sizeof(struct fcb2_disk_area));
37+
loc->fe_entry_num = 0;
38+
loc->fe_data_len = 0;
39+
loc->fe_sector = 0;
40+
}
41+
3242
while (rc == FCB2_ERR_CRC) {
3343
len = loc->fe_data_len;
3444
/* Next data offset in sector */
@@ -52,6 +62,17 @@ fcb2_getnext_in_area(struct fcb2 *fcb, struct fcb2_entry *loc)
5262
return rc;
5363
}
5464

65+
struct flash_sector_range *
66+
fcb2_getnext_range(struct fcb2 *fcb, struct fcb2_entry *loc)
67+
{
68+
loc->fe_entry_num = 0;
69+
loc->fe_data_len = 0;
70+
loc->fe_sector = fcb2_getnext_sector(fcb, loc->fe_sector);
71+
loc->fe_range = fcb2_get_sector_range(fcb, loc->fe_sector);
72+
73+
return loc->fe_range;
74+
}
75+
5576
int
5677
fcb2_getnext_nolock(struct fcb2 *fcb, struct fcb2_entry *loc)
5778
{
@@ -71,7 +92,7 @@ fcb2_getnext_nolock(struct fcb2 *fcb, struct fcb2_entry *loc)
7192
loc->fe_entry_num = 1;
7293
rc = fcb2_elem_info(loc);
7394
} else {
74-
rc = fcb2_getnext_in_area(fcb, loc);
95+
rc = fcb2_getnext_in_area(fcb, NULL, loc);
7596
}
7697
switch (rc) {
7798
case 0:
@@ -82,7 +103,7 @@ fcb2_getnext_nolock(struct fcb2 *fcb, struct fcb2_entry *loc)
82103
goto next_sector;
83104
}
84105
while (rc == FCB2_ERR_CRC) {
85-
rc = fcb2_getnext_in_area(fcb, loc);
106+
rc = fcb2_getnext_in_area(fcb, NULL, loc);
86107
if (rc == 0) {
87108
return 0;
88109
}

fs/fcb2/src/fcb_priv.h

-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ fcb2_len_in_flash(const struct flash_sector_range *range, uint16_t len)
4949
return (len + (range->fsr_align - 1)) & ~(range->fsr_align - 1);
5050
}
5151

52-
int fcb2_getnext_in_area(struct fcb2 *fcb, struct fcb2_entry *loc);
53-
5452
static inline int
5553
fcb2_getnext_sector(struct fcb2 *fcb, int sector)
5654
{

sys/log/full/src/log_fcb2.c

+13-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ log_fcb2_start_append(struct log *log, int len, struct fcb2_entry *loc)
173173
}
174174
#endif
175175

176-
#if MYNEWT_VAL(LOG_FCB_BOOKMARKS)
176+
#if MYNEWT_VAL(LOG_FCB_BOOKMARKS) && !MYNEWT_VAL(LOG_FCB_SECTOR_BOOKMARKS)
177177
/* The FCB needs to be rotated. */
178178
log_fcb_rotate_bmarks(fcb_log);
179179
#endif
@@ -183,6 +183,18 @@ log_fcb2_start_append(struct log *log, int len, struct fcb2_entry *loc)
183183
goto err;
184184
}
185185

186+
#if MYNEWT_VAL(LOG_FCB_SECTOR_BOOKMARKS)
187+
/* The FCB needs to be rotated, reinit previously allocated
188+
* bookmarks
189+
*/
190+
rc = log_fcb_init_bmarks(fcb_log, fcb_log->fl_bset.lfs_bmarks,
191+
fcb_log->fl_bset.lfs_cap,
192+
fcb_log->fl_bset.lfs_en_sect_bmarks);
193+
if (rc) {
194+
goto err;
195+
}
196+
#endif
197+
186198
#if MYNEWT_VAL(LOG_STORAGE_WATERMARK)
187199
/*
188200
* FCB was rotated successfully so let's check if watermark was within

sys/log/full/src/log_fcb_bmark.c

+13-2
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,11 @@ log_fcb_closest_bmark(const struct fcb_log *fcb_log, uint32_t index,
249249
fcb_log->fl_bset.lfs_next_sect < (fcb_log->fl_bset.lfs_sect_cap - 1)) {
250250
start_idx = fcb_log->fl_bset.lfs_next_sect + 1;
251251
}
252+
#elif MYNEWT_VAL(LOG_FCB2)
253+
if (!fcb_log->fl_bset.lfs_bmarks[i].lfb_entry.fe_range &&
254+
fcb_log->fl_bset.lfs_next_sect < (fcb_log->fl_bset.lfs_sect_cap - 1)) {
255+
start_idx = fcb_log->fl_bset.lfs_next_sect + 1;
256+
}
252257
#endif
253258
#endif
254259

@@ -298,9 +303,15 @@ log_fcb_closest_bmark(const struct fcb_log *fcb_log, uint32_t index,
298303
}
299304

300305
#if MYNEWT_VAL(LOG_FCB_SECTOR_BOOKMARKS)
306+
#if MYNEWT_VAL(LOG_FCB)
301307
static int
302308
log_fcb_insert_sect_bmark(struct fcb_log *fcb_log, struct fcb_entry *entry,
303309
uint32_t index)
310+
#elif MYNEWT_VAL(LOG_FCB2)
311+
static int
312+
log_fcb_insert_sect_bmark(struct fcb_log *fcb_log, struct fcb2_entry *entry,
313+
uint32_t index)
314+
#endif
304315
{
305316
struct log_fcb_bset *bset;
306317

@@ -336,7 +347,7 @@ log_fcb_replace_non_sect_bmark(struct fcb_log *fcb_log, struct fcb2_entry *entry
336347
int i = 0;
337348
struct log_fcb_bset *bset = &fcb_log->fl_bset;
338349

339-
#if MYNEWT_VAL(LOG_FCB) && MYNEWT_VAL(LOG_FCB_SECTOR_BOOKMARKS)
350+
#if MYNEWT_VAL(LOG_FCB_SECTOR_BOOKMARKS)
340351
if (bset->lfs_en_sect_bmarks) {
341352
for (i = bset->lfs_sect_cap;
342353
i < (bset->lfs_non_sect_size + bset->lfs_sect_cap);
@@ -382,7 +393,7 @@ log_fcb_add_bmark(struct fcb_log *fcb_log, struct fcb2_entry *entry,
382393
return SYS_ENOMEM;
383394
}
384395

385-
#if MYNEWT_VAL(LOG_FCB) && MYNEWT_VAL(LOG_FCB_SECTOR_BOOKMARKS)
396+
#if MYNEWT_VAL(LOG_FCB_SECTOR_BOOKMARKS)
386397
if (sect_bmark & bset->lfs_en_sect_bmarks) {
387398
rc = log_fcb_insert_sect_bmark(fcb_log, entry, index);
388399
if (rc) {

sys/log/full/syscfg.yml

+3
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,10 @@ syscfg.defs:
190190
value: 0
191191
restrictions:
192192
- LOG_FCB_BOOKMARKS
193+
<<<<<<< HEAD
193194
- LOG_FCB
195+
=======
196+
>>>>>>> 473c66d51 (sys/log: Add FCB 2 bookmarks per sector to improve reading)
194197

195198
syscfg.vals.CONSOLE_TICKS:
196199
LOG_CONSOLE_PRETTY_WITH_TIMESTAMP: 0

0 commit comments

Comments
 (0)