Skip to content
  • Paolo Bonzini's avatar
    480cff63
    coroutine-lock: add limited spinning to CoMutex · 480cff63
    Paolo Bonzini authored
    
    
    Running a very small critical section on pthread_mutex_t and CoMutex
    shows that pthread_mutex_t is much faster because it doesn't actually
    go to sleep.  What happens is that the critical section is shorter
    than the latency of entering the kernel and thus FUTEX_WAIT always
    fails.  With CoMutex there is no such latency but you still want to
    avoid wait and wakeup.  So introduce it artificially.
    
    This only works with one waiters; because CoMutex is fair, it will
    always have more waits and wakeups than a pthread_mutex_t.
    
    Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
    Reviewed-by: default avatarFam Zheng <famz@redhat.com>
    Message-id: 20170213181244.16297-3-pbonzini@redhat.com
    Signed-off-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
    480cff63
    coroutine-lock: add limited spinning to CoMutex
    Paolo Bonzini authored
    
    
    Running a very small critical section on pthread_mutex_t and CoMutex
    shows that pthread_mutex_t is much faster because it doesn't actually
    go to sleep.  What happens is that the critical section is shorter
    than the latency of entering the kernel and thus FUTEX_WAIT always
    fails.  With CoMutex there is no such latency but you still want to
    avoid wait and wakeup.  So introduce it artificially.
    
    This only works with one waiters; because CoMutex is fair, it will
    always have more waits and wakeups than a pthread_mutex_t.
    
    Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
    Reviewed-by: default avatarFam Zheng <famz@redhat.com>
    Message-id: 20170213181244.16297-3-pbonzini@redhat.com
    Signed-off-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
Loading