1 /*************************************************
2 * Exim - an Internet mail transport agent *
3 *************************************************/
5 /* Copyright (c) The Exim Maintainers 2020 */
6 /* See the file NOTICE for conditions of use and distribution. */
8 /* GNU-specific code. This is concatenated onto the generic src/os.c file.
9 GNU/Hurd has approximately the same way to determine the load average as NeXT,
10 so a variant of this could also be in the generic os.c file. See the GNU EMacs
11 getloadavg.c file, from which this snippet was derived. getloadavg.c from Emacs
12 is copyrighted by the FSF under the terms of the GPLv2 or any later version.
13 Changes are hereby placed under the same license, as requested by the GPL. */
15 #ifndef OS_LOAD_AVERAGE
16 #define OS_LOAD_AVERAGE
20 static processor_set_t default_set;
21 static int getloadavg_initialized;
27 struct processor_set_basic_info info;
30 if (!getloadavg_initialized)
32 if (processor_set_default (mach_host_self(), &default_set) == KERN_SUCCESS)
33 getloadavg_initialized = 1;
36 if (getloadavg_initialized)
38 info_count = PROCESSOR_SET_BASIC_INFO_COUNT;
39 if (processor_set_info(default_set, PROCESSOR_SET_BASIC_INFO, &host,
40 (processor_set_info_t)&info, &info_count) != KERN_SUCCESS)
41 getloadavg_initialized = 0;
44 #if LOAD_SCALE == 1000
45 return info.load_average;
47 return (int) (((double) info.load_average * 1000) / LOAD_SCALE));
54 #endif /* OS_LOAD_AVERAGE */