1*5954cfa8SSrinivasan Shanmugam.. SPDX-License-Identifier: GPL-2.0 2*5954cfa8SSrinivasan Shanmugam 3*5954cfa8SSrinivasan Shanmugam========================= 4*5954cfa8SSrinivasan Shanmugam AMDGPU Process Isolation 5*5954cfa8SSrinivasan Shanmugam========================= 6*5954cfa8SSrinivasan Shanmugam 7*5954cfa8SSrinivasan ShanmugamThe AMDGPU driver includes a feature that enables automatic process isolation on the graphics engine. This feature serializes access to the graphics engine and adds a cleaner shader which clears the Local Data Store (LDS) and General Purpose Registers (GPRs) between jobs. All processes using the GPU, including both graphics and compute workloads, are serialized when this feature is enabled. On GPUs that support partitionable graphics engines, this feature can be enabled on a per-partition basis. 8*5954cfa8SSrinivasan Shanmugam 9*5954cfa8SSrinivasan ShanmugamIn addition, there is an interface to manually run the cleaner shader when the use of the GPU is complete. This may be preferable in some use cases, such as a single-user system where the login manager triggers the cleaner shader when the user logs out. 10*5954cfa8SSrinivasan Shanmugam 11*5954cfa8SSrinivasan ShanmugamProcess Isolation 12*5954cfa8SSrinivasan Shanmugam================= 13*5954cfa8SSrinivasan Shanmugam 14*5954cfa8SSrinivasan ShanmugamThe `run_cleaner_shader` and `enforce_isolation` sysfs interfaces allow users to manually execute the cleaner shader and control the process isolation feature, respectively. 15*5954cfa8SSrinivasan Shanmugam 16*5954cfa8SSrinivasan ShanmugamPartition Handling 17*5954cfa8SSrinivasan Shanmugam------------------ 18*5954cfa8SSrinivasan Shanmugam 19*5954cfa8SSrinivasan ShanmugamThe `enforce_isolation` file in sysfs can be used to enable process isolation and automatic shader cleanup between processes. On GPUs that support graphics engine partitioning, this can be enabled per partition. The partition and its current setting (0 disabled, 1 enabled) can be read from sysfs. On GPUs that do not support graphics engine partitioning, only a single partition will be present. Writing 1 to the partition position enables enforce isolation, writing 0 disables it. 20*5954cfa8SSrinivasan Shanmugam 21*5954cfa8SSrinivasan ShanmugamExample of enabling enforce isolation on a GPU with multiple partitions: 22*5954cfa8SSrinivasan Shanmugam 23*5954cfa8SSrinivasan Shanmugam.. code-block:: console 24*5954cfa8SSrinivasan Shanmugam 25*5954cfa8SSrinivasan Shanmugam $ echo 1 0 1 0 > /sys/class/drm/card0/device/enforce_isolation 26*5954cfa8SSrinivasan Shanmugam $ cat /sys/class/drm/card0/device/enforce_isolation 27*5954cfa8SSrinivasan Shanmugam 1 0 1 0 28*5954cfa8SSrinivasan Shanmugam 29*5954cfa8SSrinivasan ShanmugamThe output indicates that enforce isolation is enabled on zeroth and second parition and disabled on first and fourth parition. 30*5954cfa8SSrinivasan Shanmugam 31*5954cfa8SSrinivasan ShanmugamFor devices with a single partition or those that do not support partitions, there will be only one element: 32*5954cfa8SSrinivasan Shanmugam 33*5954cfa8SSrinivasan Shanmugam.. code-block:: console 34*5954cfa8SSrinivasan Shanmugam 35*5954cfa8SSrinivasan Shanmugam $ echo 1 > /sys/class/drm/card0/device/enforce_isolation 36*5954cfa8SSrinivasan Shanmugam $ cat /sys/class/drm/card0/device/enforce_isolation 37*5954cfa8SSrinivasan Shanmugam 1 38*5954cfa8SSrinivasan Shanmugam 39*5954cfa8SSrinivasan ShanmugamCleaner Shader Execution 40*5954cfa8SSrinivasan Shanmugam======================== 41*5954cfa8SSrinivasan Shanmugam 42*5954cfa8SSrinivasan ShanmugamThe driver can trigger a cleaner shader to clean up the LDS and GPR state on the graphics engine. When process isolation is enabled, this happens automatically between processes. In addition, there is a sysfs file to manually trigger cleaner shader execution. 43*5954cfa8SSrinivasan Shanmugam 44*5954cfa8SSrinivasan ShanmugamTo manually trigger the execution of the cleaner shader, write `0` to the `run_cleaner_shader` sysfs file: 45*5954cfa8SSrinivasan Shanmugam 46*5954cfa8SSrinivasan Shanmugam.. code-block:: console 47*5954cfa8SSrinivasan Shanmugam 48*5954cfa8SSrinivasan Shanmugam $ echo 0 > /sys/class/drm/card0/device/run_cleaner_shader 49*5954cfa8SSrinivasan Shanmugam 50*5954cfa8SSrinivasan ShanmugamFor multi-partition devices, you can specify the partition index when triggering the cleaner shader: 51*5954cfa8SSrinivasan Shanmugam 52*5954cfa8SSrinivasan Shanmugam.. code-block:: console 53*5954cfa8SSrinivasan Shanmugam 54*5954cfa8SSrinivasan Shanmugam $ echo 0 > /sys/class/drm/card0/device/run_cleaner_shader # For partition 0 55*5954cfa8SSrinivasan Shanmugam $ echo 1 > /sys/class/drm/card0/device/run_cleaner_shader # For partition 1 56*5954cfa8SSrinivasan Shanmugam $ echo 2 > /sys/class/drm/card0/device/run_cleaner_shader # For partition 2 57*5954cfa8SSrinivasan Shanmugam # ... and so on for each partition 58*5954cfa8SSrinivasan Shanmugam 59*5954cfa8SSrinivasan ShanmugamThis command initiates the cleaner shader, which will run and complete before any new tasks are scheduled on the GPU. 60