summaryrefslogtreecommitdiff
path: root/src/basic/parse-util.h
diff options
context:
space:
mode:
authorLuca Boccassi <luca.boccassi@microsoft.com>2021-09-24 17:28:27 +0100
committerYu Watanabe <watanabe.yu+github@gmail.com>2021-09-25 07:10:44 +0900
commitf0e2cfc6dc1fc31a1a49c0a3bcaa56301e67e4ae (patch)
tree45149835ad52018d33bbe7c50ab31aa86f1ce9d5 /src/basic/parse-util.h
parent3f67dccca0130093453b9abad4bf8171a3a72687 (diff)
downloadsystemd-f0e2cfc6dc1fc31a1a49c0a3bcaa56301e67e4ae.tar.gz
basic: delete loadavg.h copy
loadavg.h is an internal header of the Linux source repository, and as such it is licensed as GPLv2-only, without syscall exception. We use it only for 4 macros, which are simply doing some math calculations that cannot thus be subject to copyright. Reimplement the same calculations in another internal header and delete loadavg.h from our tree.
Diffstat (limited to 'src/basic/parse-util.h')
-rw-r--r--src/basic/parse-util.h9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/basic/parse-util.h b/src/basic/parse-util.h
index 908202dafd..e437e0de96 100644
--- a/src/basic/parse-util.h
+++ b/src/basic/parse-util.h
@@ -3,7 +3,6 @@
#include <inttypes.h>
#include <limits.h>
-#include <linux/loadavg.h>
#include <stddef.h>
#include <stdint.h>
#include <sys/types.h>
@@ -136,6 +135,14 @@ int parse_ip_prefix_length(const char *s, int *ret);
int parse_oom_score_adjust(const char *s, int *ret);
+/* Implement floating point using fixed integers, to improve performance when
+ * calculating load averages. These macros can be used to extract the integer
+ * and decimal parts of a value. */
+#define PRECISION_BITS 11
+#define FIXED_POINT_1_0 (1 << PRECISION_BITS)
+#define INT_SIDE(x) ((x) >> PRECISION_BITS)
+#define DECIMAL_SIDE(x) INT_SIDE(((x) & (FIXED_POINT_1_0 - 1)) * 100)
+
/* Given a Linux load average (e.g. decimal number 34.89 where 34 is passed as i and 89 is passed as f), convert it
* to a loadavg_t. */
int store_loadavg_fixed_point(unsigned long i, unsigned long f, loadavg_t *ret);