Skip to content

Commit

Permalink
Merge branch 'master' into bracz-optimize-tcp-socket
Browse files Browse the repository at this point in the history
* master:
  Adds configuration options for TCP sockets, tuning for Hub app. (#759)
  Limits end to end buffering in gridconnect bridge. (#758)
  Ensures that an executor thread can not be created twice. (#757)
  Fixes build_bootloader_img.py. (#755)
  • Loading branch information
balazsracz committed Jan 2, 2024
2 parents 3e6e3ac + 761abe9 commit 781184c
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ LDFLAGSEXTRA+= --specs=nano.specs
bootloader_bin/bootloader.bin: FORCE
$(MAKE) -C $(realpath bootloader_bin) bootloader.bin

payload.cxxout: bootloader_bin/bootloader.bin
payload.cxxout: bootloader_bin/bootloader.bin $(OPENMRNPATH)/bin/build_bootloader_img.py
$(OPENMRNPATH)/bin/build_bootloader_img.py -i bootloader_bin/bootloader.bin -o $@

.cxxout.o:
Expand Down
13 changes: 10 additions & 3 deletions bin/build_bootloader_img.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@ def print_c_array(file_out, name, payload):
ofs = 0
while True :
c = file_in.read(1)
if c == "" :
break
if len(c) == 0:
print("eof at", ofs)
break
bin_file.append(c)
ofs = ofs + 1
if options.maxsize is not None and ofs >= options.maxsize:
Expand All @@ -104,26 +105,32 @@ def print_c_array(file_out, name, payload):

outputblocks = []

print("Blocks:", end=" ")
for k, block in enumerate(blocks):
if k == 0:
b = Block()
b.ofs = 0
b.data = block
b.end_ofs = 0
outputblocks.append(b)
print("b", end="")
continue
if block.count('\0') == len(block): # all zeros
if block.count(b'\x00') == len(block): # all zeros
print("o", end="")
continue
if outputblocks[-1].end_ofs == k - 1:
outputblocks[-1].data += block
outputblocks[-1].end_ofs = k
print("x", end="")
else:
b = Block()
b.ofs = k
b.data = block
b.end_ofs = k
outputblocks.append(b)
print("b", end="")

print("")
segmenttable = ''
for b in outputblocks:
print_c_array(file_out, "payload_%d" % b.ofs, b.data);
Expand Down
1 change: 1 addition & 0 deletions src/os/OS.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public:
*/
void start(const char *name, int priority, size_t stack_size)
{
HASSERT(!is_created());
os_thread_create(&handle, name, priority, stack_size, start, this);
}

Expand Down
38 changes: 35 additions & 3 deletions src/utils/GridConnectHub.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,17 @@ class GCAdapter : public GCAdapterBase
, skipMember_(skip_member)
, double_bytes_(double_bytes)
{
const int cnt = config_gridconnect_bridge_max_outgoing_packets();
if (cnt > 1)
{
ownedPool_.reset(
new LimitedPool(sizeof(Buffer<CanHubData>), cnt));
pool_ = ownedPool_.get();
}
else
{
pool_ = mainBufferPool;
}
}

/// @return where to write the packets to.
Expand All @@ -144,10 +155,27 @@ class GCAdapter : public GCAdapterBase
return destination_;
}

bool shutdown() {
return delayPort_.shutdown();
/// @return Triggers releasing all memory after a close. Returns true
/// if it's safe to delete this.
bool shutdown()
{
const int cnt = config_gridconnect_bridge_max_outgoing_packets();
bool state_delay = delayPort_.shutdown();
bool state_pool = true;
if (ownedPool_)
{
state_pool = (int(ownedPool_->free_items()) == cnt);
}
return state_delay && state_pool;
}


/// The dispatcher will be using this pool to allocate frames when a
/// hub needs to make a copy for an outgoing queue.
Pool *pool() override
{
return pool_;
}

Action entry() override
{
LOG(VERBOSE, "can packet arrived: %" PRIx32,
Expand Down Expand Up @@ -186,6 +214,10 @@ class GCAdapter : public GCAdapterBase
/// Helper class that assembles larger outgoing packets from the
/// individual packets by delaying data a little bit.
BufferPort delayPort_;
/// If we want frame limits, this pool can do that for us.
std::unique_ptr<LimitedPool> ownedPool_;
/// The allocation buffer pool to use for outgoing frames.
Pool *pool_;
/// Destination buffer (characters).
char dbuf_[56];
/// Pipe to send data to.
Expand Down

0 comments on commit 781184c

Please sign in to comment.