Development Workflow

Basic Principles

According to Figure 1, the three core elements of deterministic scheduling are deterministic compute resources, deterministic event scheduler, and deterministic service execution. The deterministic event scheduler can be ensured by a platform and an OS. The deterministic compute resources need to be allocated and reserved based on an actual service scenario, and the deterministic service execution needs to be adapted and reconstructed based on an actual service requirement.

  • Deterministic compute resources

    The compute resource includes CPUs, memory, double data rate (DDR) bandwidth, and hardware accelerator resources such as AI Core, AI Vector Core, and DVPP. After the usage of the resources allocated to the services reaches 80%, the compute resources should be expanded or the input should be restricted.

  • Deterministic service execution
    The Linux system is a fair scheduling system based on round robin. To ensure that the execution time of a task is determined, it needs to be ensured that the execution process of the task is not interrupted. Currently, the following policies are used for event scheduling:
    • The event scheduler ensures that there is only one ready task on a CPU core so that the OS cannot switch to other tasks.
    • During scheduling, tasks that have been allocated with the CPU are not preempted, ensuring that running tasks are not interrupted.

    The event scheduler and OS scheduling ensure that the task will not be switched and the task itself does not proactively release the CPU. Therefore, the service code must ensure that:

    • No active sleep occurs.
    • Avoid semaphore waiting.
    • No other system calls that may fall into kernel mode.

    In addition, after excluding the possibility of proactively releasing the CPU, the service code needs to reduce the execution time of a single task (no more than 10 ms temporarily) so that other tasks can be executed. By default, threads created by services are scheduled by the OS and are not within the scope of the deterministic scheduling framework. Therefore, to ensure deterministic scheduling, services need to remove threads and use the OpenHiva interface for communication and scheduling. For latency-sensitive services (for example, to ensure an interval of 10 ms), the services need to invoke the real-time timer interface of OpenHiva and allocate independent CPU resources.

Development Procedure

Figure 1 Development workflow
  1. Prepare the environment, including the development environment and board environment. For details about the environment requirements, see Environment Setup.
  2. Analyze development scenarios.

    Determine the required functions (such as data transfer and model inference) based on the specific scenarios, and develop the corresponding functions based on the Message Subscribing-Publishing.

  3. Create code directories.

    Create a directory to store code files, build scripts, test data, and model files.

  4. Develop an application. For details, see Message Subscribing-Publishing.
    1. Initialize resources.
    2. Publish and subscribe to messages.
    3. After all data is processed, release resources in a timely manner.
  5. Build and run the application. For details, see Build and Run.