Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/drivers/uavcan/allocator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,19 @@ struct AllocatorSynchronizer {
~AllocatorSynchronizer() { ::leave_critical_section(state); }
};

struct Allocator : public uavcan::HeapBasedPoolAllocator<uavcan::MemPoolBlockSize, AllocatorSynchronizer> {
static constexpr unsigned CapacitySoftLimit = 250;
static constexpr unsigned CapacityHardLimit = 500;
struct Allocator : public
uavcan::PoolAllocator<250 * uavcan::MemPoolBlockSize, uavcan::MemPoolBlockSize, AllocatorSynchronizer> {
static constexpr unsigned NumBlocks = 250;

Allocator() :
uavcan::HeapBasedPoolAllocator<uavcan::MemPoolBlockSize, AllocatorSynchronizer>(CapacitySoftLimit, CapacityHardLimit)
uavcan::PoolAllocator<250 * uavcan::MemPoolBlockSize, uavcan::MemPoolBlockSize, AllocatorSynchronizer>()
{ }

~Allocator()
{
if (getNumAllocatedBlocks() > 0) {
if (getNumUsedBlocks() > 0) {
PX4_ERR("UAVCAN LEAKS MEMORY: %u BLOCKS (%u BYTES) LOST",
getNumAllocatedBlocks(), getNumAllocatedBlocks() * uavcan::MemPoolBlockSize);
getNumUsedBlocks(), getNumUsedBlocks() * uavcan::MemPoolBlockSize);
}
}
};
Expand Down
21 changes: 2 additions & 19 deletions src/drivers/uavcan/uavcan_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1132,11 +1132,7 @@ UavcanNode::print_info()
{
// Memory status
printf("Pool allocator status:\n");
printf("\tCapacity hard/soft: %" PRIu16 "/%" PRIu16 " blocks\n",
_pool_allocator.getBlockCapacityHardLimit(), _pool_allocator.getBlockCapacity());
printf("\tReserved: %" PRIu16 " blocks\n", _pool_allocator.getNumReservedBlocks());
printf("\tAllocated: %" PRIu16 " blocks\n", _pool_allocator.getNumAllocatedBlocks());

printf("\tCapacity : %" PRIu16 " blocks\n", _pool_allocator.getBlockCapacity());
printf("\n");

// UAVCAN node perfcounters
Expand Down Expand Up @@ -1211,14 +1207,6 @@ UavcanNode::print_info()
perf_print_counter(_interval_perf);
}

void
UavcanNode::shrink()
{
(void)pthread_mutex_lock(&_node_mutex);
_pool_allocator.shrink();
(void)pthread_mutex_unlock(&_node_mutex);
}

void
UavcanNode::cb_getset(const uavcan::ServiceCallResult<uavcan::protocol::param::GetSet> &result)
{
Expand Down Expand Up @@ -1435,7 +1423,7 @@ UavcanNode::get_next_dirty_node_id(uint8_t base)
static void print_usage()
{
PX4_INFO("usage: \n"
"\tuavcan {start|status|stop|shrink|update}\n"
"\tuavcan {start|status|stop|update}\n"
"\t param [set|get|list|save] <node-id> <name> <value>|reset <node-id>");
}

Expand Down Expand Up @@ -1492,11 +1480,6 @@ extern "C" __EXPORT int uavcan_main(int argc, char *argv[])
::exit(0);
}

if (!std::strcmp(argv[1], "shrink")) {
inst->shrink();
::exit(0);
}

/*
* Parameter setting commands
*
Expand Down
2 changes: 0 additions & 2 deletions src/drivers/uavcan/uavcan_main.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,6 @@ class UavcanNode : public px4::ScheduledWorkItem, public ModuleParams

void print_info();

void shrink();

static UavcanNode *instance() { return _instance; }
static int getHardwareVersion(uavcan::protocol::HardwareVersion &hwver);

Expand Down
13 changes: 1 addition & 12 deletions src/drivers/uavcannode/UavcanNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -692,11 +692,7 @@ void UavcanNode::PrintInfo()

// Memory status
printf("Pool allocator status:\n");
printf("\tCapacity hard/soft: %u/%u blocks\n",
_pool_allocator.getBlockCapacityHardLimit(), _pool_allocator.getBlockCapacity());
printf("\tReserved: %u blocks\n", _pool_allocator.getNumReservedBlocks());
printf("\tAllocated: %u blocks\n", _pool_allocator.getNumAllocatedBlocks());

printf("\tCapacity: %u blocks\n", _pool_allocator.getBlockCapacity());
printf("\n");

// UAVCAN node perfcounters
Expand Down Expand Up @@ -750,13 +746,6 @@ void UavcanNode::PrintInfo()
pthread_mutex_unlock(&_node_mutex);
}

void UavcanNode::shrink()
{
(void)pthread_mutex_lock(&_node_mutex);
_pool_allocator.shrink();
(void)pthread_mutex_unlock(&_node_mutex);
}

} // namespace uavcannode

static void print_usage()
Expand Down
2 changes: 0 additions & 2 deletions src/drivers/uavcannode/UavcanNode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,6 @@ class UavcanNode : public px4::ScheduledWorkItem

void PrintInfo();

void shrink();

static UavcanNode *instance() { return _instance; }
static int getHardwareVersion(uavcan::protocol::HardwareVersion &hwver);

Expand Down
12 changes: 6 additions & 6 deletions src/drivers/uavcannode/allocator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,19 @@ struct AllocatorSynchronizer {
~AllocatorSynchronizer() { ::leave_critical_section(state); }
};

struct Allocator : public uavcan::HeapBasedPoolAllocator<uavcan::MemPoolBlockSize, AllocatorSynchronizer> {
static constexpr unsigned CapacitySoftLimit = 250;
static constexpr unsigned CapacityHardLimit = 500;
struct Allocator : public
uavcan::PoolAllocator<250 * uavcan::MemPoolBlockSize, uavcan::MemPoolBlockSize, AllocatorSynchronizer> {
static constexpr unsigned NumBlocks = 250;

Allocator() :
uavcan::HeapBasedPoolAllocator<uavcan::MemPoolBlockSize, AllocatorSynchronizer>(CapacitySoftLimit, CapacityHardLimit)
uavcan::PoolAllocator<250 * uavcan::MemPoolBlockSize, uavcan::MemPoolBlockSize, AllocatorSynchronizer>()
{ }

~Allocator()
{
if (getNumAllocatedBlocks() > 0) {
if (getNumUsedBlocks() > 0) {
PX4_ERR("UAVCAN LEAKS MEMORY: %u BLOCKS (%u BYTES) LOST",
getNumAllocatedBlocks(), getNumAllocatedBlocks() * uavcan::MemPoolBlockSize);
getNumUsedBlocks(), getNumUsedBlocks() * uavcan::MemPoolBlockSize);
}
}
};
Expand Down
Loading