diff --git a/admin/wireshark-dissectors/peers/packet-happp.c b/admin/wireshark-dissectors/peers/packet-happp.c index 43babd214..581262f79 100644 --- a/admin/wireshark-dissectors/peers/packet-happp.c +++ b/admin/wireshark-dissectors/peers/packet-happp.c @@ -214,7 +214,7 @@ enum { STD_T_SINT = 0, /* signed int */ STD_T_UINT, /* unsigned int */ STD_T_ULL, /* unsigned long long */ - STD_T_FRQP, /* freq_ctr_period structure made of three unsigned int */ + STD_T_FRQP, /* freq_ctr structure made of three unsigned int */ }; /* Prototypes */ diff --git a/include/haproxy/activity-t.h b/include/haproxy/activity-t.h index 328bde8bd..c1c16aaf8 100644 --- a/include/haproxy/activity-t.h +++ b/include/haproxy/activity-t.h @@ -57,7 +57,7 @@ struct activity { ALWAYS_ALIGN(64); struct freq_ctr cpust_1s; // avg amount of half-ms stolen over last second - struct freq_ctr_period cpust_15s; // avg amount of half-ms stolen over last 15s + struct freq_ctr cpust_15s; // avg amount of half-ms stolen over last 15s unsigned int avg_loop_us; // average run time per loop over last 1024 runs unsigned int accepted; // accepted incoming connections unsigned int accq_pushed; // accept queue connections pushed diff --git a/include/haproxy/applet.h b/include/haproxy/applet.h index 2c8293a9f..48b516688 100644 --- a/include/haproxy/applet.h +++ b/include/haproxy/applet.h @@ -48,7 +48,7 @@ static inline void appctx_init(struct appctx *appctx, unsigned long thread_mask) appctx->chunk = NULL; appctx->io_release = NULL; appctx->thread_mask = thread_mask; - appctx->call_rate.curr_sec = 0; + appctx->call_rate.curr_tick = 0; appctx->call_rate.curr_ctr = 0; appctx->call_rate.prev_ctr = 0; appctx->state = 0; diff --git a/include/haproxy/freq_ctr-t.h b/include/haproxy/freq_ctr-t.h index f99365367..d5f1a8912 100644 --- a/include/haproxy/freq_ctr-t.h +++ b/include/haproxy/freq_ctr-t.h @@ -24,27 +24,17 @@ #include -/* The implicit freq_ctr counter counts a rate of events per second. It is the - * preferred form to count rates over a one-second period, because it does not - * involve any divide. +/* The generic freq_ctr counter counts a rate of events per period, where the + * period has to be known by the user. The period is measured in ticks and + * must be at least 2 ticks long. This form is slightly more CPU intensive for + * reads than the per-second form as it involves a divide. */ struct freq_ctr { - unsigned int curr_sec; /* start date of current period (seconds from now.tv_sec) */ + unsigned int curr_tick; /* start date of current period (wrapping ticks) */ unsigned int curr_ctr; /* cumulated value for current period */ unsigned int prev_ctr; /* value for last period */ }; -/* The generic freq_ctr_period counter counts a rate of events per period, where - * the period has to be known by the user. The period is measured in ticks and - * must be at least 2 ticks long. This form is slightly more CPU intensive than - * the per-second form. - */ -struct freq_ctr_period { - unsigned int curr_tick; /* start date of current period (wrapping ticks) */ - unsigned int curr_ctr; /* cumulated value for current period */ - unsigned int prev_ctr; /* value for last period */ -}; - #endif /* _HAPROXY_FREQ_CTR_T_H */ /* diff --git a/include/haproxy/freq_ctr.h b/include/haproxy/freq_ctr.h index c0a954f6d..de845d6cc 100644 --- a/include/haproxy/freq_ctr.h +++ b/include/haproxy/freq_ctr.h @@ -28,7 +28,7 @@ #include /* exported functions from freq_ctr.c */ -ullong freq_ctr_total(struct freq_ctr_period *ctr, uint period, int pend); +ullong freq_ctr_total(struct freq_ctr *ctr, uint period, int pend); /* Update a frequency counter by incremental units. It is automatically * rotated if the period is over. It is important that it correctly initializes @@ -49,7 +49,7 @@ static inline unsigned int update_freq_ctr(struct freq_ctr *ctr, unsigned int in * we operate, since timing variations would have resulted in the * same uncertainty as well. */ - curr_sec = ctr->curr_sec; + curr_sec = ctr->curr_tick; do { now_tmp = global_now >> 32; if (curr_sec == (now_tmp & 0x7fffffff)) @@ -57,7 +57,7 @@ static inline unsigned int update_freq_ctr(struct freq_ctr *ctr, unsigned int in /* remove the bit, used for the lock */ curr_sec &= 0x7fffffff; - } while (!_HA_ATOMIC_CAS(&ctr->curr_sec, &curr_sec, curr_sec | 0x80000000)); + } while (!_HA_ATOMIC_CAS(&ctr->curr_tick, &curr_sec, curr_sec | 0x80000000)); __ha_barrier_atomic_store(); elapsed = (now_tmp & 0x7fffffff) - curr_sec; @@ -72,7 +72,7 @@ static inline unsigned int update_freq_ctr(struct freq_ctr *ctr, unsigned int in } /* release the lock and update the time in case of rotate. */ - _HA_ATOMIC_STORE(&ctr->curr_sec, curr_sec & 0x7fffffff); + _HA_ATOMIC_STORE(&ctr->curr_tick, curr_sec & 0x7fffffff); return _HA_ATOMIC_ADD_FETCH(&ctr->curr_ctr, inc); } @@ -82,7 +82,7 @@ static inline unsigned int update_freq_ctr(struct freq_ctr *ctr, unsigned int in * a null area. This one works on frequency counters which have a period * different from one second. */ -static inline unsigned int update_freq_ctr_period(struct freq_ctr_period *ctr, +static inline unsigned int update_freq_ctr_period(struct freq_ctr *ctr, unsigned int period, unsigned int inc) { unsigned int curr_tick; @@ -135,7 +135,7 @@ unsigned int read_freq_ctr(struct freq_ctr *ctr); * instead which does not have the flapping correction, so that even frequencies * as low as one event/period are properly handled. */ -static inline uint read_freq_ctr_period(struct freq_ctr_period *ctr, uint period) +static inline uint read_freq_ctr_period(struct freq_ctr *ctr, uint period) { ullong total = freq_ctr_total(ctr, period, -1); @@ -152,7 +152,7 @@ unsigned int freq_ctr_remain(struct freq_ctr *ctr, unsigned int freq, unsigned i * while respecting events per period, and taking into account that * events are already known to be pending. Returns 0 if limit was reached. */ -static inline uint freq_ctr_remain_period(struct freq_ctr_period *ctr, uint period, uint freq, uint pend) +static inline uint freq_ctr_remain_period(struct freq_ctr *ctr, uint period, uint freq, uint pend) { ullong total = freq_ctr_total(ctr, period, pend); uint avg = div64_32(total, period); @@ -176,7 +176,7 @@ unsigned int next_event_delay(struct freq_ctr *ctr, unsigned int freq, unsigned * time, which will be rounded down 1ms for better accuracy, with a minimum * of one ms. */ -static inline uint next_event_delay_period(struct freq_ctr_period *ctr, uint period, uint freq, uint pend) +static inline uint next_event_delay_period(struct freq_ctr *ctr, uint period, uint freq, uint pend) { ullong total = freq_ctr_total(ctr, period, pend); ullong limit = (ullong)freq * period; @@ -196,7 +196,7 @@ static inline uint next_event_delay_period(struct freq_ctr_period *ctr, uint per } /* process freq counters over configurable periods */ -unsigned int read_freq_ctr_period(struct freq_ctr_period *ctr, unsigned int period); +unsigned int read_freq_ctr_period(struct freq_ctr *ctr, unsigned int period); /* While the functions above report average event counts per period, we are * also interested in average values per event. For this we use a different diff --git a/include/haproxy/stick_table-t.h b/include/haproxy/stick_table-t.h index a3f35dc45..bae32d910 100644 --- a/include/haproxy/stick_table-t.h +++ b/include/haproxy/stick_table-t.h @@ -72,7 +72,7 @@ enum { STD_T_SINT = 0, /* data is of type signed int */ STD_T_UINT, /* data is of type unsigned int */ STD_T_ULL, /* data is of type unsigned long long */ - STD_T_FRQP, /* data is of type freq_ctr_period */ + STD_T_FRQP, /* data is of type freq_ctr */ STD_T_DICT, /* data is of type key of dictionary entry */ }; @@ -116,7 +116,7 @@ union stktable_data { int std_t_sint; unsigned int std_t_uint; unsigned long long std_t_ull; - struct freq_ctr_period std_t_frqp; + struct freq_ctr std_t_frqp; struct dict_entry *std_t_dict; /* types of each storable data */ @@ -124,24 +124,24 @@ union stktable_data { struct dict_entry *server_key; unsigned int gpt0; unsigned int gpc0; - struct freq_ctr_period gpc0_rate; + struct freq_ctr gpc0_rate; unsigned int gpc1; - struct freq_ctr_period gpc1_rate; + struct freq_ctr gpc1_rate; unsigned int conn_cnt; - struct freq_ctr_period conn_rate; + struct freq_ctr conn_rate; unsigned int conn_cur; unsigned int sess_cnt; - struct freq_ctr_period sess_rate; + struct freq_ctr sess_rate; unsigned int http_req_cnt; - struct freq_ctr_period http_req_rate; + struct freq_ctr http_req_rate; unsigned int http_err_cnt; - struct freq_ctr_period http_err_rate; + struct freq_ctr http_err_rate; unsigned long long bytes_in_cnt; - struct freq_ctr_period bytes_in_rate; + struct freq_ctr bytes_in_rate; unsigned long long bytes_out_cnt; - struct freq_ctr_period bytes_out_rate; + struct freq_ctr bytes_out_rate; unsigned int http_fail_cnt; - struct freq_ctr_period http_fail_rate; + struct freq_ctr http_fail_rate; }; /* known data types */ diff --git a/include/haproxy/stick_table.h b/include/haproxy/stick_table.h index abaf3e979..401b89e8f 100644 --- a/include/haproxy/stick_table.h +++ b/include/haproxy/stick_table.h @@ -79,7 +79,7 @@ static inline int stktable_type_size(int type) case STD_T_ULL: return sizeof(unsigned long long); case STD_T_FRQP: - return sizeof(struct freq_ctr_period); + return sizeof(struct freq_ctr); case STD_T_DICT: return sizeof(struct dict_entry *); } diff --git a/src/freq_ctr.c b/src/freq_ctr.c index d68a7841d..3d1416392 100644 --- a/src/freq_ctr.c +++ b/src/freq_ctr.c @@ -37,7 +37,7 @@ unsigned int read_freq_ctr(struct freq_ctr *ctr) __ha_compiler_barrier(); _past = ctr->prev_ctr; __ha_compiler_barrier(); - _curr_sec = ctr->curr_sec; + _curr_sec = ctr->curr_tick; __ha_compiler_barrier(); if (_curr_sec & 0x80000000) continue; @@ -45,7 +45,7 @@ unsigned int read_freq_ctr(struct freq_ctr *ctr) __ha_compiler_barrier(); past = ctr->prev_ctr; __ha_compiler_barrier(); - curr_sec = ctr->curr_sec; + curr_sec = ctr->curr_tick; __ha_compiler_barrier(); if (_curr == curr && _past == past && _curr_sec == curr_sec) break; @@ -80,7 +80,7 @@ unsigned int freq_ctr_remain(struct freq_ctr *ctr, unsigned int freq, unsigned i __ha_compiler_barrier(); _past = ctr->prev_ctr; __ha_compiler_barrier(); - _curr_sec = ctr->curr_sec; + _curr_sec = ctr->curr_tick; __ha_compiler_barrier(); if (_curr_sec & 0x80000000) continue; @@ -88,7 +88,7 @@ unsigned int freq_ctr_remain(struct freq_ctr *ctr, unsigned int freq, unsigned i __ha_compiler_barrier(); past = ctr->prev_ctr; __ha_compiler_barrier(); - curr_sec = ctr->curr_sec; + curr_sec = ctr->curr_tick; __ha_compiler_barrier(); if (_curr == curr && _past == past && _curr_sec == curr_sec) break; @@ -127,7 +127,7 @@ unsigned int next_event_delay(struct freq_ctr *ctr, unsigned int freq, unsigned __ha_compiler_barrier(); _past = ctr->prev_ctr; __ha_compiler_barrier(); - _curr_sec = ctr->curr_sec; + _curr_sec = ctr->curr_tick; __ha_compiler_barrier(); if (_curr_sec & 0x80000000) continue; @@ -135,7 +135,7 @@ unsigned int next_event_delay(struct freq_ctr *ctr, unsigned int freq, unsigned __ha_compiler_barrier(); past = ctr->prev_ctr; __ha_compiler_barrier(); - curr_sec = ctr->curr_sec; + curr_sec = ctr->curr_tick; __ha_compiler_barrier(); if (_curr == curr && _past == past && _curr_sec == curr_sec) break; @@ -176,7 +176,7 @@ unsigned int next_event_delay(struct freq_ctr *ctr, unsigned int freq, unsigned * read_freq_ctr_period() to avoid reporting ups and downs on low-frequency * events when the past value is <= 1. */ -ullong freq_ctr_total(struct freq_ctr_period *ctr, uint period, int pend) +ullong freq_ctr_total(struct freq_ctr *ctr, uint period, int pend) { ullong curr, past; uint curr_tick; diff --git a/src/peers.c b/src/peers.c index dd3d9dd63..2ebb107df 100644 --- a/src/peers.c +++ b/src/peers.c @@ -713,7 +713,7 @@ static int peer_prepare_updatemsg(char *msg, size_t size, struct peer_prep_param break; } case STD_T_FRQP: { - struct freq_ctr_period *frqp; + struct freq_ctr *frqp; frqp = &stktable_data_cast(data_ptr, std_t_frqp); intencode((unsigned int)(now_ms - frqp->curr_tick), &cursor); @@ -1667,11 +1667,11 @@ static int peer_treat_updatemsg(struct appctx *appctx, struct peer *p, int updt, break; case STD_T_FRQP: { - struct freq_ctr_period data; + struct freq_ctr data; - /* First bit is reserved for the freq_ctr_period lock + /* First bit is reserved for the freq_ctr lock Note: here we're still protected by the stksess lock - so we don't need to update the update the freq_ctr_period + so we don't need to update the update the freq_ctr using its internal lock */ data.curr_tick = tick_add(now_ms, -decoded_int) & ~0x1; diff --git a/src/stick_table.c b/src/stick_table.c index e305a44b7..1fe60a00c 100644 --- a/src/stick_table.c +++ b/src/stick_table.c @@ -3627,7 +3627,7 @@ static int table_process_entry_per_key(struct appctx *appctx, char **args) int data_type; int cur_arg; void *ptr; - struct freq_ctr_period *frqp; + struct freq_ctr *frqp; if (!*args[4]) return cli_err(appctx, "Key value expected\n"); @@ -3764,9 +3764,9 @@ static int table_process_entry_per_key(struct appctx *appctx, char **args) * push measures without having to update them too often. */ frqp = &stktable_data_cast(ptr, std_t_frqp); - /* First bit is reserved for the freq_ctr_period lock + /* First bit is reserved for the freq_ctr lock Note: here we're still protected by the stksess lock - so we don't need to update the update the freq_ctr_period + so we don't need to update the update the freq_ctr using its internal lock */ frqp->curr_tick = now_ms & ~0x1; frqp->prev_ctr = 0; diff --git a/src/stream.c b/src/stream.c index bdc974ccc..6c60cd495 100644 --- a/src/stream.c +++ b/src/stream.c @@ -424,7 +424,7 @@ struct stream *stream_new(struct session *sess, enum obj_type *origin, struct bu s->buffer_wait.target = s; s->buffer_wait.wakeup_cb = stream_buf_available; - s->call_rate.curr_sec = s->call_rate.curr_ctr = s->call_rate.prev_ctr = 0; + s->call_rate.curr_tick = s->call_rate.curr_ctr = s->call_rate.prev_ctr = 0; s->pcli_next_pid = 0; s->pcli_flags = 0; s->unique_id = IST_NULL;