Skip to content

Commit

Permalink
Add basic support for B7 RC / KVMFR 20
Browse files Browse the repository at this point in the history
This is a minor patch adding partial support for the updated KVMFR
version. Support for the RGB 24-in-32 operating mode may not work
as expected, but non-compressed modes used in previous versions,
such as BGRA/RGBA, should continue to work.

Note that the overarching plan for LGProxy is still to overhaul the
architecture, as this code is a mess. This is a stop-gap measure so
that users can benefit from the new Looking Glass features within
LGProxy.

Creation of further discussions or issues is welcome, so that new
feature additions and bugfixes can be triaged based on user feedback.

Changes:

- Use upstream Looking Glass again, as I won't maintain the texture
  compression fork
- Remove compressed texture support (see above). If you need texture
  compression support, use the old version `1ef3453`.
- Update copyright short identifier to GPL 2.0 or later
- Update help messages
- Use the OS name field in KVMFR to display the LGProxy relay version
- Update C standard to C11. It should already have been used in
  practice due to LG using it, but we define it here explicitly now.
- Enable optimization. We barely tested LGProxy with optimization, so
  it might break things.
- Enable sleep periods under 1ms and sync mode. This still has a quite
  a few problems that have to be ironed out, but in theory it will
  further reduce CPU usage.

Specific Recommendations:

- For TCP users, we recommend trying the new native TCP provider in
  Libfabric by updating your Libfabric versions (on both sides) to
  version 1.18.0 or higher. While this is no alternative to RDMA, it
  should provide improved performance in TCP mode.
  • Loading branch information
beanfacts committed May 9, 2024
1 parent 24d972a commit 820e8d9
Show file tree
Hide file tree
Showing 20 changed files with 222 additions and 120 deletions.
10 changes: 5 additions & 5 deletions lgproxy/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.0.0)
cmake_minimum_required(VERSION 3.5.0)
project(lgproxy LANGUAGES C)

get_filename_component(PROJECT_TOP "${PROJECT_SOURCE_DIR}/.." ABSOLUTE)
Expand Down Expand Up @@ -50,8 +50,8 @@ add_compile_options(
"-ffast-math"
"-fdata-sections"
"-ffunction-sections"
#"$<$<CONFIG:DEBUG>:-O0;-g3;-ggdb>"
"-O0;-g3;-ggdb"
"$<$<CONFIG:DEBUG>:-O0;-g3;-ggdb>"
# "-O0;-g3;-ggdb"
)

file(COPY "${PROJECT_TOP}/repos/libtrf/libtrf/conf" DESTINATION "./source_build")
Expand Down Expand Up @@ -80,14 +80,14 @@ set(SINK

add_executable(source ${SOURCE})
target_link_libraries(source trf lgmp m lg_common protobuf-c)
set_property(TARGET source PROPERTY C_STANDARD 99)
set_property(TARGET source PROPERTY C_STANDARD 11)

set_target_properties(source PROPERTIES RUNTIME_OUTPUT_DIRECTORY "./source_build")

add_executable(sink ${SINK})

target_link_libraries(sink trf lgmp m lg_common protobuf-c)
set_property(TARGET sink PROPERTY C_STANDARD 99)
set_property(TARGET sink PROPERTY C_STANDARD 11)

set_target_properties(sink PROPERTIES RUNTIME_OUTPUT_DIRECTORY "./sink_build")

Expand Down
26 changes: 7 additions & 19 deletions lgproxy/common/include/lp_convert.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
SPDX-License-Identifier: GPL-2.0-only
SPDX-License-Identifier: GPL-2.0-or-later
Telescope Project
Looking Glass Proxy
Expand Down Expand Up @@ -46,16 +46,10 @@ static inline uint64_t lpLGToTrfFormat(int lg_type)
return TRF_TEX_RGBA_1010102;
case FRAME_TYPE_RGBA16F:
return TRF_TEX_RGBA_16161616F;
case FRAME_TYPE_RGB:
case FRAME_TYPE_RGB_24:
return TRF_TEX_RGB_888;
case FRAME_TYPE_DXT1:
return TRF_TEX_DXT1;
case FRAME_TYPE_DXT5:
return TRF_TEX_DXT5;
case FRAME_TYPE_ETC2:
return TRF_TEX_ETC2;
case FRAME_TYPE_ETC2_EAC:
return TRF_TEX_ETC2_EAC;
case FRAME_TYPE_BGR_32:
return TRF_TEX_BGR_32;
default:
return TRF_TEX_INVALID;
}
Expand All @@ -80,15 +74,9 @@ static inline uint64_t lpTrftoLGFormat(int trf_type)
case TRF_TEX_RGBA_16161616F:
return FRAME_TYPE_RGBA16F;
case TRF_TEX_RGB_888:
return FRAME_TYPE_RGB;
case TRF_TEX_DXT1:
return FRAME_TYPE_DXT1;
case TRF_TEX_DXT5:
return FRAME_TYPE_DXT5;
case TRF_TEX_ETC2:
return FRAME_TYPE_ETC2;
case TRF_TEX_ETC2_EAC:
return FRAME_TYPE_ETC2_EAC;
return FRAME_TYPE_RGB_24;
case TRF_TEX_BGR_32:
return FRAME_TYPE_BGR_32;
default:
return FRAME_TYPE_INVALID;
}
Expand Down
2 changes: 1 addition & 1 deletion lgproxy/common/include/lp_msg.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
SPDX-License-Identifier: GPL-2.0-only
SPDX-License-Identifier: GPL-2.0-or-later
Telescope Project
Looking Glass Proxy
Expand Down
2 changes: 1 addition & 1 deletion lgproxy/common/include/lp_retrieve.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
SPDX-License-Identifier: GPL-2.0-only
SPDX-License-Identifier: GPL-2.0-or-later
Telescope Project
Looking Glass Proxy
Expand Down
2 changes: 1 addition & 1 deletion lgproxy/common/include/lp_trf_client.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
SPDX-License-Identifier: GPL-2.0-only
SPDX-License-Identifier: GPL-2.0-or-later
Telescope Project
Looking Glass Proxy
Expand Down
2 changes: 1 addition & 1 deletion lgproxy/common/include/lp_trf_server.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
SPDX-License-Identifier: GPL-2.0-only
SPDX-License-Identifier: GPL-2.0-or-later
Telescope Project
Looking Glass Proxy
Expand Down
15 changes: 8 additions & 7 deletions lgproxy/common/include/lp_types.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
SPDX-License-Identifier: GPL-2.0-only
SPDX-License-Identifier: GPL-2.0-or-later
Telescope Project
Looking Glass Proxy
Expand Down Expand Up @@ -180,15 +180,16 @@ typedef struct {

typedef struct {
/**
* @brief Libfabric Poll Interval default will be set to 1 millisecond
*
* @brief Libfabric polling interval in nanoseconds. If this is 0 (default),
* then busy waiting will be used. If this is negative, then the program
* will use synchronous mode.
*/
int poll_int;
int64_t poll_int;
/**
* @brief Delete SHM file on exit default will it will not delete the shm file unless specified
*
* @brief Delete the shared memory file on program exit. By default, this is
* false.
*/
bool delete_exit;
bool delete_exit;
}LPUserOpts;

typedef enum {
Expand Down
7 changes: 5 additions & 2 deletions lgproxy/common/include/lp_utils.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
SPDX-License-Identifier: GPL-2.0-only
SPDX-License-Identifier: GPL-2.0-or-later
Telescope Project
Looking Glass Proxy
Expand Down Expand Up @@ -36,9 +36,10 @@
*
* @param ctx Context to use.
* @param msg Message pointer to be set when a message has been received.
* @param timeoutMs Optional timeout for the message in milliseconds.
* @return 0 on success, negative error code on failure.
*/
int lpPollMsg(PLPContext ctx, TrfMsg__MessageWrapper ** msg);
int lpPollMsg(PLPContext ctx, TrfMsg__MessageWrapper ** msg, int timeoutMs);

/**
* @brief Parse bytes neede from string passed in to arguments
Expand All @@ -48,6 +49,8 @@ int lpPollMsg(PLPContext ctx, TrfMsg__MessageWrapper ** msg);
*/
uint64_t lpParseMemString(char * data);

int64_t lpParsePollString(char * data);

/**
* @brief Check if the SHM File needs to be truncated
*
Expand Down
2 changes: 1 addition & 1 deletion lgproxy/common/include/lp_write.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
SPDX-License-Identifier: GPL-2.0-only
SPDX-License-Identifier: GPL-2.0-or-later
Telescope Project
Looking Glass Proxy
Expand Down
2 changes: 1 addition & 1 deletion lgproxy/common/src/lp_msg.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
SPDX-License-Identifier: GPL-2.0-only
SPDX-License-Identifier: GPL-2.0-or-later
Telescope Project
Looking Glass Proxy
Expand Down
11 changes: 4 additions & 7 deletions lgproxy/common/src/lp_retrieve.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
SPDX-License-Identifier: GPL-2.0-only
SPDX-License-Identifier: GPL-2.0-or-later
Telescope Project
Looking Glass Proxy
Expand Down Expand Up @@ -82,7 +82,7 @@ int lpClientInitSession(PLPContext ctx)
for (int retry = 0; retry < 20; retry++)
{
status = lgmpClientSessionInit(ctx->lp_host.lgmp_client, &udataSize,
(uint8_t **) &udata);
(uint8_t **) &udata, NULL);
lp__log_trace("lgmpClientSessionInit: %s", lgmpStatusString(status));

switch (status)
Expand Down Expand Up @@ -257,11 +257,8 @@ int lpGetFrame(PLPContext ctx, KVMFRFrame ** out, FrameBuffer ** fb)
}

if (frame)
{
lp__log_trace("------------ Frame Received ------------");
lp__log_trace("Frame size: %d x %d", frame->frameWidth, frame->frameHeight);
lp__log_trace("----------------------------------------");
}
lp__log_trace("Received frame size: %d x %d",
frame->frameWidth, frame->frameHeight);

frameSerial = frame->frameSerial;
*out = frame;
Expand Down
2 changes: 1 addition & 1 deletion lgproxy/common/src/lp_trf_client.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
SPDX-License-Identifier: GPL-2.0-only
SPDX-License-Identifier: GPL-2.0-or-later
Telescope Project
Looking Glass Proxy
Expand Down
2 changes: 1 addition & 1 deletion lgproxy/common/src/lp_trf_server.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
SPDX-License-Identifier: GPL-2.0-only
SPDX-License-Identifier: GPL-2.0-or-later
Telescope Project
Looking Glass Proxy
Expand Down
2 changes: 1 addition & 1 deletion lgproxy/common/src/lp_types.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
SPDX-License-Identifier: GPL-2.0-only
SPDX-License-Identifier: GPL-2.0-or-later
Telescope Project
Looking Glass Proxy
Expand Down
102 changes: 77 additions & 25 deletions lgproxy/common/src/lp_utils.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
SPDX-License-Identifier: GPL-2.0-only
SPDX-License-Identifier: GPL-2.0-or-later
Telescope Project
Looking Glass Proxy
Expand All @@ -24,23 +24,47 @@
#include "lp_utils.h"
#include "version.h"

int lpPollMsg(PLPContext ctx, TrfMsg__MessageWrapper ** msg)
int lpPollMsg(PLPContext ctx, TrfMsg__MessageWrapper ** msg, int timeoutMs)
{
struct fi_cq_data_entry de;
struct fi_cq_err_entry err;
ssize_t ret;

ret = trfFabricPollRecv(ctx->lp_client.client_ctx, &de, &err, 0, 0, NULL, 1);
if (ret == 0 || ret == -EAGAIN)
struct TRFContext * tc = ctx->lp_client.client_ctx;
assert(tc);

if (timeoutMs > 0) {
struct timespec dl;
ret = trfGetDeadline(&dl, timeoutMs);
if (ret < 0)
{
lp__log_error("Clock error: %s", strerror(-ret));
return ret;
}
ret = trfFabricPollRecv(ctx->lp_client.client_ctx, &de, &err,
tc->opts->fab_cq_sync, tc->opts->fab_poll_rate,
&dl, 1);
}
else
{
return -EAGAIN;
ret = trfFabricPollRecv(ctx->lp_client.client_ctx, &de, &err, 0, 0,
NULL, 1);
}
if (ret < 0)
switch (ret)
{
lp__log_error("Unable to poll CQ: %s", fi_strerror(-ret));
return ret;
case 0:
case -EAGAIN:
return -EAGAIN;
case -ETIMEDOUT:
return -ETIMEDOUT;
case 1:
break;
default:
lp__log_error("Unable to poll CQ: %s", fi_strerror(-ret));
return ret;
}
void *msgmem = trfMemPtr(&ctx->lp_client.client_ctx->xfer.fabric->msg_mem);

void * msgmem = trfMemPtr(&ctx->lp_client.client_ctx->xfer.fabric->msg_mem);
ret = trfMsgUnpack(msg,
trfMsgGetPackedLength(msgmem),
trfMsgGetPayload(msgmem));
Expand All @@ -50,6 +74,7 @@ int lpPollMsg(PLPContext ctx, TrfMsg__MessageWrapper ** msg)
strerror(-ret));
return ret;
}

return 0;
}

Expand All @@ -61,22 +86,49 @@ uint64_t lpParseMemString(char * data)
{
return b;
}
else

switch (multiplier)
{
switch (multiplier)
{
case 'K':
case 'k':
return b * 1024;
case 'M':
case 'm':
return b * 1024 * 1024;
case 'G':
case 'g':
return b * 1024 * 1024 * 1024;
default:
return 0;
}
case 'K':
case 'k':
return b * 1024;
case 'M':
case 'm':
return b * 1024 * 1024;
case 'G':
case 'g':
return b * 1024 * 1024 * 1024;
default:
return 0;
}
}

int64_t lpParsePollString(char * data)
{
char multiplier = data[strlen(data)-1];
int64_t b = atoi(data);
if (multiplier >= '0' && multiplier <= '9')
{
return b * (int64_t) 1000000;
}

switch (multiplier)
{
case 's':
case 'S':
return b * (int64_t) 1000000000;
case 'm':
case 'M':
return b * (int64_t) 1000000;
case 'u':
case 'U':
return b * (int64_t) 1000;
case 'n':
case 'N':
return b;
default:
lp__log_warn("Invalid polling interval, defaulting to busy wait");
return 0;
}
}

Expand All @@ -103,7 +155,7 @@ bool lpShouldTruncate(PLPContext ctx)

int lpSetDefaultOpts(PLPContext ctx)
{
ctx->opts.poll_int = 1;
ctx->opts.poll_int = 0;
ctx->shm = "/dev/shm/looking-glass";
return 0;
}
Expand Down
Loading

0 comments on commit 820e8d9

Please sign in to comment.