aboutsummaryrefslogtreecommitdiffstats
path: root/src/vppinfra/cuckoo_debug.h
blob: eb236509935c8c92d32d227d480c1e523082f023 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
 * Copyright (c) 2017 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/**
 * @file
 * @brief cuckoo debugs
 */
#ifndef __included_cuckoo_debug_h__
#define __included_cuckoo_debug_h__

/* controls debug counters */
#define CLIB_CUCKOO_DEBUG_COUNTERS (0)

/* controls debug prints */
#define CLIB_CUCKOO_DEBUG (0)

/* controls garbage collection related debug prints */
#define CLIB_CUCKOO_DEBUG_GC (0)

#if CLIB_CUCKOO_DEBUG
#define CLIB_CUCKOO_DEBUG_FILE_DEF    \
  static const char *__file = NULL;   \
  {                                   \
    __file = strrchr (__FILE__, '/'); \
    if (__file)                       \
      {                               \
        ++__file;                     \
      }                               \
    else                              \
      {                               \
        __file = __FILE__;            \
      }                               \
  }

#define CLIB_CUCKOO_DBG(fmt, ...)                                         \
  do                                                                      \
    {                                                                     \
      CLIB_CUCKOO_DEBUG_FILE_DEF                                          \
      static u8 *_s = NULL;                                               \
      _s = format (_s, "DBG:%s:%d:%s():" fmt, __file, __LINE__, __func__, \
                   ##__VA_ARGS__);                                        \
      printf ("%.*s\n", vec_len (_s), _s);                                \
      vec_reset_length (_s);                                              \
    }                                                                     \
  while (0);

#define CLIB_CUCKOO_ERR(fmt, ...)                                         \
  do                                                                      \
    {                                                                     \
      CLIB_CUCKOO_DEBUG_FILE_DEF                                          \
      static u8 *_s = NULL;                                               \
      _s = format (_s, "ERR:%s:%d:%s():" fmt, __file, __LINE__, __func__, \
                   ##__VA_ARGS__);                                        \
      printf ("%.*s\n", vec_len (_s), _s);                                \
      vec_reset_length (_s);                                              \
    }                                                                     \
  while (0);

#else
#define CLIB_CUCKOO_DBG(...)
#define CLIB_CUCKOO_ERR(...)
#endif

#endif /* __included_cuckoo_debug_h__ */

/*
 * fd.io coding-style-patch-verification: ON
 *
 * Local Variables:
 * eval: (c-set-style "gnu")
 * End:
 */
**< library minor version number */ u8 maplog_patch_version; /**< library patch version number */ 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 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 */ u64 number_of_records; /**< number of records in entire log */ u64 number_of_files; /**< number of files in entire log */ u8 file_basename[256]; /**< file basename */ } clib_maplog_header_t; #define MAPLOG_MAJOR_VERSION 1 #define MAPLOG_MINOR_VERSION 1 #define MAPLOG_PATCH_VERSION 0 /** Process-private main data structure */ typedef struct { CLIB_CACHE_LINE_ALIGN_MARK (cacheline1); /** rw cache line: atomic ticket-counter, file index */ volatile u64 next_record_index; /** file size in records, rounded to a power of two */ u64 file_size_in_records; u32 log2_file_size_in_records; /**< lg file size in records */ volatile u32 current_file_index; /**< current file index */ volatile u32 flags; /**< flags, currently just "init" or not */ /* read-mostly cache line: size parameters, file names, etc. */ CLIB_CACHE_LINE_ALIGN_MARK (cacheline2); u32 record_size_in_cachelines; /**< record size in cache lines */ /* double-buffered mmap'ed logfiles */ volatile u8 *file_baseva[2]; /**< active segment base addresses */ u8 *filenames[2]; /**< active segment file names */ /* vector not c-string */ u8 *file_basename; /**< basename, e.g. "/tmp/mylog" */ u8 *header_filename; /**< log header file name */ } clib_maplog_main_t; /* 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 { clib_maplog_main_t *mm; /**< pointer to the main structure */ char *file_basename; /**< file base name */ 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; /**< 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 */ int clib_maplog_init (clib_maplog_init_args_t * ap); void clib_maplog_update_header (clib_maplog_main_t * mm); void clib_maplog_close (clib_maplog_main_t * mm); int clib_maplog_process (char *file_basename, void *fp_arg); format_function_t format_maplog_header; u8 *_clib_maplog_get_entry_slowpath (clib_maplog_main_t * mm, u64 my_record_index); /** * @brief Obtain a log entry pointer * * Increments the atomic ticket counter, and returns a pointer to * the newly-allocated log entry. The slowpath function replaces * a full log segment with a new/fresh/empty log segment * * @param[in] mm maplog object pointer * @return pointer to the allocated log entry */ static inline void * clib_maplog_get_entry (clib_maplog_main_t * mm) { u64 my_record_index; u8 *rv; ASSERT (mm->flags & CLIB_MAPLOG_FLAG_INIT); 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)) { /* 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 */ } rv = (u8 *) mm->file_baseva[(my_record_index >> mm->log2_file_size_in_records) & 1] + (my_record_index & (mm->file_size_in_records - 1)) * mm->record_size_in_cachelines * CLIB_CACHE_LINE_BYTES; return rv; } #endif /* __included_maplog_h__ */ /* * fd.io coding-style-patch-verification: ON * * Local Variables: * eval: (c-set-style "gnu") * End: */