-
Notifications
You must be signed in to change notification settings - Fork 11.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[libc] Fix RPC interface when sending and recieving aribtrary packets
The interface exported by the RPC library allows users to simply send and recieve fixed sized packets without worrying about the data motion underneath. However, this was broken in the current implementation. We can think of the send and recieve implementations in terms of waiting for ownership of the buffer, using the buffer, and posting ownership to the other side. Our implementation of `recv` was incorrect in the following scenarios. recv -> send // we still own the buffer and should give away ownership recv -> close // The other side is not waiting for data, this will result in multiple openings of the same port This patch attempts to fix this with an admittedly hacky fix where we track if the previous implementation was a recv and post conditionally. Reviewed By: JonChesterfield Differential Revision: https://reviews.llvm.org/D150327
- Loading branch information
Showing
4 changed files
with
103 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
//===-- Loader test to check the RPC interface with the loader ------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "src/__support/GPU/utils.h" | ||
#include "src/__support/RPC/rpc_client.h" | ||
#include "test/IntegrationTest/test.h" | ||
|
||
using namespace __llvm_libc; | ||
|
||
// Test to ensure that we can use aribtrary combinations of sends and recieves | ||
// as long as they are mirrored. | ||
static void test_interface(bool end_with_send) { | ||
uint64_t cnt = 0; | ||
rpc::Client::Port port = rpc::client.open<rpc::TEST_INTERFACE>(); | ||
port.send([&](rpc::Buffer *buffer) { buffer->data[0] = end_with_send; }); | ||
port.send([&](rpc::Buffer *buffer) { buffer->data[0] = cnt = cnt + 1; }); | ||
port.recv([&](rpc::Buffer *buffer) { cnt = buffer->data[0]; }); | ||
port.send([&](rpc::Buffer *buffer) { buffer->data[0] = cnt = cnt + 1; }); | ||
port.recv([&](rpc::Buffer *buffer) { cnt = buffer->data[0]; }); | ||
port.send([&](rpc::Buffer *buffer) { buffer->data[0] = cnt = cnt + 1; }); | ||
port.send([&](rpc::Buffer *buffer) { buffer->data[0] = cnt = cnt + 1; }); | ||
port.recv([&](rpc::Buffer *buffer) { cnt = buffer->data[0]; }); | ||
port.recv([&](rpc::Buffer *buffer) { cnt = buffer->data[0]; }); | ||
if (end_with_send) | ||
port.send([&](rpc::Buffer *buffer) { buffer->data[0] = cnt = cnt + 1; }); | ||
else | ||
port.recv([&](rpc::Buffer *buffer) { cnt = buffer->data[0]; }); | ||
port.close(); | ||
|
||
ASSERT_TRUE(cnt == 9 && "Invalid number of increments"); | ||
} | ||
|
||
TEST_MAIN(int argc, char **argv, char **envp) { | ||
test_interface(true); | ||
test_interface(false); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters