A method and system for parallel enumeration of USB devices based on dynamic priority scheduling
The parallel enumeration method for USB devices using dynamic priority scheduling and resource arbitration solves the problems of inefficiency and resource contention in the USB enumeration process, achieving fast and energy-efficient multi-device enumeration, and improving user experience and system stability.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- TIH MICROELECTRONIC TECH CO LTD
- Filing Date
- 2026-04-23
- Publication Date
- 2026-07-21
AI Technical Summary
The existing USB enumeration process suffers from inefficiency, resource contention, and deadlock risks, and causes unnecessary energy waste for low-power devices, resulting in a poor user experience, especially when multiple devices are connected.
A parallel enumeration method for USB devices based on dynamic priority scheduling is adopted. The host controller assigns an initial enumeration priority to each new device, decomposes the enumeration process into atomic subtasks, and uses a central scheduler for resource arbitration and dynamic priority adjustment. This allows non-conflicting subtasks to be executed in parallel, and combines adaptive power management to optimize power consumption.
It significantly improves the speed of multi-device enumeration, prevents resource conflicts, reduces power consumption, ensures priority processing of critical input devices, enhances user experience, and is compatible with existing USB protocol stacks.
Smart Images

Figure CN122431830A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the technical field of computer interfaces, and more specifically, relates to a method and system for parallel enumeration of USB devices based on dynamic priority scheduling. Background Technology
[0002] USB (Universal Serial Bus) is the standard interface for connecting modern computing devices to peripheral devices. USB enumeration is the process by which a host identifies a newly connected device and loads the appropriate driver for it, including steps such as device detection, reset, address allocation, descriptor reading and configuration.
[0003] Chinese patent document CN102890662A discloses a method for identifying the host operating system by performing a second enumeration on a USB HID device. The method includes powering on the USB HID device and initializing it; performing a first enumeration on the USB HID device to determine the type of the host operating system; performing a second enumeration after sequentially completing a soft power-off and reconnection process between the USB HID device and the host operating system to ensure that the USB HID device can work normally; and re-executing the entire process to determine the host's operating system after restarting after receiving a restart flag from the host.
[0004] The standard USB enumeration process in existing technologies is typically executed serially and sequentially. When multiple devices connect simultaneously through a hub, the host controller enumerates them one by one in the order they are detected. This approach has the following significant drawbacks: Inefficiency: Serial enumeration causes the total enumeration time to increase linearly with the number of devices, requiring users to wait for all devices to become ready in sequence, resulting in a poor user experience. Resource contention and deadlock risks: When multiple devices simultaneously request system resources (such as memory and interrupts), contention may occur. If the enumeration process of a device (such as driver loading) malfunctions or times out, it can block the enumeration of subsequent devices, even causing the entire bus to respond slowly. Static power management: During enumeration, all ports are typically subjected to maximum power, which can lead to unnecessary energy waste for low-power devices or battery-powered hosts (such as laptops and tablets). Summary of the Invention
[0005] The present invention aims to overcome at least one of the defects of the prior art and provide a parallel enumeration method for USB devices based on dynamic priority scheduling to solve problems such as low efficiency, serial enumeration causing the total enumeration time to increase linearly with the number of devices, requiring users to wait for all devices to be ready in sequence, resulting in a poor user experience, resource contention and deadlock risks.
[0006] The detailed technical solution of this invention is as follows: A parallel enumeration method for USB devices based on dynamic priority scheduling, the method comprising: S1: When a port connection event is detected, the host controller assigns a temporary logical identifier to each new device, obtains the physical attributes of its port, and assigns an initial enumeration priority to the new device; The initial enumeration priority setting rules are as follows: key human-machine interface devices directly connected to the root hub have high priority; large-capacity storage devices have medium priority; and devices located in deep hub networks have low priority.
[0007] S2: The host central scheduler creates an independent enumeration task queue for each new device, breaking down the standard enumeration process into atomic subtasks, including: port reset, address allocation, descriptor acquisition, driver matching and loading, and function configuration. These subtasks are marked as different resource requirement types. S3: The host central scheduler maintains a global ready subtask queue, calculates dynamic priorities based on the current priority of the device to which the subtask belongs and the subtask type, and sorts them accordingly; then, before scheduling the execution of a subtask, it retrieves the first subtask and checks for conflicts in the resources it requires: For non-conflicting subtasks, they are allowed to be executed in parallel in different USB transaction schedulers; For conflicting subtasks, execute them in order of priority or retry after introducing a random delay; S4. Perform the enumeration operation and determine whether the descriptor acquisition is complete; Once the device descriptor is obtained, the request and retrieval of the device's address allocation and configuration descriptor can be triggered. At the same time, the device identification information is submitted to the driver matching engine for asynchronous query. Once a matching driver file is found, it is loaded. The descriptor retrieval includes the device descriptor and the configuration descriptor. If the descriptor is not obtained, continue with descriptor acquisition or waiting; if the descriptor is confirmed to be ready, call the driver matching engine; if continuing execution or waiting fails, update the task execution history, record the failure / time, and return to the ready subtask queue. Then, the host system matches the enumerated devices according to the driver file, which means the current enumeration phase is complete.
[0008] Furthermore, S3 specifically includes: S31 maintains a global ready subtask queue: First, when a new enumerated subtask arrives, the system assigns a unique task ID to the subtask and records the required resources. Then determine whether the subtask depends on other unfinished tasks: if yes, suspend the subtask and add it to the "waiting dependency queue"; if no, add it to the "global ready task queue". The scheduler schedules event triggers, i.e., subtask triggers, from the global ready task queue, calculates dynamic priorities based on the current priority of the device to which the subtask belongs and the subtask type, and sorts them accordingly. S32 Resource Conflict Detection: Extract the first subtask and perform a conflict check; If a conflict occurs, a resource arbitration strategy is executed: whether to preempt depends on the urgency of the subtask, including strategy A and strategy B; if strategy A is executed, the subtask is marked as "resource waiting" and added back to the "ready subtask queue" for execution in priority order; if strategy B is executed, the subtask is marked as "resource preemption" and retried after introducing a random delay. If there is no conflict or arbitration is successful, resources are allocated to the subtask, the status is marked as "in execution", and the subtask is distributed to the execution unit, allowing it to be executed in parallel in different USB transaction schedulers.
[0009] Furthermore, the introduced random delay strategy is as follows: Using an exponential backoff strategy, the delay time for conflicting tasks is: T_delay = T_base × B N / K. Where T_base is the preset base time unit, B is the backoff coefficient, N is the number of conflicts that occur in this task, and K is the weighting factor based on the current priority of the task.
[0010] Furthermore, the sorting based on the current priority of the device and the subtask type is specifically as follows: a dynamic adjustment strategy based on the initial enumeration priority, i.e., the initial enumeration priority and the dynamic priority adjustment strategy constitute a complete priority control process of "static initial value + dynamic feedback", including: Construct a dynamic priority score strategy model, i.e., dynamic priority score = base score + emergency increment - penalty item + reward item + load item; The initial enumeration priority is the base score, which serves as a static baseline to establish a benchmark score for the device, reflecting its inherent importance. The urgency of device interaction is the urgency increment. As a real-time intervention, an urgency increment that decays over time is set based on the urgency of the interaction waiting signal issued by the operating system or driver layer. As the most powerful dynamic intervention factor, it can instantly change the scheduling order and ensure user experience. The execution history of subtasks serves as a penalty / reward item, acting as negative feedback. Each time a subtask fails and is retried, its priority score is multiplied by a penalty coefficient less than 1. The penalty item is calculated as: Penalty = Current Dynamic Priority - Current Dynamic Priority * Penalty Coefficient. When a device successfully completes N subtasks consecutively, its score increases, and a reward item is directly added to encourage devices that perform well. This prevents the failure or anomaly of a single device from blocking the entire system, achieving both "fairness" and "robustness." The host load is the load factor. As a global resource regulator, when the host load index exceeds the threshold, the priority score of all computationally intensive subtasks is multiplied by a load factor less than 1, while the priority score of I / O waiting tasks is multiplied by a load factor greater than or equal to 1. That is, load item = current dynamic priority * load factor - current dynamic priority.
[0011] This causes the system to tend to perform lightweight tasks, wait for the load to decrease, smooth the system load, and avoid resource overload leading to overall crash.
[0012] Furthermore, the driver files for the matched enumerated devices are preloaded from the storage medium into the memory cache before the device configuration is complete, significantly reducing the waiting time during the driver loading stage.
[0013] Furthermore, it also includes S5: During the enumeration process, based on the power consumption field in the acquired device descriptor and the current task status of the device, the power supply mode of the port where the device is located is dynamically adjusted, and the device quickly enters the energy-saving state when the device queue is idle; and the enumeration progress, resource usage and dynamic priority of each device are recorded in real time.
[0014] In another aspect of the present invention, a system is provided for implementing a parallel enumeration method for USB devices based on dynamic priority scheduling, the system comprising: Enhanced host controller interface module, device perception and classification module, host central scheduler and resource arbitrator, pipeline processing engine, adaptive power management module and enumeration status database.
[0015] Enhanced host controller interface module: Used to connect new devices, responsible for detecting their underlying USB signals, and connecting to the host to provide the basis for execution; Device Awareness and Classification Module: Upon detecting a port connection event, the module performs an initial classification of the new device, assigning a temporary logical identifier and transmitting it to the host central scheduler and resource arbitrator. The port connection event represents the connection of the new device. Based on the hub level and port number of the device, combined with a quick device descriptor read attempt, the module performs a preliminary classification of the device: keyboards and mice are identified as HID devices, USB flash drives as mass storage devices, and printers as printers.
[0016] The host central scheduler and resource arbitrator: First, an independent enumeration task queue is created for each new device, breaking down the standard enumeration process into atomic subtasks and marking them as different resource requirement types; Second, a globally ready subtask queue is maintained, storing all subtasks and waiting for scheduling; Then, the subtasks are sorted according to the current priority of the device to which they belong and the subtask type; After resource conflict detection, the subtasks are transferred to the pipeline processing engine for execution.
[0017] Pipeline processing engine: Performs enumeration operations to determine if descriptor acquisition is complete; once the device descriptor is acquired, it triggers the request and acquisition of the device's address allocation and configuration descriptor, and simultaneously submits the device identification information to the driver matching engine for asynchronous querying. If a matching driver file is found, it is loaded. Descriptor acquisition includes both the device descriptor and the configuration descriptor. If the descriptor is not acquired, it continues with descriptor acquisition or waits; if the descriptor is confirmed to be ready, it calls the driver matching engine; if continuing execution or waiting fails, it updates the task execution history, records the failure / time taken, and returns to the ready subtask queue.
[0018] Furthermore, the pipeline processing engine also includes preloading of driver files.
[0019] Adaptive power management module: During the enumeration process, based on the power consumption field in the obtained device descriptor and the current task status of the device, the power supply mode of the port where the device is located is dynamically adjusted, and the device quickly enters the power saving state when the device queue is idle.
[0020] Enumeration status database: Records the enumeration progress, resource usage, and dynamic priority of each device in real time.
[0021] In another aspect of the invention, a computer-readable storage medium is also provided, which stores executable instructions that, when executed, cause the machine to perform a USB device parallel enumeration method based on dynamic priority scheduling as described above.
[0022] Compared with the prior art, the beneficial effects of the present invention are as follows: (1) The present invention provides a USB device parallel enumeration method and system based on dynamic priority scheduling. By executing non-conflicting subtasks and pipeline operations in parallel, the traditional serial enumeration "device and" time model is optimized to a time model close to "device maximum". Especially for scenarios with a large number of connected devices (such as workstations and servers), the overall enumeration time can be shortened by 30%-70%, significantly improving the speed of multi-device enumeration.
[0023] (2) The present invention provides a parallel enumeration method and system for USB devices based on dynamic priority scheduling. The dynamic priority and resource arbitration mechanism effectively prevent enumeration suspension or system lag caused by resource conflicts. Key input devices can be processed with priority, ensuring the immediacy of user interaction.
[0024] (3) The present invention provides a parallel enumeration method and system for USB devices based on dynamic priority scheduling. The intelligent scheduling smooths the usage curves of CPU, memory and bus bandwidth, avoiding the instantaneous load impact caused by all devices performing high-intensity operations (such as driver loading) at the same time. The integrated adaptive power management reduces unnecessary power consumption during enumeration, which is particularly beneficial for mobile devices and embedded systems to extend battery life and achieve energy saving in the enumeration process.
[0025] (4) The present invention provides a USB device parallel enumeration method and system based on dynamic priority scheduling, which is implemented at the host controller driver level, transparent to the upper-layer operating system and application, and fully compatible with the existing USB protocol stack and device driver. Attached Figure Description
[0026] Figure 1 This is a schematic diagram of the method flow described in this invention.
[0027] Figure 2 This is a timing diagram comparing the traditional serial enumeration process in Embodiment 1 of the present invention with the parallel pipeline enumeration process of the present invention.
[0028] Figure 3 This is a flowchart illustrating the dynamic priority scheduling and resource arbitration process in Embodiment 1 of the present invention.
[0029] Figure 4 This is a schematic diagram of the dynamic adjustment strategy based on the initial enumeration priority in Embodiment 1 of the present invention.
[0030] Figure 5 This is a schematic diagram of the "decision-execution-feedback" cycle in Embodiment 1 of the present invention.
[0031] Figure 6 This is a schematic diagram of the system structure in Embodiment 2 of the present invention. Detailed Implementation
[0032] The present invention will be further described below with reference to the accompanying drawings and embodiments.
[0033] It should be noted that the following detailed descriptions are exemplary and intended to provide further illustration of the invention. Unless otherwise specified, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention pertains.
[0034] It should be noted that the terminology used herein is for the purpose of describing particular embodiments only and is not intended to limit the scope of exemplary embodiments according to the invention. As used herein, the singular form is intended to include the plural form as well, unless the context clearly indicates otherwise. Furthermore, it should be understood that when the terms "comprising" and / or "including" are used in this specification, they indicate the presence of features, steps, operations, devices, components, and / or combinations thereof.
[0035] Where there is no conflict, the embodiments and features in the embodiments of the present invention can be combined with each other.
[0036] Example 1 To address the shortcomings of existing technologies, the core of this approach lies in decoupling the enumeration process into multiple subtasks that can be executed in parallel or pipelined, and dynamically allocating system resources through a central scheduler to achieve fast, stable, and energy-efficient enumeration of multiple access devices.
[0037] On a computer platform running a Windows / Linux operating system, the USB host controller driver of this invention is integrated. When a user plugs in a USB hub containing a keyboard, mouse, USB flash drive, and printer, the system works collaboratively according to steps S1 to S5. A parallel enumeration method for USB devices based on dynamic priority scheduling is executed as follows: S1: Equipment Detection and Initial Classification: When a port connection event is detected, the host controller assigns a temporary logical identifier (LID) to each new device, which is a label for different devices, and obtains the physical attributes of its port (such as the hub level and port number). It initially assigns an enumeration priority based on the new device's connection location (such as the root hub port number or the external hub port number) and device type (through the first descriptor read attempt).
[0038] The initial enumeration priority setting rules are as follows: key human-machine interface devices (HID, such as keyboards and mice) directly connected to the root hub have the highest priority; large-capacity storage devices are next; and devices located in deep hub networks are next.
[0039] Preferably, taking keyboard, mouse, USB flash drive and printer as examples, the system's enhanced host controller interface module detects the hub connection event and assigns a unique temporary logical identifier (LID1, LID2, LID3, LID4) to the hub and the devices (keyboard, mouse, USB flash drive and printer) on its four ports.
[0040] Based on the above information, devices are assigned initial enumeration priorities: keyboard (LID1) and mouse (LID2) are assigned "high priority," while USB flash drive (LID3) and printer (LID4) are assigned "medium priority." This information is recorded in the enumeration status database.
[0041] S2: Create a parallel dynamic task queue: Each new device creates an independent enumeration task queue, breaking down the standard enumeration process into atomic subtasks, including: port reset, address allocation, descriptor acquisition (device descriptor, configuration descriptor, etc.), driver matching and loading, and function configuration. These subtasks are then categorized into different resource requirement types, such as bus bandwidth requirement, CPU computation requirement, and I / O wait requirement.
[0042] Preferably, the central scheduler and resource arbitrator create an independent dynamic task queue for each LID. This decouples the enumeration process for each device into atomic subtasks, for example: LID1 queue: [Port reset, address allocation, get device descriptor, get configuration descriptor, set configuration, driver loading]; LID2 queue: [Port reset, address allocation, get device descriptor, get configuration descriptor, set configuration, driver loading]; LID3 and LID4 are the same as above.
[0043] Each subtask is tagged with a resource requirement type, such as "port reset" and "address allocation" being bus bandwidth-intensive, and "driver loading" being CPU- and memory-intensive.
[0044] S3: Dynamic Priority Scheduling and Resource Arbitration The host central scheduler maintains a global ready subtask queue, sorts the subtasks according to the current priority of the device to which they belong and the subtask type, and stores them in the global ready subtask queue to await scheduling; then, before scheduling the execution of a subtask, it checks the conflict of the resources it requires; for non-conflicting subtasks (e.g., reading descriptors from different devices), they are allowed to be executed in parallel in different USB transaction schedulers. For conflicting subtasks, execute them in order of priority or retry after introducing a random delay.
[0045] This invention does not merely break down and queue tasks in software logic (which is a form of concurrency), but rather achieves overlapping execution in physical time through deep collaboration between the scheduler and the underlying hardware capabilities. This fundamentally breaks through the inherent serial bottleneck in the USB enumeration process, which is the key technical guarantee for achieving the goal of "optimizing the total enumeration time from the sum of devices to the maximum of devices".
[0046] Specifically, such as Figure 3 As shown, the dynamic priority scheduling and resource arbitration specifically include: S31 maintains a global ready subtask queue: First, when a new enumerated subtask arrives (such as port reset, address allocation, obtaining descriptors (device descriptor, configuration descriptor), driver matching and loading, function configuration), the system assigns a unique task ID to the subtask and records the required resource requirements; Then determine whether the subtask depends on other unfinished tasks: if yes, suspend the subtask and add it to the "waiting dependency queue"; if no, add it to the "global ready task queue". Event triggering, i.e., subtask triggering, is scheduled from the global ready task queue. Dynamic priorities are calculated and sorted based on the current priority of the device to which the subtask belongs and the subtask type. S32 Resource Conflict Detection: Extract the first subtask and perform a conflict check; If a conflict occurs, a resource arbitration strategy is executed: whether to preempt depends on the urgency of the subtask, including strategy A (waiting) and strategy B (preemption); if strategy A (waiting) is executed, the subtask is marked as "resource waiting" and added back to the "ready subtask queue" for execution in priority order; if strategy B (preemption) is executed, the subtask is marked as "resource preemption", a random delay is introduced, and the process is retried. If there is no conflict or the arbitration is successful, resources are allocated to the subtask, the status is marked as "in execution", and the subtask is dispatched to the execution unit (such as the driver loader executing the driver loading task), allowing it to be executed in parallel in different USB transaction schedulers; Specifically, the conflict check involves checking whether the resources (memory blocks, interrupt lines, bandwidth) required by the task conflict with those of the task currently being executed.
[0047] The USB transaction scheduler described above is a scheduler that handles physical transactions related to the USB bus, such as IN / OUT / SETUP token packets and subsequent data packets and handshake packets. It is a physical execution unit. It is implemented based on physical and practical rules such as USB bus timing, frame / microframe structure, and bandwidth availability. The host central scheduler is the scheduling strategy engine implemented in this invention. It processes logical tasks and schedules atomic enumerated subtasks, such as "port reset" and "acquire descriptor." It is a logical concept that makes decisions based on strategic rules such as device priority, task dependencies, and resource conflict prediction.
[0048] Furthermore, such as Figure 4 As shown, the sorting based on the current priority of the device to which it belongs and the subtask type is specifically as follows: a dynamic adjustment strategy based on the initial enumeration priority, that is, the initial enumeration priority and the dynamic priority adjustment strategy constitute a complete priority control process of "static initial value + dynamic feedback". The dynamic adjustment strategy involves: the urgency of device interaction (e.g., input devices), subtask execution history (e.g., number of retries; higher retries temporarily lower priority to prevent starvation), and host load (CPU and memory usage). The dynamic priority scheduling includes: Initial phase: Assigning initial enumeration priority (static evaluation: based on type / position); Runtime phase: Priority dynamic adjustment strategy (dynamic feedback: based on runtime state); Then, the task is scheduled and executed. If the task succeeds, the final result is a closed-loop feedback, achieving efficient and stable parallel enumeration. If the task fails or is retried, a feedback loop is initiated, i.e., a dynamic priority adjustment strategy is introduced (e.g., temporarily reducing the priority), and the task re-enters the runtime phase.
[0049] Specifically, the priority dynamic adjustment strategy, i.e., the strategy description model, is: Dynamic Priority Score = Base Score + Emergency Increment - Penalty Item + Reward Item + Load Item; 1) Initial enumeration priority (base score as static baseline); Purpose: To establish a benchmark score for the equipment, reflecting its inherent importance.
[0050] Specific assignment example: HID (keyboard, mouse): Base score = 100; Large-capacity storage (USB flash drive, hard drive): Base score = 70; Video / audio equipment (camera, speakers): base score = 60; Other / Unknown Devices: Base Score = 50; (Note: The impact of connection level can be converted into a coefficient, such as the root hub device coefficient being 1.0, the first-level hub coefficient being 0.9, and so on).
[0051] 2) Urgency of device interaction (urgent increment as real-time intervention); Function: This is the most powerful dynamic intervention factor, namely the emergency increment that decays over time, which can instantly change the scheduling order and ensure user experience.
[0052] Specific strategies: Detection: The operating system or driver layer sends an "interactive wait" signal (such as detecting user input focus switching, mouse movement events, or audio playback stuttering).
[0053] Response (Increment): Once the signal is triggered, immediately add a very large increment Q (e.g., +200) to the priority score of the current and all subsequent subtasks of the corresponding device. This ensures that the next ready task for that device will almost certainly be at the head of the queue in the next sorting.
[0054] Decay: This increment can gradually decay over time or as the task is completed, i.e., decrease q / t (e.g., 5 / s) until it returns to normal.
[0055] 3) Subtask execution history (penalty / reward items used as negative feedback adjustment); Function: To prevent the failure or malfunction of a single device from blocking the entire system, thus achieving "fairness" and "robustness".
[0056] Specific strategies: Penalty: For each failed retry of a subtask, its priority score is multiplied by a penalty coefficient less than 1 (e.g., *0.7). That is, penalty = current dynamic priority - current dynamic priority * 0.7. This gradually moves the device to which the subtask belongs to the queue further back, freeing up resources for other devices.
[0057] Rewards: After a device successfully completes N sub-tasks consecutively, its sub-task dynamic priority score will be increased, which is equivalent to adding a reward (e.g., +5) to encourage devices that perform well.
[0058] Historical Elapsed Time: Records the historical average elapsed time for a certain type of subtask (such as driver loading). If the current task times out significantly (>2 times the average elapsed time), a penalty is triggered.
[0059] 4) Host load status (load factor serves as a global resource regulator); Function: To smooth system load and prevent resource overload from causing overall crash.
[0060] Specific strategies: Monitoring metrics: CPU utilization, available memory, and USB bus bandwidth utilization.
[0061] The adjustment rules for monitoring indicators include: Load balancing: When the host load metric, i.e., the monitoring metric, exceeds a threshold (e.g., 80%), the priority score of all computationally intensive subtasks (such as driver matching and descriptor resolution) is multiplied by a load factor less than 1 (e.g., a factor of *0.8), while the priority score of I / O-waiting tasks is multiplied by a load factor greater than or equal to 1 (the score remains unchanged or increases slightly). That is, load item = current dynamic priority * load factor - current dynamic priority. This causes the system to tend to execute lightweight tasks, waiting for the load to decrease.
[0062] To prevent starvation: When the host load metric exceeds the threshold, a "wait time" factor is introduced for tasks that have been penalized multiple times (i.e., twice or more). As the wait time increases, the score receives a small compensatory increase to ensure that the task can eventually be executed.
[0063] Load balancing refers to reducing the execution priority of intensive subtasks to prevent excessive load. Preventing starvation, on the other hand, prevents some tasks from being starved of execution when the load is too high.
[0064] In summary, the scheduler sorts all tasks in the "Global Ready Subtask Queue" (usually in descending order) based on the dynamic priority values output by the "Dynamic Priority Adjustment Strategy." It then outputs an ordered list of tasks to be executed. The task at the top of the queue will receive system resources first and be executed.
[0065] This embodiment takes the simultaneous enumeration of a keyboard (HID, base score 100) and a USB flash drive (storage device, base score 70) as an example.
[0066] Initially: The keyboard task queue is scheduled first.
[0067] Issue: The keyboard retried twice when "Get Configuration Descriptor" (load is normal).
[0068] Dynamic calculation: The dynamic score for keyboard tasks is calculated as follows: 100 (base score) * 0.7^2 (retry penalty) ≈ 49 points. USB flash drive task dynamic score = 70 points; Sorting result: At this point, the USB drive task (70 points) will be scheduled before the keyboard task (49 points).
[0069] Sudden Intervention: Suddenly, the system detected that the user pressed the Caps Lock key on the keyboard (interactive emergency event). The system detected other data packets during the enumeration process! No penalty, reward, or load items.
[0070] Recalculate: Keyboard task dynamic score = 49 + 200 (urgent increment) = 249 points; Final order: The keyboard task (249 points) immediately jumps to the front of the queue and is either preempted or given priority in the next scheduling cycle.
[0071] The preferred strategy for introducing random delays is as follows: An exponential backoff strategy is adopted, and the delay time of conflicting tasks is calculated according to the formula T_delay=T_base×(B^N) / K. Where T_base is the preset base time unit (e.g., 10 microseconds), B is the backoff coefficient (usually 2), N is the number of conflicts that occur in the task, and K is a weighting factor based on the current priority of the task (the higher the priority, the larger the value of K).
[0072] S4: Pipeline descriptor processing and driver preloading; Perform the enumeration operation to determine whether the descriptor acquisition is complete; If the device descriptor has been obtained, the device address allocation and configuration descriptor request can be triggered after the device descriptor is obtained. At the same time, the device identification information (manufacturer identification code VID, product identification code PID) is submitted to the driver matching engine for asynchronous query to obtain the matching driver file. If the descriptor is not obtained, continue execution (descriptor acquisition) or wait. If the descriptor is confirmed to be ready, the driver matching engine is called. If continuing execution or waiting fails, the task execution history is updated, the failure / time is recorded, and the ready subtask queue is returned. The host system matches and enumerates the device (a USB device) based on the driver file, thus completing the current enumeration phase. Preferably, this is done if and only if all its predefined atomic subtasks (including port reset, address allocation, descriptor acquisition, and configuration settings) are marked as successful. If the enumeration is complete, the resources occupied by the subtask are released, and then the progress of the device in the enumeration state database is updated. At this time, the device enters the "configured" state at the USB protocol level. Then a new scheduling event is generated, and the new event triggers the next round of scheduling by S3 to enter the ready subtask queue. If the enumeration fails, the task execution history is updated, the failure is recorded, and the task is returned to the ready subtask queue. Preferably, after the current enumeration phase is completed, the central scheduler will deregister the device from the dynamic enumeration task queue, and its corresponding logical identifier (LID) and related runtime resources can be reclaimed.
[0073] Preferably, the driver files for matching enumerated devices can be preloaded from the storage medium into the memory cache before the device is fully configured, which greatly shortens the waiting time during the driver loading stage.
[0074] In this embodiment, taking the completion of the "get device descriptor" task of keyboard LID1 as an example, the matching engine is driven to perform asynchronous queries, including: 1) The descriptor parser parses the descriptor, extracts the VID / PID, and updates the information to the enumeration state database; 2) The driver loading manager then starts, uses the VID / PID to query the system driver store, and begins preloading the keyboard driver file into the memory cache. Simultaneously, the parsed device power consumption information is also recorded.
[0075] The mouse LID2 descriptor is then returned to the system, triggering the same pipelined processing described above.
[0076] While the mouse descriptor I / O waits, scheduler S3 has switched to execute the "address allocation" task for the USB drive's LID3. This achieves pipeline filling between different device subtasks.
[0077] The above S3 and S4 form a tightly coupled, feedback-enabled "decision-execution-feedback" loop, specifically as follows: Figure 5 As shown, a loop is formed consisting of a dynamic scheduling and arbitration layer (decision brain), a pipeline execution layer, and a feedback closed loop layer. The enumeration process is executed by issuing enumeration commands to obtain descriptors and set addresses.
[0078] Preferably, the timing comparison between the traditional serial enumeration process and the parallel pipelined enumeration process is as follows: Figure 2 As shown in the diagram, the upper half, representing the traditional enumeration timeline, describes the process as follows: At time T0, the bus detects three devices (A, B, and C) connected simultaneously. T1-T5 represent the complete enumeration process for device A, sequentially performing "a port reset" -> "b address allocation" -> "c descriptor acquisition" -> "d driver loading" -> "e configuration." This entire process occupies a continuous time block, during which the bus only processes device A. Device B's "a port reset" only begins at time T6. After device B's enumeration is complete, device C begins its enumeration process.
[0079] The lower half of the diagram, describing the parallel enumeration time, is as follows: At time T0, the system detects the insertion of three devices (A, B, and C). Between T0 and T1, the scheduler initializes and prioritizes the three devices. At time T1, the serial process for device A begins, but the task is decomposed. Device B's "port reset" task starts shortly after time T1, while device A is still performing "address allocation." This is because the bus resources used by "port reset" and "address allocation" do not conflict, and the scheduler allows them to run in parallel. Device C's "port reset" also begins shortly afterward.
[0080] Pipeline operation description: After device A completes "acquiring descriptors," the descriptor information is immediately sent to the "driver matching engine" to begin asynchronous driver search and "pre-fetching." At this time, device A's process continues into "configuration," while device B may be performing "address allocation," and device C may have just completed a reset. Driver loading is no longer a blocking step. The "driver matching engine" operates independently and in parallel, without being blocked by the main process.
[0081] S5: Integrated Adaptive Power Management During the enumeration process, the central scheduler dynamically adjusts the power supply mode of the port where the device is located (e.g., switching from high-power enumeration mode to negotiated operating power mode) based on the power consumption field in the acquired device descriptor and the current task status of the device (e.g., in I / O waiting), and quickly enters the power saving state when the device queue is idle; and monitors the task status of the database and the scheduler in real time. Subsequently, the driver loading and power state fine-tuning of the device will be completed as independent system background tasks, by the general mechanism of the operating system and the driver preloading manager and adaptive power management module in this invention, without affecting the enumeration and scheduling of other newly connected devices.
[0082] In this embodiment, when the "Settings Configuration" subtask of keyboard LID1 is completed, the adaptive power management module reads its bMaxPower field (assumed to be 100mA) from the enumerated state library.
[0083] The module then dynamically adjusts the power supply to the port where the keyboard is located from the full power (500mA) of the enumeration module to a lower power (such as 100mA) that meets its operating requirements through the host controller.
[0084] The LID2 mouse also performs similar power-saving adjustments after completing the same phase.
[0085] Subsequent scheduling and conflict handling (return to S3 logic): When the enumeration process of USB flash drive LID3 and printer LID4 progresses to the "driver loading" subtask, the resource arbitration module S3 detects that both are "memory-intensive" tasks and that the current system has insufficient free memory, so both are processed simultaneously.
[0086] The arbitration module makes a ruling based on the current dynamic priorities of the two tasks (which may be fine-tuned due to execution history). Since the USB drive's LID3 task is ready, its priority is temporarily increased to allow its driver loading to proceed first. The printer's LID4 driver loading task is marked as having a resource conflict, and after a small random delay, it is placed back into the ready queue to wait. Once the LID4 resource is no longer conflicting, the subsequent "driver loading" subtasks are completed sequentially, thus completing the enumeration process.
[0087] Example 2 This embodiment provides a system for implementing a parallel enumeration method for USB devices based on dynamic priority scheduling. Figure 6 The system includes: an enhanced host controller interface module, a device perception and classification module, a host central scheduler and resource arbitrator, a pipeline processing engine, an adaptive power management module, and an enumerated state database.
[0088] Enhanced host controller interface module: Used to connect new devices, responsible for detecting their underlying USB signals, and connecting to the host to provide the basis for execution; Device Awareness and Classification Module: Upon detecting a port connection event, the module performs an initial classification of the new device, assigning a temporary logical identifier and transmitting it to the host central scheduler and resource arbitrator. The port connection event represents the connection of the new device. Preferably, the device awareness and classification module performs a preliminary classification based on the hub level (all first-level) and port number, combined with a quick device descriptor read attempt: keyboards and mice are identified as HID (Human Interface Device) devices, USB flash drives are identified as mass storage devices, and printers are identified as printers.
[0089] The host central scheduler and resource arbitrator work as follows: First, an independent enumeration task queue is created for each new device, breaking down the standard enumeration process into atomic subtasks, which are then marked as different resource requirement types. Second, a globally ready subtask queue is maintained, storing all subtasks and awaiting scheduling. The subtasks are then sorted according to the current priority of the device to which they belong and the subtask type. After resource conflict detection, the subtasks are transferred to the pipeline processing engine for execution. Pipeline processing engine: Performs enumeration operations to determine if descriptor acquisition is complete; once the device descriptor is acquired, it triggers the request and acquisition of the device's address allocation and configuration descriptor, and simultaneously submits the device identification information to the driver matching engine for asynchronous querying. If a matching driver file is found, it is loaded. Descriptor acquisition includes both the device descriptor and the configuration descriptor. If the descriptor is not acquired, it continues with descriptor acquisition or waits; if the descriptor is confirmed to be ready, it calls the driver matching engine; if continuing execution or waiting fails, it updates the task execution history, records the failure / time taken, and returns to the ready subtask queue.
[0090] Furthermore, the pipeline processing engine also includes preloading of driver files.
[0091] Adaptive power management module: During the enumeration process, based on the power consumption field in the obtained device descriptor and the current task status of the device, dynamically adjust the power supply mode of the port where it is located, and quickly enter the energy-saving state when the device queue is idle. Enumeration status database: Records the enumeration progress, resource usage, and dynamic priority of each device in real time.
[0092] Example 3 This embodiment also provides a computer-readable storage medium storing executable instructions that, when executed, cause the machine to perform a USB device parallel enumeration method based on dynamic priority scheduling as described above.
[0093] Specifically, a system or apparatus equipped with a readable storage medium may be provided, on which software program code implementing the functions of any of the embodiments described above is stored, and the computer or processor of the system or apparatus can read and execute the instructions stored in the readable storage medium.
[0094] In this case, the program code itself, which can be read from the readable medium, can perform the functions of any of the above embodiments, and therefore the computer-readable code and the readable storage medium storing the computer-readable code constitute a part of this specification.
[0095] Examples of readable storage media include floppy disks, hard disks, magneto-optical disks, optical disks (such as CD-ROM, CD-R, CD-RW, DVD-ROM, DVD-RAM, DVD-RW, DVD-RW), magnetic tapes, non-volatile memory cards, and ROMs. Alternatively, program code can be downloaded from a server computer or the cloud via a communication network.
[0096] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0097] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0098] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0099] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0100] Obviously, the above embodiments of the present invention are merely examples for clearly illustrating the technical solutions of the present invention, and are not intended to limit the specific implementation of the present invention. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the claims of the present invention should be included within the protection scope of the claims of the present invention.
Claims
1. A parallel enumeration method for USB devices based on dynamic priority scheduling, characterized in that, The method includes: S1: When a port connection event is detected, the host controller assigns a temporary logical identifier to each new device, obtains the physical attributes of its port, and assigns an initial enumeration priority to the new device; The initial enumeration priority setting rules are as follows: key human-machine interface devices directly connected to the root hub have high priority; large-capacity storage devices have medium priority; and devices located in deep hub networks have low priority. S2: The host central scheduler creates an independent enumeration task queue for each new device, breaking down the standard enumeration process into atomic subtasks, including: port reset, address allocation, descriptor acquisition, driver matching and loading, and function configuration. These subtasks are marked as different resource requirement types. S3: The host central scheduler maintains a global ready subtask queue, calculates dynamic priorities based on the current priority of the device to which the subtask belongs and the subtask type, and sorts them accordingly; then, before scheduling the execution of a subtask, it retrieves the first subtask and checks for conflicts in the resources it requires: For non-conflicting subtasks, they are allowed to be executed in parallel in different USB transaction schedulers; For conflicting subtasks, execute them in order of priority or retry after introducing a random delay; S4. Perform the enumeration operation and determine whether the descriptor acquisition is complete; Once the device descriptor is obtained, the request and retrieval of the device's address allocation and configuration descriptor can be triggered. At the same time, the device identification information is submitted to the driver matching engine for asynchronous query. Once a matching driver file is found, it is loaded. The descriptor retrieval includes the device descriptor and the configuration descriptor. If the descriptor is not obtained, continue with descriptor acquisition or waiting; if the descriptor is confirmed to be ready, call the driver matching engine; if continuing execution or waiting fails, update the task execution history, record the failure / time, and return to the ready subtask queue. Then, the host system matches the enumerated devices according to the driver file, which means the current enumeration phase is complete.
2. The USB device parallel enumeration method based on dynamic priority scheduling according to claim 1, characterized in that, S3 specifically includes: S31 maintains a global ready subtask queue: First, when a new enumerated subtask arrives, the system assigns a unique task ID to the subtask and records the required resources. Then determine whether the subtask depends on other unfinished tasks: if yes, suspend the subtask and add it to the "waiting dependency queue"; if no, add it to the "global ready task queue". The scheduler schedules event triggers, i.e., subtask triggers, from the global ready task queue, calculates dynamic priorities based on the current priority of the device to which the subtask belongs and the subtask type, and sorts them accordingly. S32 Resource Conflict Detection: Extract the first subtask and perform a conflict check; If a conflict occurs, a resource arbitration strategy is executed: whether to preempt depends on the urgency of the subtask, including strategy A and strategy B; if strategy A is executed, the subtask is marked as "resource waiting" and added back to the "ready subtask queue" for execution in priority order; if strategy B is executed, the subtask is marked as "resource preemption" and retried after introducing a random delay. If there is no conflict or arbitration is successful, resources are allocated to the subtask, the status is marked as "in execution", and the subtask is dispatched to the execution unit, allowing it to be executed in parallel in different USB transaction schedulers.
3. The USB device parallel enumeration method based on dynamic priority scheduling according to claim 2, characterized in that, The introduced random delay strategy is as follows: Using an exponential backoff strategy, the delay time for conflicting tasks is: T_delay = T_base × (B^N) / K; Where T_base is the preset base time unit, B is the backoff coefficient, N is the number of conflicts that occur in the task, and K is the weighting factor based on the current priority of the task.
4. The parallel enumeration method for USB devices based on dynamic priority scheduling according to claim 3, characterized in that, The sorting is based on the current priority of the device to which it belongs and the subtask type, specifically as follows: Construct a dynamic priority score strategy model, i.e., dynamic priority score = base score + emergency increment - penalty item + reward item + load item; The initial enumeration priority is the base score, which serves as a static baseline to establish a benchmark score for the device. The urgency of device interaction is the urgency increment. As a real-time intervention, an urgency increment that decays over time is set based on the urgency of the interaction waiting signal issued by the operating system or driver layer. This serves as a dynamic intervention factor to instantly change the scheduling order. The execution history of subtasks serves as a penalty / reward item. As a negative feedback adjustment, each time a subtask fails and is retried, its priority score is multiplied by a penalty coefficient less than 1. The penalty item = current dynamic priority - current dynamic priority * penalty coefficient. After a device successfully completes N subtasks consecutively, its score increases directly by a reward item. The host load is the load factor. As a global resource regulator, when the host load index exceeds the threshold, the priority score of all computationally intensive subtasks is multiplied by a load factor less than 1, while the priority score of I / O waiting tasks is multiplied by a load factor greater than or equal to 1. That is, load item = current dynamic priority * load factor - current dynamic priority.
5. The USB device parallel enumeration method based on dynamic priority scheduling according to claim 3, characterized in that, The driver files for the matched enumerated devices are preloaded from the storage medium into the memory cache before the device configuration is complete.
6. A parallel enumeration method for USB devices based on dynamic priority scheduling according to claim 1 or 5, characterized in that, It also includes S5: During the enumeration process, based on the power consumption field in the acquired device descriptor and the current task status of the device, the power supply mode of the port where the device is located is dynamically adjusted, and the device quickly enters the energy-saving state when the device queue is idle; and the enumeration progress, resource usage and dynamic priority of each device are recorded in real time.
7. A system for implementing a parallel enumeration method for USB devices based on dynamic priority scheduling, characterized in that, The system includes: Enhanced host controller interface module, device perception and classification module, host central scheduler and resource arbitrator, pipeline processing engine, adaptive power management module and enumeration status database; Enhanced host controller interface module: Used to connect new devices, responsible for detecting their underlying USB signals, and connecting to the host to provide the basis for execution; Device perception and classification module: Detects port connection events and performs initial classification of new devices, i.e., assigns a temporary logical identifier, and transmits it to the host central scheduler and resource arbitrator. The port connection event is the connection of the new device. Preliminary classification: Keyboard and mouse are identified as HID class, USB flash drive is identified as mass storage class, and printer is identified as printing class. The host central scheduler and resource arbitrator: First, an independent enumeration task queue is created for each new device, and the standard enumeration process is broken down into atomic subtasks, which are marked as different resource requirement types. Second, a global ready subtask queue is maintained to store all subtasks and wait for scheduling. Then, the subtasks are sorted according to the current priority of the device to which they belong and the subtask type. After resource conflict detection, the subtasks are transferred to the pipeline processing engine for execution. Pipeline processing engine: Performs enumeration operations to determine if descriptor acquisition is complete; after acquiring the device descriptor, it triggers the request and acquisition of the device's address allocation and configuration descriptor, and submits the device identification information to the driver matching engine for asynchronous querying. If a matching driver file is found, it is loaded. Descriptor acquisition includes device descriptor and configuration descriptor; if the descriptor is not acquired, it continues to acquire the descriptor or waits; if the descriptor is confirmed to be ready, it calls the driver matching engine; if continuing execution or waiting fails, it updates the task execution history, records the failure / time consumption, and returns to the ready subtask queue. The pipeline processing engine also includes preloading of driver files; Adaptive power management module: During the enumeration process, based on the power consumption field in the obtained device descriptor and the current task status of the device, dynamically adjust the power supply mode of the port where it is located, and quickly enter the energy-saving state when the device queue is idle. Enumeration status database: Records the enumeration progress, resource usage, and dynamic priority of each device in real time.
8. An electronic device, characterized in that, The electronic device includes: processor; A memory on which computer programs that can run on the processor are stored; When the computer program is executed by the processor, it implements the steps of a method for accurate acquisition of multi-dimensional information in orchards based on a collaborative calibration algorithm and a foldable probe, as described in any one of claims 1 to 6.
9. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the method as described in any one of claims 1 to 6.