X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvppinfra%2Fmaplog.h;h=ea6a835c7b5bf7a6db7caaa98c35a21e05926af6;hb=494a09a3959f3782a7c7f1fa42b7d16a99c98630;hp=9bc8596de1b80c76aecd714d9de333681dcc25b0;hpb=55c79e9c7e14b501baa72bc8b415e0a66752ed01;p=vpp.git diff --git a/src/vppinfra/maplog.h b/src/vppinfra/maplog.h index 9bc8596de1b..ea6a835c7b5 100644 --- a/src/vppinfra/maplog.h +++ b/src/vppinfra/maplog.h @@ -45,12 +45,12 @@ typedef struct u8 maplog_major_version; /**< library major version number */ u8 maplog_minor_version; /**< library minor version number */ u8 maplog_patch_version; /**< library patch version number */ - u8 pad; + u8 maplog_flag_wrapped; /**< log has wrapped */ u32 application_id; /**< application identifier */ u8 application_major_version; /**< application major version number */ u8 application_minor_version; /**< application minor version number */ u8 application_patch_version; /**< application patch version number */ - u8 pad2; + u8 maplog_flag_circular; /**< log is circular */ u32 record_size_in_cachelines; /**< record size in cache lines */ u32 cacheline_size; /**< cache line size */ u64 file_size_in_records; /**< file size in records */ @@ -60,7 +60,7 @@ typedef struct } clib_maplog_header_t; #define MAPLOG_MAJOR_VERSION 1 -#define MAPLOG_MINOR_VERSION 0 +#define MAPLOG_MINOR_VERSION 1 #define MAPLOG_PATCH_VERSION 0 /** Process-private main data structure */ @@ -90,6 +90,8 @@ typedef struct /* flag bits */ #define CLIB_MAPLOG_FLAG_INIT (1<<0) +#define CLIB_MAPLOG_FLAG_CIRCULAR (1<<1) +#define CLIB_MAPLOG_FLAG_WRAPPED (1<<2) /** log initialization structure */ typedef struct @@ -99,9 +101,10 @@ typedef struct u64 file_size_in_bytes; /**< file size in bytes */ u32 record_size_in_bytes; /**< record size in bytes */ u32 application_id; /**< application identifier */ - u8 application_major_version; /**< applcation major version number */ - u8 application_minor_version; /**< applcation minor version number */ - u8 application_patch_version; /**< applcation patch version number */ + u8 application_major_version; /**< application major version number */ + u8 application_minor_version; /**< application minor version number */ + u8 application_patch_version; /**< application patch version number */ + u8 maplog_is_circular; /**< single, circular log */ } clib_maplog_init_args_t; /* function prototypes */ @@ -134,14 +137,20 @@ clib_maplog_get_entry (clib_maplog_main_t * mm) ASSERT (mm->flags & CLIB_MAPLOG_FLAG_INIT); - my_record_index = __sync_fetch_and_add (&mm->next_record_index, 1); + my_record_index = clib_atomic_fetch_add (&mm->next_record_index, 1); /* Time to unmap and create a new logfile? */ if (PREDICT_FALSE ((my_record_index & (mm->file_size_in_records - 1)) == 0)) { - /* Yes, but not the very first time... (;-)... */ - if (my_record_index) - return _clib_maplog_get_entry_slowpath (mm, my_record_index); + /* Regular log? Switch file... */ + if (!(mm->flags & CLIB_MAPLOG_FLAG_CIRCULAR)) + { + /* Yes, but not the very first time... (;-)... */ + if (my_record_index) + return _clib_maplog_get_entry_slowpath (mm, my_record_index); + } + else /* Circular log: set the wrap bit and move along */ + mm->flags |= CLIB_MAPLOG_FLAG_WRAPPED; /* FALLTHROUGH */ }