Mode switching method and device and electronic equipment

By monitoring the reactor load and dynamically switching the SPDK working mode, combined with full-process interrupt processing, this solves the problems of SPDK's resource waste and insufficient performance under different loads, achieving a balance between energy consumption and performance, and is suitable for high-performance storage and low-load scenarios.

CN120762846APending Publication Date: 2025-10-10XINHUASAN INFORMATION TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510887712.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-06-27
Publication Date
2025-10-10

AI Technical Summary

Technical Problem

SPDK's working mode cannot automatically switch according to business conditions, resulting in an inability to achieve a relative balance between energy saving and performance. The interrupt mode has insufficient performance under high load, and the polling mode wastes CPU resources under low load.

Method used

By monitoring the reactor's load, the operating mode is dynamically switched: switching to polling mode when overloaded and switching to interrupt mode when idle, implementing full-process interrupt handling and combining it with backend storage interrupt handles to reduce CPU usage.

Benefits of technology

It automatically adjusts the working mode under different load conditions, taking into account both energy consumption optimization and performance improvement, reducing CPU usage to 0, and is suitable for high-performance storage scenarios and extreme energy saving under low load.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120762846A_ABST
    Figure CN120762846A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of computers, and particularly provides a mode switching method and device and electronic equipment. The method comprises the following steps: according to the busy duration of each reaction in each period, determining the load of the reaction in each period; under the condition that the current working mode is the interrupt mode, detecting whether the load of the reactor in the recently continuous M1 cycles meets a set overload condition or not for each reactor, and determining whether to switch the current working mode from the interrupt mode to a polling mode or not according to an overload detection result of at least one reactor; under the condition that the current operation mode is a polling mode, detecting whether the load of the reactor in the latest continuous M2 cycles meets a set idle condition or not for each reactor, and determining whether to switch the current working mode from the polling mode to an interruption mode or not according to an idle detection result of at least one reactor; m2 is a positive integer. Therefore, energy consumption optimization and performance improvement are both considered.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a method, device, and electronic device for mode switching. Background Art

[0002] The Storage Performance Development Kit (SPDK) operates in two modes: interrupt mode and polling mode. Interrupt mode introduces latency and performs worse than polling mode, failing to meet performance requirements under high loads. Polling mode continuously occupies the Central Processing Unit (CPU), potentially leading to excessive CPU utilization and wasting CPU resources under low loads.

[0003] Under related technologies, SPDK usually sets corresponding working modes for different application scenarios to suit different application scenarios. However, it cannot automatically switch modes according to business conditions and cannot achieve a relative balance between energy saving and performance. Summary of the Invention

[0004] In view of this, embodiments of the present application provide a mode switching method, device, and electronic device.

[0005] On the one hand, an embodiment of the present application provides a mode switching method, which is applied to an electronic device using a storage development toolkit SPDK framework. The SPDK creates at least one task execution unit reactor and creates a backend storage file descriptor bs->fd based on a backend storage module. The method includes:

[0006] Determine the load of each reactor in each cycle based on the busy time of each reactor in each cycle;

[0007] When the current operating mode is interrupt mode, each reactor is tested for its load in the most recent M1 cycles to see if it meets the set overload condition. Based on the overload detection result of at least one reactor, a determination is made as to whether the current operating mode should be switched from interrupt mode to polling mode. M1 is a positive integer. Polling mode instructs the reactor to perform operations based on a polling mechanism. In interrupt mode, the reactor is awakened to perform event processing when it detects any file descriptor event is ready. File descriptor events include the backend storage file descriptor bs->fd created based on the backend storage module.

[0008] When the current operating mode is polling mode, for each reactor, check whether the load of the reactor in the most recent M2 cycles meets the set idle condition. Then, based on the idle detection result of at least one reactor, determine whether to switch the current operating mode from polling mode to interrupt mode; M2 is a positive integer.

[0009] In one embodiment, the overload condition is set as follows: the load in a single cycle exceeds a first load threshold;

[0010] The idle condition is set as: the load in a single cycle is lower than the second load threshold.

[0011] In one embodiment, determining whether to switch a current operating mode from an interrupt mode to a polling mode based on an overload detection result of at least one reactor includes:

[0012] Filter out the overloaded reactor from at least one reactor; the load of the overloaded reactor in the most recent M1 consecutive cycles meets the set overload condition;

[0013] If the number of overloaded reactors is not less than a first threshold, the current working mode is switched from the interrupt mode to the polling mode.

[0014] In one embodiment, determining whether to switch a current operating mode from a polling mode to an interrupt mode based on an idle detection result of at least one reactor includes:

[0015] Select an idle reactor from at least one reactor; the load of the idle reactor in the last M1 consecutive cycles meets the set idle condition;

[0016] If the number of idle reactors is not less than the second number threshold, the current working mode is switched from the polling mode to the interrupt mode.

[0017] In one embodiment, the SPDK creates a corresponding task file descriptor reactor->epfd for each reactor; the method further includes:

[0018] When the current working mode is interrupt mode, the following event loop is executed for each reactor:

[0019] The reactor calls the blocking function to block the corresponding reactor->epfd until any file descriptor event monitored by the reactor->epfd is ready;

[0020] When any file descriptor event monitored by reactor->epfd is ready, wake up the reactor;

[0021] The reactor calls the corresponding callback function to perform event processing operations.

[0022] In one implementation, the file descriptor further includes a thread file descriptor thread->epfd;

[0023] Before calling the blocking function through the reactor to block the corresponding reactor->epfd, the method also includes:

[0024] For each reactor, perform the following steps:

[0025] Create the thread spdk_thread through the reactor;

[0026] Create the corresponding reactor->epfd for the reactor;

[0027] Create corresponding thread->epfd for spdk_thread;

[0028] Register thread->epfd to the monitoring list of reactor->epfd so that reactor can monitor the events of spdk_thread.

[0029] In one embodiment, the file descriptor further includes a transmission file descriptor trans->fd;

[0030] Before calling the blocking function through the reactor to block the corresponding reactor->epfd, the method also includes:

[0031] Through spdk_thread, create a transmission trans instance and generate the corresponding trans->fd;

[0032] Register trans->fd to the listening list of spdk_thread so that spdk_thread can listen to the events of the trans instance.

[0033] In one embodiment, before calling the blocking function by the reactor to block and monitor the corresponding reactor->epfd, the method further includes:

[0034] Create a host block device hbd instance through spdk_thread;

[0035] Based on the hbd instance, create an object manager objecter instance and generate the corresponding bs->fd;

[0036] Register bs->fd to the listening list of spdk_thread so that spdk_thread can listen to the events of the objecter instance.

[0037] On the one hand, an embodiment of the present application provides a mode switching device, which is applied to an electronic device using a storage development toolkit SPDK framework. The SPDK creates at least one task execution unit reactor and creates a backend storage file descriptor bs->fd based on a backend storage module. The device includes:

[0038] A determination unit, configured to determine the load of each reactor in each cycle according to the busy duration of each reactor in each cycle;

[0039] The first switching unit is configured to, when the current operating mode is the interrupt mode, detect for each reactor whether the load of the reactor in the most recent consecutive M1 cycles meets a set overload condition, and determine whether to switch the current operating mode from the interrupt mode to the polling mode based on the overload detection result of at least one reactor; wherein M1 is a positive integer; the polling mode is used to instruct the reactor to perform operations based on the polling mechanism. In the interrupt mode, the reactor is awakened to perform event processing operations when it detects that any file descriptor event is ready; the file descriptor event includes the backend storage file descriptor bs->fd created based on the backend storage module;

[0040] The second switching unit is configured to detect, for each reactor, whether the load of the reactor in the most recent consecutive M2 cycles meets the set idle condition when the current operating mode is the polling mode, and determine whether to switch the current operating mode from the polling mode to the interrupt mode based on the idle detection result of at least one reactor; M2 is a positive integer.

[0041] In one embodiment, the overload condition is set as follows: the load in a single cycle exceeds a first load threshold;

[0042] The idle condition is set as: the load in a single cycle is lower than the second load threshold.

[0043] In one embodiment, the first switching unit is configured to:

[0044] Filter out the overloaded reactor from at least one reactor; the load of the overloaded reactor in the most recent M1 consecutive cycles meets the set overload condition;

[0045] If the number of overloaded reactors is not less than a first threshold, the current working mode is switched from the interrupt mode to the polling mode.

[0046] In one embodiment, the second switching unit is configured to:

[0047] Select an idle reactor from at least one reactor; the load of the idle reactor in the last M1 consecutive cycles meets the set idle condition;

[0048] If the number of idle reactors is not less than the second number threshold, the current working mode is switched from the polling mode to the interrupt mode.

[0049] In one embodiment, the SPDK creates a corresponding task file descriptor reactor->epfd for each reactor; the first switching unit is further configured to:

[0050] When the current working mode is interrupt mode, the following event loop is executed for each reactor:

[0051] The reactor calls the blocking function to block the corresponding reactor->epfd until any file descriptor event monitored by the reactor->epfd is ready;

[0052] When any file descriptor event monitored by reactor->epfd is ready, wake up the reactor;

[0053] The reactor calls the corresponding callback function to perform event processing operations.

[0054] In one embodiment, the file descriptor further includes a thread file descriptor thread->epfd; and the first switching unit is further configured to:

[0055] For each reactor, perform the following steps:

[0056] Create the thread spdk_thread through the reactor;

[0057] Create the corresponding reactor->epfd for the reactor;

[0058] Create corresponding thread->epfd for spdk_thread;

[0059] Register thread->epfd to the monitoring list of reactor->epfd so that reactor can monitor the events of spdk_thread.

[0060] In one embodiment, the file descriptor further includes a transmission file descriptor trans->fd; and the first switching unit is further configured to:

[0061] Through spdk_thread, create a transmission trans instance and generate the corresponding trans->fd;

[0062] Register trans->fd to the listening list of spdk_thread so that spdk_thread can listen to the events of the trans instance.

[0063] In one embodiment, before calling the blocking function to block and monitor the corresponding reactor->epfd through the reactor, the first switching unit is further configured to:

[0064] Create a host block device hbd instance through spdk_thread;

[0065] Based on the hbd instance, create an object manager objecter instance and generate the corresponding bs->fd;

[0066] Register bs->fd to the listening list of spdk_thread so that spdk_thread can listen to the events of the objecter instance.

[0067] In one aspect, an embodiment of the present application provides an electronic device, including:

[0068] processor; and

[0069] The memory stores computer instructions, where the computer instructions are used to enable the processor to execute the steps of the method provided in any of the various optional implementations of any of the above-mentioned mode switching.

[0070] On the one hand, an embodiment of the present application provides a computer-readable storage medium storing computer instructions, which are used to enable a computer to execute the steps of the method provided in various optional implementations of any of the above-mentioned mode switching.

[0071] On the one hand, an embodiment of the present application provides a computer program product, including computer-readable code, or a non-volatile computer-readable storage medium carrying computer-readable code. When the computer-readable code runs in a processor of an electronic device, the processor in the electronic device executes the steps of the method provided in various optional implementations of any of the above-mentioned mode switching.

[0072] The mode switching method in an embodiment of the present application includes determining the load of each reactor in each cycle based on the busy duration of each reactor in each cycle; when the current working mode is interrupt mode, detecting whether the load of each reactor in the most recent M1 consecutive cycles meets the set overload condition, and determining whether to switch the current working mode from interrupt mode to polling mode based on the overload detection result of at least one reactor; wherein M1 is a positive integer; the polling mode is used to instruct the reactor to perform operations based on the polling mechanism. In interrupt mode, the reactor is awakened to perform event processing operations when it listens to any file descriptor event ready; the file descriptor event includes the backend storage file descriptor bs->fd created based on the backend storage module; when the current operating mode is polling mode, detecting whether the load of each reactor in the most recent M2 consecutive cycles meets the set idle condition, and determining whether to switch the current working mode from polling mode to interrupt mode based on the idle detection result of at least one reactor; M2 is a positive integer. In this way, the working mode can be automatically switched according to the business load, taking into account both energy consumption optimization and performance improvement. BRIEF DESCRIPTION OF THE DRAWINGS

[0073] Figure 1 This is a flowchart of a mode switching method in an embodiment of the present application.

[0074] Figure 2 It is an interactive flow chart of a mode switching method in an embodiment of the present application.

[0075] Figure 3 This is an initialization interaction flow chart in an embodiment of the present application.

[0076] Figure 4 It is a schematic diagram of a monitoring relationship in an embodiment of the present application.

[0077] Figure 5 This is an interactive flow chart of a method for handling interrupt events in an embodiment of the present application.

[0078] Figure 6 This is a structural block diagram of a mode switching device in an embodiment of the present application.

[0079] Figure 7 It is a structural diagram of an electronic device in an embodiment of the present application. DETAILED DESCRIPTION

[0080] The technical solutions of the present application will be described clearly and completely below in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application. In addition, the technical features involved in the different embodiments of the present application described below can be combined with each other as long as they do not conflict with each other.

[0081] As a high-performance storage development toolkit (SPDK), SPDK aims to maximize the performance and efficiency of storage systems. It has achieved significant success in the storage field, boasting widespread adoption and an active community. It significantly improves storage system throughput, latency, and CPU utilization, and is widely used in a variety of high-performance storage scenarios, including: Cloud computing: It provides high-performance virtualized storage support for virtual machines, such as virtual hosts (vhosts) and virtual host users (vhost-users). Distributed storage: It is used to build high-performance distributed storage systems, such as Ceph and MinIO. Databases: It provides low-latency and high-throughput storage access for database systems, such as MySQL and PostgreSQL. Real-time data processing: It is suitable for latency-sensitive applications, such as financial trading and real-time analytics (RTA). High-performance storage device optimization: It maximizes the performance of non-volatile memory express (NVMe) SSDs, making it suitable for high-performance storage devices.

[0082] SPDK operates in two modes: interrupt mode and polling mode. Interrupt mode introduces latency and offers inferior performance to polling mode, failing to meet performance requirements under high loads. Polling mode continuously occupies the CPU, potentially leading to excessive CPU utilization and wasting CPU resources under low loads. Balancing energy consumption and performance is a key issue in storage system operation. Different application scenarios have varying energy and performance requirements, and maintaining a balance between these two is a worthy area of ​​research.

[0083] Under the relevant technology, SPDK usually sets corresponding working modes for different application scenarios to suit different application scenarios respectively. However, it is impossible to automatically switch modes according to business conditions. Specifically, in actual applications, business models and business volumes often change with changes in time periods or usage scenarios. However, the existing SPDK framework lacks a mechanism to automatically perceive real-time changes in business and cannot dynamically adjust the working mode according to real-time changes in business. This leads to resource waste or insufficient performance when business volume changes, and it is impossible to achieve a relative balance between energy saving and performance. Furthermore, because the back-end storage module does not provide an interrupt handle, the interrupt mode of SPDK does not use interrupt processing throughout the entire process. When no business is received, the process cannot maximize the release of CPU resources and cannot reduce the CPU occupancy rate to 0.

[0084] Based on the defects of the above-mentioned related technologies, the embodiments of the present application provide a mode switching method, device and electronic device, aiming to balance energy consumption optimization and performance improvement.

[0085] A mode switching method is provided in an embodiment of the present application. The method can be applied to electronic devices that adopt the SPDK framework. The present application does not limit the type of electronic device. It can be any type of device suitable for implementation, such as terminal devices and servers, etc. The present application will not go into details about this.

[0086] In one implementation, the SPDK framework includes a thread (spdk_thread) module, a transport (trans) module, a scheduler module, a block device host block device (Bdev_Hbd), and a backend storage (BS) module. It also creates instances of the main task execution unit (main_reactor), the task execution unit (reactor), spdk_thread, trans instances, host block device (hbd) instances, and the object manager (objecter). Each reactor is bound to a CPU core.

[0087] See Figure 1 As shown in FIG. 1 , a flow chart of a method for mode switching in an embodiment of the present application is shown in FIG. Figure 1 The method is described below. The specific implementation process of the method is as follows:

[0088] Step 101: Determine the load of each reactor in each cycle according to the busy duration of each reactor in each cycle.

[0089] Step 102: When the current operating mode is the interrupt mode, for each reactor, check whether the load of the reactor in the most recent M1 consecutive cycles meets the set overload condition, and determine whether to switch the current operating mode from the interrupt mode to the polling mode based on the overload detection result of at least one reactor.

[0090] Where M1 is a positive integer; polling mode is used to instruct the reactor to perform operations based on the polling mechanism. In interrupt mode, the reactor is awakened to perform event processing operations when it detects any file descriptor event is ready; file descriptor events include the backend storage file descriptor bs->fd created based on the backend storage module; file descriptors can also include thread file descriptors thread->epfd and transmission file descriptors trans->fd. File descriptors can also be called event handles.

[0091] The overload condition is set as follows: the load in a single cycle exceeds a first load threshold to determine whether a cycle is overloaded. In actual applications, the first load threshold can be set according to actual application scenarios and is not limited here.

[0092] In one embodiment, when determining whether to switch the current working mode from the interrupt mode to the polling mode based on the overload detection result of at least one reactor, the following steps may be taken:

[0093] S1021: Filter out an overloaded reactor from at least one reactor; the load of the overloaded reactor in the most recent M1 consecutive cycles all meets the set overload condition.

[0094] S1022: If the number of overloaded reactors is not less than a first threshold, the current working mode is switched from the interrupt mode to the polling mode.

[0095] For example, if a single reactor is currently operating in interrupt mode, then when its load exceeds 50 (i.e., the first threshold) for three consecutive scheduling cycles (i.e., M1), the reactor switches to polling mode. For another example, the first threshold could be the total number of reactors, meaning that the reactor switches to polling mode only when all reactors are overloaded.

[0096] Optionally, one scheduling period may be 1 second, and the default first load threshold may be 50. Furthermore, it may be modified through a configuration file and restarted to take effect after the target application (TGT).

[0097] In this way, oscillation can be prevented through three cycles, and mode switching makes performance the main focus at this time.

[0098] Step 103: When the current operating mode is polling mode, for each reactor, check whether the load of the reactor in the most recent consecutive M2 cycles meets the set idle condition, and determine whether to switch the current operating mode from polling mode to interrupt mode based on the idle detection result of at least one reactor.

[0099] Wherein, M2 is a positive integer, and the idle condition is set as: the load in a single cycle is lower than the second load threshold, so as to determine whether a certain cycle is idle.

[0100] In actual applications, the second load threshold can be set according to actual application scenarios and is not limited here.

[0101] S1031: Filter out an idle reactor from at least one reactor; the load of the idle reactor in the most recent M1 consecutive cycles all meets the set idle condition;

[0102] S1032: If the number of idle reactors is not less than a second number threshold, the current working mode is switched from the polling mode to the interrupt mode.

[0103] For example, if a single reactor is currently operating in polling mode, then when its load is below 50 (the second threshold) for 10 consecutive scheduling cycles (i.e., M2), the reactor switches to interrupt mode, primarily for energy conservation. Alternatively, the second threshold could be the total number of reactors, meaning that the reactor switches only when all reactors are idle.

[0104] In this way, by switching between full interrupt mode and adaptive mode, the storage process can be adjusted in real time according to the user's business volume, achieving a balance between energy consumption and performance.

[0105] In one implementation, SPDK creates a corresponding task file descriptor reactor->epfd for each reactor. When the current working mode is interrupt mode, the following event loop is executed for each reactor:

[0106] The reactor calls a blocking function to block the corresponding reactor->epfd until any file descriptor event monitored by reactor->epfd is ready; when any file descriptor event monitored by reactor->epfd is ready, the reactor is woken up; the reactor calls the corresponding callback function to perform event processing operations, and after the processing is completed, the reactor is blocked again.

[0107] In one embodiment, the file descriptor further includes a thread file descriptor thread->epfd. For each reactor, the following steps are performed:

[0108] Create a thread spdk_thread through the reactor; create a corresponding reactor->epfd for the reactor; create a corresponding thread->epfd for the spdk_thread; register thread->epfd to the monitoring list of reactor->epfd, so that the reactor monitors the events of spdk_thread.

[0109] In one embodiment, the file descriptor includes a transmission file descriptor trans->fd. Through spdk_thread, a transmission trans instance is created and a corresponding trans->fd is generated. Trans->fd is registered in the listening list of spdk_thread, so that spdk_thread listens to events of the trans instance.

[0110] In one embodiment, a host block device hbd instance is created through spdk_thread; based on the hbd instance, an object manager objecter instance is created and a corresponding bs->fd is generated; bs->fd is registered in the listening list of spdk_thread, so that spdk_thread listens to events of the objecter instance.

[0111] The following combination Figure 2 For further explanation of the mode switching method, see Figure 2 FIG. 1 is an interactive flow chart of a mode switching method, which includes:

[0112] Step 201: Each reactor counts the busy duration of each cycle.

[0113] In one embodiment, the main reactor creates multiple reactors, each of which executes the following steps in a loop for each cycle:

[0114] Process the event or message of the current round (i.e. the current period), and after the processing is completed, calculate the busy duration and idle duration of the current period.

[0115] Optionally, the busy duration can be the size of a busy time slice, and the idle duration can be the size of an idle time slice.

[0116] Step 202: The main reactor sends the busy duration of each reactor to the Scheduler.

[0117] In an embodiment, the main reactor respectively calculates the duration of each operating state of each reactor. The operating states can include busy and idle, for example, the following time slices can be obtained: the current idle time slice on the reactor core->current_idle_tsc, the total idle time slice on the reactor core->total_idle_tsc, the current busy time slice on the reactor core->current_busy_tsc, and the total busy time slice on the reactor core->total_busy_tsc.

[0118] Step 203: The Scheduler determines the load of each reactor in each period according to the busy duration of each reactor in the period.

[0119] In an embodiment, when determining the load of any reactor in any period, the following formula can be used:

[0120] Load = 100 * busy duration / period duration. Wherein, the period duration is the duration of the period, i.e. the sum of the busy duration and the idle duration of the period.

[0121] Step 204: The Scheduler sends a mode switching instruction to each reactor when the mode switching condition is met according to the load of each reactor in each period.

[0122] Step 205: Each reactor performs mode switching based on the mode switching instruction.

[0123] Step 206: Each reactor sends a mode switching instruction to each corresponding spdk_thread.

[0124] Step 207: Each spdk_thread performs mode switching based on the mode switching instruction.

[0125] Step 208: Each spdk_thread sends a mode switching notification to the trans instance.

[0126] Step 209: The trans instance performs mode switching based on the mode switching notification.

[0127] Step 210: Each spdk_thread sends a mode switch notification to the BS instance.

[0128] Step 211: The BS instance performs mode switching based on the mode switching notification.

[0129] Before switching modes, take a reactor as an example to initialize and perform interrupt monitoring. Figure 3 For a description of the initialization process, see Figure 3 FIG. 1 is a flowchart of an initialization interaction, wherein the method includes:

[0130] Step 301: The main reactor creates a corresponding reactor for the CPU core and generates reactor->epfd.

[0131] In one implementation, during the startup of a target application (TGT), a corresponding reactor is created for each CPU core.

[0132] TGT is a high-performance target-side application implementation designed specifically for optimizing storage performance. It leverages the user-mode drivers and lock-free architecture of the Storage Performance Development Kit (SPDK) and is suitable for storage scenarios requiring low latency and high throughput. TGT enables sharing of local high-performance storage devices with remote clients via protocols such as the Internet Small Computer System Interface (iSCSI) and the Non-Volatile Memory Host Controller Interface Specification over Fabrics (nvmf).

[0133] Step 302: The reactor creates spdk_thread and generates thread->epfd.

[0134] For example, the reactor calls the spdk_thread module (also called a component), creates a spdk_thread, and sets its name to poll_group_xx.

[0135] Step 303: The reactor registers thread->epfd to the monitoring list of reactor->epfd.

[0136] In this way, you can monitor thread->epfd events through reactor->epfd.

[0137] Step 304: spdk_thread creates a trans instance.

[0138] In one implementation, spdk_thread calls the trans module to create a trans instance.

[0139] Step 305: The trans module generates trans->fd corresponding to the trans instance.

[0140] For example, poll_group_xx calls the trans module to create a trans instance for host-side network transmission and generates trans->fd.

[0141] Step 306: spdk_thread registers trans->fd to the monitoring list of spdk_thread.

[0142] In this way, spdk_thread can monitor events on trans->fd.

[0143] Step 307: spdk_thread calls Bdev_Hbd to create a host block device hbd instance.

[0144] Step 308: Bdev_Hbd calls the BS module to create an objecter instance.

[0145] Specifically, the hbd instance calls the BS module to create an objecter instance.

[0146] Step 309: Bdev_Hbd receives the creation success notification returned by the BS module.

[0147] Step 310: Bdev_Hbd sets the interrupt mode and sends a file descriptor creation request to the BS module.

[0148] Step 311: Bdev_Hbd receives bs->fd returned by the BS module.

[0149] Step 312: The spdk_thread module registers bs->fd in the monitoring list of spdk_thread.

[0150] In this way, the file descriptor monitoring relationship between reactor->epfd, thread->epfd, trans->fd, and bs->fd can be established.

[0151] See Figure 4 The figure shows a schematic diagram of a monitoring relationship. Figure 4 In the process, first, the reactor creates reactor->epfd. Specifically, the reactor initializes its own epfd. epfd is the instance handle of the extensible input / output (I / O) event notification mechanism (epoll). It can be generated through system calls such as epoll_create and serves as a "container" for managing events.

[0152] Among them, epoll: is an efficient I / O multiplexing mechanism under Linux, and epoll_wait is used to block and wait for events (such as read-write readiness or interruption) to occur on the registered file descriptor (fd) to implement asynchronous I / O processing.

[0153] reactor->epfd->epoll_wait: reactor starts the epoll_wait (blocking function) loop, continuously blocking and waiting for events to be triggered. It is the "root driver" of the entire asynchronous process.

[0154] reactor->epfd->epoll_wait->thread->epfd: spdk_thread is the logical thread in SPDK, working with the reactor. It will also associate its own epfd and register it with the reactor's epfd. This means that the reactor's epoll_wait can listen to events on the spdk_thread's epfd, realizing event-driven collaboration across components.

[0155] thread->epfd->epoll_wait->trans->fd: spdk_thread's epfd will further manage finer-grained fd. For example, trans->fd can be understood as the file descriptor of the "transport layer", which is responsible for data interaction. Through epoll_wait, you can monitor the events of trans->fd.

[0156] trans->fd->epoll_wait->host->fd: trans->fd is associated with host->fd, which is the file descriptor on the host side. It may correspond to the device or communication resource for the host to interact with the storage, forming a hierarchical event listening chain.

[0157] thread->epfd->epoll_wait->bs->fd: spdk_thread's epfd also directly monitors bs->fd, which is the file descriptor of the backend storage. For example, the backend storage can be an interactive resource of devices such as a disk or SSD to respond to backend storage events.

[0158] In this embodiment, SPDK implements an interrupt flow from reactor, spdk_thread, trans, host, and BS, thus achieving a continuous interrupt flow throughout the entire process. For example, when the host sends an IO request or the backend storage returns an IO response, an event is ready on host->fd or bs->fd, and they wake up in sequence until the reactor->fd calls the callback function for processing.

[0159] The following combination Figure 5 For a description of interrupt event handling, see Figure 5 FIG. 1 is an interactive flow chart of a method for handling an interrupt event, wherein the method includes:

[0160] Step 501: The reactor blocks and waits to be awakened.

[0161] Step 502: The host sends a connection request to the trans module.

[0162] In one embodiment, the host sends a connection request to the TGT relying on the trans module to establish a Transmission Control Protocol (TCP) connection.

[0163] Step 503: The trans module senses that the host message event is ready through trans->fd.

[0164] Step 504: The reactor sends an event processing instruction to the spdk_thread module.

[0165] Specifically, after being awakened by the monitoring mechanism, the reactor sends event processing instructions to the spdk_thread module.

[0166] Step 505: The spdk_thread module performs processing operations based on the host message.

[0167] Specifically, the spdk_thread module performs processing operations based on the host-side message read from trans->fd.

[0168] Step 506: The spdk_thread module performs processing operations based on the backend storage side message.

[0169] Specifically, the spdk_thread module performs processing operations based on the backend storage side message read by bs->fd.

[0170] In this way, the entire processing completes a full-process interruption closed loop. When no business is delivered, all threads can be blocked, thereby reducing the CPU usage to 0.

[0171] In the embodiments of the present application, on the one hand, the ultimate energy-saving effect of zero CPU resource usage can be achieved. Specifically, by adding a back-end storage interrupt handle to the SPDK framework, a full-process interrupt mode is constructed, so that the system can reduce the CPU usage of the business thread to 0 in a no-business scenario. Specifically, when the back-end storage module provides an interrupt handle, SPDK can implement full-link interrupt drive from reactor, thread, trans to host, and all threads enter a blocked state when there is no business, completely avoiding the waste of CPU resources caused by the lack of an interrupt handle in the back-end storage in the traditional interrupt mode. This mechanism enables the storage system to maximize the release of CPU resources in low-load scenarios. Compared with the problem that the interrupt mode in related technologies cannot completely release resources, it can reduce a large amount of idle CPU consumption, and is especially suitable for scenarios with periodic business fluctuations such as cloud computing and distributed storage, providing core support for reducing cooling energy consumption and hardware costs for data centers.

[0172] Another invention achieves an intelligent balance between energy consumption and performance through dynamic adaptive mode switching. Specifically, by monitoring the business load in real time and automatically switching operating modes, a dynamic optimization mechanism is established. When the business load exceeds a first load threshold for multiple consecutive cycles, it automatically switches to polling mode. By eliminating interrupt latency and context switching overhead, it improves I / O throughput and meets the requirements of high-performance scenarios such as databases and real-time transactions. When the load falls below a second load threshold for multiple consecutive cycles, it switches to full interrupt mode, reducing CPU usage to zero and significantly reducing energy consumption. This adaptive switching uses the Scheduler module to accurately count the busy and idle time slices of reactor and spdk_thread, avoiding the lag and resource waste of traditional manual configuration modes and improving system resource utilization.

[0173] Furthermore, it also has the advantages of universality and scalability of technical architecture. First, the standardized transformation of the entire process interruption: through the unified access of the back-end interrupt handle, the SPDK framework can form a standardized interrupt processing link from heterogeneous storage devices to network protocols, which can be directly adapted to a variety of distributed storage systems without the need for customized development for different hardware or protocols. Secondly, the lightweight load perception is achieved: the single-cycle statistical overhead of the Scheduler module is small, which can meet the cluster deployment requirements of large-scale data centers. Furthermore, a flexible threshold adjustment mechanism is configured: the load threshold and switching cycle can be customized through the configuration file, which can support the differentiated needs of low-latency scenarios such as the financial industry and energy-saving scenarios such as edge computing, and can achieve the best effect in different industry scenarios.

[0174] Based on the same inventive concept, a mode switching device is also provided in the embodiment of the present application. Since the principle of solving the problem by the above-mentioned device and equipment is similar to a method of mode switching, the implementation of the above-mentioned device can refer to the implementation of the method, and the repeated parts will not be repeated. The device can be applied to electronic devices. This application does not limit the type of electronic device. It can be any type of device suitable for implementation, such as terminal devices and servers, etc. This application will not go into details. The device embodiment can be implemented by software, or by hardware or a combination of software and hardware. Taking software implementation as an example, as a device in a logical sense, it is formed by the processor of the electronic device in which it is located reading the corresponding computer program instructions in the non-volatile memory into the memory for execution.

[0175] See Figure 6 FIG. 1 is a block diagram of a mode switching device according to an embodiment of the present application. In some embodiments, the mode switching device according to the present application includes:

[0176] A determination unit 601 is configured to determine the load of each reactor in each cycle according to the busy duration of each reactor in each cycle;

[0177] The first switching unit 602 is configured to, when the current operating mode is the interrupt mode, detect for each reactor whether the load of the reactor in the most recent consecutive M1 cycles meets a set overload condition, and determine whether to switch the current operating mode from the interrupt mode to the polling mode based on the overload detection result of at least one reactor; wherein M1 is a positive integer; the polling mode is used to instruct the reactor to perform operations based on the polling mechanism. In the interrupt mode, the reactor is awakened to perform event processing operations when it detects any file descriptor event is ready; the file descriptor event includes the backend storage file descriptor bs->fd created based on the backend storage module;

[0178] The second switching unit 603 is used to detect, for each reactor, whether the load of the reactor in the most recent consecutive M2 cycles meets the set idle condition when the current operating mode is the polling mode, and determine whether to switch the current operating mode from the polling mode to the interrupt mode based on the idle detection result of at least one reactor; M2 is a positive integer.

[0179] In one embodiment, the overload condition is set as follows: the load in a single cycle exceeds a first load threshold;

[0180] The idle condition is set as: the load in a single cycle is lower than the second load threshold.

[0181] In one implementation, the first switching unit 602 is configured to:

[0182] Filter out the overloaded reactor from at least one reactor; the load of the overloaded reactor in the most recent M1 consecutive cycles meets the set overload condition;

[0183] If the number of overloaded reactors is not less than a first threshold, the current working mode is switched from the interrupt mode to the polling mode.

[0184] In one implementation, the second switching unit 603 is configured to:

[0185] Select an idle reactor from at least one reactor; the load of the idle reactor in the last M1 consecutive cycles meets the set idle condition;

[0186] If the number of idle reactors is not less than the second number threshold, the current working mode is switched from the polling mode to the interrupt mode.

[0187] In one embodiment, the SPDK creates a corresponding task file descriptor reactor->epfd for each reactor; the first switching unit 602 is further configured to:

[0188] When the current working mode is interrupt mode, the following event loop is executed for each reactor:

[0189] The reactor calls the blocking function to block the corresponding reactor->epfd until any file descriptor event monitored by the reactor->epfd is ready;

[0190] When any file descriptor event monitored by reactor->epfd is ready, wake up the reactor;

[0191] The reactor calls the corresponding callback function to perform event processing operations.

[0192] In one implementation, the file descriptor further includes a thread file descriptor thread->epfd; and the first switching unit 602 is further configured to:

[0193] For each reactor, perform the following steps:

[0194] Create the thread spdk_thread through the reactor;

[0195] Create the corresponding reactor->epfd for the reactor;

[0196] Create corresponding thread->epfd for spdk_thread;

[0197] Register thread->epfd to the monitoring list of reactor->epfd so that reactor can monitor the events of spdk_thread.

[0198] In one embodiment, the file descriptor further includes a transmission file descriptor trans->fd; and the first switching unit 602 is further configured to:

[0199] Through spdk_thread, create a transmission trans instance and generate the corresponding trans->fd;

[0200] Register trans->fd to the listening list of spdk_thread so that spdk_thread can listen to the events of the trans instance.

[0201] In one embodiment, before calling the blocking function to block and monitor the corresponding reactor->epfd through the reactor, the first switching unit 602 is further configured to:

[0202] Create a host block device hbd instance through spdk_thread;

[0203] Based on the hbd instance, create an object manager objecter instance and generate the corresponding bs->fd;

[0204] Register bs->fd to the listening list of spdk_thread so that spdk_thread can listen to the events of the objecter instance.

[0205] The mode switching method in an embodiment of the present application includes determining the load of each reactor in each cycle based on the busy duration of each reactor in each cycle; when the current working mode is interrupt mode, detecting whether the load of each reactor in the most recent M1 consecutive cycles meets the set overload condition, and determining whether to switch the current working mode from interrupt mode to polling mode based on the overload detection result of at least one reactor; wherein M1 is a positive integer; the polling mode is used to instruct the reactor to perform operations based on the polling mechanism. In interrupt mode, the reactor is awakened to perform event processing operations when it listens to any file descriptor event ready; the file descriptor event includes the backend storage file descriptor bs->fd created based on the backend storage module; when the current operating mode is polling mode, detecting whether the load of each reactor in the most recent M2 consecutive cycles meets the set idle condition, and determining whether to switch the current working mode from polling mode to interrupt mode based on the idle detection result of at least one reactor; M2 is a positive integer. In this way, the working mode can be automatically switched according to the business load, taking into account both energy consumption optimization and performance improvement.

[0206] In an embodiment of the present application, an electronic device is further provided, including:

[0207] processor; and

[0208] The memory stores computer instructions, where the computer instructions are used to enable the processor to execute the method of any of the above embodiments.

[0209] In an embodiment of the present application, a computer-readable storage medium is provided, which stores computer instructions, and the computer instructions are used to enable a computer to execute the method of any of the above-mentioned embodiments.

[0210] An embodiment of the present application also provides a computer program product, including computer-readable code, or a non-volatile computer-readable storage medium carrying computer-readable code. When the computer-readable code runs in a processor of an electronic device, the processor in the electronic device implements any of the above-mentioned methods.

[0211] Figure 7 FIG. 7 shows a schematic structural diagram of an electronic device 7000. Figure 7 As shown, the electronic device 7000 includes: a processor 7010 and a memory 7020, and optionally, may also include a power supply 7030, a display unit 7040, and an input unit 7050.

[0212] The processor 7010 is the control center of the electronic device 7000. It uses various interfaces and lines to connect various components, and performs various functions of the electronic device 7000 by running or executing software programs and / or data stored in the memory 7020, thereby monitoring the electronic device 7000 as a whole.

[0213] In the embodiment of the present application, the processor 7010 executes the various steps in the above embodiment when calling the computer program stored in the memory 7020.

[0214] Optionally, the processor 7010 may include one or more processing units. Preferably, the processor 7010 may integrate an application processor and a modem processor, wherein the application processor primarily processes the operating system, user interface, and applications, and the modem processor primarily processes wireless communications. It is understood that the modem processor may not be integrated into the processor 7010. In some embodiments, the processor and memory may be implemented on a single chip. In some embodiments, they may also be implemented on separate chips.

[0215] The memory 7020 may mainly include a program storage area and a data storage area. The program storage area may store an operating system, various applications, etc., and the data storage area may store data created based on the use of the electronic device 7000. In addition, the memory 7020 may include a high-speed random access memory and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other volatile solid-state storage device.

[0216] The electronic device 7000 also includes a power supply 7030 (such as a battery) for supplying power to various components. The power supply can be logically connected to the processor 7010 through a power management system, thereby managing functions such as charging, discharging, and power consumption through the power management system.

[0217] The display unit 7040 can be used to display information input by the user or information provided to the user, as well as various menus of the electronic device 7000. In the embodiment of the present application, it is mainly used to display the display interface of each application in the electronic device 7000 and objects such as text and pictures displayed on the display interface. The display unit 7040 may include a display panel 7041. The display panel 7041 can be configured in the form of a liquid crystal display (LCD), an organic light-emitting diode (OLED), etc.

[0218] The input unit 7050 can be used to receive information such as numbers or characters input by the user. The input unit 7050 may include a touch panel 7051 and other input devices 7052. The touch panel 7051, also known as a touch screen, can receive user touch operations on or near it (for example, operations performed by the user using a finger, a stylus, or any other suitable object or accessory on or near the touch panel 7051).

[0219] Specifically, the touch panel 7051 can detect user touch operations and the signals generated by the touch operations, convert these signals into touch point coordinates, and send them to the processor 7010. It can also receive and execute commands sent by the processor 7010. In addition, the touch panel 7051 can be implemented using various types, such as resistive, capacitive, infrared, and surface acoustic wave. Other input devices 7052 can include, but are not limited to, one or more of a physical keyboard, function keys (such as volume control buttons, power buttons, etc.), a trackball, a mouse, a joystick, etc.

[0220] Of course, the touch panel 7051 can cover the display panel 7041. When the touch panel 7051 detects a touch operation on or near it, it transmits it to the processor 7010 to determine the type of touch event. Then the processor 7010 provides corresponding visual output on the display panel 7041 according to the type of touch event. Figure 7 In the embodiment, the touch panel 7051 and the display panel 7041 are two independent components to realize the input and output functions of the electronic device 7000, but in some embodiments, the touch panel 7051 and the display panel 7041 can be integrated to realize the input and output functions of the electronic device 7000.

[0221] The electronic device 7000 may also include one or more sensors, such as a pressure sensor, a gravity acceleration sensor, a proximity light sensor, etc. Of course, according to the needs of specific applications, the electronic device 7000 may also include other components such as a camera. Since these components are not the key components used in the embodiments of this application, Figure 7 It is not shown and will not be described in detail.

[0222] Those skilled in the art will understand that Figure 7 The electronic device is merely an example and does not limit the electronic device. The electronic device may include more or fewer components than shown in the figure, or may include a combination of certain components or different components.

[0223] For the convenience of description, the above parts are divided into modules (or units) according to their functions and described separately. Of course, when implementing this application, the functions of each module (or unit) can be implemented in the same or multiple software or hardware.

Claims

1. A mode switching method, characterized in that: The method is applied to an electronic device using a storage development toolkit (SPDK) framework. The SPDK creates at least one task execution unit (reactor) and creates a backend storage file descriptor (bs->fd) based on a backend storage module. The method includes: Determine the load of each reactor in each cycle based on the busy time of each reactor in each cycle; When the current operating mode is interrupt mode, each reactor is tested for its load in the most recent M1 cycles to see if it meets the set overload condition, and a determination is made based on the overload detection result of at least one reactor whether to switch the current operating mode from the interrupt mode to the polling mode; wherein M1 is a positive integer; the polling mode is used to instruct the reactor to perform operations based on the polling mechanism, and in the interrupt mode, the reactor is awakened to perform event processing operations when it detects any file descriptor event is ready; the file descriptor event includes the backend storage file descriptor bs->fd created based on the backend storage module; When the current operating mode is the polling mode, for each reactor, the load of the reactor in the most recent consecutive M2 cycles is detected to see whether it meets the set idle condition, and based on the idle detection result of the at least one reactor, it is determined whether to switch the current operating mode from the polling mode to the interrupt mode; M2 is a positive integer.

2. The method according to claim 1, characterized in that The set overload condition is: the load in a single cycle exceeds a first load threshold; The set idle condition is: the load in a single cycle is lower than a second load threshold.

3. The method according to claim 1 or 2, characterized in that The determining, based on the overload detection result of at least one reactor, whether to switch the current working mode from the interrupt mode to the polling mode includes: An overloaded reactor is selected from the at least one reactor; the load of the overloaded reactor in the most recent M1 consecutive cycles all meets the set overload condition; If the number of the overloaded reactors is not less than a first number threshold, the current working mode is switched from the interrupt mode to the polling mode.

4. The method according to claim 1 or 2, characterized in that The determining, according to the idle detection result of the at least one reactor, whether to switch the current working mode from the polling mode to the interrupt mode includes: Selecting an idle reactor from the at least one reactor; wherein the load of the idle reactor in the most recent M1 consecutive cycles meets the set idle condition; If the number of the idle reactors is not less than a second number threshold, the current working mode is switched from the polling mode to the interrupt mode.

5. The method according to claim 1 or 2, characterized in that The SPDK creates a corresponding task file descriptor reactor->epfd for each reactor; the method further includes: When the current working mode is the interrupt mode, the following event loop is executed for each reactor: The reactor calls the blocking function to block the corresponding reactor->epfd until any file descriptor event monitored by the reactor->epfd is ready; When any file descriptor event monitored by reactor->epfd is ready, wake up the reactor; The reactor calls the corresponding callback function to perform event processing operations.

6. The method according to claim 5, characterized in that The file descriptor also includes a thread file descriptor thread->epfd; Before calling the blocking function by the reactor to block and monitor the corresponding reactor->epfd, the method further includes: For each reactor, perform the following steps: Create the thread spdk_thread through the reactor; Create the corresponding reactor->epfd for the reactor; Create a corresponding thread->epfd for the spdk_thread; Register the thread->epfd to the monitoring list of the reactor->epfd so that the reactor monitors the events of the spdk_thread.

7. The method according to claim 6, characterized in that The file descriptor also includes a transmission file descriptor trans->fd; Before calling the blocking function by the reactor to block and monitor the corresponding reactor->epfd, the method further includes: Through the spdk_thread, create a transmission trans instance and generate the corresponding trans->fd; Register the trans->fd to the monitoring list of the spdk_thread so that the spdk_thread monitors the events of the trans instance.

8. The method according to claim 6, characterized in that Before calling the blocking function by the reactor to block and monitor the corresponding reactor->epfd, the method further includes: Create a host block device hbd instance through the spdk_thread; Based on the hbd instance, create an object manager objecter instance and generate the corresponding bs->fd; Register the bs->fd to the monitoring list of the spdk_thread, so that the spdk_thread monitors the events of the objecter instance.

9. A mode switching device, characterized in that: The device is applied to an electronic device using a storage development toolkit (SPDK) framework. The SPDK creates at least one task execution unit (reactor) and creates a backend storage file descriptor (bs->fd) based on a backend storage module. The device includes: A determination unit, configured to determine the load of each reactor in each cycle according to the busy duration of each reactor in each cycle; a first switching unit configured to, when the current operating mode is the interrupt mode, detect, for each reactor, whether the load of the reactor in the most recent consecutive M1 cycles meets a set overload condition, and determine, based on the overload detection result of at least one reactor, whether to switch the current operating mode from the interrupt mode to the polling mode; wherein M1 is a positive integer; the polling mode is used to instruct the reactor to perform operations based on the polling mechanism, and in the interrupt mode, the reactor is awakened to perform event processing operations when it detects that any file descriptor event is ready; the file descriptor event includes a backend storage file descriptor bs->fd created based on the backend storage module; The second switching unit is configured to detect, for each reactor, whether the load of the reactor in the most recent consecutive M2 cycles meets the set idle condition when the current operating mode is the polling mode, and determine whether to switch the current operating mode from the polling mode to the interrupt mode based on the idle detection result of the at least one reactor; M2 is a positive integer.

10. An electronic device, characterized in that: include: processor; as well as A memory storing computer instructions, wherein the computer instructions are used to enable the processor to execute the method according to any one of claims 1 to 8.