View topic - How to increase speed of copying memory?

How to increase speed of copying memory?

anything that doesn't fit to other groups.

How to increase speed of copying memory?

Postby xuyong » Tue Jan 06, 2004 12:39 am

I try to copy one memory block to another,using memcpy(&a,&b,size),the cost time is more than 3ms,but the expected cost time is below 1.5ms,how to do? by the way,I use pci bus to read data,first I use mmap() map one memory block,second the hardware send a interrupt,during the thread for the interrupt I do the work copying memory,but the shortest interrupt delay time is about 2.5ms,so sometimes the data is losted.
xuyong
Senior Member
 
Posts: 431
Joined: Sun Mar 02, 2003 7:52 am

Postby bjchip » Tue Jan 06, 2004 2:35 am

If you are getting data from the PCI bus, is that data being passed async on the bus or is it properly set up for DMA. There's a HUGE difference in PCI bus performance if you haven't got the DMA set up. Copying across the PCI bus means you should be looking at the actual PCI interface chipset if you are time critical. Also a consideration, what else is going on on the PCI bus at the instant. Your post implies that it doesn't always fail,. sometimes it is fast enough. That leads me to infer that there is another thread of execution playing on the PCI bus.

respectfully
BJ
bjchip
Active Member
 
Posts: 46
Joined: Wed Nov 26, 2003 10:20 pm

Postby xuyong » Tue Jan 06, 2004 2:39 am

how to setup DMA?thanks
xuyong
Senior Member
 
Posts: 431
Joined: Sun Mar 02, 2003 7:52 am

Postby rick » Tue Jan 06, 2004 3:29 am

As bjchip said, you need to make sure you have no other bus activity which can interfere. A video card (which is a bus master) trying to update the screen at the same time you are trying to service an ISR can easily cause unexpected latency. This is the primary reason why an device with hard real time requirements should not be running a gui.

Take a look at the flags you can use with mmap() (in the helpviewer) for ways to control how the memory is mapped to facilitate DMA access.
rick
QNX Master
 
Posts: 500
Joined: Wed Nov 13, 2002 3:59 am

Postby xuyong » Tue Jan 06, 2004 5:43 am

yes,a video card share the same interrupt with my dsp card,should I stop interrupt when I service an ISR? please tell me how to solve it.
xuyong
Senior Member
 
Posts: 431
Joined: Sun Mar 02, 2003 7:52 am

Postby rick » Tue Jan 06, 2004 2:49 pm

If you have a hard realtime requirement, get rid of the video card - or any other card which is a bus master. Once the hardware controls the bus (as the video card will do), there is nothing the software can do with the bus until it is released by the hardware.
rick
QNX Master
 
Posts: 500
Joined: Wed Nov 13, 2002 3:59 am

Postby xuyong » Wed Jan 07, 2004 7:10 am

I have to show something to the customer and have one GUI programme
xuyong
Senior Member
 
Posts: 431
Joined: Sun Mar 02, 2003 7:52 am

Re: How to increase speed of copying memory?

Postby mario » Wed Jan 07, 2004 5:11 pm

xuyong wrote:I try to copy one memory block to another,using memcpy(&a,&b,size),the cost time is more than 3ms,but the expected cost time is below 1.5ms,how to do? by the way,I use pci bus to read data,first I use mmap() map one memory block,second the hardware send a interrupt,during the thread for the interrupt I do the work copying memory,but the shortest interrupt delay time is about 2.5ms,so sometimes the data is losted.


My 2 cents,

Make sure that a and b are quad aligned., going memcpy on unaligned data can be clostly, and worst over PCI bus since it's not cached and 32 bit wide.

Other possiblility is to write a version of memcpy that uses MMX instructions. sources in assembler are available on Intel and AMD site if my memory servers me right, but aren't written for gnu asm.
mario
QNX Master
 
Posts: 4132
Joined: Sun Sep 01, 2002 1:04 am

Postby bjchip » Wed Jan 07, 2004 11:13 pm

How do you set up DMA?

This is generally done at the driver level for the specific card that is on the PCI bus.

Your video card doesn't HAVE to have an interrupt to deal with video AFAIK. Its absence changes the performance of the card mostly with respect to power saving. That can usually be set up in the bios for most x86 boards.

At the driver level you have to choose a block size and map CONTIGUOUS real memory to it. I am new to QNX myself so I am not sure how to do this in detail in this system, but I expect to know in another week or so :-). You transmit the address of that memory to the card on the PCI bus and tell it how you want the data sent. That's a "push" process. There is also a "pull" method in which you control the PCI card from the driver. Generally all PCI chipsets have a set of registers, a FIFO buffer or some other mechanism for handling the low level memory transfer. You can get an interrupt from the PCI card when it has transferred data into the QNX driver memory (now it is across the bus and internal memcp speeds apply) and process it out at that time.

This means you have to get down and dirty with the PCI chipset registers for your specific card and with the driver for that card. It isn't pretty if you have to do it for the first time.

That's about the limit of what I can provide. The QNX masters have to fill in the details :-)

respectfully
BJ
bjchip
Active Member
 
Posts: 46
Joined: Wed Nov 26, 2003 10:20 pm

Postby cdm » Thu Jan 08, 2004 6:33 am

BJ - how are you calling mmap()? Can you post a code snippet of what you are doing to setup the memory? I suspect you are using PROT_NOCACHE on the mapping.
cdm
QNX Master
 
Posts: 789
Joined: Fri Jul 05, 2002 9:38 am

Postby bjchip » Thu Jan 08, 2004 10:37 pm

I haven't called mmap yet. I got my copy of qnx a week ago :-)
bjchip
Active Member
 
Posts: 46
Joined: Wed Nov 26, 2003 10:20 pm

Postby noc » Thu Jan 08, 2004 11:37 pm

Guess cdm mixed up you and xuyong (original poster of the thread) :)
noc
Senior Member
 
Posts: 1634
Joined: Sat Jul 06, 2002 4:34 am

Postby cdm » Fri Jan 09, 2004 4:31 am

Yep - my bad. :) that was for the original poster.
cdm
QNX Master
 
Posts: 789
Joined: Fri Jul 05, 2002 9:38 am

Postby xuyong » Fri Jan 09, 2004 9:22 am

yes,I use PROT_NOCACHE,if I should disable the PROT_NOCACHE
xuyong
Senior Member
 
Posts: 431
Joined: Sun Mar 02, 2003 7:52 am

Postby xuyong » Fri Jan 09, 2004 11:25 am

I try to not use PROT_NOCACHE in mmap() and write the cache line in pci config register(original it is 0),but the time costed is same as before.
xuyong
Senior Member
 
Posts: 431
Joined: Sun Mar 02, 2003 7:52 am

Next

Return to General Programming

Who is online

Users browsing this forum: No registered users and 2 guests

cron