os.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. #include "endian.h"
  25. #define GETSYSCTL_BY_NAME(name, var) getsysctl_by_name(name, &(var), sizeof(var))
  26. int getsysctl_by_name(const char *name, void *ptr, size_t len);
  27. #endif
  28. // =====================================================================================================================
  29. // common defs for Apple/FreeBSD/Linux
  30. extern const char *os_type;
  31. #define get_system_cpus() get_system_cpus_with_cache(true, false)
  32. #define get_system_cpus_uncached() get_system_cpus_with_cache(false, false)
  33. long get_system_cpus_with_cache(bool cache, bool for_netdata);
  34. unsigned long read_cpuset_cpus(const char *filename, long system_cpus);
  35. extern pid_t pid_max;
  36. pid_t get_system_pid_max(void);
  37. extern unsigned int system_hz;
  38. void get_system_HZ(void);
  39. #include <sys/timex.h>
  40. #if defined(__FreeBSD__) || defined(__APPLE__)
  41. #define ADJUST_TIMEX(x) ntp_adjtime(x)
  42. #else
  43. #define ADJUST_TIMEX(x) adjtimex(x)
  44. #endif
  45. #endif //NETDATA_OS_H