This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
Re: [Bug libc/1005] putc() runs slower
- From: Uttam Pawar <uttamp at us dot ibm dot com>
- To: libc-alpha at sources dot redhat dot com
- Date: Mon, 11 Jul 2005 10:57:53 -0700
- Subject: Re: [Bug libc/1005] putc() runs slower
- References: <20050610213731.1005.uttamp@us.ibm.com> <20050610214606.17578.qmail@sourceware.org>
Following the proposed patch for to fix the performance issue while
using putc() in single threaded application.
patch has added a check in _IO_putc(), _IO_getc(), putchar()and
getchar() library call if the calling application is single threaded or
not. If it is single threaded at the time of call, then unlocked version
of library functions gets called.
This make sense because, when an application calls putc() or any of the
above call, thread of executation is going to remain single (unless in
multi-thread env.), till we come back from the call and execute
pthread_create() and so on. There is no chance of new thread getting
created while application is in the middle of any of the above mentioned
call. I've built and ran complete glibc testsuite with the above patch
and did not see any new failures but saw an improvement in the
performance numbers (obviously).
--------------------------------------------------------------------------------
diff -urN glibc-20041219T2331_putc/ChangeLog
glibc-20041219T2331_putc.mine/ChangeLog
--- glibc-20041219T2331_putc/ChangeLog 2005-07-11 16:49:01.271964184
-0700
+++ glibc-20041219T2331_putc.mine/ChangeLog 2005-07-11
16:55:27.087010304 -0700
@@ -1,3 +1,11 @@
+2005-06-14 Uttam Pawar <uttamp@us.ibm.com>
+ * libio/getc.c (_IO_getc): Added a check if it's been called from
+ single threaded application if it is then use unlocked version of
+ library call.
+ * libio/getchar.c (getchar): Likewise
+ * libio/putc.c (_IO_putc): Likewise
+ * libio/putchar.c (putchar): Likewise
+
2004-12-19 Roland McGrath <roland@redhat.com>
* iconv/iconvconfig.c (nostdlib, output_file, output_file_len):
diff -urN glibc-20041219T2331_putc/libio/getc.c
glibc-20041219T2331_putc.mine/libio/getc.c
--- glibc-20041219T2331_putc/libio/getc.c 2003-08-29 12:58:26.000000000
-0700
+++ glibc-20041219T2331_putc.mine/libio/getc.c 2005-07-11
17:04:44.627034944 -0700
@@ -28,6 +28,7 @@
#include "libioP.h"
#include "stdio.h"
+#include <sysdep-cancel.h>
#undef _IO_getc
@@ -37,9 +38,13 @@
{
int result;
CHECK_FILE (fp, EOF);
- _IO_acquire_lock (fp);
- result = _IO_getc_unlocked (fp);
- _IO_release_lock (fp);
+ if(SINGLE_THREAD_P) {
+ result = _IO_getc_unlocked (fp);
+ } else {
+ _IO_acquire_lock (fp);
+ result = _IO_getc_unlocked (fp);
+ _IO_release_lock (fp);
+ }
return result;
}
diff -urN glibc-20041219T2331_putc/libio/getchar.c
glibc-20041219T2331_putc.mine/libio/getchar.c
--- glibc-20041219T2331_putc/libio/getchar.c 2003-08-29
12:58:27.000000000 -0700
+++ glibc-20041219T2331_putc.mine/libio/getchar.c 2005-07-11
17:08:50.195973992 -0700
@@ -27,6 +27,7 @@
#include "libioP.h"
#include "stdio.h"
+#include <sysdep-cancel.h>
#undef getchar
@@ -34,9 +35,13 @@
getchar ()
{
int result;
- _IO_acquire_lock (_IO_stdin);
- result = _IO_getc_unlocked (_IO_stdin);
- _IO_release_lock (_IO_stdin);
+ if(SINGLE_THREAD_P) {
+ result = _IO_getc_unlocked (_IO_stdin);
+ } else {
+ _IO_acquire_lock (_IO_stdin);
+ result = _IO_getc_unlocked (_IO_stdin);
+ _IO_release_lock (_IO_stdin);
+ }
return result;
}
diff -urN glibc-20041219T2331_putc/libio/putc.c
glibc-20041219T2331_putc.mine/libio/putc.c
--- glibc-20041219T2331_putc/libio/putc.c 2003-08-29 12:58:27.000000000
-0700
+++ glibc-20041219T2331_putc.mine/libio/putc.c 2005-07-11
17:08:22.812011320 -0700
@@ -19,6 +19,7 @@
#include "libioP.h"
#include "stdio.h"
+#include <sysdep-cancel.h>
#undef _IO_putc
@@ -29,9 +30,13 @@
{
int result;
CHECK_FILE (fp, EOF);
- _IO_acquire_lock (fp);
- result = _IO_putc_unlocked (c, fp);
- _IO_release_lock (fp);
+ if(SINGLE_THREAD_P) {
+ result = _IO_putc_unlocked (c, fp);
+ } else {
+ _IO_acquire_lock (fp);
+ result = _IO_putc_unlocked (c, fp);
+ _IO_release_lock (fp);
+ }
return result;
}
INTDEF(_IO_putc)
diff -urN glibc-20041219T2331_putc/libio/putchar.c
glibc-20041219T2331_putc.mine/libio/putchar.c
--- glibc-20041219T2331_putc/libio/putchar.c 2003-08-29
12:58:27.000000000 -0700
+++ glibc-20041219T2331_putc.mine/libio/putchar.c 2005-07-11
17:08:58.935980424 -0700
@@ -18,6 +18,7 @@
#include "libioP.h"
#include "stdio.h"
+#include <sysdep-cancel.h>
#undef putchar
@@ -26,9 +27,13 @@
int c;
{
int result;
- _IO_acquire_lock (_IO_stdout);
- result = _IO_putc_unlocked (c, _IO_stdout);
- _IO_release_lock (_IO_stdout);
+ if(SINGLE_THREAD_P) {
+ result = _IO_putc_unlocked (c, _IO_stdout);
+ } else {
+ _IO_acquire_lock (_IO_stdout);
+ result = _IO_putc_unlocked (c, _IO_stdout);
+ _IO_release_lock (_IO_stdout);
+ }
return result;
}
------------------------------------------------------
Thanks,
Uttam