33 u32 record_size_in_cache_lines;
34 u64 file_size_in_records;
47 record_size_in_cache_lines =
82 for (i = 0; i < limit; i++)
88 fd = open ((
char *) mm->
filenames[i], O_CREAT | O_RDWR | O_TRUNC, 0600);
100 if (write (fd, &zero, 1) != 1)
107 PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
135 fd = open ((
char *) mm->
header_filename, O_CREAT | O_RDWR | O_TRUNC, 0600);
142 rv = write (fd, h,
sizeof (*h));
143 if (rv !=
sizeof (*h))
156 for (i = 0; i < limit; i++)
198 (void) munmap ((
u8 *) mm->
file_baseva[unmap_index], file_size_in_bytes);
201 fd = open ((
char *) mm->
filenames[unmap_index],
202 O_CREAT | O_RDWR | O_TRUNC, 0600);
211 if (lseek (fd, file_size_in_bytes - 1, SEEK_SET) == (off_t) - 1)
216 if (write (fd, &zero, 1) != 1)
223 mmap (0, file_size_in_bytes, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
263 rv = read (fd, h,
sizeof (*h));
264 if (rv !=
sizeof (*h))
275 if (lseek (fd, 0, SEEK_SET) < 0)
281 rv = write (fd, h,
sizeof (*h));
282 if (rv !=
sizeof (*h))
302 u64 file_size_in_bytes;
316 for (i = 0; i < limit; i++)
338 int verbose = va_arg (*args,
int);
343 s =
format (s,
"log ver %d.%d.%d app id %u ver %d.%d.%d %s %s\n",
352 s =
format (s,
" records are %d %d-byte cachelines\n",
354 s =
format (s,
" files are %lld records long, %lld files\n",
360 s =
format (s,
"%s %lld records %lld files %lld records/file",
389 u64 file_size_in_bytes;
390 u8 *header_filename, *this_filename = 0;
393 u64 records_this_file, records_left;
398 header_filename =
format (0,
"%s_header%c", file_basename, 0);
400 fd = open ((
char *) header_filename, O_RDONLY, 0600);
407 rv = read (fd, h,
sizeof (*h));
408 if (rv !=
sizeof (*h))
425 this_filename =
format (this_filename,
"%s_%llu%c", file_basename,
427 fd = open ((
char *) this_filename, O_RDONLY, 0600);
435 mmap (0, file_size_in_bytes, PROT_READ, MAP_SHARED, fd, 0);
438 if (file_baseva == (
u8 *) MAP_FAILED)
454 (*fp) (
h, file_baseva, records_this_file);
460 u64 first_chunk_number_of_records = records_this_file -
461 first_chunk_record_index;
462 u8 *chunk_baseva = file_baseva +
465 (*fp) (
h, chunk_baseva, first_chunk_number_of_records);
466 (*fp) (
h, file_baseva,
467 records_this_file - first_chunk_number_of_records);
470 if (munmap (file_baseva, file_size_in_bytes) < 0)
476 records_left -= records_this_file;
477 if (records_left == 0)
u8 application_patch_version
application patch version number
int clib_maplog_init(clib_maplog_init_args_t *a)
Initialize a maplog object.
volatile u64 next_record_index
rw cache line: atomic ticket-counter, file index
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
void clib_maplog_update_header(clib_maplog_main_t *mm)
Update a mapped log header file.
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
#define CLIB_MAPLOG_FLAG_WRAPPED
u64 file_size_in_records
file size in records, rounded to a power of two
volatile u32 current_file_index
current file index
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
u32 record_size_in_cachelines
record size in cache lines
#define CLIB_MAPLOG_FLAG_INIT
description fragment has unexpected format
u32 log2_file_size_in_records
lg file size in records
mmap-based thread-safe fixed-size record double-buffered logging.
u8 * file_basename
basename, e.g.
u8 * format_maplog_header(u8 *s, va_list *args)
format a log header
#define CLIB_MAPLOG_FLAG_CIRCULAR
#define MAPLOG_MAJOR_VERSION
u8 application_minor_version
application minor version number
sll srl srl sll sra u16x4 i
#define vec_free(V)
Free vector's memory (no header).
#define clib_warning(format, args...)
u32 application_id
application identifier
volatile u32 flags
flags, currently just "init" or not
u8 application_major_version
application major version number
volatile u8 * file_baseva[2]
active segment base addresses
#define MAPLOG_MINOR_VERSION
char * file_basename
file base name
u32 record_size_in_bytes
record size in bytes
u8 * header_filename
log header file name
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
static uword max_log2(uword x)
Process-private main data structure.
void clib_maplog_close(clib_maplog_main_t *mm)
Close a mapped log, and update the log header file.
#define clib_unix_warning(format, args...)
u64 file_size_in_bytes
file size in bytes
int clib_maplog_process(char *file_basename, void *fp_arg)
Process a complete maplog.
#define CLIB_CACHE_LINE_BYTES
u8 maplog_is_circular
single, circular log
u8 * filenames[2]
active segment file names
clib_maplog_main_t * mm
pointer to the main structure
log initialization structure
#define MAPLOG_PATCH_VERSION