Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* Re: [PATCH] Fix 'info os' crashes on sparc.
       [not found] <20121120.003006.1287326526424655175.davem@davemloft.net>
@ 2012-11-20  6:13 ` David Miller
  2012-11-20 14:44   ` Pedro Alves
  0 siblings, 1 reply; 3+ messages in thread
From: David Miller @ 2012-11-20  6:13 UTC (permalink / raw)
  To: gdb-patches; +Cc: stan, kcy

From: David Miller <davem@davemloft.net>
Date: Tue, 20 Nov 2012 00:30:06 -0500 (EST)

> 2012-11-19  David S. Miller  <davem@davemloft.net>
> 
> 	* common/linux-osdata.c (get_number_of_cpu_cores): Add support
> 	for parsing the layout of sparc /proc/cpuinfo files.

Actually, there is a better fix, GLIBC already has all of this /proc
parsing logic for every cpu type, and can even distinguish activated
vs. non-activated cpus.

We simply need to do sysconf(_SC_NPROCESSORS_ONLN)

The thing is, this code still has a problem.  The number of cpus
active doesn't tell us anything about what the largest cpu number
might be.

The cpus numbers themselves can be arbitrarily sparse and beyond the
number of cpus.

And it's the cpu numbers that are used to index these various tables.

gdb/

2012-11-19  David S. Miller  <davem@davemloft.net>

	* common/linux-osdata.c (get_number_of_cpu_cores): Delete.
	(linux_xfer_osdata_processes): Fetch _SC_NPROCESSORS_ONLN via
	sysconf.
	(get_cores_used_by_process): Update comment.

diff --git a/gdb/common/linux-osdata.c b/gdb/common/linux-osdata.c
index afe3e75..d54f9d3 100644
--- a/gdb/common/linux-osdata.c
+++ b/gdb/common/linux-osdata.c
@@ -26,6 +26,7 @@
 #include "linux-osdata.h"
 
 #include <sys/types.h>
+#include <sys/sysinfo.h>
 #include <ctype.h>
 #include <stdlib.h>
 #include <string.h>
@@ -253,30 +254,8 @@ get_process_owner (uid_t *owner, PID_T pid)
     return -1;
 }
 
-/* Returns the number of CPU cores found on the system.  */
-
-static int
-get_number_of_cpu_cores (void)
-{
-  int cores = 0;
-  FILE *f = fopen ("/proc/cpuinfo", "r");
-
-  while (!feof (f))
-    {
-      char buf[512];
-      char *p = fgets (buf, sizeof (buf), f);
-
-      if (p && strncmp (buf, "processor", 9) == 0)
-	++cores;
-    }
-
-  fclose (f);
-
-  return cores;
-}
-
 /* Find the CPU cores used by process PID and return them in CORES.
-   CORES points to an array of at least get_number_of_cpu_cores ()
+   CORES points to an array of at least sysconf(_SC_NPROCESSOR_ONLN)
    elements.  */
 
 static int
@@ -340,7 +319,7 @@ linux_xfer_osdata_processes (gdb_byte *readbuf,
       dirp = opendir ("/proc");
       if (dirp)
 	{
-	  const int num_cores = get_number_of_cpu_cores ();
+	  const int num_cores = sysconf (_SC_NPROCESSORS_ONLN);
 	  struct dirent *dp;
 
 	  while ((dp = readdir (dirp)) != NULL)


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

* Re: [PATCH] Fix 'info os' crashes on sparc.
  2012-11-20  6:13 ` [PATCH] Fix 'info os' crashes on sparc David Miller
@ 2012-11-20 14:44   ` Pedro Alves
  2012-11-20 17:41     ` David Miller
  0 siblings, 1 reply; 3+ messages in thread
From: Pedro Alves @ 2012-11-20 14:44 UTC (permalink / raw)
  To: David Miller; +Cc: gdb-patches, stan, kcy

On 11/20/2012 06:13 AM, David Miller wrote:

> The thing is, this code still has a problem.  The number of cpus
> active doesn't tell us anything about what the largest cpu number
> might be.
> 
> The cpus numbers themselves can be arbitrarily sparse and beyond the
> number of cpus.
> 
> And it's the cpu numbers that are used to index these various tables.
> 

Indeed.

> gdb/
> 
> 2012-11-19  David S. Miller  <davem@davemloft.net>
> 
> 	* common/linux-osdata.c (get_number_of_cpu_cores): Delete.
> 	(linux_xfer_osdata_processes): Fetch _SC_NPROCESSORS_ONLN via
> 	sysconf.
> 	(get_cores_used_by_process): Update comment.

OK.  Thanks.

-- 
Pedro Alves


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

* Re: [PATCH] Fix 'info os' crashes on sparc.
  2012-11-20 14:44   ` Pedro Alves
@ 2012-11-20 17:41     ` David Miller
  0 siblings, 0 replies; 3+ messages in thread
From: David Miller @ 2012-11-20 17:41 UTC (permalink / raw)
  To: palves; +Cc: gdb-patches, stan, kcy

From: Pedro Alves <palves@redhat.com>
Date: Tue, 20 Nov 2012 14:44:39 +0000

> On 11/20/2012 06:13 AM, David Miller wrote:
> 
>> gdb/
>> 
>> 2012-11-19  David S. Miller  <davem@davemloft.net>
>> 
>> 	* common/linux-osdata.c (get_number_of_cpu_cores): Delete.
>> 	(linux_xfer_osdata_processes): Fetch _SC_NPROCESSORS_ONLN via
>> 	sysconf.
>> 	(get_cores_used_by_process): Update comment.
> 
> OK.  Thanks.

Thanks for reviewing, committed.


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

end of thread, other threads:[~2012-11-20 17:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20121120.003006.1287326526424655175.davem@davemloft.net>
2012-11-20  6:13 ` [PATCH] Fix 'info os' crashes on sparc David Miller
2012-11-20 14:44   ` Pedro Alves
2012-11-20 17:41     ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox