# Inferring TLB Configuration with Performance Tools
## 2 Materials and Methods
### Procedure
```
1 uintptr_tgenerate_unique_address(uint32_tN,uint32_ttarget_set,size_tblock_size,intiteration,uintptr_tbase_address){
2 uintptr_tlower_half=0x2a+iteration;//0x2A.Ensuringuniquenessforeachaddress
3//CalculatetheupperhalfneededtoachievethetargetsetwhenKORedwiththelowerhalf
4 uintptr_tupper_half=lower_half^target_set;
5
6//TestXORtoverifcorrectness(optional,fordemonstration)
7 uintptr_ttest=lower_half^upper_half;
8
9//ExtractthelowestN+1 bitsofeachhalf
10 uintptr_tlower_bits=lower_half&((1<<(N))-1);//MasktogetthelowestN+1 bits
11 uintptr_tupper_bits=upper_half&((1<<(N))-1);//Samesaskforupperhalf
12
13//Combethehalves,insertimethemafterthe12-bitpageoffset
14 uintptr_tcombined_half=(upper_bits<<(N))|lower_bits;//Shiftandcombine
15
16 uintptr_tcombined_half_modulated=combined_half%(block_size>>12);//Ensurewithinblockbounds
17 uintptr_taddress_modulated=combined_half_modulated<<12;//Re-adjuststforthe12-bitpageoffset
18 uintptr_twa_addr=base_address+address_modulated;//Calculateadjustedvirtualaddresswithintheallocatedblock
19
20 returnva_addr;
21}
```  
**Listing 3**Xeon STLB C program. A shell script is designed to execute each of the previously mentioned C programs, specifically to pass values for ways and sets as arguments. The script is configured to handle a range of candidate 'ways' from 0 to 20 (and from 0 to 50 for XOR-N), aligning with the parameters of this study. The'sets' are fixed at predetermined values: 4, 8, 16, 32, and 64 (with 128 and 256 for XOR-N). Additionally, the script is structured to sequentially monitor specific events of interest in our study. It uses a loop structure, where each iteration executes the C program with a fixed'sets' value while systematically varying 'ways' within the specified range. A distinctive feature of the script is its ability to initiate event tracking exclusively when the C program is running, thereby minimizing the recording of unrelated processes. The results from each unique'set'-and-'ways' combination are compiled and stored in Comma Separated Values (CSV) files, enabling detailed subsequent analysis. Two Python scripts are used to analyze the data. The Python A program, heatmap_tlb.py is designed to process the CSV files generated by the shell script. Its primary role is to remove log messages so that specific data related to the performance event produces a consistent CSV file structure across all program executions. In this context, 'command' denotes the event that was measured. The script carefully extracts data for 'ways' in the predetermined range, along with the corresponding values of the event. Additionally, it incorporates the'set' value into this newly formed dataset. Consequently, we obtain a comprehensive dataset that encapsulates a specific'set' for the entire range of 'ways', along with their respective event values. Building upon the data, the script then employs Pandas, a powerful Python data analysis library, to create a pivot table. A pivot table maps the'set'-and-'ways' combinations to the event. The final product of this script is a heatmap, which visually represents these combinations on a single plot. This heatmap offers a clear and concise visual representation of the data, thus facilitating easier interpretation and analysis of the patterns and trends within the dataset. Python B reads CSV files containing performance data for each candidate TLB configuration, selects the data by a specific performance event, and then isolates data within a specified range of 'ways'. The script calculates the gradient (first derivative) of the mean values with respect to 'ways' for each'sets' configuration, indicating how the performance metric changes as the number of 'ways' increases. These derivatives can be used to identify trends or significant changes in the performance metric. The results are plotted, displaying gradients against 'ways' for each'sets' configuration, providing a visual analysis of the performance data. This approach enables a detailed examination of how different TLB configurations affect CPU performance.