View Single Post
Old 09-08-08, 01:32 AM   #1
jazzychad
bootstrapped user
 
Join Date: Sep 2008
Posts: 4
Default nvclock: map_dev_mem (mmap) returning -1

Hi All,

I am trying to run nvclock on my system so that I can slow down the fans on my two GeForce 6600's (which currently sound like jet engines). I downloaded the latest source and compiled it. When it ran I always got a segfault. I narrowed down the problem to the map_dev_mem function in src/backend/back_linux.c It is always returning -1 (error code EINVAL). Of course this causes a segfault when something tries to access the mapped data (there is no check for invalid mmap return in the code).

Here are the relevant bits of code and the output it creates:

Code:
static void *map_dev_mem (int fd, unsigned long Base, unsigned long Size)
{
        void *base;
        int mapflags = MAP_SHARED;
        unsigned long realBase, alignOff;

        realBase = (Base & ~((unsigned long)getpagesize() - 1));
        alignOff = Base - realBase;


        CBE_FPRINTF(stderr, "...getpagesize is %u - mask is 0x%x...\n", getpagesize(), ~(getpagesize() - 1));
        CBE_FPRINTF(stderr, "...sizeof(Base) = %d...\n", sizeof(Base));
        CBE_FPRINTF(stderr, "...calling mmap with the following args: \n\t 0, %u, %d, %u (0x%x) - Base %u (0x%x)...\n", Size, fd, realBase, realBase, Base, Base);

        base = mmap((void  *)0, Size + alignOff, PROT_READ|PROT_WRITE,
                    mapflags, fd, (off_t)realBase);

        CBE_FPRINTF(stderr, "...map_dev_mem returning %p + %u...\n", base, alignOff);

        return (void *) ((char *)base + alignOff);
}
Output:

Code:
...getpagesize is 4096 - mask is 0xfffff000...
...sizeof(Base) = 4...
...calling mmap with the following args: 
         0, 4096, 3, 3356495872 (0xc8101000) - Base 3356495872 (0xc8101000)...
...map_dev_mem returning 0xffffffff + 0...

...getpagesize is 4096 - mask is 0xfffff000...
...sizeof(Base) = 4...
...calling mmap with the following args: 
         0, 4096, 3, 3356491776 (0xc8100000) - Base 3356491776 (0xc8100000)...
...map_dev_mem returning 0xffffffff + 0...

...getpagesize is 4096 - mask is 0xfffff000...
...sizeof(Base) = 4...
...calling mmap with the following args: 
         0, 196607, 3, 3355443200 (0xc8000000) - Base 3355443200 (0xc8000000)...
...map_dev_mem returning 0xffffffff + 0...

...getpagesize is 4096 - mask is 0xfffff000...
...sizeof(Base) = 4...
...calling mmap with the following args: 
         0, 8192, 3, 3361738752 (0xc8601000) - Base 3361738752 (0xc8601000)...
...map_dev_mem returning 0xffffffff + 0...

...getpagesize is 4096 - mask is 0xfffff000...
...sizeof(Base) = 4...
...calling mmap with the following args: 
         0, 8192, 3, 3362258944 (0xc8680000) - Base 3362258944 (0xc8680000)...
...map_dev_mem returning 0xffffffff + 0...

...getpagesize is 4096 - mask is 0xfffff000...
...sizeof(Base) = 4...
...calling mmap with the following args: 
         0, 65535, 3, 3358588928 (0xc8300000) - Base 3358588928 (0xc8300000)...
...map_dev_mem returning 0xffffffff + 0...
... where 0xffffffff of course means -1.

strace confirms the error (output for last mmap call):
Code:
mmap2(NULL, 65535, PROT_READ|PROT_WRITE, MAP_SHARED, 3, 0xc8300) = -1 EINVAL (Invalid argument)
Does anyone have any clue why this would be happening? /dev/nvidia0 and /dev/nvidia1 both exist and have rw permissions for everybody

System specs:
Ubuntu 7.10 i686
AMD Athlon XP 2400+
2GB RAM
Asus A8N-SLI Deluxe mobo
2x PNY nVidia GeForce 6600 SLI cards
nVidia drivers: 100.14.19

My overall goal is just to be able to control the fan speeds on the 6600's, but I haven't found any other methods except for everyone raving about nvclock.

Any help is appreciated. Thanks!
jazzychad is offline   Reply With Quote