Gabe Black has submitted this change. ( https://gem5-review.googlesource.com/c/public/gem5/+/50763 )

 (

11 is the latest approved patch-set.
No files were changed between the latest approved patch-set and the submitted one.
 )Change subject: dev,gpu-compute: Use a TranslationGen in DmaVirtDevice.
......................................................................

dev,gpu-compute: Use a TranslationGen in DmaVirtDevice.

Use a TranslationGen to iterate over the translations for a region,
rather than using a ChunkGenerator with a fixed page size the device
needs to know.

Change-Id: I5da565232bd5282074ef279ca74e556daeffef70
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/50763
Tested-by: kokoro <[email protected]>
Reviewed-by: Matthew Poremba <[email protected]>
Reviewed-by: Daniel Carvalho <[email protected]>
Maintainer: Matthew Poremba <[email protected]>
---
M src/gpu-compute/gpu_command_processor.cc
M src/gpu-compute/gpu_command_processor.hh
M src/dev/hsa/hsa_packet_processor.cc
M src/dev/hsa/hsa_packet_processor.hh
M src/dev/dma_virt_device.cc
M src/dev/dma_virt_device.hh
6 files changed, 43 insertions(+), 39 deletions(-)

Approvals:
  Matthew Poremba: Looks good to me, approved; Looks good to me, approved
  Daniel Carvalho: Looks good to me, approved
  kokoro: Regressions pass




diff --git a/src/dev/dma_virt_device.cc b/src/dev/dma_virt_device.cc
index 2a392c24..b377a03 100644
--- a/src/dev/dma_virt_device.cc
+++ b/src/dev/dma_virt_device.cc
@@ -36,11 +36,6 @@
 namespace gem5
 {

-DmaVirtDevice::DmaVirtDevice(const Params& p)
-    : DmaDevice(p), pageBytes(p.system->getPageBytes())
-{
-}
-
 void
 DmaVirtDevice::dmaReadVirt(Addr host_addr, unsigned size,
                                  DmaCallback *cb, void *data, Tick delay)
@@ -68,17 +63,13 @@
     // move the buffer data pointer with the chunks
     uint8_t *loc_data = (uint8_t*)data;

- for (ChunkGenerator gen(addr, size, pageBytes); !gen.done(); gen.next()) {
-        Addr phys;
-
-        // translate pages into their corresponding frames
-        translateOrDie(gen.addr(), phys);
+    TranslationGenPtr gen = translate(addr, size);
+    for (const auto &range: *gen) {
+ fatal_if(range.fault, "Failed translation: vaddr 0x%x", range.vaddr);

         Event *event = cb ? cb->getChunkEvent() : nullptr;
-
-        (this->*dmaFn)(phys, gen.size(), event, loc_data, delay);
-
-        loc_data += gen.size();
+        (this->*dmaFn)(range.paddr, range.size, event, loc_data, delay);
+        loc_data += range.size;
     }
 }

diff --git a/src/dev/dma_virt_device.hh b/src/dev/dma_virt_device.hh
index 5c36d7b..e38d291 100644
--- a/src/dev/dma_virt_device.hh
+++ b/src/dev/dma_virt_device.hh
@@ -35,15 +35,13 @@
 #define __DEV_DMA_VIRT_DEVICE_HH__

 #include "dev/dma_device.hh"
+#include "mem/translation_gen.hh"

 namespace gem5
 {

 class DmaVirtDevice : public DmaDevice
 {
-  private:
-    Addr pageBytes;
-
   protected:
     /**
      * Wraps a std::function object in a DmaCallback.  Much cleaner than
@@ -72,7 +70,7 @@
     };

   public:
-    DmaVirtDevice(const Params& p);
+    DmaVirtDevice(const Params& p) : DmaDevice(p) { }
     virtual ~DmaVirtDevice() { }

     /**
@@ -119,13 +117,15 @@
                  DmaCallback *cb, void *data, Tick delay = 0);

     /**
-     * Function used to translate from virtual to physical addresses. All
-     * classes inheriting from DmaVirtDevice must define this.
+     * Function used to translate a range of addresses from virtual to
+     * physical addresses. All classes inheriting from DmaVirtDevice must
+     * define this.
      *
-     * @param vaddr Input virtual address
-     * @param paddr Output physical address written by reference
+     * @param vaddr Virtual address of the start of the range
+     * @param size Size of the range in bytes
+     * @return A translation generator for this range
      */
-    virtual void translateOrDie(Addr vaddr, Addr &paddr) = 0;
+    virtual TranslationGenPtr translate(Addr vaddr, Addr size) = 0;
 };

 } // namespace gem5
diff --git a/src/dev/hsa/hsa_packet_processor.cc b/src/dev/hsa/hsa_packet_processor.cc
index 22124b1..44c0e87 100644
--- a/src/dev/hsa/hsa_packet_processor.cc
+++ b/src/dev/hsa/hsa_packet_processor.cc
@@ -162,16 +162,15 @@
     return pioDelay;
 }

-void
-HSAPacketProcessor::translateOrDie(Addr vaddr, Addr &paddr)
+TranslationGenPtr
+HSAPacketProcessor::translate(Addr vaddr, Addr size)
 {
// Grab the process and try to translate the virtual address with it; with // new extensions, it will likely be wrong to just arbitrarily grab context
     // zero.
     auto process = sys->threads[0]->getProcessPtr();

-    if (!process->pTable->translate(vaddr, paddr))
-        fatal("failed translation: vaddr 0x%x\n", vaddr);
+    return process->pTable->translateRange(vaddr, size);
 }

 /**
diff --git a/src/dev/hsa/hsa_packet_processor.hh b/src/dev/hsa/hsa_packet_processor.hh
index aabe24e..144fe42 100644
--- a/src/dev/hsa/hsa_packet_processor.hh
+++ b/src/dev/hsa/hsa_packet_processor.hh
@@ -348,7 +348,7 @@
     typedef HSAPacketProcessorParams Params;
     HSAPacketProcessor(const Params &p);
     ~HSAPacketProcessor();
-    void translateOrDie(Addr vaddr, Addr &paddr) override;
+    TranslationGenPtr translate(Addr vaddr, Addr size) override;
     void setDeviceQueueDesc(uint64_t hostReadIndexPointer,
                             uint64_t basePointer,
                             uint64_t queue_id,
diff --git a/src/gpu-compute/gpu_command_processor.cc b/src/gpu-compute/gpu_command_processor.cc
index 88d7703..a444c9d 100644
--- a/src/gpu-compute/gpu_command_processor.cc
+++ b/src/gpu-compute/gpu_command_processor.cc
@@ -65,19 +65,15 @@
     return *hsaPP;
 }

-void
-GPUCommandProcessor::translateOrDie(Addr vaddr, Addr &paddr)
+TranslationGenPtr
+GPUCommandProcessor::translate(Addr vaddr, Addr size)
 {
-    /**
-     * Grab the process and try to translate the virtual address with it;
-     * with new extensions, it will likely be wrong to just arbitrarily
-     * grab context zero.
-     */
+ // Grab the process and try to translate the virtual address with it; with + // new extensions, it will likely be wrong to just arbitrarily grab context
+    // zero.
     auto process = sys->threads[0]->getProcessPtr();

-    if (!process->pTable->translate(vaddr, paddr)) {
-        fatal("failed translation: vaddr 0x%x\n", vaddr);
-    }
+    return process->pTable->translateRange(vaddr, size);
 }

 /**
diff --git a/src/gpu-compute/gpu_command_processor.hh b/src/gpu-compute/gpu_command_processor.hh
index 1c36c2b..c9084d1 100644
--- a/src/gpu-compute/gpu_command_processor.hh
+++ b/src/gpu-compute/gpu_command_processor.hh
@@ -135,7 +135,7 @@
     typedef void (DmaDevice::*DmaFnPtr)(Addr, int, Event*, uint8_t*, Tick);
     void initABI(HSAQueueEntry *task);
     HSAPacketProcessor *hsaPP;
-    void translateOrDie(Addr vaddr, Addr &paddr) override;
+    TranslationGenPtr translate(Addr vaddr, Addr size) override;

     /**
      * Perform a DMA read of the read_dispatch_id_field_base_byte_offset

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/50763
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: I5da565232bd5282074ef279ca74e556daeffef70
Gerrit-Change-Number: 50763
Gerrit-PatchSet: 14
Gerrit-Owner: Gabe Black <[email protected]>
Gerrit-Reviewer: Andreas Sandberg <[email protected]>
Gerrit-Reviewer: Daniel Carvalho <[email protected]>
Gerrit-Reviewer: Gabe Black <[email protected]>
Gerrit-Reviewer: Giacomo Travaglini <[email protected]>
Gerrit-Reviewer: Jason Lowe-Power <[email protected]>
Gerrit-Reviewer: Matthew Poremba <[email protected]>
Gerrit-Reviewer: kokoro <[email protected]>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Reply via email to