TCLUG Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [TCLUG:6710] log message "kernel: Sound error: Couldn't allocate DMA buffer"



On 24 Jun, Steve Siegfried wrote:
> The funny thing about this is that after I boot, sound works just fine.
> But once that log message shows up, my PC remains mute until I reboot.
> 
> Anybody else seen something like this and possibly know the cure?
> 
Try compiling sound support into the kernel instead of loading as a
module, this has seemed to help.  I've also seen this error with older
kernels and a floppy drive.  Can't allocate DMA so I can't read the
floppy drive.  The way I fixed that was to write a program like chill
under Solaris.  It allocates memory until malloc fails then frees it. 
Then I can allocate the DMA.  I remember reading somewhere that the DMA
memory needs to be allocated in the lower 16MB of RAM, or something
funny like that.  So by allocating all my memory everything gets
swapped out and therefore isn't mapped into the lower memory addresses
and the DMA will allocate.  

This probably isn't the best answer, but it's worth a try.  Attached is
the C code for it.
-- 
Jon Schewe
schewe@tcfreenet.org
http://tcfreenet.org/~schewe
//************************************************************************
// linked list program
//
//************************************************************************

// make sure file isn't included more than once
#ifndef list_h
#define list_h

// declaration of the listnode class
template <class ntype>
class listnode{
  friend class list<ntype>;		//make list a friend
public:
  listnode(ntype &);	
private:
  ntype data;
  listnode *nextptr;
};

// declaration of class list
template<class ntype>
class list
{
public:
  list();
  ~list();
  ntype &get_firstptr_data();
  void remove(ntype &);
  void insert(ntype &);
  void search(ntype &);
  void update(ntype &);
  int isempty() const;
  void print() const;
  int getlength();

private:
  listnode<ntype> *firstptr;
  listnode<ntype> *lastptr;
  listnode<ntype> *getnewnode(ntype &);
};

//all of includes
#include <iostream.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

// listnode constructor
template<class ntype>
listnode<ntype>::listnode(ntype &info)	
{
  data = info;
  nextptr=0;
}

// default constructor
template<class ntype>
list<ntype>::list()	
{
  firstptr=lastptr = 0;
}

template<class ntype>
list<ntype>::~list()	
{
  if (!isempty())
  {
    listnode<ntype> *curptr=firstptr,*tempptr;	

    while (curptr !=0)
    {
      tempptr = curptr;
      cout <<tempptr->data<<endl;
      curptr = curptr->nextptr;
      delete tempptr;
    }
  }
}

// function that returns the length of the linked list
template<class ntype>
int list<ntype>::getlength()
{
  int num = 0;
  if(!isempty())
  {
    listnode<ntype> *curptr = firstptr;
    while(curptr != 0)
    {
      curptr = curptr->nextptr;
      num++;
    }
  }
  return num;
}

// search for a node in the list
template<class ntype>
void list<ntype>::search( ntype& value)
{
  if(isempty())
    cout << "The list is empty." << endl;
  else
  {
    listnode<ntype> *curptr = firstptr;
    while(curptr->data != value && curptr->nextptr != 0)
      curptr = curptr->nextptr;
    if(curptr->nextptr == 0)
      cout << "Not in the list" << endl;
    else
      cout << curptr->data;
  }
}

// insert a new node in the list
template<class ntype>
void list<ntype>::insert(ntype &value) 
{
  listnode<ntype> *newptr = getnewnode(value);	
  if(isempty())
  {
    firstptr = lastptr = newptr;
  }
  else
  {
    listnode<ntype> *curptr = firstptr, *tempptr = firstptr;
    while(curptr->data < value)
    {
      if(curptr->nextptr != 0)
      {
        tempptr = curptr;
        curptr = curptr->nextptr;
      }
      else
      {
        if(curptr->data != value)
        {
          curptr->nextptr = newptr;
          newptr->nextptr = 0;
          lastptr = newptr;
          return;
        }
      }
    }
    if(curptr->data != value)
    {
      if(curptr == firstptr)
      {
        newptr->nextptr = firstptr;
        firstptr = newptr;
      }
      else
      {
        tempptr->nextptr = newptr;
        newptr->nextptr = curptr;
      }
    }
    else
      cout << "Already in list.\n";
  }
}

// get the firstptr
template<class ntype>
ntype &list<ntype>::get_firstptr_data()
{
  return firstptr->data;
}

// remove a node from the list
template<class ntype>
void list<ntype>::remove(ntype &value)
{
  if (isempty())
    cout<<"The list is empty"<<endl;
  else
  {
    listnode<ntype> *currentptr,*tempptr = firstptr;
    while(tempptr->data != value)
    {
      if(tempptr->nextptr !=0)
      {
        currentptr=tempptr;
        tempptr=tempptr->nextptr;
      }
      else
      {
        cout<<value<<" is not in the list."<<endl;
        return;
      }
    }
    if(tempptr->nextptr !=0)
    {
      if (tempptr==firstptr)
      {
        //cout <<value<<" has been deleted"<<endl;
        firstptr= tempptr->nextptr;
        delete tempptr;
      }
    
      else
      {
        cout <<value<<" has been deleted"<<endl;
        currentptr->nextptr= tempptr->nextptr;
        delete tempptr;
      }
    }
    else
      if (tempptr==firstptr)
      {
        cout <<value<<" has been deleted"<<endl;
        delete tempptr;
        firstptr=lastptr=0;
        cout<<"The list is now empty"<<endl;
      }
      else if (tempptr==lastptr)
      {
        cout <<value<<" has been deleted"<<endl;
        lastptr=currentptr;
        currentptr->nextptr =0;
        delete tempptr;
      }
  }
}

// checks if the list is empty
template<class ntype>
int list<ntype>::isempty() const	
{
  return firstptr == 0;
}

// creates a new node
template<class ntype>
listnode<ntype>* list<ntype>::getnewnode(ntype&value)
{
  listnode<ntype> *ptr = new listnode<ntype>(value);	
  assert (ptr != 0);
  return ptr;
}

template<class ntype>
void list<ntype>::print() const	
{
  if (isempty())
  {
    cout << "The list is empty"<<endl;
    return ;
  }
  listnode<ntype> *curptr = firstptr;	
  cout << "The list is :  "<<endl;
  if (lastptr->nextptr==0)
    cout<<"0"<<endl;
  else
    cout <<lastptr->nextptr<<endl;
  while(curptr != 0)
  {
    cout << curptr->data<<' ';
    curptr = curptr->nextptr;
  }
  cout <<endl<<endl;
}
#endif
#include <iostream.h>
#include <stdlib.h>
#include "list.h"

// 1Mb
#define CHUNK 1048576
int main()
{
  list<void *> ptrs;
  void *ptr;
  unsigned int i = 0;
  int *int_ptr;

  // allocate 1 chunk at a time and add the pointer to the list so we can later
  // free it
  while(NULL != (ptr = malloc(CHUNK)))
  {
    // put random numbers into the data
    int_ptr = (int *)ptr;
    for(int j=0; j<CHUNK/sizeof(int); j++)
      int_ptr[j] = rand();
    
    cout << "i=" << i << endl;;
    ptrs.insert(ptr);
    i++;
  }

  cout << "Allocated " << i << "Mb of memory\n";
  
  while(!ptrs.isempty())
  {
    free(ptrs.get_firstptr_data());
    ptrs.remove(ptrs.get_firstptr_data());
  }

  cout << "Successfully freed the memory\n";
}