33 u32 record_size_in_cache_lines;
34 u64 file_size_in_records;
45 memset (mm, 0,
sizeof (*mm));
47 record_size_in_cache_lines =
73 for (i = 0; i < 2; i++)
79 fd = open ((
char *) mm->
filenames[i], O_CREAT | O_RDWR | O_TRUNC, 0600);
91 if (write (fd, &zero, 1) != 1)
98 PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
107 memset (h, 0,
sizeof (*h));
125 fd = open ((
char *) mm->
header_filename, O_CREAT | O_RDWR | O_TRUNC, 0600);
132 rv = write (fd, h,
sizeof (*h));
133 if (rv !=
sizeof (*h))
146 for (i = 0; i < 2; i++)
185 (void) munmap ((
u8 *) mm->
file_baseva[unmap_index], file_size_in_bytes);
188 fd = open ((
char *) mm->
filenames[unmap_index],
189 O_CREAT | O_RDWR | O_TRUNC, 0600);
198 if (lseek (fd, file_size_in_bytes - 1, SEEK_SET) == (off_t) - 1)
203 if (write (fd, &zero, 1) != 1)
210 mmap (0, file_size_in_bytes, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
250 rv = read (fd, h,
sizeof (*h));
251 if (rv !=
sizeof (*h))
261 if (lseek (fd, 0, SEEK_SET) < 0)
267 rv = write (fd, h,
sizeof (*h));
268 if (rv !=
sizeof (*h))
288 u64 file_size_in_bytes;
300 for (i = 0; i < 2; i++)
308 memset (mm, 0,
sizeof (*mm));
322 int verbose = va_arg (*args,
int);
327 s =
format (s,
"log ver %d.%d.%d app id %u ver %d.%d.%d\n",
334 s =
format (s,
" records are %d %d-byte cachelines\n",
336 s =
format (s,
" files are %lld records long, %lld files\n",
342 s =
format (s,
"%s %lld records %lld files %lld records/file",
371 u64 file_size_in_bytes;
372 u8 *header_filename, *this_filename = 0;
375 u64 records_this_file, records_left;
380 header_filename =
format (0,
"%s_header%c", file_basename, 0);
382 fd = open ((
char *) header_filename, O_RDONLY, 0600);
389 rv = read (fd, h,
sizeof (*h));
390 if (rv !=
sizeof (*h))
407 this_filename =
format (this_filename,
"%s_%llu%c", file_basename,
409 fd = open ((
char *) this_filename, O_RDONLY, 0600);
417 mmap (0, file_size_in_bytes, PROT_READ, MAP_SHARED, fd, 0);
420 if (file_baseva == (
u8 *) MAP_FAILED)
430 (*fp) (
h, file_baseva, records_this_file);
432 if (munmap (file_baseva, file_size_in_bytes) < 0)
438 records_left -= records_this_file;
439 if (records_left == 0)
sll srl srl sll sra u16x4 i
u8 application_patch_version
applcation 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
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).
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
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 MAPLOG_MAJOR_VERSION
u8 application_minor_version
applcation minor version number
#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
applcation 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 * filenames[2]
active segment file names
clib_maplog_main_t * mm
pointer to the main structure
log initialization structure
#define MAPLOG_PATCH_VERSION