hce-node application  1.4.3
HCE Hierarchical Cluster Engine node application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
cf_hist.h
Go to the documentation of this file.
1 /*
2  * Citrusleaf Foundation
3  * include/hist.h - timer functionality
4  *
5  * Copyright 2009 by Citrusleaf. All rights reserved.
6  * THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE. THE COPYRIGHT NOTICE
7  * ABOVE DOES NOT EVIDENCE ANY ACTUAL OR INTENDED PUBLICATION.
8  */
9 #pragma once
10 
11 #include <stdint.h>
12 
13 #include "cf_atomic.h"
14 
15 /* SYNOPSIS
16  * For timing things, you want to know this histogram of what took how much time.
17  * So have an interface where you create a histogram object, can dump a histogram object,
18  * and can "start" / "stop" a given timer and add it to the histogram - multithread safe,
19  * of course.
20  */
21 
22 #define CF_N_HIST_COUNTS 64
23 
24 //
25 // The counts are powers of two. count[0]
26 // count[0] is 1024 * 1024 a second
27 // count[13] is about a millisecond (1/1024 second)
28 // count[25] is a second
29 
30 
31 typedef struct cf_histogram_counts_s {
34 
35 typedef struct cf_histogram_s {
36  char name[64];
39 } cf_histogram;
40 
41 extern cf_histogram * cf_histogram_create(char *name);
42 extern void cf_histogram_dump( cf_histogram *h ); // for debugging
44 extern void cf_histogram_insert_data_point(cf_histogram *h, uint64_t start);
45 
46 /* SYNOPSIS
47  * Some bithacks are eternal and handy
48  * http://graphics.stanford.edu/~seander/bithacks.html
49  */
50 
51 #define cf_bits_find_first_set(__x) ffs(__x)
52 #define cf_bits_find_first_set_64(__x) ffsll(__x)
53 
54 extern int cf_bits_find_last_set(uint32_t c);
55 extern int cf_bits_find_last_set_64(uint64_t c);
56 
57 static const char cf_LogTable256[] =
58 {
59 #define CF_LT(n) n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n
60  -1, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3,
61  CF_LT(4), CF_LT(5), CF_LT(5), CF_LT(6), CF_LT(6), CF_LT(6), CF_LT(6),
62  CF_LT(7), CF_LT(7), CF_LT(7), CF_LT(7), CF_LT(7), CF_LT(7), CF_LT(7), CF_LT(7)
63 };
64 
65 // round a value up to the nearest MODULUS
66 
67 static inline uint32_t cf_roundup( uint32_t i, uint32_t modulus) {
68  uint32_t t = i % modulus;
69  if (t == 0) return(i);
70  return( i + (modulus - t ) );
71 }
72 
73 static inline uint64_t cf_roundup_64( uint64_t i, uint32_t modulus) {
74  uint64_t t = i % modulus;
75  if (t == 0) return(i);
76  return( i + (modulus - t ) );
77 }
78