Skip to content

Conversation

@flamingradian
Copy link
Collaborator

This supersedes #6 (at least if the design makes sense).

Method definitions

The largest change is to the method definitions. The new top-level struct is hrpc_method_def_interp4. It contains an array of inner types, and of accepted arguments which may reference inner types by array index.

An argument is defined as a tuple of 2 numbers: type and data. Currently, data is either a size or an index for an inner type. Referencing open source IDL's on the internet, this is the conversion:

in uint32_t: 0 4
in uint64_t: 0 8
in struct: 1 (TYPE SIZE)
in struct with a sequence: 2 (TYPE ID)
in sequence<type>: 3 (TYPE SIZE)
in sequence<struct with a sequence>: 4 (TYPE ID)
rout type: 6 (TYPE SIZE)
rout struct with a sequence: 7 (TYPE ID)
rout sequence<type>: 8 (TYPE SIZE)
rout sequence<struct with a sequence>: 9 (TYPE ID)

Inner types are basically arrays of arguments, used to define a type that has a sequence as a member. They are restricted to 2 of the types, currently preventing recursion:

type: 1 (TYPE SIZE)
sequence<type>: 3 (TYPE SIZE)

Interface files

With the addition of inner types, it's harder to keep the array defined in a macro that can change based on compilation unit. The only readable option I found was to split the data structures into a C file, while the inline functions go in the header file.

The inline functions are changed to pass the file descriptor and handle from thread-local variables instead of parameters. This is similar to how the original fastrpc does it, but it still requires explicit hexagonrpc_fd_from_env(void) and hrpc_open_...(size_t n_err, char *err) calls at the start of the program.

More information will be provided as this gets developed. There are a lot of changes to the API, so it will take some work to get this ready.

@flamingradian flamingradian force-pushed the rdacayan/big-api-change branch 2 times, most recently from e6d033f to f9e7000 Compare July 3, 2025 22:48
@flamingradian
Copy link
Collaborator Author

In libhexagonrpc, the use of function pointers brings up a performance concern since the CPU might not be able to pipeline effectively. GCC inlines things to the point where the functions are known at compile-time, while Clang doesn't inline emit_args unless __attribute__((always_inline)) is specified or -Ofast is passed.

This optimization can be compiler-specific for now. First, we need to decide on one implementation. Since no other issues have been raised here, I'll let this supersede #6.

@flamingradian
Copy link
Collaborator Author

The __thread variables make the project less readable, especially without much documentation. It should just be deferred.

@flamingradian flamingradian force-pushed the rdacayan/big-api-change branch 5 times, most recently from d170a73 to 6ce931b Compare August 19, 2025 02:52
@flamingradian flamingradian changed the title Draft: API changes to libhexagonrpc Support for more methods, new error API, unit test in libhexagonrpc Aug 19, 2025
When the kernel side of FastRPC fails, the return value is -1 and errno
is set. When the remote side of FastRPC fails, the return value is an
AEE error code. It is not specialized for the reverse tunnel. Add an
error API that can convert the return value to a string-based error.

Signed-off-by: Richard Acayan <[email protected]>
When there are more than 31 methods in a remote interface, an extended
method ID is added to the primary input buffer when the ID is greater
than 30. Select the method from the primary input buffer when the ID is
greater than 30 in the reverse tunnel.

Signed-off-by: Richard Acayan <[email protected]>
The current method definition format has a few issues. There is no way
to represent `apps_std_mkdir(in string dir, in long long mode)` because
it has a sequence before a fixed-length argument. The fixed-length
arguments are passed in 4-byte units, making large fixed-length arrays
awkward. Sequences of sequences cannot be represented.

Add a new version of the remote method definition to support more
methods, with sequences of sequences, mixed input and output arguments,
and fixed-length data structures greater than 32 bits.

Signed-off-by: Richard Acayan <[email protected]>
The code for opening and closing a remote interface with an error is
duplicated in hexagonrpcd and chrecd. Like the remotectl interface
itself, the error handling is useful for most FastRPC applications. Add
a new API for opening and closing remote interfaces with error checking.

Signed-off-by: Richard Acayan <[email protected]>
The handle API is a high-level interface that puts all error messages in
the same buffer. Use the handle API to open and close the
adsp_default_listener remote interface.

Signed-off-by: Richard Acayan <[email protected]>
The handle API is a high-level interface that puts all error messages in
the same buffer. Use the handle API to open and close the chre_slpi
remote interface for code deduplication.

Signed-off-by: Richard Acayan <[email protected]>
The FastRPC peer can encode a 32-bit size for a variable-length
sequence. The members of the sequence can have a size more than 1,
potentially using more than 32 bits. Expand the buffer size to a size_t.

Signed-off-by: Richard Acayan <[email protected]>
To use interp4 method definitions for everything, the reverse tunnel
needs to be updated to understand them. Add support for the new method
definitions, preferring them if present.

Signed-off-by: Richard Acayan <[email protected]>
The new interp4 definitions add support for more remote methods with
sequences of multi-byte data, sequences of sequences, plain integers
interleaved with sequences, and constant-size data other than 32-bit
integers. The new definitions are complex and can't fit in a simple
macro. Switch the remotectl interface to interp4, split it into a header
and source file, and update the users.

Signed-off-by: Richard Acayan <[email protected]>
The new interp4 definitions add support for more remote methods with
sequences of multi-byte data, sequences of sequences, plain integers
interleaved with sequences, and constant-size data other than 32-bit
integers. The new definitions are complex and can't fit in a simple
macro. Switch the chre_slpi interface to interp4, split it into a header
and source file, and update the users.

Signed-off-by: Richard Acayan <[email protected]>
The new interp4 definitions add support for more remote methods with
sequences of multi-byte data, sequences of sequences, plain integers
interleaved with sequences, and constant-size data other than 32-bit
integers. The new definitions are complex and can't fit in a simple
macro. Switch the chre_slpi interface to interp4, split it into a header
and source file, and add the new definitions to the implementation.

Signed-off-by: Richard Acayan <[email protected]>
The new interp4 definitions add support for more remote methods with
sequences of multi-byte data, sequences of sequences, plain integers
interleaved with sequences, and constant-size data other than 32-bit
integers. The new definitions are complex and can't fit in a simple
macro. Switch the apps_mem interface to interp4, split it into a header
and source file, and add the new definitions to the implementation.

Signed-off-by: Richard Acayan <[email protected]>
The new interp4 definitions add support for more remote methods with
sequences of multi-byte data, sequences of sequences, plain integers
interleaved with sequences, and constant-size data other than 32-bit
integers. The new definitions are complex and can't fit in a simple
macro. Switch the adsp_listener interface to interp4, split it into a
header and source file, and update the users.

Signed-off-by: Richard Acayan <[email protected]>
The new interp4 definitions add support for more remote methods with
sequences of multi-byte data, sequences of sequences, plain integers
interleaved with sequences, and constant-size data other than 32-bit
integers. The new definitions are complex and can't fit in a simple
macro. Switch the chre_slpi interface to interp4, split it into a header
and source file, and update the users.

Signed-off-by: Richard Acayan <[email protected]>
With the remote method definitions converted to interp4, the interp2
definitions are no longer needed. Replace the interp2 definitions with
the interp4 definitions recently added.

Signed-off-by: Richard Acayan <[email protected]>
Both the hexagonfs and iobuffer tests need malloc and free. The iobuffer
test also needs REMOTE_SCALARS_MAKE. Include stdlib directly and include
the new libhexagonrpc header file.

Signed-off-by: Richard Acayan <[email protected]>
The iobuffer decoder depends on REMOTE_SCALARS_INBUFS to know the number
of encoded input buffers without knowing the exact length of the encoded
input. Depend on the new hexagonrpc header which is being switched to.

Signed-off-by: Richard Acayan <[email protected]>
There is now no user of the interp2 APIs in the source tree.
Remove them.

Signed-off-by: Richard Acayan <[email protected]>
The hexagonrpc function is getting very complex and deserves its own
unit test. Add a unit test for the hexagonrpc function.

Signed-off-by: Richard Acayan <[email protected]>
@flamingradian flamingradian force-pushed the rdacayan/big-api-change branch from 6ce931b to c706676 Compare August 29, 2025 00:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants