Am Donnerstag, 6. Dezember 2007 schrieb Julian Seward:
> > It is 100% repeatable for me but, interestingly, only on my machine at
> > home. My machine at work doesn't have the same problem. Both are
> > x86_64 machines with two cores and 4Gb of memory and both are running
> > Fedora 8!
>
> This probably sounds like a really dumbass question, but .. do the two
> machines have the same CPUs?  I ask because just recently Christoph
> Bartoschek (IIRC) reported some strangeness to do with memory
> corruption and CPUs.  Or something.  Christoph, can you summarise
> what it is you found?

We could resolve the strangeness by updating the linux kernel.
The kernel comming with opensuse 10.2 had the error. Updating Opensuse to 10.3 
resolved the issues. Our sysadmin tells me that all distributions with 
kernels smaller than or equal to 2.6.18 showed the error.

I have attached the testprogram that forces the error. This program forces the 
error after running about 10 - 60 minutes. If it runs longer than 60 minutes 
it does not fail.

The program just allocates a big array and increments the values inside. The 
program fails if the expected value is not in a memory cell.

The program shows the error when it is run natively. It is not run as a 
valgrind client.

I've only used in our machines with 64 GiB of memory and used 67 as the 
parameter. 

I would expect that you have to change the program to allocate only 4.1 GiB on 
a 4 GiB machine. Currently it accepts only full GiB steps.

You should also adapt the number of threads to the available number of cores.

Greetings
Christoph
#include <iostream>
#include <sstream>

extern "C" {
#include <pthread.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
}

typedef unsigned long long u64;


static u64 const blocks = 4096;

static u64 total_mem;
static u64 block_len;

unsigned char * mem;


struct BlockInfo {

   BlockInfo() : value(0) {
      pthread_mutex_init(&mutex, NULL);
   }

   char prepadding[128];
   unsigned char value;
   pthread_mutex_t mutex;
   char postpadding[128];
};

BlockInfo blockinfo[blocks];

extern "C" void * run(void * ) {

   int fd = open("/dev/urandom", O_RDONLY);

   if (fd < 0) {
      std::cout << "Could not open random" << std::endl;
      exit(-1);
   }

   while (true) {

      unsigned char p;
      u64 block;

      read(fd, &p, sizeof(unsigned char));
      read(fd, &block, sizeof(block));

      block = block % blocks;

      pthread_mutex_lock(&(blockinfo[block].mutex));
         u64 start = block * block_len;
         u64 stop = (block + 1) * block_len;

         for (u64 i = start; i < stop; ++i) {
            if (mem[i] != blockinfo[block].value) {
               std::cout << "PthreadId: " << pthread_self() << std::endl
                         << "Block: " << block << "  Startaddress: " << (void *) &mem[start] << "  Stopaddress: " << (void *) &mem[stop] << std::endl
                         << "Element: " << i << "  Element in block: " << (i-start) << "  Address: " << (void *) &mem[i] << std::endl
                         << "Value: " << (int) mem[i] << "  Expected: " << (int) blockinfo[block].value << std::endl;
               exit(-1);
            }
         }

         blockinfo[block].value = mem[start] + p;

         for (u64 i = start; i < stop; ++i) {
            mem[i] += p;
         }
      pthread_mutex_unlock(&(blockinfo[block].mutex));
   }
}

int main(int argc, char ** argv) {

   // Extract used memory
   if (argc != 2) {
      std::cerr << "Usage: " << argv[0] << "  <Used mem>\nUsed is in GiB\n";
      exit(-1);
   }

   std::stringstream ss(argv[1]);
   ss >> total_mem;
   if (not ss) {
      std::cerr << "Could not extract memory from: " << argv[1] << std::endl;
      exit(-1);
   }

   total_mem *= 1024ULL * 1024ULL * 1024ULL;
   block_len = total_mem / blocks;

   mem = new unsigned char[total_mem];

   for (u64 i = 0; i < total_mem; ++i) {
      mem[i] = 0;
   }

   std::cout << "Starting threads\n";

   pthread_t pid;
   for (int i = 0; i < 8; ++i) pthread_create(&pid, NULL, run, NULL);
-------------------------------------------------------------------------
SF.Net email is sponsored by: The Future of Linux Business White Paper
from Novell.  From the desktop to the data center, Linux is going
mainstream.  Let it simplify your IT future.
http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4
_______________________________________________
Valgrind-developers mailing list
Valgrind-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-developers

Reply via email to