Hi. I'm now working to reduce ixgbe's busy loop using with kpause()[*1]. I wrote the following code:
#define usec_delay(x) ixgbe_delay(x) #define msec_delay(x) ixgbe_delay((x) * 1000) void ixgbe_delay(unsigned int us) { if (__predict_false(cold)) delay(us); else if ((us / 1000) >= hztoms(1)) kpause("ixgdly", false, mstohz(us / 1000), NULL); else delay(us); } Does kpause(x, y, 1, z) guarantee to wait at least 1 tick length of time? Or, does it wakeup the next tick? Should I add extra 1 tick to kpause()? man 9 "tsleep" says: timo If non-zero, the process will sleep for at most timo/hz seconds. If this amount of time elapses and no wakeup(ident) has occurred, and no signal (if PCATCH was set) was posted, tsleep() will return EWOULDBLOCK. it sleep "at most timeo/hz" seconds. So some code use it like: tsleep(ident, priority, wmsg, 1 + 1); to sleep AT LEAST 1 tick. Is this type of treatment required on kpause()? man 9 kpause has no such note. For example, usb_subr.c rev. 1.268's usb_delay_ms_locked() is as follows: ------------------------ void usb_delay_ms_locked(struct usbd_bus *bus, u_int ms, kmutex_t *lock) { /* Wait at least two clock ticks so we know the time has passed. */ if (bus->ub_usepolling || cold) delay((ms+1) * 1000); else kpause("usbdly", false, (ms*hz+999)/1000 + 1, lock); } ------------------------- In the rev. 1.1. It was. ------------------------- void usbd_delay_ms(ms) int ms; { /* Wait at least two clock ticks so we know the time has passed. */ if (usbd_use_polling) delay((ms+1) * 1000); else tsleep(&ms, PRIBIO, "usbdly", (ms*hz+999)/1000 + 1); } ------------------------- If it's not required to add extra 1 tick on kpause(), usb_delay_ms_locked() can be simplified. [*1] http://www.netbsd.org/~msaitoh/ixgbe-sleep-20200618-0.dif Thanks in advance. -- ----------------------------------------------- SAITOH Masanobu (msai...@execsw.org msai...@netbsd.org)