Skip to content

Commit

Permalink
Fix early flush logic.
Browse files Browse the repository at this point in the history
Use clock() instead of time() to determine how much time has passed, as that likely has a higher resolution. Also add back in the old flush logic, as a backup in case clock() doesn't have a high-enough resolution to cause it to flush before the entire command buffer is used up.


BUG=
TEST=


Review URL: http://codereview.chromium.org/7789023

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@100057 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
jbauman@chromium.org committed Sep 8, 2011
1 parent 703901a commit 14eb04b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
22 changes: 15 additions & 7 deletions gpu/command_buffer/client/cmd_buffer_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ CommandBufferHelper::~CommandBufferHelper() {
}

bool CommandBufferHelper::FlushSync() {
time(&last_flush_time_);
last_flush_time_ = clock();
last_put_sent_ = put_;
CommandBuffer::State state = command_buffer_->FlushSync(put_, get_offset());
return state.error == error::kNoError;
}

void CommandBufferHelper::Flush() {
time(&last_flush_time_);
last_flush_time_ = clock();
last_put_sent_ = put_;
command_buffer_->Flush(put_);
}
Expand Down Expand Up @@ -152,11 +152,19 @@ void CommandBufferHelper::WaitForAvailableEntries(int32 count) {
return;
}
}
// Allow this command buffer to be pre-empted by another if a "reasonable"
// amount of work has been done.
if (commands_issued_ % kCommandsPerFlushCheck == 0) {
clock_t current_time = time(NULL);
if (difftime(current_time, last_flush_time_) > kFlushDelay)
// Force a flush if the buffer is getting half full, or even earlier if the
// reader is known to be idle.
int32 pending =
(put_ + usable_entry_count_ - last_put_sent_) % usable_entry_count_;
int32 limit = usable_entry_count_ /
((get_offset() == last_put_sent_) ? 16 : 2);
if (pending > limit) {
Flush();
} else if (commands_issued_ % kCommandsPerFlushCheck == 0) {
// Allow this command buffer to be pre-empted by another if a "reasonable"
// amount of work has been done.
clock_t current_time = clock();
if (current_time - last_flush_time_ > kFlushDelay * CLOCKS_PER_SEC)
Flush();
}
}
Expand Down
2 changes: 1 addition & 1 deletion gpu/command_buffer/client/cmd_buffer_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ class CommandBufferHelper {
int commands_issued_;

// Using C runtime instead of base because this file cannot depend on base.
time_t last_flush_time_;
clock_t last_flush_time_;

friend class CommandBufferHelperTest;
DISALLOW_COPY_AND_ASSIGN(CommandBufferHelper);
Expand Down

0 comments on commit 14eb04b

Please sign in to comment.