Skip to content

Commit 883f7e4

Browse files
committed
uavcan: static allocation
1 parent be29f64 commit 883f7e4

File tree

6 files changed

+13
-47
lines changed

6 files changed

+13
-47
lines changed

src/drivers/uavcan/allocator.hpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,18 @@ struct AllocatorSynchronizer {
5050
~AllocatorSynchronizer() { ::leave_critical_section(state); }
5151
};
5252

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

5756
Allocator() :
58-
uavcan::HeapBasedPoolAllocator<uavcan::MemPoolBlockSize, AllocatorSynchronizer>(CapacitySoftLimit, CapacityHardLimit)
57+
uavcan::PoolAllocator<250 * uavcan::MemPoolBlockSize, uavcan::MemPoolBlockSize, AllocatorSynchronizer>()
5958
{ }
6059

6160
~Allocator()
6261
{
63-
if (getNumAllocatedBlocks() > 0) {
62+
if (getNumUsedBlocks() > 0) {
6463
PX4_ERR("UAVCAN LEAKS MEMORY: %u BLOCKS (%u BYTES) LOST",
65-
getNumAllocatedBlocks(), getNumAllocatedBlocks() * uavcan::MemPoolBlockSize);
64+
getNumUsedBlocks(), getNumUsedBlocks() * uavcan::MemPoolBlockSize);
6665
}
6766
}
6867
};

src/drivers/uavcan/uavcan_main.cpp

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,11 +1132,7 @@ UavcanNode::print_info()
11321132
{
11331133
// Memory status
11341134
printf("Pool allocator status:\n");
1135-
printf("\tCapacity hard/soft: %" PRIu16 "/%" PRIu16 " blocks\n",
1136-
_pool_allocator.getBlockCapacityHardLimit(), _pool_allocator.getBlockCapacity());
1137-
printf("\tReserved: %" PRIu16 " blocks\n", _pool_allocator.getNumReservedBlocks());
1138-
printf("\tAllocated: %" PRIu16 " blocks\n", _pool_allocator.getNumAllocatedBlocks());
1139-
1135+
printf("\tCapacity : %" PRIu16 " blocks\n", _pool_allocator.getBlockCapacity());
11401136
printf("\n");
11411137

11421138
// UAVCAN node perfcounters
@@ -1211,14 +1207,6 @@ UavcanNode::print_info()
12111207
perf_print_counter(_interval_perf);
12121208
}
12131209

1214-
void
1215-
UavcanNode::shrink()
1216-
{
1217-
(void)pthread_mutex_lock(&_node_mutex);
1218-
_pool_allocator.shrink();
1219-
(void)pthread_mutex_unlock(&_node_mutex);
1220-
}
1221-
12221210
void
12231211
UavcanNode::cb_getset(const uavcan::ServiceCallResult<uavcan::protocol::param::GetSet> &result)
12241212
{
@@ -1435,7 +1423,7 @@ UavcanNode::get_next_dirty_node_id(uint8_t base)
14351423
static void print_usage()
14361424
{
14371425
PX4_INFO("usage: \n"
1438-
"\tuavcan {start|status|stop|shrink|update}\n"
1426+
"\tuavcan {start|status|stop|update}\n"
14391427
"\t param [set|get|list|save] <node-id> <name> <value>|reset <node-id>");
14401428
}
14411429

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

1495-
if (!std::strcmp(argv[1], "shrink")) {
1496-
inst->shrink();
1497-
::exit(0);
1498-
}
1499-
15001483
/*
15011484
* Parameter setting commands
15021485
*

src/drivers/uavcan/uavcan_main.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,6 @@ class UavcanNode : public px4::ScheduledWorkItem, public ModuleParams
215215

216216
void print_info();
217217

218-
void shrink();
219-
220218
static UavcanNode *instance() { return _instance; }
221219
static int getHardwareVersion(uavcan::protocol::HardwareVersion &hwver);
222220

src/drivers/uavcannode/UavcanNode.cpp

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -692,11 +692,7 @@ void UavcanNode::PrintInfo()
692692

693693
// Memory status
694694
printf("Pool allocator status:\n");
695-
printf("\tCapacity hard/soft: %u/%u blocks\n",
696-
_pool_allocator.getBlockCapacityHardLimit(), _pool_allocator.getBlockCapacity());
697-
printf("\tReserved: %u blocks\n", _pool_allocator.getNumReservedBlocks());
698-
printf("\tAllocated: %u blocks\n", _pool_allocator.getNumAllocatedBlocks());
699-
695+
printf("\tCapacity: %u blocks\n", _pool_allocator.getBlockCapacity());
700696
printf("\n");
701697

702698
// UAVCAN node perfcounters
@@ -750,13 +746,6 @@ void UavcanNode::PrintInfo()
750746
pthread_mutex_unlock(&_node_mutex);
751747
}
752748

753-
void UavcanNode::shrink()
754-
{
755-
(void)pthread_mutex_lock(&_node_mutex);
756-
_pool_allocator.shrink();
757-
(void)pthread_mutex_unlock(&_node_mutex);
758-
}
759-
760749
} // namespace uavcannode
761750

762751
static void print_usage()

src/drivers/uavcannode/UavcanNode.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,6 @@ class UavcanNode : public px4::ScheduledWorkItem
131131

132132
void PrintInfo();
133133

134-
void shrink();
135-
136134
static UavcanNode *instance() { return _instance; }
137135
static int getHardwareVersion(uavcan::protocol::HardwareVersion &hwver);
138136

src/drivers/uavcannode/allocator.hpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,18 @@ struct AllocatorSynchronizer {
5050
~AllocatorSynchronizer() { ::leave_critical_section(state); }
5151
};
5252

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

5756
Allocator() :
58-
uavcan::HeapBasedPoolAllocator<uavcan::MemPoolBlockSize, AllocatorSynchronizer>(CapacitySoftLimit, CapacityHardLimit)
57+
uavcan::PoolAllocator<250 * uavcan::MemPoolBlockSize, uavcan::MemPoolBlockSize, AllocatorSynchronizer>()
5958
{ }
6059

6160
~Allocator()
6261
{
63-
if (getNumAllocatedBlocks() > 0) {
62+
if (getNumUsedBlocks() > 0) {
6463
PX4_ERR("UAVCAN LEAKS MEMORY: %u BLOCKS (%u BYTES) LOST",
65-
getNumAllocatedBlocks(), getNumAllocatedBlocks() * uavcan::MemPoolBlockSize);
64+
getNumUsedBlocks(), getNumUsedBlocks() * uavcan::MemPoolBlockSize);
6665
}
6766
}
6867
};

0 commit comments

Comments
 (0)