LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-16-2011, 02:57 PM   #1
gaz250587
LQ Newbie
 
Registered: Jul 2011
Posts: 4

Rep: Reputation: Disabled
Shared memory problem


Hi Guys,

I'm hoping i've come to the right place and someone can help me here!

I'm doing some work for a client, they have upgraded the processor in one of their products due to redundancy issues. They were running linux with a custom application that uses a kernel module to gather data from the PCI port which then sticks the data in a shared memory space for a GUI app to pick up and display on the screen.

My job was to port this existing platform over to the new processor, I think its a AMD Geode... same processor family before but has double the RAM (256MB now).

Problem is, the shared memory doesn't work on the new processor. Everything else is exactly the same as before! I tried putting dummy data from the kernel module in the shared memory space, but the GUI application can only read 0's from the shared memory space.

its quite a complicated problem to explain, I can post code if need be and provide more information, but I was wondering if anyone would know why shared memory space could fail when the difference between the new and old processor is just bigger RAM.

I don't know enough about linux to even begin trying to fix it! Apologies if I've done a terrible job of explaining the problem! If anyone can even suggest something that would be great! The person who write the existing code isn't available so i'm trying to understand it! I'm not sure if you have to reserve a particular area of memory if you want to share it!
 
Old 07-16-2011, 04:22 PM   #2
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
What method of shared memory are you using, i.e. shmat or mmap?
Kevin Barry
 
Old 07-16-2011, 04:26 PM   #3
gaz250587
LQ Newbie
 
Registered: Jul 2011
Posts: 4

Original Poster
Rep: Reputation: Disabled
Hi,

the GUI app uses mmap, which should return a pointer to the shared memory. The kernel module, I think uses kalloc or something (i havent got the code with me so that could be wrong). I dont see any absolute addresses being used.

The kernel module sort of saves itself in /dev . The GUI app then opens the kernel module as a file read operation. Not sure if that helps or not!
 
Old 07-16-2011, 05:26 PM   #4
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
So it creates a character device or something similar? I don't believe that's actually shared memory since the module could easily generate data as it's accessed. Does the GUI read the same number of bytes as are written by the module? Can it read 0s even if nothing is written to the file first? Also, if mmap is used, why is read also used? I can't really help with the module, but please post a minimal main function that would replicate the problem were I to have the module running.
Kevin Barry
 
Old 07-16-2011, 05:32 PM   #5
gaz250587
LQ Newbie
 
Registered: Jul 2011
Posts: 4

Original Poster
Rep: Reputation: Disabled
Yes I believe it is a character device! And yes it does read the same amount of bytes written by the module! The functionality is basically a oscilloscope. So the module writes data from the PCI (which is written to by an FPGA reading an ADC) into this 'shared memory' buffer and the GUI app reads it and draws it on the screen.

It may open the device as read and write...not just read.

Ill post the code, guess that will help alot!

Someone mentioned to me that the kernel has to reserve memory? I got told to look at menu.lst in /boot/grub... didn't help much though!
 
Old 07-23-2011, 05:33 AM   #6
gaz250587
LQ Newbie
 
Registered: Jul 2011
Posts: 4

Original Poster
Rep: Reputation: Disabled
Hi,

So this is the code that opens up the module, and then gets a pointer to the shared memory using mmap. struct sample is basically just a structure used to store data for 8 input channels which is stored in the shared memory.
Code:
file_desc = open("/dev/capture/0", O_RDWR);
data_start = (struct sample *)mmap(0, LEN, PROT_READ | PROT_WRITE, MAP_SHARED, file_desc, 0);
This code is in the module. Not sure if the first bit with kmalloc_area is useful but i thought id post it anyway. allocator_allocate_dma is another module, not sure if its a standard module or not but I have the code for it.

Code:
kmalloc_area = (int *)__get_free_pages(GFP_KERNEL,1);
for (virt_addr=(unsigned long)kmalloc_area; virt_addr<(unsigned long)kmalloc_area+0x1000; virt_addr+=PAGE_SIZE)
{
     // reserve all pages to make them remapable
     mem_map_reserve(virt_to_page(virt_addr));
}       
my_mem = allocator_allocate_dma (LEN, GFP_KERNEL);
if (!my_mem)
{
     printk(KERN_WARNING "Cant allocate memory!\n");
}
printk ("my_mem = %lx\nremapping!\n", my_mem);
mem_ptr = ioremap(my_mem, LEN);
Any help would be appreciated im very stuck!

Thanks
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
shared memory problem shayke23 Linux - Kernel 3 06-15-2009 12:32 PM
Linux shared memory segment access problem and x86 Virtual Memory layout. regmee Linux - Kernel 1 08-23-2008 12:11 AM
Difference between resident memory,shared memory and virtual memory in system monitor mathimca05 Linux - Newbie 1 11-11-2007 04:05 AM
Gdk shared memory problem pandersson61 Linux - Software 2 03-17-2006 02:31 AM
Problem with shared memory in C under Linux d1s4st3r Programming 4 06-29-2005 03:34 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:39 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration