Skip to content
This repository has been archived by the owner on Sep 24, 2024. It is now read-only.

Commit

Permalink
Test host CPU utilization
Browse files Browse the repository at this point in the history
  • Loading branch information
qizzz committed Sep 21, 2023
1 parent f56b021 commit fef4716
Show file tree
Hide file tree
Showing 2 changed files with 167 additions and 45 deletions.
141 changes: 96 additions & 45 deletions DPDPU/StorageEngine/DDSApplication/DDSApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ using std::endl;
using std::thread;
using std::this_thread::yield;

#define PAGE_SIZE 64
#define PAGE_SIZE 8192

std::mutex mtx;
std::condition_variable cv;
Expand Down Expand Up @@ -281,6 +281,22 @@ BenchmarkIOWithPolling(
delete pollWorker;
}

static uint64_t file_time_2_utc(const FILETIME* ftime)
{
LARGE_INTEGER li;

li.LowPart = ftime->dwLowDateTime;
li.HighPart = ftime->dwHighDateTime;
return li.QuadPart;
}

static int get_processor_number()
{
SYSTEM_INFO info;
GetSystemInfo(&info);
return (int)info.dwNumberOfProcessors;
}

void
BenchmarkIOCPUEfficient(
DDS_FrontEnd::DDSFrontEnd& Store,
Expand All @@ -301,7 +317,7 @@ BenchmarkIOCPUEfficient(
bool pollResult;
size_t completedOps = 0;

ErrorCodeT result = Store->GetDefaultPoll(&pollId);
ErrorCodeT result = Store.GetDefaultPoll(&pollId);
if (result != DDS_ERROR_CODE_SUCCESS) {
cout << "Failed to get default poll" << endl;
return;
Expand All @@ -320,10 +336,31 @@ BenchmarkIOCPUEfficient(
}

cout << "Benchmarking writes..." << endl;

FILETIME now;
FILETIME creation_time;
FILETIME exit_time;
FILETIME kernel_time;
FILETIME user_time;
int64_t system_time;
int64_t time;
int64_t system_time_delta;
int64_t time_delta;
int64_t last_time_ = 0;
int64_t last_system_time_ = 0;

GetSystemTimeAsFileTime(&now);
GetProcessTimes(GetCurrentProcess(), &creation_time, &exit_time, &kernel_time, &user_time);

system_time = (file_time_2_utc(&kernel_time) + file_time_2_utc(&user_time)) / get_processor_number();
time = file_time_2_utc(&now);
last_system_time_ = system_time;
last_time_ = time;

Profiler profiler(totalIOs);
profiler.Start();

for (size_t i = 0; i != totalIOs; i++) {
for (size_t i = 0; i != totalIOs;) {
result = Store.WriteFile(
FileId,
writeBuffer,
Expand All @@ -334,7 +371,7 @@ BenchmarkIOCPUEfficient(
);

if (result == DDS_ERROR_CODE_TOO_MANY_REQUESTS || result == DDS_ERROR_CODE_REQUEST_RING_FAILURE) {
result = Store->PollWait(
result = Store.PollWait(
pollId,
&opSize,
&pollContext,
Expand All @@ -343,32 +380,25 @@ BenchmarkIOCPUEfficient(
&pollResult
);

if (result != DDS_ERROR_CODE_SUCCESS) {
cout << "Failed to poll an operation [" << result << "]" << endl;
return;
}

if (pollResult) {
do {
completedOps++;

result = Store.WriteFile(
FileId,
writeBuffer,
PAGE_SIZE,
&bytesServiced,
NULL,
NULL
Store.PollWait(
pollId,
&opSize,
&pollContext,
&opContext,
0,
&pollResult
);
}
} while (pollResult);
}

if (result != DDS_ERROR_CODE_IO_PENDING) {
cout << "Failed to write file: " << FileId << " [" << result << "]" << endl;
else {
i++;
}
}

while (completedOps != totalIOs) {
result = Store->PollWait(
result = Store.PollWait(
pollId,
&opSize,
&pollContext,
Expand All @@ -388,8 +418,18 @@ BenchmarkIOCPUEfficient(
}

profiler.Stop();

GetSystemTimeAsFileTime(&now);
GetProcessTimes(GetCurrentProcess(), &creation_time, &exit_time, &kernel_time, &user_time);

profiler.Report();

system_time = (file_time_2_utc(&kernel_time) + file_time_2_utc(&user_time)) / get_processor_number();
time = file_time_2_utc(&now);
system_time_delta = system_time - last_system_time_;
time_delta = time - last_time_;
cout << "CPU utilization: " << (system_time_delta * 1.0 / time_delta) * 100 << "%" << endl;

result = Store.SetFilePointer(
FileId,
0,
Expand All @@ -407,8 +447,16 @@ BenchmarkIOCPUEfficient(
memset(readBuffer, 0, sizeof(char) * PAGE_SIZE * DDS_MAX_OUTSTANDING_IO);
completedOps = 0;

GetSystemTimeAsFileTime(&now);
GetProcessTimes(GetCurrentProcess(), &creation_time, &exit_time, &kernel_time, &user_time);

system_time = (file_time_2_utc(&kernel_time) + file_time_2_utc(&user_time)) / get_processor_number();
time = file_time_2_utc(&now);
last_system_time_ = system_time;
last_time_ = time;

profiler.Start();
for (size_t i = 0; i != totalIOs; i++) {
for (size_t i = 0; i != totalIOs;) {
result = Store.ReadFile(
FileId,
&readBuffer[(i % DDS_MAX_OUTSTANDING_IO) * PAGE_SIZE],
Expand All @@ -419,7 +467,7 @@ BenchmarkIOCPUEfficient(
);

if (result == DDS_ERROR_CODE_TOO_MANY_REQUESTS || result == DDS_ERROR_CODE_REQUEST_RING_FAILURE) {
result = Store->PollWait(
result = Store.PollWait(
pollId,
&opSize,
&pollContext,
Expand All @@ -428,32 +476,25 @@ BenchmarkIOCPUEfficient(
&pollResult
);

if (result != DDS_ERROR_CODE_SUCCESS) {
cout << "Failed to poll an operation [" << result << "]" << endl;
return;
}

if (pollResult) {
do {
completedOps++;

result = Store.ReadFile(
FileId,
writeBuffer,
PAGE_SIZE,
&bytesServiced,
NULL,
NULL
Store.PollWait(
pollId,
&opSize,
&pollContext,
&opContext,
0,
&pollResult
);
}
} while (pollResult);
}

if (result != DDS_ERROR_CODE_IO_PENDING) {
cout << "Failed to read file: " << FileId << endl;
else {
i++;
}
}

while (completedOps != totalIOs) {
result = Store->PollWait(
result = Store.PollWait(
pollId,
&opSize,
&pollContext,
Expand All @@ -473,7 +514,17 @@ BenchmarkIOCPUEfficient(
}

profiler.Stop();

GetSystemTimeAsFileTime(&now);
GetProcessTimes(GetCurrentProcess(), &creation_time, &exit_time, &kernel_time, &user_time);

profiler.Report();

system_time = (file_time_2_utc(&kernel_time) + file_time_2_utc(&user_time)) / get_processor_number();
time = file_time_2_utc(&now);
system_time_delta = system_time - last_system_time_;
time_delta = time - last_time_;
cout << "CPU utilization: " << (system_time_delta * 1.0 / time_delta) * 100 << "%" << endl;
}

DWORD WINAPI SleepThread(LPVOID lpParam) {
Expand Down Expand Up @@ -530,7 +581,7 @@ int main()
const char* fileName = "/data/example";
// const FileSizeT maxFileSize = 1073741824ULL;
// const FileSizeT maxFileSize = 8192000;
const FileSizeT maxFileSize = 1638400000;
const FileSizeT maxFileSize = 163840000000;
const FileAccessT fileAccess = 0;
const FileShareModeT shareMode = 0;
const FileAttributesT fileAttributes = 0;
Expand Down
71 changes: 71 additions & 0 deletions DPDPU/StorageEngine/DDSFrontEnd/DDSFrontEnd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,77 @@ DDSFrontEnd::WriteFile(
) {
ErrorCodeT result = DDS_ERROR_CODE_SUCCESS;

/*
PollIdT pollId = AllFiles[FileId]->PollId;
PollT* poll = AllPolls[pollId];
size_t mySlot;
FileIOT* pIO;
bool expectedAvail;
bool found = false;
for (int i = DDS_MAX_OUTSTANDING_IO; i != 0; i--) {
mySlot = poll->NextRequestSlot.fetch_add(1, std::memory_order_relaxed);
mySlot %= DDS_MAX_OUTSTANDING_IO;
pIO = poll->OutstandingRequests[mySlot];
expectedAvail = true;
if (pIO->IsAvailable.compare_exchange_weak(
expectedAvail,
false,
std::memory_order_relaxed
) == false) {
//
// If this is a callback-based completion,
// perform polling once
//
//
if (pIO->AppCallback) {
FileIOSizeT bytesServiced;
ContextT fileCtxt;
ContextT ioCtxt;
bool pollResult;
PollWait(
pollId,
&bytesServiced,
&fileCtxt,
&ioCtxt,
0,
&pollResult
);
}
}
else {
found = true;
break;
}
}
if (!found) {
//
// If this is a callback-based completion,
// perform polling once
//
//
if (pIO->AppCallback) {
FileIOSizeT bytesServiced;
ContextT fileCtxt;
ContextT ioCtxt;
bool pollResult;
PollWait(
pollId,
&bytesServiced,
&fileCtxt,
&ioCtxt,
0,
&pollResult
);
}
return DDS_ERROR_CODE_TOO_MANY_REQUESTS;
}
*/

PollIdT pollId = AllFiles[FileId]->PollId;
PollT* poll = AllPolls[pollId];
size_t mySlot = poll->NextRequestSlot.fetch_add(1, std::memory_order_relaxed);
Expand Down

0 comments on commit fef4716

Please sign in to comment.