[client] clipboard: reduce remote file transfer latency

Mark the last non-empty FILE_DATA payload with BEGIN and END when the
producer knows it is terminal. Complete producer bookkeeping in the
following fileDataEnd call without consuming another LGMP grant. Keep
the standalone terminal record for empty and legacy unknown streams.

Drain up to 64 queued clipboard records per worker pass instead of
sleeping after every message. Poll at 1 ms while transfers, blocked
writes, held input, or pending output are active, and retain the 10 ms
interval while idle.

This removes a serialized grant round trip from every non-empty file
response and reduces scheduling delay while a large transfer is active.
Keep the 1 MiB payload size because the bottleneck was stop-and-wait
latency, not the chunk capacity.

Exercise a full 1 MiB response in a single BEGIN|END grant and retain
coverage for empty unknown-size responses.
This commit is contained in:
Geoffrey McRae
2026-08-15 01:13:13 +10:00
parent f9ffce528a
commit 6631fde35f
7 changed files with 123 additions and 56 deletions

View File

@@ -719,6 +719,7 @@ static bool checkCommit(TestState * state, uint32_t token,
}
static bool checkFileCommit(TestState * state, uint32_t grantToken,
KVMFRClipboardFileOperation operation,
KVMFRClipboardMessage * commit, KVMFRClipboardMessage * slot,
const void ** data)
{
@@ -736,7 +737,7 @@ static bool checkFileCommit(TestState * state, uint32_t grantToken,
CHECK(slot->flags == commit->flags);
CHECK(slot->length == commit->length);
CHECK(slot->sequence == commit->sequence);
CHECK(slot->token == KVMFR_CLIPBOARD_FILE_OP_READ);
CHECK(slot->token == operation);
*data = (const uint8_t *)lgmpHostMemPtr(
state->grantMemory[grantToken - 1]) + sizeof(*slot);
return true;
@@ -1280,26 +1281,47 @@ static bool testFileStream(TestState * state)
CHECK(postGrant(state, claimRecord.generation, 1));
CHECK(waitMemory(state, state->grantMemory[0]));
CHECK(state->ops->fileDataChunk(state->clipboard,
&descriptor, 0, bytes, sizeof(bytes)) ==
&descriptor, 0, bytes, sizeof(bytes), true) ==
LG_CLIPBOARD_RESULT_ACCEPTED);
KVMFRClipboardMessage commit;
KVMFRClipboardMessage slot;
const void * data;
CHECK(checkFileCommit(state, 1, &commit, &slot, &data));
CHECK(slot.flags == KVMFR_CLIPBOARD_FLAG_BEGIN);
CHECK(checkFileCommit(state, 1, KVMFR_CLIPBOARD_FILE_OP_READ,
&commit, &slot, &data));
CHECK(slot.flags == (KVMFR_CLIPBOARD_FLAG_BEGIN |
KVMFR_CLIPBOARD_FLAG_END));
CHECK(slot.offset == 0 && slot.sequence == 0 &&
slot.size == sizeof(bytes));
CHECK(slot.length == sizeof(bytes));
CHECK(memcmp(data, bytes, sizeof(bytes)) == 0);
CHECK(state->ops->fileDataEnd(state->clipboard,
&descriptor, sizeof(bytes)) == LG_CLIPBOARD_RESULT_ACCEPTED);
CHECK(noClientData(state));
const unsigned requests = atomic_load(&state->events.fileRequest);
request.transfer = KVMFR_CLIPBOARD_TRANSFER_HELPER | UINT64_C(0x7803);
request.offset = 0;
request.size = KVMFR_CLIPBOARD_FILE_ROOT_NODE;
request.flags = 0;
request.token = KVMFR_CLIPBOARD_FILE_OP_LIST;
CHECK(postRecord(state, &request,
KVMFR_CLIPBOARD_QUEUE_MESSAGE, NULL));
CHECK(waitAtomic(state, &state->events.fileRequest, requests + 1));
const LG_ClipboardFileRequest empty = state->events.fileRequestValue;
CHECK(empty.operation == LG_CLIPBOARD_FILE_LIST);
CHECK(state->ops->fileDataBegin(state->clipboard,
&empty, KVMFR_CLIPBOARD_SIZE_UNKNOWN) ==
LG_CLIPBOARD_RESULT_ACCEPTED);
CHECK(postGrant(state, claimRecord.generation, 1));
CHECK(waitMemory(state, state->grantMemory[0]));
CHECK(state->ops->fileDataEnd(state->clipboard,
&descriptor, sizeof(bytes)) == LG_CLIPBOARD_RESULT_ACCEPTED);
CHECK(checkFileCommit(state, 1, &commit, &slot, &data));
CHECK(slot.flags == KVMFR_CLIPBOARD_FLAG_END);
CHECK(slot.offset == sizeof(bytes) && slot.sequence == 1 &&
slot.size == sizeof(bytes));
&empty, 0) == LG_CLIPBOARD_RESULT_ACCEPTED);
CHECK(checkFileCommit(state, 1, KVMFR_CLIPBOARD_FILE_OP_LIST,
&commit, &slot, &data));
CHECK(slot.flags == (KVMFR_CLIPBOARD_FLAG_BEGIN |
KVMFR_CLIPBOARD_FLAG_END));
CHECK(slot.offset == 0 && slot.sequence == 0 && slot.size == 0);
CHECK(slot.length == 0);
return true;
}