AMDKFD Kernel Driver
Subsystems (3)
v3 cover AMDKFD Kernel Driver
Hi,
Here is the v3 patch set of amdkfd.
This version contains changes and fixes to code, as agreed on during the review of the v2 patch set.
The major changes are:
- There are two new module parameters: # of processes and # of queues per process. The defaults, as agreed on in the v2 review, are 32 and 128 respectively. This sets the default amount of GART address space that amdkfd requires to 3.5MB (3MB for userspace queues mqds and 0.5MB for other stuff, such as mqd for kernel queue, hpd for pipelines, etc.)
- All the GART address space usage of amdkfd is done inside a single contiguous buffer that is allocated from system memory, and pinned to the start of the GART during the startup of amdkfd (which is just after the startup of radeon). The management of this buffer is done by the radeon sa manager. This buffer is not evict-able.
- Mapping of doorbells is initiated by the userspace lib (by mmap syscall), instead of initiating it from inside an ioctl (using vm_mmap).
- Removed ioctls for exclusive access to performance counters
- Added documentation about the QCM (Queue Control Management), apertures and interfaces between amdkfd and radeon.
Two important notes:
- The topology patch has not been changed. Look at
http://lists.freedesktop.org/archives/dri-devel/2014-July/065042.html
for my response. I also put my answer as an explanation in the commit msg of the patch.
- There are still some minor code style issues I need to fix. I didn't want to delay v3 any further but I will publish either v4 with those fixes, or just relevant patches if the whole patch set will be merged.
For people who like to review using git, the v3 patch set is located at:
http://cgit.freedesktop.org/~gabbayo/linux/log/?h=kfd-next-3.17-v3
In addition, I would like to announce that we have uploaded the userspace lib that accompanies amdkfd. That lib is called "libhsakmt" and you can view it at:
http://cgit.freedesktop.org/~gabbayo/libhsakmt
Alexey Skidanov (1):
amdkfd: Implement the Get Process Aperture IOCTL
Andrew Lewycky (3):
amdkfd: Add basic modules to amdkfd
amdkfd: Add interrupt handling module
amdkfd: Implement the Set Memory Policy IOCTL
Ben Goz (8):
amdkfd: Add queue module
amdkfd: Add mqd_manager module
amdkfd: Add kernel queue module
amdkfd: Add module parameter of scheduling policy
amdkfd: Add packet manager module
amdkfd: Add process queue manager module
amdkfd: Add device queue manager module
amdkfd: Implement the create/destroy/update queue IOCTLs
Evgeny Pinchuk (2):
amdkfd: Add topology module to amdkfd
amdkfd: Implement the Get Clock Counters IOCTL
Oded Gabbay (9):
drm/radeon: reduce number of free VMIDs and pipes in KV drm/radeon/cik: Don't touch int of pipes 1-7 drm/radeon: Report doorbell configuration to amdkfd drm/radeon: adding synchronization for GRBM GFX drm/radeon: Add radeon <--> amdkfd interface Update MAINTAINERS and CREDITS files with amdkfd info
amdkfd: Add IOCTL set definitions of amdkfd
amdkfd: Add amdkfd skeleton driver
amdkfd: Add binding/unbinding calls to amd_iommu driver
CREDITS | 7 + MAINTAINERS | 10 + drivers/gpu/drm/radeon/Kconfig | 2 + drivers/gpu/drm/radeon/Makefile | 3 + drivers/gpu/drm/radeon/amdkfd/Kconfig | 10 + drivers/gpu/drm/radeon/amdkfd/Makefile | 14 + drivers/gpu/drm/radeon/amdkfd/cik_regs.h | 220 ++++ drivers/gpu/drm/radeon/amdkfd/kfd_aperture.c | 350 ++++++ drivers/gpu/drm/radeon/amdkfd/kfd_chardev.c | 511 +++++++++ drivers/gpu/drm/radeon/amdkfd/kfd_crat.h | 294 +++++ drivers/gpu/drm/radeon/amdkfd/kfd_device.c | 300 +++++ .../drm/radeon/amdkfd/kfd_device_queue_manager.c | 989 ++++++++++++++++ .../drm/radeon/amdkfd/kfd_device_queue_manager.h | 144 +++ drivers/gpu/drm/radeon/amdkfd/kfd_doorbell.c | 236 ++++ drivers/gpu/drm/radeon/amdkfd/kfd_interrupt.c | 161 +++ drivers/gpu/drm/radeon/amdkfd/kfd_kernel_queue.c | 330 ++++++ drivers/gpu/drm/radeon/amdkfd/kfd_kernel_queue.h | 66 ++ drivers/gpu/drm/radeon/amdkfd/kfd_module.c | 147 +++ drivers/gpu/drm/radeon/amdkfd/kfd_mqd_manager.c | 305 +++++ drivers/gpu/drm/radeon/amdkfd/kfd_mqd_manager.h | 88 ++ drivers/gpu/drm/radeon/amdkfd/kfd_packet_manager.c | 495 ++++++++ drivers/gpu/drm/radeon/amdkfd/kfd_pasid.c | 95 ++ drivers/gpu/drm/radeon/amdkfd/kfd_pm4_headers.h | 682 +++++++++++ drivers/gpu/drm/radeon/amdkfd/kfd_pm4_opcodes.h | 107 ++ drivers/gpu/drm/radeon/amdkfd/kfd_priv.h | 560 +++++++++ drivers/gpu/drm/radeon/amdkfd/kfd_process.c | 347 ++++++ .../drm/radeon/amdkfd/kfd_process_queue_manager.c | 346 ++++++ drivers/gpu/drm/radeon/amdkfd/kfd_queue.c | 85 ++ drivers/gpu/drm/radeon/amdkfd/kfd_topology.c | 1207 ++++++++++++++++++++ drivers/gpu/drm/radeon/amdkfd/kfd_topology.h | 168 +++ drivers/gpu/drm/radeon/cik.c | 154 +-- drivers/gpu/drm/radeon/cik_reg.h | 65 ++ drivers/gpu/drm/radeon/cikd.h | 53 +- drivers/gpu/drm/radeon/radeon.h | 10 + drivers/gpu/drm/radeon/radeon_device.c | 32 + drivers/gpu/drm/radeon/radeon_drv.c | 5 + drivers/gpu/drm/radeon/radeon_kfd.c | 525 +++++++++ drivers/gpu/drm/radeon/radeon_kfd.h | 177 +++ drivers/gpu/drm/radeon/radeon_kms.c | 7 + include/uapi/linux/kfd_ioctl.h | 126 ++ 40 files changed, 9338 insertions(+), 95 deletions(-) create mode 100644 drivers/gpu/drm/radeon/amdkfd/Kconfig create mode 100644 drivers/gpu/drm/radeon/amdkfd/Makefile create mode 100644 drivers/gpu/drm/radeon/amdkfd/cik_regs.h create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_aperture.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_chardev.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_crat.h create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_device.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_device_queue_manager.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_device_queue_manager.h create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_doorbell.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_interrupt.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_kernel_queue.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_kernel_queue.h create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_module.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_mqd_manager.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_mqd_manager.h create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_packet_manager.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_pasid.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_pm4_headers.h create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_pm4_opcodes.h create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_priv.h create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_process.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_process_queue_manager.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_queue.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_topology.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_topology.h create mode 100644 drivers/gpu/drm/radeon/radeon_kfd.c create mode 100644 drivers/gpu/drm/radeon/radeon_kfd.h create mode 100644 include/uapi/linux/kfd_ioctl.h
Signature · 1 line
1.9.1
PATCH v3 1/23 drm/radeon: reduce number of free VMIDs and pipes in KV
To support HSA on KV, we need to limit the number of vmids and pipes that are available for radeon's use with KV.
This patch reserves VMIDs 8-15 for amdkfd (so radeon can only use VMIDs 0-7) and also makes radeon thinks that KV has only a single MEC with a single pipe in it
(v3) Use define for static vmid allocation in radeon
--- drivers/gpu/drm/radeon/cik.c | 48 +++++++++++++++++++++---------------------- drivers/gpu/drm/radeon/cikd.h | 2 ++ 2 files changed, 26 insertions(+), 24 deletions(-)
drivers/gpu/drm/radeon/cik.c +24 -24
@@ -4660,12 +4660,11 @@ static int cik_mec_init(struct radeon_device *rdev)/* * KV: 2 MEC, 4 Pipes/MEC, 8 Queues/Pipe - 64 Queues total * CI/KB: 1 MEC, 4 Pipes/MEC, 8 Queues/Pipe - 32 Queues total +* Nonetheless, we assign only 1 pipe because all other pipes will +* be handled by KFD */ -if (rdev->family ==CHIP_KAVERI ) - rdev->mec.num_mec =2 ; -else - rdev->mec.num_mec =1 ; - rdev->mec.num_pipe =4 ; + rdev->mec.num_mec =1 ; + rdev->mec.num_pipe =1 ; rdev->mec.num_queue = rdev->mec.num_mec * rdev->mec.num_pipe *8 ;if (rdev->mec.hpd_eop_obj ==NULL ) {
@@ -4807,28 +4806,24 @@ static int cik_cp_compute_resume(struct radeon_device *rdev)/* init the pipes */ mutex_lock (&rdev->srbm_mutex); -for (i =0 ; i < (rdev->mec.num_pipe * rdev->mec.num_mec); i++) { -int me = (i <4 ) ?1 :2 ; -int pipe = (i <4 ) ? i : (i -4 ); - eop_gpu_addr = rdev->mec.hpd_eop_gpu_addr + (i *MEC_HPD_SIZE *2 ); + eop_gpu_addr = rdev->mec.hpd_eop_gpu_addr; -cik_srbm_select (rdev, me, pipe,0 ,0 ); +cik_srbm_select (rdev,0 ,0 ,0 ,0 ); -/* write the EOP addr */ -WREG32 (CP_HPD_EOP_BASE_ADDR , eop_gpu_addr >>8 ); -WREG32 (CP_HPD_EOP_BASE_ADDR_HI ,upper_32_bits (eop_gpu_addr) >>8 ); +/* write the EOP addr */ +WREG32 (CP_HPD_EOP_BASE_ADDR , eop_gpu_addr >>8 ); +WREG32 (CP_HPD_EOP_BASE_ADDR_HI ,upper_32_bits (eop_gpu_addr) >>8 ); -/* set the VMID assigned */ -WREG32 (CP_HPD_EOP_VMID ,0 ); +/* set the VMID assigned */ +WREG32 (CP_HPD_EOP_VMID ,0 ); + +/* set the EOP size, register value is 2^(EOP_SIZE+1) dwords */ + tmp =RREG32 (CP_HPD_EOP_CONTROL ); + tmp &= ~EOP_SIZE_MASK ; + tmp |=order_base_2 (MEC_HPD_SIZE /8 ); +WREG32 (CP_HPD_EOP_CONTROL , tmp); -/* set the EOP size, register value is 2^(EOP_SIZE+1) dwords */ - tmp =RREG32 (CP_HPD_EOP_CONTROL ); - tmp &= ~EOP_SIZE_MASK ; - tmp |=order_base_2 (MEC_HPD_SIZE /8 ); -WREG32 (CP_HPD_EOP_CONTROL , tmp); - } -cik_srbm_select (rdev,0 ,0 ,0 ,0 );mutex_unlock (&rdev->srbm_mutex);/* init the queues. Just two for now. */
@@ -5874,8 +5869,13 @@ int cik_ib_parse(struct radeon_device *rdev, struct radeon_ib *ib)*/ int cik_vm_init (struct radeon_device *rdev) { -/* number of VMs */ - rdev->vm_manager.nvm =16 ; +/* +* number of VMs +* VMID 0 is reserved for System +* radeon graphics/compute will use VMIDs 1-7 +* amdkfd will use VMIDs 8-15 +*/ + rdev->vm_manager.nvm =RADEON_NUM_OF_VMIDS ;/* base offset of vram pages */ if (rdev->flags &RADEON_IS_IGP ) {u64 tmp =RREG32 (MC_VM_FB_OFFSET );
drivers/gpu/drm/radeon/cikd.h +2 -0
@@ -30,6 +30,8 @@#define CIK_RB_BITMAP_WIDTH_PER_SH 2#define HAWAII_RB_BITMAP_WIDTH_PER_SH 4 +#define RADEON_NUM_OF_VMIDS 8 +/* DIDT IND registers */ #define DIDT_SQ_CTRL0 0x0# define DIDT_CTRL_EN (1 << 0)
Signature · 1 line
1.9.1
PATCH v3 2/23 drm/radeon/cik: Don't touch int of pipes 1-7
In reply to Oded Gabbayamdkfd should set interrupts for pipes 1-7.
--- drivers/gpu/drm/radeon/cik.c | 71 +------------------------------------------- 1 file changed, 1 insertion(+), 70 deletions(-)
drivers/gpu/drm/radeon/cik.c +1 -70
@@ -7265,8 +7265,7 @@ static int cik_irq_init(struct radeon_device *rdev)int cik_irq_set (struct radeon_device *rdev) {u32 cp_int_cntl; -u32 cp_m1p0, cp_m1p1, cp_m1p2, cp_m1p3; -u32 cp_m2p0, cp_m2p1, cp_m2p2, cp_m2p3; +u32 cp_m1p0;u32 crtc1 =0 , crtc2 =0 , crtc3 =0 , crtc4 =0 , crtc5 =0 , crtc6 =0 ;u32 hpd1, hpd2, hpd3, hpd4, hpd5, hpd6;u32 grbm_int_cntl =0 ;
@@ -7300,13 +7299,6 @@ int cik_irq_set(struct radeon_device *rdev) dma_cntl1 =RREG32 (SDMA0_CNTL +SDMA1_REGISTER_OFFSET ) & ~TRAP_ENABLE ; cp_m1p0 =RREG32 (CP_ME1_PIPE0_INT_CNTL ) & ~TIME_STAMP_INT_ENABLE ; - cp_m1p1 =RREG32 (CP_ME1_PIPE1_INT_CNTL ) & ~TIME_STAMP_INT_ENABLE ; - cp_m1p2 =RREG32 (CP_ME1_PIPE2_INT_CNTL ) & ~TIME_STAMP_INT_ENABLE ; - cp_m1p3 =RREG32 (CP_ME1_PIPE3_INT_CNTL ) & ~TIME_STAMP_INT_ENABLE ; - cp_m2p0 =RREG32 (CP_ME2_PIPE0_INT_CNTL ) & ~TIME_STAMP_INT_ENABLE ; - cp_m2p1 =RREG32 (CP_ME2_PIPE1_INT_CNTL ) & ~TIME_STAMP_INT_ENABLE ; - cp_m2p2 =RREG32 (CP_ME2_PIPE2_INT_CNTL ) & ~TIME_STAMP_INT_ENABLE ; - cp_m2p3 =RREG32 (CP_ME2_PIPE3_INT_CNTL ) & ~TIME_STAMP_INT_ENABLE ;if (rdev->flags &RADEON_IS_IGP ) thermal_int = RREG32_SMC(CG_THERMAL_INT_CTRL) &
@@ -7328,33 +7320,6 @@ int cik_irq_set(struct radeon_device *rdev)case 0 : cp_m1p0 |=TIME_STAMP_INT_ENABLE ;break ; -case 1 : - cp_m1p1 |=TIME_STAMP_INT_ENABLE ; -break ; -case 2 : - cp_m1p2 |=TIME_STAMP_INT_ENABLE ; -break ; -case 3 : - cp_m1p2 |=TIME_STAMP_INT_ENABLE ; -break ; -default : -DRM_DEBUG ("si_irq_set: sw int cp1 invalid pipe %d\n" , ring->pipe); -break ; - } - }else if (ring->me ==2 ) { -switch (ring->pipe) { -case 0 : - cp_m2p0 |=TIME_STAMP_INT_ENABLE ; -break ; -case 1 : - cp_m2p1 |=TIME_STAMP_INT_ENABLE ; -break ; -case 2 : - cp_m2p2 |=TIME_STAMP_INT_ENABLE ; -break ; -case 3 : - cp_m2p2 |=TIME_STAMP_INT_ENABLE ; -break ;default :DRM_DEBUG ("si_irq_set: sw int cp1 invalid pipe %d\n" , ring->pipe);break ;
@@ -7371,33 +7336,6 @@ int cik_irq_set(struct radeon_device *rdev)case 0 : cp_m1p0 |=TIME_STAMP_INT_ENABLE ;break ; -case 1 : - cp_m1p1 |=TIME_STAMP_INT_ENABLE ; -break ; -case 2 : - cp_m1p2 |=TIME_STAMP_INT_ENABLE ; -break ; -case 3 : - cp_m1p2 |=TIME_STAMP_INT_ENABLE ; -break ; -default : -DRM_DEBUG ("si_irq_set: sw int cp2 invalid pipe %d\n" , ring->pipe); -break ; - } - }else if (ring->me ==2 ) { -switch (ring->pipe) { -case 0 : - cp_m2p0 |=TIME_STAMP_INT_ENABLE ; -break ; -case 1 : - cp_m2p1 |=TIME_STAMP_INT_ENABLE ; -break ; -case 2 : - cp_m2p2 |=TIME_STAMP_INT_ENABLE ; -break ; -case 3 : - cp_m2p2 |=TIME_STAMP_INT_ENABLE ; -break ;default :DRM_DEBUG ("si_irq_set: sw int cp2 invalid pipe %d\n" , ring->pipe);break ;
@@ -7486,13 +7424,6 @@ int cik_irq_set(struct radeon_device *rdev)WREG32 (SDMA0_CNTL +SDMA1_REGISTER_OFFSET , dma_cntl1);WREG32 (CP_ME1_PIPE0_INT_CNTL , cp_m1p0); -WREG32 (CP_ME1_PIPE1_INT_CNTL , cp_m1p1); -WREG32 (CP_ME1_PIPE2_INT_CNTL , cp_m1p2); -WREG32 (CP_ME1_PIPE3_INT_CNTL , cp_m1p3); -WREG32 (CP_ME2_PIPE0_INT_CNTL , cp_m2p0); -WREG32 (CP_ME2_PIPE1_INT_CNTL , cp_m2p1); -WREG32 (CP_ME2_PIPE2_INT_CNTL , cp_m2p2); -WREG32 (CP_ME2_PIPE3_INT_CNTL , cp_m2p3);WREG32 (GRBM_INT_CNTL , grbm_int_cntl);
Signature · 1 line
1.9.1
PATCH v3 3/23 drm/radeon: Report doorbell configuration to amdkfd
In reply to Oded Gabbayradeon and amdkfd share the doorbell aperture.
radeon sets it up, takes the doorbells required for its own rings and reports the setup to amdkfd.
radeon reserved doorbells are at the start of the doorbell aperture.
--- drivers/gpu/drm/radeon/radeon.h | 4 ++++ drivers/gpu/drm/radeon/radeon_device.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+)
drivers/gpu/drm/radeon/radeon.h +4 -0
@@ -691,6 +691,10 @@ struct radeon_doorbell {int radeon_doorbell_get (struct radeon_device *rdev,u32 *page);void radeon_doorbell_free (struct radeon_device *rdev,u32 doorbell); +void radeon_doorbell_get_kfd_info (struct radeon_device *rdev, +phys_addr_t *aperture_base, +size_t *aperture_size, +size_t *start_offset);/* * IRQS.
drivers/gpu/drm/radeon/radeon_device.c +31 -0
@@ -373,6 +373,37 @@ void radeon_doorbell_free(struct radeon_device *rdev, u32 doorbell)__clear_bit (doorbell, rdev->doorbell.used); } +/** +* radeon_doorbell_get_kfd_info - Report doorbell configuration required to +* setup KFD +* +* @rdev: radeon_device pointer +* @aperture_base: output returning doorbell aperture base physical address +* @aperture_size: output returning doorbell aperture size in bytes +* @start_offset: output returning # of doorbell bytes reserved for radeon. +* +* Radeon and the KFD share the doorbell aperture. Radeon sets it up, +* takes doorbells required for its own rings and reports the setup to KFD. +* Radeon reserved doorbells are at the start of the doorbell aperture. +*/ +void radeon_doorbell_get_kfd_info (struct radeon_device *rdev, +phys_addr_t *aperture_base, +size_t *aperture_size, +size_t *start_offset) +{ +/* The first num_doorbells are used by radeon. +* KFD takes whatever's left in the aperture. */ +if (rdev->doorbell.size > rdev->doorbell.num_doorbells *sizeof (u32)) { + *aperture_base = rdev->doorbell.base; + *aperture_size = rdev->doorbell.size; + *start_offset = rdev->doorbell.num_doorbells *sizeof (u32); + }else { + *aperture_base =0 ; + *aperture_size =0 ; + *start_offset =0 ; + } +} +/* * radeon_wb_*() * Writeback is the the method by which the the GPU updates special pages
Signature · 1 line
1.9.1
PATCH v3 4/23 drm/radeon: adding synchronization for GRBM GFX
In reply to Oded GabbayImplementing a lock for selecting and accessing shader engines and arrays. This lock will make sure that radeon and amdkfd are not colliding when accessing shader engines and arrays with GRBM_GFX_INDEX register.
--- drivers/gpu/drm/radeon/cik.c | 26 ++++++++++++++++++++++++++ drivers/gpu/drm/radeon/radeon.h | 2 ++ drivers/gpu/drm/radeon/radeon_device.c | 1 + 3 files changed, 29 insertions(+)
drivers/gpu/drm/radeon/cik.c +26 -0
@@ -1563,6 +1563,8 @@ static const u32 godavari_golden_registers[] =static void cik_init_golden_registers (struct radeon_device *rdev) { +/* Some of the registers might be dependant on GRBM_GFX_INDEX */ +mutex_lock (&rdev->grbm_idx_mutex);switch (rdev->family) {case CHIP_BONAIRE : radeon_program_register_sequence(rdev,
@@ -1637,6 +1639,7 @@ static void cik_init_golden_registers(struct radeon_device *rdev)default :break ; } +mutex_unlock (&rdev->grbm_idx_mutex); }/**
@@ -3419,6 +3422,7 @@ static void cik_setup_rb(struct radeon_device *rdev,u32 disabled_rbs =0 ;u32 enabled_rbs =0 ; +mutex_lock (&rdev->grbm_idx_mutex);for (i =0 ; i < se_num; i++) {for (j =0 ; j < sh_per_se; j++) {cik_select_se_sh (rdev, i, j);
@@ -3430,6 +3434,7 @@ static void cik_setup_rb(struct radeon_device *rdev, } }cik_select_se_sh (rdev,0xffffffff ,0xffffffff ); +mutex_unlock (&rdev->grbm_idx_mutex); mask =1 ;for (i =0 ; i < max_rb_num_per_se * se_num; i++) {
@@ -3440,6 +3445,7 @@ static void cik_setup_rb(struct radeon_device *rdev, rdev->config.cik.backend_enable_mask = enabled_rbs; +mutex_lock (&rdev->grbm_idx_mutex);for (i =0 ; i < se_num; i++) {cik_select_se_sh (rdev, i,0xffffffff ); data =0 ;
@@ -3467,6 +3473,7 @@ static void cik_setup_rb(struct radeon_device *rdev,WREG32 (PA_SC_RASTER_CONFIG , data); }cik_select_se_sh (rdev,0xffffffff ,0xffffffff ); +mutex_unlock (&rdev->grbm_idx_mutex); }/**
@@ -3684,6 +3691,12 @@ static void cik_gpu_init(struct radeon_device *rdev)/* set HW defaults for 3D engine */ WREG32 (CP_MEQ_THRESHOLDS ,MEQ1_START (0x30 ) |MEQ2_START (0x60 )); +mutex_lock (&rdev->grbm_idx_mutex); +/* +* making sure that the following register writes will be broadcasted +* to all the shaders +*/ +cik_select_se_sh (rdev,0xffffffff ,0xffffffff );WREG32 (SX_DEBUG_1 ,0x20 );WREG32 (TA_CNTL_AUX ,0x00010000 );
@@ -3739,6 +3752,7 @@ static void cik_gpu_init(struct radeon_device *rdev)WREG32 (PA_CL_ENHANCE ,CLIP_VTX_REORDER_ENA |NUM_CLIP_SEQ (3 ));WREG32 (PA_SC_ENHANCE ,ENABLE_PA_SC_OUT_OF_ORDER ); +mutex_unlock (&rdev->grbm_idx_mutex);udelay (50 ); }
@@ -6036,6 +6050,7 @@ static void cik_wait_for_rlc_serdes(struct radeon_device *rdev)u32 i, j, k;u32 mask; +mutex_lock (&rdev->grbm_idx_mutex);for (i =0 ; i < rdev->config.cik.max_shader_engines; i++) {for (j =0 ; j < rdev->config.cik.max_sh_per_se; j++) {cik_select_se_sh (rdev, i, j);
@@ -6047,6 +6062,7 @@ static void cik_wait_for_rlc_serdes(struct radeon_device *rdev) } }cik_select_se_sh (rdev,0xffffffff ,0xffffffff ); +mutex_unlock (&rdev->grbm_idx_mutex); mask =SE_MASTER_BUSY_MASK |GC_MASTER_BUSY |TC0_MASTER_BUSY |TC1_MASTER_BUSY ;for (k =0 ; k < rdev->usec_timeout; k++) {
@@ -6181,10 +6197,12 @@ static int cik_rlc_resume(struct radeon_device *rdev)WREG32 (RLC_LB_CNTR_INIT ,0 );WREG32 (RLC_LB_CNTR_MAX ,0x00008000 ); +mutex_lock (&rdev->grbm_idx_mutex);cik_select_se_sh (rdev,0xffffffff ,0xffffffff );WREG32 (RLC_LB_INIT_CU_MASK ,0xffffffff );WREG32 (RLC_LB_PARAMS ,0x00600408 );WREG32 (RLC_LB_CNTL ,0x80000004 ); +mutex_unlock (&rdev->grbm_idx_mutex);WREG32 (RLC_MC_CNTL ,0 );WREG32 (RLC_UCODE_CNTL ,0 );
@@ -6251,11 +6269,13 @@ static void cik_enable_cgcg(struct radeon_device *rdev, bool enable) tmp =cik_halt_rlc (rdev); +mutex_lock (&rdev->grbm_idx_mutex);cik_select_se_sh (rdev,0xffffffff ,0xffffffff );WREG32 (RLC_SERDES_WR_CU_MASTER_MASK ,0xffffffff );WREG32 (RLC_SERDES_WR_NONCU_MASTER_MASK ,0xffffffff ); tmp2 =BPM_ADDR_MASK |CGCG_OVERRIDE_0 |CGLS_ENABLE ;WREG32 (RLC_SERDES_WR_CTRL , tmp2); +mutex_unlock (&rdev->grbm_idx_mutex);cik_update_rlc (rdev, tmp);
@@ -6297,11 +6317,13 @@ static void cik_enable_mgcg(struct radeon_device *rdev, bool enable) tmp =cik_halt_rlc (rdev); +mutex_lock (&rdev->grbm_idx_mutex);cik_select_se_sh (rdev,0xffffffff ,0xffffffff );WREG32 (RLC_SERDES_WR_CU_MASTER_MASK ,0xffffffff );WREG32 (RLC_SERDES_WR_NONCU_MASTER_MASK ,0xffffffff ); data =BPM_ADDR_MASK |MGCG_OVERRIDE_0 ;WREG32 (RLC_SERDES_WR_CTRL , data); +mutex_unlock (&rdev->grbm_idx_mutex);cik_update_rlc (rdev, tmp);
@@ -6345,11 +6367,13 @@ static void cik_enable_mgcg(struct radeon_device *rdev, bool enable) tmp =cik_halt_rlc (rdev); +mutex_lock (&rdev->grbm_idx_mutex);cik_select_se_sh (rdev,0xffffffff ,0xffffffff );WREG32 (RLC_SERDES_WR_CU_MASTER_MASK ,0xffffffff );WREG32 (RLC_SERDES_WR_NONCU_MASTER_MASK ,0xffffffff ); data =BPM_ADDR_MASK |MGCG_OVERRIDE_1 ;WREG32 (RLC_SERDES_WR_CTRL , data); +mutex_unlock (&rdev->grbm_idx_mutex);cik_update_rlc (rdev, tmp); }
@@ -6778,10 +6802,12 @@ static u32 cik_get_cu_active_bitmap(struct radeon_device *rdev, u32 se, u32 sh)u32 mask =0 , tmp, tmp1;int i; +mutex_lock (&rdev->grbm_idx_mutex);cik_select_se_sh (rdev, se, sh); tmp =RREG32 (CC_GC_SHADER_ARRAY_CONFIG ); tmp1 =RREG32 (GC_USER_SHADER_ARRAY_CONFIG );cik_select_se_sh (rdev,0xffffffff ,0xffffffff ); +mutex_unlock (&rdev->grbm_idx_mutex); tmp &=0xffff0000 ;
drivers/gpu/drm/radeon/radeon.h +2 -0
@@ -2374,6 +2374,8 @@ struct radeon_device {struct radeon_atcs atcs;/* srbm instance registers */ struct mutex srbm_mutex; +/* GRBM index mutex. Protects concurrents access to GRBM index */ +struct mutex grbm_idx_mutex;/* clock, powergating flags */ u32 cg_flags;u32 pg_flags;
drivers/gpu/drm/radeon/radeon_device.c +1 -0
@@ -1298,6 +1298,7 @@ int radeon_device_init(struct radeon_device *rdev,mutex_init (&rdev->pm.mutex);mutex_init (&rdev->gpu_clock_mutex);mutex_init (&rdev->srbm_mutex); +mutex_init (&rdev->grbm_idx_mutex);init_rwsem (&rdev->pm.mclk_lock);init_rwsem (&rdev->exclusive_lock);init_waitqueue_head (&rdev->irq.vblank_queue);
Signature · 1 line
1.9.1
PATCH v3 6/23 Update MAINTAINERS and CREDITS files with amdkfd info
In reply to Oded Gabbay--- CREDITS | 7 +++++++ MAINTAINERS | 10 ++++++++++ 2 files changed, 17 insertions(+)
CREDITS +7 -0
@@ -1197,6 +1197,13 @@ S: R. Tocantins, 89 - Cristo Rei S: 80050-430 - Curitiba - Paraná S: Brazil +N: Oded Gabbay +E: [email protected] +D: AMD KFD maintainer +S: 12 Shraga Raphaeli +S: Petah-Tikva, 4906418 +S: Israel + N: Kumar Gala E: [email protected] D: Embedded PowerPC 6xx/7xx/74xx/82xx/83xx/85xx support
MAINTAINERS +10 -0
@@ -589,6 +589,16 @@ F: drivers/crypto/geode* F: drivers/video/geode/ F: arch/x86/include/asm/geode.h +AMD KFD (radeon extension) +M: Oded Gabbay <[email protected]> +L: [email protected] +T: git git://people.freedesktop.org/~gabbayo/linux.git +S: Supported +F: drivers/gpu/drm/radeon/amdkfd/* +F: drivers/gpu/drm/radeon/radeon_kfd.c +F: drivers/gpu/drm/radeon/radeon_kfd.h +F: include/linux/uapi/linux/kfd_ioctl.h + AMD IOMMU (AMD-VI) M: Joerg Roedel <[email protected]> L: [email protected]
Signature · 6 lines
1.9.1 _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v3 5/23 drm/radeon: Add radeon <--> amdkfd interface
In reply to Oded GabbayThis patch adds the interface between the radeon driver and the amdkfd driver. The interface implementation is contained in radeon_kfd.c and radeon_kfd.h.
The interface itself is represented by a pointer to struct kfd_dev. The pointer is located inside radeon_device structure.
All the register accesses that amdkfd need are done using this interface. This allows us to avoid direct register accesses in amdkfd proper, while also avoiding locking between amdkfd and radeon.
The single exception is the doorbells that are used in both of the drivers. However, because they are located in separate pci bar pages, the danger of sharing registers between the drivers is minimal.
Having said that, we are planning to move the doorbells as well to radeon.
(v3)
Add interface for sa manager init and fini. The init function will allocate a buffer on system memory and pin it to the GART address space via the radeon sa manager.
All mappings of buffers to GART address space are done via the radeon sa manager. The interface of allocate memory will use the radeon sa manager to sub allocate from the single buffer that was allocated during the init function.
(v3) Change lower_32/upper_32 calls to use linux macros
(v3) Add documentation for the interface
--- drivers/gpu/drm/radeon/Makefile | 1 + drivers/gpu/drm/radeon/cik.c | 9 + drivers/gpu/drm/radeon/cik_reg.h | 65 +++++ drivers/gpu/drm/radeon/cikd.h | 51 +++- drivers/gpu/drm/radeon/radeon.h | 4 + drivers/gpu/drm/radeon/radeon_drv.c | 5 + drivers/gpu/drm/radeon/radeon_kfd.c | 538 ++++++++++++++++++++++++++++++++++++ drivers/gpu/drm/radeon/radeon_kfd.h | 177 ++++++++++++ drivers/gpu/drm/radeon/radeon_kms.c | 7 + 9 files changed, 856 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/drm/radeon/radeon_kfd.c create mode 100644 drivers/gpu/drm/radeon/radeon_kfd.h
drivers/gpu/drm/radeon/Makefile +1 -0
@@ -104,6 +104,7 @@ radeon-y += \ radeon_vce.o \ vce_v1_0.o \ vce_v2_0.o \ + radeon_kfd.o radeon-$(CONFIG_COMPAT) += radeon_ioc32.o radeon-$(CONFIG_VGA_SWITCHEROO) += radeon_atpx_handler.o
drivers/gpu/drm/radeon/cik.c +9 -0
@@ -32,6 +32,7 @@#include "cik_blit_shaders.h" #include "radeon_ucode.h" #include "clearstate_ci.h" +#include "radeon_kfd.h" MODULE_FIRMWARE ("radeon/BONAIRE_pfp.bin" );MODULE_FIRMWARE ("radeon/BONAIRE_me.bin" );
@@ -7766,6 +7767,9 @@ restart_ih:while (rptr != wptr) {/* wptr/rptr are in bytes! */ ring_index = rptr /4 ; + +radeon_kfd_interrupt (rdev, (const void *) &rdev->ih.ring[ring_index]); + src_id =le32_to_cpu (rdev->ih.ring[ring_index]) &0xff ; src_data =le32_to_cpu (rdev->ih.ring[ring_index +1 ]) &0xfffffff ; ring_id =le32_to_cpu (rdev->ih.ring[ring_index +2 ]) &0xff ;
@@ -8453,6 +8457,10 @@ static int cik_startup(struct radeon_device *rdev)if (r)return r; + r =radeon_kfd_resume (rdev); +if (r) +return r; +return 0 ; }
@@ -8501,6 +8509,7 @@ int cik_resume(struct radeon_device *rdev)*/ int cik_suspend (struct radeon_device *rdev) { +radeon_kfd_suspend (rdev);radeon_pm_suspend (rdev);dce6_audio_fini (rdev);radeon_vm_manager_fini (rdev);
drivers/gpu/drm/radeon/cik_reg.h +65 -0
69 lines not on this page · raw message
drivers/gpu/drm/radeon/cikd.h +50 -1
78 lines not on this page · raw message
drivers/gpu/drm/radeon/radeon.h +4 -0
@@ -2388,6 +2388,10 @@ struct radeon_device {u64 vram_pin_size;u64 gart_pin_size; +/* amdkfd interface */ +struct kfd_dev *kfd; +struct radeon_sa_manager kfd_bo; +struct mutex mn_lock;DECLARE_HASHTABLE (mn_hash,7 ); };
drivers/gpu/drm/radeon/radeon_drv.c +5 -0
@@ -39,6 +39,8 @@#include <linux/pm_runtime.h> #include <linux/vga_switcheroo.h> #include "drm_crtc_helper.h" +#include "radeon_kfd.h" +/* * KMS wrapper. * - 2.0.0 - initial interface
@@ -639,12 +641,15 @@ static int __init radeon_init(void)#endif } +radeon_kfd_init (); +/* let modprobe override vga console setting */ return drm_pci_init (driver, pdriver); } static void __exit radeon_exit(void) { +radeon_kfd_fini ();drm_pci_exit (driver, pdriver);radeon_unregister_atpx_handler (); }
drivers/gpu/drm/radeon/radeon_kfd.c new file +538 -0
538 lines not on this page · raw message
drivers/gpu/drm/radeon/radeon_kfd.h new file +177 -0
177 lines not on this page · raw message
drivers/gpu/drm/radeon/radeon_kms.c +7 -0
@@ -34,6 +34,8 @@#include <linux/slab.h> #include <linux/pm_runtime.h> +#include "radeon_kfd.h" +#if defined(CONFIG_VGA_SWITCHEROO )bool radeon_has_atpx (void );#else
@@ -63,6 +65,8 @@ int radeon_driver_unload_kms(struct drm_device *dev)pm_runtime_get_sync (dev->dev); +radeon_kfd_device_fini (rdev); +radeon_acpi_fini (rdev);radeon_modeset_fini (rdev);
@@ -142,6 +146,9 @@ int radeon_driver_load_kms(struct drm_device *dev, unsigned long flags) "Error during ACPI methods call\n"); } +radeon_kfd_device_probe (rdev); +radeon_kfd_device_init (rdev); +if (radeon_is_px (dev)) {pm_runtime_use_autosuspend (dev->dev);pm_runtime_set_autosuspend_delay (dev->dev,5000 );
Signature · 1 line
1.9.1
PATCH v3 7/23 amdkfd: Add IOCTL set definitions of amdkfd
In reply to Oded Gabbay- KFD_IOC_GET_VERSION:
Retrieves the interface version of amdkfd
- KFD_IOC_CREATE_QUEUE:
Creates a usermode queue that runs on a specific GPU device
- KFD_IOC_DESTROY_QUEUE:
Destroys an existing usermode queue
- KFD_IOC_SET_MEMORY_POLICY:
Sets the memory policy of the default and alternate aperture of the calling process
- KFD_IOC_GET_CLOCK_COUNTERS:
Retrieves counters (timestamps) of CPU and GPU
- KFD_IOC_GET_PROCESS_APERTURES:
Retrieves information about process apertures that were initialized during the open() call of the amdkfd device
- KFD_IOC_UPDATE_QUEUE:
Updates configuration of an existing usermode queue
(v3) remove pragma pack
(v3) remove pmc ioctls
(v3) add parameter for doorbell offset
(v3) add comment on counters
--- include/uapi/linux/kfd_ioctl.h | 123 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 include/uapi/linux/kfd_ioctl.h
include/uapi/linux/kfd_ioctl.h new file +123 -0
@@ -0,0 +1,123 @@ +/* +* Copyright 2014 Advanced Micro Devices, Inc. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR +* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +*/ + +#ifndef KFD_IOCTL_H_INCLUDED +#define KFD_IOCTL_H_INCLUDED + +#include <linux/types.h> +#include <linux/ioctl.h> + +#define KFD_IOCTL_CURRENT_VERSION 1 + +struct kfd_ioctl_get_version_args { +uint32_t min_supported_version;/* from KFD */ +uint32_t max_supported_version;/* from KFD */ +}; + +/* For kfd_ioctl_create_queue_args.queue_type. */ +#define KFD_IOC_QUEUE_TYPE_COMPUTE 0 +#define KFD_IOC_QUEUE_TYPE_SDMA 1 + +struct kfd_ioctl_create_queue_args { +uint64_t ring_base_address;/* to KFD */ +uint64_t write_pointer_address;/* from KFD */ +uint64_t read_pointer_address;/* from KFD */ +uint64_t doorbell_offset;/* from KFD */ + +uint32_t ring_size;/* to KFD */ +uint32_t gpu_id;/* to KFD */ +uint32_t queue_type;/* to KFD */ +uint32_t queue_percentage;/* to KFD */ +uint32_t queue_priority;/* to KFD */ +uint32_t queue_id;/* from KFD */ +}; + +struct kfd_ioctl_destroy_queue_args { +uint32_t queue_id;/* to KFD */ +}; + +struct kfd_ioctl_update_queue_args { +uint64_t ring_base_address;/* to KFD */ + +uint32_t queue_id;/* to KFD */ +uint32_t ring_size;/* to KFD */ +uint32_t queue_percentage;/* to KFD */ +uint32_t queue_priority;/* to KFD */ +}; + +/* For kfd_ioctl_set_memory_policy_args.default_policy and alternate_policy */ +#define KFD_IOC_CACHE_POLICY_COHERENT 0 +#define KFD_IOC_CACHE_POLICY_NONCOHERENT 1 + +struct kfd_ioctl_set_memory_policy_args { +uint64_t alternate_aperture_base;/* to KFD */ +uint64_t alternate_aperture_size;/* to KFD */ + +uint32_t gpu_id;/* to KFD */ +uint32_t default_policy;/* to KFD */ +uint32_t alternate_policy;/* to KFD */ +}; + +/* +* All counters are monotonic. They are used for profiling of compute jobs. +* The profiling is done by userspace. +* +* In case of GPU reset, the counter should not be affected. +*/ + +struct kfd_ioctl_get_clock_counters_args { +uint64_t gpu_clock_counter;/* from KFD */ +uint64_t cpu_clock_counter;/* from KFD */ +uint64_t system_clock_counter;/* from KFD */ +uint64_t system_clock_freq;/* from KFD */ + +uint32_t gpu_id;/* to KFD */ +}; + +#define NUM_OF_SUPPORTED_GPUS 7 + +struct kfd_process_device_apertures { +uint64_t lds_base;/* from KFD */ +uint64_t lds_limit;/* from KFD */ +uint64_t scratch_base;/* from KFD */ +uint64_t scratch_limit;/* from KFD */ +uint64_t gpuvm_base;/* from KFD */ +uint64_t gpuvm_limit;/* from KFD */ +uint32_t gpu_id;/* from KFD */ +}; + +struct kfd_ioctl_get_process_apertures_args { +struct kfd_process_device_apertures process_apertures[NUM_OF_SUPPORTED_GPUS ];/* from KFD */ +uint8_t num_of_nodes;/* from KFD, should be in the range [1 - NUM_OF_SUPPORTED_GPUS]*/ +}; + +#define KFD_IOC_MAGIC 'K' + +#define KFD_IOC_GET_VERSION _IOR(KFD_IOC_MAGIC, 1, struct kfd_ioctl_get_version_args) +#define KFD_IOC_CREATE_QUEUE _IOWR(KFD_IOC_MAGIC, 2, struct kfd_ioctl_create_queue_args) +#define KFD_IOC_DESTROY_QUEUE _IOWR(KFD_IOC_MAGIC, 3, struct kfd_ioctl_destroy_queue_args) +#define KFD_IOC_SET_MEMORY_POLICY _IOW(KFD_IOC_MAGIC, 4, struct kfd_ioctl_set_memory_policy_args) +#define KFD_IOC_GET_CLOCK_COUNTERS _IOWR(KFD_IOC_MAGIC, 5, struct kfd_ioctl_get_clock_counters_args) +#define KFD_IOC_GET_PROCESS_APERTURES _IOR(KFD_IOC_MAGIC, 6, struct kfd_ioctl_get_process_apertures_args) +#define KFD_IOC_UPDATE_QUEUE _IOW(KFD_IOC_MAGIC, 7, struct kfd_ioctl_update_queue_args) + +#endif
Signature · 1 line
1.9.1
PATCH v3 8/23 amdkfd: Add amdkfd skeleton driver
In reply to Oded GabbayThis patch adds the amdkfd skeleton driver. The driver does nothing except define a /dev/kfd device.
It returns -ENODEV on all amdkfd IOCTLs.
(v3) move bool to end of struct
(v3) remove pmc ioctls
(v3) add meaningful error message for ioctl error
--- drivers/gpu/drm/radeon/Kconfig | 2 + drivers/gpu/drm/radeon/Makefile | 2 + drivers/gpu/drm/radeon/amdkfd/Kconfig | 10 ++ drivers/gpu/drm/radeon/amdkfd/Makefile | 9 ++ drivers/gpu/drm/radeon/amdkfd/kfd_chardev.c | 187 ++++++++++++++++++++++++++++ drivers/gpu/drm/radeon/amdkfd/kfd_device.c | 129 +++++++++++++++++++ drivers/gpu/drm/radeon/amdkfd/kfd_module.c | 98 +++++++++++++++ drivers/gpu/drm/radeon/amdkfd/kfd_priv.h | 82 ++++++++++++ 8 files changed, 519 insertions(+) create mode 100644 drivers/gpu/drm/radeon/amdkfd/Kconfig create mode 100644 drivers/gpu/drm/radeon/amdkfd/Makefile create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_chardev.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_device.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_module.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_priv.h
drivers/gpu/drm/radeon/Kconfig +2 -0
@@ -6,3 +6,5 @@ config DRM_RADEON_UMS Userspace modesetting is deprecated for quite some time now, so enable this only if you have ancient versions of the DDX drivers. + +source "drivers/gpu/drm/radeon/amdkfd/Kconfig"
drivers/gpu/drm/radeon/Makefile +2 -0
@@ -112,4 +112,6 @@ radeon-$(CONFIG_ACPI) += radeon_acpi.o obj-$(CONFIG_DRM_RADEON)+= radeon.o +obj-$(CONFIG_HSA_RADEON)+= amdkfd/ + CFLAGS_radeon_trace_points.o := -I$(src)
drivers/gpu/drm/radeon/amdkfd/Kconfig new file +10 -0
@@ -0,0 +1,10 @@ +# +# Heterogenous system architecture configuration +# + +config HSA_RADEON + tristate "HSA kernel driver for AMD Radeon devices" + depends on DRM_RADEON && AMD_IOMMU_V2 && X86_64 + default m + help + Enable this if you want to use HSA features on AMD radeon devices.
drivers/gpu/drm/radeon/amdkfd/Makefile new file +9 -0
@@ -0,0 +1,9 @@ +# +# Makefile for Heterogenous System Architecture support for AMD radeon devices +# + +ccflags-y := -Iinclude/drm + +amdkfd-y := kfd_module.o kfd_device.o kfd_chardev.o + +obj-$(CONFIG_HSA_RADEON) += amdkfd.o
drivers/gpu/drm/radeon/amdkfd/kfd_chardev.c new file +187 -0
187 lines not on this page · raw message
drivers/gpu/drm/radeon/amdkfd/kfd_device.c new file +129 -0
129 lines not on this page · raw message
drivers/gpu/drm/radeon/amdkfd/kfd_module.c new file +98 -0
98 lines not on this page · raw message
drivers/gpu/drm/radeon/amdkfd/kfd_priv.h new file +82 -0
82 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH v3 9/23 amdkfd: Add topology module to amdkfd
In reply to Oded GabbayFrom: Evgeny Pinchuk <[email protected]>
This patch adds the topology module to the driver. The topology is exposed to userspace through the sysfs.
The calls to add and remove a device to/from topology are done by the radeon driver.
The CPU information, that is provided in the topology section of the amdkfd driver, is extracted from the CRAT table. Unlike the CPU information located in /sys/devices/system/cpu/cpu*, which is extracted from the SRAT table.
While the CPU information provided by the CRAT and the SRAT tables might be identical, the node topology might be different. The SRAT table contains the topology of CPU nodes only. The CRAT table contains the topology of CPU and GPU nodes together (and can be interleaved). For example CPU node 1 in SRAT can be CPU node 3 in CRAT. Furthermore it's worth to mention that the CRAT table contains only HSA compatible nodes (nodes which are compliant with the HSA spec).
To recap, amdkfd exposes a different kind of topology than the one exposed by /sys/devices/system/cpu/cpu even though it may contain similar information.
--- drivers/gpu/drm/radeon/amdkfd/Makefile | 2 +- drivers/gpu/drm/radeon/amdkfd/kfd_crat.h | 294 +++++++ drivers/gpu/drm/radeon/amdkfd/kfd_device.c | 7 + drivers/gpu/drm/radeon/amdkfd/kfd_module.c | 7 + drivers/gpu/drm/radeon/amdkfd/kfd_priv.h | 17 + drivers/gpu/drm/radeon/amdkfd/kfd_topology.c | 1207 ++++++++++++++++++++++++++ drivers/gpu/drm/radeon/amdkfd/kfd_topology.h | 168 ++++ 7 files changed, 1701 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_crat.h create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_topology.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_topology.h
drivers/gpu/drm/radeon/amdkfd/Makefile +1 -1
@@ -4,6 +4,6 @@ ccflags-y := -Iinclude/drm -amdkfd-y := kfd_module.o kfd_device.o kfd_chardev.o +amdkfd-y := kfd_module.o kfd_device.o kfd_chardev.o kfd_topology.o obj-$(CONFIG_HSA_RADEON) += amdkfd.o
drivers/gpu/drm/radeon/amdkfd/kfd_crat.h new file +294 -0
294 lines not on this page · raw message
drivers/gpu/drm/radeon/amdkfd/kfd_device.c +7 -0
@@ -100,6 +100,9 @@ bool kgd2kfd_device_init(struct kfd_dev *kfd, { kfd->shared_resources = *gpu_resources; +if (kfd_topology_add_device (kfd) !=0 ) +return false; + kfd->init_complete = true;dev_info (kfd_device,"added device (%x:%x)\n" , kfd->pdev->vendor, kfd->pdev->device);
@@ -109,6 +112,10 @@ bool kgd2kfd_device_init(struct kfd_dev *kfd,void kgd2kfd_device_exit (struct kfd_dev *kfd) { +int err =kfd_topology_remove_device (kfd); + +BUG_ON (err !=0 ); +kfree (kfd); }
drivers/gpu/drm/radeon/amdkfd/kfd_module.c +7 -0
@@ -73,16 +73,23 @@ static int __init kfd_module_init(void)if (err <0 ) goto err_ioctl; + err =kfd_topology_init (); +if (err <0 ) + goto err_topology; +dev_info (kfd_device,"Initialized module\n" );return 0 ; +err_topology: +kfd_chardev_exit (); err_ioctl:return err; } static void __exit kfd_module_exit(void) { +kfd_topology_shutdown ();kfd_chardev_exit ();dev_info (kfd_device,"Removed module\n" ); }
drivers/gpu/drm/radeon/amdkfd/kfd_priv.h +17 -0
@@ -32,6 +32,14 @@#include <linux/spinlock.h> #include "../radeon_kfd.h" +#define KFD_SYSFS_FILE_MODE 0444 + +/* GPU ID hash width in bits */ +#define KFD_GPU_ID_HASH_WIDTH 16 + +/* Macro for allocating structures */ +#define kfd_alloc_struct (ptr_to_struct) ((typeof(ptr_to_struct)) kzalloc(sizeof(*ptr_to_struct), GFP_KERNEL)) +struct kfd_device_info {const struct kfd_scheduler_class *scheduler_class;unsigned int max_pasid_bits;
@@ -72,6 +80,15 @@ struct kfd_process {extern struct device *kfd_device; +/* Topology */ +int kfd_topology_init (void ); +void kfd_topology_shutdown (void ); +int kfd_topology_add_device (struct kfd_dev *gpu); +int kfd_topology_remove_device (struct kfd_dev *gpu); +struct kfd_dev *kfd_device_by_id (uint32_t gpu_id); +struct kfd_dev *kfd_device_by_pci_dev (const struct pci_dev *pdev); +struct kfd_dev *kfd_topology_enum_kfd_devices (uint8_t idx); +/* Interrupts */ void kgd2kfd_interrupt (struct kfd_dev *dev,const void *ih_ring_entry);
drivers/gpu/drm/radeon/amdkfd/kfd_topology.c new file +1207 -0
1,207 lines not on this page · raw message
drivers/gpu/drm/radeon/amdkfd/kfd_topology.h new file +168 -0
168 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH v3 11/23 amdkfd: Add binding/unbinding calls to amd_iommu driver
In reply to Oded GabbayThis patch adds the functions to bind and unbind pasid from a device through the amd_iommu driver.
The unbind function is called when the mm_struct of the process is released.
The bind function is not called here because it is called only in the IOCTLs which are not yet implemented at this stage of the patchset.
--- drivers/gpu/drm/radeon/amdkfd/kfd_device.c | 86 ++++++++++++++++++++++++++++- drivers/gpu/drm/radeon/amdkfd/kfd_priv.h | 1 + drivers/gpu/drm/radeon/amdkfd/kfd_process.c | 12 ++++ 3 files changed, 98 insertions(+), 1 deletion(-)
drivers/gpu/drm/radeon/amdkfd/kfd_device.c +85 -1
@@ -98,6 +98,63 @@ struct kfd_dev *kgd2kfd_probe(struct kgd_dev *kgd, struct pci_dev *pdev)return kfd; } +static bool device_iommu_pasid_init (struct kfd_dev *kfd) +{ +const u32 required_iommu_flags =AMD_IOMMU_DEVICE_FLAG_ATS_SUP |AMD_IOMMU_DEVICE_FLAG_PRI_SUP + |AMD_IOMMU_DEVICE_FLAG_PASID_SUP ; + +struct amd_iommu_device_info iommu_info; +unsigned int pasid_limit; +int err; + + err =amd_iommu_device_info (kfd->pdev, &iommu_info); +if (err <0 ) { +dev_err (kfd_device,"error getting iommu info. is the iommu enabled?\n" ); +return false; + } + +if ((iommu_info.flags & required_iommu_flags) != required_iommu_flags) { +dev_err (kfd_device,"error required iommu flags ats(%i), pri(%i), pasid(%i)\n" , + (iommu_info.flags &AMD_IOMMU_DEVICE_FLAG_ATS_SUP ) !=0 , + (iommu_info.flags &AMD_IOMMU_DEVICE_FLAG_PRI_SUP ) !=0 , + (iommu_info.flags &AMD_IOMMU_DEVICE_FLAG_PASID_SUP ) !=0 ); +return false; + } + + pasid_limit = min_t(unsigned int, + (unsigned int )1 << kfd->device_info->max_pasid_bits, + iommu_info.max_pasids); +/* +* last pasid is used for kernel queues doorbells +* in the future the last pasid might be used for a kernel thread. +*/ + pasid_limit = min_t(unsigned int, + pasid_limit, + kfd->doorbell_process_limit -1 ); + + err =amd_iommu_init_device (kfd->pdev, pasid_limit); +if (err <0 ) { +dev_err (kfd_device,"error initializing iommu device\n" ); +return false; + } + +if (!kfd_set_pasid_limit (pasid_limit)) { +dev_err (kfd_device,"error setting pasid limit\n" ); +amd_iommu_free_device (kfd->pdev); +return false; + } + +return true; +} + +static void iommu_pasid_shutdown_callback (struct pci_dev *pdev,int pasid) +{ +struct kfd_dev *dev =kfd_device_by_pci_dev (pdev); + +if (dev) +kfd_unbind_process_from_device (dev, pasid); +} +bool kgd2kfd_device_init (struct kfd_dev *kfd,const struct kgd2kfd_shared_resources *gpu_resources) {
@@ -129,6 +186,13 @@ bool kgd2kfd_device_init(struct kfd_dev *kfd, goto kfd_topology_add_device_error; } +if (!device_iommu_pasid_init (kfd)) { +dev_err (kfd_device, +"Error initializing iommuv2 for device (%x:%x)\n" , + kfd->pdev->vendor, kfd->pdev->device); + goto device_iommu_pasid_error; + } +amd_iommu_set_invalidate_ctx_cb (kfd->pdev, iommu_pasid_shutdown_callback); kfd->init_complete = true; dev_info(kfd_device, "added device (%x:%x)\n", kfd->pdev->vendor,
@@ -136,6 +200,8 @@ bool kgd2kfd_device_init(struct kfd_dev *kfd, goto out; +device_iommu_pasid_error: +kfd_topology_remove_device (kfd); kfd_topology_add_device_error: kfd2kgd->fini_sa_manager (kfd->kgd); dev_err(kfd_device,
@@ -147,7 +213,10 @@ out:void kgd2kfd_device_exit (struct kfd_dev *kfd) { -kfd_topology_remove_device (kfd); +if (kfd->init_complete) { +amd_iommu_free_device (kfd->pdev); +kfd_topology_remove_device (kfd); + }kfree (kfd); }
@@ -155,12 +224,27 @@ void kgd2kfd_device_exit(struct kfd_dev *kfd)void kgd2kfd_suspend (struct kfd_dev *kfd) {BUG_ON (kfd ==NULL ); + +if (kfd->init_complete) +amd_iommu_free_device (kfd->pdev); }int kgd2kfd_resume (struct kfd_dev *kfd) { +unsigned int pasid_limit; +int err; +BUG_ON (kfd ==NULL ); + pasid_limit =kfd_get_pasid_limit (); + +if (kfd->init_complete) { + err =amd_iommu_init_device (kfd->pdev, pasid_limit); +if (err <0 ) +return -ENXIO ; +amd_iommu_set_invalidate_ctx_cb (kfd->pdev, iommu_pasid_shutdown_callback); + } +return 0 ; }
drivers/gpu/drm/radeon/amdkfd/kfd_priv.h +1 -0
@@ -188,6 +188,7 @@ struct kfd_process {struct kfd_process *kfd_create_process (const struct task_struct *);struct kfd_process *kfd_get_process (const struct task_struct *); +void kfd_unbind_process_from_device (struct kfd_dev *dev,unsigned int pasid);struct kfd_process_device *kfd_get_process_device_data (struct kfd_dev *dev,struct kfd_process *p,int create_pdd);
drivers/gpu/drm/radeon/amdkfd/kfd_process.c +12 -0
@@ -24,6 +24,7 @@#include <linux/log2.h> #include <linux/sched.h> #include <linux/slab.h> +#include <linux/amd-iommu.h> #include <linux/notifier.h> struct mm_struct ;
@@ -150,6 +151,7 @@ static void kfd_process_notifier_release(struct mmu_notifier *mn,mutex_lock (&p->mutex);list_for_each_entry_safe (pdd, temp, &p->per_device_data, per_device_list) { +amd_iommu_unbind_pasid (pdd->dev->pdev, p->pasid);list_del (&pdd->per_device_list);kfree (pdd); }
@@ -255,6 +257,7 @@ struct kfd_process_device *kfd_bind_process_to_device(struct kfd_dev *dev, struct kfd_process *p) {struct kfd_process_device *pdd =kfd_get_process_device_data (dev, p,1 ); +int err;if (pdd ==NULL )return ERR_PTR (-ENOMEM );
@@ -262,6 +265,15 @@ struct kfd_process_device *kfd_bind_process_to_device(struct kfd_dev *dev,if (pdd->bound)return pdd; + err =amd_iommu_bind_pasid (dev->pdev, p->pasid, p->lead_thread); +if (err <0 ) +return ERR_PTR (err); + +if (err <0 ) { +amd_iommu_unbind_pasid (dev->pdev, p->pasid); +return ERR_PTR (err); + } + pdd->bound = true;return pdd;
Signature · 1 line
1.9.1
PATCH v3 12/23 amdkfd: Add queue module
In reply to Oded GabbayFrom: Ben Goz <[email protected]>
The queue module enables allocating and initializing queues uniformly.
v3: remove typedef
v3: break pr_debug to one line
v3: remove memset
v3: add documentation
--- drivers/gpu/drm/radeon/amdkfd/Makefile | 2 +- drivers/gpu/drm/radeon/amdkfd/kfd_priv.h | 123 +++++++++++++++++++++++++++++- drivers/gpu/drm/radeon/amdkfd/kfd_queue.c | 85 +++++++++++++++++++++ 3 files changed, 208 insertions(+), 2 deletions(-) create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_queue.c
drivers/gpu/drm/radeon/amdkfd/Makefile +1 -1
@@ -6,6 +6,6 @@ ccflags-y := -Iinclude/drm amdkfd-y := kfd_module.o kfd_device.o kfd_chardev.o kfd_topology.o \ kfd_pasid.o kfd_doorbell.o kfd_aperture.o \ - kfd_process.o + kfd_process.o kfd_queue.o obj-$(CONFIG_HSA_RADEON) += amdkfd.o
drivers/gpu/drm/radeon/amdkfd/kfd_priv.h +122 -1
135 lines not on this page · raw message
drivers/gpu/drm/radeon/amdkfd/kfd_queue.c new file +85 -0
85 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH v3 10/23 amdkfd: Add basic modules to amdkfd
In reply to Oded GabbayFrom: Andrew Lewycky <[email protected]>
This patch adds the process module and three helper modules:
- kfd_process, which handles process which open /dev/kfd
- kfd_doorbell, which provides helper functions for doorbell allocation, release and mapping to userspace
- kfd_pasid, which provides helper functions for pasid allocation and release
- kfd_aperture, which provides helper functions for managing the LDS, Local GPU memory and Scratch memory apertures of the process
This patch only contains the basic kfd_process module, which doesn't contain the reference to the queue scheduler. This was done to allow easier code review.
Also, this patch doesn't contain the calls to the IOMMU driver for binding the pasid to the device. Again, this was done to allow easier code review
The kfd_process object is created when a process opens /dev/kfd and is closed when the mm_struct of that process is teared-down.
v3: Remove kfd_vidmem file
v3: Replace direct mmput call to mmu_notifier release
v3: remove typedefs
v3: move bool to end of struct
v3: Add new kernel params for gart usage limitation
v3: init sa manager
v3: fix debug msgs
v3: remove support for LDS in 32 bit
v3: Change code to support mmap of doorbell pages from userspace
v3: Add documentation for apertures
--- drivers/gpu/drm/radeon/amdkfd/Makefile | 4 +- drivers/gpu/drm/radeon/amdkfd/kfd_aperture.c | 350 +++++++++++++++++++++++++++ drivers/gpu/drm/radeon/amdkfd/kfd_chardev.c | 31 ++- drivers/gpu/drm/radeon/amdkfd/kfd_device.c | 45 +++- drivers/gpu/drm/radeon/amdkfd/kfd_doorbell.c | 236 ++++++++++++++++++ drivers/gpu/drm/radeon/amdkfd/kfd_module.c | 32 ++- drivers/gpu/drm/radeon/amdkfd/kfd_pasid.c | 95 ++++++++ drivers/gpu/drm/radeon/amdkfd/kfd_priv.h | 141 +++++++++++ drivers/gpu/drm/radeon/amdkfd/kfd_process.c | 319 ++++++++++++++++++++++++ drivers/gpu/drm/radeon/radeon_kfd.c | 21 +- 10 files changed, 1247 insertions(+), 27 deletions(-) create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_aperture.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_doorbell.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_pasid.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_process.c
drivers/gpu/drm/radeon/amdkfd/Makefile +3 -1
@@ -4,6 +4,8 @@ ccflags-y := -Iinclude/drm -amdkfd-y := kfd_module.o kfd_device.o kfd_chardev.o kfd_topology.o +amdkfd-y := kfd_module.o kfd_device.o kfd_chardev.o kfd_topology.o \ + kfd_pasid.o kfd_doorbell.o kfd_aperture.o \ + kfd_process.o obj-$(CONFIG_HSA_RADEON) += amdkfd.o
drivers/gpu/drm/radeon/amdkfd/kfd_aperture.c new file +350 -0
350 lines not on this page · raw message
drivers/gpu/drm/radeon/amdkfd/kfd_chardev.c +29 -2
@@ -38,6 +38,7 @@static long kfd_ioctl (struct file *,unsigned int ,unsigned long );static int kfd_open (struct inode *,struct file *); +static int kfd_mmap (struct file *,struct vm_area_struct *);static const char kfd_dev_name[] ="kfd" ;
@@ -46,6 +47,7 @@ static const struct file_operations kfd_fops = { .unlocked_ioctl = kfd_ioctl, .compat_ioctl = kfd_ioctl, .open = kfd_open, + .mmap = kfd_mmap, };static int kfd_char_dev_major =-1 ;
@@ -96,9 +98,22 @@ struct device *kfd_chardev(void)static int kfd_open (struct inode *inode,struct file *filep) { +struct kfd_process *process; +if (iminor (inode) !=0 )return -ENODEV ; + process =kfd_create_process (current); +if (IS_ERR (process)) +return PTR_ERR (process); + + process->is_32bit_user_mode =is_compat_task (); + +dev_dbg (kfd_device,"process %d opened, compat mode (32 bit) - %d\n" , + process->pasid, process->is_32bit_user_mode); + +kfd_init_apertures (process); +return 0 ; }
@@ -142,8 +157,9 @@ static long kfd_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)"ioctl cmd 0x%x (#%d), arg 0x%lx\n" , cmd, _IOC_NR(cmd), arg); -/* TODO: add function that retrieves process */ - process =NULL ; + process =kfd_get_process (current); +if (IS_ERR (process)) +return PTR_ERR (process);switch (cmd) {case KFD_IOC_CREATE_QUEUE :
@@ -185,3 +201,14 @@ static long kfd_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)return err; } + +static int kfd_mmap (struct file *filp,struct vm_area_struct *vma) +{ +struct kfd_process *process; + + process =kfd_get_process (current); +if (IS_ERR (process)) +return PTR_ERR (process); + +return kfd_doorbell_mmap (process, vma); +}
drivers/gpu/drm/radeon/amdkfd/kfd_device.c +39 -6
74 lines not on this page · raw message
drivers/gpu/drm/radeon/amdkfd/kfd_doorbell.c new file +236 -0
236 lines not on this page · raw message
drivers/gpu/drm/radeon/amdkfd/kfd_module.c +31 -1
@@ -22,7 +22,6 @@#include <linux/module.h> #include <linux/sched.h> -#include <linux/notifier.h> #include <linux/moduleparam.h> #include <linux/device.h> #include "kfd_priv.h"
@@ -46,6 +45,16 @@ static const struct kgd2kfd_calls kgd2kfd = { .resume = kgd2kfd_resume, }; +int max_num_of_processes =KFD_MAX_NUM_OF_PROCESSES_DEFAULT ; +module_param (max_num_of_processes, int,0444 ); +MODULE_PARM_DESC (max_num_of_processes, +"Kernel cmdline parameter that defines the amdkfd maximum number of supported processes" ); + +int max_num_of_queues_per_process =KFD_MAX_NUM_OF_QUEUES_PER_PROCESS_DEFAULT ; +module_param (max_num_of_queues_per_process, int,0444 ); +MODULE_PARM_DESC (max_num_of_queues_per_process, +"Kernel cmdline parameter that defines the amdkfd maximum number of supported queues per process" ); +bool kgd2kfd_init (unsigned interface_version,const struct kfd2kgd_calls *f2g,const struct kgd2kfd_calls **g2f)
@@ -69,6 +78,24 @@ static int __init kfd_module_init(void) {int err; +/* Verify module parameters */ +if ((max_num_of_processes <0 ) || + (max_num_of_processes >KFD_MAX_NUM_OF_PROCESSES )) { +pr_err ("kfd: max_num_of_processes must be between 0 to KFD_MAX_NUM_OF_PROCESSES\n" ); +return -1 ; + } + +if ((max_num_of_queues_per_process <0 ) || + (max_num_of_queues_per_process > +KFD_MAX_NUM_OF_QUEUES_PER_PROCESS )) { +pr_err ("kfd: max_num_of_queues_per_process must be between 0 to KFD_MAX_NUM_OF_QUEUES_PER_PROCESS\n" ); +return -1 ; + } + + err =kfd_pasid_init (); +if (err <0 ) + goto err_pasid; + err =kfd_chardev_init ();if (err <0 ) goto err_ioctl;
@@ -84,6 +111,8 @@ static int __init kfd_module_init(void) err_topology:kfd_chardev_exit (); err_ioctl: +kfd_pasid_exit (); +err_pasid:return err; }
@@ -91,6 +120,7 @@ static void __exit kfd_module_exit(void) {kfd_topology_shutdown ();kfd_chardev_exit (); +kfd_pasid_exit ();dev_info (kfd_device,"Removed module\n" ); }
drivers/gpu/drm/radeon/amdkfd/kfd_pasid.c new file +95 -0
95 lines not on this page · raw message
drivers/gpu/drm/radeon/amdkfd/kfd_priv.h +141 -0
178 lines not on this page · raw message
drivers/gpu/drm/radeon/amdkfd/kfd_process.c new file +319 -0
319 lines not on this page · raw message
drivers/gpu/drm/radeon/radeon_kfd.c +4 -17
@@ -177,8 +177,7 @@ static u32 pool_to_domain(enum kgd_memory_pool p)static int init_sa_manager (struct kgd_dev *kgd,unsigned int size) {struct radeon_device *rdev = (struct radeon_device *)kgd; -u64 max_offset[4 ]; -int r, i; +int r;BUG_ON (kgd ==NULL );
@@ -191,21 +190,9 @@ static int init_sa_manager(struct kgd_dev *kgd, unsigned int size)if (r)return r; -/* Try to pin buffer in first 8MB, 16MB or 64MB of GART */ - max_offset[0 ] =roundup (size,8 *1024 *1024 ); - max_offset[1 ] =roundup (size,16 *1024 *1024 ); - max_offset[2 ] =roundup (size,64 *1024 *1024 ); - max_offset[3 ] =0 ; - -for (i =0 ; i <4 ; i++) { - - r =radeon_sa_bo_manager_start (rdev, &rdev->kfd_bo, - max_offset[i]); -if (!r) -return r; - } - -radeon_sa_bo_manager_fini (rdev, &rdev->kfd_bo); + r =radeon_sa_bo_manager_start (rdev, &rdev->kfd_bo); +if (r) +radeon_sa_bo_manager_fini (rdev, &rdev->kfd_bo);return r; }
Signature · 6 lines
1.9.1 _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v3 16/23 amdkfd: Add packet manager module
In reply to Oded GabbayFrom: Ben Goz <[email protected]>
The packet manager module builds PM4 packets for the sole use of the CP scheduler. Those packets are used by the HIQ to submit runlists to the CP.
v3: remove include of cik_mqds.h
v3: Change lower_32/upper_32 calls to use linux macros
v3: use new gart allocation functions
v3: add documentation
--- drivers/gpu/drm/radeon/amdkfd/Makefile | 2 +- drivers/gpu/drm/radeon/amdkfd/kfd_packet_manager.c | 495 +++++++++++++++++++++ drivers/gpu/drm/radeon/amdkfd/kfd_priv.h | 72 +++ 3 files changed, 568 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_packet_manager.c
drivers/gpu/drm/radeon/amdkfd/Makefile +1 -1
@@ -7,6 +7,6 @@ ccflags-y := -Iinclude/drm amdkfd-y := kfd_module.o kfd_device.o kfd_chardev.o kfd_topology.o \ kfd_pasid.o kfd_doorbell.o kfd_aperture.o \ kfd_process.o kfd_queue.o kfd_mqd_manager.o \ - kfd_kernel_queue.o + kfd_kernel_queue.o kfd_packet_manager.o obj-$(CONFIG_HSA_RADEON) += amdkfd.o
drivers/gpu/drm/radeon/amdkfd/kfd_packet_manager.c new file +495 -0
495 lines not on this page · raw message
drivers/gpu/drm/radeon/amdkfd/kfd_priv.h +72 -0
102 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH v3 13/23 amdkfd: Add mqd_manager module
In reply to Oded GabbayFrom: Ben Goz <[email protected]>
The mqd_manager module handles MQD data structures.
MQD stands for Memory Queue Descriptor, which is used by the H/W to keep the usermode queue state in memory.
v3: remove new typedefs
v3: remove pragma pack 4
v3: remove cik_mqds.h
v3: Change lower_32/upper_32 calls to use linux macros
v3: use new gart allocation functions
v3: Add documentation
--- drivers/gpu/drm/radeon/amdkfd/Makefile | 2 +- drivers/gpu/drm/radeon/amdkfd/cik_regs.h | 220 +++++++++++++++++ drivers/gpu/drm/radeon/amdkfd/kfd_mqd_manager.c | 305 ++++++++++++++++++++++++ drivers/gpu/drm/radeon/amdkfd/kfd_mqd_manager.h | 88 +++++++ drivers/gpu/drm/radeon/amdkfd/kfd_priv.h | 11 + 5 files changed, 625 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/drm/radeon/amdkfd/cik_regs.h create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_mqd_manager.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_mqd_manager.h
drivers/gpu/drm/radeon/amdkfd/Makefile +1 -1
@@ -6,6 +6,6 @@ ccflags-y := -Iinclude/drm amdkfd-y := kfd_module.o kfd_device.o kfd_chardev.o kfd_topology.o \ kfd_pasid.o kfd_doorbell.o kfd_aperture.o \ - kfd_process.o kfd_queue.o + kfd_process.o kfd_queue.o kfd_mqd_manager.o obj-$(CONFIG_HSA_RADEON) += amdkfd.o
drivers/gpu/drm/radeon/amdkfd/cik_regs.h new file +220 -0
220 lines not on this page · raw message
drivers/gpu/drm/radeon/amdkfd/kfd_mqd_manager.c new file +305 -0
305 lines not on this page · raw message
drivers/gpu/drm/radeon/amdkfd/kfd_mqd_manager.h new file +88 -0
88 lines not on this page · raw message
drivers/gpu/drm/radeon/amdkfd/kfd_priv.h +11 -0
@@ -237,6 +237,17 @@ struct queue {struct kfd_dev *device; }; +/* +* Please read the kfd_mqd_manager.h description. +*/ +enum KFD_MQD_TYPE { +KFD_MQD_TYPE_CIK_COMPUTE =0 ,/* for no cp scheduling */ +KFD_MQD_TYPE_CIK_HIQ ,/* for hiq */ +KFD_MQD_TYPE_CIK_CP ,/* for cp queues and diq */ +KFD_MQD_TYPE_CIK_SDMA ,/* for sdma queues */ +KFD_MQD_TYPE_MAX +}; +/* Data that is per-process-per device. */ struct kfd_process_device {/*
Signature · 1 line
1.9.1
PATCH v3 15/23 amdkfd: Add module parameter of scheduling policy
In reply to Oded GabbayFrom: Ben Goz <[email protected]>
This patch adds a new parameter to the amdkfd driver. This parameter enables the user to select the scheduling policy of the CP. The choices are:
* CP Scheduling with support for over-subscription
* CP Scheduling without support for over-subscription
* Without CP Scheduling
Note that the third option (Without CP scheduling) is only for debug purposes and bringup of new H/W. As such, it is _not_ guaranteed to work at all times on all H/W versions.
v3: fix description
v3: change permissions to read_only
v3: verify value
v3: add documentation
--- drivers/gpu/drm/radeon/amdkfd/kfd_module.c | 12 ++++++++++++ drivers/gpu/drm/radeon/amdkfd/kfd_priv.h | 29 +++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+)
drivers/gpu/drm/radeon/amdkfd/kfd_module.c +12 -0
@@ -45,6 +45,11 @@ static const struct kgd2kfd_calls kgd2kfd = { .resume = kgd2kfd_resume, }; +int sched_policy =KFD_SCHED_POLICY_HWS_NO_OVERSUBSCRIPTION ; +module_param (sched_policy, int,0444 ); +MODULE_PARM_DESC (sched_policy, +"Kernel cmdline parameter that defines the amdkfd scheduling policy" ); +int max_num_of_processes =KFD_MAX_NUM_OF_PROCESSES_DEFAULT ;module_param (max_num_of_processes, int,0444 ); MODULE_PARM_DESC(max_num_of_processes,
@@ -79,6 +84,13 @@ static int __init kfd_module_init(void)int err;/* Verify module parameters */ +if ((sched_policy <KFD_SCHED_POLICY_HWS ) || + (sched_policy >KFD_SCHED_POLICY_NO_HWS )) { +pr_err ("kfd: sched_policy has invalid value\n" ); +return -1 ; + } + +/* Verify module parameters */ if ((max_num_of_processes <0 ) || (max_num_of_processes >KFD_MAX_NUM_OF_PROCESSES )) {pr_err ("kfd: max_num_of_processes must be between 0 to KFD_MAX_NUM_OF_PROCESSES\n" );
drivers/gpu/drm/radeon/amdkfd/kfd_priv.h +29 -0
@@ -65,6 +65,35 @@ extern int max_num_of_queues_per_process;#define KFD_MAX_NUM_OF_QUEUES_PER_PROCESS_DEFAULT 128#define KFD_MAX_NUM_OF_QUEUES_PER_PROCESS 1024 +/* Kernel module parameter to specify the scheduling policy */ +extern int sched_policy; + +/** +* enum kfd_sched_policy +* +* @KFD_SCHED_POLICY_HWS: H/W scheduling policy known as command processor (cp) +* scheduling. In this scheduling mode we're using the firmware code to schedule +* the user mode queues and kernel queues such as HIQ and DIQ. +* the HIQ queue is used as a special queue that dispatches the configuration to +* the cp and the user mode queues list that are currently running. +* the DIQ queue is a debugging queue that dispatches debugging commands to the +* firmware. +* in this scheduling mode user mode queues over subscription feature is enabled. +* +* @KFD_SCHED_POLICY_HWS_NO_OVERSUBSCRIPTION: The same as above but the over +* subscription feature disabled. +* +* @KFD_SCHED_POLICY_NO_HWS: no H/W scheduling policy is a mode which directly +* set the command processor registers and sets the queues "manually". This mode +* is used *ONLY* for debugging proposes. +* +*/ +enum kfd_sched_policy { +KFD_SCHED_POLICY_HWS =0 , +KFD_SCHED_POLICY_HWS_NO_OVERSUBSCRIPTION , +KFD_SCHED_POLICY_NO_HWS +}; +enum cache_policy { cache_policy_coherent, cache_policy_noncoherent
Signature · 1 line
1.9.1
PATCH v3 14/23 amdkfd: Add kernel queue module
In reply to Oded GabbayFrom: Ben Goz <[email protected]>
The kernel queue module enables the amdkfd to establish kernel queues, not exposed to user space.
The kernel queues are used for HIQ (HSA Interface Queue) and DIQ (Debug Interface Queue) operations
v3: remove use of internal typedefs
v3: use new gart allocation functions
--- drivers/gpu/drm/radeon/amdkfd/Makefile | 3 +- .../drm/radeon/amdkfd/kfd_device_queue_manager.h | 101 +++ drivers/gpu/drm/radeon/amdkfd/kfd_kernel_queue.c | 330 ++++++++++ drivers/gpu/drm/radeon/amdkfd/kfd_kernel_queue.h | 66 ++ drivers/gpu/drm/radeon/amdkfd/kfd_pm4_headers.h | 682 +++++++++++++++++++++ drivers/gpu/drm/radeon/amdkfd/kfd_pm4_opcodes.h | 107 ++++ drivers/gpu/drm/radeon/amdkfd/kfd_priv.h | 33 +- 7 files changed, 1320 insertions(+), 2 deletions(-) create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_device_queue_manager.h create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_kernel_queue.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_kernel_queue.h create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_pm4_headers.h create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_pm4_opcodes.h
drivers/gpu/drm/radeon/amdkfd/Makefile +2 -1
@@ -6,6 +6,7 @@ ccflags-y := -Iinclude/drm amdkfd-y := kfd_module.o kfd_device.o kfd_chardev.o kfd_topology.o \ kfd_pasid.o kfd_doorbell.o kfd_aperture.o \ - kfd_process.o kfd_queue.o kfd_mqd_manager.o + kfd_process.o kfd_queue.o kfd_mqd_manager.o \ + kfd_kernel_queue.o obj-$(CONFIG_HSA_RADEON) += amdkfd.o
drivers/gpu/drm/radeon/amdkfd/kfd_device_queue_manager.h new file +101 -0
101 lines not on this page · raw message
drivers/gpu/drm/radeon/amdkfd/kfd_kernel_queue.c new file +330 -0
330 lines not on this page · raw message
drivers/gpu/drm/radeon/amdkfd/kfd_kernel_queue.h new file +66 -0
66 lines not on this page · raw message
drivers/gpu/drm/radeon/amdkfd/kfd_pm4_headers.h new file +682 -0
682 lines not on this page · raw message
drivers/gpu/drm/radeon/amdkfd/kfd_pm4_opcodes.h new file +107 -0
107 lines not on this page · raw message
drivers/gpu/drm/radeon/amdkfd/kfd_priv.h +32 -1
@@ -35,6 +35,15 @@#define KFD_SYSFS_FILE_MODE 0444 +/* +* When working with cp scheduler we should assign the HIQ manually or via the radeon driver +* to a fixed hqd slot, here are the fixed HIQ hqd slot definitions for Kaveri. +* In Kaveri only the first ME queues participates in the cp scheduling taking that in mind +* we set the HIQ slot in the second ME. +*/ +#define KFD_CIK_HIQ_PIPE 4 +#define KFD_CIK_HIQ_QUEUE 0 +/* GPU ID hash width in bits */ #define KFD_GPU_ID_HASH_WIDTH 16
@@ -56,6 +65,11 @@ extern int max_num_of_queues_per_process;#define KFD_MAX_NUM_OF_QUEUES_PER_PROCESS_DEFAULT 128#define KFD_MAX_NUM_OF_QUEUES_PER_PROCESS 1024 +enum cache_policy { + cache_policy_coherent, + cache_policy_noncoherent +}; +struct kfd_device_info {const struct kfd_scheduler_class *scheduler_class;unsigned int max_pasid_bits;
@@ -83,8 +97,10 @@ struct kfd_dev {struct kgd2kfd_shared_resources shared_resources; -bool init_complete; +/* QCM Device instance */ +struct device_queue_manager *dqm; +bool init_complete; };/* KGD2KFD callbacks */
@@ -366,6 +382,21 @@ int kgd2kfd_resume(struct kfd_dev *dev);/* amdkfd Apertures */ int kfd_init_apertures (struct kfd_process *process); +/* Queue Context Management */ +int init_queue (struct queue **q,struct queue_properties properties); +void uninit_queue (struct queue *q); +void print_queue (struct queue *q); + +/* Packet Manager */ + +struct packet_manager { +struct device_queue_manager *dqm; +struct kernel_queue *priv_queue; +struct mutex lock; +bool allocated; +struct kfd_mem_obj *ib_buffer_obj; +}; +uint64_t kfd_get_number_elems (struct kfd_dev *kfd);phys_addr_t kfd_get_process_doorbells (struct kfd_dev *dev,struct kfd_process *process);
Signature · 1 line
1.9.1
PATCH v3 17/23 amdkfd: Add process queue manager module
In reply to Oded GabbayFrom: Ben Goz <[email protected]>
The queue scheduler divides into two sections, one section is process bounded and the other section is device bounded.
The process bounded section is handled by this module. The PQM handles usermode queue setup, updates and tear-down.
v3: use kernel param to limit queues per process instead of define
v3: use doorbell address from user
--- drivers/gpu/drm/radeon/amdkfd/Makefile | 3 +- drivers/gpu/drm/radeon/amdkfd/kfd_priv.h | 17 + drivers/gpu/drm/radeon/amdkfd/kfd_process.c | 16 + .../drm/radeon/amdkfd/kfd_process_queue_manager.c | 343 +++++++++++++++++++++ 4 files changed, 378 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_process_queue_manager.c
drivers/gpu/drm/radeon/amdkfd/Makefile +2 -1
@@ -7,6 +7,7 @@ ccflags-y := -Iinclude/drm amdkfd-y := kfd_module.o kfd_device.o kfd_chardev.o kfd_topology.o \ kfd_pasid.o kfd_doorbell.o kfd_aperture.o \ kfd_process.o kfd_queue.o kfd_mqd_manager.o \ - kfd_kernel_queue.o kfd_packet_manager.o + kfd_kernel_queue.o kfd_packet_manager.o \ + kfd_process_queue_manager.o obj-$(CONFIG_HSA_RADEON) += amdkfd.o
drivers/gpu/drm/radeon/amdkfd/kfd_priv.h +17 -0
@@ -365,6 +365,9 @@ struct kfd_process_device {struct kfd_dev *dev; +/* per-process-per device QCM data structure */ +struct qcm_process_device qpd; +/*Apertures*/ uint64_t lds_base;uint64_t lds_limit;
@@ -410,6 +413,8 @@ struct kfd_process {*/ struct list_head per_device_data; +struct process_queue_manager pqm; +/* The process's queues. */ size_t queue_array_size;
@@ -477,11 +482,23 @@ inline uint32_t upper_32(uint64_t x);int init_queue (struct queue **q,struct queue_properties properties);void uninit_queue (struct queue *q); +void print_queue_properties (struct queue_properties *q);void print_queue (struct queue *q);struct kernel_queue *kernel_queue_init (struct kfd_dev *dev,enum kfd_queue_type type);void kernel_queue_uninit (struct kernel_queue *kq); +/* Process Queue Manager */ +struct process_queue_node { +struct queue *q; +struct kernel_queue *kq; +struct list_head process_queue_list; +}; + +int pqm_init (struct process_queue_manager *pqm,struct kfd_process *p); +void pqm_uninit (struct process_queue_manager *pqm); +int pqm_destroy_queue (struct process_queue_manager *pqm,unsigned int qid); +/* Packet Manager */ #define KFD_HIQ_TIMEOUT (500)
drivers/gpu/drm/radeon/amdkfd/kfd_process.c +16 -0
@@ -150,6 +150,9 @@ static void kfd_process_notifier_release(struct mmu_notifier *mn,mutex_lock (&p->mutex); +/* In case our notifier is called before IOMMU notifier */ +pqm_uninit (&p->pqm); +list_for_each_entry_safe (pdd, temp, &p->per_device_data, per_device_list) {amd_iommu_unbind_pasid (pdd->dev->pdev, p->pasid);list_del (&pdd->per_device_list);
@@ -214,8 +217,16 @@ static struct kfd_process *create_process(const struct task_struct *thread)INIT_LIST_HEAD (&process->per_device_data); + err =pqm_init (&process->pqm, process); +if (err !=0 ) + goto err_process_pqm_init; +return process; +err_process_pqm_init: +hash_del_rcu (&process->kfd_processes); +synchronize_rcu (); +mmu_notifier_unregister_no_release (&process->mmu_notifier, process->mm); err_mmu_notifier:kfd_pasid_free (process->pasid); err_alloc_pasid:
@@ -240,6 +251,9 @@ struct kfd_process_device *kfd_get_process_device_data(struct kfd_dev *dev, pdd =kzalloc (sizeof (*pdd),GFP_KERNEL );if (pdd !=NULL ) { pdd->dev = dev; +INIT_LIST_HEAD (&pdd->qpd.queues_list); +INIT_LIST_HEAD (&pdd->qpd.priv_queue_list); + pdd->qpd.dqm = dev->dqm;list_add (&pdd->per_device_list, &p->per_device_data); } }
@@ -299,6 +313,8 @@ void kfd_unbind_process_from_device(struct kfd_dev *dev, unsigned int pasid)mutex_lock (&p->mutex); +pqm_uninit (&p->pqm); + pdd =kfd_get_process_device_data (dev, p,0 );/*
drivers/gpu/drm/radeon/amdkfd/kfd_process_queue_manager.c new file +343 -0
343 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH v3 18/23 amdkfd: Add device queue manager module
In reply to Oded GabbayFrom: Ben Goz <[email protected]>
The queue scheduler divides into two sections, one section is process bounded and the other section is device bounded.
The device bounded section is handled by this module.
The DQM module handles queue setup, update and tear-down from the device side. It also supports suspend/resume operation.
v3: change device_init
v3: use new gart allocation functions
v3: Add documentation
--- drivers/gpu/drm/radeon/amdkfd/Makefile | 2 +- drivers/gpu/drm/radeon/amdkfd/kfd_device.c | 28 +- .../drm/radeon/amdkfd/kfd_device_queue_manager.c | 989 +++++++++++++++++++++ .../drm/radeon/amdkfd/kfd_device_queue_manager.h | 43 + drivers/gpu/drm/radeon/amdkfd/kfd_priv.h | 13 + 5 files changed, 1073 insertions(+), 2 deletions(-) create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_device_queue_manager.c
drivers/gpu/drm/radeon/amdkfd/Makefile +1 -1
@@ -8,6 +8,6 @@ amdkfd-y := kfd_module.o kfd_device.o kfd_chardev.o kfd_topology.o \ kfd_pasid.o kfd_doorbell.o kfd_aperture.o \ kfd_process.o kfd_queue.o kfd_mqd_manager.o \ kfd_kernel_queue.o kfd_packet_manager.o \ - kfd_process_queue_manager.o + kfd_process_queue_manager.o kfd_device_queue_manager.o obj-$(CONFIG_HSA_RADEON) += amdkfd.o
drivers/gpu/drm/radeon/amdkfd/kfd_device.c +27 -1
@@ -25,6 +25,7 @@#include <linux/pci.h> #include <linux/slab.h> #include "kfd_priv.h" +#include "kfd_device_queue_manager.h" #define MQD_SIZE_ALIGNED 768
@@ -194,12 +195,33 @@ bool kgd2kfd_device_init(struct kfd_dev *kfd, }amd_iommu_set_invalidate_ctx_cb (kfd->pdev, iommu_pasid_shutdown_callback); + kfd->dqm =device_queue_manager_init (kfd); +if (!kfd->dqm) { +dev_err (kfd_device, +"Error initializing queue manager for device (%x:%x)\n" , + kfd->pdev->vendor, kfd->pdev->device); + goto device_queue_manager_error; + } + +if (kfd->dqm->start (kfd->dqm) !=0 ) { +dev_err (kfd_device, +"Error starting queuen manager for device (%x:%x)\n" , + kfd->pdev->vendor, kfd->pdev->device); + goto dqm_start_error; + } + kfd->init_complete = true;dev_info (kfd_device,"added device (%x:%x)\n" , kfd->pdev->vendor, kfd->pdev->device); +pr_debug ("kfd: Starting kfd with the following scheduling policy %d\n" , sched_policy); + goto out; +dqm_start_error: +device_queue_manager_uninit (kfd->dqm); +device_queue_manager_error: +amd_iommu_free_device (kfd->pdev); device_iommu_pasid_error:kfd_topology_remove_device (kfd); kfd_topology_add_device_error:
@@ -214,6 +236,7 @@ out:void kgd2kfd_device_exit (struct kfd_dev *kfd) {if (kfd->init_complete) { +device_queue_manager_uninit (kfd->dqm);amd_iommu_free_device (kfd->pdev);kfd_topology_remove_device (kfd); }
@@ -225,8 +248,10 @@ void kgd2kfd_suspend(struct kfd_dev *kfd) {BUG_ON (kfd ==NULL ); -if (kfd->init_complete) +if (kfd->init_complete) { + kfd->dqm->stop (kfd->dqm);amd_iommu_free_device (kfd->pdev); + } }int kgd2kfd_resume (struct kfd_dev *kfd)
@@ -243,6 +268,7 @@ int kgd2kfd_resume(struct kfd_dev *kfd)if (err <0 )return -ENXIO ;amd_iommu_set_invalidate_ctx_cb (kfd->pdev, iommu_pasid_shutdown_callback); + kfd->dqm->start (kfd->dqm); }return 0 ;
drivers/gpu/drm/radeon/amdkfd/kfd_device_queue_manager.c new file +989 -0
989 lines not on this page · raw message
drivers/gpu/drm/radeon/amdkfd/kfd_device_queue_manager.h +43 -0
49 lines not on this page · raw message
drivers/gpu/drm/radeon/amdkfd/kfd_priv.h +13 -0
@@ -430,6 +430,7 @@ struct kfd_process {struct kfd_process *kfd_create_process (const struct task_struct *);struct kfd_process *kfd_get_process (const struct task_struct *); +struct kfd_process_device *kfd_bind_process_to_device (struct kfd_dev *dev,struct kfd_process *p);void kfd_unbind_process_from_device (struct kfd_dev *dev,unsigned int pasid); struct kfd_process_device *kfd_get_process_device_data(struct kfd_dev *dev, struct kfd_process *p,
@@ -485,6 +486,9 @@ void uninit_queue(struct queue *q);void print_queue_properties (struct queue_properties *q);void print_queue (struct queue *q); +struct mqd_manager *mqd_manager_init (enum KFD_MQD_TYPE type,struct kfd_dev *dev); +struct device_queue_manager *device_queue_manager_init (struct kfd_dev *dev); +void device_queue_manager_uninit (struct device_queue_manager *dqm);struct kernel_queue *kernel_queue_init (struct kfd_dev *dev,enum kfd_queue_type type);void kernel_queue_uninit (struct kernel_queue *kq);
@@ -503,6 +507,8 @@ int pqm_destroy_queue(struct process_queue_manager *pqm, unsigned int qid);#define KFD_HIQ_TIMEOUT (500) +#define KFD_FENCE_COMPLETED (100) +#define KFD_FENCE_INIT (10)#define KFD_UNMAP_LATENCY (15)struct packet_manager {
@@ -513,6 +519,13 @@ struct packet_manager {struct kfd_mem_obj *ib_buffer_obj; }; +int pm_init (struct packet_manager *pm,struct device_queue_manager *dqm); +void pm_uninit (struct packet_manager *pm); +int pm_send_set_resources (struct packet_manager *pm,struct scheduling_resources *res); +int pm_send_runlist (struct packet_manager *pm,struct list_head *dqm_queues); +int pm_send_query_status (struct packet_manager *pm,uint64_t fence_address,uint32_t fence_value); +int pm_send_unmap_queue (struct packet_manager *pm,enum kfd_queue_type type, +enum kfd_preempt_type_filter mode,uint32_t filter_param,bool reset);void pm_release_ib (struct packet_manager *pm);uint64_t kfd_get_number_elems (struct kfd_dev *kfd);
Signature · 1 line
1.9.1
PATCH v3 20/23 amdkfd: Implement the create/destroy/update queue IOCTLs
In reply to Oded GabbayFrom: Ben Goz <[email protected]>
v3: remove use of internal typedefs
v3: fix debug prints
v3: add checks for parameters
v3: use doorbell address from user
--- drivers/gpu/drm/radeon/amdkfd/kfd_chardev.c | 182 ++++++++++++++++++++- drivers/gpu/drm/radeon/amdkfd/kfd_priv.h | 8 + .../drm/radeon/amdkfd/kfd_process_queue_manager.c | 5 +- include/uapi/linux/kfd_ioctl.h | 7 +- 4 files changed, 196 insertions(+), 6 deletions(-)
drivers/gpu/drm/radeon/amdkfd/kfd_chardev.c +179 -3
@@ -119,17 +119,193 @@ static int kfd_open(struct inode *inode, struct file *filep)static long kfd_ioctl_create_queue (struct file *filep,struct kfd_process *p,void __user *arg) { -return -ENODEV ; +struct kfd_ioctl_create_queue_args args; +struct kfd_dev *dev; +int err =0 ; +unsigned int queue_id; +struct kfd_process_device *pdd; +struct queue_properties q_properties; + +memset (&q_properties,0 ,sizeof (struct queue_properties )); + +if (copy_from_user (&args, arg,sizeof (args))) +return -EFAULT ; + +if (args.queue_percentage >KFD_MAX_QUEUE_PERCENTAGE ) { +pr_err ("kfd: queue percentage must be between 0 to KFD_MAX_QUEUE_PERCENTAGE\n" ); +return -EINVAL ; + } + +if (args.queue_priority >KFD_MAX_QUEUE_PRIORITY ) { +pr_err ("kfd: queue priority must be between 0 to KFD_MAX_QUEUE_PRIORITY\n" ); +return -EINVAL ; + } + +if ((args.ring_base_address) && + (!access_ok (VERIFY_WRITE , args.ring_base_address,sizeof (uint64_t )))) { +pr_err ("kfd: can't access ring base address\n" ); +return -EFAULT ; + } + +if (!is_power_of_2 (args.ring_size)) { +pr_err ("kfd: ring size must be between 0 to KFD_MAX_QUEUE_PERCENTAGE\n" ); +return -EINVAL ; + } + +if (!access_ok (VERIFY_WRITE , args.read_pointer_address,sizeof (uint32_t ))) { +pr_err ("kfd: can't access read pointer\n" ); +return -EFAULT ; + } + +if (!access_ok (VERIFY_WRITE , args.write_pointer_address,sizeof (uint32_t ))) { +pr_err ("kfd: can't access write pointer\n" ); +return -EFAULT ; + } + + q_properties.is_interop = false; + q_properties.queue_percent = args.queue_percentage; + q_properties.priority = args.queue_priority; + q_properties.queue_address = args.ring_base_address; + q_properties.queue_size = args.ring_size; + q_properties.read_ptr = (uint32_t *) args.read_pointer_address; + q_properties.write_ptr = (uint32_t *) args.write_pointer_address; + + +pr_debug ("kfd: creating queue ioctl\n" ); + +pr_debug ("Queue Percentage (%d, %d)\n" , + q_properties.queue_percent, args.queue_percentage); + +pr_debug ("Queue Priority (%d, %d)\n" , + q_properties.priority, args.queue_priority); + +pr_debug ("Queue Address (0x%llX, 0x%llX)\n" , + q_properties.queue_address, args.ring_base_address); + +pr_debug ("Queue Size (0x%llX, %u)\n" , + q_properties.queue_size, args.ring_size); + +pr_debug ("Queue r/w Pointers (0x%llX, 0x%llX)\n" , + (uint64_t ) q_properties.read_ptr, + (uint64_t ) q_properties.write_ptr); + + dev =kfd_device_by_id (args.gpu_id); +if (dev ==NULL ) +return -EINVAL ; + +mutex_lock (&p->mutex); + + pdd =kfd_bind_process_to_device (dev, p); +if (IS_ERR (pdd) <0 ) { + err =PTR_ERR (pdd); + goto err_bind_process; + } + +pr_debug ("kfd: creating queue for PASID %d on GPU 0x%x\n" , + p->pasid, + dev->id); + + err =pqm_create_queue (&p->pqm, dev, filep, &q_properties,0 ,KFD_QUEUE_TYPE_COMPUTE , &queue_id); +if (err !=0 ) + goto err_create_queue; + + args.queue_id = queue_id; + +/* Return gpu_id as doorbell offset for mmap usage */ + args.doorbell_offset = args.gpu_id <<PAGE_SHIFT ; + +if (copy_to_user (arg, &args,sizeof (args))) { + err = -EFAULT ; + goto err_copy_args_out; + } + +mutex_unlock (&p->mutex); + +pr_debug ("kfd: queue id %d was created successfully\n" , args.queue_id); + +pr_debug ("ring buffer address == 0x%016llX\n" , + args.ring_base_address); + +pr_debug ("read ptr address == 0x%016llX\n" , + args.read_pointer_address); + +pr_debug ("write ptr address == 0x%016llX\n" , + args.write_pointer_address); + +return 0 ; + +err_copy_args_out: +pqm_destroy_queue (&p->pqm, queue_id); +err_create_queue: +err_bind_process: +mutex_unlock (&p->mutex); +return err; }static int kfd_ioctl_destroy_queue (struct file *filp,struct kfd_process *p,void __user *arg) { -return -ENODEV ; +int retval; +struct kfd_ioctl_destroy_queue_args args; + +if (copy_from_user (&args, arg,sizeof (args))) +return -EFAULT ; + +pr_debug ("kfd: destroying queue id %d for PASID %d\n" , + args.queue_id, + p->pasid); + +mutex_lock (&p->mutex); + + retval =pqm_destroy_queue (&p->pqm, args.queue_id); + +mutex_unlock (&p->mutex); +return retval; }static int kfd_ioctl_update_queue (struct file *filp,struct kfd_process *p,void __user *arg) { -return -ENODEV ; +int retval; +struct kfd_ioctl_update_queue_args args; +struct queue_properties properties; + +if (copy_from_user (&args, arg,sizeof (args))) +return -EFAULT ; + +if (args.queue_percentage >KFD_MAX_QUEUE_PERCENTAGE ) { +pr_err ("kfd: queue percentage must be between 0 to KFD_MAX_QUEUE_PERCENTAGE\n" ); +return -EINVAL ; + } + +if (args.queue_priority >KFD_MAX_QUEUE_PRIORITY ) { +pr_err ("kfd: queue priority must be between 0 to KFD_MAX_QUEUE_PRIORITY\n" ); +return -EINVAL ; + } + +if ((args.ring_base_address) && + (!access_ok (VERIFY_WRITE , args.ring_base_address,sizeof (uint64_t )))) { +pr_err ("kfd: can't access ring base address\n" ); +return -EFAULT ; + } + +if (!is_power_of_2 (args.ring_size)) { +pr_err ("kfd: ring size must be between 0 to KFD_MAX_QUEUE_PERCENTAGE\n" ); +return -EINVAL ; + } + + properties.queue_address = args.ring_base_address; + properties.queue_size = args.ring_size; + properties.queue_percent = args.queue_percentage; + properties.priority = args.queue_priority; + +pr_debug ("kfd: updating queue id %d for PASID %d\n" , args.queue_id, p->pasid); + +mutex_lock (&p->mutex); + + retval =pqm_update_queue (&p->pqm, args.queue_id, &properties); + +mutex_unlock (&p->mutex); + +return retval; }static long kfd_ioctl_set_memory_policy (struct file *filep,struct kfd_process *p,void __user *arg)
drivers/gpu/drm/radeon/amdkfd/kfd_priv.h +8 -0
@@ -513,7 +513,15 @@ struct process_queue_node {int pqm_init (struct process_queue_manager *pqm,struct kfd_process *p);void pqm_uninit (struct process_queue_manager *pqm); +int pqm_create_queue (struct process_queue_manager *pqm, +struct kfd_dev *dev, +struct file *f, +struct queue_properties *properties, +unsigned int flags, +enum kfd_queue_type type, +unsigned int *qid);int pqm_destroy_queue (struct process_queue_manager *pqm,unsigned int qid); +int pqm_update_queue (struct process_queue_manager *pqm,unsigned int qid,struct queue_properties *p);/* Packet Manager */
drivers/gpu/drm/radeon/amdkfd/kfd_process_queue_manager.c +4 -1
@@ -257,7 +257,10 @@ int pqm_destroy_queue(struct process_queue_manager *pqm, unsigned int qid)pr_debug ("kfd: In Func %s\n" , __func__); pqn =get_queue_by_qid (pqm, qid); -BUG_ON (!pqn); +if (pqn ==NULL ) { +pr_err ("kfd: queue id does not match any known queue\n" ); +return -EINVAL ; + } dev =NULL ;if (pqn->kq)
include/uapi/linux/kfd_ioctl.h +5 -2
@@ -34,8 +34,11 @@ struct kfd_ioctl_get_version_args { };/* For kfd_ioctl_create_queue_args.queue_type. */ -#define KFD_IOC_QUEUE_TYPE_COMPUTE 0 -#define KFD_IOC_QUEUE_TYPE_SDMA 1 +#define KFD_IOC_QUEUE_TYPE_COMPUTE 0 +#define KFD_IOC_QUEUE_TYPE_SDMA 1 + +#define KFD_MAX_QUEUE_PERCENTAGE 100 +#define KFD_MAX_QUEUE_PRIORITY 15struct kfd_ioctl_create_queue_args {uint64_t ring_base_address;/* to KFD */
Signature · 1 line
1.9.1
PATCH v3 21/23 amdkfd: Implement the Set Memory Policy IOCTL
In reply to Oded GabbayFrom: Andrew Lewycky <[email protected]>
--- drivers/gpu/drm/radeon/amdkfd/kfd_chardev.c | 51 ++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-)
drivers/gpu/drm/radeon/amdkfd/kfd_chardev.c +50 -1
@@ -35,6 +35,7 @@#include <uapi/asm-generic/mman-common.h> #include <asm/processor.h> #include "kfd_priv.h" +#include "kfd_device_queue_manager.h" static long kfd_ioctl (struct file *,unsigned int ,unsigned long );static int kfd_open (struct inode *,struct file *);
@@ -310,7 +311,55 @@ static int kfd_ioctl_update_queue(struct file *filp, struct kfd_process *p, voidstatic long kfd_ioctl_set_memory_policy (struct file *filep,struct kfd_process *p,void __user *arg) { -return -ENODEV ; +struct kfd_ioctl_set_memory_policy_args args; +struct kfd_dev *dev; +int err =0 ; +struct kfd_process_device *pdd; +enum cache_policy default_policy, alternate_policy; + +if (copy_from_user (&args, arg,sizeof (args))) +return -EFAULT ; + +if (args.default_policy !=KFD_IOC_CACHE_POLICY_COHERENT + && args.default_policy !=KFD_IOC_CACHE_POLICY_NONCOHERENT ) { +return -EINVAL ; + } + +if (args.alternate_policy !=KFD_IOC_CACHE_POLICY_COHERENT + && args.alternate_policy !=KFD_IOC_CACHE_POLICY_NONCOHERENT ) { +return -EINVAL ; + } + + dev =kfd_device_by_id (args.gpu_id); +if (dev ==NULL ) +return -EINVAL ; + +mutex_lock (&p->mutex); + + pdd =kfd_bind_process_to_device (dev, p); +if (IS_ERR (pdd) <0 ) { + err =PTR_ERR (pdd); + goto out; + } + + default_policy = (args.default_policy ==KFD_IOC_CACHE_POLICY_COHERENT ) + ? cache_policy_coherent : cache_policy_noncoherent; + + alternate_policy = (args.alternate_policy ==KFD_IOC_CACHE_POLICY_COHERENT ) + ? cache_policy_coherent : cache_policy_noncoherent; + +if (!dev->dqm->set_cache_memory_policy (dev->dqm, + &pdd->qpd, + default_policy, + alternate_policy, + (void __user *)args.alternate_aperture_base, + args.alternate_aperture_size)) + err = -EINVAL ; + +out: +mutex_unlock (&p->mutex); + +return err; }static long kfd_ioctl_get_clock_counters (struct file *filep,struct kfd_process *p,void __user *arg)
Signature · 1 line
1.9.1
PATCH v3 23/23 amdkfd: Implement the Get Process Aperture IOCTL
In reply to Oded GabbayFrom: Alexey Skidanov <[email protected]>
v3: fix debug msg
--- drivers/gpu/drm/radeon/amdkfd/kfd_chardev.c | 47 ++++++++++++++++++++++++++++- drivers/gpu/drm/radeon/amdkfd/kfd_priv.h | 5 +++ 2 files changed, 51 insertions(+), 1 deletion(-)
drivers/gpu/drm/radeon/amdkfd/kfd_chardev.c +46 -1
@@ -397,7 +397,52 @@ static long kfd_ioctl_get_clock_counters(struct file *filep, struct kfd_processstatic int kfd_ioctl_get_process_apertures (struct file *filp,struct kfd_process *p,void __user *arg) { -return -ENODEV ; +struct kfd_ioctl_get_process_apertures_args args; +struct kfd_process_device *pdd; + +dev_dbg (kfd_device,"get apertures for PASID %d" , p->pasid); + +if (copy_from_user (&args, arg,sizeof (args))) +return -EFAULT ; + + args.num_of_nodes =0 ; + +mutex_lock (&p->mutex); + +/*if the process-device list isn't empty*/ +if (kfd_has_process_device_data (p)) { +/* Run over all pdd of the process */ + pdd =kfd_get_first_process_device_data (p); +do { + + args.process_apertures[args.num_of_nodes].gpu_id = pdd->dev->id; + args.process_apertures[args.num_of_nodes].lds_base = pdd->lds_base; + args.process_apertures[args.num_of_nodes].lds_limit = pdd->lds_limit; + args.process_apertures[args.num_of_nodes].gpuvm_base = pdd->gpuvm_base; + args.process_apertures[args.num_of_nodes].gpuvm_limit = pdd->gpuvm_limit; + args.process_apertures[args.num_of_nodes].scratch_base = pdd->scratch_base; + args.process_apertures[args.num_of_nodes].scratch_limit = pdd->scratch_limit; + +dev_dbg (kfd_device,"node id %u\n" , args.num_of_nodes); +dev_dbg (kfd_device,"gpu id %u\n" , pdd->dev->id); +dev_dbg (kfd_device,"lds_base %llX\n" , pdd->lds_base); +dev_dbg (kfd_device,"lds_limit %llX\n" , pdd->lds_limit); +dev_dbg (kfd_device,"gpuvm_base %llX\n" , pdd->gpuvm_base); +dev_dbg (kfd_device,"gpuvm_limit %llX\n" , pdd->gpuvm_limit); +dev_dbg (kfd_device,"scratch_base %llX\n" , pdd->scratch_base); +dev_dbg (kfd_device,"scratch_limit %llX\n" , pdd->scratch_limit); + + args.num_of_nodes++; + }while ((pdd =kfd_get_next_process_device_data (p, pdd)) !=NULL && + (args.num_of_nodes <NUM_OF_SUPPORTED_GPUS )); + } + +mutex_unlock (&p->mutex); + +if (copy_to_user (arg, &args,sizeof (args))) +return -EFAULT ; + +return 0 ; }static long kfd_ioctl (struct file *filep,unsigned int cmd,unsigned long arg)
drivers/gpu/drm/radeon/amdkfd/kfd_priv.h +5 -0
@@ -445,6 +445,11 @@ struct kfd_process_device *kfd_get_process_device_data(struct kfd_dev *dev,struct kfd_process *p, int create_pdd); +/* Process device data iterator */ +struct kfd_process_device *kfd_get_first_process_device_data (struct kfd_process *p); +struct kfd_process_device *kfd_get_next_process_device_data (struct kfd_process *p,struct kfd_process_device *pdd); +bool kfd_has_process_device_data (struct kfd_process *p); +/* PASIDs */ int kfd_pasid_init (void );void kfd_pasid_exit (void );
Signature · 1 line
1.9.1
PATCH v3 22/23 amdkfd: Implement the Get Clock Counters IOCTL
In reply to Oded GabbayFrom: Evgeny Pinchuk <[email protected]>
--- drivers/gpu/drm/radeon/amdkfd/kfd_chardev.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-)
drivers/gpu/drm/radeon/amdkfd/kfd_chardev.c +28 -1
@@ -364,7 +364,34 @@ out:static long kfd_ioctl_get_clock_counters (struct file *filep,struct kfd_process *p,void __user *arg) { -return -ENODEV ; +struct kfd_ioctl_get_clock_counters_args args; +struct kfd_dev *dev; +struct timespec time; + +if (copy_from_user (&args, arg,sizeof (args))) +return -EFAULT ; + + dev =kfd_device_by_id (args.gpu_id); +if (dev ==NULL ) +return -EINVAL ; + +/* Reading GPU clock counter from KGD */ + args.gpu_clock_counter = kfd2kgd->get_gpu_clock_counter (dev->kgd); + +/* No access to rdtsc. Using raw monotonic time */ +getrawmonotonic (&time); + args.cpu_clock_counter = (uint64_t )timespec_to_ns (&time); + +get_monotonic_boottime (&time); + args.system_clock_counter = (uint64_t )timespec_to_ns (&time); + +/* Since the counter is in nano-seconds we use 1GHz frequency */ + args.system_clock_freq =1000000000 ; + +if (copy_to_user (arg, &args,sizeof (args))) +return -EFAULT ; + +return 0 ; }
Signature · 1 line
1.9.1
PATCH v3 19/23 amdkfd: Add interrupt handling module
In reply to Oded GabbayFrom: Andrew Lewycky <[email protected]>
This patch adds the interrupt handling module, in kfd_interrupt.c, and its related members in different data structures to the amdkfd driver.
The amdkfd interrupt module maintains an internal interrupt ring per amdkfd device. The internal interrupt ring contains interrupts that needs further handling. The extra handling is deferred to a later time through a workqueue.
There's no acknowledgment for the interrupts we use. The hardware simply queues a new interrupt each time without waiting.
The fixed-size internal queue means that it's possible for us to lose interrupts because we have no back-pressure to the hardware.
v3: change device init
v3: make sure spin lock is taken only if init is complete
v3: move bool to end of struct
--- drivers/gpu/drm/radeon/amdkfd/Makefile | 3 +- drivers/gpu/drm/radeon/amdkfd/kfd_device.c | 23 +++- drivers/gpu/drm/radeon/amdkfd/kfd_interrupt.c | 161 ++++++++++++++++++++++++++ drivers/gpu/drm/radeon/amdkfd/kfd_priv.h | 18 ++- 4 files changed, 200 insertions(+), 5 deletions(-) create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_interrupt.c
drivers/gpu/drm/radeon/amdkfd/Makefile +2 -1
@@ -8,6 +8,7 @@ amdkfd-y := kfd_module.o kfd_device.o kfd_chardev.o kfd_topology.o \ kfd_pasid.o kfd_doorbell.o kfd_aperture.o \ kfd_process.o kfd_queue.o kfd_mqd_manager.o \ kfd_kernel_queue.o kfd_packet_manager.o \ - kfd_process_queue_manager.o kfd_device_queue_manager.o + kfd_process_queue_manager.o kfd_device_queue_manager.o \ + kfd_interrupt.o obj-$(CONFIG_HSA_RADEON) += amdkfd.o
drivers/gpu/drm/radeon/amdkfd/kfd_device.c +22 -1
@@ -31,6 +31,7 @@static const struct kfd_device_info kaveri_device_info = { .max_pasid_bits =16 , + .ih_ring_entry_size =4 *sizeof (uint32_t ) };struct kfd_deviceid {
@@ -187,6 +188,13 @@ bool kgd2kfd_device_init(struct kfd_dev *kfd, goto kfd_topology_add_device_error; } +if (kfd_interrupt_init (kfd)) { +dev_err (kfd_device, +"Error initializing interrupts for device (%x:%x)\n" , + kfd->pdev->vendor, kfd->pdev->device); + goto kfd_interrupt_error; + } +if (!device_iommu_pasid_init (kfd)) { dev_err(kfd_device, "Error initializing iommuv2 for device (%x:%x)\n",
@@ -223,6 +231,8 @@ dqm_start_error: device_queue_manager_error:amd_iommu_free_device (kfd->pdev); device_iommu_pasid_error: +kfd_interrupt_exit (kfd); +kfd_interrupt_error:kfd_topology_remove_device (kfd); kfd_topology_add_device_error: kfd2kgd->fini_sa_manager (kfd->kgd);
@@ -238,6 +248,7 @@ void kgd2kfd_device_exit(struct kfd_dev *kfd)if (kfd->init_complete) {device_queue_manager_uninit (kfd->dqm);amd_iommu_free_device (kfd->pdev); +kfd_interrupt_exit (kfd);kfd_topology_remove_device (kfd); }
@@ -274,6 +285,16 @@ int kgd2kfd_resume(struct kfd_dev *kfd)return 0 ; } -void kgd2kfd_interrupt (struct kfd_dev *dev,const void *ih_ring_entry) +/* This is called directly from KGD at ISR. */ +void kgd2kfd_interrupt (struct kfd_dev *kfd,const void *ih_ring_entry) { +if (kfd->init_complete) { +spin_lock (&kfd->interrupt_lock); + +if (kfd->interrupts_active + &&enqueue_ih_ring_entry (kfd, ih_ring_entry)) +schedule_work (&kfd->interrupt_work); + +spin_unlock (&kfd->interrupt_lock); + } }
drivers/gpu/drm/radeon/amdkfd/kfd_interrupt.c new file +161 -0
161 lines not on this page · raw message
drivers/gpu/drm/radeon/amdkfd/kfd_priv.h +15 -3
@@ -126,10 +126,19 @@ struct kfd_dev {struct kgd2kfd_shared_resources shared_resources; +void *interrupt_ring; +size_t interrupt_ring_size; +atomic_t interrupt_ring_rptr; +atomic_t interrupt_ring_wptr; +struct work_struct interrupt_work; +spinlock_t interrupt_lock; +/* QCM Device instance */ struct device_queue_manager *dqm;bool init_complete; +/* Interrupts of interest to KFD are copied from the HW ring into a SW ring. */ +bool interrupts_active; };/* KGD2KFD callbacks */
@@ -468,11 +477,14 @@ struct kfd_dev *kfd_device_by_pci_dev(const struct pci_dev *pdev);struct kfd_dev *kfd_topology_enum_kfd_devices (uint8_t idx);/* Interrupts */ -void kgd2kfd_interrupt (struct kfd_dev *dev,const void *ih_ring_entry); +int kfd_interrupt_init (struct kfd_dev *dev); +void kfd_interrupt_exit (struct kfd_dev *dev); +void kgd2kfd_interrupt (struct kfd_dev *kfd,const void *ih_ring_entry); +bool enqueue_ih_ring_entry (struct kfd_dev *kfd,const void *ih_ring_entry);/* Power Management */ -void kgd2kfd_suspend (struct kfd_dev *dev); -int kgd2kfd_resume (struct kfd_dev *dev); +void kgd2kfd_suspend (struct kfd_dev *kfd); +int kgd2kfd_resume (struct kfd_dev *kfd);/* amdkfd Apertures */ int kfd_init_apertures (struct kfd_process *process);
Signature · 1 line
1.9.1
Hi
Quoted 28 lines · Oded Gabbay
Hi,
Here is the v3 patch set of amdkfd.This version contains changes and fixes to code, as agreed on during the review of the v2 patch set.
The major changes are:
- There are two new module parameters: # of processes and # of queues per process. The defaults, as agreed on in the v2 review, are 32 and 128 respectively. This sets the default amount of GART address space that amdkfd requires to 3.5MB (3MB for userspace queues mqds and 0.5MB for other stuff, such as mqd for kernel queue, hpd for pipelines, etc.)
- All the GART address space usage of amdkfd is done inside a single contiguous buffer that is allocated from system memory, and pinned to the start of the GART during the startup of amdkfd (which is just after the startup of radeon). The management of this buffer is done by the radeon sa manager. This buffer is not evict-able.
- Mapping of doorbells is initiated by the userspace lib (by mmap syscall), instead of initiating it from inside an ioctl (using
vm_mmap).- Removed ioctls for exclusive access to performance counters
- Added documentation about the QCM (Queue Control Management), apertures and interfaces between amdkfd and radeon.
Quoted 6 lines
Two important notes:
- The topology patch has not been changed. Look at
http://lists.freedesktop.org/archives/dri-devel/2014-July/065042.html
for my response. I also put my answer as an explanation in the commit msg of the patch.
This patchset adds 10.000 lines and contains nearly 0 comments *why* stuff is added. Seriously, it is almost impossible to understand what you're doing. Can you please include a high-level introduction in the [0/X] cover-letter and include it in every series you send? A blog-post or something would also be fine. And yes, it's totally ok if this is 10k lines of plain-text.
Lets start with the basics:
1) Why do you use kobject directly to expose the topology? Almost no other driver does that, why do you use it in amdkfd instead of "struct bus" and "struct device"? You totally lack uevent handling, sysfs hierarchy integration and more. If you'd use existing infrastructue instead of kobject directly, everything would work just fine.
2) What kind of topology is exposed? Is it nested? How deep? How many items are usually expected? How does the sysfs tree (tree /sys/..../topology) look like on your machine? For people without the hardware it's nearly impossible to understand how this will look like.
3) How is the interface supposed to be used? I can see one global char-dev where you can queue jobs by providing a GPU-ID. Why don't you create one char-dev *per* available GPU just like all other interfaces do? Why is this a separate thing instead of a drm_minor object that can be added per device as a separate interface to KMS and render-nodes? Where is the underlying "struct device" for those GPUs?
4) Why is the topology static? FWIW, you allow runtime modifications, but I cannot see any notification mechanism for user-space? Again, using existing driver-core would provide all that for free.
I really appreciate that you provided code instead of just ideas, but please describe why you do things the way they are. And please provide examples for people who do not have the hardware.
Thanks
David
Quoted 122 lines
- There are still some minor code style issues I need to fix. I didn't want to delay v3 any further but I will publish either v4 with those fixes, or just relevant patches if the whole patch set will be merged.
For people who like to review using git, the v3 patch set is located at:
http://cgit.freedesktop.org/~gabbayo/linux/log/?h=kfd-next-3.17-v3In addition, I would like to announce that we have uploaded the userspace lib that accompanies amdkfd. That lib is called "libhsakmt" and you can view it at:
http://cgit.freedesktop.org/~gabbayo/libhsakmtAlexey Skidanov (1):
amdkfd: Implement the Get Process Aperture IOCTLAndrew Lewycky (3):
amdkfd: Add basic modules to amdkfd
amdkfd: Add interrupt handling module
amdkfd: Implement the Set Memory Policy IOCTLBen Goz (8):
amdkfd: Add queue module
amdkfd: Addmqd_managermodule
amdkfd: Add kernel queue module
amdkfd: Add module parameter of scheduling policy
amdkfd: Add packet manager module
amdkfd: Add process queue manager module
amdkfd: Add device queue manager module
amdkfd: Implement the create/destroy/update queue IOCTLsEvgeny Pinchuk (2):
amdkfd: Add topology module to amdkfd
amdkfd: Implement the Get Clock Counters IOCTLOded Gabbay (9):
drm/radeon: reduce number of free VMIDs and pipes in KV drm/radeon/cik: Don't touch int of pipes 1-7 drm/radeon: Report doorbell configuration to amdkfd drm/radeon: adding synchronization for GRBM GFX drm/radeon: Add radeon <--> amdkfd interface UpdateMAINTAINERSand CREDITS files with amdkfd info
amdkfd: Add IOCTL set definitions of amdkfd
amdkfd: Add amdkfd skeleton driver
amdkfd: Add binding/unbinding calls toamd_iommudriverCREDITS | 7 + MAINTAINERS | 10 + drivers/gpu/drm/radeon/Kconfig | 2 + drivers/gpu/drm/radeon/Makefile | 3 + drivers/gpu/drm/radeon/amdkfd/Kconfig | 10 + drivers/gpu/drm/radeon/amdkfd/Makefile | 14 + drivers/gpu/drm/radeon/amdkfd/cik_regs.h | 220 ++++ drivers/gpu/drm/radeon/amdkfd/kfd_aperture.c | 350 ++++++ drivers/gpu/drm/radeon/amdkfd/kfd_chardev.c | 511 +++++++++ drivers/gpu/drm/radeon/amdkfd/kfd_crat.h | 294 +++++ drivers/gpu/drm/radeon/amdkfd/kfd_device.c | 300 +++++ .../drm/radeon/amdkfd/kfd_device_queue_manager.c | 989 ++++++++++++++++ .../drm/radeon/amdkfd/kfd_device_queue_manager.h | 144 +++ drivers/gpu/drm/radeon/amdkfd/kfd_doorbell.c | 236 ++++ drivers/gpu/drm/radeon/amdkfd/kfd_interrupt.c | 161 +++ drivers/gpu/drm/radeon/amdkfd/kfd_kernel_queue.c | 330 ++++++ drivers/gpu/drm/radeon/amdkfd/kfd_kernel_queue.h | 66 ++ drivers/gpu/drm/radeon/amdkfd/kfd_module.c | 147 +++ drivers/gpu/drm/radeon/amdkfd/kfd_mqd_manager.c | 305 +++++ drivers/gpu/drm/radeon/amdkfd/kfd_mqd_manager.h | 88 ++ drivers/gpu/drm/radeon/amdkfd/kfd_packet_manager.c | 495 ++++++++ drivers/gpu/drm/radeon/amdkfd/kfd_pasid.c | 95 ++ drivers/gpu/drm/radeon/amdkfd/kfd_pm4_headers.h | 682 +++++++++++ drivers/gpu/drm/radeon/amdkfd/kfd_pm4_opcodes.h | 107 ++ drivers/gpu/drm/radeon/amdkfd/kfd_priv.h | 560 +++++++++ drivers/gpu/drm/radeon/amdkfd/kfd_process.c | 347 ++++++ .../drm/radeon/amdkfd/kfd_process_queue_manager.c | 346 ++++++ drivers/gpu/drm/radeon/amdkfd/kfd_queue.c | 85 ++ drivers/gpu/drm/radeon/amdkfd/kfd_topology.c | 1207 ++++++++++++++++++++ drivers/gpu/drm/radeon/amdkfd/kfd_topology.h | 168 +++ drivers/gpu/drm/radeon/cik.c | 154 +-- drivers/gpu/drm/radeon/cik_reg.h | 65 ++ drivers/gpu/drm/radeon/cikd.h | 53 +- drivers/gpu/drm/radeon/radeon.h | 10 + drivers/gpu/drm/radeon/radeon_device.c | 32 + drivers/gpu/drm/radeon/radeon_drv.c | 5 + drivers/gpu/drm/radeon/radeon_kfd.c | 525 +++++++++ drivers/gpu/drm/radeon/radeon_kfd.h | 177 +++ drivers/gpu/drm/radeon/radeon_kms.c | 7 + include/uapi/linux/kfd_ioctl.h | 126 ++ 40 files changed, 9338 insertions(+), 95 deletions(-) create mode 100644 drivers/gpu/drm/radeon/amdkfd/Kconfig create mode 100644 drivers/gpu/drm/radeon/amdkfd/Makefile create mode 100644 drivers/gpu/drm/radeon/amdkfd/cik_regs.h create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_aperture.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_chardev.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_crat.h create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_device.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_device_queue_manager.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_device_queue_manager.h create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_doorbell.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_interrupt.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_kernel_queue.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_kernel_queue.h create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_module.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_mqd_manager.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_mqd_manager.h create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_packet_manager.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_pasid.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_pm4_headers.h create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_pm4_opcodes.h create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_priv.h create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_process.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_process_queue_manager.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_queue.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_topology.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_topology.h create mode 100644 drivers/gpu/drm/radeon/radeon_kfd.c create mode 100644 drivers/gpu/drm/radeon/radeon_kfd.h create mode 100644 include/uapi/linux/kfd_ioctl.h--
1.9.1_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 39 lines · Oded Gabbay
Hi,
Here is the v3 patch set of amdkfd.This version contains changes and fixes to code, as agreed on during the review of the v2 patch set.
The major changes are:
- There are two new module parameters: # of processes and # of queues per process. The defaults, as agreed on in the v2 review, are 32 and 128 respectively. This sets the default amount of GART address space that amdkfd requires to 3.5MB (3MB for userspace queues mqds and 0.5MB for other stuff, such as mqd for kernel queue, hpd for pipelines, etc.)
- All the GART address space usage of amdkfd is done inside a single contiguous buffer that is allocated from system memory, and pinned to the start of the GART during the startup of amdkfd (which is just after the startup of radeon). The management of this buffer is done by the radeon sa manager. This buffer is not evict-able.
- Mapping of doorbells is initiated by the userspace lib (by mmap syscall), instead of initiating it from inside an ioctl (using
vm_mmap).- Removed ioctls for exclusive access to performance counters
- Added documentation about the QCM (Queue Control Management), apertures and interfaces between amdkfd and radeon.
Two important notes:
- The topology patch has not been changed. Look at
http://lists.freedesktop.org/archives/dri-devel/2014-July/065042.html
for my response. I also put my answer as an explanation in the commit msg of the patch.- There are still some minor code style issues I need to fix. I didn't want to delay v3 any further but I will publish either v4 with those fixes, or just relevant patches if the whole patch set will be merged.
Quoted 6 lines
For people who like to review using git, the v3 patch set is located at:
http://cgit.freedesktop.org/~gabbayo/linux/log/?h=kfd-next-3.17-v3In addition, I would like to announce that we have uploaded the userspace lib that accompanies amdkfd. That lib is called "libhsakmt" and you can view it at:
http://cgit.freedesktop.org/~gabbayo/libhsakmt
Not commenting on the patchset yet, will try to find sometime in my non work hour to do that. But the userspace you released are just a libdrm like thing and this is not what we mean by we need to have userspace that shows how the kernel api is use.
So this library is nothing but a wrapper and have allmost no value for any serious review of the kernel api.
To be clear, when we ask for open source userspace that shows how things are suppose to be use we are thinking something like mesa but in this case most likely something like an open source opencl implementation on top of that kernel api.
Btw this library code remind me of VHDL ... thought code style for userspace library is anybody choice.
Cheers,
Jérôme
Quoted 112 lines
Alexey Skidanov (1):
amdkfd: Implement the Get Process Aperture IOCTLAndrew Lewycky (3):
amdkfd: Add basic modules to amdkfd
amdkfd: Add interrupt handling module
amdkfd: Implement the Set Memory Policy IOCTLBen Goz (8):
amdkfd: Add queue module
amdkfd: Addmqd_managermodule
amdkfd: Add kernel queue module
amdkfd: Add module parameter of scheduling policy
amdkfd: Add packet manager module
amdkfd: Add process queue manager module
amdkfd: Add device queue manager module
amdkfd: Implement the create/destroy/update queue IOCTLsEvgeny Pinchuk (2):
amdkfd: Add topology module to amdkfd
amdkfd: Implement the Get Clock Counters IOCTLOded Gabbay (9):
drm/radeon: reduce number of free VMIDs and pipes in KV drm/radeon/cik: Don't touch int of pipes 1-7 drm/radeon: Report doorbell configuration to amdkfd drm/radeon: adding synchronization for GRBM GFX drm/radeon: Add radeon <--> amdkfd interface UpdateMAINTAINERSand CREDITS files with amdkfd info
amdkfd: Add IOCTL set definitions of amdkfd
amdkfd: Add amdkfd skeleton driver
amdkfd: Add binding/unbinding calls toamd_iommudriverCREDITS | 7 + MAINTAINERS | 10 + drivers/gpu/drm/radeon/Kconfig | 2 + drivers/gpu/drm/radeon/Makefile | 3 + drivers/gpu/drm/radeon/amdkfd/Kconfig | 10 + drivers/gpu/drm/radeon/amdkfd/Makefile | 14 + drivers/gpu/drm/radeon/amdkfd/cik_regs.h | 220 ++++ drivers/gpu/drm/radeon/amdkfd/kfd_aperture.c | 350 ++++++ drivers/gpu/drm/radeon/amdkfd/kfd_chardev.c | 511 +++++++++ drivers/gpu/drm/radeon/amdkfd/kfd_crat.h | 294 +++++ drivers/gpu/drm/radeon/amdkfd/kfd_device.c | 300 +++++ .../drm/radeon/amdkfd/kfd_device_queue_manager.c | 989 ++++++++++++++++ .../drm/radeon/amdkfd/kfd_device_queue_manager.h | 144 +++ drivers/gpu/drm/radeon/amdkfd/kfd_doorbell.c | 236 ++++ drivers/gpu/drm/radeon/amdkfd/kfd_interrupt.c | 161 +++ drivers/gpu/drm/radeon/amdkfd/kfd_kernel_queue.c | 330 ++++++ drivers/gpu/drm/radeon/amdkfd/kfd_kernel_queue.h | 66 ++ drivers/gpu/drm/radeon/amdkfd/kfd_module.c | 147 +++ drivers/gpu/drm/radeon/amdkfd/kfd_mqd_manager.c | 305 +++++ drivers/gpu/drm/radeon/amdkfd/kfd_mqd_manager.h | 88 ++ drivers/gpu/drm/radeon/amdkfd/kfd_packet_manager.c | 495 ++++++++ drivers/gpu/drm/radeon/amdkfd/kfd_pasid.c | 95 ++ drivers/gpu/drm/radeon/amdkfd/kfd_pm4_headers.h | 682 +++++++++++ drivers/gpu/drm/radeon/amdkfd/kfd_pm4_opcodes.h | 107 ++ drivers/gpu/drm/radeon/amdkfd/kfd_priv.h | 560 +++++++++ drivers/gpu/drm/radeon/amdkfd/kfd_process.c | 347 ++++++ .../drm/radeon/amdkfd/kfd_process_queue_manager.c | 346 ++++++ drivers/gpu/drm/radeon/amdkfd/kfd_queue.c | 85 ++ drivers/gpu/drm/radeon/amdkfd/kfd_topology.c | 1207 ++++++++++++++++++++ drivers/gpu/drm/radeon/amdkfd/kfd_topology.h | 168 +++ drivers/gpu/drm/radeon/cik.c | 154 +-- drivers/gpu/drm/radeon/cik_reg.h | 65 ++ drivers/gpu/drm/radeon/cikd.h | 53 +- drivers/gpu/drm/radeon/radeon.h | 10 + drivers/gpu/drm/radeon/radeon_device.c | 32 + drivers/gpu/drm/radeon/radeon_drv.c | 5 + drivers/gpu/drm/radeon/radeon_kfd.c | 525 +++++++++ drivers/gpu/drm/radeon/radeon_kfd.h | 177 +++ drivers/gpu/drm/radeon/radeon_kms.c | 7 + include/uapi/linux/kfd_ioctl.h | 126 ++ 40 files changed, 9338 insertions(+), 95 deletions(-) create mode 100644 drivers/gpu/drm/radeon/amdkfd/Kconfig create mode 100644 drivers/gpu/drm/radeon/amdkfd/Makefile create mode 100644 drivers/gpu/drm/radeon/amdkfd/cik_regs.h create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_aperture.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_chardev.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_crat.h create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_device.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_device_queue_manager.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_device_queue_manager.h create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_doorbell.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_interrupt.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_kernel_queue.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_kernel_queue.h create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_module.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_mqd_manager.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_mqd_manager.h create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_packet_manager.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_pasid.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_pm4_headers.h create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_pm4_opcodes.h create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_priv.h create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_process.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_process_queue_manager.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_queue.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_topology.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_topology.h create mode 100644 drivers/gpu/drm/radeon/radeon_kfd.c create mode 100644 drivers/gpu/drm/radeon/radeon_kfd.h create mode 100644 include/uapi/linux/kfd_ioctl.hSignature · 6 lines
1.9.1 _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 38 lines · David Herrmann
Hi
Quoted 28 lines · Oded Gabbay
Hi,
Here is the v3 patch set of amdkfd.This version contains changes and fixes to code, as agreed on during the review of the v2 patch set.
The major changes are:
- There are two new module parameters: # of processes and # of queues per process. The defaults, as agreed on in the v2 review, are 32 and 128 respectively. This sets the default amount of GART address space that amdkfd requires to 3.5MB (3MB for userspace queues mqds and 0.5MB for other stuff, such as mqd for kernel queue, hpd for pipelines, etc.)
- All the GART address space usage of amdkfd is done inside a single contiguous buffer that is allocated from system memory, and pinned to the start of the GART during the startup of amdkfd (which is just after the startup of radeon). The management of this buffer is done by the radeon sa manager. This buffer is not evict-able.
- Mapping of doorbells is initiated by the userspace lib (by mmap syscall), instead of initiating it from inside an ioctl (using
vm_mmap).- Removed ioctls for exclusive access to performance counters
- Added documentation about the QCM (Queue Control Management), apertures and interfaces between amdkfd and radeon.
Quoted 6 lines
Two important notes:
- The topology patch has not been changed. Look at
http://lists.freedesktop.org/archives/dri-devel/2014-July/065042.html
for my response. I also put my answer as an explanation in the commit msg of the patch.
Quoted 6 lines
This patchset adds 10.000 lines and contains nearly 0 comments *why* stuff is added. Seriously, it is almost impossible to understand what you're doing. Can you please include a high-level introduction in the [0/X] cover-letter and include it in every series you send? A blog-post or something would also be fine. And yes, it's totally ok if this is 10k lines of plain-text.
My bad. I forgot to attach the cover letter of v2 and especially v1, which includes a lengthy explanation of the driver.
So here it is and I will respond to your other comments later.
Oded
v2 cover letter:
-------------------
As a continuation to the existing discussion, here is a v2 patch series restructured with a cleaner history and no totally-different-early-versions of the code.
Instead of 83 patches, there are now a total of 25 patches, where 5 of them are modifications to radeon driver and 18 of them include only amdkfd code. There is no code going away or even modified between patches, only added.
The driver was renamed from radeon_kfd to amdkfd and moved to reside under drm/radeon/amdkfd. This move was done to emphasize the fact that this driver
is an AMD-only driver at this point. Having said that, we do foresee a generic hsa framework being implemented in the future and in that case, we will adjust amdkfd to work within that framework.
As the amdkfd driver should support multiple AMD gfx drivers, we want to keep it as a seperate driver from radeon. Therefore, the amdkfd code is contained in its own folder. The amdkfd folder was put under the radeon folder because the only AMD gfx driver in the Linux kernel at this point is the radeon driver. Having said that, we will probably need to move it (maybe to be directly under drm) after we integrate with additional AMD gfx drivers.
For people who like to review using git, the v2 patch set is located at:
http://cgit.freedesktop.org/~gabbayo/linux/log/?h=kfd-next-3.17-v2
Written by Oded Gabbayh <[email protected]>
-------------------------
Original Cover Letter:
-------------------------
This patch set implements a Heterogeneous System Architecture (HSA) driver for radeon-family GPUs.
HSA allows different processor types (CPUs, DSPs, GPUs, etc..) to share system resources more effectively via HW features including shared pageable memory, userspace-accessible work queues, and platform-level atomics. In addition to the memory protection mechanisms in GPUVM and IOMMUv2, the Sea Islands family of GPUs also performs HW-level validation of commands passed in through the queues (aka rings).
The code in this patch set is intended to serve both as a sample driver for other HSA-compatible hardware devices and as a production driver for radeon-family processors. The code is architected to support multiple CPUs each with connected GPUs, although the current implementation focuses on a single Kaveri/Berlin APU, and works alongside the existing radeon kernel graphics driver (kgd).
AMD GPUs designed for use with HSA (Sea Islands and up) share some hardware functionality between HSA compute and regular gfx/compute (memory, interrupts, registers), while other functionality has been added specifically for HSA compute (hw scheduler for virtualized compute rings). All shared hardware is owned by the radeon graphics driver, and an interface
between kfd and kgd allows the kfd to make use of those shared resources, while HSA-specific functionality is managed directly by kfd by submitting packets into an HSA-specific command queue (the "HIQ").
During kfd module initialization a char device node (/dev/kfd) is created (surviving until module exit), with ioctls for queue creation & management, and data structures are initialized for managing HSA device topology.
The rest of the initialization is driven by calls from the radeon kgd at the following points :
- radeon_init (kfd_init)
- radeon_exit (kfd_fini)
- radeon_driver_load_kms (kfd_device_probe, kfd_device_init)
- radeon_driver_unload_kms (kfd_device_fini)
During the probe and init processing per-device data structures are established which connect to the associated graphics kernel driver. This information is exposed to userspace via sysfs, along with a version number allowing userspace to determine if a topology change has occurred while it was reading from sysfs.
The interface between kfd and kgd also allows the kfd to request buffer management services from kgd, and allows kgd to route interrupt requests to kfd code since the interrupt block is shared between regular graphics/compute and HSA compute subsystems in the GPU.
The kfd code works with an open source usermode library ("libhsakmt") which is in the final stages of IP review and should be published in a separate repo over the next few days.
The code operates in one of three modes, selectable via the sched_policy module parameter :
- sched_policy=0 uses a hardware scheduler running in the MEC block within CP, and allows oversubscription (more queues than HW slots)
- sched_policy=1 also uses HW scheduling but does not allow oversubscription, so create_queue requests fail when we run out of HW slots
- sched_policy=2 does not use HW scheduling, so the driver manually assigns queues to HW slots by programming registers
The "no HW scheduling" option is for debug & new hardware bringup only, so has less test coverage than the other options. Default in the current code is "HW scheduling without oversubscription" since that is where we have the most test coverage but we expect to change the default to "HW scheduling with oversubscription" after further testing. This effectively removes the HW limit on the number of work queues available to applications.
Programs running on the GPU are associated with an address space through the
VMID field, which is translated to a unique PASID at access time via a set of 16 VMID-to-PASID mapping registers. The available VMIDs (currently 16) are partitioned (under control of the radeon kgd) between current gfx/compute and HSA compute, with each getting 8 in the current code. The VMID-to-PASID mapping registers are updated by the HW scheduler when used, and by driver code if HW scheduling is not being used.
The Sea Islands compute queues use a new "doorbell" mechanism instead of the
earlier kernel-managed write pointer registers. Doorbells use a separate BAR
dedicated for this purpose, and pages within the doorbell aperture are mapped to userspace (each page mapped to only one user address space). Writes to the doorbell aperture are intercepted by GPU hardware, allowing userspace code to safely manage work queues (rings) without requiring a kernel call for every ring update.
First step for an application process is to open the kfd device. Calls to open create a kfd "process" structure only for the first thread of the process. Subsequent open calls are checked to see if they are from processes
using the same mm_struct and, if so, don't do anything. The kfd per-process data lives as long as the mm_struct exists. Each mm_struct is associated with a unique PASID, allowing the IOMMUv2 to make userspace process memory accessible to the GPU.
Next step is for the application to collect topology information via sysfs. This gives userspace enough information to be able to identify specific nodes (processors) in subsequent queue management calls. Application processes can create queues on multiple processors, and processors support queues from multiple processes.
At this point the application can create work queues in userspace memory and
pass them through the usermode library to kfd to have them mapped onto HW queue slots so that commands written to the queues can be executed by the GPU. Queue operations specify a processor node, and so the bulk of this code
is device-specific.
Written by John Bridgman <[email protected]>
Quoted 154 lines
Lets start with the basics:
1) Why do you use kobject directly to expose the topology? Almost no other driver does that, why do you use it in amdkfd instead of "struct bus" and "struct device"? You totally lack uevent handling, sysfs hierarchy integration and more. If you'd use existing infrastructue instead of kobject directly, everything would work just fine.
2) What kind of topology is exposed? Is it nested? How deep? How many items are usually expected? How does the sysfs tree (
tree /sys/..../topology) look like on your machine? For people without the hardware it's nearly impossible to understand how this will look like.3) How is the interface supposed to be used? I can see one global char-dev where you can queue jobs by providing a GPU-ID. Why don't you create one char-dev *per* available GPU just like all other interfaces do? Why is this a separate thing instead of a
drm_minorobject that can be added per device as a separate interface to KMS and render-nodes? Where is the underlying "struct device" for those GPUs?4) Why is the topology static? FWIW, you allow runtime modifications, but I cannot see any notification mechanism for user-space? Again, using existing driver-core would provide all that for free.
I really appreciate that you provided code instead of just ideas, but please describe why you do things the way they are. And please provide examples for people who do not have the hardware.
Thanks
DavidQuoted 122 lines
- There are still some minor code style issues I need to fix. I didn't want to delay v3 any further but I will publish either v4 with those fixes, or just relevant patches if the whole patch set will be merged.
For people who like to review using git, the v3 patch set is located at:
http://cgit.freedesktop.org/~gabbayo/linux/log/?h=kfd-next-3.17-v3In addition, I would like to announce that we have uploaded the userspace lib that accompanies amdkfd. That lib is called "libhsakmt" and you can view it at:
http://cgit.freedesktop.org/~gabbayo/libhsakmtAlexey Skidanov (1):
amdkfd: Implement the Get Process Aperture IOCTLAndrew Lewycky (3):
amdkfd: Add basic modules to amdkfd
amdkfd: Add interrupt handling module
amdkfd: Implement the Set Memory Policy IOCTLBen Goz (8):
amdkfd: Add queue module
amdkfd: Addmqd_managermodule
amdkfd: Add kernel queue module
amdkfd: Add module parameter of scheduling policy
amdkfd: Add packet manager module
amdkfd: Add process queue manager module
amdkfd: Add device queue manager module
amdkfd: Implement the create/destroy/update queue IOCTLsEvgeny Pinchuk (2):
amdkfd: Add topology module to amdkfd
amdkfd: Implement the Get Clock Counters IOCTLOded Gabbay (9):
drm/radeon: reduce number of free VMIDs and pipes in KV drm/radeon/cik: Don't touch int of pipes 1-7 drm/radeon: Report doorbell configuration to amdkfd drm/radeon: adding synchronization for GRBM GFX drm/radeon: Add radeon <--> amdkfd interface UpdateMAINTAINERSand CREDITS files with amdkfd info
amdkfd: Add IOCTL set definitions of amdkfd
amdkfd: Add amdkfd skeleton driver
amdkfd: Add binding/unbinding calls toamd_iommudriverCREDITS | 7 + MAINTAINERS | 10 + drivers/gpu/drm/radeon/Kconfig | 2 + drivers/gpu/drm/radeon/Makefile | 3 + drivers/gpu/drm/radeon/amdkfd/Kconfig | 10 + drivers/gpu/drm/radeon/amdkfd/Makefile | 14 + drivers/gpu/drm/radeon/amdkfd/cik_regs.h | 220 ++++ drivers/gpu/drm/radeon/amdkfd/kfd_aperture.c | 350 ++++++ drivers/gpu/drm/radeon/amdkfd/kfd_chardev.c | 511 +++++++++ drivers/gpu/drm/radeon/amdkfd/kfd_crat.h | 294 +++++ drivers/gpu/drm/radeon/amdkfd/kfd_device.c | 300 +++++ .../drm/radeon/amdkfd/kfd_device_queue_manager.c | 989 ++++++++++++++++ .../drm/radeon/amdkfd/kfd_device_queue_manager.h | 144 +++ drivers/gpu/drm/radeon/amdkfd/kfd_doorbell.c | 236 ++++ drivers/gpu/drm/radeon/amdkfd/kfd_interrupt.c | 161 +++ drivers/gpu/drm/radeon/amdkfd/kfd_kernel_queue.c | 330 ++++++ drivers/gpu/drm/radeon/amdkfd/kfd_kernel_queue.h | 66 ++ drivers/gpu/drm/radeon/amdkfd/kfd_module.c | 147 +++ drivers/gpu/drm/radeon/amdkfd/kfd_mqd_manager.c | 305 +++++ drivers/gpu/drm/radeon/amdkfd/kfd_mqd_manager.h | 88 ++ drivers/gpu/drm/radeon/amdkfd/kfd_packet_manager.c | 495 ++++++++ drivers/gpu/drm/radeon/amdkfd/kfd_pasid.c | 95 ++ drivers/gpu/drm/radeon/amdkfd/kfd_pm4_headers.h | 682 +++++++++++ drivers/gpu/drm/radeon/amdkfd/kfd_pm4_opcodes.h | 107 ++ drivers/gpu/drm/radeon/amdkfd/kfd_priv.h | 560 +++++++++ drivers/gpu/drm/radeon/amdkfd/kfd_process.c | 347 ++++++ .../drm/radeon/amdkfd/kfd_process_queue_manager.c | 346 ++++++ drivers/gpu/drm/radeon/amdkfd/kfd_queue.c | 85 ++ drivers/gpu/drm/radeon/amdkfd/kfd_topology.c | 1207 ++++++++++++++++++++ drivers/gpu/drm/radeon/amdkfd/kfd_topology.h | 168 +++ drivers/gpu/drm/radeon/cik.c | 154 +-- drivers/gpu/drm/radeon/cik_reg.h | 65 ++ drivers/gpu/drm/radeon/cikd.h | 53 +- drivers/gpu/drm/radeon/radeon.h | 10 + drivers/gpu/drm/radeon/radeon_device.c | 32 + drivers/gpu/drm/radeon/radeon_drv.c | 5 + drivers/gpu/drm/radeon/radeon_kfd.c | 525 +++++++++ drivers/gpu/drm/radeon/radeon_kfd.h | 177 +++ drivers/gpu/drm/radeon/radeon_kms.c | 7 + include/uapi/linux/kfd_ioctl.h | 126 ++ 40 files changed, 9338 insertions(+), 95 deletions(-) create mode 100644 drivers/gpu/drm/radeon/amdkfd/Kconfig create mode 100644 drivers/gpu/drm/radeon/amdkfd/Makefile create mode 100644 drivers/gpu/drm/radeon/amdkfd/cik_regs.h create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_aperture.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_chardev.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_crat.h create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_device.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_device_queue_manager.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_device_queue_manager.h create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_doorbell.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_interrupt.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_kernel_queue.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_kernel_queue.h create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_module.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_mqd_manager.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_mqd_manager.h create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_packet_manager.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_pasid.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_pm4_headers.h create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_pm4_opcodes.h create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_priv.h create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_process.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_process_queue_manager.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_queue.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_topology.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_topology.h create mode 100644 drivers/gpu/drm/radeon/radeon_kfd.c create mode 100644 drivers/gpu/drm/radeon/radeon_kfd.h create mode 100644 include/uapi/linux/kfd_ioctl.h--
1.9.1_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
))To be clear, when we ask for open source userspace that shows how things are suppose to be use we are thinking something like mesa but in this case most likely something like an open source opencl implementation on top of that kernel api.
Yep, understood. We're working on that too. Next should be the HSA API runtime, which is essentially the user mode driver for HSA that language toolchains run over.
I think Sumatra (Java) will probably be the first open source language runtime rather than OpenCL -- it's working today albeit via an older version of the HSA API.
Thanks,
JB
----- Original Message -----
From: Jerome Glisse [mailto:[email protected]]
Sent: Tuesday, August 05, 2014 01:51 PM Eastern Standard Time
To: Gabbay, Oded
Cc: Lewycky, Andrew; Daenzer, Michel; [email protected] <[email protected]>; [email protected] <[email protected]>; Andrew Morton <[email protected]>
Subject: Re: [PATCH v3 00/23] AMDKFD Kernel Driver
Quoted 39 lines · Oded Gabbay
Hi,
Here is the v3 patch set of amdkfd.This version contains changes and fixes to code, as agreed on during the review of the v2 patch set.
The major changes are:
- There are two new module parameters: # of processes and # of queues per process. The defaults, as agreed on in the v2 review, are 32 and 128 respectively. This sets the default amount of GART address space that amdkfd requires to 3.5MB (3MB for userspace queues mqds and 0.5MB for other stuff, such as mqd for kernel queue, hpd for pipelines, etc.)
- All the GART address space usage of amdkfd is done inside a single contiguous buffer that is allocated from system memory, and pinned to the start of the GART during the startup of amdkfd (which is just after the startup of radeon). The management of this buffer is done by the radeon sa manager. This buffer is not evict-able.
- Mapping of doorbells is initiated by the userspace lib (by mmap syscall), instead of initiating it from inside an ioctl (using
vm_mmap).- Removed ioctls for exclusive access to performance counters
- Added documentation about the QCM (Queue Control Management), apertures and interfaces between amdkfd and radeon.
Two important notes:
- The topology patch has not been changed. Look at
http://lists.freedesktop.org/archives/dri-devel/2014-July/065042.html
for my response. I also put my answer as an explanation in the commit msg of the patch.- There are still some minor code style issues I need to fix. I didn't want to delay v3 any further but I will publish either v4 with those fixes, or just relevant patches if the whole patch set will be merged.
Quoted 6 lines
For people who like to review using git, the v3 patch set is located at:
http://cgit.freedesktop.org/~gabbayo/linux/log/?h=kfd-next-3.17-v3In addition, I would like to announce that we have uploaded the userspace lib that accompanies amdkfd. That lib is called "libhsakmt" and you can view it at:
http://cgit.freedesktop.org/~gabbayo/libhsakmt
Not commenting on the patchset yet, will try to find sometime in my non work hour to do that. But the userspace you released are just a libdrm like thing and this is not what we mean by we need to have userspace that shows how the kernel api is use.
So this library is nothing but a wrapper and have allmost no value for any serious review of the kernel api.
To be clear, when we ask for open source userspace that shows how things are suppose to be use we are thinking something like mesa but in this case most likely something like an open source opencl implementation on top of that kernel api.
Btw this library code remind me of VHDL ... thought code style for userspace library is anybody choice.
Cheers,
Jérôme
Quoted 96 lines
Alexey Skidanov (1):
amdkfd: Implement the Get Process Aperture IOCTLAndrew Lewycky (3):
amdkfd: Add basic modules to amdkfd
amdkfd: Add interrupt handling module
amdkfd: Implement the Set Memory Policy IOCTLBen Goz (8):
amdkfd: Add queue module
amdkfd: Addmqd_managermodule
amdkfd: Add kernel queue module
amdkfd: Add module parameter of scheduling policy
amdkfd: Add packet manager module
amdkfd: Add process queue manager module
amdkfd: Add device queue manager module
amdkfd: Implement the create/destroy/update queue IOCTLsEvgeny Pinchuk (2):
amdkfd: Add topology module to amdkfd
amdkfd: Implement the Get Clock Counters IOCTLOded Gabbay (9):
drm/radeon: reduce number of free VMIDs and pipes in KV drm/radeon/cik: Don't touch int of pipes 1-7 drm/radeon: Report doorbell configuration to amdkfd drm/radeon: adding synchronization for GRBM GFX drm/radeon: Add radeon <--> amdkfd interface UpdateMAINTAINERSand CREDITS files with amdkfd info
amdkfd: Add IOCTL set definitions of amdkfd
amdkfd: Add amdkfd skeleton driver
amdkfd: Add binding/unbinding calls toamd_iommudriverCREDITS | 7 + MAINTAINERS | 10 + drivers/gpu/drm/radeon/Kconfig | 2 + drivers/gpu/drm/radeon/Makefile | 3 + drivers/gpu/drm/radeon/amdkfd/Kconfig | 10 + drivers/gpu/drm/radeon/amdkfd/Makefile | 14 + drivers/gpu/drm/radeon/amdkfd/cik_regs.h | 220 ++++ drivers/gpu/drm/radeon/amdkfd/kfd_aperture.c | 350 ++++++ drivers/gpu/drm/radeon/amdkfd/kfd_chardev.c | 511 +++++++++ drivers/gpu/drm/radeon/amdkfd/kfd_crat.h | 294 +++++ drivers/gpu/drm/radeon/amdkfd/kfd_device.c | 300 +++++ .../drm/radeon/amdkfd/kfd_device_queue_manager.c | 989 ++++++++++++++++ .../drm/radeon/amdkfd/kfd_device_queue_manager.h | 144 +++ drivers/gpu/drm/radeon/amdkfd/kfd_doorbell.c | 236 ++++ drivers/gpu/drm/radeon/amdkfd/kfd_interrupt.c | 161 +++ drivers/gpu/drm/radeon/amdkfd/kfd_kernel_queue.c | 330 ++++++ drivers/gpu/drm/radeon/amdkfd/kfd_kernel_queue.h | 66 ++ drivers/gpu/drm/radeon/amdkfd/kfd_module.c | 147 +++ drivers/gpu/drm/radeon/amdkfd/kfd_mqd_manager.c | 305 +++++ drivers/gpu/drm/radeon/amdkfd/kfd_mqd_manager.h | 88 ++ drivers/gpu/drm/radeon/amdkfd/kfd_packet_manager.c | 495 ++++++++ drivers/gpu/drm/radeon/amdkfd/kfd_pasid.c | 95 ++ drivers/gpu/drm/radeon/amdkfd/kfd_pm4_headers.h | 682 +++++++++++ drivers/gpu/drm/radeon/amdkfd/kfd_pm4_opcodes.h | 107 ++ drivers/gpu/drm/radeon/amdkfd/kfd_priv.h | 560 +++++++++ drivers/gpu/drm/radeon/amdkfd/kfd_process.c | 347 ++++++ .../drm/radeon/amdkfd/kfd_process_queue_manager.c | 346 ++++++ drivers/gpu/drm/radeon/amdkfd/kfd_queue.c | 85 ++ drivers/gpu/drm/radeon/amdkfd/kfd_topology.c | 1207 ++++++++++++++++++++ drivers/gpu/drm/radeon/amdkfd/kfd_topology.h | 168 +++ drivers/gpu/drm/radeon/cik.c | 154 +-- drivers/gpu/drm/radeon/cik_reg.h | 65 ++ drivers/gpu/drm/radeon/cikd.h | 53 +- drivers/gpu/drm/radeon/radeon.h | 10 + drivers/gpu/drm/radeon/radeon_device.c | 32 + drivers/gpu/drm/radeon/radeon_drv.c | 5 + drivers/gpu/drm/radeon/radeon_kfd.c | 525 +++++++++ drivers/gpu/drm/radeon/radeon_kfd.h | 177 +++ drivers/gpu/drm/radeon/radeon_kms.c | 7 + include/uapi/linux/kfd_ioctl.h | 126 ++ 40 files changed, 9338 insertions(+), 95 deletions(-) create mode 100644 drivers/gpu/drm/radeon/amdkfd/Kconfig create mode 100644 drivers/gpu/drm/radeon/amdkfd/Makefile create mode 100644 drivers/gpu/drm/radeon/amdkfd/cik_regs.h create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_aperture.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_chardev.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_crat.h create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_device.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_device_queue_manager.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_device_queue_manager.h create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_doorbell.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_interrupt.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_kernel_queue.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_kernel_queue.h create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_module.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_mqd_manager.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_mqd_manager.h create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_packet_manager.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_pasid.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_pm4_headers.h create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_pm4_opcodes.h create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_priv.h
Quoted 16 lines
create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_process.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_process_queue_manager.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_queue.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_topology.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_topology.h create mode 100644 drivers/gpu/drm/radeon/radeon_kfd.c create mode 100644 drivers/gpu/drm/radeon/radeon_kfd.h create mode 100644 include/uapi/linux/kfd_ioctl.hSignature · 6 lines
1.9.1 _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 205 lines · Oded
Quoted 38 lines · David Herrmann
Hi
Quoted 28 lines · Oded Gabbay
Hi,
Here is the v3 patch set of amdkfd.This version contains changes and fixes to code, as agreed on during the review of the v2 patch set.
The major changes are:
- There are two new module parameters: # of processes and # of queues per process. The defaults, as agreed on in the v2 review, are 32 and 128 respectively. This sets the default amount of GART address space that amdkfd requires to 3.5MB (3MB for userspace queues mqds and 0.5MB for other stuff, such as mqd for kernel queue, hpd for pipelines, etc.)
- All the GART address space usage of amdkfd is done inside a single contiguous buffer that is allocated from system memory, and pinned to the start of the GART during the startup of amdkfd (which is just after the startup of radeon). The management of this buffer is done by the radeon sa manager. This buffer is not evict-able.
- Mapping of doorbells is initiated by the userspace lib (by mmap syscall), instead of initiating it from inside an ioctl (using
vm_mmap).- Removed ioctls for exclusive access to performance counters
- Added documentation about the QCM (Queue Control Management), apertures and interfaces between amdkfd and radeon.
Quoted 6 lines
Two important notes:
- The topology patch has not been changed. Look at
http://lists.freedesktop.org/archives/dri-devel/2014-July/065042.html
for my response. I also put my answer as an explanation in the commit msg of the patch.Quoted 6 lines
This patchset adds 10.000 lines and contains nearly 0 comments *why* stuff is added. Seriously, it is almost impossible to understand what you're doing. Can you please include a high-level introduction in the [0/X] cover-letter and include it in every series you send? A blog-post or something would also be fine. And yes, it's totally ok if this is 10k lines of plain-text.
My bad. I forgot to attach the cover letter of v2 and especially v1, which includes a lengthy explanation of the driver.
So here it is and I will respond to your other comments later.
Oded
v2 cover letter:
-------------------As a continuation to the existing discussion, here is a v2 patch series restructured with a cleaner history and no totally-different-early-versions of the code.
Instead of 83 patches, there are now a total of 25 patches, where 5 of them are modifications to radeon driver and 18 of them include only amdkfd code. There is no code going away or even modified between patches, only added.
The driver was renamed from
radeon_kfdto amdkfd and moved to reside under drm/radeon/amdkfd. This move was done to emphasize the fact that this driver
is an AMD-only driver at this point. Having said that, we do foresee a generic hsa framework being implemented in the future and in that case, we will adjust amdkfd to work within that framework.As the amdkfd driver should support multiple AMD gfx drivers, we want to keep it as a seperate driver from radeon. Therefore, the amdkfd code is contained in its own folder. The amdkfd folder was put under the radeon folder because the only AMD gfx driver in the Linux kernel at this point is the radeon driver. Having said that, we will probably need to move it (maybe to be directly under drm) after we integrate with additional AMD gfx drivers.
For people who like to review using git, the v2 patch set is located at:
http://cgit.freedesktop.org/~gabbayo/linux/log/?h=kfd-next-3.17-v2Written by Oded Gabbayh <[email protected]>
-------------------------
Original Cover Letter:
-------------------------This patch set implements a Heterogeneous System Architecture (HSA) driver for radeon-family GPUs.
HSA allows different processor types (CPUs, DSPs, GPUs, etc..) to share system resources more effectively via HW features including shared pageable memory, userspace-accessible work queues, and platform-level atomics. In addition to the memory protection mechanisms in GPUVM and IOMMUv2, the Sea Islands family of GPUs also performs HW-level validation of commands passed in through the queues (aka rings).
The code in this patch set is intended to serve both as a sample driver for other HSA-compatible hardware devices and as a production driver for radeon-family processors. The code is architected to support multiple CPUs each with connected GPUs, although the current implementation focuses on a single Kaveri/Berlin APU, and works alongside the existing radeon kernel graphics driver (kgd).
AMD GPUs designed for use with HSA (Sea Islands and up) share some hardware functionality between HSA compute and regular gfx/compute (memory, interrupts, registers), while other functionality has been added specifically for HSA compute (hw scheduler for virtualized compute rings). All shared hardware is owned by the radeon graphics driver, and an interface
between kfd and kgd allows the kfd to make use of those shared resources, while HSA-specific functionality is managed directly by kfd by submitting packets into an HSA-specific command queue (the "HIQ").During kfd module initialization a char device node (
/dev/kfd) is created (surviving until module exit), with ioctls for queue creation & management, and data structures are initialized for managing HSA device topology.The rest of the initialization is driven by calls from the radeon kgd at the following points :
-
radeon_init(kfd_init)
-radeon_exit(kfd_fini)
-radeon_driver_load_kms(kfd_device_probe,kfd_device_init)
-radeon_driver_unload_kms(kfd_device_fini)During the probe and init processing per-device data structures are established which connect to the associated graphics kernel driver. This information is exposed to userspace via sysfs, along with a version number allowing userspace to determine if a topology change has occurred while it was reading from sysfs.
The interface between kfd and kgd also allows the kfd to request buffer management services from kgd, and allows kgd to route interrupt requests to kfd code since the interrupt block is shared between regular graphics/compute and HSA compute subsystems in the GPU.
The kfd code works with an open source usermode library ("libhsakmt") which is in the final stages of IP review and should be published in a separate repo over the next few days.
The code operates in one of three modes, selectable via the
sched_policymodule parameter :- sched_policy=0 uses a hardware scheduler running in the MEC block within CP, and allows oversubscription (more queues than HW slots)
- sched_policy=1 also uses HW scheduling but does not allow oversubscription, so
create_queuerequests fail when we run out of HW slots- sched_policy=2 does not use HW scheduling, so the driver manually assigns queues to HW slots by programming registers
The "no HW scheduling" option is for debug & new hardware bringup only, so has less test coverage than the other options. Default in the current code is "HW scheduling without oversubscription" since that is where we have the most test coverage but we expect to change the default to "HW scheduling with oversubscription" after further testing. This effectively removes the HW limit on the number of work queues available to applications.
Programs running on the GPU are associated with an address space through the
VMID field, which is translated to a unique PASID at access time via a set of 16 VMID-to-PASID mapping registers. The available VMIDs (currently 16) are partitioned (under control of the radeon kgd) between current gfx/compute and HSA compute, with each getting 8 in the current code. The VMID-to-PASID mapping registers are updated by the HW scheduler when used, and by driver code if HW scheduling is not being used.The Sea Islands compute queues use a new "doorbell" mechanism instead of the
earlier kernel-managed write pointer registers. Doorbells use a separate BAR
dedicated for this purpose, and pages within the doorbell aperture are mapped to userspace (each page mapped to only one user address space). Writes to the doorbell aperture are intercepted by GPU hardware, allowing userspace code to safely manage work queues (rings) without requiring a kernel call for every ring update.First step for an application process is to open the kfd device. Calls to open create a kfd "process" structure only for the first thread of the process. Subsequent open calls are checked to see if they are from processes
using the samemm_structand, if so, don't do anything. The kfd per-process data lives as long as themm_structexists. Eachmm_structis associated with a unique PASID, allowing the IOMMUv2 to make userspace process memory accessible to the GPU.Next step is for the application to collect topology information via sysfs. This gives userspace enough information to be able to identify specific nodes (processors) in subsequent queue management calls. Application processes can create queues on multiple processors, and processors support queues from multiple processes.
At this point the application can create work queues in userspace memory and
pass them through the usermode library to kfd to have them mapped onto HW queue slots so that commands written to the queues can be executed by the GPU. Queue operations specify a processor node, and so the bulk of this code
is device-specific.
Quoted 13 lines
Written by John Bridgman <[email protected]>
Quoted 9 lines
Lets start with the basics:
1) Why do you use kobject directly to expose the topology? Almost no other driver does that, why do you use it in amdkfd instead of "struct bus" and "struct device"? You totally lack uevent handling, sysfs hierarchy integration and more. If you'd use existing infrastructue instead of kobject directly, everything would work just fine.
The development of the module was done according to this document:
https://www.kernel.org/doc/Documentation/filesystems/sysfs.txt
Could you please elaborate some more why we must use "struct bus" and struct "device" ?
Quoted 4 lines
Quoted 4 lines
2) What kind of topology is exposed? Is it nested? How deep? How many items are usually expected? How does the sysfs tree (
tree /sys/..../topology) look like on your machine? For people without the hardware it's nearly impossible to understand how this will look like.
I published v4 patch-set of amdkfd, and I put a snapshot of the topology as it exists on a KV machine (only processor which is currently supported).
Quoted 8 lines
Quoted 8 lines
3) How is the interface supposed to be used? I can see one global char-dev where you can queue jobs by providing a GPU-ID. Why don't you create one char-dev *per* available GPU just like all other interfaces do? Why is this a separate thing instead of a
drm_minorobject that can be added per device as a separate interface to KMS and render-nodes? Where is the underlying "struct device" for those GPUs?
There were 2 major arguments for using a single fd :
1. Our ioctls are actually system calls in disguise. They operate on the process, not on a device.
2. An HSA device won't always be a GPU. Therefore, we don't want to be tied to drm framework too much.
You may call these arguments "philosophical" but nevertheless, I think they are valid.
Quoted 3 lines
Quoted 3 lines
4) Why is the topology static? FWIW, you allow runtime modifications, but I cannot see any notification mechanism for user-space? Again, using existing driver-core would provide all that for free.
Currently, we don't support any other processor than KV, and KV is an integrated processor which can't be hot-plugged. Therefore, the topology is static.
Our design states that the userspace is responsible for snapshotting the topology before it opens our fd. Therefore, we don't use uevent to notify the userspace about changes (currently theoretical) in the topology. For example you can look at the libhsakmt code I published to see how the userspace behaves with the topology.
Quoted 135 lines
Quoted 130 lines
I really appreciate that you provided code instead of just ideas, but please describe why you do things the way they are. And please provide examples for people who do not have the hardware.
Thanks
DavidQuoted 122 lines
- There are still some minor code style issues I need to fix. I didn't want to delay v3 any further but I will publish either v4 with those fixes, or just relevant patches if the whole patch set will be merged.
For people who like to review using git, the v3 patch set is located at:
http://cgit.freedesktop.org/~gabbayo/linux/log/?h=kfd-next-3.17-v3In addition, I would like to announce that we have uploaded the userspace lib that accompanies amdkfd. That lib is called "libhsakmt" and you can view it at:
http://cgit.freedesktop.org/~gabbayo/libhsakmtAlexey Skidanov (1):
amdkfd: Implement the Get Process Aperture IOCTLAndrew Lewycky (3):
amdkfd: Add basic modules to amdkfd
amdkfd: Add interrupt handling module
amdkfd: Implement the Set Memory Policy IOCTLBen Goz (8):
amdkfd: Add queue module
amdkfd: Addmqd_managermodule
amdkfd: Add kernel queue module
amdkfd: Add module parameter of scheduling policy
amdkfd: Add packet manager module
amdkfd: Add process queue manager module
amdkfd: Add device queue manager module
amdkfd: Implement the create/destroy/update queue IOCTLsEvgeny Pinchuk (2):
amdkfd: Add topology module to amdkfd
amdkfd: Implement the Get Clock Counters IOCTLOded Gabbay (9):
drm/radeon: reduce number of free VMIDs and pipes in KV drm/radeon/cik: Don't touch int of pipes 1-7 drm/radeon: Report doorbell configuration to amdkfd drm/radeon: adding synchronization for GRBM GFX drm/radeon: Add radeon <--> amdkfd interface UpdateMAINTAINERSand CREDITS files with amdkfd info
amdkfd: Add IOCTL set definitions of amdkfd
amdkfd: Add amdkfd skeleton driver
amdkfd: Add binding/unbinding calls toamd_iommudriverCREDITS | 7 + MAINTAINERS | 10 + drivers/gpu/drm/radeon/Kconfig | 2 + drivers/gpu/drm/radeon/Makefile | 3 + drivers/gpu/drm/radeon/amdkfd/Kconfig | 10 + drivers/gpu/drm/radeon/amdkfd/Makefile | 14 + drivers/gpu/drm/radeon/amdkfd/cik_regs.h | 220 ++++ drivers/gpu/drm/radeon/amdkfd/kfd_aperture.c | 350 ++++++ drivers/gpu/drm/radeon/amdkfd/kfd_chardev.c | 511 +++++++++ drivers/gpu/drm/radeon/amdkfd/kfd_crat.h | 294 +++++ drivers/gpu/drm/radeon/amdkfd/kfd_device.c | 300 +++++ .../drm/radeon/amdkfd/kfd_device_queue_manager.c | 989 ++++++++++++++++ .../drm/radeon/amdkfd/kfd_device_queue_manager.h | 144 +++ drivers/gpu/drm/radeon/amdkfd/kfd_doorbell.c | 236 ++++ drivers/gpu/drm/radeon/amdkfd/kfd_interrupt.c | 161 +++ drivers/gpu/drm/radeon/amdkfd/kfd_kernel_queue.c | 330 ++++++ drivers/gpu/drm/radeon/amdkfd/kfd_kernel_queue.h | 66 ++ drivers/gpu/drm/radeon/amdkfd/kfd_module.c | 147 +++ drivers/gpu/drm/radeon/amdkfd/kfd_mqd_manager.c | 305 +++++ drivers/gpu/drm/radeon/amdkfd/kfd_mqd_manager.h | 88 ++ drivers/gpu/drm/radeon/amdkfd/kfd_packet_manager.c | 495 ++++++++ drivers/gpu/drm/radeon/amdkfd/kfd_pasid.c | 95 ++ drivers/gpu/drm/radeon/amdkfd/kfd_pm4_headers.h | 682 +++++++++++ drivers/gpu/drm/radeon/amdkfd/kfd_pm4_opcodes.h | 107 ++ drivers/gpu/drm/radeon/amdkfd/kfd_priv.h | 560 +++++++++ drivers/gpu/drm/radeon/amdkfd/kfd_process.c | 347 ++++++ .../drm/radeon/amdkfd/kfd_process_queue_manager.c | 346 ++++++ drivers/gpu/drm/radeon/amdkfd/kfd_queue.c | 85 ++ drivers/gpu/drm/radeon/amdkfd/kfd_topology.c | 1207 ++++++++++++++++++++ drivers/gpu/drm/radeon/amdkfd/kfd_topology.h | 168 +++ drivers/gpu/drm/radeon/cik.c | 154 +-- drivers/gpu/drm/radeon/cik_reg.h | 65 ++ drivers/gpu/drm/radeon/cikd.h | 53 +- drivers/gpu/drm/radeon/radeon.h | 10 + drivers/gpu/drm/radeon/radeon_device.c | 32 + drivers/gpu/drm/radeon/radeon_drv.c | 5 + drivers/gpu/drm/radeon/radeon_kfd.c | 525 +++++++++ drivers/gpu/drm/radeon/radeon_kfd.h | 177 +++ drivers/gpu/drm/radeon/radeon_kms.c | 7 + include/uapi/linux/kfd_ioctl.h | 126 ++ 40 files changed, 9338 insertions(+), 95 deletions(-) create mode 100644 drivers/gpu/drm/radeon/amdkfd/Kconfig create mode 100644 drivers/gpu/drm/radeon/amdkfd/Makefile create mode 100644 drivers/gpu/drm/radeon/amdkfd/cik_regs.h create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_aperture.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_chardev.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_crat.h create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_device.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_device_queue_manager.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_device_queue_manager.h create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_doorbell.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_interrupt.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_kernel_queue.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_kernel_queue.h create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_module.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_mqd_manager.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_mqd_manager.h create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_packet_manager.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_pasid.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_pm4_headers.h create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_pm4_opcodes.h create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_priv.h create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_process.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_process_queue_manager.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_queue.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_topology.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_topology.h create mode 100644 drivers/gpu/drm/radeon/radeon_kfd.c create mode 100644 drivers/gpu/drm/radeon/radeon_kfd.h create mode 100644 include/uapi/linux/kfd_ioctl.h--
1.9.1_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel