linux-hotplug.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* udevd on very large systems: again
@ 2007-05-01 23:42 George Beshers
  2007-05-02 19:37 ` Kay Sievers
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: George Beshers @ 2007-05-01 23:42 UTC (permalink / raw)
  To: linux-hotplug

[-- Attachment #1: Type: text/plain, Size: 388 bytes --]


After some testing the following patch seems safe for dealing with computers
with more than 500 processors.  It occurred to me that it might be 
easier and
just as useful to note when udev is running on a large computer (e.g., >= 8p
and >= 16Gb of memory) and simply not worry about throttling at that point.

The patch should apply cleanly against udev-110.

Comments welcome.

George


[-- Attachment #2: patch --]
[-- Type: text/plain, Size: 2344 bytes --]

diff -Naur udev-110.Orig/udevd.c udev-110.new/udevd.c
--- udev-110.Orig/udevd.c	2007-05-01 08:33:39.000000000 -0400
+++ udev-110.new/udevd.c	2007-05-01 12:49:38.000000000 -0400
@@ -347,31 +347,21 @@
 
 static int cpu_count(void)
 {
-	int f;
-	char buf[65536];
+	FILE* f;
+	char buf[1024];
 	int len;
 	const char *pos;
 	int count = 0;
 
-	f = open("/proc/stat", O_RDONLY);
-	if (f == -1)
+	f = fopen("/proc/stat", "r");
+	if (f == NULL)
 		return -1;
 
-	len = read(f, buf, sizeof(buf)-1);
-	close(f);
-	if (len <= 0)
-		return -1;
-	buf[len] = '\0';
-
-	pos = strstr(buf, "cpu");
-	if (pos == NULL)
-		return -1;
-
-	while (pos != NULL) {
-		if (strncmp(pos, "cpu", 3) == 0 &&isdigit(pos[3]))
+	while (fgets(buf, 1024, f) != NULL) {
+		if (strncmp(buf, "cpu", 3) == 0 && isdigit(buf[3]))
 			count++;
-		pos = strstr(&pos[3], "cpu");
 	}
+	fclose(f);
 
 	if (count == 0)
 		return -1;
@@ -380,30 +370,46 @@
 
 static int running_processes(void)
 {
-	int f;
-	char buf[32768];
+	FILE* f;
+	char buf[1024];
 	int len;
-	int running;
+	int running = -1;
 	const char *pos;
+	int retries = 3;
 
-	f = open("/proc/stat", O_RDONLY);
-	if (f == -1)
-		return -1;
-
-	len = read(f, buf, sizeof(buf)-1);
-	close(f);
-	if (len <= 0)
-		return -1;
-	buf[len] = '\0';
-
-	pos = strstr(buf, "procs_running ");
-	if (pos == NULL)
-		return -1;
+	/*
+	 * The retries is probably overkill but the text display is
+	 * changing rapidly.on large systems (>= 512p) and so, while
+	 * I have not actually recorded an instance where the retry
+         * was used I would rather not have it fail.
+	 * 
+	 * An alternative approach would be to note when we are on
+	 * a fairly large system (8cpus and 16Gbytes say) at which
+	 * point throttling is probably not really necessary.
+	 */
+	do {
+		f = fopen("/proc/stat", "r");
+		if (f == NULL)
+			return -1;
+
+		while (fgets(buf, 1024, f) != NULL) {
+			pos = strstr(buf, "procs_running ");
+			if (pos != NULL) {
+				int res;
+				res = sscanf(pos, "procs_running %u",
+					     &running);
+				if (res == 1) {
+					fclose(f);
+					return running;
+				}
+				break;
+			}
+		}
 
-	if (sscanf(pos, "procs_running %u", &running) != 1)
-		return -1;
+		fclose(f);
+	} while (retries-- > 0);
 
-	return running;
+	return -1;
 }
 
 /* return the number of process es in our session, count only until limit */

[-- Attachment #3: Type: text/plain, Size: 286 bytes --]

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/

[-- Attachment #4: Type: text/plain, Size: 226 bytes --]

_______________________________________________
Linux-hotplug-devel mailing list  http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2007-05-03 21:12 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-05-01 23:42 udevd on very large systems: again George Beshers
2007-05-02 19:37 ` Kay Sievers
2007-05-02 21:11 ` Kay Sievers
2007-05-02 21:26 ` George Beshers
2007-05-02 21:39 ` George Beshers
2007-05-02 23:42 ` Kay Sievers
2007-05-02 23:51 ` Kay Sievers
2007-05-03 19:49 ` George Beshers
2007-05-03 21:12 ` Kay Sievers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).