diff options
author | Tom St Denis <tom.stdenis@amd.com> | 2017-07-31 09:35:24 -0400 |
---|---|---|
committer | Alex Deucher <alexander.deucher@amd.com> | 2017-08-17 15:45:59 -0400 |
commit | aca817181273d9c765ef61ab7674e5c8a4b727ca (patch) | |
tree | 11c99408e06b4a84f55c26e4bfd54a4965473707 /drivers/gpu/drm/amd/amdgpu | |
parent | dbcca4aab1b2e1983e5432cb2a1d4f5f1d8b4750 (diff) |
drm/amd/amdgpu: Add tracepoint for DMA page mapping (v4)
This helps map DMA addresses back to physical addresses.
Signed-off-by: Tom St Denis <tom.stdenis@amd.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
(v2): Added tracepoints for USERPTR, SG mappings, and
SWIOTBL mappings. Reformatted trace call perform
PCI decoding internal to the trace.
(v3): Add unmap tracepoints as well
(v4): Move traces into separate functions
Diffstat (limited to 'drivers/gpu/drm/amd/amdgpu')
-rw-r--r-- | drivers/gpu/drm/amd/amdgpu/amdgpu_trace.h | 56 | ||||
-rw-r--r-- | drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 56 |
2 files changed, 106 insertions, 6 deletions
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_trace.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_trace.h index 9ab58245e518..d8cd3e554488 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_trace.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_trace.h | |||
@@ -14,6 +14,62 @@ | |||
14 | #define AMDGPU_JOB_GET_TIMELINE_NAME(job) \ | 14 | #define AMDGPU_JOB_GET_TIMELINE_NAME(job) \ |
15 | job->base.s_fence->finished.ops->get_timeline_name(&job->base.s_fence->finished) | 15 | job->base.s_fence->finished.ops->get_timeline_name(&job->base.s_fence->finished) |
16 | 16 | ||
17 | TRACE_EVENT(amdgpu_ttm_tt_populate, | ||
18 | TP_PROTO(struct amdgpu_device *adev, uint64_t dma_address, uint64_t phys_address), | ||
19 | TP_ARGS(adev, dma_address, phys_address), | ||
20 | TP_STRUCT__entry( | ||
21 | __field(uint16_t, domain) | ||
22 | __field(uint8_t, bus) | ||
23 | __field(uint8_t, slot) | ||
24 | __field(uint8_t, func) | ||
25 | __field(uint64_t, dma) | ||
26 | __field(uint64_t, phys) | ||
27 | ), | ||
28 | TP_fast_assign( | ||
29 | __entry->domain = pci_domain_nr(adev->pdev->bus); | ||
30 | __entry->bus = adev->pdev->bus->number; | ||
31 | __entry->slot = PCI_SLOT(adev->pdev->devfn); | ||
32 | __entry->func = PCI_FUNC(adev->pdev->devfn); | ||
33 | __entry->dma = dma_address; | ||
34 | __entry->phys = phys_address; | ||
35 | ), | ||
36 | TP_printk("%04x:%02x:%02x.%x: 0x%llx => 0x%llx", | ||
37 | (unsigned)__entry->domain, | ||
38 | (unsigned)__entry->bus, | ||
39 | (unsigned)__entry->slot, | ||
40 | (unsigned)__entry->func, | ||
41 | (unsigned long long)__entry->dma, | ||
42 | (unsigned long long)__entry->phys) | ||
43 | ); | ||
44 | |||
45 | TRACE_EVENT(amdgpu_ttm_tt_unpopulate, | ||
46 | TP_PROTO(struct amdgpu_device *adev, uint64_t dma_address, uint64_t phys_address), | ||
47 | TP_ARGS(adev, dma_address, phys_address), | ||
48 | TP_STRUCT__entry( | ||
49 | __field(uint16_t, domain) | ||
50 | __field(uint8_t, bus) | ||
51 | __field(uint8_t, slot) | ||
52 | __field(uint8_t, func) | ||
53 | __field(uint64_t, dma) | ||
54 | __field(uint64_t, phys) | ||
55 | ), | ||
56 | TP_fast_assign( | ||
57 | __entry->domain = pci_domain_nr(adev->pdev->bus); | ||
58 | __entry->bus = adev->pdev->bus->number; | ||
59 | __entry->slot = PCI_SLOT(adev->pdev->devfn); | ||
60 | __entry->func = PCI_FUNC(adev->pdev->devfn); | ||
61 | __entry->dma = dma_address; | ||
62 | __entry->phys = phys_address; | ||
63 | ), | ||
64 | TP_printk("%04x:%02x:%02x.%x: 0x%llx => 0x%llx", | ||
65 | (unsigned)__entry->domain, | ||
66 | (unsigned)__entry->bus, | ||
67 | (unsigned)__entry->slot, | ||
68 | (unsigned)__entry->func, | ||
69 | (unsigned long long)__entry->dma, | ||
70 | (unsigned long long)__entry->phys) | ||
71 | ); | ||
72 | |||
17 | TRACE_EVENT(amdgpu_mm_rreg, | 73 | TRACE_EVENT(amdgpu_mm_rreg, |
18 | TP_PROTO(unsigned did, uint32_t reg, uint32_t value), | 74 | TP_PROTO(unsigned did, uint32_t reg, uint32_t value), |
19 | TP_ARGS(did, reg, value), | 75 | TP_ARGS(did, reg, value), |
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c index c803b082324d..00817b9712df 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | |||
@@ -43,6 +43,7 @@ | |||
43 | #include <linux/pagemap.h> | 43 | #include <linux/pagemap.h> |
44 | #include <linux/debugfs.h> | 44 | #include <linux/debugfs.h> |
45 | #include "amdgpu.h" | 45 | #include "amdgpu.h" |
46 | #include "amdgpu_trace.h" | ||
46 | #include "bif/bif_4_1_d.h" | 47 | #include "bif/bif_4_1_d.h" |
47 | 48 | ||
48 | #define DRM_FILE_PAGE_OFFSET (0x100000000ULL >> PAGE_SHIFT) | 49 | #define DRM_FILE_PAGE_OFFSET (0x100000000ULL >> PAGE_SHIFT) |
@@ -662,6 +663,38 @@ release_pages: | |||
662 | return r; | 663 | return r; |
663 | } | 664 | } |
664 | 665 | ||
666 | static void amdgpu_trace_dma_map(struct ttm_tt *ttm) | ||
667 | { | ||
668 | struct amdgpu_device *adev = amdgpu_ttm_adev(ttm->bdev); | ||
669 | struct amdgpu_ttm_tt *gtt = (void *)ttm; | ||
670 | unsigned i; | ||
671 | |||
672 | if (unlikely(trace_amdgpu_ttm_tt_populate_enabled())) { | ||
673 | for (i = 0; i < ttm->num_pages; i++) { | ||
674 | trace_amdgpu_ttm_tt_populate( | ||
675 | adev, | ||
676 | gtt->ttm.dma_address[i], | ||
677 | page_to_phys(ttm->pages[i])); | ||
678 | } | ||
679 | } | ||
680 | } | ||
681 | |||
682 | static void amdgpu_trace_dma_unmap(struct ttm_tt *ttm) | ||
683 | { | ||
684 | struct amdgpu_device *adev = amdgpu_ttm_adev(ttm->bdev); | ||
685 | struct amdgpu_ttm_tt *gtt = (void *)ttm; | ||
686 | unsigned i; | ||
687 | |||
688 | if (unlikely(trace_amdgpu_ttm_tt_unpopulate_enabled())) { | ||
689 | for (i = 0; i < ttm->num_pages; i++) { | ||
690 | trace_amdgpu_ttm_tt_unpopulate( | ||
691 | adev, | ||
692 | gtt->ttm.dma_address[i], | ||
693 | page_to_phys(ttm->pages[i])); | ||
694 | } | ||
695 | } | ||
696 | } | ||
697 | |||
665 | /* prepare the sg table with the user pages */ | 698 | /* prepare the sg table with the user pages */ |
666 | static int amdgpu_ttm_tt_pin_userptr(struct ttm_tt *ttm) | 699 | static int amdgpu_ttm_tt_pin_userptr(struct ttm_tt *ttm) |
667 | { | 700 | { |
@@ -688,6 +721,8 @@ static int amdgpu_ttm_tt_pin_userptr(struct ttm_tt *ttm) | |||
688 | drm_prime_sg_to_page_addr_arrays(ttm->sg, ttm->pages, | 721 | drm_prime_sg_to_page_addr_arrays(ttm->sg, ttm->pages, |
689 | gtt->ttm.dma_address, ttm->num_pages); | 722 | gtt->ttm.dma_address, ttm->num_pages); |
690 | 723 | ||
724 | amdgpu_trace_dma_map(ttm); | ||
725 | |||
691 | return 0; | 726 | return 0; |
692 | 727 | ||
693 | release_sg: | 728 | release_sg: |
@@ -721,6 +756,8 @@ static void amdgpu_ttm_tt_unpin_userptr(struct ttm_tt *ttm) | |||
721 | put_page(page); | 756 | put_page(page); |
722 | } | 757 | } |
723 | 758 | ||
759 | amdgpu_trace_dma_unmap(ttm); | ||
760 | |||
724 | sg_free_table(ttm->sg); | 761 | sg_free_table(ttm->sg); |
725 | } | 762 | } |
726 | 763 | ||
@@ -892,7 +929,7 @@ static struct ttm_tt *amdgpu_ttm_tt_create(struct ttm_bo_device *bdev, | |||
892 | 929 | ||
893 | static int amdgpu_ttm_tt_populate(struct ttm_tt *ttm) | 930 | static int amdgpu_ttm_tt_populate(struct ttm_tt *ttm) |
894 | { | 931 | { |
895 | struct amdgpu_device *adev; | 932 | struct amdgpu_device *adev = amdgpu_ttm_adev(ttm->bdev); |
896 | struct amdgpu_ttm_tt *gtt = (void *)ttm; | 933 | struct amdgpu_ttm_tt *gtt = (void *)ttm; |
897 | unsigned i; | 934 | unsigned i; |
898 | int r; | 935 | int r; |
@@ -915,14 +952,14 @@ static int amdgpu_ttm_tt_populate(struct ttm_tt *ttm) | |||
915 | drm_prime_sg_to_page_addr_arrays(ttm->sg, ttm->pages, | 952 | drm_prime_sg_to_page_addr_arrays(ttm->sg, ttm->pages, |
916 | gtt->ttm.dma_address, ttm->num_pages); | 953 | gtt->ttm.dma_address, ttm->num_pages); |
917 | ttm->state = tt_unbound; | 954 | ttm->state = tt_unbound; |
918 | return 0; | 955 | r = 0; |
956 | goto trace_mappings; | ||
919 | } | 957 | } |
920 | 958 | ||
921 | adev = amdgpu_ttm_adev(ttm->bdev); | ||
922 | |||
923 | #ifdef CONFIG_SWIOTLB | 959 | #ifdef CONFIG_SWIOTLB |
924 | if (swiotlb_nr_tbl()) { | 960 | if (swiotlb_nr_tbl()) { |
925 | return ttm_dma_populate(>t->ttm, adev->dev); | 961 | r = ttm_dma_populate(>t->ttm, adev->dev); |
962 | goto trace_mappings; | ||
926 | } | 963 | } |
927 | #endif | 964 | #endif |
928 | 965 | ||
@@ -945,7 +982,12 @@ static int amdgpu_ttm_tt_populate(struct ttm_tt *ttm) | |||
945 | return -EFAULT; | 982 | return -EFAULT; |
946 | } | 983 | } |
947 | } | 984 | } |
948 | return 0; | 985 | |
986 | r = 0; | ||
987 | trace_mappings: | ||
988 | if (likely(!r)) | ||
989 | amdgpu_trace_dma_map(ttm); | ||
990 | return r; | ||
949 | } | 991 | } |
950 | 992 | ||
951 | static void amdgpu_ttm_tt_unpopulate(struct ttm_tt *ttm) | 993 | static void amdgpu_ttm_tt_unpopulate(struct ttm_tt *ttm) |
@@ -966,6 +1008,8 @@ static void amdgpu_ttm_tt_unpopulate(struct ttm_tt *ttm) | |||
966 | 1008 | ||
967 | adev = amdgpu_ttm_adev(ttm->bdev); | 1009 | adev = amdgpu_ttm_adev(ttm->bdev); |
968 | 1010 | ||
1011 | amdgpu_trace_dma_unmap(ttm); | ||
1012 | |||
969 | #ifdef CONFIG_SWIOTLB | 1013 | #ifdef CONFIG_SWIOTLB |
970 | if (swiotlb_nr_tbl()) { | 1014 | if (swiotlb_nr_tbl()) { |
971 | ttm_dma_unpopulate(>t->ttm, adev->dev); | 1015 | ttm_dma_unpopulate(>t->ttm, adev->dev); |