TechTalkz.com Logo Ask the Expert

Go Back   TechTalkz.com Technology & Computer Troubleshooting Forums > Tech Support Archives > Microsoft > Microsoft Device Drivers

Notices

Cache promble

Microsoft Device Drivers


Reply
 
Thread Tools Display Modes
Old 20-06-2008, 11:05 PM   #1
Danial.F
Guest
 
Posts: n/a
Cache promble

Hi all,
I got a amazing problem of cache.
In a driver, I allocate a block of memory using
MmAllocateContiguousMemorySpecifyCache, and I set the cache type to
MmNonCached. Then I map this memory into user mode using
MmMapLockedPagesSpecifyCache where I also set the cache type to MmNonCached.
So, here, both the driver and the application can access the shared memory.
The problem comes up:
assume pDriver is a system space virtual address and pApp is a user space
virtual address and they both point to the same physical memory address.
first, set a value in driver, *pDriver = 1; read the value in application
and I get the value 1; second, set a value in driver *pDriver = 2; read the
value in application but this time I still get the value 1; third, *pDriver =
3; read the value and get the value 2; and so on...
So, from the 2nd time on, the driver set a new value but the application
always get the previous value set by driver last time.

Is it caused by cache? But I've already set the cache type as MmNonCached.
Anyone can explain this problem?

If the cache type is set to MmNonCached for MmMapLockedPagesSpecifyCache
and MmAllocateContiguousMemorySpecifyCache, the memory will not be cached to
any level of cache(both L1 and L2) or may be cached in a certain level of
cache(L1 or L2? ) Anybody know this?
  Reply With Quote
Old 21-06-2008, 01:56 AM   #2
Kalle Olavi Niemitalo
Guest
 
Posts: n/a
Re: Cache promble

Danial.F <DanialF@discussions.microsoft.com> writes:

> first, set a value in driver, *pDriver = 1; read the value in application
> and I get the value 1; second, set a value in driver *pDriver = 2; read the
> value in application but this time I still get the value 1;


Did you inspect the machine instructions generated by the
compiler, to verify that the driver actually writes the values to
memory, and the application actually reads them from memory,
instead of getting cached values from registers? If that is the
problem, then declaring your pointers as pointing to volatile
data should help.
  Reply With Quote
Old 21-06-2008, 03:00 AM   #3
Danial.F
Guest
 
Posts: n/a
Re: Cache promble

From the asm instructions, i definitely see that the value is moved to memory
and the value is than moved from memory to a temp value for printing out to
screen.

The value is set in the driver and read in an application, they could be in
different thread contexts. How can they get a different value?

"Kalle Olavi Niemitalo" wrote:

> Danial.F <DanialF@discussions.microsoft.com> writes:
>
> > first, set a value in driver, *pDriver = 1; read the value in application
> > and I get the value 1; second, set a value in driver *pDriver = 2; read the
> > value in application but this time I still get the value 1;

>
> Did you inspect the machine instructions generated by the
> compiler, to verify that the driver actually writes the values to
> memory, and the application actually reads them from memory,
> instead of getting cached values from registers? If that is the
> problem, then declaring your pointers as pointing to volatile
> data should help.
>

  Reply With Quote
Reply

Thread Tools
Display Modes



< Home - Windows Help - MS Office Help - Hardware Support >


New To Site? Need Help?

All times are GMT +5.5. The time now is 05:26 AM.


vBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO
Copyright © 2005-2010, TechTalkz.com. All Rights Reserved - Privacy Policy
Valid XHTML 1.0 Transitional