about summary refs log tree commit diff
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2001-07-17 02:38:34 +0000
committerUlrich Drepper <drepper@redhat.com>2001-07-17 02:38:34 +0000
commit23700036397721389b90ac41571d68df2f26ad67 (patch)
treefd1fef01ef5380a5464e370871d202ce2e90e4b3
parent98e75a1c9c50e99e46c94623d9a9a8088c4efe30 (diff)
downloadglibc-23700036397721389b90ac41571d68df2f26ad67.tar.gz
glibc-23700036397721389b90ac41571d68df2f26ad67.tar.xz
glibc-23700036397721389b90ac41571d68df2f26ad67.zip
Update.
	only if debug_level > 0.  Add little performance improvements.
	Use TEMP_FAILURE_RETRY around write calls.
-rw-r--r--ChangeLog3
-rw-r--r--nscd/connections.c35
-rw-r--r--nscd/grpcache.c4
-rw-r--r--nscd/hstcache.c4
-rw-r--r--nscd/pwdcache.c4
5 files changed, 28 insertions, 22 deletions
diff --git a/ChangeLog b/ChangeLog
index 1eb5574a2d..4588974ae3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,7 +1,8 @@
 2001-07-16  Ulrich Drepper  <drepper@redhat.com>
 
 	* nscd/connections.c: Print messages caused by user application
-	only if debug_level > 0.
+	only if debug_level > 0.  Add little performance improvements.
+	Use TEMP_FAILURE_RETRY around write calls.
 	* nscd/grpcache.c: Likewise.
 	* nscd/hstcache.c: Likewise.
 	* nscd/pwdcache.c: Likewise.
diff --git a/nscd/connections.c b/nscd/connections.c
index 47660d723a..7f7514f8f6 100644
--- a/nscd/connections.c
+++ b/nscd/connections.c
@@ -203,9 +203,10 @@ invalidate_cache (char *key)
     number = pwddb;
   else if (strcmp (key, "group") == 0)
     number = grpdb;
-  else if (strcmp (key, "hosts") == 0)
+  else if (__builtin_expect (strcmp (key, "hosts"), 0) == 0)
     number = hstdb;
-  else return;
+  else
+    return;
 
   if (dbs[number].enabled)
     prune_cache (&dbs[number], LONG_MAX);
@@ -216,11 +217,11 @@ invalidate_cache (char *key)
 static void
 handle_request (int fd, request_header *req, void *key, uid_t uid)
 {
-  if (debug_level > 0)
+  if (__builtin_expect (debug_level, 0) > 0)
     dbg_log (_("handle_request: request received (Version = %d)"),
 	     req->version);
 
-  if (req->version != NSCD_VERSION)
+  if (__builtin_expect (req->version, NSCD_VERSION) != NSCD_VERSION)
     {
       if (debug_level > 0)
 	dbg_log (_("\
@@ -229,12 +230,13 @@ cannot handle old request version %d; current version is %d"),
       return;
     }
 
-  if (req->type >= GETPWBYNAME && req->type <= LASTDBREQ)
+  if (__builtin_expect (req->type, GETPWBYNAME) >= GETPWBYNAME
+      && __builtin_expect (req->type, LASTDBREQ) <= LASTDBREQ)
     {
       struct hashentry *cached;
       struct database *db = &dbs[serv2db[req->type]];
 
-      if (debug_level > 0)
+      if (__builtin_expect (debug_level, 0) > 0)
 	{
 	  if (req->type == GETHOSTBYADDR || req->type == GETHOSTBYADDRv6)
 	    {
@@ -256,7 +258,7 @@ cannot handle old request version %d; current version is %d"),
 	  if (TEMP_FAILURE_RETRY (write (fd, db->disabled_iov->iov_base,
 					 db->disabled_iov->iov_len))
 	      != db->disabled_iov->iov_len
-	      && debug_level > 0)
+	      && __builtin_expect (debug_level, 0) > 0)
 	    {
 	      /* We have problems sending the result.  */
 	      char buf[256];
@@ -278,7 +280,7 @@ cannot handle old request version %d; current version is %d"),
 	  /* Hurray it's in the cache.  */
 	  if (TEMP_FAILURE_RETRY (write (fd, cached->packet, cached->total))
 	      != cached->total
-	      && debug_level > 0)
+	      && __builtin_expect (debug_level, 0) > 0)
 	    {
 	      /* We have problems sending the result.  */
 	      char buf[256];
@@ -293,7 +295,7 @@ cannot handle old request version %d; current version is %d"),
 
       pthread_rwlock_unlock (&db->lock);
     }
-  else if (debug_level > 0)
+  else if (__builtin_expect (debug_level, 0) > 0)
     {
       if (req->type == INVALIDATE)
 	dbg_log ("\t%s (%s)", serv2str[req->type], (char *)key);
@@ -425,7 +427,7 @@ nscd_run (void *p)
 	  char buf[256];
 	  uid_t uid = 0;
 
-	  if (fd < 0)
+	  if (__builtin_expect (fd, 0) < 0)
 	    {
 	      dbg_log (_("while accepting connection: %s"),
 		       strerror_r (errno, buf, sizeof (buf)));
@@ -433,8 +435,9 @@ nscd_run (void *p)
 	    }
 
 	  /* Now read the request.  */
-	  if (TEMP_FAILURE_RETRY (read (fd, &req, sizeof (req)))
-	      != sizeof (req))
+	  if (__builtin_expect (TEMP_FAILURE_RETRY (read (fd, &req,
+							  sizeof (req)))
+				!= sizeof (req), 0))
 	    {
 	      if (debug_level > 0)
 		dbg_log (_("short read while reading request: %s"),
@@ -469,7 +472,8 @@ nscd_run (void *p)
 	  /* It should not be possible to crash the nscd with a silly
 	     request (i.e., a terribly large key).  We limit the size
 	     to 1kb.  */
-	  if (req.key_len < 0 || req.key_len > 1024)
+	  if (__builtin_expect (req.key_len, 1) < 0
+	      || __builtin_expect (req.key_len, 1) > 1024)
 	    {
 	      if (debug_level > 0)
 		dbg_log (_("key length in request too long: %d"), req.key_len);
@@ -481,8 +485,9 @@ nscd_run (void *p)
 	      /* Get the key.  */
 	      char keybuf[req.key_len];
 
-	      if (TEMP_FAILURE_RETRY (read (fd, keybuf, req.key_len))
-		  != req.key_len)
+	      if (__builtin_expect (TEMP_FAILURE_RETRY (read (fd, keybuf,
+							      req.key_len))
+				    != req.key_len, 0))
 		{
 		  if (debug_level > 0)
 		    dbg_log (_("short read while reading request key: %s"),
diff --git a/nscd/grpcache.c b/nscd/grpcache.c
index 5e037b5b1f..93a7a0d86d 100644
--- a/nscd/grpcache.c
+++ b/nscd/grpcache.c
@@ -170,7 +170,7 @@ cache_addgr (struct database *db, int fd, request_header *req, void *key,
       memcpy (cp, buf, n);
 
       /* Write the result.  */
-      written = write (fd, &data->resp, total);
+      written = TEMP_FAILURE_RETRY (write (fd, &data->resp, total));
 
       /* Compute the timeout time.  */
       t += db->postimeout;
@@ -187,7 +187,7 @@ cache_addgr (struct database *db, int fd, request_header *req, void *key,
       pthread_rwlock_unlock (&db->lock);
     }
 
-  if (written != total && debug_level > 0)
+  if (__builtin_expect (written != total, 0) && debug_level > 0)
     {
       char buf[256];
       dbg_log (_("short write in %s: %s"),  __FUNCTION__,
diff --git a/nscd/hstcache.c b/nscd/hstcache.c
index 3e8c370b70..c7cdc4deb4 100644
--- a/nscd/hstcache.c
+++ b/nscd/hstcache.c
@@ -200,7 +200,7 @@ cache_addhst (struct database *db, int fd, request_header *req, void *key,
       /* We write the dataset before inserting it to the database
 	 since while inserting this thread might block and so would
 	 unnecessarily let the receiver wait.  */
-      written = write (fd, data, total);
+      written = TEMP_FAILURE_RETRY (write (fd, data, total));
 
       addr_list_type = (hst->h_length == NS_INADDRSZ
 			? GETHOSTBYADDR : GETHOSTBYADDRv6);
@@ -272,7 +272,7 @@ cache_addhst (struct database *db, int fd, request_header *req, void *key,
       pthread_rwlock_unlock (&db->lock);
     }
 
-  if (written != total && debug_level > 0)
+  if (__builtin_expect (written != total, 0) && debug_level > 0)
     {
       char buf[256];
       dbg_log (_("short write in %s: %s"),  __FUNCTION__,
diff --git a/nscd/pwdcache.c b/nscd/pwdcache.c
index 88990ad30a..94d8bd2d55 100644
--- a/nscd/pwdcache.c
+++ b/nscd/pwdcache.c
@@ -166,7 +166,7 @@ cache_addpw (struct database *db, int fd, request_header *req, void *key,
       /* We write the dataset before inserting it to the database
 	 since while inserting this thread might block and so would
 	 unnecessarily let the receiver wait.  */
-      written = write (fd, &data->resp, total);
+      written = TEMP_FAILURE_RETRY (write (fd, &data->resp, total));
 
       /* Compute the timeout time.  */
       t += db->postimeout;
@@ -183,7 +183,7 @@ cache_addpw (struct database *db, int fd, request_header *req, void *key,
       pthread_rwlock_unlock (&db->lock);
     }
 
-  if (written != total && debug_level > 0)
+  if (__builtin_expect (written != total, 0) && debug_level > 0)
     {
       char buf[256];
       dbg_log (_("short write in %s: %s"),  __FUNCTION__,