Method and System for Accelerating the Simulation Log of Palladium Z1 Printing
Through custom variable character conversion printing functions and table lookup methods, logs are cached in memory and then written to files when errors occur, solving the problem of reduced simulation speed and huge logging after adding logs to Palladium Z1, achieving efficient log printing and simulation performance optimization.
Patent Information
- Application Number
- CN202111353513.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-16
- Publication Date
- 2025-06-13
- Estimated Expiration
- 2041-11-16
AI Technical Summary
In the Palladium Z1 acceleration emulator, adding simulation logs will cause a sharp drop in simulation speed, and the simulation logs generated will be huge, which is inconvenient to save and debug.
By defining large tables and empty tables cached in the middle, customizing variable character conversion printing functions, using table lookup method instead of the traditional fprintf or sprintf printing functions, and caches logs in memory, and then writing to the file when an error occurs.
It has achieved speed up printing logs on Palladium Z1, with only ~10% reduction in simulation performance, and saves storage space, and only saves part of the log before the error, making it easy to read and debug.
Smart Images

Figure CN114237524B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of computer languages, and particularly relates to a method and system for accelerating the printing simulation log of palladium Z1. Background Art
[0002] Palladium Z1 is an acceleration emulator, abbreviated as PZ1. The reasons for the existence of PZ1 are as follows: The simulation speed of the Simulator is too slow, but its debug ability is strong. The simulation speed of the FPGA is fast, but its debug ability is too weak.
[0003] Therefore, an acceleration emulator (PZ1) between the simulator and the FPGA was born. As shown in the following, the working mode of Pz1 is as follows: Our checker platform works in the software part, and the design code works in the hardware part. Normally, the HW part runs at the high-speed end, but for checking, we have to interrupt its operation and then lead wires for checking. Figure 1
[0004] In order to ensure the running speed of the HW as much as possible, there is a fifo mechanism between the SW side and the HW side. After the HW runs for a period of time, data is thrown into the fifo, and then the SW takes the data from the fifo for checking. Therefore, to a certain extent, the SW will drag down the HW side and cause the simulation to slow down. Therefore, the greater the proportion of the time occupied by the transactions processed on the SW side, the more the simulation speed will be affected.
[0005] When the program simulation goes wrong, the simulation log used for debugging is very important. This involves the problem of log printing. The simulation speed of pz1 is fast, and the generated log is also very large. In order to perform checks, printing the log on the SW side will inevitably cause the speed of pz1 to decrease.
[0006] Therefore, there are two problems faced: 1. After adding the printed log, the simulation speed drops sharply. 2. The generated simulation log is huge, which is not convenient for storage and debugging.
[0007] Therefore, this article aims to solve the above two problems under the condition of adding the simulation log, and at the same time improve the traditional log printing scheme, taking into account both the simulation speed and the debug ability. Summary of the Invention
[0008] In view of the deficiencies of the prior art, the present invention discloses a method and system for accelerating the printing simulation log of palladium Z1, which is used to solve the problems that the simulation speed drops sharply after adding the printed log, and the generated simulation log is huge and not convenient for storage and debugging.
[0009] The present invention is achieved through the following technical solutions:
[0010] In a first aspect, the present invention provides a method for accelerating the printing simulation log of palladium Z1, including the following steps:
[0011] S1 Define an empty table for the large table and the intermediate cache, and customize a variable character conversion printing function based on this.
[0012] S2 Customize a custom cache space, a head pointer, and a write pointer, and initialize the custom cache space at the same time.
[0013] S3 Call the zprint_str function, and implement the zprint_inner function in the zprint_str function to enter the log printing.
[0014] S4 Define the zprint_flush function, and when the log printing condition is triggered, print the cached data into the log file.
[0015] Furthermore, in S1, define a large table in 4-digit hexadecimal and an empty table for the intermediate cache.
[0016] Furthermore, in S1, customize a variable character conversion printing function with 64bit, 32bit, and 16bit widths based on the defined large table and the empty table of the intermediate cache.
[0017] Furthermore, in the method, the zprint_inner function is used to implement writing data into the cache and performing wrap-around writing into the cache when the data written exceeds the cache space.
[0018] Furthermore, in the method, the string or variable to be printed is copied to the printtmp buffer through memcpy, and then written into the cache area through zprint_str.
[0019] Furthermore, the method performs printing through a look-up table method, caches the log in memory, and writes it into the file when an error occurs.
[0020] In a second aspect, the present invention provides a system for accelerating the printing simulation log of palladium Z1, including a Palladium Z1 acceleration emulator, including a processor and a memory. Among them, computer-readable instructions are stored on the memory, and when the computer-readable instructions are executed by the processor, the method for accelerating the printing simulation log of palladium Z1 described in the first aspect is implemented.
[0021] The beneficial effects of the present invention are:
[0022] The present invention replaces the traditional fprintf or sprintf printing functions by means of table lookup, thereby realizing the conversion of variables to characters and achieving the purpose of accelerating the printing of logs on pz1. At the same time, the logs are cached in memory and written to a file only when an error occurs, saving storage; the simulation performance of the improved printing scheme pz1 of the present invention only drops by about 10%. Only the part of the log before the error occurs is saved, which is convenient for reading and debugging. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] In order to more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the following will briefly introduce the drawings required for the description of the embodiments or the prior art. Obviously, the drawings in the following description are only some embodiments of the present invention. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.
[0024] Figure 1 is the schematic diagram of the working mode of Pz1 in the background technology of the present invention;
[0025] Figure 2 is the principle step diagram of a method for accelerating the printing simulation log of palladium Z1;
[0026] Figure 3 is the schematic diagram of the present invention's embodiment being copied to the printtmp buffer through memcpy and written to the buffer through zprint_str. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0027] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the following will clearly and completely describe the technical solutions in the embodiments of the present invention with reference to the drawings in the embodiments of the present invention. Obviously, the described embodiments are some, but not all, of the embodiments of the present invention. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without creative efforts fall within the scope of protection of the present invention.
[0028] Embodiment 1
[0029] Referring to Figure 2 As shown, this embodiment provides a method for accelerating the printing simulation log of palladium Z1, including the following steps:
[0030] S1 Define a large table and an empty table for intermediate caching, and customize a variable-character conversion printing function accordingly;
[0031] S2 Customize a custom cache space, a head pointer, and a write pointer, and initialize the custom cache space at the same time;
[0032] S3 calls the zprint_str function, and implements the zprint_inner function in the zprint_str function to enter the log printing;
[0033] S4 defines the zprint_flush function, and when the log printing condition is triggered, it prints the cached data into the log file.
[0034] In this embodiment, a large table of 4-digit hexadecimal and an empty intermediate cache table are defined, and a custom character conversion printing function for 64bit, 32bit, and 16bit width variables is defined through the defined large table and the empty intermediate cache table.
[0035] The zprint_inner function in this embodiment is used to implement data writing into the cache and wrap-around writing into the cache when the data writing exceeds the cache space.
[0036] In this embodiment, the string or variable to be printed is copied to the printtmp buffer through memcpy, and then written into the cache area through zprint_str.
[0037] This embodiment performs printing through a look-up table method, caches the log in memory, and writes it into the file when an error occurs.
[0038] This embodiment replaces the traditional fprintf or sprintf printing function through a look-up table method, thereby realizing the conversion from variables to characters, and achieving the purpose of accelerating log printing on pz1.
[0039] This embodiment caches the log in memory, waits for an error to write it into the file, saves storage, and is convenient for reading and debugging at the same time.
[0040] Embodiment 2
[0041] At the specific implementation level, this embodiment provides a solution for accelerating the printing of simulation logs on palladium Z1. It replaces the traditional printing method through a look-up table method, caches the log in memory, and writes it into the file when an error occurs. The specific steps are as follows:
[0042] Step1: Define a large table of 4-digit hexadecimal
[0043] static const char* uint2str_table
[65536] = {
[0044] "0000",
[0045] "0001",
[0046] ”0002”,
[0047] …
[0048] ”fffc”,
[0049] ”fffd”,
[0050] ”fffe”,
[0051] ”ffff”
[0052] };
[0053] Step2: Define an empty table for intermediate caching
[0054] Static char uint2str_tmp
[17] = {
[0055] ””,
[0056] ””,
[0057] …
[0058] ””,
[0059] ””
[0060] };
[0061] Step3: Customize a function for converting and printing variables with 64-bit, 32-bit, and 16-bit widths using the two tables from step1 and step2
[0062] const char* uint64_to_str(uint64_t data) {
[0063] for (uint64_t i = 0; i < 4; i++) {
[0064] uint64_t index = (data >> ((3 - i) << 4)) & 0xffff;
[0065] const char* str16 = uint2str_table[index];
[0066] memcpy(uint2str_tmp + i * 4, str16, 4);
[0067] }
[0068] uint2str_tmp
[16] = ””;
[0069] Return uint2str_tmp;
[0070] }
[0071] const char* uint32_to_str(uint32_t data) {
[0072] for (uint64_t i = 0; i < 2; i++) {
[0073] uint64_t index = (data >> ((1 - i) << 4)) & 0xffff;
[0074] const char* str16 = uint2str_table[index];
[0075] memcpy(uint2str_tmp + i * 4, str16, 4);
[0076] }
[0077] uint2str_tmp[8] = "";
[0078] Return uint2str_tmp;
[0079] }
[0080] const char* uint16_to_str(uint16_t data) {
[0081] const char* str16 = uint2str_table[data];
[0082] memcpy(uint2str_tmp, str16, 4);
[0083] uint2str_tmp[4] = "";
[0084] Return uint2str_tmp;
[0085] }
[0086] Step4: Custom cache space
[0087] #define ZPRINT_SIZE (1024 * 1024 * 1024)
[0088] Step5: Define a head pointer and a write pointer, and initialize the custom cache space at the same time
[0089] char* g_zprint_head;
[0090] char* g_zprint_ptr;
[0091] void zprint_init(){
[0092] g_zprint_head = (char*)malloc(ZPRINT_SIZE);
[0093] g_zprint_ptr = g_zprint_head;
[0094] }
[0095] Step6: When it is necessary to print the log, directly call the zprint_str function. Implement the zprint_inner function in zprint_str. zprint_inner mainly realizes writing data into the cache and performs wrap-around writing into the cache when the written data exceeds the cache space.
[0096] void zprint_str(const char*str){
[0097] zprint_inner(str,strlen(str));
[0098] }
[0099] Static inline void zprint_inner(const char*str,int64_tlen){
[0100] if(g_zprint_ptr - g_zprint_head + len > ZPRINT_SIZE){
[0101] int64_tlen_left = g_zprint_ptr - g_zprint_head + len - ZPRINT_SIZE;
[0102] memcpy(g_zprint_ptr,str,len - len_left);
[0103] g_zprint_ptr = g_zprint_head;
[0104] memcpy(g_zprint_ptr,str + len - len_left,len_left);
[0105] g_zprint_ptr += len_left;
[0106] }else{
[0107] memcpy(g_zprint_ptr, str, len);
[0108] g_zprint_ptr += len;
[0109] }
[0110] }
[0111] The following is an example:
[0112] Refer to Figure 3 As shown, the string or variable to be printed (through the conversion functions uint64_to_str / uint32_to_str / uint16_to_str) is copied to the printtmp buffer through memcpy, and then written to the buffer through zprint_str.
[0113] static char zprinttmp
[1024] ;
[0114] int zprintlen = 0;
[0115] …
[0116] memcpy(zprinttmp + zprintlen, "hart:", 5);
[0117] zprintlen += 5;
[0118] memcpy(zprinttmp + zprintlen, uint16_to_str(hart_id), 5);
[0119] zprintlen += 5;
[0120] memcpy(zprinttmp + zprintlen, "dasm:", 5);
[0121] zprintlen += 5;
[0122] memcpy(zprinttmp + zprintlen, uint32_to_str(bits), 8);
[0123] zprintlen += 8;
[0124] memcpy(zprinttmp + zprintlen, "time:", 5);
[0125] zprintlen += 5;
[0126] memcpy(zprinttmp + zprintlen, uint64_to_str(time), 17);
[0127] zprintlen += 17;
[0128] zprinttmp[zprintlen] = 0;
[0129] zprint_str(zprinttmp);
[0130] Step 7: Define the zprint_flush function. When the condition for printing the log is triggered, print the cached data into the log file.
[0131] Void zprint_flush() {
[0132] FILE *fp;
[0133] fp = fopen(”zprint.log”, ”W”);
[0134] for (int i = 0; i < ZPRINT_SIZE; i++) {
[0135] if (i < (g_zprint_head + ZPRINT_SIZE - g_print_ptr)) {
[0136] fprintf(fp, ”%c”, *(g_zprint_ptr + i));
[0137] } else {
[0138] fprint(fp, ”%c”, *(g_zprint_head + i - ((g_zprint_head + ZPRIN T_SIZE - g_zprint_ptr))));
[0139] }
[0140] }
[0141] }
[0142] In this embodiment, the traditional fprintf or sprintf printing functions are replaced by the method of looking up tables, so as to realize the conversion from variables to characters, and achieve the purpose of speeding up the printing of logs on pz1.
[0143] Example 3
[0144] This embodiment provides a system for accelerating the printing simulation log of Palladium Z1, including a Palladium Z1 acceleration emulator, a processor, and a memory. Among them, computer-readable instructions are stored on the memory, and when the computer-readable instructions are executed by the processor, a method for accelerating the printing simulation log of Palladium Z1 is implemented.
[0145] In summary, the present invention replaces the traditional fprintf or sprintf printing function by means of table lookup, thereby realizing the conversion from variables to characters, and achieving the purpose of accelerating the printing of logs on pz1. At the same time, the log is cached in the memory and written to the file only when an error occurs, saving storage; the improved printing scheme of the present invention only reduces the simulation performance of pz1 by about 10%. Only the part of the log before the error is saved, which is convenient for reading and debugging.
[0146] The above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it; although the present invention has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that: they can still modify the technical solutions recorded in the foregoing embodiments, or perform equivalent replacements on some of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method for accelerating the printing simulation log of palladium Z1, characterized in that, it includes the following steps: S1. Define an empty large table and an empty intermediate cache table, and customize a variable character conversion printing function based on this; S2. Customize the cache space, head pointer, and write pointer, and initialize the customized cache space at the same time; S3. Call the zprint_str function, and implement the zprint_inner function in the zprint_str function to enter the log printing; the zprint_inner function is used to implement writing data into the cache and perform wrap-around writing into the cache when the data written exceeds the cache space; S4. Define the zprint_flush function, and when the condition for triggering the printing of the log occurs, print the data in the cache to the log file; the method performs printing through a look-up table method, caches the log in the memory, and writes it to the file when an error occurs; The string or variable to be printed is copied to the printtmp buffer through memcpy, and then written to the cache area through zprint_str.
2. A method for accelerating the printing simulation log of palladium Z1 according to claim 1, characterized in that, in S1, a 4-bit hexadecimal large table and an empty intermediate cache table are defined.
3. A method for accelerating the printing simulation log of palladium Z1 according to claim 2, characterized in that, in S1, based on the defined large table and the empty intermediate cache table, customize 64-bit, 32-bit, and 16-bit width variable character conversion printing functions.
4. A system for accelerating the printing simulation log of palladium Z1, characterized in that, it includes a Palladium Z1 acceleration emulator, a processor, and a memory. Among them, computer-readable instructions are stored on the memory, and when the computer-readable instructions are executed by the processor, the method for accelerating the printing simulation log of palladium Z1 according to any one of claims 1 to 3 is implemented.
Citation Information
Patent Citations
Data printing method and device, electronic equipment and storage medium
CN111240996A
Printer
CN1252557A