Hello,

a user has reported high CPU usage in `top` when running rpld from
ttyrpld 2.12. It is repeatable with the current one (2.15), and it
seems to boil down to the read() function of the rpldev device, as I
have found out by placing getrusage() before and after the main read()
call in rpld. However, I cannot find anything that looks like a busy
wait in the kernel part (copy below), especially since the kernel code
is essentially the same for other BSDs, but neither FreeBSD or NetBSD
show high CPU usage.

Does anyone have an idea where it might be coming from? Is tsleep()
running a busywait?


Jan Engelhardt


--- ttyrpld-2.15/k_openbsd-3.8/rpldev.c ---
// return number of available bytes to read
static inline size_t avail_R(void);
// return minimum of the two
static inline unsigned int min_uint(unsigned int, unsigned int);
// circular buffer, read ptr and write ptr
static char *Buffer, *BufRP, *BufWP;

static int urpl_read(dev_t dev, struct uio *uio, int flags) {
    size_t count;
    int ret;

    mtx_enter(&Buffer_lock);
    if(Buffer == NULL)
        goto out;

    while(BufRP == BufWP) {
        mtx_leave(&Buffer_lock);
        if(flags & IO_NDELAY)
            return EWOULDBLOCK;
        if((ret = tsleep(&Buffer, PCATCH, "rpldev", 0)) != 0)
            return ret;
        ret = 0;
        mtx_enter(&Buffer_lock);
        if(Buffer == NULL)
            goto out;
    }
    
    count = min_uint(uio->uio_resid, avail_R());
    ret   = circular_get(uio, count);
 out:
    mtx_leave(&Buffer_lock);
    return ret;
}
--- end excerpt ---

Reply via email to