* The bodies of this function and prof_leakcheck() are compiled out unless heap * profiling is enabled, so that it is possible to compile jemalloc with * floating point support completely disabled. Avoiding floating point code is * important on memory-constrained systems, but it also enables a workaround for * versions of glibc that don't properly save/restore floating point registers * duri
| 1137 | * -mno-sse) in order for the workaround to be complete. |
| 1138 | */ |
| 1139 | void |
| 1140 | prof_sample_threshold_update(prof_tdata_t *tdata) { |
| 1141 | #ifdef JEMALLOC_PROF |
| 1142 | if (!config_prof) { |
| 1143 | return; |
| 1144 | } |
| 1145 | |
| 1146 | if (lg_prof_sample == 0) { |
| 1147 | tsd_bytes_until_sample_set(tsd_fetch(), 0); |
| 1148 | return; |
| 1149 | } |
| 1150 | |
| 1151 | /* |
| 1152 | * Compute sample interval as a geometrically distributed random |
| 1153 | * variable with mean (2^lg_prof_sample). |
| 1154 | * |
| 1155 | * __ __ |
| 1156 | * | log(u) | 1 |
| 1157 | * tdata->bytes_until_sample = | -------- |, where p = --------------- |
| 1158 | * | log(1-p) | lg_prof_sample |
| 1159 | * 2 |
| 1160 | * |
| 1161 | * For more information on the math, see: |
| 1162 | * |
| 1163 | * Non-Uniform Random Variate Generation |
| 1164 | * Luc Devroye |
| 1165 | * Springer-Verlag, New York, 1986 |
| 1166 | * pp 500 |
| 1167 | * (http://luc.devroye.org/rnbookindex.html) |
| 1168 | */ |
| 1169 | uint64_t r = prng_lg_range_u64(&tdata->prng_state, 53); |
| 1170 | double u = (double)r * (1.0/9007199254740992.0L); |
| 1171 | uint64_t bytes_until_sample = (uint64_t)(log(u) / |
| 1172 | log(1.0 - (1.0 / (double)((uint64_t)1U << lg_prof_sample)))) |
| 1173 | + (uint64_t)1U; |
| 1174 | if (bytes_until_sample > SSIZE_MAX) { |
| 1175 | bytes_until_sample = SSIZE_MAX; |
| 1176 | } |
| 1177 | tsd_bytes_until_sample_set(tsd_fetch(), bytes_until_sample); |
| 1178 | |
| 1179 | #endif |
| 1180 | } |
| 1181 | |
| 1182 | #ifdef JEMALLOC_JET |
| 1183 | static prof_tdata_t * |
no test coverage detected