| 1959 | } |
| 1960 | |
| 1961 | static void house_keeping(struct io_uring *ring) |
| 1962 | { |
| 1963 | static unsigned long last_bytes; |
| 1964 | unsigned long bytes, elapsed; |
| 1965 | struct conn *c; |
| 1966 | int i, j; |
| 1967 | |
| 1968 | vlog("House keeping entered\n"); |
| 1969 | |
| 1970 | bytes = 0; |
| 1971 | for (i = 0; i < nr_conns; i++) { |
| 1972 | c = &conns[i]; |
| 1973 | |
| 1974 | for (j = 0; j < 2; j++) { |
| 1975 | struct conn_dir *cd = &c->cd[j]; |
| 1976 | |
| 1977 | bytes += cd->in_bytes + cd->out_bytes; |
| 1978 | } |
| 1979 | if (c->flags & CONN_F_DISCONNECTED) { |
| 1980 | vlog("%d: disconnected\n", i); |
| 1981 | |
| 1982 | if (!(c->flags & CONN_F_REAPED)) { |
| 1983 | void *ret; |
| 1984 | |
| 1985 | pthread_join(c->thread, &ret); |
| 1986 | c->flags |= CONN_F_REAPED; |
| 1987 | } |
| 1988 | continue; |
| 1989 | } |
| 1990 | if (c->flags & CONN_F_DISCONNECTING) |
| 1991 | continue; |
| 1992 | |
| 1993 | if (should_shutdown(c)) { |
| 1994 | __close_conn(ring, c); |
| 1995 | c->flags |= CONN_F_DISCONNECTING; |
| 1996 | } |
| 1997 | } |
| 1998 | |
| 1999 | elapsed = mtime_since_now(&last_housekeeping); |
| 2000 | if (bytes && elapsed >= 900) { |
| 2001 | unsigned long bw; |
| 2002 | |
| 2003 | bw = (8 * (bytes - last_bytes) / 1000UL) / elapsed; |
| 2004 | if (bw) { |
| 2005 | if (open_conns) |
| 2006 | printf("Bandwidth (threads=%d): %'luMbit\n", open_conns, bw); |
| 2007 | gettimeofday(&last_housekeeping, NULL); |
| 2008 | last_bytes = bytes; |
| 2009 | } |
| 2010 | } |
| 2011 | } |
| 2012 | |
| 2013 | /* |
| 2014 | * Event loop shared between the parent, and the connections. Could be |
no test coverage detected