All of lore.kernel.org
 help / color / mirror / Atom feed
* libsepol optimization
@ 2007-08-28 20:08 Ulrich Drepper
  0 siblings, 0 replies; only message in thread
From: Ulrich Drepper @ 2007-08-28 20:08 UTC (permalink / raw)
  To: SE-Linux


[-- Attachment #1.1: Type: text/plain, Size: 460 bytes --]

First in a serious or changes proposed for libsepol.

The first is a little patch which shrinks the DSO by 4.3%.  The
next_entry and put_entry functions are marked inline.  These are not
good candidates, the code is too big.  I bet without inlining them the
code actually runs faster because the i-cache isn't so polluted.  Plus
the savings in memory of course.

-- 
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖


[-- Attachment #1.2: d-libsepol-uninline --]
[-- Type: text/plain, Size: 2944 bytes --]

diff -durp libsepol-2.0.7/src/private.h libsepol-2.0.7-new/src/private.h
--- libsepol-2.0.7/src/private.h	2007-08-23 13:52:45.000000000 -0700
+++ libsepol-2.0.7-new/src/private.h	2007-08-28 12:26:46.000000000 -0700
@@ -7,6 +7,7 @@
 #include <byteswap.h>
 #include <endian.h>
 #include <errno.h>
+#include <dso.h>
 
 #if __BYTE_ORDER == __LITTLE_ENDIAN
 #define cpu_to_le16(x) (x)
@@ -41,52 +42,6 @@ extern struct policydb_compat_info *poli
 							   unsigned int type);
 
 /* Reading from a policy "file". */
-static inline int next_entry(void *buf, struct policy_file *fp, size_t bytes)
-{
-	size_t nread;
-
-	switch (fp->type) {
-	case PF_USE_STDIO:
-		nread = fread(buf, bytes, 1, fp->fp);
-		if (nread != 1)
-			return -1;
-		break;
-	case PF_USE_MEMORY:
-		if (bytes > fp->len)
-			return -1;
-		memcpy(buf, fp->data, bytes);
-		fp->data += bytes;
-		fp->len -= bytes;
-		break;
-	default:
-		return -1;
-	}
-	return 0;
-}
-
-static inline size_t put_entry(const void *ptr, size_t size, size_t n,
-			       struct policy_file *fp)
-{
-	size_t bytes = size * n;
-
-	switch (fp->type) {
-	case PF_USE_STDIO:
-		return fwrite(ptr, size, n, fp->fp);
-	case PF_USE_MEMORY:
-		if (bytes > fp->len) {
-			errno = ENOSPC;
-			return 0;
-		}
-
-		memcpy(fp->data, ptr, bytes);
-		fp->data += bytes;
-		fp->len -= bytes;
-		return n;
-	case PF_LEN:
-		fp->len += bytes;
-		return n;
-	default:
-		return 0;
-	}
-	return 0;
-}
+extern int next_entry(void *buf, struct policy_file *fp, size_t bytes) hidden;
+extern size_t put_entry(const void *ptr, size_t size, size_t n,
+		        struct policy_file *fp) hidden;
diff -durp libsepol-2.0.7/src/services.c libsepol-2.0.7-new/src/services.c
--- libsepol-2.0.7/src/services.c	2007-08-23 13:52:45.000000000 -0700
+++ libsepol-2.0.7-new/src/services.c	2007-08-28 12:25:58.000000000 -0700
@@ -927,6 +927,58 @@ static int convert_context(sepol_securit
 	return rc;
 }
 
+/* Reading from a policy "file". */
+int hidden next_entry(void *buf, struct policy_file *fp, size_t bytes)
+{
+	size_t nread;
+
+	switch (fp->type) {
+	case PF_USE_STDIO:
+		nread = fread(buf, bytes, 1, fp->fp);
+
+		if (nread != 1)
+			return -1;
+		break;
+	case PF_USE_MEMORY:
+		if (bytes > fp->len)
+			return -1;
+		memcpy(buf, fp->data, bytes);
+		fp->data += bytes;
+		fp->len -= bytes;
+		break;
+	default:
+		return -1;
+	}
+	return 0;
+}
+
+size_t hidden put_entry(const void *ptr, size_t size, size_t n,
+			struct policy_file *fp)
+{
+	size_t bytes = size * n;
+
+	switch (fp->type) {
+	case PF_USE_STDIO:
+		return fwrite(ptr, size, n, fp->fp);
+	case PF_USE_MEMORY:
+		if (bytes > fp->len) {
+			errno = ENOSPC;
+			return 0;
+		}
+
+		memcpy(fp->data, ptr, bytes);
+		fp->data += bytes;
+		fp->len -= bytes;
+		return n;
+	case PF_LEN:
+		fp->len += bytes;
+		return n;
+	default:
+		return 0;
+	}
+	return 0;
+}
+
 /*
  * Read a new set of configuration data from 
  * a policy database binary representation file.

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2007-08-29 16:45 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-08-28 20:08 libsepol optimization Ulrich Drepper

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.