Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 10 Oct 2002 01:15:24 -0700 (PDT)
From:      Jian Tang <t_fisher@163.com>
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   kern/43887: abnormal CPU useage when use pthread_mutex
Message-ID:  <200210100815.g9A8FOh8004682@www.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         43887
>Category:       kern
>Synopsis:       abnormal CPU useage when use pthread_mutex
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Oct 10 01:20:01 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Jian Tang
>Release:        FreeBSD 4.3
>Organization:
CongXing
>Environment:
$ uname -a
FreeBSD cvs.risson.com 4.3-RELEASE FreeBSD 4.3-RELEASE #0: Tue Nov  6 12:53:47 CST 2001     tang@cvs.risson.com:/usr/src/sys
/compile/kernel  i386
>Description:
I have a small code to test the efficiency of the pthread_mutext.
#include <unistd.h>
#include <pthread.h>
#include <errno.h>

int main(int argc,char** argv)
{
    pthread_mutex_t mutex;
    long i,j;
    j =0;
    pthread_mutex_init(&mutex,NULL);
    while(1)
    {
        pthread_mutex_lock(&mutex);
        i = j*j;
        j++;
        pthread_mutex_unlock(&mutex);

        printf("i=%ld\n",i);
        if(usleep(800)== -1)
            printf("usleep fail. %s",strerror(errno));
    }
    return 0;
}

When I ran this program, I found that the usage of CPU is very high. 
CPU states: 25.3% user,  0.0% nice, 71.6% system,  0.4% interrupt,  2.7% idle

To reduce the usage of CPU,I added the time of usleep. I found that when the time of usleep is large than 1000,the status of cpu came back normal.
CPU states:  0.0% user,  0.0% nice,  1.6% system,  0.4% interrupt, 98.1% idle

I guess this problem is caused by the scheduler of thread. 
>How-To-Repeat:

>Fix:
     
>Release-Note:
>Audit-Trail:
>Unformatted:

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200210100815.g9A8FOh8004682>