hello,
how do i increase task speed after adding a multipe queue handle in a single task
xTaskCreate(&task, "task", 2048 * 2, NULL, 11, &xHandle);
task handle:
void main_task(void *pvParameter)
{
// static variables declartions
while(1)
{
if (xQueueReceive(handle, (void *)&array, (portTickType)5)) {
//processing the received messages
}
//sending the received messages to local queue say handle_1_queue size of 10
if (xQueueReceive(another_handle, (void *)&another_array, (portTickType)5)) {
//processing the received messages
}
//sending the received messages to local queue say handle_2_queue size of 10
if (handle_1_queue_size == 10) {
//send entire queue to cloud
}
if (handle_2_queue_size == 10) {
//send entire queue to cloud
}
}
}
whole process becomes slow by adding second queue handle if only one queue handle had been there task is so much faster is there any way to handle this
ps: i could not create another task
thanks and regrads
manikandan v
Receive message from a queue - This call can block upto 5 ticks as that is the value you are passing to the xQueueReceive’s xTicksToWait parameter.
Receive message from another queue - This call can block upto 5 ticks as that is the value you are passing to the xQueueReceive’s xTicksToWait parameter.
2 calls to send data to cloud.
So essentially when you add another queue, you are adding a block time of upto 5 ticks and an additional call to the cloud. These are the sources that would contribute to the run time increase. There may be something else in the code that you have not shared.
How much is the delay?
If you describe the problem that you are trying to solve, we can try to suggest a solution.
hello,
dealy is vTaskDelay(10/ portTICK_RATE_MS);
is there a way to asking questions privately so that i can share the entire function?
my problem is that after adding a second queue handle cpu speed decrease up to 3/10 i want to increase this as much as possibe
my queue creation:
handle1= xQueueCreate(20, sizeof(structure1)); //size->32
handle2=xQueueCreate(15, sizeof(structure2)); //size->48
your terminology is unlear. The CPU speed certainly does not decrease, what does decrease? You probably mean the loop turnaround time? Gaurav has already explained what the factors are here-
You can remove the blocking time on each of the xQueueReceive calls. If there is nothing in the queue it will return pdFALSE immediately which will cause the if block to be skipped.
The loop will run in much less time, but you’ll also need to give consideration to how you yield to allow other tasks that are ready to run. You dont show how youre doing this in what you have posted, so I assume you arent doing that at all.
If you dont yield or otherwise block somewhere in your task then you may starve other tasks of run time, and this will also contribute to things appearing to run slower - it may take a tick to pre-emptively switch to another task (if pre-emption is enabled).
Your current code “plays nice” in this respect due to having a block time in calls to xQueueReceive which will allow your task to yield to another task, but you could reduce the block time to 1 tick for example to allow this task to complete its loop quicker.
I described the factors that contribute to the loop turn around time - adjusting them will help you to reduce the turn around time.
You can send me a DM. If possible, I’d still recommend to share the code here (after removing any intellectual property obviously) so that more people can take a look at it.
@manivalaguru Reading through the problem, you have posted code that doesn’t meet your expectations, but not an actual description of what you are actually wanting to do. I wouldn’t be surprized if this is something you haven’t actually stopped to define (and I mean WHAT, not HOW).
Having a clearly defined goal often defines good ways to acheive it, not having a goal often leads to muddles like you have here.
I will also add that having a single task waiting on multiple unrelated objects (queues, semaphores, events, etc) is often a sign of unclear planing.
One option might be to put those queues into a QueueSet, so the task waits just on the QueueSet, then gets whatever data appears.
Another technique that might be useful is computing the block time dependent on what has happened recently to let you get multiple inputs but still deliver your output on time (if that is the issue).