F19: getting number of cores, cachesize, etc.

Ranjan Maitra maitra.mbox.ignored at inbox.com
Sat Nov 16 14:57:08 UTC 2013


Hi,

I am running the latest updated F19 and have the following code (see
below) from a GPL'ed program (not written by me) which involves getting
the number of cores and the cache size. The program compiles and runs
fine (no valgrind errors) on i686 architecture but not on the newer
x86_64. I have localized the problem to here, because if I explicitly
give the numbers by hand, there is not an issue (there are no valgrind
errors). Any suggestions as to what is going wrong and how to fix this? 

Many thanks for any help and best wishes,
Ranjan

Here is the code: 

#define SIZE_T int

SIZE_T get_nb_cores()
{
	SIZE_T n = 0;
	char line[BS];
	FILE *fp;
	if ((fp = fopen("/proc/cpuinfo","r")) == NULL) return (1);
	while (fgets(line,BS,fp)) n += !strncmp(line,"processor",9);
	return(n);
}

SIZE_T get_cache_size()
{
	SIZE_T n = 512;
	char line[BS],c;
	FILE *fp;
	if ((fp = fopen("/proc/cpuinfo","r")) == NULL) return (1);
	while (fgets(line,BS,fp))
		if (!strncmp(line,"cache size",10)) sscanf(line+11,"%c %
d",&c,&n); return(n*1024);
}

The valgrind errors go like this:

.....................

==17144== Warning: invalid file descriptor 1031 in syscall open()

.....................

==17144==    at 0x4A06409: malloc
(in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==17144==    by 0x3EBCC6C3CC: __fopen_internal
(in /usr/lib64/libc-2.17.so) ==17144==    by 0x4149A5: get_nb_cores
(knnp.c:112)

.....................

==17144==    at 0x4A06409: malloc
(in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) ==17144==
by 0x3EBCC6C3CC: __fopen_internal (in /usr/lib64/libc-2.17.so)
==17144==    by 0x414A20: get_cache_size (knnp.c:122)

____________________________________________________________
FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks & orcas on your desktop!
Check it out at http://www.inbox.com/marineaquarium




More information about the users mailing list