Skip to content

Fix mbed-client behaviour in irq contexts #2530

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@

int8_t M2MConnectionHandlerPimpl::_tasklet_id = -1;

static MemoryPool<M2MConnectionHandlerPimpl::TaskIdentifier, 16> memory_pool;

extern "C" void connection_tasklet_event_handler(arm_event_s *event)
{
tr_debug("M2MConnectionHandlerPimpl::connection_tasklet_event_handler");
Expand Down Expand Up @@ -74,7 +76,7 @@ extern "C" void connection_tasklet_event_handler(arm_event_s *event)
break;
}
if (task_id) {
free(task_id);
memory_pool.free(task_id);
}
}

Expand Down Expand Up @@ -145,7 +147,7 @@ bool M2MConnectionHandlerPimpl::resolve_server_address(const String& server_addr
_server_port = server_port;
_server_type = server_type;
_server_address = server_address;
TaskIdentifier* task = (TaskIdentifier*)malloc(sizeof(TaskIdentifier));
TaskIdentifier* task = memory_pool.alloc();
if (!task) {
return false;
}
Expand Down Expand Up @@ -248,7 +250,7 @@ bool M2MConnectionHandlerPimpl::send_data(uint8_t *data,
return false;
}

TaskIdentifier* task = (TaskIdentifier*)malloc(sizeof(TaskIdentifier));
TaskIdentifier* task = memory_pool.alloc();
if (!task) {
free(buffer);
return false;
Expand Down Expand Up @@ -310,9 +312,7 @@ int8_t M2MConnectionHandlerPimpl::connection_tasklet_handler()

void M2MConnectionHandlerPimpl::socket_event()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this called from irq context? then it make sense to minimize code here, like remove trace and allocation related calls,,, but how faster this memory_pool really are? any numbers?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't measured their performance, it would be interesting to see the numbers.

Although the issue isn't with average performance, but with jitter. As a simple linked-list, the memory pool garuntees constant runtime, where malloc may have an outlier (in the case of coalescing lazily for example) but be faster on average. This outlier may disrupt interrupt based communication.

{
tr_debug("M2MConnectionHandlerPimpl::socket_event()");

TaskIdentifier* task = (TaskIdentifier*)malloc(sizeof(TaskIdentifier));
TaskIdentifier* task = memory_pool.alloc();
if (!task) {
_observer.socket_error(M2MConnectionHandler::SOCKET_READ_ERROR, true);
return;
Expand Down