Skip to content

Commit e25ec26

Browse files
committed
reduce the impact of kevent64
1 parent cff30c4 commit e25ec26

File tree

3 files changed

+40
-22
lines changed

3 files changed

+40
-22
lines changed

os/linux_base.h

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -84,19 +84,11 @@ struct voucher_offsets_s {
8484
* Stub out defines for other missing types
8585
*/
8686

87-
// Pulled from OS X man page for kevent
88-
struct kevent64_s {
89-
uint64_t ident; /* identifier for this event */
90-
int16_t filter; /* filter for event */
91-
uint16_t flags; /* general flags */
92-
uint32_t fflags; /* filter-specific flags */
93-
int64_t data; /* filter-specific data */
94-
uint64_t udata; /* opaque user data identifier */
95-
uint64_t ext[2]; /* filter-specific extensions */
96-
};
97-
98-
int kevent64(int kq, /*const*/ struct kevent64_s *changelist, int nchanges, struct kevent64_s *eventlist,
99-
int nevents, unsigned int flags, const struct timespec *timeout);
87+
#if !HAVE_KEVENT64
88+
// we fall back to use kevent
89+
#define kevent64_s kevent
90+
#define kevent64(kq,cl,nc,el,ne,f,to) kevent(kq,cl,nc,el,ne,to)
91+
#endif
10092

10193
// SIZE_T_MAX should not be hardcoded like this here.
10294
#define SIZE_T_MAX (0x7fffffff)
@@ -106,6 +98,8 @@ int kevent64(int kq, /*const*/ struct kevent64_s *changelist, int nchanges, stru
10698

10799
// The following values are passed as part of the EVFILT_TIMER requests
108100

101+
#define IGNORE_KEVENT64_EXT /* will force the kevent64_s.ext[] to not be used -> leeway ignored */
102+
109103
#define NOTE_SECONDS 0x01
110104
#define NOTE_USECONDS 0x02
111105
#define NOTE_NSECONDS 0x04

src/shims/linux_stubs.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ int sysctlbyname(const char *name, void *oldp, size_t *oldlenp,
8484
LINUX_PORT_ERROR();
8585
}
8686

87+
#if 0
88+
89+
// this code remains here purely for debugging purposes
90+
// ultimately it can be deleted
8791

8892
DISPATCH_NOINLINE
8993
static const char *
@@ -130,9 +134,8 @@ _evfiltstr(short filt)
130134
#define dbg_cond_kevent64(cond,fmt...) do { } while(0)
131135
#endif
132136

133-
#include <time.h>
134137

135-
int kevent64(int kq, /*const*/ struct kevent64_s *changelist, int nchanges, struct kevent64_s *eventlist,
138+
int kevent64(int kq, const struct kevent64_s *changelist_c, int nchanges, struct kevent64_s *eventlist,
136139
int nevents, unsigned int flags, const struct timespec *timeout)
137140
{
138141
// Documentation is not really clear. Instrument the code to make sure
@@ -142,6 +145,8 @@ int kevent64(int kq, /*const*/ struct kevent64_s *changelist, int nchanges, stru
142145
// no more than 1 change or one event is passed until we get a better handle of the
143146
// usage pattern of this. (Hubertus Franke)
144147

148+
struct kevent64_s *changelist = (struct kevent64_s*) changelist_c; // so we can modify it
149+
145150
#if 1
146151
// lets put some checks in here to make sure we do it all correct
147152
// we can only convert kevent64_s -> kevent for a single entry since kevent64_s has ext[0:1] extension
@@ -159,13 +164,13 @@ int kevent64(int kq, /*const*/ struct kevent64_s *changelist, int nchanges, stru
159164
// on first attempt). We also ignore the LEEWAY. Finally we must convert from
160165
// NSECS to MSECS (might have to expand to deal with OTHER NOTE_xSECS flags
161166

162-
changelist->data -= _dispatch_get_nanoseconds();
167+
//changelist->data -= _dispatch_get_nanoseconds();
163168
//changelist->data -= time(NULL) * NSEC_PER_SEC;
164169
dbg_kevent64("kevent64(%s,%x) data=%lx:%ld\n",
165170
_evfiltstr(changelist->filter),changelist->fflags,
166171
changelist->data,changelist->data);
167-
changelist->data /= 1000000UL;
168-
if ((int64_t)(changelist->data) <= 0) changelist->data = 1; // for some reason time turns negative
172+
//changelist->data /= 1000000UL;
173+
//if ((int64_t)(changelist->data) <= 0) changelist->data = 1; // for some reason time turns negative
169174
}
170175
}
171176
#endif
@@ -176,6 +181,8 @@ int kevent64(int kq, /*const*/ struct kevent64_s *changelist, int nchanges, stru
176181
return rc;
177182
}
178183

184+
#endif
185+
179186
/*
180187
* Stubbed out static data
181188
*/

src/source.c

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1858,13 +1858,22 @@ _dispatch_timers_get_delay(uint64_t nows[], struct dispatch_timer_s timer[],
18581858
return ridx;
18591859
}
18601860

1861+
1862+
#if HAVE_KEVENT64
1863+
# define kevent_set_ext1(ke,val) (ke)->ext[1] = (val)
1864+
# define delay_add_wall(delay,at) (delay) += (at)
1865+
#else
1866+
# define kevent_set_ext1(ke,val) do { } while (0)
1867+
# define delay_add_wall(delay,at) do { } while (0)
1868+
#endif
1869+
18611870
static bool
18621871
_dispatch_timers_program2(uint64_t nows[], _dispatch_kevent_qos_s *ke,
18631872
unsigned int qos)
18641873
{
18651874
unsigned int tidx;
18661875
bool poll;
1867-
uint64_t delay, leeway;
1876+
uint64_t delay, leeway, nowtime;
18681877

18691878
tidx = _dispatch_timers_get_delay(nows, _dispatch_timer, &delay, &leeway,
18701879
(int)qos);
@@ -1881,13 +1890,21 @@ _dispatch_timers_program2(uint64_t nows[], _dispatch_kevent_qos_s *ke,
18811890
_dispatch_trace_next_timer_set(
18821891
TAILQ_FIRST(&_dispatch_kevent_timer[tidx].dk_sources), qos);
18831892
_dispatch_trace_next_timer_program(delay, qos);
1884-
delay += _dispatch_source_timer_now(nows, DISPATCH_TIMER_KIND_WALL);
1893+
nowtime =_dispatch_source_timer_now(nows, DISPATCH_TIMER_KIND_WALL);
1894+
delay_add_wall(delay,nowtime);
1895+
1896+
//printf("%s: delay %ld nsecs\n",__FUNCTION__,delay);
1897+
// convert delay into msecs
1898+
delay /= 1000000L;
1899+
if ((int64_t)(delay) <= 0) delay = 1; // for some reason time turns negative
1900+
//if ((int64_t)(delay) <= 0) printf("%s: delay =%d\n",__FUNCTION__,(int64_t)delay);
1901+
18851902
if (slowpath(_dispatch_timers_force_max_leeway)) {
18861903
ke->data = (int64_t)(delay + leeway);
1887-
ke->ext[1] = 0;
1904+
kevent_set_ext1(ke,0);
18881905
} else {
18891906
ke->data = (int64_t)delay;
1890-
ke->ext[1] = leeway;
1907+
kevent_set_ext1(ke,leeway);
18911908
}
18921909
ke->flags |= EV_ADD|EV_ENABLE;
18931910
ke->flags &= ~EV_DELETE;

0 commit comments

Comments
 (0)