Skip to content

Commit 79caa34

Browse files
[Sys] Increased Read Buffers to Reduce Total Syscalls
This change was originally proposed by @heshpdx See PR verilog-to-routing#2772 By increasing the read buffer, the number of syscalls can be reduced since more of the large files are read per call.
1 parent 66f35d9 commit 79caa34

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

libs/EXTERNAL/libblifparse/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ add_library(libblifparse STATIC
4545
target_include_directories(libblifparse PUBLIC ${LIB_INCLUDE_DIRS} ${CMAKE_CURRENT_BINARY_DIR})
4646
set_target_properties(libblifparse PROPERTIES PREFIX "") #Avoid extra 'lib' prefix
4747

48+
# Set the read buffer size in the generated lexers. This reduces the number of
49+
# syscalls since the default is only 1kB.
50+
target_compile_definitions(libblifparse PRIVATE YY_READ_BUF_SIZE=1048576)
51+
4852
#Create the test executable
4953
add_executable(blifparse_test src/main.cpp)
5054
target_link_libraries(blifparse_test libblifparse)

libs/libpugiutil/src/pugixml_loc.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
#include <cstdio>
22
#include <algorithm>
3+
#include <vector>
34
#include "pugixml_util.hpp"
45
#include "pugixml_loc.hpp"
56

7+
// The size of the read buffer when reading from a file.
8+
#ifndef PUGI_UTIL_READ_BUF_SIZE
9+
#define PUGI_UTIL_READ_BUF_SIZE 1048576
10+
#endif // PUGI_UTIL_READ_BUF_SIZE
11+
612
namespace pugiutil {
713

814
//Return the line number from the given offset
@@ -30,10 +36,10 @@ void loc_data::build_loc_data() {
3036

3137
std::ptrdiff_t offset = 0;
3238

33-
char buffer[1024];
39+
std::vector<char> buffer(PUGI_UTIL_READ_BUF_SIZE);
3440
std::size_t size;
3541

36-
while ((size = fread(buffer, 1, sizeof(buffer), f)) > 0) {
42+
while ((size = fread(buffer.data(), 1, buffer.size() * sizeof(char), f)) > 0) {
3743
for (std::size_t i = 0; i < size; ++i) {
3844
if (buffer[i] == '\n') {
3945
offsets_.push_back(offset + i);

libs/libvtrutil/src/vtr_digest.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,15 @@
33

44
#include <iostream>
55
#include <fstream>
6-
#include <array>
6+
#include <vector>
77

88
#include "picosha2.h"
99

10+
// The size of the read buffer when reading from a file.
11+
#ifndef VTR_UTIL_READ_BUF_SIZE
12+
#define VTR_UTIL_READ_BUF_SIZE 1048576
13+
#endif // VTR_UTIL_READ_BUF_SIZE
14+
1015
namespace vtr {
1116

1217
std::string secure_digest_file(const std::string& filepath) {
@@ -21,7 +26,7 @@ std::string secure_digest_stream(std::istream& is) {
2126
//Read the stream in chunks and calculate the SHA256 digest
2227
picosha2::hash256_one_by_one hasher;
2328

24-
std::array<char, 1024> buf;
29+
std::vector<char> buf(VTR_UTIL_READ_BUF_SIZE);
2530
while (!is.eof()) {
2631
//Process a chunk
2732
is.read(buf.data(), buf.size());

0 commit comments

Comments
 (0)