From mboxrd@z Thu Jan 1 00:00:00 1970 From: George Beshers Date: Tue, 01 May 2007 23:42:09 +0000 Subject: udevd on very large systems: again Message-Id: <4637D051.7060103@sgi.com> MIME-Version: 1 Content-Type: multipart/mixed; boundary="------------020903050106060708000900" List-Id: To: linux-hotplug@vger.kernel.org This is a multi-part message in MIME format. --------------020903050106060708000900 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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 --------------020903050106060708000900 Content-Type: text/plain; name="patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="patch" 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 */ --------------020903050106060708000900 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline ------------------------------------------------------------------------- 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/ --------------020903050106060708000900 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ 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 --------------020903050106060708000900--