From owner-freebsd-bugs Thu Oct 10 1:20: 4 2002 Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 58D0337B401 for ; Thu, 10 Oct 2002 01:20:02 -0700 (PDT) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 9E5BE43EB2 for ; Thu, 10 Oct 2002 01:20:01 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.6/8.12.6) with ESMTP id g9A8K1Co084042 for ; Thu, 10 Oct 2002 01:20:01 -0700 (PDT) (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.6/8.12.6/Submit) id g9A8K1kf084041; Thu, 10 Oct 2002 01:20:01 -0700 (PDT) Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id D5AC237B401 for ; Thu, 10 Oct 2002 01:15:28 -0700 (PDT) Received: from www.freebsd.org (www.freebsd.org [216.136.204.117]) by mx1.FreeBSD.org (Postfix) with ESMTP id 956C943EAF for ; Thu, 10 Oct 2002 01:15:28 -0700 (PDT) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.12.6/8.12.6) with ESMTP id g9A8FO7R004683 for ; Thu, 10 Oct 2002 01:15:24 -0700 (PDT) (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.12.6/8.12.6/Submit) id g9A8FOh8004682; Thu, 10 Oct 2002 01:15:24 -0700 (PDT) Message-Id: <200210100815.g9A8FOh8004682@www.freebsd.org> Date: Thu, 10 Oct 2002 01:15:24 -0700 (PDT) From: Jian Tang To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-1.0 Subject: kern/43887: abnormal CPU useage when use pthread_mutex Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org >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 #include #include 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