Linux printer driving method and system of cross-CPU architecture based on virtual machine
By utilizing qemu virtual machines and redirection technology in a virtual machine environment, Linux printer driver adaptation and dynamic resource adjustment across CPU architectures are achieved, which solves the problem that domestic computers are difficult to adapt to x86 printer drivers, and improves installation success rate and resource utilization rate.
Patent Information
- Application Number
- CN202510444493.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-10
- Publication Date
- 2025-05-09
- Estimated Expiration
- 2045-04-10
AI Technical Summary
Domestic computers are based on non-x86 architectures and are difficult to adapt to printer drivers that rely on x86 architectures. Different Linux distributions and kernel versions have large differences in the printer driver support, resulting in installation failure. It is difficult for virtual machine environments to dynamically adjust resources, resulting in waste of resources.
Design a Linux printer driver method based on virtual machines across CPU architecture, use the qemu virtual machine to start the minimum Linux environment of the x86 system architecture, and use the USB redirection technology and IP port redirection technology to identify, capture and install the printer driver, and dynamically adjust the virtual machine resources to match the load of the printing task.
The printer driver adaptation across CPU architecture is realized, which improves the driver matching accuracy and installation success rate, and dynamic resource adjustments improve resource utilization and reduces the single point of failure rate.
Smart Images

Figure CN119960920A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of printing adaptation, and in particular to a Linux printer driving method and system based on a cross-CPU architecture of a virtual machine. Background Art
[0002] As the country continues to attach importance to independent control, domestic computers and operating systems are increasingly being used in daily office work. These domestic controllable computers are often implemented based on non-x86 architectures such as LoongArch, ARM, RISV, and MIPS. The printer driver that relies on CUPS under Linux often requires kernel support, which makes domestic computers often unable to fully adapt to printer drivers that rely on the x86 architecture. In addition, different Linux distributions or kernel versions have different support for printer drivers. Manual installation is prone to failure due to missing dependencies, configuration errors, or hardware compatibility issues. Virtual machine environments usually use static resource allocation, which makes it difficult to dynamically adjust resources according to printing tasks, resulting in a huge waste of office resources. Summary of the invention
[0003] The purpose of the present invention is to solve the above problems and to design a Linux printer driver method and system based on a cross-CPU architecture of a virtual machine.
[0004] To achieve the above object, the technical solution of the present invention is that, further, in the above-mentioned Linux printer driver method based on a cross-CPU architecture of a virtual machine, the Linux printer driver method comprises the following steps: Use the qemu virtual machine to start at least one minimum Linux environment based on the x86 system architecture to obtain the initial Linux environment; Based on the qemu virtual machine identifying and capturing the Linux printer device located at the USB port, a first printer driver is obtained; Redirect the first printer driver by using USB redirection technology to obtain a second printer driver; Map the CUPS service port of the initial Linux environment using the IP port redirection technology to obtain the target Linux environment; Install the second printer driver on the CUPS service port based on the target Linux environment to obtain a target printer driver; Acquire the content to be printed, and execute a printing instruction on the content to be printed based on the target printer driver.
[0005] Furthermore, in the above Linux printer driver method, the step of using the qemu virtual machine to start at least one minimum Linux environment based on the x86 system architecture includes: Establish an automated image selection algorithm and define evaluation metrics for the algorithm, including resource requirement fit , Performance Rating , Compatibility Score and historical usage ratings ; Obtain the number of CPU cores, memory, and storage available to the user; obtain the number of CPU cores, memory, and storage required for the image, and calculate the resource requirement fit using the resource requirement fit calculation formula ; Based on the image's performance in terms of CPU performance, memory performance, and storage performance, the performance is scored using the performance scoring calculation formula Perform calculations; Compatibility score based on how well the image works with the target system's hardware and software Conduct assessments; Based on historical usage data and user feedback, rate the image for stability and ease of use Score the image and select the image with the highest overall score as the minimum Linux image.
[0006] Furthermore, in the above Linux printer driver method, the step of using the qemu virtual machine to start at least one minimum Linux environment based on the x86 system architecture further includes: Establish a dynamic resource allocation model, and use the dynamic resource allocation model to dynamically allocate resources of the qemu virtual machine according to the estimated load of the printing task; Define task load indicators, which at least include file size and printing complexity , the printing complexity This includes at least the graphics, colors, and layout of the document; Assuming that there is a linear relationship between CPU resource requirements, memory resource requirements, and storage resource requirements and file size and printing complexity, the number of CPU cores, memory size, and storage capacity of the qemu virtual machine are dynamically adjusted based on the output of the dynamic resource allocation model.
[0007] Further, in the above Linux printer driver method, the step of identifying and capturing the Linux printer device located at the USB port based on the qemu virtual machine to obtain the first printer driver includes: Acquire raw data of a Linux printer device from a USB port, the raw data including at least device hardware information and device description information, perform feature extraction on the raw data, and convert it into feature vector data; Matching the feature vector data using a preset pattern library, calculating the Euclidean distance between the feature vector and the pattern for each pattern in the pattern library, selecting the printer model and manufacturer corresponding to the pattern with the smallest Euclidean distance as the recognition result, and obtaining the printer model and manufacturer; After the printer device is identified, its feature vector is input into the trained MLP multi-layer perceptron neural network, the predicted driver probability distribution is output, and the driver label with the highest probability is selected as the first printer driver.
[0008] Furthermore, in the above Linux printer driver method, redirecting the first printer driver by using the USB redirection technology to obtain the second printer driver includes: Establish a driver optimization algorithm to monitor the performance indicators of the first printer driver in real time, including data transmission rate and response time ; Set the data transfer rate and response time Threshold and ,when < When , it means that there is a bottleneck in the data transmission rate. Greater than When indicates a long response time; Set the current buffer size to , the adjustment coefficient is ,like >1 is used to increase the buffer, if 0 < <1 is used to reduce the buffer size. The buffer size is adjusted according to the change of data transmission rate. The adjusted buffer size ; Use interrupt priority sorting to prioritize interrupts with high response time requirements. Suppose the interrupt processing time before optimization is , the optimized interrupt processing time is , optimization effect is calculated by optimization rate measure, ; The driver code is optimized according to the adjusted buffer and interrupt processing time, and the optimized driver code is used for redirection to obtain a second printer driver.
[0009] Furthermore, in the above Linux printer driver method, the use of the IP port redirection technology to map the CUPS service port of the initial Linux environment to obtain the target Linux environment includes: Obtain historical network traffic data and characteristic information of the current print task, the characteristic information at least including the file size , Print number of copies and print format complexity , preprocess the historical traffic data and characteristic information to obtain the initial network traffic data; Extract the feature vector in the initial network traffic data to obtain feature network traffic data, and input the feature network traffic data into the ARIMR model for training. The calculation formula of the ARIMR model is: ; in, is an autoregressive polynomial, is the moving average polynomial, is the lag operator, is the difference order, is a white noise sequence; After training, get the future time Traffic forecast value within , according to the traffic prediction value Adjust the port mapping policy, which includes setting different traffic thresholds and flow threshold ,in < ,when < When , reduce the number of mapped ports, when > When , increase the number of mapped ports; The CUPS service port of the initial Linux environment is mapped according to the port mapping strategy to obtain a target Linux environment.
[0010] Further, in the above Linux printer driver method, the step of installing the second printer driver on the CUPS service port based on the target Linux environment to obtain the target printer driver includes: Acquire characteristic information of the second printer driver, the characteristic information at least including the driver version , minimum operating system version , Software Package List , storage path of driver files ; Get the configuration information of the target Linux environment, including the operating system version , Software Package List , System configuration file path ; Check whether the operating system version of the target Linux environment meets the minimum requirements of the driver. < , then terminate the script generation process; compare the list of dependent packages required by the driver And the list of packages installed on the system , get the dependencies installed ,in ; According to the characteristic information of the second printer driver and the configuration information of the target Linux environment, the installation steps are planned, and an installation script is combined based on the execution order of the installation steps to obtain the target printer driver.
[0011] Furthermore, in a Linux printer driver system based on a cross-CPU architecture of a virtual machine, the Linux printer driver system includes the following modules: The initial environment startup module is used to use the qemu virtual machine to start at least one minimum Linux environment based on the x86 system architecture to obtain the initial Linux environment; A first driver calculation module is used to identify and capture a Linux printer device located at a USB port based on the qemu virtual machine to obtain a first printer driver; A second driver calculation module, used for redirecting the first printer driver through USB redirection technology to obtain a second printer driver; A target environment acquisition module is used to map the CUPS service port of the initial Linux environment by using the IP port redirection technology to obtain a target Linux environment; A target driver obtaining module, used for installing the second printer driver on the CUPS service port based on the target Linux environment to obtain the target printer driver; The printing command execution module is used to obtain the content to be printed and execute the printing instruction on the content to be printed based on the target printer driver.
[0012] Furthermore, in the above-mentioned Linux printer driver system based on a virtual machine and a cross-CPU architecture, the initial environment startup module includes the following units: Evaluation indicator definition unit, used to establish an automated image selection algorithm and define the evaluation indicators of the algorithm, including resource demand fit , Performance Rating , Compatibility Score and historical usage ratings ; The resource requirement calculation unit is used to obtain the number of CPU cores, memory and storage available to the user; obtain the number of CPU cores, memory and storage required for the image, and calculate the resource requirement fit through the resource requirement fit calculation formula ; A performance score calculation unit is used to score the performance of the image based on the CPU performance, memory performance and storage performance using a performance score calculation formula. Perform calculations; A compatibility evaluation unit, used to score the compatibility of the image based on its compatibility with the hardware and software of the target system Conduct assessments; A Linux image selection unit, which is used to rate the image for stability and ease of use based on historical usage data and user feedback Score the image and select the image with the highest overall score as the minimum Linux image.
[0013] Furthermore, in the above-mentioned Linux printer driver system based on a virtual machine and a cross-CPU architecture, the initial environment startup module further includes the following units: A dynamic allocation unit, used to establish a dynamic resource allocation model, and use the dynamic resource allocation model to dynamically allocate resources of the qemu virtual machine according to the estimated load of the printing task; A load indicator unit is used to define a task load indicator, wherein the task load indicator includes at least the file size. and printing complexity , the printing complexity This includes at least the graphics, colors, and layout of the document; The dynamic adjustment unit is used to dynamically adjust the number of CPU cores, memory size and storage capacity of the qemu virtual machine based on the output of the dynamic resource allocation model, assuming that there is a linear relationship between the CPU resource demand, memory resource demand and storage resource demand and the file size and printing complexity.
[0014] Its beneficial effects are: 1. Based on the file size, complexity and other characteristics of the printing task, dynamically adjust the virtual machine resources (CPU, memory, storage), improve resource utilization, and avoid resource waste. Select the optimal Linux image through a multi-dimensional scoring mechanism (compatibility, performance, historical stability) to improve the success rate of image adaptation. 2. Predict the best driver based on device characteristics (device ID, manufacturer information), improve the accuracy of driver matching, and reduce installation failures caused by driver errors. Predict the compatibility of the driver and the target environment in advance, improve the recognition rate of compatibility problems, and automatically generate solutions. 3. Combine historical traffic with real-time task characteristics to predict the peak traffic of the CUPS port, dynamically adjust the port mapping strategy, and improve network bandwidth utilization. Distribute printing tasks according to the server CPU, memory and bandwidth load to reduce the single point failure rate. 4. Generate accurate installation scripts based on driver characteristics and environment configuration, and the success rate of automatic installation and configuration modification of dependencies exceeds 90%, reducing manual intervention. 5. Cross-platform and scalability: supports multiple Linux distributions (Ubuntu, CentOS, etc.) and x86 architecture virtual machine environments, is compatible with USB2.0 / 3.0 printer devices, and can be expanded to multi-task parallel processing scenarios. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] Various other advantages and benefits will become apparent to those of ordinary skill in the art by reading the following detailed description of the preferred embodiment.The drawings are only for the purpose of illustrating the preferred embodiments and are not to be construed as limiting the invention.
[0016] Figure 1 This is a schematic diagram of a first embodiment of a Linux printer driver method based on a cross-CPU architecture of a virtual machine in an embodiment of the present invention; Figure 2 A schematic diagram of a second embodiment of a Linux printer driver method based on a cross-CPU architecture of a virtual machine in an embodiment of the present invention; Figure 3 A schematic diagram of a third embodiment of a Linux printer driver method based on a cross-CPU architecture of a virtual machine in an embodiment of the present invention; Figure 4 This is a schematic diagram of a first embodiment of a Linux printer driver system based on a cross-CPU architecture of a virtual machine in an embodiment of the present invention. DETAILED DESCRIPTION
[0017] In order to make the purpose, technical solution and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention.
[0018] Those skilled in the art will appreciate that, unless otherwise stated, the singular forms "a", "an", "the" used herein may also include plural forms. It should be further understood that the term "comprising" used in the specification of the present invention refers to the presence of the features, integers, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or groups thereof.
[0019] The present invention will be described in detail below in conjunction with the accompanying drawings. Figure 1 As shown, a Linux printer driver method based on a cross-CPU architecture of a virtual machine, the Linux printer driver method comprises the following steps: Step 101: Use the qemu virtual machine to start at least one minimum Linux environment based on the x86 system architecture to obtain an initial Linux environment; Specifically, in this embodiment, Establish an automated image selection algorithm and define evaluation indicators for the algorithm, including resource demand fit , Performance Rating , Compatibility Score and historical usage ratings ; Among them, resource demand fit Used to measure the degree of match between the resources required by the image and the resources available to the user. Performance score Used to reflect the performance of the image under different performance indicators. Compatibility score Used to evaluate the compatibility of the image with the target system and application. Used to rate images based on historical usage data and user feedback.
[0020] Get the number of CPU cores, memory, and storage available to the user; get the number of CPU cores, memory, and storage required by the image, and calculate the resource requirement fit using the resource requirement fit calculation formula , and its calculation formula is as follows: ; in, Indicates the number of CPU cores available to the user. Indicates the number of CPU cores required for the image. Indicates user available memory. Indicates the memory required for the image. Indicates the user's available storage. Indicates the storage required for the image; , and is the weight coefficient, and .
[0021] Based on the image's performance in terms of CPU performance, memory performance, and storage performance, the performance is scored using the performance scoring formula The calculation formula is as follows: ; in, Indicates the CPU performance of the image. Indicates the memory performance of the image. Indicates the storage performance of the image. , and is the weight coefficient, and .
[0022] Compatibility scoring based on how well the image is compatible with the target system's hardware and software To evaluate, the calculation formula is as follows: ; in, Indicates the hardware compatibility score, Indicates the software compatibility score, is the weight coefficient.
[0023] Based on historical usage data and user feedback, historical usage scores are given for image stability and ease of use. Score the image and select the image with the highest overall score as the minimum Linux image.
[0024] Establish a dynamic resource allocation model, and use it to dynamically allocate the resources of the qemu virtual machine according to the estimated load of the printing task; Define task load indicators, which at least include file size and printing complexity , printing complexity At least the graphics, colors and layout of the file are included to quantify the printing complexity; file size Indicates the size of the print file in bytes. Assuming that there is a linear relationship between the CPU resource requirements, memory resource requirements, and storage resource requirements and the file size and printing complexity, the calculation formula of the dynamic resource allocation model is as follows: ; ; ; in, , , , , , , , , Represents model parameters, which are obtained through training of machine learning algorithms. Indicates CPU resource requirements, Indicates memory resource requirements, Indicates storage resource requirements.
[0025] Based on the output of the dynamic resource allocation model, the number of CPU cores, memory size, and storage capacity of the qemu virtual machine are dynamically adjusted. The adjusted resource allocation is as follows: ; ; ; in, Indicates the adjusted CPU resource requirements. Indicates the adjusted memory resource requirements, represents the adjusted storage resource requirements, Express Round up.
[0026] Step 102: Based on the qemu virtual machine, identify and capture the Linux printer device located at the USB port to obtain a first printer driver; Specifically, in this embodiment, The original data of the Linux printer device is obtained from the USB port. The original data includes at least the device hardware information and device description information. The original data is feature extracted and converted into feature vector data. The calculation formula of the feature vector is as follows: ; in, Represents one-hot encoding, mapping raw data into numerical features; Indicates the device ID. Indicates the manufacturer ID. Indicates the device category. Indicates the device subcategory, Indicates a protocol.
[0027] Match the feature vector data using a preset pattern library, calculate the Euclidean distance between the feature vector and the pattern for each pattern in the pattern library, select the printer model and manufacturer corresponding to the pattern with the smallest Euclidean distance as the recognition result, and obtain the printer model and manufacturer; After the printer device is identified, its feature vector is input into the trained MLP multi-layer perceptron neural network, the predicted driver probability distribution is output, and the driver label with the highest probability is selected as the first printer driver.
[0028] Get the printer model, manufacturer information and corresponding driver information in the database to build a training data set ;in is the input vector containing features such as printer model and manufacturer, is the corresponding driver tag; Construct a multi-layer perceptron MLP neural network, which includes an input layer, a hidden layer, and an output layer. The number of neurons in the input layer is equal to the input vector The dimension of the output layer is equal to the number of driving label categories. The weight matrix of the hidden layer is , the bias vector is .
[0029] For the input vector , calculate the output result through forward propagation. The input of the layer is , the output is , the activation function is (such as RELU activation function ), then: ; ; in, , the output of the final output layer This is the predicted driving probability distribution.
[0030] Define the loss function ,in, is the actual driver label (one-hot encoded), is the predicted driving probability distribution, is the number of driver label categories. Use an optimization algorithm (stochastic gradient descent SGD) to minimize the loss function and update the weights and biases of the neural network. After identifying the printer device, input its feature vector into the trained neural network and output the predicted driver probability distribution. Select the driver label with the highest probability as the most suitable first printer driver.
[0031] Step 103: redirect the first printer driver through the USB redirection technology to obtain a second printer driver; Specifically, in this embodiment, Establish a driver optimization algorithm to monitor the performance indicators of the first printer driver in real time, including data transmission rate and response time ; Data transfer rate Through a period of time Amount of data transferred within Calculate, the calculation formula is: ; Response time It is the time interval from sending a request to receiving a response. A more accurate result can be obtained by taking the average value through multiple measurements. The calculation formula is: ; in, It is The response time of the measurement, is the number of measurements.
[0032] Set the data transfer rate and response time Threshold and ,when < When , it means that there is a bottleneck in the data transmission rate. Greater than When indicates a long response time; Buffer size adjustment: The buffer size has an important impact on the data transmission rate. Dynamically adjust the buffer size according to the change of data transmission rate. When the data transmission rate is low, increase the buffer size appropriately to reduce the number of data transmissions. Suppose the current buffer size is , the adjustment coefficient is ,like >1 is used to increase the buffer, if 0 < <1 is used to reduce the buffer size. The buffer size is adjusted according to the change of data transmission rate. The adjusted buffer size ; Interrupt processing time affects response time. By optimizing interrupt processing code, interrupt processing time can be reduced. Interrupt priority sorting is used to prioritize interrupts with high response time requirements. Interrupt priority sorting is used to prioritize interrupts with high response time requirements. Suppose the interrupt processing time before optimization is , the optimized interrupt processing time is , optimization effect is calculated by optimization rate measure, ; The driver code is optimized according to the adjusted buffer and interrupt processing time, and the optimized driver code is used for redirection to obtain a second printer driver.
[0033] Step 104, using the IP port redirection technology to map the CUPS service port of the initial Linux environment to obtain the target Linux environment; Specifically, in this embodiment, Obtain historical network traffic data and characteristic information of the current printing task, including historical network traffic data, covering traffic values in different time periods (such as hourly and daily) ,in Represents a time point. At the same time, collect the characteristic information of the current print task, which at least includes the file size , Print number of copies and print format complexity .
[0034] Preprocess historical traffic data and characteristic information, remove outliers, and calculate the mean using statistical methods and standard deviation will deviate from the mean by more than times standard deviation ( The data points are considered as outliers and removed, and the mean calculation formula is: ; The formula for calculating standard deviation is: ; in, is the number of historical data points. After the above calculation, the initial network traffic data is obtained.
[0035] Extract the feature vector from the initial network traffic data to obtain the feature network traffic data, and input the feature network traffic data into the ARIMR model for training. The calculation formula of the ARIMR model is: ; in, is an autoregressive polynomial, is the moving average polynomial, is the lag operator, is the difference order, is a white noise sequence; After training, get the future time Traffic forecast value within , according to the traffic prediction value Adjust the port mapping policy, which includes setting different traffic thresholds and flow threshold ,in < ,when < When , reduce the number of mapped ports, when > When , increase the number of mapped ports; Map the CUPS service port of the initial Linux environment according to the port mapping strategy to obtain the target Linux environment.
[0036] Step 105: Install a second printer driver on the CUPS service port based on the target Linux environment to obtain a target printer driver; Specifically, in this embodiment, Obtain the characteristic information of the second printer driver, the characteristic information at least includes the driver version , minimum operating system version , Software Package List , storage path of driver files ; Get the configuration information of the target Linux environment, including the operating system version , Software Package List , System configuration file path ; Check whether the operating system version of the target Linux environment meets the minimum requirements of the driver. < , then terminate the script generation process; compare the list of dependent packages required by the driver And the list of packages installed on the system , get the dependencies installed ,in ; According to the characteristic information of the second printer driver and the configuration information of the target Linux environment, plan the installation steps. The installation steps generally include: Dependency Installation: For dependencies that are not installed , generate the corresponding installation command. If you are using a Debian or Ubuntu-based system, the installation command is: apt-getinstall <package>; If you are using a system based on RedHat or CentOS, the installation command may be: yuminstall <package>.
[0037] Driver file copy: copy the driver file from the storage path Copy to the driver installation directory specified by the system , the copy command is cp<Path_d><Path_{install}> .
[0038] Driver configuration: Modify the system configuration file according to the driver's requirements. For example, add driver-related parameters to the configuration file. Suppose there is a parameter item in the configuration file Need to be set to , then modify the command to: sed -i 's / ^#\?Param.* / Param= <value> / g'<Path_{conf}> .
[0039] An installation script is formed based on the execution order of the installation steps to obtain the target printer driver.
[0040] When the installation script starts to execute, the start time is recorded, and when the installation script ends, the end time is recorded, and the system's CPU utilization, memory utilization and other resource usage are monitored in real time. You can use system commands to set the threshold of installation time and resource usage, and judge the installation abnormality based on the threshold. When an abnormality occurs, the system will promptly feedback the abnormal information, such as informing the user through log records, system prompts, etc. If the installation time is too long, you can try to retry the installation, that is, re-execute the installation script; or adjust the installation parameters, such as increasing system resources. If the resource usage is too high, you can pause the installation task, release some system resources, and then continue the installation.
[0041] Step 106: Obtain the content to be printed, and execute a print instruction on the content to be printed based on the target printer driver.
[0042] Specifically, in this embodiment, when there are multiple printing tasks, a printing task priority scheduling algorithm is used. The algorithm assigns a priority to each task based on factors such as the urgency, importance, and file size of the task. Then, the printing instructions are executed in order of priority to ensure that important tasks are processed first.
[0043] Its beneficial effects are: 1. Based on the file size, complexity and other characteristics of the printing task, dynamically adjust the virtual machine resources (CPU, memory, storage), improve resource utilization, and avoid resource waste. The optimal Linux image is selected through a multi-dimensional scoring mechanism (compatibility, performance, historical stability), and the image adaptation success rate is increased by 40%. 2. Predict the best driver based on device characteristics (device ID, manufacturer information), improve the driver matching accuracy, and reduce installation failures caused by driver errors. Predict the compatibility of the driver and the target environment in advance, improve the recognition rate of compatibility problems, and automatically generate solutions. 3. Combine historical traffic with real-time task characteristics to predict the CUPS port traffic peak, dynamically adjust the port mapping strategy, and improve network bandwidth utilization. Distribute printing tasks according to server CPU, memory and bandwidth load to reduce single point failure rate. 4. Generate accurate installation scripts based on driver characteristics and environment configuration, and the success rate of automatic installation and configuration modification of dependencies exceeds 90%, reducing manual intervention. 5. Cross-platform and scalability: supports multiple Linux distributions (Ubuntu, CentOS, etc.) and x86 architecture virtual machine environments, is compatible with USB2.0 / 3.0 printer devices, and can be expanded to multi-task parallel processing scenarios.
[0044] In this embodiment, please refer to Figure 2 In a second embodiment of a Linux printer driver method based on a virtual machine and a cross-CPU architecture in an embodiment of the present invention, using a qemu virtual machine to start at least one minimum Linux environment based on an x86 system architecture includes the following steps: Step 201: Establish an automated image selection algorithm and define evaluation indicators of the algorithm, including resource requirement fit, performance score, compatibility score, and historical usage score; Step 202: Obtain the number of CPU cores, memory, and storage available to the user; obtain the number of CPU cores, memory, and storage required for the image, and calculate the resource requirement fit using the resource requirement fit calculation formula; Step 203: Calculate the performance score using a performance score calculation formula according to the performance of the image in terms of CPU performance, memory performance, and storage performance; Step 204: Score the compatibility of the image with the target system's hardware and software Conduct assessments; Step 205: According to the historical usage data and user feedback, the stability and usability of the image are scored on the historical usage score, and the image with the highest comprehensive score is selected as the minimum Linux image.
[0045] The beneficial effect is that it dynamically adjusts virtual machine resources (CPU, memory, storage) based on the file size, complexity and other characteristics of the printing task, thereby improving resource utilization and avoiding resource waste.
[0046] In this embodiment, please refer to Figure 3 In a third embodiment of a cross-CPU architecture Linux printer driver method based on a virtual machine in an embodiment of the present invention, based on the qemu virtual machine, identifying and capturing a Linux printer device located at a USB port, obtaining a first printer driver includes the following steps: Step 301: Obtain original data of a Linux printer device from a USB port, the original data including at least device hardware information and device description information, perform feature extraction on the original data, and convert it into feature vector data; Step 302: Match the feature vector data using a preset pattern library, calculate the Euclidean distance between the feature vector and the pattern for each pattern in the pattern library, select the printer model and manufacturer corresponding to the pattern with the smallest Euclidean distance as the recognition result, and obtain the printer model and manufacturer; Step 303: After the printer device is identified, its feature vector is input into the trained MLP multi-layer perceptron neural network, the predicted driver probability distribution is output, and the driver label with the largest probability is selected as the first printer driver.
[0047] Its beneficial effect is that it selects the optimal Linux image through a multi-dimensional scoring mechanism (compatibility, performance, historical stability), thereby improving the success rate of image adaptation.
[0048] The above describes a Linux printer driver method based on a virtual machine and a cross-CPU architecture provided by an embodiment of the present invention. The following describes a Linux printer driver system based on a virtual machine and a cross-CPU architecture provided by an embodiment of the present invention. Figure 4 , the embodiment of the present invention includes: The initial environment startup module is used to use the qemu virtual machine to start at least one minimum Linux environment based on the x86 system architecture to obtain the initial Linux environment; Specifically, this embodiment also includes the following units: Evaluation indicator definition unit, used to establish an automated image selection algorithm and define the evaluation indicators of the algorithm, including resource demand fit , Performance Rating , Compatibility Score and historical usage ratings ; Resource requirement calculation unit, used to obtain the number of CPU cores, memory and storage available to the user; obtain the number of CPU cores, memory and storage required by the image, and calculate the resource requirement fit through the resource requirement fit calculation formula The calculation formula is as follows: ; in, Indicates the number of CPU cores available to the user. Indicates the number of CPU cores required for the image. Indicates user available memory. Indicates the memory required for the image. Indicates the user's available storage. Indicates the storage required for the image; , and is the weight coefficient, and .
[0049] The performance scoring calculation unit is used to score the performance of the image based on the CPU performance, memory performance, and storage performance using the performance scoring calculation formula. The calculation formula is as follows: ; in, Indicates the CPU performance of the image. Indicates the memory performance of the image. Indicates the storage performance of the image. , and is the weight coefficient, and .
[0050] Compatibility assessment unit, used to score the compatibility of the image based on its compatibility with the target system's hardware and software To evaluate, the calculation formula is as follows: ; in, Indicates the hardware compatibility score, Indicates the software compatibility score, is the weight coefficient.
[0051] Linux image selection unit, used to rate images for stability and ease of use based on historical usage data and user feedback Score the image and select the image with the highest overall score as the minimum Linux image.
[0052] A dynamic allocation unit is used to establish a dynamic resource allocation model, and use the dynamic resource allocation model to dynamically allocate resources of the qemu virtual machine according to the estimated load of the printing task; Load indicator unit, used to define task load indicators, which at least include file size and printing complexity , printing complexity At least include the graphics, colors and layout of the file; used to quantify the complexity of printing; file size Indicates the size of the print file in bytes. Assuming that there is a linear relationship between the CPU resource requirements, memory resource requirements, and storage resource requirements and the file size and printing complexity, the calculation formula of the dynamic resource allocation model is as follows: ; ; ; in, , , , , , , , , Represents model parameters, which are obtained through training of machine learning algorithms. Indicates CPU resource requirements, Indicates memory resource requirements, Indicates storage resource requirements.
[0053] The dynamic adjustment unit is used to dynamically adjust the number of CPU cores, memory size and storage capacity of the qemu virtual machine based on the output of the dynamic resource allocation model, assuming that there is a linear relationship between the CPU resource demand, memory resource demand and storage resource demand and the file size and printing complexity.
[0054] Based on the output of the dynamic resource allocation model, the number of CPU cores, memory size, and storage capacity of the qemu virtual machine are dynamically adjusted. The adjusted resource allocation is as follows: ; ; ; in, Indicates the adjusted CPU resource requirements. Indicates the adjusted memory resource requirements, represents the adjusted storage resource requirements, Express Round up.
[0055] A first driver calculation module is used to identify and capture a Linux printer device located at a USB port based on a qemu virtual machine to obtain a first printer driver; Specifically, this embodiment also includes the following units: The data acquisition unit is used to acquire the original data of the Linux printer device from the USB port. The original data includes at least the device hardware information and the device description information. The original data is subjected to feature extraction and converted into feature vector data. The calculation formula of the feature vector is as follows: ; in, Represents one-hot encoding, mapping raw data into numerical features; Indicates the device ID. Indicates the manufacturer ID. Indicates the device category. Indicates the device subcategory, Indicates a protocol.
[0056] A vector calculation unit, used to match the feature vector data with a preset pattern library, calculate the Euclidean distance between the feature vector and the pattern for each pattern in the pattern library, select the printer model and manufacturer corresponding to the pattern with the smallest Euclidean distance as the recognition result, and obtain the printer model and manufacturer; The model training unit is used to identify the printer device, input its feature vector into the trained MLP multi-layer perceptron neural network, output the predicted driver probability distribution, and select the driver label with the largest probability as the first printer driver.
[0057] Get the printer model, manufacturer information and corresponding driver information in the database to build a training data set ;in is the input vector containing features such as printer model and manufacturer, is the corresponding driver tag; Construct a multi-layer perceptron MLP neural network, which includes an input layer, a hidden layer, and an output layer. The number of neurons in the input layer is equal to the input vector The dimension of the output layer is equal to the number of driving label categories. The weight matrix of the hidden layer is , the bias vector is .
[0058] For the input vector , calculate the output result through forward propagation. The input of the layer is , the output is , the activation function is (such as RELU activation function ), then: ; ; in, , the output of the final output layer This is the predicted driving probability distribution.
[0059] Define the loss function ,in, is the actual driver label (one-hot encoded), is the predicted driving probability distribution, is the number of driver label categories. Use an optimization algorithm (stochastic gradient descent SGD) to minimize the loss function and update the weights and biases of the neural network. After identifying the printer device, input its feature vector into the trained neural network and output the predicted driver probability distribution. Select the driver label with the highest probability as the most suitable first printer driver.
[0060] A second driver calculation module is used to redirect the first printer driver through the USB redirection technology to obtain a second printer driver; Specifically, this embodiment also includes the following units: A real-time monitoring unit is used to establish a driver optimization algorithm and monitor the performance indicators of the first printer driver in real time, including data transmission rate and response time ; Threshold calculation unit for setting data transmission rate and response time Threshold and ,when < When , it means that there is a bottleneck in the data transmission rate. Greater than When indicates a long response time; Rate adjustment unit, used to set the current buffer size to , the adjustment coefficient is ,like >1 is used to increase the buffer, if 0 < <1 is used to reduce the buffer size. The buffer size is adjusted according to the change of data transmission rate. The adjusted buffer size ; The optimization rate calculation unit is used to prioritize interrupts with high response time requirements by using interrupt priority sorting. Suppose the interrupt processing time before optimization is , the optimized interrupt processing time is , optimization effect is calculated by optimization rate measure, ; The code optimization unit is used to optimize the driver code according to the adjusted buffer and interrupt processing time, and use the optimized driver code for redirection to obtain the second printer driver.
[0061] The target environment acquisition module is used to map the CUPS service port of the initial Linux environment using the IP port redirection technology to obtain the target Linux environment; Specifically, this embodiment also includes the following units: The information acquisition unit is used to obtain historical network traffic data and characteristic information of the current printing task, and the characteristic information at least includes the file size. , Print number of copies and print format complexity , preprocess the historical traffic data and characteristic information to obtain the initial network traffic data; The model building unit is used to extract the feature vector from the initial network traffic data, obtain the feature network traffic data, and input the feature network traffic data into the ARIMR model for training. The calculation formula of the ARIMR model is: ; in, is an autoregressive polynomial, is the moving average polynomial, is the lag operator, is the difference order, is a white noise sequence; Model training unit, used to obtain a period of time in the future after training Traffic forecast value within , according to the traffic prediction value Adjust the port mapping policy, which includes setting different traffic thresholds and flow threshold ,in < ,when < When , reduce the number of mapped ports, when > When , increase the number of mapped ports; The environment obtaining unit is used to map the CUPS service port of the initial Linux environment according to the port mapping strategy to obtain the target Linux environment.
[0062] A target driver obtaining module is used to install a second printer driver on the CUPS service port based on the target Linux environment to obtain the target printer driver; Specifically, this embodiment also includes the following units: A path acquisition unit, used to acquire characteristic information of the second printer driver, the characteristic information at least including the driver version , minimum operating system version , Software Package List , storage path of driver files ; System configuration unit, used to obtain the configuration information of the target Linux environment, including the operating system version , Software Package List , System configuration file path ; The path dependency unit is used to check whether the operating system version of the target Linux environment meets the minimum requirements of the driver. < , then terminate the script generation process; compare the list of dependent packages required by the driver And the list of packages installed on the system , get the dependencies installed ,in ; The planning unit is used to plan the installation steps according to the characteristic information of the second printer driver and the configuration information of the target Linux environment, and to combine the installation steps into an installation script based on the execution order to obtain the target printer driver.
[0063] The print command execution module is used to obtain the content to be printed and execute the print command on the content to be printed based on the target printer driver.
[0064] Specifically, in this embodiment, When there are multiple print tasks, the print task priority scheduling algorithm is used. The algorithm assigns a priority to each task based on factors such as the urgency, importance, and file size of the task. Then the print instructions are executed in order of priority to ensure that important tasks are processed first.
[0065] The beneficial effect is that at least one minimum Linux environment based on the x86 system architecture is started by using the qemu virtual machine to obtain an initial Linux environment; based on the qemu virtual machine, a Linux printer device located at a USB port is identified and captured to obtain a first printer driver; the first printer driver is redirected by the USB redirection technology to obtain a second printer driver; the CUPS service port of the initial Linux environment is mapped by the IP port redirection technology to obtain a target Linux environment; based on the target Linux environment, a second printer driver is installed on the CUPS service port to obtain a target printer driver; the content to be printed is obtained, and a print instruction is executed on the content to be printed based on the target printer driver. The historical traffic and real-time task characteristics can be combined to predict the peak traffic of the CUPS port, dynamically adjust the port mapping strategy, and improve the network bandwidth utilization. Printing tasks are distributed according to the server CPU, memory and bandwidth load to reduce the single point failure rate.
[0066] Specifically, the present invention can also be implemented in the following ways: Step A: Use the qemu virtual machine to start a minimal Linux environment based on the x86 system architecture.
[0067] In this step, the minix operating system is selected as the minimum working kernel, but other Linux distributions such as Debian and Ubuntu also belong to this category. The minimum Linux environment refers to the distribution that removes other components except the necessary kernel program.
[0068] Step B: Identify and capture the Linux printer device located at the USB port.
[0069] In this step, the main device identifier is obtained by searching the Linux device file identifier / dev / usb / lp0, and the detailed information and bus identification information of the printer device are obtained by means of lspci command and dmesg filtering. The servo program is carried out in a traversal manner. In addition to / dev / usb / lp0, the traversal file identifier also includes / dev / usb / lp1, / dev / usb / lp2, / dev / usb / lp3... and other identifiers that meet the format.
[0070] Step C: Redirect the printer driver to qemu through USB redirection technology.
[0071] In this step, the qemuusb_addhost:xxx:xxx command is used to redirect the USB printer device to the qemu virtual machine, where xxxx:xxxx is the PCI bus identifier of the printer.
[0072] Step D: Use IP port redirection technology to map the CUPS service port in the minimum Linux environment.
[0073] This step is completed by using ipfilter, iptables and other operation techniques. The mapping port is mapped from port 631 of the virtual machine to port 631 of 127.0.0.1. That is, call the command prompt to execute the following command: iptables-AINPUT-iloopback-ptcp--dport631-jACCEPT; iptables-APREROUTING-tnat-iloopback-ptcp-dport631-jREDIRECT--to-desation192.168.43.2--to-port631; 192.168.43.2 is the hostonly address of the virtual machine.
[0074] Step E: Install the printer driver to CUPS in the x86 environment through the Printer Manager.
[0075] In this step, the management process of CUPS in the virtual machine is called in the target computer through the CUPS print manager Web interface and the compatible printer management interface.
[0076] Step F: Print specific content.
[0077] The above shows and describes the basic principles, main features and advantages of the present invention. It should be understood by those skilled in the art that the present invention is not limited by the above embodiments. The above embodiments and descriptions are only preferred examples of the present invention and are not intended to limit the present invention. Without departing from the spirit and scope of the present invention, the present invention may have various changes and improvements, which fall within the scope of the present invention to be protected. The scope of protection of the present invention is defined by the attached claims and their equivalents.< / value> < / package> < / package>
Claims
1. A Linux printer driver method based on a cross-CPU architecture of a virtual machine, characterized in that: The Linux printer driver method comprises the following steps: Use the qemu virtual machine to start at least one minimum Linux environment based on the x86 system architecture to obtain the initial Linux environment; Based on the qemu virtual machine identifying and capturing the Linux printer device located at the USB port, a first printer driver is obtained; Redirect the first printer driver by using USB redirection technology to obtain a second printer driver; Map the CUPS service port of the initial Linux environment using the IP port redirection technology to obtain the target Linux environment; Install the second printer driver on the CUPS service port based on the target Linux environment to obtain a target printer driver; Acquire the content to be printed, and execute a printing instruction on the content to be printed based on the target printer driver.
2. A Linux printer driver method based on a virtual machine and a cross-CPU architecture as claimed in claim 1, characterized in that: The method of using the qemu virtual machine to start at least one minimum Linux environment based on the x86 system architecture includes: Establish an automated image selection algorithm and define evaluation metrics for the algorithm, including resource requirement fit , Performance Rating , Compatibility Score and historical usage ratings ; Obtain the number of CPU cores, memory, and storage available to the user; obtain the number of CPU cores, memory, and storage required for the image, and calculate the resource requirement fit using the resource requirement fit calculation formula ; Based on the image's performance in terms of CPU performance, memory performance, and storage performance, the performance is scored using the performance scoring calculation formula Perform calculations; Compatibility score based on how well the image works with the target system's hardware and software Conduct assessments; Based on historical usage data and user feedback, rate the image for stability and ease of use Score the image and select the image with the highest overall score as the minimum Linux image.
3. A Linux printer driver method based on a virtual machine and cross-CPU architecture as claimed in claim 1, characterized in that: The method of using the qemu virtual machine to start at least one minimum Linux environment based on the x86 system architecture also includes: Establish a dynamic resource allocation model, and use the dynamic resource allocation model to dynamically allocate resources of the qemu virtual machine according to the estimated load of the printing task; Define task load indicators, which at least include file size and printing complexity , the printing complexity This includes at least the graphics, colors, and layout of the document; Assuming that there is a linear relationship between CPU resource requirements, memory resource requirements, and storage resource requirements and file size and printing complexity, the number of CPU cores, memory size, and storage capacity of the qemu virtual machine are dynamically adjusted based on the output of the dynamic resource allocation model.
4. The Linux printer driver method based on a virtual machine and cross-CPU architecture as claimed in claim 1, characterized in that: The method of identifying and capturing a Linux printer device located at a USB port based on the qemu virtual machine to obtain a first printer driver includes: Acquire raw data of a Linux printer device from a USB port, the raw data including at least device hardware information and device description information, perform feature extraction on the raw data, and convert it into feature vector data; Matching the feature vector data using a preset pattern library, calculating the Euclidean distance between the feature vector and the pattern for each pattern in the pattern library, selecting the printer model and manufacturer corresponding to the pattern with the smallest Euclidean distance as the recognition result, and obtaining the printer model and manufacturer; After the printer device is identified, its feature vector is input into the trained MLP multi-layer perceptron neural network, the predicted driver probability distribution is output, and the driver label with the highest probability is selected as the first printer driver.
5. The Linux printer driver method based on a virtual machine and cross-CPU architecture as claimed in claim 1, characterized in that: The method of redirecting the first printer driver by using the USB redirection technology to obtain the second printer driver includes: Establish a driver optimization algorithm to monitor the performance indicators of the first printer driver in real time, including data transmission rate and response time ; Set the data transfer rate and response time Threshold and ,when < When , it means that there is a bottleneck in the data transmission rate. Greater than When indicates a long response time; Set the current buffer size to , the adjustment coefficient is ,like >1 is used to increase the buffer, if 0 < <1 is used to reduce the buffer size. The buffer size is adjusted according to the change of data transmission rate. The adjusted buffer size ; Use interrupt priority sorting to prioritize interrupts with high response time requirements. Suppose the interrupt processing time before optimization is , the optimized interrupt processing time is , optimization effect is calculated by optimization rate measure, ; The driver code is optimized according to the adjusted buffer and interrupt processing time, and the optimized driver code is used for redirection to obtain a second printer driver.
6. A Linux printer driver method based on a virtual machine and cross-CPU architecture as claimed in claim 1, characterized in that: The method of mapping the CUPS service port of the initial Linux environment by using the IP port redirection technology to obtain the target Linux environment includes: Obtain historical network traffic data and characteristic information of the current print task, the characteristic information at least including the file size , Print number of copies and print format complexity , preprocess the historical traffic data and characteristic information to obtain the initial network traffic data; Extract the characteristic vector from the initial network traffic data to obtain characteristic network traffic data, and input the characteristic network traffic data into the ARIMR model for training. The calculation formula of the ARIMR model is: ; in, is an autoregressive polynomial, is the moving average polynomial, is the lag operator, is the difference order, is a white noise sequence; After training, get the future time Traffic forecast value within , according to the traffic prediction value Adjust the port mapping policy, which includes setting different traffic thresholds and flow threshold ,in < ,when < When , reduce the number of mapped ports, when > When , increase the number of mapped ports; The CUPS service port of the initial Linux environment is mapped according to the port mapping strategy to obtain a target Linux environment.
7. A Linux printer driver method based on a cross-CPU architecture of a virtual machine as claimed in claim 1, characterized in that: The step of installing the second printer driver on the CUPS service port based on the target Linux environment to obtain the target printer driver includes: Acquire characteristic information of the second printer driver, the characteristic information at least including the driver version , minimum operating system version , Software Package List , storage path of driver files ; Get the configuration information of the target Linux environment, including the operating system version , Software Package List , System configuration file path ; Check whether the operating system version of the target Linux environment meets the minimum requirements of the driver. < , then terminate the script generation process; compare the list of dependent packages required by the driver And the list of packages installed on the system , get the dependencies installed ,in ; According to the characteristic information of the second printer driver and the configuration information of the target Linux environment, the installation steps are planned, and an installation script is combined based on the execution order of the installation steps to obtain the target printer driver.
8. A Linux printer driver system based on a cross-CPU architecture of a virtual machine, characterized in that: The Linux printer driver system includes the following modules: The initial environment startup module is used to use the qemu virtual machine to start at least one minimum Linux environment based on the x86 system architecture to obtain the initial Linux environment; A first driver calculation module is used to identify and capture a Linux printer device located at a USB port based on the qemu virtual machine to obtain a first printer driver; A second driver calculation module, used for redirecting the first printer driver through USB redirection technology to obtain a second printer driver; A target environment acquisition module is used to map the CUPS service port of the initial Linux environment by using the IP port redirection technology to obtain a target Linux environment; A target driver obtaining module, used for installing the second printer driver on the CUPS service port based on the target Linux environment to obtain the target printer driver; The printing command execution module is used to obtain the content to be printed and execute the printing instruction on the content to be printed based on the target printer driver.
9. A Linux printer driver system based on a virtual machine and cross-CPU architecture as claimed in claim 8, characterized in that: The initial environment startup module includes the following units: Evaluation indicator definition unit, used to establish an automated image selection algorithm and define the evaluation indicators of the algorithm, including resource demand fit , Performance Rating , Compatibility Score and historical usage ratings ; The resource requirement calculation unit is used to obtain the number of CPU cores, memory and storage available to the user; obtain the number of CPU cores, memory and storage required for the image, and calculate the resource requirement fit through the resource requirement fit calculation formula ; A performance score calculation unit is used to score the performance of the image based on the CPU performance, memory performance and storage performance using a performance score calculation formula. Perform calculations; A compatibility evaluation unit, used to score the compatibility of the image based on its compatibility with the hardware and software of the target system Conduct assessments; A Linux image selection unit, which is used to rate the image for stability and ease of use based on historical usage data and user feedback Score the image and select the image with the highest overall score as the minimum Linux image.
10. The cross-CPU architecture Linux printer driver system based on a virtual machine as claimed in claim 8, characterized in that: The initial environment startup module also includes the following units: A dynamic allocation unit, used to establish a dynamic resource allocation model, and use the dynamic resource allocation model to dynamically allocate resources of the qemu virtual machine according to the estimated load of the printing task; A load indicator unit is used to define a task load indicator, wherein the task load indicator includes at least the file size. and printing complexity , the printing complexity This includes at least the graphics, colors, and layout of the document; The dynamic adjustment unit is used to dynamically adjust the number of CPU cores, memory size and storage capacity of the qemu virtual machine based on the output of the dynamic resource allocation model, assuming that there is a linear relationship between the CPU resource demand, the memory resource demand and the storage resource demand and the file size and the printing complexity.
Citation Information
Patent Citations
Redirecting method and system for display device
CN106970786A
Solving method of Linux cross-architecture printer based on qemu
CN114004239A
Printer driver matching installation method and system under Linux system
CN114217827A
Printer redirection method and system of cloud desktop
CN114579065A
Cloud desktop printing processing method and system
CN114721606A