Go to the documentation of this file.
38 #include <sys/epoll.h>
39 #include <sys/param.h>
40 #include <sys/prctl.h>
41 #include <sys/sysinfo.h>
46 #define HAVE_IFADDRS_H 1
49 # if __UCLIBC_MAJOR__ < 0 && __UCLIBC_MINOR__ < 9 && __UCLIBC_SUBLEVEL__ < 32
50 # undef HAVE_IFADDRS_H
55 # if defined(__ANDROID__)
60 # include <sys/socket.h>
61 # include <net/ethernet.h>
62 # include <netpacket/packet.h>
66 #ifndef CLOCK_MONOTONIC_COARSE
67 # define CLOCK_MONOTONIC_COARSE 6
74 #ifndef CLOCK_BOOTTIME
75 # define CLOCK_BOOTTIME 7
93 #if defined(__ANDROID_API__) && __ANDROID_API__ < 21
103 if (fd == -1 && (errno == ENOSYS || errno == EINVAL)) {
104 fd = epoll_create(256);
110 loop->backend_fd = fd;
111 loop->inotify_fd = -1;
112 loop->inotify_watchers = NULL;
125 old_watchers =
loop->inotify_watchers;
128 loop->backend_fd = -1;
140 if (
loop->inotify_fd == -1)
return;
143 loop->inotify_fd = -1;
153 assert(
loop->watchers != NULL);
160 for (
i = 0;
i < nfds;
i++)
170 if (
loop->backend_fd >= 0) {
210 static const int max_safe_timeout = 1789569;
211 static int no_epoll_pwait;
212 static int no_epoll_wait;
230 if (
loop->nfds == 0) {
245 assert(w->
fd < (
int)
loop->nwatchers);
274 sigemptyset(&sigset);
275 sigaddset(&sigset, SIGPROF);
276 sigmask |= 1 << (SIGPROF - 1);
288 if (
sizeof(
int32_t) ==
sizeof(
long) &&
timeout >= max_safe_timeout)
291 if (sigmask != 0 && no_epoll_pwait != 0)
292 if (pthread_sigmask(SIG_BLOCK, &sigset, NULL))
295 if (no_epoll_wait != 0 || (sigmask != 0 && no_epoll_pwait == 0)) {
296 #if defined(__ANDROID_API__) && __ANDROID_API__ < 21
300 nfds = epoll_pwait(
loop->backend_fd,
306 if (nfds == -1 && errno == ENOSYS)
313 if (nfds == -1 && errno == ENOSYS)
317 if (sigmask != 0 && no_epoll_pwait != 0)
318 if (pthread_sigmask(SIG_UNBLOCK, &sigset, NULL))
340 if (errno == ENOSYS) {
342 assert(no_epoll_wait == 0 || no_epoll_pwait == 0);
370 assert(
loop->watchers != NULL);
371 loop->watchers[
loop->nwatchers] =
x.watchers;
375 for (
i = 0;
i < nfds;
i++) {
384 assert((
unsigned) fd < loop->nwatchers);
428 if (w == &
loop->signal_io_watcher)
437 if (have_signals != 0)
438 loop->signal_io_watcher.cb(
loop, &
loop->signal_io_watcher, POLLIN);
440 loop->watchers[
loop->nwatchers] = NULL;
441 loop->watchers[
loop->nwatchers + 1] = NULL;
443 if (have_signals != 0)
464 real_timeout -= (
loop->time -
base);
465 if (real_timeout <= 0)
474 static clock_t fast_clock_id = -1;
488 t.tv_nsec <= 1 * 1000 * 1000) {
491 fast_clock_id = CLOCK_MONOTONIC;
495 clock_id = CLOCK_MONOTONIC;
497 clock_id = fast_clock_id;
499 if (clock_gettime(clock_id, &t))
502 return t.tv_sec * (
uint64_t) 1e9 + t.tv_nsec;
515 fd =
open(
"/proc/self/stat", O_RDONLY);
516 while (fd == -1 && errno == EINTR);
523 while (
n == -1 && errno == EINTR);
530 s = strchr(
buf,
' ');
542 for (
i = 1;
i <= 22;
i++) {
543 s = strchr(s + 1,
' ');
549 val = strtol(s, NULL, 10);
555 *rss = val * getpagesize();
564 static volatile int no_clock_boottime;
572 if (no_clock_boottime) {
573 retry:
r = clock_gettime(CLOCK_MONOTONIC, &
now);
576 no_clock_boottime = 1;
583 *uptime =
now.tv_sec;
592 if (!fgets(
buf,
sizeof(
buf), statfile_fp))
596 while (fgets(
buf,
sizeof(
buf), statfile_fp)) {
597 if (strncmp(
buf,
"cpu", 3))
611 unsigned int numcpus;
620 if (statfile_fp == NULL)
644 if (ci[0].speed == 0)
654 if (errno != EINTR && errno != EINPROGRESS)
675 static const char model_marker[] =
"model name\t: ";
676 static const char speed_marker[] =
"cpu MHz\t\t: ";
677 const char* inferred_model;
678 unsigned int model_idx;
679 unsigned int speed_idx;
685 (void) &model_marker;
686 (void) &speed_marker;
695 #if defined(__arm__) || \
696 defined(__i386__) || \
697 defined(__mips__) || \
703 while (fgets(
buf,
sizeof(
buf), fp)) {
704 if (model_idx < numcpus) {
705 if (strncmp(
buf, model_marker,
sizeof(model_marker) - 1) == 0) {
706 model =
buf +
sizeof(model_marker) - 1;
712 ci[model_idx++].
model = model;
716 #if defined(__arm__) || defined(__mips__)
717 if (model_idx < numcpus) {
720 static const char model_marker[] =
"Processor\t: ";
722 static const char model_marker[] =
"cpu model\t\t: ";
724 if (strncmp(
buf, model_marker,
sizeof(model_marker) - 1) == 0) {
725 model =
buf +
sizeof(model_marker) - 1;
731 ci[model_idx++].
model = model;
736 if (speed_idx < numcpus) {
737 if (strncmp(
buf, speed_marker,
sizeof(speed_marker) - 1) == 0) {
738 ci[speed_idx++].
speed = atoi(
buf +
sizeof(speed_marker) - 1);
752 inferred_model =
"unknown";
754 inferred_model = ci[model_idx - 1].
model;
756 while (model_idx < numcpus) {
757 model =
uv__strndup(inferred_model, strlen(inferred_model));
760 ci[model_idx++].
model = model;
768 unsigned int numcpus,
782 clock_ticks = sysconf(_SC_CLK_TCK);
783 assert(clock_ticks != (
uint64_t) -1);
784 assert(clock_ticks != 0);
788 if (!fgets(
buf,
sizeof(
buf), statfile_fp))
793 while (fgets(
buf,
sizeof(
buf), statfile_fp)) {
797 if (strncmp(
buf,
"cpu", 3))
803 int r = sscanf(
buf,
"cpu%u ", &
n);
806 for (
len =
sizeof(
"cpu0");
n /= 10;
len++);
815 if (6 != sscanf(
buf +
len,
816 "%" PRIu64
" %" PRIu64
" %" PRIu64
817 "%" PRIu64
" %" PRIu64
" %" PRIu64,
828 ts.
sys = clock_ticks *
sys;
830 ts.
irq = clock_ticks *
irq;
833 assert(
num == numcpus);
846 "/sys/devices/system/cpu/cpu%u/cpufreq/scaling_cur_freq",
853 if (fscanf(fp,
"%" PRIu64, &val) != 1)
871 if (ent->
ifa_addr->sa_family == PF_PACKET)
873 return !exclude_type;
877 #ifndef HAVE_IFADDRS_H
885 struct sockaddr_ll *sll;
894 for (ent = addrs; ent != NULL; ent = ent->
ifa_next) {
913 address = *addresses;
915 for (ent = addrs; ent != NULL; ent = ent->
ifa_next) {
939 for (ent = addrs; ent != NULL; ent = ent->
ifa_next) {
943 address = *addresses;
945 for (
i = 0;
i < (*count);
i++) {
946 size_t namelen = strlen(ent->
ifa_name);
948 if (strncmp(address->
name, ent->
ifa_name, namelen) == 0 &&
949 (address->
name[namelen] == 0 || address->
name[namelen] ==
':')) {
950 sll = (
struct sockaddr_ll*)ent->
ifa_addr;
977 #if defined(PR_SET_NAME)
978 prctl(PR_SET_NAME, title);
1002 p = strstr(
buf, what);
1009 if (1 != sscanf(
p,
"%" PRIu64
" kB", &rc))
1024 struct sysinfo info;
1032 if (0 == sysinfo(&info))
1033 return (
uint64_t) info.freeram * info.mem_unit;
1040 struct sysinfo info;
1048 if (0 == sysinfo(&info))
1049 return (
uint64_t) info.totalram * info.mem_unit;
1062 snprintf(
filename, 256,
"/sys/fs/cgroup/%s/%s", cgroup, param);
1074 sscanf(
buf,
"%" PRIu64, &rc);
FILE * uv__open_file(const char *path)
#define ARRAY_SIZE(array)
return memset(p, 0, total)
static void read_speeds(unsigned int numcpus, uv_cpu_info_t *ci)
UV_EXTERN void uv_free_cpu_info(uv_cpu_info_t *cpu_infos, int count)
void uv_free_interface_addresses(uv_interface_address_t *addresses, int count)
int uv__close_nocheckstdio(int fd)
int uv__open_cloexec(const char *path, int flags)
static int uv__cpu_num(FILE *statfile_fp, unsigned int *numcpus)
#define QUEUE_DATA(ptr, type, field)
int uv_uptime(double *uptime)
void uv__io_poll(uv_loop_t *loop, int timeout)
struct uv_cpu_times_s cpu_times
union uv_interface_address_s::@401 netmask
void uv__platform_loop_delete(uv_loop_t *loop)
uv__os390_epoll * epoll_create1(int flags)
void retry(grpc_end2end_test_config config)
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
int uv__platform_loop_init(uv_loop_t *loop)
static int read_models(unsigned int numcpus, uv_cpu_info_t *ci)
uint64_t uv_get_constrained_memory(void)
static int read_times(FILE *statfile_fp, unsigned int numcpus, uv_cpu_info_t *ci)
#define CLOCK_MONOTONIC_COARSE
struct sockaddr * ifa_netmask
struct sockaddr * ifa_addr
int uv__inotify_fork(uv_loop_t *loop, void *old_watchers)
int uv__io_check_fd(uv_loop_t *loop, int fd)
char * uv__strdup(const char *s)
uint64_t uv_get_free_memory(void)
uint64_t uv__hrtime(uv_clocktype_t type)
static uint64_t uv__read_proc_meminfo(const char *what)
unsigned __int64 uint64_t
void uv__set_process_title(const char *title)
void * uv__calloc(size_t count, size_t size)
int uv_resident_set_memory(size_t *rss)
static uint64_t read_cpufreq(unsigned int cpunum)
_W64 unsigned int uintptr_t
int uv__io_fork(uv_loop_t *loop)
int epoll_wait(uv__os390_epoll *lst, struct epoll_event *events, int maxevents, int timeout)
int uv_interface_addresses(uv_interface_address_t **addresses, int *count)
static uint64_t uv__read_cgroups_uint64(const char *cgroup, const char *param)
int read(izstream &zs, T *x, Items items)
struct sockaddr_in address4
struct sockaddr_in6 netmask6
#define SAVE_ERRNO(block)
int epoll_ctl(uv__os390_epoll *lst, int op, int fd, struct epoll_event *event)
static int uv__ifaddr_exclude(struct ifaddrs *ent, int exclude_type)
void uv__platform_invalidate_fd(uv_loop_t *loop, int fd)
uint64_t uv_get_total_memory(void)
void uv__io_stop(uv_loop_t *loop, uv__io_t *w, unsigned int events)
char * uv__strndup(const char *s, size_t n)
union uv_interface_address_s::@400 address
struct ifaddrs * ifa_next
struct sockaddr_in netmask4
int uv_cpu_info(uv_cpu_info_t **cpu_infos, int *count)
void freeifaddrs(struct ifaddrs *ifa)
__BEGIN_DECLS int getifaddrs(struct ifaddrs **ifap)
struct sockaddr_in6 address6
grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:00:28