GithubHelp home page GithubHelp logo

Comments (9)

ufrisk avatar ufrisk commented on July 23, 2024 1

If you read as frequently as possible the CPU usage is going to be high. One thread will be doing PCILeech work all the time, and this is not a problem if your computer have more than CPU core.

If reading a very small value as frequently as possible I would recommend using the VMM_FLAG_NOCACHE - the last thing you want is to have your value cached for a couple of seconds before it's refreshed.

PCILeech_VmmReadEx(dwPID, vaAddressToRead, pb, cb, &cbRead, VMM_FLAG_NOCACHE);

Also there is a small delay when reading from the FPGA of of approx: 500uS which is waited in a loop (consumes a lot of cpu). The reason for this is that there is no Sleep function in Windows that will sleep the thread this short amount of time.

If you wish to tune that wait period you can do so by setting the values as per below

PCILeech_DeviceConfigSet(PCILEECH_DEVICE_OPT_FPGA_DELAY_READ, <yourvalue>);
PCILeech_DeviceConfigSet(PCILEECH_DEVICE_OPT_FPGA_DELAY_WRITE, <yourvalue>);

Please note that setting very low values may result in insability and errors. But they are very conservatively set from the beginning. If reading very small amounts of memory it may even be possible to set it to zero, but you have to try it out on your system.

from pcileech.

hrt avatar hrt commented on July 23, 2024

Are you sure it is the mem read function?
I haven't used the DLL myself but having loops without any kind of sleep will use large % of CPU regardless of what you do.

from pcileech.

false avatar false commented on July 23, 2024

Well, yes, my cpu usage focuses on these read calls. I managed to optimize them a bit by reading big chunks at a time then access directly the elements through memory. But it's still not perfect.
I think I can do something with the cache options though. I am currently testing if I can get something quite good out of the option "PCILEECH_VMM_CONFIG_READCACHE_TICKS" .

from pcileech.

hrt avatar hrt commented on July 23, 2024

Pretty sure there's a good reason there are some delays (hoping someone will tell me why) but I changed the config:
DELAY_READ to 0 in (for me) devicefpga.c
code runs about 3 times faster.
I've also tried caching virtual to physical mappings myself (I'm not using the dll) but surprisingly it was more of a performance hit than boost.
Might re-try the caching though

from pcileech.

hrt avatar hrt commented on July 23, 2024

update : caching efficiently further cut my speed by a factor of at least 6
I'm doing quite a lot of reads in 20ms using pciescreamer

but there are less error checks (cache is made to refresh the mapping for that virtual address every 2000 times it is accessed) -> room for error

from pcileech.

hrt avatar hrt commented on July 23, 2024
QWORD VirtualToPhysical(_Inout_ PPCILEECH_CONTEXT ctx, QWORD virtualAddress)
{
  QWORD pageBase, pageSize;
  DWORD offset = virtualAddress % CACHE_SIZE;
  if (!cache[offset].physicalAddress | cache[offset].hits > RETRY_COUNT | !cache[offset].result)
  {
    cache[offset].result = Util_PageTable_Virtual2Physical(ctx, ctx->cfg->qwCR3, virtualAddress, &(cache[offset].physicalAddress), &pageBase, &pageSize);
    cache[offset].physicalAddress *= cache[offset].result; 
  }
  cache[offset].hits += 1;
  return cache[offset].physicalAddress;
}

I'm not sure how this all goes into play with the dll because I haven't touched/looked at it

from pcileech.

false avatar false commented on July 23, 2024

Yes, PCILeech_DeviceConfigSet(PCILEECH_DEVICE_OPT_FPGA_DELAY_READ, 1); fixed my problem to be honnest ; Or at least I can't notice any kind of bad performance anymore.

On the same kind of subject, I have noticed a big usage of memory by pcileech. Is that because you cache everything ? I did not have the time to check sources about it yet.
I have about 150MB referenced under pcileech.dll in my application memory usage.
Is that normal ? Anyway to optimize it as I don't use the pcileech cache at all ?

from pcileech.

ufrisk avatar ufrisk commented on July 23, 2024

If you initialize the VMM the cache will always be created. This takes up quite some memory. Even if you do not use the read cache you'll use the page table cache and process cache.

But is this super important? 150MB may be big but it's not huge; and computers usually have gigabytes of memory these days ...

from pcileech.

false avatar false commented on July 23, 2024

No it is not an issue at all indeed. I just wanted to make sure it was the normal behavior, not a leak or anything. Ty

from pcileech.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.