os.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // SPDX-License-Identifier: GPL-3.0-or-later
  2. #ifndef NETDATA_OS_H
  3. #define NETDATA_OS_H
  4. #include "libnetdata.h"
  5. // =====================================================================================================================
  6. // FreeBSD
  7. #if __FreeBSD__
  8. #include <sys/sysctl.h>
  9. #define GETSYSCTL_BY_NAME(name, var) getsysctl_by_name(name, &(var), sizeof(var))
  10. int getsysctl_by_name(const char *name, void *ptr, size_t len);
  11. #define GETSYSCTL_MIB(name, mib) getsysctl_mib(name, mib, sizeof(mib)/sizeof(int))
  12. int getsysctl_mib(const char *name, int *mib, size_t len);
  13. #define GETSYSCTL_SIMPLE(name, mib, var) getsysctl_simple(name, mib, sizeof(mib)/sizeof(int), &(var), sizeof(var))
  14. #define GETSYSCTL_WSIZE(name, mib, var, size) getsysctl_simple(name, mib, sizeof(mib)/sizeof(int), var, size)
  15. int getsysctl_simple(const char *name, int *mib, size_t miblen, void *ptr, size_t len);
  16. #define GETSYSCTL_SIZE(name, mib, size) getsysctl(name, mib, sizeof(mib)/sizeof(int), NULL, &(size))
  17. #define GETSYSCTL(name, mib, var, size) getsysctl(name, mib, sizeof(mib)/sizeof(int), &(var), &(size))
  18. int getsysctl(const char *name, int *mib, size_t miblen, void *ptr, size_t *len);
  19. #endif
  20. // =====================================================================================================================
  21. // MacOS
  22. #if __APPLE__
  23. #include <sys/sysctl.h>
  24. #define GETSYSCTL_BY_NAME(name, var) getsysctl_by_name(name, &(var), sizeof(var))
  25. int getsysctl_by_name(const char *name, void *ptr, size_t len);
  26. #endif
  27. // =====================================================================================================================
  28. // common defs for Apple/FreeBSD/Linux
  29. extern const char *os_type;
  30. #define get_system_cpus() get_system_cpus_with_cache(true, false)
  31. #define get_system_cpus_uncached() get_system_cpus_with_cache(false, false)
  32. long get_system_cpus_with_cache(bool cache, bool for_netdata);
  33. unsigned long read_cpuset_cpus(const char *filename, long system_cpus);
  34. extern pid_t pid_max;
  35. pid_t get_system_pid_max(void);
  36. extern unsigned int system_hz;
  37. void get_system_HZ(void);
  38. #include <sys/timex.h>
  39. #if defined(__FreeBSD__) || defined(__APPLE__)
  40. #define ADJUST_TIMEX(x) ntp_adjtime(x)
  41. #else
  42. #define ADJUST_TIMEX(x) adjtimex(x)
  43. #endif
  44. #endif //NETDATA_OS_H