diff options
Diffstat (limited to 'include/linux')
| -rw-r--r-- | include/linux/kernel.h | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/include/linux/kernel.h b/include/linux/kernel.h index ecb87544cc5d..03d8a6b0e2e8 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h | |||
| @@ -193,6 +193,25 @@ extern int _cond_resched(void); | |||
| 193 | (__x < 0) ? -__x : __x; \ | 193 | (__x < 0) ? -__x : __x; \ |
| 194 | }) | 194 | }) |
| 195 | 195 | ||
| 196 | /** | ||
| 197 | * reciprocal_scale - "scale" a value into range [0, ep_ro) | ||
| 198 | * @val: value | ||
| 199 | * @ep_ro: right open interval endpoint | ||
| 200 | * | ||
| 201 | * Perform a "reciprocal multiplication" in order to "scale" a value into | ||
| 202 | * range [0, ep_ro), where the upper interval endpoint is right-open. | ||
| 203 | * This is useful, e.g. for accessing a index of an array containing | ||
| 204 | * ep_ro elements, for example. Think of it as sort of modulus, only that | ||
| 205 | * the result isn't that of modulo. ;) Note that if initial input is a | ||
| 206 | * small value, then result will return 0. | ||
| 207 | * | ||
| 208 | * Return: a result based on val in interval [0, ep_ro). | ||
| 209 | */ | ||
| 210 | static inline u32 reciprocal_scale(u32 val, u32 ep_ro) | ||
| 211 | { | ||
| 212 | return (u32)(((u64) val * ep_ro) >> 32); | ||
| 213 | } | ||
| 214 | |||
| 196 | #if defined(CONFIG_MMU) && \ | 215 | #if defined(CONFIG_MMU) && \ |
| 197 | (defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_DEBUG_ATOMIC_SLEEP)) | 216 | (defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_DEBUG_ATOMIC_SLEEP)) |
| 198 | void might_fault(void); | 217 | void might_fault(void); |
