Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Code/EntryPoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ int main(int argc, const char * argv[]) {
return -1;
}

auto processor_information = GetProcessorInformation();
auto processor_information = FileReadSpeedTest::GetProcessorInformation();
if (!processor_information.has_value()) {
std::cerr << "Error: Could not find processor information." << std::endl;
return -1;
Expand All @@ -26,7 +26,7 @@ int main(int argc, const char * argv[]) {
}
std::cout << std::endl;

auto overlapped_io_file_read = PrepareToReadFile(argv[1], processor_information->actual_cores_);
auto overlapped_io_file_read = FileReadSpeedTest::PrepareToReadFile(argv[1], processor_information->actual_cores_);
if (!overlapped_io_file_read.has_value()) {
std::cerr << "Error";
return -1;
Expand Down
136 changes: 70 additions & 66 deletions Code/GetProcessorInformation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,82 +13,86 @@

//#include <iostream>

/*struct ProcessorInformation {
int actual_cores_;
int hyperthreading_cores_;
};*/
namespace FileReadSpeedTest {

std::optional<ProcessorCoreInformation> GetProcessorInformation() noexcept {
DWORD required_buffer_size = 0;
BOOL result = GetLogicalProcessorInformation(nullptr, &required_buffer_size);
if (result == FALSE) {
DWORD error_code = GetLastError();
if (error_code != ERROR_INSUFFICIENT_BUFFER) {
/*struct ProcessorInformation {
int actual_cores_;
int hyperthreading_cores_;
};*/

std::optional<ProcessorCoreInformation> GetProcessorInformation() noexcept {
DWORD required_buffer_size = 0;
BOOL result = GetLogicalProcessorInformation(nullptr, &required_buffer_size);
if (result == FALSE) {
DWORD error_code = GetLastError();
if (error_code != ERROR_INSUFFICIENT_BUFFER) {
return std::nullopt;
}
}
size_t processor_information_count = required_buffer_size / sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION);
auto processor_information = std::make_unique<SYSTEM_LOGICAL_PROCESSOR_INFORMATION[]>(processor_information_count);
result = GetLogicalProcessorInformation(processor_information.get(), &required_buffer_size);
if (result == FALSE) {
return std::nullopt;
}
}
size_t processor_information_count = required_buffer_size / sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION);
auto processor_information = std::make_unique<SYSTEM_LOGICAL_PROCESSOR_INFORMATION[]>(processor_information_count);
result = GetLogicalProcessorInformation(processor_information.get(), &required_buffer_size);
if (result == FALSE) {
return std::nullopt;
}

ProcessorCoreInformation processor_core_information = {};
ProcessorCoreInformation processor_core_information = {};

for(DWORD i = 0; i < processor_information_count; i++) {
//std::cout << "Core " << i << ": " << processor_information[i].ProcessorMask << std::endl;
switch (processor_information[i].Relationship) {
/*
case RelationProcessorPackage:
std::cout << "\tPhysical package" << std::endl;
break;
case RelationNumaNode:
std::cout << "\tNUMA node: " << processor_information[i].NumaNode.NodeNumber << std::endl;
break;
*/
case RelationProcessorCore:
{
processor_core_information.actual_cores_++;
if (processor_information[i].ProcessorCore.Flags == 1) {
processor_core_information.hyperthreading_cores_++;
}
}
break;
/*
case RelationCache:
std::cout << "\tL";
switch (processor_information[i].Cache.Level) {
case 1:
std::cout << "1 ";
break;
case 2:
std::cout << "2 ";
for(DWORD i = 0; i < processor_information_count; i++) {
//std::cout << "Core " << i << ": " << processor_information[i].ProcessorMask << std::endl;
switch (processor_information[i].Relationship) {
/*
case RelationProcessorPackage:
std::cout << "\tPhysical package" << std::endl;
break;
case 3:
std::cout << "3 ";
case RelationNumaNode:
std::cout << "\tNUMA node: " << processor_information[i].NumaNode.NodeNumber << std::endl;
break;
*/
case RelationProcessorCore:
{
processor_core_information.actual_cores_++;
if (processor_information[i].ProcessorCore.Flags == 1) {
processor_core_information.hyperthreading_cores_++;
}
}
switch (processor_information[i].Cache.Type) {
case CacheUnified:
std::cout << "unified";
break;
case CacheInstruction:
std::cout << "instuction";
break;
case CacheData:
std::cout << "data";
break;
case CacheTrace:
std::cout << "trace";
break;
/*
case RelationCache:
std::cout << "\tL";
switch (processor_information[i].Cache.Level) {
case 1:
std::cout << "1 ";
break;
case 2:
std::cout << "2 ";
break;
case 3:
std::cout << "3 ";
break;
}
switch (processor_information[i].Cache.Type) {
case CacheUnified:
std::cout << "unified";
break;
case CacheInstruction:
std::cout << "instuction";
break;
case CacheData:
std::cout << "data";
break;
case CacheTrace:
std::cout << "trace";
break;
}
std::cout << " cache, " << processor_information[i].Cache.Size << " KiB" << std::endl;
std::cout << "\tCache line size: " << processor_information[i].Cache.LineSize << " KiB" << std::endl;
break;
*/
}
std::cout << " cache, " << processor_information[i].Cache.Size << " KiB" << std::endl;
std::cout << "\tCache line size: " << processor_information[i].Cache.LineSize << " KiB" << std::endl;
break;
*/
}

return processor_core_information;
}

return processor_core_information;
}
} // namespace FileReadSpeedTest
22 changes: 13 additions & 9 deletions Code/GetProcessorInformation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef GETPROCESSORINFORMATION_HPP
#define GETPROCESSORINFORMATION_HPP
#ifndef FILEREADSPEEDTEST_GETPROCESSORINFORMATION_HPP
#define FILEREADSPEEDTEST_GETPROCESSORINFORMATION_HPP

#include <optional>

class ProcessorCoreInformation {
public:
int actual_cores_;
int hyperthreading_cores_;
};
namespace FileReadSpeedTest {

std::optional<ProcessorCoreInformation> GetProcessorInformation() noexcept;
class ProcessorCoreInformation {
public:
int actual_cores_;
int hyperthreading_cores_;
};

#endif // #ifndef GETPROCESSORINFORMATION_HPP
std::optional<ProcessorCoreInformation> GetProcessorInformation() noexcept;

} // namespace FileReadSpeedTest

#endif // #ifndef FILEREADSPEEDTEST_GETPROCESSORINFORMATION_HPP
40 changes: 22 additions & 18 deletions Code/OSAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,32 @@
#endif
#include <Windows.h>

OSAllocation::OSAllocation(void* memory) noexcept
: memory_(std::move(memory))
{}
namespace FileReadSpeedTest {

OSAllocation::OSAllocation(void* memory) noexcept
: memory_(std::move(memory))
{}

std::optional<OSAllocation> OSAllocator::allocate(size_t size) noexcept {
void* pointer = VirtualAlloc(NULL, size, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
if (pointer == NULL) {
// GetLastError()
return std::nullopt;
}

return OSAllocation{pointer};
}

void OSAllocator::deallocate(OSAllocation& allocation) noexcept {
if (allocation.memory_) {
BOOL result = VirtualFree(allocation.memory_, 0, MEM_RELEASE);
if (result == 0) {
std::optional<OSAllocation> OSAllocator::allocate(size_t size) noexcept {
void* pointer = VirtualAlloc(NULL, size, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
if (pointer == NULL) {
// GetLastError()
return std::nullopt;
}

allocation.memory_ = nullptr;
return OSAllocation{pointer};
}
}

void OSAllocator::deallocate(OSAllocation& allocation) noexcept {
if (allocation.memory_) {
BOOL result = VirtualFree(allocation.memory_, 0, MEM_RELEASE);
if (result == 0) {
// GetLastError()
}

allocation.memory_ = nullptr;
}
}

} // namespace FileReadSpeedTest
30 changes: 17 additions & 13 deletions Code/OSAllocator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,30 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef OSALLOCATOR_HPP
#define OSALLOCATOR_HPP
#ifndef FILEREADSPEEDTEST_OSALLOCATOR_HPP
#define FILEREADSPEEDTEST_OSALLOCATOR_HPP

#include <optional>

class OSAllocation {
public:
namespace FileReadSpeedTest {

explicit OSAllocation(void* memory) noexcept;
class OSAllocation {
public:

void* memory_;
explicit OSAllocation(void* memory) noexcept;

};
void* memory_;

class OSAllocator {
public:
};

static std::optional<OSAllocation> allocate(size_t size) noexcept;
static void deallocate(OSAllocation& allocation) noexcept;
class OSAllocator {
public:

};
static std::optional<OSAllocation> allocate(size_t size) noexcept;
static void deallocate(OSAllocation& allocation) noexcept;

#endif // #ifndef OSALLOCATOR_HPP
};

} // namespace FileReadSpeedTest

#endif // #ifndef FILEREADSPEEDTEST_OSALLOCATOR_HPP
Loading
Loading