diff options
author | Costa Tsaousis <costa@netdata.cloud> | 2022-05-24 08:20:40 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-24 08:20:40 +0300 |
commit | 080e0aee277ee636d98df536b00e98bae46cdf37 (patch) | |
tree | 00d2546a184533f42c87866f4fd9570ef9530796 /libnetdata | |
parent | d34a3d068ba51e35470ca9367e6d09441a0ea593 (diff) |
Faster queries (#12988)
* faster rrdeng_load_metric_next()
* no need to check validity for number - already done at the query side
* solve discrepancy between query create and free
* inline unpack_storage_number
Diffstat (limited to 'libnetdata')
-rw-r--r-- | libnetdata/storage_number/storage_number.c | 44 | ||||
-rw-r--r-- | libnetdata/storage_number/storage_number.h | 39 |
2 files changed, 43 insertions, 40 deletions
diff --git a/libnetdata/storage_number/storage_number.c b/libnetdata/storage_number/storage_number.c index ce99007cff..ba7a668745 100644 --- a/libnetdata/storage_number/storage_number.c +++ b/libnetdata/storage_number/storage_number.c @@ -92,56 +92,22 @@ RET_SN: } // Lookup table to make storage number unpacking efficient. -static calculated_number lut10x[4 * 8]; +calculated_number unpack_storage_number_lut10x[4 * 8]; __attribute__((constructor)) void initialize_lut(void) { // The lookup table is partitioned in 4 subtables based on the // values of the factor and exp bits. for (int i = 0; i < 8; i++) { // factor = 0 - lut10x[0 * 8 + i] = 1 / pow(10, i); // exp = 0 - lut10x[1 * 8 + i] = pow(10, i); // exp = 1 + unpack_storage_number_lut10x[0 * 8 + i] = 1 / pow(10, i); // exp = 0 + unpack_storage_number_lut10x[1 * 8 + i] = pow(10, i); // exp = 1 // factor = 1 - lut10x[2 * 8 + i] = 1 / pow(100, i); // exp = 0 - lut10x[3 * 8 + i] = pow(100, i); // exp = 1 + unpack_storage_number_lut10x[2 * 8 + i] = 1 / pow(100, i); // exp = 0 + unpack_storage_number_lut10x[3 * 8 + i] = pow(100, i); // exp = 1 } } -calculated_number unpack_storage_number(storage_number value) { - if(!value) return 0; - - int sign = 1, exp = 0; - int factor = 0; - - // bit 32 = 0:positive, 1:negative - if(unlikely(value & (1 << 31))) - sign = -1; - - // bit 31 = 0:divide, 1:multiply - if(unlikely(value & (1 << 30))) - exp = 1; - - // bit 27 SN_EXISTS_100 - if(unlikely(value & (1 << 26))) - factor = 1; - - // bit 26 SN_EXISTS_RESET - // bit 25 SN_ANOMALY_BIT - - // bit 30, 29, 28 = (multiplier or divider) 0-7 (8 total) - int mul = (value & ((1<<29)|(1<<28)|(1<<27))) >> 27; - - // bit 24 to bit 1 = the value, so remove all other bits - value ^= value & ((1<<31)|(1<<30)|(1<<29)|(1<<28)|(1<<27)|(1<<26)|(1<<25)|(1<<24)); - - calculated_number n = value; - - // fprintf(stderr, "UNPACK: %08X, sign = %d, exp = %d, mul = %d, factor = %d, n = " CALCULATED_NUMBER_FORMAT "\n", value, sign, exp, mul, factor, n); - - return sign * lut10x[(factor * 16) + (exp * 8) + mul] * n; -} - /* int print_calculated_number(char *str, calculated_number value) { diff --git a/libnetdata/storage_number/storage_number.h b/libnetdata/storage_number/storage_number.h index 4101f69e01..7e7b511b0c 100644 --- a/libnetdata/storage_number/storage_number.h +++ b/libnetdata/storage_number/storage_number.h @@ -80,7 +80,7 @@ typedef uint32_t storage_number; #define did_storage_number_reset(value) ((((storage_number) (value)) & SN_EXISTS_RESET) != 0) storage_number pack_storage_number(calculated_number value, uint32_t flags); -calculated_number unpack_storage_number(storage_number value); +static inline calculated_number unpack_storage_number(storage_number value) __attribute__((const)); int print_calculated_number(char *str, calculated_number value); @@ -98,4 +98,41 @@ int print_calculated_number(char *str, calculated_number value); // period of at least every other 10 samples. #define MAX_INCREMENTAL_PERCENT_RATE 10 + +static inline calculated_number unpack_storage_number(storage_number value) { + extern calculated_number unpack_storage_number_lut10x[4 * 8]; + + if(!value) return 0; + + int sign = 1, exp = 0; + int factor = 0; + + // bit 32 = 0:positive, 1:negative + if(unlikely(value & (1 << 31))) + sign = -1; + + // bit 31 = 0:divide, 1:multiply + if(unlikely(value & (1 << 30))) + exp = 1; + + // bit 27 SN_EXISTS_100 + if(unlikely(value & (1 << 26))) + factor = 1; + + // bit 26 SN_EXISTS_RESET + // bit 25 SN_ANOMALY_BIT + + // bit 30, 29, 28 = (multiplier or divider) 0-7 (8 total) + int mul = (value & ((1<<29)|(1<<28)|(1<<27))) >> 27; + + // bit 24 to bit 1 = the value, so remove all other bits + value ^= value & ((1<<31)|(1<<30)|(1<<29)|(1<<28)|(1<<27)|(1<<26)|(1<<25)|(1<<24)); + + calculated_number n = value; + + // fprintf(stderr, "UNPACK: %08X, sign = %d, exp = %d, mul = %d, factor = %d, n = " CALCULATED_NUMBER_FORMAT "\n", value, sign, exp, mul, factor, n); + + return sign * unpack_storage_number_lut10x[(factor * 16) + (exp * 8) + mul] * n; +} + #endif /* NETDATA_STORAGE_NUMBER_H */ |